common-fun.c 1.3 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * Copyright (C) 2014 CERN (www.cern.ch)
 * Author: Alessandro Rubini
 *
 * Released according to the GNU LGPL, version 2.1 or any later version.
 */
#include <ppsi/ppsi.h>

9
void wr_reset_process(struct pp_instance *ppi, wr_role_t role) {
10
	struct wr_dsport *wrp = WR_DSPOR(ppi);
11

12 13 14 15 16 17 18 19 20 21
	wrp->wrStateTimeout = WR_DEFAULT_STATE_TIMEOUT_MS;
	wrp->calPeriod = WR_DEFAULT_CAL_PERIOD;
	wrp->wrMode = role;
	wrp->wrModeOn=FALSE;
	wrp->calibrated = !WR_DEFAULT_PHY_CALIBRATION_REQUIRED;
	/* Reset parent data */
	wrp->parentWrConfig = NON_WR;
	wrp->parentIsWRnode =
			wrp->parentWrModeOn =
					wrp->parentCalibrated = FALSE;
22 23 24 25 26 27 28 29 30
}

/* The handshake failed: go master or slave in normal PTP mode */
void wr_handshake_fail(struct pp_instance *ppi)
{
	struct wr_dsport *wrp = WR_DSPOR(ppi);

	pp_diag(ppi, ext, 1, "Handshake failure: now non-wr %s\n",
		wrp->wrMode == WR_MASTER ? "master" : "slave");
31 32 33
	wrp->next_state=WRS_IDLE;
	wr_reset_process(ppi,WR_ROLE_NONE);
	wr_servo_reset(ppi);
34
	pdstate_disable_extension(ppi);
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
}


/* One of the steps failed: either retry or fail */
int wr_handshake_retry(struct pp_instance *ppi)
{
	struct wr_dsport *wrp = WR_DSPOR(ppi);

	if (wrp->wrStateRetry > 0) {
		wrp->wrStateRetry--;
		pp_diag(ppi, ext, 1, "Retry on timeout\n");
		return 1; /* yes, retry */
	}
	return 0; /* don't retry, we are over already */
}