Commit 25692a35 authored by baujc's avatar baujc

Code optimization

- Make externalPortConfiguration compliant with the PTP specifications
- Optimize code for externalPortConfiguration
- Optimize code for slaveOnly
- Replace "CONFIG_HAS_P2P && ppi->delayMechanism==P2P" by an inline
function
parent 9c5b584f
...@@ -252,7 +252,9 @@ config NR_FOREIGN_RECORDS ...@@ -252,7 +252,9 @@ config NR_FOREIGN_RECORDS
default 1 if ARCH_WRPC default 1 if ARCH_WRPC
default 5 default 5
help help
Size of foreignMasterDS data set (Clause 9.3.2.4.5) Size of foreignMasterDS data set (Clause 9.3.2.4.5).
If the code is optimized with externalPortConfiguration.enable forced to true,
the NR_FOREIGN_RECORDS should be set to 1
config SINGLE_FMASTER config SINGLE_FMASTER
boolean boolean
......
...@@ -120,6 +120,21 @@ static void enable_asymmetryCorrection(struct pp_instance *ppi, Boolean enable ) ...@@ -120,6 +120,21 @@ static void enable_asymmetryCorrection(struct pp_instance *ppi, Boolean enable )
ppi->asymmetryCorrectionPortDS.constantAsymmetry=picos_to_interval(ppi->cfg.constantAsymmetry_ps); ppi->asymmetryCorrectionPortDS.constantAsymmetry=picos_to_interval(ppi->cfg.constantAsymmetry_ps);
} }
static char *strCodeOpt="CODEOPT=("
#if CONFIG_HAS_CODEOPT_EPC_ENABLED
" EPC"
#endif
#if CONFIG_HAS_CODEOPT_SO_ENABLED
" SO"
#endif
#if CONFIG_HAS_CODEOPT_SINGLE_FMASTER
" SFM"
#endif
#if CONFIG_HAS_CODEOPT_SINGLE_PORT
" SP"
#endif
")";
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct pp_globals *ppg; struct pp_globals *ppg;
...@@ -132,9 +147,9 @@ int main(int argc, char **argv) ...@@ -132,9 +147,9 @@ int main(int argc, char **argv)
setbuf(stdout, NULL); setbuf(stdout, NULL);
pp_printf("PPSi. Commit %s, built on " __DATE__ "\n", pp_printf("PPSi. Commit %s, built on " __DATE__ ", %s\n",
PPSI_VERSION); PPSI_VERSION,
strCodeOpt);
/* check if there is another instance of PPSi already running */ /* check if there is another instance of PPSi already running */
ppsi_head = wrs_shm_get(wrs_shm_ptp, "", WRS_SHM_READ); ppsi_head = wrs_shm_get(wrs_shm_ptp, "", WRS_SHM_READ);
if (!ppsi_head) { if (!ppsi_head) {
......
...@@ -286,7 +286,9 @@ int pp_state_machine(struct pp_instance *ppi, void *buf, int len) ...@@ -286,7 +286,9 @@ int pp_state_machine(struct pp_instance *ppi, void *buf, int len)
if ( ppi->ext_hooks->get_tmo_lstate_detection!=NULL) if ( ppi->ext_hooks->get_tmo_lstate_detection!=NULL)
tmo=(*ppi->ext_hooks->get_tmo_lstate_detection)(ppi); tmo=(*ppi->ext_hooks->get_tmo_lstate_detection)(ppi);
else else
tmo= pp_timeout_get(ppi,PP_TO_ANN_RECEIPT); tmo= is_externalPortConfigurationEnabled(DSDEF(ppi)) ?
6000 /* JCB: Default value. Is it correct ? */
: pp_timeout_get(ppi,PP_TO_ANN_RECEIPT);
pp_timeout_set(ppi,PP_TO_PROT_STATE, tmo); pp_timeout_set(ppi,PP_TO_PROT_STATE, tmo);
} }
} }
......
...@@ -355,7 +355,7 @@ typedef struct {/*draft P1588_v_29: Clause 17.6.3 */ ...@@ -355,7 +355,7 @@ typedef struct {/*draft P1588_v_29: Clause 17.6.3 */
/** ************************************************************************/ /** ************************************************************************/
/* Enumeration States (table 8, page 73) */ /* Enumeration States (table 8, page 73) */
enum pp_std_states { typedef enum {
PPS_END_OF_TABLE = 0, PPS_END_OF_TABLE = 0,
PPS_INITIALIZING, PPS_INITIALIZING,
PPS_FAULTY, PPS_FAULTY,
...@@ -367,9 +367,9 @@ enum pp_std_states { ...@@ -367,9 +367,9 @@ enum pp_std_states {
PPS_UNCALIBRATED, PPS_UNCALIBRATED,
PPS_SLAVE, PPS_SLAVE,
PPS_LAST_STATE=PPS_SLAVE PPS_LAST_STATE=PPS_SLAVE
}; }pp_std_states;
enum pp_std_messages { typedef enum {
PPM_SYNC = 0x0, PPM_SYNC = 0x0,
PPM_DELAY_REQ, PPM_DELAY_REQ,
PPM_PDELAY_REQ, PPM_PDELAY_REQ,
...@@ -385,7 +385,7 @@ enum pp_std_messages { ...@@ -385,7 +385,7 @@ enum pp_std_messages {
PPM_NO_MESSAGE, PPM_NO_MESSAGE,
PPM_NOTHING_TO_DO = 0x100, /* for hooks.master_msg() */ PPM_NOTHING_TO_DO = 0x100, /* for hooks.master_msg() */
}; }pp_std_messages;
/* Enumeration Domain Number (table 2, page 41) */ /* Enumeration Domain Number (table 2, page 41) */
enum ENDomainNumber { enum ENDomainNumber {
......
...@@ -273,10 +273,8 @@ struct pp_instance { ...@@ -273,10 +273,8 @@ struct pp_instance {
unsigned long ptp_tx_count; unsigned long ptp_tx_count;
unsigned long ptp_rx_count; unsigned long ptp_rx_count;
#if CONFIG_HAS_P2P
Boolean received_dresp; /* Count the number of delay response messages received for a given delay request */ Boolean received_dresp; /* Count the number of delay response messages received for a given delay request */
Boolean received_dresp_fup; /* Count the number of delay response follow up messages received for a given delay request */ Boolean received_dresp_fup; /* Count the number of delay response follow up messages received for a given delay request */
#endif
Boolean ptp_msg_received; /* Use to detect reception of a ptp message after an ppsi instance initialization */ Boolean ptp_msg_received; /* Use to detect reception of a ptp message after an ppsi instance initialization */
Boolean ptp_support; /* True if allow pure PTP support */ Boolean ptp_support; /* True if allow pure PTP support */
Boolean ext_enabled; /* True if the extension is enabled */ Boolean ext_enabled; /* True if the extension is enabled */
......
...@@ -54,7 +54,7 @@ struct pp_vlanhdr { ...@@ -54,7 +54,7 @@ struct pp_vlanhdr {
/* Factorize some random information in this table */ /* Factorize some random information in this table */
struct pp_msgtype_info { struct pp_msgtype_info {
enum pp_std_messages msg_type; pp_std_messages msg_type;
uint16_t msglen; uint16_t msglen;
unsigned char chtype; unsigned char chtype;
unsigned char is_pdelay; unsigned char is_pdelay;
...@@ -161,6 +161,14 @@ static inline int is_externalPortConfigurationEnabled (defaultDS_t *def) { ...@@ -161,6 +161,14 @@ static inline int is_externalPortConfigurationEnabled (defaultDS_t *def) {
return CONFIG_HAS_CODEOPT_EPC_ENABLED || def->externalPortConfigurationEnabled; return CONFIG_HAS_CODEOPT_EPC_ENABLED || def->externalPortConfigurationEnabled;
} }
static inline int is_delayMechanismP2P(struct pp_instance *ppi) {
return CONFIG_HAS_P2P && ppi->delayMechanism == P2P;
}
static inline int is_delayMechanismE2E(struct pp_instance *ppi) {
return CONFIG_HAS_P2P==0 || ppi->delayMechanism == E2E;
}
static inline int is_slaveOnly(defaultDS_t *def) { static inline int is_slaveOnly(defaultDS_t *def) {
return CONFIG_HAS_CODEOPT_SINGLE_PORT && (CONFIG_HAS_CODEOPT_SO_ENABLED || def->slaveOnly); return CONFIG_HAS_CODEOPT_SINGLE_PORT && (CONFIG_HAS_CODEOPT_SO_ENABLED || def->slaveOnly);
} }
......
...@@ -106,7 +106,7 @@ int l1e_servo_got_sync(struct pp_instance *ppi) ...@@ -106,7 +106,7 @@ int l1e_servo_got_sync(struct pp_instance *ppi)
gs->t2=ppi->t2;apply_faulty_stamp(ppi,2); gs->t2=ppi->t2;apply_faulty_stamp(ppi,2);
if (CONFIG_HAS_P2P && ppi->delayMechanism == P2P && gs->got_sync) { if ( is_delayMechanismP2P(ppi) && gs->got_sync) {
gs->got_sync=0; gs->got_sync=0;
__l1e_servo_update(ppi); __l1e_servo_update(ppi);
}else { }else {
......
...@@ -128,8 +128,10 @@ int wr_execute_slave(struct pp_instance *ppi) ...@@ -128,8 +128,10 @@ int wr_execute_slave(struct pp_instance *ppi)
{ {
pp_diag(ppi, ext, 2, "hook: %s\n", __func__); pp_diag(ppi, ext, 2, "hook: %s\n", __func__);
if (pp_timeout(ppi, PP_TO_FAULT)) if ( !is_externalPortConfigurationEnabled(DSDEF(ppi)) ) {
wr_servo_reset(ppi); /* the caller handles ptp state machine */ if (pp_timeout(ppi, PP_TO_FAULT))
wr_servo_reset(ppi); /* the caller handles ptp state machine */
}
if ((ppi->state == PPS_SLAVE) && if ((ppi->state == PPS_SLAVE) &&
(WR_DSPOR(ppi)->wrConfig & WR_S_ONLY) && (WR_DSPOR(ppi)->wrConfig & WR_S_ONLY) &&
...@@ -151,18 +153,22 @@ static int wr_handle_announce(struct pp_instance *ppi) ...@@ -151,18 +153,22 @@ static int wr_handle_announce(struct pp_instance *ppi)
{ {
pp_diag(ppi, ext, 2, "hook: %s\n", __func__); pp_diag(ppi, ext, 2, "hook: %s\n", __func__);
switch (ppi->state) { /* Clause 17.6.5.3 : ExternalPortConfiguration enabled
case WRS_PRESENT: * - The Announce receipt timeout mechanism (see 9.2.6.12) shall not be active.
case WRS_S_LOCK : */
case WRS_LOCKED : if ( !is_externalPortConfigurationEnabled(DSDEF(ppi)) ) {
case WRS_CALIBRATION : switch (ppi->state) {
case WRS_CALIBRATED : case WRS_PRESENT:
case WRS_RESP_CALIB_REQ : case WRS_S_LOCK :
case WRS_WR_LINK_ON : case WRS_LOCKED :
/* reset announce timeout when in the WR slave states */ case WRS_CALIBRATION :
pp_timeout_reset(ppi, PP_TO_ANN_RECEIPT); case WRS_CALIBRATED :
case WRS_RESP_CALIB_REQ :
case WRS_WR_LINK_ON :
/* reset announce timeout when in the WR slave states */
pp_timeout_reset(ppi, PP_TO_ANN_RECEIPT);
}
} }
/* handshake is started in slave mode */ /* handshake is started in slave mode */
return 0; return 0;
} }
...@@ -171,7 +177,7 @@ static int wr_sync_followup(struct pp_instance *ppi) { ...@@ -171,7 +177,7 @@ static int wr_sync_followup(struct pp_instance *ppi) {
if ( ppi->ext_enabled ) { if ( ppi->ext_enabled ) {
wr_servo_got_sync(ppi); wr_servo_got_sync(ppi);
if (CONFIG_HAS_P2P && ppi->delayMechanism == P2P) if (is_delayMechanismP2P(ppi))
wr_servo_update(ppi); wr_servo_update(ppi);
} }
else { else {
......
...@@ -157,7 +157,7 @@ int wr_servo_got_delay(struct pp_instance *ppi) ...@@ -157,7 +157,7 @@ int wr_servo_got_delay(struct pp_instance *ppi)
s->t3 = ppi->t3; apply_faulty_stamp(ppi, 3); s->t3 = ppi->t3; apply_faulty_stamp(ppi, 3);
s->t4 = ppi->t4; apply_faulty_stamp(ppi, 4); s->t4 = ppi->t4; apply_faulty_stamp(ppi, 4);
if (CONFIG_HAS_P2P && ppi->delayMechanism == P2P) { if ( is_delayMechanismP2P(ppi) ) {
s->t5 = ppi->t5; apply_faulty_stamp(ppi, 5); s->t5 = ppi->t5; apply_faulty_stamp(ppi, 5);
s->t6 = ppi->t6; apply_faulty_stamp(ppi, 6); s->t6 = ppi->t6; apply_faulty_stamp(ppi, 6);
...@@ -349,7 +349,7 @@ int wr_servo_update(struct pp_instance *ppi) ...@@ -349,7 +349,7 @@ int wr_servo_update(struct pp_instance *ppi)
wrs_shm_write(ppsi_head, WRS_SHM_WRITE_BEGIN); wrs_shm_write(ppsi_head, WRS_SHM_WRITE_BEGIN);
prev_delayMM_ps = s->delayMM_ps; prev_delayMM_ps = s->delayMM_ps;
if (CONFIG_HAS_P2P && ppi->delayMechanism == P2P) { if ( is_delayMechanismP2P(ppi) ) {
if (!wr_p2p_offset(ppi, s, &offset)) if (!wr_p2p_offset(ppi, s, &offset))
goto out; goto out;
} else { } else {
......
This diff is collapsed.
...@@ -20,7 +20,9 @@ static int presp_call_servo(struct pp_instance *ppi) ...@@ -20,7 +20,9 @@ static int presp_call_servo(struct pp_instance *ppi)
if (is_incorrect(&ppi->t4)) if (is_incorrect(&ppi->t4))
return 0; /* not an error, just no data */ return 0; /* not an error, just no data */
pp_timeout_reset(ppi, PP_TO_FAULT); if ( !is_externalPortConfigurationEnabled(DSDEF(ppi)) )
pp_timeout_reset(ppi, PP_TO_FAULT);
if (is_ext_hook_available(ppi,handle_presp)) if (is_ext_hook_available(ppi,handle_presp))
ret = ppi->ext_hooks->handle_presp(ppi); ret = ppi->ext_hooks->handle_presp(ppi);
else { else {
......
...@@ -84,27 +84,29 @@ static int is_grand_master(struct pp_instance *ppi) { ...@@ -84,27 +84,29 @@ static int is_grand_master(struct pp_instance *ppi) {
return has_master && !has_slave; return has_master && !has_slave;
} }
/* This function should not be called when externalPortConfiguration is enabled */
int st_com_check_announce_receive_timeout(struct pp_instance *ppi) int st_com_check_announce_receive_timeout(struct pp_instance *ppi)
{ {
if (pp_timeout(ppi, PP_TO_ANN_RECEIPT)) { /* Clause 17.6.5.3 : ExternalPortConfiguration enabled
/* 9.2.6.11 b) reset timeout when an announce timeout happened */ * - The Announce receipt timeout mechanism (see 9.2.6.12) shall not be active.
pp_timeout_reset(ppi, PP_TO_ANN_RECEIPT); */
if ( !is_externalPortConfigurationEnabled(DSDEF(ppi))) {
if ( !is_slaveOnly(DSDEF(ppi)) ) { if (pp_timeout(ppi, PP_TO_ANN_RECEIPT)) {
if ( is_grand_master(ppi) ) { /* 9.2.6.11 b) reset timeout when an announce timeout happened */
bmc_m1(ppi); pp_timeout_reset(ppi, PP_TO_ANN_RECEIPT);
if ( !is_slaveOnly(DSDEF(ppi)) ) {
if ( is_grand_master(ppi) ) {
bmc_m1(ppi);
} else {
bmc_m3(ppi);
}
ppi->next_state = PPS_MASTER;
} else { } else {
bmc_m3(ppi); ppi->next_state = PPS_LISTENING;
}
if ( is_externalPortConfigurationEnabled(DSDEF(ppi)) ) {
/* Clause 17.6.5.3 : The announce receipt timeout mechanism shall not be active */
return 0;
} }
ppi->next_state = PPS_MASTER; bmc_flush_erbest(ppi); /* ErBest is removed from the foreign master list and ErBest need to be re-computed */
} else {
ppi->next_state = PPS_LISTENING;
} }
bmc_flush_erbest(ppi); /* ErBest is removed from the foreign master list and ErBest need to be re-computed */
} }
return 0; return 0;
} }
......
...@@ -402,10 +402,8 @@ static int msg_issue_delay_req(struct pp_instance *ppi) ...@@ -402,10 +402,8 @@ static int msg_issue_delay_req(struct pp_instance *ppi)
int msg_issue_request(struct pp_instance *ppi) int msg_issue_request(struct pp_instance *ppi)
{ {
#if CONFIG_HAS_P2P if ( is_delayMechanismP2P(ppi) )
if (ppi->delayMechanism == P2P)
return msg_issue_pdelay_req(ppi); return msg_issue_pdelay_req(ppi);
#endif
return msg_issue_delay_req(ppi); return msg_issue_delay_req(ppi);
} }
......
...@@ -97,9 +97,11 @@ int pp_init_globals(struct pp_globals *ppg, struct pp_runtime_opts *pp_rt_opts) ...@@ -97,9 +97,11 @@ int pp_init_globals(struct pp_globals *ppg, struct pp_runtime_opts *pp_rt_opts)
*/ */
def->externalPortConfigurationEnabled=pp_rt_opts->externalPortConfigurationEnabled; def->externalPortConfigurationEnabled=pp_rt_opts->externalPortConfigurationEnabled;
def->slaveOnly=rt_opts->slaveOnly; def->slaveOnly=rt_opts->slaveOnly;
if ( is_slaveOnly(def) && is_externalPortConfigurationEnabled(def) ) { if ( is_externalPortConfigurationEnabled(def) ) {
pp_printf("ppsi: Incompatible configuration: SlaveOnly and externalPortConfigurationEnabled\n"); if ( def->slaveOnly ) {
def->slaveOnly=FALSE; pp_printf("ppsi: Incompatible configuration: SlaveOnly and externalPortConfigurationEnabled\n");
def->slaveOnly=FALSE;
}
} }
......
...@@ -57,7 +57,8 @@ static void _pp_servo_init(struct pp_instance *ppi) ...@@ -57,7 +57,8 @@ static void _pp_servo_init(struct pp_instance *ppi)
servo->flags |= PP_SERVO_FLAG_VALID; servo->flags |= PP_SERVO_FLAG_VALID;
pp_timeout_reset(ppi, PP_TO_FAULT); if ( !is_externalPortConfigurationEnabled(DSDEF(ppi)) )
pp_timeout_reset(ppi, PP_TO_FAULT);
pp_diag(ppi, servo, 1, "Initialized: obs_drift %lli\n", pp_diag(ppi, servo, 1, "Initialized: obs_drift %lli\n",
servo->obs_drift); servo->obs_drift);
} }
...@@ -167,10 +168,9 @@ int pp_servo_calculate_delays(struct pp_instance *ppi) { ...@@ -167,10 +168,9 @@ int pp_servo_calculate_delays(struct pp_instance *ppi) {
if ( is_timestamps_incorrect(ppi,&errcount, 0x3 /* mask=t1&t2 */)) if ( is_timestamps_incorrect(ppi,&errcount, 0x3 /* mask=t1&t2 */))
return 0; /* Error. Invalid timestamps */ return 0; /* Error. Invalid timestamps */
if (CONFIG_HAS_P2P && ppi->delayMechanism == P2P) ret= is_delayMechanismP2P(ppi) ?
ret=calculate_p2p_delayMM(ppi); calculate_p2p_delayMM(ppi)
else : calculate_e2e_delayMM(ppi);
ret=calculate_e2e_delayMM(ppi);
if ( !ret) if ( !ret)
return 0; /* delays cannot be calculated */ return 0; /* delays cannot be calculated */
...@@ -250,7 +250,7 @@ void pp_servo_got_sync(struct pp_instance *ppi, int allowTimingOutput) ...@@ -250,7 +250,7 @@ void pp_servo_got_sync(struct pp_instance *ppi, int allowTimingOutput)
servo->t1=ppi->t1; servo->t1=ppi->t1;
servo->t2=ppi->t2; servo->t2=ppi->t2;
if (CONFIG_HAS_P2P && ppi->delayMechanism == P2P && servo->got_sync) { if ( is_delayMechanismP2P(ppi) && servo->got_sync) {
/* P2P mechanism */ /* P2P mechanism */
servo->got_sync=0; servo->got_sync=0;
__pp_servo_update(ppi); __pp_servo_update(ppi);
......
...@@ -51,14 +51,21 @@ int pp_listening(struct pp_instance *ppi, void *buf, int len) ...@@ -51,14 +51,21 @@ int pp_listening(struct pp_instance *ppi, void *buf, int len)
int e = 0; /* error var, to check errors in msg handling */ int e = 0; /* error var, to check errors in msg handling */
MsgHeader *hdr = &ppi->received_ptp_header; MsgHeader *hdr = &ppi->received_ptp_header;
pp_timeout_reset(ppi, PP_TO_FAULT); /* no fault as long as we listen */ if ( is_externalPortConfigurationEnabled(DSDEF(ppi)) ) {
if (is_ext_hook_available(ppi,listening)) if (is_ext_hook_available(ppi,listening))
e = ppi->ext_hooks->listening(ppi, buf, len); e=ppi->ext_hooks->listening(ppi, buf, len);
if (e) if ( e )
goto out; goto epc_out;
} else {
pp_timeout_reset(ppi, PP_TO_FAULT); /* no fault as long as we listen */
if (is_ext_hook_available(ppi,listening))
e = ppi->ext_hooks->listening(ppi, buf, len);
if ( e )
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 (CONFIG_HAS_P2P && ppi->delayMechanism == P2P) if ( is_delayMechanismP2P(ppi) )
e = pp_lib_may_issue_request(ppi); e = pp_lib_may_issue_request(ppi);
/* /*
* The management of messages is now table-driven * The management of messages is now table-driven
...@@ -72,22 +79,29 @@ int pp_listening(struct pp_instance *ppi, void *buf, int len) ...@@ -72,22 +79,29 @@ int pp_listening(struct pp_instance *ppi, void *buf, int len)
hdr->messageType); hdr->messageType);
} }
st_com_check_announce_receive_timeout(ppi); /* Clause 17.6.5.3 : ExternalPortConfiguration enabled
* - The Announce receipt timeout mechanism (see 9.2.6.12) shall not be active.
*/
if ( ! is_externalPortConfigurationEnabled(DSDEF(ppi))) {
st_com_check_announce_receive_timeout(ppi);
if (pp_timeout(ppi, PP_TO_FAULT)) if (pp_timeout(ppi, PP_TO_FAULT))
ppi->next_state = PPS_FAULTY; ppi->next_state = PPS_FAULTY;
out: out:;
if (e != 0) if (e != 0)
ppi->next_state = PPS_FAULTY; ppi->next_state = PPS_FAULTY;
if (CONFIG_HAS_P2P && ppi->delayMechanism ==P2P) { ppi->next_delay = is_delayMechanismP2P(ppi) ?
ppi->next_delay = pp_next_delay_2(ppi, pp_next_delay_2(ppi,PP_TO_ANN_RECEIPT, PP_TO_REQUEST) :
PP_TO_ANN_RECEIPT, PP_TO_REQUEST); pp_next_delay_1(ppi, PP_TO_ANN_RECEIPT);
} else { return e;
ppi->next_delay = pp_next_delay_1(ppi,
PP_TO_ANN_RECEIPT);
} }
epc_out:;
ppi->next_delay = is_delayMechanismP2P(ppi) ?
pp_next_delay_1(ppi, PP_TO_REQUEST) :
INT_MAX;
return e; return e;
} }
...@@ -69,13 +69,16 @@ int pp_master(struct pp_instance *ppi, void *buf, int len) ...@@ -69,13 +69,16 @@ int pp_master(struct pp_instance *ppi, void *buf, int len)
int pre = (ppi->state == PPS_PRE_MASTER); int pre = (ppi->state == PPS_PRE_MASTER);
int e = 0; /* error var, to check errors in msg handling */ int e = 0; /* error var, to check errors in msg handling */
/* no fault as long as we are master */ if ( !is_externalPortConfigurationEnabled(DSDEF(ppi))) {
pp_timeout_reset(ppi, PP_TO_FAULT); /* no fault as long as we are master */
pp_timeout_reset(ppi, PP_TO_FAULT);
}
/* upgrade from pre-master to master */ /* upgrade from pre-master to master */
if (pre && if (!is_externalPortConfigurationEnabled(DSDEF(ppi)) &&
pp_timeout(ppi, PP_TO_QUALIFICATION) && pre &&
!is_externalPortConfigurationEnabled(DSDEF(ppi))) { pp_timeout(ppi, PP_TO_QUALIFICATION)
) {
ppi->next_state = PPS_MASTER; ppi->next_state = PPS_MASTER;
/* start sending immediately and reenter */ /* start sending immediately and reenter */
pp_timeout_reset_N(ppi, PP_TO_SYNC_SEND,0); pp_timeout_reset_N(ppi, PP_TO_SYNC_SEND,0);
...@@ -94,7 +97,7 @@ int pp_master(struct pp_instance *ppi, void *buf, int len) ...@@ -94,7 +97,7 @@ int pp_master(struct pp_instance *ppi, void *buf, int len)
} }
/* when the clock is using peer-delay, the master must send it too */ /* when the clock is using peer-delay, the master must send it too */
if (CONFIG_HAS_P2P && ppi->delayMechanism == P2P) if ( is_delayMechanismP2P(ppi) )
pp_lib_may_issue_request(ppi); pp_lib_may_issue_request(ppi);
/* /*
...@@ -124,42 +127,49 @@ int pp_master(struct pp_instance *ppi, void *buf, int len) ...@@ -124,42 +127,49 @@ int pp_master(struct pp_instance *ppi, void *buf, int len)
msgtype); msgtype);
} }
if (pp_timeout(ppi, PP_TO_FAULT)) if ( !is_externalPortConfigurationEnabled(DSDEF(ppi))) {
ppi->next_state = PPS_FAULTY; if (pp_timeout(ppi, PP_TO_FAULT))
ppi->next_state = PPS_FAULTY;
out:
switch(e) {
case PP_SEND_OK: /* 0 */
/* Why should we switch to slave? Remove this code? */
if (is_slaveOnly(DSDEF(ppi)))
ppi->next_state = PPS_LISTENING;
break;
case PP_SEND_ERROR:
/* fall through: a lost frame is not the end of the world */
case PP_SEND_NO_STAMP:
/* nothing, just keep the ball rolling */
e = 0;
break;
} }
if (pre) { out:
if (CONFIG_HAS_P2P && ppi->delayMechanism == P2P) { if ( is_externalPortConfigurationEnabled(DSDEF(ppi))) {
ppi->next_delay = pp_next_delay_2(ppi, if ( e==PP_SEND_ERROR || e==PP_SEND_NO_STAMP )
PP_TO_QUALIFICATION, PP_TO_REQUEST); e=0;
if (pre) {
ppi->next_delay = is_delayMechanismP2P(ppi) ?
pp_next_delay_1(ppi,PP_TO_REQUEST) :
INT_MAX;
} else { } else {
ppi->next_delay = pp_next_delay_1(ppi, ppi->next_delay = is_delayMechanismP2P(ppi) ?
PP_TO_QUALIFICATION); pp_next_delay_3(ppi,PP_TO_ANN_SEND, PP_TO_SYNC_SEND, PP_TO_REQUEST) :
} pp_next_delay_2(ppi,PP_TO_ANN_SEND, PP_TO_SYNC_SEND);
}
} else { } else {
if (CONFIG_HAS_P2P && ppi->delayMechanism == P2P) { switch(e) {
ppi->next_delay = pp_next_delay_3(ppi, case PP_SEND_OK: /* 0 */
PP_TO_ANN_SEND, PP_TO_SYNC_SEND, PP_TO_REQUEST); /* Why should we switch to slave? Remove this code? */
if ( is_slaveOnly(DSDEF(ppi)) )
ppi->next_state = PPS_LISTENING;
break;
case PP_SEND_ERROR:
/* fall through: a lost frame is not the end of the world */
case PP_SEND_NO_STAMP:
/* nothing, just keep the ball rolling */
e = 0;
break;
}
if (pre) {
ppi->next_delay = is_delayMechanismP2P(ppi) ?
pp_next_delay_2(ppi,PP_TO_QUALIFICATION, PP_TO_REQUEST) :
pp_next_delay_1(ppi,PP_TO_QUALIFICATION);
} else { } else {
ppi->next_delay = pp_next_delay_2(ppi, ppi->next_delay = is_delayMechanismP2P(ppi) ?
PP_TO_ANN_SEND, PP_TO_SYNC_SEND); pp_next_delay_3(ppi,PP_TO_ANN_SEND, PP_TO_SYNC_SEND, PP_TO_REQUEST) :
} pp_next_delay_2(ppi,PP_TO_ANN_SEND, PP_TO_SYNC_SEND);
}
} }
return e; return e;
} }
...@@ -46,13 +46,18 @@ static int passive_handle_announce(struct pp_instance *ppi, void *buf, int len) ...@@ -46,13 +46,18 @@ static int passive_handle_announce(struct pp_instance *ppi, void *buf, int len)
bmc_add_frgn_master(ppi, &frgn_master); bmc_add_frgn_master(ppi, &frgn_master);
} }
if (erbest!=NULL && !bmc_pidcmp(&hdr->sourcePortIdentity, /* Clause 17.6.5.3 : ExternalPortConfiguration enabled
&erbest->sourcePortIdentity)) { * - The Announce receipt timeout mechanism (see 9.2.6.12) shall not be active.
/* */
* 9.2.6.11 d) reset timeout when an announce if (! is_externalPortConfigurationEnabled(DSDEF(ppi))) {
* is received from the clock putting it into passive (erbest) if (erbest!=NULL && !bmc_pidcmp(&hdr->sourcePortIdentity,
*/ &erbest->sourcePortIdentity)) {
pp_timeout_reset(ppi, PP_TO_ANN_RECEIPT); /*
* 9.2.6.11 d) reset timeout when an announce
* is received from the clock putting it into passive (erbest)
*/
pp_timeout_reset(ppi, PP_TO_ANN_RECEIPT);
}
} }
return 0; return 0;
...@@ -63,11 +68,13 @@ int pp_passive(struct pp_instance *ppi, void *buf, int len) ...@@ -63,11 +68,13 @@ int pp_passive(struct pp_instance *ppi, void *buf, int len)
int e = 0; /* error var, to check errors in msg handling */ int e = 0; /* error var, to check errors in msg handling */
MsgHeader *hdr = &ppi->received_ptp_header; MsgHeader *hdr = &ppi->received_ptp_header;
pp_timeout_reset(ppi, PP_TO_FAULT); /* no fault as long as we are if ( ! is_externalPortConfigurationEnabled(DSDEF(ppi)) ) {
* passive */ /* no fault as long as we are passive */
pp_timeout_reset(ppi, PP_TO_FAULT);
}
/* when the clock is using peer-delay, passive must send it too */ /* when the clock is using peer-delay, passive must send it too */
if (CONFIG_HAS_P2P && ppi->delayMechanism == P2P) if ( is_delayMechanismP2P(ppi) )
e = pp_lib_may_issue_request(ppi); e = pp_lib_may_issue_request(ppi);
/* /*
...@@ -82,21 +89,22 @@ int pp_passive(struct pp_instance *ppi, void *buf, int len) ...@@ -82,21 +89,22 @@ int pp_passive(struct pp_instance *ppi, void *buf, int len)
hdr->messageType); hdr->messageType);
} }
st_com_check_announce_receive_timeout(ppi); /* Clause 17.6.5.3 : ExternalPortConfiguration enabled
* - The Announce receipt timeout mechanism (see 9.2.6.12) shall not be active.
if (pp_timeout(ppi, PP_TO_FAULT)) */
ppi->next_state = PPS_FAULTY; if ( is_externalPortConfigurationEnabled(DSDEF(ppi))) {
ppi->next_delay = is_delayMechanismP2P(ppi) ?
if (e != 0) pp_next_delay_1(ppi,PP_TO_REQUEST) :
ppi->next_state = PPS_FAULTY; INT_MAX;
if (CONFIG_HAS_P2P && ppi->delayMechanism == P2P) {
ppi->next_delay = pp_next_delay_2(ppi,
PP_TO_ANN_RECEIPT, PP_TO_REQUEST);
} else { } else {
ppi->next_delay = pp_next_delay_1(ppi, st_com_check_announce_receive_timeout(ppi);
PP_TO_ANN_RECEIPT); ppi->next_delay = is_delayMechanismP2P(ppi) ?
pp_next_delay_2(ppi,PP_TO_ANN_RECEIPT, PP_TO_REQUEST) :
pp_next_delay_1(ppi,PP_TO_ANN_RECEIPT);
if (pp_timeout(ppi, PP_TO_FAULT) || e !=0 )
ppi->next_state = PPS_FAULTY;
} }
return e; return e;
} }
...@@ -46,7 +46,7 @@ static int slave_handle_sync(struct pp_instance *ppi, void *buf, ...@@ -46,7 +46,7 @@ static int slave_handle_sync(struct pp_instance *ppi, void *buf,
return 0; return 0;
} }
if ( ppi->delayMechanism==E2E && ppi->t1.scaled_nsecs==0 && ppi->t1.secs==0 ) { if ( is_delayMechanismE2E(ppi) && ppi->t1.scaled_nsecs==0 && ppi->t1.secs==0 ) {
/* First time we receive the SYNC message in uncalib/slave state /* First time we receive the SYNC message in uncalib/slave state
* We set the REQUEST time-out to the minDelayReqInterval/2 value (500ms) * We set the REQUEST time-out to the minDelayReqInterval/2 value (500ms)
* in order to provide quickly a DelayReq message * in order to provide quickly a DelayReq message
...@@ -159,7 +159,9 @@ static int slave_handle_response(struct pp_instance *ppi, void *buf, ...@@ -159,7 +159,9 @@ static int slave_handle_response(struct pp_instance *ppi, void *buf,
pp_time_add(&ppi->t4, &hdr->cField); pp_time_add(&ppi->t4, &hdr->cField);
/* WARNING: should be "sub" (see README-cfield::BUG) */ /* WARNING: should be "sub" (see README-cfield::BUG) */
pp_timeout_reset(ppi, PP_TO_FAULT); if ( !is_externalPortConfigurationEnabled(DSDEF(ppi)) )
pp_timeout_reset(ppi, PP_TO_FAULT);
if (is_ext_hook_available(ppi,handle_resp)) { if (is_ext_hook_available(ppi,handle_resp)) {
ret=ppi->ext_hooks->handle_resp(ppi); ret=ppi->ext_hooks->handle_resp(ppi);
} }
...@@ -192,6 +194,10 @@ static int slave_handle_announce(struct pp_instance *ppi, void *buf, int len) ...@@ -192,6 +194,10 @@ static int slave_handle_announce(struct pp_instance *ppi, void *buf, int len)
*/ */
bmc_store_frgn_master(ppi, &frgn_master, buf, len); bmc_store_frgn_master(ppi, &frgn_master, buf, len);
/* Clause 17.6.5.3 : ExternalPortConfiguration enabled
* - The Announce receipt timeout mechanism (see 9.2.6.12) shall not be active.
* - The specifications of 9.5.3 shall be replaced by the specifications of 17.6.5.5
*/
if (!is_externalPortConfigurationEnabled(DSDEF(ppi)) ) { if (!is_externalPortConfigurationEnabled(DSDEF(ppi)) ) {
if ( !msg_from_current_master(ppi) ) { if ( !msg_from_current_master(ppi) ) {
pp_error("%s: Announce message is not from current parent\n", pp_error("%s: Announce message is not from current parent\n",
...@@ -207,13 +213,13 @@ static int slave_handle_announce(struct pp_instance *ppi, void *buf, int len) ...@@ -207,13 +213,13 @@ static int slave_handle_announce(struct pp_instance *ppi, void *buf, int len)
return 0; return 0;
} }
/* 9.2.6.11 a) reset timeout */
pp_timeout_reset(ppi, PP_TO_ANN_RECEIPT);
} }
/* Add foreign master: Figure 36 & 54 */ /* Add foreign master: Figure 36 & 54 */
bmc_add_frgn_master(ppi, &frgn_master); bmc_add_frgn_master(ppi, &frgn_master);
/* 9.2.6.11 a) reset timeout */
pp_timeout_reset(ppi, PP_TO_ANN_RECEIPT);
/* 9.5.3 Figure 29 update data set if announce from current master */ /* 9.5.3 Figure 29 update data set if announce from current master */
bmc_s1(ppi, &frgn_master); bmc_s1(ppi, &frgn_master);
...@@ -254,9 +260,11 @@ int pp_slave(struct pp_instance *ppi, void *buf, int len) ...@@ -254,9 +260,11 @@ int pp_slave(struct pp_instance *ppi, void *buf, int len)
ppi->next_state = PPS_SLAVE; ppi->next_state = PPS_SLAVE;
} }
} else { } else {
/* TODO add implementation specific SYNCHRONIZATION event */ if ( !is_externalPortConfigurationEnabled(DSDEF(ppi)) ) {
/* TODO add implementation specific SYNCHRONIZATION event */
if (pp_timeout(ppi, PP_TO_FAULT)) if (pp_timeout(ppi, PP_TO_FAULT))
ppi->next_state = PPS_UNCALIBRATED; ppi->next_state = PPS_UNCALIBRATED;
}
} }
/* Force to stay on desired state if externalPortConfiguration option is enabled */ /* Force to stay on desired state if externalPortConfiguration option is enabled */
if (is_externalPortConfigurationEnabled(DSDEF(ppi)) ) if (is_externalPortConfigurationEnabled(DSDEF(ppi)) )
...@@ -295,15 +303,20 @@ int pp_slave(struct pp_instance *ppi, void *buf, int len) ...@@ -295,15 +303,20 @@ int pp_slave(struct pp_instance *ppi, void *buf, int len)
*/ */
ret = slave_execute(ppi); ret = slave_execute(ppi);
st_com_check_announce_receive_timeout(ppi); /* Clause 17.6.5.3 : ExternalPortConfiguration enabled
* - The Announce receipt timeout mechanism (see 9.2.6.12) shall not be active.
*/
if ( !is_externalPortConfigurationEnabled(DSDEF(ppi)))
st_com_check_announce_receive_timeout(ppi);
out: out:
if ( ret==PP_SEND_NO_STAMP ) { if ( ret==PP_SEND_NO_STAMP ) {
ret = PP_SEND_OK;/* nothing, just keep the ball rolling */ ret = PP_SEND_OK;/* nothing, just keep the ball rolling */
} }
ppi->next_delay = pp_next_delay_2(ppi, ppi->next_delay = is_externalPortConfigurationEnabled(DSDEF(ppi)) ?
PP_TO_ANN_RECEIPT, PP_TO_REQUEST); pp_next_delay_1(ppi,PP_TO_REQUEST) :
pp_next_delay_2(ppi,PP_TO_ANN_RECEIPT, PP_TO_REQUEST);
return ret; return ret;
} }
...@@ -123,7 +123,7 @@ void pp_timeout_init(struct pp_instance *ppi) ...@@ -123,7 +123,7 @@ void pp_timeout_init(struct pp_instance *ppi)
{ {
portDS_t *port = ppi->portDS; portDS_t *port = ppi->portDS;
timeOutInstCnt_t *tmoCnt=ppi->tmo_cfg; timeOutInstCnt_t *tmoCnt=ppi->tmo_cfg;
Boolean p2p=CONFIG_HAS_P2P && ppi->delayMechanism == P2P; Boolean p2p=is_delayMechanismP2P(ppi);
Integer8 logDelayRequest=p2p ? Integer8 logDelayRequest=p2p ?
port->logMinPdelayReqInterval : port->logMinDelayReqInterval; port->logMinPdelayReqInterval : port->logMinDelayReqInterval;
...@@ -135,12 +135,6 @@ void pp_timeout_init(struct pp_instance *ppi) ...@@ -135,12 +135,6 @@ void pp_timeout_init(struct pp_instance *ppi)
tmoCnt[PP_TO_ANN_SEND].which_rand=TO_RAND_70_130; tmoCnt[PP_TO_ANN_SEND].which_rand=TO_RAND_70_130;
tmoCnt[PP_TO_REQUEST].initValueMs= pp_timeout_log_to_ms(logDelayRequest); tmoCnt[PP_TO_REQUEST].initValueMs= pp_timeout_log_to_ms(logDelayRequest);
/* fault timeout is 4 avg request intervals, not randomized */
tmoCnt[PP_TO_FAULT].initValueMs = pp_timeout_log_to_ms(logDelayRequest);
if ( tmoCnt[PP_TO_FAULT].initValueMs < (TIMEOUT_MAX_VALUE_MS>>2))
tmoCnt[PP_TO_FAULT].initValueMs<<=2; /* We can multiply by 4. No risk of overload */
tmoCnt[PP_TO_SYNC_SEND].initValueMs = pp_timeout_log_to_ms(port->logSyncInterval); tmoCnt[PP_TO_SYNC_SEND].initValueMs = pp_timeout_log_to_ms(port->logSyncInterval);
// Initialize BMCA timer (Independent Timer) // Initialize BMCA timer (Independent Timer)
...@@ -151,11 +145,23 @@ void pp_timeout_init(struct pp_instance *ppi) ...@@ -151,11 +145,23 @@ void pp_timeout_init(struct pp_instance *ppi)
if (gtmoCnt->initValueMs==TIMEOUT_DISABLE_VALUE || ms<gtmoCnt->initValueMs) if (gtmoCnt->initValueMs==TIMEOUT_DISABLE_VALUE || ms<gtmoCnt->initValueMs)
gtmoCnt->initValueMs=ms; gtmoCnt->initValueMs=ms;
} }
tmoCnt[PP_TO_ANN_RECEIPT].initValueMs = 1000 * ( /* Clause 17.6.5.3 : ExternalPortConfiguration enabled
port->announceReceiptTimeout << port->logAnnounceInterval); * - The Announce receipt timeout mechanism (see 9.2.6.12) shall not be active.
*/
if ( is_externalPortConfigurationEnabled(DSDEF(ppi)) ) {
tmoCnt[PP_TO_ANN_RECEIPT].initValueMs =
tmoCnt[PP_TO_FAULT].initValueMs=
tmoCnt[PP_TO_QUALIFICATION].initValueMs =TIMEOUT_DISABLE_VALUE;
} else {
tmoCnt[PP_TO_ANN_RECEIPT].initValueMs=1000 * (port->announceReceiptTimeout << port->logAnnounceInterval);
/* fault timeout is 4 avg request intervals, not randomized */
tmoCnt[PP_TO_FAULT].initValueMs = pp_timeout_log_to_ms(logDelayRequest);
if ( tmoCnt[PP_TO_FAULT].initValueMs < (TIMEOUT_MAX_VALUE_MS>>2))
tmoCnt[PP_TO_FAULT].initValueMs<<=2; /* We can multiply by 4. No risk of overload */
tmoCnt[PP_TO_QUALIFICATION].initValueMs =
(1000 << port->logAnnounceInterval)*(DSCUR(ppi)->stepsRemoved + 1);
}
tmoCnt[PP_TO_ANN_SEND].initValueMs = pp_timeout_log_to_ms(port->logAnnounceInterval); tmoCnt[PP_TO_ANN_SEND].initValueMs = pp_timeout_log_to_ms(port->logAnnounceInterval);
tmoCnt[PP_TO_QUALIFICATION].initValueMs =
(1000 << port->logAnnounceInterval)*(DSCUR(ppi)->stepsRemoved + 1);
} }
int pp_timeout_get(struct pp_instance *ppi, int index) { int pp_timeout_get(struct pp_instance *ppi, int index) {
......
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