injectchannel WIP

This commit is contained in:
2019-11-13 15:11:11 +01:00
parent 5ee3f5cf4c
commit 28a5aa8342
13 changed files with 185 additions and 4 deletions

View File

@ -41,6 +41,8 @@ int dacValues[NDAC] = {0};
int onChipdacValues[ONCHIP_NDAC][NCHIP] = {0};
int defaultDacValues[NDAC] = {0};
int defaultOnChipdacValues[ONCHIP_NDAC][NCHIP] = {0};
int injectedChannelsOffset = 0;
int injectedChannelsIncrement = 0;
int detPos[2] = {0, 0};
int isInitCheckDone() {
@ -649,6 +651,7 @@ int setOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex, int val) {
FILE_LOG(logINFO, ("Setting on chip dac[%d - %s]: 0x%x\n", (int)ind, names[ind], val));
char buffer[2];
memset(buffer, 0, sizeof(buffer));
buffer[1] = ((val & 0xF) << 4) | (((int)ind) & 0xF); // LSB (4 bits) + ADDR (4 bits)
buffer[0] = (val >> 4) & 0x3F; // MSB (6 bits)
@ -1057,6 +1060,43 @@ int getClockDivider(enum CLKINDEX ind) {
return (getVCOFrequency(ind) / clkFrequency[ind]);
}
int setInjectChannel(int offset, int increment) {
if (offset < 0 || increment < 1) {
FILE_LOG(logERROR, ("Cannot inject channel. Invalid offset %d or increment %d\n", offset, increment));
return FAIL;
}
FILE_LOG(logINFO, ("Injecting channels [offset:%d, increment:%d]\n", offset, increment));
// 4 bits of padding + 128 bits + 4 bits for address = 136 bits
char buffer[17];
memset(buffer, 0, sizeof(buffer));
int startCh = 4; // 4 due to padding
int ich = 0;
for (ich = startCh + offset; ich < startCh + NCHAN; ich = ich + increment) {
buffer[ich] = 1;
}
for (ich = 0; ich < sizeof(buffer); ++ich) {
printf("%d : 0x%02hhx\n", ich, buffer[ich]);
}
//int chipIndex = -1; // for all chips
//if (ASIC_Driver_Set(chipIndex, sizeof(buffer), buffer) == FAIL) {
// return FAIL;
//}
injectedChannelsOffset = offset;
injectedChannelsIncrement = increment;
return OK;
}
void getInjectedChannels(int* offset, int* increment) {
*offset = injectedChannelsOffset;
*increment = injectedChannelsIncrement;
}
/* aquisition */

View File

@ -448,6 +448,8 @@ int getVCOFrequency(enum CLKINDEX ind);
int getMaxClockDivider();
int setClockDivider(enum CLKINDEX ind, int val);
int getClockDivider(enum CLKINDEX ind);
int setInjectChannel(int offset, int increment);
void getInjectedChannels(int* offset, int* increment);
#endif

View File

@ -194,4 +194,6 @@ int get_clock_divider(int);
int set_pipeline(int);
int get_pipeline(int);
int set_on_chip_dac(int);
int get_on_chip_dac(int);
int get_on_chip_dac(int);
int set_inject_channel(int);
int get_inject_channel(int);

View File

@ -296,6 +296,8 @@ const char* getFunctionName(enum detFuncs func) {
case F_GET_PIPELINE: return "F_GET_PIPELINE";
case F_SET_ON_CHIP_DAC: return "F_SET_ON_CHIP_DAC";
case F_GET_ON_CHIP_DAC: return "F_GET_ON_CHIP_DAC";
case F_SET_INJECT_CHANNEL: return "F_SET_INJECT_CHANNEL";
case F_GET_INJECT_CHANNEL: return "F_GET_INJECT_CHANNEL";
default: return "Unknown Function";
}
@ -469,6 +471,8 @@ void function_table() {
flist[F_GET_PIPELINE] = &get_pipeline;
flist[F_SET_ON_CHIP_DAC] = &set_on_chip_dac;
flist[F_GET_ON_CHIP_DAC] = &get_on_chip_dac;
flist[F_SET_INJECT_CHANNEL] = &set_inject_channel;
flist[F_GET_INJECT_CHANNEL] = &get_inject_channel;
// check
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
@ -6145,4 +6149,60 @@ int get_on_chip_dac(int file_des) {
}
#endif
return Server_SendResult(file_des, INT32, UPDATE, &retval, sizeof(retval));
}
}
int set_inject_channel(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int args[2] = {-1, -1};
if (receiveData(file_des, args, sizeof(args), INT32) < 0)
return printSocketReadError();
FILE_LOG(logINFO, ("Setting inject channel: [%d, %d]\n", args[0], args[1]));
#ifndef GOTTHARD2D
functionNotImplemented();
#else
// only set
if (Server_VerifyLock() == OK) {
int offset = args[0];
int increment = args[1];
if (offset < 0 || increment < 1) {
ret = FAIL;
sprintf(mess, "Could not inject channel. Invalid offset %d or increment %d\n", offset, increment);
FILE_LOG(logERROR, (mess));
} else {
ret = setInjectChannel(offset, increment);
if (ret == FAIL) {
ret = FAIL;
sprintf(mess, "Could not inject channel\n", offset, increment);
FILE_LOG(logERROR, (mess));
}
}
}
#endif
return Server_SendResult(file_des, INT32, UPDATE, NULL, 0);
}
int get_inject_channel(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int retvals[2] = {-1, -1};
FILE_LOG(logDEBUG1, ("Getting injected channels\n"));
#ifndef GOTTHARD2D
functionNotImplemented();
#else
// get only
int offset = -1, increment = -1;
getInjectedChannels(&offset, &increment);
FILE_LOG(logDEBUG1, ("Get Injected channels: [offset:%d, increment:%d]\n", offset, increment));
retvals[0] = offset;
retvals[1] = increment;
#endif
return Server_SendResult(file_des, INT32, UPDATE, retvals, sizeof(retvals));
}