rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
mmc_card_util.h File Reference

Functions

void incLogFileName (FIL *fd)
 
void printFatFsError (const char *str, FRESULT f_error)
 
void writeErrorReportFile ()
 

Function Documentation

◆ incLogFileName()

void incLogFileName ( FIL *  fd)

Definition at line 18 of file mmc_card_util.cpp.

18 {
19 // clear the memory
20 memset(fd, 0, sizeof(FIL));
21 // This file has the index for next log file name
22 FRESULT ret = f_open(fd, LOG_INDEX_FILENAME, FA_READ);
23
24 char data[_MAX_FILLER];
25 memset(data, 0, sizeof(data));
26
27 if (ret == FR_OK) {
28 UINT readed = 0;
29 // leave one byte for terminating 0
30 ret = f_read(fd, (void*)data, sizeof(data) - 1, &readed);
31
32 if (ret != FR_OK) {
33 printFatFsError("log index file read", ret);
34 logFileIndex = MIN_FILE_INDEX;
35 } else {
36 efiPrintf("Got content [%s] size %d", data, readed);
37 logFileIndex = maxI(MIN_FILE_INDEX, atoi(data));
38 if (absI(logFileIndex) == ATOI_ERROR_CODE) {
39 logFileIndex = MIN_FILE_INDEX;
40 } else {
41 // next file would use next file name
43 }
44 }
45 f_close(fd);
46 } else if (ret == FR_NO_FILE) {
47 // no index file - this is not an error, just an empty SD
48 logFileIndex = MIN_FILE_INDEX;
49 } else {
50 printFatFsError("log index file open", ret);
51 efiPrintf("%s: not found or error: %d", LOG_INDEX_FILENAME, ret);
52 logFileIndex = MIN_FILE_INDEX;
53 }
54
55 // truncate or create new
56 ret = f_open(fd, LOG_INDEX_FILENAME, FA_CREATE_ALWAYS | FA_WRITE);
57 if (ret == FR_OK) {
58 UINT writen = 0;
59 size_t len = itoa10(data, logFileIndex) - data;
60 ret = f_write(fd, (void*)data, len, &writen);
61 if ((ret != FR_OK) || (len != writen)) {
62 printFatFsError("log index write", ret);
63 }
64 f_close(fd);
65 } else {
66 printFatFsError("log index file write", ret);
67 }
68
69 efiPrintf("New log file index %d", logFileIndex);
70}
char * itoa10(char *p, int num)
Definition efilib.cpp:107
void printFatFsError(const char *str, FRESULT f_error)
Definition mmc_card.cpp:273
int logFileIndex
static NO_CACHE FIL fd

Referenced by sdLogger().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ printFatFsError()

void printFatFsError ( const char str,
FRESULT  f_error 
)

Definition at line 273 of file mmc_card.cpp.

273 {
274 static int fatFsErrors = 0;
275
276 if (fatFsErrors++ > 16) {
277 // no reason to spam the console
278 return;
279 }
280
281 efiPrintf("%s FATfs Error %d %s", str, f_error, f_error <= FR_INVALID_PARAMETER ? fatErrors[f_error] : "unknown");
282}
static const char * fatErrors[]
Definition mmc_card.cpp:249

Referenced by incLogFileName(), sdFormat(), sdLoggerCreateFile(), and unmountMmc().

Here is the caller graph for this function:

◆ writeErrorReportFile()

void writeErrorReportFile ( )

Go to the source code of this file.