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; return FAIL;
} }
strcat(mtdvalue,pch); 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 //tell FPGA to not touch flash
system("echo 0 > /sys/class/gpio/gpio9/value"); 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 //writing the program to flash
*filefp = fopen(mtdvalue, "w"); *filefp = fopen(mtdvalue, "w");
@ -3473,6 +3465,11 @@ int stopWritingFPGAprogram(FILE* filefp){
} }
printf("FPGA has picked up the program from flash\n\n"); 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; return OK;
} }

View File

@ -3534,16 +3534,9 @@ int program_fpga(int file_des) {
#endif #endif
//opening file pointer to flash and telling FPGA to not touch flash //opening file pointer to flash and telling FPGA to not touch flash
int startret = startWritingFPGAprogram(&fp); if(startWritingFPGAprogram(&fp) != OK){
/*printf("startret:%d\n",startret);*/
if(startret != OK){
if(startret == FAIL){
sprintf(mess,"Could not write to flash. Error at startup.\n"); sprintf(mess,"Could not write to flash. Error at startup.\n");
cprintf(RED,"%s",mess); 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; ret=FAIL;
filesize = 0; filesize = 0;
} }

View File

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