nRF Connect SDK API 0.1.0
Loading...
Searching...
No Matches
modules_common.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#ifndef _MODULES_COMMON_H_
8#define _MODULES_COMMON_H_
9
14#include <zephyr/kernel.h>
15
22#ifdef __cplusplus
23extern "C" {
24#endif
25
34#define IS_EVENT(_ptr, _mod, _evt) \
35 is_ ## _mod ## _module_event(&_ptr->module._mod.header) && \
36 _ptr->module._mod.type == _evt
37
43#define SEND_EVENT(_mod, _type) \
44 struct _mod ## _module_event *event = new_ ## _mod ## _module_event(); \
45 __ASSERT(event, "Not enough heap left to allocate event"); \
46 event->type = _type; \
47 APP_EVENT_SUBMIT(event)
48
55#define SEND_ERROR(_mod, _type, _error_code) \
56 struct _mod ## _module_event *event = new_ ## _mod ## _module_event(); \
57 __ASSERT(event, "Not enough heap left to allocate event"); \
58 event->type = _type; \
59 event->data.err = _error_code; \
60 APP_EVENT_SUBMIT(event)
61
68#define SEND_SHUTDOWN_ACK(_mod, _type, _id) \
69 struct _mod ## _module_event *event = new_ ## _mod ## _module_event(); \
70 __ASSERT(event, "Not enough heap left to allocate event"); \
71 event->type = _type; \
72 event->data.id = _id; \
73 APP_EVENT_SUBMIT(event)
74
77 /* Variable used to construct a linked list of module metadata. */
78 sys_snode_t header;
79 /* ID specific to each module. Internally assigned when calling module_start(). */
80 uint32_t id;
81 /* The ID of the module thread. */
82 k_tid_t thread_id;
83 /* Name of the module. */
84 char *name;
85 /* Pointer to the internal message queue in the module. */
86 struct k_msgq *msg_q;
87 /* Flag signifying if the module supports shutdown. */
89};
90
95void module_purge_queue(struct module_data *module);
96
104int module_get_next_msg(struct module_data *module, void *msg);
105
113int module_enqueue_msg(struct module_data *module, void *msg);
114
122bool modules_shutdown_register(uint32_t id_reg);
123
130int module_start(struct module_data *module);
131
137
138#ifdef __cplusplus
139}
140#endif
141
146#endif /* _MODULES_COMMON_H_ */
void module_purge_queue(struct module_data *module)
Purge a module's queue.
uint32_t module_active_count_get(void)
Get the number of active modules in the application.
bool modules_shutdown_register(uint32_t id_reg)
Register that a module has performed a graceful shutdown.
int module_enqueue_msg(struct module_data *module, void *msg)
Enqueue message to a module's queue.
int module_get_next_msg(struct module_data *module, void *msg)
Get the next message in a module's queue.
int module_start(struct module_data *module)
Register and start a module.
struct k_msgq * msg_q
Definition: modules_common.h:86
k_tid_t thread_id
Definition: modules_common.h:82
uint32_t id
Definition: modules_common.h:80
char * name
Definition: modules_common.h:84
sys_snode_t header
Definition: modules_common.h:78
bool supports_shutdown
Definition: modules_common.h:88
Structure that contains module metadata.
Definition: modules_common.h:76