int main (void) { boot_up(); //Initialize USB port pins and set up the UART rprintf("Boot up complete\n"); if(IOPIN0 & (1<<23)) //Check to see if the USB cable is plugged in { main_msc(); //If so, run the USB device driver. } else{ rprintf("No USB Detected\n"); } //Init SD if(sd_raw_init()) //Initialize the SD card { openroot(); //Open the root directory on the SD card rprintf("Root open\n"); if(root_file_exists(FW_FILE)) //Check to see if the firmware file is residing in the root directory { rprintf("New firmware found\n"); load_fw(FW_FILE); //If we found the firmware file, then program it's contents into memory. rprintf("New firmware loaded\n"); } } else{ //Didn't find a card to initialize rprintf("No SD Card Detected\n"); delay_ms(250); } rprintf("Boot Done. Calling firmware...\n"); call_firmware(); //Run the new code! while(1); }
//0 for success, negative for failure int readLogCon(void) { char keyword[64]; char value[64]; char stringBuf[512]; struct fat16_file_struct fd; int len; int s=0; int t=0; keyword[0]=0; value[0]=0; int result; if(root_file_exists(LOGCON_NAME)) { //There already is a logcon file, open it and suck int in result = root_open(&fd,LOGCON_NAME); if(result<0) return result; len = fat16_read_file(&fd, (unsigned char *)stringBuf, 512); if(len<0) return -1; fat16_close_file(&fd); } else { //No existing logcon file, write a fresh one result=root_open_new(&fd,LOGCON_NAME); if(result<0) return result; stringBuf[0]=0; //Write out each default line for(int i=0;strlen(fTable[i].tag)>0;i++) { strcat(stringBuf,fTable[i].tag); strcat(stringBuf,"="); strcat(stringBuf,fTable[i].def); strcat(stringBuf,"\r\n"); } //write it out to the file len=strlen(stringBuf); fat16_write_file(&fd, (unsigned char*)stringBuf, len); fat16_close_file(&fd); sd_raw_sync(); } //Either way, the logcon file is now in stringBuf and //its length is in len s=0; t=0; char inValue=0; for(s = 0; s < len; s++) { if(stringBuf[s] == '=') { keyword[t]=0; inValue=1; t=0; } else if(stringBuf[s]=='\n') { value[t]=0; inValue=0; t=0; result=processLine(keyword,value); if(result<0) return result; } else { if(inValue) { value[t]=stringBuf[s]; } else { keyword[t]=stringBuf[s]; } t++; } } return 0; }