mirror of https://github.com/FOME-Tech/fome-fw.git
class constructors are a great way to have simple initialization sequence
This commit is contained in:
parent
cfd8889236
commit
f7321942e9
|
@ -161,7 +161,6 @@ void runRusEfi(void) {
|
||||||
efiAssertVoid(CUSTOM_RM_STACK_1, getCurrentRemainingStack() > 512, "init s");
|
efiAssertVoid(CUSTOM_RM_STACK_1, getCurrentRemainingStack() > 512, "init s");
|
||||||
assertEngineReference();
|
assertEngineReference();
|
||||||
engine->setConfig(config);
|
engine->setConfig(config);
|
||||||
initIntermediateLoggingBuffer();
|
|
||||||
addConsoleAction(CMD_REBOOT, scheduleReboot);
|
addConsoleAction(CMD_REBOOT, scheduleReboot);
|
||||||
addConsoleAction(CMD_REBOOT_DFU, jump_to_bootloader);
|
addConsoleAction(CMD_REBOOT_DFU, jump_to_bootloader);
|
||||||
|
|
||||||
|
|
|
@ -39,10 +39,29 @@
|
||||||
#include "console_io.h"
|
#include "console_io.h"
|
||||||
#include "os_util.h"
|
#include "os_util.h"
|
||||||
|
|
||||||
static MemoryStream intermediateLoggingBuffer;
|
|
||||||
static uint8_t intermediateLoggingBufferData[INTERMEDIATE_LOGGING_BUFFER_SIZE] CCM_OPTIONAL;
|
static uint8_t intermediateLoggingBufferData[INTERMEDIATE_LOGGING_BUFFER_SIZE] CCM_OPTIONAL;
|
||||||
//todo define max-printf-buffer
|
|
||||||
static bool intermediateLoggingBufferInited = false;
|
class IntermediateLogging {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Class constructors are a great way to have simple initialization sequence
|
||||||
|
*/
|
||||||
|
IntermediateLogging() {
|
||||||
|
msObjectInit(&intermediateLoggingBuffer, intermediateLoggingBufferData, INTERMEDIATE_LOGGING_BUFFER_SIZE, 0);
|
||||||
|
}
|
||||||
|
MemoryStream intermediateLoggingBuffer;
|
||||||
|
|
||||||
|
// todo: look into chsnprintf once on Chibios 3
|
||||||
|
void vappendPrintfI(Logging *logging, const char *fmt, va_list arg) {
|
||||||
|
intermediateLoggingBuffer.eos = 0; // reset
|
||||||
|
efiAssertVoid(CUSTOM_ERR_6603, getCurrentRemainingStack() > 128, "lowstck#1b");
|
||||||
|
chvprintf((BaseSequentialStream *) &intermediateLoggingBuffer, fmt, arg);
|
||||||
|
intermediateLoggingBuffer.buffer[intermediateLoggingBuffer.eos] = 0; // need to terminate explicitly
|
||||||
|
logging->append((char *)intermediateLoggingBuffer.buffer);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static IntermediateLogging intermediateLogging;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns true if data does not fit into this buffer
|
* @returns true if data does not fit into this buffer
|
||||||
|
@ -93,26 +112,13 @@ void appendFast(Logging *logging, const char *text) {
|
||||||
logging->linePointer = s - 1;
|
logging->linePointer = s - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: look into chsnprintf once on Chibios 3
|
|
||||||
static void vappendPrintfI(Logging *logging, const char *fmt, va_list arg) {
|
|
||||||
if (!intermediateLoggingBufferInited) {
|
|
||||||
firmwareError(CUSTOM_ERR_BUFF_INIT_ERROR, "intermediateLoggingBufferInited not inited!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
intermediateLoggingBuffer.eos = 0; // reset
|
|
||||||
efiAssertVoid(CUSTOM_ERR_6603, getCurrentRemainingStack() > 128, "lowstck#1b");
|
|
||||||
chvprintf((BaseSequentialStream *) &intermediateLoggingBuffer, fmt, arg);
|
|
||||||
intermediateLoggingBuffer.buffer[intermediateLoggingBuffer.eos] = 0; // need to terminate explicitly
|
|
||||||
logging->append((char *)intermediateLoggingBuffer.buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this method acquires system lock to guard the shared intermediateLoggingBuffer memory stream
|
* this method acquires system lock to guard the shared intermediateLoggingBuffer memory stream
|
||||||
*/
|
*/
|
||||||
void Logging::vappendPrintf(const char *fmt, va_list arg) {
|
void Logging::vappendPrintf(const char *fmt, va_list arg) {
|
||||||
efiAssertVoid(CUSTOM_ERR_6604, getCurrentRemainingStack() > 128, "lowstck#5b");
|
efiAssertVoid(CUSTOM_ERR_6604, getCurrentRemainingStack() > 128, "lowstck#5b");
|
||||||
int wasLocked = lockAnyContext();
|
int wasLocked = lockAnyContext();
|
||||||
vappendPrintfI(this, fmt, arg);
|
intermediateLogging.vappendPrintfI(this, fmt, arg);
|
||||||
if (!wasLocked) {
|
if (!wasLocked) {
|
||||||
unlockAnyContext();
|
unlockAnyContext();
|
||||||
}
|
}
|
||||||
|
@ -273,13 +279,6 @@ uint32_t remainingSize(Logging *logging) {
|
||||||
return logging->bufferSize - loggingSize(logging);
|
return logging->bufferSize - loggingSize(logging);
|
||||||
}
|
}
|
||||||
|
|
||||||
void initIntermediateLoggingBuffer(void) {
|
|
||||||
initLoggingCentral();
|
|
||||||
|
|
||||||
msObjectInit(&intermediateLoggingBuffer, intermediateLoggingBufferData, INTERMEDIATE_LOGGING_BUFFER_SIZE, 0);
|
|
||||||
intermediateLoggingBufferInited = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
/* unit test implementations */
|
/* unit test implementations */
|
||||||
void Logging::vappendPrintf(const char *fmt, va_list arg) {
|
void Logging::vappendPrintf(const char *fmt, va_list arg) {
|
||||||
|
|
|
@ -47,8 +47,6 @@ public:
|
||||||
char DEFAULT_BUFFER[200];
|
char DEFAULT_BUFFER[200];
|
||||||
};
|
};
|
||||||
|
|
||||||
void initIntermediateLoggingBuffer(void);
|
|
||||||
|
|
||||||
int isInitialized(Logging *logging);
|
int isInitialized(Logging *logging);
|
||||||
|
|
||||||
void initLoggingExt(Logging *logging, const char *name, char *buffer, int bufferSize);
|
void initLoggingExt(Logging *logging, const char *name, char *buffer, int bufferSize);
|
||||||
|
|
|
@ -30,16 +30,34 @@ static char *accumulationBuffer;
|
||||||
static log_buf_t pendingBuffers0;
|
static log_buf_t pendingBuffers0;
|
||||||
static log_buf_t pendingBuffers1;
|
static log_buf_t pendingBuffers1;
|
||||||
|
|
||||||
/**
|
|
||||||
* amount of data accumulated so far
|
|
||||||
*/
|
|
||||||
static uint32_t accumulatedSize;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We copy all the pending data into this buffer once we are ready to push it out
|
* We copy all the pending data into this buffer once we are ready to push it out
|
||||||
*/
|
*/
|
||||||
static char * outputBuffer;
|
static char * outputBuffer;
|
||||||
|
|
||||||
|
|
||||||
|
class LoggingCentral {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Class constructors are a great way to have simple initialization sequence
|
||||||
|
*/
|
||||||
|
LoggingCentral() {
|
||||||
|
pendingBuffers0[0] = 0;
|
||||||
|
pendingBuffers1[0] = 0;
|
||||||
|
accumulationBuffer = pendingBuffers0;
|
||||||
|
outputBuffer = pendingBuffers1;
|
||||||
|
accumulatedSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* amount of data accumulated so far
|
||||||
|
*/
|
||||||
|
uint32_t accumulatedSize;
|
||||||
|
};
|
||||||
|
|
||||||
|
static LoggingCentral loggingCentral;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method appends the content of specified thread-local logger into the global buffer
|
* This method appends the content of specified thread-local logger into the global buffer
|
||||||
* of logging content.
|
* of logging content.
|
||||||
|
@ -54,7 +72,7 @@ void scheduleLogging(Logging *logging) {
|
||||||
int newLength = efiStrlen(logging->buffer);
|
int newLength = efiStrlen(logging->buffer);
|
||||||
|
|
||||||
bool alreadyLocked = lockOutputBuffer();
|
bool alreadyLocked = lockOutputBuffer();
|
||||||
if (accumulatedSize + newLength >= MAX_DL_CAPACITY) {
|
if (loggingCentral.accumulatedSize + newLength >= MAX_DL_CAPACITY) {
|
||||||
/**
|
/**
|
||||||
* if no one is consuming the data we have to drop it
|
* if no one is consuming the data we have to drop it
|
||||||
* this happens in case of serial-over-USB, todo: find a better solution?
|
* this happens in case of serial-over-USB, todo: find a better solution?
|
||||||
|
@ -66,8 +84,8 @@ void scheduleLogging(Logging *logging) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// memcpy is faster then strcpy because it is not looking for line terminator
|
// memcpy is faster then strcpy because it is not looking for line terminator
|
||||||
memcpy(accumulationBuffer + accumulatedSize, logging->buffer, newLength + 1);
|
memcpy(accumulationBuffer + loggingCentral.accumulatedSize, logging->buffer, newLength + 1);
|
||||||
accumulatedSize += newLength;
|
loggingCentral.accumulatedSize += newLength;
|
||||||
if (!alreadyLocked) {
|
if (!alreadyLocked) {
|
||||||
unlockOutputBuffer();
|
unlockOutputBuffer();
|
||||||
}
|
}
|
||||||
|
@ -93,12 +111,12 @@ char * swapOutputBuffers(int *actualOutputBufferSize) {
|
||||||
char *temp = outputBuffer;
|
char *temp = outputBuffer;
|
||||||
|
|
||||||
#if EFI_ENABLE_ASSERTS
|
#if EFI_ENABLE_ASSERTS
|
||||||
expectedOutputSize = accumulatedSize;
|
expectedOutputSize = loggingCentral.accumulatedSize;
|
||||||
#endif /* EFI_ENABLE_ASSERTS */
|
#endif /* EFI_ENABLE_ASSERTS */
|
||||||
outputBuffer = accumulationBuffer;
|
outputBuffer = accumulationBuffer;
|
||||||
|
|
||||||
accumulationBuffer = temp;
|
accumulationBuffer = temp;
|
||||||
accumulatedSize = 0;
|
loggingCentral.accumulatedSize = 0;
|
||||||
accumulationBuffer[0] = 0;
|
accumulationBuffer[0] = 0;
|
||||||
|
|
||||||
if (!alreadyLocked) {
|
if (!alreadyLocked) {
|
||||||
|
@ -119,14 +137,6 @@ char * swapOutputBuffers(int *actualOutputBufferSize) {
|
||||||
return outputBuffer;
|
return outputBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initLoggingCentral(void) {
|
|
||||||
pendingBuffers0[0] = 0;
|
|
||||||
pendingBuffers1[0] = 0;
|
|
||||||
accumulationBuffer = pendingBuffers0;
|
|
||||||
outputBuffer = pendingBuffers1;
|
|
||||||
accumulatedSize = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rusEfi business logic invokes this method in order to eventually print stuff to rusEfi console
|
* rusEfi business logic invokes this method in order to eventually print stuff to rusEfi console
|
||||||
*
|
*
|
||||||
|
|
|
@ -8,6 +8,5 @@
|
||||||
|
|
||||||
class Logging;
|
class Logging;
|
||||||
|
|
||||||
void initLoggingCentral(void);
|
|
||||||
char * swapOutputBuffers(int *actualOutputBufferSize);
|
char * swapOutputBuffers(int *actualOutputBufferSize);
|
||||||
void scheduleMsg(Logging *logging, const char *fmt, ...);
|
void scheduleMsg(Logging *logging, const char *fmt, ...);
|
||||||
|
|
|
@ -103,8 +103,6 @@ void rusEfiFunctionalTest(void) {
|
||||||
initTriggerDecoderLogger(&sharedLogger);
|
initTriggerDecoderLogger(&sharedLogger);
|
||||||
#endif /* EFI_SHAFT_POSITION_INPUT */
|
#endif /* EFI_SHAFT_POSITION_INPUT */
|
||||||
|
|
||||||
initIntermediateLoggingBuffer();
|
|
||||||
|
|
||||||
engine->setConfig(config);
|
engine->setConfig(config);
|
||||||
|
|
||||||
initializeConsole(&sharedLogger);
|
initializeConsole(&sharedLogger);
|
||||||
|
|
Loading…
Reference in New Issue