Lines Matching refs:fcbp
19 uint8_t fcb_get_align(const struct fcb *fcbp) in fcb_get_align() argument
23 if (fcbp->fap == NULL) { in fcb_get_align()
27 align = flash_area_align(fcbp->fap); in fcb_get_align()
32 int fcb_flash_read(const struct fcb *fcbp, const struct flash_sector *sector, off_t off, in fcb_flash_read() argument
41 if (fcbp->fap == NULL) { in fcb_flash_read()
45 rc = flash_area_read(fcbp->fap, sector->fs_off + off, dst, len); in fcb_flash_read()
54 int fcb_flash_write(const struct fcb *fcbp, const struct flash_sector *sector, off_t off, in fcb_flash_write() argument
63 if (fcbp->fap == NULL) { in fcb_flash_write()
67 rc = flash_area_write(fcbp->fap, sector->fs_off + off, src, len); in fcb_flash_write()
76 int fcb_erase_sector(const struct fcb *fcbp, const struct flash_sector *sector) in fcb_erase_sector() argument
80 if (fcbp->fap == NULL) { in fcb_erase_sector()
84 rc = flash_area_flatten(fcbp->fap, sector->fs_off, sector->fs_size); in fcb_erase_sector()
92 int fcb_init(int f_area_id, struct fcb *fcbp) in fcb_init() argument
103 if (!fcbp->f_sectors || fcbp->f_sector_cnt - fcbp->f_scratch_cnt < 1) { in fcb_init()
107 rc = flash_area_open(f_area_id, &fcbp->fap); in fcb_init()
112 fparam = flash_get_parameters(fcbp->fap->fa_dev); in fcb_init()
113 fcbp->f_erase_value = fparam->erase_value; in fcb_init()
115 align = fcb_get_align(fcbp); in fcb_init()
121 for (i = 0; i < fcbp->f_sector_cnt; i++) { in fcb_init()
122 sector = &fcbp->f_sectors[i]; in fcb_init()
123 rc = fcb_sector_hdr_read(fcbp, sector, &fda); in fcb_init()
147 oldest_sector = newest_sector = &fcbp->f_sectors[0]; in fcb_init()
148 rc = fcb_sector_hdr_init(fcbp, oldest_sector, 0); in fcb_init()
154 fcbp->f_align = align; in fcb_init()
155 fcbp->f_oldest = oldest_sector; in fcb_init()
156 fcbp->f_active.fe_sector = newest_sector; in fcb_init()
157 fcbp->f_active.fe_elem_off = fcb_len_in_flash(fcbp, sizeof(struct fcb_disk_area)); in fcb_init()
158 fcbp->f_active_id = newest; in fcb_init()
161 rc = fcb_getnext_in_sector(fcbp, &fcbp->f_active); in fcb_init()
170 k_mutex_init(&fcbp->f_mtx); in fcb_init()
174 int fcb_free_sector_cnt(struct fcb *fcbp) in fcb_free_sector_cnt() argument
179 fa = fcbp->f_active.fe_sector; in fcb_free_sector_cnt()
180 for (i = 0; i < fcbp->f_sector_cnt; i++) { in fcb_free_sector_cnt()
181 fa = fcb_getnext_sector(fcbp, fa); in fcb_free_sector_cnt()
182 if (fa == fcbp->f_oldest) { in fcb_free_sector_cnt()
189 int fcb_is_empty(struct fcb *fcbp) in fcb_is_empty() argument
191 return (fcbp->f_active.fe_sector == fcbp->f_oldest && in fcb_is_empty()
192 fcbp->f_active.fe_elem_off == fcb_len_in_flash(fcbp, sizeof(struct fcb_disk_area))); in fcb_is_empty()
216 int fcb_put_len(const struct fcb *fcbp, uint8_t *buf, uint16_t len) in fcb_put_len() argument
219 buf[0] = len ^ ~fcbp->f_erase_value; in fcb_put_len()
222 buf[0] = (len | 0x80) ^ ~fcbp->f_erase_value; in fcb_put_len()
223 buf[1] = (len >> 7) ^ ~fcbp->f_erase_value; in fcb_put_len()
230 int fcb_get_len(const struct fcb *fcbp, uint8_t *buf, uint16_t *len) in fcb_get_len() argument
236 buf0_xor = buf[0] ^ ~fcbp->f_erase_value; in fcb_get_len()
238 if ((buf[0] == fcbp->f_erase_value) && (buf[1] == fcbp->f_erase_value)) { in fcb_get_len()
242 buf1_xor = buf[1] ^ ~fcbp->f_erase_value; in fcb_get_len()
255 int fcb_sector_hdr_init(struct fcb *fcbp, struct flash_sector *sector, uint16_t id) in fcb_sector_hdr_init() argument
260 fda.fd_magic = fcb_flash_magic(fcbp); in fcb_sector_hdr_init()
261 fda.fd_ver = fcbp->f_version; in fcb_sector_hdr_init()
262 fda._pad = fcbp->f_erase_value; in fcb_sector_hdr_init()
265 rc = fcb_flash_write(fcbp, sector, 0, &fda, sizeof(fda)); in fcb_sector_hdr_init()
278 int fcb_sector_hdr_read(struct fcb *fcbp, struct flash_sector *sector, struct fcb_disk_area *fdap) in fcb_sector_hdr_read() argument
286 rc = fcb_flash_read(fcbp, sector, 0, fdap, sizeof(*fdap)); in fcb_sector_hdr_read()
290 if (fdap->fd_magic == MK32(fcbp->f_erase_value)) { in fcb_sector_hdr_read()
293 if (fdap->fd_magic != fcb_flash_magic(fcbp)) { in fcb_sector_hdr_read()
306 int fcb_offset_last_n(struct fcb *fcbp, uint8_t entries, struct fcb_entry *last_n_entry) in fcb_offset_last_n() argument
319 while (!fcb_getnext(fcbp, &loc)) { in fcb_offset_last_n()
326 rc = fcb_getnext(fcbp, last_n_entry); in fcb_offset_last_n()
346 int fcb_clear(struct fcb *fcbp) in fcb_clear() argument
351 while (!fcb_is_empty(fcbp)) { in fcb_clear()
352 rc = fcb_rotate(fcbp); in fcb_clear()