Преглед изворни кода

nv storage update, when write error, don't update write index

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui пре 4 година
родитељ
комит
7fbe41080e
3 измењених фајлова са 14 додато и 3 уклоњено
  1. 12 3
      Application/app/nv_storage.c
  2. 1 0
      Application/app/nv_storage.h
  3. 1 0
      Application/app/sox/state.c

+ 12 - 3
Application/app/nv_storage.c

@@ -67,7 +67,8 @@ int nv_read_sn(uint8_t *sn, int len){
 	memcpy(sn, sn_info.sn, sn_info.len);
 	return sn_info.len;
 }
-
+static int _soc_write_error = 0;
+static int _soc_write_success = 0;
 /* soc 保存,拆分每次保存一个byte,确保e2rom写操作不会占用太长时间 */
 void nv_save_soc(void){
 #if 0	
@@ -87,13 +88,21 @@ void nv_save_soc(void){
 #endif
 }
 
+void nv_storage_log(void) {
+	state_debug("soc nv write: %d\n", _soc_write_success, _soc_write_error);
+}
+
 static void nv_save_soc_task(shark_timer_t *timer){
 	if (soc_write_pending == 0) {
 		return;
 	}
 	if (soc_write_index < sizeof(soc_data)){
-		AT24CXX_Write(SOC_ADDR + SOC_SIZE * soc_write_backup_index + soc_write_index, soc_data + soc_write_index, 1);
-		soc_write_index ++;
+		if (AT24CXX_Write(SOC_ADDR + SOC_SIZE * soc_write_backup_index + soc_write_index, soc_data + soc_write_index, 1) == 1) {
+			soc_write_index ++;
+			_soc_write_success ++;
+		}else {
+			_soc_write_error ++;
+		}
 	}else {
 		soc_write_index = 0;
 		soc_write_backup_index ++;

+ 1 - 0
Application/app/nv_storage.h

@@ -17,4 +17,5 @@ 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);
+void nv_storage_log(void);
 

+ 1 - 0
Application/app/sox/state.c

@@ -132,6 +132,7 @@ void bms_state_log(void){
 	state_debug("BackUp value 0x%x\n", bsp_get_backup());
 	state_debug("Debug: %d, %d. uart reinit=%d\n", shark_uart_timeout(), io_state()->hall_detect, uart_reinit_count);
 	log_no_hall_time();
+	nv_storage_log();
 #if 0
 	state_debug("Charging: %d\n", _bms_state.charging);
 	state_debug("WorkMode %d\n", _bms_state.work_mode);