66 lines
1015 B
C
66 lines
1015 B
C
#ifndef TEST
|
|
#include <main.h>
|
|
#include <usart.h>
|
|
#endif
|
|
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#ifdef TEST
|
|
#include <stdio.h>
|
|
#endif
|
|
|
|
|
|
#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;
|
|
}
|