refactor signaling with led and debug pins

This commit is contained in:
2020-11-01 22:15:04 +01:00
parent 99addddede
commit b7f32a6bf6
9 changed files with 53 additions and 103 deletions

View File

@ -37,7 +37,7 @@ BUILD_DIR = build
###################################### ######################################
# C sources # C sources
C_SOURCES = \ C_SOURCES = \
User/Src/frontend.c User/Src/led.c User/Src/logger.c User/Src/loopCtrl.c User/Src/main2.c User/Src/mbusComm.c User/Src/ringbuffer.c hottislib/PontCoopScheduler.c \ User/Src/frontend.c User/Src/signal.c User/Src/logger.c User/Src/loopCtrl.c User/Src/main2.c User/Src/mbusComm.c User/Src/ringbuffer.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 \

View File

@ -9,5 +9,6 @@ void frontendInit();
void frontendAdcCallback(ADC_HandleTypeDef* hadc); void frontendAdcCallback(ADC_HandleTypeDef* hadc);
void frontendEnable(); void frontendEnable();
void frontendDisable(); void frontendDisable();
void frontendSetThreshold(int32_t threshold);
#endif // _FRONTEND_H_ #endif // _FRONTEND_H_

View File

@ -1,11 +0,0 @@
#ifndef _LED_H_
#define _LED_H_
#include <stdbool.h>
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

@ -10,7 +10,7 @@
static volatile int32_t frontendAdcThreshold = 240; static volatile int32_t frontendAdcThreshold = 0;
static volatile bool frontendEnabled = false; static volatile bool frontendEnabled = false;
@ -21,7 +21,7 @@ void frontendInit() {
logMsg("frontendInit, adc started"); logMsg("frontendInit, adc started");
} }
void frontendSetThreshold(uint16_t threshold) { void frontendSetThreshold(int32_t threshold) {
frontendAdcThreshold = threshold; frontendAdcThreshold = threshold;
} }

View File

@ -1,39 +0,0 @@
#include <main.h>
#include <led.h>
#include <stdint.h>
#include <stdlib.h>
#include <stm32f103xe.h>
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,7 +1,7 @@
#ifndef TEST #ifndef TEST
#include <main.h> #include <main.h>
#include <usart.h> #include <usart.h>
#include <led.h> #include <signal.h>
#include <PontCoopScheduler.h> #include <PontCoopScheduler.h>
#endif #endif
@ -56,7 +56,7 @@ int logExec() {
#ifndef TEST #ifndef TEST
static void flashGreenLed(void *handle) { static void flashGreenLed(void *handle) {
led(GREEN, TOGGLE); signal(LED_GREEN, TOGGLE);
} }
#endif // TEST #endif // TEST

View File

@ -1,6 +1,6 @@
#include <main.h> #include <main.h>
#include <loopCtrl.h> #include <loopCtrl.h>
#include <led.h> #include <signal.h>
bool loopActive = false; bool loopActive = false;
@ -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) {
led(RED, ON); signal(LED_RED, ON);
loopActive = false; loopActive = false;
} }
} }

View File

@ -9,20 +9,19 @@
#include <PontCoopScheduler.h> #include <PontCoopScheduler.h>
#include <led.h> #include <signal.h>
#include <loopCtrl.h> #include <loopCtrl.h>
#include <mbusComm.h> #include <mbusComm.h>
#include <logger.h> #include <logger.h>
#include <frontend.h> #include <frontend.h>
void my_setup_1() { void my_setup_1() {
schInit(); schInit();
logInit(); logInit();
} }
void my_errorHandler() { void my_errorHandler() {
led(RED, ON); signal(LED_RED, ON);
} }
void helloMeterbus(void *handle) { void helloMeterbus(void *handle) {
@ -34,17 +33,17 @@ void helloMeterbus(void *handle) {
void my_setup_2() { void my_setup_2() {
led(RED, OFF); signal(LED_RED, OFF);
led(GREEN, ON); signal(LED_GREEN, ON);
frontendInit(); frontendInit();
frontendSetThreshold(240);
schAdd(helloMeterbus, NULL, 0, 1000); schAdd(helloMeterbus, NULL, 0, 1000);
} }
void my_loop() { void my_loop() {
HAL_GPIO_TogglePin(Debug_Signal_2_GPIO_Port, Debug_Signal_2_Pin); signal(DEBUG_1, TOGGLE);
schExec(); schExec();
logExec(); logExec();

View File

@ -3,7 +3,7 @@
#include <PontCoopScheduler.h> #include <PontCoopScheduler.h>
#include <mbusComm.h> #include <mbusComm.h>
#include <loopCtrl.h> #include <loopCtrl.h>
#include <led.h> #include <signal.h>
#include <logger.h> #include <logger.h>
#include <frontend.h> #include <frontend.h>
@ -48,7 +48,7 @@ static void handleRequestEngine(void *handle) {
case SEND_CONT: case SEND_CONT:
logMsg("hre state SEND_CONT"); logMsg("hre state SEND_CONT");
led(RED, OFF); signal(LED_RED, OFF);
if (! loopActive) { if (! loopActive) {
logMsg("hre enabling loop, try %d", localMbusCommHandle->retryCnt); logMsg("hre enabling loop, try %d", localMbusCommHandle->retryCnt);
localMbusCommHandle->retryCnt++; localMbusCommHandle->retryCnt++;