Nordic nrf51 sdk sources. Mirrored from https://github.com/ARMmbed/nrf51-sdk.

Dependents:   nRF51822 nRF51822

Embed: (wiki syntax)

« Back to documentation index

FStorage

Module which provides low level functionality to store data to flash. More...

Data Structures

struct  fs_config_t
 Flash storage config variable. More...

Modules

 FStorage configuration
 

FStorage configuration.


Typedefs

typedef void(* fs_cb_t )(uint8_t op_code, uint32_t result, uint32_t const *p_data, fs_length_t length_words)
 Callback for flash operations.

Functions

static void fs_callback (uint8_t op_code, uint32_t result, uint32_t const *p_data, fs_length_t length_words)
 Function prototype for a callback handler.
ret_code_t fs_init (void)
 Function to initialize FStorage.
ret_code_t fs_store (fs_config_t const *p_config, uint32_t const *p_addr, uint32_t const *const p_data, fs_length_t length_words)
 Function to store data in flash.
ret_code_t fs_erase (fs_config_t const *p_config, uint32_t *const p_addr, fs_length_t length_words)
 Function to erase a page in flash.
void fs_sys_event_handler (uint32_t sys_evt)
 Function to call to handle events from the SoftDevice.

Detailed Description

Module which provides low level functionality to store data to flash.


Typedef Documentation

typedef void(* fs_cb_t)(uint8_t op_code, uint32_t result, uint32_t const *p_data, fs_length_t length_words)

Callback for flash operations.

Parameters:
[in]op_codeFlash access operation code.
[in]resultResult of the operation.
[in]dataPointer to resulting data (or NULL if not in use).
[in]length_wordsLength of data in words.

Definition at line 71 of file fstorage.h.


Function Documentation

static void fs_callback ( uint8_t  op_code,
uint32_t  result,
uint32_t const *  p_data,
fs_length_t  length_words 
) [static]

Function prototype for a callback handler.

This function is expected to be implemented by the module that registers for fstorage usage. Its usage is described in the function pointer type fs_cb_t.

Parameters:
[in]op_codeFlash operation code.
[in]resultResult of the flash operation.
[in]p_dataPointer to the resulting data (or NULL if not in use).
[in]length_wordsLength of data in words.
ret_code_t fs_erase ( fs_config_t const *  p_config,
uint32_t *const   p_addr,
fs_length_t  length_words 
)

Function to erase a page in flash.

Note:
The erase address must be aligned on a page boundary. The length in words must be equivalent to the page size.
Parameters:
[in]p_configPointer to the configuration of the user that requests the operation.
[in]p_addrAddress of page to erase (the same as first word in the page).
[in]length_wordsLength (in 4 byte words) of the area to erase.
Return values:
NRF_SUCCESSSuccess. Command queued.
NRF_ERROR_INVALID_STATEError. The module is not initialized.
NRF_ERROR_INVALID_ADDRError. Data is unaligned or invalid configuration.
Anyerror returned by the SoftDevice flash API.

Check that the address is aligned on a page boundary and the length to erase is a multiple of the page size.

Definition at line 484 of file fstorage.c.

ret_code_t fs_init ( void   )

Function to initialize FStorage.

This function allocates flash data pages according to the number requested in the config variable. The data used to initialize. the fstorage is section placed variables in the data section "fs_data".

Assign pages to registered users, beginning with the ones with the lowest order, which will be assigned pages with the lowest memory address.

Definition at line 409 of file fstorage.c.

ret_code_t fs_store ( fs_config_t const *  p_config,
uint32_t const *  p_addr,
uint32_t const *const   p_data,
fs_length_t  length_words 
)

Function to store data in flash.

Warning:
The data to be written to flash has to be kept in memory until the operation has terminated, i.e., a callback is received.
Parameters:
[in]p_configConst pointer to configiguration of module user that requests a store operation.
[in]p_addrWrite address of store operation.
[in]p_dataPointer to the data to store.
[in]length_wordsLength of the data to store.
Return values:
NRF_SUCCESSSuccess. Command queued.
NRF_ERROR_INVALID_STATEError. The module is not initialized.
NRF_ERROR_INVALID_ADDRError. Data is unaligned or invalid configuration.
Anyerror returned by the SoftDevice flash API.

Definition at line 454 of file fstorage.c.

void fs_sys_event_handler ( uint32_t  sys_evt )

Function to call to handle events from the SoftDevice.

Parameters:
sys_evtSystem event from the SoftDevice

Function to call to handle events from the SoftDevice.

This function should be dispatched system events if any of the modules used by the application rely on FStorage. Examples include Peer Manager and Flash Data Storage.

Parameters:
[in]sys_evtSystem Event received.

A flash operation was initiated by this module. Handle its result.

A flash operation was initiated outside this module. We have now receveid a callback which indicates it has finished. Clear the FS_FLAG_FLASH_REQ_PENDING flag.

Definition at line 524 of file fstorage.c.