Commit f7205dab authored by baujc's avatar baujc

Review of WR protocol implementation (2)

- Has Hal is no longer used for ingress/egress latencies, we must then
take them from the configuration file
- Definition used by the common servo (WR & HA)
- Implementation of the IDLE state
See previous commit 'Review of WR protocol implementation'
parent 91a1564c
......@@ -29,13 +29,13 @@ static int wrsipc_cmd(int cmd, int value)
{
if(cmd == PTPDEXP_COMMAND_WR_TRACKING) {
if ( CONFIG_HAS_EXT_WR ) {
wr_servo_enable_tracking(value);
wrh_servo_enable_tracking(value);
return 0;
}
}
if(cmd == PTPDEXP_COMMAND_L1SYNC_TRACKING) {
if ( CONFIG_HAS_EXT_L1SYNC ) {
l1e_servo_enable_tracking(value);
wrh_servo_enable_tracking(value);
return 0;
}
}
......
......@@ -320,7 +320,7 @@ int main(int argc, char **argv)
}
/* Set WR extension hooks */
ppi->ext_hooks=&wr_ext_hooks;
ppi->cfg.egressLatency_ps=ppi->cfg.ingressLatency_ps=0; /* Forced to 0: Already taken into account in WR calculation */
enable_asymmetryCorrection(ppi,ppi->cfg.asymmetryCorrectionEnable);
} else {
fprintf(stderr, "ppsi: Profile WR not supported");
exit(1);
......
......@@ -71,5 +71,69 @@ static inline struct wrh_operations *WRH_OPER(void)
}
/****************************************************************************************/
/* wrh_servo interface */
/* Servo state */
typedef enum {
WRH_UNINITIALIZED = 0,
WRH_SYNC_TAI,
WRH_SYNC_NSEC,
WRH_SYNC_PHASE,
WRH_TRACK_PHASE,
WRH_WAIT_OFFSET_STABLE,
}wrh_servo_state_t;
#define WRH_SERVO_RESET_DATA_SIZE (sizeof(wrh_servo_t)-offsetof(wrh_servo_t,reset_address))
#define WRH_SERVO_RESET_DATA(servo) memset(&servo->reset_address,0,WRH_SERVO_RESET_DATA_SIZE);
typedef struct wrh_servo_t {
/* Values used by snmp. Values are increased at servo update when
* erroneous condition occurs. */
uint32_t n_err_state;
uint32_t n_err_offset;
uint32_t n_err_delta_rtt;
int32_t cur_setpoint_ps;
/* ----- All data after this line will cleared during a servo reset */
int reset_address;
/* These fields are used by servo code, after setting at init time */
int32_t clock_period_ps;
/* Following fields are for monitoring/diagnostics (use w/ shmem) */
int64_t delayMM_ps;
int64_t delayMS_ps;
int tracking_enabled;
int64_t skew_ps;
int64_t offsetMS_ps;
/* These fields are used by servo code, across iterations */
int64_t prev_delayMS_ps;
int missed_iters;
Boolean readyForSync; /* Ready for synchronization */
} wrh_servo_t;
static inline wrh_servo_t *WRH_SRV(struct pp_instance *ppi)
{
return (wrh_servo_t *)ppi->ext_data;
}
/* Prototypes */
extern void wrh_servo_enable_tracking(int enable);
extern int wrh_servo_init(struct pp_instance *ppi);
extern void wrh_servo_reset(struct pp_instance *ppi);
extern void wrh_servo_enable_tracking(int enable);
extern int wrh_servo_got_sync(struct pp_instance *ppi);
extern int wrh_servo_got_resp(struct pp_instance *ppi);
extern int wrh_servo_got_presp(struct pp_instance *ppi);
extern int wrh_update_correction_values(struct pp_instance *ppi);
#endif /* __WRH_H__ */
/*
* Copyright (C) 2012 CERN (www.cern.ch)
* Author: Aurelio Colosimo
* Based on ptp-noposix project (see AUTHORS for details)
*
* Released to the public domain
*/
#include <ppsi/ppsi.h>
/*
* WRS_PRESENT is the entry point for a WR slave
*
* Here we send SLAVE_PRESENT and wait for LOCK. If timeout,
* re-send SLAVE_PRESENT from WR_STATE_RETRY times
*/
int wr_idle(struct pp_instance *ppi, void *buf, int len, int new_state)
{
int delay=1000;//INT_MAX;
if ( ppi->ext_enabled ) {
/* While the extension is enabled, we expect to have
* a working WR connection.
*/
struct wr_dsport *wrp = WR_DSPOR(ppi);
switch (ppi->state) {
case PPS_MASTER :
{
/* Check the reception of a slave present message.
* If it arrives we must restart the WR handshake
*/
MsgSignaling wrsig_msg;
if (ppi->received_ptp_header.messageType == PPM_SIGNALING) {
msg_unpack_wrsig(ppi, buf, &wrsig_msg,
&(wrp->msgTmpWrMessageID));
if (wrp->msgTmpWrMessageID == SLAVE_PRESENT) {
lstate_set_link_in_progress(ppi);
wrp->next_state = WRS_M_LOCK;
delay=0;
}
}
if ( wrp->wrModeOn && wrp->parentWrModeOn )
lstate_set_link_established(ppi);
break;
}
case PPS_SLAVE :
if ( !(wrp->wrModeOn && wrp->parentWrModeOn) ) {
/* Failure detected in the protocol */
ppi->next_state=PPS_UNCALIBRATED;
wr_reset_process(ppi,WR_ROLE_NONE);
lstate_set_link_pdetection(ppi);
}
break;
case PPS_UNCALIBRATED :
break;
}
}
return delay;
}
......@@ -264,9 +264,7 @@ void msg_unpack_announce(struct pp_instance *ppi, void *buf, MsgAnnounce *ann)
/* this can fill in extention specific flags otherwise just zero them*/
if (is_ext_hook_available(ppi,unpack_announce))
ppi->ext_hooks->unpack_announce(buf, ann);
else
ann->ext_specific = 0;
ppi->ext_hooks->unpack_announce(ppi,buf, ann);
}
/* Pack Follow Up message into out buffer of ppi*/
......
......@@ -12,8 +12,6 @@
#include <endpoint.h> /* wrpc-sw */
#include <ptpd_netif.h> /* wrpc-sw */
int frame_rx_delay_us; /* set by faults.c */
#ifdef CONFIG_ABSCAL
#define HAS_ABSCAL 1
#else
......@@ -39,7 +37,7 @@ static int wrpc_open_ch(struct pp_instance *ppi)
struct wr_sockaddr addr;
char *macaddr = PP_MCAST_MACADDRESS;
if (CONFIG_HAS_P2P && ppi->delayMechanism == P2P)
if ( is_delayMechanismP2P(ppi) )
macaddr = PP_PDELAY_MACADDRESS;
addr.ethertype = htons(ETH_P_1588);
memcpy(addr.mac, macaddr, sizeof(mac_addr_t));
......
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