Zephyr API Documentation  3.5.0
A Scalable Open Source RTOS
3.5.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
fcb.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017-2023 Nordic Semiconductor ASA
3 * Copyright (c) 2015 Runtime Inc
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7#ifndef ZEPHYR_INCLUDE_FS_FCB_H_
8#define ZEPHYR_INCLUDE_FS_FCB_H_
9
10/*
11 * Flash circular buffer.
12 */
13#include <inttypes.h>
14#include <limits.h>
15
18
19#include <zephyr/kernel.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
38#define FCB_MAX_LEN (CHAR_MAX | CHAR_MAX << 7)
49struct fcb_entry {
60};
61
68#define FCB_ENTRY_FA_DATA_OFF(entry) (entry.fe_sector->fs_off +\
69 entry.fe_data_off)
75 struct fcb_entry loc;
76 const struct flash_area *fap;
78};
79
83#define FCB_FLAGS_CRC_DISABLED BIT(0)
84
92struct fcb {
93 /* Caller of fcb_init fills this in */
113 /* Flash circular buffer internal state */
129 const struct flash_area *fap;
138#ifdef CONFIG_FCB_ALLOW_FIXED_ENDMARKER
139 const uint8_t f_flags;
141#endif
142};
143
163int fcb_init(int f_area_id, struct fcb *fcb);
164
180int fcb_append(struct fcb *fcb, uint16_t len, struct fcb_entry *loc);
181
190int fcb_append_finish(struct fcb *fcb, struct fcb_entry *append_loc);
191
207typedef int (*fcb_walk_cb)(struct fcb_entry_ctx *loc_ctx, void *arg);
208
224int fcb_walk(struct fcb *fcb, struct flash_sector *sector, fcb_walk_cb cb,
225 void *cb_arg);
226
243int fcb_getnext(struct fcb *fcb, struct fcb_entry *loc);
244
253int fcb_rotate(struct fcb *fcb);
254
266
275
283int fcb_is_empty(struct fcb *fcb);
284
294int fcb_offset_last_n(struct fcb *fcb, uint8_t entries,
295 struct fcb_entry *last_n_entry);
296
304int fcb_clear(struct fcb *fcb);
305
328int fcb_flash_read(const struct fcb *fcb, const struct flash_sector *sector,
329 off_t off, void *dst, size_t len);
330
342int fcb_flash_write(const struct fcb *fcb, const struct flash_sector *sector,
343 off_t off, const void *src, size_t len);
344
349#ifdef __cplusplus
350}
351#endif
352
353#endif /* ZEPHYR_INCLUDE_FS_FCB_H_ */
irp nz macro MOVR cc s mov cc s endm endr irp aw macro LDR aa off
Definition: asm-macro-32-bit-gnu.h:17
Public API for flash map.
int fcb_append_finish(struct fcb *fcb, struct fcb_entry *append_loc)
Finishes entry append operation.
int fcb_free_sector_cnt(struct fcb *fcb)
Get free sector count.
int fcb_walk(struct fcb *fcb, struct flash_sector *sector, fcb_walk_cb cb, void *cb_arg)
Walk over all entries in the FCB sector.
int fcb_init(int f_area_id, struct fcb *fcb)
Initialize FCB instance.
int fcb_append(struct fcb *fcb, uint16_t len, struct fcb_entry *loc)
Appends an entry to circular buffer.
int fcb_is_empty(struct fcb *fcb)
Check whether FCB has any data.
int fcb_clear(struct fcb *fcb)
Clear fcb instance storage.
int fcb_rotate(struct fcb *fcb)
Rotate fcb sectors.
int fcb_offset_last_n(struct fcb *fcb, 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_walk_cb)(struct fcb_entry_ctx *loc_ctx, void *arg)
FCB Walk callback function type.
Definition: fcb.h:207
int fcb_getnext(struct fcb *fcb, struct fcb_entry *loc)
Get next fcb entry location.
int fcb_append_to_scratch(struct fcb *fcb)
Start using the scratch block.
int fcb_flash_write(const struct fcb *fcb, const struct flash_sector *sector, off_t off, const void *src, size_t len)
Write raw data to the fcb flash sector.
int fcb_flash_read(const struct fcb *fcb, const struct flash_sector *sector, off_t off, void *dst, size_t len)
Read raw data from the fcb flash sector.
Public kernel APIs.
__INTPTR_TYPE__ off_t
Definition: types.h:36
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
Structure for transferring complete information about FCB entry location within flash memory.
Definition: fcb.h:74
struct fcb_entry loc
FCB entry info.
Definition: fcb.h:75
const struct flash_area * fap
Flash area where the entry is placed.
Definition: fcb.h:76
FCB entry info structure.
Definition: fcb.h:49
uint32_t fe_elem_off
Offset from the start of the sector to beginning of element.
Definition: fcb.h:53
uint32_t fe_data_off
Offset from the start of the sector to the start of element.
Definition: fcb.h:56
uint16_t fe_data_len
Size of data area in fcb entry.
Definition: fcb.h:59
struct flash_sector * fe_sector
Pointer to info about sector where data are placed.
Definition: fcb.h:50
FCB instance structure.
Definition: fcb.h:92
uint8_t f_version
Current version number of the data.
Definition: fcb.h:103
const struct flash_area * fap
Flash area used by the fcb instance, internal state.
Definition: fcb.h:129
struct k_mutex f_mtx
Locking for accessing the FCB data, internal state.
Definition: fcb.h:114
struct fcb_entry f_active
internal state
Definition: fcb.h:122
uint32_t f_magic
Magic value, should not be 0xFFFFFFFF.
Definition: fcb.h:94
uint8_t f_erase_value
The value flash takes when it is erased.
Definition: fcb.h:134
uint16_t f_active_id
Flash location where the newest data is, internal state.
Definition: fcb.h:123
uint8_t f_sector_cnt
Number of elements in sector array.
Definition: fcb.h:104
uint8_t f_align
writes to flash have to aligned to this, internal state
Definition: fcb.h:126
uint8_t f_scratch_cnt
Number of sectors to keep empty.
Definition: fcb.h:105
struct flash_sector * f_oldest
Pointer to flash sector containing the oldest data, internal state.
Definition: fcb.h:117
struct flash_sector * f_sectors
Array of sectors, must be contiguous.
Definition: fcb.h:110
Flash partition.
Definition: flash_map.h:57
Structure for transfer flash sector boundaries.
Definition: flash_map.h:79
Mutex Structure.
Definition: kernel.h:2911
Macro utilities.