Просмотр исходного кода

add option for re-calibration what need clear life cycle

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 4 лет назад
Родитель
Сommit
af974ba146

+ 10 - 3
Application/app/iap.c

@@ -3,7 +3,7 @@
 #include "app/nv_storage.h"
 #include "bsp/fmc_flash.h"
 #include "bsp/shark_rtc.h"
-
+#include "libs/logger.h"
 static int iap_write_image(uint8_t *data, int len);
 static int iap_check_image(uint8_t *data, int len);
 void _reboot_timer_handler(shark_timer_t *t);
@@ -73,8 +73,15 @@ void process_iap_message(can_frame_t *frame, int len){
 			break;
 		case CAN_KET_ERASE_NV:
 			shark_rtc_set_backup(0x3002);
-			nv_erase_soc(0);
-			nv_erase_soc(1);
+			if (len == 0) {
+				nv_erase_all_soc(1);
+			}else {
+				if (frame->data[0] == 1) {//erase and clear cycle
+					nv_erase_all_soc(0);
+				}else {
+					nv_erase_all_soc(1);
+				}
+			}
 			shark_timer_post(&_reboot_timer, 100);
 			protocol_send_ack(frame->head.can_addr, frame->key, 1);
 			break;

+ 2 - 6
Application/app/nv_storage.c

@@ -143,12 +143,8 @@ void nv_save_all_soc(void){
 	nv_save_soc_by_backup(1);
 }
 
-void nv_erase_soc(int index){
-	uint8_t data = 0xFF;
-	stop_writer();
-	for (int i = 0; i < sizeof(soc_t) + sizeof(uint16_t); i++){
-		AT24CXX_Write(SOC_ADDR + SOC_SIZE * index + i, &data, 1);
-	}	
+void nv_erase_all_soc(int keep_cycle){
+	soc_clear_calibrate(keep_cycle);
 }
 
 int nv_restore_soc_by_backup(int index, soc_t *soc){

+ 1 - 1
Application/app/nv_storage.h

@@ -12,7 +12,7 @@ typedef struct {
 
 void nv_save_soc(void);
 int nv_restore_soc(void);
-void nv_erase_soc(int index);
+void nv_erase_all_soc(int keep_cycle);
 int nv_save_sn(uint8_t *sn, int len);
 int nv_read_sn(uint8_t *sn, int len);
 int nv_read_write_test(void);

+ 9 - 0
Application/app/sox/soc.c

@@ -93,6 +93,15 @@ static void _soc_clear(void){
 	_soc.total_coulomb = 0;
 }
 
+void soc_clear_calibrate(int keep_cycle) {
+	float total = _soc.total_coulomb;
+	_soc_clear();
+	if (keep_cycle) {
+		_soc.total_coulomb = total;
+	}
+	nv_save_all_soc();
+}
+
 void soc_restore_by_iap(uint8_t flags, uint8_t capaticy){
 	_soc.coulomb_min = 0;
 	_soc.coulomb_max = DEFALUT_MAX_COULOMB; //30HA,Õâ¸öÖµ×î×ÜÐèÒªsohÄ£¿é¸ø

+ 1 - 0
Application/app/sox/soc.h

@@ -37,5 +37,6 @@ void soc_restore_by_iap(uint8_t flags, uint8_t capaticy);
 u8 soc_get_version(void);
 void soc_set_version(u8 version);
 bool soc_is_force_full(void);
+void soc_clear_calibrate(int keep_cycle);