Commit 6f5b3eb6 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski

wrc_main: implement wrc_is_timing_up() API function

parent 0bb4615c
...@@ -75,4 +75,7 @@ void rtipc_action(void); ...@@ -75,4 +75,7 @@ void rtipc_action(void);
/* div64.c, lifted from the linux kernel through pp_printf or ppsi */ /* div64.c, lifted from the linux kernel through pp_printf or ppsi */
extern uint32_t __div64_32(uint64_t *n, uint32_t base); extern uint32_t __div64_32(uint64_t *n, uint32_t base);
int wrc_is_timing_up(void);
#endif /* __WRC_H__ */ #endif /* __WRC_H__ */
...@@ -62,6 +62,12 @@ uint32_t cal_phase_transition = 2389; ...@@ -62,6 +62,12 @@ uint32_t cal_phase_transition = 2389;
int wrc_vlan_number = CONFIG_VLAN_NR; int wrc_vlan_number = CONFIG_VLAN_NR;
// fixme: this probably deserves to be moved to another file...
static int prev_ptp_mode;
static int prev_ptp_state;
static int prev_servo_state;
static int prev_timing_ok;
static void wrc_initialize(void) static void wrc_initialize(void)
{ {
uint8_t mac_addr[6]; uint8_t mac_addr[6];
...@@ -132,6 +138,7 @@ static int wrc_check_link(void) ...@@ -132,6 +138,7 @@ static int wrc_check_link(void)
rv = 1; rv = 1;
} else if (prev_state && !state) { } else if (prev_state && !state) {
wrc_verbose("Link down.\n"); wrc_verbose("Link down.\n");
prev_timing_ok = 0;
event_post( WRC_EVENT_LINK_DOWN ); event_post( WRC_EVENT_LINK_DOWN );
gen_gpio_out(&pin_sysc_led_link, 0); gen_gpio_out(&pin_sysc_led_link, 0);
link_status = LINK_WENT_DOWN; link_status = LINK_WENT_DOWN;
...@@ -189,16 +196,17 @@ static int update_uptime(void) ...@@ -189,16 +196,17 @@ static int update_uptime(void)
return 0; return 0;
} }
// fixme: this probably deserves to be moved to another file... int wrc_is_timing_up()
static int prev_ptp_mode; {
static int prev_ptp_state; return prev_timing_ok;
static int prev_servo_state; }
static void wrc_dispatch_ptp_events_init(void) static void wrc_dispatch_ptp_events_init(void)
{ {
prev_ptp_mode = -1; prev_ptp_mode = -1;
prev_ptp_state = -1; prev_ptp_state = -1;
prev_servo_state = -1; prev_servo_state = -1;
prev_timing_ok = 0;
} }
static void wrc_dispatch_ptp_events_poll(void) static void wrc_dispatch_ptp_events_poll(void)
...@@ -212,6 +220,7 @@ static void wrc_dispatch_ptp_events_poll(void) ...@@ -212,6 +220,7 @@ static void wrc_dispatch_ptp_events_poll(void)
if( mode != prev_ptp_mode ) if( mode != prev_ptp_mode )
{ {
main_dbg("PTP mode changed.\n"); main_dbg("PTP mode changed.\n");
prev_timing_ok = 0;
event_post( WRC_EVENT_PTP_MODE_CHANGED ); event_post( WRC_EVENT_PTP_MODE_CHANGED );
} }
...@@ -222,21 +231,34 @@ static void wrc_dispatch_ptp_events_poll(void) ...@@ -222,21 +231,34 @@ static void wrc_dispatch_ptp_events_poll(void)
if( mode == WRC_MODE_MASTER ) if( mode == WRC_MODE_MASTER )
{ {
if( ppi->state == PPS_MASTER && prev_ptp_state != PPS_MASTER ) if( ppi->state == PPS_MASTER && prev_ptp_state != PPS_MASTER )
{
prev_timing_ok = 1;
event_post( WRC_EVENT_TIMING_UP ); event_post( WRC_EVENT_TIMING_UP );
}
else if ( ppi->state != PPS_MASTER && prev_ptp_state == PPS_MASTER ) else if ( ppi->state != PPS_MASTER && prev_ptp_state == PPS_MASTER )
{
prev_timing_ok = 0;
event_post( WRC_EVENT_TIMING_DOWN ); event_post( WRC_EVENT_TIMING_DOWN );
}
} }
else if ( mode == WRC_MODE_SLAVE ) else if ( mode == WRC_MODE_SLAVE )
{ {
if( ppi->state == PPS_SLAVE ) if( ppi->state == PPS_SLAVE )
{ {
if( ss->state == WR_TRACK_PHASE && prev_servo_state != WR_TRACK_PHASE ) if( ss->state == WR_TRACK_PHASE && prev_servo_state != WR_TRACK_PHASE )
{
prev_timing_ok = 1;
event_post( WRC_EVENT_TIMING_UP ); event_post( WRC_EVENT_TIMING_UP );
}
else if( ss->state != WR_TRACK_PHASE && prev_servo_state == WR_TRACK_PHASE ) else if( ss->state != WR_TRACK_PHASE && prev_servo_state == WR_TRACK_PHASE )
{
prev_timing_ok = 0;
event_post( WRC_EVENT_TIMING_DOWN ); event_post( WRC_EVENT_TIMING_DOWN );
}
} }
else if( ppi->state != PPS_SLAVE && prev_ptp_state == PPS_SLAVE ) else if( ppi->state != PPS_SLAVE && prev_ptp_state == PPS_SLAVE )
{ {
prev_timing_ok = 0;
event_post( WRC_EVENT_TIMING_DOWN ); event_post( WRC_EVENT_TIMING_DOWN );
} }
} }
......
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