diff --git a/APP/monitor_task.c b/APP/monitor_task.c index b06b7a0..996bf35 100644 --- a/APP/monitor_task.c +++ b/APP/monitor_task.c @@ -105,7 +105,7 @@ void StartMonitorTask(void * argument) }break; case 1: { - power_set(value); + power_set(0,value); }break; case 2: { @@ -373,7 +373,7 @@ void StartMonitorTask(void * argument) union {float F; uint32_t W;int32_t w; uint16_t H[2];int16_t h[2]; uint8_t B[4];}src; - src.W = power_state(); + src.W = power_state(0); send_buff[send_len++] = src.B[0]; send_buff[send_len++] = src.B[1]; send_buff[send_len++] = src.B[2]; diff --git a/BSP/drv_power.c b/BSP/drv_power.c index 1bd9f94..ecec762 100644 --- a/BSP/drv_power.c +++ b/BSP/drv_power.c @@ -41,8 +41,10 @@ void adc_init(void) bat_single.channel = ADC_SIG_VOLTAGE; bat_single.filter_buff = (double *)pvPortMalloc(FILTER_BUFF_DEEP * 8); bat_single.filter_deep = FILTER_BUFF_DEEP; - bat_single.pretask = &bat_single_setio; + + bat_single.pretask = &ExtIO_setLetch;//预处理函数 bat_single.scale = &scale_bat; + bat_single.afttask = &ExtIO_setLetch;//后处理函数 bat_voltage.channel = ADC_BAT_VOLTAGE; bat_voltage.filter_buff = (double *)pvPortMalloc(FILTER_BUFF_DEEP * 8); @@ -179,7 +181,7 @@ double get_voltage(adcInfo_t *ptr) //读取ADC前的预先工作 if(ptr->pretask) { - ptr->pretask(ptr->pre_arg); + ptr->pretask(ptr->ExtIO,ptr->Letch); } //读取ADC数值 @@ -203,7 +205,7 @@ double get_voltage(adcInfo_t *ptr) //读取之后的善后工作 if(ptr->afttask) { - ptr->afttask(ptr->aft_arg); + ptr->afttask(ptr->ExtIO,ptr->Letch); } //返回 @@ -212,58 +214,79 @@ double get_voltage(adcInfo_t *ptr) +uint32_t Lecth_State = 0x00000000; +//按位输入数据,根据位的0,1设置锁存 -//group -GPIO_TypeDef *LEIO_port[3] = {EX_LE0_GPIO_Port,EX_LE1_GPIO_Port,EX_LE2_GPIO_Port}; -uint16_t LEIO_pin[3] = {EX_LE0_Pin,EX_LE1_Pin,EX_LE2_Pin}; - - -GPIO_TypeDef *ExtIO_port[Bat_Num] = {B_RELAY_IN_GPIO_Port,B_RELAY_OUT_GPIO_Port,B_RELAY_DIS_GPIO_Port}; -uint16_t ExtIO_pin[Bat_Num] = {B_RELAY_IN_Pin,B_RELAY_OUT_Pin,B_RELAY_DIS_Pin}; - - - - - -void bat_single_setExtIO(int argc, char *argv[]) +void ExtIO_setLetch(int32_t channel,uint16_t state) { //设置IO - if(argv[1] >= Bat_Num) + if(channel >= Bat_Num) { return; } - uint8_t state = 0;//0 lock 1 unlock - - uint8_t group = 0;//0(0~7) 1(8~15) 2(16~23) - + uint8_t group = 0;//000(None) 001(0~7) 010(8~15) 100(16~23) 111(0~23) + uint8_t letch = 0; //设置通道数据 + if(channel != Bat_Num_All) + { + group |= 0x01 << (channel / 8); + //bit op 0 lock 1 unlock + if(state) + { + Lecth_State |= 0x00000001 << channel; + } + else + { + Lecth_State &= ~(0x00000001 << channel); + } + } + else + { + group = 0x07; + Lecth_State = (state)?(0xFFFFFFFF):(0x00000000); + } - - - - + switch(group) + { + case 0x01:{ + letch = Lecth_State; + }break; + case 0x02:{ + letch = Lecth_State >> 8; + }break; + case 0x04:{ + letch = Lecth_State >> 16; + }break; + case 0x07:{ + letch = Lecth_State; + }break; + } //设置数据 - HAL_GPIO_WritePin(EX_D0_GPIO_Port,EX_D0_Pin,(1)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); - HAL_GPIO_WritePin(EX_D1_GPIO_Port,EX_D1_Pin,(1)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); - HAL_GPIO_WritePin(EX_D2_GPIO_Port,EX_D2_Pin,(1)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); - HAL_GPIO_WritePin(EX_D3_GPIO_Port,EX_D3_Pin,(1)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); + HAL_GPIO_WritePin(EX_D0_GPIO_Port,EX_D0_Pin,(letch & 0x01)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); + HAL_GPIO_WritePin(EX_D1_GPIO_Port,EX_D1_Pin,(letch & 0x02)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); + HAL_GPIO_WritePin(EX_D2_GPIO_Port,EX_D2_Pin,(letch & 0x04)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); + HAL_GPIO_WritePin(EX_D3_GPIO_Port,EX_D3_Pin,(letch & 0x08)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); - HAL_GPIO_WritePin(EX_D4_GPIO_Port,EX_D4_Pin,(1)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); - HAL_GPIO_WritePin(EX_D5_GPIO_Port,EX_D5_Pin,(1)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); - HAL_GPIO_WritePin(EX_D6_GPIO_Port,EX_D6_Pin,(1)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); - HAL_GPIO_WritePin(EX_D7_GPIO_Port,EX_D7_Pin,(1)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); + HAL_GPIO_WritePin(EX_D4_GPIO_Port,EX_D4_Pin,(letch & 0x10)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); + HAL_GPIO_WritePin(EX_D5_GPIO_Port,EX_D5_Pin,(letch & 0x20)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); + HAL_GPIO_WritePin(EX_D6_GPIO_Port,EX_D6_Pin,(letch & 0x40)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); + HAL_GPIO_WritePin(EX_D7_GPIO_Port,EX_D7_Pin,(letch & 0x80)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); + //根据group设置锁存器的锁存 //锁存器解锁 - HAL_GPIO_WritePin(LEIO_port[group],LEIO_pin[group],(1)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); + HAL_GPIO_WritePin(EX_LE0_GPIO_Port,EX_LE0_Pin,(group & 0x01)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); + HAL_GPIO_WritePin(EX_LE1_GPIO_Port,EX_LE1_Pin,(group & 0x02)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); + HAL_GPIO_WritePin(EX_LE2_GPIO_Port,EX_LE2_Pin,(group & 0x04)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); //锁存器锁定 - HAL_GPIO_WritePin(LEIO_port[group],LEIO_pin[group],(0)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); + HAL_GPIO_WritePin(EX_LE0_GPIO_Port,EX_LE0_Pin,(group & 0x01)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); + HAL_GPIO_WritePin(EX_LE1_GPIO_Port,EX_LE1_Pin,(group & 0x02)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); + HAL_GPIO_WritePin(EX_LE2_GPIO_Port,EX_LE2_Pin,(group & 0x04)?(GPIO_PIN_SET):(GPIO_PIN_RESET)); - } @@ -388,7 +411,6 @@ Rt = (UxR1+(Ux-U1)R2)/(U1-Ux) #define R2 1000.0 double scale_temp(double Vx) { - double voltage = 0; double Rt = 0; Rt = (Vx*R1 + (Vx - Vi) * R2)/(Vi - Vx ); @@ -403,8 +425,6 @@ double scale_temp(double Vx) //返回温度 return temperature_deg; - - return voltage; } diff --git a/BSP/drv_power.h b/BSP/drv_power.h index add540f..ee37496 100644 --- a/BSP/drv_power.h +++ b/BSP/drv_power.h @@ -25,16 +25,12 @@ typedef struct { double *filter_buff; uint32_t filter_deep; - uint32_t *pre_arg; - uint32_t pre_num; + uint32_t ExtIO; + uint32_t Letch; - - uint32_t *aft_arg; - uint32_t aft_num; - - void (*pretask)(int argc, char *argv[]); + void (*pretask)(int32_t,uint16_t); double (*scale)(double); - void (*afttask)(int argc, char *argv[]); + void (*afttask)(int32_t,uint16_t); }adcInfo_t; @@ -82,7 +78,7 @@ void adc_init(void); double get_voltage(adcInfo_t *ptr); -void bat_single_setio(uint32_t arg); +void ExtIO_setLetch(int32_t channel,uint16_t state); double scale_single(double value); double scale_bat(double value); diff --git a/MDK-ARM/B_Current_Ctrl/B_Current_Ctrl.axf b/MDK-ARM/B_Current_Ctrl/B_Current_Ctrl.axf new file mode 100644 index 0000000..5c08674 Binary files /dev/null and b/MDK-ARM/B_Current_Ctrl/B_Current_Ctrl.axf differ diff --git a/MDK-ARM/B_Current_Ctrl/B_Current_Ctrl.build_log.htm b/MDK-ARM/B_Current_Ctrl/B_Current_Ctrl.build_log.htm index f2deee3..6f4c5e3 100644 --- a/MDK-ARM/B_Current_Ctrl/B_Current_Ctrl.build_log.htm +++ b/MDK-ARM/B_Current_Ctrl/B_Current_Ctrl.build_log.htm @@ -28,27 +28,15 @@ Project File Date: 09/30/2025 *** Using Compiler 'V5.03 [Build 24]', folder: 'C:\Keil_v5\ARM\ARMCC\Bin' Build target 'B_Current_Ctrl' compiling drv_power.c... -..\BSP\drv_power.c(130): warning: #177-D: variable "max_index" was declared but never referenced +..\BSP\drv_power.c(132): warning: #177-D: variable "max_index" was declared but never referenced int max_index = filter_deep - 1; -..\BSP\drv_power.c(131): warning: #177-D: variable "min_index" was declared but never referenced +..\BSP\drv_power.c(133): warning: #177-D: variable "min_index" was declared but never referenced int min_index = 0; -..\BSP\drv_power.c(357): warning: #111-D: statement is unreachable - return voltage; -..\BSP\drv_power.c: 3 warnings, 0 errors -compiling monitor_task.c... -..\APP\monitor_task.c(108): error: #165: too few arguments in function call - power_set(value); -..\APP\monitor_task.c(270): warning: #1035-D: single-precision operand implicitly converted to double-precision - bat_capacity = src.F * 0.001;//Ah -..\APP\monitor_task.c(376): error: #165: too few arguments in function call - src.W = power_state(); -..\APP\monitor_task.c: 1 warning, 2 errors -compiling device_task.c... -compiling main_task.c... -..\APP\main_task.c(53): warning: #177-D: variable "tick" was declared but never referenced - uint16_t tick = 0; -..\APP\main_task.c: 1 warning, 0 errors -"B_Current_Ctrl\B_Current_Ctrl.axf" - 2 Error(s), 5 Warning(s). +..\BSP\drv_power.c: 2 warnings, 0 errors +linking... +Program Size: Code=65192 RO-data=5916 RW-data=12396 ZI-data=41620 +FromELF: creating hex file... +"B_Current_Ctrl\B_Current_Ctrl.axf" - 0 Error(s), 2 Warning(s).