Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
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
40#define FCB_MAX_LEN (0x3fffu)
63
70#define FCB_ENTRY_FA_DATA_OFF(entry) (entry.fe_sector->fs_off +\
71 entry.fe_data_off)
77 struct fcb_entry loc;
78 const struct flash_area *fap;
80};
81
85#define FCB_FLAGS_CRC_DISABLED BIT(0)
86
94struct fcb {
95 /* Caller of fcb_init fills this in */
115 /* Flash circular buffer internal state */
131 const struct flash_area *fap;
140#ifdef CONFIG_FCB_ALLOW_FIXED_ENDMARKER
141 const uint8_t f_flags;
143#endif
144};
145
165int fcb_init(int f_area_id, struct fcb *fcbp);
166
182int fcb_append(struct fcb *fcbp, uint16_t len, struct fcb_entry *loc);
183
192int fcb_append_finish(struct fcb *fcbp, struct fcb_entry *append_loc);
193
209typedef int (*fcb_walk_cb)(struct fcb_entry_ctx *loc_ctx, void *arg);
210
226int fcb_walk(struct fcb *fcbp, struct flash_sector *sector, fcb_walk_cb cb, void *cb_arg);
227
244int fcb_getnext(struct fcb *fcbp, struct fcb_entry *loc);
245
254int fcb_rotate(struct fcb *fcbp);
255
266int fcb_append_to_scratch(struct fcb *fcbp);
267
275int fcb_free_sector_cnt(struct fcb *fcbp);
276
284int fcb_is_empty(struct fcb *fcbp);
285
295int fcb_offset_last_n(struct fcb *fcbp, uint8_t entries, struct fcb_entry *last_n_entry);
296
304int fcb_clear(struct fcb *fcbp);
305
328int fcb_flash_read(const struct fcb *fcbp, const struct flash_sector *sector, off_t off,
329 void *dst, size_t len);
330
342int fcb_flash_write(const struct fcb *fcbp, const struct flash_sector *sector, off_t off,
343 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_to_scratch(struct fcb *fcbp)
Start using the scratch block.
int fcb_getnext(struct fcb *fcbp, struct fcb_entry *loc)
Get next fcb entry location.
int fcb_free_sector_cnt(struct fcb *fcbp)
Get free sector count.
int fcb_clear(struct fcb *fcbp)
Clear fcb instance storage.
int fcb_append_finish(struct fcb *fcbp, struct fcb_entry *append_loc)
Finishes entry append operation.
int fcb_init(int f_area_id, struct fcb *fcbp)
Initialize FCB instance.
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_rotate(struct fcb *fcbp)
Rotate fcb sectors.
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_append(struct fcb *fcbp, uint16_t len, struct fcb_entry *loc)
Appends an entry to circular buffer.
int fcb_is_empty(struct fcb *fcbp)
Check whether FCB has any data.
int(* fcb_walk_cb)(struct fcb_entry_ctx *loc_ctx, void *arg)
FCB Walk callback function type.
Definition fcb.h:209
int fcb_flash_read(const struct fcb *fcbp, const struct flash_sector *sector, off_t off, void *dst, size_t len)
Read raw data from the fcb flash sector.
int fcb_flash_write(const struct fcb *fcbp, const struct flash_sector *sector, off_t off, const void *src, size_t len)
Write raw data to 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:76
struct fcb_entry loc
FCB entry info.
Definition fcb.h:77
const struct flash_area * fap
Flash area where the entry is placed.
Definition fcb.h:78
FCB entry info structure.
Definition fcb.h:51
uint32_t fe_elem_off
Offset from the start of the sector to beginning of element.
Definition fcb.h:55
uint32_t fe_data_off
Offset from the start of the sector to the start of element.
Definition fcb.h:58
uint16_t fe_data_len
Size of data area in fcb entry.
Definition fcb.h:61
struct flash_sector * fe_sector
Pointer to info about sector where data are placed.
Definition fcb.h:52
FCB instance structure.
Definition fcb.h:94
uint8_t f_version
Current version number of the data.
Definition fcb.h:105
const struct flash_area * fap
Flash area used by the fcb instance, internal state.
Definition fcb.h:131
struct k_mutex f_mtx
Locking for accessing the FCB data, internal state.
Definition fcb.h:116
struct fcb_entry f_active
internal state
Definition fcb.h:124
uint32_t f_magic
Magic value, should not be 0xFFFFFFFF.
Definition fcb.h:96
uint8_t f_erase_value
The value flash takes when it is erased.
Definition fcb.h:136
uint16_t f_active_id
Flash location where the newest data is, internal state.
Definition fcb.h:125
uint8_t f_sector_cnt
Number of elements in sector array.
Definition fcb.h:106
uint8_t f_align
writes to flash have to aligned to this, internal state
Definition fcb.h:128
uint8_t f_scratch_cnt
Number of sectors to keep empty.
Definition fcb.h:107
struct flash_sector * f_oldest
Pointer to flash sector containing the oldest data, internal state.
Definition fcb.h:119
struct flash_sector * f_sectors
Array of sectors, must be contiguous.
Definition fcb.h:112
Flash partition.
Definition flash_map.h:59
Structure for transfer flash sector boundaries.
Definition flash_map.h:81
Mutex Structure.
Definition kernel.h:2917
Macro utilities.