works for niosg

This commit is contained in:
maliakal_d 2021-09-14 10:30:04 +02:00
parent b2cb99a0c2
commit 0f8869153e
6 changed files with 55 additions and 10 deletions

View File

@ -3711,14 +3711,14 @@ int program_fpga(int file_des) {
// receive program
if (ret == OK) {
char *fpgasrc = malloc(filesize);
if (receiveData(file_des, fpgasrc, filesize, OTHER) < 0)
if (receiveData(file_des, fpgasrc, filesize, OTHER) < 0) {
free(fpgasrc);
return printSocketReadError();
}
#ifndef VIRTUAL
ret = eraseAndWriteToFlash(mess, checksum, fpgasrc, filesize);
#endif
Server_SendResult(file_des, INT32, NULL, 0);
// free resources
free(fpgasrc);
}
if (ret == FAIL) {

View File

@ -1241,7 +1241,7 @@ int DetectorImpl::kbhit() {
}
std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
/* // validate type of file
// validate type of file
bool isPof = false;
switch (multi_shm()->multiDetectorType) {
case JUNGFRAU:
@ -1361,9 +1361,10 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
throw RuntimeError("Program FPGA: Could not close destination file");
}
LOG(logINFOBLUE) << "File has been converted to " << destfname;
*/
// loading dst file to memory
FILE *fp = fopen("/tmp/SLS_DET_MCB.tzgmUT", "r");
// FILE *fp = fopen("/tmp/SLS_DET_MCB.tzgmUT", "r");
FILE *fp = fopen(destfname, "r");
if (fp == nullptr) {
throw RuntimeError("Program FPGA: Could not open rawbin file");
}

View File

@ -3477,7 +3477,7 @@ void Module::programFPGAviaBlackfin(std::vector<char> buffer) {
LOG(logINFO) << "Checksum verified for module " << moduleIndex << " ("
<< shm()->hostname << ")";
// erasing flash
// simulating erasing flash
{
LOG(logINFO) << "Erasing Flash for module " << moduleIndex << " ("
<< shm()->hostname << ")";
@ -3533,6 +3533,7 @@ void Module::programFPGAviaNios(std::vector<char> buffer) {
strcpy(cChecksum, checksum.c_str());
client.Send(cChecksum);
// validate file size before sending program
if (client.Receive<int>() == FAIL) {
std::ostringstream os;
os << "Detector " << moduleIndex << " (" << shm()->hostname << ")"
@ -3540,6 +3541,49 @@ void Module::programFPGAviaNios(std::vector<char> buffer) {
throw RuntimeError(os.str());
}
client.Send(buffer);
// simulating erasing flash
{
LOG(logINFO) << "(Simulating) Erasing Flash for module " << moduleIndex << " ("
<< shm()->hostname << ")";
printf("%d%%\r", 0);
std::cout << std::flush;
// erasing takes 10 seconds, printing here (otherwise need threads
// in server-unnecessary)
const int ERASE_TIME = 10;
int count = ERASE_TIME + 1;
while (count > 0) {
std::this_thread::sleep_for(std::chrono::seconds(1));
--count;
printf(
"%d%%\r",
static_cast<int>(
(static_cast<double>(ERASE_TIME - count) / ERASE_TIME) * 100));
std::cout << std::flush;
}
printf("\n");
}
// simulating writing to flash
{
LOG(logINFO) << "(Simulating) Writing to Flash for module " << moduleIndex << " (" << shm()->hostname << ")";
printf("%d%%\r", 0);
std::cout << std::flush;
// writing takes 45 seconds, printing here (otherwise need threads
// in server-unnecessary)
const int ERASE_TIME = 45;
int count = ERASE_TIME + 1;
while (count > 0) {
std::this_thread::sleep_for(std::chrono::seconds(1));
--count;
printf(
"%d%%\r",
static_cast<int>(
(static_cast<double>(ERASE_TIME - count) / ERASE_TIME) * 100));
std::cout << std::flush;
}
printf("\n");
}
if (client.Receive<int>() == FAIL) {
std::ostringstream os;
os << "Detector " << moduleIndex << " (" << shm()->hostname << ")"
@ -3547,6 +3591,6 @@ void Module::programFPGAviaNios(std::vector<char> buffer) {
throw RuntimeError(os.str());
}
LOG(logINFO) << "FPGA programmed successfully";
rebootController();
//rebootController();
}
} // namespace sls

View File

@ -6,8 +6,8 @@
#define APICTB 0x210909
#define APIGOTTHARD 0x210909
#define APIGOTTHARD2 0x210909
#define APIJUNGFRAU 0x210909
#define APIMYTHEN3 0x210909
#define APIMOENCH 0x210909
#define APIEIGER 0x210909
#define APIJUNGFRAU 0x210913
#define APIGOTTHARD2 0x210914