Commit be3e6c27 authored by Alessandro Rubini's avatar Alessandro Rubini

timeout: reset them all at FSM new state

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 6305e770
...@@ -119,6 +119,8 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen) ...@@ -119,6 +119,8 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
if (ppi->state != ppi->next_state) { if (ppi->state != ppi->next_state) {
ppi->state = ppi->next_state; ppi->state = ppi->next_state;
ppi->is_new_state = 1; ppi->is_new_state = 1;
pp_timeout_setall(ppi);
ppi->flags &= ~PPI_FLAGS_WAITING;
pp_diag_fsm(ppi, ip->name, STATE_LEAVE, 0); pp_diag_fsm(ppi, ip->name, STATE_LEAVE, 0);
return 0; /* next_delay unused: go to new state now */ return 0; /* next_delay unused: go to new state now */
} }
......
...@@ -57,9 +57,6 @@ out: ...@@ -57,9 +57,6 @@ out:
else else
ppi->next_state = PPS_FAULTY; ppi->next_state = PPS_FAULTY;
if (ppi->next_state != ppi->state)
pp_timeout_clr(ppi, PP_TO_ANN_RECEIPT);
ppi->next_delay = WR_DSPOR(ppi)->wrStateTimeout; ppi->next_delay = WR_DSPOR(ppi)->wrStateTimeout;
return e; return e;
......
...@@ -15,10 +15,6 @@ ...@@ -15,10 +15,6 @@
int pp_faulty(struct pp_instance *ppi, unsigned char *pkt, int plen) int pp_faulty(struct pp_instance *ppi, unsigned char *pkt, int plen)
{ {
if (ppi->is_new_state) {
pp_timeout_set(ppi, PP_TO_FAULTY);
}
if (pp_timeout(ppi, PP_TO_FAULTY)) { if (pp_timeout(ppi, PP_TO_FAULTY)) {
ppi->next_state = PPS_INITIALIZING; ppi->next_state = PPS_INITIALIZING;
return 0; return 0;
......
...@@ -20,11 +20,6 @@ int pp_listening(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -20,11 +20,6 @@ int pp_listening(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (e) if (e)
goto out; goto out;
if (ppi->is_new_state) {
pp_timeout_restart_annrec(ppi);
pp_timeout_set(ppi, PP_TO_REQUEST);
}
/* when the clock is using peer-delay, listening must send it too */ /* when the clock is using peer-delay, listening must send it too */
if (ppi->glbs->delay_mech == PP_P2P_MECH if (ppi->glbs->delay_mech == PP_P2P_MECH
&& pp_timeout_z(ppi, PP_TO_REQUEST)) { && pp_timeout_z(ppi, PP_TO_REQUEST)) {
...@@ -102,10 +97,6 @@ out: ...@@ -102,10 +97,6 @@ out:
if (e != 0) if (e != 0)
ppi->next_state = PPS_FAULTY; ppi->next_state = PPS_FAULTY;
/* Leaving this state */
if (ppi->next_state != ppi->state)
pp_timeout_clr(ppi, PP_TO_ANN_RECEIPT);
ppi->next_delay = pp_ms_to_timeout(ppi, PP_TO_ANN_RECEIPT); ppi->next_delay = pp_ms_to_timeout(ppi, PP_TO_ANN_RECEIPT);
return 0; return 0;
......
...@@ -67,16 +67,6 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -67,16 +67,6 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen)
MsgHeader *hdr = &ppi->received_ptp_header; MsgHeader *hdr = &ppi->received_ptp_header;
MsgPDelayRespFollowUp respFllw; MsgPDelayRespFollowUp respFllw;
if (ppi->is_new_state) {
pp_timeout_set(ppi, PP_TO_SYNC_SEND);
pp_timeout_set(ppi, PP_TO_REQUEST);
pp_timeout_set(ppi, PP_TO_ANN_SEND);
/* Send an announce immediately, when becomes master */
if ((e = pp_master_issue_announce(ppi)) < 0)
goto out;
}
if (pp_timeout_z(ppi, PP_TO_SYNC_SEND)) { if (pp_timeout_z(ppi, PP_TO_SYNC_SEND)) {
/* Restart the timeout for next time */ /* Restart the timeout for next time */
pp_timeout_set(ppi, PP_TO_SYNC_SEND); pp_timeout_set(ppi, PP_TO_SYNC_SEND);
......
...@@ -15,11 +15,6 @@ int pp_passive(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -15,11 +15,6 @@ int pp_passive(struct pp_instance *ppi, unsigned char *pkt, int plen)
MsgHeader *hdr = &ppi->received_ptp_header; MsgHeader *hdr = &ppi->received_ptp_header;
MsgPDelayRespFollowUp respFllw; MsgPDelayRespFollowUp respFllw;
if (ppi->is_new_state) {
pp_timeout_restart_annrec(ppi);
pp_timeout_set(ppi, PP_TO_REQUEST);
}
/* when the clock is using peer-delay, listening must send it too */ /* when the clock is using peer-delay, listening must send it too */
if (ppi->glbs->delay_mech == PP_P2P_MECH if (ppi->glbs->delay_mech == PP_P2P_MECH
&& pp_timeout_z(ppi, PP_TO_REQUEST)) { && pp_timeout_z(ppi, PP_TO_REQUEST)) {
...@@ -96,10 +91,6 @@ no_incoming_msg: ...@@ -96,10 +91,6 @@ no_incoming_msg:
if (e != 0) if (e != 0)
ppi->next_state = PPS_FAULTY; ppi->next_state = PPS_FAULTY;
if (ppi->next_state != ppi->state) {
pp_timeout_clr(ppi, PP_TO_ANN_RECEIPT);
}
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS; ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
return 0; return 0;
......
...@@ -27,12 +27,6 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -27,12 +27,6 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
e = pp_hooks.new_slave(ppi, pkt, plen); e = pp_hooks.new_slave(ppi, pkt, plen);
if (e) if (e)
goto out; goto out;
ppi->flags &= ~PPI_FLAGS_WAITING;
pp_timeout_restart_annrec(ppi);
pp_timeout_set(ppi, PP_TO_REQUEST);
} }
if (plen == 0) if (plen == 0)
...@@ -167,10 +161,8 @@ out: ...@@ -167,10 +161,8 @@ out:
} }
if (ppi->next_state != ppi->state) { if (ppi->next_state != ppi->state) {
pp_timeout_clr(ppi, PP_TO_ANN_RECEIPT);
pp_timeout_clr(ppi, PP_TO_REQUEST);
pp_servo_init(ppi); pp_servo_init(ppi);
return e;
} }
d1 = d2 = pp_ms_to_timeout(ppi, PP_TO_ANN_RECEIPT); d1 = d2 = pp_ms_to_timeout(ppi, PP_TO_ANN_RECEIPT);
if (ppi->timeouts[PP_TO_REQUEST]) if (ppi->timeouts[PP_TO_REQUEST])
......
...@@ -90,6 +90,19 @@ void pp_timeout_set(struct pp_instance *ppi, int index) ...@@ -90,6 +90,19 @@ void pp_timeout_set(struct pp_instance *ppi, int index)
__pp_timeout_set(ppi, index, millisec); __pp_timeout_set(ppi, index, millisec);
} }
/*
* When we enter a new fsm state, we init all timeouts. Who cares if
* some of them are not used (and even if some have no default timeout)
*/
void pp_timeout_setall(struct pp_instance *ppi)
{
int i;
for (i = 0; i < __PP_TO_ARRAY_SIZE; i++)
pp_timeout_set(ppi, i);
/* but announce_send must be send soon */
__pp_timeout_set(ppi, PP_TO_ANN_SEND, 20);
}
void pp_timeout_clr(struct pp_instance *ppi, int index) void pp_timeout_clr(struct pp_instance *ppi, int index)
{ {
ppi->timeouts[index] = 0; ppi->timeouts[index] = 0;
......
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