30 static volatile Wrx * _wrx = (
volatile Wrx *)(
WRX_BASE);
40 while (_wrx->magic != WRX_MAGIC)
48 if (_wrx->ver != WRX_VERSION) {
49 errSet(ERROR_CTX(E_WRX_EP_VER));
52 logInfo(
"Ok, WRPC up!, Version " STR(WRX_VERSION));
65 if (!_wrxUp)
return NULL;
72 return _wrx->cmd.code != WRX_COMMAND_NONE;
75 static bool wrxReady() {
78 while (_wrx->cmd.code != WRX_COMMAND_NONE)
87 static inline bool wrxWaitForReply(uint16_t code) {
89 if (!wrxReady())
return false;
90 if (_wrx->info.cmdcode != code) {
99 if (!wrxReady())
return false;
102 _wrx->cmd.code = WRX_COMMAND_AUTONEG_ON;
104 _wrx->cmd.code = WRX_COMMAND_AUTONEG_OFF;
113 if (!_wrxUp)
return 0;
115 return _wrx->info.utcTime;
121 if (!wrxReady())
return false;
123 _wrx->cmd.params.tuneWord = tuneWord;
124 _wrx->cmd.code = WRX_COMMAND_SET_TUNEWORD;
132 if (!wrxReady())
return false;
134 _wrx->cmd.code = WRX_COMMAND_GET_TUNEINFO;
136 if (!wrxWaitForReply(WRX_COMMAND_GET_TUNEINFO))
return false;
138 *info = _wrx->info.cmdreply.tuneInfo;
146 if (!wrxReady())
return false;
148 _wrx->cmd.code = WRX_COMMAND_GET_SFP_VENDOR_SN;
150 if (!wrxWaitForReply(WRX_COMMAND_GET_SFP_VENDOR_SN))
return false;
152 memcpy(sn, _wrx->info.cmdreply.sfpVendorSN, 16);
158 bool wrxSetSFPThreshold(
int index, uint16_t value)
160 if (!wrxReady())
return false;
162 _wrx->cmd.params.threshold.value = value;
163 _wrx->cmd.params.threshold.index = index;
164 _wrx->cmd.code = WRX_COMMAND_SET_THRESHOLD;
171 if (!wrxReady())
return false;
172 if (len == 0 || len > 4)
return false;
173 _wrx->cmd.params.i2cWrt.addr = addr;
174 _wrx->cmd.params.i2cWrt.reg = reg;
175 _wrx->cmd.params.i2cWrt.len = len;
176 _wrx->cmd.code = WRX_COMMAND_READ_SFP_I2C;
177 if (!wrxWaitForReply(WRX_COMMAND_READ_SFP_I2C)) {
180 memcpy(buf, _wrx->info.cmdreply.i2cRd.data, len);
187 if (!wrxReady())
return false;
188 if (len == 0 || len > 4)
return false;
191 _wrx->cmd.params.i2cWrt.addr = addr;
192 _wrx->cmd.params.i2cWrt.reg = reg;
193 _wrx->cmd.params.i2cWrt.len = len;
194 memcpy(&_wrx->cmd.params.i2cWrt.data[0], buf, len);
195 _wrx->cmd.code = WRX_COMMAND_WRITE_SFP_I2C;
bool wrxGetTuneInfo(WrxTuneInfo *info)
Sets the fields of the WrxTuneInfo structure.
#define WRX_BASE
WhiteRabbit exchange address, not a real device.
bool wrxModI2cWrite(uint8_t addr, uint8_t reg, uint8_t len, uint8_t *buf)
Write SFP I2C bus (raw)
#define E_NOTFOUND
Generic error: not found (ID or resource.
uint64_t wrxUtcTime()
Returns the UTC time, or 0 if not available.
bool wrxInit()
Initializes the whiteRabbit eXchange.
#define STR(EXPR)
Stringyfies an expression.
void timeDelay(uint32_t msec)
Simple busy-wait delay.
#define E_INVSTATE
Generic error: Module is in a state in which.
static uint32_t timeOutInit(uint32_t msec)
Initializes a timeout with the specified no of msecs.
static bool timeOut(uint32_t to)
Checks whether or not the timeout has expired.
Manages the global system error.
bool wrxSetTuneWord(int32_t tuneWord)
Sets the tune-word.
bool wrxGetSFPSerialNo(char sn[17])
Gets the sfp serial number.
bool wrxUp()
Returns whether or not the WhiteRabbit interface is up and running.
volatile WrxInfo * wrxInfo()
Returns the whiteRabbit information structure if available, else NULL.
bool wrxModI2cRead(uint8_t addr, uint8_t reg, uint8_t len, uint8_t *buf)
Read SFP I2C bus (raw)
#define E_TIMEOUT
Generic error: Timeout error.
bool wrxCmdPending()
Returns whether or not there is a command still pending to be executed.
#define LOG_DEF(NAME,...)
Define a logger for a module.
bool wrxSetAutoNeg(bool on)
Returns autonegotation on or off.
This file assigns all device structures to memory mapped structures.
bool errSet(uint32_t code, const char *error, const char *name)
Sets an error.
Implements a generic logger facility.
WhiteRabbit exchange exchanges information between the 2nd LM32 and WhiteRabbit though a small client...
#define logInfo(MSG,...)
Write a log message with formatting on info level.