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

@ -25,13 +25,13 @@ int i2c_open(const char* file,unsigned int addr){
//device file
int fd = open( file, O_RDWR );
if (fd < 0) {
FILE_LOG(logERROR, ("Warning: Unable to open file %s\n",file));
LOG(logERROR, ("Warning: Unable to open file %s\n",file));
return -1;
}
//device address
if( ioctl( fd, I2C_SLAVE, addr&0x7F ) < 0 ) {
FILE_LOG(logERROR, ("Warning: Unable to set slave address:0x%x \n",addr));
LOG(logERROR, ("Warning: Unable to set slave address:0x%x \n",addr));
return -2;
}
return fd;
@ -45,17 +45,17 @@ int i2c_read(){
unsigned char buf = reg;
if (write(fd, &buf, 1)!= 1){
FILE_LOG(logERROR, ("Warning: Unable to write read request to register %d\n", reg));
LOG(logERROR, ("Warning: Unable to write read request to register %d\n", reg));
return -1;
}
//read and update value (but old value read out)
if(read(fd, &buf, 1) != 1){
FILE_LOG(logERROR, ("Warning: Unable to read register %d\n", reg));
LOG(logERROR, ("Warning: Unable to read register %d\n", reg));
return -2;
}
//read again to read the updated value
if(read(fd, &buf, 1) != 1){
FILE_LOG(logERROR, ("Warning: Unable to read register %d\n", reg));
LOG(logERROR, ("Warning: Unable to read register %d\n", reg));
return -2;
}
close(fd);
@ -76,7 +76,7 @@ int i2c_write(unsigned int value){
buf[0] = reg;
buf[1] = val;
if (write(fd, buf, 2) != 2) {
FILE_LOG(logERROR, ("Warning: Unable to write %d to register %d\n",val, reg));
LOG(logERROR, ("Warning: Unable to write %d to register %d\n",val, reg));
return -1;
}
@ -92,10 +92,10 @@ int main(int argc, char* argv[]) {
int fd = open(PORTNAME, O_RDWR | O_NOCTTY | O_SYNC);
if(fd < 0){
FILE_LOG(logERROR, ("Warning: Unable to open port %s\n", PORTNAME));
LOG(logERROR, ("Warning: Unable to open port %s\n", PORTNAME));
return -1;
}
FILE_LOG(logINFO, ("opened port at %s\n",PORTNAME));
LOG(logINFO, ("opened port at %s\n",PORTNAME));
struct termios serial_conf;
// reset structure
@ -110,17 +110,17 @@ int main(int argc, char* argv[]) {
serial_conf.c_lflag = ICANON;
// flush input
if(tcflush(fd, TCIOFLUSH) < 0){
FILE_LOG(logERROR, ("Warning: error form tcflush %d\n", errno));
LOG(logERROR, ("Warning: error form tcflush %d\n", errno));
return 0;
}
// set new options for the port, TCSANOW:changes occur immediately without waiting for data to complete
if(tcsetattr(fd, TCSANOW, &serial_conf) < 0){
FILE_LOG(logERROR, ("Warning: error form tcsetattr %d\n", errno));
LOG(logERROR, ("Warning: error form tcsetattr %d\n", errno));
return 0;
}
if(tcsetattr(fd, TCSAFLUSH, &serial_conf) < 0){
FILE_LOG(logERROR, ("Warning: error form tcsetattr %d\n", errno));
LOG(logERROR, ("Warning: error form tcsetattr %d\n", errno));
return 0;
}
@ -130,25 +130,25 @@ int main(int argc, char* argv[]) {
char buffer[BUFFERSIZE];
memset(buffer,0,BUFFERSIZE);
buffer[BUFFERSIZE-1] = '\n';
FILE_LOG(logINFO, ("Ready...\n"));
LOG(logINFO, ("Ready...\n"));
while(ret != GOODBYE){
memset(buffer,0,BUFFERSIZE);
n = read(fd,buffer,BUFFERSIZE);
FILE_LOG(logDEBUG1, ("Received %d Bytes\n", n));
FILE_LOG(logINFO, ("Got message: '%s'\n",buffer));
LOG(logDEBUG1, ("Received %d Bytes\n", n));
LOG(logINFO, ("Got message: '%s'\n",buffer));
switch(buffer[0]){
case '\0':
FILE_LOG(logINFO, ("Got Start (Detector restart)\n"));
LOG(logINFO, ("Got Start (Detector restart)\n"));
break;
case 's':
FILE_LOG(logINFO, ("Got Start \n"));
LOG(logINFO, ("Got Start \n"));
break;
case 'p':
if (!sscanf(&buffer[1],"%d",&ival)){
FILE_LOG(logERROR, ("Warning: cannot scan voltage value\n"));
LOG(logERROR, ("Warning: cannot scan voltage value\n"));
break;
}
// ok/ fail
@ -158,9 +158,9 @@ int main(int argc, char* argv[]) {
strcpy(buffer,"fail ");
else
strcpy(buffer,"success ");
FILE_LOG(logINFO, ("Sending: '%s'\n",buffer));
LOG(logINFO, ("Sending: '%s'\n",buffer));
n = write(fd, buffer, BUFFERSIZE);
FILE_LOG(logDEBUG1, ("Sent %d Bytes\n", n));
LOG(logDEBUG1, ("Sent %d Bytes\n", n));
break;
case 'g':
@ -173,17 +173,17 @@ int main(int argc, char* argv[]) {
else
strcpy(buffer,"success ");
n = write(fd, buffer, BUFFERSIZE);
FILE_LOG(logINFO, ("Sending: '%s'\n",buffer));
FILE_LOG(logDEBUG1, ("Sent %d Bytes\n", n));
LOG(logINFO, ("Sending: '%s'\n",buffer));
LOG(logDEBUG1, ("Sent %d Bytes\n", n));
//value
memset(buffer,0,BUFFERSIZE);
buffer[BUFFERSIZE-1] = '\n';
if(ival >= 0){
FILE_LOG(logINFO, ("Sending: '%d'\n",ival));
LOG(logINFO, ("Sending: '%d'\n",ival));
sprintf(buffer,"%d ",ival);
n = write(fd, buffer, BUFFERSIZE);
FILE_LOG(logINFO, ("Sent %d Bytes\n", n));
}else FILE_LOG(logERROR, ("%s\n",buffer));
LOG(logINFO, ("Sent %d Bytes\n", n));
}else LOG(logERROR, ("%s\n",buffer));
break;
case 'e':
@ -191,7 +191,7 @@ int main(int argc, char* argv[]) {
ret = GOODBYE;
break;
default:
FILE_LOG(logERROR, ("Unknown Command. buffer:'%s'\n",buffer));
LOG(logERROR, ("Unknown Command. buffer:'%s'\n",buffer));
break;
}
}

View File

@ -77,7 +77,7 @@ unsigned int BebInfo_GetSrcPort(struct BebInfo* bebInfo, int ten_gig) {return te
void BebInfo_Print(struct BebInfo* bebInfo) {
FILE_LOG(logINFO, (
LOG(logINFO, (
"%d) Beb Info:\n"
"\tSerial Add: 0x%x\n"
"\tMAC 1GbE: %s\n"
@ -133,7 +133,7 @@ void Beb_Beb(int id) {
if (!Beb_InitBebInfos()) exit(1);
FILE_LOG(logDEBUG1, ("Printing Beb infos:\n"));
LOG(logDEBUG1, ("Printing Beb infos:\n"));
unsigned int i;
for(i=1;i<bebInfoSize;i++) BebInfo_Print(&beb_infos[i]);
@ -157,12 +157,12 @@ void Beb_GetModuleConfiguration(int* master, int* top, int* normal) {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Module Configuration FAIL\n"));
LOG(logERROR, ("Module Configuration FAIL\n"));
} else {
//read data
ret = Beb_Read32(csp0base, MODULE_CONFIGURATION_MASK);
FILE_LOG(logDEBUG1, ("Module Configuration OK\n"));
FILE_LOG(logDEBUG1, ("Beb: value =0x%x\n",ret));
LOG(logDEBUG1, ("Module Configuration OK\n"));
LOG(logDEBUG1, ("Beb: value =0x%x\n",ret));
if (ret&TOP_BIT_MASK) {
*top = 1;
Beb_top = 1;
@ -215,7 +215,7 @@ void Beb_EndofDataSend(int tengiga) {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_COUNTER_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Delay read counter fail\n"));
LOG(logERROR, ("Delay read counter fail\n"));
return;
} else {
//read data first time
@ -227,7 +227,7 @@ void Beb_EndofDataSend(int tengiga) {
r_framepktMsbcounter = Beb_Read32(csp0base, addr_r_framepktMsbcounter);
r_txndelaycounter = Beb_Read32(csp0base, addr_r_txndelaycounter);
r_framedelaycounter = Beb_Read32(csp0base, addr_r_framedelaycounter);
FILE_LOG(logDEBUG1, ("\nLeft\n"
LOG(logDEBUG1, ("\nLeft\n"
"FramepacketLsbcounter: %d\n"
"FramepacketMsbcounter: %d\n"
"Txndelaycounter:%d\n"
@ -245,7 +245,7 @@ void Beb_EndofDataSend(int tengiga) {
while(1) {
maxtimer = MAX(MAX(l_txndelaycounter,l_framedelaycounter),MAX(r_txndelaycounter,r_framedelaycounter));
maxtimer /= 100;
FILE_LOG(logDEBUG1, ("Will wait for %d us\n",maxtimer));
LOG(logDEBUG1, ("Will wait for %d us\n",maxtimer));
usleep(maxtimer);
//read new values
@ -257,7 +257,7 @@ void Beb_EndofDataSend(int tengiga) {
r_framepktMsbcounter_new = Beb_Read32(csp0base, addr_r_framepktMsbcounter);
r_txndelaycounter_new = Beb_Read32(csp0base, addr_r_txndelaycounter);
r_framedelaycounter_new = Beb_Read32(csp0base, addr_r_framedelaycounter);
FILE_LOG(logDEBUG1, ("\nLeft\n"
LOG(logDEBUG1, ("\nLeft\n"
"FramepacketLsbcounter: %d\n"
"FramepacketMsbcounter: %d\n"
"Txndelaycounter:%d\n"
@ -288,7 +288,7 @@ void Beb_EndofDataSend(int tengiga) {
}
FILE_LOG(logINFO, ("Detector has sent all data\n"));
LOG(logINFO, ("Detector has sent all data\n"));
//close file pointer
Beb_close(fd,csp0base);
}
@ -310,14 +310,14 @@ int Beb_SetMasterViaSoftware() {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Set Master FAIL\n"));
LOG(logERROR, ("Set Master FAIL\n"));
} else {
value = Beb_Read32(csp0base, MASTERCONFIG_OFFSET);
value|=MASTER_BIT;
value|=OVERWRITE_HARDWARE_BIT;
int newval = Beb_Write32(csp0base, MASTERCONFIG_OFFSET,value);
if (newval!=value) {
FILE_LOG(logERROR, ("Could not set Master via Software\n"));
LOG(logERROR, ("Could not set Master via Software\n"));
} else {
ret = 0;
}
@ -343,14 +343,14 @@ int Beb_SetSlaveViaSoftware() {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Set Slave FAIL\n"));
LOG(logERROR, ("Set Slave FAIL\n"));
} else {
value = Beb_Read32(csp0base, MASTERCONFIG_OFFSET);
value&=~MASTER_BIT;
value|=OVERWRITE_HARDWARE_BIT;
int newval = Beb_Write32(csp0base, MASTERCONFIG_OFFSET,value);
if (newval!=value) {
FILE_LOG(logERROR, ("Could not set Slave via Software\n"));
LOG(logERROR, ("Could not set Slave via Software\n"));
} else {
ret = 0;
}
@ -371,11 +371,11 @@ int Beb_Activate(int enable) {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Deactivate FAIL\n"));
LOG(logERROR, ("Deactivate FAIL\n"));
} else {
if (enable > -1) {
value = Beb_Read32(csp0base, MASTERCONFIG_OFFSET);
FILE_LOG(logINFO, ("Deactivate register value before:%d\n",value));
LOG(logINFO, ("Deactivate register value before:%d\n",value));
if (enable)
value&=~DEACTIVATE_BIT;
else
@ -384,9 +384,9 @@ int Beb_Activate(int enable) {
int newval = Beb_Write32(csp0base, MASTERCONFIG_OFFSET,value);
if (newval!=value) {
if (enable) {
FILE_LOG(logERROR, ("Could not activate via Software\n"));
LOG(logERROR, ("Could not activate via Software\n"));
} else {
FILE_LOG(logERROR, ("Could not deactivate via Software\n"));
LOG(logERROR, ("Could not deactivate via Software\n"));
}
}
}
@ -396,9 +396,9 @@ int Beb_Activate(int enable) {
else ret = 1;
if (enable == -1) {
if (ret) {
FILE_LOG(logINFOBLUE, ("Detector is active. Register value:%d\n", value));
LOG(logINFOBLUE, ("Detector is active. Register value:%d\n", value));
} else {
FILE_LOG(logERROR, ("Detector is deactivated! Register value:%d\n", value));
LOG(logERROR, ("Detector is deactivated! Register value:%d\n", value));
}
}
@ -430,7 +430,7 @@ int Beb_Set32bitOverflow(int val) {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Could not read register to set overflow flag in 32 bit mode. FAIL\n"));
LOG(logERROR, ("Could not read register to set overflow flag in 32 bit mode. FAIL\n"));
return -1;
}
else {
@ -459,7 +459,7 @@ int Beb_GetTenGigaFlowControl() {
u_int32_t* csp0base = 0;
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) {
FILE_LOG(logERROR, ("Could not read register to get ten giga flow control. FAIL\n"));
LOG(logERROR, ("Could not read register to get ten giga flow control. FAIL\n"));
return -1;
} else {
u_int32_t retval = Beb_Read32(csp0base, offset);
@ -471,13 +471,13 @@ int Beb_GetTenGigaFlowControl() {
}
int Beb_SetTenGigaFlowControl(int value) {
FILE_LOG(logINFO, ("Setting ten giga flow control to %d\n", value));
LOG(logINFO, ("Setting ten giga flow control to %d\n", value));
value = value == 0 ? 0 : 1;
u_int32_t offset = FLOW_REG_OFFSET;
u_int32_t* csp0base = 0;
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) {
FILE_LOG(logERROR, ("Could not read register to set ten giga flow control. FAIL\n"));
LOG(logERROR, ("Could not read register to set ten giga flow control. FAIL\n"));
return 0;
} else {
// reset bit
@ -499,7 +499,7 @@ int Beb_GetTransmissionDelayFrame() {
u_int32_t* csp0base = 0;
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) {
FILE_LOG(logERROR, ("Could not read register to get transmission delay frame. FAIL\n"));
LOG(logERROR, ("Could not read register to get transmission delay frame. FAIL\n"));
return -1;
} else {
u_int32_t retval = Beb_Read32(csp0base, offset);
@ -509,16 +509,16 @@ int Beb_GetTransmissionDelayFrame() {
}
int Beb_SetTransmissionDelayFrame(int value) {
FILE_LOG(logINFO, ("Setting transmission delay frame to %d\n", value));
LOG(logINFO, ("Setting transmission delay frame to %d\n", value));
if (value < 0) {
FILE_LOG(logERROR, ("Invalid transmission delay frame value %d\n", value));
LOG(logERROR, ("Invalid transmission delay frame value %d\n", value));
return 0;
}
u_int32_t offset = TXM_DELAY_FRAME_OFFSET;
u_int32_t* csp0base = 0;
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) {
FILE_LOG(logERROR, ("Could not read register to set transmission delay frame. FAIL\n"));
LOG(logERROR, ("Could not read register to set transmission delay frame. FAIL\n"));
return 0;
} else {
Beb_Write32(csp0base, offset, value);
@ -532,7 +532,7 @@ int Beb_GetTransmissionDelayLeft() {
u_int32_t* csp0base = 0;
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) {
FILE_LOG(logERROR, ("Could not read register to get transmission delay left. FAIL\n"));
LOG(logERROR, ("Could not read register to get transmission delay left. FAIL\n"));
return -1;
} else {
u_int32_t retval = Beb_Read32(csp0base, offset);
@ -542,16 +542,16 @@ int Beb_GetTransmissionDelayLeft() {
}
int Beb_SetTransmissionDelayLeft(int value) {
FILE_LOG(logINFO, ("Setting transmission delay left to %d\n", value));
LOG(logINFO, ("Setting transmission delay left to %d\n", value));
if (value < 0) {
FILE_LOG(logERROR, ("Invalid transmission delay left value %d\n", value));
LOG(logERROR, ("Invalid transmission delay left value %d\n", value));
return 0;
}
u_int32_t offset = TXM_DELAY_LEFT_OFFSET;
u_int32_t* csp0base = 0;
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) {
FILE_LOG(logERROR, ("Could not read register to set transmission delay left. FAIL\n"));
LOG(logERROR, ("Could not read register to set transmission delay left. FAIL\n"));
return 0;
} else {
Beb_Write32(csp0base, offset, value);
@ -565,7 +565,7 @@ int Beb_GetTransmissionDelayRight() {
u_int32_t* csp0base = 0;
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) {
FILE_LOG(logERROR, ("Could not read register to get transmission delay right. FAIL\n"));
LOG(logERROR, ("Could not read register to get transmission delay right. FAIL\n"));
return -1;
} else {
u_int32_t retval = Beb_Read32(csp0base, offset);
@ -575,16 +575,16 @@ int Beb_GetTransmissionDelayRight() {
}
int Beb_SetTransmissionDelayRight(int value) {
FILE_LOG(logINFO, ("Setting transmission delay right to %d\n", value));
LOG(logINFO, ("Setting transmission delay right to %d\n", value));
if (value < 0) {
FILE_LOG(logERROR, ("Invalid transmission delay right value %d\n", value));
LOG(logERROR, ("Invalid transmission delay right value %d\n", value));
return 0;
}
u_int32_t offset = TXM_DELAY_RIGHT_OFFSET;
u_int32_t* csp0base = 0;
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) {
FILE_LOG(logERROR, ("Could not read register to set transmission delay right. FAIL\n"));
LOG(logERROR, ("Could not read register to set transmission delay right. FAIL\n"));
return 0;
} else {
Beb_Write32(csp0base, offset, value);
@ -617,12 +617,12 @@ int Beb_SetNetworkParameter(enum NETWORKINDEX mode, int val) {
break;
default: FILE_LOG(logERROR, ("Unrecognized mode in network parameter: %d\n",mode)); return -1;
default: LOG(logERROR, ("Unrecognized mode in network parameter: %d\n",mode)); return -1;
}
//open file pointer
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Could not read register to set network parameter. FAIL\n"));
LOG(logERROR, ("Could not read register to set network parameter. FAIL\n"));
return -1;
} else {
if (val > -1) {
@ -655,11 +655,11 @@ int Beb_ResetToHardwareSettings() {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Reset to Hardware Settings FAIL\n"));
LOG(logERROR, ("Reset to Hardware Settings FAIL\n"));
} else {
value = Beb_Write32(csp0base, MASTERCONFIG_OFFSET,0);
if (value) {
FILE_LOG(logERROR, ("Could not reset to hardware settings\n"));
LOG(logERROR, ("Could not reset to hardware settings\n"));
} else {
ret = 0;
}
@ -682,11 +682,11 @@ u_int32_t Beb_GetFirmwareRevision() {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_VERSION);
if (fd < 0) {
FILE_LOG(logERROR, ("Firmware Revision Read FAIL\n"));
LOG(logERROR, ("Firmware Revision Read FAIL\n"));
} else {
value = Beb_Read32(csp0base, FIRMWARE_VERSION_OFFSET);
if (!value) {
FILE_LOG(logERROR, ("Firmware Revision Number does not exist in this version\n"));
LOG(logERROR, ("Firmware Revision Number does not exist in this version\n"));
}
}
@ -706,11 +706,11 @@ u_int32_t Beb_GetFirmwareSoftwareAPIVersion() {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_VERSION);
if (fd < 0) {
FILE_LOG(logERROR, ("Firmware Software API Version Read FAIL\n"));
LOG(logERROR, ("Firmware Software API Version Read FAIL\n"));
} else {
value = Beb_Read32(csp0base, FIRMWARESOFTWARE_API_OFFSET);
if (!value) {
FILE_LOG(logERROR, ("Firmware Software API Version does not exist in this version\n"));
LOG(logERROR, ("Firmware Software API Version does not exist in this version\n"));
}
}
@ -731,14 +731,14 @@ void Beb_ResetFrameNumber() {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Reset Frame Number FAIL\n"));
LOG(logERROR, ("Reset Frame Number FAIL\n"));
} else {
//write a 1
Beb_Write32(csp0base, FRAME_NUM_RESET_OFFSET, 1);
usleep(100000); //100ms
//write a 0
Beb_Write32(csp0base, FRAME_NUM_RESET_OFFSET, 0);
FILE_LOG(logINFO, ("Frame Number Reset OK\n"));
LOG(logINFO, ("Frame Number Reset OK\n"));
//close file pointer
Beb_close(fd,csp0base);
}
@ -764,7 +764,7 @@ int Beb_InitBebInfos() {//file name at some point
int i0=Beb_detid,i1=0;
if (Beb_GetBebInfoIndex(i0)) {
FILE_LOG(logERROR, ("cant add beb. adding beb %d, beb number %d already added.\n",Beb_detid, i0));
LOG(logERROR, ("cant add beb. adding beb %d, beb number %d already added.\n",Beb_detid, i0));
exit(0);
}
struct BebInfo b1;
@ -798,7 +798,7 @@ int Beb_SetBebSrcHeaderInfos(unsigned int beb_number, int ten_gig, char* src_mac
/******* if (!i) return 0;****************************/ //i must be greater than 0, zero is the global send
BebInfo_SetHeaderInfo(&beb_infos[i],ten_gig,src_mac,src_ip,src_port);
FILE_LOG(logINFO, ("Printing Beb info number (%d) :\n",i));
LOG(logINFO, ("Printing Beb info number (%d) :\n",i));
BebInfo_Print(&beb_infos[i]);
return 1;
@ -813,7 +813,7 @@ int Beb_CheckSourceStuffBebInfo() {
if (!Beb_SetHeaderData(
BebInfo_GetBebNumber(&beb_infos[i]),0,"00:00:00:00:00:00","10.0.0.1",20000)||
!Beb_SetHeaderData(BebInfo_GetBebNumber(&beb_infos[i]),1,"00:00:00:00:00:00","10.0.0.1",20000)) {
FILE_LOG(logINFO, ("Error in BebInfo for module number %d.\n",BebInfo_GetBebNumber(&beb_infos[i])));
LOG(logINFO, ("Error in BebInfo for module number %d.\n",BebInfo_GetBebNumber(&beb_infos[i])));
BebInfo_Print(&beb_infos[i]);
return 0;
}
@ -826,10 +826,10 @@ unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb) {
unsigned int i;
for(i=1;i<bebInfoSize;i++)
if (beb_numb==BebInfo_GetBebNumber(&beb_infos[i])) {
FILE_LOG(logDEBUG1, ("*****found beb index:%d, for beb number:%d\n",i,beb_numb));
LOG(logDEBUG1, ("*****found beb index:%d, for beb number:%d\n",i,beb_numb));
return i;
}
FILE_LOG(logDEBUG1, ("*****Returning 0\n"));
LOG(logDEBUG1, ("*****Returning 0\n"));
return 0;
}
@ -841,7 +841,7 @@ int Beb_WriteTo(unsigned int index) {
return 1;
if (index>=bebInfoSize) {
FILE_LOG(logERROR, ("WriteTo index error.\n"));
LOG(logERROR, ("WriteTo index error.\n"));
return 0;
}
@ -886,7 +886,7 @@ int Beb_SetUpUDPHeader(unsigned int beb_number, int ten_gig, unsigned int header
int fd = Beb_open(&csp0base,bram_phy_addr);
if (fd < 0) {
FILE_LOG(logERROR, ("Set up UDP Header FAIL\n"));
LOG(logERROR, ("Set up UDP Header FAIL\n"));
} else {
//read data
memcpy(csp0base+header_number*16, &udp_header, sizeof(udp_header));
@ -932,18 +932,18 @@ int Beb_SetHeaderData1(char* src_mac, char* src_ip, unsigned int src_port, char*
*/
if (!Beb_SetMAC(src_mac,&(udp_header.src_mac[0]))) return 0;
FILE_LOG(logINFO, ("Setting Source MAC to %s\n",src_mac));
LOG(logINFO, ("Setting Source MAC to %s\n",src_mac));
if (!Beb_SetIP(src_ip,&(udp_header.src_ip[0]))) return 0;
FILE_LOG(logINFO, ("Setting Source IP to %s\n",src_ip));
LOG(logINFO, ("Setting Source IP to %s\n",src_ip));
if (!Beb_SetPortNumber(src_port,&(udp_header.src_port[0]))) return 0;
FILE_LOG(logINFO, ("Setting Source port to %d\n",src_port));
LOG(logINFO, ("Setting Source port to %d\n",src_port));
if (!Beb_SetMAC(dst_mac,&(udp_header.dst_mac[0]))) return 0;
FILE_LOG(logINFO, ("Setting Destination MAC to %s\n",dst_mac));
LOG(logINFO, ("Setting Destination MAC to %s\n",dst_mac));
if (!Beb_SetIP(dst_ip,&(udp_header.dst_ip[0]))) return 0;
FILE_LOG(logINFO, ("Setting Destination IP to %s\n",dst_ip));
LOG(logINFO, ("Setting Destination IP to %s\n",dst_ip));
if (!Beb_SetPortNumber(dst_port,&(udp_header.dst_port[0]))) return 0;
FILE_LOG(logINFO, ("Setting Destination port to %d\n",dst_port));
LOG(logINFO, ("Setting Destination port to %d\n",dst_port));
Beb_AdjustIPChecksum(&udp_header);
@ -968,7 +968,7 @@ int Beb_SetMAC(char* mac, uint8_t* dst_ptr) {
char *pch = strtok (macVal,":");
while (pch != NULL) {
if (strlen(pch)!=2) {
FILE_LOG(logERROR, ("Error: in mac address -> %s\n",macVal));
LOG(logERROR, ("Error: in mac address -> %s\n",macVal));
return 0;
}
@ -987,7 +987,7 @@ int Beb_SetIP(char* ip, uint8_t* dst_ptr) {
char *pch = strtok (ipVal,".");
while (pch != NULL) {
if (((i!=3) && ((strlen(pch)>3) || (strlen(pch)<1))) || ((i==3)&&((strlen(pch)<1) || (strlen(pch) > 3)))) {
FILE_LOG(logERROR, ("Error: in ip address -> %s\n",ipVal));
LOG(logERROR, ("Error: in ip address -> %s\n",ipVal));
return 0;
}
@ -1050,11 +1050,11 @@ int Beb_SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, i
Beb_send_data[1] = 0x62000000 | (!stop_read_when_fifo_empty) << 27 | (ten_gig==1) << 24 | packet_size << 14 | dst_number << 8 | npackets;
FILE_LOG(logDEBUG1, ("Beb_send_data[1]:%X\n",Beb_send_data[1]));
LOG(logDEBUG1, ("Beb_send_data[1]:%X\n",Beb_send_data[1]));
Beb_send_data[2] = 0;
Beb_SwapDataFun(0,2,&(Beb_send_data[1]));
FILE_LOG(logDEBUG1, ("Beb_send_data[1] Swapped:%X\n",Beb_send_data[1]));
LOG(logDEBUG1, ("Beb_send_data[1] Swapped:%X\n",Beb_send_data[1]));
if (Beb_activated) {
if (!Beb_WriteTo(i)) return 0;
@ -1085,7 +1085,7 @@ int Beb_StopAcquisition()
//open file pointer
int fd = Beb_open(&csp0base,XPAR_CMD_GENERATOR);
if (fd < 0) {
FILE_LOG(logERROR, ("Beb Stop Acquisition FAIL\n"));
LOG(logERROR, ("Beb Stop Acquisition FAIL\n"));
return 0;
} else {
//find value
@ -1098,7 +1098,7 @@ int Beb_StopAcquisition()
Beb_Write32(csp0base, (LEFT_OFFSET + STOP_ACQ_OFFSET),(valuel&(~STOP_ACQ_BIT)));
Beb_Write32(csp0base, (RIGHT_OFFSET + STOP_ACQ_OFFSET),(valuer&(~STOP_ACQ_BIT)));
FILE_LOG(logINFO, ("Beb Stop Acquisition OK\n"));
LOG(logINFO, ("Beb Stop Acquisition OK\n"));
//close file pointer
Beb_close(fd,csp0base);
}
@ -1116,7 +1116,7 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int dst_nu
unsigned int nl = Beb_readNLines;
unsigned int npackets = (nl * maxnp) / maxnl;
if ((nl * maxnp) % maxnl) {
FILE_LOG(logERROR, ("Read N Lines is incorrect. Switching to Full Image Readout\n"));
LOG(logERROR, ("Read N Lines is incorrect. Switching to Full Image Readout\n"));
npackets = maxnp;
}
int in_two_requests = (npackets > MAX_PACKETS_PER_REQUEST) ? 1 : 0;
@ -1126,8 +1126,8 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int dst_nu
unsigned int header_size = 4; //4*64 bits
unsigned int packet_size = ten_gig ? 0x200 : 0x80; // 4k or 1k packets
FILE_LOG(logDEBUG1, ("----Beb_RequestNImages Start----\n"));
FILE_LOG(logINFO, ("beb_number:%d, ten_gig:%d,dst_number:%d, npackets:%d, "
LOG(logDEBUG1, ("----Beb_RequestNImages Start----\n"));
LOG(logINFO, ("beb_number:%d, ten_gig:%d,dst_number:%d, npackets:%d, "
"Beb_bit_mode:%d, header_size:%d, nimages:%d, test_just_send_out_packets_no_wait:%d\n",
beb_number, ten_gig, dst_number, npackets, Beb_bit_mode, header_size,
nimages, test_just_send_out_packets_no_wait));
@ -1138,13 +1138,13 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int dst_nu
//open file pointer
int fd = Beb_open(&csp0base,XPAR_CMD_GENERATOR);
if (fd < 0) {
FILE_LOG(logERROR, ("Beb Request N Images FAIL\n"));
LOG(logERROR, ("Beb Request N Images FAIL\n"));
return 0;
} else {
{
int i;
for (i=0; i < 10; i++)
FILE_LOG(logDEBUG1, ("%X\n",Beb_Read32(csp0base, (LEFT_OFFSET + i*4))));
LOG(logDEBUG1, ("%X\n",Beb_Read32(csp0base, (LEFT_OFFSET + i*4))));
}
// Generating commands
u_int32_t send_header_command = 0x62000000 | (!test_just_send_out_packets_no_wait) << 27 | (ten_gig==1) << 24 | header_size << 14 | 0;
@ -1152,8 +1152,8 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int dst_nu
{
int i;
for (i=0; i < 10; i++)
FILE_LOG(logDEBUG1, ("%X\n",Beb_Read32(csp0base, (LEFT_OFFSET + i*4))));
FILE_LOG(logDEBUG1, ("%d\n",in_two_requests));
LOG(logDEBUG1, ("%X\n",Beb_Read32(csp0base, (LEFT_OFFSET + i*4))));
LOG(logDEBUG1, ("%d\n",in_two_requests));
}
//"0x20 << 8" is dst_number (0x00 for left, 0x20 for right)
//Left
@ -1181,12 +1181,12 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int dst_nu
{
int i;
for (i=0; i < 10; i++)
FILE_LOG(logDEBUG1, ("%X\n",Beb_Read32(csp0base, (LEFT_OFFSET + i*4)))); //*(ptrl+i));
FILE_LOG(logDEBUG1, ("%d\n",in_two_requests));
LOG(logDEBUG1, ("%X\n",Beb_Read32(csp0base, (LEFT_OFFSET + i*4)))); //*(ptrl+i));
LOG(logDEBUG1, ("%d\n",in_two_requests));
}
Beb_close(fd,csp0base);
FILE_LOG(logDEBUG1, ("----Beb_RequestNImages----\n"));
LOG(logDEBUG1, ("----Beb_RequestNImages----\n"));
}
return 1;
@ -1194,7 +1194,7 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int dst_nu
int Beb_Test(unsigned int beb_number) {
FILE_LOG(logINFO, ("Testing module number: %d\n",beb_number));
LOG(logINFO, ("Testing module number: %d\n",beb_number));
//int SetUpUDPHeader(unsigned int beb_number, int ten_gig, unsigned int header_number, string dst_mac, string dst_ip, unsigned int dst_port) {
@ -1202,14 +1202,14 @@ int Beb_Test(unsigned int beb_number) {
unsigned int index = Beb_GetBebInfoIndex(beb_number);
if (!index) {
FILE_LOG(logERROR, ("Error beb number (%d)not in list????\n",beb_number));
LOG(logERROR, ("Error beb number (%d)not in list????\n",beb_number));
return 0;
}
unsigned int i;
for(i=0;i<64;i++) {
if (!Beb_SetUpUDPHeader(beb_number,0,i,"60:fb:42:f4:e3:d2","129.129.205.186",22000+i)) {
FILE_LOG(logERROR, ("Error setting up header table....\n"));
LOG(logERROR, ("Error setting up header table....\n"));
return 0;
}
}
@ -1217,7 +1217,7 @@ int Beb_Test(unsigned int beb_number) {
// SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int npackets, unsigned int packet_size, int stop_read_when_fifo_empty=1);
for(i=0;i<64;i++) {
if (!Beb_SendMultiReadRequest(beb_number,i%3+1,0,i,1,0,1)) {
FILE_LOG(logERROR, ("Error requesting data....\n"));
LOG(logERROR, ("Error requesting data....\n"));
return 0;
}
}
@ -1237,7 +1237,7 @@ int Beb_GetBebFPGATemp()
//open file pointer
int fd = Beb_open(&csp0base,XPAR_SYSMON_0_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Module Configuration FAIL\n"));
LOG(logERROR, ("Module Configuration FAIL\n"));
} else {
//read data
ret = Beb_Read32(csp0base, FPGA_TEMP_OFFSET);
@ -1255,11 +1255,11 @@ void Beb_SetDetectorNumber(uint32_t detid) {
return;
uint32_t swapid = Beb_swap_uint16(detid);
//FILE_LOG(logINFO, "detector id %d swapped %d\n", detid, swapid));
//LOG(logINFO, "detector id %d swapped %d\n", detid, swapid));
u_int32_t* csp0base=0;
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_TEST_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Set Detector ID FAIL\n"));
LOG(logERROR, ("Set Detector ID FAIL\n"));
return;
} else {
uint32_t value = Beb_Read32(csp0base, UDP_HEADER_A_LEFT_OFST);
@ -1267,24 +1267,24 @@ void Beb_SetDetectorNumber(uint32_t detid) {
Beb_Write32(csp0base, UDP_HEADER_A_LEFT_OFST, value | ((swapid << UDP_HEADER_ID_OFST) & UDP_HEADER_ID_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_A_LEFT_OFST);
if ((value & UDP_HEADER_ID_MSK) != ((swapid << UDP_HEADER_ID_OFST) & UDP_HEADER_ID_MSK)) {
FILE_LOG(logERROR, ("Set Detector ID FAIL\n"));
LOG(logERROR, ("Set Detector ID FAIL\n"));
}
value = Beb_Read32(csp0base, UDP_HEADER_A_RIGHT_OFST);
value &= UDP_HEADER_X_MSK; // to keep previous x value
Beb_Write32(csp0base, UDP_HEADER_A_RIGHT_OFST, value | ((swapid << UDP_HEADER_ID_OFST) & UDP_HEADER_ID_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_A_RIGHT_OFST);
if ((value & UDP_HEADER_ID_MSK) != ((swapid << UDP_HEADER_ID_OFST) & UDP_HEADER_ID_MSK)) {
FILE_LOG(logERROR, ("Set Detector ID FAIL\n"));
LOG(logERROR, ("Set Detector ID FAIL\n"));
}
Beb_close(fd,csp0base);
}
FILE_LOG(logINFO, ("Detector id %d set in UDP Header\n\n", detid));
LOG(logINFO, ("Detector id %d set in UDP Header\n\n", detid));
}
int Beb_SetQuad(int value) {
if (value < 0)
return OK;
FILE_LOG(logINFO, ("Setting Quad to %d in Beb\n", value));
LOG(logINFO, ("Setting Quad to %d in Beb\n", value));
Beb_quadEnable = (value == 0 ? 0 : 1);
return Beb_SetDetectorPosition(Beb_positions);
}
@ -1300,7 +1300,7 @@ int* Beb_GetDetectorPosition() {
int Beb_SetDetectorPosition(int pos[]) {
if (!Beb_activated)
return OK;
FILE_LOG(logINFO, ("Got Position values %d %d...\n", pos[0],pos[1]));
LOG(logINFO, ("Got Position values %d %d...\n", pos[0],pos[1]));
// save positions
Beb_positions[0] = pos[0];
@ -1321,7 +1321,7 @@ int Beb_SetDetectorPosition(int pos[]) {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_TEST_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Set Detector Position FAIL\n"));
LOG(logERROR, ("Set Detector Position FAIL\n"));
return FAIL;
} else {
uint32_t value = 0;
@ -1333,7 +1333,7 @@ int Beb_SetDetectorPosition(int pos[]) {
Beb_Write32(csp0base, UDP_HEADER_A_LEFT_OFST, value | ((posval << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_A_LEFT_OFST);
if ((value & UDP_HEADER_X_MSK) != ((posval << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK)) {
FILE_LOG(logERROR, ("Could not set row position for left port\n"));
LOG(logERROR, ("Could not set row position for left port\n"));
ret = FAIL;
}
// x right
@ -1343,7 +1343,7 @@ int Beb_SetDetectorPosition(int pos[]) {
Beb_Write32(csp0base, UDP_HEADER_A_RIGHT_OFST, value | ((posval << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_A_RIGHT_OFST);
if ((value & UDP_HEADER_X_MSK) != ((posval << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK)) {
FILE_LOG(logERROR, ("Could not set row position for right port\n"));
LOG(logERROR, ("Could not set row position for right port\n"));
ret = FAIL;
}
@ -1356,7 +1356,7 @@ int Beb_SetDetectorPosition(int pos[]) {
Beb_Write32(csp0base, UDP_HEADER_B_LEFT_OFST, value | ((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_B_LEFT_OFST);
if ((value & UDP_HEADER_Y_MSK) != ((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK)) {
FILE_LOG(logERROR, ("Could not set column position for left port\n"));
LOG(logERROR, ("Could not set column position for left port\n"));
ret = FAIL;
}
@ -1367,7 +1367,7 @@ int Beb_SetDetectorPosition(int pos[]) {
Beb_Write32(csp0base, UDP_HEADER_B_RIGHT_OFST, value | ((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_B_RIGHT_OFST);
if ((value & UDP_HEADER_Y_MSK) != ((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK)) {
FILE_LOG(logERROR, ("Could not set column position for right port\n"));
LOG(logERROR, ("Could not set column position for right port\n"));
ret = FAIL;
}
@ -1376,7 +1376,7 @@ int Beb_SetDetectorPosition(int pos[]) {
Beb_close(fd,csp0base);
}
if (ret == OK) {
FILE_LOG(logINFO, ("Position set to...\n"
LOG(logINFO, ("Position set to...\n"
"\tLeft: [%d, %d]\n"
"\tRight:[%d, %d]\n",
posLeft[0], posLeft[1], posRight[0], posRight[1]));
@ -1390,12 +1390,12 @@ int Beb_SetStartingFrameNumber(uint64_t value) {
Beb_deactivatedStartFrameNumber = value;
return OK;
}
FILE_LOG(logINFO, ("Setting start frame number: %llu\n", (long long unsigned int)value));
LOG(logINFO, ("Setting start frame number: %llu\n", (long long unsigned int)value));
u_int32_t* csp0base = 0;
int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_TEST_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Set Start Frame Number FAIL\n"));
LOG(logERROR, ("Set Start Frame Number FAIL\n"));
return FAIL;
}
// since the read is not implemented in firmware yet
@ -1407,7 +1407,7 @@ int Beb_SetStartingFrameNumber(uint64_t value) {
Beb_Write32(csp0base, UDP_HEADER_FRAME_NUMBER_MSB_OFST, (valueInFirmware >> 32) & (0xffffffff));
Beb_close(fd,csp0base);
FILE_LOG(logINFO, ("Going to reset Frame Number\n"));
LOG(logINFO, ("Going to reset Frame Number\n"));
Beb_ResetFrameNumber();
return OK;
}
@ -1418,11 +1418,11 @@ int Beb_GetStartingFrameNumber(uint64_t* retval, int tengigaEnable) {
return OK;
}
FILE_LOG(logDEBUG1, ("Getting start frame number\n"));
LOG(logDEBUG1, ("Getting start frame number\n"));
u_int32_t* csp0base = 0;
int fd = Beb_open(&csp0base, XPAR_COUNTER_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Get Start Frame Number FAIL\n"));
LOG(logERROR, ("Get Start Frame Number FAIL\n"));
return FAIL;
}
@ -1440,7 +1440,7 @@ int Beb_GetStartingFrameNumber(uint64_t* retval, int tengigaEnable) {
Beb_close(fd,csp0base);
if (left1g != right1g) {
FILE_LOG(logERROR, ("Retrieved inconsistent frame numbers from 1g left %llu and right %llu\n",
LOG(logERROR, ("Retrieved inconsistent frame numbers from 1g left %llu and right %llu\n",
(long long int)left1g, (long long int)right1g));
*retval = (left1g > right1g) ? left1g : right1g; // give max to set it to when stopping acq & different value
return -2; // to differentiate between failed address mapping
@ -1461,7 +1461,7 @@ int Beb_GetStartingFrameNumber(uint64_t* retval, int tengigaEnable) {
++right10g; // increment for firmware
if (left10g != right10g) {
FILE_LOG(logERROR, ("Retrieved inconsistent frame numbers from `0g left %llu and right %llu\n",
LOG(logERROR, ("Retrieved inconsistent frame numbers from `0g left %llu and right %llu\n",
(long long int)left10g, (long long int)right10g));
*retval = (left10g > right10g) ? left10g : right10g; // give max to set it to when stopping acq & different value
return -2; // to differentiate between failed address mapping
@ -1484,15 +1484,15 @@ int Beb_open(u_int32_t** csp0base, u_int32_t offset) {
int fd = open("/dev/mem", O_RDWR | O_SYNC, 0);
if (fd == -1) {
FILE_LOG(logERROR, ("\nCan't find /dev/mem!\n"));
LOG(logERROR, ("\nCan't find /dev/mem!\n"));
} else {
FILE_LOG(logDEBUG1, ("/dev/mem opened\n"));
LOG(logDEBUG1, ("/dev/mem opened\n"));
*csp0base = (u_int32_t*)mmap(0, BEB_MMAP_SIZE, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd, offset);
if (*csp0base == MAP_FAILED) {
FILE_LOG(logERROR, ("\nCan't map memmory area!!\n"));
LOG(logERROR, ("\nCan't map memmory area!!\n"));
fd = -1;
}
else FILE_LOG(logDEBUG1, ("CSP0 mapped %p\n",(void*)*csp0base));
else LOG(logDEBUG1, ("CSP0 mapped %p\n",(void*)*csp0base));
}
return fd;
}

File diff suppressed because it is too large Load Diff

View File

@ -55,7 +55,7 @@ void Feb_Interface_SendCompleteList(unsigned int n,unsigned int* list) {
int Feb_Interface_WriteTo(unsigned int ch) {
if (ch>0xfff) return 0;
FILE_LOG(logDEBUG1, ("FIW ch %d\n", ch));
LOG(logDEBUG1, ("FIW ch %d\n", ch));
Feb_Interface_send_data_raw[0] = 0x8fff0000;
if (Local_Write(ll,4,Feb_Interface_send_data_raw)!=4) return 0;
@ -176,7 +176,7 @@ int Feb_Interface_WriteMemory(unsigned int sub_num, unsigned int mem_num, unsign
start_address &= 0x3fff;
nwrites &= 0x3ff;
if (!nwrites||nwrites>Feb_Interface_send_buffer_size-2) {
FILE_LOG(logERROR, ("invalid nwrites:%d\n",nwrites));
LOG(logERROR, ("invalid nwrites:%d\n",nwrites));
return 0;
}//*d-1026

View File

@ -8,18 +8,18 @@
void Local_LocalLinkInterface1(struct LocalLinkInterface* ll,unsigned int ll_fifo_badr) {
FILE_LOG(logDEBUG1, ("Initialize PLB LL FIFOs\n"));
LOG(logDEBUG1, ("Initialize PLB LL FIFOs\n"));
ll->ll_fifo_base=0;
ll->ll_fifo_ctrl_reg=0;
if (Local_Init(ll,ll_fifo_badr)) {
Local_Reset(ll);
FILE_LOG(logDEBUG1, ("\tFIFO Status : 0x%08x\n\n\n", Local_StatusVector(ll)));
} else FILE_LOG(logERROR, ("\tCould not map LocalLink : 0x%08x\n\n\n", ll_fifo_badr));
LOG(logDEBUG1, ("\tFIFO Status : 0x%08x\n\n\n", Local_StatusVector(ll)));
} else LOG(logERROR, ("\tCould not map LocalLink : 0x%08x\n\n\n", ll_fifo_badr));
}
void Local_LocalLinkInterface(struct LocalLinkInterface* ll) {
FILE_LOG(logDEBUG1, ("Initializing new memory\n"));
LOG(logDEBUG1, ("Initializing new memory\n"));
}
@ -55,7 +55,7 @@ int Local_Reset(struct LocalLinkInterface* ll) {
int Local_Reset1(struct LocalLinkInterface* ll,unsigned int rst_mask) {
ll->ll_fifo_ctrl_reg |= rst_mask;
FILE_LOG(logDEBUG1, ("\tCTRL Register bits: 0x%08x\n",ll->ll_fifo_ctrl_reg));
LOG(logDEBUG1, ("\tCTRL Register bits: 0x%08x\n",ll->ll_fifo_ctrl_reg));
HWIO_xfs_out32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll->ll_fifo_ctrl_reg);
HWIO_xfs_out32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll->ll_fifo_ctrl_reg);
@ -90,9 +90,9 @@ int Local_Write(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buf
last_word = (buffer_len-1)/4;
word_ptr = (unsigned int *)buffer;
FILE_LOG(logDEBUG1, ("LL Write - Len: %2d - If: %X - Data: ",buffer_len, ll->ll_fifo_base));
LOG(logDEBUG1, ("LL Write - Len: %2d - If: %X - Data: ",buffer_len, ll->ll_fifo_base));
for (i=0; i < buffer_len/4; i++)
FILE_LOG(logDEBUG1, ("%.8X ",*(((unsigned *) buffer)+i)));
LOG(logDEBUG1, ("%.8X ",*(((unsigned *) buffer)+i)));
while (words_send <= last_word)
{
@ -101,7 +101,7 @@ int Local_Write(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buf
status = HWIO_xfs_in32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_STATUS);
if ((status & PLB_LL_FIFO_STATUS_ALMOSTFULL) == 0) vacancy = 1;
if (vacancy == 0) {
FILE_LOG(logERROR, ("Fifo full!\n"));
LOG(logERROR, ("Fifo full!\n"));
}
}
@ -136,7 +136,7 @@ int Local_Read(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buff
volatile unsigned int fifo_val;
int sof = 0;
FILE_LOG(logDEBUG1, ("LL Read - If: %X - Data: ",ll->ll_fifo_base));
LOG(logDEBUG1, ("LL Read - If: %X - Data: ",ll->ll_fifo_base));
word_ptr = (unsigned int *)buffer;
do
@ -162,7 +162,7 @@ int Local_Read(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buff
{
if ( (buffer_len >> 2) > buffer_ptr)
{
FILE_LOG(logDEBUG1, ("%.8X ", fifo_val));
LOG(logDEBUG1, ("%.8X ", fifo_val));
word_ptr[buffer_ptr++] = fifo_val; //write to buffer
}
else
@ -174,7 +174,7 @@ int Local_Read(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buff
if (status & PLB_LL_FIFO_STATUS_LL_EOF)
{
len = (buffer_ptr << 2) -3 + ( (status & PLB_LL_FIFO_STATUS_LL_REM)>>PLB_LL_FIFO_STATUS_LL_REM_SHIFT );
FILE_LOG(logDEBUG1, ("Len: %d\n",len));
LOG(logDEBUG1, ("Len: %d\n",len));
buffer_ptr = 0;
return len;
}
@ -207,11 +207,11 @@ int Local_Test(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buff
do{
len = Local_Read(ll,rec_buff_len,rec_buffer);
FILE_LOG(logDEBUG1, ("receive length: %i\n",len));
LOG(logDEBUG1, ("receive length: %i\n",len));
if (len > 0) {
rec_buffer[len]=0;
FILE_LOG(logINFO, ("%s\n", (char*) rec_buffer));
LOG(logINFO, ("%s\n", (char*) rec_buffer));
}
} while(len > 0);

View File

@ -107,7 +107,7 @@ void basictests() {
initCheckDone = 0;
memset(initErrorMessage, 0, MAX_STR_LENGTH);
#ifdef VIRTUAL
FILE_LOG(logINFOBLUE, ("************ EIGER Virtual Server *****************\n\n"));
LOG(logINFOBLUE, ("************ EIGER Virtual Server *****************\n\n"));
#endif
uint32_t ipadd = getDetectorIP();
uint64_t macadd = getDetectorMAC();
@ -116,7 +116,7 @@ void basictests() {
int64_t sw_fw_apiversion = getFirmwareAPIVersion();
int64_t client_sw_apiversion = getClientServerAPIVersion();
FILE_LOG(logINFOBLUE, ("**************** EIGER Server *********************\n\n"
LOG(logINFOBLUE, ("**************** EIGER Server *********************\n\n"
"Detector IP Addr:\t\t 0x%x\n"
"Detector MAC Addr:\t\t 0x%llx\n"
@ -150,7 +150,7 @@ void basictests() {
//cant read versions
if (!fwversion || !sw_fw_apiversion) {
strcpy(initErrorMessage, "Cant read versions from FPGA. Please update firmware.\n");
FILE_LOG(logERROR, (initErrorMessage));
LOG(logERROR, (initErrorMessage));
initError = FAIL;
return;
}
@ -161,7 +161,7 @@ void basictests() {
"Please update detector software (min. %lld) to be compatible with this firmware.\n",
(long long int)sw_fw_apiversion,
(long long int)REQUIRED_FIRMWARE_VERSION);
FILE_LOG(logERROR, (initErrorMessage));
LOG(logERROR, (initErrorMessage));
initError = FAIL;
return;
}
@ -172,11 +172,11 @@ void basictests() {
"Please update firmware (min. %lld) to be compatible with this server.\n",
(long long int)fwversion,
(long long int)REQUIRED_FIRMWARE_VERSION);
FILE_LOG(logERROR, (initErrorMessage));
LOG(logERROR, (initErrorMessage));
initError = FAIL;
return;
}
FILE_LOG(logINFO, ("Compatibility - success\n"));
LOG(logINFO, ("Compatibility - success\n"));
}
@ -250,7 +250,7 @@ u_int64_t getDetectorMAC() {
//increment by 1 for 10g
if (send_to_ten_gig)
res++;
//FILE_LOG(logINFO, ("mac:%llx\n",res));
//LOG(logINFO, ("mac:%llx\n",res));
return res;
}
@ -281,7 +281,7 @@ u_int32_t getDetectorIP() {
}
strcpy(output,temp);
sscanf(output, "%x", &res);
//FILE_LOG(logINFO, ("ip:%x\n",res));
//LOG(logINFO, ("ip:%x\n",res));
return res;
}
@ -312,10 +312,10 @@ void initControlServer() {
if (Feb_Control_OpenSerialCommunication())
;// Feb_Control_CloseSerialCommunication();
}
FILE_LOG(logDEBUG1, ("Control server: FEB Initialization done\n"));
LOG(logDEBUG1, ("Control server: FEB Initialization done\n"));
Beb_Beb(detid);
Beb_SetDetectorNumber(getDetectorNumber());
FILE_LOG(logDEBUG1, ("Control server: BEB Initialization done\n"));
LOG(logDEBUG1, ("Control server: BEB Initialization done\n"));
setupDetector();
// activate (if it gets ip) (later FW will deactivate at startup)
@ -340,7 +340,7 @@ void initStopServer() {
Feb_Interface_FebInterface();
Feb_Control_FebControl();
Feb_Control_Init(master,top,normal,getDetectorNumber());
FILE_LOG(logDEBUG1, ("Stop server: FEB Initialization done\n"));
LOG(logDEBUG1, ("Stop server: FEB Initialization done\n"));
// activate (if it gets ip) (later FW will deactivate at startup)
// also needed for stop server for status
if (getDetectorIP() != 0) {
@ -368,7 +368,7 @@ void getModuleConfiguration() {
#else
normal = 1;
#endif
FILE_LOG(logINFOBLUE, ("Module: %s %s %s\n",
LOG(logINFOBLUE, ("Module: %s %s %s\n",
(top ? "TOP" : "BOTTOM"),
(master ? "MASTER" : "SLAVE"),
(normal ? "NORMAL" : "SPECIAL")));
@ -379,7 +379,7 @@ void getModuleConfiguration() {
int *n=&normal;
Beb_GetModuleConfiguration(m,t,n);
if (isControlServer) {
FILE_LOG(logINFOBLUE, ("Module: %s %s %s\n",
LOG(logINFOBLUE, ("Module: %s %s %s\n",
(top ? "TOP" : "BOTTOM"),
(master ? "MASTER" : "SLAVE"),
(normal ? "NORMAL" : "SPECIAL")));
@ -392,7 +392,7 @@ void getModuleConfiguration() {
pclose(sysFile);
sscanf(output,"%u",&detid);
if (isControlServer) {
FILE_LOG(logINFOBLUE, ("Detector ID: %u\n\n", detid));
LOG(logINFOBLUE, ("Detector ID: %u\n\n", detid));
}
#endif
}
@ -402,15 +402,15 @@ void getModuleConfiguration() {
/* set up detector */
void allocateDetectorStructureMemory() {
FILE_LOG(logINFO, ("This Server is for 1 Eiger half module (250k)\n\n"));
LOG(logINFO, ("This Server is for 1 Eiger half module (250k)\n\n"));
//Allocation of memory
detectorModules = malloc(sizeof(sls_detector_module));
detectorChans = malloc(NCHIP*NCHAN*sizeof(int));
detectorDacs = malloc(NDAC*sizeof(int));
FILE_LOG(logDEBUG1, ("modules from 0x%x to 0x%x\n",detectorModules, detectorModules));
FILE_LOG(logDEBUG1, ("chans from 0x%x to 0x%x\n",detectorChans, detectorChans));
FILE_LOG(logDEBUG1, ("dacs from 0x%x to 0x%x\n",detectorDacs, detectorDacs));
LOG(logDEBUG1, ("modules from 0x%x to 0x%x\n",detectorModules, detectorModules));
LOG(logDEBUG1, ("chans from 0x%x to 0x%x\n",detectorChans, detectorChans));
LOG(logDEBUG1, ("dacs from 0x%x to 0x%x\n",detectorDacs, detectorDacs));
(detectorModules)->dacs = detectorDacs;
(detectorModules)->chanregs = detectorChans;
(detectorModules)->ndac = NDAC;
@ -435,19 +435,19 @@ void setupDetector() {
allocateDetectorStructureMemory();
//set dacs
FILE_LOG(logINFOBLUE, ("Setting Default Dac values\n"));
LOG(logINFOBLUE, ("Setting Default Dac values\n"));
{
int i = 0;
const int defaultvals[NDAC] = DEFAULT_DAC_VALS;
for(i = 0; i < NDAC; ++i) {
setDAC((enum DACINDEX)i,defaultvals[i],0);
if ((detectorModules)->dacs[i] != defaultvals[i]) {
FILE_LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n",i ,defaultvals[i], (detectorModules)->dacs[i]));
LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n",i ,defaultvals[i], (detectorModules)->dacs[i]));
}
}
}
FILE_LOG(logINFOBLUE, ("Setting Default Parameters\n"));
LOG(logINFOBLUE, ("Setting Default Parameters\n"));
//setting default measurement parameters
setNumFrames(DEFAULT_NUM_FRAMES);
setExpTime(DEFAULT_EXPTIME);
@ -476,7 +476,7 @@ void setupDetector() {
#ifndef VIRTUAL
Feb_Control_CheckSetup();
#endif
FILE_LOG(logDEBUG1, ("Setup detector done\n\n"));
LOG(logDEBUG1, ("Setup detector done\n\n"));
}
@ -512,13 +512,13 @@ int readRegister(uint32_t offset, uint32_t* retval) {
int setDynamicRange(int dr) {
#ifdef VIRTUAL
if (dr > 0) {
FILE_LOG(logINFO, ("Setting dynamic range: %d\n", dr));
LOG(logINFO, ("Setting dynamic range: %d\n", dr));
eiger_dynamicrange = dr;
}
return eiger_dynamicrange;
#else
if (dr > 0) {
FILE_LOG(logDEBUG1, ("Setting dynamic range: %d\n", dr));
LOG(logDEBUG1, ("Setting dynamic range: %d\n", dr));
if (Feb_Control_SetDynamicRange(dr)) {
//EigerSetBitMode(dr);
@ -527,7 +527,7 @@ int setDynamicRange(int dr) {
for(i=0;i<32;i++) dst_requested[i] = 0; //clear dst requested
if (Beb_SetUpTransferParameters(dr))
eiger_dynamicrange = dr;
else FILE_LOG(logERROR, ("Could not set bit mode in the back end\n"));
else LOG(logERROR, ("Could not set bit mode in the back end\n"));
}
}
//make sure back end and front end have the same bit mode
@ -574,7 +574,7 @@ int getOverFlowMode() {
void setStoreInRamMode(int mode) {
mode = (mode == 0 ? 0 : 1);
FILE_LOG(logINFO, ("Setting Store in Ram mode to %d\n", mode));
LOG(logINFO, ("Setting Store in Ram mode to %d\n", mode));
eiger_storeinmem = mode;
}
@ -608,7 +608,7 @@ int getStartingFrameNumber(uint64_t* retval) {
void setNumFrames(int64_t val) {
if (val > 0) {
FILE_LOG(logINFO, ("Setting number of frames %lld\n", (long long int)val));
LOG(logINFO, ("Setting number of frames %lld\n", (long long int)val));
#ifndef VIRTUAL
if (Feb_Control_SetNExposures((unsigned int)val * eiger_ntriggers)) {
eiger_nexposures = val;
@ -631,7 +631,7 @@ int64_t getNumFrames() {
void setNumTriggers(int64_t val) {
if (val > 0) {
FILE_LOG(logINFO, ("Setting number of triggers %lld\n", (long long int)val));
LOG(logINFO, ("Setting number of triggers %lld\n", (long long int)val));
#ifndef VIRTUAL
if (Feb_Control_SetNExposures((unsigned int)val * eiger_nexposures)) {
eiger_ntriggers = val;
@ -652,7 +652,7 @@ int64_t getNumTriggers() {
}
int setExpTime(int64_t val) {
FILE_LOG(logINFO, ("Setting exptime %lld ns\n", (long long int)val));
LOG(logINFO, ("Setting exptime %lld ns\n", (long long int)val));
#ifndef VIRTUAL
Feb_Control_SetExposureTime(val/(1E9));
#else
@ -670,7 +670,7 @@ int64_t getExpTime() {
}
int setPeriod(int64_t val) {
FILE_LOG(logINFO, ("Setting period %lld ns\n", (long long int)val));
LOG(logINFO, ("Setting period %lld ns\n", (long long int)val));
#ifndef VIRTUAL
Feb_Control_SetExposurePeriod(val/(1E9));
#else
@ -688,7 +688,7 @@ int64_t getPeriod() {
}
int setSubExpTime(int64_t val) {
FILE_LOG(logINFO, ("Setting subexptime %lld ns\n", (long long int)val));
LOG(logINFO, ("Setting subexptime %lld ns\n", (long long int)val));
#ifndef VIRTUAL
// calculate subdeadtime before settings subexptime
int64_t subdeadtime = Feb_Control_GetSubFramePeriod() - Feb_Control_GetSubFrameExposureTime();
@ -713,14 +713,14 @@ int64_t getSubExpTime() {
}
int setDeadTime(int64_t val) {
FILE_LOG(logINFO, ("Setting subdeadtime %lld ns\n", (long long int)val));
LOG(logINFO, ("Setting subdeadtime %lld ns\n", (long long int)val));
#ifndef VIRTUAL
// get subexptime
int64_t subexptime = Feb_Control_GetSubFrameExposureTime();
#else
int64_t subexptime = eiger_virtual_subexptime * 10;
#endif
FILE_LOG(logINFO, ("Setting sub period (subdeadtime(%lld)): %lldns\n",
LOG(logINFO, ("Setting sub period (subdeadtime(%lld)): %lldns\n",
(long long int)subexptime,
(long long int)val),
(long long int)(val + subexptime));
@ -771,7 +771,7 @@ int64_t getMeasuredSubPeriod() {
int setModule(sls_detector_module myMod, char* mess) {
FILE_LOG(logINFO, ("Setting module with settings %d\n",myMod.reg));
LOG(logINFO, ("Setting module with settings %d\n",myMod.reg));
// settings
setSettings( (enum detectorSettings)myMod.reg);
@ -781,9 +781,9 @@ int setModule(sls_detector_module myMod, char* mess) {
if (detectorModules) {
if (copyModule(detectorModules,&myMod) == FAIL) {
sprintf(mess, "Could not copy module\n");
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined\n"));
LOG(logERROR, ("Settings has been changed to undefined\n"));
return FAIL;
}
}
@ -791,9 +791,9 @@ int setModule(sls_detector_module myMod, char* mess) {
// iodelay
if (setIODelay(myMod.iodelay)!= myMod.iodelay) {
sprintf(mess, "Could not set module. Could not set iodelay %d\n", myMod.iodelay);
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined\n"));
LOG(logERROR, ("Settings has been changed to undefined\n"));
return FAIL;
}
@ -803,7 +803,7 @@ int setModule(sls_detector_module myMod, char* mess) {
else {
// (loading a random trim file) (dont return fail)
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
}
// dacs
@ -813,9 +813,9 @@ int setModule(sls_detector_module myMod, char* mess) {
setDAC((enum DACINDEX)i, myMod.dacs[i] , 0);
if (myMod.dacs[i] != (detectorModules)->dacs[i]) {
sprintf(mess, "Could not set module. Could not set dac %d\n", i);
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined\n"));
LOG(logERROR, ("Settings has been changed to undefined\n"));
return FAIL;
}
}
@ -823,9 +823,9 @@ int setModule(sls_detector_module myMod, char* mess) {
// trimbits
#ifndef VIRTUAL
if (myMod.nchan == 0) {
FILE_LOG(logINFO, ("Setting module without trimbits\n"));
LOG(logINFO, ("Setting module without trimbits\n"));
} else {
FILE_LOG(logINFO, ("Setting module with trimbits\n"));
LOG(logINFO, ("Setting module with trimbits\n"));
//includ gap pixels
unsigned int tt[263680];
int iy, ichip, ix, ip = 0, ich = 0;
@ -844,9 +844,9 @@ int setModule(sls_detector_module myMod, char* mess) {
//set trimbits
if (!Feb_Control_SetTrimbits(Feb_Control_GetModuleNumber(), tt)) {
sprintf(mess, "Could not set module. Could not set trimbits\n");
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
return FAIL;
}
}
@ -859,9 +859,9 @@ int setModule(sls_detector_module myMod, char* mess) {
setRateCorrection(0);
sprintf(mess,"Cannot set module. Cannot set Rate correction. "
"No default tau provided. Deactivating Rate Correction\n");
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
return FAIL;
}
}
@ -872,9 +872,9 @@ int setModule(sls_detector_module myMod, char* mess) {
int64_t retvalTau = setRateCorrection(myMod.tau);
if (myMod.tau != retvalTau) {
sprintf(mess, "Cannot set module. Could not set rate correction\n");
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
return FAIL;
}
}
@ -923,7 +923,7 @@ enum detectorSettings setSettings(enum detectorSettings sett) {
return thisSettings;
}if (sett != GET_SETTINGS)
thisSettings = sett;
FILE_LOG(logINFO, ("Settings: %d\n", thisSettings));
LOG(logINFO, ("Settings: %d\n", thisSettings));
return thisSettings;
}
@ -939,13 +939,13 @@ enum detectorSettings getSettings() {
/* parameters - threshold */
int getThresholdEnergy() {
FILE_LOG(logDEBUG1, ("Getting Threshold energy\n"));
LOG(logDEBUG1, ("Getting Threshold energy\n"));
return eiger_photonenergy;
}
int setThresholdEnergy(int ev) {
FILE_LOG(logINFO, ("Setting threshold energy:%d\n",ev));
LOG(logINFO, ("Setting threshold energy:%d\n",ev));
if (ev >= 0)
eiger_photonenergy = ev;
return getThresholdEnergy();
@ -962,7 +962,7 @@ void setDAC(enum DACINDEX ind, int val, int mV) {
if (val < 0)
return;
FILE_LOG(logDEBUG1, ("Setting dac[%d]: %d %s \n", (int)ind, val, (mV ? "mV" : "dac units")));
LOG(logDEBUG1, ("Setting dac[%d]: %d %s \n", (int)ind, val, (mV ? "mV" : "dac units")));
if (ind == E_VTHRESHOLD) {
setDAC(E_VCMP_LL, val, mV);
@ -975,7 +975,7 @@ void setDAC(enum DACINDEX ind, int val, int mV) {
// validate index
if (ind < 0 || ind >= NDAC) {
FILE_LOG(logERROR, ("\tDac index %d is out of bounds (0 to %d)\n", ind, NDAC - 1));
LOG(logERROR, ("\tDac index %d is out of bounds (0 to %d)\n", ind, NDAC - 1));
return;
}
@ -1013,24 +1013,24 @@ int getDAC(enum DACINDEX ind, int mV) {
(ret[1]==ret[2])&&
(ret[2]==ret[3]) &&
(ret[3]==ret[4])) {
FILE_LOG(logINFO, ("\tvthreshold match\n"));
LOG(logINFO, ("\tvthreshold match\n"));
return ret[0];
} else {
FILE_LOG(logERROR, ("\tvthreshold mismatch vcmp_ll:%d vcmp_lr:%d vcmp_rl:%d vcmp_rr:%d vcp:%d\n",
LOG(logERROR, ("\tvthreshold mismatch vcmp_ll:%d vcmp_lr:%d vcmp_rl:%d vcmp_rr:%d vcp:%d\n",
ret[0],ret[1],ret[2],ret[3], ret[4]));
return -1;
}
}
if (!mV) {
FILE_LOG(logDEBUG1, ("Getting DAC %d : %d dac\n",ind, (detectorModules)->dacs[ind]));
LOG(logDEBUG1, ("Getting DAC %d : %d dac\n",ind, (detectorModules)->dacs[ind]));
return (detectorModules)->dacs[ind];
}
int voltage = -1;
// dac units to voltage
ConvertToDifferentRange(LTC2620_MIN_VAL, LTC2620_MAX_VAL, DAC_MIN_MV, DAC_MAX_MV,
(detectorModules)->dacs[ind], &voltage);
FILE_LOG(logDEBUG1, ("Getting DAC %d : %d dac (%d mV)\n",ind, (detectorModules)->dacs[ind], voltage));
LOG(logDEBUG1, ("Getting DAC %d : %d dac (%d mV)\n",ind, (detectorModules)->dacs[ind], voltage));
return voltage;
}
@ -1072,7 +1072,7 @@ int getADC(enum ADCINDEX ind) {
return -1;
}
FILE_LOG(logINFO, ("Temperature %s: %f°C\n", tempnames[ind], (double)retval/1000.00));
LOG(logINFO, ("Temperature %s: %f°C\n", tempnames[ind], (double)retval/1000.00));
return retval;
#endif
@ -1106,13 +1106,13 @@ int setHighVoltage(int val) {
// get
if (!Feb_Control_GetHighVoltage(&eiger_highvoltage)) {
FILE_LOG(logERROR, ("Could not read high voltage\n"));
LOG(logERROR, ("Could not read high voltage\n"));
return -3;
}
// tolerance of 5
if (abs(eiger_theo_highvoltage-eiger_highvoltage) > HIGH_VOLTAGE_TOLERANCE) {
FILE_LOG(logINFO, ("High voltage still ramping: %d\n", eiger_highvoltage));
LOG(logINFO, ("High voltage still ramping: %d\n", eiger_highvoltage));
return eiger_highvoltage;
}
return eiger_theo_highvoltage;
@ -1146,10 +1146,10 @@ void setTiming( enum timingMode arg) {
ret = 3;
break;
default:
FILE_LOG(logERROR, ("Unknown timing mode %d\n", arg));
LOG(logERROR, ("Unknown timing mode %d\n", arg));
return;
}
FILE_LOG(logDEBUG1, ("Setting Triggering Mode: %d\n", (int)ret));
LOG(logDEBUG1, ("Setting Triggering Mode: %d\n", (int)ret));
#ifndef VIRTUAL
if (Feb_Control_SetTriggerMode(ret,1))
#endif
@ -1168,7 +1168,7 @@ enum timingMode getTiming() {
case 3:
return GATED;
default:
FILE_LOG(logERROR, ("Unknown trigger mode found %d\n", eiger_triggermode));
LOG(logERROR, ("Unknown trigger mode found %d\n", eiger_triggermode));
return GET_TIMING_MODE;
}
}
@ -1186,7 +1186,7 @@ int configureMAC() {
int destport = udpDetails.dstport;
int destport2 = udpDetails.dstport2;
FILE_LOG(logINFO, ("Configuring MAC\n"));
LOG(logINFO, ("Configuring MAC\n"));
char src_mac[50], src_ip[INET_ADDRSTRLEN],dst_mac[50], dst_ip[INET_ADDRSTRLEN];
getMacAddressinString(src_mac, 50, sourcemac);
@ -1194,7 +1194,7 @@ int configureMAC() {
getIpAddressinString(src_ip, sourceip);
getIpAddressinString(dst_ip, destip);
FILE_LOG(logINFO, (
LOG(logINFO, (
"\tSource IP : %s\n"
"\tSource MAC : %s\n"
"\tSource Port : %d\n"
@ -1209,13 +1209,13 @@ int configureMAC() {
char cDestIp[MAX_STR_LENGTH];
memset(cDestIp, 0, MAX_STR_LENGTH);
sprintf(cDestIp, "%d.%d.%d.%d", (destip>>24)&0xff,(destip>>16)&0xff,(destip>>8)&0xff,(destip)&0xff);
FILE_LOG(logINFO, ("1G UDP: Destination (IP: %s, port:%d, port2:%d)\n", cDestIp, destport, destport2));
LOG(logINFO, ("1G UDP: Destination (IP: %s, port:%d, port2:%d)\n", cDestIp, destport, destport2));
if (setUDPDestinationDetails(0, cDestIp, destport) == FAIL) {
FILE_LOG(logERROR, ("could not set udp destination IP and port\n"));
LOG(logERROR, ("could not set udp destination IP and port\n"));
return FAIL;
}
if (setUDPDestinationDetails(1, cDestIp, destport2) == FAIL) {
FILE_LOG(logERROR, ("could not set udp destination IP and port2\n"));
LOG(logERROR, ("could not set udp destination IP and port2\n"));
return FAIL;
}
return OK;
@ -1227,13 +1227,13 @@ int configureMAC() {
if (!top)
dst_port = destport2;
FILE_LOG(logINFO, ("\tDest Port : %d\n", dst_port));
LOG(logINFO, ("\tDest Port : %d\n", dst_port));
int i=0;
/* for(i=0;i<32;i++) { modified for Aldo*/
if (Beb_SetBebSrcHeaderInfos(beb_num,send_to_ten_gig,src_mac,src_ip,src_port) &&
Beb_SetUpUDPHeader(beb_num,send_to_ten_gig,header_number+i,dst_mac,dst_ip, dst_port)) {
FILE_LOG(logDEBUG1, ("\tset up left ok\n"));
LOG(logDEBUG1, ("\tset up left ok\n"));
} else {
return FAIL;
}
@ -1243,12 +1243,12 @@ int configureMAC() {
dst_port = destport2;
if (!top)
dst_port = destport;
FILE_LOG(logINFO, ("\tDest Port : %d\n",dst_port));
LOG(logINFO, ("\tDest Port : %d\n",dst_port));
/*for(i=0;i<32;i++) {*//** modified for Aldo*/
if (Beb_SetBebSrcHeaderInfos(beb_num,send_to_ten_gig,src_mac,src_ip,src_port) &&
Beb_SetUpUDPHeader(beb_num,send_to_ten_gig,header_number+i,dst_mac,dst_ip, dst_port)) {
FILE_LOG(logDEBUG1, (" set up right ok\n"));
LOG(logDEBUG1, (" set up right ok\n"));
} else {
return FAIL;
}
@ -1344,7 +1344,7 @@ int getReadNLines() {
int enableTenGigabitEthernet(int val) {
if (val!=-1) {
FILE_LOG(logINFO, ("Setting 10Gbe: %d\n", (val > 0) ? 1 : 0));
LOG(logINFO, ("Setting 10Gbe: %d\n", (val > 0) ? 1 : 0));
if (val>0)
send_to_ten_gig = 1;
else
@ -1359,11 +1359,11 @@ int enableTenGigabitEthernet(int val) {
/* eiger specific - iodelay, pulse, rate, temp, activate, delay nw parameter */
int setClockDivider(enum CLKINDEX ind, int val) {
if (ind != RUN_CLK) {
FILE_LOG(logERROR, ("Unknown clock index: %d\n", ind));
LOG(logERROR, ("Unknown clock index: %d\n", ind));
return FAIL;
}
if (val >= 0) {
FILE_LOG(logINFO, ("Setting Read out Speed: %d\n", val));
LOG(logINFO, ("Setting Read out Speed: %d\n", val));
#ifndef VIRTUAL
if (Feb_Control_SetReadoutSpeed(val))
#endif
@ -1374,7 +1374,7 @@ int setClockDivider(enum CLKINDEX ind, int val) {
int getClockDivider(enum CLKINDEX ind) {
if (ind != RUN_CLK) {
FILE_LOG(logERROR, ("Unknown clock index: %d\n", ind));
LOG(logERROR, ("Unknown clock index: %d\n", ind));
return FAIL;
}
return eiger_readoutspeed;
@ -1382,7 +1382,7 @@ int getClockDivider(enum CLKINDEX ind) {
int setIODelay(int val) {
if (val!=-1) {
FILE_LOG(logDEBUG1, ("Setting IO Delay: %d\n",val));
LOG(logDEBUG1, ("Setting IO Delay: %d\n",val));
#ifndef VIRTUAL
if (Feb_Control_SetIDelays(Feb_Control_GetModuleNumber(),val))
#endif
@ -1394,7 +1394,7 @@ int setIODelay(int val) {
int setCounterBit(int val) {
if (val!=-1) {
FILE_LOG(logINFO, ("Setting Counter Bit: %d\n",val));
LOG(logINFO, ("Setting Counter Bit: %d\n",val));
#ifdef VIRTUAL
eiger_virtual_counter_bit = val;
#else
@ -1458,10 +1458,10 @@ int64_t setRateCorrection(int64_t custom_tau_in_nsec) {//in nanosec (will never
//same setting
if ((tau_in_nsec == custom_tau_in_nsec) && (ratetable_period_in_nsec == actual_period)) {
if (eiger_dynamicrange == 32) {
FILE_LOG(logINFO, ("Rate Table already created before: Same Tau %lldns, Same subexptime %lldns\n",
LOG(logINFO, ("Rate Table already created before: Same Tau %lldns, Same subexptime %lldns\n",
(long long int)tau_in_nsec,(long long int)ratetable_period_in_nsec));
} else {
FILE_LOG(logINFO, ("Rate Table already created before: Same Tau %lldns, Same exptime %lldns\n",
LOG(logINFO, ("Rate Table already created before: Same Tau %lldns, Same exptime %lldns\n",
(long long int)tau_in_nsec,(long long int)ratetable_period_in_nsec));
}
}
@ -1475,7 +1475,7 @@ int64_t setRateCorrection(int64_t custom_tau_in_nsec) {//in nanosec (will never
}
//activating rate correction
eiger_virtual_ratecorrection_variable = 1;
FILE_LOG(logINFO, ("Rate Correction Value set to %lld ns\n",(long long int)eiger_virtual_ratetable_tau_in_ns));
LOG(logINFO, ("Rate Correction Value set to %lld ns\n",(long long int)eiger_virtual_ratetable_tau_in_ns));
return eiger_virtual_ratetable_tau_in_ns;
#else
@ -1504,10 +1504,10 @@ int64_t setRateCorrection(int64_t custom_tau_in_nsec) {//in nanosec (will never
//same setting
if ((tau_in_nsec == custom_tau_in_nsec) && (ratetable_period_in_nsec == actual_period)) {
if (dr == 32) {
FILE_LOG(logINFO, ("Rate Table already created before: Same Tau %lldns, Same subexptime %lldns\n",
LOG(logINFO, ("Rate Table already created before: Same Tau %lldns, Same subexptime %lldns\n",
tau_in_nsec,ratetable_period_in_nsec));
} else {
FILE_LOG(logINFO, ("Rate Table already created before: Same Tau %lldns, Same exptime %lldns\n",
LOG(logINFO, ("Rate Table already created before: Same Tau %lldns, Same exptime %lldns\n",
tau_in_nsec,ratetable_period_in_nsec));
}
}
@ -1515,14 +1515,14 @@ int64_t setRateCorrection(int64_t custom_tau_in_nsec) {//in nanosec (will never
else {
int ret = Feb_Control_SetRateCorrectionTau(custom_tau_in_nsec);
if (ret<=0) {
FILE_LOG(logERROR, ("Rate correction failed. Deactivating rate correction\n"));
LOG(logERROR, ("Rate correction failed. Deactivating rate correction\n"));
Feb_Control_SetRateCorrectionVariable(0);
return ret;
}
}
//activating rate correction
Feb_Control_SetRateCorrectionVariable(1);
FILE_LOG(logINFO, ("Rate Correction Value set to %lld ns\n", (long long int)Feb_Control_Get_RateTable_Tau_in_nsec()));
LOG(logINFO, ("Rate Correction Value set to %lld ns\n", (long long int)Feb_Control_Get_RateTable_Tau_in_nsec()));
Feb_Control_PrintCorrectedValues();
return Feb_Control_Get_RateTable_Tau_in_nsec();
@ -1543,7 +1543,7 @@ int getDefaultSettingsTau_in_nsec() {
void setDefaultSettingsTau_in_nsec(int t) {
default_tau_from_file = t;
FILE_LOG(logINFO, ("Default tau set to %d\n", default_tau_from_file));
LOG(logINFO, ("Default tau set to %d\n", default_tau_from_file));
}
int64_t getCurrentTau() {
@ -1572,7 +1572,7 @@ void setExternalGating(int enable[]) {
int setAllTrimbits(int val) {
#ifndef VIRTUAL
if (!Feb_Control_SaveAllTrimbitsTo(val)) {
FILE_LOG(logERROR, ("Could not set all trimbits\n"));
LOG(logERROR, ("Could not set all trimbits\n"));
return FAIL;
}
#endif
@ -1583,7 +1583,7 @@ int setAllTrimbits(int val) {
}
}
FILE_LOG(logINFO, ("All trimbits have been set to %d\n", val));
LOG(logINFO, ("All trimbits have been set to %d\n", val));
return OK;
}
@ -1599,7 +1599,7 @@ int getAllTrimbits() {
}
}
FILE_LOG(logINFO, ("Value of all Trimbits: %d\n", value));
LOG(logINFO, ("Value of all Trimbits: %d\n", value));
return value;
}
@ -1711,7 +1711,7 @@ int setTransmissionDelayRight(int value) {
int prepareAcquisition() {
#ifndef VIRTUAL
FILE_LOG(logINFO, ("Going to prepare for acquisition with counter_bit:%d\n",Feb_Control_Get_Counter_Bit()));
LOG(logINFO, ("Going to prepare for acquisition with counter_bit:%d\n",Feb_Control_Get_Counter_Bit()));
Feb_Control_PrepareForAcquisition();
#endif
return OK;
@ -1728,15 +1728,15 @@ int startStateMachine() {
if(createUDPSocket(1) != OK) {
return FAIL;
}
FILE_LOG(logINFOBLUE, ("starting state machine\n"));
LOG(logINFOBLUE, ("starting state machine\n"));
eiger_virtual_status = 1;
eiger_virtual_stop = 0;
if (pthread_create(&eiger_virtual_tid, NULL, &start_timer, NULL)) {
FILE_LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
eiger_virtual_status = 0;
return FAIL;
}
FILE_LOG(logINFO ,("Virtual Acquisition started\n"));
LOG(logINFO ,("Virtual Acquisition started\n"));
return OK;
#else
@ -1744,21 +1744,21 @@ int startStateMachine() {
//get the DAQ toggle bit
prev_flag = Feb_Control_AcquisitionStartedBit();
FILE_LOG(logINFO, ("Going to start acquisition\n"));
LOG(logINFO, ("Going to start acquisition\n"));
Feb_Control_StartAcquisition();
if (!eiger_storeinmem) {
FILE_LOG(logINFO, ("requesting images right after start\n"));
LOG(logINFO, ("requesting images right after start\n"));
ret = startReadOut();
}
//wait for acquisition start
if (ret == OK) {
if (!Feb_Control_WaitForStartedFlag(5000, prev_flag)) {
FILE_LOG(logERROR, ("Acquisition did not FILE_LOG(logERROR ouble reading register\n"));
LOG(logERROR, ("Acquisition did not LOG(logERROR ouble reading register\n"));
return FAIL;
}
FILE_LOG(logINFOGREEN, ("Acquisition started\n"));
LOG(logINFOGREEN, ("Acquisition started\n"));
}
return ret;
@ -1779,7 +1779,7 @@ void* start_timer(void* arg) {
int numPacketsPerFrame = (tgEnable ? 4 : 16) * dr;
int npixelsx = 256 * 2 * bytesPerPixel;
int databytes = 256 * 256 * 2 * bytesPerPixel;
FILE_LOG(logINFO, (" dr:%f\n bytesperpixel:%d\n tgenable:%d\n datasize:%d\n packetsize:%d\n numpackes:%d\n npixelsx:%d\n databytes:%d\n",
LOG(logINFO, (" dr:%f\n bytesperpixel:%d\n tgenable:%d\n datasize:%d\n packetsize:%d\n numpackes:%d\n npixelsx:%d\n databytes:%d\n",
dr, bytesPerPixel, tgEnable, datasize, packetsize, numPacketsPerFrame, npixelsx, databytes));
@ -1855,7 +1855,7 @@ void* start_timer(void* arg) {
sendUDPPacket(1, packetData2, packetsize);
}
}
FILE_LOG(logINFO, ("Sent frame: %d\n", frameNr));
LOG(logINFO, ("Sent frame: %d\n", frameNr));
clock_gettime(CLOCK_REALTIME, &end);
int64_t time_ns = ((end.tv_sec - begin.tv_sec) * 1E9 +
(end.tv_nsec - begin.tv_nsec));
@ -1873,7 +1873,7 @@ void* start_timer(void* arg) {
closeUDPSocket(1);
eiger_virtual_status = 0;
FILE_LOG(logINFOBLUE, ("Finished Acquiring\n"));
LOG(logINFOBLUE, ("Finished Acquiring\n"));
return NULL;
}
#endif
@ -1882,13 +1882,13 @@ void* start_timer(void* arg) {
int stopStateMachine() {
FILE_LOG(logINFORED, ("Going to stop acquisition\n"));
LOG(logINFORED, ("Going to stop acquisition\n"));
#ifdef VIRTUAL
eiger_virtual_stop = 0;
return OK;
#else
if ((Feb_Control_StopAcquisition() != STATUS_IDLE) || (!Beb_StopAcquisition()) ) {
FILE_LOG(logERROR, ("failed to stop acquisition\n"));
LOG(logERROR, ("failed to stop acquisition\n"));
return FAIL;
}
@ -1914,7 +1914,7 @@ int softwareTrigger() {
int startReadOut() {
FILE_LOG(logINFO, ("Requesting images...\n"));
LOG(logINFO, ("Requesting images...\n"));
#ifdef VIRTUAL
return OK;
#else
@ -1945,10 +1945,10 @@ int startReadOut() {
enum runStatus getRunStatus() {
#ifdef VIRTUAL
if (eiger_virtual_status == 0) {
FILE_LOG(logINFO, ("Status: IDLE\n"));
LOG(logINFO, ("Status: IDLE\n"));
return IDLE;
} else {
FILE_LOG(logINFO, ("Status: RUNNING...\n"));
LOG(logINFO, ("Status: RUNNING...\n"));
return RUNNING;
}
#else
@ -1956,13 +1956,13 @@ enum runStatus getRunStatus() {
int i = Feb_Control_AcquisitionInProgress();
switch (i) {
case STATUS_ERROR:
FILE_LOG(logERROR, ("Status: ERROR reading status register\n"));
LOG(logERROR, ("Status: ERROR reading status register\n"));
return ERROR;
case STATUS_IDLE:
FILE_LOG(logINFOBLUE, ("Status: IDLE\n"));
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
default:
FILE_LOG(logINFOBLUE, ("Status: RUNNING...\n"));
LOG(logINFOBLUE, ("Status: RUNNING...\n"));
return RUNNING;
}
@ -1978,22 +1978,22 @@ void readFrame(int *ret, char *mess) {
while(eiger_virtual_status == 1){
usleep(500);
}
FILE_LOG(logINFOGREEN, ("acquisition successfully finished\n"));
LOG(logINFOGREEN, ("acquisition successfully finished\n"));
return;
#else
if (Feb_Control_WaitForFinishedFlag(5000) == STATUS_ERROR) {
FILE_LOG(logERROR, ("Waiting for finished flag\n"));
LOG(logERROR, ("Waiting for finished flag\n"));
*ret = FAIL;
return;
}
FILE_LOG(logINFOGREEN, ("Acquisition finished\n"));
LOG(logINFOGREEN, ("Acquisition finished\n"));
if (eiger_storeinmem) {
FILE_LOG(logINFO, ("requesting images after storing in memory\n"));
LOG(logINFO, ("requesting images after storing in memory\n"));
if (startReadOut() == FAIL) {
strcpy(mess,"Could not execute read image requests\n");
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
*ret = (int)FAIL;
return;
}
@ -2001,7 +2001,7 @@ void readFrame(int *ret, char *mess) {
//wait for detector to send
Beb_EndofDataSend(send_to_ten_gig);
FILE_LOG(logINFOGREEN, ("Acquisition successfully finished\n"));
LOG(logINFOGREEN, ("Acquisition successfully finished\n"));
#endif
}
@ -2020,7 +2020,7 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
int idac, ichan;
int ret=OK;
FILE_LOG(logDEBUG1, ("Copying module\n"));
LOG(logDEBUG1, ("Copying module\n"));
if (srcMod->serialnumber>=0) {
@ -2028,16 +2028,16 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
}
//no trimbit feature
if (destMod->nchan && ((srcMod->nchan)>(destMod->nchan))) {
FILE_LOG(logINFO, ("Number of channels of source is larger than number of channels of destination\n"));
LOG(logINFO, ("Number of channels of source is larger than number of channels of destination\n"));
return FAIL;
}
if ((srcMod->ndac)>(destMod->ndac)) {
FILE_LOG(logINFO, ("Number of dacs of source is larger than number of dacs of destination\n"));
LOG(logINFO, ("Number of dacs of source is larger than number of dacs of destination\n"));
return FAIL;
}
FILE_LOG(logDEBUG1, ("DACs: src %d, dest %d\n",srcMod->ndac,destMod->ndac));
FILE_LOG(logDEBUG1, ("Chans: src %d, dest %d\n",srcMod->nchan,destMod->nchan));
LOG(logDEBUG1, ("DACs: src %d, dest %d\n",srcMod->ndac,destMod->ndac));
LOG(logDEBUG1, ("Chans: src %d, dest %d\n",srcMod->nchan,destMod->nchan));
destMod->ndac=srcMod->ndac;
destMod->nchip=srcMod->nchip;
destMod->nchan=srcMod->nchan;
@ -2049,7 +2049,7 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
destMod->tau=srcMod->tau;
if (srcMod->eV>=0)
destMod->eV=srcMod->eV;
FILE_LOG(logDEBUG1, ("Copying register %x (%x)\n",destMod->reg,srcMod->reg ));
LOG(logDEBUG1, ("Copying register %x (%x)\n",destMod->reg,srcMod->reg ));
if (destMod->nchan!=0) {
for (ichan=0; ichan<(srcMod->nchan); ichan++) {
@ -2057,7 +2057,7 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
*((destMod->chanregs)+ichan)=*((srcMod->chanregs)+ichan);
}
}
else FILE_LOG(logINFO, ("Not Copying trimbits\n"));
else LOG(logINFO, ("Not Copying trimbits\n"));
for (idac=0; idac<(srcMod->ndac); idac++) {
if (*((srcMod->dacs)+idac)>=0) {

View File

@ -54,20 +54,20 @@ void basictests() {
initCheckDone = 0;
memset(initErrorMessage, 0, MAX_STR_LENGTH);
#ifdef VIRTUAL
FILE_LOG(logINFOBLUE, ("******** Mythen3 Virtual Server *****************\n"));
LOG(logINFOBLUE, ("******** Mythen3 Virtual Server *****************\n"));
if (mapCSP0() == FAIL) {
strcpy(initErrorMessage,
"Could not map to memory. Dangerous to continue.\n");
FILE_LOG(logERROR, (initErrorMessage));
LOG(logERROR, (initErrorMessage));
initError = FAIL;
}
return;
#else
FILE_LOG(logINFOBLUE, ("************ Mythen3 Server *********************\n"));
LOG(logINFOBLUE, ("************ Mythen3 Server *********************\n"));
if (mapCSP0() == FAIL) {
strcpy(initErrorMessage,
"Could not map to memory. Dangerous to continue.\n");
FILE_LOG(logERROR, ("%s\n\n", initErrorMessage));
LOG(logERROR, ("%s\n\n", initErrorMessage));
initError = FAIL;
return;
}
@ -75,7 +75,7 @@ void basictests() {
if ((!debugflag) && ((checkType() == FAIL) || (testFpga() == FAIL)|| (testBus() == FAIL))) {
strcpy(initErrorMessage,
"Could not pass basic tests of FPGA and bus. Dangerous to continue.\n");
FILE_LOG(logERROR, ("%s\n\n", initErrorMessage));
LOG(logERROR, ("%s\n\n", initErrorMessage));
initError = FAIL;
return;
}
@ -88,7 +88,7 @@ void basictests() {
int64_t client_sw_apiversion = getClientServerAPIVersion();
uint32_t requiredFirmwareVersion = REQRD_FRMWRE_VRSN;
FILE_LOG(logINFOBLUE, ("*************************************************\n"
LOG(logINFOBLUE, ("*************************************************\n"
"Hardware Version:\t\t 0x%x\n"
"Detector IP Addr:\t\t 0x%x\n"
@ -117,11 +117,11 @@ void basictests() {
//cant read versions
FILE_LOG(logINFO, ("Testing Firmware-software compatibility:\n"));
LOG(logINFO, ("Testing Firmware-software compatibility:\n"));
if(!fwversion || !sw_fw_apiversion){
strcpy(initErrorMessage,
"Cant read versions from FPGA. Please update firmware.\n");
FILE_LOG(logERROR, (initErrorMessage));
LOG(logERROR, (initErrorMessage));
initError = FAIL;
return;
}
@ -133,7 +133,7 @@ void basictests() {
"Please update detector software (min. 0x%llx) to be compatible with this firmware.\n",
(long long int)sw_fw_apiversion,
(long long int)requiredFirmwareVersion);
FILE_LOG(logERROR, (initErrorMessage));
LOG(logERROR, (initErrorMessage));
initError = FAIL;
return;
}
@ -145,11 +145,11 @@ void basictests() {
"Please update firmware (min. 0x%llx) to be compatible with this server.\n",
(long long int)fwversion,
(long long int)requiredFirmwareVersion);
FILE_LOG(logERROR, (initErrorMessage));
LOG(logERROR, (initErrorMessage));
initError = FAIL;
return;
}
FILE_LOG(logINFO, ("Compatibility - success\n"));
LOG(logINFO, ("Compatibility - success\n"));
#endif
}
@ -160,7 +160,7 @@ int checkType() {
#endif
u_int32_t type = ((bus_r(FPGA_VERSION_REG) & DETECTOR_TYPE_MSK) >> DETECTOR_TYPE_OFST);
if (type != MYTHEN3){
FILE_LOG(logERROR, ("This is not a Mythen3 firmware (read %d, expected %d)\n", type, MYTHEN3));
LOG(logERROR, ("This is not a Mythen3 firmware (read %d, expected %d)\n", type, MYTHEN3));
return FAIL;
}
@ -171,15 +171,15 @@ int testFpga() {
#ifdef VIRTUAL
return OK;
#endif
FILE_LOG(logINFO, ("Testing FPGA:\n"));
LOG(logINFO, ("Testing FPGA:\n"));
//fixed pattern
int ret = OK;
volatile u_int32_t val = bus_r(FIX_PATT_REG);
if (val == FIX_PATT_VAL) {
FILE_LOG(logINFO, ("Fixed pattern: successful match 0x%08x\n",val));
LOG(logINFO, ("Fixed pattern: successful match 0x%08x\n",val));
} else {
FILE_LOG(logERROR, ("Fixed pattern does not match! Read 0x%08x, expected 0x%08x\n", val, FIX_PATT_VAL));
LOG(logERROR, ("Fixed pattern does not match! Read 0x%08x, expected 0x%08x\n", val, FIX_PATT_VAL));
ret = FAIL;
}
return ret;
@ -189,7 +189,7 @@ int testBus() {
#ifdef VIRTUAL
return OK;
#endif
FILE_LOG(logINFO, ("Testing Bus:\n"));
LOG(logINFO, ("Testing Bus:\n"));
int ret = OK;
u_int32_t addr = DTA_OFFSET_REG;
@ -199,7 +199,7 @@ int testBus() {
for (i = 0; i < times; ++i) {
bus_w(addr, i * 100);
if (i * 100 != bus_r(addr)) {
FILE_LOG(logERROR, ("Mismatch! Wrote 0x%x, read 0x%x\n",
LOG(logERROR, ("Mismatch! Wrote 0x%x, read 0x%x\n",
i * 100, bus_r(addr)));
ret = FAIL;
}
@ -208,7 +208,7 @@ int testBus() {
bus_w(addr, 0);
if (ret == OK) {
FILE_LOG(logINFO, ("Successfully tested bus %d times\n", times));
LOG(logINFO, ("Successfully tested bus %d times\n", times));
}
return ret;
}
@ -294,7 +294,7 @@ u_int32_t getDetectorIP(){
}
strcpy(output,temp);
sscanf(output, "%x", &res);
//FILE_LOG(logINFO, ("ip:%x\n",res);
//LOG(logINFO, ("ip:%x\n",res);
return res;
}
@ -316,7 +316,7 @@ void initStopServer() {
usleep(CTRL_SRVR_INIT_TIME_US);
if (mapCSP0() == FAIL) {
FILE_LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
exit(EXIT_FAILURE);
}
}
@ -325,7 +325,7 @@ void initStopServer() {
/* set up detector */
void setupDetector() {
FILE_LOG(logINFO, ("This Server is for 1 Mythen3 module \n"));
LOG(logINFO, ("This Server is for 1 Mythen3 module \n"));
clkFrequency[READOUT_C0] = DEFAULT_READOUT_C0;
clkFrequency[READOUT_C1] = DEFAULT_READOUT_C1;
@ -380,7 +380,7 @@ void setupDetector() {
int setDefaultDacs() {
int ret = OK;
FILE_LOG(logINFOBLUE, ("Setting Default Dac values\n"));
LOG(logINFOBLUE, ("Setting Default Dac values\n"));
{
int i = 0;
const int defaultvals[NDAC] = DEFAULT_DAC_VALS;
@ -397,7 +397,7 @@ void cleanFifos() {
#ifdef VIRTUAL
return;
#endif
FILE_LOG(logINFO, ("Clearing Acquisition Fifos\n"));
LOG(logINFO, ("Clearing Acquisition Fifos\n"));
bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_CLR_ACQSTN_FIFO_MSK);
}
@ -405,7 +405,7 @@ void resetCore() {
#ifdef VIRTUAL
return;
#endif
FILE_LOG(logINFO, ("Resetting Core\n"));
LOG(logINFO, ("Resetting Core\n"));
bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_CRE_RST_MSK);
}
@ -413,7 +413,7 @@ void resetPeripheral() {
#ifdef VIRTUAL
return;
#endif
FILE_LOG(logINFO, ("Resetting Peripheral\n"));
LOG(logINFO, ("Resetting Peripheral\n"));
bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_PRPHRL_RST_MSK);
}
@ -437,7 +437,7 @@ int setDynamicRange(int dr){
regval = CONFIG_DYNAMIC_RANGE_24_VAL;
break;
default:
FILE_LOG(logERROR, ("Invalid dynamic range %d\n", dr));
LOG(logERROR, ("Invalid dynamic range %d\n", dr));
return -1;
}
// set it
@ -456,7 +456,7 @@ int setDynamicRange(int dr){
case CONFIG_DYNAMIC_RANGE_24_VAL:
return 32;
default:
FILE_LOG(logERROR, ("Invalid dynamic range %d read back\n", regval >> CONFIG_DYNAMIC_RANGE_OFST));
LOG(logERROR, ("Invalid dynamic range %d read back\n", regval >> CONFIG_DYNAMIC_RANGE_OFST));
return -1;
}
}
@ -466,7 +466,7 @@ int setDynamicRange(int dr){
void setNumFrames(int64_t val) {
if (val > 0) {
FILE_LOG(logINFO, ("Setting number of frames %lld\n", (long long int)val));
LOG(logINFO, ("Setting number of frames %lld\n", (long long int)val));
set64BitReg(val, SET_FRAMES_LSB_REG, SET_FRAMES_MSB_REG);
}
}
@ -477,7 +477,7 @@ int64_t getNumFrames() {
void setNumTriggers(int64_t val) {
if (val > 0) {
FILE_LOG(logINFO, ("Setting number of triggers %lld\n", (long long int)val));
LOG(logINFO, ("Setting number of triggers %lld\n", (long long int)val));
set64BitReg(val, SET_CYCLES_LSB_REG, SET_CYCLES_MSB_REG);
}
}
@ -488,10 +488,10 @@ int64_t getNumTriggers() {
int setExpTime(int64_t val) {
if (val < 0) {
FILE_LOG(logERROR, ("Invalid exptime: %lld ns\n", (long long int)val));
LOG(logERROR, ("Invalid exptime: %lld ns\n", (long long int)val));
return FAIL;
}
FILE_LOG(logINFO, ("Setting exptime %lld ns\n", (long long int)val));
LOG(logINFO, ("Setting exptime %lld ns\n", (long long int)val));
val *= (1E-9 * clkFrequency[SYSTEM_C0]);
setPatternWaitTime(0, val);
@ -510,10 +510,10 @@ int64_t getExpTime() {
int setPeriod(int64_t val) {
if (val < 0) {
FILE_LOG(logERROR, ("Invalid period: %lld ns\n", (long long int)val));
LOG(logERROR, ("Invalid period: %lld ns\n", (long long int)val));
return FAIL;
}
FILE_LOG(logINFO, ("Setting period %lld ns\n", (long long int)val));
LOG(logINFO, ("Setting period %lld ns\n", (long long int)val));
val *= (1E-9 * FIXED_PLL_FREQUENCY);
set64BitReg(val, SET_PERIOD_LSB_REG, SET_PERIOD_MSB_REG);
@ -537,7 +537,7 @@ void setCounterMask(uint32_t arg) {
countermask = arg;
// convert mask into number of counters (until firmware converts to mask)
int ncounters = __builtin_popcount(countermask);
FILE_LOG(logINFO, ("Setting number of counters to %d\n", ncounters));
LOG(logINFO, ("Setting number of counters to %d\n", ncounters));
uint32_t val = 0;
switch (ncounters) {
case 1:
@ -553,7 +553,7 @@ void setCounterMask(uint32_t arg) {
uint32_t addr = CONFIG_REG;
bus_w(addr, bus_r(addr) &~ CONFIG_COUNTER_ENA_MSK);
bus_w(addr, bus_r(addr) | val);
FILE_LOG(logDEBUG, ("Config Reg: 0x%x\n", bus_r(addr)));
LOG(logDEBUG, ("Config Reg: 0x%x\n", bus_r(addr)));
}
uint32_t getCounterMask() {
@ -592,10 +592,10 @@ uint32_t getCounterMask() {
int setDelayAfterTrigger(int64_t val) {
if (val < 0) {
FILE_LOG(logERROR, ("Invalid delay after trigger: %lld ns\n", (long long int)val));
LOG(logERROR, ("Invalid delay after trigger: %lld ns\n", (long long int)val));
return FAIL;
}
FILE_LOG(logINFO, ("Setting delay after trigger %lld ns\n", (long long int)val));
LOG(logINFO, ("Setting delay after trigger %lld ns\n", (long long int)val));
val *= (1E-9 * FIXED_PLL_FREQUENCY);
set64BitReg(val, SET_TRIGGER_DELAY_LSB_REG, SET_TRIGGER_DELAY_MSB_REG);
@ -649,11 +649,11 @@ void setDAC(enum DACINDEX ind, int val, int mV) {
}
char* dac_names[] = {DAC_NAMES};
FILE_LOG(logDEBUG1, ("Setting dac[%d - %s]: %d %s \n", (int)ind, dac_names[ind], val, (mV ? "mV" : "dac units")));
LOG(logDEBUG1, ("Setting dac[%d - %s]: %d %s \n", (int)ind, dac_names[ind], val, (mV ? "mV" : "dac units")));
int dacval = val;
#ifdef VIRTUAL
FILE_LOG(logINFO, ("Setting dac[%d - %s]: %d %s \n", (int)ind, dac_names[ind], val, (mV ? "mV" : "dac units")));
LOG(logINFO, ("Setting dac[%d - %s]: %d %s \n", (int)ind, dac_names[ind], val, (mV ? "mV" : "dac units")));
if (!mV) {
dacValues[ind] = val;
}
@ -670,12 +670,12 @@ void setDAC(enum DACINDEX ind, int val, int mV) {
int getDAC(enum DACINDEX ind, int mV) {
if (!mV) {
FILE_LOG(logDEBUG1, ("Getting DAC %d : %d dac\n",ind, dacValues[ind]));
LOG(logDEBUG1, ("Getting DAC %d : %d dac\n",ind, dacValues[ind]));
return dacValues[ind];
}
int voltage = -1;
LTC2620_D_DacToVoltage(dacValues[ind], &voltage);
FILE_LOG(logDEBUG1, ("Getting DAC %d : %d dac (%d mV)\n",ind, dacValues[ind], voltage));
LOG(logDEBUG1, ("Getting DAC %d : %d dac (%d mV)\n",ind, dacValues[ind], voltage));
return voltage;
}
@ -696,7 +696,7 @@ int setHighVoltage(int val){
// setting hv
if (val >= 0) {
FILE_LOG(logINFO, ("Setting High voltage: %d V\n", val));
LOG(logINFO, ("Setting High voltage: %d V\n", val));
DAC6571_Set(val);
highvoltage = val;
}
@ -709,15 +709,15 @@ void setTiming( enum timingMode arg){
if(arg != GET_TIMING_MODE){
switch (arg) {
case AUTO_TIMING:
FILE_LOG(logINFO, ("Set Timing: Auto\n"));
LOG(logINFO, ("Set Timing: Auto\n"));
bus_w(EXT_SIGNAL_REG, bus_r(EXT_SIGNAL_REG) & ~EXT_SIGNAL_MSK);
break;
case TRIGGER_EXPOSURE:
FILE_LOG(logINFO, ("Set Timing: Trigger\n"));
LOG(logINFO, ("Set Timing: Trigger\n"));
bus_w(EXT_SIGNAL_REG, bus_r(EXT_SIGNAL_REG) | EXT_SIGNAL_MSK);
break;
default:
FILE_LOG(logERROR, ("Unknown timing mode %d\n", arg));
LOG(logERROR, ("Unknown timing mode %d\n", arg));
}
}
}
@ -742,17 +742,17 @@ int configureMAC() {
char cDestIp[MAX_STR_LENGTH];
memset(cDestIp, 0, MAX_STR_LENGTH);
sprintf(cDestIp, "%d.%d.%d.%d", (dstip>>24)&0xff,(dstip>>16)&0xff,(dstip>>8)&0xff,(dstip)&0xff);
FILE_LOG(logINFO, ("1G UDP: Destination (IP: %s, port:%d)\n", cDestIp, dstport));
LOG(logINFO, ("1G UDP: Destination (IP: %s, port:%d)\n", cDestIp, dstport));
if (setUDPDestinationDetails(0, cDestIp, dstport) == FAIL) {
FILE_LOG(logERROR, ("could not set udp destination IP and port\n"));
LOG(logERROR, ("could not set udp destination IP and port\n"));
return FAIL;
}
#endif
FILE_LOG(logINFOBLUE, ("Configuring MAC\n"));
LOG(logINFOBLUE, ("Configuring MAC\n"));
FILE_LOG(logINFO, ("\tSource IP : %d.%d.%d.%d \t\t(0x%08x)\n",
LOG(logINFO, ("\tSource IP : %d.%d.%d.%d \t\t(0x%08x)\n",
(srcip>>24)&0xff,(srcip>>16)&0xff,(srcip>>8)&0xff,(srcip)&0xff, srcip));
FILE_LOG(logINFO, ("\tSource MAC : %02x:%02x:%02x:%02x:%02x:%02x \t(0x%010llx)\n",
LOG(logINFO, ("\tSource MAC : %02x:%02x:%02x:%02x:%02x:%02x \t(0x%010llx)\n",
(unsigned int)((srcmac>>40)&0xFF),
(unsigned int)((srcmac>>32)&0xFF),
(unsigned int)((srcmac>>24)&0xFF),
@ -760,11 +760,11 @@ int configureMAC() {
(unsigned int)((srcmac>>8)&0xFF),
(unsigned int)((srcmac>>0)&0xFF),
(long long unsigned int)srcmac));
FILE_LOG(logINFO, ("\tSource Port : %d \t\t\t(0x%08x)\n", srcport, srcport));
LOG(logINFO, ("\tSource Port : %d \t\t\t(0x%08x)\n", srcport, srcport));
FILE_LOG(logINFO, ("\tDest. IP : %d.%d.%d.%d \t\t(0x%08x)\n",
LOG(logINFO, ("\tDest. IP : %d.%d.%d.%d \t\t(0x%08x)\n",
(dstip>>24)&0xff,(dstip>>16)&0xff,(dstip>>8)&0xff,(dstip)&0xff, dstip));
FILE_LOG(logINFO, ("\tDest. MAC : %02x:%02x:%02x:%02x:%02x:%02x \t(0x%010llx)\n",
LOG(logINFO, ("\tDest. MAC : %02x:%02x:%02x:%02x:%02x:%02x \t(0x%010llx)\n",
(unsigned int)((dstmac>>40)&0xFF),
(unsigned int)((dstmac>>32)&0xFF),
(unsigned int)((dstmac>>24)&0xFF),
@ -772,7 +772,7 @@ int configureMAC() {
(unsigned int)((dstmac>>8)&0xFF),
(unsigned int)((dstmac>>0)&0xFF),
(long long unsigned int)dstmac));
FILE_LOG(logINFO, ("\tDest. Port : %d \t\t\t(0x%08x)\n\n",dstport, dstport));
LOG(logINFO, ("\tDest. Port : %d \t\t\t(0x%08x)\n\n",dstport, dstport));
// start addr
uint32_t addr = BASE_UDP_RAM;
@ -846,7 +846,7 @@ void calcChecksum(udp_header* udp) {
sum = (sum & 0xffff) + (sum >> 16);// Fold 32-bit sum to 16 bits
long int checksum = sum & 0xffff;
checksum += UDP_IP_HEADER_LENGTH_BYTES;
FILE_LOG(logINFO, ("\tIP checksum is 0x%lx\n",checksum));
LOG(logINFO, ("\tIP checksum is 0x%lx\n",checksum));
udp->ip_checksum = checksum;
}
@ -863,7 +863,7 @@ int setDetectorPosition(int pos[]) {
bus_w(addr, (bus_r(addr) &~COORD_ROW_MSK) | ((value << COORD_ROW_OFST) & COORD_ROW_MSK));
valueRead = ((bus_r(addr) & COORD_ROW_MSK) >> COORD_ROW_OFST);
if (valueRead != value) {
FILE_LOG(logERROR, ("Could not set row. Set %d, read %d\n", value, valueRead));
LOG(logERROR, ("Could not set row. Set %d, read %d\n", value, valueRead));
ret = FAIL;
}
@ -872,12 +872,12 @@ int setDetectorPosition(int pos[]) {
bus_w(addr, (bus_r(addr) &~COORD_COL_MSK) | ((value << COORD_COL_OFST) & COORD_COL_MSK));
valueRead = ((bus_r(addr) & COORD_COL_MSK) >> COORD_COL_OFST);
if (valueRead != value) {
FILE_LOG(logERROR, ("Could not set column. Set %d, read %d\n", value, valueRead));
LOG(logERROR, ("Could not set column. Set %d, read %d\n", value, valueRead));
ret = FAIL;
}
if (ret == OK) {
FILE_LOG(logINFO, ("\tPosition set to [%d, %d]\n", detPos[X], detPos[Y]));
LOG(logINFO, ("\tPosition set to [%d, %d]\n", detPos[X], detPos[Y]));
}
return ret;
@ -892,18 +892,18 @@ int* getDetectorPosition() {
uint64_t readPatternWord(int addr) {
// error (handled in tcp)
if (addr < 0 || addr >= MAX_PATTERN_LENGTH) {
FILE_LOG(logERROR, ("Cannot get Pattern - Word. Invalid addr 0x%x. "
LOG(logERROR, ("Cannot get Pattern - Word. Invalid addr 0x%x. "
"Should be between 0 and 0x%x\n", addr, MAX_PATTERN_LENGTH));
return -1;
}
FILE_LOG(logINFO, (" Reading Pattern Word (addr:0x%x)\n", addr));
LOG(logINFO, (" Reading Pattern Word (addr:0x%x)\n", addr));
uint32_t reg_lsb = PATTERN_STEP0_LSB_REG + addr * REG_OFFSET * 2; // the first word in RAM as base plus the offset of the word to write (addr)
uint32_t reg_msb = PATTERN_STEP0_MSB_REG + addr * REG_OFFSET * 2;
// read value
uint64_t retval = get64BitReg(reg_lsb, reg_msb);
FILE_LOG(logDEBUG1, (" Word(addr:0x%x) retval: 0x%llx\n", addr, (long long int) retval));
LOG(logDEBUG1, (" Word(addr:0x%x) retval: 0x%llx\n", addr, (long long int) retval));
return retval;
}
@ -915,18 +915,18 @@ uint64_t writePatternWord(int addr, uint64_t word) {
// error (handled in tcp)
if (addr < 0 || addr >= MAX_PATTERN_LENGTH) {
FILE_LOG(logERROR, ("Cannot set Pattern - Word. Invalid addr 0x%x. "
LOG(logERROR, ("Cannot set Pattern - Word. Invalid addr 0x%x. "
"Should be between 0 and 0x%x\n", addr, MAX_PATTERN_LENGTH));
return -1;
}
FILE_LOG(logINFO, ("Setting Pattern Word (addr:0x%x, word:0x%llx)\n", addr, (long long int) word));
LOG(logINFO, ("Setting Pattern Word (addr:0x%x, word:0x%llx)\n", addr, (long long int) word));
uint32_t reg_lsb = PATTERN_STEP0_LSB_REG + addr * REG_OFFSET * 2; // the first word in RAM as base plus the offset of the word to write (addr)
uint32_t reg_msb = PATTERN_STEP0_MSB_REG + addr * REG_OFFSET * 2;
// write word
set64BitReg(word, reg_lsb, reg_msb);
FILE_LOG(logDEBUG1, (" Wrote word. PatternIn Reg: 0x%llx\n", get64BitReg(reg_lsb, reg_msb)));
LOG(logDEBUG1, (" Wrote word. PatternIn Reg: 0x%llx\n", get64BitReg(reg_lsb, reg_msb)));
return readPatternWord(addr);
}
@ -935,7 +935,7 @@ int setPatternWaitAddress(int level, int addr) {
// error (handled in tcp)
if (addr >= MAX_PATTERN_LENGTH) {
FILE_LOG(logERROR, ("Cannot set Pattern Wait Address. Invalid addr 0x%x. "
LOG(logERROR, ("Cannot set Pattern Wait Address. Invalid addr 0x%x. "
"Should be between 0 and 0x%x\n", addr, MAX_PATTERN_LENGTH));
return -1;
}
@ -961,20 +961,20 @@ int setPatternWaitAddress(int level, int addr) {
mask = PATTERN_WAIT_2_ADDR_MSK;
break;
default:
FILE_LOG(logERROR, ("Cannot set Pattern Wait Address. Invalid level 0x%x. "
LOG(logERROR, ("Cannot set Pattern Wait Address. Invalid level 0x%x. "
"Should be between 0 and 2.\n", level));
return -1;
}
// set
if (addr >= 0) {
FILE_LOG(logINFO, ("Setting Pattern Wait Address (level:%d, addr:0x%x)\n", level, addr));
LOG(logINFO, ("Setting Pattern Wait Address (level:%d, addr:0x%x)\n", level, addr));
bus_w(reg, ((addr << offset) & mask));
}
// get
uint32_t regval = ((bus_r(reg) & mask) >> offset);
FILE_LOG(logDEBUG1, (" Wait Address retval (level:%d, addr:0x%x)\n", level, regval));
LOG(logDEBUG1, (" Wait Address retval (level:%d, addr:0x%x)\n", level, regval));
return regval;
}
@ -996,20 +996,20 @@ uint64_t setPatternWaitTime(int level, uint64_t t) {
regm = PATTERN_WAIT_TIMER_2_MSB_REG;
break;
default:
FILE_LOG(logERROR, ("Cannot set Pattern Wait Time. Invalid level %d. "
LOG(logERROR, ("Cannot set Pattern Wait Time. Invalid level %d. "
"Should be between 0 and 2.\n", level));
return -1;
}
// set
if ((int64_t)t >= 0) {
FILE_LOG(logINFO, ("Setting Pattern Wait Time (level:%d, t:%lld)\n", level, (long long int)t));
LOG(logINFO, ("Setting Pattern Wait Time (level:%d, t:%lld)\n", level, (long long int)t));
set64BitReg(t, regl, regm);
}
// get
uint64_t regval = get64BitReg(regl, regm);
FILE_LOG(logDEBUG1, (" Wait Time retval (level:%d, t:%lld)\n", level, (long long int)regval));
LOG(logDEBUG1, (" Wait Time retval (level:%d, t:%lld)\n", level, (long long int)regval));
return regval;
}
@ -1017,7 +1017,7 @@ void setPatternLoop(int level, int *startAddr, int *stopAddr, int *nLoop) {
// (checked at tcp)
if (*startAddr >= MAX_PATTERN_LENGTH || *stopAddr >= MAX_PATTERN_LENGTH) {
FILE_LOG(logERROR, ("Cannot set Pattern Loop, Address (startaddr:0x%x, stopaddr:0x%x) must be "
LOG(logERROR, ("Cannot set Pattern Loop, Address (startaddr:0x%x, stopaddr:0x%x) must be "
"less than 0x%x\n",
*startAddr, *stopAddr, MAX_PATTERN_LENGTH));
}
@ -1065,7 +1065,7 @@ void setPatternLoop(int level, int *startAddr, int *stopAddr, int *nLoop) {
break;
default:
// already checked at tcp interface
FILE_LOG(logERROR, ("Cannot set Pattern loop. Invalid level %d. "
LOG(logERROR, ("Cannot set Pattern loop. Invalid level %d. "
"Should be between -1 and 2.\n", level));
*startAddr = 0;
*stopAddr = 0;
@ -1076,7 +1076,7 @@ void setPatternLoop(int level, int *startAddr, int *stopAddr, int *nLoop) {
if (level >= 0) {
// set iteration
if (*nLoop >= 0) {
FILE_LOG(logINFO, ("Setting Pattern Loop (level:%d, nLoop:%d)\n",
LOG(logINFO, ("Setting Pattern Loop (level:%d, nLoop:%d)\n",
level, *nLoop));
bus_w(nLoopReg, *nLoop);
}
@ -1086,20 +1086,20 @@ void setPatternLoop(int level, int *startAddr, int *stopAddr, int *nLoop) {
// set
if (*startAddr >= 0 && *stopAddr >= 0) {
// writing start and stop addr
FILE_LOG(logINFO, ("Setting Pattern Loop (level:%d, startaddr:0x%x, stopaddr:0x%x)\n",
LOG(logINFO, ("Setting Pattern Loop (level:%d, startaddr:0x%x, stopaddr:0x%x)\n",
level, *startAddr, *stopAddr));
bus_w(addr, ((*startAddr << startOffset) & startMask) | ((*stopAddr << stopOffset) & stopMask));
FILE_LOG(logDEBUG1, ("Addr:0x%x, val:0x%x\n", addr, bus_r(addr)));
LOG(logDEBUG1, ("Addr:0x%x, val:0x%x\n", addr, bus_r(addr)));
}
// get
else {
*startAddr = ((bus_r(addr) & startMask) >> startOffset);
FILE_LOG(logDEBUG1, ("Getting Pattern Loop Start Address (level:%d, Read startAddr:0x%x)\n",
LOG(logDEBUG1, ("Getting Pattern Loop Start Address (level:%d, Read startAddr:0x%x)\n",
level, *startAddr));
*stopAddr = ((bus_r(addr) & stopMask) >> stopOffset);
FILE_LOG(logDEBUG1, ("Getting Pattern Loop Stop Address (level:%d, Read stopAddr:0x%x)\n",
LOG(logDEBUG1, ("Getting Pattern Loop Stop Address (level:%d, Read stopAddr:0x%x)\n",
level, *stopAddr));
}
}
@ -1121,27 +1121,27 @@ uint64_t getPatternBitMask() {
}
int checkDetectorType() {
FILE_LOG(logINFO, ("Checking type of module\n"));
LOG(logINFO, ("Checking type of module\n"));
FILE* fd = fopen(TYPE_FILE_NAME, "r");
if (fd == NULL) {
FILE_LOG(logERROR, ("Could not open file %s to get type of the module attached\n", TYPE_FILE_NAME));
LOG(logERROR, ("Could not open file %s to get type of the module attached\n", TYPE_FILE_NAME));
return -1;
}
char buffer[MAX_STR_LENGTH];
memset(buffer, 0, sizeof(buffer));
fread (buffer, MAX_STR_LENGTH, sizeof(char), fd);
if (strlen(buffer) == 0) {
FILE_LOG(logERROR, ("Could not read file %s to get type of the module attached\n", TYPE_FILE_NAME));
LOG(logERROR, ("Could not read file %s to get type of the module attached\n", TYPE_FILE_NAME));
return -1;
}
int type = atoi(buffer);
if (type > TYPE_NO_MODULE_STARTING_VAL) {
FILE_LOG(logERROR, ("No Module attached! Expected %d for Mythen, got %d\n", TYPE_MYTHEN3_MODULE_VAL, type));
LOG(logERROR, ("No Module attached! Expected %d for Mythen, got %d\n", TYPE_MYTHEN3_MODULE_VAL, type));
return -2;
}
if (abs(type - TYPE_MYTHEN3_MODULE_VAL) > TYPE_TOLERANCE) {
FILE_LOG(logERROR, ("Wrong Module attached! Expected %d for Mythen3, got %d\n", TYPE_MYTHEN3_MODULE_VAL, type));
LOG(logERROR, ("Wrong Module attached! Expected %d for Mythen3, got %d\n", TYPE_MYTHEN3_MODULE_VAL, type));
return FAIL;
}
return OK;
@ -1150,11 +1150,11 @@ int checkDetectorType() {
int powerChip (int on){
if(on != -1){
if(on){
FILE_LOG(logINFO, ("Powering chip: on\n"));
LOG(logINFO, ("Powering chip: on\n"));
bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_PWR_CHIP_MSK);
}
else{
FILE_LOG(logINFO, ("Powering chip: off\n"));
LOG(logINFO, ("Powering chip: off\n"));
bus_w(CONTROL_REG, bus_r(CONTROL_REG) & ~CONTROL_PWR_CHIP_MSK);
}
}
@ -1165,19 +1165,19 @@ int powerChip (int on){
int setPhase(enum CLKINDEX ind, int val, int degrees) {
if (ind < 0 || ind >= NUM_CLOCKS) {
FILE_LOG(logERROR, ("Unknown clock index %d to set phase\n", ind));
LOG(logERROR, ("Unknown clock index %d to set phase\n", ind));
return FAIL;
}
char* clock_names[] = {CLK_NAMES};
FILE_LOG(logINFOBLUE, ("Setting %s clock (%d) phase to %d %s\n", clock_names[ind], ind, val, degrees == 0 ? "" : "degrees"));
LOG(logINFOBLUE, ("Setting %s clock (%d) phase to %d %s\n", clock_names[ind], ind, val, degrees == 0 ? "" : "degrees"));
int maxShift = getMaxPhase(ind);
// validation
if (degrees && (val < 0 || val > 359)) {
FILE_LOG(logERROR, ("\tPhase outside limits (0 - 359°C)\n"));
LOG(logERROR, ("\tPhase outside limits (0 - 359°C)\n"));
return FAIL;
}
if (!degrees && (val < 0 || val > maxShift - 1)) {
FILE_LOG(logERROR, ("\tPhase outside limits (0 - %d phase shifts)\n", maxShift - 1));
LOG(logERROR, ("\tPhase outside limits (0 - %d phase shifts)\n", maxShift - 1));
return FAIL;
}
@ -1186,14 +1186,14 @@ int setPhase(enum CLKINDEX ind, int val, int degrees) {
if (degrees) {
ConvertToDifferentRange(0, 359, 0, maxShift - 1, val, &valShift);
}
FILE_LOG(logDEBUG1, ("\tphase shift: %d (degrees/shift: %d)\n", valShift, val));
LOG(logDEBUG1, ("\tphase shift: %d (degrees/shift: %d)\n", valShift, val));
int relativePhase = valShift - clkPhase[ind];
FILE_LOG(logDEBUG1, ("\trelative phase shift: %d (Current phase: %d)\n", relativePhase, clkPhase[ind]));
LOG(logDEBUG1, ("\trelative phase shift: %d (Current phase: %d)\n", relativePhase, clkPhase[ind]));
// same phase
if (!relativePhase) {
FILE_LOG(logINFO, ("\tNothing to do in Phase Shift\n"));
LOG(logINFO, ("\tNothing to do in Phase Shift\n"));
return OK;
}
@ -1212,7 +1212,7 @@ int setPhase(enum CLKINDEX ind, int val, int degrees) {
int getPhase(enum CLKINDEX ind, int degrees) {
if (ind < 0 || ind >= NUM_CLOCKS) {
FILE_LOG(logERROR, ("Unknown clock index %d to get phase\n", ind));
LOG(logERROR, ("Unknown clock index %d to get phase\n", ind));
return -1;
}
if (!degrees)
@ -1225,7 +1225,7 @@ int getPhase(enum CLKINDEX ind, int degrees) {
int getMaxPhase(enum CLKINDEX ind) {
if (ind < 0 || ind >= NUM_CLOCKS) {
FILE_LOG(logERROR, ("Unknown clock index %d to get max phase\n", ind));
LOG(logERROR, ("Unknown clock index %d to get max phase\n", ind));
return -1;
}
int vcofreq = getVCOFrequency(ind);
@ -1233,7 +1233,7 @@ int getMaxPhase(enum CLKINDEX ind) {
int ret = ((double)vcofreq / (double)clkFrequency[ind]) * maxshiftstep;
char* clock_names[] = {CLK_NAMES};
FILE_LOG(logDEBUG1, ("\tMax Phase Shift (%s): %d (Clock: %d Hz, VCO:%d Hz)\n",
LOG(logDEBUG1, ("\tMax Phase Shift (%s): %d (Clock: %d Hz, VCO:%d Hz)\n",
clock_names[ind], ret, clkFrequency[ind], vcofreq));
return ret;
@ -1241,13 +1241,13 @@ int getMaxPhase(enum CLKINDEX ind) {
int validatePhaseinDegrees(enum CLKINDEX ind, int val, int retval) {
if (ind < 0 || ind >= NUM_CLOCKS) {
FILE_LOG(logERROR, ("Unknown clock index %d to validate phase in degrees\n", ind));
LOG(logERROR, ("Unknown clock index %d to validate phase in degrees\n", ind));
return FAIL;
}
if (val == -1) {
return OK;
}
FILE_LOG(logDEBUG1, ("validating phase in degrees for clk %d\n", (int)ind));
LOG(logDEBUG1, ("validating phase in degrees for clk %d\n", (int)ind));
int maxShift = getMaxPhase(ind);
// convert degrees to shift
int valShift = 0;
@ -1264,7 +1264,7 @@ int validatePhaseinDegrees(enum CLKINDEX ind, int val, int retval) {
int getFrequency(enum CLKINDEX ind) {
if (ind < 0 || ind >= NUM_CLOCKS) {
FILE_LOG(logERROR, ("Unknown clock index %d to get frequency\n", ind));
LOG(logERROR, ("Unknown clock index %d to get frequency\n", ind));
return -1;
}
return clkFrequency[ind];
@ -1272,7 +1272,7 @@ int getFrequency(enum CLKINDEX ind) {
int getVCOFrequency(enum CLKINDEX ind) {
if (ind < 0 || ind >= NUM_CLOCKS) {
FILE_LOG(logERROR, ("Unknown clock index %d to get vco frequency\n", ind));
LOG(logERROR, ("Unknown clock index %d to get vco frequency\n", ind));
return -1;
}
int pllIndex = (int)(ind >= SYSTEM_C0 ? SYSTEM_PLL : READOUT_PLL);
@ -1285,7 +1285,7 @@ int getMaxClockDivider() {
int setClockDivider(enum CLKINDEX ind, int val) {
if (ind < 0 || ind >= NUM_CLOCKS) {
FILE_LOG(logERROR, ("Unknown clock index %d to set clock divider\n", ind));
LOG(logERROR, ("Unknown clock index %d to set clock divider\n", ind));
return FAIL;
}
if (val < 2 || val > getMaxClockDivider()) {
@ -1296,7 +1296,7 @@ int setClockDivider(enum CLKINDEX ind, int val) {
int currentdiv = vcofreq / (int)clkFrequency[ind];
int newfreq = vcofreq / val;
FILE_LOG(logINFO, ("\tSetting %s clock (%d) divider from %d (%d Hz) to %d (%d Hz). \n\t(Vcofreq: %d Hz)\n", clock_names[ind], ind, currentdiv, clkFrequency[ind], val, newfreq, vcofreq));
LOG(logINFO, ("\tSetting %s clock (%d) divider from %d (%d Hz) to %d (%d Hz). \n\t(Vcofreq: %d Hz)\n", clock_names[ind], ind, currentdiv, clkFrequency[ind], val, newfreq, vcofreq));
// Remembering old phases in degrees
int oldPhases[NUM_CLOCKS];
@ -1312,7 +1312,7 @@ int setClockDivider(enum CLKINDEX ind, int val) {
int clkIndex = (int)(ind >= SYSTEM_C0 ? ind - SYSTEM_C0 : ind);
ALTERA_PLL_C10_SetOuputFrequency (pllIndex, clkIndex, newfreq);
clkFrequency[ind] = newfreq;
FILE_LOG(logINFO, ("\t%s clock (%d) divider set to %d (%d Hz)\n", clock_names[ind], ind, val, clkFrequency[ind]));
LOG(logINFO, ("\t%s clock (%d) divider set to %d (%d Hz)\n", clock_names[ind], ind, val, clkFrequency[ind]));
// phase is reset by pll (when setting output frequency)
if (ind >= READOUT_C0) {
@ -1330,7 +1330,7 @@ int setClockDivider(enum CLKINDEX ind, int val) {
for (i = 0; i < NUM_CLOCKS; ++i) {
int currPhaseDeg = getPhase(i, 1);
if (oldPhases[i] != currPhaseDeg) {
FILE_LOG(logINFO, ("\tCorrecting %s clock (%d) phase from %d to %d degrees\n", clock_names[i], i, currPhaseDeg, oldPhases[i]));
LOG(logINFO, ("\tCorrecting %s clock (%d) phase from %d to %d degrees\n", clock_names[i], i, currPhaseDeg, oldPhases[i]));
setPhase(i, oldPhases[i], 1);
}
}
@ -1340,7 +1340,7 @@ int setClockDivider(enum CLKINDEX ind, int val) {
int getClockDivider(enum CLKINDEX ind) {
if (ind < 0 || ind >= NUM_CLOCKS) {
FILE_LOG(logERROR, ("Unknown clock index %d to get clock divider\n", ind));
LOG(logERROR, ("Unknown clock index %d to get clock divider\n", ind));
return -1;
}
return (getVCOFrequency(ind) / (int)clkFrequency[ind]);
@ -1354,25 +1354,25 @@ int startStateMachine(){
if(createUDPSocket(0) != OK) {
return FAIL;
}
FILE_LOG(logINFOBLUE, ("starting state machine\n"));
LOG(logINFOBLUE, ("starting state machine\n"));
// set status to running
virtual_status = 1;
virtual_stop = 0;
if(pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
FILE_LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
virtual_status = 0;
return FAIL;
}
FILE_LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
return OK;
#endif
FILE_LOG(logINFOBLUE, ("Starting State Machine\n"));
LOG(logINFOBLUE, ("Starting State Machine\n"));
cleanFifos();
//start state machine
bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_STRT_ACQSTN_MSK);
FILE_LOG(logINFO, ("Status Register: %08x\n",bus_r(STATUS_REG)));
LOG(logINFO, ("Status Register: %08x\n",bus_r(STATUS_REG)));
return OK;
}
@ -1440,7 +1440,7 @@ void* start_timer(void* arg) {
sendUDPPacket(0, packetData, packetsize);
}
}
FILE_LOG(logINFO, ("Sent frame: %d\n", frameNr));
LOG(logINFO, ("Sent frame: %d\n", frameNr));
// calculate time left in period
clock_gettime(CLOCK_REALTIME, &end);
@ -1460,52 +1460,52 @@ void* start_timer(void* arg) {
closeUDPSocket(0);
// set status to idle
virtual_status = 0;
FILE_LOG(logINFOBLUE, ("Finished Acquiring\n"));
LOG(logINFOBLUE, ("Finished Acquiring\n"));
return NULL;
}
#endif
int stopStateMachine(){
FILE_LOG(logINFORED, ("Stopping State Machine\n"));
LOG(logINFORED, ("Stopping State Machine\n"));
#ifdef VIRTUAL
virtual_stop = 0;
return OK;
#endif
//stop state machine
bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_STP_ACQSTN_MSK);
FILE_LOG(logINFO, ("Status Register: %08x\n", bus_r(STATUS_REG)));
LOG(logINFO, ("Status Register: %08x\n", bus_r(STATUS_REG)));
return OK;
}
enum runStatus getRunStatus(){
#ifdef VIRTUAL
if(virtual_status == 0){
FILE_LOG(logINFOBLUE, ("Status: IDLE\n"));
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
}else{
FILE_LOG(logINFOBLUE, ("Status: RUNNING\n"));
LOG(logINFOBLUE, ("Status: RUNNING\n"));
return RUNNING;
}
#endif
FILE_LOG(logDEBUG1, ("Getting status\n"));
LOG(logDEBUG1, ("Getting status\n"));
uint32_t retval = bus_r(PAT_STATUS_REG);
FILE_LOG(logINFO, ("Status Register: %08x\n",retval));
LOG(logINFO, ("Status Register: %08x\n",retval));
enum runStatus s;
//running
if (retval & PAT_STATUS_RUN_BUSY_MSK) {
if (retval & PAT_STATUS_WAIT_FOR_TRGGR_MSK) {
FILE_LOG(logINFOBLUE, ("Status: WAITING\n"));
LOG(logINFOBLUE, ("Status: WAITING\n"));
s = WAITING;
} else {
if (retval & PAT_STATUS_DLY_BFRE_TRGGR_MSK) {
FILE_LOG(logINFO, ("Status: Delay before Trigger\n"));
LOG(logINFO, ("Status: Delay before Trigger\n"));
} else if (retval & PAT_STATUS_DLY_AFTR_TRGGR_MSK) {
FILE_LOG(logINFO, ("Status: Delay after Trigger\n"));
LOG(logINFO, ("Status: Delay after Trigger\n"));
}
FILE_LOG(logINFOBLUE, ("Status: RUNNING\n"));
LOG(logINFOBLUE, ("Status: RUNNING\n"));
s = RUNNING;
}
}
@ -1514,16 +1514,16 @@ enum runStatus getRunStatus(){
else {
// stopped or error
if (retval & PAT_STATUS_FIFO_FULL_MSK) {
FILE_LOG(logINFOBLUE, ("Status: STOPPED\n")); //FIFO FULL??
LOG(logINFOBLUE, ("Status: STOPPED\n")); //FIFO FULL??
s = STOPPED;
} else if (retval & PAT_STATUS_CSM_BUSY_MSK) {
FILE_LOG(logINFOBLUE, ("Status: READ MACHINE BUSY\n"));
LOG(logINFOBLUE, ("Status: READ MACHINE BUSY\n"));
s = TRANSMITTING;
} else if (!retval) {
FILE_LOG(logINFOBLUE, ("Status: IDLE\n"));
LOG(logINFOBLUE, ("Status: IDLE\n"));
s = IDLE;
} else {
FILE_LOG(logERROR, ("Status: Unknown status %08x\n", retval));
LOG(logERROR, ("Status: Unknown status %08x\n", retval));
s = ERROR;
}
}
@ -1538,7 +1538,7 @@ void readFrame(int *ret, char *mess) {
}
#ifdef VIRTUAL
FILE_LOG(logINFOGREEN, ("acquisition successfully finished\n"));
LOG(logINFOGREEN, ("acquisition successfully finished\n"));
return;
#endif
@ -1547,9 +1547,9 @@ void readFrame(int *ret, char *mess) {
int64_t retval = getNumFramesLeft() + 1;
if ( retval > 0) {
FILE_LOG(logERROR, ("No data and run stopped: %lld frames left\n",(long long int)retval));
LOG(logERROR, ("No data and run stopped: %lld frames left\n",(long long int)retval));
} else {
FILE_LOG(logINFOGREEN, ("Acquisition successfully finished\n"));
LOG(logINFOGREEN, ("Acquisition successfully finished\n"));
}
}
@ -1558,7 +1558,7 @@ u_int32_t runBusy() {
return virtual_status;
#endif
u_int32_t s = (bus_r(PAT_STATUS_REG) & PAT_STATUS_RUN_BUSY_MSK);
//FILE_LOG(logDEBUG1, ("Status Register: %08x\n", s));
//LOG(logDEBUG1, ("Status Register: %08x\n", s));
return s;
}

View File

@ -28,7 +28,7 @@ logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4, logDEBUG5
#define ERROR_MSG_LENGTH 1000
#define FILE_LOG(lvl, fmt, ...) \
#define LOG(lvl, fmt, ...) \
if (lvl > FILELOG_MAX_LEVEL); \
else {char* temp = FILELOG_BuildLog fmt; FILELOG_PrintLog(lvl, temp);free(temp);}

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;
}