implement uart connection for logger

This commit is contained in:
2020-10-29 15:44:13 +01:00
parent e5a77ccc00
commit 3ce69c0a64
9 changed files with 73 additions and 27 deletions

View File

@ -1,6 +1,8 @@
#ifndef TEST
#include <main.h>
#include <usart.h>
#include <led.h>
#include <PontCoopScheduler.h>
#endif
#include <stdint.h>
@ -33,15 +35,17 @@ void logFree() {
ringbufferFree(&logBuffer);
}
int logExecute() {
int logExec() {
int c = -1;
#ifndef TEST
if (false) { // is the TX channel free
if (__HAL_UART_GET_FLAG(&debugUart, UART_FLAG_TXE)) { // is the TX channel free
#endif // TEST
c = ringbufferGetOne(&logBuffer);
if (c > 0) {
#ifndef TEST
// transfer to TX channel
uint8_t cc = (uint8_t) c;
HAL_UART_Transmit(&debugUart, &cc, 1, HAL_MAX_DELAY);
#endif // TEST
}
#ifndef TEST
@ -50,14 +54,22 @@ int logExecute() {
return c;
}
#ifndef TEST
static void flashGreenLed(void *handle) {
led(GREEN, TOGGLE);
}
#endif // TEST
int logMsg(char *msg) {
int res = -1;
if (-1 == (res = ringbufferPut(&logBuffer, msg, strlen(msg)))) {
if (-1 == (res = ringbufferPut(&logBuffer, (uint8_t*) msg, strlen(msg)))) {
#ifndef TEST
// blink the red light or so
// blink the green light or so
flashGreenLed(NULL);
schAdd(flashGreenLed, NULL, 100, 0);
#else
printf("\n*** red blink ***\n");
printf("\n*** green blink ***\n");
#endif // TEST
}