ctb server: added adcvpp option to get and in mv

This commit is contained in:
maliakal_d 2019-05-14 18:38:30 +02:00
parent 45ae8a41ab
commit f90d8c6aff
6 changed files with 92 additions and 19 deletions

View File

@ -1,6 +1,6 @@
CROSS = bfin-uclinux-
CC = $(CROSS)gcc
CFLAGS += -Wall -DCHIPTESTBOARDD -DSTOP_SERVER -DDEBUG1 #-DJCTB -DVERBOSEI #-DVERBOSE
CFLAGS += -Wall -DCHIPTESTBOARDD -DSTOP_SERVER #-DDEBUG1 #-DJCTB -DVERBOSEI #-DVERBOSE
LDLIBS += -lm -lstdc++
PROGS = ctbDetectorServer

View File

@ -119,6 +119,7 @@
#define AD9257_VREF_REG (0x18)
#define AD9257_VREF_OFST (0)
#define AD9257_VREF_MSK (0x00000007 << AD9257_VREF_OFST)
#define AD9257_VREF_DEFAULT_VAL (AD9257_VREF_2_0_VAL)
#define AD9257_VREF_1_0_VAL ((0x0 << AD9257_VREF_OFST) & AD9257_VREF_MSK)
#define AD9257_VREF_1_14_VAL ((0x1 << AD9257_VREF_OFST) & AD9257_VREF_MSK)
#define AD9257_VREF_1_33_VAL ((0x2 << AD9257_VREF_OFST) & AD9257_VREF_MSK)
@ -130,6 +131,7 @@ uint32_t AD9257_CsMask = 0x0;
uint32_t AD9257_ClkMask = 0x0;
uint32_t AD9257_DigMask = 0x0;
int AD9257_DigOffset = 0x0;
int AD9257_VrefVoltage = 0;
/**
* Set Defines
@ -158,19 +160,84 @@ void AD9257_Disable() {
}
/**
* Get max valid vref value
* @param get max vref voltage unit (4 for 2.0V)
* Get vref voltage
*/
int AD9257_GetMaxValidVref() {
return 0x4;
int AD9257_GetVrefVoltage(int mV) {
if (mV == 0)
return AD9257_VrefVoltage;
switch(AD9257_VrefVoltage) {
case 0:
return 1000;
case 1:
return 1140;
case 2:
return 1330;
case 3:
return 1600;
case 4:
return 2000;
default:
FILE_LOG(logERROR, ("Could not convert Adc Vpp from mode to mV\n"));
return -1;
}
}
/**
* 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
*/
void AD9257_SetVrefVoltage(int val) {
AD9257_Set(AD9257_VREF_REG, val);
int AD9257_SetVrefVoltage(int val, int mV) {
int mode = val;
// convert to mode
if (mV) {
switch(val) {
case 1000:
mode = 0;
break;
case 1140:
mode = 1;
break;
case 1330:
mode = 2;
break;
case 1600:
mode = 3;
break;
case 2000:
mode = 4;
break;
// validation for mV
default:
FILE_LOG(logERROR, ("mv:%d doesnt exist\n", val));
return FAIL;
}
}
// validation for mode
switch(mode) {
case 0:
FILE_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));
break;
case 2:
FILE_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));
break;
case 4:
FILE_LOG(logINFO, ("Setting ADC Vref to 2.0 V (Mode:%d)\n", mode));
break;
default:
return FAIL;
}
// set vref voltage
AD9257_Set(AD9257_VREF_REG, mode);
AD9257_VrefVoltage = mode;
return OK;
}
/**
@ -244,4 +311,7 @@ void AD9257_Configure(){
AD9257_Set(AD9257_TEST_MODE_REG, AD9257_TST_MXD_BT_FRQ_VAL);
#endif
// set default value again (to remember the value set)
AD9257_SetVrefVoltage(AD9257_VREF_DEFAULT_VAL, 0);
}

View File

@ -166,8 +166,8 @@ extern void AD9252_Set(int addr, int val); // AD9252.h (old board)
extern void AD9257_Set(int addr, int val); // AD9257.h
#endif
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
extern int AD9257_GetMaxValidVref(); // AD9257.h
extern void AD9257_SetVrefVoltage(int val); // AD9257.h
extern int AD9257_GetVrefVoltage(int mV); // AD9257.h
extern int AD9257_SetVrefVoltage(int val, int mV); // AD9257.h
#endif
void setDAC(enum DACINDEX ind, int val, int mV);

View File

@ -333,7 +333,7 @@ void function_table() {
int iloop = 0;
for (iloop = 0; iloop < NUM_DET_FUNCTIONS ; ++iloop) {
FILE_LOG(logDEBUG1, ("function fnum=%d, (%s)\n", iloop,
FILE_LOG(logDEBUG3, ("function fnum=%d, (%s)\n", iloop,
getFunctionName((enum detFuncs)iloop)));
}
}
@ -793,14 +793,17 @@ int set_dac(int file_des) {
// adc vpp
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
case ADC_VPP:
if (val < 0 || val > AD9257_GetMaxValidVref()) {
ret = FAIL;
sprintf(mess,"Could not set dac. Adc Vpp value should be between 0 and %d\n", AD9257_GetMaxValidVref());
FILE_LOG(logERROR,(mess));
} else {
AD9257_SetVrefVoltage(val);
retval = val; // cannot read
}
// set
if (val >= 0) {
ret = AD9257_SetVrefVoltage(val, mV);
if (ret == FAIL) {
sprintf(mess,"Could not set Adc Vpp. Please set a proper value\n");
FILE_LOG(logERROR,(mess));
}
}
retval = AD9257_GetVrefVoltage(mV);
FILE_LOG(logDEBUG1, ("Adc Vpp retval: %d %s\n", retval, (mV ? "mV" : "mode")));
// cannot validate (its just a variable and mv gives different value)
break;
#endif

View File

@ -6,5 +6,5 @@
#define APILIB 0x190405
#define APIRECEIVER 0x190405
#define APIGUI 0x190405
#define APICTB 0x190514
#define APIEIGER 0x190514
#define APICTB 0x190514