Commit a8733f10 authored by Alessandro Rubini's avatar Alessandro Rubini

state-initializing: merge extension into std, using hooks.init()

This removes the WR-specific state-initializing.c by introducing
the init() hook for the standard state-initializing.

Meanwhile, clean up error management a little in the init state.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent b4ef46b0
......@@ -307,6 +307,7 @@ static inline struct pp_servo *SRV(struct pp_instance *ppi)
* allow NULL pointers.
*/
struct pp_ext_hooks {
int (*init)(struct pp_instance *ppi, unsigned char *pkt, int plen);
};
extern struct pp_ext_hooks pp_hooks; /* The one for the extension we build */
......
......@@ -7,7 +7,6 @@ LIBWRO := $D/libwr.o
LIBS += $(LIBWRO)
OBJ-libwr := $D/fsm-table.o \
$D/state-initializing.o \
$D/state-listening.o \
$D/state-master.o \
$D/state-slave.o \
......
#include <ppsi/ppsi.h>
#include "wr-api.h"
/* ext-whiterabbit must offer its own hooks */
struct pp_ext_hooks pp_hooks;
static int wr_init(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
WR_DSPOR(ppi)->wrStateTimeout = WR_DEFAULT_STATE_TIMEOUT_MS;
WR_DSPOR(ppi)->wrStateRetry = WR_DEFAULT_STATE_REPEAT;
WR_DSPOR(ppi)->calPeriod = WR_DEFAULT_CAL_PERIOD;
WR_DSPOR(ppi)->wrModeOn = 0;
WR_DSPOR(ppi)->parentWrConfig = 0;
WR_DSPOR(ppi)->calibrated = !WR_DEFAULT_PHY_CALIBRATION_REQUIRED;
return 0;
}
struct pp_ext_hooks pp_hooks = {
.init = wr_init,
};
/*
* Aurelio Colosimo for CERN, 2011 -- GNU LGPL v2.1 or later
* Based on PTPd project v. 2.1.0 (see AUTHORS for details)
*/
#include <ppsi/ppsi.h>
#include <ppsi/diag.h>
#include <pps_gen.h>
#include <softpll_ng.h>
#include <syscon.h>
#include "wr-api.h"
/*
* Initializes network and other stuff
*/
#define LOCK_TIMEOUT_GM (60000)
int pp_initializing(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
unsigned char *id, *mac;
if (NP(ppi)->inited)
pp_net_shutdown(ppi);
if (pp_net_init(ppi) < 0)
goto failure;
NP(ppi)->inited = 1;
DSPOR(ppi)->portState = PPS_INITIALIZING;
/* Initialize default data set */
DSDEF(ppi)->twoStepFlag = PP_TWO_STEP_FLAG;
/* Clock identity comes from mac address with 0xff:0xfe intermixed */
id = DSDEF(ppi)->clockIdentity;
mac = NP(ppi)->ch[PP_NP_GEN].addr;
id[0] = mac[0];
id[1] = mac[1];
id[2] = mac[2];
id[3] = 0xff;
id[4] = 0xfe;
id[5] = mac[3];
id[6] = mac[4];
id[7] = mac[5];
DSDEF(ppi)->numberPorts = 1;
memcpy(&DSDEF(ppi)->clockQuality, &OPTS(ppi)->clock_quality,
sizeof(ClockQuality));
DSDEF(ppi)->priority1 = OPTS(ppi)->prio1;
DSDEF(ppi)->priority2 = OPTS(ppi)->prio2;
DSDEF(ppi)->domainNumber = OPTS(ppi)->domain_number;
DSDEF(ppi)->slaveOnly = OPTS(ppi)->slave_only;
if (OPTS(ppi)->slave_only)
ppi->defaultDS->clockQuality.clockClass = 255;
/* Initialize port data set */
memcpy(ppi->portDS->portIdentity.clockIdentity,
ppi->defaultDS->clockIdentity, PP_CLOCK_IDENTITY_LENGTH);
DSPOR(ppi)->portIdentity.portNumber = 1;
DSPOR(ppi)->logMinDelayReqInterval = PP_DEFAULT_DELAYREQ_INTERVAL;
DSPOR(ppi)->peerMeanPathDelay.seconds = 0;
DSPOR(ppi)->peerMeanPathDelay.nanoseconds = 0;
DSPOR(ppi)->logAnnounceInterval = OPTS(ppi)->announce_intvl;
DSPOR(ppi)->announceReceiptTimeout =
PP_DEFAULT_ANNOUNCE_RECEIPT_TIMEOUT;
DSPOR(ppi)->logSyncInterval = OPTS(ppi)->sync_intvl;
DSPOR(ppi)->delayMechanism = PP_DEFAULT_DELAY_MECHANISM;
DSPOR(ppi)->logMinPdelayReqInterval = PP_DEFAULT_PDELAYREQ_INTERVAL;
DSPOR(ppi)->versionNumber = PP_VERSION_PTP;
WR_DSPOR(ppi)->wrStateTimeout = WR_DEFAULT_STATE_TIMEOUT_MS;
WR_DSPOR(ppi)->wrStateRetry = WR_DEFAULT_STATE_REPEAT;
WR_DSPOR(ppi)->calPeriod = WR_DEFAULT_CAL_PERIOD;
WR_DSPOR(ppi)->wrModeOn = 0;
WR_DSPOR(ppi)->parentWrConfig = 0;
WR_DSPOR(ppi)->calibrated = !WR_DEFAULT_PHY_CALIBRATION_REQUIRED;
if (pp_timer_init(ppi))
goto failure;
pp_init_clock(ppi);
m1(ppi);
msg_pack_header(ppi, ppi->buf_out);
if (!OPTS(ppi)->master_only)
ppi->next_state = PPS_LISTENING;
else
ppi->next_state = PPS_MASTER;
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
return 0;
failure:
PP_PRINTF("Failed to initialize network\n");
ppi->next_state = PPS_FAULTY;
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
return 0;
}
......@@ -14,6 +14,7 @@
int pp_initializing(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
unsigned char *id, *mac;
int ret = 0;
if (NP(ppi)->inited)
pp_net_shutdown(ppi);
......@@ -64,9 +65,18 @@ int pp_initializing(struct pp_instance *ppi, unsigned char *pkt, int plen)
DSPOR(ppi)->logMinPdelayReqInterval = PP_DEFAULT_PDELAYREQ_INTERVAL;
DSPOR(ppi)->versionNumber = PP_VERSION_PTP;
if (pp_timer_init(ppi))
if (pp_hooks.init)
ret = pp_hooks.init(ppi, pkt, plen);
if (ret) {
PP_PRINTF("%s: can't init extension\n");
goto failure;
}
ret = pp_timer_init(ppi);
if (ret) {
PP_PRINTF("%s: can't init timers\n");
goto failure;
}
pp_init_clock(ppi);
m1(ppi);
......@@ -81,8 +91,7 @@ int pp_initializing(struct pp_instance *ppi, unsigned char *pkt, int plen)
return 0;
failure:
PP_PRINTF("Failed to initialize network\n");
ppi->next_state = PPS_FAULTY;
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
return 0;
return ret;
}
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