Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
Loading...
Searching...
No Matches
Plat-settings

This module includes the platform abstraction for non-volatile storage of settings. More...

Classes

struct  settingBuffer
 Data structure for vectored I/O using caUtilSettingsAddVector. More...

Typedefs

typedef void(* setting_moved_cb_t) (void)

Functions

void caUtilSettingsInit (struct ca821x_dev *aInstance, const char *aApplicationName, uint32_t aNodeId)
 Performs any initialization for the settings subsystem, if necessary.
void caUtilSettingsDeinit (struct ca821x_dev *aInstance)
 Performs any de-initialization for the settings subsystem, if necessary.
ca_error caUtilSettingsGet (struct ca821x_dev *aInstance, uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength)
 This function fetches the value of the setting identified by aKey and write it to the memory pointed to by aValue.
ca_error caUtilSettingsSet (struct ca821x_dev *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
 Sets or replaces the value of a setting.
ca_error caUtilSettingsAdd (struct ca821x_dev *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
 Adds a value to a setting This function adds the value to a setting identified by aKey, without replacing any existing values.
ca_error caUtilSettingsDelete (struct ca821x_dev *aInstance, uint16_t aKey, int aIndex)
 Removes a setting from the setting store.
void caUtilSettingsWipe (struct ca821x_dev *aInstance, const char *aApplicationName, uint32_t aNodeId)
 Removes all settings from the setting store.
ca_error caUtilSettingsGetAddress (struct ca821x_dev *aInstance, uint16_t aKey, int aIndex, void **aValue, uint16_t *aValueLength)
 Get the address at which a particular setting is stored.
ca_error caUtilSettingsAddVector (struct ca821x_dev *aInstance, uint16_t aKey, struct settingBuffer *aVector, size_t aCount)
 Add a vector of buffers to the storage.
ca_error caUtilSettingsGetFromAddress (struct ca821x_dev *aInstance, uint16_t aKey, uint16_t aRelativeAddress, uint8_t **aValue, uint16_t *aValueLength)
 Attempt to read a setting from a specific address in constant time.
ca_error caUtilSettingsDeleteAtAddress (struct ca821x_dev *aInstance, uint16_t aKey, uint16_t aRelativeAddress)
 Delete a setting stored at a specific address.
uint16_t caUtilSettingsGetLastWriteAddress (void)
 Get the address of the last write made by a caUtilSettings* API.
uint32_t caUtilSettingsGetLastReadAddress (void)
 Get the address of the last read made by a caUtilSettings* API.
void caUtilSettingsSetSettingMovedCb (setting_moved_cb_t aCb)
 Registers the callback for when all settings have moved.
uint32_t caUtilSettingsSwapSettingsBlock (struct ca821x_dev *aInstance)
 Defragment the persistent storage by migrating all valid items to a fresh flash region.

Detailed Description

This module includes the platform abstraction for non-volatile storage of settings.

Typedef Documentation

◆ setting_moved_cb_t

typedef void(* setting_moved_cb_t) (void)

Function Documentation

◆ caUtilSettingsAdd()

ca_error caUtilSettingsAdd ( struct ca821x_dev * aInstance,
uint16_t aKey,
const uint8_t * aValue,
uint16_t aValueLength )

Adds a value to a setting This function adds the value to a setting identified by aKey, without replacing any existing values.

Note that the underlying implementation is not required to maintain the order of the items associated with a specific key. The added value may be added to the end, the beginning, or even somewhere in the middle. The order of any pre-existing values may also change.

Calling this function successfully may cause unrelated settings with multiple values to be reordered.

Parameters
[in]aInstanceThe Cascoda instance structure.
[in]aKeyThe key associated with the setting to change.
[in]aValueA pointer to where the new value of the setting should be read from. MUST NOT be NULL if aValueLength is non-zero.
[in]aValueLengthThe length of the data pointed to by aValue. May be zero.
Return values
CA_ERROR_SUCCESSThe given setting was added or staged to be added.
CA_ERROR_NOT_IMPLEMENTEDThis function is not implemented on this platform.
CA_ERROR_NO_BUFFERNo space remaining to store the given setting.

◆ caUtilSettingsAddVector()

ca_error caUtilSettingsAddVector ( struct ca821x_dev * aInstance,
uint16_t aKey,
struct settingBuffer * aVector,
size_t aCount )

Add a vector of buffers to the storage.

Stored in continuous flash within the setting described by aKey

Parameters
aInstanceAPI instance. Unused on baremetal.
aKeyThe key associated with the requested setting.
aVectorAn array of settingBuffer structures that describes the buffers to copy into flash.
aCountThe number of buffers within the aVector array.
Return values
CA_ERROR_SUCCESSThe given setting was added or staged to be added.
CA_ERROR_NOT_IMPLEMENTEDThis function is not implemented on this platform.
CA_ERROR_NO_BUFFERNo space remaining to store the given setting.

◆ caUtilSettingsDeinit()

void caUtilSettingsDeinit ( struct ca821x_dev * aInstance)

Performs any de-initialization for the settings subsystem, if necessary.

Parameters
[in]aInstanceThe Cascoda instance structure.

◆ caUtilSettingsDelete()

ca_error caUtilSettingsDelete ( struct ca821x_dev * aInstance,
uint16_t aKey,
int aIndex )

Removes a setting from the setting store.

This function deletes a specific value from the setting identified by aKey from the settings store.

Note that the underlying implementation is not required to maintain the order of the items associated with a specific key.

Parameters
[in]aInstanceThe Cascoda instance structure.
[in]aKeyThe key associated with the requested setting.
[in]aIndexThe index of the value to be removed. If set to -1, all values for this aKey will be removed.
Return values
CA_ERROR_SUCCESSThe given key and index was found and removed successfully.
CA_ERROR_NOT_FOUNDThe given key or index was not found in the setting store.
CA_ERROR_NOT_IMPLEMENTEDThis function is not implemented on this platform.

◆ caUtilSettingsDeleteAtAddress()

ca_error caUtilSettingsDeleteAtAddress ( struct ca821x_dev * aInstance,
uint16_t aKey,
uint16_t aRelativeAddress )

Delete a setting stored at a specific address.

This function is designed to be used alongside a cache in RAM which stores addresses obtained using caUtilSettingsGetLastWriteAddress. In return, this function is very fast and its speed is independent of how full the persistent storage is, unlike caUtilSettingsGet.

Parameters
aInstanceDevice Instance
aKeyExpected key of the entry
aRelativeAddressAddress of the entry
Return values
CA_ERROR_SUCCESSDeleted a valid item with the matching key.
CA_ERROR_ALREADYItem is valid but already deleted.
CA_ERROR_NOT_FOUNDItem at address is not valid.

◆ caUtilSettingsGet()

ca_error caUtilSettingsGet ( struct ca821x_dev * aInstance,
uint16_t aKey,
int aIndex,
uint8_t * aValue,
uint16_t * aValueLength )

This function fetches the value of the setting identified by aKey and write it to the memory pointed to by aValue.

It then writes the length to the integer pointed to by aValueLength. The initial value of aValueLength is the maximum number of bytes to be written to aValue.

This function can be used to check for the existence of a key without fetching the value by setting aValue and aValueLength to NULL. You can also check the length of the setting without fetching it by setting only aValue to NULL.

Note that the underlying storage implementation is not required to maintain the order of settings with multiple values. The order of such values MAY change after ANY write operation to the store.

Parameters
[in]aInstanceThe Cascoda instance structure.
[in]aKeyThe key associated with the requested setting.
[in]aIndexThe index of the specific item to get.
[out]aValueA pointer to where the value of the setting should be written. May be set to NULL if just testing for the presence or length of a setting.
[in,out]aValueLengthA pointer to the length of the value. When called, this pointer should point to an integer containing the maximum value size that can be written to aValue. At return, the actual length of the setting is written. This may be set to NULL if performing a presence check.
Return values
CA_ERROR_SUCCESSThe given setting was found and fetched successfully.
CA_ERROR_NOT_FOUNDThe given setting was not found in the setting store.
CA_ERROR_NOT_IMPLEMENTEDThis function is not implemented on this platform.

◆ caUtilSettingsGetAddress()

ca_error caUtilSettingsGetAddress ( struct ca821x_dev * aInstance,
uint16_t aKey,
int aIndex,
void ** aValue,
uint16_t * aValueLength )

Get the address at which a particular setting is stored.

Parameters
aInstanceAPI instance of storage to inspect. Unused on baremetal
aKeyThe key associated with the requested setting.
aIndexThe index of the value to be removed. If set to -1, all values for this aKey will be removed.
aValueA pointer to where the address of the setting should be written.
aValueLengthThe length of the setting
Return values
CA_ERROR_SUCCESSThe given setting was found and fetched successfully.
CA_ERROR_NOT_FOUNDThe given setting was not found in the setting store.
CA_ERROR_NOT_IMPLEMENTEDThis function is not implemented on this platform.

◆ caUtilSettingsGetFromAddress()

ca_error caUtilSettingsGetFromAddress ( struct ca821x_dev * aInstance,
uint16_t aKey,
uint16_t aRelativeAddress,
uint8_t ** aValue,
uint16_t * aValueLength )

Attempt to read a setting from a specific address in constant time.

This function is designed to be used alongside a cache in RAM which stores addresses obtained using caUtilSettingsGetLastWriteAddress. In return, this function is very fast and its speed is independent of how full the persistent storage is, unlike caUtilSettingsGet.

Parameters
aInstanceDevice instance
aKeyKey we are expecting to find at aRelativeAddress
aRelativeAddressAddress where the entry is expected
aValueOutput buffer
aValueLengthInput for the output buffer size. Outputs the written size
Return values
CA_ERROR_SUCCESSFound a valid item with the matching key.
CA_ERROR_NOT_FOUNDItem at address is not valid.

◆ caUtilSettingsGetLastReadAddress()

uint32_t caUtilSettingsGetLastReadAddress ( void )

Get the address of the last read made by a caUtilSettings* API.

Returns
uint16_t Relative address of the previous read. Internally converted to an absolute address when calling utilsFlash* functions

◆ caUtilSettingsGetLastWriteAddress()

uint16_t caUtilSettingsGetLastWriteAddress ( void )

Get the address of the last write made by a caUtilSettings* API.

Returns
uint16_t Relative address of the previous write. Internally converted to an absolute address when calling utilsFlash* functions

◆ caUtilSettingsInit()

void caUtilSettingsInit ( struct ca821x_dev * aInstance,
const char * aApplicationName,
uint32_t aNodeId )

Performs any initialization for the settings subsystem, if necessary.

On baremetal platforms, only one instance of the storage is created, and therefore the arguments are not important.

On host platforms (e.g. POSIX) multiple instances of the MAC may be in use at the same time, and it may be desirable to have persistent storage for each individual instance.

This function opens / creates a different settings context for every unique combination of application name & node ID, and binds it to the CA821x device instance. Subsequent settings API calls using the same device instance will use that same settings context.

The configurable application name is useful for distinguishing between applications (e.g. you would not want your integration test suite to overwrite your Thread credentials), while the node ID is useful for distinguishing between multiple SDKs running on the same host.

Parameters
[in]aInstanceThe Cascoda instance structure.
[in]aApplicationNameUsed to distinguish between applications. Unused on baremetal.
[in]aNodeIdUsed to distinguish between different nodes on the same host. Must be smaller than or equal to 9999. Unused on baremetal.

◆ caUtilSettingsSet()

ca_error caUtilSettingsSet ( struct ca821x_dev * aInstance,
uint16_t aKey,
const uint8_t * aValue,
uint16_t aValueLength )

Sets or replaces the value of a setting.

This function sets or replaces the value of a setting identified by aKey. If there was more than one value previously associated with aKey, then they are all deleted and replaced with this single entry.

Calling this function successfully may cause unrelated settings with multiple values to be reordered.

Parameters
[in]aInstanceThe Cascoda instance structure.
[in]aKeyThe key associated with the setting to change.
[in]aValueA pointer to where the new value of the setting should be read from. MUST NOT be NULL if aValueLength is non-zero.
[in]aValueLengthThe length of the data pointed to by aValue. May be zero.
Return values
CA_ERROR_SUCCESSThe given setting was changed or staged.
CA_ERROR_NOT_IMPLEMENTEDThis function is not implemented on this platform.
CA_ERROR_NO_BUFFERNo space remaining to store the given setting.

◆ caUtilSettingsSetSettingMovedCb()

void caUtilSettingsSetSettingMovedCb ( setting_moved_cb_t aCb)

Registers the callback for when all settings have moved.

Used for updating or invalidating an address cache generated with caUtilSettingsGetLastWriteAddress

Parameters
aCbThe function to be called. Will be called once per settings swap (aka defragment / garbage collection).

◆ caUtilSettingsSwapSettingsBlock()

uint32_t caUtilSettingsSwapSettingsBlock ( struct ca821x_dev * aInstance)

Defragment the persistent storage by migrating all valid items to a fresh flash region.

This function is called automatically when necessary by the caUtilSettingsSet/Add APIs. In general, calling this function is unnecessary unless you want to guarantee that future writes will return quickly (without having to defragment).

◆ caUtilSettingsWipe()

void caUtilSettingsWipe ( struct ca821x_dev * aInstance,
const char * aApplicationName,
uint32_t aNodeId )

Removes all settings from the setting store.

This function deletes all settings from the settings store, resetting it to its initial factory state.

Parameters
[in]aInstanceThe Cascoda instance structure.
[in]aApplicationNameApplication of the storage file, used to distinguish between storage applications. Unused on baremetal.
[in]aNodeIdUsed to distinguish between different nodes on the same host. Must be smaller than or equal to 9999. Unused on baremetal.