From c98c5dd8a55db67c7171c4578ef5d4fd27d92dbf Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Tue, 10 Nov 2020 22:18:51 +0100 Subject: [PATCH] debug works in interrupt mode now, needs some refactoring, MBUSYield stops the whole system --- cube/User/Inc/logger.h | 11 +---------- cube/User/Src/logger.c | 42 ++++++++++++++-------------------------- cube/User/Src/main2.c | 8 ++------ cube/User/Src/mqttComm.c | 6 +++++- 4 files changed, 23 insertions(+), 44 deletions(-) diff --git a/cube/User/Inc/logger.h b/cube/User/Inc/logger.h index 89e106b..d809bcc 100644 --- a/cube/User/Inc/logger.h +++ b/cube/User/Inc/logger.h @@ -3,8 +3,6 @@ #include -// won't work so far -// #define LOGGER_INTERRUPT typedef enum { LOG_HIGH, @@ -29,14 +27,7 @@ int errMsg(const char *format, ...); int coloredMsg(const t_logColor color, const char *format, ...); -// reads the ringbuffer and transfers data to output channel -// call this from the idle-loop -// return value can be ignored, it is only used in test -int logExec(); - -#ifdef LOGGER_INTERRUPT -void mbusCommTxCpltCallback(UART_HandleTypeDef *huart); -#endif +void debugTxCpltCallback(UART_HandleTypeDef *huart); #endif // _LOGGER_H_ diff --git a/cube/User/Src/logger.c b/cube/User/Src/logger.c index 7f5df6c..e2cb8db 100644 --- a/cube/User/Src/logger.c +++ b/cube/User/Src/logger.c @@ -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; } diff --git a/cube/User/Src/main2.c b/cube/User/Src/main2.c index 9c9bfa5..529b91f 100644 --- a/cube/User/Src/main2.c +++ b/cube/User/Src/main2.c @@ -206,7 +206,6 @@ void my_loop() { show(DEBUG_1, TOGGLE); schExec(); - logExec(); } void SYSTICK_Callback() { @@ -214,7 +213,7 @@ void SYSTICK_Callback() { schUpdate(); // MQTT Interface - MilliTimer_Handler(); + // MilliTimer_Handler(); } void HAL_GPIO_EXTI_Callback(uint16_t pin) { @@ -232,12 +231,9 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) { void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) { if (huart == &mbusUart) { mbusCommTxCpltCallback(huart); - } -#ifdef LOGGER_INTERRUPT - else if (huart == &debugUart) { + } else if (huart == &debugUart) { debugTxCpltCallback(huart); } -#endif } void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { diff --git a/cube/User/Src/mqttComm.c b/cube/User/Src/mqttComm.c index 60823c8..fb15f57 100644 --- a/cube/User/Src/mqttComm.c +++ b/cube/User/Src/mqttComm.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -61,7 +62,10 @@ static void messageArrived(MessageData* md) } static void mqttHandler(void *handle) { -// MQTTYield(&mqttClient, data.keepAliveInterval); + show(DEBUG_2, ON); + MQTTYield(&mqttClient, data.keepAliveInterval); + show(DEBUG_2, OFF); + } void mqttCommInit(void *handle) {