Commit c90cfd41 authored by Alessandro Rubini's avatar Alessandro Rubini

proto-standard: add fsm-lib.c to factorize a timeout stanza

To help me knowning what is audited and what is not, I will rename
the "common functions" to fsm-lib. Let's now open this pp_lib_*
name space with some more timeout cleanup.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 3c0f2a03
...@@ -57,6 +57,8 @@ struct pp_vlanhdr { ...@@ -57,6 +57,8 @@ struct pp_vlanhdr {
uint16_t h_proto; uint16_t h_proto;
}; };
/* Helpers for the fsm (fsm-lib.c) */
extern int pp_lib_may_issue_request(struct pp_instance *ppi);
/* We use data sets a lot, so have these helpers */ /* We use data sets a lot, so have these helpers */
static inline struct pp_globals *GLBS(struct pp_instance *ppi) static inline struct pp_globals *GLBS(struct pp_instance *ppi)
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
D := proto-standard D := proto-standard
OBJ-y += $D/fsm-table.o \ OBJ-y += $D/fsm-table.o \
$D/fsm-lib.o \
$D/state-initializing.o \ $D/state-initializing.o \
$D/state-faulty.o \ $D/state-faulty.o \
$D/state-disabled.o \ $D/state-disabled.o \
......
/*
* Copyright (C) 2011 CERN (www.cern.ch)
* Author: Aurelio Colosimo
* Copyright (C) 2014 GSI (www.gsi.de)
* Author: Alessandro Rubin
*
* Released according to the GNU LGPL, version 2.1 or any later version.
*/
#include <ppsi/ppsi.h>
int pp_lib_may_issue_request(struct pp_instance *ppi)
{
int e;
if (!pp_timeout(ppi, PP_TO_REQUEST))
return 0;
pp_timeout_set(ppi, PP_TO_REQUEST);
e = msg_issue_request(ppi);
if (e)
return e;
ppi->t3 = ppi->last_snt_time;
return 0;
}
...@@ -21,15 +21,8 @@ int pp_listening(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -21,15 +21,8 @@ int pp_listening(struct pp_instance *ppi, unsigned char *pkt, int plen)
goto out; goto out;
/* 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)) { e = pp_lib_may_issue_request(ppi);
e = msg_issue_request(ppi);
ppi->t3 = ppi->last_snt_time;
/* Restart the timeout for next time */
pp_timeout_set(ppi, PP_TO_REQUEST);
}
if (plen == 0) if (plen == 0)
goto out; goto out;
......
...@@ -85,15 +85,8 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -85,15 +85,8 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen)
} }
/* when the clock is using peer-delay, the muster mast send it too */ /* when the clock is using peer-delay, the muster mast 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)) { e = pp_lib_may_issue_request(ppi);
e = msg_issue_request(ppi);
ppi->t3 = ppi->last_snt_time;
/* Restart the timeout for next time */
pp_timeout_set(ppi, PP_TO_REQUEST);
}
if (plen == 0) if (plen == 0)
goto out; goto out;
......
...@@ -16,15 +16,8 @@ int pp_passive(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -16,15 +16,8 @@ int pp_passive(struct pp_instance *ppi, unsigned char *pkt, int plen)
MsgPDelayRespFollowUp respFllw; MsgPDelayRespFollowUp respFllw;
/* 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)) { e = pp_lib_may_issue_request(ppi);
e = msg_issue_request(ppi);
ppi->t3 = ppi->last_snt_time;
/* Restart the timeout for next time */
pp_timeout_set(ppi, PP_TO_REQUEST);
}
if (plen == 0) if (plen == 0)
goto no_incoming_msg; goto no_incoming_msg;
......
...@@ -29,6 +29,8 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -29,6 +29,8 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
goto out; goto out;
} }
e = pp_lib_may_issue_request(ppi);
if (plen == 0) if (plen == 0)
goto out; goto out;
...@@ -139,15 +141,6 @@ out: ...@@ -139,15 +141,6 @@ out:
if (e == 0) if (e == 0)
e = st_com_execute_slave(ppi); e = st_com_execute_slave(ppi);
if (pp_timeout_z(ppi, PP_TO_REQUEST)) {
e = msg_issue_request(ppi);
ppi->t3 = ppi->last_snt_time;
/* Restart the timeout for next time */
pp_timeout_set(ppi, PP_TO_REQUEST);
}
switch(e) { switch(e) {
case PP_SEND_OK: /* 0 */ case PP_SEND_OK: /* 0 */
break; break;
......
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