implement uart connection for logger
This commit is contained in:
parent
e5a77ccc00
commit
3ce69c0a64
@ -37,7 +37,7 @@ BUILD_DIR = build
|
|||||||
######################################
|
######################################
|
||||||
# C sources
|
# C sources
|
||||||
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/main.c \
|
||||||
Core/Src/gpio.c \
|
Core/Src/gpio.c \
|
||||||
Core/Src/adc.c \
|
Core/Src/adc.c \
|
||||||
|
@ -3,7 +3,9 @@
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
void ledRed(bool on);
|
typedef enum { RED, GREEN } ledColor_t;
|
||||||
void ledGreen(bool on);
|
typedef enum { ON, OFF, TOGGLE } ledAction_t;
|
||||||
|
|
||||||
|
void led(ledColor_t color, ledAction_t action);
|
||||||
|
|
||||||
#endif // _LED_H_
|
#endif // _LED_H_
|
||||||
|
@ -14,6 +14,6 @@ int logMsg(char *msg);
|
|||||||
// reads the ringbuffer and transfers data to output channel
|
// reads the ringbuffer and transfers data to output channel
|
||||||
// call this from the idle-loop
|
// call this from the idle-loop
|
||||||
// return value can be ignored, it is only used in test
|
// return value can be ignored, it is only used in test
|
||||||
int logExecute();
|
int logExec();
|
||||||
|
|
||||||
#endif // _LOGGER_H_
|
#endif // _LOGGER_H_
|
||||||
|
@ -1,10 +1,39 @@
|
|||||||
#include <main.h>
|
#include <main.h>
|
||||||
#include <led.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) {
|
void led(ledColor_t color, ledAction_t action) {
|
||||||
HAL_GPIO_WritePin(LED_Green_GPIO_Port, LED_Green_Pin, on ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef TEST
|
#ifndef TEST
|
||||||
#include <main.h>
|
#include <main.h>
|
||||||
#include <usart.h>
|
#include <usart.h>
|
||||||
|
#include <led.h>
|
||||||
|
#include <PontCoopScheduler.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@ -33,15 +35,17 @@ void logFree() {
|
|||||||
ringbufferFree(&logBuffer);
|
ringbufferFree(&logBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int logExecute() {
|
int logExec() {
|
||||||
int c = -1;
|
int c = -1;
|
||||||
#ifndef TEST
|
#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
|
#endif // TEST
|
||||||
c = ringbufferGetOne(&logBuffer);
|
c = ringbufferGetOne(&logBuffer);
|
||||||
if (c > 0) {
|
if (c > 0) {
|
||||||
#ifndef TEST
|
#ifndef TEST
|
||||||
// transfer to TX channel
|
// transfer to TX channel
|
||||||
|
uint8_t cc = (uint8_t) c;
|
||||||
|
HAL_UART_Transmit(&debugUart, &cc, 1, HAL_MAX_DELAY);
|
||||||
#endif // TEST
|
#endif // TEST
|
||||||
}
|
}
|
||||||
#ifndef TEST
|
#ifndef TEST
|
||||||
@ -50,14 +54,22 @@ int logExecute() {
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef TEST
|
||||||
|
static void flashGreenLed(void *handle) {
|
||||||
|
led(GREEN, TOGGLE);
|
||||||
|
}
|
||||||
|
#endif // TEST
|
||||||
|
|
||||||
int logMsg(char *msg) {
|
int logMsg(char *msg) {
|
||||||
int res = -1;
|
int res = -1;
|
||||||
|
|
||||||
if (-1 == (res = ringbufferPut(&logBuffer, msg, strlen(msg)))) {
|
if (-1 == (res = ringbufferPut(&logBuffer, (uint8_t*) msg, strlen(msg)))) {
|
||||||
#ifndef TEST
|
#ifndef TEST
|
||||||
// blink the red light or so
|
// blink the green light or so
|
||||||
|
flashGreenLed(NULL);
|
||||||
|
schAdd(flashGreenLed, NULL, 100, 0);
|
||||||
#else
|
#else
|
||||||
printf("\n*** red blink ***\n");
|
printf("\n*** green blink ***\n");
|
||||||
#endif // TEST
|
#endif // TEST
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ void loopDisable() {
|
|||||||
void loopStatusCallback() {
|
void loopStatusCallback() {
|
||||||
GPIO_PinState status = HAL_GPIO_ReadPin(Loop_Status_GPIO_Port, Loop_Status_Pin);
|
GPIO_PinState status = HAL_GPIO_ReadPin(Loop_Status_GPIO_Port, Loop_Status_Pin);
|
||||||
if (status == GPIO_PIN_SET) {
|
if (status == GPIO_PIN_SET) {
|
||||||
ledRed(true);
|
led(RED, ON);
|
||||||
loopActive = false;
|
loopActive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,28 +1,30 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include <PontCoopScheduler.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <main.h>
|
#include <main.h>
|
||||||
#include <usart.h>
|
#include <usart.h>
|
||||||
|
|
||||||
|
#include <PontCoopScheduler.h>
|
||||||
|
|
||||||
#include <led.h>
|
#include <led.h>
|
||||||
#include <loopCtrl.h>
|
#include <loopCtrl.h>
|
||||||
#include <mbusComm.h>
|
#include <mbusComm.h>
|
||||||
|
#include <logger.h>
|
||||||
|
|
||||||
|
|
||||||
void my_setup_1() {
|
void my_setup_1() {
|
||||||
schInit();
|
schInit();
|
||||||
|
logInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void my_errorHandler() {
|
void my_errorHandler() {
|
||||||
ledRed(true);
|
led(RED, ON);
|
||||||
}
|
}
|
||||||
|
|
||||||
void helloWorld(void *handle) {
|
void helloWorld(void *handle) {
|
||||||
static char hello[] = "Hello World\n\r";
|
logMsg("Hello World\n\r");
|
||||||
HAL_UART_Transmit_IT(&debugUart, (uint8_t*) hello, strlen(hello));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void helloMeterbus(void *handle) {
|
void helloMeterbus(void *handle) {
|
||||||
@ -31,8 +33,8 @@ void helloMeterbus(void *handle) {
|
|||||||
|
|
||||||
|
|
||||||
void my_setup_2() {
|
void my_setup_2() {
|
||||||
ledRed(false);
|
led(RED, OFF);
|
||||||
ledGreen(true);
|
led(GREEN, ON);
|
||||||
|
|
||||||
schAdd(helloWorld, NULL, 0, 5000);
|
schAdd(helloWorld, NULL, 0, 5000);
|
||||||
schAdd(helloMeterbus, NULL, 0, 10000);
|
schAdd(helloMeterbus, NULL, 0, 10000);
|
||||||
@ -41,6 +43,7 @@ void my_setup_2() {
|
|||||||
|
|
||||||
void my_loop() {
|
void my_loop() {
|
||||||
schExec();
|
schExec();
|
||||||
|
logExec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SYSTICK_Callback() {
|
void SYSTICK_Callback() {
|
||||||
@ -51,4 +54,4 @@ void HAL_GPIO_EXTI_Callback(uint16_t pin) {
|
|||||||
if (pin == Loop_Status_Pin) {
|
if (pin == Loop_Status_Pin) {
|
||||||
loopStatusCallback();
|
loopStatusCallback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ static void handleRequestEngine(void *handle) {
|
|||||||
// no break !!
|
// no break !!
|
||||||
|
|
||||||
case SEND_CONT:
|
case SEND_CONT:
|
||||||
ledRed(false);
|
led(RED, OFF);
|
||||||
if (! loopActive) {
|
if (! loopActive) {
|
||||||
myHandle->retryCnt++;
|
myHandle->retryCnt++;
|
||||||
loopEnable();
|
loopEnable();
|
||||||
|
@ -846,7 +846,7 @@ void testLogger0() {
|
|||||||
|
|
||||||
memset(buffer, 0, 128);
|
memset(buffer, 0, 128);
|
||||||
i = 0;
|
i = 0;
|
||||||
while (0 < (c = logExecute())) {
|
while (0 < (c = logExec())) {
|
||||||
buffer[i] = (uint8_t) c;
|
buffer[i] = (uint8_t) c;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@ -881,7 +881,7 @@ void testLogger1() {
|
|||||||
|
|
||||||
memset(buffer, 0, 128);
|
memset(buffer, 0, 128);
|
||||||
i = 0;
|
i = 0;
|
||||||
while (0 < (c = logExecute())) {
|
while (0 < (c = logExec())) {
|
||||||
buffer[i] = (uint8_t) c;
|
buffer[i] = (uint8_t) c;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@ -932,7 +932,7 @@ void testLogger2() {
|
|||||||
|
|
||||||
memset(buffer, 0, 128);
|
memset(buffer, 0, 128);
|
||||||
i = 0;
|
i = 0;
|
||||||
while (0 < (c = logExecute())) {
|
while (0 < (c = logExec())) {
|
||||||
buffer[i] = (uint8_t) c;
|
buffer[i] = (uint8_t) c;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user