mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-22 09:37:59 +02:00
Separate headers (#57)
* WIP, ctb * WIP, eiger * WIP, gotthard * WIP, jungfrau * WIP, gotthard2 * WIP, mythen3 * WIP, moench * fixed gotthard apiversioning mismatch with gotthard2
This commit is contained in:
49
slsDetectorServers/slsDetectorServer/include/AD7689.h
Executable file
49
slsDetectorServers/slsDetectorServer/include/AD7689.h
Executable file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
/**
|
||||
* Set Defines
|
||||
* @param reg spi register
|
||||
* @param roreg spi readout register
|
||||
* @param cmsk conversion mask
|
||||
* @param clkmsk clock output mask
|
||||
* @param dmsk digital output mask
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* Disable SPI
|
||||
*/
|
||||
void AD7689_Disable();
|
||||
|
||||
/**
|
||||
* Set SPI reg value
|
||||
* @param codata value to be set
|
||||
*/
|
||||
void AD7689_Set(uint32_t codata);
|
||||
|
||||
/**
|
||||
* Get SPI reg value
|
||||
* @returns SPI reg value
|
||||
*/
|
||||
uint16_t AD7689_Get();
|
||||
|
||||
/**
|
||||
* Get temperature
|
||||
* @returns temperature in °C
|
||||
*/
|
||||
int AD7689_GetTemperature();
|
||||
|
||||
/**
|
||||
* Reads channels voltage
|
||||
* @param ichan channel number from 0 to 7
|
||||
* @returns channel voltage in mV
|
||||
*/
|
||||
int AD7689_GetChannel(int ichan);
|
||||
|
||||
/**
|
||||
* Configure
|
||||
*/
|
||||
void AD7689_Configure();
|
29
slsDetectorServers/slsDetectorServer/include/AD9252.h
Executable file
29
slsDetectorServers/slsDetectorServer/include/AD9252.h
Executable file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
/**
|
||||
* Set Defines
|
||||
* @param reg spi register
|
||||
* @param cmsk chip select mask
|
||||
* @param clkmsk clock output mask
|
||||
* @param dmsk digital output mask
|
||||
* @param dofst digital output offset
|
||||
*/
|
||||
void AD9252_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst);
|
||||
|
||||
/**
|
||||
* Disable SPI
|
||||
*/
|
||||
void AD9252_Disable();
|
||||
|
||||
/**
|
||||
* Set SPI reg value
|
||||
* @param codata value to be set
|
||||
*/
|
||||
void AD9252_Set(int addr, int val);
|
||||
|
||||
/**
|
||||
* Configure
|
||||
*/
|
||||
void AD9252_Configure();
|
41
slsDetectorServers/slsDetectorServer/include/AD9257.h
Executable file
41
slsDetectorServers/slsDetectorServer/include/AD9257.h
Executable file
@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
/**
|
||||
* Set Defines
|
||||
* @param reg spi register
|
||||
* @param cmsk chip select mask
|
||||
* @param clkmsk clock output mask
|
||||
* @param dmsk digital output mask
|
||||
* @param dofst digital output offset
|
||||
*/
|
||||
void AD9257_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst);
|
||||
|
||||
/**
|
||||
* Disable SPI
|
||||
*/
|
||||
void AD9257_Disable() ;
|
||||
|
||||
/**
|
||||
* Get vref voltage
|
||||
*/
|
||||
int AD9257_GetVrefVoltage(int mV);
|
||||
|
||||
/**
|
||||
* Set vref voltage
|
||||
* @param val voltage to be set (0 for 1.0V, 1 for 1.14V, 2 for 1.33V, 3 for 1.6V, 4 for 2.0V
|
||||
* @returns ok or fail
|
||||
*/
|
||||
int AD9257_SetVrefVoltage(int val, int mV);
|
||||
|
||||
/**
|
||||
* Set SPI reg value
|
||||
* @param codata value to be set
|
||||
*/
|
||||
void AD9257_Set(int addr, int val);
|
||||
|
||||
/**
|
||||
* Configure
|
||||
*/
|
||||
void AD9257_Configure();
|
54
slsDetectorServers/slsDetectorServer/include/ALTERA_PLL.h
Executable file
54
slsDetectorServers/slsDetectorServer/include/ALTERA_PLL.h
Executable file
@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
/**
|
||||
* Set Defines
|
||||
* @param creg control register
|
||||
* @param preg parameter register
|
||||
* @param rprmsk reconfig parameter reset mask
|
||||
* @param wpmsk write parameter mask
|
||||
* @param prmsk pll reset mask
|
||||
* @param amsk address mask
|
||||
* @param aofst address offset
|
||||
*/
|
||||
void ALTERA_PLL_SetDefines(uint32_t creg, uint32_t preg, uint32_t rprmsk, uint32_t wpmsk, uint32_t prmsk, uint32_t amsk, int aofst);
|
||||
|
||||
/**
|
||||
* Reset only PLL
|
||||
*/
|
||||
void ALTERA_PLL_ResetPLL ();
|
||||
|
||||
/**
|
||||
* Reset PLL Reconfiguration and PLL
|
||||
*/
|
||||
void ALTERA_PLL_ResetPLLAndReconfiguration ();
|
||||
|
||||
/**
|
||||
* Set PLL Reconfig register
|
||||
* @param reg register
|
||||
* @param val value
|
||||
*/
|
||||
void ALTERA_PLL_SetPllReconfigReg(uint32_t reg, uint32_t val);
|
||||
|
||||
/**
|
||||
* Write Phase Shift
|
||||
* @param phase phase shift
|
||||
* @param clkIndex clock index
|
||||
* @param pos 1 if up down direction of shift is positive, else 0
|
||||
*/
|
||||
void ALTERA_PLL_SetPhaseShift(int32_t phase, int clkIndex, int pos);
|
||||
|
||||
/**
|
||||
* Set PLL mode register to polling mode
|
||||
*/
|
||||
void ALTERA_PLL_SetModePolling();
|
||||
/**
|
||||
* Calculate and write output frequency
|
||||
* @param clkIndex clock index
|
||||
* @param pllVCOFreqMhz PLL VCO Frequency in Mhz
|
||||
* @param value frequency to set to
|
||||
* @param frequency set
|
||||
*/
|
||||
int ALTERA_PLL_SetOuputFrequency (int clkIndex, int pllVCOFreqMhz, int value);
|
||||
|
38
slsDetectorServers/slsDetectorServer/include/I2C.h
Executable file
38
slsDetectorServers/slsDetectorServer/include/I2C.h
Executable file
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
/**
|
||||
* Configure the I2C core,
|
||||
* Enable core and
|
||||
* Calibrate the calibration register for current readout
|
||||
* @param creg control register (defined in RegisterDefs.h)
|
||||
* @param sreg status register (defined in RegisterDefs.h)
|
||||
* @param rreg rx data fifo register (defined in RegisterDefs.h)
|
||||
* @param rlvlreg rx data fifo level register (defined in RegisterDefs.h)
|
||||
* @param slreg scl low count register (defined in RegisterDefs.h)
|
||||
* @param shreg scl high count register (defined in RegisterDefs.h)
|
||||
* @param sdreg sda hold register (defined in RegisterDefs.h)
|
||||
* @param treg transfer command fifo register (defined in RegisterDefs.h)
|
||||
*/
|
||||
void I2C_ConfigureI2CCore(uint32_t creg, uint32_t sreg,
|
||||
uint32_t rreg, uint32_t rlvlreg,
|
||||
uint32_t slreg, uint32_t shreg, uint32_t sdreg, uint32_t treg);
|
||||
|
||||
/**
|
||||
* Read register
|
||||
* @param deviceId device Id
|
||||
* @param addr register address
|
||||
* @returns value read from register
|
||||
*/
|
||||
uint32_t I2C_Read(uint32_t devId, uint32_t addr);
|
||||
|
||||
/**
|
||||
* Write register (16 bit value)
|
||||
* @param deviceId device Id
|
||||
* @param addr register address
|
||||
* @param data data to be written (16 bit)
|
||||
*/
|
||||
void I2C_Write(uint32_t devId, uint32_t addr, uint16_t data);
|
||||
|
||||
|
39
slsDetectorServers/slsDetectorServer/include/INA226.h
Executable file
39
slsDetectorServers/slsDetectorServer/include/INA226.h
Executable file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
/**
|
||||
* Configure the I2C core and Enable core
|
||||
* @param rOhm shunt resister value in Ohms (defined in slsDetectorServer_defs.h)
|
||||
* @param creg control register (defined in RegisterDefs.h)
|
||||
* @param sreg status register (defined in RegisterDefs.h)
|
||||
* @param rreg rx data fifo register (defined in RegisterDefs.h)
|
||||
* @param rlvlreg rx data fifo level register (defined in RegisterDefs.h)
|
||||
* @param slreg scl low count register (defined in RegisterDefs.h)
|
||||
* @param shreg scl high count register (defined in RegisterDefs.h)
|
||||
* @param sdreg sda hold register (defined in RegisterDefs.h)
|
||||
* @param treg transfer command fifo register (defined in RegisterDefs.h)
|
||||
*/
|
||||
void INA226_ConfigureI2CCore(double rOhm, uint32_t creg, uint32_t sreg,
|
||||
uint32_t rreg, uint32_t rlvlreg,
|
||||
uint32_t slreg, uint32_t shreg, uint32_t sdreg, uint32_t treg);
|
||||
|
||||
/**
|
||||
* Calibrate resolution of current register
|
||||
* @param deviceId device Id (defined in slsDetectorServer_defs.h)
|
||||
*/
|
||||
void INA226_CalibrateCurrentRegister(uint32_t deviceId);
|
||||
|
||||
/**
|
||||
* Read voltage of device
|
||||
* @param deviceId device Id
|
||||
* @returns voltage in mV
|
||||
*/
|
||||
int INA226_ReadVoltage(uint32_t deviceId);
|
||||
|
||||
/**
|
||||
* Read current
|
||||
* @param deviceId device Id
|
||||
* @returns current in mA
|
||||
*/
|
||||
int INA226_ReadCurrent(uint32_t deviceId);
|
115
slsDetectorServers/slsDetectorServer/include/LTC2620.h
Executable file
115
slsDetectorServers/slsDetectorServer/include/LTC2620.h
Executable file
@ -0,0 +1,115 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
/**
|
||||
* Set Defines
|
||||
* @param reg spi register
|
||||
* @param cmsk chip select mask
|
||||
* @param clkmsk clock output mask
|
||||
* @param dmsk digital output mask
|
||||
* @param dofst digital output offset
|
||||
* @param nd total number of dacs for this board (for dac channel and daisy chain chip id)
|
||||
* @param minMV minimum voltage determined by hardware
|
||||
* @param maxMV maximum voltage determined by hardware
|
||||
*/
|
||||
void LTC2620_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst, int nd, int minMV, int maxMV);
|
||||
|
||||
/**
|
||||
* Disable SPI
|
||||
*/
|
||||
void LTC2620_Disable();
|
||||
|
||||
/**
|
||||
* Get power down value
|
||||
*/
|
||||
int LTC2620_GetPowerDownValue();
|
||||
|
||||
/**
|
||||
* Get minimum input value for dac
|
||||
*/
|
||||
int LTC2620_GetMinInput();
|
||||
|
||||
/**
|
||||
* Get maximum input value for dac
|
||||
*/
|
||||
int LTC2620_GetMaxInput();
|
||||
|
||||
/**
|
||||
* Get max number of steps
|
||||
*/
|
||||
int LTC2620_GetMaxNumSteps();
|
||||
|
||||
/**
|
||||
* Convert voltage to dac units
|
||||
* @param voltage value in mv
|
||||
* @param dacval pointer to value converted to dac units
|
||||
* @returns FAIL when voltage outside limits, OK if conversion successful
|
||||
*/
|
||||
int LTC2620_VoltageToDac(int voltage, int* dacval);
|
||||
|
||||
/**
|
||||
* Convert dac units to voltage
|
||||
* @param dacval dac units
|
||||
* @param voltage pointer to value converted to mV
|
||||
* @returns FAIL when voltage outside limits, OK if conversion successful
|
||||
*/
|
||||
int LTC2620_DacToVoltage(int dacval, int* voltage);
|
||||
|
||||
/**
|
||||
* Set a single chip (all non ctb detectors use this)
|
||||
* when max dac is 8
|
||||
* @param cmd command
|
||||
* @param data dac value to be set
|
||||
* @param dacaddr dac channel number in chip
|
||||
*/
|
||||
void LTC2620_SetSingle(int cmd, int data, int dacaddr);
|
||||
|
||||
/**
|
||||
* bit bang the data into all the chips daisy fashion
|
||||
* @param valw current value of register while bit banging
|
||||
* @param val data to be sent (data, dac addr and command)
|
||||
*/
|
||||
void LTC2620_SendDaisyData(uint32_t* valw, uint32_t val);
|
||||
|
||||
/**
|
||||
* Set a single chip (all non ctb detectors use this)
|
||||
* when max dac is 8
|
||||
* @param cmd command
|
||||
* @param data dac value to be set
|
||||
* @param dacaddr dac channel number in chip
|
||||
* @param chipIndex index of the chip
|
||||
*/
|
||||
void LTC2620_SetDaisy(int cmd, int data, int dacaddr, int chipIndex);
|
||||
|
||||
/**
|
||||
* Sets a single chip (LTC2620_SetSingle) or multiple chip (LTC2620_SetDaisy)
|
||||
* multiple chip is only for ctb where the multiple chips are connected in daisy fashion
|
||||
* @param cmd command to send
|
||||
* @param data dac value to be set
|
||||
* @param dacaddr dac channel number for the chip
|
||||
* @param chipIndex the chip to be set
|
||||
*/
|
||||
void LTC2620_Set(int cmd, int data, int dacaddr, int chipIndex);
|
||||
|
||||
/**
|
||||
* Configure (obtains dacaddr, command and ichip and calls LTC2620_Set)
|
||||
*/
|
||||
void LTC2620_Configure();
|
||||
|
||||
/**
|
||||
* Set Dac (obtains dacaddr, command and ichip and calls LTC2620_Set)
|
||||
* @param dacnum dac number
|
||||
* @param data dac value to set
|
||||
*/
|
||||
void LTC2620_SetDAC (int dacnum, int data);
|
||||
|
||||
/**
|
||||
* Set dac in dac units or mV
|
||||
* @param dacnum dac index
|
||||
* @param val value in dac units or mV
|
||||
* @param mV 0 for dac units and 1 for mV unit
|
||||
* @param dacval pointer to value in dac units
|
||||
* @returns OK or FAIL for success of operation
|
||||
*/
|
||||
int LTC2620_SetDACValue (int dacnum, int val, int mV, int* dacval);
|
31
slsDetectorServers/slsDetectorServer/include/MAX1932.h
Executable file
31
slsDetectorServers/slsDetectorServer/include/MAX1932.h
Executable file
@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
/**
|
||||
* Set Defines
|
||||
* @param reg spi register
|
||||
* @param cmsk chip select mask
|
||||
* @param clkmsk clock output mask
|
||||
* @param dmsk digital output mask
|
||||
* @param dofst digital output offset
|
||||
* @param minMV minimum voltage determined by hardware
|
||||
* @param maxMV maximum voltage determined by hardware
|
||||
*/
|
||||
void MAX1932_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst,
|
||||
int minMV, int maxMV);
|
||||
|
||||
/**
|
||||
* Disable SPI
|
||||
*/
|
||||
void MAX1932_Disable();
|
||||
|
||||
/**
|
||||
* Set value
|
||||
* @param val value to set
|
||||
* @return OK or FAIL
|
||||
*/
|
||||
int MAX1932_Set (int val) ;
|
||||
|
||||
|
||||
|
26
slsDetectorServers/slsDetectorServer/include/UDPPacketHeaderGenerator.h
Executable file
26
slsDetectorServers/slsDetectorServer/include/UDPPacketHeaderGenerator.h
Executable file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
/**
|
||||
* Get current udp packet number
|
||||
*/
|
||||
uint32_t getUDPPacketNumber();
|
||||
|
||||
/**
|
||||
* Get current udp frame number
|
||||
*/
|
||||
uint64_t getUDPFrameNumber();
|
||||
|
||||
/**
|
||||
* Called for each UDP packet header creation
|
||||
* @param buffer pointer to header
|
||||
* @param id module id
|
||||
*/
|
||||
void createUDPPacketHeader(char* buffer, uint16_t id);
|
||||
|
||||
/**
|
||||
* fill up the udp packet with data till its full
|
||||
* @param buffer pointer to memory
|
||||
*/
|
||||
int fillUDPPacket(char* buffer);
|
105
slsDetectorServers/slsDetectorServer/include/blackfin.h
Executable file
105
slsDetectorServers/slsDetectorServer/include/blackfin.h
Executable file
@ -0,0 +1,105 @@
|
||||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
/** I2C defines */
|
||||
#define I2C_CLOCK_MHZ (131.25)
|
||||
|
||||
/**
|
||||
* Write into a 16 bit register
|
||||
* @param offset address offset
|
||||
* @param data 16 bit data
|
||||
*/
|
||||
void bus_w16(u_int32_t offset, u_int16_t data);
|
||||
|
||||
/**
|
||||
* Read from a 16 bit register
|
||||
* @param offset address offset
|
||||
* @retuns 16 bit data read
|
||||
*/
|
||||
u_int16_t bus_r16(u_int32_t offset);
|
||||
|
||||
/**
|
||||
* Write into a 32 bit register
|
||||
* @param offset address offset
|
||||
* @param data 32 bit data
|
||||
*/
|
||||
void bus_w(u_int32_t offset, u_int32_t data);
|
||||
|
||||
/**
|
||||
* Read from a 32 bit register
|
||||
* @param offset address offset
|
||||
* @retuns 32 bit data read
|
||||
*/
|
||||
u_int32_t bus_r(u_int32_t offset);
|
||||
|
||||
/**
|
||||
* Read from a 64 bit register
|
||||
* @param aLSB LSB offset address
|
||||
* @param aMSB MSB offset address
|
||||
* @returns 64 bit data read
|
||||
*/
|
||||
int64_t get64BitReg(int aLSB, int aMSB);
|
||||
|
||||
/**
|
||||
* Write into a 64 bit register
|
||||
* @param value 64 bit data
|
||||
* @param aLSB LSB offset address
|
||||
* @param aMSB MSB offset address
|
||||
* @returns 64 bit data read
|
||||
*/
|
||||
int64_t set64BitReg(int64_t value, int aLSB, int aMSB);
|
||||
|
||||
/**
|
||||
* Read unsigned 64 bit from a 64 bit register
|
||||
* @param aLSB LSB offset address
|
||||
* @param aMSB MSB offset address
|
||||
* @returns unsigned 64 bit data read
|
||||
*/
|
||||
uint64_t getU64BitReg(int aLSB, int aMSB);
|
||||
|
||||
/**
|
||||
* Write unsigned 64 bit into a 64 bit register
|
||||
* @param value unsigned 64 bit data
|
||||
* @param aLSB LSB offset address
|
||||
* @param aMSB MSB offset address
|
||||
*/
|
||||
void setU64BitReg(uint64_t value, int aLSB, int aMSB);
|
||||
|
||||
/**
|
||||
* Read from a 32 bit register (literal register value provided by client)
|
||||
* @param offset address offset
|
||||
* @retuns 32 bit data read
|
||||
*/
|
||||
u_int32_t readRegister(u_int32_t offset);
|
||||
|
||||
/**
|
||||
* Write into a 32 bit register (literal register value provided by client)
|
||||
* @param offset address offset
|
||||
* @param data 32 bit data
|
||||
*/
|
||||
u_int32_t writeRegister(u_int32_t offset, u_int32_t data);
|
||||
|
||||
/**
|
||||
* Read from a 16 bit register (literal register value provided by client)
|
||||
* @param offset address offset
|
||||
* @retuns 16 bit data read
|
||||
*/
|
||||
u_int32_t readRegister16(u_int32_t offset);
|
||||
|
||||
/**
|
||||
* Write into a 16 bit register (literal register value provided by client)
|
||||
* @param offset address offset
|
||||
* @param data 16 bit data
|
||||
*/
|
||||
u_int32_t writeRegister16(u_int32_t offset, u_int32_t data);
|
||||
|
||||
/**
|
||||
* Get base address for memory copy
|
||||
*/
|
||||
uint64_t Blackfin_getBaseAddress();
|
||||
/**
|
||||
* Map FPGA
|
||||
*/
|
||||
int mapCSP0(void);
|
14
slsDetectorServers/slsDetectorServer/include/common.h
Executable file
14
slsDetectorServers/slsDetectorServer/include/common.h
Executable file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* Convert a value from a range to a different range (eg voltage to dac or vice versa)
|
||||
* @param inputMin input minimum
|
||||
* @param inputMax input maximum
|
||||
* @param outputMin output minimum
|
||||
* @param outputMax output maximum
|
||||
* @param inputValue input value
|
||||
* @param outputValue pointer to output value
|
||||
* @returns FAIL if input value is out of bounds, else OK
|
||||
*/
|
||||
int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int outputMax,
|
||||
int inputValue, int* outputValue);
|
15
slsDetectorServers/slsDetectorServer/include/commonServerFunctions.h
Executable file
15
slsDetectorServers/slsDetectorServer/include/commonServerFunctions.h
Executable file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
void SPIChipSelect (uint32_t* valw, uint32_t addr, uint32_t csmask, uint32_t clkmask, uint32_t digoutmask, int convBit);
|
||||
|
||||
void SPIChipDeselect (uint32_t* valw, uint32_t addr, uint32_t csmask, uint32_t clkmask, uint32_t digoutmask, int convBit);
|
||||
|
||||
void sendDataToSPI (uint32_t* valw, uint32_t addr, uint32_t val, int numbitstosend, uint32_t clkmask, uint32_t digoutmask, int digofset);
|
||||
|
||||
uint32_t receiveDataFromSPI (uint32_t* valw, uint32_t addr, int numbitstoreceive, uint32_t clkmask, uint32_t readaddr) ;
|
||||
|
||||
void serializeToSPI(uint32_t addr, uint32_t val, uint32_t csmask, int numbitstosend, uint32_t clkmask, uint32_t digoutmask, int digofset, int convBit);
|
||||
|
||||
uint32_t serializeFromSPI(uint32_t addr, uint32_t csmask, int numbitstoreceive, uint32_t clkmask, uint32_t digoutmask, uint32_t readaddr, int convBit);
|
34
slsDetectorServers/slsDetectorServer/include/communication_funcs_UDP.h
Executable file
34
slsDetectorServers/slsDetectorServer/include/communication_funcs_UDP.h
Executable file
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
/**
|
||||
* Get UDP socket desicriptor
|
||||
* @param udp port index
|
||||
*/
|
||||
int getUdPSocketDescriptor(int index);
|
||||
|
||||
/**
|
||||
* Set udp destination
|
||||
* @param index udp port index
|
||||
* @param ip udp destination ip
|
||||
* @param port udp destination port
|
||||
*/
|
||||
int setUDPDestinationDetails(int index, const char* ip, unsigned short int port);
|
||||
|
||||
/**
|
||||
* Create udp socket
|
||||
* @param index udp port index
|
||||
*/
|
||||
int createUDPSocket(int index);
|
||||
|
||||
/**
|
||||
* Writes to socket file descriptor
|
||||
* @param index udp port index
|
||||
* @param buf pointer to memory to write
|
||||
* @param length length of buffer to write to socket
|
||||
*/
|
||||
int sendUDPPacket(int index, const char* buf, int length);
|
||||
|
||||
/**
|
||||
* Close udp socket
|
||||
* @index udp port index
|
||||
*/
|
||||
void closeUDPSocket(int index);
|
52
slsDetectorServers/slsDetectorServer/include/programfpga.h
Executable file
52
slsDetectorServers/slsDetectorServer/include/programfpga.h
Executable file
@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/**
|
||||
* Define GPIO pins if not defined
|
||||
*/
|
||||
void defineGPIOpins();
|
||||
|
||||
/**
|
||||
* Notify FPGA to not touch flash
|
||||
*/
|
||||
void FPGAdontTouchFlash();
|
||||
|
||||
/**
|
||||
* Notify FPGA to program from flash
|
||||
*/
|
||||
void FPGATouchFlash();
|
||||
|
||||
/**
|
||||
* Reset FPGA
|
||||
*/
|
||||
void resetFPGA();
|
||||
|
||||
/**
|
||||
* Erasing flash
|
||||
*/
|
||||
void eraseFlash();
|
||||
|
||||
/**
|
||||
* Open the drive to copy program and
|
||||
* notify FPGA not to touch the program
|
||||
* @param filefp pointer to flash
|
||||
* @return 0 for success, 1 for fail (cannot open file for writing program)
|
||||
*/
|
||||
int startWritingFPGAprogram(FILE** filefp);
|
||||
|
||||
/**
|
||||
* When done writing the program, close file pointer and
|
||||
* notify FPGA to pick up the program from flash
|
||||
* @param filefp pointer to flash
|
||||
*/
|
||||
void stopWritingFPGAprogram(FILE* filefp);
|
||||
|
||||
/**
|
||||
* Write FPGA Program to flash
|
||||
* @param fpgasrc source program
|
||||
* @param fsize size of program
|
||||
* @param filefp pointer to flash
|
||||
* @return 0 for success, 1 for fail (cannot write)
|
||||
*/
|
||||
int writeFPGAProgram(char* fpgasrc, size_t fsize, FILE* filefp);
|
@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "AD7689.h"
|
||||
#include "commonServerFunctions.h" // blackfin.h, ansi.h
|
||||
#include "common.h"
|
||||
#include "blackfin.h"
|
||||
#include "clogger.h"
|
||||
|
||||
|
||||
/* AD7689 ADC DEFINES */
|
||||
|
||||
@ -69,7 +71,7 @@
|
||||
#define AD7689_INT_MAX_STEPS (0xFFFF + 1)
|
||||
#define AD7689_TMP_C_FOR_1_MV (25.00 / 283.00)
|
||||
|
||||
|
||||
// Definitions from the fpga
|
||||
uint32_t AD7689_Reg = 0x0;
|
||||
uint32_t AD7689_ROReg = 0x0;
|
||||
uint32_t AD7689_CnvMask = 0x0;
|
||||
@ -77,15 +79,6 @@ uint32_t AD7689_ClkMask = 0x0;
|
||||
uint32_t AD7689_DigMask = 0x0;
|
||||
int AD7689_DigOffset = 0x0;
|
||||
|
||||
/**
|
||||
* Set Defines
|
||||
* @param reg spi register
|
||||
* @param roreg spi readout register
|
||||
* @param cmsk conversion mask
|
||||
* @param clkmsk clock output mask
|
||||
* @param dmsk digital output mask
|
||||
* @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));
|
||||
@ -97,9 +90,6 @@ void AD7689_SetDefines(uint32_t reg, uint32_t roreg, uint32_t cmsk, uint32_t clk
|
||||
AD7689_DigOffset = dofst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable SPI
|
||||
*/
|
||||
void AD7689_Disable() {
|
||||
bus_w(AD7689_Reg, (bus_r(AD7689_Reg)
|
||||
&~(AD7689_CnvMask)
|
||||
@ -107,30 +97,18 @@ void AD7689_Disable() {
|
||||
&~(AD7689_DigMask)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set SPI reg value
|
||||
* @param codata value to be set
|
||||
*/
|
||||
void AD7689_Set(u_int32_t codata) {
|
||||
void AD7689_Set(uint32_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, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SPI reg value
|
||||
* @returns SPI reg value
|
||||
*/
|
||||
uint16_t AD7689_Get() {
|
||||
FILE_LOG(logINFO, ("\tGetting ADC SPI Register.\n"));
|
||||
return (uint16_t)serializeFromSPI(AD7689_Reg, AD7689_CnvMask, AD7689_ADC_DATA_NUMBITS,
|
||||
AD7689_ClkMask, AD7689_DigMask, AD7689_ROReg, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get temperature
|
||||
* @returns temperature in °C
|
||||
*/
|
||||
int AD7689_GetTemperature() {
|
||||
AD7689_Set(
|
||||
// read back
|
||||
@ -167,11 +145,6 @@ int AD7689_GetTemperature() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads channels voltage
|
||||
* @param ichan channel number from 0 to 7
|
||||
* @returns channel voltage in mV
|
||||
*/
|
||||
int AD7689_GetChannel(int ichan) {
|
||||
// filter channels val
|
||||
if (ichan < 0 || ichan >= AD7689_NUM_CHANNELS) {
|
||||
@ -209,9 +182,6 @@ int AD7689_GetChannel(int ichan) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure
|
||||
*/
|
||||
void AD7689_Configure(){
|
||||
FILE_LOG(logINFOBLUE, ("Configuring AD7689 (Slow ADCs): \n"));
|
||||
|
@ -1,9 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "AD9252.h"
|
||||
#include "commonServerFunctions.h" // blackfin.h, ansi.h
|
||||
#ifdef GOTTHARDD
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include "blackfin.h"
|
||||
#include "clogger.h"
|
||||
|
||||
/* AD9252 ADC DEFINES */
|
||||
#define AD9252_ADC_NUMBITS (24)
|
||||
@ -100,20 +98,13 @@
|
||||
#define AD9252_OUT_CLK_600_VAL ((0xa << AD9252_OUT_CLK_OFST) & AD9252_OUT_CLK_MSK)
|
||||
#define AD9252_OUT_CLK_660_VAL ((0xb << AD9252_OUT_CLK_OFST) & AD9252_OUT_CLK_MSK) // 0xb - 0xf is 660
|
||||
|
||||
// defines from the fpga
|
||||
uint32_t AD9252_Reg = 0x0;
|
||||
uint32_t AD9252_CsMask = 0x0;
|
||||
uint32_t AD9252_ClkMask = 0x0;
|
||||
uint32_t AD9252_DigMask = 0x0;
|
||||
int AD9252_DigOffset = 0x0;
|
||||
|
||||
/**
|
||||
* Set Defines
|
||||
* @param reg spi register
|
||||
* @param cmsk chip select mask
|
||||
* @param clkmsk clock output mask
|
||||
* @param dmsk digital output mask
|
||||
* @param dofst digital output offset
|
||||
*/
|
||||
void AD9252_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst) {
|
||||
AD9252_Reg = reg;
|
||||
AD9252_CsMask = cmsk;
|
||||
@ -122,9 +113,6 @@ void AD9252_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dm
|
||||
AD9252_DigOffset = dofst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable SPI
|
||||
*/
|
||||
void AD9252_Disable() {
|
||||
bus_w(AD9252_Reg, (bus_r(AD9252_Reg)
|
||||
| AD9252_CsMask
|
||||
@ -132,10 +120,6 @@ void AD9252_Disable() {
|
||||
&~(AD9252_DigMask));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set SPI reg value
|
||||
* @param codata value to be set
|
||||
*/
|
||||
void AD9252_Set(int addr, int val) {
|
||||
|
||||
u_int32_t codata;
|
||||
@ -145,9 +129,6 @@ void AD9252_Set(int addr, int val) {
|
||||
AD9252_ClkMask, AD9252_DigMask, AD9252_DigOffset, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure
|
||||
*/
|
||||
void AD9252_Configure(){
|
||||
FILE_LOG(logINFOBLUE, ("Configuring ADC9252:\n"));
|
||||
|
@ -1,9 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "AD9257.h"
|
||||
#include "commonServerFunctions.h" // blackfin.h, ansi.h
|
||||
#ifdef GOTTHARDD
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include "blackfin.h"
|
||||
#include "clogger.h"
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
/* AD9257 ADC DEFINES */
|
||||
#define AD9257_ADC_NUMBITS (24)
|
||||
@ -126,6 +125,7 @@
|
||||
#define AD9257_VREF_1_6_VAL ((0x3 << AD9257_VREF_OFST) & AD9257_VREF_MSK)
|
||||
#define AD9257_VREF_2_0_VAL ((0x4 << AD9257_VREF_OFST) & AD9257_VREF_MSK)
|
||||
|
||||
// defines from the fpga
|
||||
uint32_t AD9257_Reg = 0x0;
|
||||
uint32_t AD9257_CsMask = 0x0;
|
||||
uint32_t AD9257_ClkMask = 0x0;
|
||||
@ -133,14 +133,6 @@ uint32_t AD9257_DigMask = 0x0;
|
||||
int AD9257_DigOffset = 0x0;
|
||||
int AD9257_VrefVoltage = 0;
|
||||
|
||||
/**
|
||||
* Set Defines
|
||||
* @param reg spi register
|
||||
* @param cmsk chip select mask
|
||||
* @param clkmsk clock output mask
|
||||
* @param dmsk digital output mask
|
||||
* @param dofst digital output offset
|
||||
*/
|
||||
void AD9257_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst) {
|
||||
AD9257_Reg = reg;
|
||||
AD9257_CsMask = cmsk;
|
||||
@ -149,9 +141,6 @@ void AD9257_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dm
|
||||
AD9257_DigOffset = dofst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable SPI
|
||||
*/
|
||||
void AD9257_Disable() {
|
||||
bus_w(AD9257_Reg, (bus_r(AD9257_Reg)
|
||||
| AD9257_CsMask
|
||||
@ -159,9 +148,6 @@ void AD9257_Disable() {
|
||||
& ~(AD9257_DigMask));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get vref voltage
|
||||
*/
|
||||
int AD9257_GetVrefVoltage(int mV) {
|
||||
if (mV == 0)
|
||||
return AD9257_VrefVoltage;
|
||||
@ -182,11 +168,6 @@ int AD9257_GetVrefVoltage(int mV) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set vref voltage
|
||||
* @param val voltage to be set (0 for 1.0V, 1 for 1.14V, 2 for 1.33V, 3 for 1.6V, 4 for 2.0V
|
||||
* @returns ok or fail
|
||||
*/
|
||||
int AD9257_SetVrefVoltage(int val, int mV) {
|
||||
int mode = val;
|
||||
// convert to mode
|
||||
@ -240,10 +221,6 @@ int AD9257_SetVrefVoltage(int val, int mV) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set SPI reg value
|
||||
* @param codata value to be set
|
||||
*/
|
||||
void AD9257_Set(int addr, int val) {
|
||||
|
||||
u_int32_t codata;
|
||||
@ -253,9 +230,6 @@ void AD9257_Set(int addr, int val) {
|
||||
AD9257_ClkMask, AD9257_DigMask, AD9257_DigOffset, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure
|
||||
*/
|
||||
void AD9257_Configure(){
|
||||
FILE_LOG(logINFOBLUE, ("Configuring ADC9257:\n"));
|
||||
|
@ -1,4 +1,6 @@
|
||||
#pragma once
|
||||
#include "ALTERA_PLL.h"
|
||||
#include "clogger.h"
|
||||
#include "blackfin.h"
|
||||
|
||||
#include <unistd.h> // usleep
|
||||
|
||||
@ -72,6 +74,7 @@
|
||||
#define ALTERA_PLL_WAIT_TIME_US (10 * 1000)
|
||||
|
||||
|
||||
// defines from the fpga
|
||||
uint32_t ALTERA_PLL_Cntrl_Reg = 0x0;
|
||||
uint32_t ALTERA_PLL_Param_Reg = 0x0;
|
||||
uint32_t ALTERA_PLL_Cntrl_RcnfgPrmtrRstMask = 0x0;
|
||||
@ -81,16 +84,6 @@ uint32_t ALTERA_PLL_Cntrl_AddrMask = 0x0;
|
||||
int ALTERA_PLL_Cntrl_AddrOfst = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Set Defines
|
||||
* @param creg control register
|
||||
* @param preg parameter register
|
||||
* @param rprmsk reconfig parameter reset mask
|
||||
* @param wpmsk write parameter mask
|
||||
* @param prmsk pll reset mask
|
||||
* @param amsk address mask
|
||||
* @param aofst address offset
|
||||
*/
|
||||
void ALTERA_PLL_SetDefines(uint32_t creg, uint32_t preg, uint32_t rprmsk, uint32_t wpmsk, uint32_t prmsk, uint32_t amsk, int aofst) {
|
||||
ALTERA_PLL_Cntrl_Reg = creg;
|
||||
ALTERA_PLL_Param_Reg = preg;
|
||||
@ -101,9 +94,6 @@ void ALTERA_PLL_SetDefines(uint32_t creg, uint32_t preg, uint32_t rprmsk, uint32
|
||||
ALTERA_PLL_Cntrl_AddrOfst = aofst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset only PLL
|
||||
*/
|
||||
void ALTERA_PLL_ResetPLL () {
|
||||
FILE_LOG(logINFO, ("Resetting only PLL\n"));
|
||||
|
||||
@ -119,9 +109,6 @@ void ALTERA_PLL_ResetPLL () {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset PLL Reconfiguration and PLL
|
||||
*/
|
||||
void ALTERA_PLL_ResetPLLAndReconfiguration () {
|
||||
FILE_LOG(logINFO, ("Resetting PLL and Reconfiguration\n"));
|
||||
|
||||
@ -130,12 +117,6 @@ void ALTERA_PLL_ResetPLLAndReconfiguration () {
|
||||
bus_w(ALTERA_PLL_Cntrl_Reg, bus_r(ALTERA_PLL_Cntrl_Reg) & ~ALTERA_PLL_Cntrl_RcnfgPrmtrRstMask & ~ALTERA_PLL_Cntrl_PLLRstMask);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set PLL Reconfig register
|
||||
* @param reg register
|
||||
* @param val value
|
||||
*/
|
||||
void ALTERA_PLL_SetPllReconfigReg(uint32_t reg, uint32_t val) {
|
||||
FILE_LOG(logDEBUG1, ("Setting PLL Reconfig Reg, reg:0x%x, val:0x%x)\n", reg, val));
|
||||
|
||||
@ -164,12 +145,6 @@ void ALTERA_PLL_SetPllReconfigReg(uint32_t reg, uint32_t val) {
|
||||
usleep(ALTERA_PLL_WAIT_TIME_US);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write Phase Shift
|
||||
* @param phase phase shift
|
||||
* @param clkIndex clock index
|
||||
* @param pos 1 if up down direction of shift is positive, else 0
|
||||
*/
|
||||
void ALTERA_PLL_SetPhaseShift(int32_t phase, int clkIndex, int pos) {
|
||||
FILE_LOG(logINFO, ("\tWriting PLL Phase Shift\n"));
|
||||
uint32_t value = (((phase << ALTERA_PLL_SHIFT_NUM_SHIFTS_OFST) & ALTERA_PLL_SHIFT_NUM_SHIFTS_MSK) |
|
||||
@ -182,21 +157,11 @@ void ALTERA_PLL_SetPhaseShift(int32_t phase, int clkIndex, int pos) {
|
||||
ALTERA_PLL_SetPllReconfigReg(ALTERA_PLL_PHASE_SHIFT_REG, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PLL mode register to polling mode
|
||||
*/
|
||||
void ALTERA_PLL_SetModePolling() {
|
||||
FILE_LOG(logINFO, ("\tSetting Polling Mode\n"));
|
||||
ALTERA_PLL_SetPllReconfigReg(ALTERA_PLL_MODE_REG, ALTERA_PLL_MODE_PLLNG_MD_VAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate and write output frequency
|
||||
* @param clkIndex clock index
|
||||
* @param pllVCOFreqMhz PLL VCO Frequency in Mhz
|
||||
* @param value frequency to set to
|
||||
* @param frequency set
|
||||
*/
|
||||
int ALTERA_PLL_SetOuputFrequency (int clkIndex, int pllVCOFreqMhz, int value) {
|
||||
FILE_LOG(logDEBUG1, ("C%d: Setting output frequency to %d (pllvcofreq: %dMhz)\n", clkIndex, value, pllVCOFreqMhz));
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "I2C.h"
|
||||
#include "blackfin.h"
|
||||
#include "clogger.h"
|
||||
|
||||
#include <unistd.h> // usleep
|
||||
|
||||
/**
|
||||
@ -86,6 +87,7 @@
|
||||
//#define I2C_RX_DATA_FIFO_LVL_OFST (0)
|
||||
//#define I2C_RX_DATA_FIFO_LVL_MSK (0x000000FF << I2C_RX_DATA_FIFO_LVL_OFST)
|
||||
|
||||
// defines in the fpga
|
||||
uint32_t I2C_Control_Reg = 0x0;
|
||||
uint32_t I2C_Status_Reg = 0x0;
|
||||
uint32_t I2C_Rx_Data_Fifo_Reg = 0x0;
|
||||
@ -95,19 +97,7 @@ uint32_t I2C_Scl_High_Count_Reg = 0x0;
|
||||
uint32_t I2C_Sda_Hold_Reg = 0x0;
|
||||
uint32_t I2C_Transfer_Command_Fifo_Reg = 0x0;
|
||||
|
||||
/**
|
||||
* Configure the I2C core,
|
||||
* Enable core and
|
||||
* Calibrate the calibration register for current readout
|
||||
* @param creg control register (defined in RegisterDefs.h)
|
||||
* @param sreg status register (defined in RegisterDefs.h)
|
||||
* @param rreg rx data fifo register (defined in RegisterDefs.h)
|
||||
* @param rlvlreg rx data fifo level register (defined in RegisterDefs.h)
|
||||
* @param slreg scl low count register (defined in RegisterDefs.h)
|
||||
* @param shreg scl high count register (defined in RegisterDefs.h)
|
||||
* @param sdreg sda hold register (defined in RegisterDefs.h)
|
||||
* @param treg transfer command fifo register (defined in RegisterDefs.h)
|
||||
*/
|
||||
|
||||
void I2C_ConfigureI2CCore(uint32_t creg, uint32_t sreg,
|
||||
uint32_t rreg, uint32_t rlvlreg,
|
||||
uint32_t slreg, uint32_t shreg, uint32_t sdreg, uint32_t treg) {
|
||||
@ -160,12 +150,6 @@ void I2C_ConfigureI2CCore(uint32_t creg, uint32_t sreg,
|
||||
//The INA226 supports the transmission protocol for fast mode (1 kHz to 400 kHz) and high-speed mode (1 kHz to 2.94 MHz).
|
||||
}
|
||||
|
||||
/**
|
||||
* Read register
|
||||
* @param deviceId device Id
|
||||
* @param addr register address
|
||||
* @returns value read from register
|
||||
*/
|
||||
uint32_t I2C_Read(uint32_t devId, uint32_t addr) {
|
||||
FILE_LOG(logDEBUG2, (" ================================================\n"));
|
||||
FILE_LOG(logDEBUG2, (" Reading from I2C device 0x%x and reg 0x%x\n", devId, addr));
|
||||
@ -222,12 +206,6 @@ uint32_t I2C_Read(uint32_t devId, uint32_t addr) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write register (16 bit value)
|
||||
* @param deviceId device Id
|
||||
* @param addr register address
|
||||
* @param data data to be written (16 bit)
|
||||
*/
|
||||
void I2C_Write(uint32_t devId, uint32_t addr, uint16_t data) {
|
||||
FILE_LOG(logDEBUG2, (" ================================================\n"));
|
||||
FILE_LOG(logDEBUG2, (" Writing to I2C (Device:0x%x, reg:0x%x, data:%d)\n", devId, addr, data));
|
@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "INA226.h"
|
||||
#include "I2C.h"
|
||||
#include "clogger.h"
|
||||
#include "common.h"
|
||||
|
||||
#include "math.h"
|
||||
|
||||
/**
|
||||
@ -52,24 +54,12 @@
|
||||
/** get current unit */
|
||||
#define INA226_getConvertedCurrentUnits(shuntV, calibReg) ((double)shuntV * (double)calibReg / (double)2048)
|
||||
|
||||
// defines from the fpga
|
||||
double INA226_Shunt_Resistor_Ohm = 0.0;
|
||||
int INA226_Calibration_Register_Value = 0;
|
||||
|
||||
#define INA226_CALIBRATION_CURRENT_TOLERANCE (1.2268)
|
||||
|
||||
|
||||
/**
|
||||
* Configure the I2C core and Enable core
|
||||
* @param rOhm shunt resister value in Ohms (defined in slsDetectorServer_defs.h)
|
||||
* @param creg control register (defined in RegisterDefs.h)
|
||||
* @param sreg status register (defined in RegisterDefs.h)
|
||||
* @param rreg rx data fifo register (defined in RegisterDefs.h)
|
||||
* @param rlvlreg rx data fifo level register (defined in RegisterDefs.h)
|
||||
* @param slreg scl low count register (defined in RegisterDefs.h)
|
||||
* @param shreg scl high count register (defined in RegisterDefs.h)
|
||||
* @param sdreg sda hold register (defined in RegisterDefs.h)
|
||||
* @param treg transfer command fifo register (defined in RegisterDefs.h)
|
||||
*/
|
||||
void INA226_ConfigureI2CCore(double rOhm, uint32_t creg, uint32_t sreg,
|
||||
uint32_t rreg, uint32_t rlvlreg,
|
||||
uint32_t slreg, uint32_t shreg, uint32_t sdreg, uint32_t treg) {
|
||||
@ -80,10 +70,6 @@ void INA226_ConfigureI2CCore(double rOhm, uint32_t creg, uint32_t sreg,
|
||||
I2C_ConfigureI2CCore(creg, sreg, rreg, rlvlreg, slreg, shreg, sdreg, treg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calibrate resolution of current register
|
||||
* @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
|
||||
@ -104,11 +90,6 @@ void INA226_CalibrateCurrentRegister(uint32_t deviceId) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read voltage of device
|
||||
* @param deviceId device Id
|
||||
* @returns voltage in mV
|
||||
*/
|
||||
int INA226_ReadVoltage(uint32_t deviceId) {
|
||||
FILE_LOG(logDEBUG1, (" Reading voltage\n"));
|
||||
uint32_t regval = I2C_Read(deviceId, INA226_BUS_VOLTAGE_REG);
|
||||
@ -129,11 +110,6 @@ int INA226_ReadVoltage(uint32_t deviceId) {
|
||||
return voltagemV;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read current
|
||||
* @param deviceId device Id
|
||||
* @returns current in mA
|
||||
*/
|
||||
int INA226_ReadCurrent(uint32_t deviceId) {
|
||||
FILE_LOG(logDEBUG1, (" Reading current\n"));
|
||||
|
@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "LTC2620.h"
|
||||
#include "commonServerFunctions.h" // blackfin.h, ansi.h
|
||||
#include "common.h"
|
||||
#include "blackfin.h"
|
||||
#include "clogger.h"
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@ -29,6 +31,11 @@
|
||||
#define LTC2620_MAX_VAL (4095) // 12 bits
|
||||
#define LTC2620_MAX_STEPS (LTC2620_MAX_VAL + 1)
|
||||
|
||||
#ifdef CHIPTESTBOARDD
|
||||
#include "slsDetectorServer_defs.h"
|
||||
#endif
|
||||
|
||||
// defines from the fpga
|
||||
uint32_t LTC2620_Reg = 0x0;
|
||||
uint32_t LTC2620_CsMask = 0x0;
|
||||
uint32_t LTC2620_ClkMask = 0x0;
|
||||
@ -38,17 +45,6 @@ int LTC2620_Ndac = 0;
|
||||
int LTC2620_MinVoltage = 0;
|
||||
int LTC2620_MaxVoltage = 0;
|
||||
|
||||
/**
|
||||
* Set Defines
|
||||
* @param reg spi register
|
||||
* @param cmsk chip select mask
|
||||
* @param clkmsk clock output mask
|
||||
* @param dmsk digital output mask
|
||||
* @param dofst digital output offset
|
||||
* @param nd total number of dacs for this board (for dac channel and daisy chain chip id)
|
||||
* @param minMV minimum voltage determined by hardware
|
||||
* @param maxMV maximum voltage determined by hardware
|
||||
*/
|
||||
void LTC2620_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst, int nd, int minMV, int maxMV) {
|
||||
LTC2620_Reg = reg;
|
||||
LTC2620_CsMask = cmsk;
|
||||
@ -60,10 +56,6 @@ void LTC2620_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t d
|
||||
LTC2620_MaxVoltage = maxMV;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Disable SPI
|
||||
*/
|
||||
void LTC2620_Disable() {
|
||||
bus_w(LTC2620_Reg, (bus_r(LTC2620_Reg)
|
||||
| LTC2620_CsMask
|
||||
@ -71,40 +63,34 @@ void LTC2620_Disable() {
|
||||
& ~(LTC2620_DigMask));
|
||||
}
|
||||
|
||||
int LTC2620_GetPowerDownValue() {
|
||||
return LTC2620_PWR_DOWN_VAL;
|
||||
}
|
||||
|
||||
int LTC2620_GetMinInput() {
|
||||
return LTC2620_MIN_VAL;
|
||||
}
|
||||
|
||||
int LTC2620_GetMaxInput() {
|
||||
return LTC2620_MAX_VAL;
|
||||
}
|
||||
|
||||
int LTC2620_GetMaxNumSteps() {
|
||||
return LTC2620_MAX_STEPS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert voltage to dac units
|
||||
* @param voltage value in mv
|
||||
* @param dacval pointer to value converted to dac units
|
||||
* @returns FAIL when voltage outside limits, OK if conversion successful
|
||||
*/
|
||||
int LTC2620_VoltageToDac(int voltage, int* dacval) {
|
||||
return ConvertToDifferentRange(LTC2620_MinVoltage, LTC2620_MaxVoltage,
|
||||
LTC2620_MIN_VAL, LTC2620_MAX_VAL,
|
||||
voltage, dacval);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert dac units to voltage
|
||||
* @param dacval dac units
|
||||
* @param voltage pointer to value converted to mV
|
||||
* @returns FAIL when voltage outside limits, OK if conversion successful
|
||||
*/
|
||||
int LTC2620_DacToVoltage(int dacval, int* voltage) {
|
||||
return ConvertToDifferentRange( LTC2620_MIN_VAL, LTC2620_MAX_VAL,
|
||||
LTC2620_MinVoltage, LTC2620_MaxVoltage,
|
||||
dacval, voltage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set a single chip (all non ctb detectors use this)
|
||||
* when max dac is 8
|
||||
* @param cmd command
|
||||
* @param data dac value to be set
|
||||
* @param dacaddr dac channel number in chip
|
||||
*/
|
||||
void LTC2620_SetSingle(int cmd, int data, int dacaddr) {
|
||||
FILE_LOG(logDEBUG2, ("(Single) dac addr:%d, dac value:%d, cmd:%d\n", dacaddr, data, cmd));
|
||||
|
||||
@ -117,26 +103,11 @@ void LTC2620_SetSingle(int cmd, int data, int dacaddr) {
|
||||
LTC2620_ClkMask, LTC2620_DigMask, LTC2620_DigOffset, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* bit bang the data into all the chips daisy fashion
|
||||
* @param valw current value of register while bit banging
|
||||
* @param val data to be sent (data, dac addr and command)
|
||||
*/
|
||||
void LTC2620_SendDaisyData(uint32_t* valw, uint32_t val) {
|
||||
sendDataToSPI(valw, LTC2620_Reg, val, LTC2620_DAISY_CHAIN_NUMBITS,
|
||||
LTC2620_ClkMask, LTC2620_DigMask, LTC2620_DigOffset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set a single chip (all non ctb detectors use this)
|
||||
* when max dac is 8
|
||||
* @param cmd command
|
||||
* @param data dac value to be set
|
||||
* @param dacaddr dac channel number in chip
|
||||
* @param chipIndex index of the chip
|
||||
*/
|
||||
void LTC2620_SetDaisy(int cmd, int data, int dacaddr, int chipIndex) {
|
||||
|
||||
int nchip = LTC2620_Ndac / LTC2620_NUMCHANNELS;
|
||||
@ -189,15 +160,6 @@ void LTC2620_SetDaisy(int cmd, int data, int dacaddr, int chipIndex) {
|
||||
SPIChipDeselect(&valw, LTC2620_Reg, LTC2620_CsMask, LTC2620_ClkMask, LTC2620_DigMask, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets a single chip (LTC2620_SetSingle) or multiple chip (LTC2620_SetDaisy)
|
||||
* multiple chip is only for ctb where the multiple chips are connected in daisy fashion
|
||||
* @param cmd command to send
|
||||
* @param data dac value to be set
|
||||
* @param dacaddr dac channel number for the chip
|
||||
* @param chipIndex the chip to be set
|
||||
*/
|
||||
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(logDEBUG2, (" ================================================\n"));
|
||||
@ -210,10 +172,6 @@ void LTC2620_Set(int cmd, int data, int dacaddr, int chipIndex) {
|
||||
FILE_LOG(logDEBUG2, (" ================================================\n"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Configure (obtains dacaddr, command and ichip and calls LTC2620_Set)
|
||||
*/
|
||||
void LTC2620_Configure(){
|
||||
FILE_LOG(logINFOBLUE, ("Configuring LTC2620\n"));
|
||||
|
||||
@ -230,12 +188,6 @@ void LTC2620_Configure(){
|
||||
LTC2620_Set(cmd, data, addr, -1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set Dac (obtains dacaddr, command and ichip and calls LTC2620_Set)
|
||||
* @param dacnum dac number
|
||||
* @param data dac value to set
|
||||
*/
|
||||
void LTC2620_SetDAC (int dacnum, int data) {
|
||||
FILE_LOG(logDEBUG1, ("Setting dac %d to %d\n", dacnum, data));
|
||||
// LTC2620 index
|
||||
@ -258,14 +210,6 @@ void LTC2620_SetDAC (int dacnum, int data) {
|
||||
LTC2620_Set(cmd, data, addr, ichip);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set dac in dac units or mV
|
||||
* @param dacnum dac index
|
||||
* @param val value in dac units or mV
|
||||
* @param mV 0 for dac units and 1 for mV unit
|
||||
* @param dacval pointer to value in dac units
|
||||
* @returns OK or FAIL for success of operation
|
||||
*/
|
||||
int LTC2620_SetDACValue (int dacnum, int val, int mV, int* dacval) {
|
||||
FILE_LOG(logDEBUG1, ("dacnum:%d, val:%d, ismV:%d\n", dacnum, val, mV));
|
||||
// validate index
|
@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "MAX1932.h"
|
||||
#include "commonServerFunctions.h" // blackfin.h, ansi.h
|
||||
#include "blackfin.h"
|
||||
#include "clogger.h"
|
||||
#include "common.h"
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
/* MAX1932 HV DEFINES */
|
||||
|
||||
@ -12,6 +15,7 @@
|
||||
#define MAX1932_MAX_DAC_VAL (0x1)
|
||||
#define MAX1932_POWER_OFF_DAC_VAL (0x0)
|
||||
|
||||
// defines from the fpga
|
||||
uint32_t MAX1932_Reg = 0x0;
|
||||
uint32_t MAX1932_CsMask = 0x0;
|
||||
uint32_t MAX1932_ClkMask = 0x0;
|
||||
@ -20,17 +24,6 @@ int MAX1932_DigOffset = 0x0;
|
||||
int MAX1932_MinVoltage = 0;
|
||||
int MAX1932_MaxVoltage = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Set Defines
|
||||
* @param reg spi register
|
||||
* @param cmsk chip select mask
|
||||
* @param clkmsk clock output mask
|
||||
* @param dmsk digital output mask
|
||||
* @param dofst digital output offset
|
||||
* @param minMV minimum voltage determined by hardware
|
||||
* @param maxMV maximum voltage determined by hardware
|
||||
*/
|
||||
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"));
|
||||
@ -43,10 +36,6 @@ void MAX1932_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t d
|
||||
MAX1932_MaxVoltage = maxMV;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Disable SPI
|
||||
*/
|
||||
void MAX1932_Disable() {
|
||||
bus_w(MAX1932_Reg, (bus_r(MAX1932_Reg)
|
||||
| MAX1932_CsMask
|
||||
@ -54,12 +43,6 @@ void MAX1932_Disable() {
|
||||
& ~(MAX1932_DigMask));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set value
|
||||
* @param val value to set
|
||||
* @return OK or FAIL
|
||||
*/
|
||||
int MAX1932_Set (int val) {
|
||||
FILE_LOG(logDEBUG1, ("Setting high voltage to %d\n", val));
|
||||
if (val < 0)
|
@ -1,9 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "UDPPacketHeaderGenerator.h"
|
||||
#include "clogger.h"
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
@ -38,11 +36,6 @@ uint64_t getUDPFrameNumber() {
|
||||
return udpFrameNumber;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called for each UDP packet header creation
|
||||
*
|
||||
*/
|
||||
void createUDPPacketHeader(char* buffer, uint16_t id) {
|
||||
memset(buffer, 0, sizeof(sls_detector_header));
|
||||
sls_detector_header* header = (sls_detector_header*)(buffer);
|
||||
@ -60,7 +53,6 @@ void createUDPPacketHeader(char* buffer, uint16_t id) {
|
||||
udpFrameNumber = 0;
|
||||
}
|
||||
|
||||
|
||||
int fillUDPPacket(char* buffer) {
|
||||
FILE_LOG(logDEBUG2, ("Analog (databytes:%d, offset:%d)\n Digital (databytes:%d offset:%d)\n",
|
||||
analogDataBytes, analogOffset, digitalDataBytes, digitalOffset));
|
@ -1,70 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "blackfin.h"
|
||||
#include "RegisterDefs.h"
|
||||
#include "sls_detector_defs.h"
|
||||
#include "ansi.h"
|
||||
#include "clogger.h"
|
||||
|
||||
#include <fcntl.h> // open
|
||||
#include <sys/mman.h> // mmap
|
||||
|
||||
|
||||
/* global variables */
|
||||
u_int64_t CSP0BASE = 0;
|
||||
#define CSP0 0x20200000
|
||||
#define MEM_SIZE 0x100000
|
||||
|
||||
|
||||
/** I2C defines */
|
||||
#define I2C_CLOCK_MHZ (131.25)
|
||||
|
||||
/**
|
||||
* Write into a 16 bit register
|
||||
* @param offset address offset
|
||||
* @param data 16 bit data
|
||||
*/
|
||||
void bus_w16(u_int32_t offset, u_int16_t data) {
|
||||
volatile u_int16_t *ptr1;
|
||||
ptr1=(u_int16_t*)(CSP0BASE+offset*2);
|
||||
*ptr1=data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a 16 bit register
|
||||
* @param offset address offset
|
||||
* @retuns 16 bit data read
|
||||
*/
|
||||
u_int16_t bus_r16(u_int32_t offset){
|
||||
volatile u_int16_t *ptr1;
|
||||
ptr1=(u_int16_t*)(CSP0BASE+offset*2);
|
||||
return *ptr1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write into a 32 bit register
|
||||
* @param offset address offset
|
||||
* @param data 32 bit data
|
||||
*/
|
||||
void bus_w(u_int32_t offset, u_int32_t data) {
|
||||
volatile u_int32_t *ptr1;
|
||||
ptr1=(u_int32_t*)(CSP0BASE+offset*2);
|
||||
*ptr1=data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a 32 bit register
|
||||
* @param offset address offset
|
||||
* @retuns 32 bit data read
|
||||
*/
|
||||
u_int32_t bus_r(u_int32_t offset) {
|
||||
volatile u_int32_t *ptr1;
|
||||
ptr1=(u_int32_t*)(CSP0BASE+offset*2);
|
||||
return *ptr1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a 64 bit register
|
||||
* @param aLSB LSB offset address
|
||||
* @param aMSB MSB offset address
|
||||
* @returns 64 bit data read
|
||||
*/
|
||||
int64_t get64BitReg(int aLSB, int aMSB){
|
||||
int64_t v64;
|
||||
u_int32_t vLSB,vMSB;
|
||||
@ -76,13 +48,6 @@ int64_t get64BitReg(int aLSB, int aMSB){
|
||||
return v64;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write into a 64 bit register
|
||||
* @param value 64 bit data
|
||||
* @param aLSB LSB offset address
|
||||
* @param aMSB MSB offset address
|
||||
* @returns 64 bit data read
|
||||
*/
|
||||
int64_t set64BitReg(int64_t value, int aLSB, int aMSB){
|
||||
int64_t v64;
|
||||
u_int32_t vLSB,vMSB;
|
||||
@ -97,71 +62,35 @@ int64_t set64BitReg(int64_t value, int aLSB, int aMSB){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Read unsigned 64 bit from a 64 bit register
|
||||
* @param aLSB LSB offset address
|
||||
* @param aMSB MSB offset address
|
||||
* @returns unsigned 64 bit data read
|
||||
*/
|
||||
uint64_t getU64BitReg(int aLSB, int aMSB){
|
||||
uint64_t retval = bus_r(aMSB);
|
||||
retval = (retval << 32) | bus_r(aLSB);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write unsigned 64 bit into a 64 bit register
|
||||
* @param value unsigned 64 bit data
|
||||
* @param aLSB LSB offset address
|
||||
* @param aMSB MSB offset address
|
||||
*/
|
||||
void setU64BitReg(uint64_t value, int aLSB, int aMSB){
|
||||
bus_w(aLSB, value & (0xffffffff));
|
||||
bus_w(aMSB, (value >> 32) & (0xffffffff));
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a 32 bit register (literal register value provided by client)
|
||||
* @param offset address offset
|
||||
* @retuns 32 bit data read
|
||||
*/
|
||||
u_int32_t readRegister(u_int32_t offset) {
|
||||
return bus_r(offset << MEM_MAP_SHIFT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write into a 32 bit register (literal register value provided by client)
|
||||
* @param offset address offset
|
||||
* @param data 32 bit data
|
||||
*/
|
||||
u_int32_t writeRegister(u_int32_t offset, u_int32_t data) {
|
||||
bus_w(offset << MEM_MAP_SHIFT, data);
|
||||
return readRegister(offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a 16 bit register (literal register value provided by client)
|
||||
* @param offset address offset
|
||||
* @retuns 16 bit data read
|
||||
*/
|
||||
u_int32_t readRegister16(u_int32_t offset) {
|
||||
return (u_int32_t)bus_r16(offset << MEM_MAP_SHIFT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write into a 16 bit register (literal register value provided by client)
|
||||
* @param offset address offset
|
||||
* @param data 16 bit data
|
||||
*/
|
||||
u_int32_t writeRegister16(u_int32_t offset, u_int32_t data) {
|
||||
bus_w16(offset << MEM_MAP_SHIFT, (u_int16_t)data);
|
||||
return readRegister16(offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Map FPGA
|
||||
*/
|
||||
int mapCSP0(void) {
|
||||
// if not mapped
|
||||
if (CSP0BASE == 0) {
|
||||
@ -195,3 +124,8 @@ int mapCSP0(void) {
|
||||
FILE_LOG(logINFO, ("Memory already mapped before\n"));
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
uint64_t Blackfin_getBaseAddress() {
|
||||
return CSP0BASE;
|
||||
}
|
@ -1,15 +1,7 @@
|
||||
#pragma once
|
||||
#include "common.h"
|
||||
#include "clogger.h"
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
/**
|
||||
* Convert a value from a range to a different range (eg voltage to dac or vice versa)
|
||||
* @param inputMin input minimum
|
||||
* @param inputMax input maximum
|
||||
* @param outputMin output minimum
|
||||
* @param outputMax output maximum
|
||||
* @param inputValue input value
|
||||
* @param outputValue pointer to output value
|
||||
* @returns FAIL if input value is out of bounds, else OK
|
||||
*/
|
||||
int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int outputMax,
|
||||
int inputValue, int* outputValue) {
|
||||
FILE_LOG(logDEBUG1, (" Input Value: %d (Input:(%d - %d), Output:(%d - %d))\n",
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "commonServerFunctions.h"
|
||||
#include "blackfin.h"
|
||||
#include "clogger.h"
|
||||
|
||||
#include <unistd.h> // usleep
|
||||
|
||||
void SPIChipSelect (uint32_t* valw, uint32_t addr, uint32_t csmask, uint32_t clkmask, uint32_t digoutmask, int convBit) {
|
@ -1,9 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "communication_funcs_UDP.h"
|
||||
#include "clogger.h"
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "programfpga.h"
|
||||
#include "ansi.h"
|
||||
#include "clogger.h"
|
||||
#include "slsDetectorServer_defs.h"
|
||||
|
||||
#include <unistd.h> // usleep
|
||||
#include <string.h>
|
||||
@ -12,10 +13,6 @@
|
||||
int gpioDefined = 0;
|
||||
char mtdvalue[MTDSIZE] = {0};
|
||||
|
||||
|
||||
/**
|
||||
* Define GPIO pins if not defined
|
||||
*/
|
||||
void defineGPIOpins(){
|
||||
if (!gpioDefined) {
|
||||
//define the gpio pins
|
||||
@ -29,27 +26,17 @@ void defineGPIOpins(){
|
||||
}else FILE_LOG(logDEBUG1, ("gpio pins already defined earlier\n"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify FPGA to not touch flash
|
||||
*/
|
||||
void FPGAdontTouchFlash(){
|
||||
//tell FPGA to not touch flash
|
||||
system("echo 0 > /sys/class/gpio/gpio9/value");
|
||||
//usleep(100*1000);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notify FPGA to program from flash
|
||||
*/
|
||||
void FPGATouchFlash(){
|
||||
//tell FPGA to touch flash to program itself
|
||||
system("echo 1 > /sys/class/gpio/gpio9/value");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset FPGA
|
||||
*/
|
||||
void resetFPGA(){
|
||||
FILE_LOG(logINFOBLUE, ("Reseting FPGA\n"));
|
||||
FPGAdontTouchFlash();
|
||||
@ -57,9 +44,6 @@ void resetFPGA(){
|
||||
usleep(CTRL_SRVR_INIT_TIME_US);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erasing flash
|
||||
*/
|
||||
void eraseFlash(){
|
||||
FILE_LOG(logDEBUG1, ("Erasing Flash\n"));
|
||||
char command[255];
|
||||
@ -69,12 +53,6 @@ void eraseFlash(){
|
||||
FILE_LOG(logINFO, ("Flash erased\n"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the drive to copy program and
|
||||
* notify FPGA not to touch the program
|
||||
* @param filefp pointer to flash
|
||||
* @return 0 for success, 1 for fail (cannot open file for writing program)
|
||||
*/
|
||||
int startWritingFPGAprogram(FILE** filefp){
|
||||
FILE_LOG(logDEBUG1, ("Start Writing of FPGA program\n"));
|
||||
|
||||
@ -114,11 +92,6 @@ int startWritingFPGAprogram(FILE** filefp){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* When done writing the program, close file pointer and
|
||||
* notify FPGA to pick up the program from flash
|
||||
* @param filefp pointer to flash
|
||||
*/
|
||||
void stopWritingFPGAprogram(FILE* filefp){
|
||||
FILE_LOG(logDEBUG1, ("Stopping of writing FPGA program\n"));
|
||||
|
||||
@ -147,14 +120,6 @@ void stopWritingFPGAprogram(FILE* filefp){
|
||||
FILE_LOG(logINFO, ("FPGA has picked up the program from flash\n"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write FPGA Program to flash
|
||||
* @param fpgasrc source program
|
||||
* @param fsize size of program
|
||||
* @param filefp pointer to flash
|
||||
* @return 0 for success, 1 for fail (cannot write)
|
||||
*/
|
||||
int writeFPGAProgram(char* fpgasrc, size_t fsize, FILE* filefp){
|
||||
FILE_LOG(logDEBUG1, ("Writing of FPGA Program\n"
|
||||
"\taddress of fpgasrc:%p\n"
|
Reference in New Issue
Block a user