Commit 8f74f661 authored by Aurelio Colosimo's avatar Aurelio Colosimo

declared and implemented functions and struct for wr-servo

parent 116b1fc9
......@@ -8,106 +8,13 @@
#include "spec.h"
#include "../proto-ext-whiterabbit/wr-constants.h"
#if 0
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 spec) */
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 paramaters
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 int32_t cal_phase_transition;
extern int32_t sfp_alpha;
static int read_phase_val(hexp_port_state_t *state)
{
int32_t dmtd_phase;
if(spll_read_ptracker(0, &dmtd_phase, NULL))
{
state->phase_val = dmtd_phase;
state->phase_val_valid = 1;
}
else
{
state->phase_val = 0;
state->phase_val_valid = 0;
}
return 0;
}
static int halexp_get_port_state(hexp_port_state_t *state, const char *port_name)
{
state->valid = 1;
/* FIXME Unused in the current context?
#ifdef WRPC_MASTER
state->mode = HEXP_PORT_MODE_WR_MASTER;
#else
state->mode = HEXP_PORT_MODE_WR_SLAVE;
#endif*/
ep_get_deltas( &state->delta_tx, &state->delta_rx);
read_phase_val(state);
state->up = ep_link_up(NULL);
state->tx_calibrated = 1;
state->rx_calibrated = 1;
state->is_locked = spll_check_lock(0);
state->lock_priority = 0;
spll_get_phase_shift(0, NULL, &state->phase_setpoint);
state->clock_period = 8000;
state->t2_phase_transition = cal_phase_transition;
state->t4_phase_transition = cal_phase_transition;
get_mac_addr(state->hw_addr);
state->hw_index = 0;
state->fiber_fix_alpha = sfp_alpha;
return 0;
}
static int ptpd_netif_read_calibration_data(const char *ifaceName,
uint64_t *deltaTx, uint64_t *deltaRx, int32_t *fix_alpha,
static int spec_read_calibration_data(struct pp_instance *ppi,
uint32_t *deltaTx, uint32_t *deltaRx, int32_t *fix_alpha,
int32_t *clock_period)
{
hexp_port_state_t state;
halexp_get_port_state(&state, ifaceName);
halexp_get_port_state(&state, OPTS(ppi)->iface_name);
// check if the data is available
if(state.valid)
......@@ -142,7 +49,7 @@ static int ptpd_netif_read_calibration_data(const char *ifaceName,
}
#endif
/* Begin of exported functions */
int spec_calibrating_disable(struct pp_instance *ppi, int txrx)
......@@ -155,9 +62,9 @@ int spec_calibrating_enable(struct pp_instance *ppi, int txrx)
return WR_HW_CALIB_OK;
}
int spec_calibrating_poll(struct pp_instance *ppi, int txrx, uint64_t *delta)
int spec_calibrating_poll(struct pp_instance *ppi, int txrx, uint32_t *delta)
{
uint64_t delta_rx = 0, delta_tx = 0;
uint32_t delta_rx = 0, delta_tx = 0;
/* FIXME: why delta is 64bit whereas ep_get_deltas accepts 32bit? */
ep_get_deltas( &delta_tx, &delta_rx);
......@@ -191,7 +98,7 @@ int wr_calibrating_disable(struct pp_instance *ppi, int txrx)
int wr_calibrating_enable(struct pp_instance *ppi, int txrx)
__attribute__((alias("spec_calibrating_enable")));
int wr_calibrating_poll(struct pp_instance *ppi, int txrx, uint64_t *delta)
int wr_calibrating_poll(struct pp_instance *ppi, int txrx, uint32_t *delta)
__attribute__((alias("spec_calibrating_poll")));
int wr_calibration_pattern_enable(struct pp_instance *ppi,
......@@ -201,3 +108,8 @@ int wr_calibration_pattern_enable(struct pp_instance *ppi,
int wr_calibration_pattern_disable(struct pp_instance *ppi)
__attribute__((alias("spec_calibration_pattern_disable")));
int wr_read_calibration_data(struct pp_instance *ppi,
uint32_t *deltaTx, uint32_t *deltaRx, int32_t *fix_alpha,
int32_t *clock_period)
__attribute__((alias("spec_read_calibration_data")));
......@@ -4,6 +4,7 @@
#include <stdint.h>
#include <ppsi/ppsi.h>
#include <pps_gen.h>
#include "dev/softpll_ng.h"
#include "../proto-ext-whiterabbit/wr-constants.h"
......@@ -25,6 +26,37 @@ int spec_spll_locking_disable(struct pp_instance *ppi)
return WR_SPLL_OK;
}
int spec_spll_enable_ptracker(struct pp_instance *ppi)
{
spll_enable_ptracker(0, 1);
return WR_SPLL_OK;
}
int spec_enable_timing_output(struct pp_instance *ppi, int enable)
{
pps_gen_enable_output(enable);
return WR_SPLL_OK;
}
int spec_adjust_in_progress()
{
return pps_gen_busy() || spll_shifter_busy(0);
}
int spec_adjust_counters(int64_t adjust_sec, int32_t adjust_nsec)
{
if(adjust_sec)
pps_gen_adjust(PPSG_ADJUST_SEC, adjust_sec);
if(adjust_nsec)
pps_gen_adjust(PPSG_ADJUST_NSEC, adjust_nsec);
return 0;
}
int spec_adjust_phase(int32_t phase_ps)
{
spll_set_phase_shift(SPLL_ALL_CHANNELS, phase_ps);
}
int wr_locking_enable(struct pp_instance *ppi)
__attribute__((alias("spec_spll_locking_enable")));
......@@ -33,3 +65,18 @@ int wr_locking_poll(struct pp_instance *ppi)
int wr_locking_disable(struct pp_instance *ppi)
__attribute__((alias("spec_spll_locking_disable")));
int wr_enable_ptracker(struct pp_instance *ppi)
__attribute__((alias("spec_spll_enable_ptracker")));
int wr_enable_timing_output(struct pp_instance *ppi, int enable)
__attribute__((alias("spec_enable_timing_output")));
int wr_adjust_in_progress()
__attribute__((alias("spec_adjust_in_progress")));
int wr_adjust_counters(int64_t adjust_sec, int32_t adjust_nsec)
__attribute__((alias("spec_adjust_counters")));
int wr_adjust_phase(int32_t phase_ps)
__attribute__((alias("spec_adjust_phase")));
......@@ -42,5 +42,53 @@ int wr_calibration_pattern_enable(struct pp_instance *ppi,
unsigned int calibrationPeriod, unsigned int calibrationPattern,
unsigned int calibrationPatternLen);
int wr_calibration_pattern_disable(struct pp_instance *ppi);
int wr_read_calibration_data(struct pp_instance *ppi,
uint32_t *deltaTx, uint32_t *deltaRx, int32_t *fix_alpha,
int32_t *clock_period);
int wr_enable_ptracker(struct pp_instance *ppi);
int wr_enable_timing_output(struct pp_instance *ppi, int enable);
uint32_t wr_timer_get_msec_tics(void);
int wr_adjust_in_progress(void);
int wr_adjust_counters(int64_t adjust_sec, int32_t adjust_nsec);
int wr_adjust_phase(int32_t phase_ps);
/* wr_servo interface */
int wr_servo_init(struct pp_instance *ppi);
void wr_servo_reset();
int wr_servo_man_adjust_phase(int phase);
int wr_servo_got_sync(struct pp_instance *ppi, TimeInternal *t1,
TimeInternal *t2);
int wr_servo_got_delay(struct pp_instance *ppi, Integer32 cf);
int wr_servo_update(struct pp_instance *ppi);
struct wr_servo_state_t {
char if_name[16];
int state;
int next_state;
TimeInternal prev_t4;
TimeInternal mu;
TimeInternal nsec_offset;
int32_t delta_tx_m;
int32_t delta_rx_m;
int32_t delta_tx_s;
int32_t delta_rx_s;
int32_t cur_setpoint;
int64_t delta_ms;
int64_t delta_ms_prev;
TimeInternal t1, t2, t3, t4;
uint64_t last_tics;
int32_t fiber_fix_alpha;
int32_t clock_period_ps;
int missed_iters;
};
/* All data used as extension ppsi-wr must be put here */
struct wr_data_t {
struct wr_servo_state_t servo_state;
};
#endif /* __WREXT_WR_API_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