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

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

View File

@ -3,8 +3,6 @@
#include <main.h>
// 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_

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;
}

View File

@ -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) {

View File

@ -2,6 +2,7 @@
#include <logger.h>
#include <PontCoopScheduler.h>
#include <wizHelper.h>
#include <show.h>
#include <stdint.h>
#include <string.h>
@ -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) {