implement uart connection for logger

This commit is contained in:
Wolfgang Hottgenroth 2020-10-29 15:44:13 +01:00
parent e5a77ccc00
commit 3ce69c0a64
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F
9 changed files with 73 additions and 27 deletions

View File

@ -37,7 +37,7 @@ BUILD_DIR = build
######################################
# C sources
C_SOURCES = \
User/Src/mbusComm.c User/Src/led.c User/Src/loopCtrl.c User/Src/main2.c hottislib/PontCoopScheduler.c \
User/Src/ringbuffer.c User/Src/logger.c User/Src/mbusComm.c User/Src/led.c User/Src/loopCtrl.c User/Src/main2.c hottislib/PontCoopScheduler.c \
Core/Src/main.c \
Core/Src/gpio.c \
Core/Src/adc.c \

View File

@ -3,7 +3,9 @@
#include <stdbool.h>
void ledRed(bool on);
void ledGreen(bool on);
typedef enum { RED, GREEN } ledColor_t;
typedef enum { ON, OFF, TOGGLE } ledAction_t;
void led(ledColor_t color, ledAction_t action);
#endif // _LED_H_

View File

@ -14,6 +14,6 @@ int logMsg(char *msg);
// 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 logExecute();
int logExec();
#endif // _LOGGER_H_

View File

@ -1,10 +1,39 @@
#include <main.h>
#include <led.h>
#include <stdint.h>
#include <stdlib.h>
#include <stm32f103xe.h>
void ledRed(bool on) {
HAL_GPIO_WritePin(LED_Red_GPIO_Port, LED_Red_Pin, on ? GPIO_PIN_SET : GPIO_PIN_RESET);
}
void ledGreen(bool on) {
HAL_GPIO_WritePin(LED_Green_GPIO_Port, LED_Green_Pin, on ? GPIO_PIN_SET : GPIO_PIN_RESET);
void led(ledColor_t color, ledAction_t action) {
GPIO_TypeDef *port = NULL;
uint16_t pin = 0;
switch (color) {
case RED:
port = LED_Red_GPIO_Port;
pin = LED_Red_Pin;
break;
case GREEN:
port = LED_Green_GPIO_Port;
pin = LED_Green_Pin;
break;
}
if (port != NULL) {
switch (action) {
case ON:
HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET);
break;
case OFF:
HAL_GPIO_WritePin(port, pin, GPIO_PIN_RESET);
break;
case TOGGLE:
HAL_GPIO_TogglePin(port, pin);
break;
}
}
}

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
}

View File

@ -20,7 +20,7 @@ void loopDisable() {
void loopStatusCallback() {
GPIO_PinState status = HAL_GPIO_ReadPin(Loop_Status_GPIO_Port, Loop_Status_Pin);
if (status == GPIO_PIN_SET) {
ledRed(true);
led(RED, ON);
loopActive = false;
}
}

View File

@ -1,28 +1,30 @@
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <PontCoopScheduler.h>
#include <stdlib.h>
#include <main.h>
#include <usart.h>
#include <PontCoopScheduler.h>
#include <led.h>
#include <loopCtrl.h>
#include <mbusComm.h>
#include <logger.h>
void my_setup_1() {
schInit();
logInit();
}
void my_errorHandler() {
ledRed(true);
led(RED, ON);
}
void helloWorld(void *handle) {
static char hello[] = "Hello World\n\r";
HAL_UART_Transmit_IT(&debugUart, (uint8_t*) hello, strlen(hello));
logMsg("Hello World\n\r");
}
void helloMeterbus(void *handle) {
@ -31,8 +33,8 @@ void helloMeterbus(void *handle) {
void my_setup_2() {
ledRed(false);
ledGreen(true);
led(RED, OFF);
led(GREEN, ON);
schAdd(helloWorld, NULL, 0, 5000);
schAdd(helloMeterbus, NULL, 0, 10000);
@ -41,6 +43,7 @@ void my_setup_2() {
void my_loop() {
schExec();
logExec();
}
void SYSTICK_Callback() {
@ -51,4 +54,4 @@ void HAL_GPIO_EXTI_Callback(uint16_t pin) {
if (pin == Loop_Status_Pin) {
loopStatusCallback();
}
}
}

View File

@ -41,7 +41,7 @@ static void handleRequestEngine(void *handle) {
// no break !!
case SEND_CONT:
ledRed(false);
led(RED, OFF);
if (! loopActive) {
myHandle->retryCnt++;
loopEnable();

View File

@ -846,7 +846,7 @@ void testLogger0() {
memset(buffer, 0, 128);
i = 0;
while (0 < (c = logExecute())) {
while (0 < (c = logExec())) {
buffer[i] = (uint8_t) c;
i++;
}
@ -881,7 +881,7 @@ void testLogger1() {
memset(buffer, 0, 128);
i = 0;
while (0 < (c = logExecute())) {
while (0 < (c = logExec())) {
buffer[i] = (uint8_t) c;
i++;
}
@ -932,7 +932,7 @@ void testLogger2() {
memset(buffer, 0, 128);
i = 0;
while (0 < (c = logExecute())) {
while (0 < (c = logExec())) {
buffer[i] = (uint8_t) c;
i++;
}