Add sysparam_get_info function

This commit is contained in:
Alex Stewart 2016-05-09 20:47:30 -07:00
parent 20909a4da1
commit 66589f5d3f
2 changed files with 28 additions and 0 deletions

View file

@ -3,6 +3,10 @@
#include <esp/types.h>
#ifndef DEFAULT_SYSPARAM_SECTORS
#define DEFAULT_SYSPARAM_SECTORS 4
#endif
/** @file sysparam.h
*
* Read/write "system parameters" to persistent flash.
@ -112,6 +116,22 @@ sysparam_status_t sysparam_init(uint32_t base_addr, uint32_t top_addr);
*/
sysparam_status_t sysparam_create_area(uint32_t base_addr, uint16_t num_sectors, bool force);
/** Get the start address and size of the currently active sysparam area
*
* Fills in `base_addr` and `num_sectors` with the location and size of the
* currently active sysparam area. The returned values correspond to the
* arguments passed to the sysparam_create_area() call when the area was
* originally created.
*
* @param[out] base_addr The flash address at which the sysparam area starts
* @param[out] num_sectors The number of flash sectors used by the sysparam
* area
*
* @retval ::SYSPARAM_OK Completed successfully
* @retval ::SYSPARAM_ERR_NOINIT No current sysparam area is active
*/
sysparam_status_t sysparam_get_info(uint32_t *base_addr, uint32_t *num_sectors);
/** Get the value associated with a key
*
* This is the core "get value" function. It will retrieve the value for the

View file

@ -615,6 +615,14 @@ sysparam_status_t sysparam_create_area(uint32_t base_addr, uint16_t num_sectors,
return SYSPARAM_OK;
}
sysparam_status_t sysparam_get_info(uint32_t *base_addr, uint32_t *num_sectors) {
if (!_sysparam_info.cur_base) return SYSPARAM_ERR_NOINIT;
*base_addr = min(_sysparam_info.cur_base, _sysparam_info.alt_base);
*num_sectors = (_sysparam_info.region_size / sdk_flashchip.sector_size) * 2;
return SYSPARAM_OK;
}
sysparam_status_t sysparam_get_data(const char *key, uint8_t **destptr, size_t *actual_length, bool *is_binary) {
struct sysparam_context ctx;
sysparam_status_t status;