Commit c8545723 authored by baujc's avatar baujc

In WR states with retry, improve precision of the time-out

Instead of restarting a timer on each retry, the timer is initialized
only once when we enter in the state. It helps to respect the time spent
in a given state before to skip it due to the time-out.
parent d55f3cc0
......@@ -17,28 +17,30 @@ int wr_calibrated(struct pp_instance *ppi, void *buf, int len)
{
struct wr_dsport *wrp = WR_DSPOR(ppi);
MsgSignaling wrsig_msg;
int e = 0, enable = 0;
int enable = 0;
if (ppi->is_new_state) {
wrp->wrStateRetry = WR_STATE_RETRY;
__pp_timeout_set(ppi, PP_TO_EXT_0, WR_CALIBRATED_TIMEOUT_MS*(WR_STATE_RETRY+1));
enable = 1;
} else if (pp_timeout(ppi, PP_TO_EXT_0)) {
} else {
int rms=pp_next_delay_1(ppi, PP_TO_EXT_0);
if ( rms==0 || rms<(wrp->wrStateRetry*WR_CALIBRATED_TIMEOUT_MS)) {
/*
* FIXME: We should implement a retry by re-sending
* the "calibrated" message, moving it here from the
* previous state (sub-state 8 of "state-wr-calibration"
*/
if (wr_handshake_retry(ppi))
enable = 1;
else
return 0; /* non-wr already */
if (wr_handshake_retry(ppi))
enable = 1;
else
return 0; /* non-wr already */
}
}
if (enable)
{
__pp_timeout_set(ppi, PP_TO_EXT_0, WR_CALIBRATED_TIMEOUT_MS);
e = msg_issue_wrsig(ppi, CALIBRATED);
}
if (enable){
msg_issue_wrsig(ppi, CALIBRATED);
}
if (ppi->received_ptp_header.messageType == PPM_SIGNALING) {
msg_unpack_wrsig(ppi, buf, &wrsig_msg,
......@@ -52,6 +54,6 @@ int wr_calibrated(struct pp_instance *ppi, void *buf, int len)
ppi->next_state = WRS_WR_LINK_ON;
}
ppi->next_delay = wrp->wrStateTimeout;
ppi->next_delay = pp_next_delay_1(ppi,PP_TO_EXT_0)-wrp->wrStateRetry*WR_CALIBRATED_TIMEOUT_MS;
return 0;
}
......@@ -21,16 +21,19 @@ int wr_calibration(struct pp_instance *ppi, void *buf, int len)
if (ppi->is_new_state) {
wrp->wrStateRetry = WR_STATE_RETRY;
__pp_timeout_set(ppi, PP_TO_EXT_0, wrp->calPeriod*(WR_STATE_RETRY+1));
sendmsg = 1;
} else if (pp_timeout(ppi, PP_TO_EXT_0)) {
if (wr_handshake_retry(ppi))
sendmsg = 1;
else
return 0; /* non-wr already */
} else {
int rms=pp_next_delay_1(ppi, PP_TO_EXT_0);
if ( rms==0 || rms<(wrp->wrStateRetry*wrp->calPeriod)) {
if (wr_handshake_retry(ppi))
sendmsg = 1;
else
return 0; /* non-wr already */
}
}
if (sendmsg) {
__pp_timeout_set(ppi, PP_TO_EXT_0, wrp->calPeriod);
msg_issue_wrsig(ppi, CALIBRATE);
wrp->wrPortState = WR_PORT_CALIBRATION_0;
if (wrp->calibrated)
......@@ -135,7 +138,7 @@ int wr_calibration(struct pp_instance *ppi, void *buf, int len)
break;
}
ppi->next_delay = wrp->wrStateTimeout;
ppi->next_delay = pp_next_delay_1(ppi,PP_TO_EXT_0)-wrp->wrStateRetry*wrp->calPeriod;
return 0; /* ignore error */
}
......@@ -15,23 +15,26 @@
*/
int wr_locked(struct pp_instance *ppi, void *buf, int len)
{
int e = 0, sendmsg = 0;
int e=0, sendmsg = 0;
MsgSignaling wrsig_msg;
struct wr_dsport *wrp = WR_DSPOR(ppi);
if (ppi->is_new_state) {
wrp->wrStateRetry = WR_STATE_RETRY;
__pp_timeout_set(ppi, PP_TO_EXT_0, WR_LOCKED_TIMEOUT_MS*(WR_STATE_RETRY+1));
sendmsg = 1;
} else if (pp_timeout(ppi, PP_TO_EXT_0)) {
if (wr_handshake_retry(ppi))
sendmsg = 1;
else
return 0; /* non-wr already */
} else {
int rms=pp_next_delay_1(ppi, PP_TO_EXT_0);
if ( rms==0 || rms<(wrp->wrStateRetry*WR_LOCKED_TIMEOUT_MS)) {
if (wr_handshake_retry(ppi))
sendmsg = 1;
else
return 0; /* non-wr already */
}
}
if (sendmsg) {
__pp_timeout_set(ppi, PP_TO_EXT_0, WR_LOCKED_TIMEOUT_MS);
e = msg_issue_wrsig(ppi, LOCKED);
e=msg_issue_wrsig(ppi, LOCKED);
}
if (ppi->received_ptp_header.messageType == PPM_SIGNALING) {
......@@ -43,7 +46,7 @@ int wr_locked(struct pp_instance *ppi, void *buf, int len)
ppi->next_state = WRS_RESP_CALIB_REQ;
}
ppi->next_delay = wrp->wrStateTimeout;
ppi->next_delay = pp_next_delay_1(ppi,PP_TO_EXT_0)-wrp->wrStateRetry*WR_LOCKED_TIMEOUT_MS;
return e;
}
......@@ -21,17 +21,20 @@ int wr_m_lock(struct pp_instance *ppi, void *buf, int len)
if (ppi->is_new_state) {
wrp->wrStateRetry = WR_STATE_RETRY;
__pp_timeout_set(ppi, PP_TO_EXT_0, WR_M_LOCK_TIMEOUT_MS*(WR_STATE_RETRY+1));
sendmsg = 1;
} else if (pp_timeout(ppi, PP_TO_EXT_0)) {
if (wr_handshake_retry(ppi))
sendmsg = 1;
else
return 0; /* non-wr already */
} else {
int rms=pp_next_delay_1(ppi, PP_TO_EXT_0);
if ( rms==0 || rms<(wrp->wrStateRetry*WR_M_LOCK_TIMEOUT_MS)) {
if (wr_handshake_retry(ppi))
sendmsg = 1;
else
return 0; /* non-wr already */
}
}
if (sendmsg) {
e = msg_issue_wrsig(ppi, LOCK);
__pp_timeout_set(ppi, PP_TO_EXT_0, WR_M_LOCK_TIMEOUT_MS);
}
if (ppi->received_ptp_header.messageType == PPM_SIGNALING) {
......@@ -43,7 +46,7 @@ int wr_m_lock(struct pp_instance *ppi, void *buf, int len)
}
ppi->next_delay = wrp->wrStateTimeout;
ppi->next_delay = pp_next_delay_1(ppi,PP_TO_EXT_0)-wrp->wrStateRetry*WR_M_LOCK_TIMEOUT_MS;
return e;
}
......@@ -24,16 +24,19 @@ int wr_present(struct pp_instance *ppi, void *buf, int len)
if (ppi->is_new_state) {
wrp->wrStateRetry = WR_STATE_RETRY;
__pp_timeout_set(ppi, PP_TO_EXT_0, WR_PRESENT_TIMEOUT_MS*(WR_STATE_RETRY+1));
sendmsg = 1;
} else if (pp_timeout(ppi, PP_TO_EXT_0)) {
if (wr_handshake_retry(ppi))
sendmsg = 1;
else
return 0; /* non-wr already */
} else {
int rms=pp_next_delay_1(ppi, PP_TO_EXT_0);
if ( rms==0 || rms<(wrp->wrStateRetry*WR_PRESENT_TIMEOUT_MS)) {
if (wr_handshake_retry(ppi))
sendmsg = 1;
else
return 0; /* non-wr already */
}
}
if (sendmsg) {
__pp_timeout_set(ppi, PP_TO_EXT_0, WR_PRESENT_TIMEOUT_MS);
e = msg_issue_wrsig(ppi, SLAVE_PRESENT);
}
......@@ -51,7 +54,7 @@ int wr_present(struct pp_instance *ppi, void *buf, int len)
/* nothing, just stay here again */
}
ppi->next_delay = WR_DSPOR(ppi)->wrStateTimeout;
ppi->next_delay = pp_next_delay_1(ppi,PP_TO_EXT_0)-wrp->wrStateRetry*WR_PRESENT_TIMEOUT_MS;
return e;
}
......@@ -18,21 +18,23 @@ int wr_resp_calib_req(struct pp_instance *ppi, void *buf, int len)
if (ppi->is_new_state) {
wrp->wrStateRetry = WR_STATE_RETRY;
__pp_timeout_set(ppi, PP_TO_EXT_0,WR_RESP_CALIB_REQ_TIMEOUT_MS*(WR_STATE_RETRY+1));
enable = 1;
} else if (pp_timeout(ppi, PP_TO_EXT_0)) {
if (send_pattern)
wrp->ops->calib_pattern_disable(ppi);
if (wr_handshake_retry(ppi))
enable = 1;
else
return 0; /* non-wr already */
} else {
int rms=pp_next_delay_1(ppi, PP_TO_EXT_0);
if ( rms==0 || rms<(wrp->wrStateRetry*WR_RESP_CALIB_REQ_TIMEOUT_MS)) {
if (send_pattern)
wrp->ops->calib_pattern_disable(ppi);
if (wr_handshake_retry(ppi))
enable = 1;
else
return 0; /* non-wr already */
}
}
if (enable) { /* first or retry */
if (send_pattern)
wrp->ops->calib_pattern_enable(ppi, 0, 0, 0);
__pp_timeout_set(ppi, PP_TO_EXT_0,
WR_RESP_CALIB_REQ_TIMEOUT_MS);
}
if (ppi->received_ptp_header.messageType == PPM_SIGNALING) {
......@@ -50,6 +52,6 @@ int wr_resp_calib_req(struct pp_instance *ppi, void *buf, int len)
}
}
ppi->next_delay = wrp->wrStateTimeout;
ppi->next_delay = pp_next_delay_1(ppi,PP_TO_EXT_0)-wrp->wrStateRetry*WR_RESP_CALIB_REQ_TIMEOUT_MS;
return e;
}
......@@ -17,21 +17,24 @@ int wr_s_lock(struct pp_instance *ppi, void *buf, int len)
if (ppi->is_new_state) {
wrp->wrStateRetry = WR_STATE_RETRY;
__pp_timeout_set(ppi, PP_TO_EXT_0, WR_S_LOCK_TIMEOUT_MS*(WR_STATE_RETRY+1));
enable = 1;
} else if (pp_timeout(ppi, PP_TO_EXT_0)) {
wrp->ops->locking_disable(ppi);
if (wr_handshake_retry(ppi))
enable = 1;
else
return 0; /* non-wr already */
} else {
int rms=pp_next_delay_1(ppi, PP_TO_EXT_0);
if ( rms==0 || rms<(wrp->wrStateRetry*WR_S_LOCK_TIMEOUT_MS)) {
wrp->ops->locking_disable(ppi);
if (wr_handshake_retry(ppi))
enable = 1;
else
return 0; /* non-wr already */
}
}
if (enable) {
wrp->ops->locking_enable(ppi);
__pp_timeout_set(ppi, PP_TO_EXT_0, WR_S_LOCK_TIMEOUT_MS);
}
ppi->next_delay = wrp->wrStateTimeout;
ppi->next_delay = pp_next_delay_1(ppi,PP_TO_EXT_0)-wrp->wrStateRetry*WR_S_LOCK_TIMEOUT_MS;
poll_ret = wrp->ops->locking_poll(ppi, 0);
if (poll_ret == WR_SPLL_READY) {
......
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