Commit 8c270c93 authored by Aurelio Colosimo's avatar Aurelio Colosimo

proto-ext-whiterabbit: implementation and fix of some calibration steps

This major patch implements wr-m-lock, wr-s-lock and wr-locked states,
while fixing bugs in wr-present and master state.
parent ace961a4
...@@ -177,6 +177,19 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -177,6 +177,19 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen)
break; break;
case PPM_SIGNALING:
{
MsgSignaling wrsig_msg;
msg_unpack_wrsig(ppi, pkt, &wrsig_msg,
&(DSPOR(ppi)->msgTmpWrMessageID));
if ((DSPOR(ppi)->msgTmpWrMessageID == SLAVE_PRESENT) &&
(DSPOR(ppi)->wrConfig & WR_M_ONLY))
ppi->next_state = WRS_M_LOCK;
break;
}
default: default:
/* disreguard, nothing to do */ /* disreguard, nothing to do */
break; break;
......
...@@ -8,11 +8,33 @@ ...@@ -8,11 +8,33 @@
int wr_locked(struct pp_instance *ppi, unsigned char *pkt, int plen) int wr_locked(struct pp_instance *ppi, unsigned char *pkt, int plen)
{ {
/* FIXME implementation */ int e = 0;
if (ppi->is_new_state) { if (ppi->is_new_state) {
DSPOR(ppi)->portState = PPS_UNCALIBRATED; DSPOR(ppi)->portState = PPS_UNCALIBRATED;
DSPOR(ppi)->wrPortState = WRS_LOCKED; DSPOR(ppi)->wrPortState = WRS_LOCKED;
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS; pp_timer_start(DSPOR(ppi)->wrStateTimeout / 1000,
ppi->timers[PP_TIMER_WRS_LOCKED]);
e = msg_issue_wrsig(ppi, LOCKED);
}
if (pp_timer_expired(ppi->timers[PP_TIMER_WRS_LOCKED])) {
ppi->next_state = PPS_LISTENING;
DSPOR(ppi)->wrMode = NON_WR;
DSPOR(ppi)->wrPortState = WRS_IDLE;
goto state_updated;
} }
return 0;
no_incoming_msg:
if (e != 0)
ppi->next_state = PPS_FAULTY;
state_updated:
if (ppi->next_state != ppi->state)
pp_timer_stop(ppi->timers[PP_TIMER_WRS_LOCKED]);
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
return e;
} }
...@@ -8,11 +8,47 @@ ...@@ -8,11 +8,47 @@
int wr_m_lock(struct pp_instance *ppi, unsigned char *pkt, int plen) int wr_m_lock(struct pp_instance *ppi, unsigned char *pkt, int plen)
{ {
/* FIXME implementation */ int e = 0;
MsgSignaling wrsig_msg;
if (ppi->is_new_state) { if (ppi->is_new_state) {
DSPOR(ppi)->portState = PPS_MASTER; DSPOR(ppi)->portState = PPS_MASTER;
DSPOR(ppi)->wrPortState = WRS_M_LOCK; DSPOR(ppi)->wrPortState = WRS_M_LOCK;
DSPOR(ppi)->wrMode = WR_MASTER;
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS; ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
e = msg_issue_wrsig(ppi, LOCK);
pp_timer_start(WR_M_LOCK_TIMEOUT_MS / 1000,
ppi->timers[PP_TIMER_WRS_M_LOCK]);
}
if (pp_timer_expired(ppi->timers[PP_TIMER_WRS_M_LOCK])) {
ppi->next_state = PPS_MASTER;
DSPOR(ppi)->wrPortState = WRS_IDLE;
DSPOR(ppi)->wrMode = NON_WR;
goto state_updated;
}
if (plen == 0)
goto no_incoming_msg;
if (ppi->msg_tmp_header.messageType == PPM_SIGNALING) {
msg_unpack_wrsig(ppi, pkt, &wrsig_msg,
&(DSPOR(ppi)->msgTmpWrMessageID));
if (DSPOR(ppi)->msgTmpWrMessageID == LOCKED)
ppi->next_state = WRS_CALIBRATION;
} }
return 0;
no_incoming_msg:
if (e != 0)
ppi->next_state = PPS_FAULTY;
state_updated:
if (ppi->next_state != ppi->state)
pp_timer_stop(ppi->timers[PP_TIMER_WRS_M_LOCK]);
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
return e;
} }
...@@ -11,11 +11,12 @@ int wr_present(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -11,11 +11,12 @@ int wr_present(struct pp_instance *ppi, unsigned char *pkt, int plen)
{ {
int e = 0; int e = 0;
MsgSignaling wrsig_msg;
if (ppi->is_new_state) { if (ppi->is_new_state) {
DSPOR(ppi)->portState = PPS_UNCALIBRATED; DSPOR(ppi)->portState = PPS_UNCALIBRATED;
DSPOR(ppi)->wrPortState = WRS_PRESENT; DSPOR(ppi)->wrPortState = WRS_PRESENT;
DSPOR(ppi)->wrMode = WR_SLAVE; DSPOR(ppi)->wrMode = WR_SLAVE;
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
pp_timer_start(DSPOR(ppi)->wrStateTimeout / 1000, pp_timer_start(DSPOR(ppi)->wrStateTimeout / 1000,
ppi->timers[PP_TIMER_WRS_PRESENT]); ppi->timers[PP_TIMER_WRS_PRESENT]);
st_com_restart_annrec_timer(ppi); st_com_restart_annrec_timer(ppi);
...@@ -24,9 +25,24 @@ int wr_present(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -24,9 +25,24 @@ int wr_present(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (pp_timer_expired(ppi->timers[PP_TIMER_WRS_PRESENT])) { if (pp_timer_expired(ppi->timers[PP_TIMER_WRS_PRESENT])) {
ppi->next_state = PPS_LISTENING; ppi->next_state = PPS_LISTENING;
DSPOR(ppi)->wrMode = NON_WR;
DSPOR(ppi)->wrPortState = WRS_IDLE;
goto state_updated; goto state_updated;
} }
if (plen == 0)
goto no_incoming_msg;
if (ppi->msg_tmp_header.messageType == PPM_SIGNALING) {
msg_unpack_wrsig(ppi, pkt, &wrsig_msg,
&(DSPOR(ppi)->msgTmpWrMessageID));
if (DSPOR(ppi)->msgTmpWrMessageID == LOCK)
ppi->next_state = WRS_S_LOCK;
}
no_incoming_msg:
if (e == 0) if (e == 0)
st_com_execute_slave(ppi, 0); st_com_execute_slave(ppi, 0);
else else
......
...@@ -8,11 +8,33 @@ ...@@ -8,11 +8,33 @@
int wr_s_lock(struct pp_instance *ppi, unsigned char *pkt, int plen) int wr_s_lock(struct pp_instance *ppi, unsigned char *pkt, int plen)
{ {
/* FIXME implementation */ int e = 0;
if (ppi->is_new_state) { if (ppi->is_new_state) {
DSPOR(ppi)->portState = PPS_SLAVE; DSPOR(ppi)->portState = PPS_UNCALIBRATED;
DSPOR(ppi)->wrPortState = WRS_S_LOCK; DSPOR(ppi)->wrPortState = WRS_S_LOCK;
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS; ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
wr_locking_enable(ppi);
pp_timer_start(WR_S_LOCK_TIMEOUT_MS / 1000,
ppi->timers[PP_TIMER_WRS_S_LOCK]);
} }
return 0;
if (pp_timer_expired(ppi->timers[PP_TIMER_WRS_S_LOCK])) {
ppi->next_state = PPS_FAULTY;
DSPOR(ppi)->wrPortState = WRS_IDLE;
DSPOR(ppi)->wrMode = NON_WR;
goto state_updated;
}
if (wr_locking_poll(ppi) == WR_SPLL_READY) {
ppi->next_state = WRS_LOCKED;
wr_locking_disable(ppi);
}
state_updated:
if (ppi->next_state != ppi->state)
pp_timer_stop(ppi->timers[PP_TIMER_WRS_S_LOCK]);
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
return e;
} }
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#define WR_DEFAULT_CAL_PATTERN_LEN 0xA /* 10 bits */ #define WR_DEFAULT_CAL_PATTERN_LEN 0xA /* 10 bits */
#define WR_DEFAULT_STATE_TIMEOUT_MS 2000 /* [ms] (was 300) */ #define WR_DEFAULT_STATE_TIMEOUT_MS 2000 /* [ms] (was 300) */
#define WR_M_LOCK_TIMEOUT_MS 10000
#define WR_S_LOCK_TIMEOUT_MS 10000
#define WR_DEFAULT_STATE_REPEAT 3 #define WR_DEFAULT_STATE_REPEAT 3
#define WR_DEFAULT_INIT_REPEAT 3 #define WR_DEFAULT_INIT_REPEAT 3
......
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