debug works in interrupt mode now, needs some refactoring, MBUSYield stops the whole system

This commit is contained in:
2020-11-10 22:18:51 +01:00
parent 15d8afa207
commit c98c5dd8a5
4 changed files with 23 additions and 44 deletions

View File

@ -25,6 +25,8 @@
#endif // TEST
uint8_t singleOctetTXBuffer;
static ringbuffer_t logBuffer;
void logInit() {
@ -35,35 +37,15 @@ void logFree() {
ringbufferFree(&logBuffer);
}
#ifdef LOGGER_INTERRUPT
void mbusCommTxCpltCallback(UART_HandleTypeDef *huart) {
logExec();
}
#endif
int logExec() {
int c = -1;
#ifndef TEST
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;
#ifndef LOGGER_INTERRUPT
HAL_UART_Transmit(&debugUart, &cc, 1, HAL_MAX_DELAY);
#else
HAL_UART_Transmit_IT(&debugUart, &cc, 1);
#endif // LOGGER_INTERRUPT
#endif // TEST
}
#ifndef TEST
void debugTxCpltCallback(UART_HandleTypeDef *huart) {
int c = ringbufferGetOne(&logBuffer);
if (c > 0) {
singleOctetTXBuffer = (uint8_t) c;
HAL_UART_Transmit_IT(&debugUart, &singleOctetTXBuffer, 1);
}
#endif // TEST
return c;
}
#ifndef TEST
static void flashGreenLed(void *handle) {
show(LED_GREEN, TOGGLE);
@ -87,7 +69,12 @@ static int innerLogMsg(const char *pre, const char *post, const char *format, va
strcat(msgBuffer, post);
}
if (-1 == (res = ringbufferPut(&logBuffer, (uint8_t*) msgBuffer, strlen(msgBuffer)))) {
HAL_NVIC_DisableIRQ(UART4_IRQn);
res = ringbufferPut(&logBuffer, (uint8_t*) msgBuffer, strlen(msgBuffer));
HAL_NVIC_EnableIRQ(UART4_IRQn);
if (-1 == res) {
#ifndef TEST
// blink the green light or so
flashGreenLed(NULL);
@ -96,6 +83,7 @@ static int innerLogMsg(const char *pre, const char *post, const char *format, va
printf("\n*** green blink ***\n");
#endif // TEST
}
debugTxCpltCallback(NULL);
}
return res;
}