From b7f32a6bf6d68b0de864336f92ed2a51e1b74562 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Sun, 1 Nov 2020 22:15:04 +0100 Subject: [PATCH] refactor signaling with led and debug pins --- cube/Makefile | 76 ++++++++++++++++++++-------------------- cube/User/Inc/frontend.h | 1 + cube/User/Inc/led.h | 11 ------ cube/User/Src/frontend.c | 4 +-- cube/User/Src/led.c | 39 --------------------- cube/User/Src/logger.c | 4 +-- cube/User/Src/loopCtrl.c | 4 +-- cube/User/Src/main2.c | 13 ++++--- cube/User/Src/mbusComm.c | 4 +-- 9 files changed, 53 insertions(+), 103 deletions(-) delete mode 100644 cube/User/Inc/led.h delete mode 100644 cube/User/Src/led.c diff --git a/cube/Makefile b/cube/Makefile index 52d1a42..f2fca04 100644 --- a/cube/Makefile +++ b/cube/Makefile @@ -1,4 +1,4 @@ -# Processed by ../tools/insertMyCode.sh +# Processed by ../tools/insertMyCode.sh ########################################################################################################################## # File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Sun Nov 01 15:55:46 CET 2020] ########################################################################################################################## @@ -36,36 +36,36 @@ BUILD_DIR = build # source ###################################### # 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 \ -Core/Src/main.c \ -Core/Src/gpio.c \ -Core/Src/adc.c \ -Core/Src/spi.c \ -Core/Src/usart.c \ -Core/Src/stm32f1xx_it.c \ -Core/Src/stm32f1xx_hal_msp.c \ -Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c \ -Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c \ -Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.c \ -Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c \ -Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c \ -Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c \ -Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c \ -Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c \ -Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c \ -Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c \ -Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c \ -Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c \ -Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c \ -Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c \ -Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c \ -Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c \ -Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \ +C_SOURCES = \ +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/gpio.c \ +Core/Src/adc.c \ +Core/Src/spi.c \ +Core/Src/usart.c \ +Core/Src/stm32f1xx_it.c \ +Core/Src/stm32f1xx_hal_msp.c \ +Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c \ +Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c \ +Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.c \ +Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c \ +Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c \ +Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c \ +Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c \ +Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c \ +Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c \ +Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c \ +Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c \ +Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c \ +Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c \ +Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c \ +Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c \ +Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c \ +Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \ Core/Src/system_stm32f1xx.c # ASM sources -ASM_SOURCES = \ +ASM_SOURCES = \ startup_stm32f103xe.s @@ -109,8 +109,8 @@ MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI) AS_DEFS = # C defines -C_DEFS = \ --DUSE_HAL_DRIVER \ +C_DEFS = \ +-DUSE_HAL_DRIVER \ -DSTM32F103xE @@ -118,14 +118,14 @@ C_DEFS = \ AS_INCLUDES = # C includes -C_INCLUDES = \ --Ihottislib \ --IUser/Inc \ --ICore/Inc \ --IDrivers/STM32F1xx_HAL_Driver/Inc \ --IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \ --IDrivers/CMSIS/Device/ST/STM32F1xx/Include \ --IDrivers/CMSIS/Include \ +C_INCLUDES = \ +-Ihottislib \ +-IUser/Inc \ +-ICore/Inc \ +-IDrivers/STM32F1xx_HAL_Driver/Inc \ +-IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \ +-IDrivers/CMSIS/Device/ST/STM32F1xx/Include \ +-IDrivers/CMSIS/Include \ -IDrivers/CMSIS/Include diff --git a/cube/User/Inc/frontend.h b/cube/User/Inc/frontend.h index 9d5ad1d..cbcc05a 100644 --- a/cube/User/Inc/frontend.h +++ b/cube/User/Inc/frontend.h @@ -9,5 +9,6 @@ void frontendInit(); void frontendAdcCallback(ADC_HandleTypeDef* hadc); void frontendEnable(); void frontendDisable(); +void frontendSetThreshold(int32_t threshold); #endif // _FRONTEND_H_ \ No newline at end of file diff --git a/cube/User/Inc/led.h b/cube/User/Inc/led.h deleted file mode 100644 index 857bd7b..0000000 --- a/cube/User/Inc/led.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _LED_H_ -#define _LED_H_ - -#include - -typedef enum { RED, GREEN } ledColor_t; -typedef enum { ON, OFF, TOGGLE } ledAction_t; - -void led(ledColor_t color, ledAction_t action); - -#endif // _LED_H_ diff --git a/cube/User/Src/frontend.c b/cube/User/Src/frontend.c index 30b964f..ca20e93 100644 --- a/cube/User/Src/frontend.c +++ b/cube/User/Src/frontend.c @@ -10,7 +10,7 @@ -static volatile int32_t frontendAdcThreshold = 240; +static volatile int32_t frontendAdcThreshold = 0; static volatile bool frontendEnabled = false; @@ -21,7 +21,7 @@ void frontendInit() { logMsg("frontendInit, adc started"); } -void frontendSetThreshold(uint16_t threshold) { +void frontendSetThreshold(int32_t threshold) { frontendAdcThreshold = threshold; } diff --git a/cube/User/Src/led.c b/cube/User/Src/led.c deleted file mode 100644 index a6bfb13..0000000 --- a/cube/User/Src/led.c +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -#include -#include -#include - - -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; - } - } -} diff --git a/cube/User/Src/logger.c b/cube/User/Src/logger.c index c73bcc4..a3946a9 100644 --- a/cube/User/Src/logger.c +++ b/cube/User/Src/logger.c @@ -1,7 +1,7 @@ #ifndef TEST #include #include -#include +#include #include #endif @@ -56,7 +56,7 @@ int logExec() { #ifndef TEST static void flashGreenLed(void *handle) { - led(GREEN, TOGGLE); + signal(LED_GREEN, TOGGLE); } #endif // TEST diff --git a/cube/User/Src/loopCtrl.c b/cube/User/Src/loopCtrl.c index 51d93c9..ea674b7 100644 --- a/cube/User/Src/loopCtrl.c +++ b/cube/User/Src/loopCtrl.c @@ -1,6 +1,6 @@ #include #include -#include +#include bool loopActive = false; @@ -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) { - led(RED, ON); + signal(LED_RED, ON); loopActive = false; } } \ No newline at end of file diff --git a/cube/User/Src/main2.c b/cube/User/Src/main2.c index 144478f..43c219d 100644 --- a/cube/User/Src/main2.c +++ b/cube/User/Src/main2.c @@ -9,20 +9,19 @@ #include -#include +#include #include #include #include #include - void my_setup_1() { schInit(); logInit(); } void my_errorHandler() { - led(RED, ON); + signal(LED_RED, ON); } void helloMeterbus(void *handle) { @@ -34,17 +33,17 @@ void helloMeterbus(void *handle) { void my_setup_2() { - led(RED, OFF); - led(GREEN, ON); + signal(LED_RED, OFF); + signal(LED_GREEN, ON); frontendInit(); + frontendSetThreshold(240); schAdd(helloMeterbus, NULL, 0, 1000); } void my_loop() { - HAL_GPIO_TogglePin(Debug_Signal_2_GPIO_Port, Debug_Signal_2_Pin); - + signal(DEBUG_1, TOGGLE); schExec(); logExec(); diff --git a/cube/User/Src/mbusComm.c b/cube/User/Src/mbusComm.c index ddf51f6..78b8a4c 100644 --- a/cube/User/Src/mbusComm.c +++ b/cube/User/Src/mbusComm.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include @@ -48,7 +48,7 @@ static void handleRequestEngine(void *handle) { case SEND_CONT: logMsg("hre state SEND_CONT"); - led(RED, OFF); + signal(LED_RED, OFF); if (! loopActive) { logMsg("hre enabling loop, try %d", localMbusCommHandle->retryCnt); localMbusCommHandle->retryCnt++;