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

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

View File

@ -528,6 +528,18 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
*/
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
\param fname file name . If not specified, extension is automatically generated!
\param imod module number, -1 means all modules

View File

@ -441,10 +441,23 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAdvanced;
i++;
/* fpga */
descrToFuncMap[i].m_pFuncName="programfpga";
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAdvanced;
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 */
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));
} else if (cmd=="programfpga") {
}
else if (cmd=="programfpga") {
if (action==GET_ACTION)
return string("cannot get");
if (narg<2)
return string("wrong usage: should specify programming file");
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]);
#ifdef VERBOSE
std::cout<< " programming file " << sval << std::endl;
#endif
myDet->setOnline(ONLINE_FLAG);
if(myDet->programFPGA(sval) == OK)
return string("programming successful");
return string("programming unsuccessful");
return string("successful");
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
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 << "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) {

View File

@ -497,7 +497,16 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
*/
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
\param fname file name . Axtension is automatically generated!