소스 검색

加入工厂测试结果写入和读取

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 3 년 전
부모
커밋
8b4b845ca6
4개의 변경된 파일42개의 추가작업 그리고 0개의 파일을 삭제
  1. 8 0
      Application/app/bms_message.c
  2. 23 0
      Application/app/nv_storage.c
  3. 9 0
      Application/app/nv_storage.h
  4. 2 0
      Application/app/protocol.h

+ 8 - 0
Application/app/bms_message.c

@@ -300,6 +300,14 @@ void process_bms_message(can_frame_t *frame, int len){
 			}
 			break;
 		}
+		case CAN_KEY_FACTORY_RESULT: {
+			if (len == 1) {
+				nv_save_factory_result(frame->data[0]);
+			}
+			uint8_t res = nv_read_factory_result();
+			protocol_send_ack(frame->head.can_addr, frame->key, res);
+			break;
+		}
 		default:
 			break;
 	}

+ 23 - 0
Application/app/nv_storage.c

@@ -16,6 +16,8 @@ static void nv_save_soc_task(shark_timer_t *timer);
 static shark_timer_t _save_backup_timer = {.handler = nv_save_soc_task};
 #define SOC_SIZE (((sizeof(soc_t) + sizeof(uint16_t)) + 0xF)&(0xFFF0)) //需要16字节对齐
 #define SN_ADDR (SOC_ADDR + (SOC_SIZE * 2))
+#define SN_SIZE 32
+#define RES_ADDR (SN_ADDR + SN_SIZE)
 
 static uint8_t soc_write_pending = 0;
 static uint8_t soc_write_backup_index = 0;
@@ -67,6 +69,27 @@ int nv_read_sn(uint8_t *sn, int len){
 	memcpy(sn, sn_info.sn, sn_info.len);
 	return sn_info.len;
 }
+
+int nv_save_factory_result(uint8_t result) {
+	factory_t f;
+	f.result = result;
+	uint16_t crc16 = shark_crc16_update(0, (const u8 *)&f, sizeof(f) - 2);
+	f.crc = crc16;
+	return AT24CXX_Write(RES_ADDR, (uint8_t *)&f, sizeof(f));
+}
+
+uint8_t nv_read_factory_result(void) {
+	factory_t f;
+	if (AT24CXX_Read(RES_ADDR, (uint8_t *)&f, sizeof(f)) < 0) {
+		return 0xFF;
+	}
+	uint16_t crc16 = shark_crc16_update(0, (const u8 *)&f, sizeof(f) - 2);
+	if (f.crc != crc16) {
+		return 0xFF;
+	}
+	return f.result;
+}
+
 static int _soc_write_error = 0;
 static int _soc_write_success = 0;
 /* soc 保存,拆分每次保存一个byte,确保e2rom写操作不会占用太长时间 */

+ 9 - 0
Application/app/nv_storage.h

@@ -8,6 +8,12 @@ typedef struct {
 	uint8_t sn[24];
 	uint16_t crc;
 }sn_t;
+
+typedef struct {
+	uint8_t result;
+	uint16_t crc;
+}factory_t;
+
 #pragma pack(pop)
 
 void nv_save_soc(void);
@@ -18,4 +24,7 @@ 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);
+int nv_save_factory_result(uint8_t result);
+uint8_t nv_read_factory_result(void);
+
 

+ 2 - 0
Application/app/protocol.h

@@ -165,6 +165,8 @@ typedef struct {
 
 #define CAN_KEY_POWERDOWN 0xad /* power down, magic:0xFF005AA5*/
 
+#define CAN_KEY_FACTORY_RESULT 0xb0
+
 #define CAN_KEY_IAP_ENTER   0xF0
 #define CAN_KEY_IAP_BEGIN   0xF1
 #define CAN_KEY_IAP_CHECK   0xF2