switching the gpio definitions into function implementation

This commit is contained in:
Dhanya Maliakal 2016-09-30 07:56:54 +02:00
parent d3c4d52118
commit f513fb06fb
6 changed files with 19 additions and 27 deletions

View File

@ -3408,25 +3408,17 @@ int startWritingFPGAprogram(FILE** filefp){
return FAIL;
}
strcat(mtdvalue,pch);
printf ("\nWriting FPGA program to flash.\nThe drive is %s\n",mtdvalue);
printf ("\nFlash drive found: %s\n",mtdvalue);
//define the gpio pins
system("echo 7 > /sys/class/gpio/export");
system("echo 9 > /sys/class/gpio/export");
//define their direction
system("echo in > /sys/class/gpio/gpio7/direction");
system("echo out > /sys/class/gpio/gpio9/direction");
//tell FPGA to not touch flash
system("echo 0 > /sys/class/gpio/gpio9/value");
/*
char output2[255];
fp = popen("echo 0 > /sys/class/gpio/gpio9/value","r");
fgets(output2, sizeof(output2), fp);
pclose(fp);
printf("strlen output %d\n", strlen(output2)); //always 1
printf("output got:%s\n",output2);
if(strstr (output2,"No such file or directory")!= NULL){ //doesnt notice
printf("matched!\n");
return -1;
}
printf("not matched\n");
*/
//writing the program to flash
*filefp = fopen(mtdvalue, "w");
@ -3473,6 +3465,11 @@ int stopWritingFPGAprogram(FILE* filefp){
}
printf("FPGA has picked up the program from flash\n\n");
//undefine the pins
system("echo 7 > /sys/class/gpio/unexport");
system("echo 9 > /sys/class/gpio/unexport");
return OK;
}

View File

@ -3534,16 +3534,9 @@ int program_fpga(int file_des) {
#endif
//opening file pointer to flash and telling FPGA to not touch flash
int startret = startWritingFPGAprogram(&fp);
/*printf("startret:%d\n",startret);*/
if(startret != OK){
if(startret == FAIL){
if(startWritingFPGAprogram(&fp) != OK){
sprintf(mess,"Could not write to flash. Error at startup.\n");
cprintf(RED,"%s",mess);
}/*else if (startret == -1){
cprintf(RED,"Error: Please define the gpio pins and their direction in /etc/rc before rebooting\n");
cprintf(RED,"%s",mess);
}*/
ret=FAIL;
filesize = 0;
}

View File

@ -6477,7 +6477,7 @@ int slsDetector::programFPGA(string fname){
return FAIL;
}
#ifdef VERBOSE
std::cout << "Successfully loaded the rawbin file" << std::endl;
std::cout << "Successfully loaded the rawbin file to program memory" << std::endl;
#endif
const size_t maxprogramsize = 2 * 1024 *1024;
@ -6509,7 +6509,8 @@ int slsDetector::programFPGA(string fname){
std::cout<< "This can take awhile. Please be patient..." << endl;
printf("Erasing Flash:%d%%\r",0);
std::cout << flush;
int count = 65;
//erasing takes 65 seconds, printing here (otherwise need threads in server-unnecessary)
int count = 66;
while(count>0){
usleep(1 * 1000 * 1000);
count--;
@ -6521,7 +6522,7 @@ int slsDetector::programFPGA(string fname){
std::cout << flush;
}
//sending program in parts of 2mb each
while(filesize > 0){
unitprogramsize = maxprogramsize; //2mb
@ -6536,13 +6537,14 @@ int slsDetector::programFPGA(string fname){
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 Program 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;
}