// Open up file on SD card with read permissions int SDFileOpenRead() { FRESULT iFResult = FR_OK; // If a file is already open, close it. if(fileOpen) { SDCloseFile(); } iFResult = f_open(&fil, "data.txt", FA_OPEN_EXISTING | FA_READ); // Check return status to see if opened successfully if(iFResult != FR_OK) { #ifdef DEBUG_MODE UARTprintf("\tdata.TXT failed to open for reading\n"); #endif // Raise flag in status register RaiseSDFileOpenReadErrFlag(); return 1; } else { #ifdef DEBUG_MODE UARTprintf("\tdata.TXT opened for reading\n"); #endif fileOpen = true; return 0; } }
// Open/create file on SD card with write permissions int SDFileOpenWrite() { FRESULT iFResult = FR_OK; // If a file is already open, close it. if(fileOpen) { SDCloseFile(); } // If file overwrite is true, overwrite the SD card file if(GetSDFileOverwrite()) { iFResult = f_open(&fil, "data.txt", FA_CREATE_ALWAYS | FA_WRITE); } // Otherwise open and append else { iFResult = f_open(&fil, "data.txt", FA_OPEN_ALWAYS | FA_WRITE); } // Check return status to see if opened successfully if(iFResult != FR_OK) { #ifdef DEBUG_MODE UARTprintf("\tDATA.TXT failed to open for writing\n"); #endif return 1; } else { #ifdef DEBUG_MODE UARTprintf("\tDATA.TXT opened for writing\n"); #endif fileOpen = true; return 0; } }