Skip to content

Commit f23ebfd

Browse files
MarekPietapdunaj
authored andcommitted
caf: power_event: Introduce power off event
The event is used to broadcast information that system power off is about to happen. Jira: NCSDK-31573 Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
1 parent 55c1ef3 commit f23ebfd

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

include/caf/events/power_event.h

+22
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,27 @@ struct power_down_event {
5757
bool error;
5858
};
5959

60+
/** @brief Power off event.
61+
*
62+
* The power off event is submitted by the module that controls the power management in the
63+
* application to inform other application modules that system power off (sys_poweroff) is about to
64+
* happen. This happens when system is already suspended by @ref power_down_event and entering power
65+
* off state is not restricted.
66+
*
67+
* The module that controls the power management in the application registers itself as the final
68+
* subscriber for the event. When it receives the power off event, it instantly calls the
69+
* sys_poweroff API. Because of that, after handling the power off event, an application module can
70+
* no longer trigger system wakeup using a @ref wake_up_event. An application module could trigger
71+
* system reboot (sys_reboot) to wakeup the system (leaving the power off state goes through the
72+
* system reboot anyway).
73+
*/
74+
struct power_off_event {
75+
/** Event header. */
76+
struct app_event_header header;
77+
78+
/** Information if the power off was result of a fatal error. */
79+
bool error;
80+
};
6081

6182
/** @brief Wake up event.
6283
*
@@ -94,6 +115,7 @@ extern "C" {
94115
#endif
95116

96117
APP_EVENT_TYPE_DECLARE(power_down_event);
118+
APP_EVENT_TYPE_DECLARE(power_off_event);
97119
APP_EVENT_TYPE_DECLARE(wake_up_event);
98120

99121
#ifdef __cplusplus

subsys/caf/events/Kconfig

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ config CAF_INIT_LOG_POWER_DOWN_EVENTS
1818
depends on LOG
1919
default y
2020

21+
config CAF_INIT_LOG_POWER_OFF_EVENTS
22+
bool "Log power off events"
23+
depends on CAF_PM_EVENTS
24+
depends on LOG
25+
default y
26+
2127
config CAF_INIT_LOG_WAKE_UP_EVENTS
2228
bool "Log wake up events"
2329
depends on CAF_PM_EVENTS

subsys/caf/events/power_event.c

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ APP_EVENT_TYPE_DEFINE(power_down_event,
1313
IF_ENABLED(CONFIG_CAF_INIT_LOG_POWER_DOWN_EVENTS,
1414
(APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE))));
1515

16+
APP_EVENT_TYPE_DEFINE(power_off_event,
17+
NULL,
18+
NULL,
19+
APP_EVENT_FLAGS_CREATE(
20+
IF_ENABLED(CONFIG_CAF_INIT_LOG_POWER_OFF_EVENTS,
21+
(APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE))));
22+
1623
APP_EVENT_TYPE_DEFINE(wake_up_event,
1724
NULL,
1825
NULL,

0 commit comments

Comments
 (0)