Skip to content

Commit eebcdf2

Browse files
MarekPietarlubos
authored andcommitted
caf: events: Add module_suspend_req_event and module_resume_req_event
Add events used to temporarily suspend an application module. Change also adds a new module state: MODULE_STATE_SUSPENDED. Jira: NCSDK-24220 Signed-off-by: Marek Pieta <[email protected]> Signed-off-by: Aleksander Strzebonski <[email protected]>
1 parent 7a39232 commit eebcdf2

File tree

7 files changed

+129
-0
lines changed

7 files changed

+129
-0
lines changed

include/caf/events/module_state_event.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ enum module_state {
202202
*/
203203
MODULE_STATE_STANDBY,
204204

205+
/** Module is suspended in reaction to @ref module_suspend_req_event. The module is resumed
206+
* by @ref module_resume_req_event.
207+
*/
208+
MODULE_STATE_SUSPENDED,
209+
205210
/** Module reported fatal error. */
206211
MODULE_STATE_ERROR,
207212

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef _MODULE_SUSPEND_EVENT_H_
8+
#define _MODULE_SUSPEND_EVENT_H_
9+
10+
/**
11+
* @file
12+
* @defgroup caf_module_suspend_event CAF Module Suspend Event
13+
* @{
14+
* @brief CAF Module Suspend Event.
15+
*/
16+
17+
18+
#include <app_event_manager.h>
19+
#include <app_event_manager_profiler_tracer.h>
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
struct module_suspend_req_event {
26+
/** Event header. */
27+
struct app_event_header header;
28+
29+
/** ID of the module to be suspended. */
30+
const void *sink_module_id;
31+
32+
/** ID of the module that requests the suspension. */
33+
const void *src_module_id;
34+
};
35+
36+
APP_EVENT_TYPE_DECLARE(module_suspend_req_event);
37+
38+
struct module_resume_req_event {
39+
/** Event header. */
40+
struct app_event_header header;
41+
42+
/** ID of the module to be resumed. */
43+
const void *sink_module_id;
44+
45+
/** ID of the module that requests the resumption. */
46+
const void *src_module_id;
47+
};
48+
49+
APP_EVENT_TYPE_DECLARE(module_resume_req_event);
50+
51+
#ifdef __cplusplus
52+
}
53+
#endif
54+
55+
/**
56+
* @}
57+
*/
58+
59+
#endif /* _MODULE_SUSPEND_EVENT_H_ */

subsys/caf/events/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ zephyr_sources_ifdef(CONFIG_CAF_MODULE_STATE_EVENTS
88
module_state_event.c
99
)
1010

11+
zephyr_sources_ifdef(CONFIG_CAF_MODULE_SUSPEND_EVENTS
12+
module_suspend_event.c
13+
)
14+
1115
zephyr_sources_ifdef(CONFIG_CAF_PM_EVENTS
1216
power_event.c
1317
)

subsys/caf/events/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ rsource "Kconfig.factory_reset_event"
137137
rsource "Kconfig.force_power_down_event"
138138
rsource "Kconfig.keep_alive_event"
139139
rsource "Kconfig.module_state_event"
140+
rsource "Kconfig.module_suspend_event"
140141
rsource "Kconfig.power_manager_event"
141142
rsource "Kconfig.sensor_event"
142143

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
config CAF_MODULE_SUSPEND_EVENTS
8+
bool "Module suspend/resume request events"
9+
depends on CAF_MODULE_STATE_EVENTS
10+
help
11+
Enable support for module suspend/resume request events.
12+
13+
config CAF_INIT_LOG_MODULE_SUSPEND_EVENTS
14+
bool "Log module suspend/resume request events"
15+
depends on CAF_MODULE_SUSPEND_EVENTS
16+
depends on LOG
17+
default y

subsys/caf/events/module_state_event.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ static const char * const state_name[] = {
1515
[MODULE_STATE_READY] = "READY",
1616
[MODULE_STATE_OFF] = "OFF",
1717
[MODULE_STATE_STANDBY] = "STANDBY",
18+
[MODULE_STATE_SUSPENDED] = "SUSPENDED",
1819
[MODULE_STATE_ERROR] = "ERROR",
1920
};
2021

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <stdio.h>
8+
9+
#include <caf/events/module_suspend_event.h>
10+
#include <caf/events/module_state_event.h>
11+
12+
static void log_module_suspend_req_event(const struct app_event_header *aeh)
13+
{
14+
const struct module_suspend_req_event *event = cast_module_suspend_req_event(aeh);
15+
16+
APP_EVENT_MANAGER_LOG(aeh, "sink module: %s, source module: %s",
17+
module_name_get(event->sink_module_id),
18+
module_name_get(event->src_module_id));
19+
}
20+
21+
APP_EVENT_TYPE_DEFINE(module_suspend_req_event,
22+
log_module_suspend_req_event,
23+
NULL,
24+
APP_EVENT_FLAGS_CREATE(
25+
IF_ENABLED(CONFIG_CAF_INIT_LOG_MODULE_SUSPEND_EVENTS,
26+
(APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE))));
27+
28+
static void log_module_resume_req_event(const struct app_event_header *aeh)
29+
{
30+
const struct module_resume_req_event *event = cast_module_resume_req_event(aeh);
31+
32+
APP_EVENT_MANAGER_LOG(aeh, "sink module: %s, source module: %s",
33+
module_name_get(event->sink_module_id),
34+
module_name_get(event->src_module_id));
35+
}
36+
37+
APP_EVENT_TYPE_DEFINE(module_resume_req_event,
38+
log_module_resume_req_event,
39+
NULL,
40+
APP_EVENT_FLAGS_CREATE(
41+
IF_ENABLED(CONFIG_CAF_INIT_LOG_MODULE_SUSPEND_EVENTS,
42+
(APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE))));

0 commit comments

Comments
 (0)