19 #include "sensebe_store_config.h" 21 #include "hal_nop_delay.h" 25 #include "nrf_assert.h" 26 #include "common_util.h" 31 #define LAST_APP_PAGE_ADDR 0x27000 33 #define CONFIG_SIZE_TO_POINTER 6 35 #define NO_OF_CONFIGS 165 39 #define LAST_CONFIG_END_ADDR (LAST_APP_PAGE_ADDR+NO_OF_CONFIGS*CONFIG_SIZE_TO_POINTER\ 43 #define CONFIG_FW_VER_LOC LAST_CONFIG_END_ADDR+CONFIG_SIZE_TO_POINTER+0x2 45 #define MEM_RESET_VALUE 0xFFFFFFFF 47 #define MEM_FULL LAST_CONFIG_END_ADDR 57 static uint32_t get_next_location (
void);
64 static void clear_all_config (
void);
69 static void update_fw_ver (
void);
71 static uint32_t get_next_location (
void)
73 log_printf(
"%s\n",__func__);
74 uint32_t * p_mem_loc = (uint32_t *) LAST_APP_PAGE_ADDR;
75 while(p_mem_loc < (uint32_t *)LAST_CONFIG_END_ADDR)
77 if(*(p_mem_loc) == MEM_RESET_VALUE)
79 return (uint32_t)p_mem_loc;
81 p_mem_loc += CONFIG_SIZE_TO_POINTER;
89 log_printf(
"%s\n",__func__);
90 if(get_next_location () == LAST_APP_PAGE_ADDR)
102 log_printf(
"%s\n",__func__);
103 uint32_t * p_mem_loc = (uint32_t *) get_next_location();
104 if(p_mem_loc == (uint32_t *)MEM_FULL)
107 p_mem_loc = (uint32_t *) get_next_location();
109 hal_nvmc_write_data(p_mem_loc, latest_config,
sizeof(sensebe_config_t));
115 log_printf(
"%s\n",__func__);
116 uint32_t * p_mem_loc = (uint32_t*)get_next_location();
117 if(p_mem_loc != (uint32_t*)LAST_APP_PAGE_ADDR)
119 p_mem_loc -= CONFIG_SIZE_TO_POINTER;
121 return (sensebe_config_t*) p_mem_loc;
124 static void clear_all_config (
void)
126 log_printf(
"%s\n",__func__);
127 hal_nvmc_erase_page (LAST_APP_PAGE_ADDR);
132 log_printf(
"%s\n",__func__);
133 uint32_t * p_mem_loc = (uint32_t *) CONFIG_FW_VER_LOC;
134 uint32_t local_major_num = *p_mem_loc/10000;
135 if(*p_mem_loc == MEM_RESET_VALUE)
139 else if(local_major_num != (FW_VER/10000))
146 static void update_fw_ver ()
148 log_printf(
"%s\n",__func__);
149 uint32_t * p_mem_loc = (uint32_t *) CONFIG_FW_VER_LOC;
150 uint32_t local_fw_ver = FW_VER;
151 hal_nvmc_write_data (p_mem_loc, &local_fw_ver,
sizeof(uint32_t));
void sensebe_store_config_write(sensebe_config_t *latest_config)
Function to write the sensebe_config_t at address location received from get_next_location().
bool sensebe_store_config_is_memory_empty(void)
sensebe_config_t * sensebe_store_config_get_last_config()
void sensebe_store_config_check_fw_ver()
Function to check the major number of firmware if latest major number \ firmware version is greater t...