logging
This commit is contained in:
parent
eb64cc8dce
commit
804e8c8acf
@ -5,6 +5,9 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
#define LOGGER_OUTPUT_BY_INTERRUPT
|
||||
|
||||
typedef enum {
|
||||
LOG_NORMAL,
|
||||
LOG_HIGH,
|
||||
@ -26,7 +29,12 @@ int logMsg(const char *format, ...);
|
||||
|
||||
int coloredMsg(const t_logColor color, bool syslogToo, const char *format, ...);
|
||||
|
||||
#ifdef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
void debugTxCpltCallback(UART_HandleTypeDef *huart);
|
||||
#endif
|
||||
|
||||
#ifndef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
void logExec();
|
||||
#endif
|
||||
|
||||
#endif // _LOGGER_H_
|
||||
|
@ -13,6 +13,9 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
#include <stm32f103xe.h>
|
||||
#endif //LOGGER_OUTPUT_BY_INTERRUPT
|
||||
|
||||
|
||||
#define LOGBUFFER_SIZE 2048
|
||||
@ -34,13 +37,30 @@ void logFree() {
|
||||
ringbufferFree(&logBuffer);
|
||||
}
|
||||
|
||||
#ifdef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
void debugTxCpltCallback(UART_HandleTypeDef *huart) {
|
||||
int c = ringbufferGetOne(&logBuffer);
|
||||
if (c > 0) {
|
||||
singleOctetTXBuffer = (uint8_t) c;
|
||||
HAL_UART_Transmit_IT(&debugUart, &singleOctetTXBuffer, 1);
|
||||
}
|
||||
}
|
||||
#endif //LOGGER_OUTPUT_BY_INTERRUPT
|
||||
|
||||
#ifndef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
int logExec() {
|
||||
int c = -1;
|
||||
if (__HAL_UART_GET_FLAG(&debugUart, UART_FLAG_TXE)) { // is the TX channel free
|
||||
c = ringbufferGetOne(&logBuffer);
|
||||
if (c > 0) {
|
||||
// transfer to TX channel
|
||||
uint8_t cc = (uint8_t) c;
|
||||
HAL_UART_Transmit(&debugUart, &cc, 1, HAL_MAX_DELAY);
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
#endif //LOGGER_OUTPUT_BY_INTERRUPT
|
||||
|
||||
void syslog(char *msg) {
|
||||
static uint8_t state = 0;
|
||||
@ -90,12 +110,19 @@ static int innerLogMsg(const char *pre, const char *post, bool syslogToo, const
|
||||
if (post) {
|
||||
strcat(bufferStart - preSize, post);
|
||||
}
|
||||
|
||||
#ifdef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
HAL_NVIC_DisableIRQ(UART4_IRQn);
|
||||
res = ringbufferPut(&logBuffer, (uint8_t*) (bufferStart - preSize), strlen(bufferStart - preSize));
|
||||
HAL_NVIC_EnableIRQ(UART4_IRQn);
|
||||
#endif //LOGGER_OUTPUT_BY_INTERRUPT
|
||||
|
||||
res = ringbufferPut(&logBuffer, (uint8_t*) (bufferStart - preSize), strlen(bufferStart - preSize));
|
||||
|
||||
#ifdef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
HAL_NVIC_EnableIRQ(UART4_IRQn);
|
||||
#endif //LOGGER_OUTPUT_BY_INTERRUPT
|
||||
|
||||
#ifdef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
debugTxCpltCallback(NULL);
|
||||
#endif LOGGER_OUTPUT_BY_INTERRUPT
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -208,6 +208,10 @@ void my_loop() {
|
||||
show(DEBUG_1, TOGGLE);
|
||||
|
||||
schExec();
|
||||
|
||||
#ifndef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
logExec();
|
||||
#endif //LOGGER_OUTPUT_BY_INTERRUPT
|
||||
}
|
||||
|
||||
void SYSTICK_Callback() {
|
||||
@ -229,9 +233,12 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
|
||||
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) {
|
||||
if (huart == &mbusUart) {
|
||||
mbusCommTxCpltCallback(huart);
|
||||
} else if (huart == &debugUart) {
|
||||
}
|
||||
#ifdef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
else if (huart == &debugUart) {
|
||||
debugTxCpltCallback(huart);
|
||||
}
|
||||
#endif //LOGGER_OUTPUT_BY_INTERRUPT
|
||||
}
|
||||
|
||||
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user