Parcourir la source

debug 重启问题

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui il y a 5 ans
Parent
commit
bbd3091f3b

+ 2 - 1
Application/app/sox/measure_task.c

@@ -36,12 +36,13 @@ measure_value_t * measure_value(void){
 	return &_measure_value;
 }
 extern uint32_t check_gain_error;
+extern int gd32_adc_error;
 void measure_log(void){
 	measure_debug("Current %.4f -- %.4f\n", (float)_measure_value.load_current/1000.0f, (float)_measure_value.current_5238/1000.0f);
 	for (int i = 0; i < CELLS_NUM; i++){
 		//measure_debug("Cell[%d]: %.3fv\n", i, _measure_value.cell_vol[i]/1000.0f);
 	}
-	measure_debug("Gain:%f, Off %f, check error = %d\n", get_ml5238_gain(), get_ml5238_vos(), check_gain_error);
+	measure_debug("Gain:%f, Off %f, check error = %d, %d\n", get_ml5238_gain(), get_ml5238_vos(), check_gain_error, gd32_adc_error);
 }
 /*
  * 测量电芯电压,计算出总电压, 测量总电流,放电和充电

+ 5 - 0
Application/bsp/bsp.c

@@ -64,6 +64,11 @@ char* bsp_get_fversion(void){
 	return (char *)iap_fw_version;
 }
 
+void system_reboot(void){
+	NVIC_SystemReset();
+}
+
+
 /* timeout:1-25 */
 void wdog_start(int timeout){
 #if CONFIG_DEBUG == 0

+ 28 - 9
Application/bsp/gd32_adc.c

@@ -1,6 +1,8 @@
 #include "gd32_adc.h"
 #include "gpio.h"
 #include "clock.h"
+#include "libs/shark_types.h"
+#include "libs/shark_task.h"
 /* For 12-bits resolution, the total conversion time is 
  *sampling time + 12.5 ADCCLK cycles 
  *all channel is enabled oversample to reach 16bit accurate
@@ -12,6 +14,7 @@ static int volatile adc_work = ADC_WORK_IDLE;
 #define dma_buf_len 66
 static uint16_t dma_buf[dma_buf_len]; 
 #endif
+int gd32_adc_error = 0;
 void gd32_adc_init(void){
 	rcu_periph_clock_enable(RCU_GPIOA);
 	rcu_periph_clock_enable(RCU_GPIOB);	
@@ -205,26 +208,28 @@ int adc_sample(int chan, int calibration){
 	return value & mask;
 }
 
-//times * 0.6ms + 1ms
-int adc_sample_avg(int chan, int times){
+
+static int adc_sample_internal(int chan, int times, int *error) {
 	int value = 0;
 	int count = 0;
 	int min = 0xFFFFF;
 	int max = -0xFFFFF;
-	//gd32_adc_init();
-	//hardware oversample to 16bit
-	//adc_oversample_mode_config(ADC_OVERSAMPLING_ALL_CONVERT, ADC_OVERSAMPLING_SHIFT_2B, ADC_OVERSAMPLING_RATIO_MUL64);
-	//adc_oversample_mode_enable();
-    /* use max convert time to make sure the adc work fine */
+
     adc_regular_channel_config(0, chan, ADC_SAMPLETIME_55POINT5);////55.5 + 12.5 = 68 cycle, 68 * 256/(7*1000000)
 	adc_enable();
 	delay_us(1000); //MUST delay, for adc work fine
 	/* ADC calibration and reset calibration */
 	adc_calibration_enable();
-
+	*error = 0;
 	while(count < times){
+		u64 start_time = shark_get_mseconds();
 		adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
-    	while(SET != adc_flag_get(ADC_FLAG_EOC));
+    	while(SET != adc_flag_get(ADC_FLAG_EOC)){
+			if (shark_get_mseconds() - start_time >= 10){
+				*error = -1;
+				break;
+			}
+		};
     	int one = adc_regular_data_read();
 		adc_flag_clear(ADC_FLAG_EOC);		
 		value += (one & 0xFFF);
@@ -241,5 +246,19 @@ int adc_sample_avg(int chan, int times){
 		return value/times;
 	}
 	return (value - min - max)/(times-2);
+	
+}
+//times * 0.6ms + 1ms
+int adc_sample_avg(int chan, int times){
+	int error = 0;
+	int value = adc_sample_internal(chan, times, &error);
+	if (error < 0) {
+		gd32_adc_error ++;
+		gd32_adc_deinit();
+		delay_us(5 * 1000);
+		gd32_adc_init();
+		value = adc_sample_internal(chan, times, &error);
+	}
+	return value;
 }
 #endif /* DMA_ADC_CH */

+ 5 - 0
Application/bsp/irqs.c

@@ -1,5 +1,6 @@
 #include "gd32f3x0.h"
 #include "nv_storage.h"
+extern void system_reboot(void);
 /*!
     \brief      this function handles NMI exception
     \param[in]  none
@@ -20,6 +21,7 @@ void HardFault_Handler(void){
     /* if Hard Fault exception occurs, go to infinite loop */
 	nv_save_all_soc();
     while (1){
+		system_reboot();
     }
 }
 
@@ -34,6 +36,7 @@ void MemManage_Handler(void)
     /* if Memory Manage exception occurs, go to infinite loop */
 	nv_save_all_soc();
     while (1){
+		system_reboot();
     }
 }
 
@@ -48,6 +51,7 @@ void BusFault_Handler(void)
     /* if Bus Fault exception occurs, go to infinite loop */
 	nv_save_all_soc();
     while (1){
+		system_reboot();
     }
 }
 
@@ -62,6 +66,7 @@ void UsageFault_Handler(void)
     /* if Usage Fault exception occurs, go to infinite loop */
 	nv_save_all_soc();
     while (1){
+		system_reboot();
     }
 }
 

+ 2 - 3
Application/bsp/mcu_power_sleep.c

@@ -86,7 +86,6 @@ static int pre_deepsleep(void){
 		post_deepsleep();
 		return -1;
 	}
-	
 	wdog_set_timeout(WDOG_TIME_FOR_SLEEP);
 	wait_for_enter_dsleep();
 	if (_is_wakeup_source()) {
@@ -143,13 +142,13 @@ void mcu_enter_deepsleep(void){
 			wdog_reload();
 			while (shark_rtc_start_alarm(RTC_ALARM_FOR_SLEEP) < 0){
 				wdog_reload();
-				if (_is_wakeup_source() || (_sleep_second_time_now >= (24 * 60 * 60))){
+				if (_is_wakeup_source() || (_sleep_second_time_now >= (60))){
 					break;
 				}
 			}
 			wait_for_enter_dsleep();
 		}
-	}while(!_is_wakeup_source() && (_sleep_second_time_now < (24 * 60 * 60)));
+	}while(!_is_wakeup_source() && (_sleep_second_time_now < (60)));
 	_sleep_second_time += _sleep_second_time_now;
 	disable_wakeup_irq();
 	post_deepsleep();