Skip to content

Commit 8203498

Browse files
author
cromwelldev
committed
Fixed log loop with constant usage of temp buffer
Callback timer set to 500ms intervals
1 parent c1f0fa7 commit 8203498

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

Diff for: lib/LPCMod/DebugLogger.c

+21-16
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#define LogRotationDepth 5
1919

20-
#define FlushInterval_us 50000
20+
#define FlushInterval_ms 500
2121

2222
#define logFilename "xblast.log"
2323
static const char* const ActiveLogFileLocation = PathSep"MASTER_X"PathSep logFilename;
@@ -31,7 +31,7 @@ static unsigned int cursorInBuf = 0;
3131

3232
static void processTempBuf(void);
3333
static void stringFormat(const char* const debugFlag, unsigned char logLevel, const char* const functionName, const char* const buffer, const va_list* vargs);
34-
static void writeString(const char* const string, unsigned char writeToLogFile);
34+
static void writeString(const char* const string, unsigned char writeToLogFile, unsigned char spiPrintOnly);
3535
static void put(unsigned char writeToFile, const char* const string);
3636
static unsigned char assertWriteToFile(const char* const szDebugFlag, unsigned char flushLogFlag);
3737
static const char* const getLogLevelString(unsigned char logLevel);
@@ -41,9 +41,9 @@ void debugLoggerInit(void)
4141
activeLogHandle.obj.fs = NULL;
4242
if(0 == logRotate())
4343
{
44-
processTempBuf();
45-
newCallbackTimer(&forceFlushLog, FlushInterval_us);
4644
initDone = 1;
45+
processTempBuf();
46+
newCallbackTimer(&forceFlushLog, FlushInterval_ms);
4747
}
4848
}
4949

@@ -80,7 +80,7 @@ unsigned char logRotate(void)
8080
XBlastLogger(DEBUG_LOGGER, DBG_LVL_DEBUG, "Open:%s.", ActiveLogFileLocation);
8181
if(FR_OK != result)
8282
{
83-
XBlastLogger(DEBUG_LOGGER, DBG_LVL_ERROR, "Couldn't open log file.");
83+
XBlastLogger(DEBUG_LOGGER, DBG_LVL_ERROR | DBG_FLG_SPI, "Couldn't open log file.");
8484
return 1;
8585
}
8686

@@ -158,16 +158,17 @@ static void processTempBuf(void)
158158

159159
if(initDone)
160160
{
161-
XBlastLogger(DEBUG_LOGGER, DBG_LVL_INFO, "Dumping temp log buffer. len:%u", cursorInBuf);
161+
XBlastLogger(DEBUG_LOGGER, DBG_LVL_DEBUG | DBG_FLG_SPI, "Dumping temp log buffer. len:%u", cursorInBuf);
162162
writeCount = f_puts(tempBufBeforeHDDInit, &activeLogHandle);
163-
XBlastLogger(DEBUG_LOGGER, DBG_LVL_DEBUG, "puts writeCount:%u", writeCount);
163+
XBlastLogger(DEBUG_LOGGER, DBG_LVL_DEBUG | DBG_FLG_SPI, "puts writeCount:%u", writeCount);
164164

165-
if(cursorInBuf != writeCount)
165+
if(cursorInBuf > writeCount)
166166
{
167-
XBlastLogger(DEBUG_LOGGER, DBG_LVL_FATAL, "Temp log dump error:%u", writeCount);
167+
XBlastLogger(DEBUG_LOGGER, DBG_LVL_FATAL | DBG_FLG_SPI, "Temp log dump error:%u", writeCount);
168168
}
169169

170170
}
171+
*tempBufBeforeHDDInit = '\0';
171172
cursorInBuf = 0;
172173
}
173174

@@ -177,29 +178,33 @@ static void stringFormat(const char* const debugFlag, unsigned char logLevel, co
177178
char tempBuf[1024];
178179
unsigned char writeToLogfile;
179180
unsigned char flushToLogFile = logLevel & DBG_FLG_DUMP;
180-
logLevel &= ~((unsigned char)DBG_FLG_DUMP);
181+
unsigned char spiPrintOnly = logLevel & DBG_FLG_SPI;
182+
logLevel &= ~((unsigned char)DBG_FLG_DUMP | DBG_FLG_SPI);
181183

182184
writeToLogfile = assertWriteToFile(debugFlag, flushToLogFile);
183-
sprintf(tempBuf, "[%s][%s][%s] ", getLogLevelString(logLevel), debugFlag, functionName);
184-
writeString(tempBuf, writeToLogfile);
185+
sprintf(tempBuf, "[%u][%s][%s][%s] ", getMS(), getLogLevelString(logLevel), debugFlag, functionName);
186+
writeString(tempBuf, writeToLogfile, spiPrintOnly);
185187
vsprintf(tempBuf,buffer, *vargs);
186-
writeString(tempBuf, writeToLogfile);
188+
writeString(tempBuf, writeToLogfile, spiPrintOnly);
187189

188190
if('\n' != tempBuf[strlen(tempBuf) - 1])
189191
{
190-
writeString("\n", writeToLogfile);
192+
writeString("\n", writeToLogfile, spiPrintOnly);
191193
}
192194
}
193195

194-
static void writeString(const char* const string, unsigned char writeToLogFile)
196+
static void writeString(const char* const string, unsigned char writeToLogFile, unsigned char spiPrintOnly)
195197
{
196198
FRESULT result;
197199
/* write to SPI debugger, if applicable */
198200
#ifdef SPITRACE
199201
printTextSPI(string);
200202
#endif
201203
/* Write to log file*/
202-
put(writeToLogFile, string);
204+
if(0 == spiPrintOnly)
205+
{
206+
put(writeToLogFile, string);
207+
}
203208
}
204209

205210
static void put(unsigned char writeToFile, const char* const string)

0 commit comments

Comments
 (0)