mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 21:37:13 +02:00
program fpga printouts for errors
This commit is contained in:
@ -1,9 +1,9 @@
|
|||||||
Path: slsDetectorPackage/slsDetectorServers/jungfrauDetectorServer
|
Path: slsDetectorPackage/slsDetectorServers/jungfrauDetectorServer
|
||||||
URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
|
URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
|
||||||
Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
|
Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
|
||||||
Repsitory UUID: ed9dc3b386898603d74a489528292139d47aac1a
|
Repsitory UUID: 969551ae373167dcfc28466f19e53a349da70f67
|
||||||
Revision: 32
|
Revision: 33
|
||||||
Branch: program
|
Branch: program
|
||||||
Last Changed Author: Erik_Frojdh
|
Last Changed Author: Dhanya_Thattil
|
||||||
Last Changed Rev: 4488
|
Last Changed Rev: 4489
|
||||||
Last Changed Date: 2019-03-29 14:42:42.000000002 +0100 ../slsDetectorServer/slsDetectorServer_funcs.c
|
Last Changed Date: 2019-04-01 09:39:27.000000002 +0200 ../slsDetectorServer/slsDetectorServer_funcs.c
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git"
|
#define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git"
|
||||||
#define GITREPUUID "ed9dc3b386898603d74a489528292139d47aac1a"
|
#define GITREPUUID "969551ae373167dcfc28466f19e53a349da70f67"
|
||||||
#define GITAUTH "Erik_Frojdh"
|
#define GITAUTH "Dhanya_Thattil"
|
||||||
#define GITREV 0x4488
|
#define GITREV 0x4489
|
||||||
#define GITDATE 0x20190329
|
#define GITDATE 0x20190401
|
||||||
#define GITBRANCH "program"
|
#define GITBRANCH "program"
|
||||||
|
@ -3279,106 +3279,101 @@ int program_fpga(int file_des) {
|
|||||||
// only set
|
// only set
|
||||||
if (Server_VerifyLock() == OK) {
|
if (Server_VerifyLock() == OK) {
|
||||||
|
|
||||||
|
FILE_LOG(logINFOBLUE, ("Programming FPGA...\n"));
|
||||||
|
|
||||||
|
size_t filesize = 0;
|
||||||
|
size_t totalsize = 0;
|
||||||
|
size_t unitprogramsize = 0;
|
||||||
|
char* fpgasrc = NULL;
|
||||||
|
FILE* fp = NULL;
|
||||||
|
|
||||||
|
// filesize
|
||||||
|
if (receiveData(file_des,&filesize,sizeof(filesize),INT32) < 0)
|
||||||
|
return printSocketReadError();
|
||||||
|
totalsize = filesize;
|
||||||
|
FILE_LOG(logDEBUG1, ("Total program size is: %d\n", totalsize));
|
||||||
|
|
||||||
// not in programming mode
|
// not in programming mode
|
||||||
if (debugflag != PROGRAMMING_MODE) {
|
/*if (debugflag != PROGRAMMING_MODE) {
|
||||||
//to receive any arguments
|
|
||||||
int n = 1;
|
|
||||||
while (n > 0)
|
|
||||||
n = receiveData(file_des, mess, MAX_STR_LENGTH, OTHER);
|
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
sprintf(mess,"FPGA cannot be programmed in this mode. "
|
sprintf(mess,"FPGA cannot be programmed in this mode. "
|
||||||
"Restart on-board detector server with -update for programming mode.\n");
|
"Restart on-board detector server with -update for programming mode.\n");
|
||||||
FILE_LOG(logERROR,(mess));
|
FILE_LOG(logERROR,(mess));
|
||||||
|
}*/
|
||||||
|
|
||||||
|
// opening file pointer to flash and telling FPGA to not touch flash
|
||||||
|
if (ret != FAIL && startWritingFPGAprogram(&fp) != OK) {
|
||||||
|
ret = FAIL;
|
||||||
|
sprintf(mess,"Could not write to flash. Error at startup.\n");
|
||||||
|
FILE_LOG(logERROR,(mess));
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
//---------------- first ret ----------------
|
||||||
FILE_LOG(logINFOBLUE, ("Programming FPGA...\n"));
|
Server_SendResult(file_des, INT32, NO_UPDATE, NULL, 0);
|
||||||
|
|
||||||
size_t filesize = 0;
|
if (ret != FAIL) {
|
||||||
size_t totalsize = 0;
|
//erasing flash
|
||||||
size_t unitprogramsize = 0;
|
eraseFlash();
|
||||||
char* fpgasrc = NULL;
|
fpgasrc = (char*)malloc(MAX_FPGAPROGRAMSIZE);
|
||||||
FILE* fp = NULL;
|
}
|
||||||
|
|
||||||
// filesize
|
//writing to flash part by part
|
||||||
if (receiveData(file_des,&filesize,sizeof(filesize),INT32) < 0)
|
while(ret != FAIL && filesize) {
|
||||||
|
|
||||||
|
unitprogramsize = MAX_FPGAPROGRAMSIZE; //2mb
|
||||||
|
if (unitprogramsize > filesize) //less than 2mb
|
||||||
|
unitprogramsize = filesize;
|
||||||
|
FILE_LOG(logDEBUG1, ("unit size to receive is:%d\n"
|
||||||
|
"filesize:%d\n", unitprogramsize, filesize));
|
||||||
|
|
||||||
|
|
||||||
|
//receive part of program
|
||||||
|
if (receiveData(file_des,fpgasrc,unitprogramsize,OTHER) < 0)
|
||||||
return printSocketReadError();
|
return printSocketReadError();
|
||||||
totalsize = filesize;
|
|
||||||
FILE_LOG(logDEBUG1, ("Total program size is: %d\n", totalsize));
|
|
||||||
|
|
||||||
// opening file pointer to flash and telling FPGA to not touch flash
|
if (!(unitprogramsize - filesize)) {
|
||||||
if (startWritingFPGAprogram(&fp) != OK) {
|
fpgasrc[unitprogramsize] = '\0';
|
||||||
ret = FAIL;
|
filesize -= unitprogramsize;
|
||||||
sprintf(mess,"Could not write to flash. Error at startup.\n");
|
unitprogramsize++;
|
||||||
FILE_LOG(logERROR,(mess));
|
} else
|
||||||
}
|
filesize -= unitprogramsize;
|
||||||
|
|
||||||
//---------------- first ret ----------------
|
// write part to flash
|
||||||
|
ret = writeFPGAProgram(fpgasrc, unitprogramsize, fp);
|
||||||
|
|
||||||
|
//---------------- middle rets ----------------
|
||||||
Server_SendResult(file_des, INT32, NO_UPDATE, NULL, 0);
|
Server_SendResult(file_des, INT32, NO_UPDATE, NULL, 0);
|
||||||
|
|
||||||
if (ret != FAIL) {
|
|
||||||
//erasing flash
|
|
||||||
eraseFlash();
|
|
||||||
fpgasrc = (char*)malloc(MAX_FPGAPROGRAMSIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
//writing to flash part by part
|
|
||||||
while(ret != FAIL && filesize) {
|
|
||||||
|
|
||||||
unitprogramsize = MAX_FPGAPROGRAMSIZE; //2mb
|
|
||||||
if (unitprogramsize > filesize) //less than 2mb
|
|
||||||
unitprogramsize = filesize;
|
|
||||||
FILE_LOG(logDEBUG1, ("unit size to receive is:%d\n"
|
|
||||||
"filesize:%d\n", unitprogramsize, filesize));
|
|
||||||
|
|
||||||
|
|
||||||
//receive part of program
|
if (ret == FAIL) {
|
||||||
if (receiveData(file_des,fpgasrc,unitprogramsize,OTHER) < 0)
|
FILE_LOG(logERROR, ("Failure: Breaking out of program receiving\n"));
|
||||||
return printSocketReadError();
|
} else {
|
||||||
|
//print progress
|
||||||
if (!(unitprogramsize - filesize)) {
|
FILE_LOG(logINFO, ("Writing to Flash:%d%%\r",
|
||||||
fpgasrc[unitprogramsize] = '\0';
|
(int) (((double)(totalsize-filesize)/totalsize)*100) ));
|
||||||
filesize -= unitprogramsize;
|
fflush(stdout);
|
||||||
unitprogramsize++;
|
|
||||||
} else
|
|
||||||
filesize -= unitprogramsize;
|
|
||||||
|
|
||||||
// write part to flash
|
|
||||||
ret = writeFPGAProgram(fpgasrc, unitprogramsize, fp);
|
|
||||||
|
|
||||||
//---------------- middle rets ----------------
|
|
||||||
Server_SendResult(file_des, INT32, NO_UPDATE, NULL, 0);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (ret == FAIL) {
|
|
||||||
FILE_LOG(logERROR, ("Failure: Breaking out of program receiving\n"));
|
|
||||||
} else {
|
|
||||||
//print progress
|
|
||||||
FILE_LOG(logINFO, ("Writing to Flash:%d%%\r",
|
|
||||||
(int) (((double)(totalsize-filesize)/totalsize)*100) ));
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
FILE_LOG(logINFO, ("Done copying program or due to failure earlier\n"));
|
|
||||||
|
|
||||||
// closing file pointer to flash and informing FPGA
|
|
||||||
stopWritingFPGAprogram(fp);
|
|
||||||
|
|
||||||
//free resources
|
|
||||||
if (fpgasrc != NULL)
|
|
||||||
free(fpgasrc);
|
|
||||||
if (fp != NULL)
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
FILE_LOG(logDEBUG1, ("Done with program receiving command\n"));
|
|
||||||
|
|
||||||
if (ret != FAIL && isControlServer) {
|
|
||||||
basictests();
|
|
||||||
initControlServer();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
printf("\n");
|
||||||
|
FILE_LOG(logINFO, ("Done copying program or due to failure earlier\n"));
|
||||||
|
|
||||||
|
// closing file pointer to flash and informing FPGA
|
||||||
|
stopWritingFPGAprogram(fp);
|
||||||
|
|
||||||
|
//free resources
|
||||||
|
if (fpgasrc != NULL)
|
||||||
|
free(fpgasrc);
|
||||||
|
if (fp != NULL)
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
FILE_LOG(logDEBUG1, ("Done with program receiving command\n"));
|
||||||
|
|
||||||
|
if (ret != FAIL && isControlServer) {
|
||||||
|
basictests();
|
||||||
|
initControlServer();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -3403,7 +3403,7 @@ int slsDetector::programFPGA(std::vector<char> buffer) {
|
|||||||
int fnum = F_PROGRAM_FPGA;
|
int fnum = F_PROGRAM_FPGA;
|
||||||
int ret = FAIL;
|
int ret = FAIL;
|
||||||
char mess[MAX_STR_LENGTH] = {0};
|
char mess[MAX_STR_LENGTH] = {0};
|
||||||
FILE_LOG(logINFO) << "Sending programming binary to detector " << detector_shm()->hostname;
|
FILE_LOG(logINFO) << "Sending programming binary to detector " << detId << " (" << detector_shm()->hostname << ")";
|
||||||
|
|
||||||
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
||||||
auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort);
|
auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort);
|
||||||
@ -3413,14 +3413,16 @@ int slsDetector::programFPGA(std::vector<char> buffer) {
|
|||||||
// opening error
|
// opening error
|
||||||
if (ret == FAIL) {
|
if (ret == FAIL) {
|
||||||
client.receiveData(mess, sizeof(mess));
|
client.receiveData(mess, sizeof(mess));
|
||||||
throw RuntimeError("Detector " + std::to_string(detId) +
|
std::ostringstream os;
|
||||||
" returned error: " + std::string(mess));
|
os << "Detector " << detId << " (" << detector_shm()->hostname << ")" <<
|
||||||
|
" returned error: " << mess;
|
||||||
|
throw RuntimeError(os.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// erasing flash
|
// erasing flash
|
||||||
if (ret != FAIL) {
|
if (ret != FAIL) {
|
||||||
FILE_LOG(logINFO) << "This can take awhile. Please be patient...";
|
FILE_LOG(logINFO) << "This can take awhile. Please be patient...";
|
||||||
FILE_LOG(logINFO) << detId << "Erasing Flash:";
|
FILE_LOG(logINFO) << "Erasing Flash for detector " << detId << " (" << detector_shm()->hostname << ")";
|
||||||
printf("%d%%\r", 0);
|
printf("%d%%\r", 0);
|
||||||
std::cout << std::flush;
|
std::cout << std::flush;
|
||||||
// erasing takes 65 seconds, printing here (otherwise need threads
|
// erasing takes 65 seconds, printing here (otherwise need threads
|
||||||
@ -3434,7 +3436,7 @@ int slsDetector::programFPGA(std::vector<char> buffer) {
|
|||||||
std::cout << std::flush;
|
std::cout << std::flush;
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
FILE_LOG(logINFO) << detId << "Writing to Flash:";
|
FILE_LOG(logINFO) << "Writing to Flash to detector " << detId << " (" << detector_shm()->hostname << ")";
|
||||||
printf("%d%%\r", 0);
|
printf("%d%%\r", 0);
|
||||||
std::cout << std::flush;
|
std::cout << std::flush;
|
||||||
}
|
}
|
||||||
@ -3464,8 +3466,10 @@ int slsDetector::programFPGA(std::vector<char> buffer) {
|
|||||||
} else {
|
} else {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
client.receiveData(mess, sizeof(mess));
|
client.receiveData(mess, sizeof(mess));
|
||||||
throw RuntimeError("Detector " + std::to_string(detId) +
|
std::ostringstream os;
|
||||||
" returned error: " + std::string(mess));
|
os << "Detector " << detId << " (" << detector_shm()->hostname << ")" <<
|
||||||
|
" returned error: " << mess;
|
||||||
|
throw RuntimeError(os.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@ -3476,8 +3480,10 @@ int slsDetector::programFPGA(std::vector<char> buffer) {
|
|||||||
client.receiveData(&ret, sizeof(ret));
|
client.receiveData(&ret, sizeof(ret));
|
||||||
if (ret == FAIL) {
|
if (ret == FAIL) {
|
||||||
client.receiveData(mess, sizeof(mess));
|
client.receiveData(mess, sizeof(mess));
|
||||||
throw RuntimeError("Detector " + std::to_string(detId) +
|
std::ostringstream os;
|
||||||
" returned error: " + std::string(mess));
|
os << "Detector " << detId << " (" << detector_shm()->hostname << ")" <<
|
||||||
|
" returned error: " << mess;
|
||||||
|
throw RuntimeError(os.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3495,8 +3501,10 @@ int slsDetector::programFPGA(std::vector<char> buffer) {
|
|||||||
stop.receiveData(&stopret, sizeof(stopret));
|
stop.receiveData(&stopret, sizeof(stopret));
|
||||||
if (stopret == FAIL) {
|
if (stopret == FAIL) {
|
||||||
client.receiveData(mess, sizeof(mess));
|
client.receiveData(mess, sizeof(mess));
|
||||||
throw RuntimeError("Detector " + std::to_string(detId) +
|
std::ostringstream os;
|
||||||
" returned error: " + std::string(mess));
|
os << "Detector " << detId << " (" << detector_shm()->hostname << ")" <<
|
||||||
|
" returned error: " << mess;
|
||||||
|
throw RuntimeError(os.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user