Commit 44deab24 authored by Alessandro Rubini's avatar Alessandro Rubini

proto-ext-whiterabbit: split out wr-specific portDS

struct DSPort now has a void pointer called ext_dsport that is used by
each extension to store its own local data.  White Rabbit, thus,
is not a special case any more in this respect.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 756f9d6b
......@@ -254,35 +254,7 @@ typedef struct DSPort {
Integer8 logMinPdelayReqInterval;
UInteger4 versionNumber;
/* White Rabbit extension begin (see wrspec.v2-06-07-2011, page 17) */
Enumeration8 wrConfig;
Enumeration8 wrMode;
Boolean wrModeOn;
Enumeration8 wrPortState;
/* FIXME check doc: knownDeltaTx, knownDeltaRx, deltasKnown?) */
Boolean calibrated;
FixedDelta deltaTx;
FixedDelta deltaRx;
UInteger32 wrStateTimeout;
UInteger8 wrStateRetry;
UInteger32 calPeriod;
UInteger8 calRetry;
Enumeration8 parentWrConfig;
Boolean parentIsWRnode; /* FIXME Not in the doc */
/* FIXME check doc: (parentWrMode?) */
Enumeration16 msgTmpWrMessageID; /* FIXME Not in the doc */
Boolean parentWrModeOn;
Boolean parentCalibrated;
/* FIXME: are they in the doc? */
UInteger16 otherNodeCalSendPattern;
UInteger32 otherNodeCalPeriod;
UInteger8 otherNodeCalRetry;
FixedDelta otherNodeDeltaTx;
FixedDelta otherNodeDeltaRx;
Boolean doRestart;
Boolean linkUP;
/* White Rabbit extension end */
void *ext_dsport;
} DSPort;
/* Time Properties Data Set */
......
......@@ -87,12 +87,13 @@ void s1(struct pp_instance *ppi, MsgHeader *hdr, MsgAnnounce *ann)
DSPRO(ppi)->timeSource = ann->timeSource;
/* White Rabbit */
DSPOR(ppi)->parentIsWRnode = ((ann->wrFlags & WR_NODE_MODE) != NON_WR);
DSPOR(ppi)->parentWrModeOn =
WR_DSPOR(ppi)->parentIsWRnode =
((ann->wrFlags & WR_NODE_MODE) != NON_WR);
WR_DSPOR(ppi)->parentWrModeOn =
(ann->wrFlags & WR_IS_WR_MODE) ? TRUE : FALSE;
DSPOR(ppi)->parentCalibrated =
WR_DSPOR(ppi)->parentCalibrated =
((ann->wrFlags & WR_IS_CALIBRATED) ? 1 : 0);
DSPOR(ppi)->parentWrConfig = ann->wrFlags & WR_NODE_MODE;
WR_DSPOR(ppi)->parentWrConfig = ann->wrFlags & WR_NODE_MODE;
DSCUR(ppi)->primarySlavePortNumber =
DSPOR(ppi)->portIdentity.portNumber;
......
......@@ -12,10 +12,10 @@ int st_com_execute_slave(struct pp_instance *ppi, int check_delayreq)
{
int ret = 0;
if (DSPOR(ppi)->doRestart) {
if (WR_DSPOR(ppi)->doRestart) {
ppi->next_state = PPS_INITIALIZING;
st_com_restart_annrec_timer(ppi);
DSPOR(ppi)->doRestart = FALSE;
WR_DSPOR(ppi)->doRestart = FALSE;
return 0;
}
......@@ -178,10 +178,10 @@ int st_com_slave_handle_announce(struct pp_instance *ppi, unsigned char *buf,
st_com_add_foreign(ppi, buf);
}
if ((DSPOR(ppi)->wrConfig & WR_S_ONLY) &&
if ((WR_DSPOR(ppi)->wrConfig & WR_S_ONLY) &&
(1 /* FIXME: Recommended State, see page 33*/) &&
(DSPOR(ppi)->parentWrConfig & WR_M_ONLY) &&
(!DSPOR(ppi)->wrModeOn || !DSPOR(ppi)->parentWrModeOn))
(WR_DSPOR(ppi)->parentWrConfig & WR_M_ONLY) &&
(!WR_DSPOR(ppi)->wrModeOn || !WR_DSPOR(ppi)->parentWrModeOn))
ppi->next_state = WRS_PRESENT;
/*Reset Timer handling Announce receipt timeout*/
......@@ -286,7 +286,7 @@ int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
add_TimeInternal(&correction_field, &correction_field,
&ppi->last_sync_corr_field);
if (!DSPOR(ppi)->wrModeOn) {
if (!WR_DSPOR(ppi)->wrModeOn) {
pp_update_offset(ppi, &precise_orig_timestamp,
&ppi->sync_receive_time,
&correction_field);
......
......@@ -229,8 +229,8 @@ int msg_pack_announce(struct pp_instance *ppi)
*(UInteger16 *) (buf + 61) = htons(DSCUR(ppi)->stepsRemoved);
*(Enumeration8 *) (buf + 63) = DSPRO(ppi)->timeSource;
if (DSPOR(ppi)->wrConfig != NON_WR &&
DSPOR(ppi)->wrConfig != WR_S_ONLY) {
if (WR_DSPOR(ppi)->wrConfig != NON_WR &&
WR_DSPOR(ppi)->wrConfig != WR_S_ONLY) {
msg_pack_announce_wr_tlv(ppi);
return WR_ANNOUNCE_LENGTH;
}
......
......@@ -68,12 +68,12 @@ int pp_initializing(struct pp_instance *ppi, unsigned char *pkt, int plen)
DSPOR(ppi)->delayMechanism = PP_DEFAULT_DELAY_MECHANISM;
DSPOR(ppi)->logMinPdelayReqInterval = PP_DEFAULT_PDELAYREQ_INTERVAL;
DSPOR(ppi)->versionNumber = PP_VERSION_PTP;
DSPOR(ppi)->wrStateTimeout = WR_DEFAULT_STATE_TIMEOUT_MS;
DSPOR(ppi)->wrStateRetry = WR_DEFAULT_STATE_REPEAT;
DSPOR(ppi)->calPeriod = WR_DEFAULT_CAL_PERIOD;
DSPOR(ppi)->wrModeOn = 0;
DSPOR(ppi)->parentWrConfig = 0;
DSPOR(ppi)->calibrated = !WR_DEFAULT_PHY_CALIBRATION_REQUIRED;
WR_DSPOR(ppi)->wrStateTimeout = WR_DEFAULT_STATE_TIMEOUT_MS;
WR_DSPOR(ppi)->wrStateRetry = WR_DEFAULT_STATE_REPEAT;
WR_DSPOR(ppi)->calPeriod = WR_DEFAULT_CAL_PERIOD;
WR_DSPOR(ppi)->wrModeOn = 0;
WR_DSPOR(ppi)->parentWrConfig = 0;
WR_DSPOR(ppi)->calibrated = !WR_DEFAULT_PHY_CALIBRATION_REQUIRED;
if (pp_timer_init(ppi))
goto failure;
......
......@@ -14,8 +14,8 @@ int pp_listening(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (ppi->is_new_state) {
DSPOR(ppi)->portState = PPS_LISTENING;
DSPOR(ppi)->wrMode = NON_WR;
DSPOR(ppi)->wrPortState = WRS_IDLE;
WR_DSPOR(ppi)->wrMode = NON_WR;
WR_DSPOR(ppi)->wrPortState = WRS_IDLE;
st_com_restart_annrec_timer(ppi);
}
......
......@@ -190,10 +190,10 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
MsgSignaling wrsig_msg;
msg_unpack_wrsig(ppi, pkt, &wrsig_msg,
&(DSPOR(ppi)->msgTmpWrMessageID));
&(WR_DSPOR(ppi)->msgTmpWrMessageID));
if ((DSPOR(ppi)->msgTmpWrMessageID == SLAVE_PRESENT) &&
(DSPOR(ppi)->wrConfig & WR_M_ONLY))
if ((WR_DSPOR(ppi)->msgTmpWrMessageID == SLAVE_PRESENT) &&
(WR_DSPOR(ppi)->wrConfig & WR_M_ONLY))
ppi->next_state = WRS_M_LOCK;
break;
......
......@@ -113,7 +113,7 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
hdr->correctionfield,
&correction_field);
if (!DSPOR(ppi)->wrModeOn)
if (!WR_DSPOR(ppi)->wrModeOn)
pp_update_delay(ppi, &correction_field);
else {
wr_servo_got_delay(ppi,
......
......@@ -11,18 +11,18 @@ int wr_calibrated(struct pp_instance *ppi, unsigned char *pkt, int plen)
MsgSignaling wrsig_msg;
if (ppi->is_new_state) {
DSPOR(ppi)->wrPortState = WRS_CALIBRATED;
WR_DSPOR(ppi)->wrPortState = WRS_CALIBRATED;
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
pp_timer_start(DSPOR(ppi)->wrStateTimeout,
pp_timer_start(WR_DSPOR(ppi)->wrStateTimeout,
ppi->timers[PP_TIMER_WRS_CALIBRATED]);
}
if (pp_timer_expired(ppi->timers[PP_TIMER_WRS_CALIBRATED])) {
if (DSPOR(ppi)->wrMode == WR_MASTER)
if (WR_DSPOR(ppi)->wrMode == WR_MASTER)
ppi->next_state = PPS_MASTER;
else
ppi->next_state = PPS_LISTENING;
DSPOR(ppi)->wrPortState = WRS_IDLE;
WR_DSPOR(ppi)->wrPortState = WRS_IDLE;
goto state_updated;
}
......@@ -31,13 +31,13 @@ int wr_calibrated(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (ppi->msg_tmp_header.messageType == PPM_SIGNALING) {
msg_unpack_wrsig(ppi, pkt, &wrsig_msg,
&(DSPOR(ppi)->msgTmpWrMessageID));
&(WR_DSPOR(ppi)->msgTmpWrMessageID));
if ((DSPOR(ppi)->msgTmpWrMessageID == CALIBRATE) &&
(DSPOR(ppi)->wrMode == WR_MASTER))
if ((WR_DSPOR(ppi)->msgTmpWrMessageID == CALIBRATE) &&
(WR_DSPOR(ppi)->wrMode == WR_MASTER))
ppi->next_state = WRS_RESP_CALIB_REQ;
else if ((DSPOR(ppi)->msgTmpWrMessageID == WR_MODE_ON) &&
(DSPOR(ppi)->wrMode == WR_SLAVE))
else if ((WR_DSPOR(ppi)->msgTmpWrMessageID == WR_MODE_ON) &&
(WR_DSPOR(ppi)->wrMode == WR_SLAVE))
ppi->next_state = WRS_WR_LINK_ON;
}
......@@ -46,6 +46,6 @@ state_updated:
pp_timer_stop(ppi->timers[PP_TIMER_WRS_CALIBRATED]);
ret:
ppi->next_delay = DSPOR(ppi)->wrStateTimeout;
ppi->next_delay = WR_DSPOR(ppi)->wrStateTimeout;
return 0;
}
......@@ -13,31 +13,31 @@ int wr_calibration(struct pp_instance *ppi, unsigned char *pkt, int plen)
uint32_t delta;
if (ppi->is_new_state) {
DSPOR(ppi)->wrPortState = WRS_CALIBRATION;
WR_DSPOR(ppi)->wrPortState = WRS_CALIBRATION;
e = msg_issue_wrsig(ppi, CALIBRATE);
pp_timer_start(DSPOR(ppi)->calPeriod,
pp_timer_start(WR_DSPOR(ppi)->calPeriod,
ppi->timers[PP_TIMER_WRS_CALIBRATION]);
if (DSPOR(ppi)->calibrated) {
DSPOR(ppi)->wrPortState = WRS_CALIBRATION_2;
if (WR_DSPOR(ppi)->calibrated) {
WR_DSPOR(ppi)->wrPortState = WRS_CALIBRATION_2;
}
}
if (pp_timer_expired(ppi->timers[PP_TIMER_WRS_CALIBRATION])) {
if (DSPOR(ppi)->wrMode == WR_MASTER)
if (WR_DSPOR(ppi)->wrMode == WR_MASTER)
ppi->next_state = PPS_MASTER;
else
ppi->next_state = PPS_LISTENING;
DSPOR(ppi)->wrPortState = WRS_IDLE;
WR_DSPOR(ppi)->wrPortState = WRS_IDLE;
goto state_updated;
}
switch (DSPOR(ppi)->wrPortState) {
switch (WR_DSPOR(ppi)->wrPortState) {
case WRS_CALIBRATION:
/* enable pattern sending */
if (wr_calibration_pattern_enable(ppi, 0, 0, 0) ==
WR_HW_CALIB_OK)
DSPOR(ppi)->wrPortState = WRS_CALIBRATION_1;
WR_DSPOR(ppi)->wrPortState = WRS_CALIBRATION_1;
else
break;
......@@ -45,7 +45,7 @@ int wr_calibration(struct pp_instance *ppi, unsigned char *pkt, int plen)
/* enable Tx calibration */
if (wr_calibrating_enable(ppi, WR_HW_CALIB_TX)
== WR_HW_CALIB_OK)
DSPOR(ppi)->wrPortState = WRS_CALIBRATION_2;
WR_DSPOR(ppi)->wrPortState = WRS_CALIBRATION_2;
else
break;
......@@ -53,16 +53,16 @@ int wr_calibration(struct pp_instance *ppi, unsigned char *pkt, int plen)
/* wait until Tx calibration is finished */
if (wr_calibrating_poll(ppi, WR_HW_CALIB_TX, &delta) ==
WR_HW_CALIB_READY) {
DSPOR(ppi)->deltaTx.scaledPicoseconds.msb =
WR_DSPOR(ppi)->deltaTx.scaledPicoseconds.msb =
0xFFFFFFFF & (((uint64_t)delta) >> 16);
DSPOR(ppi)->deltaTx.scaledPicoseconds.lsb =
WR_DSPOR(ppi)->deltaTx.scaledPicoseconds.lsb =
0xFFFFFFFF & (((uint64_t)delta) << 16);
PP_PRINTF("Tx=>>scaledPicoseconds.msb = 0x%x\n",
DSPOR(ppi)->deltaTx.scaledPicoseconds.msb);
PP_PRINTF("Tx=>>scaledPicoseconds.lsb = 0x%x\n",
DSPOR(ppi)->deltaTx.scaledPicoseconds.lsb);
DSPOR(ppi)->wrPortState = WRS_CALIBRATION_3;
WR_DSPOR(ppi)->wrPortState = WRS_CALIBRATION_3;
}
else
break; /* again */
......@@ -71,14 +71,14 @@ int wr_calibration(struct pp_instance *ppi, unsigned char *pkt, int plen)
/* disable Tx calibration */
if (wr_calibrating_disable(ppi, WR_HW_CALIB_TX)
== WR_HW_CALIB_OK)
DSPOR(ppi)->wrPortState = WRS_CALIBRATION_4;
WR_DSPOR(ppi)->wrPortState = WRS_CALIBRATION_4;
else
break;
case WRS_CALIBRATION_4:
/* disable pattern sending */
if (wr_calibration_pattern_disable(ppi) == WR_HW_CALIB_OK)
DSPOR(ppi)->wrPortState = WRS_CALIBRATION_5;
WR_DSPOR(ppi)->wrPortState = WRS_CALIBRATION_5;
else
break;
......@@ -86,7 +86,7 @@ int wr_calibration(struct pp_instance *ppi, unsigned char *pkt, int plen)
/* enable Rx calibration using the pattern sent by other port */
if (wr_calibrating_enable(ppi, WR_HW_CALIB_RX) ==
WR_HW_CALIB_OK)
DSPOR(ppi)->wrPortState = WRS_CALIBRATION_6;
WR_DSPOR(ppi)->wrPortState = WRS_CALIBRATION_6;
else
break;
......@@ -95,16 +95,16 @@ int wr_calibration(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (wr_calibrating_poll(ppi, WR_HW_CALIB_RX, &delta) ==
WR_HW_CALIB_READY) {
PP_PRINTF("Rx fixed delay = %d\n", (int)delta);
DSPOR(ppi)->deltaRx.scaledPicoseconds.msb =
WR_DSPOR(ppi)->deltaRx.scaledPicoseconds.msb =
0xFFFFFFFF & (delta >> 16);
DSPOR(ppi)->deltaRx.scaledPicoseconds.lsb =
WR_DSPOR(ppi)->deltaRx.scaledPicoseconds.lsb =
0xFFFFFFFF & (delta << 16);
PP_PRINTF("Rx=>>scaledPicoseconds.msb = 0x%x\n",
DSPOR(ppi)->deltaRx.scaledPicoseconds.msb);
PP_PRINTF("Rx=>>scaledPicoseconds.lsb = 0x%x\n",
DSPOR(ppi)->deltaRx.scaledPicoseconds.lsb);
DSPOR(ppi)->wrPortState = WRS_CALIBRATION_7;
WR_DSPOR(ppi)->wrPortState = WRS_CALIBRATION_7;
}
else
break; /* again */
......@@ -113,14 +113,14 @@ int wr_calibration(struct pp_instance *ppi, unsigned char *pkt, int plen)
/* disable Rx calibration */
if (wr_calibrating_disable(ppi, WR_HW_CALIB_RX)
== WR_HW_CALIB_OK)
DSPOR(ppi)->wrPortState = WRS_CALIBRATION_8;
WR_DSPOR(ppi)->wrPortState = WRS_CALIBRATION_8;
else
break;
case WRS_CALIBRATION_8:
/* send deltas to the other port and go to the next state */
e = msg_issue_wrsig(ppi, CALIBRATED);
ppi->next_state = WRS_CALIBRATED;
DSPOR(ppi)->calibrated = TRUE;
WR_DSPOR(ppi)->calibrated = TRUE;
default:
break;
......@@ -130,7 +130,7 @@ state_updated:
if (ppi->next_state != ppi->state)
pp_timer_stop(ppi->timers[PP_TIMER_WRS_CALIBRATION]);
ppi->next_delay = DSPOR(ppi)->wrStateTimeout;
ppi->next_delay = WR_DSPOR(ppi)->wrStateTimeout;
return e;
}
......@@ -11,22 +11,22 @@ int wr_link_on(struct pp_instance *ppi, unsigned char *pkt, int plen)
int e = 0;
if (ppi->is_new_state) {
DSPOR(ppi)->wrModeOn = TRUE;
WR_DSPOR(ppi)->wrModeOn = TRUE;
wr_enable_ptracker(ppi);
if (DSPOR(ppi)->wrMode == WR_MASTER)
if (WR_DSPOR(ppi)->wrMode == WR_MASTER)
e = msg_issue_wrsig(ppi, WR_MODE_ON);
DSPOR(ppi)->parentWrModeOn = TRUE;
DSPOR(ppi)->wrPortState = WRS_WR_LINK_ON;
WR_DSPOR(ppi)->parentWrModeOn = TRUE;
WR_DSPOR(ppi)->wrPortState = WRS_WR_LINK_ON;
}
if (e != 0)
return -1;
DSPOR(ppi)->wrPortState = WRS_IDLE;
WR_DSPOR(ppi)->wrPortState = WRS_IDLE;
if (DSPOR(ppi)->wrMode == WR_SLAVE)
if (WR_DSPOR(ppi)->wrMode == WR_SLAVE)
ppi->next_state = PPS_SLAVE;
else
ppi->next_state = PPS_MASTER;
......
......@@ -13,8 +13,8 @@ int wr_locked(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (ppi->is_new_state) {
DSPOR(ppi)->portState = PPS_UNCALIBRATED;
DSPOR(ppi)->wrPortState = WRS_LOCKED;
pp_timer_start(DSPOR(ppi)->wrStateTimeout,
WR_DSPOR(ppi)->wrPortState = WRS_LOCKED;
pp_timer_start(WR_DSPOR(ppi)->wrStateTimeout,
ppi->timers[PP_TIMER_WRS_LOCKED]);
e = msg_issue_wrsig(ppi, LOCKED);
......@@ -22,8 +22,8 @@ int wr_locked(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (pp_timer_expired(ppi->timers[PP_TIMER_WRS_LOCKED])) {
ppi->next_state = PPS_LISTENING;
DSPOR(ppi)->wrMode = NON_WR;
DSPOR(ppi)->wrPortState = WRS_IDLE;
WR_DSPOR(ppi)->wrMode = NON_WR;
WR_DSPOR(ppi)->wrPortState = WRS_IDLE;
goto state_updated;
}
......@@ -33,9 +33,9 @@ int wr_locked(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (ppi->msg_tmp_header.messageType == PPM_SIGNALING) {
msg_unpack_wrsig(ppi, pkt, &wrsig_msg,
&(DSPOR(ppi)->msgTmpWrMessageID));
&(WR_DSPOR(ppi)->msgTmpWrMessageID));
if (DSPOR(ppi)->msgTmpWrMessageID == CALIBRATE)
if (WR_DSPOR(ppi)->msgTmpWrMessageID == CALIBRATE)
ppi->next_state = WRS_RESP_CALIB_REQ;
}
......@@ -47,7 +47,7 @@ state_updated:
if (ppi->next_state != ppi->state)
pp_timer_stop(ppi->timers[PP_TIMER_WRS_LOCKED]);
ppi->next_delay = DSPOR(ppi)->wrStateTimeout;
ppi->next_delay = WR_DSPOR(ppi)->wrStateTimeout;
return e;
}
......@@ -13,8 +13,8 @@ int wr_m_lock(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (ppi->is_new_state) {
DSPOR(ppi)->portState = PPS_MASTER;
DSPOR(ppi)->wrPortState = WRS_M_LOCK;
DSPOR(ppi)->wrMode = WR_MASTER;
WR_DSPOR(ppi)->wrPortState = WRS_M_LOCK;
WR_DSPOR(ppi)->wrMode = WR_MASTER;
e = msg_issue_wrsig(ppi, LOCK);
pp_timer_start(WR_M_LOCK_TIMEOUT_MS,
ppi->timers[PP_TIMER_WRS_M_LOCK]);
......@@ -22,7 +22,7 @@ int wr_m_lock(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (pp_timer_expired(ppi->timers[PP_TIMER_WRS_M_LOCK])) {
ppi->next_state = PPS_MASTER;
DSPOR(ppi)->wrPortState = WRS_IDLE;
WR_DSPOR(ppi)->wrPortState = WRS_IDLE;
goto state_updated;
}
......@@ -32,9 +32,9 @@ int wr_m_lock(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (ppi->msg_tmp_header.messageType == PPM_SIGNALING) {
msg_unpack_wrsig(ppi, pkt, &wrsig_msg,
&(DSPOR(ppi)->msgTmpWrMessageID));
&(WR_DSPOR(ppi)->msgTmpWrMessageID));
if (DSPOR(ppi)->msgTmpWrMessageID == LOCKED)
if (WR_DSPOR(ppi)->msgTmpWrMessageID == LOCKED)
ppi->next_state = WRS_CALIBRATION;
}
......@@ -46,7 +46,7 @@ state_updated:
if (ppi->next_state != ppi->state)
pp_timer_stop(ppi->timers[PP_TIMER_WRS_M_LOCK]);
ppi->next_delay = DSPOR(ppi)->wrStateTimeout;
ppi->next_delay = WR_DSPOR(ppi)->wrStateTimeout;
return e;
}
......@@ -15,8 +15,8 @@ int wr_present(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (ppi->is_new_state) {
DSPOR(ppi)->portState = PPS_UNCALIBRATED;
DSPOR(ppi)->wrPortState = WRS_PRESENT;
DSPOR(ppi)->wrMode = WR_SLAVE;
WR_DSPOR(ppi)->wrPortState = WRS_PRESENT;
WR_DSPOR(ppi)->wrMode = WR_SLAVE;
pp_timer_start(WR_WRS_PRESENT_TIMEOUT_MS,
ppi->timers[PP_TIMER_WRS_PRESENT]);
st_com_restart_annrec_timer(ppi);
......@@ -25,8 +25,8 @@ int wr_present(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (pp_timer_expired(ppi->timers[PP_TIMER_WRS_PRESENT])) {
ppi->next_state = PPS_LISTENING;
DSPOR(ppi)->wrMode = NON_WR;
DSPOR(ppi)->wrPortState = WRS_IDLE;
WR_DSPOR(ppi)->wrMode = NON_WR;
WR_DSPOR(ppi)->wrPortState = WRS_IDLE;
goto state_updated;
}
......@@ -36,9 +36,9 @@ int wr_present(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (ppi->msg_tmp_header.messageType == PPM_SIGNALING) {
msg_unpack_wrsig(ppi, pkt, &wrsig_msg,
&(DSPOR(ppi)->msgTmpWrMessageID));
&(WR_DSPOR(ppi)->msgTmpWrMessageID));
if (DSPOR(ppi)->msgTmpWrMessageID == LOCK)
if (WR_DSPOR(ppi)->msgTmpWrMessageID == LOCK)
ppi->next_state = WRS_S_LOCK;
}
......@@ -54,7 +54,7 @@ state_updated:
pp_timer_stop(ppi->timers[PP_TIMER_ANN_RECEIPT]);
}
ppi->next_delay = DSPOR(ppi)->wrStateTimeout;
ppi->next_delay = WR_DSPOR(ppi)->wrStateTimeout;
return e;
}
......@@ -12,24 +12,24 @@ int wr_resp_calib_req(struct pp_instance *ppi, unsigned char *pkt, int plen)
MsgSignaling wrsig_msg;
if (ppi->is_new_state) {
DSPOR(ppi)->wrPortState = WRS_RESP_CALIB_REQ;
WR_DSPOR(ppi)->wrPortState = WRS_RESP_CALIB_REQ;
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
if (DSPOR(ppi)->otherNodeCalSendPattern) {
if (WR_DSPOR(ppi)->otherNodeCalSendPattern) {
wr_calibration_pattern_enable(ppi, 0, 0, 0);
pp_timer_start(
DSPOR(ppi)->otherNodeCalPeriod / 1000,
WR_DSPOR(ppi)->otherNodeCalPeriod / 1000,
ppi->timers[PP_TIMER_WRS_RESP_CALIB_REQ]);
}
}
if ((DSPOR(ppi)->otherNodeCalSendPattern) &&
if ((WR_DSPOR(ppi)->otherNodeCalSendPattern) &&
(pp_timer_expired(ppi->timers[PP_TIMER_WRS_RESP_CALIB_REQ]))) {
if (DSPOR(ppi)->wrMode == WR_MASTER)
if (WR_DSPOR(ppi)->wrMode == WR_MASTER)
ppi->next_state = PPS_MASTER;
else
ppi->next_state = PPS_LISTENING;
DSPOR(ppi)->wrPortState = WRS_IDLE;
WR_DSPOR(ppi)->wrPortState = WRS_IDLE;
goto state_updated;
}
......@@ -39,12 +39,12 @@ int wr_resp_calib_req(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (ppi->msg_tmp_header.messageType == PPM_SIGNALING) {
msg_unpack_wrsig(ppi, pkt, &wrsig_msg,
&(DSPOR(ppi)->msgTmpWrMessageID));
&(WR_DSPOR(ppi)->msgTmpWrMessageID));
if (DSPOR(ppi)->msgTmpWrMessageID == CALIBRATED) {
if (DSPOR(ppi)->otherNodeCalSendPattern)
if (WR_DSPOR(ppi)->msgTmpWrMessageID == CALIBRATED) {
if (WR_DSPOR(ppi)->otherNodeCalSendPattern)
wr_calibration_pattern_disable(ppi);
if (DSPOR(ppi)->wrMode == WR_MASTER)
if (WR_DSPOR(ppi)->wrMode == WR_MASTER)
ppi->next_state = WRS_WR_LINK_ON;
else
ppi->next_state = WRS_CALIBRATION;
......@@ -56,7 +56,7 @@ state_updated:
if (ppi->next_state != ppi->state)
pp_timer_stop(ppi->timers[PP_TIMER_WRS_M_LOCK]);
ppi->next_delay = DSPOR(ppi)->wrStateTimeout;
ppi->next_delay = WR_DSPOR(ppi)->wrStateTimeout;
return e;
}
......@@ -11,7 +11,7 @@ int wr_s_lock(struct pp_instance *ppi, unsigned char *pkt, int plen)
int e = 0;
if (ppi->is_new_state) {
DSPOR(ppi)->portState = PPS_UNCALIBRATED;
DSPOR(ppi)->wrPortState = WRS_S_LOCK;
WR_DSPOR(ppi)->wrPortState = WRS_S_LOCK;
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
wr_locking_enable(ppi);
pp_timer_start(WR_S_LOCK_TIMEOUT_MS,
......@@ -20,8 +20,8 @@ int wr_s_lock(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (pp_timer_expired(ppi->timers[PP_TIMER_WRS_S_LOCK])) {
ppi->next_state = PPS_FAULTY;
DSPOR(ppi)->wrPortState = WRS_IDLE;
DSPOR(ppi)->wrMode = NON_WR;
WR_DSPOR(ppi)->wrPortState = WRS_IDLE;
WR_DSPOR(ppi)->wrMode = NON_WR;
goto state_updated;
}
......@@ -34,7 +34,7 @@ state_updated:
if (ppi->next_state != ppi->state)
pp_timer_stop(ppi->timers[PP_TIMER_WRS_S_LOCK]);
ppi->next_delay = DSPOR(ppi)->wrStateTimeout;
ppi->next_delay = WR_DSPOR(ppi)->wrStateTimeout;
return e;
}
......@@ -8,6 +8,46 @@
#include "wr-constants.h"
/*
* This structure is used as extension-specific data in the DSPort
* (see wrspec.v2-06-07-2011, page 17)
*/
struct wr_dsport {
Enumeration8 wrConfig;
Enumeration8 wrMode;
Boolean wrModeOn;
Enumeration8 wrPortState;
/* FIXME check doc: knownDeltaTx, knownDeltaRx, deltasKnown?) */
Boolean calibrated;
FixedDelta deltaTx;
FixedDelta deltaRx;
UInteger32 wrStateTimeout;
UInteger8 wrStateRetry;
UInteger32 calPeriod;
UInteger8 calRetry;
Enumeration8 parentWrConfig;
Boolean parentIsWRnode; /* FIXME Not in the doc */
/* FIXME check doc: (parentWrMode?) */
Enumeration16 msgTmpWrMessageID; /* FIXME Not in the doc */
Boolean parentWrModeOn;
Boolean parentCalibrated;
/* FIXME: are they in the doc? */
UInteger16 otherNodeCalSendPattern;
UInteger32 otherNodeCalPeriod;
UInteger8 otherNodeCalRetry;
FixedDelta otherNodeDeltaTx;
FixedDelta otherNodeDeltaRx;
Boolean doRestart;
Boolean linkUP;
};
/* This uppercase name matches "DSPOR(ppi)" used by standard protocol */
static inline struct wr_dsport *WR_DSPOR(struct pp_instance *ppi)
{
return ppi->portDS->ext_dsport;
}
/* Pack/Unkpack White rabbit message in the suffix of PTP announce message */
void msg_pack_announce_wr_tlv(struct pp_instance *ppi);
void msg_unpack_announce_wr_tlv(void *buf, MsgAnnounce *ann);
......
......@@ -69,12 +69,12 @@ void msg_pack_announce_wr_tlv(struct pp_instance *ppi)
| WR_TLV_WR_VERSION_NUMBER)));
//wrMessageId
*(UInteger16*)(buf + 74) = htons(ANN_SUFIX);
wr_flags = wr_flags | DSPOR(ppi)->wrConfig;
wr_flags = wr_flags | WR_DSPOR(ppi)->wrConfig;
if (DSPOR(ppi)->calibrated)
if (WR_DSPOR(ppi)->calibrated)
wr_flags = WR_IS_CALIBRATED | wr_flags;
if (DSPOR(ppi)->wrModeOn)
if (WR_DSPOR(ppi)->wrModeOn)
wr_flags = WR_IS_WR_MODE | wr_flags;
*(UInteger16*)(buf + 76) = htons(wr_flags);
}
......@@ -112,7 +112,7 @@ int msg_pack_wrsig(struct pp_instance *ppi, Enumeration16 wr_msg_id)
void *buf;
UInteger16 len = 0;
if ((DSPOR(ppi)->wrMode == NON_WR) || (wr_msg_id == ANN_SUFIX)) {
if ((WR_DSPOR(ppi)->wrMode == NON_WR) || (wr_msg_id == ANN_SUFIX)) {
PP_PRINTF("BUG: Trying to send invalid wr_msg mode=%x id=%x",
DSPOR(ppi)->wrMode, wr_msg_id);
return 0;
......@@ -144,24 +144,26 @@ int msg_pack_wrsig(struct pp_instance *ppi, Enumeration16 wr_msg_id)
switch (wr_msg_id) {
case CALIBRATE:
if(DSPOR(ppi)->calibrated) {
put_be16(buf+56, (DSPOR(ppi)->calRetry << 8 | 0x0000));
if(WR_DSPOR(ppi)->calibrated) {
put_be16(buf+56,
(WR_DSPOR(ppi)->calRetry << 8 | 0x0000));
}
else {
put_be16(buf+56, (DSPOR(ppi)->calRetry << 8 | 0x0001));
put_be16(buf+56,
(WR_DSPOR(ppi)->calRetry << 8 | 0x0001));
}
put_be32(buf+58, DSPOR(ppi)->calPeriod);
put_be32(buf+58, WR_DSPOR(ppi)->calPeriod);
len = 20;
break;
case CALIBRATED: /* new fsm */
/* delta TX */
put_be32(buf+56, DSPOR(ppi)->deltaTx.scaledPicoseconds.msb);
put_be32(buf+60, DSPOR(ppi)->deltaTx.scaledPicoseconds.lsb);
put_be32(buf+56, WR_DSPOR(ppi)->deltaTx.scaledPicoseconds.msb);
put_be32(buf+60, WR_DSPOR(ppi)->deltaTx.scaledPicoseconds.lsb);
/* delta RX */
put_be32(buf+64, DSPOR(ppi)->deltaRx.scaledPicoseconds.msb);
put_be32(buf+68, DSPOR(ppi)->deltaRx.scaledPicoseconds.lsb);
put_be32(buf+64, WR_DSPOR(ppi)->deltaRx.scaledPicoseconds.msb);
put_be32(buf+68, WR_DSPOR(ppi)->deltaRx.scaledPicoseconds.lsb);
len = 24;
break;
......@@ -235,22 +237,24 @@ void msg_unpack_wrsig(struct pp_instance *ppi, void *buf,
switch (wr_msg_id) {
case CALIBRATE:
DSPOR(ppi)->otherNodeCalSendPattern = 0x00FF & get_be16(buf+56);
DSPOR(ppi)->otherNodeCalRetry = 0x00FF & (get_be16(buf+56) >> 8);
DSPOR(ppi)->otherNodeCalPeriod = get_be32(buf+58);
WR_DSPOR(ppi)->otherNodeCalSendPattern =
0x00FF & get_be16(buf+56);
WR_DSPOR(ppi)->otherNodeCalRetry =
0x00FF & (get_be16(buf+56) >> 8);
WR_DSPOR(ppi)->otherNodeCalPeriod = get_be32(buf+58);
break;
case CALIBRATED:
/* delta TX */
DSPOR(ppi)->otherNodeDeltaTx.scaledPicoseconds.msb =
WR_DSPOR(ppi)->otherNodeDeltaTx.scaledPicoseconds.msb =
get_be32(buf+56);
DSPOR(ppi)->otherNodeDeltaTx.scaledPicoseconds.lsb =
WR_DSPOR(ppi)->otherNodeDeltaTx.scaledPicoseconds.lsb =
get_be32(buf+60);
/* delta RX */
DSPOR(ppi)->otherNodeDeltaRx.scaledPicoseconds.msb =
WR_DSPOR(ppi)->otherNodeDeltaRx.scaledPicoseconds.msb =
get_be32(buf+64);
DSPOR(ppi)->otherNodeDeltaRx.scaledPicoseconds.lsb =
WR_DSPOR(ppi)->otherNodeDeltaRx.scaledPicoseconds.lsb =
get_be32(buf+68);
break;
......
......@@ -190,11 +190,11 @@ int wr_servo_init(struct pp_instance *ppi)
s->cur_setpoint = 0;
s->missed_iters = 0;
s->delta_tx_m = ((((int32_t)DSPOR(ppi)->otherNodeDeltaTx.scaledPicoseconds.lsb) >> 16) & 0xffff) | (((int32_t)DSPOR(ppi)->otherNodeDeltaTx.scaledPicoseconds.msb) << 16);
s->delta_rx_m = ((((int32_t)DSPOR(ppi)->otherNodeDeltaRx.scaledPicoseconds.lsb) >> 16) & 0xffff) | (((int32_t)DSPOR(ppi)->otherNodeDeltaRx.scaledPicoseconds.msb) << 16);
s->delta_tx_m = ((((int32_t)WR_DSPOR(ppi)->otherNodeDeltaTx.scaledPicoseconds.lsb) >> 16) & 0xffff) | (((int32_t)WR_DSPOR(ppi)->otherNodeDeltaTx.scaledPicoseconds.msb) << 16);
s->delta_rx_m = ((((int32_t)WR_DSPOR(ppi)->otherNodeDeltaRx.scaledPicoseconds.lsb) >> 16) & 0xffff) | (((int32_t)WR_DSPOR(ppi)->otherNodeDeltaRx.scaledPicoseconds.msb) << 16);
s->delta_tx_s = ((((int32_t)DSPOR(ppi)->deltaTx.scaledPicoseconds.lsb) >> 16) & 0xffff) | (((int32_t)DSPOR(ppi)->deltaTx.scaledPicoseconds.msb) << 16);
s->delta_rx_s = ((((int32_t)DSPOR(ppi)->deltaRx.scaledPicoseconds.lsb) >> 16) & 0xffff) | (((int32_t)DSPOR(ppi)->deltaRx.scaledPicoseconds.msb) << 16);
s->delta_tx_s = ((((int32_t)WR_DSPOR(ppi)->deltaTx.scaledPicoseconds.lsb) >> 16) & 0xffff) | (((int32_t)WR_DSPOR(ppi)->deltaTx.scaledPicoseconds.msb) << 16);
s->delta_rx_s = ((((int32_t)WR_DSPOR(ppi)->deltaRx.scaledPicoseconds.lsb) >> 16) & 0xffff) | (((int32_t)WR_DSPOR(ppi)->deltaRx.scaledPicoseconds.msb) << 16);
cur_servo_state.delta_tx_m = (int64_t)s->delta_tx_m;
cur_servo_state.delta_rx_m = (int64_t)s->delta_rx_m;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment