Flash abstraction library that provides basic read, write, and erase operations. More...
Modules |
|
| Flash abstraction library configuration | |
| NVMC implementation | |
|
API implementation of fstorage that uses the non-volatile memory controller (NVMC).
|
|
| SoftDevice implementation | |
|
API implementation of fstorage that uses the SoftDevice.
|
|
Data Structures |
|
| struct | nrf_fstorage_evt_t |
|
An fstorage event.
More...
|
|
| struct | nrf_fstorage_info_t |
|
Information about the implementation and the flash peripheral.
More...
|
|
| struct | nrf_fstorage_t |
|
An fstorage instance.
More...
|
|
| struct | nrf_fstorage_api_s |
|
Functions provided by the API implementation.
More...
|
|
Macros |
|
| #define | NRF_FSTORAGE_DEF (inst) NRF_SECTION_ITEM_REGISTER (fs_data, inst) |
|
Macro for defining an fstorage instance.
More...
|
|
| #define | NRF_FSTORAGE_INSTANCE_GET (i) NRF_SECTION_ITEM_GET (fs_data, nrf_fstorage_t , (i)) |
|
Macro for retrieving an fstorage instance.
|
|
| #define | NRF_FSTORAGE_INSTANCE_CNT NRF_SECTION_ITEM_COUNT (fs_data, nrf_fstorage_t ) |
|
Macro for retrieving the total number of fstorage instances.
|
|
Typedefs |
|
| typedef void(* | nrf_fstorage_evt_handler_t )( nrf_fstorage_evt_t *p_evt) |
|
Event handler function prototype.
More...
|
|
| typedef struct nrf_fstorage_api_s | nrf_fstorage_api_t |
|
Functions provided by the API implementation.
|
|
Enumerations |
|
| enum |
nrf_fstorage_evt_id_t
{
NRF_FSTORAGE_EVT_READ_RESULT , NRF_FSTORAGE_EVT_WRITE_RESULT , NRF_FSTORAGE_EVT_ERASE_RESULT } |
|
Event IDs.
More...
|
|
Functions |
|
| ret_code_t | nrf_fstorage_init ( nrf_fstorage_t *p_fs, nrf_fstorage_api_t *p_api, void *p_param) |
|
Function for initializing fstorage.
More...
|
|
| ret_code_t | nrf_fstorage_uninit ( nrf_fstorage_t *p_fs, void *p_param) |
|
Function for uninitializing an fstorage instance.
More...
|
|
| ret_code_t | nrf_fstorage_read ( nrf_fstorage_t const *p_fs, uint32_t addr, void *p_dest, uint32_t len) |
|
Function for reading data from flash.
More...
|
|
| ret_code_t | nrf_fstorage_write ( nrf_fstorage_t const *p_fs, uint32_t dest, void const *p_src, uint32_t len, void *p_param) |
|
Function for writing data to flash.
More...
|
|
| ret_code_t | nrf_fstorage_erase ( nrf_fstorage_t const *p_fs, uint32_t page_addr, uint32_t len, void *p_param) |
|
Function for erasing flash pages.
More...
|
|
| uint8_t const * | nrf_fstorage_rmap ( nrf_fstorage_t const *p_fs, uint32_t addr) |
|
Map a flash address to a pointer in the MCU address space that can be dereferenced.
More...
|
|
| uint8_t * | nrf_fstorage_wmap ( nrf_fstorage_t const *p_fs, uint32_t addr) |
|
Map a flash address to a pointer in the MCU address space that can be written to.
More...
|
|
| bool | nrf_fstorage_is_busy ( nrf_fstorage_t const *p_fs) |
|
Function for querying the status of fstorage.
More...
|
|
Detailed Description
Flash abstraction library that provides basic read, write, and erase operations.
The fstorage library can be implemented in different ways. Two implementations are provided:
- The SoftDevice implementation implements flash access through the SoftDevice.
- The NVMC implementation implements flash access through the non-volatile memory controller.
You can select the implementation that should be used independently for each instance of fstorage.
Macro Definition Documentation
| #define NRF_FSTORAGE_DEF | ( | inst | ) | NRF_SECTION_ITEM_REGISTER (fs_data, inst) |
Macro for defining an fstorage instance.
Users of fstorage must define an instance variable by using this macro. Each instance is tied to an API implementation and contains information such as the program and erase units for the target flash peripheral. Instance variables are placed in the "fs_data" section of the binary.
- Parameters
-
[in] inst A definition of an nrf_fstorage_t variable.
Typedef Documentation
| typedef void(* nrf_fstorage_evt_handler_t)( nrf_fstorage_evt_t *p_evt) |
Event handler function prototype.
- Parameters
-
[in] p_evt The event.
Enumeration Type Documentation
Event IDs.
| Enumerator | |
|---|---|
| NRF_FSTORAGE_EVT_WRITE_RESULT |
Event for nrf_fstorage_write . |
| NRF_FSTORAGE_EVT_ERASE_RESULT |
Event for nrf_fstorage_erase . |
Function Documentation
| ret_code_t nrf_fstorage_erase | ( | nrf_fstorage_t const * | p_fs , |
| uint32_t | page_addr , | ||
| uint32_t | len , | ||
| void * | p_param | ||
| ) |
Function for erasing flash pages.
This function erases
len
pages starting from the page at address
page_addr
. The erase operation must be initiated on a page boundary.
- Parameters
-
[in] p_fs The fstorage instance. [in] page_addr Address of the page to erase. [in] len Number of pages to erase. [in] p_param User-defined parameter passed to the event handler (may be NULL).
- Return values
-
NRF_SUCCESS If the operation was accepted. NRF_ERROR_NULL If p_fsis NULL.NRF_ERROR_INVALID_STATE If the module is not initialized. NRF_ERROR_INVALID_LENGTH If lenis zero.NRF_ERROR_INVALID_ADDR If the address page_addris outside the flash memory boundaries specified inp_fs, or if it is unaligned.NRF_ERROR_NO_MEM If no memory is available to accept the operation. When using the SoftDevice implementation , this error indicates that the internal queue of operations is full.
| ret_code_t nrf_fstorage_init | ( | nrf_fstorage_t * | p_fs , |
| nrf_fstorage_api_t * | p_api , | ||
| void * | p_param | ||
| ) |
Function for initializing fstorage.
- Parameters
-
[in] p_fs The fstorage instance to initialize. [in] p_api The API implementation to use. [in] p_param An optional parameter to pass to the implementation-specific API call.
- Return values
-
NRF_SUCCESS If initialization was successful. NRF_ERROR_NULL If p_fsorp_apifield inp_fsis NULL.NRF_ERROR_INTERNAL If another error occurred.
| bool nrf_fstorage_is_busy | ( | nrf_fstorage_t const * | p_fs | ) |
Function for querying the status of fstorage.
An uninitialized instance of fstorage is treated as not busy.
- Parameters
-
[in] p_fs The fstorage instance. Pass NULL to query all instances.
- Returns
-
If
p_fsisNULL, this function returns true if any fstorage instance is busy or false otherwise. -
If
p_fsis notNULL, this function returns true if the fstorage instance is busy or false otherwise.
| ret_code_t nrf_fstorage_read | ( | nrf_fstorage_t const * | p_fs , |
| uint32_t | addr , | ||
| void * | p_dest , | ||
| uint32_t | len | ||
| ) |
Function for reading data from flash.
Copy
len
bytes from
addr
to
p_dest
.
- Parameters
-
[in] p_fs The fstorage instance. [in] addr Address in flash where to read from. [in] p_dest Buffer where the data should be copied. [in] len Length of the data to be copied (in bytes).
- Return values
-
NRF_SUCCESS If the operation was successful. NRF_ERROR_NULL If p_fsorp_destis NULL.NRF_ERROR_INVALID_STATE If the module is not initialized. NRF_ERROR_INVALID_LENGTH If lenis zero or otherwise invalid.NRF_ERROR_INVALID_ADDR If the address addris outside the flash memory boundaries specified inp_fs, or if it is unaligned.
| uint8_t const* nrf_fstorage_rmap | ( | nrf_fstorage_t const * | p_fs , |
| uint32_t | addr | ||
| ) |
Map a flash address to a pointer in the MCU address space that can be dereferenced.
- Parameters
-
p_fs The fstorage instance. addr The address to map.
- Return values
-
A pointer to the specified address, or NULLif the address cannot be mapped or ifp_fsisNULL.
| ret_code_t nrf_fstorage_uninit | ( | nrf_fstorage_t * | p_fs , |
| void * | p_param | ||
| ) |
Function for uninitializing an fstorage instance.
- Parameters
-
[in] p_fs The fstorage instance to uninitialize. [in] p_param An optional parameter to pass to the implementation-specific API call.
- Return values
-
NRF_SUCCESS If uninitialization was successful. NRF_ERROR_NULL If p_fsis NULL.NRF_ERROR_INVALID_STATE If the module is not initialized. NRF_ERROR_INTERNAL If another error occurred.
| uint8_t* nrf_fstorage_wmap | ( | nrf_fstorage_t const * | p_fs , |
| uint32_t | addr | ||
| ) |
Map a flash address to a pointer in the MCU address space that can be written to.
- Parameters
-
p_fs The fstorage instance. addr The address to map.
- Return values
-
A pointer to the specified address, or NULLif the address cannot be mapped or ifp_fsisNULL.
| ret_code_t nrf_fstorage_write | ( | nrf_fstorage_t const * | p_fs , |
| uint32_t | dest , | ||
| void const * | p_src , | ||
| uint32_t | len , | ||
| void * | p_param | ||
| ) |
Function for writing data to flash.
Write
len
bytes from
p_src
to
dest
.
When using SoftDevice implementation , the data is written by several calls to sd_flash_write if the length of the data exceeds NRF_FSTORAGE_SD_MAX_WRITE_SIZE bytes. Only one event is sent upon completion.
- Note
- The data to be written to flash must be kept in memory until the operation has terminated and an event is received.
- Parameters
-
[in] p_fs The fstorage instance. [in] dest Address in flash memory where to write the data. [in] p_src Data to be written. [in] len Length of the data (in bytes). [in] p_param User-defined parameter passed to the event handler (may be NULL).
- Return values
-
NRF_SUCCESS If the operation was accepted. NRF_ERROR_NULL If p_fsorp_srcis NULL.NRF_ERROR_INVALID_STATE If the module is not initialized. NRF_ERROR_INVALID_LENGTH If lenis zero or not a multiple of the program unit, or if it is otherwise invalid.NRF_ERROR_INVALID_ADDR If the address destis outside the flash memory boundaries specified inp_fs, or if it is unaligned.NRF_ERROR_NO_MEM If no memory is available to accept the operation. When using the SoftDevice implementation , this error indicates that the internal queue of operations is full.