wrpc-calibration.c 2.82 KB
Newer Older
1 2 3 4 5 6
/*
 * Aurelio Colosimo for CERN, 2012 -- public domain
 */

#include <endpoint.h>
#include <ppsi/ppsi.h>
7
#include <softpll_ng.h>
8
#include <hal_exports.h>
9
#include "wrpc.h"
10 11
#include "../proto-ext-whiterabbit/wr-constants.h"

12
static int wrpc_read_calibration_data(struct pp_instance *ppi,
13
  uint32_t *deltaTx, uint32_t *deltaRx, int32_t *fix_alpha,
14 15 16 17
  int32_t *clock_period)
{
  hexp_port_state_t state;

18
  halexp_get_port_state(&state, ppi->iface_name);
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

  // check if the data is available
  if(state.valid)
  {

    if(fix_alpha)
      *fix_alpha = state.fiber_fix_alpha;

    if(clock_period)
      *clock_period = state.clock_period;

    //check if tx is calibrated,
    // if so read data
    if(state.tx_calibrated)
    {
      if(deltaTx) *deltaTx = state.delta_tx;
    }
    else
      return WR_HW_CALIB_NOT_FOUND;

    //check if rx is calibrated,
    // if so read data
    if(state.rx_calibrated)
    {
      if(deltaRx) *deltaRx = state.delta_rx;
    }
    else
      return WR_HW_CALIB_NOT_FOUND;

  }
  return WR_HW_CALIB_OK;

}

53

54 55
/* Begin of exported functions */

56
int wrpc_calibrating_disable(struct pp_instance *ppi, int txrx)
57 58 59 60
{
	return WR_HW_CALIB_OK;
}

61
int wrpc_calibrating_enable(struct pp_instance *ppi, int txrx)
62 63 64 65
{
	return WR_HW_CALIB_OK;
}

66
int wrpc_calibrating_poll(struct pp_instance *ppi, int txrx, uint32_t *delta)
67
{
68
	uint32_t delta_rx = 0, delta_tx = 0;
69

70
	/* FIXME: why delta was 64bit whereas ep_get_deltas accepts 32bit? */
71
	wrpc_read_calibration_data(ppi, &delta_tx, &delta_rx, NULL, NULL);
72 73 74 75 76 77 78 79 80

	if (txrx == WR_HW_CALIB_TX)
		*delta = delta_tx;
	else
		*delta = delta_rx;

	return WR_HW_CALIB_READY;
}

81
int wrpc_calibration_pattern_enable(struct pp_instance *ppi,
82 83 84
				    unsigned int calibrationPeriod,
				    unsigned int calibrationPattern,
				    unsigned int calibrationPatternLen)
85 86 87 88 89
{
	ep_cal_pattern_enable();
	return WR_HW_CALIB_OK;
}

90
int wrpc_calibration_pattern_disable(struct pp_instance *ppi)
91 92 93 94 95 96
{
	ep_cal_pattern_disable();
	return WR_HW_CALIB_OK;
}

int wr_calibrating_disable(struct pp_instance *ppi, int txrx)
97
	__attribute__((alias("wrpc_calibrating_disable")));
98 99

int wr_calibrating_enable(struct pp_instance *ppi, int txrx)
100
	__attribute__((alias("wrpc_calibrating_enable")));
101

102
int wr_calibrating_poll(struct pp_instance *ppi, int txrx, uint32_t *delta)
103
	__attribute__((alias("wrpc_calibrating_poll")));
104 105 106 107

int wr_calibration_pattern_enable(struct pp_instance *ppi,
	unsigned int calibrationPeriod, unsigned int calibrationPattern,
	unsigned int calibrationPatternLen)
108
	__attribute__((alias("wrpc_calibration_pattern_enable")));
109

110
int wr_calibration_pattern_disable(struct pp_instance *ppi)
111
	__attribute__((alias("wrpc_calibration_pattern_disable")));
112 113 114 115

int wr_read_calibration_data(struct pp_instance *ppi,
	uint32_t *deltaTx, uint32_t *deltaRx, int32_t *fix_alpha,
	int32_t *clock_period)
116
	__attribute__((alias("wrpc_read_calibration_data")));