Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/nrf-bm/release_notes/release_notes_changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ Libraries
* The :c:func:`bm_zms_active_sector_free_space` function to return ``-EFAULT`` when the input parameter ``fs`` is ``NULL``.
* The :c:func:`bm_zms_mount` function to expect an additional input parameter of type pointer to struct :c:struct:`bm_zms_fs_config` for configuring a Zephyr Memory Storage file system instance at initialization.

* Removed the :kconfig:option:`CONFIG_BM_ZMS_MAX_USERS` Kconfig option. Now the library expects at most one callback for each instance of the struct :c:struct:`bm_zms_fs`.

* :ref:`lib_peer_manager` library:

* Updated:
Expand Down
23 changes: 11 additions & 12 deletions include/bm/fs/bm_zms.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern "C" {
*/

/**
* @defgroup bm_zms_data_structures BM_ZMS data structures
* @defgroup bm_zms_data_types BM_ZMS data types
* @ingroup bm_zms
* @{
*/
Expand Down Expand Up @@ -63,6 +63,13 @@ struct bm_zms_init_flags {
bool cb_registred; /* true when the user callback is registred. */
} __packed;

/**
* @brief Bare Metal ZMS event handler function prototype.
*
* @param p_evt The event.
*/
typedef void (*bm_zms_cb_t)(bm_zms_evt_t const *p_evt);

/** Zephyr Memory Storage file system structure */
struct bm_zms_fs {
/** File system offset in flash. */
Expand Down Expand Up @@ -91,8 +98,8 @@ struct bm_zms_fs {
struct bm_storage zms_bm_storage;
/** Number of writes currently handled by the storage system. */
atomic_t ongoing_writes;
/** The user number that identifies the callback for an event. */
uint32_t user_num;
/** User callback for propagating events. */
bm_zms_cb_t user_cb;
#if CONFIG_BM_ZMS_LOOKUP_CACHE
/** Lookup table used to cache ATE addresses of written IDs. */
uint64_t lookup_cache[CONFIG_BM_ZMS_LOOKUP_CACHE_SIZE];
Expand Down Expand Up @@ -121,22 +128,14 @@ struct bm_zms_fs_config {
* @{
*/

/**
*@brief Bare Metal ZMS event handler function prototype.
*
* @param p_evt The event.
*/
typedef void (*bm_zms_cb_t)(bm_zms_evt_t const *p_evt);

/**
* @brief Register a callback to BM_ZMS for handling events.
*
* @param cb Pointer to the event handler callback.
* @param fs Pointer to the file system structure.
* @param cb Pointer to the event handler callback.
*
* @retval 0 on success.
* @retval -EFAULT if @p fs or @p cb are NULL.
* @retval -ENOMEM if no more callback slots are available.
*/
int bm_zms_register(struct bm_zms_fs *fs, bm_zms_cb_t cb);

Expand Down
6 changes: 0 additions & 6 deletions subsys/fs/bm_zms/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ config BM_ZMS_CUSTOM_BLOCK_SIZE
help
Changes the internal buffer size of BM_ZMS.

config BM_ZMS_MAX_USERS
int "BM_ZMS maximum users"
default 8
help
Defines the maximum number of event handlers that can be registred by the user.

config BM_ZMS_OP_QUEUE_SIZE
int "BM_ZMS operations queue size"
default 16
Expand Down
22 changes: 4 additions & 18 deletions subsys/fs/bm_zms/bm_zms.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ static int bm_zms_clear_execute(void);
*/
static atomic_t queued_op_cnt;

/* The table of app callback functions. */
static bm_zms_cb_t zms_cb_table[CONFIG_BM_ZMS_MAX_USERS];

/* Queue of bm_zms operations. */
RING_BUF_DECLARE(zms_fifo, CONFIG_BM_ZMS_OP_QUEUE_SIZE * sizeof(zms_op_t));

Expand Down Expand Up @@ -97,8 +94,8 @@ static void event_prepare(bm_zms_evt_t *p_evt)

static void event_send(bm_zms_evt_t const *const p_evt, struct bm_zms_fs *fs)
{
if (zms_cb_table[fs->user_num] != NULL) {
zms_cb_table[fs->user_num](p_evt);
if (fs->user_cb != NULL) {
fs->user_cb(p_evt);
}
}

Expand Down Expand Up @@ -188,7 +185,7 @@ static void queue_process(void)
/* bm_zms needs to be reinitialized after clearing */
cur_op.fs->init_flags.initialized = false;
cur_op.fs->init_flags.initializing = false;
zms_cb_table[cur_op.fs->user_num] = NULL;
cur_op.fs->user_cb = NULL;
cur_op.op_completed = true;
result = 0;
} else {
Expand Down Expand Up @@ -325,22 +322,11 @@ static void zms_event_handler(struct bm_storage_evt *p_evt)

int bm_zms_register(struct bm_zms_fs *fs, bm_zms_cb_t cb)
{
int i;

if (!fs || !cb) {
return -EFAULT;
}

for (i = 0; i < CONFIG_BM_ZMS_MAX_USERS; i++) {
if (zms_cb_table[i] == NULL) {
break;
}
}
if (i == CONFIG_BM_ZMS_MAX_USERS) {
return -ENOMEM;
}
zms_cb_table[i] = cb;
fs->user_num = i;
fs->user_cb = cb;
fs->init_flags.cb_registred = true;

return 0;
Expand Down