2 Commits ea1df6414e ... 29733a9f50

Auteur SHA1 Bericht Datum
  Chenyingjia 29733a9f50 add 1.3.18 2 jaren geleden
  Chenyingjia 11c8b3c754 battery changer 2 jaren geleden
6 gewijzigde bestanden met toevoegingen van 276 en 64 verwijderingen
  1. 204 35
      app/app_chargerpin_conn_detect.c
  2. 21 3
      app/app_one_wire.c
  3. 3 0
      app/app_one_wire.h
  4. 18 6
      hal/hal_battery/hal_battery_NoPowerEnPin.c
  5. 29 19
      system/selfcheck.c
  6. 1 1
      system/usr_config.h

+ 204 - 35
app/app_chargerpin_conn_detect.c

@@ -69,6 +69,15 @@ void fml_adc_callback(uint32_t sample_point, Fml_Adc_All_Channel_Adc_Value_t all
 					app_pair_host_process_case1();
 				}
 			}
+			
+			if(client_ram.init)
+			{
+				if(client_ram.statu == 1)
+				{
+					client_ram.adc_value=all_adc_value.channel_4_adc_value;
+					app_pair_client_process_case1();
+				}
+			}			
 			break;
 		case FML_ADC_SAMPLE_POINT_1:
 			//PAIR_CHARGERPIN_PRINT("FML_ADC_SAMPLE_POINT_1 NULL %d\n",all_adc_value.channel_4_adc_value);
@@ -83,15 +92,6 @@ void fml_adc_callback(uint32_t sample_point, Fml_Adc_All_Channel_Adc_Value_t all
 			break;
 	}
 	
-	if(client_ram.init)
-	{
-		if(client_ram.statu == 1)
-		{
-			client_ram.adc_value=all_adc_value.channel_4_adc_value;
-			app_pair_client_process_case1();
-		}
-	}
-	
 	#else
 	static char asjdhaskjhdki=0;
 	PAIR_CHARGERPIN_PRINT("ADC_Read fml_adc_callback %d\n", all_adc_value.channel_4_adc_value);
@@ -141,19 +141,27 @@ static void null_pcs(void)
 //-------------------------------------------
 unsigned char shefcheck_buff[5];
 char shefcheck_event_fag=0;
+
 check_callbackt check_callbackt_ram;
 Event check_callback_find_hi_ram;
 void shefcheck_event(unsigned char *buff, int length)
 {
 	shefcheck_event_fag=1;
 }
+
+char one_byte_receive_error_code=0;
+void one_byte_receive_Event_err_hander(unsigned char error_code)
+{
+	one_byte_receive_error_code=1;
+}
+
 void check_callback_regist(check_callbackt evt)
 {
-check_callbackt_ram=evt;
+	check_callbackt_ram=evt;
 }
 void check_callback_find_hi_regist(Event evt)
 {
-check_callback_find_hi_ram=evt;
+	check_callback_find_hi_ram=evt;
 }
 //-------------------------------------------
 
@@ -189,6 +197,10 @@ void app_pair_host_process_case1(void)
 						Process_SetHoldOn(app_pair_host_process,1);
 						one_byte_receive_init(shefcheck_buff,2,shefcheck_event);
 						shefcheck_event_fag=0;
+						
+						one_byte_receive_Event_err_register(one_byte_receive_Event_err_hander);
+						one_byte_receive_error_code=0;
+						
 						fml_adc_remove_pin_channel(PIN_CHARGING, PIN_CHARGING_CHANNEL);
 						if(check_callback_find_hi_ram)check_callback_find_hi_ram();
 						PAIR_CHARGERPIN_INFO("INTO SHELF_CHECK_ADC_VALUE %d\n", mFlash.isHost);
@@ -255,6 +267,120 @@ void app_pair_host_process_case2(void)
 					host_ram.statu=1;
 				}
 }
+char host_into_fig_status=0;
+void host_into_fig(void *t)
+{
+	static short count=0;
+	static unsigned int bit_width = 0;
+	static unsigned int now_bit = 0;
+	
+	switch(host_into_fig_status)
+	{
+		case 0:
+			count=0;
+					nrf_gpio_cfg(
+					PIN_CHARGING,
+					NRF_GPIO_PIN_DIR_OUTPUT,
+					NRF_GPIO_PIN_INPUT_CONNECT,
+					NRF_GPIO_PIN_NOPULL,
+					NRF_GPIO_PIN_D0H1,
+					NRF_GPIO_PIN_NOSENSE);
+			nrf_gpio_cfg_watcher(PIN_CHARGING);
+			host_into_fig_status = 1;
+			nrf_gpio_pin_clear(PIN_CHARGING);
+			break;
+		case 1:
+			count++;
+			if(count>50)
+			{
+				host_into_fig_status = 2;
+				nrf_gpio_pin_set(PIN_CHARGING);
+				count=0;
+			}
+			break;
+		case 2:
+			count++;
+			if(count>50)
+			{
+				host_into_fig_status = 20;
+				nrf_gpio_pin_clear(PIN_CHARGING);
+				TIME_UnRegist(host_into_fig);
+			}
+			break;
+			
+		case 10:
+			count=0;
+					nrf_gpio_cfg(
+					PIN_CHARGING,
+					NRF_GPIO_PIN_DIR_OUTPUT,
+					NRF_GPIO_PIN_INPUT_CONNECT,
+					NRF_GPIO_PIN_NOPULL,
+					NRF_GPIO_PIN_D0H1,
+					NRF_GPIO_PIN_NOSENSE);
+			nrf_gpio_cfg_watcher(PIN_CHARGING);
+			host_into_fig_status = 11;
+			bit_width=0;
+			nrf_gpio_pin_clear(PIN_CHARGING);
+			now_bit = nrf_gpio_pin_read(PIN_CHARGING);
+			break;
+		
+		case 11:
+			if (now_bit == nrf_gpio_pin_read(PIN_CHARGING))
+			{
+					bit_width++;
+			}
+			else
+			{	
+				if(now_bit==0)//上升
+				{
+					now_bit=1;
+				}
+				else//下降
+				{
+					now_bit=0;
+					if((bit_width>48)&&(bit_width<60))
+					{
+						host_into_fig_status = 20;
+						TIME_UnRegist(host_into_fig);		
+					}
+				}
+				bit_width=0;
+			}
+			count++;
+			if(count>220)
+			{
+				host_into_fig_status = 30;
+				TIME_UnRegist(host_into_fig);			
+			}
+			break;
+	}
+}
+
+void send_host_into_fig(void)
+{
+	TIME_Regist(host_into_fig);
+	host_into_fig_status=0;
+}
+
+char host_into_fig_senddone(void)
+{
+	if(host_into_fig_status==20)return 1;
+	else return 0;
+}
+
+char host_into_fig_receivedone(void)
+{
+	if(host_into_fig_status==20)return 1;
+	if(host_into_fig_status==30)return 2;
+	else return 0;
+}
+
+void receive_host_into_fig(void)
+{
+	TIME_Regist(host_into_fig);
+	host_into_fig_status=10;
+}
+
 
 static void app_pair_host_process(void)
 {
@@ -274,7 +400,7 @@ static void app_pair_host_process(void)
 			case 2:
 			
 				break;
-			case 3://é?à-è?′ó?ú·¢??????D?o?
+			case 3://
 				if ((TIME_GetTicks() - host_ram.delay_pair_count > ADC_CHECKMS+ADC_CHECKMS))
 				{
 					PAIR_CHARGERPIN_PRINT(" UP pull over time  %d \n", TIME_GetTicks());
@@ -295,17 +421,10 @@ static void app_pair_host_process(void)
 			case 4:
 				if(nrf_gpio_pin_read(PIN_CHARGING)==0)
 				{
-					PAIR_CHARGERPIN_PRINT(" into_event  %d \n", TIME_GetTicks());
 					host_ram.statu=5;
 					host_ram.delay_pair_count=TIME_GetTicks();
-					
-				
 					fml_adc_remove_pin_channel(PIN_CHARGING, PIN_CHARGING_CHANNEL);
-					
-					
-					log("into_event-H\n");
-					host_ram.into_event();
-					
+					send_host_into_fig();		
 				}
 				else if(TIME_GetTicks() - host_ram.delay_pair_count > 500)
 				{
@@ -316,7 +435,18 @@ static void app_pair_host_process(void)
 					i=3;					
 				}
 				break;
+				
 			case 5:
+				if(host_into_fig_senddone())
+				{
+					host_ram.statu=6;
+					host_ram.into_event();
+					PAIR_CHARGERPIN_PRINT(" into_event  %d \n", TIME_GetTicks());
+					host_ram.delay_pair_count=TIME_GetTicks();
+				}
+				break;
+			
+			case 6:
 				if (TIME_GetTicks() - host_ram.delay_pair_count > PAIROVERTIME)
 				{
 					PAIR_CHARGERPIN_PRINT("  over_event %d\n", TIME_GetTicks());
@@ -329,21 +459,30 @@ static void app_pair_host_process(void)
 				break;
 //==============================s				
 			case 11:
-				if((TIME_GetTicks() - host_ram.delay_pair_count > 5000)||(shefcheck_event_fag))
+				if((TIME_GetTicks() - host_ram.delay_pair_count > 5000)||(shefcheck_event_fag)||(one_byte_receive_error_code==1))
 				{
 					if(shefcheck_event_fag)
 					{
-						if(check_callbackt_ram)check_callbackt_ram(shefcheck_buff[0]);
+						if(check_callbackt_ram)
+						{
+							check_callbackt_ram(shefcheck_buff[0]);
+							PAIR_CHARGERPIN_INFO("check_callbackt_ram(shefcheck_buff[0]); %d\n", shefcheck_buff[0]);
+						}
 					}
 					else 
 					{
 						PAIR_CHARGERPIN_PRINT("  =====================wait low over time %d\n", nrf_gpio_pin_read(PIN_CHARGING));
 					}
+					if(one_byte_receive_error_code==1)
+					{
+						one_byte_receive_error_code=0;
+						PAIR_CHARGERPIN_INFO("EXTI SHELF_CHECK_ADC_VALUE %d one_byte_receive_error_code\n", mFlash.isHost);
+					}
 					host_ram.statu=0;
 					Process_UpdatePeroid(app_pair_host_process,ADC_CHECKMS);
 					Process_SetHoldOn(app_pair_host_process,0);
 					one_byte_receive_uninit();
-					PAIR_CHARGERPIN_INFO("EXTI SHELF_CHECK_ADC_VALUE %d\n", mFlash.isHost);
+					PAIR_CHARGERPIN_INFO("EXTI SHELF_CHECK_ADC_VALUE %d %d\n", mFlash.isHost,one_byte_receive_error_code);
 					i=3;					
 				}
 				break;
@@ -355,7 +494,7 @@ static void app_pair_host_process(void)
 
 
 #define CONN_MAX_ADC 1000
-#define CONN_MIN_ADC 600
+#define CONN_MIN_ADC 750
 void app_pair_client_init(Event into,Event over)
 {
 	client_ram.init=1;
@@ -395,12 +534,12 @@ void app_pair_client_process_case1(void)
 						client_ram.pair_line=CHARGE;
 					}
 				}
-				else if(client_ram.adc_value>CONN_MIN_ADC)
+				else if((client_ram.adc_value>CONN_MIN_ADC)&&(client_ram.adc_value<CONN_MIN_ADC+100))
 				{
 					PAIR_CHARGERPIN_PRINT("CONNECT_NO_CHARGE\n");
 					if(client_ram.pair_line!=CONNECT_NO_CHARGE)
 					{
-						PAIR_CHARGERPIN_INFO("INTO CONNECT_NO_CHARGE %d\n", mFlash.isHost);
+						PAIR_CHARGERPIN_INFO("INTO CONNECT_NO_CHARGE %d %d\n", mFlash.isHost,client_ram.adc_value);
 						client_ram.pair_line=CONNECT_NO_CHARGE;	
 
 						
@@ -444,6 +583,10 @@ void app_pair_client_process_case1(void)
 						Process_SetHoldOn(app_pair_client_process,1);
 						one_byte_receive_init(shefcheck_buff,2,shefcheck_event);
 						shefcheck_event_fag=0;
+						
+						one_byte_receive_Event_err_register(one_byte_receive_Event_err_hander);
+						one_byte_receive_error_code=0;
+						
 						fml_adc_remove_pin_channel(PIN_CHARGING, PIN_CHARGING_CHANNEL);
 						PAIR_CHARGERPIN_INFO("INTO SHELF_CHECK_ADC_VALUE %d\n", 1);
 						if(check_callback_find_hi_ram)
@@ -482,26 +625,42 @@ static void app_pair_client_process(void)
 					client_ram.delay_pair_count=TIME_GetTicks();
 				}
 				break;
+				
 			case 3:
 				if(nrf_gpio_pin_read(PIN_CHARGING)==0)
 				{
-					log("into_event-C\n");
-					client_ram.into_event();	
-					client_ram.delay_pair_count=TIME_GetTicks();
-					PAIR_CHARGERPIN_PRINT("  into_event-C %d\n", TIME_GetTicks());
-					PAIR_CHARGERPIN_PRINT("  wait pair %d\n", nrf_gpio_pin_read(PIN_CHARGING));	
+					receive_host_into_fig();
 					client_ram.statu=4;
 				}
 				else if(TIME_GetTicks() - client_ram.delay_pair_count > 100)
 				{
-					PAIR_CHARGERPIN_PRINT("  wait low over time %d\n", nrf_gpio_pin_read(PIN_CHARGING));
+					PAIR_CHARGERPIN_PRINT("  wait low over time1 %d\n", nrf_gpio_pin_read(PIN_CHARGING));
 					client_ram.statu=0;
 					Process_UpdatePeroid(app_pair_client_process,ADC_CHECKMS);
 					Process_SetHoldOn(app_pair_client_process,0);	
 					i=3;					
 				}
 				break;
+				
 			case 4:
+				if(host_into_fig_receivedone()==1)
+				{
+					client_ram.into_event();	
+					client_ram.delay_pair_count=TIME_GetTicks();
+					PAIR_CHARGERPIN_PRINT("  into_event-C %d\n", TIME_GetTicks());
+					client_ram.statu=5;
+				}
+				else if(host_into_fig_receivedone()==2)
+				{
+					PAIR_CHARGERPIN_PRINT("  wait low over time %d\n", nrf_gpio_pin_read(PIN_CHARGING));
+					client_ram.statu=0;
+					Process_UpdatePeroid(app_pair_client_process,ADC_CHECKMS);
+					Process_SetHoldOn(app_pair_client_process,0);	
+					i=3;	
+				}
+				break;
+				
+			case 5:
 				if (TIME_GetTicks() - client_ram.delay_pair_count > PAIROVERTIME)
 				{
 					client_ram.statu=0;
@@ -514,21 +673,31 @@ static void app_pair_client_process(void)
 				break;
 //==============================s				
 			case 11:
-				if((TIME_GetTicks() - client_ram.delay_pair_count > 5000)||(shefcheck_event_fag))
+				if((TIME_GetTicks() - client_ram.delay_pair_count > 5000)||(shefcheck_event_fag)||(one_byte_receive_error_code==1))
 				{
 					if(shefcheck_event_fag)
 					{
-						if(check_callbackt_ram)check_callbackt_ram(shefcheck_buff[0]);
+						if(check_callbackt_ram)
+						{
+							check_callbackt_ram(shefcheck_buff[0]);
+							PAIR_CHARGERPIN_INFO("check_callbackt_ram(shefcheck_buff[0]); %d\n", shefcheck_buff[0]);
+						}
 					}
 					else 
 					{
 						PAIR_CHARGERPIN_PRINT("  =====================wait low over time %d\n", nrf_gpio_pin_read(PIN_CHARGING));
 					}
+					
+					if(one_byte_receive_error_code==1)
+					{
+						one_byte_receive_error_code=0;
+						PAIR_CHARGERPIN_INFO("EXTI SHELF_CHECK_ADC_VALUE %d one_byte_receive_error_code\n", mFlash.isHost);
+					}
 					client_ram.statu=0;
 					Process_UpdatePeroid(app_pair_client_process,ADC_CHECKMS);
 					Process_SetHoldOn(app_pair_client_process,0);
 					one_byte_receive_uninit();
-					PAIR_CHARGERPIN_INFO("EXTI SHELF_CHECK_ADC_VALUE %d\n", 1);
+					PAIR_CHARGERPIN_INFO("EXTI SHELF_CHECK_ADC_VALUE %d %d\n", mFlash.isHost,one_byte_receive_error_code );
 					i=3;					
 				}
 				break;

+ 21 - 3
app/app_one_wire.c

@@ -514,7 +514,12 @@ struct
 	unsigned short length;
 	int value ;
 	_Event _evt;
+	_Event_ERR _evt_err;
 }one_byte_ram;
+void one_byte_receive_Event_err_register(_Event_ERR _cb)
+{
+	one_byte_ram._evt_err=_cb;
+}
 void one_byte_receive_init(unsigned char *recbuff,unsigned short len,_Event evt)
 {
 		nrf_gpio_cfg(
@@ -578,6 +583,15 @@ void one_byte_receive_pcs(void*t)
 					}
 					one_byte_ram.bit_width=0;
 				}
+				
+				if(one_byte_ram.now_bit==0)
+				{
+					if(one_byte_ram.bit_width>1.5*one_byte_ram.cf_BIT_WIDTH+15)
+					{
+						if(one_byte_ram._evt_err)one_byte_ram._evt_err(1);//低电平长度错误
+					}
+				}
+				
 				break;
 			case 2:
 				one_byte_ram.tim_cun++;
@@ -606,11 +620,11 @@ void one_byte_receive_pcs(void*t)
 								PAIR_CHARGERPIN_PRINT("%d %d %3d %d\r\n", one_byte_ram.bitindex,one_byte_ram.byteindex,one_byte_ram.value,one_byte_ram.value > 0);
 								if (one_byte_ram.value > 0)
 								{
-										one_byte_ram.buff[one_byte_ram.byteindex] |= 0x01 << one_byte_ram.bitindex;
+										one_byte_ram.buff[one_byte_ram.byteindex] |= 0x01 <<(7 - one_byte_ram.bitindex);
 								}
 								else
 								{
-										one_byte_ram.buff[one_byte_ram.byteindex] &= ~(0x01 << one_byte_ram.bitindex);
+										one_byte_ram.buff[one_byte_ram.byteindex] &= ~(0x01 << (7 - one_byte_ram.bitindex));
 								}							
 							}
 							else if((one_byte_ram.bitindex==0)&&(one_byte_ram.byteindex==one_byte_ram.length))
@@ -650,7 +664,11 @@ void one_byte_receive_pcs(void*t)
 						{
 							if((one_byte_ram.bit_width > 1.5*one_byte_ram.cf_BIT_WIDTH-5)&&(one_byte_ram.bit_width < 1.5*one_byte_ram.cf_BIT_WIDTH+5))
 							{
-								if(one_byte_ram._evt)one_byte_ram._evt(one_byte_ram.buff,one_byte_ram.byteindex);
+								if(one_byte_ram._evt)
+								{
+									one_byte_ram._evt(one_byte_ram.buff,one_byte_ram.byteindex);
+									PAIR_CHARGERPIN_INFO("one_byte_ram.buff[0] %d one_byte_ram.byteindex %d \r\n", one_byte_ram.buff[0], one_byte_ram.byteindex);
+								}
 								PAIR_CHARGERPIN_PRINT("  one_byte_ram._evt  \r\n");
 								PAIR_CHARGERPIN_PRINT("  receive done tim %d; %d\r\n",one_byte_ram.tim_cun,one_byte_ram.bit_width);
 								one_byte_ram.statu=1;

+ 3 - 0
app/app_one_wire.h

@@ -2,6 +2,8 @@
 #define __app_one_wire_h__
 
 typedef void (*_Event)(unsigned char*,int);
+typedef void (*_Event_ERR)(unsigned char);
+
 void chargerpin_one_ms_init(_Event success_evt);
 void chargerpin_one_ms_pcs(void *t);
 void chargerpin_one_ms_uninit(void);
@@ -9,6 +11,7 @@ void chargerpin_one_ms_uninit(void);
 void one_byte_receive_pcs(void*t);
 void one_byte_receive_init(unsigned char *recbuff,unsigned short len,_Event evt);
 void one_byte_receive_uninit(void);
+void one_byte_receive_Event_err_register(_Event_ERR _cb);
 #endif
 
 

+ 18 - 6
hal/hal_battery/hal_battery_NoPowerEnPin.c

@@ -92,7 +92,7 @@ void cb_init(void)
 //返回5V信号,有5V的话返回1,没有的话返回0
 static char charge_in(void)
 {
-	if ((app_chargepin_pairline() == CHARGE))
+	if (nrf_gpio_pin_read(PIN_CHARGING))
 	{
 		return 1;
 	}
@@ -283,6 +283,13 @@ static float Power_management(float mV_Battery, float mV_Charge)
 		{
 			battercb->P1 = Voltage2power(mV_Battery);
 			battercb->sta = 1; //放电过程
+			
+			if ( ( interp1(mV_Battery/10.0f) - battercb->P1 > 15.0f ) || ( interp1(mV_Battery/10.0f) - battercb->P1 < -15.0f ) )
+			{
+					battercb->P1 = interp1(mV_Battery/10.0f);
+					SEGGER_RTT_printf(0,"battercb->P1 > celibration \r\n");
+			}
+			
 		}
 		break;
 	case 1://放电
@@ -295,14 +302,21 @@ static float Power_management(float mV_Battery, float mV_Charge)
 		else
 		{
 			battercb->P2 = Voltage2power(mV_Battery);
-			if (battercb->P1 > battercb->P2) //过滤刚拔掉充电线时候的虚高
+			if ( ( battercb->P2 - battercb->P1 > 15.0f ) || ( battercb->P2 - battercb->P1 < -15.0f ) )
 			{
-				battercb->P1 = battercb->P2;
+					battercb->P1 = battercb->P2;
+					SEGGER_RTT_printf(0,"battercb->P1 > celibration \r\n");
+			}
+			else
+			{
+					if ( battercb->P1 > battercb->P2 )
+					{
+							battercb->P1 = battercb->P2;
+					}
 			}
 			//解决充满电后充电器不拔出来的情况显示不到100%的情况
 			if (battercb->P1 > 95.0f)
 			{
-				DEBUG_LOG( "battercb->P1 > 95.0f\r\n");
 				if (charge_in())
 				{
 					battercb->P1 = 100.0f;
@@ -344,8 +358,6 @@ static float Power_management(float mV_Battery, float mV_Charge)
 			//---------------------------------------------------
 			battercb->P2 = chargeV2P_f(mV_Battery);
 
-			//log("%f\n",P2);
-			//SEGGER_RTT_Write(0,logbuftemp, logbuftemp_len);
 
 			battercb->kg = mV_Charge / 1000.0f;
 			if (battercb->kg > 1.0f)

+ 29 - 19
system/selfcheck.c

@@ -295,10 +295,9 @@ static void selfcheck_process(void)
 	uint8_t 								buf[256];
 	uint8_t 								L=0;
 	char 										mac_buf[16];	
-	static int16_t					charge_chip_adc_max = 0;
+	static uint32_t					charge_chip_adc_max = 0;
 	static int16_t					battery_adc_max = 0;
 	static uint32_t 				t_count = 0;
-	static uint32_t					charge_chip_adc_t_count = 0;
 	static uint32_t					battery_adc_t_count = 0;
 	static uint32_t					roll_t_count = 0;
 	static uint32_t         sensor_t_count = 0;
@@ -321,25 +320,11 @@ static void selfcheck_process(void)
 	Mahony_process(0,0,0,ob_selfcheck.m_data.acc[0],ob_selfcheck.m_data.acc[1],ob_selfcheck.m_data.acc[2],0,0,0);
 	
 	
-	//筛选最大的充电芯片电压
-	fml_adc_get_value(PIN_ADC_CHARGMEASURE_CHANNEL,&adc_value);
-	charge_chip_adc_max = (charge_chip_adc_max > adc_value)?charge_chip_adc_max:adc_value;
-	
 	//筛选最大的电池分压后的电压
 	fml_adc_get_value(PIN_ADC_BAT_CHANNEL,&adc_value);
 	adc_value = ADC_RESULT_IN_MILLI_VOLTS(adc_value) * 5 / 3;
-	battery_adc_max = (battery_adc_max > adc_value)?battery_adc_max:adc_value;
-	
+	battery_adc_max = adc_value;
 	
-	//每3秒读取ADC,以5V电压测试充电芯片是否正常,设置自检结果。
-	if(t_count - charge_chip_adc_t_count > (3000/100))
-	{
-		if(SELFCHECK_CHARGE_CHIP_PIN_ADC_MIN_THRESHOLD > charge_chip_adc_max)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_CHARGE_CHIP_PIN_ADC);
-		else ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_CHARGE_CHIP_PIN_ADC);
-		//更新计时
-		charge_chip_adc_t_count = t_count;
-	}
-
 	//每3秒读取ADC,以5V电压测试电池分压电阻是否焊接,不考虑阻值,设置自检结果。
 	if(t_count - battery_adc_t_count > (3000/100))
 	{
@@ -348,6 +333,23 @@ static void selfcheck_process(void)
 		//更新计时
 		battery_adc_t_count = t_count;
 	}
+	
+	//充电芯片监测充电
+	fml_adc_get_value(PIN_ADC_CHARGMEASURE_CHANNEL,&adc_value);
+	if(SELFCHECK_CHARGE_CHIP_PIN_ADC_MIN_THRESHOLD < adc_value)
+	{
+		charge_chip_adc_max++;
+	}
+	if(charge_chip_adc_max > 10)
+	{
+		ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_CHARGE_CHIP_PIN_ADC);
+	}
+	else
+	{
+		ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_CHARGE_CHIP_PIN_ADC);
+	}
+	
+	
 
 	//每3秒检测加速度roll值,设置自检结果。
 	if(t_count - roll_t_count > (3000/100))
@@ -526,13 +528,21 @@ static void selfcheck_process(void)
 		if(continue_trigger != 0)continue_trigger--;
 	}
 					
-	//第60秒重启
-	if(t_count >= (60000/100) && !slave_isconnect() && continue_trigger==0)
+	//第30秒重启
+	if(t_count >= (30000/100) && !slave_isconnect() && continue_trigger==0)
 	{
     memset(mac_buf, 0, sizeof(mac_buf));
     sprintf(mac_buf, "%02X%02X%02X%02X%02X%02X", mFlash.macHost[0], mFlash.macHost[1], mFlash.macHost[2], mFlash.mClient.macAddr[3], mFlash.mClient.macAddr[4], mFlash.mClient.macAddr[5]);
 		ST_scan_stop();
     host_set_scan_name(mac_buf, strlen(mac_buf));
+		//保存数据到flash
+		if(Flash_SaveStep() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_Power,"save step fail");
+		extern battercb_t battery_record;
+		extern void printbatter_cb(battercb_t *c,unsigned char *buff);
+		memcpy(&mFlash.mbattercb_t,&battery_record,sizeof(battercb_t));
+		mBackup.RestartCnt =0;
+		if(Flash_SaveBackup() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_Power,"pwr save backup fail");
+		if(Flash_SaveInfomation() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_Power,"pwr save information fail");
 		NVIC_SystemReset();
 	}
 }

+ 1 - 1
system/usr_config.h

@@ -5,7 +5,7 @@
 #define SHOES_NAME "SMART SHOE"
 #define SHOES_NAME_LEN  64
 #define HARDWARE_VERSION	0x00010301
-#define SOFTWARE_VERSION	0x0011
+#define SOFTWARE_VERSION	0x0012
 
 // <h> ¹«¹²