Commit 458391e2 authored by Alessandro Rubini's avatar Alessandro Rubini Committed by Aurelio Colosimo

diag-fsm: add names to states, add enum for enter/leave

parent c0398417
...@@ -8,17 +8,17 @@ ...@@ -8,17 +8,17 @@
* This has diagnostics. It calls pp_printf (which one, we don't know) * This has diagnostics. It calls pp_printf (which one, we don't know)
*/ */
void pp_diag_fsm(struct pp_instance *ppi, int sequence, int plen) void pp_diag_fsm(struct pp_instance *ppi, char *name, int sequence, int plen)
{ {
if (!sequence) { if (sequence == STATE_ENTER) {
/* enter with or without a packet len */ /* enter with or without a packet len */
pp_printf("fsm for %p: ENTER %3i (packet len %i)\n", pp_printf("fsm for %p: ENTER %3i (%s), packet len %i\n",
ppi, ppi->state, plen); ppi, ppi->state, name, plen);
return; return;
} }
/* leave has one \n more, so different states are separate */ /* leave has one \n more, so different states are separate */
pp_printf("fsm for %p: LEAVE %3i (next: %3i in %i ms)\n\n", pp_printf("fsm for %p: LEAVE %3i (%s) (next: %3i in %i ms)\n\n",
ppi, ppi->state, ppi->next_state, ppi->next_delay); ppi, ppi->state, name, ppi->next_state, ppi->next_delay);
} }
void pp_diag_trace(struct pp_instance *ppi, const char *f, int line) void pp_diag_trace(struct pp_instance *ppi, const char *f, int line)
......
...@@ -30,13 +30,13 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen) ...@@ -30,13 +30,13 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
/* found: handle this state */ /* found: handle this state */
ppi->next_state = state; ppi->next_state = state;
ppi->next_delay = 0; ppi->next_delay = 0;
pp_diag_fsm(ppi, 0 /* enter */, plen); pp_diag_fsm(ppi, ip->name, STATE_ENTER, plen);
err = ip->f1(ppi, packet, plen); err = ip->f1(ppi, packet, plen);
if (!err && ip->f2) if (!err && ip->f2)
err = ip->f2(ppi, packet, plen); err = ip->f2(ppi, packet, plen);
if (err) if (err)
pp_diag_error(ppi, err); pp_diag_error(ppi, err);
pp_diag_fsm(ppi, 1 /* leave */, 0 /* unused */); pp_diag_fsm(ppi, ip->name, STATE_LEAVE, 0 /* unused */);
ppi->is_new_state = 0; ppi->is_new_state = 0;
......
...@@ -13,7 +13,12 @@ ...@@ -13,7 +13,12 @@
* strerror(errno) together with the explanation. Avoid diag_printf if * strerror(errno) together with the explanation. Avoid diag_printf if
* possible, for size reasons, but here it is anyways. * possible, for size reasons, but here it is anyways.
*/ */
extern void pp_diag_fsm(struct pp_instance *ppi, int sequence, int plen); enum {
STATE_ENTER,
STATE_LEAVE
};
extern void pp_diag_fsm(struct pp_instance *ppi, char *name, int seq, int plen);
extern void pp_diag_trace(struct pp_instance *ppi, const char *f, int line); extern void pp_diag_trace(struct pp_instance *ppi, const char *f, int line);
extern void pp_diag_error(struct pp_instance *ppi, int err); extern void pp_diag_error(struct pp_instance *ppi, int err);
extern void pp_diag_error_str2(struct pp_instance *ppi, char *s1, char *s2); extern void pp_diag_error_str2(struct pp_instance *ppi, char *s1, char *s2);
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#define ETH_P_1588 0x88F7 #define ETH_P_1588 0x88F7
#endif #endif
#define __weak __attribute__((weak))
/* Macros for diagnostic prints. Set pp_diag_verbosity as 0 or 1 (PP_V macros /* Macros for diagnostic prints. Set pp_diag_verbosity as 0 or 1 (PP_V macros
* disabled/enabled) */ * disabled/enabled) */
extern int pp_diag_verbosity; extern int pp_diag_verbosity;
...@@ -352,6 +354,7 @@ extern const Integer32 PP_ADJ_FREQ_MAX; ...@@ -352,6 +354,7 @@ extern const Integer32 PP_ADJ_FREQ_MAX;
struct pp_state_table_item { struct pp_state_table_item {
int state; int state;
char *name;
int (*f1)(struct pp_instance *ppi, uint8_t *packet, int plen); int (*f1)(struct pp_instance *ppi, uint8_t *packet, int plen);
int (*f2)(struct pp_instance *ppi, uint8_t *packet, int plen); int (*f2)(struct pp_instance *ppi, uint8_t *packet, int plen);
}; };
......
...@@ -10,15 +10,15 @@ ...@@ -10,15 +10,15 @@
* the linker can avoid pulling this data space if another table is there. * the linker can avoid pulling this data space if another table is there.
*/ */
struct pp_state_table_item pp_state_table[] = { struct pp_state_table_item pp_state_table[] __weak = {
{ PPS_INITIALIZING, pp_initializing,}, { PPS_INITIALIZING, "initializing", pp_initializing,},
{ PPS_FAULTY, pp_faulty,}, { PPS_FAULTY, "faulty", pp_faulty,},
{ PPS_DISABLED, pp_disabled,}, { PPS_DISABLED, "disabled", pp_disabled,},
{ PPS_LISTENING, pp_listening,}, { PPS_LISTENING, "listening", pp_listening,},
{ PPS_PRE_MASTER, pp_pre_master,}, { PPS_PRE_MASTER, "pre-master", pp_pre_master,},
{ PPS_MASTER, pp_master,}, { PPS_MASTER, "master", pp_master,},
{ PPS_PASSIVE, pp_passive,}, { PPS_PASSIVE, "passive", pp_passive,},
{ PPS_UNCALIBRATED, pp_uncalibrated,}, { PPS_UNCALIBRATED, "uncalibrated", pp_uncalibrated,},
{ PPS_SLAVE, pp_slave,}, { PPS_SLAVE, "slave", pp_slave,},
{ PPS_END_OF_TABLE,} { PPS_END_OF_TABLE,}
}; };
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