Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

Flash Circular Buffer APIs. More...

Typedefs

typedef int(* fcb_walk_cb) (struct fcb_entry_ctx *loc_ctx, void *arg)
 FCB Walk callback function type.
 

Functions

int fcb_init (int f_area_id, struct fcb *fcbp)
 Initialize FCB instance.
 
int fcb_append (struct fcb *fcbp, uint16_t len, struct fcb_entry *loc)
 Appends an entry to circular buffer.
 
int fcb_append_finish (struct fcb *fcbp, struct fcb_entry *append_loc)
 Finishes entry append operation.
 
int fcb_walk (struct fcb *fcbp, struct flash_sector *sector, fcb_walk_cb cb, void *cb_arg)
 Walk over all entries in the FCB sector.
 
int fcb_getnext (struct fcb *fcbp, struct fcb_entry *loc)
 Get next fcb entry location.
 
int fcb_rotate (struct fcb *fcbp)
 Rotate fcb sectors.
 
int fcb_append_to_scratch (struct fcb *fcbp)
 Start using the scratch block.
 
int fcb_free_sector_cnt (struct fcb *fcbp)
 Get free sector count.
 
int fcb_is_empty (struct fcb *fcbp)
 Check whether FCB has any data.
 
int fcb_offset_last_n (struct fcb *fcbp, uint8_t entries, struct fcb_entry *last_n_entry)
 Finds the fcb entry that gives back up to n entries at the end.
 
int fcb_clear (struct fcb *fcbp)
 Clear fcb instance storage.
 

Detailed Description

Flash Circular Buffer APIs.

Typedef Documentation

◆ fcb_walk_cb

typedef int(* fcb_walk_cb) (struct fcb_entry_ctx *loc_ctx, void *arg)

#include <include/zephyr/fs/fcb.h>

FCB Walk callback function type.

Type of function which is expected to be called while walking over fcb entries thanks to a fcb_walk call.

Entry data can be read using flash_area_read(), using loc_ctx fields as arguments. If cb wants to stop the walk, it should return non-zero value.

Parameters
[in]loc_ctxentry location information (full context)
[in,out]argcallback context, transferred from fcb_walk.
Returns
0 continue walking, non-zero stop walking.

Function Documentation

◆ fcb_append()

int fcb_append ( struct fcb fcbp,
uint16_t  len,
struct fcb_entry loc 
)

#include <include/zephyr/fs/fcb.h>

Appends an entry to circular buffer.

When writing the contents for the entry, use loc->fe_sector and loc->fe_data_off with flash_area_write() to fcb flash_area. When you're finished, call fcb_append_finish() with loc as argument.

Parameters
[in]fcbpFCB instance structure.
[in]lenLength of data which are expected to be written as the entry payload.
[out]locentry location information
Returns
0 on success, non-zero on failure.

◆ fcb_append_finish()

int fcb_append_finish ( struct fcb fcbp,
struct fcb_entry append_loc 
)

#include <include/zephyr/fs/fcb.h>

Finishes entry append operation.

Parameters
[in]fcbpFCB instance structure.
[in]append_locentry location information
Returns
0 on success, non-zero on failure.

◆ fcb_append_to_scratch()

int fcb_append_to_scratch ( struct fcb fcbp)

#include <include/zephyr/fs/fcb.h>

Start using the scratch block.

Take one of the scratch blocks into use. So a scratch sector becomes active sector to which entries can be appended.

Parameters
[in]fcbpFCB instance structure.
Returns
0 on success, non-zero on failure.

◆ fcb_clear()

int fcb_clear ( struct fcb fcbp)

#include <include/zephyr/fs/fcb.h>

Clear fcb instance storage.

Parameters
[in]fcbpFCB instance structure.
Returns
0 on success; non-zero on failure

◆ fcb_free_sector_cnt()

int fcb_free_sector_cnt ( struct fcb fcbp)

#include <include/zephyr/fs/fcb.h>

Get free sector count.

Parameters
[in]fcbpFCB instance structure.
Returns
Number of free sectors.

◆ fcb_getnext()

int fcb_getnext ( struct fcb fcbp,
struct fcb_entry loc 
)

#include <include/zephyr/fs/fcb.h>

Get next fcb entry location.

Function to obtain fcb entry location in relation to entry pointed by

loc. If loc->fe_sector is set and loc->fe_elem_off is not 0 function fetches next fcb entry location. If loc->fe_sector is NULL function fetches the oldest entry location within FCB storage. loc->fe_sector is set and loc->fe_elem_off is 0 function fetches the first entry location in the fcb sector.

Parameters
[in]fcbpFCB instance structure.
[in,out]locentry location information
Returns
0 on success, non-zero on failure.

◆ fcb_init()

int fcb_init ( int  f_area_id,
struct fcb fcbp 
)

#include <include/zephyr/fs/fcb.h>

Initialize FCB instance.

Parameters
[in]f_area_idID of flash area where fcb storage resides.
[in,out]fcbpFCB instance structure.
Returns
0 on success, non-zero on failure.

◆ fcb_is_empty()

int fcb_is_empty ( struct fcb fcbp)

#include <include/zephyr/fs/fcb.h>

Check whether FCB has any data.

Parameters
[in]fcbpFCB instance structure.
Returns
Positive value if fcb is empty, otherwise 0.

◆ fcb_offset_last_n()

int fcb_offset_last_n ( struct fcb fcbp,
uint8_t  entries,
struct fcb_entry last_n_entry 
)

#include <include/zephyr/fs/fcb.h>

Finds the fcb entry that gives back up to n entries at the end.

Parameters
[in]fcbpFCB instance structure.
[in]entriesnumber of fcb entries the user wants to get
[out]last_n_entrylast_n_entry the fcb_entry to be returned
Returns
0 on there are any fcbs available; -ENOENT otherwise

◆ fcb_rotate()

int fcb_rotate ( struct fcb fcbp)

#include <include/zephyr/fs/fcb.h>

Rotate fcb sectors.

Function erases the data from oldest sector. Upon that the next sector becomes the oldest. Active sector is also switched if needed.

Parameters
[in]fcbpFCB instance structure.

◆ fcb_walk()

int fcb_walk ( struct fcb fcbp,
struct flash_sector sector,
fcb_walk_cb  cb,
void *  cb_arg 
)

#include <include/zephyr/fs/fcb.h>

Walk over all entries in the FCB sector.

Parameters
[in]sectorfcb sector to be walked. If null, traverse entire storage.
[in]fcbpFCB instance structure.
[in]cbpointer to the function which gets called for every entry. If cb wants to stop the walk, it should return non-zero value.
[in,out]cb_argcallback context, transferred to the callback implementation.
Returns
0 on success, negative on failure (or transferred form callback return-value), positive transferred form callback return-value