Bluetooth: Mesh: Convert to new net_buf_simple APIs
Convert the mesh code to use the new net_buf_siple APIs. This has the benefit of saving 4 bytes off the stack due to the not needed pointer. Also update the publication context helpers to map to the new net_buf_simple API in an intuitive way. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
18422de8da
commit
ac1360f0a7
18 changed files with 546 additions and 587 deletions
|
@ -256,7 +256,11 @@ struct bt_mesh_model_op {
|
|||
*/
|
||||
#define BT_MESH_PUB_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 50)
|
||||
|
||||
/** Model publication context. */
|
||||
/** Model publication context.
|
||||
*
|
||||
* The context should primarily be created using the
|
||||
* BT_MESH_MODEL_PUB_DEFINE macro.
|
||||
*/
|
||||
struct bt_mesh_model_pub {
|
||||
/** The model the context belongs to. Initialized by the stack. */
|
||||
struct bt_mesh_model *mod;
|
||||
|
@ -275,20 +279,10 @@ struct bt_mesh_model_pub {
|
|||
|
||||
/** @brief Publication buffer, containing the publication message.
|
||||
*
|
||||
* The application is expected to initialize this with
|
||||
* a valid net_buf_simple pointer, with the help of e.g.
|
||||
* the NET_BUF_SIMPLE() macro. The publication buffer must
|
||||
* contain a valid publication message before calling the
|
||||
* bt_mesh_model_publish() API or after the publication's
|
||||
* @ref bt_mesh_model_pub.update callback has been called
|
||||
* and returned success. The buffer must be created outside
|
||||
* of function context, i.e. it must not be on the stack.
|
||||
* This is most conveniently acheived by creating it inline
|
||||
* when declaring the publication context:
|
||||
* This will get correctly created when the publication context
|
||||
* has been defined using the BT_MESH_MODEL_PUB_DEFINE macro.
|
||||
*
|
||||
* static struct bt_mesh_model_pub my_pub = {
|
||||
* .msg = NET_BUF_SIMPLE(size),
|
||||
* };
|
||||
* BT_MESH_MODEL_PUB_DEFINE(name, update, size);
|
||||
*/
|
||||
struct net_buf_simple *msg;
|
||||
|
||||
|
@ -310,6 +304,21 @@ struct bt_mesh_model_pub {
|
|||
struct k_delayed_work timer;
|
||||
};
|
||||
|
||||
/** @def BT_MESH_MODEL_PUB_DEFINE
|
||||
*
|
||||
* Define a model publication context.
|
||||
*
|
||||
* @param _name Variable name given to the context.
|
||||
* @param _update Optional message update callback (may be NULL).
|
||||
* @param _msg_len Length of the publication message.
|
||||
*/
|
||||
#define BT_MESH_MODEL_PUB_DEFINE(_name, _update, _msg_len) \
|
||||
NET_BUF_SIMPLE_DEFINE_STATIC(bt_mesh_pub_msg_##_name, _msg_len); \
|
||||
static struct bt_mesh_model_pub _name = { \
|
||||
.update = _update, \
|
||||
.msg = &bt_mesh_pub_msg_##_name, \
|
||||
}
|
||||
|
||||
/** Abstraction that describes a Mesh Model instance */
|
||||
struct bt_mesh_model {
|
||||
union {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue