Commit c79743b9 authored by Aurelio Colosimo's avatar Aurelio Colosimo

wr state machine functions skeleton

This patch introduces the state machine for white rabbit.
It is intended as a flat state machine, so that the application state is
univocally determined by its ppsi->state variable. Internally, each state
function saves the Port Dataset, keeping the double level of states: portState
for general state, and wrPortState as White Rabbit FSM. This permits to be
logically coherent with the specification document (which defines an internal
WR state machine) and to have a simplified approach in the source code.
parent ee45a0a6
......@@ -23,6 +23,14 @@ OBJ-libwr := $W/fsm-table.o \
$W/arith.o \
$W/servo.o \
$W/open-close.o \
$W/state-wr-present.o \
$W/state-wr-m-lock.o \
$W/state-wr-s-lock.o \
$W/state-wr-locked.o \
$W/state-wr-calibration.o \
$W/state-wr-calibrated.o \
$W/state-wr-resp-calib-req.o \
$W/state-wr-link-on.o \
$W/wr_msg.o
$(TARGET).o: $(LIBWR)
......
......@@ -3,6 +3,7 @@
*/
#include <ppsi/ppsi.h>
#include "wr_api.h"
/*
* This is the default state machine table. It is weak so an extension
......@@ -20,5 +21,13 @@ struct pp_state_table_item pp_state_table[] __weak = {
{ PPS_PASSIVE, "passive", pp_passive,},
{ PPS_UNCALIBRATED, "uncalibrated", pp_uncalibrated,},
{ PPS_SLAVE, "slave", pp_slave,},
{ WRS_PRESENT, "wr-present", wr_present,},
{ WRS_M_LOCK, "wr-m-lock", wr_m_lock,},
{ WRS_S_LOCK, "wr-s-lock", wr_s_lock,},
{ WRS_LOCKED, "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,},
{ PPS_END_OF_TABLE,}
};
/*
* Aurelio Colosimo for CERN, 2012 -- GNU LGPL v2.1 or later
* Based on PTPd project v. 2.1.0 (see AUTHORS for details)
*/
#include <ppsi/ppsi.h>
#include "wr_api.h"
int wr_calibrated(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
/* FIXME implementation */
if (ppi->is_new_state) {
DSPOR(ppi)->portState = PPS_MASTER;
DSPOR(ppi)->wrPortState = WRS_CALIBRATED;
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
}
return 0;
}
/*
* Aurelio Colosimo for CERN, 2012 -- GNU LGPL v2.1 or later
* Based on PTPd project v. 2.1.0 (see AUTHORS for details)
*/
#include <ppsi/ppsi.h>
#include "wr_api.h"
int wr_calibration(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
/* FIXME implementation */
if (ppi->is_new_state) {
DSPOR(ppi)->portState = PPS_MASTER;
DSPOR(ppi)->wrPortState = WRS_CALIBRATION;
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
}
return 0;
}
/*
* Aurelio Colosimo for CERN, 2012 -- GNU LGPL v2.1 or later
* Based on PTPd project v. 2.1.0 (see AUTHORS for details)
*/
#include <ppsi/ppsi.h>
#include "wr_api.h"
int wr_link_on(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
/* FIXME implementation */
if (ppi->is_new_state) {
/* DSPOR(ppi)->portState depends on previous states, should not
* change when entering in link on, so no need to update it here
*/
DSPOR(ppi)->wrPortState = WRS_WR_LINK_ON;
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
}
return 0;
}
/*
* Aurelio Colosimo for CERN, 2012 -- GNU LGPL v2.1 or later
* Based on PTPd project v. 2.1.0 (see AUTHORS for details)
*/
#include <ppsi/ppsi.h>
#include "wr_api.h"
int wr_locked(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
/* FIXME implementation */
if (ppi->is_new_state) {
DSPOR(ppi)->portState = PPS_SLAVE;
DSPOR(ppi)->wrPortState = WRS_LOCKED;
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
}
return 0;
}
/*
* Aurelio Colosimo for CERN, 2012 -- GNU LGPL v2.1 or later
* Based on PTPd project v. 2.1.0 (see AUTHORS for details)
*/
#include <ppsi/ppsi.h>
#include "wr_api.h"
int wr_m_lock(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
/* FIXME implementation */
if (ppi->is_new_state) {
DSPOR(ppi)->portState = PPS_MASTER;
DSPOR(ppi)->wrPortState = WRS_M_LOCK;
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
}
return 0;
}
/*
* Aurelio Colosimo for CERN, 2012 -- GNU LGPL v2.1 or later
* Based on PTPd project v. 2.1.0 (see AUTHORS for details)
*/
#include <ppsi/ppsi.h>
#include "wr_api.h"
int wr_present(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
/* FIXME implementation */
if (ppi->is_new_state) {
DSPOR(ppi)->portState = PPS_SLAVE;
DSPOR(ppi)->wrPortState = WRS_PRESENT;
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
}
return 0;
}
/*
* Aurelio Colosimo for CERN, 2012 -- GNU LGPL v2.1 or later
* Based on PTPd project v. 2.1.0 (see AUTHORS for details)
*/
#include <ppsi/ppsi.h>
#include "wr_api.h"
int wr_resp_calib_req(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
/* FIXME implementation */
if (ppi->is_new_state) {
DSPOR(ppi)->portState = PPS_SLAVE;
DSPOR(ppi)->wrPortState = WRS_RESP_CALIB_REQ;
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
}
return 0;
}
/*
* Aurelio Colosimo for CERN, 2012 -- GNU LGPL v2.1 or later
* Based on PTPd project v. 2.1.0 (see AUTHORS for details)
*/
#include <ppsi/ppsi.h>
#include "wr_api.h"
int wr_s_lock(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
/* FIXME implementation */
if (ppi->is_new_state) {
DSPOR(ppi)->portState = PPS_SLAVE;
DSPOR(ppi)->wrPortState = WRS_S_LOCK;
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
}
return 0;
}
......@@ -3,5 +3,23 @@
* Based on ptp-noposix
*/
/* Pack White rabbit message in the suffix of PTP announce message */
#include "wr_constants.h"
/* Pack/Unkpack White rabbit message in the suffix of PTP announce message */
void msg_pack_announce_wr_tlv(struct pp_instance *ppi);
void msg_unpack_announce_wr_tlv(void *buf, MsgAnnounce *ann);
/* Pack/Unkpack White rabbit message signaling msg */
int msg_pack_wrsig(struct pp_instance *ppi, Enumeration16 wr_msg_id);
void msg_unpack_wrsig(struct pp_instance *ppi, void *buf,
MsgSignaling *wrsig_msg, Enumeration16 *wr_msg_id);
/* White rabbit state functions */
int wr_present(struct pp_instance *ppi, unsigned char *pkt, int plen);
int wr_m_lock(struct pp_instance *ppi, unsigned char *pkt, int plen);
int wr_s_lock(struct pp_instance *ppi, unsigned char *pkt, int plen);
int wr_locked(struct pp_instance *ppi, unsigned char *pkt, int plen);
int wr_calibration(struct pp_instance *ppi, unsigned char *pkt, int plen);
int wr_calibrated(struct pp_instance *ppi, unsigned char *pkt, int plen);
int wr_resp_calib_req(struct pp_instance *ppi, unsigned char *pkt, int plen);
int wr_link_on(struct pp_instance *ppi, unsigned char *pkt, int plen);
......@@ -109,7 +109,9 @@ enum{
* \brief WR PTP states (new, single FSM) [White Rabbit]
*/
enum {
WRS_PRESENT = 0, WRS_S_LOCK, WRS_M_LOCK, WRS_LOCKED,
/* 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,
/*
each WR main state (except IDLE) has an associated timetout
......
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