From a8121ae1083f136b6a3d177371f64559930d5706 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 22 Feb 2019 09:03:30 +0100 Subject: [PATCH 1/3] ctb server: vio should be off at start up --- slsDetectorServers/ctbDetectorServer/Makefile | 2 +- slsDetectorServers/ctbDetectorServer/gitInfo.txt | 10 +++++----- slsDetectorServers/ctbDetectorServer/gitInfoCtb.h | 8 ++++---- .../ctbDetectorServer/slsDetectorFunctionList.c | 3 --- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/slsDetectorServers/ctbDetectorServer/Makefile b/slsDetectorServers/ctbDetectorServer/Makefile index 099b148f6..a6a3e48a3 100755 --- a/slsDetectorServers/ctbDetectorServer/Makefile +++ b/slsDetectorServers/ctbDetectorServer/Makefile @@ -1,6 +1,6 @@ CROSS = bfin-uclinux- CC = $(CROSS)gcc -CFLAGS += -Wall -DCHIPTESTBOARDD -DSTOP_SERVER #-DDEBUG1 #-DJCTB -DVERBOSEI #-DVERBOSE +CFLAGS += -Wall -DCHIPTESTBOARDD -DSTOP_SERVER -DDEBUG1 #-DJCTB -DVERBOSEI #-DVERBOSE LDLIBS += -lm -lstdc++ PROGS = ctbDetectorServer diff --git a/slsDetectorServers/ctbDetectorServer/gitInfo.txt b/slsDetectorServers/ctbDetectorServer/gitInfo.txt index 13a20eab9..11c551081 100644 --- a/slsDetectorServers/ctbDetectorServer/gitInfo.txt +++ b/slsDetectorServers/ctbDetectorServer/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorPackage/slsDetectorServers/ctbDetectorServer URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git -Repsitory UUID: a4f1b7670f7a6e5bfae9f34f561350643eab6ca5 -Revision: 23 -Branch: ctbBugFixes +Repsitory UUID: 40d15264c56a7a3b1a00291b0735dcec75a39f1d +Revision: 24 +Branch: refactor Last Changed Author: Dhanya_Thattil -Last Changed Rev: 4340 -Last Changed Date: 2019-02-21 11:22:00.000000002 +0100 ./Makefile +Last Changed Rev: 4346 +Last Changed Date: 2019-02-22 08:18:54.000000002 +0100 ./Makefile diff --git a/slsDetectorServers/ctbDetectorServer/gitInfoCtb.h b/slsDetectorServers/ctbDetectorServer/gitInfoCtb.h index 01768d0b3..e657c769b 100644 --- a/slsDetectorServers/ctbDetectorServer/gitInfoCtb.h +++ b/slsDetectorServers/ctbDetectorServer/gitInfoCtb.h @@ -1,6 +1,6 @@ #define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git" -#define GITREPUUID "a4f1b7670f7a6e5bfae9f34f561350643eab6ca5" +#define GITREPUUID "40d15264c56a7a3b1a00291b0735dcec75a39f1d" #define GITAUTH "Dhanya_Thattil" -#define GITREV 0x4340 -#define GITDATE 0x20190221 -#define GITBRANCH "ctbBugFixes" +#define GITREV 0x4346 +#define GITDATE 0x20190222 +#define GITBRANCH "refactor" diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index 2292d7c7b..dc013d02f 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -523,9 +523,6 @@ void setupDetector() { INA226_CalibrateCurrentRegister(I2C_POWER_VD_DEVICE_ID); setVchip(VCHIP_MIN_MV); - // set vio to minimum for fpga to function - setPower(D_PWR_IO, VIO_MIN_MV); - // altera pll ALTERA_PLL_SetDefines(PLL_CNTRL_REG, PLL_PARAM_REG, PLL_CNTRL_RCNFG_PRMTR_RST_MSK, PLL_CNTRL_WR_PRMTR_MSK, PLL_CNTRL_PLL_RST_MSK, PLL_CNTRL_ADDR_MSK, PLL_CNTRL_ADDR_OFST); From a1a6a5dbaa01b09ed1c0d1d561e52c3bfc6c353c Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 22 Feb 2019 13:22:40 +0100 Subject: [PATCH 2/3] ctb server: slow adc temp fixed --- slsDetectorServers/slsDetectorServer/AD7689.h | 29 ++++++++++-------- slsDetectorServers/slsDetectorServer/AD9257.h | 2 +- .../slsDetectorServer/LTC2620.h | 30 +++++++++---------- .../slsDetectorServer/MAX1932.h | 2 +- .../slsDetectorServer/commonServerFunctions.h | 19 +++++++----- .../slsDetector/slsDetectorCommand.cpp | 2 +- 6 files changed, 46 insertions(+), 38 deletions(-) diff --git a/slsDetectorServers/slsDetectorServer/AD7689.h b/slsDetectorServers/slsDetectorServer/AD7689.h index 0adfbf46b..d06dcfb52 100755 --- a/slsDetectorServers/slsDetectorServer/AD7689.h +++ b/slsDetectorServers/slsDetectorServer/AD7689.h @@ -61,13 +61,13 @@ #define AD7689_ADC_CFG_NUMBITS (14) #define AD7689_ADC_DATA_NUMBITS (16) -#define AD7689_NUM_CHANNELS (7) +#define AD7689_NUM_CHANNELS (8) #define AD7689_NUM_INVALID_CONVERSIONS (3) #define AD7689_INT_REF_MAX_MV (2500) // chosen using reference buffer selection in config reg #define AD7689_INT_REF_MIN_MV (0) #define AD7689_INT_MAX_STEPS (0xFFFF + 1) -#define AD7689_TMP_C_FOR_1_MV (25.00 / 283) +#define AD7689_TMP_C_FOR_1_MV (25.00 / 283.00) uint32_t AD7689_Reg = 0x0; @@ -87,6 +87,8 @@ int AD7689_DigOffset = 0x0; * @param dofst digital output offset */ void AD7689_SetDefines(uint32_t reg, uint32_t roreg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst) { + FILE_LOG(logDEBUG, ("AD7689: reg:0x%x roreg:0x%x cmsk:0x%x clkmsk:0x%x dmsk:0x%x dofst:%d\n", + reg, roreg, cmsk, clkmsk, dmsk, dofst)); AD7689_Reg = reg; AD7689_ROReg = roreg; AD7689_CnvMask = cmsk; @@ -100,9 +102,9 @@ void AD7689_SetDefines(uint32_t reg, uint32_t roreg, uint32_t cmsk, uint32_t clk */ void AD7689_Disable() { bus_w(AD7689_Reg, (bus_r(AD7689_Reg) - | AD7689_CnvMask - | AD7689_ClkMask) - &~(AD7689_DigMask)); + &~(AD7689_CnvMask) + | AD7689_ClkMask + &~(AD7689_DigMask))); } /** @@ -112,7 +114,7 @@ void AD7689_Disable() { void AD7689_Set(u_int32_t codata) { FILE_LOG(logINFO, ("\tSetting ADC SPI Register. Writing 0x%08x to Config Reg\n", codata)); serializeToSPI(AD7689_Reg, codata, AD7689_CnvMask, AD7689_ADC_CFG_NUMBITS, - AD7689_ClkMask, AD7689_DigMask, AD7689_DigOffset); + AD7689_ClkMask, AD7689_DigMask, AD7689_DigOffset, 1); } /** @@ -121,8 +123,8 @@ void AD7689_Set(u_int32_t codata) { */ uint16_t AD7689_Get() { FILE_LOG(logINFO, ("\tGetting ADC SPI Register.\n")); - return (uint16_t)serializeFromSPI(AD7689_ROReg, AD7689_Reg, AD7689_CnvMask, AD7689_ADC_DATA_NUMBITS, - AD7689_ClkMask, AD7689_DigMask); + return (uint16_t)serializeFromSPI(AD7689_Reg, AD7689_CnvMask, AD7689_ADC_DATA_NUMBITS, + AD7689_ClkMask, AD7689_DigMask, AD7689_ROReg, 1); } /** @@ -154,13 +156,14 @@ int AD7689_GetTemperature() { ConvertToDifferentRange(0, AD7689_INT_MAX_STEPS, AD7689_INT_REF_MIN_MV, AD7689_INT_REF_MAX_MV, regval, &retval); - FILE_LOG(logDEBUG1, ("\tvoltage read for temp: 0x%d mV\n", retval)); + FILE_LOG(logDEBUG1, ("voltage read for temp: %d mV\n", retval)); // value in °C - int temp = AD7689_TMP_C_FOR_1_MV * retval; - FILE_LOG(logDEBUG1, ("\ttemp read: 0x%d °C\n", temp)); + double tempValue = AD7689_TMP_C_FOR_1_MV * (double)retval; - return temp; + FILE_LOG(logINFO, ("\ttemp read : %f °C\n", tempValue)); + + return tempValue; } @@ -201,7 +204,7 @@ int AD7689_GetChannel(int ichan) { ConvertToDifferentRange(0, AD7689_INT_MAX_STEPS, AD7689_INT_REF_MIN_MV, AD7689_INT_REF_MAX_MV, regval, &retval); - FILE_LOG(logINFO, ("\tvoltage read for chan %d: 0x%d mV\n", retval)); + FILE_LOG(logINFO, ("\tvoltage read for chan %d: %d mV\n", ichan, retval)); return retval; } diff --git a/slsDetectorServers/slsDetectorServer/AD9257.h b/slsDetectorServers/slsDetectorServer/AD9257.h index 52e363f5e..5568a1082 100755 --- a/slsDetectorServers/slsDetectorServer/AD9257.h +++ b/slsDetectorServers/slsDetectorServer/AD9257.h @@ -183,7 +183,7 @@ void AD9257_Set(int addr, int val) { codata = val + (addr << 8); FILE_LOG(logINFO, ("\tSetting ADC SPI Register. Wrote 0x%04x at 0x%04x\n", val, addr)); serializeToSPI(AD9257_Reg, codata, AD9257_CsMask, AD9257_ADC_NUMBITS, - AD9257_ClkMask, AD9257_DigMask, AD9257_DigOffset); + AD9257_ClkMask, AD9257_DigMask, AD9257_DigOffset, 0); } /** diff --git a/slsDetectorServers/slsDetectorServer/LTC2620.h b/slsDetectorServers/slsDetectorServer/LTC2620.h index 77cd63346..538ceedd3 100755 --- a/slsDetectorServers/slsDetectorServer/LTC2620.h +++ b/slsDetectorServers/slsDetectorServer/LTC2620.h @@ -106,15 +106,15 @@ 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, ("(Single) dac addr:%d, dac value:%d, cmd:%d\n", dacaddr, data, cmd)); + FILE_LOG(logDEBUG2, ("(Single) 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) | cmd); - FILE_LOG(logDEBUG1, ("codata: 0x%x\n", codata)); + FILE_LOG(logDEBUG2, ("codata: 0x%x\n", codata)); serializeToSPI (LTC2620_Reg, codata, LTC2620_CsMask, LTC2620_NUMBITS, - LTC2620_ClkMask, LTC2620_DigMask, LTC2620_DigOffset); + LTC2620_ClkMask, LTC2620_DigMask, LTC2620_DigOffset, 0); } @@ -143,24 +143,24 @@ void LTC2620_SetDaisy(int cmd, int data, int dacaddr, int chipIndex) { uint32_t valw = 0; int ichip = 0; - FILE_LOG(logDEBUG1, ("(Daisy) desired chip index:%d, nchip:%d, dac ch:%d, val:%d, cmd:0x%x \n", + FILE_LOG(logDEBUG2, ("(Daisy) 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 uint32_t codata = (((data << LTC2620_DAC_DATA_OFST) & LTC2620_DAC_DATA_MSK) | ((dacaddr << LTC2620_DAC_ADDR_OFST) & LTC2620_DAC_ADDR_MSK) | cmd); - FILE_LOG(logDEBUG1, ("codata: 0x%x\n", codata)); + FILE_LOG(logDEBUG2, ("codata: 0x%x\n", codata)); // select all chips (ctb daisy chain; others 1 chip) - FILE_LOG(logDEBUG1, ("Selecting LTC2620\n")); + FILE_LOG(logDEBUG2, ("Selecting LTC2620\n")); SPIChipSelect (&valw, LTC2620_Reg, LTC2620_CsMask, LTC2620_ClkMask, LTC2620_DigMask); // send same data to all if (chipIndex < 0) { - FILE_LOG(logDEBUG1, ("Send same data to all\n")); + FILE_LOG(logDEBUG2, ("Send same data to all\n")); for (ichip = 0; ichip < nchip; ++ichip) { - FILE_LOG(logDEBUG1, ("Send data (0x%x) to ichip %d\n", codata, ichip)); + FILE_LOG(logDEBUG2, ("Send data (0x%x) to ichip %d\n", codata, ichip)); LTC2620_SendDaisyData(&valw, codata); } } @@ -169,24 +169,24 @@ void LTC2620_SetDaisy(int cmd, int data, int dacaddr, int chipIndex) { else { // send nothing to subsequent ichips (daisy chain) (if any chips after desired chip) for (ichip = chipIndex + 1; ichip < nchip; ++ichip) { - FILE_LOG(logDEBUG1, ("Send nothing to ichip %d\n", ichip)); + FILE_LOG(logDEBUG2, ("Send nothing to ichip %d\n", ichip)); LTC2620_SendDaisyData(&valw, LTC2620_DAC_CMD_NO_OPRTN_VAL); } // send data to desired chip - FILE_LOG(logDEBUG1, ("Send data (0x%x) to ichip %d\n", codata, chipIndex)); + FILE_LOG(logDEBUG2, ("Send data (0x%x) to ichip %d\n", codata, chipIndex)); LTC2620_SendDaisyData(&valw, codata); // send nothing to preceding ichips (daisy chain) (if any chips in front of desired chip) for (ichip = 0; ichip < chipIndex; ++ichip) { - FILE_LOG(logDEBUG1, ("Send nothing to ichip %d\n", ichip)); + FILE_LOG(logDEBUG2, ("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, ("Deselecting LTC2620\n")); - SPIChipDeselect(&valw, LTC2620_Reg, LTC2620_CsMask, LTC2620_ClkMask); + FILE_LOG(logDEBUG2, ("Deselecting LTC2620\n")); + SPIChipDeselect(&valw, LTC2620_Reg, LTC2620_CsMask, LTC2620_ClkMask, LTC2620_DigMask, 0); } @@ -200,14 +200,14 @@ void LTC2620_SetDaisy(int cmd, int data, int dacaddr, int chipIndex) { */ void LTC2620_Set(int cmd, int data, int dacaddr, int chipIndex) { FILE_LOG(logDEBUG1, ("cmd:0x%x, data:%d, dacaddr:%d, chipIndex:%d\n", cmd, data, dacaddr, chipIndex)); - FILE_LOG(logDEBUG1, (" ================================================\n")); + FILE_LOG(logDEBUG2, (" ================================================\n")); // ctb if (LTC2620_Ndac > LTC2620_NUMCHANNELS) LTC2620_SetDaisy(cmd, data, dacaddr, chipIndex); // others else LTC2620_SetSingle(cmd, data, dacaddr); - FILE_LOG(logDEBUG1, (" ================================================\n")); + FILE_LOG(logDEBUG2, (" ================================================\n")); } diff --git a/slsDetectorServers/slsDetectorServer/MAX1932.h b/slsDetectorServers/slsDetectorServer/MAX1932.h index 662f90117..99aabed01 100755 --- a/slsDetectorServers/slsDetectorServer/MAX1932.h +++ b/slsDetectorServers/slsDetectorServer/MAX1932.h @@ -88,7 +88,7 @@ int MAX1932_Set (int val) { FILE_LOG(logINFO, ("\t%dV (dacval %d)\n", val, dacvalue)); serializeToSPI(MAX1932_Reg, dacvalue, MAX1932_CsMask, MAX1932_HV_NUMBITS, - MAX1932_ClkMask, MAX1932_DigMask, MAX1932_DigOffset); + MAX1932_ClkMask, MAX1932_DigMask, MAX1932_DigOffset, 0); return OK; } diff --git a/slsDetectorServers/slsDetectorServer/commonServerFunctions.h b/slsDetectorServers/slsDetectorServer/commonServerFunctions.h index a69aad8a7..644dc6cce 100755 --- a/slsDetectorServers/slsDetectorServer/commonServerFunctions.h +++ b/slsDetectorServers/slsDetectorServer/commonServerFunctions.h @@ -18,8 +18,8 @@ void SPIChipSelect (uint32_t* valw, uint32_t addr, uint32_t csmask, uint32_t cl } -void SPIChipDeselect (uint32_t* valw, uint32_t addr, uint32_t csmask, uint32_t clkmask) { - FILE_LOG(logDEBUG2, ("SPI chip deselect. valw:0x%08x addr:0x%x csmask:0x%x, clkmask:0x%x\n", +void SPIChipDeselect (uint32_t* valw, uint32_t addr, uint32_t csmask, uint32_t clkmask, uint32_t digoutmask, int convBit) { + FILE_LOG(logDEBUG2, ("SPI chip deselect. valw:0x%08x addr:0x%x csmask:0x%x, clkmask:0x%x digmask:0x%x\n", *valw, addr, csmask, clkmask)); // chip sel bar up @@ -33,7 +33,12 @@ void SPIChipDeselect (uint32_t* valw, uint32_t addr, uint32_t csmask, uint32_t FILE_LOG(logDEBUG2, ("clk down. valw:0x%08x\n", *valw)); // stop point = start point of course - (*valw) |= csmask; + (*valw) &= ~digoutmask; + if (convBit) { + (*valw) &= ~csmask; + } else { + (*valw) |= csmask; + } bus_w (addr, (*valw)); //FIXME: for ctb slow adcs, might need to set it to low again FILE_LOG(logDEBUG2, ("stop point. valw:0x%08x\n", *valw)); } @@ -88,7 +93,7 @@ uint32_t receiveDataFromSPI (uint32_t* valw, uint32_t addr, int numbitstoreceive return retval; } -void serializeToSPI(uint32_t addr, uint32_t val, uint32_t csmask, int numbitstosend, uint32_t clkmask, uint32_t digoutmask, int digofset) { +void serializeToSPI(uint32_t addr, uint32_t val, uint32_t csmask, int numbitstosend, uint32_t clkmask, uint32_t digoutmask, int digofset, int convBit) { if (numbitstosend == 16) { FILE_LOG(logDEBUG2, ("Writing to SPI Register: 0x%04x\n", val)); } else { @@ -100,10 +105,10 @@ void serializeToSPI(uint32_t addr, uint32_t val, uint32_t csmask, int numbitstos sendDataToSPI(&valw, addr, val, numbitstosend, clkmask, digoutmask, digofset); - SPIChipDeselect(&valw, addr, csmask, clkmask); + SPIChipDeselect(&valw, addr, csmask, clkmask, digoutmask, convBit); } -uint32_t serializeFromSPI(uint32_t addr, uint32_t csmask, int numbitstoreceive, uint32_t clkmask, uint32_t digoutmask, uint32_t readaddr) { +uint32_t serializeFromSPI(uint32_t addr, uint32_t csmask, int numbitstoreceive, uint32_t clkmask, uint32_t digoutmask, uint32_t readaddr, int convBit) { uint32_t valw; @@ -111,7 +116,7 @@ uint32_t serializeFromSPI(uint32_t addr, uint32_t csmask, int numbitstoreceive, uint32_t retval = receiveDataFromSPI(&valw, addr, numbitstoreceive, clkmask, readaddr); - SPIChipDeselect(&valw, addr, csmask, clkmask); + SPIChipDeselect(&valw, addr, csmask, clkmask, digoutmask, convBit); // moving this before bringin up earlier changes temp of slow adc if (numbitstoreceive == 16) { FILE_LOG(logDEBUG2, ("Read From SPI Register: 0x%04x\n", retval)); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index bb13a3609..b3dcd43cb 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -1203,7 +1203,7 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { ++i; /*! \page settings - - v_chip [i] mv Sets/gets value for Vchip on the new chiptest board. Must be in mV. \c Returns \c (int ["mV"]). Normally don't use it! + - v_chip [i] mv Sets/gets value for Vchip on the new chiptest board. Must be in mV. \c Returns \c (int ["mV"]). Do NOT use it, unless you are completely sure you won't fry the board! */ descrToFuncMap[i].m_pFuncName = "v_chip"; // descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdDAC; From 20edf61e30b2930b25e18a979c4daadbfbae6691 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 22 Feb 2019 13:53:59 +0100 Subject: [PATCH 3/3] ctb server: removed unnecessary prints, resulting in a bug fix for slow adc temp --- slsDetectorServers/slsDetectorServer/AD7689.h | 2 +- slsDetectorServers/slsDetectorServer/I2C.h | 44 +++++++++---------- .../slsDetectorServer/LTC2620.h | 2 +- .../slsDetectorServer/commonServerFunctions.h | 32 +++++++++++--- .../slsDetector/slsDetectorCommand.cpp | 2 +- 5 files changed, 50 insertions(+), 32 deletions(-) diff --git a/slsDetectorServers/slsDetectorServer/AD7689.h b/slsDetectorServers/slsDetectorServer/AD7689.h index d06dcfb52..9e6c8f59a 100755 --- a/slsDetectorServers/slsDetectorServer/AD7689.h +++ b/slsDetectorServers/slsDetectorServer/AD7689.h @@ -103,7 +103,7 @@ void AD7689_SetDefines(uint32_t reg, uint32_t roreg, uint32_t cmsk, uint32_t clk void AD7689_Disable() { bus_w(AD7689_Reg, (bus_r(AD7689_Reg) &~(AD7689_CnvMask) - | AD7689_ClkMask + &~AD7689_ClkMask &~(AD7689_DigMask))); } diff --git a/slsDetectorServers/slsDetectorServer/I2C.h b/slsDetectorServers/slsDetectorServer/I2C.h index ad687003f..8768076f3 100755 --- a/slsDetectorServers/slsDetectorServer/I2C.h +++ b/slsDetectorServers/slsDetectorServer/I2C.h @@ -167,31 +167,31 @@ void I2C_ConfigureI2CCore(uint32_t creg, uint32_t sreg, * @returns value read from register */ uint32_t I2C_Read(uint32_t devId, uint32_t addr) { - FILE_LOG(logDEBUG1, (" ================================================\n")); - FILE_LOG(logDEBUG1, (" Reading from I2C device 0x%x and reg 0x%x\n", devId, addr)); + FILE_LOG(logDEBUG2, (" ================================================\n")); + FILE_LOG(logDEBUG2, (" Reading from I2C device 0x%x and reg 0x%x\n", devId, addr)); // device Id mask uint32_t devIdMask = ((devId << I2C_TFR_CMD_ADDR_OFST) & I2C_TFR_CMD_ADDR_MSK); - FILE_LOG(logDEBUG1, (" devId:0x%x\n", devIdMask)); + FILE_LOG(logDEBUG2, (" devId:0x%x\n", devIdMask)); // write I2C ID bus_w(I2C_Transfer_Command_Fifo_Reg, (devIdMask & ~(I2C_TFR_CMD_RW_MSK))); - FILE_LOG(logDEBUG1, (" write devID and R/-W:0x%x\n", (devIdMask & ~(I2C_TFR_CMD_RW_MSK)))); + FILE_LOG(logDEBUG2, (" write devID and R/-W:0x%x\n", (devIdMask & ~(I2C_TFR_CMD_RW_MSK)))); // write register addr bus_w(I2C_Transfer_Command_Fifo_Reg, addr); - FILE_LOG(logDEBUG1, (" write addr:0x%x\n", addr)); + FILE_LOG(logDEBUG2, (" write addr:0x%x\n", addr)); // repeated start with read (repeated start needed here because it was in write operation mode earlier, for the device ID) bus_w(I2C_Transfer_Command_Fifo_Reg, (devIdMask | I2C_TFR_CMD_RPTD_STRT_MSK | I2C_TFR_CMD_RW_READ_VAL)); - FILE_LOG(logDEBUG1, (" repeated start:0x%x\n", (devIdMask | I2C_TFR_CMD_RPTD_STRT_MSK | I2C_TFR_CMD_RW_READ_VAL))); + FILE_LOG(logDEBUG2, (" repeated start:0x%x\n", (devIdMask | I2C_TFR_CMD_RPTD_STRT_MSK | I2C_TFR_CMD_RW_READ_VAL))); // continue reading bus_w(I2C_Transfer_Command_Fifo_Reg, 0x0); - FILE_LOG(logDEBUG1, (" continue reading:0x%x\n", 0x0)); + FILE_LOG(logDEBUG2, (" continue reading:0x%x\n", 0x0)); // stop reading bus_w(I2C_Transfer_Command_Fifo_Reg, I2C_TFR_CMD_STOP_MSK); - FILE_LOG(logDEBUG1, (" stop reading:0x%x\n", I2C_TFR_CMD_STOP_MSK)); + FILE_LOG(logDEBUG2, (" stop reading:0x%x\n", I2C_TFR_CMD_STOP_MSK)); // read value uint32_t retval = 0; @@ -201,24 +201,24 @@ uint32_t I2C_Read(uint32_t devId, uint32_t addr) { int status = 1; while(status) { status = bus_r(I2C_Status_Reg) & I2C_STATUS_BUSY_MSK; - FILE_LOG(logDEBUG1, (" status:%d\n", status)); + FILE_LOG(logDEBUG2, (" status:%d\n", status)); usleep(0); } // get rx fifo level (get number of bytes to be received) int level = bus_r(I2C_Rx_Data_Fifo_Level_Reg); - FILE_LOG(logDEBUG1, (" level:%d\n", level)); + FILE_LOG(logDEBUG2, (" level:%d\n", level)); int iloop = level - 1; // level bytes to read, read 1 byte at a time for (iloop = level - 1; iloop >= 0; --iloop) { u_int16_t byte = bus_r(I2C_Rx_Data_Fifo_Reg) & I2C_RX_DATA_FIFO_RXDATA_MSK; - FILE_LOG(logDEBUG1, (" byte nr %d:0x%x\n", iloop, byte)); + FILE_LOG(logDEBUG2, (" byte nr %d:0x%x\n", iloop, byte)); // push by 1 byte at a time retval |= (byte << (8 * iloop)); } - FILE_LOG(logDEBUG1, (" retval:0x%x\n", retval)); - FILE_LOG(logDEBUG1, (" ================================================\n")); + FILE_LOG(logDEBUG2, (" retval:0x%x\n", retval)); + FILE_LOG(logDEBUG2, (" ================================================\n")); return retval; } @@ -229,34 +229,34 @@ 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, (" ================================================\n")); - FILE_LOG(logDEBUG1, (" Writing to I2C (Device:0x%x, reg:0x%x, data:%d)\n", devId, addr, data)); + FILE_LOG(logDEBUG2, (" ================================================\n")); + FILE_LOG(logDEBUG2, (" 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); - FILE_LOG(logDEBUG1, (" devId:0x%x\n", devId)); + FILE_LOG(logDEBUG2, (" devId:0x%x\n", devId)); // write I2C ID bus_w(I2C_Transfer_Command_Fifo_Reg, (devIdMask & ~(I2C_TFR_CMD_RW_MSK))); - FILE_LOG(logDEBUG1, (" write devID and R/-W:0x%x\n", (devIdMask & ~(I2C_TFR_CMD_RW_MSK)))); + FILE_LOG(logDEBUG2, (" write devID and R/-W:0x%x\n", (devIdMask & ~(I2C_TFR_CMD_RW_MSK)))); // write register addr bus_w(I2C_Transfer_Command_Fifo_Reg, addr); - FILE_LOG(logDEBUG1, (" write addr:0x%x\n", addr)); + FILE_LOG(logDEBUG2, (" write addr:0x%x\n", addr)); // do not do the repeated start as it is already in write operation mode (else it wont work) uint8_t msb = (uint8_t)((data & 0xFF00) >> 8); uint8_t lsb = (uint8_t)(data & 0x00FF); - FILE_LOG(logDEBUG1, (" msb:0x%02x, lsb:0x%02x\n", msb, lsb)); + FILE_LOG(logDEBUG2, (" msb:0x%02x, lsb:0x%02x\n", msb, lsb)); // writing data MSB bus_w(I2C_Transfer_Command_Fifo_Reg, ((msb << I2C_TFR_CMD_DATA_FR_WR_OFST) & I2C_TFR_CMD_DATA_FR_WR_MSK)); - FILE_LOG(logDEBUG1, (" write msb:0x%02x\n", ((msb << I2C_TFR_CMD_DATA_FR_WR_OFST) & I2C_TFR_CMD_DATA_FR_WR_MSK))); + FILE_LOG(logDEBUG2, (" write msb:0x%02x\n", ((msb << I2C_TFR_CMD_DATA_FR_WR_OFST) & I2C_TFR_CMD_DATA_FR_WR_MSK))); // writing data LSB and stop writing bit bus_w(I2C_Transfer_Command_Fifo_Reg, ((lsb << I2C_TFR_CMD_DATA_FR_WR_OFST) & I2C_TFR_CMD_DATA_FR_WR_MSK) | I2C_TFR_CMD_STOP_MSK); - FILE_LOG(logDEBUG1, (" write lsb and stop writing:0x%x\n", ((lsb << I2C_TFR_CMD_DATA_FR_WR_OFST) & I2C_TFR_CMD_DATA_FR_WR_MSK) | I2C_TFR_CMD_STOP_MSK)); - FILE_LOG(logDEBUG1, (" ================================================\n")); + FILE_LOG(logDEBUG2, (" write lsb and stop writing:0x%x\n", ((lsb << I2C_TFR_CMD_DATA_FR_WR_OFST) & I2C_TFR_CMD_DATA_FR_WR_MSK) | I2C_TFR_CMD_STOP_MSK)); + FILE_LOG(logDEBUG2, (" ================================================\n")); } diff --git a/slsDetectorServers/slsDetectorServer/LTC2620.h b/slsDetectorServers/slsDetectorServer/LTC2620.h index 538ceedd3..f2b0bff9b 100755 --- a/slsDetectorServers/slsDetectorServer/LTC2620.h +++ b/slsDetectorServers/slsDetectorServer/LTC2620.h @@ -154,7 +154,7 @@ void LTC2620_SetDaisy(int cmd, int data, int dacaddr, int chipIndex) { // select all chips (ctb daisy chain; others 1 chip) FILE_LOG(logDEBUG2, ("Selecting LTC2620\n")); - SPIChipSelect (&valw, LTC2620_Reg, LTC2620_CsMask, LTC2620_ClkMask, LTC2620_DigMask); + SPIChipSelect (&valw, LTC2620_Reg, LTC2620_CsMask, LTC2620_ClkMask, LTC2620_DigMask, 0); // send same data to all if (chipIndex < 0) { diff --git a/slsDetectorServers/slsDetectorServer/commonServerFunctions.h b/slsDetectorServers/slsDetectorServer/commonServerFunctions.h index 644dc6cce..1f44df843 100755 --- a/slsDetectorServers/slsDetectorServer/commonServerFunctions.h +++ b/slsDetectorServers/slsDetectorServer/commonServerFunctions.h @@ -1,16 +1,25 @@ #pragma once #include "blackfin.h" +#include // usleep -void SPIChipSelect (uint32_t* valw, uint32_t addr, uint32_t csmask, uint32_t clkmask, uint32_t digoutmask) { - FILE_LOG(logDEBUG2, ("SPI chip select. valw:0x%08x addr:0x%x csmask:0x%x, clkmask:0x%x digmask:0x%x\n", - *valw, addr, csmask, clkmask, digoutmask)); +void SPIChipSelect (uint32_t* valw, uint32_t addr, uint32_t csmask, uint32_t clkmask, uint32_t digoutmask, int convBit) { + FILE_LOG(logDEBUG2, ("SPI chip select. valw:0x%08x addr:0x%x csmask:0x%x, clkmask:0x%x digmask:0x%x convbit:%d\n", + *valw, addr, csmask, clkmask, digoutmask, convBit)); + + // needed for the slow adcs for apprx 20 ns before and after rising of convbit (usleep val is vague assumption) + if (convBit) + usleep(20); // start point (*valw) = ((bus_r(addr) | csmask | clkmask) &(~digoutmask)); bus_w (addr, (*valw)); FILE_LOG(logDEBUG2, ("startpoint. valw:0x%08x\n", *valw)); + // needed for the slow adcs for apprx 10 ns before and after rising of convbit (usleep val is vague assumption) + if (convBit) + usleep(10); + // chip sel bar down (*valw) &= ~csmask; bus_w (addr, (*valw)); @@ -19,14 +28,22 @@ void SPIChipSelect (uint32_t* valw, uint32_t addr, uint32_t csmask, uint32_t cl void SPIChipDeselect (uint32_t* valw, uint32_t addr, uint32_t csmask, uint32_t clkmask, uint32_t digoutmask, int convBit) { - FILE_LOG(logDEBUG2, ("SPI chip deselect. valw:0x%08x addr:0x%x csmask:0x%x, clkmask:0x%x digmask:0x%x\n", - *valw, addr, csmask, clkmask)); + FILE_LOG(logDEBUG2, ("SPI chip deselect. valw:0x%08x addr:0x%x csmask:0x%x, clkmask:0x%x digmask:0x%x convbit:%d\n", + *valw, addr, csmask, clkmask, digoutmask, convBit)); + + // needed for the slow adcs for apprx 20 ns before and after rising of convbit (usleep val is vague assumption) + if (convBit) + usleep(20); // chip sel bar up (*valw) |= csmask; bus_w (addr, (*valw)); FILE_LOG(logDEBUG2, ("chip sel bar up. valw:0x%08x\n", *valw)); + // needed for the slow adcs for apprx 10 ns before and after rising of convbit (usleep val is vague assumption) + if (convBit) + usleep(10); + //clk down (*valw) &= ~clkmask; bus_w (addr, (*valw)); @@ -34,6 +51,7 @@ void SPIChipDeselect (uint32_t* valw, uint32_t addr, uint32_t csmask, uint32_t // stop point = start point of course (*valw) &= ~digoutmask; + // slow adcs use convBit (has to go high and then low) instead of csmask if (convBit) { (*valw) &= ~csmask; } else { @@ -101,7 +119,7 @@ void serializeToSPI(uint32_t addr, uint32_t val, uint32_t csmask, int numbitstos } uint32_t valw; - SPIChipSelect (&valw, addr, csmask, clkmask, digoutmask); + SPIChipSelect (&valw, addr, csmask, clkmask, digoutmask, convBit); sendDataToSPI(&valw, addr, val, numbitstosend, clkmask, digoutmask, digofset); @@ -112,7 +130,7 @@ uint32_t serializeFromSPI(uint32_t addr, uint32_t csmask, int numbitstoreceive, uint32_t valw; - SPIChipSelect (&valw, addr, csmask, clkmask, digoutmask); + SPIChipSelect (&valw, addr, csmask, clkmask, digoutmask, convBit); uint32_t retval = receiveDataFromSPI(&valw, addr, numbitstoreceive, clkmask, readaddr); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index b3dcd43cb..f55c38ccf 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -4097,7 +4097,7 @@ std::string slsDetectorCommand::cmdADC(int narg, char *args[], int action, int d //if ((adc == TEMPERATURE_ADC) || (adc == TEMPERATURE_FPGA)) if (adc < 100 || adc == SLOW_ADC_TEMP) - strcat(answer," °C"); + strcat(answer,"°C"); else if (adc == I_POWER_A || adc == I_POWER_B || adc == I_POWER_C || adc == I_POWER_D || adc == I_POWER_IO) strcat(answer," mA"); else