Commit 863f8160 authored by Omar Gabella's avatar Omar Gabella

Add MON_TO_DEBUG build option

parent c2ebb355
......@@ -71,12 +71,14 @@ int wrpc_enable_timing_output(struct pp_instance *ppi, int enable)
int wrpc_adjust_in_progress_broadcast(struct pp_instance *ppi)
{
#ifdef MON_TO_DEBUG
if (shw_pps_gen_busy()) {
WR_DSPOR(ppi)->ctr_shw_pps_gen_busy++;
}
if (spll_shifter_busy(0)) {
WR_DSPOR(ppi)->ctr_spll_shifter_busy++;
}
#endif
return shw_pps_gen_busy() || spll_shifter_busy(0);
}
......
......@@ -163,6 +163,10 @@ static int wr_handle_resp(struct pp_instance *ppi)
static void wr_s1(struct pp_instance *ppi, MsgHeader *hdr, MsgAnnounce *ann)
{
#ifdef MON_TO_DEBUG
// TMP BROADCAST
WR_DSPOR(ppi)->mon_ext_specific = ann->ext_specific;
#endif
pp_diag(ppi, ext, 2, "hook: %s\n", __func__);
WR_DSPOR(ppi)->parentIsWRnode =
((ann->ext_specific & WR_NODE_MODE) != NON_WR);
......@@ -194,6 +198,7 @@ static int wr_execute_slave(struct pp_instance *ppi)
static int wr_handle_announce(struct pp_instance *ppi)
{
#ifdef MON_TO_DEBUG
// TEST TMP
WR_DSPOR(ppi)->ctr_wr_handle_announce+=1;
// TEST TMP
......@@ -204,14 +209,17 @@ static int wr_handle_announce(struct pp_instance *ppi)
if (!WR_DSPOR(ppi)->wrModeOn) {
WR_DSPOR(ppi)->ctr_wrModeOn += 1;
}
#endif
pp_diag(ppi, ext, 2, "hook: %s\n", __func__);
if ((WR_DSPOR(ppi)->wrConfig & WR_S_ONLY) &&
(1 /* FIXME: Recommended State, see page 33*/) &&
(WR_DSPOR(ppi)->parentWrConfig & WR_M_ONLY) &&
(!WR_DSPOR(ppi)->wrModeOn || !WR_DSPOR(ppi)->parentWrModeOn)) {
#ifdef BROADCAST
#ifdef MON_TO_DEBUG
// TMP KM3
WR_DSPOR(ppi)->counter_goto_wrlinkon+=1;
#endif
/* We don't want to start the handshake procedure in broadcast mode. */
WR_DSPOR(ppi)->wrMode = WR_SLAVE; // Done in wr_handshake_init
ppi->next_state = WRS_WR_LINK_ON;
......@@ -226,17 +234,20 @@ static int wr_handle_announce(struct pp_instance *ppi)
static int wr_handle_followup(struct pp_instance *ppi,
struct pp_time *t1) /* t1 == &ppi->t1 */
{
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->ctr_handle_followup+=1;
#endif
pp_diag(ppi, ext, 2, "hook: %s\n", __func__);
if (!WR_DSPOR(ppi)->wrModeOn)
return 0;
wr_servo_got_sync(ppi, t1, &ppi->t2);
#ifdef BROADCAST
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->ctr_before_update_servo+=1;
#endif
/* If broadcast we update the offset time.
* If not, check if we work on p2p to do so. */
wr_servo_update(ppi);
......
......@@ -17,10 +17,10 @@ int wr_link_on(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
struct wr_dsport *wrp = WR_DSPOR(ppi);
int e = 0;
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->counter_wrlinkon_state+=1;
#endif
wrp->wrModeOn = TRUE;
wrp->ops->enable_ptracker(ppi);
......
......@@ -56,8 +56,6 @@ struct wr_dsport {
// TMP TEST
UInteger32 counter_PP_TO_ANN_RECEIPT;
UInteger32 counter_after_timeout_check;
UInteger32 counter_before_timeout_check;
UInteger32 counter_slave_state;
UInteger32 counter_listening_state;
UInteger32 counter_wrlinkon_state;
......@@ -93,6 +91,9 @@ struct wr_dsport {
UInteger32 ctr_servo_busy;
UInteger32 ctr_shw_pps_gen_busy;
UInteger32 ctr_spll_shifter_busy;
#ifdef MON_TO_DEBUG
UInteger16 mon_ext_specific;
#endif
};
/* This uppercase name matches "DSPOR(ppi)" used by standard protocol */
......
......@@ -20,9 +20,11 @@ struct pp_time faulty_stamps[6]; /* if unused, dropped at link time */
static void apply_faulty_stamp_bc(struct pp_instance *ppi, struct wr_servo_state *s, int index)
{
if (HAS_FAULTS) {
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->ctr_has_faults++;
assert(index >= 1 && index <= 6, "Wrong T index %i\n", index);
#endif
assert(index >= 1 && index <= 6, "Wrong T index %i\n", index);
pp_time_add(&s->t1 + index - 1, faulty_stamps + index - 1);
}
}
......@@ -216,8 +218,10 @@ int wr_servo_init(struct pp_instance *ppi)
s->cur_setpoint %= s->clock_period_ps;
wrp->ops->adjust_phase(s->cur_setpoint);
s->missed_iters = 0;
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->ctr_servo_uninitialized+=1;
#endif
s->state = WR_UNINITIALIZED;
#ifdef BROADCAST
/* Fixed delays are irrelevant in broadcast but
......@@ -466,27 +470,30 @@ int wr_e2e_offset_downlink(struct pp_instance *ppi,
uint64_t big_delta_fix;
uint64_t delay_ms_fix;
static int errcount;
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->ctr_update_downlink_servo+=1;
#endif
if (is_incorrect(&s->t1) || is_incorrect(&s->t2)) {
errcount++;
if (errcount > 5) /* a 2-3 in a row are expected */
{
pp_error("%s: TimestampsIncorrect: %d %d\n", __func__,
!is_incorrect(&s->t1), !is_incorrect(&s->t2));
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->ctr_downlink_timestamp_error+=1;
#endif
// TMP TEST
WR_DSPOR(ppi)->wrModeOn = FALSE;
// to try wr_servo_reset(ppi);
/* wr_servo_init(ppi); Tried but CLB remains on UNINITIALIZED servo state */
}
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->ctr_downlink_timestamp_errorcount+=1;
return 0;
#endif
return 0;
}
if (wrp->ops->servo_hook) /* FIXME: check this, missing in p2p */
......@@ -575,10 +582,10 @@ int wr_servo_update(struct pp_instance *ppi)
int32_t ts_offset_ticks;
int32_t ts_offset_picos;
int locking_poll_ret;
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->ctr_update_servo+=1;
#endif
if (!got_sync)
return 0;
......@@ -589,10 +596,11 @@ int wr_servo_update(struct pp_instance *ppi)
#ifdef BROADCAST
if (!wr_e2e_offset_downlink(ppi, s, &ts_offset))
goto out;
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->ts_offset.secs = ts_offset.secs;
WR_DSPOR(ppi)->ts_offset.scaled_nsecs = ts_offset.scaled_nsecs;
#endif
#else
if (CONFIG_HAS_P2P && ppi->mech == PP_P2P_MECH) {
if (!wr_p2p_offset(ppi, s, &ts_offset))
......@@ -622,14 +630,17 @@ int wr_servo_update(struct pp_instance *ppi)
if (!wrp->ops->adjust_in_progress_bc(ppi)) {
s->flags &= ~WR_FLAG_WAIT_HW;
} else {
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->ctr_servo_busy++;
#endif
pp_diag(ppi, servo, 1, "servo:busy\n");
goto out;
}
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->ctr_servo_busy = 0;
#endif
/* So, we didn't return. Choose the right state */
if (ts_offset.secs) /* so bad... */
s->state = WR_SYNC_TAI;
......@@ -654,9 +665,11 @@ int wr_servo_update(struct pp_instance *ppi)
* does not converge. */
if(no_converge_counter > WR_SERVO_MAX_NO_CONVERGE_COUNT)
{
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->ctr_ctr_no_converge+=1;
WR_DSPOR(ppi)->wrModeOn = FALSE;
#endif
WR_DSPOR(ppi)->wrModeOn = FALSE;
//WR_DSPOR(ppi)->parentWrModeOn = FALSE;
//seems not necessary shw_pps_gen_enable_output(0);
wr_servo_reset(ppi);
......@@ -665,12 +678,16 @@ int wr_servo_update(struct pp_instance *ppi)
}
no_converge_counter++;
#endif
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->ctr_before_servo_states+=1;
#endif
switch (s->state) {
case WR_SYNC_TAI:
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->ctr_servo_sync_tai+=1;
#endif
wrp->ops->adjust_counters(ts_offset.secs, 0);
s->flags |= WR_FLAG_WAIT_HW;
/*
......@@ -682,16 +699,20 @@ int wr_servo_update(struct pp_instance *ppi)
break;
case WR_SYNC_NSEC:
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->ctr_servo_sync_nsec+=1;
#endif
wrp->ops->adjust_counters(0, ts_offset_ticks);
s->flags |= WR_FLAG_WAIT_HW;
s->state = WR_SYNC_PHASE;
break;
case WR_SYNC_PHASE:
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->ctr_servo_sync_phase+=1;
#endif
pp_diag(ppi, servo, 2, "oldsetp %i, offset %i:%04i\n",
s->cur_setpoint, ts_offset_ticks,
ts_offset_picos);
......@@ -716,9 +737,10 @@ int wr_servo_update(struct pp_instance *ppi)
break;
case WR_WAIT_OFFSET_STABLE:
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->ctr_servo_wait_offset_stable+=1;
#endif
/* ts_to_picos() below returns phase alone */
remaining_offset = abs(ts_offset_picos);
if(remaining_offset < WR_SERVO_OFFSET_STABILITY_THRESHOLD) {
......@@ -735,8 +757,10 @@ int wr_servo_update(struct pp_instance *ppi)
break;
case WR_TRACK_PHASE:
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->ctr_servo_track_phase+=1;
#endif
s->skew = s->delta_ms - s->delta_ms_prev;
#ifdef TRACK_PHASE_NOT_FOUND
......
......@@ -94,9 +94,10 @@ int st_com_execute_slave(struct pp_instance *ppi)
&& (ppi->role != PPSI_ROLE_SLAVE)) {
ppi->next_state = PPS_MASTER;
} else {
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->counter_PP_TO_ANN_RECEIPT++;
#endif
ppi->next_state = PPS_LISTENING;
pp_timeout_set(ppi, PP_TO_ANN_RECEIPT);
#ifdef BROADCAST
......@@ -259,9 +260,10 @@ int st_com_peer_handle_preq(struct pp_instance *ppi, unsigned char *buf,
int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
int len)
{
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->counter_handle_followup+=1;
#endif
MsgFollowUp follow;
int ret = 0;
......@@ -302,11 +304,17 @@ int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
/* Normally done in slave_handle_response, we reinitialise the timeout here after
* a followup message. We use logSyncInterval instead of logMinDelauReqInterval.
* See Table 24.*/
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->ctr_before_timeout_init_1+=1;
if (DSPOR(ppi)->logSyncInterval != hdr->logMessageInterval) {
#endif
if (DSPOR(ppi)->logSyncInterval != hdr->logMessageInterval) {
DSPOR(ppi)->logSyncInterval = hdr->logMessageInterval;
WR_DSPOR(ppi)->ctr_before_timeout_init_2+=1;
pp_timeout_init(ppi);
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->ctr_before_timeout_init_2+=1;
#endif
pp_timeout_init(ppi);
}
#endif
return 0;
......
......@@ -149,9 +149,10 @@ static void __lib_add_foreign(struct pp_instance *ppi, unsigned char *buf)
int pp_lib_handle_announce(struct pp_instance *ppi, unsigned char *buf, int len)
{
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->counter_handle_announce+=1;
#endif
__lib_add_foreign(ppi, buf);
ppi->next_state = bmc(ppi); /* got a new announce: run bmc */
pp_timeout_set(ppi, PP_TO_ANN_RECEIPT);
......
......@@ -12,10 +12,10 @@
int pp_listening(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
int e = 0; /* error var, to check errors in msg handling */
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->counter_listening_state+=1;
#endif
pp_timeout_set(ppi, PP_TO_FAULT); /* no fault as long as we listen */
if (pp_hooks.listening)
e = pp_hooks.listening(ppi, pkt, plen);
......
......@@ -77,10 +77,10 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
int e = 0; /* error var, to check errors in msg handling */
MsgHeader *hdr = &ppi->received_ptp_header;
#ifdef MON_TO_DEBUG
// TMP TEST
WR_DSPOR(ppi)->counter_slave_state+=1;
#endif
if (ppi->is_new_state) {
memset(&ppi->t1, 0, sizeof(ppi->t1));
pp_servo_init(ppi);
......
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