From 9df68e778f149ef48520bfb1d8962e196424b5c3 Mon Sep 17 00:00:00 2001 From: sunbeam Date: Wed, 19 Feb 2025 14:20:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0hwctrl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LIN Slave/.vscode/settings.json | 3 +- LIN Slave/Inc/hwctrl.h | 17 ++- LIN Slave/Src/appTask.c | 27 +++-- LIN Slave/Src/hwctrl.c | 179 +++++++++++++++++++++++++++++++- 4 files changed, 214 insertions(+), 12 deletions(-) diff --git a/LIN Slave/.vscode/settings.json b/LIN Slave/.vscode/settings.json index 540a4a0..8ef281e 100644 --- a/LIN Slave/.vscode/settings.json +++ b/LIN Slave/.vscode/settings.json @@ -77,5 +77,6 @@ "files.associations": { "bstim32.h": "c", "main.h": "c" -} +}, +"Codegeex.GenerationPreference": "block" } \ No newline at end of file diff --git a/LIN Slave/Inc/hwctrl.h b/LIN Slave/Inc/hwctrl.h index 2a66520..a04cf22 100644 --- a/LIN Slave/Inc/hwctrl.h +++ b/LIN Slave/Inc/hwctrl.h @@ -9,13 +9,21 @@ /******************************************************************************* * the defines ******************************************************************************/ - +#define DCF_ON 1 +#define DCF_OFF 0 +#define V2_12V_ON 1 +#define V2_12V_OFF 0 +#define AP_ON 1 +#define AP_OFF 0 /******************************************************************************* * the typedefs ******************************************************************************/ - +typedef enum +{ + DCF1, DCF2, DCF3, DCF4, DCF5, DCF6, DCF7, DCF8, DCF9, DCF10 +}DCFCH_TypeDef; /******************************************************************************* @@ -29,8 +37,9 @@ ******************************************************************************/ void hw_gpio_init(void); - - +void DCF_control(DCFCH_TypeDef channel, uint8_t state); +void V2_12V_control(uint8_t state); +void AP_control(uint8_t state); diff --git a/LIN Slave/Src/appTask.c b/LIN Slave/Src/appTask.c index 93882ce..56a34d6 100644 --- a/LIN Slave/Src/appTask.c +++ b/LIN Slave/Src/appTask.c @@ -1,12 +1,6 @@ /******************************************************************************* * the includes ******************************************************************************/ - - - -/******************************************************************************* -* the defines -******************************************************************************/ #include "appTask.h" #include "uart.h" #include "lin.h" @@ -16,6 +10,13 @@ #include "iwdt.h" #include "rmu.h" #include "bstim32.h" +#include "hwctrl.h" + + +/******************************************************************************* +* the defines +******************************************************************************/ + /******************************************************************************* * the typedefs @@ -73,7 +74,17 @@ void TimebaseHandle(void) void appTaskInit(void) { + hw_gpio_init(); BSTIM32_Init(); + + V2_12V_control(V2_12V_OFF); + AP_control(AP_OFF); + + for (uint8_t i = 0; i < count; i++) + { + DCF_control(i, DCF_OFF); + } + gSystick1SCnt = 0; } void appTask(void) @@ -124,3 +135,7 @@ void appTask(void) } } +void MsgCtrlIO_task(void) +{ + MsgCtrlIO(); +} diff --git a/LIN Slave/Src/hwctrl.c b/LIN Slave/Src/hwctrl.c index 0c26624..6010092 100644 --- a/LIN Slave/Src/hwctrl.c +++ b/LIN Slave/Src/hwctrl.c @@ -28,6 +28,19 @@ #define DCF10_GPIO GPIOA #define DCF10_PIN FL_GPIO_PIN_15 +#define V2_12V_CTRL_GPIO GPIOB +#define V2_12V_CTRL_PIN FL_GPIO_PIN_12 +#define V2_12V_DEN_GPIO GPIOC +#define V2_12V_DEN_PIN FL_GPIO_PIN_0 + +#define AP_CTRL_GPIO GPIOA +#define AP_CTRL_PIN FL_GPIO_PIN_5 +#define AP_DEN_GPIO GPIOA +#define AP_DEN_PIN FL_GPIO_PIN_8 + + + + /******************************************************************************* * the typedefs @@ -71,9 +84,173 @@ void hw_gpio_init(void) FL_GPIO_Init(DCF1_GPIO, &GPIO_InitStruct); GPIO_InitStruct.pin = DCF1_PIN; - + FL_GPIO_Init(DCF1_GPIO, &GPIO_InitStruct); + GPIO_InitStruct.pin = DCF2_PIN; + FL_GPIO_Init(DCF2_GPIO, &GPIO_InitStruct); + GPIO_InitStruct.pin = DCF3_PIN; + FL_GPIO_Init(DCF3_GPIO, &GPIO_InitStruct); + GPIO_InitStruct.pin = DCF4_PIN; + FL_GPIO_Init(DCF4_GPIO, &GPIO_InitStruct); + GPIO_InitStruct.pin = DCF5_PIN; + FL_GPIO_Init(DCF5_GPIO, &GPIO_InitStruct); + GPIO_InitStruct.pin = DCF6_PIN; + FL_GPIO_Init(DCF6_GPIO, &GPIO_InitStruct); + GPIO_InitStruct.pin = DCF7_PIN; + FL_GPIO_Init(DCF7_GPIO, &GPIO_InitStruct); + GPIO_InitStruct.pin = DCF8_PIN; + FL_GPIO_Init(DCF8_GPIO, &GPIO_InitStruct); + GPIO_InitStruct.pin = DCF9_PIN; + FL_GPIO_Init(DCF9_GPIO, &GPIO_InitStruct); + GPIO_InitStruct.pin = DCF10_PIN; + FL_GPIO_Init(DCF10_GPIO, &GPIO_InitStruct); } +void DCF_control(DCFCH_TypeDef channel, uint8_t state) +{ + switch (channel) + { + case DCF1: + if (state == DCF_OFF) + { + FL_GPIO_ResetOutputPin(DCF1_GPIO, DCF1_PIN); + } + else + { + FL_GPIO_SetOutputPin(DCF1_GPIO, DCF1_PIN); + } + + break; + case DCF2: + if (state == DCF_OFF) + { + FL_GPIO_ResetOutputPin(DCF2_GPIO, DCF2_PIN); + } + else + { + FL_GPIO_SetOutputPin(DCF2_GPIO, DCF2_PIN); + } + break; + + case DCF3: + if (state == DCF_OFF) + { + FL_GPIO_ResetOutputPin(DCF3_GPIO, DCF3_PIN); + } + else + { + FL_GPIO_SetOutputPin(DCF3_GPIO, DCF3_PIN); + } + break; + + case DCF4: + if (state == DCF_OFF) + { + FL_GPIO_ResetOutputPin(DCF4_GPIO, DCF4_PIN); + } + else + { + FL_GPIO_SetOutputPin(DCF4_GPIO, DCF4_PIN); + } + break; + + case DCF5: + if (state == DCF_OFF) + { + FL_GPIO_ResetOutputPin(DCF5_GPIO, DCF5_PIN); + } + else + { + FL_GPIO_SetOutputPin(DCF5_GPIO, DCF5_PIN); + } + break; + + case DCF6: + if (state == DCF_OFF) + { + FL_GPIO_ResetOutputPin(DCF6_GPIO, DCF6_PIN); + } + else + { + FL_GPIO_SetOutputPin(DCF6_GPIO, DCF6_PIN); + } + break; + + case DCF7: + if (state == DCF_OFF) + { + FL_GPIO_ResetOutputPin(DCF7_GPIO, DCF7_PIN); + } + else + { + FL_GPIO_SetOutputPin(DCF7_GPIO, DCF7_PIN); + } + break; + + case DCF8: + if (state == DCF_OFF) + { + FL_GPIO_ResetOutputPin(DCF8_GPIO, DCF8_PIN); + } + else + { + FL_GPIO_SetOutputPin(DCF8_GPIO, DCF8_PIN); + } + break; + + case DCF9: + if (state == DCF_OFF) + { + FL_GPIO_ResetOutputPin(DCF9_GPIO, DCF9_PIN); + } + else + { + FL_GPIO_SetOutputPin(DCF9_GPIO, DCF9_PIN); + } + break; + + case DCF10: + if (state == DCF_OFF) + { + FL_GPIO_ResetOutputPin(DCF10_GPIO, DCF10_PIN); + } + else + { + FL_GPIO_SetOutputPin(DCF10_GPIO, DCF10_PIN); + } + break; + + default: + break; + } +} +void V2_12V_control(uint8_t state) +{ + if (state == V2_12V_OFF) + { + FL_GPIO_ResetOutputPin(V2_12V_CTRL_GPIO, V2_12V_CTRL_PIN); + FL_GPIO_ResetOutputPin(V2_12V_DEN_GPIO, V2_12V_DEN_PIN); + } + else + { + FL_GPIO_SetOutputPin(V2_12V_CTRL_GPIO, V2_12V_CTRL_PIN); + FL_GPIO_SetOutputPin(V2_12V_DEN_GPIO, V2_12V_DEN_PIN); + } +} + +void AP_control(uint8_t state) +{ + if (state == AP_OFF) + { + FL_GPIO_ResetOutputPin(AP_CTRL_GPIO, AP_CTRL_PIN); + FL_GPIO_ResetOutputPin(AP_DEN_GPIO, AP_DEN_PIN); + } + else + { + FL_GPIO_SetOutputPin(AP_CTRL_GPIO, AP_CTRL_PIN); + FL_GPIO_SetOutputPin(AP_DEN_GPIO, AP_DEN_PIN); + } +} +