ruuvi.drivers.c
${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
|
Non-volatile storage functions. More...
Files | |
file | ruuvi_task_flash.h |
Functions | |
rd_status_t | rt_flash_init (void) |
Initialize flash storage. More... | |
rd_status_t | rt_flash_store (const uint16_t file_id, const uint16_t record_id, const void *const message, const size_t message_length) |
Store data to flash. More... | |
rd_status_t | rt_flash_load (const uint16_t file_id, const uint16_t record_id, void *const message, const size_t message_length) |
Load data from flash. More... | |
rd_status_t | rt_flash_free (const uint16_t file_id, const uint16_t record_id) |
Free data from flash. More... | |
rd_status_t | rt_flash_gc_run (void) |
Trigger garbage collection. More... | |
bool | rt_flash_busy (void) |
Check if flash is running an operation. More... | |
Non-volatile storage functions.
bool rt_flash_busy | ( | void | ) |
Check if flash is running an operation.
true | if flash is busy. |
false | if flash is not runnning operation. |
Definition at line 209 of file ruuvi_task_flash.c.
rd_status_t rt_flash_free | ( | const uint16_t | file_id, |
const uint16_t | record_id | ||
) |
Free data from flash.
The flash storage implements a simple file system, where data is arranged to files which have records. You can for example have a file for sensor configurations and record for each sensor.
This function does not physically erase the data, it only marks the record as deleteable for garbage collection.
[in] | file_id | ID of a file to delete. Valid range 1 ... 0xBFFF |
[in] | record_id | ID of a record to delete. Valid range 1 ... 0xFFFF |
RD_SUCCESS | on success. |
RD_ERROR_INVALID_STATE | if flash is not initialized. |
RD_ERROR_BUSY | if another operation was ongoing. |
RD_ERROR_NOT_FOUND | if given record was not found. |
rd_status_t rt_flash_gc_run | ( | void | ) |
Trigger garbage collection.
Free up space in flash by erasing old records. It's generally a good idea to check remaining space on flash after a write and trigger GC if the space remaining is smaller than expected record sizes. This function physically erases the records which are garbage collected. Waits until GC can be triggered, and returns when GC operation has been queued.
rd_status_t rt_flash_init | ( | void | ) |
Initialize flash storage.
If flash initialization fails, flash is purged and device tries to enter bootloader.
RD_SUCCESS | on success |
RD_ERROR_INVALID_STATE | if flash is already initialized |
Definition at line 191 of file ruuvi_task_flash.c.
rd_status_t rt_flash_load | ( | const uint16_t | file_id, |
const uint16_t | record_id, | ||
void *const | message, | ||
const size_t | message_length | ||
) |
Load data from flash.
The flash storage implements a simple file system, where data is arranged to files which have records. You can for example have a file for sensor configurations and record for each sensor.
[in] | file_id | ID of a file to load. Valid range 1 ... 0xBFFF |
[in] | record_id | ID of a record to load. Valid range 1 ... 0xFFFF |
[in] | message | Data to load. Must be aligned to a 4-byte boundary. |
[in] | message_length | Length of loaded data. Maximum 4000 bytes per record on nRF52. |
RD_SUCCESS | on success. |
RD_ERROR_NULL | if data pointer is NULL. |
RD_ERROR_INVALID_STATE | if flash is not initialized. |
RD_ERROR_BUSY | if another operation was ongoing. |
RD_ERROR_NOT_FOUND | if given record was not found. |
RD_ERROR_DATA_SIZE | if record exceeds maximum size. |
Definition at line 203 of file ruuvi_task_flash.c.
rd_status_t rt_flash_store | ( | const uint16_t | file_id, |
const uint16_t | record_id, | ||
const void *const | message, | ||
const size_t | message_length | ||
) |
Store data to flash.
The flash storage implements a simple file system, where data is arranged to files which have records. You can for example have a file for sensor configurations and record for each sensor. Underlying implementation provides wear leveling. Garbage collection may be triggered manually and is tried automatically if there is not enough space in flash. This function only queues the data to be written, you must verify that write was completed before freeing message.
If a record with given file_id and record_id already exists, the record is updated. In case the flash memory is 100 % filled, record cannot be updated as new record has to be created before old is deleted to maintain data over power outages etc.
[in] | file_id | ID of a file to store. Valid range 1 ... 0xBFFF |
[in] | record_id | ID of a record to store. Valid range 1 ... 0xFFFF |
[in] | message | Data to store. Must be aligned to a 4-byte boundary. |
[in] | message_length | Length of stored data. Maximum 4000 bytes per record on nRF52. |
RD_SUCCESS | on success. |
RD_ERROR_NULL | if data pointer is NULL. |
RD_ERROR_INVALID_STATE | if flash is not initialized. |
RD_ERROR_BUSY | if another operation was ongoing. |
RD_ERROR_NO_MEM | if there was no space for the record in flash. |
RD_ERROR_DATA_SIZE | if record exceeds maximum size. |
Definition at line 197 of file ruuvi_task_flash.c.