From 66589f5d3f83dbab745cfedb79680aaac583ac6b Mon Sep 17 00:00:00 2001 From: Alex Stewart Date: Mon, 9 May 2016 20:47:30 -0700 Subject: [PATCH] Add sysparam_get_info function --- core/include/sysparam.h | 20 ++++++++++++++++++++ core/sysparam.c | 8 ++++++++ 2 files changed, 28 insertions(+) diff --git a/core/include/sysparam.h b/core/include/sysparam.h index 9854f60..9260e73 100644 --- a/core/include/sysparam.h +++ b/core/include/sysparam.h @@ -3,6 +3,10 @@ #include +#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 diff --git a/core/sysparam.c b/core/sysparam.c index 0aa2cb2..cb08ac3 100644 --- a/core/sysparam.c +++ b/core/sysparam.c @@ -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;