sysparam fixes, tests, spi flash refactoring (#299)
Original work by @ourairquality * Sysparam threadsafe and SPI access * Sysparam test cases * Fix for negative int8 * Sysparam getting bool without memory allocation. Bool tests. * SPI flash refactoring. * Extract common spiflash.c into core. * Use spiflash.c in sysparam. * Use memcpy in spiflash.c insted of hand-written version. * Tests for spiflash.c
This commit is contained in:
parent
07ca0d2e9e
commit
a91ec6eb61
10 changed files with 724 additions and 406 deletions
|
|
@ -119,7 +119,7 @@ sysparam_status_t sysparam_init(uint32_t base_addr, uint32_t top_addr);
|
|||
* you reformat the area currently being used, you will also need to call
|
||||
* sysparam_init() again afterward before you will be able to continue using
|
||||
* it.
|
||||
*/
|
||||
*/
|
||||
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
|
||||
|
|
@ -180,24 +180,20 @@ sysparam_status_t sysparam_compact();
|
|||
*/
|
||||
sysparam_status_t sysparam_get_data(const char *key, uint8_t **destptr, size_t *actual_length, bool *is_binary);
|
||||
|
||||
/** Get the value associated with a key (static buffers only)
|
||||
/** Get the value associated with a key (static value buffer)
|
||||
*
|
||||
* This performs the same function as sysparam_get_data() but without
|
||||
* performing any memory allocations. It can thus be used before the heap has
|
||||
* been configured or in other cases where using the heap would be a problem
|
||||
* (i.e. in an OOM handler, etc). It requires that the caller pass in a
|
||||
* suitably sized buffer for the value to be read (if the supplied buffer is
|
||||
* not large enough, the returned value will be truncated and the full
|
||||
* required length will be returned in `actual_length`).
|
||||
*
|
||||
* NOTE: In addition to being large enough for the value, the supplied buffer
|
||||
* must also be at least as large as the length of the key being requested.
|
||||
* If it is not, an error will be returned.
|
||||
* allocating memory for the result value. It can thus be used before the heap
|
||||
* has been configured or in other cases where using the heap would be a
|
||||
* problem (i.e. in an OOM handler, etc). It requires that the caller pass in
|
||||
* a suitably sized buffer for the value to be read (if the supplied buffer is
|
||||
* not large enough, the returned value will be truncated and the full required
|
||||
* length will be returned in `actual_length`).
|
||||
*
|
||||
* @param[in] key Key name (zero-terminated string)
|
||||
* @param[in] buffer Pointer to a buffer to hold the returned value
|
||||
* @param[in] buffer_size Length of the supplied buffer in bytes
|
||||
* @param[out] actual_length pointer to a location to hold the actual length
|
||||
* @param[in] dest Pointer to a buffer to hold the returned value.
|
||||
* @param[in] dest_size Length of the supplied buffer in bytes.
|
||||
* @param[out] actual_length Pointer to a location to hold the actual length
|
||||
* of the data which was associated with the key
|
||||
* (may be NULL).
|
||||
* @param[out] is_binary Pointer to a bool to hold whether the returned
|
||||
|
|
@ -210,10 +206,10 @@ sysparam_status_t sysparam_get_data(const char *key, uint8_t **destptr, size_t *
|
|||
* @retval ::SYSPARAM_ERR_CORRUPT Sysparam region has bad/corrupted data
|
||||
* @retval ::SYSPARAM_ERR_IO I/O error reading/writing flash
|
||||
*/
|
||||
sysparam_status_t sysparam_get_data_static(const char *key, uint8_t *buffer, size_t buffer_size, size_t *actual_length, bool *is_binary);
|
||||
sysparam_status_t sysparam_get_data_static(const char *key, uint8_t *dest, size_t dest_size, size_t *actual_length, bool *is_binary);
|
||||
|
||||
/** Get the string value associated with a key
|
||||
*
|
||||
*
|
||||
* This routine can be used if you know that the value in a key will (or at
|
||||
* least should) be a string. It will return a zero-terminated char buffer
|
||||
* containing the value retrieved.
|
||||
|
|
@ -240,9 +236,10 @@ sysparam_status_t sysparam_get_data_static(const char *key, uint8_t *buffer, siz
|
|||
sysparam_status_t sysparam_get_string(const char *key, char **destptr);
|
||||
|
||||
/** Get the int32_t value associated with a key
|
||||
*
|
||||
*
|
||||
* This routine can be used if you know that the value in a key will (or at
|
||||
* least should) be an int32_t value.
|
||||
* least should) be an int32_t value. This is done without allocating any
|
||||
* memory.
|
||||
*
|
||||
* Note: If the status result is anything other than ::SYSPARAM_OK, the value
|
||||
* in `result` is not changed. This means it is possible to set a default
|
||||
|
|
@ -266,7 +263,8 @@ sysparam_status_t sysparam_get_int32(const char *key, int32_t *result);
|
|||
/** Get the int8_t value associated with a key
|
||||
*
|
||||
* This routine can be used if you know that the value in a key will (or at
|
||||
* least should) be a uint8_t binary value.
|
||||
* least should) be a uint8_t binary value. This is done without allocating any
|
||||
* memory.
|
||||
*
|
||||
* Note: If the status result is anything other than ::SYSPARAM_OK, the value
|
||||
* in `result` is not changed. This means it is possible to set a default
|
||||
|
|
@ -288,7 +286,7 @@ sysparam_status_t sysparam_get_int32(const char *key, int32_t *result);
|
|||
sysparam_status_t sysparam_get_int8(const char *key, int8_t *result);
|
||||
|
||||
/** Get the boolean value associated with a key
|
||||
*
|
||||
*
|
||||
* This routine can be used if you know that the value in a key will (or at
|
||||
* least should) be a boolean setting. It will read the specified value as a
|
||||
* text string and attempt to parse it as a boolean value.
|
||||
|
|
@ -320,7 +318,7 @@ sysparam_status_t sysparam_get_bool(const char *key, bool *result);
|
|||
*
|
||||
* The supplied value can be any data, up to 255 bytes in length. If `value`
|
||||
* is NULL or `value_len` is 0, this is treated as a request to delete any
|
||||
* current entry matching `key`.
|
||||
* current entry matching `key`. This is done without allocating any memory.
|
||||
*
|
||||
* If `binary` is true, the data will be considered binary (unprintable) data,
|
||||
* and this will be annotated in the saved entry. This does not affect the
|
||||
|
|
@ -368,7 +366,8 @@ sysparam_status_t sysparam_set_string(const char *key, const char *value);
|
|||
/** Set a key's value as a number
|
||||
*
|
||||
* Write an int32_t binary value to the specified key. This does the inverse of
|
||||
* the sysparam_get_int32() function.
|
||||
* the sysparam_get_int32() function. This is done without allocating any
|
||||
* memory.
|
||||
*
|
||||
* @param[in] key Key name (zero-terminated string)
|
||||
* @param[in] value Value to set
|
||||
|
|
@ -386,10 +385,8 @@ sysparam_status_t sysparam_set_int32(const char *key, int32_t value);
|
|||
/** Set a key's value as a number
|
||||
*
|
||||
* Write an int8_t binary value to the specified key. This does the inverse of
|
||||
* the sysparam_get_int8() function.
|
||||
*
|
||||
* Note that if the key already contains a value which parses to the same
|
||||
* boolean (true/false) value, it is left unchanged.
|
||||
* the sysparam_get_int8() function. This is done without allocating any
|
||||
* memory.
|
||||
*
|
||||
* @param[in] key Key name (zero-terminated string)
|
||||
* @param[in] value Value to set
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue