Bluetooth: Mesh: Add API to store model's user data in settings work

Mesh models may have a data that needs to be stored persistently.
Currently, the models should call bt_mesh_model_data_store and the store
will happen in the calling context. Most likely that it will be called
in BT RX thread as this is the context from which model's opcodes
handlers are called. Thus, the thread will be blocked until the store is
finished.

Another issues is that some models may have states that changes
frequently. Triggering the store on every state change may wear out
flash. Therefore, the models need to implement some postpone mechanism
to reduce the flash wear out.

The mesh stack has already implemented the mechanism of deferred store
with its own settings. The models could use it instead of implementing
their own mechanism.

In combination with the mesh settings workqueue, the models can store
their data without blocking the stack work.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
This commit is contained in:
Pavel Vasilyev 2023-04-20 18:09:02 +02:00 committed by Carles Cufí
commit 177e9b93bf
4 changed files with 51 additions and 0 deletions

View file

@ -1850,6 +1850,11 @@ static void store_pending_mod(struct bt_mesh_model *mod,
mod->flags &= ~BT_MESH_MOD_PUB_PENDING;
store_pending_mod_pub(mod, vnd);
}
if (mod->flags & BT_MESH_MOD_DATA_PENDING) {
mod->flags &= ~BT_MESH_MOD_DATA_PENDING;
mod->cb->pending_store(mod);
}
}
void bt_mesh_model_pending_store(void)
@ -2134,3 +2139,9 @@ void bt_mesh_model_settings_commit(void)
{
bt_mesh_model_foreach(commit_mod, NULL);
}
void bt_mesh_model_data_store_schedule(struct bt_mesh_model *mod)
{
mod->flags |= BT_MESH_MOD_DATA_PENDING;
bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_MOD_PENDING);
}

View file

@ -17,6 +17,7 @@ enum {
BT_MESH_MOD_PUB_PENDING = BIT(2),
BT_MESH_MOD_EXTENDED = BIT(3),
BT_MESH_MOD_DEVKEY_ONLY = BIT(4),
BT_MESH_MOD_DATA_PENDING = BIT(5),
};
void bt_mesh_elem_register(struct bt_mesh_elem *elem, uint8_t count);