mgmt: mcumgr: Add iterable section to register MCUmgr handlers
This replaces the requirement for applications to manually register MCUmgr handlers by having an iterable section which then automatically registers the handlers at boot time. Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This commit is contained in:
parent
f7ab9a8c52
commit
d7557102c0
17 changed files with 104 additions and 92 deletions
|
@ -11,6 +11,7 @@
|
|||
#include <zephyr/fs/fs.h>
|
||||
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
|
||||
#include <zephyr/mgmt/mcumgr/smp/smp.h>
|
||||
#include <zephyr/mgmt/mcumgr/mgmt/handlers.h>
|
||||
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt.h>
|
||||
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum.h>
|
||||
#include <assert.h>
|
||||
|
@ -688,3 +689,5 @@ void fs_mgmt_register_group(void)
|
|||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
MCUMGR_HANDLER_DEFINE(fs_mgmt, fs_mgmt_register_group);
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
|
||||
#include <zephyr/mgmt/mcumgr/smp/smp.h>
|
||||
#include <zephyr/mgmt/mcumgr/mgmt/handlers.h>
|
||||
#include <zephyr/mgmt/mcumgr/grp/img_mgmt/img_mgmt.h>
|
||||
#include <zephyr/mgmt/mcumgr/grp/img_mgmt/image.h>
|
||||
|
||||
|
@ -611,14 +612,14 @@ static struct mgmt_group img_mgmt_group = {
|
|||
};
|
||||
|
||||
|
||||
void
|
||||
img_mgmt_register_group(void)
|
||||
void img_mgmt_register_group(void)
|
||||
{
|
||||
mgmt_register_group(&img_mgmt_group);
|
||||
}
|
||||
|
||||
void
|
||||
img_mgmt_unregister_group(void)
|
||||
void img_mgmt_unregister_group(void)
|
||||
{
|
||||
mgmt_unregister_group(&img_mgmt_group);
|
||||
}
|
||||
|
||||
MCUMGR_HANDLER_DEFINE(img_mgmt, img_mgmt_register_group);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <zephyr/kernel_structs.h>
|
||||
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
|
||||
#include <zephyr/mgmt/mcumgr/smp/smp.h>
|
||||
#include <zephyr/mgmt/mcumgr/mgmt/handlers.h>
|
||||
#include <zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
@ -680,7 +681,4 @@ void os_mgmt_register_group(void)
|
|||
mgmt_register_group(&os_mgmt_group);
|
||||
}
|
||||
|
||||
void os_mgmt_module_init(void)
|
||||
{
|
||||
os_mgmt_register_group();
|
||||
}
|
||||
MCUMGR_HANDLER_DEFINE(os_mgmt, os_mgmt_register_group);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <zephyr/sys/util.h>
|
||||
#include <zephyr/shell/shell_dummy.h>
|
||||
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
|
||||
#include <zephyr/mgmt/mcumgr/mgmt/handlers.h>
|
||||
#include <zephyr/mgmt/mcumgr/smp/smp.h>
|
||||
#include <zephyr/mgmt/mcumgr/grp/shell_mgmt/shell_mgmt.h>
|
||||
#include <string.h>
|
||||
|
@ -135,8 +136,9 @@ static struct mgmt_group shell_mgmt_group = {
|
|||
};
|
||||
|
||||
|
||||
void
|
||||
shell_mgmt_register_group(void)
|
||||
void shell_mgmt_register_group(void)
|
||||
{
|
||||
mgmt_register_group(&shell_mgmt_group);
|
||||
}
|
||||
|
||||
MCUMGR_HANDLER_DEFINE(shell_mgmt, shell_mgmt_register_group);
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <zcbor_encode.h>
|
||||
|
||||
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
|
||||
#include <zephyr/mgmt/mcumgr/mgmt/handlers.h>
|
||||
#include <zephyr/mgmt/mcumgr/smp/smp.h>
|
||||
#include <zephyr/mgmt/mcumgr/grp/stat_mgmt/stat_mgmt.h>
|
||||
|
||||
|
@ -237,8 +238,9 @@ static struct mgmt_group stat_mgmt_group = {
|
|||
.mg_group_id = MGMT_GROUP_ID_STAT,
|
||||
};
|
||||
|
||||
void
|
||||
stat_mgmt_register_group(void)
|
||||
void stat_mgmt_register_group(void)
|
||||
{
|
||||
mgmt_register_group(&stat_mgmt_group);
|
||||
}
|
||||
|
||||
MCUMGR_HANDLER_DEFINE(stat_mgmt, stat_mgmt_register_group);
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <zephyr/storage/flash_map.h>
|
||||
|
||||
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
|
||||
#include <zephyr/mgmt/mcumgr/mgmt/handlers.h>
|
||||
#include <zephyr/mgmt/mcumgr/grp/zephyr/zephyr_basic.h>
|
||||
|
||||
LOG_MODULE_REGISTER(mcumgr_zephyr_grp);
|
||||
|
@ -59,13 +60,9 @@ static struct mgmt_group zephyr_basic_mgmt_group = {
|
|||
.mg_group_id = (ZEPHYR_MGMT_GRP_BASIC),
|
||||
};
|
||||
|
||||
static int zephyr_basic_mgmt_init(const struct device *dev)
|
||||
void zephyr_basic_mgmt_init(void)
|
||||
{
|
||||
ARG_UNUSED(dev);
|
||||
|
||||
LOG_INF("Registering Zephyr basic mgmt group");
|
||||
mgmt_register_group(&zephyr_basic_mgmt_group);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SYS_INIT(zephyr_basic_mgmt_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
|
||||
MCUMGR_HANDLER_DEFINE(zephyr_basic_mgmt, zephyr_basic_mgmt_init);
|
||||
|
|
|
@ -7,7 +7,9 @@
|
|||
|
||||
#include <zephyr/sys/slist.h>
|
||||
#include <zephyr/sys/byteorder.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
|
||||
#include <zephyr/mgmt/mcumgr/mgmt/handlers.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef CONFIG_MCUMGR_MGMT_NOTIFICATION_HOOKS
|
||||
|
@ -123,3 +125,19 @@ int32_t mgmt_callback_notify(uint32_t event, void *data, size_t data_size)
|
|||
return return_rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Processes all registered MCUmgr handlers at start up and registers them */
|
||||
static int mcumgr_handlers_init(const struct device *dev)
|
||||
{
|
||||
ARG_UNUSED(dev);
|
||||
|
||||
STRUCT_SECTION_FOREACH(mcumgr_handler, handler) {
|
||||
if (handler->init) {
|
||||
handler->init();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SYS_INIT(mcumgr_handlers_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue