Commit 8b1eac65 authored by Alessandro Rubini's avatar Alessandro Rubini

massive: checkpatch fixes

I confess I repent having started this. And some of the files are really
in a terrible status and need rewrie anyways (I'm not pointing fingers,
I know the history of the project and I'm aware this is what I deserve).
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 7a4696c3
......@@ -20,9 +20,8 @@ void posix_main_loop(struct pp_instance *ppi)
set_TimeInternal(&ppi->last_rcv_time, 0, 0);
if (OPTS(ppi)->ethernet_mode) {
if (OPTS(ppi)->ethernet_mode)
NP(ppi)->proto_ofst = 14;
}
/*
* The main loop here is based on select. While we are not
......
......@@ -108,8 +108,7 @@ int posix_recv_packet(struct pp_instance *ppi, void *pkt, int len,
if (POSIX_ARCH(ppi)->rcv_switch) {
ch1 = &(NP(ppi)->ch[PP_NP_GEN]);
ch2 = &(NP(ppi)->ch[PP_NP_EVT]);
}
else {
} else {
ch1 = &(NP(ppi)->ch[PP_NP_EVT]);
ch2 = &(NP(ppi)->ch[PP_NP_GEN]);
}
......@@ -283,7 +282,7 @@ int posix_open_ch(struct pp_instance *ppi, char *ifname, int chtype)
iface_addr.s_addr =
((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
PP_VPRINTF("Local IP address used : %s \n", inet_ntoa(iface_addr));
PP_VPRINTF("Local IP address used : %s\n", inet_ntoa(iface_addr));
temp = 1; /* allow address reuse */
......
......@@ -65,7 +65,7 @@ int posix_timer_expired(struct pp_timer *tm)
uint64_t now_ms;
if (tm->start == 0) {
PP_PRINTF("%p Warning: posix_timer_expired: timer not started\n",tm);
PP_PRINTF("%s: Warning: timer %p not started\n", __func__, tm);
return 0;
}
......
......@@ -6,7 +6,7 @@
* These are the functions provided by the various posix files
*/
#define POSIX_ARCH(ppi) ((struct posix_arch_data*)(ppi->arch_data))
#define POSIX_ARCH(ppi) ((struct posix_arch_data *)(ppi->arch_data))
struct posix_arch_data {
struct timeval tv;
int rcv_switch; /* flag for event / general receive order */
......
......@@ -78,9 +78,9 @@ int wrpc_calibrating_poll(struct pp_instance *ppi, int txrx, uint32_t *delta)
}
int wrpc_calibration_pattern_enable(struct pp_instance *ppi,
unsigned int calibrationPeriod,
unsigned int calibrationPattern,
unsigned int calibrationPatternLen)
unsigned int calibrationPeriod,
unsigned int calibrationPattern,
unsigned int calibrationPatternLen)
{
ep_cal_pattern_enable();
return WR_HW_CALIB_OK;
......@@ -105,7 +105,7 @@ int wr_calibration_pattern_enable(struct pp_instance *ppi,
unsigned int calibrationPeriod, unsigned int calibrationPattern,
unsigned int calibrationPatternLen)
__attribute__((alias("wrpc_calibration_pattern_enable")));
int wr_calibration_pattern_disable(struct pp_instance *ppi)
__attribute__((alias("wrpc_calibration_pattern_disable")));
......
......@@ -11,7 +11,7 @@ void pp_puts(const char *s)
uart_write_string(s);
}
void pp_get_tstamp(TimeInternal *t) //uint32_t *sptr)
void pp_get_tstamp(TimeInternal *t)
{
uint64_t sec;
uint32_t nsec;
......
......@@ -12,7 +12,7 @@
#include <ptpd_netif.h>
int wrpc_errno;
Octet buffer_out[PP_PACKET_SIZE + 14]; // 14 is ppi->proto_ofst for ethernet mode
Octet buffer_out[PP_PACKET_SIZE + 14]; /* 14 == ppi->proto_ofst for eth mode */
/* This function should init the minic and get the mac address */
int wrpc_open_ch(struct pp_instance *ppi)
......@@ -76,8 +76,8 @@ int wrpc_send_packet(struct pp_instance *ppi, void *pkt, int len,
int j;
pp_printf("sent: %i\n", len);
for (j = 0; j < len; j++) {
pp_printf("%02x ", ((char*)pkt)[j]);
if( (j+1)%16==0 )
pp_printf("%02x ", ((char *)pkt)[j]);
if( (j + 1) % 16 == 0 )
pp_printf("\n");
}
pp_printf("\n");
......@@ -94,7 +94,7 @@ int wrpc_send_packet(struct pp_instance *ppi, void *pkt, int len,
t->phase = 0;
t->correct = wr_ts.correct;
PP_VPRINTF("%s: snt=%d, sec=%d, nsec=%d\n", __FUNCTION__, snt,
PP_VPRINTF("%s: snt=%d, sec=%d, nsec=%d\n", __func__, snt,
t->seconds, t->nanoseconds);
}
......@@ -106,7 +106,7 @@ int wrpc_net_init(struct pp_instance *ppi)
ppi->buf_out = buffer_out;
ppi->buf_out = PROTO_PAYLOAD(ppi->buf_out);
ppi->buf_out+= 4 - (((int)ppi->buf_out) % 4); /* FIXME Alignment */
ppi->buf_out += 4 - (((int)ppi->buf_out) % 4); /* FIXME Alignment */
wrpc_open_ch(ppi);
return 0;
......
......@@ -45,9 +45,9 @@ int wrpc_adjust_in_progress()
int wrpc_adjust_counters(int64_t adjust_sec, int32_t adjust_nsec)
{
if(adjust_sec)
if (adjust_sec)
shw_pps_gen_adjust(PPSG_ADJUST_SEC, adjust_sec);
if(adjust_nsec)
if (adjust_nsec)
shw_pps_gen_adjust(PPSG_ADJUST_NSEC, adjust_nsec);
return 0;
}
......
......@@ -10,7 +10,7 @@ int wrpc_timer_init(struct pp_instance *ppi)
{
uint32_t i;
for(i =0; i<PP_TIMER_ARRAY_SIZE; i++)
for (i = 0; i < PP_TIMER_ARRAY_SIZE; i++)
ppi->timers[i] = &wrpc_timers[i];
return 0;
......@@ -36,7 +36,7 @@ int wrpc_timer_expired(struct pp_timer *tm)
uint32_t now;
if (tm->start == 0) {
PP_PRINTF("%p Warning: posix_timer_expired: timer not started\n",tm);
PP_PRINTF("%s: Warning: timer %p not started\n", __func__, tm);
return 0;
}
......
......@@ -85,7 +85,8 @@ extern int wrpc_testc(void);
static inline void delay(int x)
{
while(x--) asm volatile("nop");
while (x--)
asm volatile("nop");
}
/* other network stuff, bah.... */
......
......@@ -25,10 +25,9 @@ struct pp_state_table_item pp_state_table[] __weak = {
{ WRS_M_LOCK, "master/wr-m-lock", wr_m_lock,},
{ WRS_S_LOCK, "uncalibrated/wr-s-lock", wr_s_lock,},
{ WRS_LOCKED, "uncalibrated/wr-locked", wr_locked,},
{ WRS_CALIBRATION, "wr-calibration",wr_calibration,},
{ WRS_CALIBRATED, "wr-calibrated",wr_calibrated,},
{ WRS_RESP_CALIB_REQ, "wr-resp-calib-req",
wr_resp_calib_req,},
{ WRS_WR_LINK_ON, "wr-link-on", wr_link_on,},
{ WRS_CALIBRATION, "wr-calibration", wr_calibration,},
{ WRS_CALIBRATED, "wr-calibrated", wr_calibrated,},
{ WRS_RESP_CALIB_REQ, "wr-resp-calib-req", wr_resp_calib_req,},
{ WRS_WR_LINK_ON, "wr-link-on", wr_link_on,},
{ PPS_END_OF_TABLE,}
};
......@@ -42,9 +42,8 @@ static int wr_master_msg(struct pp_instance *ppi, unsigned char *pkt, int plen,
MsgHeader *hdr = &ppi->msg_tmp_header;
MsgSignaling wrsig_msg;
TimeInternal *time = &ppi->last_rcv_time;
;
switch(msgtype) {
switch (msgtype) {
/* This case is modified from the default one */
case PPM_DELAY_REQ:
......@@ -156,9 +155,8 @@ void wr_unpack_announce(void *buf, MsgAnnounce *ann)
{
int msg_len = htons(*(UInteger16 *) (buf + 2));
if (msg_len > PP_ANNOUNCE_LENGTH) {
if (msg_len > PP_ANNOUNCE_LENGTH)
msg_unpack_announce_wr_tlv(buf, ann);
}
}
......
......@@ -18,9 +18,8 @@ int wr_calibration(struct pp_instance *ppi, unsigned char *pkt, int plen)
e = msg_issue_wrsig(ppi, CALIBRATE);
pp_timer_start(WR_DSPOR(ppi)->calPeriod,
ppi->timers[PP_TIMER_WRS_CALIBRATION]);
if (WR_DSPOR(ppi)->calibrated) {
if (WR_DSPOR(ppi)->calibrated)
WR_DSPOR(ppi)->wrPortState = WRS_CALIBRATION_2;
}
}
if (pp_timer_expired(ppi->timers[PP_TIMER_WRS_CALIBRATION])) {
......@@ -63,9 +62,9 @@ int wr_calibration(struct pp_instance *ppi, unsigned char *pkt, int plen)
DSPOR(ppi)->deltaTx.scaledPicoseconds.lsb);
WR_DSPOR(ppi)->wrPortState = WRS_CALIBRATION_3;
}
else
} else {
break; /* again */
}
case WRS_CALIBRATION_3:
/* disable Tx calibration */
......@@ -105,9 +104,9 @@ int wr_calibration(struct pp_instance *ppi, unsigned char *pkt, int plen)
DSPOR(ppi)->deltaRx.scaledPicoseconds.lsb);
WR_DSPOR(ppi)->wrPortState = WRS_CALIBRATION_7;
}
else
} else {
break; /* again */
}
case WRS_CALIBRATION_7:
/* disable Rx calibration */
......
......@@ -22,7 +22,7 @@
#define WR_DEFAULT_CAL_PATTERN 0x3E0 /* 1111100000 */
#define WR_DEFAULT_CAL_PATTERN_LEN 0xA /* 10 bits */
#define WR_DEFAULT_STATE_TIMEOUT_MS 300 /* [ms] */
#define WR_DEFAULT_STATE_TIMEOUT_MS 300 /* [ms] */
#define WR_WRS_PRESENT_TIMEOUT_MS 1000
#define WR_M_LOCK_TIMEOUT_MS 10000
#define WR_S_LOCK_TIMEOUT_MS 10000
......@@ -54,7 +54,7 @@
/* new stuff for WRPTPv2 */
#define TLV_TYPE_ORG_EXTENSION 0x0003 /* organization specific */
#define TLV_TYPE_ORG_EXTENSION 0x0003 /* organization specific */
#define WR_PRIORITY1 64
......@@ -69,8 +69,8 @@
#define WR_DEFAULT_PHY_CALIBRATION_REQUIRED FALSE
#define SEND_CALIBRATION_PATTERN 0X0001
#define NOT_SEND_CALIBRATION_PATTERN 0X0000
#define SEND_CALIBRATION_PATTERN 0X0001
#define NOT_SEND_CALIBRATION_PATTERN 0X0000
/* White Rabbit softpll status values */
#define WR_SPLL_OK 0
......@@ -88,15 +88,15 @@
/* Indicates if a port is configured as White Rabbit, and what kind
* (master/slave) */
enum {
NON_WR = 0x0,
WR_S_ONLY = 0x2,
WR_M_ONLY = 0x1,
WR_M_AND_S = 0x3,
WR_MODE_AUTO= 0x4, /* only for ptpx - not in the spec */
NON_WR = 0x0,
WR_S_ONLY = 0x2,
WR_M_ONLY = 0x1,
WR_M_AND_S = 0x3,
WR_MODE_AUTO = 0x4, /* only for ptpx - not in the spec */
};
/* White Rabbit node */
enum{
enum {
WR_SLAVE = 2,
WR_MASTER = 1,
};
......@@ -116,8 +116,8 @@ enum {
enum {
/* WR states start from 16 in order not to be confused with PTP states,
* since our application FSM is flat */
WRS_PRESENT = 16, WRS_S_LOCK, WRS_M_LOCK, WRS_LOCKED,
WRS_CALIBRATION, WRS_CALIBRATED, WRS_RESP_CALIB_REQ ,WRS_WR_LINK_ON,
WRS_PRESENT = 16, WRS_S_LOCK, WRS_M_LOCK, WRS_LOCKED,
WRS_CALIBRATION, WRS_CALIBRATED, WRS_RESP_CALIB_REQ, WRS_WR_LINK_ON,
/* Each WR main state (except IDLE) has an associated timeout
* we use state names to manage timeouts as well */
WR_TIMER_ARRAY_SIZE, /* number of states which has timeouts */
......@@ -154,8 +154,8 @@ enum {
/* White Rabbit slave port's role */
enum {
NON_SLAVE = 0x0,
PRIMARY_SLAVE ,
SECONDARY_SLAVE ,
PRIMARY_SLAVE,
SECONDARY_SLAVE,
};
/* White Rabbit data initialization mode */
......
......@@ -59,16 +59,16 @@ void msg_pack_announce_wr_tlv(struct pp_instance *ppi)
buf = ppi->buf_out;
*(UInteger16 *)(buf + 2) = htons(WR_ANNOUNCE_LENGTH);
*(UInteger16*)(buf + 64) = htons(TLV_TYPE_ORG_EXTENSION);
*(UInteger16*)(buf + 66) = htons(WR_ANNOUNCE_TLV_LENGTH);
// CERN's OUI: WR_TLV_ORGANIZATION_ID, how to flip bits?
*(UInteger16*)(buf + 68) = htons((WR_TLV_ORGANIZATION_ID >> 8));
*(UInteger16*)(buf + 70) = htons((0xFFFF & (WR_TLV_ORGANIZATION_ID << 8
*(UInteger16 *)(buf + 64) = htons(TLV_TYPE_ORG_EXTENSION);
*(UInteger16 *)(buf + 66) = htons(WR_ANNOUNCE_TLV_LENGTH);
/* CERN's OUI: WR_TLV_ORGANIZATION_ID, how to flip bits? */
*(UInteger16 *)(buf + 68) = htons((WR_TLV_ORGANIZATION_ID >> 8));
*(UInteger16 *)(buf + 70) = htons((0xFFFF & (WR_TLV_ORGANIZATION_ID << 8
| WR_TLV_MAGIC_NUMBER >> 8)));
*(UInteger16*)(buf + 72) = htons((0xFFFF & (WR_TLV_MAGIC_NUMBER << 8
*(UInteger16 *)(buf + 72) = htons((0xFFFF & (WR_TLV_MAGIC_NUMBER << 8
| WR_TLV_WR_VERSION_NUMBER)));
//wrMessageId
*(UInteger16*)(buf + 74) = htons(ANN_SUFIX);
/* wrMessageId */
*(UInteger16 *)(buf + 74) = htons(ANN_SUFIX);
wr_flags = wr_flags | WR_DSPOR(ppi)->wrConfig;
if (WR_DSPOR(ppi)->calibrated)
......@@ -76,7 +76,7 @@ void msg_pack_announce_wr_tlv(struct pp_instance *ppi)
if (WR_DSPOR(ppi)->wrModeOn)
wr_flags = WR_IS_WR_MODE | wr_flags;
*(UInteger16*)(buf + 76) = htons(wr_flags);
*(UInteger16 *)(buf + 76) = htons(wr_flags);
}
void msg_unpack_announce_wr_tlv(void *buf, MsgAnnounce *ann)
......@@ -88,14 +88,14 @@ void msg_unpack_announce_wr_tlv(void *buf, MsgAnnounce *ann)
UInteger16 tlv_wrMessageID;
tlv_type = (UInteger16)get_be16(buf+64);
tlv_organizationID = htons(*(UInteger16*)(buf+68)) << 8;
tlv_organizationID = htons(*(UInteger16*)(buf+70)) >> 8
tlv_organizationID = htons(*(UInteger16 *)(buf+68)) << 8;
tlv_organizationID = htons(*(UInteger16 *)(buf+70)) >> 8
| tlv_organizationID;
tlv_magicNumber = 0xFF00 & (htons(*(UInteger16*)(buf+70)) << 8);
tlv_magicNumber = htons(*(UInteger16*)(buf+72)) >> 8
tlv_magicNumber = 0xFF00 & (htons(*(UInteger16 *)(buf+70)) << 8);
tlv_magicNumber = htons(*(UInteger16 *)(buf+72)) >> 8
| tlv_magicNumber;
tlv_versionNumber = 0xFF & htons(*(UInteger16*)(buf+72));
tlv_wrMessageID = htons(*(UInteger16*)(buf+74));
tlv_versionNumber = 0xFF & htons(*(UInteger16 *)(buf+72));
tlv_wrMessageID = htons(*(UInteger16 *)(buf+74));
if (tlv_type == TLV_TYPE_ORG_EXTENSION &&
tlv_organizationID == WR_TLV_ORGANIZATION_ID &&
......@@ -121,34 +121,33 @@ int msg_pack_wrsig(struct pp_instance *ppi, Enumeration16 wr_msg_id)
buf = ppi->buf_out;
/* Changes in header */
*(char*)(buf+0) = *(char*)(buf+0) & 0xF0; /* RAZ messageType */
*(char*)(buf+0) = *(char*)(buf+0) | 0x0C; /* Table 19 -> signaling */
*(char *)(buf+0) = *(char *)(buf+0) & 0xF0; /* RAZ messageType */
*(char *)(buf+0) = *(char *)(buf+0) | 0x0C; /* Table 19 -> signaling */
*(UInteger8*)(buf+32) = 0x05; //Table 23 -> all other
*(UInteger8 *)(buf+32) = 0x05; //Table 23 -> all other
/* target portIdentity */
memcpy((buf+34),DSPAR(ppi)->parentPortIdentity.clockIdentity,
memcpy((buf+34), DSPAR(ppi)->parentPortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH);
put_be16(buf + 42,DSPAR(ppi)->parentPortIdentity.portNumber);
put_be16(buf + 42, DSPAR(ppi)->parentPortIdentity.portNumber);
/* WR TLV */
*(UInteger16*)(buf+44) = htons(TLV_TYPE_ORG_EXTENSION);
*(UInteger16 *)(buf+44) = htons(TLV_TYPE_ORG_EXTENSION);
/* leave lenght free */
*(UInteger16*)(buf+48) = htons((WR_TLV_ORGANIZATION_ID >> 8));
*(UInteger16*)(buf+50) = htons((0xFFFF &
*(UInteger16 *)(buf+48) = htons((WR_TLV_ORGANIZATION_ID >> 8));
*(UInteger16 *)(buf+50) = htons((0xFFFF &
(WR_TLV_ORGANIZATION_ID << 8 | WR_TLV_MAGIC_NUMBER >> 8)));
*(UInteger16*)(buf+52) = htons((0xFFFF &
*(UInteger16 *)(buf+52) = htons((0xFFFF &
(WR_TLV_MAGIC_NUMBER << 8 | WR_TLV_WR_VERSION_NUMBER)));
/* wrMessageId */
*(UInteger16*)(buf+54) = htons(wr_msg_id);
*(UInteger16 *)(buf+54) = htons(wr_msg_id);
switch (wr_msg_id) {
case CALIBRATE:
if(WR_DSPOR(ppi)->calibrated) {
if (WR_DSPOR(ppi)->calibrated) {
put_be16(buf+56,
(WR_DSPOR(ppi)->calRetry << 8 | 0x0000));
}
else {
} else {
put_be16(buf+56,
(WR_DSPOR(ppi)->calRetry << 8 | 0x0001));
}
......@@ -176,10 +175,10 @@ int msg_pack_wrsig(struct pp_instance *ppi, Enumeration16 wr_msg_id)
/* header len */
put_be16(buf + 2, WR_SIGNALING_MSG_BASE_LENGTH + len);
/* TLV len */
*(Integer16*)(buf+46) = htons(len);
*(Integer16 *)(buf+46) = htons(len);
/* FIXME diagnostic */
return (WR_SIGNALING_MSG_BASE_LENGTH + len);
return WR_SIGNALING_MSG_BASE_LENGTH + len;
}
/* White Rabbit: unpacking wr signaling messages */
......@@ -192,18 +191,18 @@ void msg_unpack_wrsig(struct pp_instance *ppi, void *buf,
UInteger16 tlv_versionNumber;
Enumeration16 wr_msg_id;
memcpy(wrsig_msg->targetPortIdentity.clockIdentity,(buf+34),
memcpy(wrsig_msg->targetPortIdentity.clockIdentity, (buf + 34),
PP_CLOCK_IDENTITY_LENGTH);
wrsig_msg->targetPortIdentity.portNumber = (UInteger16)get_be16(buf+42);
tlv_type = (UInteger16)get_be16(buf+44);
tlv_organizationID = htons(*(UInteger16*)(buf+48)) << 8;
tlv_organizationID = htons(*(UInteger16*)(buf+50)) >> 8
tlv_type = (UInteger16)get_be16(buf + 44);
tlv_organizationID = htons(*(UInteger16 *)(buf + 48)) << 8;
tlv_organizationID = htons(*(UInteger16 *)(buf + 50)) >> 8
| tlv_organizationID;
tlv_magicNumber = 0xFF00 & (htons(*(UInteger16*)(buf+50)) << 8);
tlv_magicNumber = htons(*(UInteger16*)(buf+52)) >> 8
tlv_magicNumber = 0xFF00 & (htons(*(UInteger16 *)(buf + 50)) << 8);
tlv_magicNumber = htons(*(UInteger16 *)(buf + 52)) >> 8
| tlv_magicNumber;
tlv_versionNumber = 0xFF & htons(*(UInteger16*)(buf+52));
tlv_versionNumber = 0xFF & htons(*(UInteger16 *)(buf + 52));
if (tlv_type != TLV_TYPE_ORG_EXTENSION) {
PP_PRINTF("handle Signaling msg, failed, This is not "
......@@ -217,19 +216,19 @@ void msg_unpack_wrsig(struct pp_instance *ppi, void *buf,
return;
}
if(tlv_magicNumber != WR_TLV_MAGIC_NUMBER) {
if (tlv_magicNumber != WR_TLV_MAGIC_NUMBER) {
PP_PRINTF("handle Signaling msg, failed, "
"not White Rabbit magic number = 0x%x\n", tlv_magicNumber);
return;
}
if(tlv_versionNumber != WR_TLV_WR_VERSION_NUMBER ) {
if (tlv_versionNumber != WR_TLV_WR_VERSION_NUMBER ) {
PP_PRINTF("handle Signaling msg, failed, not supported "
"version number = 0x%x\n", tlv_versionNumber);
return;
}
wr_msg_id = htons(*(UInteger16*)(buf+54));
wr_msg_id = htons(*(UInteger16 *)(buf + 54));
if (pwr_msg_id) {
*pwr_msg_id = wr_msg_id;
......
......@@ -37,7 +37,8 @@ void wr_servo_enable_tracking(int enable)
static void dump_timestamp(char *what, TimeInternal ts)
{
PP_PRINTF("%s = %d:%d:%d\n", what, (int32_t)ts.seconds, ts.nanoseconds, ts.phase);
PP_PRINTF("%s = %d:%d:%d\n", what, (int32_t)ts.seconds,
ts.nanoseconds, ts.phase);
}
static int64_t ts_to_picos(TimeInternal ts)
......@@ -70,18 +71,16 @@ static TimeInternal ts_add(TimeInternal a, TimeInternal b)
c.seconds = 0;
c.nanoseconds = 0;
c.phase =a.phase + b.phase;
c.phase = a.phase + b.phase;
while(c.phase >= 1000)
{
while(c.phase >= 1000) {
c.phase -= 1000;
c.nanoseconds++;
}
c.nanoseconds += (a.nanoseconds + b.nanoseconds);
while(c.nanoseconds >= 1000000000L)
{
while(c.nanoseconds >= 1000000000L) {
c.nanoseconds -= 1000000000L;
c.seconds++;
}
......@@ -100,15 +99,13 @@ static TimeInternal ts_sub(TimeInternal a, TimeInternal b)
c.phase = a.phase - b.phase;
while(c.phase < 0)
{
c.phase+=1000;
while(c.phase < 0) {
c.phase += 1000;
c.nanoseconds--;
}
c.nanoseconds += a.nanoseconds - b.nanoseconds;
while(c.nanoseconds < 0)
{
while(c.nanoseconds < 0) {
c.nanoseconds += 1000000000L;
c.seconds--;
}
......@@ -122,37 +119,34 @@ static TimeInternal ts_sub(TimeInternal a, TimeInternal b)
* of 8ns cycles and puts the extra nanoseconds in the phase field */
static TimeInternal ts_hardwarize(TimeInternal ts, int clock_period_ps)
{
int32_t q_threshold;
int32_t q_threshold;
q_threshold = (clock_period_ps + 999) / 1000;
q_threshold = (clock_period_ps + 999) / 1000;
if(ts.nanoseconds > 0)
{
if (ts.nanoseconds > 0) {
int32_t extra_nsec = ts.nanoseconds % q_threshold;
if(extra_nsec)
{
ts.nanoseconds -=extra_nsec;
if(extra_nsec) {
ts.nanoseconds -= extra_nsec;
ts.phase += extra_nsec * 1000;
}
}
if(ts.nanoseconds < 0) {
if (ts.nanoseconds < 0) {
ts.nanoseconds += 1000000000LL;
ts.seconds--;
}
if(ts.seconds == -1 && ts.nanoseconds > 0)
{
ts.seconds++;
ts.nanoseconds -= 1000000000LL;
}
if (ts.seconds == -1 && ts.nanoseconds > 0) {
ts.seconds++;
ts.nanoseconds -= 1000000000LL;
}
if(ts.nanoseconds < 0 && ts.nanoseconds >= (-q_threshold) && ts.seconds == 0)
{
ts.nanoseconds += q_threshold;
ts.phase -= q_threshold * 1000;
}
if (ts.nanoseconds < 0 && ts.nanoseconds >= (-q_threshold)
&& ts.seconds == 0) {
ts.nanoseconds += q_threshold;
ts.phase -= q_threshold * 1000;
}
return ts;
}
......@@ -189,7 +183,7 @@ int wr_servo_init(struct pp_instance *ppi)
s->state = WR_SYNC_TAI;
s->cur_setpoint = 0;
s->missed_iters = 0;
s->delta_tx_m = ((((int32_t)WR_DSPOR(ppi)->otherNodeDeltaTx.scaledPicoseconds.lsb) >> 16) & 0xffff) | (((int32_t)WR_DSPOR(ppi)->otherNodeDeltaTx.scaledPicoseconds.msb) << 16);
s->delta_rx_m = ((((int32_t)WR_DSPOR(ppi)->otherNodeDeltaRx.scaledPicoseconds.lsb) >> 16) & 0xffff) | (((int32_t)WR_DSPOR(ppi)->otherNodeDeltaRx.scaledPicoseconds.msb) << 16);
......@@ -278,13 +272,13 @@ int wr_servo_update(struct pp_instance *ppi)
if(!got_sync)
return 0;
if(!s->t1.correct || !s->t2.correct || !s->t3.correct || !s->t4.correct)
{
PP_VPRINTF( "servo: TimestampsIncorrect: %d %d %d %d\n",
s->t1.correct, s->t2.correct, s->t3.correct, s->t4.correct);
return 0;
}
if(!s->t1.correct || !s->t2.correct ||
!s->t3.correct || !s->t4.correct) {
PP_VPRINTF( "servo: TimestampsIncorrect: %d %d %d %d\n",
s->t1.correct, s->t2.correct,
s->t3.correct, s->t4.correct);
return 0;
}
cur_servo_state.update_count++;
......@@ -348,29 +342,26 @@ int wr_servo_update(struct pp_instance *ppi)
}
if (wr_locking_poll(ppi) != WR_SPLL_READY)
{
if (wr_locking_poll(ppi) != WR_SPLL_READY) {
PP_PRINTF("PLL OutOfLock, should restart sync\n");
wr_enable_timing_output(ppi, 0);
/* TODO check
* DSPOR(ppi)->doRestart = TRUE; */
}
switch(s->state)
{
case WR_WAIT_SYNC_IDLE:
if(!wr_adjust_in_progress())
{
s->state = s->next_state;
}else PP_PRINTF("servo:busy\n");
switch (s->state) {
case WR_WAIT_SYNC_IDLE:
if (!wr_adjust_in_progress()) {
s->state = s->next_state;
} else {
PP_PRINTF("servo:busy\n");
}
break;
case WR_SYNC_TAI:
wr_enable_timing_output(ppi, 0);
if(ts_offset_hw.seconds != 0)
{
if (ts_offset_hw.seconds != 0) {
strcpy(cur_servo_state.slave_servo_state, "SYNC_SEC");
wr_adjust_counters(ts_offset_hw.seconds, 0);
wr_adjust_phase(0);
......@@ -379,26 +370,30 @@ int wr_servo_update(struct pp_instance *ppi)
s->state = WR_WAIT_SYNC_IDLE;
s->last_tics = tics;
} else s->state = WR_SYNC_NSEC;
} else {
s->state = WR_SYNC_NSEC;
}
break;
case WR_SYNC_NSEC:
strcpy(cur_servo_state.slave_servo_state, "SYNC_NSEC");
if(ts_offset_hw.nanoseconds != 0)
{
if (ts_offset_hw.nanoseconds != 0) {
wr_adjust_counters(0, ts_offset_hw.nanoseconds);
s->next_state = WR_SYNC_NSEC;
s->state = WR_WAIT_SYNC_IDLE;
s->last_tics = tics;
} else s->state = WR_SYNC_PHASE;
} else {
s->state = WR_SYNC_PHASE;
}
break;
case WR_SYNC_PHASE:
strcpy(cur_servo_state.slave_servo_state, "SYNC_PHASE");
s->cur_setpoint = ts_offset_hw.phase + ts_offset_hw.nanoseconds * 1000;
s->cur_setpoint = ts_offset_hw.phase
+ ts_offset_hw.nanoseconds * 1000;
wr_adjust_phase(s->cur_setpoint);
......@@ -406,36 +401,36 @@ int wr_servo_update(struct pp_instance *ppi)
s->state = WR_WAIT_SYNC_IDLE;
s->last_tics = tics;
s->delta_ms_prev = s->delta_ms;
break;
case WR_WAIT_OFFSET_STABLE:
{
int64_t remaining_offset = abs(ts_to_picos(ts_offset_hw));
if(ts_offset_hw.seconds !=0 || ts_offset_hw.nanoseconds != 0)
s->state = WR_SYNC_TAI;
else if(remaining_offset < WR_SERVO_OFFSET_STABILITY_THRESHOLD)
{
wr_enable_timing_output(ppi, 1);
s->state = WR_TRACK_PHASE;
} else s->missed_iters++;
if(s->missed_iters >= 10)
s->state = WR_SYNC_TAI;
break;
}
break;
case WR_WAIT_OFFSET_STABLE:
{
int64_t remaining_offset = abs(ts_to_picos(ts_offset_hw));
if (ts_offset_hw.seconds !=0 || ts_offset_hw.nanoseconds != 0)
s->state = WR_SYNC_TAI;
else
if(remaining_offset < WR_SERVO_OFFSET_STABILITY_THRESHOLD) {
wr_enable_timing_output(ppi, 1);
s->state = WR_TRACK_PHASE;
} else {
s->missed_iters++;
}
if (s->missed_iters >= 10)
s->state = WR_SYNC_TAI;
break;
}
case WR_TRACK_PHASE:
strcpy(cur_servo_state.slave_servo_state, "TRACK_PHASE");
cur_servo_state.cur_setpoint = s->cur_setpoint;
cur_servo_state.cur_skew = s->delta_ms - s->delta_ms_prev;
if(ts_offset_hw.seconds !=0 || ts_offset_hw.nanoseconds != 0)
if (ts_offset_hw.seconds !=0 || ts_offset_hw.nanoseconds != 0)
s->state = WR_SYNC_TAI;
if(tracking_enabled)
{
if(tracking_enabled) {
// shw_pps_gen_enable_output(1);
// just follow the changes of deltaMS
s->cur_setpoint += (s->delta_ms - s->delta_ms_prev);
......
......@@ -93,11 +93,11 @@ void sub_TimeInternal(TimeInternal *r, TimeInternal *x, TimeInternal *y)
void div2_TimeInternal(TimeInternal *r)
{
r->nanoseconds += r->seconds % 2 * 1000000000;
r->seconds /= 2;
r->nanoseconds /= 2;
r->nanoseconds += r->seconds % 2 * 1000000000;
r->seconds /= 2;
r->nanoseconds /= 2;
normalize_TimeInternal(r);
normalize_TimeInternal(r);
}
void set_TimeInternal(TimeInternal *t, Integer32 s, Integer32 ns)
......@@ -108,7 +108,8 @@ void set_TimeInternal(TimeInternal *t, Integer32 s, Integer32 ns)
void display_TimeInternal(const char *label, TimeInternal *t)
{
PP_VPRINTF("%s: %s%d.%09d \n", label,
(t->seconds < 0 || (t->seconds == 0 && t->nanoseconds < 0)) ? "-" : " ",
abs(t->seconds), abs(t->nanoseconds));
PP_VPRINTF("%s: %s%d.%09d\n", label,
(t->seconds < 0 || (t->seconds == 0 && t->nanoseconds < 0))
? "-" : " ",
abs(t->seconds), abs(t->nanoseconds));
}
......@@ -240,7 +240,7 @@ Integer8 bmc_dataset_cmp(struct pp_instance *ppi,
}
/* State decision algorithm 9.3.3 Fig 26 */
UInteger8 bmc_state_decision( struct pp_instance *ppi,
UInteger8 bmc_state_decision(struct pp_instance *ppi,
MsgHeader *hdr, MsgAnnounce *ann)
{
int cmpres;
......@@ -285,9 +285,8 @@ UInteger8 bmc_state_decision( struct pp_instance *ppi,
}
}
if (cmpres == 0) {
if (cmpres == 0)
PP_PRINTF("Error in bmc_state_decision, cmpres=0.\n");
}
/* MB: Is this the return code below correct? */
/* Anyway, it's a valid return code. */
......
......@@ -51,8 +51,7 @@ int st_com_execute_slave(struct pp_instance *ppi, int check_delayreq)
}
} else {
if (pp_timer_expired(ppi->timers[PP_TIMER_PDELAYREQ]))
{
if (pp_timer_expired(ppi->timers[PP_TIMER_PDELAYREQ])) {
PP_VPRINTF("event PDELAYREQ_INTERVAL_TOUT_EXPIRES\n");
ret = msg_issue_pdelay_req(ppi);
}
......@@ -100,8 +99,7 @@ void st_com_add_foreign(struct pp_instance *ppi, unsigned char *buf)
clockIdentity,
PP_CLOCK_IDENTITY_LENGTH) &&
(hdr->sourcePortIdentity.portNumber ==
ppi->frgn_master[j].port_identity.portNumber))
{
ppi->frgn_master[j].port_identity.portNumber)) {
/* Foreign Master is already in Foreign master data set
*/
ppi->frgn_master[j].ann_messages++;
......@@ -145,7 +143,7 @@ void st_com_add_foreign(struct pp_instance *ppi, unsigned char *buf)
msg_unpack_announce(buf, &ppi->frgn_master[j].ann);
PP_VPRINTF("New foreign Master added \n");
PP_VPRINTF("New foreign Master added\n");
ppi->foreign_record_i = (ppi->foreign_record_i+1) %
OPTS(ppi)->max_foreign_records;
......
......@@ -40,25 +40,25 @@ int st_com_handle_pdelay_req(struct pp_instance *ppi, unsigned char *buf,
int len);
#ifdef VERB_LOG_MSGS
#define MSG_SEND_AND_RET_VARLEN(x,y,z,w)\
#define MSG_SEND_AND_RET_VARLEN(x, y, z, w) \
if (pp_send_packet(ppi, ppi->buf_out, w,\
&ppi->last_snt_time, PP_NP_##y , z) < w) {\
PP_PRINTF("%s(%d) Message can't be sent -> FAULTY state!\n",\
pp_msg_names[PPM_##x], PPM_##x);\
return -1;\
}\
PP_VPRINTF("SENT %02d %d.%d %s \n", w,\
ppi->last_snt_time.seconds,\
ppi->last_snt_time.nanoseconds,pp_msg_names[PPM_##x]);\
ppi->sent_seq_id[PPM_## x]++;\
&ppi->last_snt_time, PP_NP_##y , z) < w) { \
PP_PRINTF("%s(%d) Message can't be sent -> FAULTY state!\n", \
pp_msg_names[PPM_##x], PPM_##x); \
return -1; \
} \
PP_VPRINTF("SENT %02d %d.%d %s\n", w, \
ppi->last_snt_time.seconds, \
ppi->last_snt_time.nanoseconds, pp_msg_names[PPM_##x]); \
ppi->sent_seq_id[PPM_## x]++; \
return 0;
#else
#define MSG_SEND_AND_RET_VARLEN(x,y,z,w)\
if (pp_send_packet(ppi, ppi->buf_out, w,\
&ppi->last_snt_time, PP_NP_##y , z) < w) {\
return -1;\
}\
ppi->sent_seq_id[PPM_## x]++;\
#define MSG_SEND_AND_RET_VARLEN(x, y, z, w) \
if (pp_send_packet(ppi, ppi->buf_out, w, \
&ppi->last_snt_time, PP_NP_##y , z) < w) { \
return -1; \
} \
ppi->sent_seq_id[PPM_## x]++; \
return 0;
#endif
......
......@@ -37,7 +37,7 @@ static inline void timestamp_display(const char *label, Timestamp *timestamp)
static inline void msg_display_header(MsgHeader *header)
{
#ifdef VERB_LOG_MSGS
PP_VPRINTF("Message header: \n");
PP_VPRINTF("Message header:\n");
PP_VPRINTF("\n");
PP_VPRINTF("transportSpecific: %d\n", header->transportSpecific);
PP_VPRINTF("messageType: %d\n", header->messageType);
......@@ -46,7 +46,7 @@ static inline void msg_display_header(MsgHeader *header)
PP_VPRINTF("domainNumber: %d\n", header->domainNumber);
PP_VPRINTF("FlagField %02x:%02x\n", header->flagField[0],
header->flagField[1]);
Integer64_display("correctionfield",&header->correctionfield);
Integer64_display("correctionfield", &header->correctionfield);
/* FIXME diag portIdentity_display(&header->sourcePortIdentity); */
PP_VPRINTF("sequenceId: %d\n", header->sequenceId);
PP_VPRINTF("controlField: %d\n", header->controlField);
......@@ -58,20 +58,20 @@ static inline void msg_display_header(MsgHeader *header)
static inline void msg_display_announce(MsgAnnounce *announce)
{
#ifdef VERB_LOG_MSGS
PP_VPRINTF("Message ANNOUNCE:\n");
timestamp_display("Origin Timestamp", &announce->originTimestamp);
PP_VPRINTF("currentUtcOffset: %d\n", announce->currentUtcOffset);
PP_VPRINTF("grandMasterPriority1: %d\n",
PP_VPRINTF("Message ANNOUNCE:\n");
timestamp_display("Origin Timestamp", &announce->originTimestamp);
PP_VPRINTF("currentUtcOffset: %d\n", announce->currentUtcOffset);
PP_VPRINTF("grandMasterPriority1: %d\n",
announce->grandmasterPriority1);
PP_VPRINTF("grandMasterClockQuality:\n");
/* FIXME diag clockQuality_display(&announce->grandmasterClockQuality); */
PP_VPRINTF("grandMasterPriority2: %d\n",
PP_VPRINTF("grandMasterClockQuality:\n");
/* FIXME diag clockQuality_display(&announce->grandmasterClockQuality); */
PP_VPRINTF("grandMasterPriority2: %d\n",
announce->grandmasterPriority2);
PP_VPRINTF("grandMasterIdentity:\n");
/* FIXME diag clockIdentity_display(announce->grandmasterIdentity); */
PP_VPRINTF("stepsRemoved: %d\n", announce->stepsRemoved);
PP_VPRINTF("timeSource: %d\n", announce->timeSource);
PP_VPRINTF("\n");
PP_VPRINTF("grandMasterIdentity:\n");
/* FIXME diag clockIdentity_display(announce->grandmasterIdentity); */
PP_VPRINTF("stepsRemoved: %d\n", announce->stepsRemoved);
PP_VPRINTF("timeSource: %d\n", announce->timeSource);
PP_VPRINTF("\n");
/* FIXME: diagnostic for extension */
#endif
}
......@@ -584,7 +584,7 @@ void msg_unpack_pdelay_resp_followup(void *buf,
PP_VPRINTF("\n");
}
const char const * pp_msg_names[] = {
const char const *pp_msg_names[] = {
"sync",
"delay_req",
"pdelay_req",
......@@ -614,7 +614,7 @@ int msg_issue_sync(struct pp_instance *ppi)
pp_get_tstamp(&now);
from_TimeInternal(&now, &orig_tstamp);
msg_pack_sync(ppi,&orig_tstamp);
msg_pack_sync(ppi, &orig_tstamp);
MSG_SEND_AND_RET(SYNC, EVT, 0);
}
......
......@@ -28,7 +28,7 @@ struct pp_runtime_opts default_rt_opts = {
.s = PP_DEFAULT_DELAY_S,
.ethernet_mode = PP_DEFAULT_ETHERNET_MODE,
.e2e_mode = PP_DEFAULT_E2E_MODE,
.gptp_mode = PP_DEFAULT_GPTP_MODE,
.gptp_mode = PP_DEFAULT_GPTP_MODE,
.ofst_first_updated = 0, /* FIXME: is it a option or a state var? */
.max_foreign_records = PP_DEFAULT_MAX_FOREIGN_RECORDS,
.cur_utc_ofst = PP_DEFAULT_UTC_OFFSET,
......
......@@ -34,18 +34,18 @@ void pp_update_delay(struct pp_instance *ppi, TimeInternal *correction_field)
if (OPTS(ppi)->max_dly) { /* If max_delay is 0 then it's OFF */
if (s_to_m_dly.seconds) {
#ifdef VERB_LOG_MSGS
PP_VPRINTF("pp_update_delay aborted, delay greater than 1"
" second\n");
PP_VPRINTF("pp_update_delay aborted, delay greater "
"than 1 second\n");
#endif
return;
}
if (s_to_m_dly.nanoseconds > OPTS(ppi)->max_dly) {
#ifdef VERB_LOG_MSGS
PP_VPRINTF("pp_update_delay aborted, delay %d greater than "
"administratively set maximum %d\n",
s_to_m_dly.nanoseconds,
OPTS(ppi)->max_dly);
PP_VPRINTF("pp_update_delay aborted, delay %d greater "
"than administratively set maximum %d\n",
s_to_m_dly.nanoseconds,
OPTS(ppi)->max_dly);
#endif
return;
}
......@@ -328,12 +328,12 @@ void pp_update_clock(struct pp_instance *ppi)
#ifdef VERB_LOG_MSGS
display:
PP_VPRINTF("\n--Offset Correction-- \n");
PP_VPRINTF("\n--Offset Correction--\n");
PP_VPRINTF("Raw offset from master: %10ds %11dns\n",
SRV(ppi)->m_to_s_dly.seconds,
SRV(ppi)->m_to_s_dly.nanoseconds);
PP_VPRINTF("\n--Offset and Delay filtered-- \n");
PP_VPRINTF("\n--Offset and Delay filtered--\n");
if (!OPTS(ppi)->e2e_mode) {
PP_VPRINTF("one-way delay averaged (P2P): %10ds %11dns\n",
......
......@@ -45,7 +45,8 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen)
goto failure;
time_snt = &ppi->last_snt_time;
add_TimeInternal(time_snt, time_snt, &OPTS(ppi)->outbound_latency);
add_TimeInternal(time_snt, time_snt,
&OPTS(ppi)->outbound_latency);
if (msg_issue_followup(ppi, time_snt))
goto failure;
}
......
......@@ -185,7 +185,7 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
int64_to_TimeInternal(hdr->correctionfield,
&correction_field);
pp_update_peer_delay(ppi,& correction_field, 0);
pp_update_peer_delay(ppi, &correction_field, 0);
}
} else {
PP_VPRINTF("pp_slave : PDelay Resp doesn'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