Commit 5e656056 authored by Adam Wujek's avatar Adam Wujek

lib: move events-ptp from wrc_main.c to a new file

Saves for wrpc 404B
Signed-off-by: 's avatarAdam Wujek <adam.wujek@creotech.pl>
parent 3d0fc82e
......@@ -43,6 +43,7 @@
#include <hw/wr_streamers.h>
#include <wrc-event.h>
#include <lib/events-ptp.h>
#include "ertm15_rf_distr.h"
#include "rf_frame_transceiver.h"
......@@ -1186,6 +1187,7 @@ int wrc_board_init()
int wrc_board_create_tasks()
{
wrc_task_create("events-ptp", wrc_events_ptp_init, wrc_events_ptp_poll);
return 0;
}
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2020 CERN (www.cern.ch)
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* Released according to the GNU LGPL, version 2.1 or any later version.
*/
#include <wrpc.h>
#include "event.h"
static int prev_ptp_mode;
static int prev_ptp_state;
static int prev_servo_state;
static int prev_timing_ok;
void wrc_events_ptp_init(void)
{
prev_ptp_mode = -1;
prev_ptp_state = -1;
prev_servo_state = -1;
prev_timing_ok = 0;
}
int wrc_events_ptp_poll(void)
{
extern struct pp_instance ppi_static;
struct pp_instance *ppi = &ppi_static;
struct pp_servo *ss = SRV(ppi);//= &((struct wr_data *)ppi->ext_data)->servo_state;
int mode = wrc_ptp_get_mode();
if( mode != prev_ptp_mode )
{
main_dbg("PTP mode changed.\n");
prev_timing_ok = 0;
event_post( WRC_EVENT_PTP_MODE_CHANGED );
}
prev_ptp_mode = mode;
// observe the PTP state machine transitions and the servo state - and depending on the mode of
// operation (master/slave), send the 'Timing up'/'Timing down' events.
if( mode == WRC_MODE_MASTER )
{
if( ppi->state == PPS_MASTER && prev_ptp_state != PPS_MASTER )
{
prev_timing_ok = 1;
event_post( WRC_EVENT_TIMING_UP );
}
else if ( ppi->state != PPS_MASTER && prev_ptp_state == PPS_MASTER )
{
prev_timing_ok = 0;
event_post( WRC_EVENT_TIMING_DOWN );
}
}
else if ( mode == WRC_MODE_SLAVE )
{
if( ppi->state == PPS_SLAVE )
{
if( ss->state == WRH_TRACK_PHASE && prev_servo_state != WRH_TRACK_PHASE )
{
prev_timing_ok = 1;
event_post( WRC_EVENT_TIMING_UP );
}
else if( ss->state != WRH_TRACK_PHASE && prev_servo_state == WRH_TRACK_PHASE )
{
prev_timing_ok = 0;
event_post( WRC_EVENT_TIMING_DOWN );
}
}
else if( ppi->state != PPS_SLAVE && prev_ptp_state == PPS_SLAVE )
{
prev_timing_ok = 0;
event_post( WRC_EVENT_TIMING_DOWN );
}
}
prev_ptp_state = ppi->state;
prev_servo_state = ss->state;
return 1;
}
void wrc_events_ptp_link_down(void)
{
prev_timing_ok = 0;
}
int wrc_is_timing_up(void)
{
return prev_timing_ok;
}
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2020 CERN (www.cern.ch)
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* Released according to the GNU LGPL, version 2.1 or any later version.
*/
#ifndef __EVENTS_PTP_H
#define __EVENTS_PTP_H
void wrc_events_ptp_init(void);
int wrc_events_ptp_poll(void);
int wrc_is_timing_up(void);
void wrc_events_ptp_link_down(void);
#endif /* __EVENTS_PTP_H */
obj-y += lib/util.o lib/wrc-tasks.o
obj-y += \
lib/util.o \
lib/wrc-tasks.o \
lib/events-ptp.o \
obj-$(CONFIG_LM32) += \
lib/assert.o \
......@@ -17,3 +20,4 @@ obj-$(CONFIG_NETCONSOLE) += lib/netconsole.o
# below requires $(AUTOCONF_PPSI) to be present before build
REQUIRE_AUTOCONF_PPSI += \
lib/net.o \
lib/events-ptp.o \
......@@ -60,12 +60,6 @@ uint32_t cal_phase_transition = 2389;
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;
struct wr_endpoint_device wrc_endpoint_dev;
int wrc_wr_diags(void); // fixme: move the header
......@@ -140,7 +134,7 @@ static int wrc_check_link(void)
rv = 1;
} else if (prev_state && !state) {
wrc_verbose("Link down.\n");
prev_timing_ok = 0;
wrc_events_ptp_link_down();
event_post( WRC_EVENT_LINK_DOWN );
gen_gpio_out(&pin_sysc_led_link, 0);
link_status = NETIF_LINK_WENT_DOWN;
......@@ -196,79 +190,6 @@ static int update_uptime(void)
return 0;
}
int wrc_is_timing_up()
{
return prev_timing_ok;
}
static void wrc_dispatch_ptp_events_init(void)
{
prev_ptp_mode = -1;
prev_ptp_state = -1;
prev_servo_state = -1;
prev_timing_ok = 0;
}
static int wrc_dispatch_ptp_events_poll(void)
{
extern struct pp_instance ppi_static;
struct pp_instance *ppi = &ppi_static;
struct pp_servo *ss = SRV(ppi);//= &((struct wr_data *)ppi->ext_data)->servo_state;
int mode = wrc_ptp_get_mode();
if( mode != prev_ptp_mode )
{
main_dbg("PTP mode changed.\n");
prev_timing_ok = 0;
event_post( WRC_EVENT_PTP_MODE_CHANGED );
}
prev_ptp_mode = mode;
// observe the PTP state machine transitions and the servo state - and depending on the mode of
// operation (master/slave), send the 'Timing up'/'Timing down' events.
if( mode == WRC_MODE_MASTER )
{
if( ppi->state == PPS_MASTER && prev_ptp_state != PPS_MASTER )
{
prev_timing_ok = 1;
event_post( WRC_EVENT_TIMING_UP );
}
else if ( ppi->state != PPS_MASTER && prev_ptp_state == PPS_MASTER )
{
prev_timing_ok = 0;
event_post( WRC_EVENT_TIMING_DOWN );
}
}
else if ( mode == WRC_MODE_SLAVE )
{
if( ppi->state == PPS_SLAVE )
{
if( ss->state == WRH_TRACK_PHASE && prev_servo_state != WRH_TRACK_PHASE )
{
prev_timing_ok = 1;
event_post( WRC_EVENT_TIMING_UP );
}
else if( ss->state != WRH_TRACK_PHASE && prev_servo_state == WRH_TRACK_PHASE )
{
prev_timing_ok = 0;
event_post( WRC_EVENT_TIMING_DOWN );
}
}
else if( ppi->state != PPS_SLAVE && prev_ptp_state == PPS_SLAVE )
{
prev_timing_ok = 0;
event_post( WRC_EVENT_TIMING_DOWN );
}
}
prev_ptp_state = ppi->state;
prev_servo_state = ss->state;
return 1;
}
static void create_tasks(void)
{
struct wrc_task *t;
......@@ -284,7 +205,7 @@ static void create_tasks(void)
wrc_task_create( "ptp_bmc", NULL, wrc_ptp_bmc_update);
wrc_task_create( "shell+gui", shell_boot_script, ui_update );
wrc_task_create( "spll-bh", NULL, spll_update );
wrc_task_create( "ptp-events", wrc_dispatch_ptp_events_init, wrc_dispatch_ptp_events_poll );
//wrc_task_create( "temperature", wrc_temp_init, wrc_temp_refresh );
t = wrc_task_create( "net-bh", NULL, net_bh_poll );
......
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