43 #define _OCTO_BOARDS 2
44 #define _OCTO_CH_MUX 8
45 #define _OCTO_CHS2MUX(CHS) ( ( CHS + ( _OCTO_CH_MUX - 1 ) ) / _OCTO_CH_MUX )
49 static const OctoBrdCfg _octoBrdCfg[_OCTO_BOARDS] = {
56 static bool octoSelPMT(
const OctoBrdCfg * cfg,
int ch,
bool * was_on)
61 if (!
ocRead(cfg->dev, cfg->cpld,
ocRegOn, &onChTmp))
return false;
63 if (onChTmp &
BIT(ch)) {
77 return pca9548_select(cfg->dev, cfg->muxb + (ch / _OCTO_CH_MUX), ch % _OCTO_CH_MUX);
80 static bool octoDeSelPMT(
const OctoBrdCfg * cfg,
int ch,
bool was_on)
91 if (!
ocRead(cfg->dev, cfg->cpld,
ocRegOn, &onChTmp))
return false;
105 for (i = 0; i < _OCTO_CHS2MUX(cfg->chs); ++i)
108 logWarn(
"Could not communicate with MUX %d:%d : %s (%08x)", i, cfg->chs,
114 if (!
ocWakeUp(cfg->dev, cfg->cpld)) {
115 logWarn(
"Failed to wake up CPLD %d: %s (%08x)", cfg->chs,
122 logWarn(
"Could not communicate with CPLD %d: %s (%08x)", cfg->chs,
134 if (!
ocRead(cfg->dev, cfg->cpld,
ocRegOn, &onChTmp))
return false;
136 if (!
ocWrite(cfg->dev, cfg->cpld,
ocRegOn, onChTmp))
return false;
140 bool octoInitChan(
int brd,
int ch, uint8_t highVolt, uint8_t threshold)
142 const OctoBrdCfg * brdCfg = &_octoBrdCfg[brd];
146 if (!octoSelPMT(brdCfg, ch, &was_on))
goto fail;
152 .threshold = threshold
160 if (!octoDeSelPMT(brdCfg, ch,
true))
return false;
164 octoDeSelPMT(brdCfg, ch, was_on);
168 bool octoPMTID(
int brd,
int ch, uint32_t *
id,
bool * pmtIdFault)
170 const OctoBrdCfg * brdCfg = &_octoBrdCfg[brd];
173 if (pmtIdFault != NULL) *pmtIdFault =
false;
175 if (!octoSelPMT(brdCfg, ch, &was_on))
goto fail;
182 if (pmtIdFault != NULL) *pmtIdFault =
true;
187 *
id = (buf[0] << 16) | (buf[1] << 8) | buf[2];
189 if (!octoDeSelPMT(brdCfg, ch, was_on))
return false;
192 octoDeSelPMT(brdCfg, ch, was_on);
201 if (!
ocRead(cfg->dev, cfg->cpld,
ocRegOn, &onChTmp))
return false;
212 return ocRead(_octoBrdCfg[brd].dev, _octoBrdCfg[brd].cpld,
ocRegFault, fault);
215 bool octoReadEnabled(
int brd, uint32_t * enabled)
217 return ocRead(_octoBrdCfg[brd].dev, _octoBrdCfg[brd].cpld,
ocRegOn, enabled);
226 if (!octoSelPMT(cfg, ch, &was_on))
goto fail;
232 return octoDeSelPMT(cfg, ch, was_on);
234 octoDeSelPMT(cfg, ch, was_on);
243 if (!octoSelPMT(cfg, ch, &was_on))
goto fail;
249 return octoDeSelPMT(cfg, ch, was_on);
251 octoDeSelPMT(cfg, ch, was_on);
bool errHas()
Returns whether there is an error pending.
This module implements the functionality required by the octopus board (large).
bool octoHighVoltage(int brd, int ch, bool hvOn)
Turns the high-voltage on or off.
#define OCTOS_MUXB_I2C_ADDR
Octopus small I2C MUX base address.
#define OCTOS_CPLD_I2C_ADDR
Octopus small CLPD address.
bool octoPiezo(bool on)
Turns the Piezo on or off.
#define OCTOL_CPLD_I2C_ADDR
Octopus large CLPD base address.
bool prmsChainTest(I2C_Device *dev, uint8_t addr)
Executes a chain test.
#define BIT(N)
Makes a value with the specified bit set.
bool octoChainTest(int brd, int ch)
Executes a chain-test.
#define OCTOS_I2C_DEV
Octopus small I2C device.
Structure defines OpenCores I2C Device.
#define E_PRMS_ID_FAULT
PROMiS ID is not consistent.
#define OCTOL_I2C_DEV
Octopus large I2C device.
const char * errGetDescr()
Returns the last error description, if any, else null.
bool prmsID(I2C_Device *dev, uint8_t addr, uint8_t *id)
Returns the burned ID of the PROMiS device.
void octoResetBoard(int brd)
void timeDelay(uint32_t msec)
Simple busy-wait delay.
bool octoInitChan(int brd, int ch, uint8_t highVolt, uint8_t threshold)
Initializes a channel on the octopus board.
bool octoPMTID(int brd, int ch, uint32_t *id, bool *pmtIdFault)
Reads a PMT ID.
#define logWarn(MSG,...)
Format a log message with warning level.
#define OCTOL_MUXB_I2C_ADDR
Octopus large I2C MUX base address.
#define OCTOS_PMT_CH
Octopus small PMT channel count.
#define OCTO_BRD_LARGE
Octo large.
Manages the global system error.
bool ocWrite(I2C_Device *dev, uint8_t addr, OCReg reg, uint32_t value)
Writes one of the CPLD registers.
void errClear()
Clears the current error.
bool octoDeinitChan(int brd, int ch)
De-Initializes a channel on the octopus board.
uint32_t errGet()
Returns the last error code, or null.
This module is responsible for distributing error codes.
#define LOG_DEF(NAME,...)
Define a logger for a module.
#define OCTOL_PMT_CH
Octopus large PMT channel count.
bool octoReadFault(int brd, uint32_t *fault)
Reads the fault register of the CLPD.
#define OCTO_PROMIS_I2C_ADDR
Generic PROMiS I2C address.
bool ocRead(I2C_Device *dev, uint8_t addr, OCReg reg, uint32_t *value)
Reads one of the CPLD registers.
bool prmsSetConfig(I2C_Device *dev, uint8_t addr, PrmsConfig *cfg)
Sets the configuration on the PROMiS device.
uint8_t highVolt
high voltage DAC value
static bool pca9548_select(I2C_Device *dev, int addr, int ch)
Select a specific channel on the PCA9548.
This driver interfaces with the PROMiS PMT ASIC.
This driver encapsulates the functionality of the CPLD on the octopus board.
This file assigns all device structures to memory mapped structures.
bool prmsHighVolt(I2C_Device *dev, uint8_t addr, bool enable)
Enables/Disables the high voltage.
#define OCTOL_PIEZO
Position of the Piezo.
Implements a generic logger facility.
static bool ocWakeUp(I2C_Device *dev, uint8_t addr)
Wakes up the octopus board, apparently it needs it.