| 12345678910111213141516171819202122232425262728293031323334 |
- #include "nv_storage.h"
- #include "bsp/AT24CXX.h"
- #include "app/sox/soc.h"
- #include "libs/logger.h"
- #include "libs/shark_utils.h"
- #define SOC_ADDR 0
- void nv_save_soc(void){
- soc_t *soc = get_soc();
-
- uint16_t crc16 = shark_crc16_update(0, (const u8 *)soc, sizeof(soc_t));
- u64 start_time = shark_get_mseconds();
- AT24CXX_Write(SOC_ADDR ,(uint8_t *)soc, sizeof(soc_t));
- AT24CXX_Write(SOC_ADDR + sizeof(soc_t),(uint8_t *)&crc16, sizeof(crc16));
- printf("write e2rom time %lld\n", (shark_get_mseconds() - start_time));
- }
- int nv_restore_soc(void){
- soc_t soc;
- AT24CXX_Read(SOC_ADDR , (uint8_t *)&soc, sizeof(soc_t));
- uint16_t crc16 = shark_crc16_update(0, (const u8 *)&soc, sizeof(soc_t));
- uint16_t crc_nv;
- AT24CXX_Read(SOC_ADDR + sizeof(soc_t), (uint8_t *)&crc_nv, sizeof(crc_nv));
- if (crc_nv != crc16) {
- return -1;
- }
- *get_soc() = soc;
- return 0;
- }
|