logger, implementation and test
This commit is contained in:
@ -1,17 +1,65 @@
|
||||
#ifndef TEST
|
||||
#include <main.h>
|
||||
#include <usart.h>
|
||||
#include <logger.h>
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void log(char *msg) {
|
||||
uint16_t len = strlen(msg);
|
||||
#ifdef TEST
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
if (HAL_UART_Transmit_IT(&debugUart, msg, len) != HAL_OK) {
|
||||
if(RingBuffer_Write(&txBuf, msg, len) != RING_BUFFER_OK)
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
||||
#include <logger.h>
|
||||
#include <ringbuffer.h>
|
||||
|
||||
|
||||
#ifdef TEST
|
||||
#define LOGBUFFER_SIZE 32
|
||||
#else
|
||||
#define LOGBUFFER_SIZE 1024
|
||||
#endif // TEST
|
||||
|
||||
|
||||
static ringbuffer_t logBuffer;
|
||||
|
||||
void logInit() {
|
||||
ringbufferInit(&logBuffer, LOGBUFFER_SIZE);
|
||||
}
|
||||
|
||||
void logFree() {
|
||||
ringbufferFree(&logBuffer);
|
||||
}
|
||||
|
||||
int logExecute() {
|
||||
int c = -1;
|
||||
#ifndef TEST
|
||||
if (false) { // is the TX channel free
|
||||
#endif // TEST
|
||||
c = ringbufferGetOne(&logBuffer);
|
||||
if (c > 0) {
|
||||
#ifndef TEST
|
||||
// transfer to TX channel
|
||||
#endif // TEST
|
||||
}
|
||||
#ifndef TEST
|
||||
}
|
||||
#endif // TEST
|
||||
return c;
|
||||
}
|
||||
|
||||
int logMsg(char *msg) {
|
||||
int res = -1;
|
||||
|
||||
if (-1 == (res = ringbufferPut(&logBuffer, msg, strlen(msg)))) {
|
||||
#ifndef TEST
|
||||
// blink the red light or so
|
||||
#else
|
||||
printf("\n*** red blink ***\n");
|
||||
#endif // TEST
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
Reference in New Issue
Block a user