Commit 17cb1360 authored by Alessandro Rubini's avatar Alessandro Rubini

arch-wrpc: major cleanup: now the spec works

This commit removes the part of wrpc.h that is not used.  It was there
when we tried to build a main function in ppsi itself, but now we
depend on the exteranl wrpc-sewpackage to provide drivers and headers,
so wrpc.h is now just for local material.

Then, wrc_ptp_ppsi.c is fixed with regard to globals and all the rest.
Moreover, I moved most of the initialization of static variables into
compile-time assignments instead of run-time, since there's nothing
dynamic here in those fields.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 912d4db3
......@@ -24,48 +24,50 @@
int ptp_mode = WRC_MODE_UNKNOWN;
static int ptp_enabled = 0, ptp_forced_stop = 0;
struct pp_instance ppi_static; /* FIXME: no more static, because used in
tests/measure_t24p.c */
CONST_VERBOSITY int pp_diag_verbosity = 0;
/*ppi fields*/
static DSDefault defaultDS;
static DSCurrent currentDS;
static DSParent parentDS;
static DSPort portDS;
static DSTimeProperties timePropertiesDS;
static struct wr_dsport wr_dsport;
static DSPort portDS = {.ext_dsport = &wr_dsport};
static DSTimeProperties timePropertiesDS;
static struct pp_servo servo;
static int delay_ms = PP_DEFAULT_NEXT_DELAY_MS;
static int start_tics = 0;
static int last_link_up = 0;
/* We now have a structure with all globals, and multiple ppi inside */
static struct pp_globals ppg_static;
static struct pp_globals ppg_static; /* forward declaration */
/* despite the name, ppi_static is not static: tests/measure_t24p.c uses it */
struct pp_instance ppi_static = {
.glbs = &ppg_static,
.defaultDS = &defaultDS,
.currentDS = &currentDS,
.parentDS = &parentDS,
.portDS = &portDS,
.timePropertiesDS = &timePropertiesDS,
.n_ops = &wrpc_net_ops,
.t_ops = &wrpc_time_ops,
};
/* We now have a structure with all globals, and multiple ppi inside */
static struct pp_globals ppg_static = {
.nports = 1,
.pp_instances = &ppi_static,
.servo = &servo,
};
int wrc_ptp_init()
{
struct pp_instance *ppi = &ppi_static; /* no malloc, one instance */
struct pp_globals *ppg = &ppg_static; /* no malloc, one instance */
sdb_find_devices();
uart_init();
pp_printf("Spec: starting. Compiled on " __DATE__ "\n");
ppi->defaultDS = &defaultDS;
ppi->currentDS = &currentDS;
ppi->parentDS = &parentDS;
portDS.ext_dsport = &wr_dsport;
ppi->portDS = &portDS;
ppi->timePropertiesDS = &timePropertiesDS;
ppi->arch_data = NULL;
ppg->nports = 1;
ppg->pp_instances = ppi;
ppg->servo = &servo;
pp_printf("PPSi for WRPC. Compiled on " __DATE__ "\n");
return 0;
}
......@@ -113,7 +115,6 @@ int wrc_ptp_set_mode(int mode)
start_tics = timer_get_tics();
pp_printf("Locking PLL");
shw_pps_gen_enable_output(0);
while (!spll_check_lock(0) && lock_timeout) {
......
......@@ -7,6 +7,7 @@
#include <softpll_ng.h>
#include "wrpc.h"
#include "../proto-ext-whiterabbit/wr-constants.h"
#include "hal_exports.h" /* wrpc-sw */
static int wrpc_read_calibration_data(struct pp_instance *ppi,
uint32_t *deltaTx, uint32_t *deltaRx, int32_t *fix_alpha,
......
......@@ -15,84 +15,16 @@
#define WRC_MODE_SLAVE 3
extern int ptp_mode;
int wrc_ptp_init();
int wrc_ptp_init(void);
int wrc_ptp_set_mode(int mode);
int wrc_ptp_get_mode();
int wrc_ptp_start();
int wrc_ptp_stop();
int wrc_ptp_update();
int wrc_ptp_get_mode(void);
int wrc_ptp_start(void);
int wrc_ptp_stop(void);
int wrc_ptp_update(void);
/* End of wrc-ptp.h */
/*
* These are the functions provided by the various bare files
*/
extern void wrpc_main_loop(struct pp_instance *ppi);
/* FIXME halexp_port_state, to be renamed and moved somewhere else */
typedef struct {
/* When non-zero: port state is valid */
int valid;
/* WR-PTP role of the port (Master, Slave, etc.) */
int mode;
/* TX and RX delays (combined, big Deltas from the link model in the wrpc) */
uint32_t delta_tx;
uint32_t delta_rx;
/* DDMTD raw phase value in picoseconds */
uint32_t phase_val;
/* When non-zero: phase_val contains a valid phase readout */
int phase_val_valid;
/* When non-zero: link is up */
int up;
/* When non-zero: TX path is calibrated (delta_tx contains valid value) */
int tx_calibrated;
/* When non-zero: RX path is calibrated (delta_rx contains valid value) */
int rx_calibrated;
int tx_tstamp_counter;
int rx_tstamp_counter;
int is_locked;
int lock_priority;
// timestamp linearization parameters
uint32_t phase_setpoint; // DMPLL phase setpoint (picoseconds)
uint32_t clock_period; // reference lock period in picoseconds
uint32_t t2_phase_transition; // approximate DMTD phase value (on slave port) at which RX timestamp (T2) counter transistion occurs (picoseconds)
uint32_t t4_phase_transition; // approximate phase value (on master port) at which RX timestamp (T4) counter transistion occurs (picoseconds)
uint8_t hw_addr[6];
int hw_index;
int32_t fiber_fix_alpha;
} hexp_port_state_t;
extern int halexp_get_port_state(hexp_port_state_t *state,
const char *port_name);
/* End halexp_port_state */
/* syscall-lookalike */
extern int wrpc_time(void);
extern void wrpc_udelay(int usecs);
/* Dev stuff */
extern void wrpc_putc(int c);
extern void wrpc_puts(const char *s);
extern int wrpc_testc(void);
static inline void delay(int x)
{
while (x--)
asm volatile("nop");
}
extern struct pp_network_operations wrpc_net_ops;
extern struct pp_time_operations wrpc_time_ops;
/* other network stuff, bah.... */
......@@ -102,38 +34,4 @@ struct wrpc_ethhdr {
uint16_t h_proto;
} __attribute__((packed));
#define CPU_CLOCK 62500000ULL
#define UART_BAUDRATE 115200ULL /* not a real UART */
#define GPIO_PIN_LED_LINK 0
#define GPIO_PIN_LED_STATUS 1
#define GPIO_PIN_SCL_OUT 2
#define GPIO_PIN_SDA_OUT 3
#define GPIO_PIN_SDA_IN 4
#define GPIO_PIN_BTN1 5
#define GPIO_PIN_BTN2 6
/* hacks to use code imported from other places (wrpc-software) */
#ifndef TRACE_DEV
#define TRACE_DEV pp_printf
#endif
#ifndef mprintf
#define mprintf pp_printf
#endif
#define DMTD_AVG_SAMPLES 256
#define DMTD_MAX_PHASE 16384
#ifndef NULL
#define NULL 0
#endif
#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
#endif
#define REF_CLOCK_PERIOD_PS 8000
#define REF_CLOCK_FREQ_HZ 125000000
#endif /* __WRPC_H */
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