replaced old logger

This commit is contained in:
Erik Frojdh
2020-03-11 12:40:12 +01:00
parent 4aeb8bf62e
commit 0de0d82a1a
79 changed files with 3635 additions and 3814 deletions

View File

@ -82,7 +82,7 @@ uint32_t AD7689_DigMask = 0x0;
int AD7689_DigOffset = 0x0;
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",
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;
@ -100,13 +100,13 @@ void AD7689_Disable() {
}
void AD7689_Set(uint32_t codata) {
FILE_LOG(logINFO, ("\tSetting ADC SPI Register. Writing 0x%08x to Config Reg\n", codata));
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);
}
uint16_t AD7689_Get() {
FILE_LOG(logINFO, ("\tGetting ADC SPI Register.\n"));
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);
}
@ -135,11 +135,11 @@ int AD7689_GetTemperature() {
ConvertToDifferentRange(0, AD7689_INT_MAX_STEPS,
AD7689_INT_REF_MIN_MV, AD7689_INT_REF_MAX_MV,
regval, &retval);
FILE_LOG(logDEBUG1, ("voltage read for temp: %d mV\n", retval));
LOG(logDEBUG1, ("voltage read for temp: %d mV\n", retval));
// value in °C
double tempValue = AD7689_TMP_C_FOR_1_MV * (double)retval;
FILE_LOG(logINFO, ("\ttemp read : %f °C (%d unit)\n", tempValue, regval));
LOG(logINFO, ("\ttemp read : %f °C (%d unit)\n", tempValue, regval));
return tempValue;
@ -148,7 +148,7 @@ int AD7689_GetTemperature() {
int AD7689_GetChannel(int ichan) {
// filter channels val
if (ichan < 0 || ichan >= AD7689_NUM_CHANNELS) {
FILE_LOG(logERROR, ("Cannot get slow adc channel. "
LOG(logERROR, ("Cannot get slow adc channel. "
"%d out of bounds (0 to %d)\n", ichan, AD7689_NUM_CHANNELS - 1));
return -1;
}
@ -179,15 +179,15 @@ int AD7689_GetChannel(int ichan) {
AD7689_INT_REF_MIN_MV, AD7689_INT_REF_MAX_MV,
regval, &retval);*/
FILE_LOG(logINFO, ("\tvoltage read for chan %d: %d uV (regVal: %d)\n", ichan, retval, regval));
LOG(logINFO, ("\tvoltage read for chan %d: %d uV (regVal: %d)\n", ichan, retval, regval));
return retval;
}
void AD7689_Configure(){
FILE_LOG(logINFOBLUE, ("Configuring AD7689 (Slow ADCs): \n"));
LOG(logINFOBLUE, ("Configuring AD7689 (Slow ADCs): \n"));
// from power up, 3 invalid conversions
FILE_LOG(logINFO, ("\tConfiguring %d x due to invalid conversions from power up\n", AD7689_NUM_INVALID_CONVERSIONS));
LOG(logINFO, ("\tConfiguring %d x due to invalid conversions from power up\n", AD7689_NUM_INVALID_CONVERSIONS));
int i = 0;
for (i = 0; i < AD7689_NUM_INVALID_CONVERSIONS; ++i) {
AD7689_Set(

View File

@ -124,40 +124,40 @@ void AD9252_Set(int addr, int val) {
u_int32_t codata;
codata = val + (addr << 8);
FILE_LOG(logINFO, ("\tSetting ADC SPI Register. Wrote 0x%04x at 0x%04x\n", val, addr));
LOG(logINFO, ("\tSetting ADC SPI Register. Wrote 0x%04x at 0x%04x\n", val, addr));
serializeToSPI(AD9252_Reg, codata, AD9252_CsMask, AD9252_ADC_NUMBITS,
AD9252_ClkMask, AD9252_DigMask, AD9252_DigOffset, 0);
}
void AD9252_Configure(){
FILE_LOG(logINFOBLUE, ("Configuring ADC9252:\n"));
LOG(logINFOBLUE, ("Configuring ADC9252:\n"));
//power mode reset
FILE_LOG(logINFO, ("\tPower mode reset\n"));
LOG(logINFO, ("\tPower mode reset\n"));
AD9252_Set(AD9252_POWER_MODE_REG, AD9252_INT_RESET_VAL);
//power mode chip run
FILE_LOG(logINFO, ("\tPower mode chip run\n"));
LOG(logINFO, ("\tPower mode chip run\n"));
AD9252_Set(AD9252_POWER_MODE_REG, AD9252_INT_CHIP_RUN_VAL);
// binary offset
FILE_LOG(logINFO, ("\tBinary offset\n"));
LOG(logINFO, ("\tBinary offset\n"));
AD9252_Set(AD9252_OUT_MODE_REG, AD9252_OUT_BINARY_OFST_VAL);
//output clock phase
#ifdef GOTTHARDD
FILE_LOG(logINFO, ("\tOutput clock phase is at default: 180\n"));
LOG(logINFO, ("\tOutput clock phase is at default: 180\n"));
#else
FILE_LOG(logINFO, ("\tOutput clock phase: 60\n"));
LOG(logINFO, ("\tOutput clock phase: 60\n"));
AD9257_Set(AD9257_OUT_PHASE_REG, AD9257_OUT_CLK_60_VAL);
#endif
// lvds-iee reduced , binary offset
FILE_LOG(logINFO, ("\tLvds-iee reduced, binary offset\n"));
LOG(logINFO, ("\tLvds-iee reduced, binary offset\n"));
AD9252_Set(AD9252_OUT_MODE_REG, AD9252_OUT_LVDS_IEEE_VAL);
// all devices on chip to receive next command
FILE_LOG(logINFO, ("\tAll devices on chip to receive next command\n"));
LOG(logINFO, ("\tAll devices on chip to receive next command\n"));
AD9252_Set(AD9252_DEV_IND_2_REG,
AD9252_CHAN_H_MSK | AD9252_CHAN_G_MSK | AD9252_CHAN_F_MSK | AD9252_CHAN_E_MSK);
AD9252_Set(AD9252_DEV_IND_1_REG,
@ -165,13 +165,13 @@ void AD9252_Configure(){
AD9252_CLK_CH_DCO_MSK | AD9252_CLK_CH_IFCO_MSK);
// no test mode
FILE_LOG(logINFO, ("\tNo test mode\n"));
LOG(logINFO, ("\tNo test mode\n"));
AD9252_Set(AD9252_TEST_MODE_REG, AD9252_TST_OFF_VAL);
#ifdef TESTADC
FILE_LOG(logINFOBLUE, ("Putting ADC in Test Mode!\n");
LOG(logINFOBLUE, ("Putting ADC in Test Mode!\n");
// mixed bit frequency test mode
FILE_LOG(logINFO, ("\tMixed bit frequency test mode\n"));
LOG(logINFO, ("\tMixed bit frequency test mode\n"));
AD9252_Set(AD9252_TEST_MODE_REG, AD9252_TST_MXD_BT_FRQ_VAL);
#endif
}

View File

@ -163,7 +163,7 @@ int AD9257_GetVrefVoltage(int mV) {
case 4:
return 2000;
default:
FILE_LOG(logERROR, ("Could not convert Adc Vpp from mode to mV\n"));
LOG(logERROR, ("Could not convert Adc Vpp from mode to mV\n"));
return -1;
}
}
@ -190,7 +190,7 @@ int AD9257_SetVrefVoltage(int val, int mV) {
break;
// validation for mV
default:
FILE_LOG(logERROR, ("mv:%d doesnt exist\n", val));
LOG(logERROR, ("mv:%d doesnt exist\n", val));
return FAIL;
}
}
@ -198,19 +198,19 @@ int AD9257_SetVrefVoltage(int val, int mV) {
// validation for mode
switch(mode) {
case 0:
FILE_LOG(logINFO, ("Setting ADC Vref to 1.0 V (Mode:%d)\n", mode));
LOG(logINFO, ("Setting ADC Vref to 1.0 V (Mode:%d)\n", mode));
break;
case 1:
FILE_LOG(logINFO, ("Setting ADC Vref to 1.14 V (Mode:%d)\n", mode));
LOG(logINFO, ("Setting ADC Vref to 1.14 V (Mode:%d)\n", mode));
break;
case 2:
FILE_LOG(logINFO, ("Setting ADC Vref to 1.33 V (Mode:%d)\n", mode));
LOG(logINFO, ("Setting ADC Vref to 1.33 V (Mode:%d)\n", mode));
break;
case 3:
FILE_LOG(logINFO, ("Setting ADC Vref to 1.6 V (Mode:%d)\n", mode));
LOG(logINFO, ("Setting ADC Vref to 1.6 V (Mode:%d)\n", mode));
break;
case 4:
FILE_LOG(logINFO, ("Setting ADC Vref to 2.0 V (Mode:%d)\n", mode));
LOG(logINFO, ("Setting ADC Vref to 2.0 V (Mode:%d)\n", mode));
break;
default:
return FAIL;
@ -225,32 +225,32 @@ void AD9257_Set(int addr, int val) {
u_int32_t codata;
codata = val + (addr << 8);
FILE_LOG(logINFO, ("\tSetting ADC SPI Register. Wrote 0x%04x at 0x%04x\n", val, addr));
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, 0);
}
void AD9257_Configure(){
FILE_LOG(logINFOBLUE, ("Configuring ADC9257:\n"));
LOG(logINFOBLUE, ("Configuring ADC9257:\n"));
//power mode reset
FILE_LOG(logINFO, ("\tPower mode reset\n"));
LOG(logINFO, ("\tPower mode reset\n"));
AD9257_Set(AD9257_POWER_MODE_REG, AD9257_INT_RESET_VAL);
//power mode chip run
FILE_LOG(logINFO, ("\tPower mode chip run\n"));
LOG(logINFO, ("\tPower mode chip run\n"));
AD9257_Set(AD9257_POWER_MODE_REG, AD9257_INT_CHIP_RUN_VAL);
// binary offset, lvds-iee reduced
FILE_LOG(logINFO, ("\tBinary offset, Lvds-ieee reduced\n"));
LOG(logINFO, ("\tBinary offset, Lvds-ieee reduced\n"));
AD9257_Set(AD9257_OUT_MODE_REG, AD9257_OUT_BINARY_OFST_VAL | AD9257_OUT_LVDS_IEEE_VAL);
//output clock phase
FILE_LOG(logINFO, ("\tOutput clock phase: 180\n"));
LOG(logINFO, ("\tOutput clock phase: 180\n"));
AD9257_Set(AD9257_OUT_PHASE_REG, AD9257_OUT_CLK_180_VAL);
// all devices on chip to receive next command
FILE_LOG(logINFO, ("\tAll devices on chip to receive next command\n"));
LOG(logINFO, ("\tAll devices on chip to receive next command\n"));
AD9257_Set(AD9257_DEV_IND_2_REG,
AD9257_CHAN_H_MSK | AD9257_CHAN_G_MSK | AD9257_CHAN_F_MSK | AD9257_CHAN_E_MSK);
@ -260,21 +260,21 @@ void AD9257_Configure(){
// vref
#ifdef GOTTHARDD
FILE_LOG(logINFO, ("\tVref default at 2.0\n"));
LOG(logINFO, ("\tVref default at 2.0\n"));
AD9257_SetVrefVoltage(AD9257_VREF_DEFAULT_VAL, 0);
#else
FILE_LOG(logINFO, ("\tVref 1.33\n"));
LOG(logINFO, ("\tVref 1.33\n"));
AD9257_SetVrefVoltage(AD9257_VREF_1_33_VAL, 0);
#endif
// no test mode
FILE_LOG(logINFO, ("\tNo test mode\n"));
LOG(logINFO, ("\tNo test mode\n"));
AD9257_Set(AD9257_TEST_MODE_REG, AD9257_TST_OFF_VAL);
#ifdef TESTADC
FILE_LOG(logINFOBLUE, ("Putting ADC in Test Mode!\n");
LOG(logINFOBLUE, ("Putting ADC in Test Mode!\n");
// mixed bit frequency test mode
FILE_LOG(logINFO, ("\tMixed bit frequency test mode\n"));
LOG(logINFO, ("\tMixed bit frequency test mode\n"));
AD9257_Set(AD9257_TEST_MODE_REG, AD9257_TST_MXD_BT_FRQ_VAL);
#endif
}

View File

@ -113,22 +113,22 @@ void ALTERA_PLL_SetDefines(uint32_t creg, uint32_t preg, uint32_t rprmsk, uint32
#endif
void ALTERA_PLL_ResetPLL () {
FILE_LOG(logINFO, ("Resetting only PLL\n"));
LOG(logINFO, ("Resetting only PLL\n"));
FILE_LOG(logDEBUG2, ("pllrstmsk:0x%x\n", ALTERA_PLL_Cntrl_PLLRstMask));
LOG(logDEBUG2, ("pllrstmsk:0x%x\n", ALTERA_PLL_Cntrl_PLLRstMask));
bus_w(ALTERA_PLL_Cntrl_Reg, bus_r(ALTERA_PLL_Cntrl_Reg) | ALTERA_PLL_Cntrl_PLLRstMask);
FILE_LOG(logDEBUG2, ("Set PLL Reset mSk: ALTERA_PLL_Cntrl_Reg:0x%x\n", bus_r(ALTERA_PLL_Cntrl_Reg)));
LOG(logDEBUG2, ("Set PLL Reset mSk: ALTERA_PLL_Cntrl_Reg:0x%x\n", bus_r(ALTERA_PLL_Cntrl_Reg)));
usleep(ALTERA_PLL_WAIT_TIME_US);
bus_w(ALTERA_PLL_Cntrl_Reg, bus_r(ALTERA_PLL_Cntrl_Reg) & ~ALTERA_PLL_Cntrl_PLLRstMask);
FILE_LOG(logDEBUG2, ("UnSet PLL Reset mSk: ALTERA_PLL_Cntrl_Reg:0x%x\n", bus_r(ALTERA_PLL_Cntrl_Reg)));
LOG(logDEBUG2, ("UnSet PLL Reset mSk: ALTERA_PLL_Cntrl_Reg:0x%x\n", bus_r(ALTERA_PLL_Cntrl_Reg)));
}
void ALTERA_PLL_ResetPLLAndReconfiguration () {
FILE_LOG(logINFO, ("Resetting PLL and Reconfiguration\n"));
LOG(logINFO, ("Resetting PLL and Reconfiguration\n"));
bus_w(ALTERA_PLL_Cntrl_Reg, bus_r(ALTERA_PLL_Cntrl_Reg) | ALTERA_PLL_Cntrl_RcnfgPrmtrRstMask | ALTERA_PLL_Cntrl_PLLRstMask);
usleep(ALTERA_PLL_WAIT_TIME_US);
@ -136,7 +136,7 @@ void ALTERA_PLL_ResetPLLAndReconfiguration () {
}
void ALTERA_PLL_SetPllReconfigReg(uint32_t reg, uint32_t val, int useSecondWRMask) {
FILE_LOG(logDEBUG1, ("Setting PLL Reconfig Reg, reg:0x%x, val:0x%x, useSecondWRMask:%d)\n", reg, val, useSecondWRMask));
LOG(logDEBUG1, ("Setting PLL Reconfig Reg, reg:0x%x, val:0x%x, useSecondWRMask:%d)\n", reg, val, useSecondWRMask));
uint32_t wrmask = ALTERA_PLL_Cntrl_WrPrmtrMask;
#ifdef JUNGFRAUD
@ -145,38 +145,38 @@ void ALTERA_PLL_SetPllReconfigReg(uint32_t reg, uint32_t val, int useSecondWRMas
}
#endif
FILE_LOG(logDEBUG2, ("pllparamreg:0x%x pllcontrolreg:0x%x addrofst:%d addrmsk:0x%x wrmask:0x%x\n",
LOG(logDEBUG2, ("pllparamreg:0x%x pllcontrolreg:0x%x addrofst:%d addrmsk:0x%x wrmask:0x%x\n",
ALTERA_PLL_Param_Reg, ALTERA_PLL_Cntrl_Reg, ALTERA_PLL_Cntrl_AddrOfst, ALTERA_PLL_Cntrl_AddrMask, wrmask));
// set parameter
bus_w(ALTERA_PLL_Param_Reg, val);
FILE_LOG(logDEBUG2, ("Set Parameter: ALTERA_PLL_Param_Reg:0x%x\n", bus_r(ALTERA_PLL_Param_Reg)));
LOG(logDEBUG2, ("Set Parameter: ALTERA_PLL_Param_Reg:0x%x\n", bus_r(ALTERA_PLL_Param_Reg)));
usleep(ALTERA_PLL_WAIT_TIME_US);
// set address
bus_w(ALTERA_PLL_Cntrl_Reg, (reg << ALTERA_PLL_Cntrl_AddrOfst) & ALTERA_PLL_Cntrl_AddrMask);
FILE_LOG(logDEBUG2, ("Set Address: ALTERA_PLL_Cntrl_Reg:0x%x\n", bus_r(ALTERA_PLL_Cntrl_Reg)));
LOG(logDEBUG2, ("Set Address: ALTERA_PLL_Cntrl_Reg:0x%x\n", bus_r(ALTERA_PLL_Cntrl_Reg)));
usleep(ALTERA_PLL_WAIT_TIME_US);
//write parameter
bus_w(ALTERA_PLL_Cntrl_Reg, bus_r(ALTERA_PLL_Cntrl_Reg) | wrmask);
FILE_LOG(logDEBUG2, ("Set WR bit: ALTERA_PLL_Cntrl_Reg:0x%x\n", bus_r(ALTERA_PLL_Cntrl_Reg)));
LOG(logDEBUG2, ("Set WR bit: ALTERA_PLL_Cntrl_Reg:0x%x\n", bus_r(ALTERA_PLL_Cntrl_Reg)));
usleep(ALTERA_PLL_WAIT_TIME_US);
bus_w(ALTERA_PLL_Cntrl_Reg, bus_r(ALTERA_PLL_Cntrl_Reg) & ~wrmask);
FILE_LOG(logDEBUG2, ("Unset WR bit: ALTERA_PLL_Cntrl_Reg:0x%x\n", bus_r(ALTERA_PLL_Cntrl_Reg)));
LOG(logDEBUG2, ("Unset WR bit: ALTERA_PLL_Cntrl_Reg:0x%x\n", bus_r(ALTERA_PLL_Cntrl_Reg)));
usleep(ALTERA_PLL_WAIT_TIME_US);
}
void ALTERA_PLL_SetPhaseShift(int32_t phase, int clkIndex, int pos) {
FILE_LOG(logINFO, ("\tWriting PLL Phase Shift\n"));
LOG(logINFO, ("\tWriting PLL Phase Shift\n"));
uint32_t value = (((phase << ALTERA_PLL_SHIFT_NUM_SHIFTS_OFST) & ALTERA_PLL_SHIFT_NUM_SHIFTS_MSK) |
((clkIndex << ALTERA_PLL_SHIFT_CNT_SELECT_OFST) & ALTERA_PLL_SHIFT_CNT_SELECT_MSK) |
(pos ? ALTERA_PLL_SHIFT_UP_DOWN_POS_VAL : ALTERA_PLL_SHIFT_UP_DOWN_NEG_VAL));
FILE_LOG(logDEBUG1, ("C%d phase word:0x%08x\n", clkIndex, value));
LOG(logDEBUG1, ("C%d phase word:0x%08x\n", clkIndex, value));
int useSecondWR = 0;
#ifdef JUNGFRAUD
@ -190,12 +190,12 @@ void ALTERA_PLL_SetPhaseShift(int32_t phase, int clkIndex, int pos) {
}
void ALTERA_PLL_SetModePolling() {
FILE_LOG(logINFO, ("\tSetting Polling Mode\n"));
LOG(logINFO, ("\tSetting Polling Mode\n"));
ALTERA_PLL_SetPllReconfigReg(ALTERA_PLL_MODE_REG, ALTERA_PLL_MODE_PLLNG_MD_VAL, 0);
}
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));
LOG(logDEBUG1, ("C%d: Setting output frequency to %d (pllvcofreq: %dMhz)\n", clkIndex, value, pllVCOFreqMhz));
// calculate output frequency
float total_div = (float)pllVCOFreqMhz / (float)value;
@ -210,14 +210,14 @@ int ALTERA_PLL_SetOuputFrequency (int clkIndex, int pllVCOFreqMhz, int value) {
++high_count;
odd_division = 1;
}
FILE_LOG(logINFO, ("\tC%d: Low:%d, High:%d, Odd:%d\n", clkIndex, low_count, high_count, odd_division));
LOG(logINFO, ("\tC%d: Low:%d, High:%d, Odd:%d\n", clkIndex, low_count, high_count, odd_division));
// command to set output frequency
uint32_t val = (((low_count << ALTERA_PLL_C_COUNTER_LW_CNT_OFST) & ALTERA_PLL_C_COUNTER_LW_CNT_MSK) |
((high_count << ALTERA_PLL_C_COUNTER_HGH_CNT_OFST) & ALTERA_PLL_C_COUNTER_HGH_CNT_MSK) |
((odd_division << ALTERA_PLL_C_COUNTER_ODD_DVSN_OFST) & ALTERA_PLL_C_COUNTER_ODD_DVSN_MSK) |
((clkIndex << ALTERA_PLL_C_COUNTER_SLCT_OFST) & ALTERA_PLL_C_COUNTER_SLCT_MSK));
FILE_LOG(logDEBUG1, ("C%d word:0x%08x\n", clkIndex, val));
LOG(logDEBUG1, ("C%d word:0x%08x\n", clkIndex, val));
// write frequency (post-scale output counter C)
ALTERA_PLL_SetPllReconfigReg(ALTERA_PLL_C_COUNTER_REG, val, 0);

View File

@ -76,10 +76,10 @@ int ALTERA_PLL_C10_GetMaxPhaseShiftStepsofVCO() {
}
void ALTERA_PLL_C10_Reconfigure(int pllIndex) {
FILE_LOG(logINFO, ("\tReconfiguring PLL %d\n", pllIndex));
LOG(logINFO, ("\tReconfiguring PLL %d\n", pllIndex));
// write anything to base address to start reconfiguring
FILE_LOG(logDEBUG1, ("\tWriting 1 to base address 0x%x to start reconfiguring\n", ALTERA_PLL_C10_BaseAddress[pllIndex]));
LOG(logDEBUG1, ("\tWriting 1 to base address 0x%x to start reconfiguring\n", ALTERA_PLL_C10_BaseAddress[pllIndex]));
bus_w_csp1(ALTERA_PLL_C10_BaseAddress[pllIndex], 0x1);
usleep(ALTERA_PLL_C10_WAIT_TIME_US);
}
@ -87,7 +87,7 @@ void ALTERA_PLL_C10_Reconfigure(int pllIndex) {
void ALTERA_PLL_C10_ResetPLL (int pllIndex) {
uint32_t resetreg = ALTERA_PLL_C10_Reset_Reg[pllIndex];
uint32_t resetmsk = ALTERA_PLL_C10_Reset_Msk[pllIndex];
FILE_LOG(logINFO, ("Resetting PLL %d\n", pllIndex));
LOG(logINFO, ("Resetting PLL %d\n", pllIndex));
bus_w_csp1(resetreg, bus_r_csp1(resetreg) | resetmsk);
usleep(ALTERA_PLL_C10_WAIT_TIME_US);
@ -95,7 +95,7 @@ void ALTERA_PLL_C10_ResetPLL (int pllIndex) {
void ALTERA_PLL_C10_SetPhaseShift(int pllIndex, int clkIndex, int phase, int pos) {
FILE_LOG(logINFO, ("\tC%d: Writing PLL %d Phase Shift [phase:%d, pos dir:%d]\n", clkIndex, pllIndex, phase, pos));
LOG(logINFO, ("\tC%d: Writing PLL %d Phase Shift [phase:%d, pos dir:%d]\n", clkIndex, pllIndex, phase, pos));
uint32_t addr = ALTERA_PLL_C10_BaseAddress[pllIndex] + (ALTERA_PLL_C10_PHASE_SHIFT_BASE_REG + (int)clkIndex) * ALTERA_PLL_C10_Reg_offset;
int maxshifts = ALTERA_PLL_C10_MAX_SHIFTS_PER_OPERATION;
@ -105,7 +105,7 @@ void ALTERA_PLL_C10_SetPhaseShift(int pllIndex, int clkIndex, int phase, int pos
int phaseToDo = (phase > maxshifts) ? maxshifts : phase;
uint32_t value = (((phaseToDo << ALTERA_PLL_C10_SHIFT_NUM_SHIFTS_OFST) & ALTERA_PLL_C10_SHIFT_NUM_SHIFTS_MSK) |
(pos ? ALTERA_PLL_C10_SHIFT_UP_DOWN_POS_VAL : ALTERA_PLL_C10_SHIFT_UP_DOWN_NEG_VAL));
FILE_LOG(logDEBUG1, ("\t[addr:0x%x, phaseTodo:%d phaseleft:%d phase word:0x%08x]\n", addr, phaseToDo, phase, value));
LOG(logDEBUG1, ("\t[addr:0x%x, phaseTodo:%d phaseleft:%d phase word:0x%08x]\n", addr, phaseToDo, phase, value));
bus_w_csp1(addr, value);
ALTERA_PLL_C10_Reconfigure(pllIndex);
@ -116,7 +116,7 @@ void ALTERA_PLL_C10_SetPhaseShift(int pllIndex, int clkIndex, int phase, int pos
void ALTERA_PLL_C10_SetOuputFrequency (int pllIndex, int clkIndex, int value) {
int pllVCOFreqHz = ALTERA_PLL_C10_VCO_FREQ[pllIndex];
FILE_LOG(logDEBUG1, ("\tC%d: Setting output frequency for pll %d to %d (pllvcofreq: %dHz)\n", clkIndex, pllIndex, value, pllVCOFreqHz));
LOG(logDEBUG1, ("\tC%d: Setting output frequency for pll %d to %d (pllvcofreq: %dHz)\n", clkIndex, pllIndex, value, pllVCOFreqHz));
// calculate output frequency
float total_div = (float)pllVCOFreqHz / (float)value;
@ -131,14 +131,14 @@ void ALTERA_PLL_C10_SetOuputFrequency (int pllIndex, int clkIndex, int value) {
++high_count;
odd_division = 1;
}
FILE_LOG(logINFO, ("\tC%d: Low:%d, High:%d, Odd:%d\n", clkIndex, low_count, high_count, odd_division));
LOG(logINFO, ("\tC%d: Low:%d, High:%d, Odd:%d\n", clkIndex, low_count, high_count, odd_division));
// command to set output frequency
uint32_t addr = ALTERA_PLL_C10_BaseAddress[pllIndex] + (ALTERA_PLL_C10_C_COUNTER_BASE_REG + (int)clkIndex) * ALTERA_PLL_C10_Reg_offset;
uint32_t val = (((low_count << ALTERA_PLL_C10_C_COUNTER_LW_CNT_OFST) & ALTERA_PLL_C10_C_COUNTER_LW_CNT_MSK) |
((high_count << ALTERA_PLL_C10_C_COUNTER_HGH_CNT_OFST) & ALTERA_PLL_C10_C_COUNTER_HGH_CNT_MSK) |
((odd_division << ALTERA_PLL_C10_C_COUNTER_ODD_DVSN_OFST) & ALTERA_PLL_C10_C_COUNTER_ODD_DVSN_MSK));
FILE_LOG(logDEBUG1, ("\t[addr:0x%x, word:0x%08x]\n", addr, val));
LOG(logDEBUG1, ("\t[addr:0x%x, word:0x%08x]\n", addr, val));
// write frequency
bus_w_csp1(addr, val);

View File

@ -20,7 +20,7 @@ char ASIC_Driver_DriverFileName[MAX_STR_LENGTH];
void ASIC_Driver_SetDefines(char* driverfname) {
FILE_LOG(logINFOBLUE, ("Configuring ASIC Driver to %s\n", driverfname));
LOG(logINFOBLUE, ("Configuring ASIC Driver to %s\n", driverfname));
memset(ASIC_Driver_DriverFileName, 0, MAX_STR_LENGTH);
strcpy(ASIC_Driver_DriverFileName, driverfname);
}
@ -28,14 +28,14 @@ void ASIC_Driver_SetDefines(char* driverfname) {
int ASIC_Driver_Set (int index, int length, char* buffer) {
char fname[MAX_STR_LENGTH];
sprintf(fname, "%s%d", ASIC_Driver_DriverFileName, index + 1);
FILE_LOG(logDEBUG2, ("\t[chip index: %d, length: %d, fname: %s]\n", index, length, fname));
LOG(logDEBUG2, ("\t[chip index: %d, length: %d, fname: %s]\n", index, length, fname));
{
FILE_LOG(logDEBUG2, ("\t[values: \n"));
LOG(logDEBUG2, ("\t[values: \n"));
int i;
for (i = 0; i < length; ++i) {
FILE_LOG(logDEBUG2, ("\t%d: 0x%02hhx\n", i, buffer[i]));
LOG(logDEBUG2, ("\t%d: 0x%02hhx\n", i, buffer[i]));
}
FILE_LOG(logDEBUG2, ("\t]\n"));
LOG(logDEBUG2, ("\t]\n"));
}
#ifdef VIRTUAL
@ -43,7 +43,7 @@ int ASIC_Driver_Set (int index, int length, char* buffer) {
#endif
int fd=open(fname, O_RDWR);
if (fd == -1) {
FILE_LOG(logERROR, ("Could not open file %s for writing to control ASIC (%d)\n", fname, index));
LOG(logERROR, ("Could not open file %s for writing to control ASIC (%d)\n", fname, index));
return FAIL;
}
@ -56,7 +56,7 @@ int ASIC_Driver_Set (int index, int length, char* buffer) {
// transfer command
int status = ioctl(fd, SPI_IOC_MESSAGE(1), &transfer);
if (status < 0) {
FILE_LOG(logERROR, ("Could not send command to ASIC\n"));
LOG(logERROR, ("Could not send command to ASIC\n"));
perror("SPI_IOC_MESSAGE");
close(fd);
return FAIL;

View File

@ -15,14 +15,14 @@ int DAC6571_HardMaxVoltage = 0;
char DAC6571_DriverFileName[MAX_STR_LENGTH];
void DAC6571_SetDefines(int hardMaxV, char* driverfname) {
FILE_LOG(logINFOBLUE, ("Configuring High Voltage to %s (hard max: %dV)\n", driverfname, hardMaxV));
LOG(logINFOBLUE, ("Configuring High Voltage to %s (hard max: %dV)\n", driverfname, hardMaxV));
DAC6571_HardMaxVoltage = hardMaxV;
memset(DAC6571_DriverFileName, 0, MAX_STR_LENGTH);
strcpy(DAC6571_DriverFileName, driverfname);
}
int DAC6571_Set (int val) {
FILE_LOG(logDEBUG1, ("Setting high voltage to %d\n", val));
LOG(logDEBUG1, ("Setting high voltage to %d\n", val));
if (val < 0)
return FAIL;
@ -34,12 +34,12 @@ int DAC6571_Set (int val) {
DAC6571_MIN_DAC_VAL, DAC6571_MAX_DAC_VAL,
val, &dacvalue);
FILE_LOG(logINFO, ("\t%dV (dacval %d)\n", val, dacvalue));
LOG(logINFO, ("\t%dV (dacval %d)\n", val, dacvalue));
//open file
FILE* fd=fopen(DAC6571_DriverFileName,"w");
if (fd==NULL) {
FILE_LOG(logERROR, ("Could not open file %s for writing to set high voltage\n", DAC6571_DriverFileName));
LOG(logERROR, ("Could not open file %s for writing to set high voltage\n", DAC6571_DriverFileName));
return FAIL;
}
//convert to string, add 0 and write to file

View File

@ -101,8 +101,8 @@ uint32_t I2C_Transfer_Command_Fifo_Reg = 0x0;
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) {
FILE_LOG(logINFO, ("\tConfiguring I2C Core for %d kbps:\n", I2C_DATA_RATE_KBPS));
FILE_LOG(logDEBUG1,("controlreg,:0x%x, statusreg,:0x%x, "
LOG(logINFO, ("\tConfiguring I2C Core for %d kbps:\n", I2C_DATA_RATE_KBPS));
LOG(logDEBUG1,("controlreg,:0x%x, statusreg,:0x%x, "
"rxrdatafiforeg: 0x%x, rxdatafifocountreg,:0x%x, "
"scllow,:0x%x, sclhighreg,:0x%x, sdaholdreg,:0x%x, transfercmdreg,:0x%x\n",
creg, sreg, rreg, rlvlreg, slreg, shreg, sdreg, treg));
@ -128,54 +128,54 @@ void I2C_ConfigureI2CCore(uint32_t creg, uint32_t sreg,
// convert to us, then to clock (defined in blackfin.h)
uint32_t sdaDataHoldCount = ((sdaDataHoldTimeNs / 1000.00) * I2C_CLOCK_MHZ);
FILE_LOG(logINFO, ("\tSetting SCL Low Period: %d ns (%d clocks)\n", sclLowPeriodNs, sclLowPeriodCount));
LOG(logINFO, ("\tSetting SCL Low Period: %d ns (%d clocks)\n", sclLowPeriodNs, sclLowPeriodCount));
bus_w(I2C_Scl_Low_Count_Reg, bus_r(I2C_Scl_Low_Count_Reg) |
((sclLowPeriodCount << I2C_SCL_LOW_COUNT_PERIOD_OFST) & I2C_SCL_LOW_COUNT_PERIOD_MSK));
FILE_LOG(logDEBUG1, ("SCL Low reg:0x%x\n", bus_r(I2C_Scl_Low_Count_Reg)));
LOG(logDEBUG1, ("SCL Low reg:0x%x\n", bus_r(I2C_Scl_Low_Count_Reg)));
FILE_LOG(logINFO, ("\tSetting SCL High Period: %d ns (%d clocks)\n", sclLowPeriodNs, sclLowPeriodCount));
LOG(logINFO, ("\tSetting SCL High Period: %d ns (%d clocks)\n", sclLowPeriodNs, sclLowPeriodCount));
bus_w(I2C_Scl_High_Count_Reg, bus_r(I2C_Scl_High_Count_Reg) |
((sclLowPeriodCount << I2C_SCL_HIGH_COUNT_PERIOD_OFST) & I2C_SCL_HIGH_COUNT_PERIOD_MSK));
FILE_LOG(logDEBUG1, ("SCL High reg:0x%x\n", bus_r(I2C_Scl_High_Count_Reg)));
LOG(logDEBUG1, ("SCL High reg:0x%x\n", bus_r(I2C_Scl_High_Count_Reg)));
FILE_LOG(logINFO, ("\tSetting SDA Hold Time: %d ns (%d clocks)\n", sdaDataHoldTimeNs, sdaDataHoldCount));
LOG(logINFO, ("\tSetting SDA Hold Time: %d ns (%d clocks)\n", sdaDataHoldTimeNs, sdaDataHoldCount));
bus_w(I2C_Sda_Hold_Reg, bus_r(I2C_Sda_Hold_Reg) |
((sdaDataHoldCount << I2C_SDA_HOLD_COUNT_PERIOD_OFST) & I2C_SDA_HOLD_COUNT_PERIOD_MSK));
FILE_LOG(logDEBUG1, ("SDA Hold reg:0x%x\n", bus_r(I2C_Sda_Hold_Reg)));
LOG(logDEBUG1, ("SDA Hold reg:0x%x\n", bus_r(I2C_Sda_Hold_Reg)));
FILE_LOG(logINFO, ("\tEnabling core and bus speed to fast (up to 400 kbps)\n"));
LOG(logINFO, ("\tEnabling core and bus speed to fast (up to 400 kbps)\n"));
bus_w(I2C_Control_Reg, bus_r(I2C_Control_Reg) |
I2C_CTRL_ENBLE_CORE_MSK | I2C_CTRL_BUS_SPEED_FAST_400_VAL);// fixme: (works?)
FILE_LOG(logDEBUG1, ("Control reg:0x%x\n", bus_r(I2C_Control_Reg)));
LOG(logDEBUG1, ("Control reg:0x%x\n", bus_r(I2C_Control_Reg)));
//The INA226 supports the transmission protocol for fast mode (1 kHz to 400 kHz) and high-speed mode (1 kHz to 2.94 MHz).
}
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));
LOG(logDEBUG2, (" ================================================\n"));
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(logDEBUG2, (" devId:0x%x\n", devIdMask));
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(logDEBUG2, (" write devID and R/-W:0x%x\n", (devIdMask & ~(I2C_TFR_CMD_RW_MSK))));
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(logDEBUG2, (" write addr:0x%x\n", addr));
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(logDEBUG2, (" repeated start:0x%x\n", (devIdMask | I2C_TFR_CMD_RPTD_STRT_MSK | I2C_TFR_CMD_RW_READ_VAL)));
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(logDEBUG2, (" continue reading:0x%x\n", 0x0));
LOG(logDEBUG2, (" continue reading:0x%x\n", 0x0));
// stop reading
bus_w(I2C_Transfer_Command_Fifo_Reg, I2C_TFR_CMD_STOP_MSK);
FILE_LOG(logDEBUG2, (" stop reading:0x%x\n", I2C_TFR_CMD_STOP_MSK));
LOG(logDEBUG2, (" stop reading:0x%x\n", I2C_TFR_CMD_STOP_MSK));
// read value
uint32_t retval = 0;
@ -185,56 +185,56 @@ 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(logDEBUG2, (" status:%d\n", status));
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(logDEBUG2, (" level:%d\n", level));
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(logDEBUG2, (" byte nr %d:0x%x\n", iloop, byte));
LOG(logDEBUG2, (" byte nr %d:0x%x\n", iloop, byte));
// push by 1 byte at a time
retval |= (byte << (8 * iloop));
}
FILE_LOG(logDEBUG2, (" retval:0x%x\n", retval));
FILE_LOG(logDEBUG2, (" ================================================\n"));
LOG(logDEBUG2, (" retval:0x%x\n", retval));
LOG(logDEBUG2, (" ================================================\n"));
return retval;
}
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));
LOG(logDEBUG2, (" ================================================\n"));
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(logDEBUG2, (" devId:0x%x\n", devId));
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(logDEBUG2, (" write devID and R/-W:0x%x\n", (devIdMask & ~(I2C_TFR_CMD_RW_MSK))));
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(logDEBUG2, (" write addr:0x%x\n", addr));
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(logDEBUG2, (" msb:0x%02x, lsb:0x%02x\n", msb, lsb));
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(logDEBUG2, (" write msb:0x%02x\n", ((msb << I2C_TFR_CMD_DATA_FR_WR_OFST) & I2C_TFR_CMD_DATA_FR_WR_MSK)));
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(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"));
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));
LOG(logDEBUG2, (" ================================================\n"));
}

View File

@ -63,21 +63,21 @@ int INA226_Calibration_Register_Value = 0;
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) {
FILE_LOG(logINFOBLUE, ("Configuring INA226\n"));
FILE_LOG(logDEBUG1, ("Shunt ohm resistor: %f\n", rOhm));
LOG(logINFOBLUE, ("Configuring INA226\n"));
LOG(logDEBUG1, ("Shunt ohm resistor: %f\n", rOhm));
INA226_Shunt_Resistor_Ohm = rOhm;
I2C_ConfigureI2CCore(creg, sreg, rreg, rlvlreg, slreg, shreg, sdreg, treg);
}
void INA226_CalibrateCurrentRegister(uint32_t deviceId) {
FILE_LOG(logINFO, ("Calibrating Current Register for Device ID: 0x%x\n", deviceId));
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, ("\tCalculated calibration reg value: 0x%0x (%d)\n", calVal, calVal));
LOG(logINFO, ("\tCalculated calibration reg value: 0x%0x (%d)\n", calVal, calVal));
calVal = ((double)calVal / INA226_CALIBRATION_CURRENT_TOLERANCE) + 0.5;
FILE_LOG(logINFO, ("\tRealculated (for tolerance) calibration reg value: 0x%0x (%d)\n", calVal, calVal));
LOG(logINFO, ("\tRealculated (for tolerance) calibration reg value: 0x%0x (%d)\n", calVal, calVal));
INA226_Calibration_Register_Value = calVal;
// calibrate current register
@ -86,71 +86,71 @@ void INA226_CalibrateCurrentRegister(uint32_t deviceId) {
// read back calibration register
int retval = I2C_Read(deviceId, INA226_CALIBRATION_REG);
if (retval != calVal) {
FILE_LOG(logERROR, ("Cannot set calibration register for I2C. Set 0x%x, read 0x%x\n", calVal, retval));
LOG(logERROR, ("Cannot set calibration register for I2C. Set 0x%x, read 0x%x\n", calVal, retval));
}
}
int INA226_ReadVoltage(uint32_t deviceId) {
FILE_LOG(logDEBUG1, (" Reading voltage\n"));
LOG(logDEBUG1, (" Reading voltage\n"));
uint32_t regval = I2C_Read(deviceId, INA226_BUS_VOLTAGE_REG);
FILE_LOG(logDEBUG1, (" bus voltage reg: 0x%08x\n", regval));
LOG(logDEBUG1, (" bus voltage reg: 0x%08x\n", regval));
// value in uV
int voltageuV = 0;
ConvertToDifferentRange(0, INA226_BUS_VOLTAGE_MX_STPS,
INA226_BUS_VOLTAGE_VMIN_UV, INA226_BUS_VOLTAGE_VMAX_UV,
regval, &voltageuV);
FILE_LOG(logDEBUG1, (" voltage: 0x%d uV\n", voltageuV));
LOG(logDEBUG1, (" voltage: 0x%d uV\n", voltageuV));
// value in mV
int voltagemV = voltageuV / 1000;
FILE_LOG(logDEBUG1, (" voltage: %d mV\n", voltagemV));
FILE_LOG(logINFO, ("Voltage via I2C (Device: 0x%x): %d mV\n", deviceId, voltagemV));
LOG(logDEBUG1, (" voltage: %d mV\n", voltagemV));
LOG(logINFO, ("Voltage via I2C (Device: 0x%x): %d mV\n", deviceId, voltagemV));
return voltagemV;
}
int INA226_ReadCurrent(uint32_t deviceId) {
FILE_LOG(logDEBUG1, (" Reading current\n"));
LOG(logDEBUG1, (" Reading current\n"));
// read shunt voltage register
FILE_LOG(logDEBUG1, (" Reading shunt voltage reg\n"));
LOG(logDEBUG1, (" Reading shunt voltage reg\n"));
uint32_t shuntVoltageRegVal = I2C_Read(deviceId, INA226_SHUNT_VOLTAGE_REG);
FILE_LOG(logDEBUG1, (" shunt voltage reg: %d\n", shuntVoltageRegVal));
LOG(logDEBUG1, (" shunt voltage reg: %d\n", shuntVoltageRegVal));
// read it once more as this error has occured once
if (shuntVoltageRegVal == 0xFFFF) {
FILE_LOG(logDEBUG1, (" Reading shunt voltage reg again\n"));
LOG(logDEBUG1, (" Reading shunt voltage reg again\n"));
shuntVoltageRegVal = I2C_Read(deviceId, INA226_SHUNT_VOLTAGE_REG);
FILE_LOG(logDEBUG1, (" shunt voltage reg: %d\n", shuntVoltageRegVal));
LOG(logDEBUG1, (" shunt voltage reg: %d\n", shuntVoltageRegVal));
}
// value for current
int retval = INA226_getConvertedCurrentUnits(shuntVoltageRegVal, INA226_Calibration_Register_Value);
FILE_LOG(logDEBUG1, (" current unit value: %d\n", retval));
LOG(logDEBUG1, (" current unit value: %d\n", retval));
// reading directly the current reg
FILE_LOG(logDEBUG1, (" Reading current reg\n"));
LOG(logDEBUG1, (" Reading current reg\n"));
int cuurentRegVal = I2C_Read(deviceId, INA226_CURRENT_REG);
FILE_LOG(logDEBUG1, (" current reg: %d\n", cuurentRegVal));
LOG(logDEBUG1, (" current reg: %d\n", cuurentRegVal));
// read it once more as this error has occured once
if (cuurentRegVal >= 0xFFF0) {
FILE_LOG(logDEBUG1, (" Reading current reg again\n"));
LOG(logDEBUG1, (" Reading current reg again\n"));
cuurentRegVal = I2C_Read(deviceId, INA226_CURRENT_REG);
FILE_LOG(logDEBUG1, (" current reg: %d\n", cuurentRegVal));
LOG(logDEBUG1, (" current reg: %d\n", cuurentRegVal));
}
// should be the same
FILE_LOG(logDEBUG1, (" ===============current reg: %d, current unit cal:%d=================================\n", cuurentRegVal, retval));
LOG(logDEBUG1, (" ===============current reg: %d, current unit cal:%d=================================\n", cuurentRegVal, retval));
// current in uA
int currentuA = cuurentRegVal * INA226_CURRENT_IMIN_UA;
FILE_LOG(logDEBUG1, (" current: %d uA\n", currentuA));
LOG(logDEBUG1, (" current: %d uA\n", currentuA));
// current in mA
int currentmA = (currentuA / 1000.00) + 0.5;
FILE_LOG(logDEBUG1, (" current: %d mA\n", currentmA));
LOG(logDEBUG1, (" current: %d mA\n", currentmA));
FILE_LOG(logINFO, ("Current via I2C (Device: 0x%x): %d mA\n", deviceId, currentmA));
LOG(logINFO, ("Current via I2C (Device: 0x%x): %d mA\n", deviceId, currentmA));
return currentmA;
}

View File

@ -92,12 +92,12 @@ int LTC2620_DacToVoltage(int dacval, int* voltage) {
}
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));
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(logDEBUG2, ("codata: 0x%x\n", codata));
LOG(logDEBUG2, ("codata: 0x%x\n", codata));
serializeToSPI (LTC2620_Reg, codata, LTC2620_CsMask, LTC2620_NUMBITS,
LTC2620_ClkMask, LTC2620_DigMask, LTC2620_DigOffset, 0);
@ -114,24 +114,24 @@ void LTC2620_SetDaisy(int cmd, int data, int dacaddr, int chipIndex) {
uint32_t valw = 0;
int ichip = 0;
FILE_LOG(logDEBUG2, ("(Daisy) desired chip index:%d, nchip:%d, dac ch:%d, val:%d, cmd:0x%x \n",
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(logDEBUG2, ("codata: 0x%x\n", codata));
LOG(logDEBUG2, ("codata: 0x%x\n", codata));
// select all chips (ctb daisy chain; others 1 chip)
FILE_LOG(logDEBUG2, ("Selecting LTC2620\n"));
LOG(logDEBUG2, ("Selecting LTC2620\n"));
SPIChipSelect (&valw, LTC2620_Reg, LTC2620_CsMask, LTC2620_ClkMask, LTC2620_DigMask, 0);
// send same data to all
if (chipIndex < 0) {
FILE_LOG(logDEBUG2, ("Send same data to all\n"));
LOG(logDEBUG2, ("Send same data to all\n"));
for (ichip = 0; ichip < nchip; ++ichip) {
FILE_LOG(logDEBUG2, ("Send data (0x%x) to ichip %d\n", codata, ichip));
LOG(logDEBUG2, ("Send data (0x%x) to ichip %d\n", codata, ichip));
LTC2620_SendDaisyData(&valw, codata);
}
}
@ -140,40 +140,40 @@ 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(logDEBUG2, ("Send nothing to ichip %d\n", ichip));
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(logDEBUG2, ("Send data (0x%x) to ichip %d\n", codata, chipIndex));
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(logDEBUG2, ("Send nothing to ichip %d\n", ichip));
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(logDEBUG2, ("Deselecting LTC2620\n"));
LOG(logDEBUG2, ("Deselecting LTC2620\n"));
SPIChipDeselect(&valw, LTC2620_Reg, LTC2620_CsMask, LTC2620_ClkMask, LTC2620_DigMask, 0);
}
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"));
LOG(logDEBUG1, ("cmd:0x%x, data:%d, dacaddr:%d, chipIndex:%d\n", cmd, data, dacaddr, chipIndex));
LOG(logDEBUG2, (" ================================================\n"));
// ctb
if (LTC2620_Ndac > LTC2620_NUMCHANNELS)
LTC2620_SetDaisy(cmd, data, dacaddr, chipIndex);
// others
else
LTC2620_SetSingle(cmd, data, dacaddr);
FILE_LOG(logDEBUG2, (" ================================================\n"));
LOG(logDEBUG2, (" ================================================\n"));
}
void LTC2620_Configure(){
FILE_LOG(logINFOBLUE, ("Configuring LTC2620\n"));
LOG(logINFOBLUE, ("Configuring LTC2620\n"));
// dac channel - all channels
int addr = (LTC2620_DAC_ADDR_MSK >> LTC2620_DAC_ADDR_OFST);
@ -189,7 +189,7 @@ void LTC2620_Configure(){
}
void LTC2620_SetDAC (int dacnum, int data) {
FILE_LOG(logDEBUG1, ("Setting dac %d to %d\n", dacnum, data));
LOG(logDEBUG1, ("Setting dac %d to %d\n", dacnum, data));
// LTC2620 index
int ichip = dacnum / LTC2620_NUMCHANNELS;
@ -202,19 +202,19 @@ 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, ("POWER DOWN\n"));
LOG(logDEBUG1, ("POWER DOWN\n"));
} else {
FILE_LOG(logDEBUG1,("Write to Input Register and Update\n"));
LOG(logDEBUG1,("Write to Input Register and Update\n"));
}
LTC2620_Set(cmd, data, addr, ichip);
}
int LTC2620_SetDACValue (int dacnum, int val, int mV, int* dacval) {
FILE_LOG(logDEBUG1, ("dacnum:%d, val:%d, ismV:%d\n", dacnum, val, mV));
LOG(logDEBUG1, ("dacnum:%d, val:%d, ismV:%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));
LOG(logERROR, ("Dac index %d is out of bounds (0 to %d)\n", dacnum, LTC2620_Ndac - 1));
return FAIL;
}
@ -240,13 +240,13 @@ int LTC2620_SetDACValue (int dacnum, int val, int mV, int* dacval) {
// conversion out of bounds
if (ret == FAIL) {
FILE_LOG(logERROR, ("Setting Dac %d %s is out of bounds\n", dacnum, (mV ? "mV" : "dac units")));
LOG(logERROR, ("Setting Dac %d %s is out of bounds\n", dacnum, (mV ? "mV" : "dac units")));
return FAIL;
}
// set
if ( (*dacval >= 0) || (*dacval == LTC2620_PWR_DOWN_VAL)) {
FILE_LOG(logINFO, ("Setting DAC %d: %d dac (%d mV)\n",dacnum, *dacval, dacmV));
LOG(logINFO, ("Setting DAC %d: %d dac (%d mV)\n",dacnum, *dacval, dacmV));
LTC2620_SetDAC(dacnum, *dacval);
}
return OK;

View File

@ -17,7 +17,7 @@ char LTC2620_D_DriverFileName[MAX_STR_LENGTH];
int LTC2620_D_NumDacs = 0;
void LTC2620_D_SetDefines(int hardMaxV, char* driverfname, int numdacs) {
FILE_LOG(logINFOBLUE, ("Configuring DACs (LTC2620) to %s (numdacs:%d, hard max: %dmV)\n", driverfname, numdacs, hardMaxV));
LOG(logINFOBLUE, ("Configuring DACs (LTC2620) to %s (numdacs:%d, hard max: %dmV)\n", driverfname, numdacs, hardMaxV));
LTC2620_D_HardMaxVoltage = hardMaxV;
memset(LTC2620_D_DriverFileName, 0, MAX_STR_LENGTH);
strcpy(LTC2620_D_DriverFileName, driverfname);
@ -40,10 +40,10 @@ int LTC2620_D_DacToVoltage(int dacval, int* voltage) {
int LTC2620_D_SetDACValue (int dacnum, int val, int mV, char* dacname, int* dacval) {
FILE_LOG(logDEBUG1, ("dacnum:%d, val:%d, ismV:%d\n", dacnum, val, mV));
LOG(logDEBUG1, ("dacnum:%d, val:%d, ismV:%d\n", dacnum, val, mV));
// validate index
if (dacnum < 0 || dacnum >= LTC2620_D_NumDacs) {
FILE_LOG(logERROR, ("Dac index %d is out of bounds (0 to %d)\n", dacnum, LTC2620_D_NumDacs - 1));
LOG(logERROR, ("Dac index %d is out of bounds (0 to %d)\n", dacnum, LTC2620_D_NumDacs - 1));
return FAIL;
}
@ -64,22 +64,22 @@ int LTC2620_D_SetDACValue (int dacnum, int val, int mV, char* dacname, int* dacv
// conversion out of bounds
if (ret == FAIL) {
FILE_LOG(logERROR, ("Setting Dac %d %s is out of bounds\n", dacnum, (mV ? "mV" : "dac units")));
LOG(logERROR, ("Setting Dac %d %s is out of bounds\n", dacnum, (mV ? "mV" : "dac units")));
return FAIL;
}
// set
if ( (*dacval >= 0) || (*dacval == LTC2620_D_PWR_DOWN_VAL)) {
FILE_LOG(logINFO, ("Setting DAC %2d [%-12s] : %d dac (%d mV)\n",dacnum, dacname, *dacval, dacmV));
LOG(logINFO, ("Setting DAC %2d [%-12s] : %d dac (%d mV)\n",dacnum, dacname, *dacval, dacmV));
char fname[MAX_STR_LENGTH];
sprintf(fname, "%s%d", LTC2620_D_DriverFileName, dacnum);
FILE_LOG(logDEBUG1, ("fname %s\n",fname));
LOG(logDEBUG1, ("fname %s\n",fname));
//open file
FILE* fd=fopen(fname,"w");
if (fd==NULL) {
FILE_LOG(logERROR, ("Could not open file %s for writing to set dac %d\n", fname, dacnum));
LOG(logERROR, ("Could not open file %s for writing to set dac %d\n", fname, dacnum));
return FAIL;
}
//convert to string, add 0 and write to file

View File

@ -26,7 +26,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"));
LOG(logINFOBLUE, ("Configuring High Voltage\n"));
MAX1932_Reg = reg;
MAX1932_CsMask = cmsk;
MAX1932_ClkMask = clkmsk;
@ -44,7 +44,7 @@ void MAX1932_Disable() {
}
int MAX1932_Set (int val) {
FILE_LOG(logDEBUG1, ("Setting high voltage to %d\n", val));
LOG(logDEBUG1, ("Setting high voltage to %d\n", val));
if (val < 0)
return FAIL;
@ -69,7 +69,7 @@ int MAX1932_Set (int val) {
dacvalue &= MAX1932_HV_DATA_MSK;
}
FILE_LOG(logINFO, ("\t%dV (dacval %d)\n", val, dacvalue));
LOG(logINFO, ("\t%dV (dacval %d)\n", val, dacvalue));
serializeToSPI(MAX1932_Reg, dacvalue, MAX1932_CsMask, MAX1932_HV_NUMBITS,
MAX1932_ClkMask, MAX1932_DigMask, MAX1932_DigOffset, 0);
return OK;

View File

@ -54,7 +54,7 @@ void createUDPPacketHeader(char* buffer, uint16_t id) {
}
int fillUDPPacket(char* buffer) {
FILE_LOG(logDEBUG2, ("Analog (databytes:%d, offset:%d)\n Digital (databytes:%d offset:%d)\n",
LOG(logDEBUG2, ("Analog (databytes:%d, offset:%d)\n Digital (databytes:%d offset:%d)\n",
analogDataBytes, analogOffset, digitalDataBytes, digitalOffset));
// reached end of data for one frame
if (analogOffset >= analogDataBytes && digitalOffset >= digitalDataBytes) {
@ -76,7 +76,7 @@ int fillUDPPacket(char* buffer) {
// increment and copy udp packet number (starts at 0)
++udpPacketNumber;
header->packetNumber = udpPacketNumber;
FILE_LOG(logDEBUG2, ("Creating packet number %d (fnum:%lld)\n", udpPacketNumber, (long long int) udpFrameNumber));
LOG(logDEBUG2, ("Creating packet number %d (fnum:%lld)\n", udpPacketNumber, (long long int) udpFrameNumber));
int freeBytes = UDP_PACKET_DATA_BYTES;
@ -111,7 +111,7 @@ int fillUDPPacket(char* buffer) {
// pad data
if (freeBytes) {
memset(buffer + sizeof(sls_detector_header) + analogBytes + digitalBytes, 0, freeBytes);
FILE_LOG(logDEBUG1, ("Padding %d bytes for fnum:%lld pnum:%d\n", freeBytes, (long long int)udpFrameNumber, udpPacketNumber));
LOG(logDEBUG1, ("Padding %d bytes for fnum:%lld pnum:%d\n", freeBytes, (long long int)udpFrameNumber, udpPacketNumber));
}
return UDP_PACKET_DATA_BYTES + sizeof(sls_detector_header);

View File

@ -44,7 +44,7 @@ int64_t get64BitReg(int aLSB, int aMSB){
vMSB=bus_r(aMSB);
v64=vMSB;
v64=(v64<<32) | vLSB;
FILE_LOG(logDEBUG5, (" reg64(%x,%x) %x %x %llx\n", aLSB, aMSB, vLSB, vMSB, (long long unsigned int)v64));
LOG(logDEBUG5, (" reg64(%x,%x) %x %x %llx\n", aLSB, aMSB, vLSB, vMSB, (long long unsigned int)v64));
return v64;
}
@ -94,33 +94,33 @@ u_int32_t writeRegister16(u_int32_t offset, u_int32_t data) {
int mapCSP0(void) {
// if not mapped
if (csp0base == 0) {
FILE_LOG(logINFO, ("Mapping memory\n"));
LOG(logINFO, ("Mapping memory\n"));
#ifdef VIRTUAL
csp0base = malloc(MEM_SIZE);
if (csp0base == NULL) {
FILE_LOG(logERROR, ("Could not allocate virtual memory.\n"));
LOG(logERROR, ("Could not allocate virtual memory.\n"));
return FAIL;
}
FILE_LOG(logINFO, ("memory allocated\n"));
LOG(logINFO, ("memory allocated\n"));
#else
int fd;
fd = open("/dev/mem", O_RDWR | O_SYNC, 0);
if (fd == -1) {
FILE_LOG(logERROR, ("Can't find /dev/mem\n"));
LOG(logERROR, ("Can't find /dev/mem\n"));
return FAIL;
}
FILE_LOG(logDEBUG1, ("/dev/mem opened\n"));
LOG(logDEBUG1, ("/dev/mem opened\n"));
csp0base = mmap(0, MEM_SIZE, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd, CSP0);
if (csp0base == MAP_FAILED) {
FILE_LOG(logERROR, ("Can't map memmory area\n"));
LOG(logERROR, ("Can't map memmory area\n"));
return FAIL;
}
#endif
FILE_LOG(logINFO, ("csp0base mapped from %p to %p\n",
LOG(logINFO, ("csp0base mapped from %p to %p\n",
csp0base, (csp0base + MEM_SIZE)));
FILE_LOG(logINFO, ("Status Register: %08x\n", bus_r(STATUS_REG)));
LOG(logINFO, ("Status Register: %08x\n", bus_r(STATUS_REG)));
}else
FILE_LOG(logINFO, ("Memory already mapped before\n"));
LOG(logINFO, ("Memory already mapped before\n"));
return OK;
}

View File

@ -4,7 +4,7 @@
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",
LOG(logDEBUG1, (" Input Value: %d (Input:(%d - %d), Output:(%d - %d))\n",
inputValue, inputMin, inputMax, outputMin, outputMax));
// validate within bounds
@ -16,7 +16,7 @@ int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int outpu
bigger = inputMin;
}
if ((inputValue < smaller) || (inputValue > bigger)) {
FILE_LOG(logERROR, ("Input Value is outside bounds (%d to %d): %d\n", smaller, bigger, inputValue));
LOG(logERROR, ("Input Value is outside bounds (%d to %d): %d\n", smaller, bigger, inputValue));
*outputValue = -1;
return FAIL;
}
@ -30,7 +30,7 @@ int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int outpu
}
*outputValue = value;
FILE_LOG(logDEBUG1, (" Converted Output Value: %d\n", *outputValue));
LOG(logDEBUG1, (" Converted Output Value: %d\n", *outputValue));
return OK;
}

View File

@ -5,7 +5,7 @@
#include <unistd.h> // usleep
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",
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));
// start point
@ -18,7 +18,7 @@ void SPIChipSelect (uint32_t* valw, uint32_t addr, uint32_t csmask, uint32_t cl
(*valw) = ((bus_r(addr) | csmask | clkmask) &(~digoutmask));
}
bus_w (addr, (*valw));
FILE_LOG(logDEBUG2, ("startpoint. valw:0x%08x\n", *valw));
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)
@ -27,12 +27,12 @@ void SPIChipSelect (uint32_t* valw, uint32_t addr, uint32_t csmask, uint32_t cl
// chip sel bar down
(*valw) &= ~csmask;
bus_w (addr, (*valw));
FILE_LOG(logDEBUG2, ("chip sel bar down. valw:0x%08x\n", *valw));
LOG(logDEBUG2, ("chip sel bar down. valw:0x%08x\n", *valw));
}
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 convbit:%d\n",
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)
@ -42,7 +42,7 @@ void SPIChipDeselect (uint32_t* valw, uint32_t addr, uint32_t csmask, uint32_t
// chip sel bar up
(*valw) |= csmask;
bus_w (addr, (*valw));
FILE_LOG(logDEBUG2, ("chip sel bar up. valw:0x%08x\n", *valw));
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)
@ -51,7 +51,7 @@ void SPIChipDeselect (uint32_t* valw, uint32_t addr, uint32_t csmask, uint32_t
//clk down
(*valw) &= ~clkmask;
bus_w (addr, (*valw));
FILE_LOG(logDEBUG2, ("clk down. valw:0x%08x\n", *valw));
LOG(logDEBUG2, ("clk down. valw:0x%08x\n", *valw));
// stop point = start point of course
(*valw) &= ~digoutmask;
@ -62,11 +62,11 @@ void SPIChipDeselect (uint32_t* valw, uint32_t addr, uint32_t csmask, uint32_t
(*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));
LOG(logDEBUG2, ("stop point. valw:0x%08x\n", *valw));
}
void sendDataToSPI (uint32_t* valw, uint32_t addr, uint32_t val, int numbitstosend, uint32_t clkmask, uint32_t digoutmask, int digofset) {
FILE_LOG(logDEBUG2, ("SPI send data. valw:0x%08x addr:0x%x val:0x%x, numbitstosend:%d, clkmask:0x%x digmask:0x%x digofst:%d\n",
LOG(logDEBUG2, ("SPI send data. valw:0x%08x addr:0x%x val:0x%x, numbitstosend:%d, clkmask:0x%x digmask:0x%x digofst:%d\n",
*valw, addr, val, numbitstosend, clkmask, digoutmask, digofset));
int i = 0;
@ -75,23 +75,23 @@ void sendDataToSPI (uint32_t* valw, uint32_t addr, uint32_t val, int numbitstose
// clk down
(*valw) &= ~clkmask;
bus_w (addr, (*valw));
FILE_LOG(logDEBUG2, ("clk down. valw:0x%08x\n", *valw));
LOG(logDEBUG2, ("clk down. valw:0x%08x\n", *valw));
// write data (i)
(*valw) = (((*valw) & ~digoutmask) + // unset bit
(((val >> (numbitstosend - 1 - i)) & 0x1) << digofset)); // each bit from val starting from msb
bus_w (addr, (*valw));
FILE_LOG(logDEBUG2, ("write data %d. valw:0x%08x\n", i, *valw));
LOG(logDEBUG2, ("write data %d. valw:0x%08x\n", i, *valw));
// clk up
(*valw) |= clkmask ;
bus_w (addr, (*valw));
FILE_LOG(logDEBUG2, ("clk up. valw:0x%08x\n", *valw));
LOG(logDEBUG2, ("clk up. valw:0x%08x\n", *valw));
}
}
uint32_t receiveDataFromSPI (uint32_t* valw, uint32_t addr, int numbitstoreceive, uint32_t clkmask, uint32_t readaddr) {
FILE_LOG(logDEBUG2, ("SPI send data. valw:0x%08x addr:0x%x numbitstoreceive:%d, clkmask:0x%x readaddr:0x%x \n",
LOG(logDEBUG2, ("SPI send data. valw:0x%08x addr:0x%x numbitstoreceive:%d, clkmask:0x%x readaddr:0x%x \n",
*valw, addr, numbitstoreceive, clkmask, readaddr));
uint32_t retval = 0;
@ -102,18 +102,18 @@ uint32_t receiveDataFromSPI (uint32_t* valw, uint32_t addr, int numbitstoreceive
// clk down
(*valw) &= ~clkmask;
bus_w (addr, (*valw));
FILE_LOG(logDEBUG2, ("clk down. valw:0x%08x\n", *valw));
LOG(logDEBUG2, ("clk down. valw:0x%08x\n", *valw));
// read data (i)
retval |= ((bus_r(readaddr) & 0x1) << (numbitstoreceive - 1 - i));
FILE_LOG(logDEBUG2, ("read data %d. retval:0x%08x\n", i, retval));
LOG(logDEBUG2, ("read data %d. retval:0x%08x\n", i, retval));
usleep(20);
// clk up
(*valw) |= clkmask ;
bus_w (addr, (*valw));
FILE_LOG(logDEBUG2, ("clk up. valw:0x%08x\n", *valw));
LOG(logDEBUG2, ("clk up. valw:0x%08x\n", *valw));
usleep(20);
}
@ -123,9 +123,9 @@ uint32_t receiveDataFromSPI (uint32_t* valw, uint32_t addr, int numbitstoreceive
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));
LOG(logDEBUG2, ("Writing to SPI Register: 0x%04x\n", val));
} else {
FILE_LOG(logDEBUG2, ("Writing to SPI Register: 0x%08x\n", val));
LOG(logDEBUG2, ("Writing to SPI Register: 0x%08x\n", val));
}
uint32_t valw;
@ -148,9 +148,9 @@ uint32_t serializeFromSPI(uint32_t addr, uint32_t csmask, int numbitstoreceive,
//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));
LOG(logDEBUG2, ("Read From SPI Register: 0x%04x\n", retval));
} else {
FILE_LOG(logDEBUG2, ("Read From SPI Register: 0x%08x\n", retval));
LOG(logDEBUG2, ("Read From SPI Register: 0x%08x\n", retval));
}
return retval;
}

View File

@ -55,7 +55,7 @@ int bindSocket(unsigned short int port_number) {
if (myport == port_number) {
sprintf(mess, "Cannot create %s socket with port %d. Already in use before.\n",
(isControlServer ? "control":"stop"), port_number);
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
}
// port ok
else {
@ -66,7 +66,7 @@ int bindSocket(unsigned short int port_number) {
if (socketDescriptor < 0) {
sprintf(mess, "Cannot create %s socket with port %d\n",
(isControlServer ? "control":"stop"), port_number);
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
}
// socket success
else {
@ -82,7 +82,7 @@ int bindSocket(unsigned short int port_number) {
if(bind(socketDescriptor,(struct sockaddr *) &addressS,sizeof(addressS)) < 0){
sprintf(mess, "Cannot bind %s socket to port %d.\n",
(isControlServer ? "control":"stop"), port_number);
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
}
// bind socket ok
else {
@ -100,7 +100,7 @@ int bindSocket(unsigned short int port_number) {
// success
myport = port_number;
ret = OK;
FILE_LOG(logDEBUG1, ("%s socket bound: isock=%d, port=%d, fd=%d\n",
LOG(logDEBUG1, ("%s socket bound: isock=%d, port=%d, fd=%d\n",
(isControlServer ? "Control":"Stop"), isock, port_number, socketDescriptor));
}
@ -108,7 +108,7 @@ int bindSocket(unsigned short int port_number) {
else {
sprintf(mess, "Cannot bind %s socket to port %d.\n",
(isControlServer ? "control":"stop"), port_number);
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
}
}
}
@ -141,81 +141,81 @@ int acceptConnection(int socketDescriptor) {
// timeout
if (result == 0) {
FILE_LOG(logDEBUG3, ("%s socket select() timed out!\n",
LOG(logDEBUG3, ("%s socket select() timed out!\n",
(isControlServer ? "control":"stop"), myport));
}
// error (not signal caught)
else if (result < 0 && errno != EINTR) {
FILE_LOG(logERROR, ("%s socket select() error: %s\n",
LOG(logERROR, ("%s socket select() error: %s\n",
(isControlServer ? "control":"stop"), myport, strerror(errno)));
}
// activity in descriptor set
else if (result > 0) {
FILE_LOG(logDEBUG3, ("%s select returned!\n", (isControlServer ? "control":"stop")));
LOG(logDEBUG3, ("%s select returned!\n", (isControlServer ? "control":"stop")));
// loop through the file descriptor set
for (j = 0; j < maxfd + 1; ++j) {
// checks if file descriptor part of set
if (FD_ISSET(j, &tempset)) {
FILE_LOG(logDEBUG3, ("fd %d is set\n",j));
LOG(logDEBUG3, ("fd %d is set\n",j));
// clear the temporary set
FD_CLR(j, &tempset);
// accept connection (if error)
if ((file_des = accept(j,(struct sockaddr *) &addressC, &address_length)) < 0) {
FILE_LOG(logERROR, ("%s socket accept() error. Connection refused.\n",
LOG(logERROR, ("%s socket accept() error. Connection refused.\n",
"Error Number: %d, Message: %s\n",
(isControlServer ? "control":"stop"),
myport, errno, strerror(errno)));
switch(errno) {
case EWOULDBLOCK:
FILE_LOG(logERROR, ("ewouldblock eagain"));
LOG(logERROR, ("ewouldblock eagain"));
break;
case EBADF:
FILE_LOG(logERROR, ("ebadf\n"));
LOG(logERROR, ("ebadf\n"));
break;
case ECONNABORTED:
FILE_LOG(logERROR, ("econnaborted\n"));
LOG(logERROR, ("econnaborted\n"));
break;
case EFAULT:
FILE_LOG(logERROR, ("efault\n"));
LOG(logERROR, ("efault\n"));
break;
case EINTR:
FILE_LOG(logERROR, ("eintr\n"));
LOG(logERROR, ("eintr\n"));
break;
case EINVAL:
FILE_LOG(logERROR, ("einval\n"));
LOG(logERROR, ("einval\n"));
break;
case EMFILE:
FILE_LOG(logERROR, ("emfile\n"));
LOG(logERROR, ("emfile\n"));
break;
case ENFILE:
FILE_LOG(logERROR, ("enfile\n"));
LOG(logERROR, ("enfile\n"));
break;
case ENOTSOCK:
FILE_LOG(logERROR, ("enotsock\n"));
LOG(logERROR, ("enotsock\n"));
break;
case EOPNOTSUPP:
FILE_LOG(logERROR, ("eOPNOTSUPP\n"));
LOG(logERROR, ("eOPNOTSUPP\n"));
break;
case ENOBUFS:
FILE_LOG(logERROR, ("ENOBUFS\n"));
LOG(logERROR, ("ENOBUFS\n"));
break;
case ENOMEM:
FILE_LOG(logERROR, ("ENOMEM\n"));
LOG(logERROR, ("ENOMEM\n"));
break;
case ENOSR:
FILE_LOG(logERROR, ("ENOSR\n"));
LOG(logERROR, ("ENOSR\n"));
break;
case EPROTO:
FILE_LOG(logERROR, ("EPROTO\n"));
LOG(logERROR, ("EPROTO\n"));
break;
default:
FILE_LOG(logERROR, ("unknown error\n"));
LOG(logERROR, ("unknown error\n"));
}
}
// accept success
@ -223,7 +223,7 @@ int acceptConnection(int socketDescriptor) {
char buf[INET_ADDRSTRLEN] = "";
memset(buf, 0, INET_ADDRSTRLEN);
inet_ntop(AF_INET, &(addressC.sin_addr), buf, INET_ADDRSTRLEN);
FILE_LOG(logDEBUG3, ("%s socket accepted connection, fd= %d\n",
LOG(logDEBUG3, ("%s socket accepted connection, fd= %d\n",
(isControlServer ? "control":"stop"), file_des));
getIpAddressFromString(buf, &dummyClientIP);
@ -255,7 +255,7 @@ void exitServer(int socketDescriptor) {
if (socketDescriptor >= 0) {
close(socketDescriptor);
}
FILE_LOG(logINFO, ("Closing %s server\n", (isControlServer ? "control":"stop")));
LOG(logINFO, ("Closing %s server\n", (isControlServer ? "control":"stop")));
FD_CLR(socketDescriptor, &readset);
isock--;
fflush(stdout);
@ -332,18 +332,18 @@ int sendDataOnly(int file_des, void* buf,int length) {
int rc = write(file_des, (char*)((char*)buf + bytesSent), bytesToSend);
// error
if (rc < 0) {
FILE_LOG(logERROR, ("Could not write to %s socket. Possible socket crash\n",
LOG(logERROR, ("Could not write to %s socket. Possible socket crash\n",
(isControlServer ? "control":"stop")));
return bytesSent;
}
// also error, wrote nothing, buffer blocked up, too fast sending for client
if (rc == 0) {
FILE_LOG(logERROR, ("Could not write to %s socket. Buffer full. Retry: %d\n",
LOG(logERROR, ("Could not write to %s socket. Buffer full. Retry: %d\n",
(isControlServer ? "control":"stop"), retry));
++retry;
// wrote nothing for many loops
if (retry >= CPU_RSND_PCKT_LOOP) {
FILE_LOG(logERROR, ("Could not write to %s socket. Buffer full! Too fast! No more.\n",
LOG(logERROR, ("Could not write to %s socket. Buffer full! Too fast! No more.\n",
(isControlServer ? "control":"stop")));
return bytesSent;
}
@ -353,7 +353,7 @@ int sendDataOnly(int file_des, void* buf,int length) {
else {
retry = 0;
if (rc != bytesToSend) {
FILE_LOG(logWARNING, ("Only partial write to %s socket. Expected to write %d bytes, wrote %d\n",
LOG(logWARNING, ("Only partial write to %s socket. Expected to write %d bytes, wrote %d\n",
(isControlServer ? "control":"stop"), bytesToSend, rc));
}
}
@ -370,7 +370,7 @@ int receiveDataOnly(int file_des, void* buf,int length) {
int nreceiving;
int nreceived;
if (file_des<0) return -1;
FILE_LOG(logDEBUG3, ("want to receive %d Bytes to %s server\n",
LOG(logDEBUG3, ("want to receive %d Bytes to %s server\n",
length, (isControlServer ? "control":"stop")));
while(length > 0) {
@ -459,7 +459,7 @@ int sendModule(int file_des, sls_detector_module *myMod) {
}
ts += n;
#endif
FILE_LOG(logDEBUG1, ("module of size %d sent register %x\n", ts, myMod->reg));
LOG(logDEBUG1, ("module of size %d sent register %x\n", ts, myMod->reg));
return ts;
}
@ -467,70 +467,70 @@ int sendModule(int file_des, sls_detector_module *myMod) {
int receiveModule(int file_des, sls_detector_module* myMod) {
enum TLogLevel level = logDEBUG1;
FILE_LOG(level, ("Receiving Module\n"));
LOG(level, ("Receiving Module\n"));
int ts = 0, n = 0;
int nDacs = myMod->ndac;
#ifdef EIGERD
int nChans = myMod->nchan; // can be zero for no trimbits
FILE_LOG(level, ("nChans: %d\n",nChans));
LOG(level, ("nChans: %d\n",nChans));
#endif
n = receiveData(file_des,&(myMod->serialnumber), sizeof(myMod->serialnumber), INT32);
if (!n) {
return -1;
}
ts += n;
FILE_LOG(level, ("serialno received. %d bytes. serialno: %d\n", n,
LOG(level, ("serialno received. %d bytes. serialno: %d\n", n,
myMod->serialnumber));
n = receiveData(file_des, &(myMod->nchan), sizeof(myMod->nchan), INT32);
if (!n) {
return -1;
}
ts += n;
FILE_LOG(level,
LOG(level,
("nchan received. %d bytes. nchan: %d\n", n, myMod->nchan));
n = receiveData(file_des, &(myMod->nchip), sizeof(myMod->nchip), INT32);
if (!n) {
return -1;
}
ts += n;
FILE_LOG(level,
LOG(level,
("nchip received. %d bytes. nchip: %d\n", n, myMod->nchip));
n = receiveData(file_des, &(myMod->ndac), sizeof(myMod->ndac), INT32);
if (!n) {
return -1;
}
ts += n;
FILE_LOG(level,
LOG(level,
("ndac received. %d bytes. ndac: %d\n", n, myMod->ndac));
n = receiveData(file_des, &(myMod->reg), sizeof(myMod->reg), INT32);
if (!n) {
return -1;
}
ts += n;
FILE_LOG(level, ("reg received. %d bytes. reg: %d\n", n, myMod->reg));
LOG(level, ("reg received. %d bytes. reg: %d\n", n, myMod->reg));
n = receiveData(file_des, &(myMod->iodelay), sizeof(myMod->iodelay),
INT32);
if (!n) {
return -1;
}
ts += n;
FILE_LOG(level, ("iodelay received. %d bytes. iodelay: %d\n", n,
LOG(level, ("iodelay received. %d bytes. iodelay: %d\n", n,
myMod->iodelay));
n = receiveData(file_des, &(myMod->tau), sizeof(myMod->tau), INT32);
if (!n) {
return -1;
}
ts += n;
FILE_LOG(level, ("tau received. %d bytes. tau: %d\n", n, myMod->tau));
LOG(level, ("tau received. %d bytes. tau: %d\n", n, myMod->tau));
n = receiveData(file_des, &(myMod->eV), sizeof(myMod->eV), INT32);
if (!n) {
return -1;
}
ts += n;
FILE_LOG(level, ("eV received. %d bytes. eV: %d\n", n, myMod->eV));
LOG(level, ("eV received. %d bytes. eV: %d\n", n, myMod->eV));
// dacs
if (nDacs != (myMod->ndac)) {
FILE_LOG(logERROR, ("received wrong number of dacs. "
LOG(logERROR, ("received wrong number of dacs. "
"Expected %d, got %d\n",
nDacs, myMod->ndac));
return 0;
@ -540,23 +540,23 @@ int receiveModule(int file_des, sls_detector_module* myMod) {
return -1;
}
ts += n;
FILE_LOG(level, ("dacs received. %d bytes.\n", n));
LOG(level, ("dacs received. %d bytes.\n", n));
// channels
#ifdef EIGERD
if (((myMod->nchan) != 0 ) && // no trimbits
(nChans != (myMod->nchan))) { // with trimbits
FILE_LOG(logERROR, ("received wrong number of channels. "
LOG(logERROR, ("received wrong number of channels. "
"Expected %d, got %d\n", nChans, (myMod->nchan)));
return 0;
}
n = receiveData(file_des, myMod->chanregs, sizeof(int) * (myMod->nchan), INT32);
FILE_LOG(level, ("chanregs received. %d bytes.\n", n));
LOG(level, ("chanregs received. %d bytes.\n", n));
if (!n && myMod->nchan != 0){
return -1;
}
ts += n;
#endif
FILE_LOG(level, ("received module of size %d register %x\n",ts,myMod->reg));
LOG(level, ("received module of size %d register %x\n",ts,myMod->reg));
return ts;
}
@ -566,7 +566,7 @@ void Server_LockedError() {
char buf[INET_ADDRSTRLEN] = "";
getIpAddressinString(buf, dummyClientIP);
sprintf(mess,"Detector locked by %s\n", buf);
FILE_LOG(logWARNING, (mess));
LOG(logWARNING, (mess));
}
@ -592,7 +592,7 @@ int Server_SendResult(int fileDes, intType itype, int update, void* retval, int
sendData(fileDes, mess, MAX_STR_LENGTH, OTHER);
// debugging feature. should not happen.
else
FILE_LOG(logERROR, ("No error message provided for this failure in %s "
LOG(logERROR, ("No error message provided for this failure in %s "
"server. Will mess up TCP.\n",
(isControlServer ? "control":"stop")));
}

View File

@ -46,12 +46,12 @@ int setUDPDestinationDetails(int index, const char* ip, unsigned short int port)
sprintf(sport, "%d", udpDestinationPort[index]);
int err = getaddrinfo(udpDestinationIp[index], sport, &hints, &udpServerAddrInfo[index]);
if (err != 0) {
FILE_LOG(logERROR, ("Failed to resolve remote socket address %s at port %d. "
LOG(logERROR, ("Failed to resolve remote socket address %s at port %d. "
"(Error code:%d, %s)\n", udpDestinationIp[index], udpDestinationPort[index], err, gai_strerror(err)));
return FAIL;
}
if (udpServerAddrInfo[index] == NULL) {
FILE_LOG(logERROR, ("Failed to resolve remote socket address %s at port %d "
LOG(logERROR, ("Failed to resolve remote socket address %s at port %d "
"(getaddrinfo returned NULL)\n", udpDestinationIp[index], udpDestinationPort[index]));
udpServerAddrInfo[index] = 0;
return FAIL;
@ -61,14 +61,14 @@ int setUDPDestinationDetails(int index, const char* ip, unsigned short int port)
}
int createUDPSocket(int index) {
FILE_LOG(logDEBUG2, ("Creating UDP Socket %d\n", index));
LOG(logDEBUG2, ("Creating UDP Socket %d\n", index));
if (!strlen(udpDestinationIp[index])) {
FILE_LOG(logERROR, ("No destination UDP ip specified.\n"));
LOG(logERROR, ("No destination UDP ip specified.\n"));
return FAIL;
}
if (udpSockfd[index] != -1) {
FILE_LOG(logERROR, ("Strange that Udp socket was still open. Closing it to create a new one\n"));
LOG(logERROR, ("Strange that Udp socket was still open. Closing it to create a new one\n"));
close(udpSockfd[index]);
udpSockfd[index] = -1;
}
@ -76,20 +76,20 @@ int createUDPSocket(int index) {
// Creating socket file descriptor
udpSockfd[index] = socket(udpServerAddrInfo[index]->ai_family, udpServerAddrInfo[index]->ai_socktype, udpServerAddrInfo[index]->ai_protocol);
if (udpSockfd[index] == -1 ) {
FILE_LOG(logERROR, ("UDP socket at port %d failed. (Error code:%d, %s)\n",
LOG(logERROR, ("UDP socket at port %d failed. (Error code:%d, %s)\n",
udpDestinationPort[index], errno, gai_strerror(errno)));
return FAIL;
}
FILE_LOG(logINFO, ("Udp client socket created for server (port %d, ip:%s)\n",
LOG(logINFO, ("Udp client socket created for server (port %d, ip:%s)\n",
udpDestinationPort[index], udpDestinationIp[index]));
// connecting allows to use "send/write" instead of "sendto", avoiding checking for server address for each packet
// using write without a connect will end in segv
if (connect(udpSockfd[index],udpServerAddrInfo[index]->ai_addr, udpServerAddrInfo[index]->ai_addrlen)==-1) {
FILE_LOG(logERROR, ("Could not connect to UDP server at ip:%s, port:%d. (Error code:%d, %s)\n",
LOG(logERROR, ("Could not connect to UDP server at ip:%s, port:%d. (Error code:%d, %s)\n",
udpDestinationIp[index], udpDestinationPort[index], errno, gai_strerror(errno)));
}
FILE_LOG(logINFO, ("Udp client socket connected\n",
LOG(logINFO, ("Udp client socket connected\n",
udpDestinationPort[index], udpDestinationIp[index]));
return OK;
}
@ -98,17 +98,17 @@ int sendUDPPacket(int index, const char* buf, int length) {
int n = write(udpSockfd[index], buf, length);
// udp sends atomically, no need to handle partial data
if (n == -1) {
FILE_LOG(logERROR, ("Could not send udp packet for socket %d. (Error code:%d, %s)\n",
LOG(logERROR, ("Could not send udp packet for socket %d. (Error code:%d, %s)\n",
index, n, errno, gai_strerror(errno)));
} else {
FILE_LOG(logDEBUG2, ("%d bytes sent\n", n));
LOG(logDEBUG2, ("%d bytes sent\n", n));
}
return n;
}
void closeUDPSocket(int index) {
if (udpSockfd[index] != -1) {
FILE_LOG(logINFO, ("Udp client socket closed\n"));
LOG(logINFO, ("Udp client socket closed\n"));
close(udpSockfd[index]);
udpSockfd[index] = -1;
}

View File

@ -46,7 +46,7 @@ int64_t get64BitReg(int aLSB, int aMSB){
vMSB=bus_r(aMSB);
v64=vMSB;
v64=(v64<<32) | vLSB;
FILE_LOG(logDEBUG5, (" reg64(%x,%x) %x %x %llx\n", aLSB, aMSB, vLSB, vMSB, (long long unsigned int)v64));
LOG(logDEBUG5, (" reg64(%x,%x) %x %x %llx\n", aLSB, aMSB, vLSB, vMSB, (long long unsigned int)v64));
return v64;
}
@ -94,32 +94,32 @@ int mapCSP0(void) {
for (i = 0; i < 2; ++i) {
// if not mapped
if (*cspbases[i] == 0) {
FILE_LOG(logINFO, ("Mapping memory for %s\n", names[i]));
LOG(logINFO, ("Mapping memory for %s\n", names[i]));
#ifdef VIRTUAL
*cspbases[i] = malloc(MEM_SIZE);
if (*cspbases[i] == NULL) {
FILE_LOG(logERROR, ("Could not allocate virtual memory for %s.\n", names[i]));
LOG(logERROR, ("Could not allocate virtual memory for %s.\n", names[i]));
return FAIL;
}
FILE_LOG(logINFO, ("memory allocated for %s\n", names[i]));
LOG(logINFO, ("memory allocated for %s\n", names[i]));
#else
int fd = open("/dev/mem", O_RDWR | O_SYNC, 0);
if (fd == -1) {
FILE_LOG(logERROR, ("Can't find /dev/mem for %s\n", names[i]));
LOG(logERROR, ("Can't find /dev/mem for %s\n", names[i]));
return FAIL;
}
FILE_LOG(logDEBUG1, ("/dev/mem opened for %s, (CSP:0x%x)\n", names[i], csps[i]));
LOG(logDEBUG1, ("/dev/mem opened for %s, (CSP:0x%x)\n", names[i], csps[i]));
*cspbases[i] = (u_int32_t*)mmap(0, MEM_SIZE, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd, csps[i]);
if (*cspbases[i] == MAP_FAILED) {
FILE_LOG(logERROR, ("Can't map memmory area for %s\n", names[i]));
LOG(logERROR, ("Can't map memmory area for %s\n", names[i]));
return FAIL;
}
#endif
FILE_LOG(logINFO, ("%s mapped from %p to %p,(CSP:0x%x) \n",
LOG(logINFO, ("%s mapped from %p to %p,(CSP:0x%x) \n",
names[i], *cspbases[i], *cspbases[i]+MEM_SIZE, csps[i]));
//FILE_LOG(logINFO, ("Status Register: %08x\n", bus_r(STATUS_REG)));
//LOG(logINFO, ("Status Register: %08x\n", bus_r(STATUS_REG)));
} else
FILE_LOG(logINFO, ("Memory %s already mapped before\n", names[i]));
LOG(logINFO, ("Memory %s already mapped before\n", names[i]));
}
return OK;
}

View File

@ -21,9 +21,9 @@ void defineGPIOpins(){
//define their direction
system("echo in > /sys/class/gpio/gpio7/direction");
system("echo out > /sys/class/gpio/gpio9/direction");
FILE_LOG(logINFO, ("gpio pins defined\n"));
LOG(logINFO, ("gpio pins defined\n"));
gpioDefined = 1;
}else FILE_LOG(logDEBUG1, ("gpio pins already defined earlier\n"));
}else LOG(logDEBUG1, ("gpio pins already defined earlier\n"));
}
void FPGAdontTouchFlash(){
@ -38,23 +38,23 @@ void FPGATouchFlash(){
}
void resetFPGA(){
FILE_LOG(logINFOBLUE, ("Reseting FPGA\n"));
LOG(logINFOBLUE, ("Reseting FPGA\n"));
FPGAdontTouchFlash();
FPGATouchFlash();
usleep(CTRL_SRVR_INIT_TIME_US);
}
void eraseFlash(){
FILE_LOG(logDEBUG1, ("Erasing Flash\n"));
LOG(logDEBUG1, ("Erasing Flash\n"));
char command[255];
memset(command, 0, 255);
sprintf(command,"flash_eraseall %s",mtdvalue);
system(command);
FILE_LOG(logINFO, ("Flash erased\n"));
LOG(logINFO, ("Flash erased\n"));
}
int startWritingFPGAprogram(FILE** filefp){
FILE_LOG(logDEBUG1, ("Start Writing of FPGA program\n"));
LOG(logDEBUG1, ("Start Writing of FPGA program\n"));
//getting the drive
//root:/> cat /proc/mtd
@ -67,11 +67,11 @@ int startWritingFPGAprogram(FILE** filefp){
memset(output, 0, 255);
FILE* fp = popen("awk \'$4== \"\\\"bitfile(spi)\\\"\" {print $1}\' /proc/mtd", "r");
if (fp == NULL) {
FILE_LOG(logERROR, ("popen returned NULL. Need that to get mtd drive.\n"));
LOG(logERROR, ("popen returned NULL. Need that to get mtd drive.\n"));
return 1;
}
if (fgets(output, sizeof(output), fp) == NULL) {
FILE_LOG(logERROR, ("fgets returned NULL. Need that to get mtd drive.\n"));
LOG(logERROR, ("fgets returned NULL. Need that to get mtd drive.\n"));
return 1;
}
pclose(fp);
@ -79,27 +79,27 @@ int startWritingFPGAprogram(FILE** filefp){
strcpy(mtdvalue,"/dev/");
char* pch = strtok(output,":");
if(pch == NULL){
FILE_LOG(logERROR, ("Could not get mtd value\n"));
LOG(logERROR, ("Could not get mtd value\n"));
return 1;
}
strcat(mtdvalue,pch);
FILE_LOG(logINFO, ("Flash drive found: %s\n", mtdvalue));
LOG(logINFO, ("Flash drive found: %s\n", mtdvalue));
FPGAdontTouchFlash();
//writing the program to flash
*filefp = fopen(mtdvalue, "w");
if(*filefp == NULL){
FILE_LOG(logERROR, ("Unable to open %s in write mode\n", mtdvalue));
LOG(logERROR, ("Unable to open %s in write mode\n", mtdvalue));
return 1;
}
FILE_LOG(logINFO, ("Flash ready for writing\n"));
LOG(logINFO, ("Flash ready for writing\n"));
return 0;
}
void stopWritingFPGAprogram(FILE* filefp){
FILE_LOG(logDEBUG1, ("Stopping of writing FPGA program\n"));
LOG(logDEBUG1, ("Stopping of writing FPGA program\n"));
int wait = 0;
if(filefp!= NULL){
@ -111,7 +111,7 @@ void stopWritingFPGAprogram(FILE* filefp){
FPGATouchFlash();
if(wait){
FILE_LOG(logDEBUG1, ("Waiting for FPGA to program from flash\n"));
LOG(logDEBUG1, ("Waiting for FPGA to program from flash\n"));
//waiting for success or done
char output[255];
int res=0;
@ -120,22 +120,22 @@ void stopWritingFPGAprogram(FILE* filefp){
fgets(output, sizeof(output), sysFile);
pclose(sysFile);
sscanf(output,"%d",&res);
FILE_LOG(logDEBUG1, ("gpi07 returned %d\n", res));
LOG(logDEBUG1, ("gpi07 returned %d\n", res));
}
}
FILE_LOG(logINFO, ("FPGA has picked up the program from flash\n"));
LOG(logINFO, ("FPGA has picked up the program from flash\n"));
}
int writeFPGAProgram(char* fpgasrc, uint64_t fsize, FILE* filefp){
FILE_LOG(logDEBUG1, ("Writing of FPGA Program\n"
LOG(logDEBUG1, ("Writing of FPGA Program\n"
"\taddress of fpgasrc:%p\n"
"\tfsize:%llu\n\tpointer:%p\n",
(void *)fpgasrc, (long long unsigned int)fsize, (void*)filefp));
if(fwrite((void*)fpgasrc , sizeof(char) , fsize , filefp )!= fsize){
FILE_LOG(logERROR, ("Could not write FPGA source to flash (size:%llu)\n", (long long unsigned int)fsize));
LOG(logERROR, ("Could not write FPGA source to flash (size:%llu)\n", (long long unsigned int)fsize));
return 1;
}
FILE_LOG(logDEBUG1, ("program written to flash\n"));
LOG(logDEBUG1, ("program written to flash\n"));
return 0;
}

View File

@ -14,7 +14,7 @@ char mtdvalue[MTDSIZE] = {0};
#define MICROCONTROLLER_FILE "/dev/ttyAL0"
void NotifyServerStartSuccess() {
FILE_LOG(logINFOBLUE, ("Server started successfully\n"));
LOG(logINFOBLUE, ("Server started successfully\n"));
char command[255];
memset(command, 0, 255);
sprintf(command,"echo r > %s",MICROCONTROLLER_FILE);
@ -26,17 +26,17 @@ void CreateNotificationForCriticalTasks() {
if (fd == NULL) {
fd = fopen(NOTIFICATION_FILE, "w");
if (fd == NULL) {
FILE_LOG(logERROR, ("Could not create notication file: %s\n", NOTIFICATION_FILE));
LOG(logERROR, ("Could not create notication file: %s\n", NOTIFICATION_FILE));
return;
}
FILE_LOG(logINFOBLUE, ("Created notification file: %s\n", NOTIFICATION_FILE));
LOG(logINFOBLUE, ("Created notification file: %s\n", NOTIFICATION_FILE));
}
fclose(fd);
NotifyCriticalTaskDone();
}
void NotifyCriticalTask() {
FILE_LOG(logINFO, ("\tNotifying Critical Task Ongoing\n"));
LOG(logINFO, ("\tNotifying Critical Task Ongoing\n"));
char command[255];
memset(command, 0, 255);
sprintf(command,"echo 1 > %s",NOTIFICATION_FILE);
@ -44,7 +44,7 @@ void NotifyCriticalTask() {
}
void NotifyCriticalTaskDone() {
FILE_LOG(logINFO, ("\tNotifying Critical Task Done\n"));
LOG(logINFO, ("\tNotifying Critical Task Done\n"));
char command[255];
memset(command, 0, 255);
sprintf(command,"echo 0 > %s",NOTIFICATION_FILE);
@ -52,7 +52,7 @@ void NotifyCriticalTaskDone() {
}
void rebootControllerAndFPGA() {
FILE_LOG(logDEBUG1, ("Reseting FPGA...\n"));
LOG(logDEBUG1, ("Reseting FPGA...\n"));
char command[255];
memset(command, 0, 255);
sprintf(command,"echo z > %s",MICROCONTROLLER_FILE);
@ -60,7 +60,7 @@ void rebootControllerAndFPGA() {
}
int findFlash(char* mess) {
FILE_LOG(logDEBUG1, ("Finding flash drive...\n"));
LOG(logDEBUG1, ("Finding flash drive...\n"));
//getting the drive
// # cat /proc/mtd
// dev: size erasesize name
@ -75,12 +75,12 @@ int findFlash(char* mess) {
FILE* fp = popen("awk \'$5== \"Application\" {print $1}\' /proc/mtd", "r");
if (fp == NULL) {
strcpy(mess, "popen returned NULL. Need that to get mtd drive.\n");
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
return RO_TRIGGER_IN_FALLING_EDGE;
}
if (fgets(output, sizeof(output), fp) == NULL) {
strcpy(mess, "fgets returned NULL. Need that to get mtd drive.\n");
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
return FAIL;
}
pclose(fp);
@ -89,21 +89,21 @@ int findFlash(char* mess) {
char* pch = strtok(output, ":");
if (pch == NULL){
strcpy (mess, "Could not get mtd value\n");
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
return FAIL;
}
strcat(mtdvalue, pch);
FILE_LOG(logINFO, ("\tFlash drive found: %s\n", mtdvalue));
LOG(logINFO, ("\tFlash drive found: %s\n", mtdvalue));
return OK;
}
void eraseFlash() {
FILE_LOG(logDEBUG1, ("Erasing Flash...\n"));
LOG(logDEBUG1, ("Erasing Flash...\n"));
char command[255];
memset(command, 0, 255);
sprintf(command,"flash_erase %s 0 0",mtdvalue);
system(command);
FILE_LOG(logINFO, ("\tFlash erased\n"));
LOG(logINFO, ("\tFlash erased\n"));
}
int eraseAndWriteToFlash(char* mess, char* fpgasrc, uint64_t fsize) {
@ -118,10 +118,10 @@ int eraseAndWriteToFlash(char* mess, char* fpgasrc, uint64_t fsize) {
if(filefp == NULL){
NotifyCriticalTaskDone();
sprintf (mess, "Unable to open %s in write mode\n", mtdvalue);
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
return FAIL;
}
FILE_LOG(logINFO, ("\tFlash ready for writing\n"));
LOG(logINFO, ("\tFlash ready for writing\n"));
// write to flash
if (writeFPGAProgram(mess, fpgasrc, fsize, filefp) == FAIL) {
@ -136,7 +136,7 @@ int eraseAndWriteToFlash(char* mess, char* fpgasrc, uint64_t fsize) {
}
int writeFPGAProgram(char* mess, char* fpgasrc, uint64_t fsize, FILE* filefp) {
FILE_LOG(logDEBUG1, ("Writing to flash...\n"
LOG(logDEBUG1, ("Writing to flash...\n"
"\taddress of fpgasrc:%p\n"
"\tfsize:%lu\n\tpointer:%p\n",
(void *)fpgasrc, fsize, (void*)filefp));
@ -144,9 +144,9 @@ int writeFPGAProgram(char* mess, char* fpgasrc, uint64_t fsize, FILE* filefp) {
uint64_t retval = fwrite((void*)fpgasrc , sizeof(char) , fsize , filefp);
if (retval != fsize) {
sprintf (mess, "Could not write FPGA source to flash (size:%llu), write %llu\n", (long long unsigned int) fsize, (long long unsigned int)retval);
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
return FAIL;
}
FILE_LOG(logINFO, ("\tProgram written to flash\n"));
LOG(logINFO, ("\tProgram written to flash\n"));
return OK;
}

View File

@ -26,10 +26,10 @@ int loadDefaultPattern(char* fname) {
if(fd == NULL) {
sprintf(initErrorMessage, "Could not open pattern file [%s].\n", fname);
initError = FAIL;
FILE_LOG(logERROR, ("%s\n\n", initErrorMessage));
LOG(logERROR, ("%s\n\n", initErrorMessage));
return FAIL;
}
FILE_LOG(logINFOBLUE, ("Reading default pattern file %s\n", fname));
LOG(logINFOBLUE, ("Reading default pattern file %s\n", fname));
// Initialization
@ -43,17 +43,17 @@ int loadDefaultPattern(char* fname) {
// ignore comments
if (line[0] == '#') {
FILE_LOG(logDEBUG1, ("Ignoring Comment\n"));
LOG(logDEBUG1, ("Ignoring Comment\n"));
continue;
}
// ignore empty lines
if (strlen(line) <= 1) {
FILE_LOG(logDEBUG1, ("Ignoring Empty line\n"));
LOG(logDEBUG1, ("Ignoring Empty line\n"));
continue;
}
FILE_LOG(logDEBUG1, ("Command to process: (size:%d) %.*s\n",
LOG(logDEBUG1, ("Command to process: (size:%d) %.*s\n",
strlen(line), strlen(line) -1, line));
memset(command, 0, LZ);
@ -259,9 +259,9 @@ int loadDefaultPattern(char* fname) {
if (strlen(initErrorMessage)) {
initError = FAIL;
FILE_LOG(logERROR, ("%s\n\n", initErrorMessage));
LOG(logERROR, ("%s\n\n", initErrorMessage));
} else {
FILE_LOG(logINFOBLUE, ("Successfully read default pattern file\n"));
LOG(logINFOBLUE, ("Successfully read default pattern file\n"));
}
return initError;
}

View File

@ -46,7 +46,7 @@ int main(int argc, char *argv[]){
#elif MOENCHD
version = APIMOENCH;
#endif
FILE_LOG(logINFO, ("SLS Detector Server %s (0x%x)\n", GITBRANCH, version));
LOG(logINFO, ("SLS Detector Server %s (0x%x)\n", GITBRANCH, version));
}
int portno = DEFAULT_PORTNO;
@ -62,39 +62,39 @@ int main(int argc, char *argv[]){
int i;
for (i = 1; i < argc; ++i) {
if(!strcasecmp(argv[i],"-stopserver")) {
FILE_LOG(logINFO, ("Detected stop server\n"));
LOG(logINFO, ("Detected stop server\n"));
isControlServer = 0;
}
else if(!strcasecmp(argv[i],"-devel")){
FILE_LOG(logINFO, ("Detected developer mode\n"));
LOG(logINFO, ("Detected developer mode\n"));
debugflag = 1;
}
else if(!strcasecmp(argv[i],"-nomodule")){
FILE_LOG(logINFO, ("Detected No Module mode\n"));
LOG(logINFO, ("Detected No Module mode\n"));
checkModuleFlag = 0;
}
else if(!strcasecmp(argv[i],"-port")){
if ((i + 1) >= argc) {
FILE_LOG(logERROR, ("no port value given. Exiting.\n"));
LOG(logERROR, ("no port value given. Exiting.\n"));
return -1;
}
if (sscanf(argv[i + 1], "%d", &portno) == 0) {
FILE_LOG(logERROR, ("cannot decode port value %s. Exiting.\n", argv[i + 1]));
LOG(logERROR, ("cannot decode port value %s. Exiting.\n", argv[i + 1]));
return -1;
}
FILE_LOG(logINFO, ("Detected port: %d\n", portno));
LOG(logINFO, ("Detected port: %d\n", portno));
}
#ifdef GOTTHARDD
else if(!strcasecmp(argv[i],"-phaseshift")){
if ((i + 1) >= argc) {
FILE_LOG(logERROR, ("no phase shift value given. Exiting.\n"));
LOG(logERROR, ("no phase shift value given. Exiting.\n"));
return -1;
}
if (sscanf(argv[i + 1], "%d", &phaseShift) == 0) {
FILE_LOG(logERROR, ("cannot decode phase shift value %s. Exiting.\n", argv[i + 1]));
LOG(logERROR, ("cannot decode phase shift value %s. Exiting.\n", argv[i + 1]));
return -1;
}
FILE_LOG(logINFO, ("Detected phase shift of %d\n", phaseShift));
LOG(logINFO, ("Detected phase shift of %d\n", phaseShift));
}
#endif
}
@ -105,19 +105,19 @@ int main(int argc, char *argv[]){
memset(cmd, 0, 100);
#endif
if (isControlServer) {
FILE_LOG(logINFO, ("Opening control server on port %d \n", portno));
LOG(logINFO, ("Opening control server on port %d \n", portno));
#ifdef STOP_SERVER
{
int i;
for (i = 0; i < argc; ++i)
sprintf(cmd, "%s %s", cmd, argv[i]);
sprintf(cmd,"%s -stopserver -port %d &", cmd, portno + 1);
FILE_LOG(logDEBUG1, ("Command to start stop server:%s\n", cmd));
LOG(logDEBUG1, ("Command to start stop server:%s\n", cmd));
system(cmd);
}
#endif
} else {
FILE_LOG(logINFO,("Opening stop server on port %d \n", portno));
LOG(logINFO,("Opening stop server on port %d \n", portno));
}
init_detector();
@ -132,9 +132,9 @@ int main(int argc, char *argv[]){
function_table();
if (isControlServer) {
FILE_LOG(logINFOBLUE, ("Control Server Ready...\n\n"));
LOG(logINFOBLUE, ("Control Server Ready...\n\n"));
} else {
FILE_LOG(logINFO, ("Stop Server Ready...\n\n"));
LOG(logINFO, ("Stop Server Ready...\n\n"));
}
// waits for connection
@ -149,7 +149,7 @@ int main(int argc, char *argv[]){
exitServer(sockfd);
if (retval == REBOOT) {
FILE_LOG(logINFORED,("Rebooting!\n"));
LOG(logINFORED,("Rebooting!\n"));
fflush(stdout);
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
rebootNiosControllerAndFPGA();
@ -157,6 +157,6 @@ int main(int argc, char *argv[]){
system("reboot");
#endif
}
FILE_LOG(logINFO,("Goodbye!\n"));
LOG(logINFO,("Goodbye!\n"));
return 0;
}