Commit 9e4a90c7 authored by Alessandro Rubini's avatar Alessandro Rubini

open-close: merge extension into std, using hooks

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent a43f3182
......@@ -308,6 +308,8 @@ static inline struct pp_servo *SRV(struct pp_instance *ppi)
*/
struct pp_ext_hooks {
int (*init)(struct pp_instance *ppi, unsigned char *pkt, int plen);
int (*open)(struct pp_instance *ppi, struct pp_runtime_opts *rt_opts);
int (*close)(struct pp_instance *ppi);
};
extern struct pp_ext_hooks pp_hooks; /* The one for the extension we build */
......
......@@ -16,7 +16,6 @@ OBJ-libwr := $D/fsm-table.o \
$D/arith.o \
$D/servo.o \
$D/hooks.o \
$D/open-close.o \
$D/state-wr-present.o \
$D/state-wr-m-lock.o \
$D/state-wr-s-lock.o \
......
......@@ -16,7 +16,19 @@ static int wr_init(struct pp_instance *ppi, unsigned char *pkt, int plen)
return 0;
}
/* This currently only works with one interface (i.e. WR Node) */
static int wr_open(struct pp_instance *ppi, struct pp_runtime_opts *rt_opts)
{
static struct wr_data_t wr_data; /* WR-specific global data */
rt_opts->iface_name = "wr1";
ppi->ext_data = &wr_data;
return 0;
}
struct pp_ext_hooks pp_hooks = {
.init = wr_init,
.open = wr_open,
};
/*
* Aurelio Colosimo for CERN, 2011 -- GNU LGPL v2.1 or later
*/
#include <ppsi/ppsi.h>
#include <ppsi/diag.h>
#include "wr-api.h"
/*
* This file deals with opening and closing an instance. The channel
* must already have been created. In practices, this initializes the
* state machine to the first state.
*
* A protocol extension can override none or both of these functions.
*/
struct pp_runtime_opts default_rt_opts = {
.clock_quality = {
.clockClass = PP_DEFAULT_CLOCK_CLASS,
.clockAccuracy = PP_DEFAULT_CLOCK_ACCURACY,
.offsetScaledLogVariance = PP_DEFAULT_CLOCK_VARIANCE,
},
.iface_name = "wr1",
.inbound_latency = {0, PP_DEFAULT_INBOUND_LATENCY},
.outbound_latency = {0, PP_DEFAULT_OUTBOUND_LATENCY},
.max_rst = PP_DEFAULT_MAX_RESET,
.max_dly = PP_DEFAULT_MAX_DELAY,
.no_adjust = PP_DEFAULT_NO_ADJUST,
.no_rst_clk = PP_DEFAULT_NO_RESET_CLOCK,
.ap = PP_DEFAULT_AP,
.ai = PP_DEFAULT_AI,
.s = PP_DEFAULT_DELAY_S,
.ethernet_mode = PP_DEFAULT_ETHERNET_MODE,
.e2e_mode = PP_DEFAULT_E2E_MODE,
.gptp_mode = PP_DEFAULT_GPTP_MODE,
.ofst_first_updated = 0, /* FIXME: is it a option or a state var? */
.max_foreign_records = PP_DEFAULT_MAX_FOREIGN_RECORDS,
.cur_utc_ofst = PP_DEFAULT_UTC_OFFSET,
.announce_intvl = PP_DEFAULT_ANNOUNCE_INTERVAL,
.sync_intvl = PP_DEFAULT_SYNC_INTERVAL,
.prio1 = PP_DEFAULT_PRIORITY1,
.prio2 = PP_DEFAULT_PRIORITY2,
.domain_number = PP_DEFAULT_DOMAIN_NUMBER,
.ttl = PP_DEFAULT_TTL,
};
static struct wr_data_t wr_data; /* white rabbit specific global data */
int pp_open_instance(struct pp_instance *ppi, struct pp_runtime_opts *rt_opts)
{
if (rt_opts)
ppi->rt_opts = rt_opts;
else
ppi->rt_opts = &default_rt_opts;
ppi->ext_data = &wr_data;
ppi->state = PPS_INITIALIZING;
return 0;
}
int pp_close_instance(struct pp_instance *ppi)
{
/* Nothing to do by now */
return 0;
}
......@@ -9,8 +9,6 @@
* This file deals with opening and closing an instance. The channel
* must already have been created. In practices, this initializes the
* state machine to the first state.
*
* A protocol extension can override none or both of these functions.
*/
struct pp_runtime_opts default_rt_opts = {
......@@ -51,11 +49,14 @@ int pp_open_instance(struct pp_instance *ppi, struct pp_runtime_opts *rt_opts)
ppi->state = PPS_INITIALIZING;
if (pp_hooks.open)
return pp_hooks.open(ppi, ppi->rt_opts);
return 0;
}
int pp_close_instance(struct pp_instance *ppi)
{
/* Nothing to do by now */
if (pp_hooks.open)
return pp_hooks.close(ppi);
return 0;
}
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