|
@@ -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};
|
|
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 SOC_SIZE (((sizeof(soc_t) + sizeof(uint16_t)) + 0xF)&(0xFFF0)) //需要16字节对齐
|
|
|
#define SN_ADDR (SOC_ADDR + (SOC_SIZE * 2))
|
|
#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_pending = 0;
|
|
|
static uint8_t soc_write_backup_index = 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);
|
|
memcpy(sn, sn_info.sn, sn_info.len);
|
|
|
return 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_error = 0;
|
|
|
static int _soc_write_success = 0;
|
|
static int _soc_write_success = 0;
|
|
|
/* soc 保存,拆分每次保存一个byte,确保e2rom写操作不会占用太长时间 */
|
|
/* soc 保存,拆分每次保存一个byte,确保e2rom写操作不会占用太长时间 */
|