Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

samples: matter: Added system off configuration for smoke CO alarm #19244

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ Matter samples
* :ref:`matter_smoke_co_alarm_sample` sample:

* Added support for ICD dynamic SIT LIT switching (DSLS).
* Added support for system off configuration for the :ref:`zephyr:nrf54l15dk_nrf54l15` target.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the changelog entry as a comment to my #19240 and remove it from this PR.


Networking samples
------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
# Enable LIT ICD configuration
CONFIG_CHIP_ICD_LIT_SUPPORT=y
CONFIG_CHIP_ICD_SIT_SLOW_POLL_LIMIT=5000
CONFIG_CHIP_ICD_REPORT_ON_ACTIVE_MODE=y
CONFIG_NCS_SAMPLE_MATTER_ZAP_FILES_PATH="snippets/lit_icd"
14 changes: 14 additions & 0 deletions samples/matter/smoke_co_alarm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
#
mainmenu "Matter nRF Connect Smoke CO Alarm Example Application"

config SAMPLE_MATTER_SYSTEM_OFF
bool "Enable system off on idle"
depends on POWEROFF
depends on SOC_SERIES_NRF54LX
depends on CHIP_ICD_LIT_SUPPORT
help
Enable turning off the whole system on entering the idle state.
This allows for greater energy savings than putting system into a sleep state for large sleep intervals.
The option is available only for nRF54L15 target, as the system is woken up using GRTC.

choice OPENTHREAD_NORDIC_LIBRARY_CONFIGURATION
default OPENTHREAD_NORDIC_LIBRARY_MTD
endchoice
Expand All @@ -13,6 +23,7 @@ choice OPENTHREAD_DEVICE_TYPE
default OPENTHREAD_MTD
endchoice

# ICD related configuration
config CHIP_ENABLE_ICD_SUPPORT
default y

Expand All @@ -22,6 +33,9 @@ config CHIP_ICD_LIT_SUPPORT
config CHIP_ICD_SIT_SLOW_POLL_LIMIT
default 5000

config CHIP_ICD_REPORT_ON_ACTIVE_MODE
default y

# Increase the supported event triggers due to the multiple alarm triggers
config NCS_SAMPLE_MATTER_TEST_EVENT_TRIGGERS_MAX
default 12
Expand Down
27 changes: 25 additions & 2 deletions samples/matter/smoke_co_alarm/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,38 @@ The sample supports ICD Dynamic SIT LIT switching (DSLS) feature to switch betwe
The device uses the SIT mode, when the wired power source is active.
Otherwise, it switches to the LIT mode, to indicate that it is possible to save the energy, when using a battery power source.
Dynamic switching is possible only if the ICD device meets all criteria for operating in the LIT mode (it has at least one client registered).
DSLS support is enabled by default.
To disable it, set the :kconfig:option:`CONFIG_CHIP_ICD_DSLS_SUPPORT` Kconfig option to ``n``.
DSLS support is disabled by default.
To enable it, set the :kconfig:option:`CONFIG_CHIP_ICD_DSLS_SUPPORT` Kconfig option to ``y``.

In the LIT mode, the device responsiveness is much lower than in the SIT mode.
However, you can request the device to become responsive to, for example, change its configuration.
To do that, you need to use the User Active Mode Trigger (UAT) feature by pressing the appropriate button.

See `User interface`_ for information about how to switch the operation modes.

System off configuration
------------------------

The sample supports optional system off configuration, that turns off the whole system once an ICD device enters the idle state.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The sample supports optional system off configuration, that turns off the whole system once an ICD device enters the idle state.
The sample supports optional system off configuration that turns off the whole system once an ICD device enters the idle state.

Turning off the system, instead of putting it to sleep allows the device to achieve much lower power consumption in the idle state.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Turning off the system, instead of putting it to sleep allows the device to achieve much lower power consumption in the idle state.
Turning off the system instead of putting it to sleep allows the device to achieve much lower power consumption in the idle state.

On the other hand, the device wakes up from a sleep state much faster than from the system off, and it sends only Thread data poll frame and Matter data report.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
On the other hand, the device wakes up from a sleep state much faster than from the system off, and it sends only Thread data poll frame and Matter data report.
On the other hand, the device wakes up from the sleep state much faster than from the system off, and it sends only a Thread data poll frame and Matter data report.

In case of waking up from the system off, the device has to boot the whole system, initialize platform, re-attach to network and send data report every time, what consumes a lot of energy.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In case of waking up from the system off, the device has to boot the whole system, initialize platform, re-attach to network and send data report every time, what consumes a lot of energy.
In case of waking up from the system off, the device has to boot the whole system, initialize platform, re-attach to network, and send data report every time, which consumes a lot of energy.


The usage of system off configuration can be beneficial from the perspective of overall power consumption for the scenarios, when the device has relatively big sleep interval and the system boot happens rarely.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The usage of system off configuration can be beneficial from the perspective of overall power consumption for the scenarios, when the device has relatively big sleep interval and the system boot happens rarely.
Using the system off configuration can be beneficial from the perspective of overall power consumption for scenarios, where the device has relatively long sleep interval and the system boot happens rarely.

It was proven by measurements that an ICD device achieves better power consumption with the system off enabled for sleep intervals bigger than 15 minutes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It was proven by measurements that an ICD device achieves better power consumption with the system off enabled for sleep intervals bigger than 15 minutes.
It was proven by measurements that an ICD device achieves lower power consumption with the system off enabled for sleep intervals longer than 15 minutes.


Additionally, the system off solution disables RAM retention, what results in losing the data that could be potentially stored there, like for example diagnostic logs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Additionally, the system off solution disables RAM retention, what results in losing the data that could be potentially stored there, like for example diagnostic logs.
The system off solution disables RAM retention, which results in losing data that could be potentially stored in RAM, like for example diagnostic logs.


This feature is disabled by default, and it is available only for the ``nrf54l15dk/nrf54l15/cpuapp`` target.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This feature is disabled by default, and it is available only for the ``nrf54l15dk/nrf54l15/cpuapp`` target.
This feature is disabled by default, and it is available only for the ``nrf54l15dk/nrf54l15/cpuapp`` board target.

To enable it, set the :kconfig:option:`CONFIG_SAMPLE_MATTER_SYSTEM_OFF` Kconfig option to ``y``.
You can test the sample configuration that enables system off and configures the device to wake-up every 30 minutes, by applying a dedicated overlay file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You can test the sample configuration that enables system off and configures the device to wake-up every 30 minutes, by applying a dedicated overlay file.
You can test the sample configuration that enables system off and configures the device to wake-up every 30 minutes by applying a dedicated overlay file.

To build the sample with the overlay file included, run the following command:

.. parsed-literal::
:class: highlight

west build -b nrf54l15dk/nrf54l15/cpuapp -- -DFILE_SUFFIX=release -DEXTRA_CONF_FILE="overlay-system_off.conf"

.. _matter_smoke_co_alarm_network_mode:

Remote testing in a network
Expand Down
17 changes: 17 additions & 0 deletions samples/matter/smoke_co_alarm/overlay-system_off.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# This overlay file provides sample configuration for the system off usage scenario.
# The configuration is supported only on the nRF54L15 target.

CONFIG_SAMPLE_MATTER_SYSTEM_OFF=y

# Use sleep period equal to 30 minutes. Align OpenThread timeout configs to respect this value.
CONFIG_CHIP_ICD_SLOW_POLL_INTERVAL=180000
CONFIG_CHIP_ICD_IDLE_MODE_DURATION=180
CONFIG_OPENTHREAD_MLE_CHILD_TIMEOUT=180
CONFIG_OPENTHREAD_CHILD_SUPERVISION_CHECK_TIMEOUT=180
CONFIG_OPENTHREAD_CHILD_SUPERVISION_INTERVAL=180
36 changes: 36 additions & 0 deletions samples/matter/smoke_co_alarm/src/app_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
#include <app/clusters/smoke-co-alarm-server/smoke-co-alarm-server.h>
#include <app/server/OnboardingCodesUtil.h>

#ifdef CONFIG_SAMPLE_MATTER_SYSTEM_OFF
#include <zephyr/sys/poweroff.h>
#include <hal/nrf_memconf.h>
#include <zephyr/drivers/timer/nrf_grtc_timer.h>
#endif

#include <zephyr/logging/log.h>

LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL);
Expand Down Expand Up @@ -55,6 +61,10 @@ Identify sIdentify = { AppTask::Instance().kSmokeCoAlarmEndpointId, AppTask::Ide
#ifdef CONFIG_CHIP_ICD_UAT_SUPPORT
#define UAT_BUTTON_MASK DK_BTN3_MSK
#endif

#ifdef CONFIG_SAMPLE_MATTER_SYSTEM_OFF
static K_WORK_DELAYABLE_DEFINE(system_off_work, AppTask::SystemOffWorkHandler);
#endif
} /* namespace */

void AppTask::IdentifyStartHandler(Identify *)
Expand All @@ -78,6 +88,28 @@ void AppTask::ButtonEventHandler(Nrf::ButtonState state, Nrf::ButtonMask hasChan
#endif
}

#ifdef CONFIG_SAMPLE_MATTER_SYSTEM_OFF
void AppTask::SystemOffWorkHandler(k_work *work)
{
z_nrf_grtc_wakeup_prepare(kSystemOffWakeUpInterval * USEC_PER_MSEC);

/* Disable RAM retention in System OFF to save more energy. */
uint32_t ram_sections = 8;

nrf_memconf_ramblock_ret_mask_enable_set(NRF_MEMCONF, 0, BIT_MASK(ram_sections), false);
nrf_memconf_ramblock_ret2_mask_enable_set(NRF_MEMCONF, 0, BIT_MASK(ram_sections), false);

sys_poweroff();
}

void AppTask::OnEnterIdleMode() {
if(Server::GetInstance().GetICDManager().GetICDMode() == ICDConfigurationData::ICDMode::LIT) {
k_work_schedule(&system_off_work, K_SECONDS(1));
}
};

#endif

void AppTask::UpdatedExpressedLedState()
{
Clusters::SmokeCoAlarm::ExpressedStateEnum state;
Expand Down Expand Up @@ -443,6 +475,10 @@ CHIP_ERROR AppTask::Init()
Nrf::Matter::TestEventTrigger::EventTrigger{ 0xFFFF, PowerSourceOffEventCallback }));
#endif

#ifdef CONFIG_SAMPLE_MATTER_SYSTEM_OFF
chip::Server::GetInstance().GetICDManager().RegisterObserver(&Instance());
#endif

return Nrf::Matter::StartServer();
}

Expand Down
48 changes: 46 additions & 2 deletions samples/matter/smoke_co_alarm/src/app_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@
#include "event_triggers/event_triggers.h"
#endif

#ifdef CONFIG_SAMPLE_MATTER_SYSTEM_OFF
#include <app/icd/server/ICDStateObserver.h>
#endif

struct k_timer;
struct Identify;

#ifdef CONFIG_SAMPLE_MATTER_SYSTEM_OFF
class AppTask : public chip::app::ICDStateObserver {
#else
class AppTask {
#endif
public:
static AppTask &Instance()
{
Expand All @@ -29,6 +37,10 @@ class AppTask {
static void IdentifyStartHandler(Identify *);
static void IdentifyStopHandler(Identify *);

#ifdef CONFIG_SAMPLE_MATTER_SYSTEM_OFF
static void SystemOffWorkHandler(k_work *work);
#endif

void UpdatedExpressedLedState();
void SelfTestHandler();

Expand All @@ -45,9 +57,41 @@ class AppTask {
static void SelfTestTimerTimeoutCallback(k_timer *timer);
static void EndSelfTestEventHandler();

#ifdef CONFIG_SAMPLE_MATTER_SYSTEM_OFF
/**
* @brief application has no action to do on this ICD event. Do nothing.
*/
void OnICDModeChange() override {};

/**
* @brief application has no action to do on this ICD event. Do nothing.
*/
void OnEnterActiveMode() override {};

/**
* @brief application has no action to do on this ICD event. Do nothing.
*/
void OnTransitionToIdle() override {};

/**
* @brief when an ICD enters the idle mode, the application arms GRTC for wake up purposes and turns off the
* system.
*/
void OnEnterIdleMode() override;

/* The device has to be active at least every ICD slow poll interval, but we have to wake up system earlier to
* boot, init and re-attach to network. Usually the whole procedure takes less than 2 s, but the wake up
* interval was set to 2.5 s to always be on the safe side.
*/
constexpr static auto kSystemOffWakeUpInterval = CONFIG_CHIP_ICD_SLOW_POLL_INTERVAL - 2500;

#endif

#ifdef CONFIG_NCS_SAMPLE_MATTER_TEST_EVENT_TRIGGERS
constexpr static Nrf::Matter::TestEventTrigger::EventTriggerId kPowerSourceOnEventTriggerId = 0xFFFF'FFFF'8000'0000;
constexpr static Nrf::Matter::TestEventTrigger::EventTriggerId kPowerSourceOffEventTriggerId = 0xFFFF'FFFF'8001'0000;
constexpr static Nrf::Matter::TestEventTrigger::EventTriggerId kPowerSourceOnEventTriggerId =
0xFFFF'FFFF'8000'0000;
constexpr static Nrf::Matter::TestEventTrigger::EventTriggerId kPowerSourceOffEventTriggerId =
0xFFFF'FFFF'8001'0000;
static CHIP_ERROR PowerSourceOnEventCallback(Nrf::Matter::TestEventTrigger::TriggerValue);
static CHIP_ERROR PowerSourceOffEventCallback(Nrf::Matter::TestEventTrigger::TriggerValue);
#endif
Expand Down
Loading