mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-14 13:57:13 +02:00
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -40,8 +40,10 @@ int startWritingFPGAprogram(FILE **filefp);
|
|||||||
* When done writing the program, close file pointer and
|
* When done writing the program, close file pointer and
|
||||||
* notify FPGA to pick up the program from flash
|
* notify FPGA to pick up the program from flash
|
||||||
* @param filefp pointer to flash
|
* @param filefp pointer to flash
|
||||||
|
* @return 0 for success, 1 for fail (time taken for fpga to touch flash
|
||||||
|
* exceeded)
|
||||||
*/
|
*/
|
||||||
void stopWritingFPGAprogram(FILE *filefp);
|
int stopWritingFPGAprogram(FILE *filefp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write FPGA Program to flash
|
* Write FPGA Program to flash
|
||||||
|
@ -7,7 +7,8 @@
|
|||||||
#include <unistd.h> // usleep
|
#include <unistd.h> // usleep
|
||||||
|
|
||||||
/* global variables */
|
/* global variables */
|
||||||
#define MTDSIZE 10
|
#define MTDSIZE 10
|
||||||
|
#define MAX_TIME_FPGA_TOUCH_FLASH_US (10 * 1000 * 1000) // 10s
|
||||||
|
|
||||||
int gpioDefined = 0;
|
int gpioDefined = 0;
|
||||||
char mtdvalue[MTDSIZE] = {0};
|
char mtdvalue[MTDSIZE] = {0};
|
||||||
@ -99,32 +100,36 @@ int startWritingFPGAprogram(FILE **filefp) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopWritingFPGAprogram(FILE *filefp) {
|
int stopWritingFPGAprogram(FILE *filefp) {
|
||||||
LOG(logDEBUG1, ("Stopping of writing FPGA program\n"));
|
LOG(logDEBUG1, ("Stopping of writing FPGA program\n"));
|
||||||
|
|
||||||
int wait = 0;
|
|
||||||
if (filefp != NULL) {
|
if (filefp != NULL) {
|
||||||
fclose(filefp);
|
fclose(filefp);
|
||||||
wait = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// touch and program
|
// touch and program
|
||||||
FPGATouchFlash();
|
FPGATouchFlash();
|
||||||
|
|
||||||
if (wait) {
|
LOG(logINFO, ("Waiting for FPGA to program from flash\n"));
|
||||||
LOG(logDEBUG1, ("Waiting for FPGA to program from flash\n"));
|
// waiting for success or done
|
||||||
// waiting for success or done
|
char output[255];
|
||||||
char output[255];
|
int res = 0;
|
||||||
int res = 0;
|
int timeSpent = 0;
|
||||||
while (res == 0) {
|
while (res == 0) {
|
||||||
FILE *sysFile = popen("cat /sys/class/gpio/gpio7/value", "r");
|
// time taken for fpga to pick up from flash
|
||||||
fgets(output, sizeof(output), sysFile);
|
usleep(1000);
|
||||||
pclose(sysFile);
|
timeSpent += 1000;
|
||||||
sscanf(output, "%d", &res);
|
if (timeSpent >= MAX_TIME_FPGA_TOUCH_FLASH_US) {
|
||||||
LOG(logDEBUG1, ("gpi07 returned %d\n", res));
|
return 1;
|
||||||
}
|
}
|
||||||
|
FILE *sysFile = popen("cat /sys/class/gpio/gpio7/value", "r");
|
||||||
|
fgets(output, sizeof(output), sysFile);
|
||||||
|
pclose(sysFile);
|
||||||
|
sscanf(output, "%d", &res);
|
||||||
|
LOG(logDEBUG1, ("gpi07 returned %d\n", res));
|
||||||
}
|
}
|
||||||
LOG(logINFO, ("FPGA has picked up the program from flash\n"));
|
LOG(logINFO, ("FPGA has picked up the program from flash\n"));
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int writeFPGAProgram(char *fpgasrc, uint64_t fsize, FILE *filefp) {
|
int writeFPGAProgram(char *fpgasrc, uint64_t fsize, FILE *filefp) {
|
||||||
|
@ -3719,6 +3719,7 @@ int program_fpga(int file_des) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// writing to flash part by part
|
// writing to flash part by part
|
||||||
|
int clientSocketCrash = 0;
|
||||||
while (ret != FAIL && filesize) {
|
while (ret != FAIL && filesize) {
|
||||||
|
|
||||||
unitprogramsize = MAX_FPGAPROGRAMSIZE; // 2mb
|
unitprogramsize = MAX_FPGAPROGRAMSIZE; // 2mb
|
||||||
@ -3729,42 +3730,61 @@ int program_fpga(int file_des) {
|
|||||||
(long long unsigned int)filesize));
|
(long long unsigned int)filesize));
|
||||||
|
|
||||||
// receive part of program
|
// receive part of program
|
||||||
if (receiveData(file_des, fpgasrc, unitprogramsize, OTHER) < 0)
|
if (receiveData(file_des, fpgasrc, unitprogramsize, OTHER) < 0) {
|
||||||
return printSocketReadError();
|
printSocketReadError();
|
||||||
|
clientSocketCrash = 1;
|
||||||
|
ret = FAIL;
|
||||||
|
}
|
||||||
|
// client has not crashed yet, so write to flash and send ret
|
||||||
|
else {
|
||||||
|
if (!(unitprogramsize - filesize)) {
|
||||||
|
fpgasrc[unitprogramsize] = '\0';
|
||||||
|
filesize -= unitprogramsize;
|
||||||
|
unitprogramsize++;
|
||||||
|
} else
|
||||||
|
filesize -= unitprogramsize;
|
||||||
|
|
||||||
if (!(unitprogramsize - filesize)) {
|
// write part to flash
|
||||||
fpgasrc[unitprogramsize] = '\0';
|
ret = writeFPGAProgram(fpgasrc, unitprogramsize, fp);
|
||||||
filesize -= unitprogramsize;
|
Server_SendResult(file_des, INT32, NULL, 0);
|
||||||
unitprogramsize++;
|
if (ret == FAIL) {
|
||||||
} else
|
strcpy(mess, "Could not write to flash. Breaking out of "
|
||||||
filesize -= unitprogramsize;
|
"program receiving. Try to flash again "
|
||||||
|
"without rebooting.\n");
|
||||||
// write part to flash
|
LOG(logERROR, (mess));
|
||||||
ret = writeFPGAProgram(fpgasrc, unitprogramsize, fp);
|
} else {
|
||||||
Server_SendResult(file_des, INT32, NULL, 0);
|
// print progress
|
||||||
if (ret == FAIL) {
|
LOG(logINFO,
|
||||||
LOG(logERROR, ("Failure: Breaking out of program receiving\n"));
|
("Writing to Flash:%d%%\r",
|
||||||
} else {
|
(int)(((double)(totalsize - filesize) / totalsize) *
|
||||||
// print progress
|
100)));
|
||||||
LOG(logINFO,
|
fflush(stdout);
|
||||||
("Writing to Flash:%d%%\r",
|
}
|
||||||
(int)(((double)(totalsize - filesize) / totalsize) *
|
|
||||||
100)));
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == OK) {
|
if (ret == OK) {
|
||||||
LOG(logINFO, ("Done copying program\n"));
|
LOG(logINFO, ("Done copying program\n"));
|
||||||
|
// closing file pointer to flash and informing FPGA
|
||||||
|
ret = stopWritingFPGAprogram(fp);
|
||||||
|
if (ret == FAIL) {
|
||||||
|
strcpy(mess, "Failed to program fpga. FPGA is taking too long "
|
||||||
|
"to pick up program from flash! Try to flash "
|
||||||
|
"again without rebooting!\n");
|
||||||
|
LOG(logERROR, (mess));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// closing file pointer to flash and informing FPGA
|
|
||||||
stopWritingFPGAprogram(fp);
|
|
||||||
|
|
||||||
// free resources
|
// free resources
|
||||||
free(fpgasrc);
|
free(fpgasrc);
|
||||||
if (fp != NULL)
|
if (fp != NULL)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
|
// send final ret (if no client crash)
|
||||||
|
if (clientSocketCrash == 0) {
|
||||||
|
Server_SendResult(file_des, INT32, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // end of Blackfin programming
|
#endif // end of Blackfin programming
|
||||||
if (ret == FAIL) {
|
if (ret == FAIL) {
|
||||||
LOG(logERROR, ("Program FPGA FAIL!\n"));
|
LOG(logERROR, ("Program FPGA FAIL!\n"));
|
||||||
|
@ -3166,6 +3166,15 @@ void Module::programFPGAviaBlackfin(std::vector<char> buffer) {
|
|||||||
std::cout << std::flush;
|
std::cout << std::flush;
|
||||||
}
|
}
|
||||||
std::cout << '\n';
|
std::cout << '\n';
|
||||||
|
|
||||||
|
// fpga has picked up from flash successfully
|
||||||
|
if (client.Receive<int>() == FAIL) {
|
||||||
|
std::ostringstream os;
|
||||||
|
os << "Detector " << moduleId << " (" << shm()->hostname << ")"
|
||||||
|
<< " returned error: " << client.readErrorMessage();
|
||||||
|
throw RuntimeError(os.str());
|
||||||
|
}
|
||||||
|
|
||||||
LOG(logINFO) << "FPGA programmed successfully";
|
LOG(logINFO) << "FPGA programmed successfully";
|
||||||
rebootController();
|
rebootController();
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
#define APILIB 0x201008
|
#define APILIB 0x201008
|
||||||
#define APIRECEIVER 0x201008
|
#define APIRECEIVER 0x201008
|
||||||
#define APIGUI 0x201009
|
#define APIGUI 0x201009
|
||||||
#define APICTB 0x201009
|
|
||||||
#define APIGOTTHARD 0x201009
|
|
||||||
#define APIGOTTHARD2 0x201009
|
|
||||||
#define APIJUNGFRAU 0x201009
|
|
||||||
#define APIMOENCH 0x201009
|
|
||||||
#define APIEIGER 0x201009
|
#define APIEIGER 0x201009
|
||||||
#define APIMYTHEN3 0x201015
|
#define APICTB 0x201016
|
||||||
|
#define APIGOTTHARD 0x201016
|
||||||
|
#define APIGOTTHARD2 0x201016
|
||||||
|
#define APIJUNGFRAU 0x201016
|
||||||
|
#define APIMYTHEN3 0x201016
|
||||||
|
#define APIMOENCH 0x201013
|
||||||
|
Reference in New Issue
Block a user