Forráskód Böngészése

update battery det

Signed-off-by: FuangCao <cavan.cao@foxmail.com>
FuangCao 5 éve
szülő
commit
2f070bcc94

+ 1 - 1
Project/version.txt

@@ -1 +1 @@
-PS100XX_V01_11041635
+PS100XX_V01_11041811

+ 16 - 12
Source/app.c

@@ -719,11 +719,15 @@ uint8_t Select_One_BAT(void)
 {
 	uint8_t temp_op = CB_BAT_NO;
 
-	if(Is_Sub_BMS_1_Normal())
+	if(Is_Sub_BMS_1_Normal() == SHARK_BMS_EXIT_SUCCESS)
 	{
-		if(Is_Sub_BMS_2_Normal())
+		if(Is_Sub_BMS_2_Normal() == SHARK_BMS_EXIT_SUCCESS)
 		{
-			if(sub_bms_info_1.packet_common.m_total_vol >= sub_bms_info_2.packet_common.m_total_vol)
+			if (sub_bms_info_1.open_times > sub_bms_info_2.open_times) {
+				temp_op = CB_BAT1;
+			} else if (sub_bms_info_1.open_times < sub_bms_info_2.open_times) {
+				temp_op = CB_BAT2;
+			} if(sub_bms_info_1.packet_common.m_total_vol >= sub_bms_info_2.packet_common.m_total_vol)
 			{
 				if(IS_CHARGE_IN())
 				{
@@ -751,7 +755,7 @@ uint8_t Select_One_BAT(void)
 			temp_op = CB_BAT1;
 		}
 	}
-	else if(Is_Sub_BMS_2_Normal())
+	else if(Is_Sub_BMS_2_Normal() == SHARK_BMS_EXIT_SUCCESS)
 	{
 		temp_op = CB_BAT2;
 	}
@@ -765,7 +769,7 @@ uint8_t Check_CB_BAT_1(void)
 {
 	uint8_t temp_op = CB_MAX;
 	
-	if(Is_Sub_BMS_1_Normal())
+	if(Is_Sub_BMS_1_Normal() == SHARK_BMS_EXIT_SUCCESS)
 	{
 		if((sub_bms_info_1.packet_common.bms_status & (BMS_STA_D_OPEN | BMS_STA_C_OPEN)) != (BMS_STA_D_OPEN | BMS_STA_C_OPEN))
 		{
@@ -801,7 +805,7 @@ uint8_t Check_CB_BAT_2(void)
 {
 	uint8_t temp_op = CB_MAX;
 	
-	if(Is_Sub_BMS_2_Normal())
+	if(Is_Sub_BMS_2_Normal() == SHARK_BMS_EXIT_SUCCESS)
 	{
 		if((sub_bms_info_2.packet_common.bms_status & (BMS_STA_D_OPEN | BMS_STA_C_OPEN)) != (BMS_STA_D_OPEN | BMS_STA_C_OPEN))
 		{
@@ -854,7 +858,7 @@ uint8_t Check_CB_BAT1_BAT2_PARRALLEL(void)
 		return temp_op;
 	}
 	//
-	if(Is_Sub_BMS_1_Normal()&&Is_Sub_BMS_2_Normal())
+	if(Is_Sub_BMS_1_Normal() == SHARK_BMS_EXIT_SUCCESS && Is_Sub_BMS_2_Normal() == SHARK_BMS_EXIT_SUCCESS)
 	{
 		if((sub_bms_info_1.packet_common.bms_status & (BMS_STA_D_OPEN | BMS_STA_C_OPEN)) != (BMS_STA_D_OPEN | BMS_STA_C_OPEN))
 		{
@@ -1005,7 +1009,7 @@ uint8_t Check_CB_BAT1_BAT2_SERIES(void)
 		return temp_op;
 	}	
 	
-	if(Is_Sub_BMS_1_Normal()&&Is_Sub_BMS_2_Normal())
+	if(Is_Sub_BMS_1_Normal() == SHARK_BMS_EXIT_SUCCESS && Is_Sub_BMS_2_Normal() == SHARK_BMS_EXIT_SUCCESS)
 	{
 		if((sub_bms_info_1.packet_common.bms_status & (BMS_STA_D_OPEN | BMS_STA_C_OPEN)) != (BMS_STA_D_OPEN | BMS_STA_C_OPEN))
 		{
@@ -1327,11 +1331,11 @@ void Check_Charge_In(void)
 
 uint8_t Change_Mode_Sub_BMS_1_Normal(void)
 {
-	return Is_Sub_BMS_1_Normal();
+	return Is_Sub_BMS_1_Normal() == SHARK_BMS_EXIT_SUCCESS;
 }
 uint8_t Change_Mode_Sub_BMS_2_Normal(void)
 {
-	return Is_Sub_BMS_2_Normal();
+	return Is_Sub_BMS_2_Normal() == SHARK_BMS_EXIT_SUCCESS;
 }
 
 uint8_t Change_Mode_Sub_BMS_PARRALLEL(void)
@@ -1346,7 +1350,7 @@ uint8_t Change_Mode_Sub_BMS_PARRALLEL(void)
 	if(is_intelligent && CB_OPERATE_PRECEDENCE_PARRALLEL != PRE_PARRALLEL)
 		return 0;
 	//
-	if(Is_Sub_BMS_1_Normal()&&Is_Sub_BMS_2_Normal())
+	if(Is_Sub_BMS_1_Normal() == SHARK_BMS_EXIT_SUCCESS && Is_Sub_BMS_2_Normal() == SHARK_BMS_EXIT_SUCCESS)
 		;
 	else
 		return 0;
@@ -1390,7 +1394,7 @@ uint8_t Change_Mode_Sub_BMS_SERIES(void)
 	if(IS_CHARGE_IN())
 		return 0;
 	
-	if(!(Is_Sub_BMS_1_Normal()&&Is_Sub_BMS_2_Normal()))
+	if(!(Is_Sub_BMS_1_Normal() == SHARK_BMS_EXIT_SUCCESS && Is_Sub_BMS_2_Normal() == SHARK_BMS_EXIT_SUCCESS))
 		return 0;
 
 	/*if(cb_operate_state == CB_BAT1)

+ 2 - 2
Source/app.h

@@ -4,8 +4,8 @@
 //#define IS_CHARGE_IN()			!gpio_input_bit_get(GPIOC,GPIO_PIN_4)
 #define IS_CHARGER_ON() 		gpio_output_bit_get(GPIOB,GPIO_PIN_12)
 #define CHARG_PROTECT_OPEN(x)   gpio_bit_write(GPIOB,GPIO_PIN_12,(bit_status)(x))
-#define BAT1_IS_OPEN()          !gpio_input_bit_get(GPIOC,GPIO_PIN_2)
-#define BAT2_IS_OPEN()          !gpio_input_bit_get(GPIOC,GPIO_PIN_1)
+#define BAT1_IS_OPEN()          (!gpio_input_bit_get(GPIOC,GPIO_PIN_2))
+#define BAT2_IS_OPEN()          (!gpio_input_bit_get(GPIOC,GPIO_PIN_1))
 
 #define S10_ENABLE(x)  //gpio_bit_write()
 #define S11_ENABLE(x)  gpio_bit_write(GPIOB,GPIO_PIN_13,(bit_status)(x))

+ 1 - 1
Source/app_bms_1.c

@@ -169,7 +169,7 @@ int8_t Rsp_Can_Bms_1_CMD(CAN_FRAME*can_bms_1_frame)
 					//bang zi ce shi start
 					#else
 					{
-						if(Is_Sub_BMS_1_Normal())
+						if(Is_Sub_BMS_1_Normal() == SHARK_BMS_EXIT_SUCCESS)
 						{
 							temp = (uint16_t)(sub_bms_info_1.packet_common.m_percent*sheng_yu_li_cheng.sy_ss_parm.neng_hao_bi*10/1000);
 							if(temp%10 >= 5)

+ 1 - 1
Source/app_bms_2.c

@@ -168,7 +168,7 @@ int8_t Rsp_Can_Bms_2_CMD(CAN_FRAME*can_bms_2_frame)
 					//bang zi ce shi start
 					#else
 					{
-						if(Is_Sub_BMS_2_Normal())
+						if(Is_Sub_BMS_2_Normal() == SHARK_BMS_EXIT_SUCCESS)
 						{
 							temp = (uint16_t)(sub_bms_info_2.packet_common.m_percent*sheng_yu_li_cheng.sy_ss_parm.neng_hao_bi*10/1000);
 							if(temp%10 >= 5)

+ 22 - 43
Source/app_rs485_1.c

@@ -495,54 +495,33 @@ uint8_t Is_Sub_BMS_1_Normal(void)
 		work_sta &= ~ST_UDR_TEMPE_CHRG;
 	}
 
-	
-	do
-	{
-		/*if(cb_operate_state != CB_BAT1_BAT2_PARRALLEL && cb_operate_state != CB_BAT_NO  )
-		{
-			if((BAT1_IS_OPEN() == 0))
-				break;
-		}*/
+	if(update_bat.ub_bat == UPDATE_BAT_1) {
+		return SHARK_BMS_EXIT_UPGRADE;
+	}
 
-		if(update_bat.ub_bat == UPDATE_BAT_1) {
-			break;
-		}
-		
-		if(define_bms_1_error != D_BMS_ERROR_NO) {
-			break;
-		}
-		
-		if((cb_operate_state == CB_BAT1_BAT2_SERIES)&&(BAT1_IS_OPEN() == 0)) {
-				break;
-		}
+	if(define_bms_1_error != D_BMS_ERROR_NO) {
+		return SHARK_BMS_EXIT_ERROR;
+	}
 
-		if(Is_Soak()) {
-			break;
-		}
-		
-		if(SUB_BMS_1_DEC() == 0) {			
-			break;
-		}
-		
-		if(work_sta)
-		{
-			bms_1_work_status = sub_bms_info_1.packet_common.work_status;			
-			break;
-		}
+	if(Is_Soak()) {
+		return SHARK_BMS_EXIT_SOAK;
+	}
 
-		if(sub_bms_1_lt_state != SUB_BMS_CONT_HV485) {			
-			break;
-		}
+	if(work_sta)
+	{
+		bms_1_work_status = sub_bms_info_1.packet_common.work_status;			
+		return SHARK_BMS_EXIT_ERROR;
+	}
 
-		if(bms_1_test_define_error != 0) {			
-			break;
-		}
-		
-		return 1;
-	}while(0);
+	if(sub_bms_1_lt_state != SUB_BMS_CONT_HV485) {			
+		return SHARK_BMS_EXIT_485;
+	}
 
-	return 0;
-	
+	if(bms_1_test_define_error != 0) {			
+		return SHARK_BMS_EXIT_ERROR;
+	}
+
+	return SHARK_BMS_EXIT_SUCCESS;
 }
 
 int8_t Operate_Sub_BMS_1_CD(uint8_t on)

+ 13 - 2
Source/app_rs485_1.h

@@ -78,6 +78,15 @@ typedef struct
 #define ENG_COMMAND                          (0x40)
 
 /*******************************************BMS֡ͷ-end*********************************************************/
+
+typedef enum {
+	SHARK_BMS_EXIT_SUCCESS,
+	SHARK_BMS_EXIT_UPGRADE,
+	SHARK_BMS_EXIT_ERROR,
+	SHARK_BMS_EXIT_SOAK,
+	SHARK_BMS_EXIT_485,
+} shark_bms_exit_code_t;
+
 #pragma  pack (push,1)  
 typedef struct
 {
@@ -149,6 +158,8 @@ typedef struct
 	
 	uint8_t rs485_connect;
 	uint8_t rs485_time_out;
+
+	uint16_t open_times;
 }SUB_BMS_INFO;
 
 extern SUB_BMS_INFO sub_bms_info_1;
@@ -317,9 +328,9 @@ void  Sub_BMS_1_lt_State(void);
 
 void  Sub_BMS_2_lt_State(void);
 
-uint8_t Is_Sub_BMS_1_Normal(void);
+shark_bms_exit_code_t Is_Sub_BMS_1_Normal(void);
 
-uint8_t Is_Sub_BMS_2_Normal(void);
+shark_bms_exit_code_t Is_Sub_BMS_2_Normal(void);
 
 int8_t Operate_Sub_BMS_1_CD(uint8_t on);
 

+ 22 - 41
Source/app_rs485_2.c

@@ -490,52 +490,33 @@ uint8_t Is_Sub_BMS_2_Normal(void)
 		work_sta &= ~ST_UDR_TEMPE_CHRG;
 	}
 
-	do
-	{
+	if(update_bat.ub_bat == UPDATE_BAT_2) {
+		return SHARK_BMS_EXIT_UPGRADE;
+	}
 
-		/*if(cb_operate_state != CB_BAT1_BAT2_PARRALLEL && cb_operate_state != CB_BAT_NO  )
-		{
-			if((BAT2_IS_OPEN() == 0))
-				break;
-		}*/
+	if(define_bms_2_error != D_BMS_ERROR_NO) {			
+		return SHARK_BMS_EXIT_ERROR;
+	}
 
-		if(update_bat.ub_bat == UPDATE_BAT_2) {
-			break;
-		}
-		
-		if(define_bms_2_error != D_BMS_ERROR_NO) {			
-			break;
-		}
-		
-		if((cb_operate_state == CB_BAT1_BAT2_SERIES)&&(BAT2_IS_OPEN() == 0)) {			
-				break;
-		}
-		if(Is_Soak()) {
-			break;
-		}
-		
-		if(SUB_BMS_2_DEC() == 0) {
-			break;
-		}
-		
-		if(work_sta)
-		{
-			bms_2_work_status = sub_bms_info_2.packet_common.work_status;
-			break;
-		}
+	if(Is_Soak()) {
+		return SHARK_BMS_EXIT_SOAK;
+	}
 
-		if(sub_bms_2_lt_state != SUB_BMS_CONT_HV485) {
-			break;
-		}
+	if(work_sta)
+	{
+		bms_2_work_status = sub_bms_info_2.packet_common.work_status;
+		return SHARK_BMS_EXIT_ERROR;
+	}
 
-		if(bms_2_test_define_error != 0) {
-			break;
-		}
-		
-		return 1;
-	}while(0);
+	if(sub_bms_2_lt_state != SUB_BMS_CONT_HV485) {
+		return SHARK_BMS_EXIT_485;
+	}
 
-	return 0;
+	if(bms_2_test_define_error != 0) {
+		return SHARK_BMS_EXIT_ERROR;
+	}
+
+	return SHARK_BMS_EXIT_SUCCESS;
 	
 }
 

+ 24 - 12
Source/delay.c

@@ -16,7 +16,7 @@
 #include "low_power.h"
 #include "hardware_test.h"
 
-static uint32_t delay = 0;
+uint64_t shark_mseconds;
 uint32_t utc_seconds = 1505216210;// 2017/9/12  19:37:50
 uint16_t s_ms ;
 
@@ -51,8 +51,6 @@ void systick_config(void)
 	}
     NVIC_SetPriority(SysTick_IRQn, 0x00U);
 
-	delay = 0;
-
 	s_ms = 0;
 }
 
@@ -64,9 +62,8 @@ void systick_config(void)
 */
 void delay_1ms(uint32_t count)
 {
-    delay = count;
-
-    while(0 != delay);
+	uint64_t time = shark_mseconds + count;
+	while (time > shark_mseconds);
 }
 
 #if 0
@@ -86,8 +83,26 @@ void delay_decrement(void)
 
 void SysTick_Handler(void)
 {
+	shark_mseconds++;
+
 	//uint8_t i,j;
-	
+
+	if (BAT1_IS_OPEN()) {
+		if (sub_bms_info_1.open_times < 0xFFFF) {
+			sub_bms_info_1.open_times++;
+		}
+	} else if (sub_bms_info_1.open_times > 0) {
+		sub_bms_info_1.open_times--;
+	}
+
+	if (BAT2_IS_OPEN()) {
+		if (sub_bms_info_2.open_times < 0xFFFF) {
+			sub_bms_info_2.open_times++;
+		}
+	} else if (sub_bms_info_2.open_times > 0) {
+		sub_bms_info_2.open_times--;
+	}
+
 	if(++s_ms >= 1000)
 	{
 		utc_seconds++;
@@ -95,12 +110,9 @@ void SysTick_Handler(void)
 
 		Measure_Temprature_Delay();
 
-		Save_Param_Time_Out();

+		Save_Param_Time_Out();
+
 	}
-		
-	if (0 != delay){ 
-        delay--;
-    }
 
 	ACC2_PWM();
 	

+ 6 - 0
Source/delay.h

@@ -2,6 +2,7 @@
 #define __DELAY_H 			   
 
 extern uint32_t utc_seconds;
+extern uint64_t shark_mseconds;
 
 
 void systick_close(void);
@@ -9,6 +10,11 @@ void systick_config(void);
 void delay_1ms(uint32_t count);
 void delay_1us(uint16_t cnt);
 
+static inline uint64_t shark_get_mseconds(void)
+{
+	return shark_mseconds;
+}
+
 #endif
 
 

+ 13 - 12
Source/drv_adc.c

@@ -2,7 +2,7 @@
 #include "drv_adc.h"
 
 
-int8_t Sample_ADC_Value(uint8_t channel,uint16_t *ADC1ConvertedValue)
+int8_t Sample_ADC_Values(uint8_t channel, uint16_t *buff, uint8_t times)
 {
 
 	    /* reset ADC */
@@ -32,11 +32,15 @@ int8_t Sample_ADC_Value(uint8_t channel,uint16_t *ADC1ConvertedValue)
     delay_1ms(1);
     /* ADC calibration and reset calibration */
     adc_calibration_enable(ADC0);
-	
-	adc_software_trigger_enable(ADC0,ADC_REGULAR_CHANNEL);
-    while(SET != adc_flag_get(ADC0,ADC_FLAG_EOC));
-    *ADC1ConvertedValue = adc_regular_data_read(ADC0);
-	adc_flag_clear(ADC0,ADC_FLAG_EOC);
+
+	while (times > 0) {
+		adc_software_trigger_enable(ADC0,ADC_REGULAR_CHANNEL);
+		while(SET != adc_flag_get(ADC0,ADC_FLAG_EOC));
+		*buff++ = adc_regular_data_read(ADC0);
+		adc_flag_clear(ADC0,ADC_FLAG_EOC);
+		times--;
+	}
+
 	//printf("adc:%d\r\n",*ADC1ConvertedValue);
 	return 1;
 }
@@ -56,13 +60,10 @@ int8_t adc_getResult_6t(unsigned char chNo, unsigned short* result)
 		return(ADC_R_ERR_NULL);
 	}
 
-	for(i=0u;i<ADC_GETRESULT_6TIMES;i++)
+	ret = Sample_ADC_Values(chNo, Vsample, ADC_GETRESULT_6TIMES);
+	if(ret <= 0)
 	{
-		ret=Sample_ADC_Value(chNo, &Vsample[i]);
-		if(ret <= 0)
-		{
-			return ADC_R_ERR_CHNUM;
-		}
+		return ADC_R_ERR_CHNUM;
 	}
 	
 	s_min = 0u;

+ 1 - 1
Source/drv_adc.h

@@ -21,7 +21,7 @@ enum
 #define Mea_Temp_Enable(x)  gpio_bit_write(GPIOC,GPIO_PIN_3,(bit_status)(x))
 
 
-int8_t Sample_ADC_Value(uint8_t channel,uint16_t *ADC1ConvertedValue);
+int8_t Sample_ADC_Values(uint8_t channel, uint16_t *buff, uint8_t times);
 
 int8_t adc_getResult_6t(unsigned char chNo, unsigned short* result);
 

+ 2 - 3
Source/drv_io.c

@@ -371,13 +371,11 @@ void EXTI0_IRQHandler(void)
     }
 }
 
-uint8_t shark_battery_shake1;
-uint8_t shark_battery_shake2;
-
 void EXTI1_IRQHandler(void)
 {
 	if (RESET != exti_flag_get(EXTI_1)) {
 		exti_flag_clear(EXTI_1);
+		sub_bms_info_2.open_times = 0;
 	}
 }
 
@@ -385,6 +383,7 @@ void EXTI2_IRQHandler(void)
 {
 	if (RESET != exti_flag_get(EXTI_2)) {
 		exti_flag_clear(EXTI_2);
+		sub_bms_info_1.open_times = 0;
 	}
 }
 

+ 1 - 1
Source/sw_build_info.h

@@ -1,3 +1,3 @@
 #pragma once
 
-#define CONFIG_VERSION "PS100XX_V01_11041635"
+#define CONFIG_VERSION "PS100XX_V01_11041811"