mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-21 00:58:01 +02:00
ctb server: server starts up good. Need to debug each function in detail
This commit is contained in:
@ -207,9 +207,10 @@ int AD7689_GetChannel(int ichan) {
|
||||
* Configure
|
||||
*/
|
||||
void AD7689_Configure(){
|
||||
FILE_LOG(logINFOBLUE, ("Configuring AD7689 (Slow ADCs):\n"));
|
||||
FILE_LOG(logINFOBLUE, ("Configuring AD7689 (Slow ADCs): \n"));
|
||||
|
||||
// from power up, 3 invalid conversions
|
||||
FILE_LOG(logINFO, ("3 times due to invalid conversions from power up\n"));
|
||||
int i = 0;
|
||||
for (i = 0; i < AD7689_NUM_INVALID_CONVERSIONS; ++i) {
|
||||
AD7689_Set(
|
||||
|
@ -18,13 +18,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#define I2C_DATA_RATE_KBPS (200)
|
||||
#define I2C_SCL_PERIOD_NS ((1000 * 1000) / I2C_DATA_RATE_KBPS)
|
||||
#define I2C_SCL_LOW_PERIOD_NS (I2C_SCL_PERIOD_NS / 2)
|
||||
#define I2C_SCL_HIGH_PERIOD_NS (I2C_SCL_PERIOD_NS / 2)
|
||||
#define I2C_SDA_DATA_HOLD_TIME_NS (I2C_SCL_HIGH_PERIOD_NS / 2)
|
||||
#define I2C_SCL_LOW_COUNT ((I2C_SCL_LOW_PERIOD_NS / 1000) * I2C_CLOCK_MHZ) // convert to us, then to clock (defined in blackfin.h)
|
||||
#define I2C_SDA_DATA_HOLD_COUNT ((I2C_SDA_DATA_HOLD_TIME_NS / 1000) * I2C_CLOCK_MHZ) // convert to us, then to clock (defined in blackfin.h)
|
||||
#define I2C_DATA_RATE_KBPS (200)
|
||||
|
||||
/** Control Register */
|
||||
#define I2C_CTRL_ENBLE_CORE_OFST (0)
|
||||
@ -83,7 +77,7 @@ uint32_t I2C_Transfer_Command_Fifo_Reg = 0x0;
|
||||
* @param treg transfer command fifo register (defined in RegisterDefs.h)
|
||||
*/
|
||||
void I2C_ConfigureI2CCore(uint32_t creg, uint32_t rreg, uint32_t slreg, uint32_t shreg, uint32_t sdreg, uint32_t treg) {
|
||||
FILE_LOG(logINFOBLUE, ("\tConfiguring I2C Core for %d kbps:\n", I2C_DATA_RATE_KBPS));
|
||||
FILE_LOG(logINFO, ("\tConfiguring I2C Core for %d kbps:\n", I2C_DATA_RATE_KBPS));
|
||||
|
||||
I2C_Control_Reg = creg;
|
||||
I2C_Rx_Data_Fifo_Level_Reg = rreg;
|
||||
@ -92,16 +86,28 @@ void I2C_ConfigureI2CCore(uint32_t creg, uint32_t rreg, uint32_t slreg, uint32_t
|
||||
I2C_Sda_Hold_Reg = sdreg;
|
||||
I2C_Transfer_Command_Fifo_Reg = treg;
|
||||
|
||||
FILE_LOG(logINFOBLUE, ("\tSetting SCL Low Period: %d ns (0x%x clocks)\n", I2C_SCL_LOW_PERIOD_NS, I2C_SCL_LOW_COUNT));
|
||||
bus_w(I2C_Scl_Low_Count_Reg, (uint32_t)I2C_SCL_LOW_COUNT);
|
||||
// calculate scl low and high period count
|
||||
uint32_t sclPeriodNs = ((1000.00 * 1000.00) / (double)I2C_DATA_RATE_KBPS);
|
||||
// scl low period same as high period
|
||||
uint32_t sclLowPeriodNs = sclPeriodNs / 2;
|
||||
// convert to us, then to clock (defined in blackfin.h)
|
||||
uint32_t sclLowPeriodCount = (sclLowPeriodNs / 1000.00) * I2C_CLOCK_MHZ;
|
||||
|
||||
FILE_LOG(logINFOBLUE, ("\tSetting SCL High Period: %d ns (0x%x clocks)\n", I2C_SCL_HIGH_PERIOD_NS, I2C_SCL_LOW_COUNT));
|
||||
bus_w(I2C_Scl_High_Count_Reg, (uint32_t)I2C_SCL_LOW_COUNT);
|
||||
// calculate sda hold data count
|
||||
uint32_t sdaDataHoldTimeNs = (sclLowPeriodNs / 2); // scl low period same as high period
|
||||
// convert to us, then to clock (defined in blackfin.h)
|
||||
uint32_t sdaDataHoldCount = ((sdaDataHoldTimeNs / 1000.00) * I2C_CLOCK_MHZ);
|
||||
|
||||
FILE_LOG(logINFOBLUE, ("\tSetting SDA Hold Time: %d ns (0x%x clocks)\n", I2C_SDA_DATA_HOLD_TIME_NS, I2C_SDA_DATA_HOLD_COUNT));
|
||||
bus_w(I2C_Sda_Hold_Reg, (uint32_t)I2C_SDA_DATA_HOLD_COUNT);
|
||||
FILE_LOG(logINFO, ("\tSetting SCL Low Period: %d ns (%d clocks)\n", sclLowPeriodNs, sclLowPeriodCount));
|
||||
bus_w(I2C_Scl_Low_Count_Reg, sclLowPeriodCount);
|
||||
|
||||
FILE_LOG(logINFOBLUE, ("\tEnabling core\n"));
|
||||
FILE_LOG(logINFO, ("\tSetting SCL High Period: %d ns (%d clocks)\n", sclLowPeriodNs, sclLowPeriodCount));
|
||||
bus_w(I2C_Scl_High_Count_Reg, sclLowPeriodCount);
|
||||
|
||||
FILE_LOG(logINFO, ("\tSetting SDA Hold Time: %d ns (%d clocks)\n", sdaDataHoldTimeNs, sdaDataHoldCount));
|
||||
bus_w(I2C_Sda_Hold_Reg, (uint32_t)sdaDataHoldCount);
|
||||
|
||||
FILE_LOG(logINFO, ("\tEnabling core\n"));
|
||||
bus_w(I2C_Control_Reg, I2C_CTRL_ENBLE_CORE_MSK | I2C_CTRL_BUS_SPEED_FAST_400_VAL);// fixme: (works?)
|
||||
}
|
||||
|
||||
@ -142,7 +148,7 @@ uint32_t I2C_Read(uint32_t devId, uint32_t addr) {
|
||||
* @param data data to be written (16 bit)
|
||||
*/
|
||||
void I2C_Write(uint32_t devId, uint32_t addr, uint16_t data) {
|
||||
FILE_LOG(logDEBUG1, ("\tWriting data %d to I2C device 0x%x and reg 0x%x\n", data, devId, addr));
|
||||
FILE_LOG(logDEBUG1, ("Writing to I2C (Device:0x%x, reg:0x%x, data:%d)\n", devId, addr, data));
|
||||
// device Id mask
|
||||
uint32_t devIdMask = ((devId << I2C_TFR_CMD_ADDR_OFST) & I2C_TFR_CMD_ADDR_MSK);
|
||||
|
||||
|
@ -57,7 +57,7 @@ double INA226_Shunt_Resistor_Ohm = 0.0;
|
||||
* @param treg transfer command fifo register (defined in RegisterDefs.h)
|
||||
*/
|
||||
void INA226_ConfigureI2CCore(double rOhm, uint32_t creg, uint32_t rreg, uint32_t slreg, uint32_t shreg, uint32_t sdreg, uint32_t treg) {
|
||||
FILE_LOG(logINFO, ("Configuring INA226\n"));
|
||||
FILE_LOG(logINFOBLUE, ("Configuring INA226\n"));
|
||||
|
||||
INA226_Shunt_Resistor_Ohm = rOhm;
|
||||
|
||||
@ -69,7 +69,7 @@ void INA226_ConfigureI2CCore(double rOhm, uint32_t creg, uint32_t rreg, uint32_t
|
||||
* @param deviceId device Id (defined in slsDetectorServer_defs.h)
|
||||
*/
|
||||
void INA226_CalibrateCurrentRegister(uint32_t deviceId) {
|
||||
|
||||
FILE_LOG(logINFO, ("Calibrating Current Register for Device ID: 0x%x\n", deviceId));
|
||||
// get calibration value based on shunt resistor
|
||||
uint16_t calVal = ((uint16_t)INA226_getCalibrationValue(INA226_Shunt_Resistor_Ohm)) & INA226_CALIBRATION_MSK;
|
||||
FILE_LOG(logINFO, ("\tWriting to Calibration reg: 0x%0x\n", calVal));
|
||||
|
@ -106,7 +106,7 @@ int LTC2620_DacToVoltage(int dacval, int* voltage) {
|
||||
* @param dacaddr dac channel number in chip
|
||||
*/
|
||||
void LTC2620_SetSingle(int cmd, int data, int dacaddr) {
|
||||
FILE_LOG(logDEBUG1, ("\tdac addr:%d, dac value:%d, cmd:%d\n", dacaddr, data, cmd));
|
||||
FILE_LOG(logDEBUG1, ("dac addr:%d, dac value:%d, cmd:%d\n", dacaddr, data, cmd));
|
||||
|
||||
uint32_t codata = (((data << LTC2620_DAC_DATA_OFST) & LTC2620_DAC_DATA_MSK) |
|
||||
((dacaddr << LTC2620_DAC_ADDR_OFST) & LTC2620_DAC_ADDR_MSK) |
|
||||
@ -142,7 +142,7 @@ void LTC2620_SetDaisy(int cmd, int data, int dacaddr, int chipIndex) {
|
||||
uint32_t valw = 0;
|
||||
int ichip = 0;
|
||||
|
||||
FILE_LOG(logDEBUG1, ("\tdesired chip index:%d, nchip:%d, dac channel:%d, dac value:%d, cmd:%d \n",
|
||||
FILE_LOG(logDEBUG1, ("desired chip index:%d, nchip:%d, dac ch:%d, val:%d, cmd:0x%x \n",
|
||||
chipIndex, nchip, dacaddr, data, cmd));
|
||||
|
||||
// data to be bit banged
|
||||
@ -151,14 +151,14 @@ void LTC2620_SetDaisy(int cmd, int data, int dacaddr, int chipIndex) {
|
||||
cmd);
|
||||
|
||||
// select all chips (ctb daisy chain; others 1 chip)
|
||||
FILE_LOG(logDEBUG1, ("\tSelecting LTC2620\n"));
|
||||
FILE_LOG(logDEBUG1, ("Selecting LTC2620\n"));
|
||||
SPIChipSelect (&valw, LTC2620_Reg, LTC2620_CsMask, LTC2620_ClkMask, LTC2620_DigMask);
|
||||
|
||||
// send same data to all
|
||||
if (chipIndex < 0) {
|
||||
FILE_LOG(logDEBUG1, ("\tSend same data to all\n"));
|
||||
FILE_LOG(logDEBUG1, ("Send same data to all\n"));
|
||||
for (ichip = 0; ichip < nchip; ++ichip) {
|
||||
FILE_LOG(logDEBUG1, ("\tSend to ichip %d\n", ichip));
|
||||
FILE_LOG(logDEBUG1, ("Send data (0x%x) to ichip %d\n", codata, ichip));
|
||||
LTC2620_SendDaisyData(&valw, codata);
|
||||
}
|
||||
}
|
||||
@ -167,24 +167,24 @@ void LTC2620_SetDaisy(int cmd, int data, int dacaddr, int chipIndex) {
|
||||
else {
|
||||
// send nothing to preceding ichips (daisy chain) (if any chips in front of desired chip)
|
||||
for (ichip = 0; ichip < chipIndex; ++ichip) {
|
||||
FILE_LOG(logDEBUG1, ("\tSend nothing to ichip %d\n", ichip));
|
||||
FILE_LOG(logDEBUG1, ("Send nothing to ichip %d\n", ichip));
|
||||
LTC2620_SendDaisyData(&valw, LTC2620_DAC_CMD_NO_OPRTN_VAL);
|
||||
}
|
||||
|
||||
// send data to desired chip
|
||||
FILE_LOG(logDEBUG1, ("\tSend data to ichip %d\n", chipIndex));
|
||||
FILE_LOG(logDEBUG1, ("Send data (0x%x) to ichip %d\n", codata, chipIndex));
|
||||
LTC2620_SendDaisyData(&valw, codata);
|
||||
|
||||
// send nothing to subsequent ichips (daisy chain) (if any chips after desired chip)
|
||||
int ichip = 0;
|
||||
for (ichip = chipIndex + 1; ichip < nchip; ++ichip) {
|
||||
FILE_LOG(logDEBUG1, ("\tSend nothing to ichip %d\n", ichip));
|
||||
FILE_LOG(logDEBUG1, ("Send nothing to ichip %d\n", ichip));
|
||||
LTC2620_SendDaisyData(&valw, LTC2620_DAC_CMD_NO_OPRTN_VAL);
|
||||
}
|
||||
}
|
||||
|
||||
// deselect all chips (ctb daisy chain; others 1 chip)
|
||||
FILE_LOG(logDEBUG1, ("\tDeselecting LTC2620\n"));
|
||||
FILE_LOG(logDEBUG1, ("Deselecting LTC2620\n"));
|
||||
SPIChipDeselect(&valw, LTC2620_Reg, LTC2620_CsMask, LTC2620_ClkMask);
|
||||
}
|
||||
|
||||
@ -198,7 +198,7 @@ void LTC2620_SetDaisy(int cmd, int data, int dacaddr, int chipIndex) {
|
||||
* @param chipIndex the chip to be set
|
||||
*/
|
||||
void LTC2620_Set(int cmd, int data, int dacaddr, int chipIndex) {
|
||||
FILE_LOG(logDEBUG1, ("\tcmd:%d data:%d dacaddr:%d chipIndex:%d\n", cmd, data, dacaddr, chipIndex));
|
||||
FILE_LOG(logDEBUG1, ("cmd:0x%x, data:%d, dacaddr:%d, chipIndex:%d\n", cmd, data, dacaddr, chipIndex));
|
||||
// ctb
|
||||
if (LTC2620_Ndac > LTC2620_NUMCHANNELS)
|
||||
LTC2620_SetDaisy(cmd, data, dacaddr, chipIndex);
|
||||
@ -215,7 +215,7 @@ void LTC2620_Configure(){
|
||||
FILE_LOG(logINFOBLUE, ("Configuring LTC2620\n"));
|
||||
|
||||
// dac channel - all channels
|
||||
int addr = LTC2620_DAC_ADDR_MSK;
|
||||
int addr = (LTC2620_DAC_ADDR_MSK >> LTC2620_DAC_ADDR_OFST);
|
||||
|
||||
// data (any random low value, just writing to power up)
|
||||
int data = 0x6;
|
||||
@ -224,7 +224,7 @@ void LTC2620_Configure(){
|
||||
int cmd = LTC2620_DAC_CMD_WR_IN_VAL; //FIXME: should be command update and not write(does not power up)
|
||||
// also why do we need to power up (for jctb, we power down next)
|
||||
|
||||
LTC2620_Set(data, addr, cmd, -1);
|
||||
LTC2620_Set(cmd, data, addr, -1);
|
||||
}
|
||||
|
||||
|
||||
@ -234,7 +234,7 @@ void LTC2620_Configure(){
|
||||
* @param data dac value to set
|
||||
*/
|
||||
void LTC2620_SetDAC (int dacnum, int data) {
|
||||
FILE_LOG(logDEBUG1, ("\tSetting dac %d to %d\n", dacnum, data));
|
||||
FILE_LOG(logDEBUG1, ("Setting dac %d to %d\n", dacnum, data));
|
||||
// LTC2620 index
|
||||
int ichip = dacnum / LTC2620_NUMCHANNELS;
|
||||
|
||||
@ -247,9 +247,9 @@ void LTC2620_SetDAC (int dacnum, int data) {
|
||||
// power down mode, value is ignored
|
||||
if (data == LTC2620_PWR_DOWN_VAL) {
|
||||
cmd = LTC2620_DAC_CMD_PWR_DWN_VAL;
|
||||
FILE_LOG(logDEBUG1, ("\tPOWER DOWN\n"));
|
||||
FILE_LOG(logDEBUG1, ("POWER DOWN\n"));
|
||||
} else {
|
||||
FILE_LOG(logDEBUG1,("\tWrite to Input Register and Update\n"));
|
||||
FILE_LOG(logDEBUG1,("Write to Input Register and Update\n"));
|
||||
}
|
||||
|
||||
LTC2620_Set(cmd, data, addr, ichip);
|
||||
@ -264,7 +264,7 @@ void LTC2620_SetDAC (int dacnum, int data) {
|
||||
* @returns OK or FAIL for success of operation
|
||||
*/
|
||||
int LTC2620_SetDACValue (int dacnum, int val, int mV, int* dacval) {
|
||||
FILE_LOG(logDEBUG1, ("\tdacnum:%d, val:%d, mV:%d\n", dacnum, val, mV));
|
||||
FILE_LOG(logDEBUG1, ("dacnum:%d, val:%d, mV:%d\n", dacnum, val, mV));
|
||||
// validate index
|
||||
if (dacnum < 0 || dacnum >= LTC2620_Ndac) {
|
||||
FILE_LOG(logERROR, ("Dac index %d is out of bounds (0 to %d)\n", dacnum, LTC2620_Ndac - 1));
|
||||
|
@ -33,6 +33,7 @@ int MAX1932_MaxVoltage = 0;
|
||||
*/
|
||||
void MAX1932_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst,
|
||||
int minMV, int maxMV) {
|
||||
FILE_LOG(logINFOBLUE, ("Configuring High Voltage\n"));
|
||||
MAX1932_Reg = reg;
|
||||
MAX1932_CsMask = cmsk;
|
||||
MAX1932_ClkMask = clkmsk;
|
||||
@ -60,7 +61,7 @@ void MAX1932_Disable() {
|
||||
* @return OK or FAIL
|
||||
*/
|
||||
int MAX1932_Set (int val) {
|
||||
FILE_LOG(logDEBUG1, ("\tSetting high voltage to %d\n", val));
|
||||
FILE_LOG(logDEBUG1, ("Setting high voltage to %d\n", val));
|
||||
if (val < 0)
|
||||
return FAIL;
|
||||
|
||||
|
@ -72,7 +72,7 @@ int64_t get64BitReg(int aLSB, int aMSB){
|
||||
vMSB=bus_r(aMSB);
|
||||
v64=vMSB;
|
||||
v64=(v64<<32) | vLSB;
|
||||
FILE_LOG(logDEBUG1, (" reg64(%x,%x) %x %x %llx\n", aLSB, aMSB, vLSB, vMSB, (long long unsigned int)v64));
|
||||
FILE_LOG(logDEBUG5, (" reg64(%x,%x) %x %x %llx\n", aLSB, aMSB, vLSB, vMSB, (long long unsigned int)v64));
|
||||
return v64;
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,8 @@
|
||||
*/
|
||||
int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int outputMax,
|
||||
int inputValue, int* outputValue) {
|
||||
FILE_LOG(logDEBUG1, ("\tInput Value: %d\n", inputValue));
|
||||
FILE_LOG(logDEBUG1, ("Input Value: %d (Input:(%d - %d), Output:(%d - %d))\n",
|
||||
inputValue, inputMin, inputMax, outputMin, outputMax));
|
||||
|
||||
// validate within bounds
|
||||
// eg. MAX1932 range is v(60 - 200) to dac(255 - 1), here inputMin > inputMax (when dac to voltage)
|
||||
@ -37,7 +38,7 @@ int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int outpu
|
||||
}
|
||||
*outputValue = value;
|
||||
|
||||
FILE_LOG(logDEBUG1, ("\tConverted Ouput Value: %d\n", *outputValue));
|
||||
FILE_LOG(logDEBUG1, ("Converted Ouput Value: %d\n", *outputValue));
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,8 @@
|
||||
#define FILELOG_MAX_LEVEL logDEBUG4
|
||||
#elif VERBOSE
|
||||
#define FILELOG_MAX_LEVEL logDEBUG
|
||||
#elif DEBUG1
|
||||
#define FILELOG_MAX_LEVEL logDEBUG1
|
||||
#endif
|
||||
|
||||
#ifndef FILELOG_MAX_LEVEL
|
||||
|
@ -181,6 +181,7 @@ int getADCIndexFromDACIndex(enum DACINDEX ind);
|
||||
int isPowerValid(int val);
|
||||
int getPower();
|
||||
void setPower(enum DACINDEX ind, int val);
|
||||
void powerOff();
|
||||
#endif
|
||||
/*#ifdef GOTTHARDD
|
||||
void initDAC(int dac_addr, int value);
|
||||
@ -223,10 +224,13 @@ int setDetectorPosition(int pos[]);
|
||||
|
||||
// very detector specific
|
||||
|
||||
|
||||
// chip test board specific - powerchip, sendudp, pll, flashing firmware
|
||||
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
|
||||
// moench specific - powerchip
|
||||
#ifdef MOENCHD
|
||||
int powerChip (int on);
|
||||
#endif
|
||||
|
||||
// chip test board specific - sendudp, pll, flashing firmware
|
||||
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
|
||||
int sendUDP(int enable);
|
||||
void configurePhase(enum CLKINDEX ind, int val);
|
||||
int getPhase(enum CLKINDEX ind);
|
||||
|
@ -3113,7 +3113,7 @@ int power_chip(int file_des) {
|
||||
return printSocketReadError();
|
||||
FILE_LOG(logDEBUG1, ("Powering chip to %d\n", arg));
|
||||
|
||||
#ifndef JUNGFRAUD
|
||||
#if (!defined(JUNGFRAUD)) && (!defined(MOENCHD))
|
||||
functionNotImplemented();
|
||||
#else
|
||||
// set & get
|
||||
|
Reference in New Issue
Block a user