You've already forked gitified_old_clb_svn
178 lines
5.2 KiB
C
178 lines
5.2 KiB
C
#include "onewire.h"
|
|
#include "wrx_proto.h"
|
|
#include "endpoint.h"
|
|
#include "ptpd.h"
|
|
#include "ptpd_exports.h"
|
|
#include "sfp.h"
|
|
|
|
#include <hw/endpoint_regs.h>
|
|
#include <hw/endpoint_mdio.h>
|
|
|
|
#define WRX_BASE 0x000001FF80 //!< Base address of WRX structure
|
|
#define WRX_OFFSET 0x0000100000 //!< Memory address offset of 2nd LM32
|
|
|
|
|
|
/* Map structure at memory location */
|
|
static volatile Wrx * _wrx = (volatile Wrx *)(WRX_BASE + WRX_OFFSET);
|
|
|
|
|
|
// Initialize WhiteRabbit Exchange
|
|
// call at initiaization time.
|
|
void wrxInit(uint8_t mac_addr[], uint16_t autonegotiation)
|
|
{
|
|
_wrx->magic = WRX_MAGIC;
|
|
_wrx->ver = WRX_VERSION;
|
|
#ifdef BROADCAST
|
|
_wrx->info.status = WRX_STATUS_BROADCAST_MODE;
|
|
#else
|
|
_wrx->info.status = 0;
|
|
#endif
|
|
|
|
// mocht je zeker weten dat het mac - adres
|
|
if ( ( _wrx->info.status & WRX_STATUS_MAC_ADDRESS_VALID ) == 0)
|
|
{
|
|
// set MAC address, if possible
|
|
memcpy(_wrx->info.macAddr, mac_addr, sizeof(_wrx->info.macAddr));
|
|
|
|
_wrx->info.status |= WRX_STATUS_MAC_ADDRESS_VALID; //!< Mark as set.
|
|
|
|
if(autonegotiation) {
|
|
_wrx->info.status |= WRX_STATUS_AUTONEG_ON;
|
|
}
|
|
|
|
_wrx->info.pState = WRX_PTP_Uninitialized;
|
|
_wrx->info.wState = WRX_WRS_Uninitialized;
|
|
_wrx->info.sState = WRX_WR_Uninitialized;
|
|
|
|
}
|
|
|
|
char c[17];
|
|
sfp_read_part_id(c);
|
|
c[16] ='\0';
|
|
printf("SFP part Id: %s", c);
|
|
}
|
|
|
|
// Execute on a regular basis (once per second) in main-loop
|
|
void wrxUpdate(int linkStatus, PtpPortDS *ptpPortDS)
|
|
{
|
|
// retrieve info structure for easy access
|
|
WrxInfo * info = &(_wrx->info);
|
|
|
|
uint16_t brd_temp = 0;
|
|
uint16_t brd_temp_frac = 0;
|
|
uint8_t sfp_temp = 0;
|
|
uint8_t sfp_temp_frac = 0;
|
|
uint16_t rx_input_power = 0;
|
|
uint16_t tx_output_power = 0;
|
|
uint16_t autonegotiation = 0;
|
|
|
|
|
|
own_readtemp(ONEWIRE_PORT, &brd_temp, &brd_temp_frac);
|
|
info->brdTemp = brd_temp;
|
|
info->brdTempFrac = brd_temp_frac;
|
|
|
|
sfp_read_temp(&sfp_temp, &sfp_temp_frac);
|
|
info->sfpTemp = sfp_temp;
|
|
info->sfpTempFrac = sfp_temp_frac;
|
|
|
|
sfp_a2_read_u16(SFP_ADC_RX_POWER, &rx_input_power);
|
|
info->rxInputPower = rx_input_power;
|
|
|
|
sfp_a2_read_u16(SFP_ADC_TX_POWER, &tx_output_power);
|
|
info->txOutputPower = tx_output_power;
|
|
|
|
// LINK_WENT_UP and LINK_UP are odd, LINK_WENT_DOWN and LINK_DOWN are even
|
|
//if(linkStatus & 1) {
|
|
if((linkStatus == 1) || (linkStatus == 3)) {
|
|
info->status |= WRX_STATUS_LINK_UP;
|
|
}
|
|
else {
|
|
info->status &= ~WRX_STATUS_LINK_UP;
|
|
}
|
|
|
|
autonegotiation = ep_get_autonegotiation();
|
|
if(!autonegotiation) {
|
|
info->status &= ~WRX_STATUS_AUTONEG_ON;
|
|
}
|
|
else {
|
|
info->status |= WRX_STATUS_AUTONEG_ON;
|
|
}
|
|
|
|
info->pState = ptpPortDS->portState;
|
|
info->wState = ptpPortDS->wrPortState;
|
|
wr_servo_state_t *s = &ptpPortDS->wr_servo;
|
|
info->sState = s->next_state;
|
|
|
|
info->sDeltaTX = s->delta_tx_s;
|
|
info->sDeltaRX = s->delta_rx_s;
|
|
info->mDeltaTX = s->delta_tx_m;
|
|
info->mDeltaRX = s->delta_rx_m;
|
|
|
|
info->mu = s->mu_picos;
|
|
info->bitslide = ep_get_bitslide();
|
|
|
|
shw_pps_gen_get_time(&(info->utcTime), NULL);
|
|
}
|
|
|
|
// Returns: 1 if there was a command
|
|
// 0 if there was no command
|
|
int wrxExecute() {
|
|
// retrieve cmd structure
|
|
WrxCmd * cmd = &(_wrx->cmd);
|
|
WrxInfo * info = &(_wrx->info);
|
|
WrxI2CRdWr * i2crw;
|
|
uint16_t tmp;
|
|
|
|
switch (cmd->code)
|
|
{
|
|
case WRX_COMMAND_NONE:
|
|
return 0;
|
|
case WRX_COMMAND_AUTONEG_OFF:
|
|
// TODO, understand magic values
|
|
pcs_write(MDIO_REG_MCR, 0x0160);
|
|
break;
|
|
case WRX_COMMAND_AUTONEG_ON:
|
|
pcs_write(MDIO_REG_MCR, 0x1140);
|
|
break;
|
|
case WRX_COMMAND_GET_TUNEINFO:
|
|
// need 2 find transceiver type, and such...
|
|
info->cmdreply.tuneInfo.tuneproc = sfp_get_tuning_procedure();
|
|
sfp_a2_read_u16(SFP_ADC_LASER_TEMP, &tmp);
|
|
info->cmdreply.tuneInfo.laserTmpWl = tmp;
|
|
info->cmdreply.tuneInfo.tuneword = sfp_get_tune_word();
|
|
info->cmdcode = WRX_COMMAND_GET_TUNEINFO;
|
|
break;
|
|
case WRX_COMMAND_SET_TUNEWORD:
|
|
sfp_set_tune_word(cmd->params.tuneWord);
|
|
break;
|
|
case WRX_COMMAND_GET_SFP_VENDOR_SN:
|
|
// get Serial number
|
|
sfp_read_part_sn(info->cmdreply.sfpVendorSN);
|
|
info->cmdcode = WRX_COMMAND_GET_SFP_VENDOR_SN;
|
|
break;
|
|
case WRX_COMMAND_SET_THRESHOLD:
|
|
//printf("Request to set threhsold index %d to %d\n",
|
|
//cmd->params.threshold.index, cmd->params.threshold.value);
|
|
sfp_a2_write_u16(cmd->params.threshold.index, cmd->params.threshold.value);
|
|
break;
|
|
case WRX_COMMAND_WRITE_SFP_I2C:
|
|
i2crw = &cmd->params.i2cWrt;
|
|
sfp_i2c_mod_write(i2crw->addr, i2crw->reg, &i2crw->data[0], i2crw->len);
|
|
break;
|
|
case WRX_COMMAND_READ_SFP_I2C:
|
|
i2crw = &cmd->params.i2cWrt;
|
|
|
|
uint8_t * ptr = &info->cmdreply.i2cRd.data[0];
|
|
sfp_i2c_mod_read(i2crw->addr, i2crw->reg, ptr, i2crw->len);
|
|
info->cmdreply.i2cRd.addr = i2crw->addr;
|
|
info->cmdreply.i2cRd.reg = i2crw->reg;
|
|
info->cmdreply.i2cRd.len = i2crw->len;
|
|
info->cmdcode = WRX_COMMAND_READ_SFP_I2C;
|
|
break;
|
|
}
|
|
// reset command
|
|
cmd->code = WRX_COMMAND_NONE;
|
|
|
|
return 1;
|
|
}
|