reset fpga implemented, changed receiver configuration warning prints, powerchip implemented

This commit is contained in:
Dhanya Maliakal 2016-11-03 12:31:34 +01:00
parent 0aecad6644
commit 4b99ff7fbe
14 changed files with 501 additions and 226 deletions

View File

@ -70,7 +70,8 @@ using namespace std;
#define PROGRAMMING_ERROR 0x0000000002000000ULL #define PROGRAMMING_ERROR 0x0000000002000000ULL
#define RECEIVER_ACTIVATE 0x0000000004000000ULL #define RECEIVER_ACTIVATE 0x0000000004000000ULL
#define DATA_STREAMING 0x0000000008000000ULL #define DATA_STREAMING 0x0000000008000000ULL
#define RESET_ERROR 0x0000000010000000ULL
#define POWER_CHIP 0x0000000020000000ULL
// 0x00000000FFFFFFFFULL // 0x00000000FFFFFFFFULL
/** @short class returning all error messages for error mask */ /** @short class returning all error messages for error mask */
class errorDefs { class errorDefs {
@ -218,7 +219,11 @@ public:
if(slsErrorMask&DATA_STREAMING) if(slsErrorMask&DATA_STREAMING)
retval.append("Could not set/reset Data Streaming\n"); retval.append("Could not set/reset Data Streaming\n");
if(slsErrorMask&RESET_ERROR)
retval.append("Could not reset the FPGA\n");
if(slsErrorMask&POWER_CHIP)
retval.append("Could not power on/off/get the chip\n");
//------------------------------------------------------ length of message //------------------------------------------------------ length of message

View File

@ -25,6 +25,9 @@
/** maximum rois */ /** maximum rois */
#define MAX_ROIS 100 #define MAX_ROIS 100
/** maximum unit size of program sent to detector */
#define MAX_FPGAPROGRAMSIZE (2 * 1024 *1024)
typedef char mystring[MAX_STR_LENGTH]; typedef char mystring[MAX_STR_LENGTH];
typedef double mysteps[MAX_SCAN_STEPS]; typedef double mysteps[MAX_SCAN_STEPS];

View File

@ -106,9 +106,9 @@ enum {
F_SET_NETWORK_PARAMETER, /**< set network parameters such as transmission delay, flow control */ F_SET_NETWORK_PARAMETER, /**< set network parameters such as transmission delay, flow control */
F_PROGRAM_FPGA /**< program FPGA */ F_PROGRAM_FPGA, /**< program FPGA */
F_RESET_FPGA, /**< reset FPGA */
F_POWER_CHIP /**< power chip */
/* Always append functions hereafter!!! */ /* Always append functions hereafter!!! */
}; };

View File

@ -7,6 +7,7 @@
#include "firmware_funcs.h" #include "firmware_funcs.h"
#include "mcb_funcs.h" #include "mcb_funcs.h"
#include "registers_m.h" #include "registers_m.h"
#include "gitInfoJungfrau.h"
//#define VERBOSE //#define VERBOSE
//#define VERYVERBOSE //#define VERYVERBOSE
@ -116,7 +117,7 @@ char mtdvalue[10];
int mapCSP0(void) { int mapCSP0(void) {
//printf("Mapping memory\n"); printf("Mapping memory\n");
#ifndef VIRTUAL #ifndef VIRTUAL
int fd; int fd;
fd = open("/dev/mem", O_RDWR | O_SYNC, 0); fd = open("/dev/mem", O_RDWR | O_SYNC, 0);
@ -163,6 +164,7 @@ void defineGPIOpins(){
} }
void resetFPGA(){ void resetFPGA(){
cprintf(BLUE,"\n*** Reseting FPGA ***\n");
FPGAdontTouchFlash(); FPGAdontTouchFlash();
FPGATouchFlash(); FPGATouchFlash();
} }
@ -177,7 +179,8 @@ void FPGATouchFlash(){
system("echo 1 > /sys/class/gpio/gpio9/value"); system("echo 1 > /sys/class/gpio/gpio9/value");
} }
void powerChip (int on){ int powerChip (int on){
if(on != -1){
if(on){ if(on){
printf("\nPowering on the chip\n"); printf("\nPowering on the chip\n");
bus_w(POWER_ON_REG,0x1); bus_w(POWER_ON_REG,0x1);
@ -188,6 +191,130 @@ void powerChip (int on){
} }
} }
return bus_r(POWER_ON_REG);
}
void initializeDetector(){
printf("Initializing Detector\n");
int i;
//printf("Bus test... ");
for (i=0; i<1000000; i++) {
bus_w(SET_DELAY_LSB_REG, i*100);
bus_r(FPGA_VERSION_REG);
if (i*100!=bus_r(SET_DELAY_LSB_REG))
cprintf(RED,"Bus Test ERROR: wrote 0x%x, read 0x%x\n",i*100,bus_r(SET_DELAY_LSB_REG));
}
//printf("Finished\n");
//confirm the detector type
if (((bus_r(PCB_REV_REG) & DETECTOR_TYPE_MASK)>>DETECTOR_TYPE_OFFSET) != JUNGFRAU_MODULE_ID){
cprintf(BG_RED,"This is not a Jungfrau Server (enum:%d)\n",myDetectorType);
exit(-1);
}
cprintf(BLUE,"\n\n********************************************************\n"
"*********************Jungfrau Server********************\n"
"********************************************************\n");
//print version
cprintf(BLUE,"\n"
"Firmware Version:\t 0x%x\n"
"Software Version:\t %llx\n"
//"F/w-S/w API Version:\t\t %lld\n"
//"Required Firmware Version:\t %d\n"
"Fixed Pattern:\t\t 0x%x\n"
"Board Revision:\t\t 0x%x\n"
"\n********************************************************\n",
bus_r(FPGA_VERSION_REG),(long long unsigned int)(((int64_t)SVNREV <<32) | (int64_t)SVNDATE)
//,sw_fw_apiversion, REQUIRED_FIRMWARE_VERSION
,bus_r(FIX_PATT_REG),(bus_r(PCB_REV_REG)&BOARD_REVISION_MASK)
);
printf("Resetting PLL\n");
resetPLL();
bus_w16(CONTROL_REG, SYNC_RESET);
bus_w16(CONTROL_REG, 0);
bus_w16(CONTROL_REG, GB10_RESET_BIT);
bus_w16(CONTROL_REG, 0);
#ifdef MCB_FUNCS
initDetector();
#endif
/*some registers set, which is in common with jungfrau, please check */
prepareADC();
/*some registers set, which is in common with jungfrau, please check */
initDac(0); initDac(8); //initializes the two dacs
//set dacs
printf("Setting Default Dac values\n");
enum dacNames{VB_COMP,VDD_PROT,VIN_COM,VREF_PRECH,VB_PIXBUF,VB_DS,VREF_DS,VREF_COMP};
int retval = -1;
int dacvalues[8][2]={
{VB_COMP, 1220},
{VDD_PROT, 3000},
{VIN_COM, 1053},
{VREF_PRECH,1450},
{VB_PIXBUF, 750},
{VB_DS, 1000},
{VREF_DS, 480},
{VREF_COMP, 420},
};
for(i=0;i<8;++i){
retval=setDac(dacvalues[i][0], dacvalues[i][1]);
if(retval!=dacvalues[i][1])
printf("Error: Setting dac %d failed, wrote %d, read %d\n",dacvalues[i][0],dacvalues[i][1],retval);
}
//done from config file
//printf("\nPowering on the chip\n");
//bus_w(POWER_ON_REG,0x1);
/* Only once */
bus_w(CONFGAIN_REG,0x0);
printf("Resetting ADC\n");
writeADC(ADCREG1,0x3); writeADC(ADCREG1,0x0);
writeADC(ADCREG2,0x40);
writeADC(ADCREG3,0xf);
writeADC(ADCREG4,0x3f);
printf("Configuring Vrefs\n");
writeADC(ADCREG_VREFS,0x2);
printf("Setting ADC Inversion\n");// (by trial and error)
bus_w(ADC_INVERSION_REG,0x453b2a9c);
adcPipeline(HALFSPEED_ADC_PIPELINE);
dbitPipeline(HALFSPEED_DBIT_PIPELINE);
adcPhase(HALFSPEED_ADC_PHASE); //set adc_clock_phase in unit of 1/(52) clock period (by trial and error)
printf("Reset mem machine fifos\n");
bus_w(MEM_MACHINE_FIFOS_REG,0x4000);
bus_w(MEM_MACHINE_FIFOS_REG,0x0);
printf("Reset run control\n");
bus_w(MEM_MACHINE_FIFOS_REG,0x0400);
bus_w(MEM_MACHINE_FIFOS_REG,0x0);
initSpeedConfGain(HALFSPEED_CONF);
setSettings(DYNAMICGAIN,-1);
//Initialization of acquistion parameters
setFrames(1*1000*1000);
setTrains(-1);
setExposureTime(10*1000);
setPeriod(2*1000*1000);
setDelay(0);
setGates(0);
setTiming(GET_EXTERNAL_COMMUNICATION_MODE);
setMaster(GET_MASTER);
setSynchronization(GET_SYNCHRONIZATION_MODE);
}
u_int16_t bus_r16(u_int32_t offset){ u_int16_t bus_r16(u_int32_t offset){

View File

@ -24,7 +24,10 @@
int mapCSP0(void); int mapCSP0(void);
void defineGPIOpins(); void defineGPIOpins();
void resetFPGA(); void resetFPGA();
void powerChip (int on); void FPGAdontTouchFlash();
void FPGATouchFlash();
int powerChip (int on);
void initializeDetector();
u_int16_t bus_r16(u_int32_t offset); u_int16_t bus_r16(u_int32_t offset);
u_int16_t bus_w16(u_int32_t offset, u_int16_t data);//aldos function u_int16_t bus_w16(u_int32_t offset, u_int16_t data);//aldos function

View File

@ -55,147 +55,25 @@ int adcvpp=0x4;
int init_detector(int b) { int init_detector(int b) {
if(b){ if(b){
defineGPIOpins(); defineGPIOpins();
resetFPGA(); resetFPGA();
usleep(250*1000); usleep(250*1000);
} }
int i;
if (mapCSP0()==FAIL) { if (mapCSP0()==FAIL) {
printf("Could not map memory\n"); printf("Could not map memory\n");
exit(1); exit(1);
} }
//------control server ------- if (b)
if (b) { initializeDetector();
//printf("Bus test... ");
for (i=0; i<1000000; i++) {
bus_w(SET_DELAY_LSB_REG, i*100);
bus_r(FPGA_VERSION_REG);
if (i*100!=bus_r(SET_DELAY_LSB_REG))
cprintf(RED,"Bus Test ERROR: wrote 0x%x, read 0x%x\n",i*100,bus_r(SET_DELAY_LSB_REG));
}
//printf("Finished\n");
//confirm the detector type
if (((bus_r(PCB_REV_REG) & DETECTOR_TYPE_MASK)>>DETECTOR_TYPE_OFFSET) != JUNGFRAU_MODULE_ID){
cprintf(BG_RED,"This is not a Jungfrau Server (enum:%d)\n",myDetectorType);
exit(-1);
}
cprintf(BLUE,"\n\n********************************************************\n"
"*********************Jungfrau Server********************\n"
"********************************************************\n");
//print version
cprintf(BLUE,"\n"
"Firmware Version:\t 0x%x\n"
"Software Version:\t %llx\n"
//"F/w-S/w API Version:\t\t %lld\n"
//"Required Firmware Version:\t %d\n"
"Fixed Pattern:\t\t 0x%x\n"
"Board Revision:\t\t 0x%x\n"
"\n********************************************************\n",
bus_r(FPGA_VERSION_REG),(long long unsigned int)(((int64_t)SVNREV <<32) | (int64_t)SVNDATE)
//,sw_fw_apiversion, REQUIRED_FIRMWARE_VERSION
,bus_r(FIX_PATT_REG),(bus_r(PCB_REV_REG)&BOARD_REVISION_MASK)
);
printf("Resetting PLL\n");
resetPLL();
bus_w16(CONTROL_REG, SYNC_RESET);
bus_w16(CONTROL_REG, 0);
bus_w16(CONTROL_REG, GB10_RESET_BIT);
bus_w16(CONTROL_REG, 0);
#ifdef MCB_FUNCS
initDetector();
#endif
printf("Initializing Detector\n");
/*some registers set, which is in common with jungfrau, please check */
prepareADC();
/*some registers set, which is in common with jungfrau, please check */
initDac(0); initDac(8); //initializes the two dacs
//set dacs
printf("Setting Default Dac values\n");
enum dacNames{VB_COMP,VDD_PROT,VIN_COM,VREF_PRECH,VB_PIXBUF,VB_DS,VREF_DS,VREF_COMP};
int retval = -1;
int dacvalues[8][2]={
{VB_COMP, 1220},
{VDD_PROT, 3000},
{VIN_COM, 1053},
{VREF_PRECH,1450},
{VB_PIXBUF, 750},
{VB_DS, 1000},
{VREF_DS, 480},
{VREF_COMP, 420},
};
for(i=0;i<8;++i){
retval=setDac(dacvalues[i][0], dacvalues[i][1]);
if(retval!=dacvalues[i][1])
printf("Error: Setting dac %d failed, wrote %d, read %d\n",dacvalues[i][0],dacvalues[i][1],retval);
}
printf("\nPowering on the chip\n");
bus_w(POWER_ON_REG,0x1);
/* Only once */
bus_w(CONFGAIN_REG,0x0);
printf("Resetting ADC\n");
writeADC(ADCREG1,0x3); writeADC(ADCREG1,0x0);
writeADC(ADCREG2,0x40);
writeADC(ADCREG3,0xf);
writeADC(ADCREG4,0x3f);
printf("Configuring Vrefs\n");
writeADC(ADCREG_VREFS,0x2);
printf("Setting ADC Inversion\n");// (by trial and error)
bus_w(ADC_INVERSION_REG,0x453b2a9c);
adcPipeline(HALFSPEED_ADC_PIPELINE);
dbitPipeline(HALFSPEED_DBIT_PIPELINE);
adcPhase(HALFSPEED_ADC_PHASE); //set adc_clock_phase in unit of 1/(52) clock period (by trial and error)
printf("Reset mem machine fifos\n");
bus_w(MEM_MACHINE_FIFOS_REG,0x4000);
bus_w(MEM_MACHINE_FIFOS_REG,0x0);
printf("Reset run control\n");
bus_w(MEM_MACHINE_FIFOS_REG,0x0400);
bus_w(MEM_MACHINE_FIFOS_REG,0x0);
initSpeedConfGain(HALFSPEED_CONF);
setSettings(DYNAMICGAIN,-1);
//Initialization of acquistion parameters
setFrames(1*1000*1000);
setTrains(-1);
setExposureTime(10*1000);
setPeriod(2*1000*1000);
setDelay(0);
setGates(0);
setTiming(GET_EXTERNAL_COMMUNICATION_MODE);
setMaster(GET_MASTER);
setSynchronization(GET_SYNCHRONIZATION_MODE);
}
//------ end of control server ------
//common for both control and stop server //common for both control and stop server
strcpy(mess,"dummy message"); strcpy(mess,"dummy message");
strcpy(lastClientIP,"none"); strcpy(lastClientIP,"none");
strcpy(thisClientIP,"none1"); strcpy(thisClientIP,"none1");
lockStatus=0; lockStatus=0;
return OK; return OK;
} }
@ -287,6 +165,9 @@ int function_table() {
flist[F_SET_CTB_PATTERN]=&set_ctb_pattern; flist[F_SET_CTB_PATTERN]=&set_ctb_pattern;
flist[F_WRITE_ADC_REG]=&write_adc_register; flist[F_WRITE_ADC_REG]=&write_adc_register;
flist[F_PROGRAM_FPGA]=&program_fpga; flist[F_PROGRAM_FPGA]=&program_fpga;
flist[F_RESET_FPGA]=&reset_fpga;
flist[F_POWER_CHIP]=&power_chip;
return OK; return OK;
} }
@ -3154,15 +3035,13 @@ int write_adc_register(int file_des) {
int program_fpga(int file_des) { int program_fpga(int file_des) {
int ret=OK; int ret=OK;
int n; int n;
const size_t maxprogramsize = 2 * 1024 *1024; sprintf(mess,"Program FPGA unsuccessful\n");
size_t unitprogramsize = 0; char* fpgasrc = NULL;
char* fpgasrc = (char*)malloc(maxprogramsize); FILE* fp = NULL;
size_t filesize = 0; size_t filesize = 0;
size_t unitprogramsize = 0;
size_t totalsize = 0; size_t totalsize = 0;
FILE* fp = NULL;
sprintf(mess,"Program FPGA\n");
//filesize //filesize
n = receiveDataOnly(file_des,&filesize,sizeof(filesize)); n = receiveDataOnly(file_des,&filesize,sizeof(filesize));
@ -3175,33 +3054,48 @@ int program_fpga(int file_des) {
printf("\n\n Total size is:%d\n",totalsize); printf("\n\n Total size is:%d\n",totalsize);
#endif #endif
//lock
if (ret==OK && differentClients==1 && lockStatus==1) {
ret=FAIL;
sprintf(mess,"Detector locked by %s\n",lastClientIP);
filesize = 0;
}
//opening file pointer to flash and telling FPGA to not touch flash //opening file pointer to flash and telling FPGA to not touch flash
if(startWritingFPGAprogram(&fp) != OK){ if(ret == OK && startWritingFPGAprogram(&fp) != OK){
sprintf(mess,"Could not write to flash. Error at startup.\n"); sprintf(mess,"Could not write to flash. Error at startup.\n");
cprintf(RED,"%s",mess); cprintf(RED,"%s",mess);
ret=FAIL; ret=FAIL;
filesize = 0; filesize = 0;
} }
//---------------- first ret ----------------
n = sendDataOnly(file_des,&ret,sizeof(ret)); n = sendDataOnly(file_des,&ret,sizeof(ret));
if (ret==FAIL) if (ret==FAIL)
n += sendDataOnly(file_des,mess,sizeof(mess)); n += sendDataOnly(file_des,mess,sizeof(mess));
//---------------- first ret ----------------
//erasing flash //erasing flash
if(ret != FAIL) if(ret != FAIL){
eraseFlash(); eraseFlash();
fpgasrc = (char*)malloc(MAX_FPGAPROGRAMSIZE);
}
//writing to flash part by part //writing to flash part by part
while(filesize){ while(ret != FAIL && filesize){
unitprogramsize = maxprogramsize; //2mb unitprogramsize = MAX_FPGAPROGRAMSIZE; //2mb
if(unitprogramsize > filesize) //less than 2mb if(unitprogramsize > filesize) //less than 2mb
unitprogramsize = filesize; unitprogramsize = filesize;
#ifdef VERY_VERBOSE #ifdef VERY_VERBOSE
printf("unit size to receive is:%d\n",unitprogramsize); printf("unit size to receive is:%d\n",unitprogramsize);
printf("filesize:%d currentpointer:%d\n",filesize,currentPointer); printf("filesize:%d currentpointer:%d\n",filesize,currentPointer);
#endif #endif
//receive //receive
n = receiveDataOnly(file_des,fpgasrc,unitprogramsize); n = receiveDataOnly(file_des,fpgasrc,unitprogramsize);
if (n < 0) { if (n < 0) {
@ -3210,6 +3104,7 @@ int program_fpga(int file_des) {
} }
if (ret==OK) {
if(!(unitprogramsize - filesize)){ if(!(unitprogramsize - filesize)){
fpgasrc[unitprogramsize]='\0'; fpgasrc[unitprogramsize]='\0';
filesize-=unitprogramsize; filesize-=unitprogramsize;
@ -3217,35 +3112,29 @@ int program_fpga(int file_des) {
}else }else
filesize-=unitprogramsize; filesize-=unitprogramsize;
if (ret==OK) {
if (differentClients==1 && lockStatus==1) {
ret=FAIL;
sprintf(mess,"Detector locked by %s\n",lastClientIP);
} else{
ret = writeFPGAProgram(fpgasrc,unitprogramsize,fp); ret = writeFPGAProgram(fpgasrc,unitprogramsize,fp);
} }
}
if(ret!=FAIL){
if (differentClients)
ret=FORCE_UPDATE;
}
/* send answer */ //---------------- middle rets ----------------
/* send OK/failed */
n = sendDataOnly(file_des,&ret,sizeof(ret)); n = sendDataOnly(file_des,&ret,sizeof(ret));
if (ret==FAIL) { if (ret==FAIL) {
n += sendDataOnly(file_des,mess,sizeof(mess)); n += sendDataOnly(file_des,mess,sizeof(mess));
cprintf(RED,"Failure: Breaking out of program receiving\n"); cprintf(RED,"Failure: Breaking out of program receiving\n");
break;
} }
//---------------- middle rets ----------------
if(ret != FAIL){
//print progress //print progress
printf("Writing to Flash:%d%%\r",(int) (((double)(totalsize-filesize)/totalsize)*100) ); printf("Writing to Flash:%d%%\r",(int) (((double)(totalsize-filesize)/totalsize)*100) );
fflush(stdout); fflush(stdout);
}
} }
printf("\n"); printf("\n");
//closing file pointer to flash and informing FPGA //closing file pointer to flash and informing FPGA
@ -3255,12 +3144,20 @@ int program_fpga(int file_des) {
ret=FAIL; ret=FAIL;
} }
if(ret!=FAIL){
ret=FORCE_UPDATE;
}
//---------------- last ret ----------------
n = sendDataOnly(file_des,&ret,sizeof(ret)); n = sendDataOnly(file_des,&ret,sizeof(ret));
if (ret==FAIL) if (ret==FAIL)
n += sendDataOnly(file_des,mess,sizeof(mess)); n += sendDataOnly(file_des,mess,sizeof(mess));
//---------------- last ret ----------------
//free resources //free resources
if(fpgasrc != NULL)
free(fpgasrc); free(fpgasrc);
if(fp!=NULL) if(fp!=NULL)
fclose(fp); fclose(fp);
@ -3270,3 +3167,73 @@ int program_fpga(int file_des) {
/*return ok/fail*/ /*return ok/fail*/
return ret; return ret;
} }
int reset_fpga(int file_des) {
int ret=OK;
int n;
sprintf(mess,"Reset FPGA unsuccessful\n");
resetFPGA();
usleep(250*1000);
initializeDetector();
ret = FORCE_UPDATE;
n = sendDataOnly(file_des,&ret,sizeof(ret));
if (ret==FAIL)
n += sendDataOnly(file_des,mess,sizeof(mess));
/*return ok/fail*/
return ret;
}
int power_chip(int file_des) {
int retval=-1;
int ret=OK;
int arg=-1;
int n;
n = receiveDataOnly(file_des,&arg,sizeof(arg));
if (n < 0) {
sprintf(mess,"Error reading from socket\n");
ret=FAIL;
}
#ifdef VERBOSE
printf("Power chip to %d\n", arg);
#endif
if (differentClients==1 && lockStatus==1 && arg!=-1) {
ret=FAIL;
sprintf(mess,"Detector locked by %s\n",lastClientIP);
} else {
retval=powerChip(arg);
#ifdef VERBOSE
printf("Chip powered: %d\n",retval);
#endif
if (retval==arg || arg<0) {
ret=OK;
} else {
ret=FAIL;
printf("Powering chip failed, wrote %d but read %d\n", arg, retval);
}
}
if (ret==OK && differentClients==1)
ret=FORCE_UPDATE;
/* send answer */
n = sendDataOnly(file_des,&ret,sizeof(ret));
if (ret==FAIL) {
n += sendDataOnly(file_des,mess,sizeof(mess));
} else
n += sendDataOnly(file_des,&retval,sizeof(retval));
return ret;
}

View File

@ -97,4 +97,6 @@ int set_ctb_pattern(int);
int write_adc_register(int);; int write_adc_register(int);;
int program_fpga(int); int program_fpga(int);
int reset_fpga(int);
int power_chip(int);
#endif #endif

View File

@ -3965,7 +3965,7 @@ int multiSlsDetector::programFPGA(string fname){
ret=detectors[i]->programFPGA(fname); ret=detectors[i]->programFPGA(fname);
if(detectors[i]->getErrorMask()) if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i)); setErrorMask(getErrorMask()|(1<<i));
if (ret!=OK) if (ret==FAIL)
ret1=FAIL; ret1=FAIL;
} }
} }
@ -3974,6 +3974,39 @@ int multiSlsDetector::programFPGA(string fname){
int multiSlsDetector::resetFPGA(){
int ret=OK, ret1=OK;
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
if (detectors[i]) {
ret=detectors[i]->resetFPGA();
if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
if (ret==FAIL)
ret1=FAIL;
}
}
return ret1;
}
int multiSlsDetector::powerChip(int ival){
int ret=OK, ret1=OK;
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
if (detectors[i]) {
ret=detectors[i]->powerChip(ival);
if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
if (ret==FAIL)
ret1=FAIL;
}
}
return ret1;
}
int multiSlsDetector::loadSettingsFile(string fname, int imod) { int multiSlsDetector::loadSettingsFile(string fname, int imod) {
int id, im, ret=OK; int id, im, ret=OK;

View File

@ -494,6 +494,17 @@ class multiSlsDetector : public slsDetectorUtils {
*/ */
int programFPGA(string fname); int programFPGA(string fname);
/** resets FPGA
\returns OK or FAIL
*/
int resetFPGA();
/** power on/off the chip
\param ival on is 1, off is 0, -1 to get
\returns OK or FAIL
*/
int powerChip(int ival= -1);
/** loads the modules settings/trimbits reading from a file - file name extension is automatically generated! */ /** loads the modules settings/trimbits reading from a file - file name extension is automatically generated! */
int loadSettingsFile(string fname, int nmod=0); int loadSettingsFile(string fname, int nmod=0);

View File

@ -5499,7 +5499,7 @@ char* slsDetector::setDetectorMAC(string detectorMAC){
(detectorMAC[11]==':')&&(detectorMAC[14]==':')){ (detectorMAC[11]==':')&&(detectorMAC[14]==':')){
strcpy(thisDetector->detectorMAC,detectorMAC.c_str()); strcpy(thisDetector->detectorMAC,detectorMAC.c_str());
if(!strcmp(thisDetector->receiver_hostname,"none")) if(!strcmp(thisDetector->receiver_hostname,"none"))
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl; std::cout << "Warning: Receiver hostname not set yet." << endl;
else if(setUDPConnection()==FAIL) else if(setUDPConnection()==FAIL)
std::cout<< "Warning: UDP connection set up failed" << std::endl; std::cout<< "Warning: UDP connection set up failed" << std::endl;
}else{ }else{
@ -5526,7 +5526,7 @@ char* slsDetector::setDetectorIP(string detectorIP){
if(result!=0){ if(result!=0){
strcpy(thisDetector->detectorIP,detectorIP.c_str()); strcpy(thisDetector->detectorIP,detectorIP.c_str());
if(!strcmp(thisDetector->receiver_hostname,"none")) if(!strcmp(thisDetector->receiver_hostname,"none"))
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl; std::cout << "Warning: Receiver hostname not set yet." << endl;
else if(setUDPConnection()==FAIL) else if(setUDPConnection()==FAIL)
std::cout<< "Warning: UDP connection set up failed" << std::endl; std::cout<< "Warning: UDP connection set up failed" << std::endl;
}else{ }else{
@ -5618,7 +5618,7 @@ char* slsDetector::setReceiverUDPIP(string udpip){
}else{ }else{
strcpy(thisDetector->receiverUDPIP,udpip.c_str()); strcpy(thisDetector->receiverUDPIP,udpip.c_str());
if(!strcmp(thisDetector->receiver_hostname,"none")) if(!strcmp(thisDetector->receiver_hostname,"none"))
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl; std::cout << "Warning: Receiver hostname not set yet." << endl;
else if(setUDPConnection()==FAIL){ else if(setUDPConnection()==FAIL){
std::cout<< "Warning: UDP connection set up failed" << std::endl; std::cout<< "Warning: UDP connection set up failed" << std::endl;
} }
@ -5641,7 +5641,7 @@ char* slsDetector::setReceiverUDPMAC(string udpmac){
(udpmac[11]==':')&&(udpmac[14]==':')){ (udpmac[11]==':')&&(udpmac[14]==':')){
strcpy(thisDetector->receiverUDPMAC,udpmac.c_str()); strcpy(thisDetector->receiverUDPMAC,udpmac.c_str());
if(!strcmp(thisDetector->receiver_hostname,"none")) if(!strcmp(thisDetector->receiver_hostname,"none"))
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl; std::cout << "Warning: Receiver hostname not set yet." << endl;
else if(setUDPConnection()==FAIL){ else if(setUDPConnection()==FAIL){
std::cout<< "Warning: UDP connection set up failed" << std::endl; std::cout<< "Warning: UDP connection set up failed" << std::endl;
} }
@ -5660,7 +5660,7 @@ char* slsDetector::setReceiverUDPMAC(string udpmac){
int slsDetector::setReceiverUDPPort(int udpport){ int slsDetector::setReceiverUDPPort(int udpport){
thisDetector->receiverUDPPort = udpport; thisDetector->receiverUDPPort = udpport;
if(!strcmp(thisDetector->receiver_hostname,"none")) if(!strcmp(thisDetector->receiver_hostname,"none"))
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl; std::cout << "Warning: Receiver hostname not set yet." << endl;
else if(setUDPConnection()==FAIL){ else if(setUDPConnection()==FAIL){
std::cout<< "Warning: UDP connection set up failed" << std::endl; std::cout<< "Warning: UDP connection set up failed" << std::endl;
} }
@ -5670,7 +5670,7 @@ int slsDetector::setReceiverUDPPort(int udpport){
int slsDetector::setReceiverUDPPort2(int udpport){ int slsDetector::setReceiverUDPPort2(int udpport){
thisDetector->receiverUDPPort2 = udpport; thisDetector->receiverUDPPort2 = udpport;
if(!strcmp(thisDetector->receiver_hostname,"none")) if(!strcmp(thisDetector->receiver_hostname,"none"))
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl; std::cout << "Warning: Receiver hostname not set yet." << endl;
else if(setUDPConnection()==FAIL){ else if(setUDPConnection()==FAIL){
std::cout<< "Warning: UDP connection set up failed" << std::endl; std::cout<< "Warning: UDP connection set up failed" << std::endl;
} }
@ -5724,7 +5724,7 @@ int slsDetector::setUDPConnection(){
//called before set up //called before set up
if(!strcmp(thisDetector->receiver_hostname,"none")){ if(!strcmp(thisDetector->receiver_hostname,"none")){
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl; std::cout << "Warning: Receiver hostname not set yet." << endl;
return FAIL; return FAIL;
} }
@ -6430,12 +6430,18 @@ int slsDetector::writeSettingsFile(string fname, int imod, int* iodelay){
int slsDetector::programFPGA(string fname){ int slsDetector::programFPGA(string fname){
int ret=FAIL; int ret=FAIL;
int fnum=F_PROGRAM_FPGA;
char mess[MAX_STR_LENGTH]="";
int64_t retval = -1;
size_t filesize=0;
char* fpgasrc = NULL;
if(thisDetector->myDetectorType != JUNGFRAU){ if(thisDetector->myDetectorType != JUNGFRAU){
std::cout << "Not implemented for this detector" << std::endl; std::cout << "Not implemented for this detector" << std::endl;
return FAIL; return FAIL;
} }
//check if it exists //check if it exists
struct stat st; struct stat st;
if(stat(fname.c_str(),&st)){ if(stat(fname.c_str(),&st)){
@ -6443,7 +6449,6 @@ int slsDetector::programFPGA(string fname){
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
return FAIL; return FAIL;
} }
//create destination file name,replaces original filename with Jungfrau.rawbin //create destination file name,replaces original filename with Jungfrau.rawbin
string destfname; string destfname;
size_t found = fname.find_last_of("/\\"); size_t found = fname.find_last_of("/\\");
@ -6452,8 +6457,6 @@ int slsDetector::programFPGA(string fname){
else else
destfname = fname.substr(0,found+1); destfname = fname.substr(0,found+1);
destfname.append("Jungfrau_MCB.rawbin"); destfname.append("Jungfrau_MCB.rawbin");
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "Converting " << fname << " to " << destfname << std::endl; std::cout << "Converting " << fname << " to " << destfname << std::endl;
#endif #endif
@ -6470,11 +6473,9 @@ int slsDetector::programFPGA(string fname){
for (filepos=0x80; filepos < 0x1000000; filepos++) { for (filepos=0x80; filepos < 0x1000000; filepos++) {
x = fgetc(src); x = fgetc(src);
if (x < 0) break; if (x < 0) break;
y=0; y=0;
for (i=0; i < 8; i++) for (i=0; i < 8; i++)
y=y| ( (( x & (1<<i) ) >> i) << (7-i) ); // This swaps the bits y=y| ( (( x & (1<<i) ) >> i) << (7-i) ); // This swaps the bits
fputc(y,dst); fputc(y,dst);
} }
if (filepos < 0x1000000){ if (filepos < 0x1000000){
@ -6485,7 +6486,6 @@ int slsDetector::programFPGA(string fname){
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "File has been converted to " << destfname << std::endl; std::cout << "File has been converted to " << destfname << std::endl;
#endif #endif
//loading file to memory //loading file to memory
FILE* fp = fopen(destfname.c_str(),"r"); FILE* fp = fopen(destfname.c_str(),"r");
if(fp == NULL){ if(fp == NULL){
@ -6498,14 +6498,14 @@ int slsDetector::programFPGA(string fname){
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
return FAIL; return FAIL;
} }
size_t filesize = ftell(fp); filesize = ftell(fp);
if(filesize == -1){ if(filesize <= 0){
std::cout << "Could not get length of rawbin file" << std::endl; std::cout << "Could not get length of rawbin file" << std::endl;
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
return FAIL; return FAIL;
} }
rewind(fp); rewind(fp);
char* fpgasrc = (char*)malloc(filesize+1); fpgasrc = (char*)malloc(filesize+1);
if(fpgasrc == NULL){ if(fpgasrc == NULL){
std::cout << "Could not allocate size of program" << std::endl; std::cout << "Could not allocate size of program" << std::endl;
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
@ -6526,14 +6526,8 @@ int slsDetector::programFPGA(string fname){
std::cout << "Successfully loaded the rawbin file to program memory" << std::endl; std::cout << "Successfully loaded the rawbin file to program memory" << std::endl;
#endif #endif
const size_t maxprogramsize = 2 * 1024 *1024;
size_t unitprogramsize = 0;
int currentPointer = 0;
size_t totalsize = filesize;
int fnum=F_PROGRAM_FPGA;
char mess[MAX_STR_LENGTH]="";
int64_t retval = -1;
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "Sending programming binary to detector " << endl; std::cout<< "Sending programming binary to detector " << endl;
#endif #endif
@ -6541,7 +6535,6 @@ int slsDetector::programFPGA(string fname){
if (connectControl() == OK){ if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->SendDataOnly(&filesize,sizeof(filesize)); controlSocket->SendDataOnly(&filesize,sizeof(filesize));
//check opening error //check opening error
controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==FAIL) { if (ret==FAIL) {
@ -6551,6 +6544,8 @@ int slsDetector::programFPGA(string fname){
filesize = 0; filesize = 0;
} }
//erasing flash
if(ret!=FAIL){ if(ret!=FAIL){
std::cout<< "This can take awhile. Please be patient..." << endl; std::cout<< "This can take awhile. Please be patient..." << endl;
printf("Erasing Flash:%d%%\r",0); printf("Erasing Flash:%d%%\r",0);
@ -6568,10 +6563,14 @@ int slsDetector::programFPGA(string fname){
std::cout << flush; std::cout << flush;
} }
//sending program in parts of 2mb each
while(filesize > 0){
unitprogramsize = maxprogramsize; //2mb //sending program in parts of 2mb each
size_t unitprogramsize = 0;
int currentPointer = 0;
size_t totalsize= filesize;
while(ret != FAIL && (filesize > 0)){
unitprogramsize = MAX_FPGAPROGRAMSIZE; //2mb
if(unitprogramsize > filesize) //less than 2mb if(unitprogramsize > filesize) //less than 2mb
unitprogramsize = filesize; unitprogramsize = filesize;
#ifdef VERBOSE #ifdef VERBOSE
@ -6579,20 +6578,18 @@ int slsDetector::programFPGA(string fname){
#endif #endif
controlSocket->SendDataOnly(fpgasrc+currentPointer,unitprogramsize); controlSocket->SendDataOnly(fpgasrc+currentPointer,unitprogramsize);
controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==FAIL) { if (ret!=FAIL) {
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
//stops writing
break;
}
filesize-=unitprogramsize; filesize-=unitprogramsize;
currentPointer+=unitprogramsize; currentPointer+=unitprogramsize;
//print progress //print progress
printf("Writing to Flash:%d%%\r",(int) (((double)(totalsize-filesize)/totalsize)*100)); printf("Writing to Flash:%d%%\r",(int) (((double)(totalsize-filesize)/totalsize)*100));
std::cout << flush; std::cout << flush;
}else{
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
}
} }
std::cout<<std::endl; std::cout<<std::endl;
@ -6603,8 +6600,6 @@ int slsDetector::programFPGA(string fname){
std::cout<< "Detector returned error: " << mess << std::endl; std::cout<< "Detector returned error: " << mess << std::endl;
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
} }
disconnectControl(); disconnectControl();
if (ret==FORCE_UPDATE) if (ret==FORCE_UPDATE)
updateDetector(); updateDetector();
@ -6612,13 +6607,81 @@ int slsDetector::programFPGA(string fname){
} }
//free resources //free resources
if(fpgasrc != NULL)
free(fpgasrc); free(fpgasrc);
return ret; return ret;
} }
int slsDetector::resetFPGA(){
int ret=FAIL;
int fnum=F_RESET_FPGA;
char mess[MAX_STR_LENGTH]="";
if(thisDetector->myDetectorType != JUNGFRAU){
std::cout << "Not implemented for this detector" << std::endl;
return FAIL;
}
#ifdef VERBOSE
std::cout<< "Sending reset to FPGA " << endl;
#endif
if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
//check opening error
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==FAIL) {
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
setErrorMask((getErrorMask())|(RESET_ERROR));
}
disconnectControl();
if (ret==FORCE_UPDATE)
updateDetector();
}
}
return ret;
}
int slsDetector::powerChip(int ival){
int ret=FAIL;
int fnum=F_POWER_CHIP;
char mess[MAX_STR_LENGTH]="";
int retval=-1;
if(thisDetector->myDetectorType != JUNGFRAU){
std::cout << "Not implemented for this detector" << std::endl;
return FAIL;
}
#ifdef VERBOSE
std::cout<< "Sending power on/off/get to the chip " << endl;
#endif
if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->SendDataOnly(&ival,sizeof(ival));
//check opening error
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==FAIL) {
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
setErrorMask((getErrorMask())|(POWER_CHIP));
}else
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
disconnectControl();
if (ret==FORCE_UPDATE)
updateDetector();
}
}
return retval;
}
int slsDetector::loadSettingsFile(string fname, int imod) { int slsDetector::loadSettingsFile(string fname, int imod) {
sls_detector_module *myMod=NULL; sls_detector_module *myMod=NULL;

View File

@ -528,6 +528,18 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
*/ */
int programFPGA(string fname); int programFPGA(string fname);
/** resets FPGA
\returns OK or FAIL
*/
int resetFPGA();
/** power on/off the chip
\param ival on is 1, off is 0, -1 to get
\returns OK or FAIL
*/
int powerChip(int ival= -1);
/** loads the modules settings/trimbits reading from a file /** loads the modules settings/trimbits reading from a file
\param fname file name . If not specified, extension is automatically generated! \param fname file name . If not specified, extension is automatically generated!
\param imod module number, -1 means all modules \param imod module number, -1 means all modules

View File

@ -441,10 +441,23 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAdvanced; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAdvanced;
i++; i++;
/* fpga */
descrToFuncMap[i].m_pFuncName="programfpga"; descrToFuncMap[i].m_pFuncName="programfpga";
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAdvanced; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAdvanced;
i++; i++;
descrToFuncMap[i].m_pFuncName="resetfpga";
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAdvanced;
i++;
/* chip */
descrToFuncMap[i].m_pFuncName="powerchip";
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAdvanced;
i++;
/* versions/ serial numbers getId */ /* versions/ serial numbers getId */
descrToFuncMap[i].m_pFuncName="moduleversion"; // descrToFuncMap[i].m_pFuncName="moduleversion"; //
@ -4352,25 +4365,52 @@ string slsDetectorCommand::cmdAdvanced(int narg, char *args[], int action) {
return myDet->externalSignalType(myDet->setExternalSignalFlags(flag,is)); return myDet->externalSignalType(myDet->setExternalSignalFlags(flag,is));
} else if (cmd=="programfpga") { }
else if (cmd=="programfpga") {
if (action==GET_ACTION) if (action==GET_ACTION)
return string("cannot get"); return string("cannot get");
if (narg<2)
return string("wrong usage: should specify programming file");
if(strstr(args[1],".pof")==NULL) if(strstr(args[1],".pof")==NULL)
return string("wrong usage: should specify programming file with .pof extension"); return string("wrong usage: programming file should have .pof extension");
string sval=string(args[1]); string sval=string(args[1]);
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< " programming file " << sval << std::endl; std::cout<< " programming file " << sval << std::endl;
#endif #endif
myDet->setOnline(ONLINE_FLAG);
if(myDet->programFPGA(sval) == OK) if(myDet->programFPGA(sval) == OK)
return string("programming successful"); return string("successful");
return string("programming unsuccessful"); return string("unsuccessful");
}
else if (cmd=="resetfpga") {
if (action==GET_ACTION)
return string("cannot get");
#ifdef VERBOSE
std::cout<< " resetting fpga " << sval << std::endl;
#endif
myDet->setOnline(ONLINE_FLAG);
if(myDet->resetFPGA() == OK)
return string("successful");
return string("unsuccessful");
}
else if (cmd=="powerchip") {
char ans[100];
myDet->setOnline(ONLINE_FLAG);
if (action==PUT_ACTION){
int ival = -1;
if (!sscanf(args[1],"%d",&ival))
return string("could not scan powerchip parameter " + string(args[1]));
myDet->powerChip(ival);
}
sprintf(ans,"%d",myDet->powerChip());
return string(ans);
} }
else else
return string("could not decode flag ")+cmd; return string("unknown command ")+cmd;
} }
@ -4382,8 +4422,8 @@ string slsDetectorCommand::helpAdvanced(int narg, char *args[], int action) {
os << "extsig:i mode \t sets the mode of the external signal i. can be \n \t \t \t off, \n \t \t \t gate_in_active_high, \n \t \t \t gate_in_active_low, \n \t \t \t trigger_in_rising_edge, \n \t \t \t trigger_in_falling_edge, \n \t \t \t ro_trigger_in_rising_edge, \n \t \t \t ro_trigger_in_falling_edge, \n \t \t \t gate_out_active_high, \n \t \t \t gate_out_active_low, \n \t \t \t trigger_out_rising_edge, \n \t \t \t trigger_out_falling_edge, \n \t \t \t ro_trigger_out_rising_edge, \n \t \t \t ro_trigger_out_falling_edge" << std::endl; os << "extsig:i mode \t sets the mode of the external signal i. can be \n \t \t \t off, \n \t \t \t gate_in_active_high, \n \t \t \t gate_in_active_low, \n \t \t \t trigger_in_rising_edge, \n \t \t \t trigger_in_falling_edge, \n \t \t \t ro_trigger_in_rising_edge, \n \t \t \t ro_trigger_in_falling_edge, \n \t \t \t gate_out_active_high, \n \t \t \t gate_out_active_low, \n \t \t \t trigger_out_rising_edge, \n \t \t \t trigger_out_falling_edge, \n \t \t \t ro_trigger_out_rising_edge, \n \t \t \t ro_trigger_out_falling_edge" << std::endl;
os << "flags mode \t sets the readout flags to mode. can be none, storeinram, tot, continous, parallel, nonparallel, safe, unknown" << std::endl; os << "flags mode \t sets the readout flags to mode. can be none, storeinram, tot, continous, parallel, nonparallel, safe, unknown" << std::endl;
os << "programfpga f \t programs the fpga with file f with .pof" << std::endl; os << "programfpga f \t programs the fpga with file f (with .pof extension)." << std::endl;
os << "resetfpga f \t resets fpga, f can be any value" << std::endl;
} }
if (action==GET_ACTION || action==HELP_ACTION) { if (action==GET_ACTION || action==HELP_ACTION) {

View File

@ -497,7 +497,16 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
*/ */
virtual int programFPGA(string fname)=0; virtual int programFPGA(string fname)=0;
/** resets FPGA
\returns OK or FAIL
*/
virtual int resetFPGA()=0;
/** power on/off the chip
\param ival on is 1, off is 0, -1 to get
\returns OK or FAIL
*/
virtual int powerChip(int ival= -1)=0;
/** saves the modules settings/trimbits writing to a file /** saves the modules settings/trimbits writing to a file
\param fname file name . Axtension is automatically generated! \param fname file name . Axtension is automatically generated!