2017-12-13 22:53:20 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Nordic Semiconductor ASA
|
|
|
|
* Copyright (c) 2015 Runtime Inc
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fcb.h"
|
|
|
|
#include "fcb_priv.h"
|
|
|
|
|
|
|
|
/*
|
2018-01-27 06:07:10 +08:00
|
|
|
* Call 'cb' for every element in flash circular buffer. If sector is specified,
|
|
|
|
* only elements with that flash_sector are reported.
|
2017-12-13 22:53:20 +08:00
|
|
|
*/
|
|
|
|
int
|
2018-01-27 06:07:10 +08:00
|
|
|
fcb_walk(struct fcb *fcb, struct flash_sector *sector, fcb_walk_cb cb,
|
2018-02-06 20:05:53 +08:00
|
|
|
void *cb_arg)
|
2017-12-13 22:53:20 +08:00
|
|
|
{
|
2018-02-06 20:05:53 +08:00
|
|
|
struct fcb_entry_ctx entry_ctx;
|
2017-12-13 22:53:20 +08:00
|
|
|
int rc;
|
|
|
|
|
2018-02-06 20:05:53 +08:00
|
|
|
entry_ctx.loc.fe_sector = sector;
|
2019-03-27 09:57:45 +08:00
|
|
|
entry_ctx.loc.fe_elem_off = 0U;
|
2017-12-13 22:53:20 +08:00
|
|
|
|
|
|
|
rc = k_mutex_lock(&fcb->f_mtx, K_FOREVER);
|
2018-02-17 08:52:16 +08:00
|
|
|
if (rc < 0) {
|
2017-12-13 22:53:20 +08:00
|
|
|
return FCB_ERR_ARGS;
|
|
|
|
}
|
2018-02-06 20:05:53 +08:00
|
|
|
while ((rc = fcb_getnext_nolock(fcb, &entry_ctx.loc)) !=
|
|
|
|
FCB_ERR_NOVAR) {
|
2017-12-13 22:53:20 +08:00
|
|
|
k_mutex_unlock(&fcb->f_mtx);
|
2018-02-06 20:05:53 +08:00
|
|
|
if (sector && entry_ctx.loc.fe_sector != sector) {
|
2017-12-13 22:53:20 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2018-02-06 20:05:53 +08:00
|
|
|
|
|
|
|
entry_ctx.fap = fcb->fap;
|
|
|
|
|
|
|
|
rc = cb(&entry_ctx, cb_arg);
|
2017-12-13 22:53:20 +08:00
|
|
|
if (rc) {
|
|
|
|
return rc;
|
|
|
|
}
|
2018-02-17 08:52:16 +08:00
|
|
|
rc = k_mutex_lock(&fcb->f_mtx, K_FOREVER);
|
|
|
|
if (rc < 0) {
|
|
|
|
return FCB_ERR_ARGS;
|
|
|
|
}
|
2017-12-13 22:53:20 +08:00
|
|
|
}
|
|
|
|
k_mutex_unlock(&fcb->f_mtx);
|
|
|
|
return 0;
|
|
|
|
}
|