Kaynağa Gözat

解决nv存soc如果其中一个crc有问题会导致整个soc都清零

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 5 yıl önce
ebeveyn
işleme
8e87a02e2f

+ 10 - 6
Application/app/nv_storage.c

@@ -121,6 +121,10 @@ static void nv_save_soc_by_backup(int index){
 	AT24CXX_Write(nv_addr + sizeof(soc_t),(uint8_t *)&crc16, sizeof(crc16));
 }
 
+void nv_save_all_soc(void){
+	nv_save_soc_by_backup(0);
+	nv_save_soc_by_backup(1);
+}
 
 void nv_erase(void){
 	uint8_t data = 0xFF;
@@ -154,18 +158,18 @@ int nv_restore_soc(void){
 	success1 = nv_restore_soc_by_backup(1, &soc1);
 
 	if (success0 == 0 || success1 == 0){
+		if (success0 == 0){
+			*get_soc() = soc0;
+		}else if (success1 == 0){
+			*get_soc() = soc1;
+		}
 		if (success1 != 0){
 			nv_save_soc_by_backup(1);
 		}
 		if (success0 != 0){
 			nv_save_soc_by_backup(0);
 		}
-		if (success0 == 0){
-			*get_soc() = soc0;
-		}else if (success1 == 0){
-			*get_soc() = soc1;
-		}
-	}	
+	}
 	return ((success0 == 0) || (success1 == 0))?0:-1;
 }
 

+ 2 - 0
Application/app/nv_storage.h

@@ -16,3 +16,5 @@ void nv_erase(void);
 int nv_save_sn(uint8_t *sn, int len);
 int nv_read_sn(uint8_t *sn, int len);
 int nv_read_write_test(void);
+void nv_save_all_soc(void);
+

+ 2 - 2
Application/app/sox/state.c

@@ -301,7 +301,7 @@ static void _process_power_down(void){
 		state_debug("BMS System PowerDown!!\n");
 
 		if (bms_work_is_normal() && soc_update_by_ocv()) {
-			nv_save_soc();
+			nv_save_all_soc();
 		}
 		
 		shark_uart_flush();
@@ -370,7 +370,7 @@ static void _process_deepsleep(s32 health){
 		return;
 	}
 	
-	nv_save_soc();
+	nv_save_all_soc();
 	mcu_enter_deepsleep();
 	soc_update_for_deepsleep(mcu_get_sleeptime());//²¹³¥ÐÝÃߵŦºÄ
 	_sleep_time = shark_get_mseconds();

+ 4 - 4
Application/bsp/irqs.c

@@ -18,7 +18,7 @@ void NMI_Handler(void)
 */
 void HardFault_Handler(void){
     /* if Hard Fault exception occurs, go to infinite loop */
-	nv_save_soc();
+	nv_save_all_soc();
     while (1){
     }
 }
@@ -32,7 +32,7 @@ void HardFault_Handler(void){
 void MemManage_Handler(void)
 {
     /* if Memory Manage exception occurs, go to infinite loop */
-	nv_save_soc();
+	nv_save_all_soc();
     while (1){
     }
 }
@@ -46,7 +46,7 @@ void MemManage_Handler(void)
 void BusFault_Handler(void)
 {
     /* if Bus Fault exception occurs, go to infinite loop */
-	nv_save_soc();
+	nv_save_all_soc();
     while (1){
     }
 }
@@ -60,7 +60,7 @@ void BusFault_Handler(void)
 void UsageFault_Handler(void)
 {
     /* if Usage Fault exception occurs, go to infinite loop */
-	nv_save_soc();
+	nv_save_all_soc();
     while (1){
     }
 }