Skip to content

Commit

Permalink
Add support for Sleepy End Device in EFR32 examples and add power man…
Browse files Browse the repository at this point in the history
…ager to enable and handle MCU sleep modes
  • Loading branch information
jmartinez-silabs committed Jan 24, 2022
1 parent 1490461 commit 9dd2eb5
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 144 deletions.
2 changes: 1 addition & 1 deletion examples/lighting-app/efr32/.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ check_system_includes = true
default_args = {
target_cpu = "arm"
target_os = "freertos"

chip_openthread_ftd = true
import("//args.gni")
}
3 changes: 3 additions & 0 deletions examples/lighting-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ declare_args() {
# Monitor & log memory usage at runtime.
enable_heap_monitoring = false

# Enable Sleepy end device
sleepy_device = false

# Wifi related stuff - they are overriden by gn -args="use_wf200=true"
use_wf200 = false
use_rs911x = false
Expand Down
1 change: 0 additions & 1 deletion examples/lighting-app/efr32/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain")
pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip"
pw_assert_BACKEND = "$dir_pw_assert_log"
chip_enable_openthread = true
chip_openthread_ftd = true
chip_system_config_use_open_thread_udp = true
47 changes: 2 additions & 45 deletions examples/lighting-app/efr32/include/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,34 +127,15 @@ extern "C" {
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/

/* Set configCREATE_LOW_POWER_DEMO as follows:
*
* 0: Build the full test and demo application.
* 1: Build the simple blinky tickless low power demo, generating the tick
* interrupt from the RTCC. EM2 will be entered. The LXFO clock is used.
* See the comments at the top of main.c, main_full.c and main_low_power.c for
* more information.
*/

#define configCREATE_LOW_POWER_DEMO (0)

/* Some configuration is dependent on the demo being built. */
#if (configCREATE_LOW_POWER_DEMO == 0)

/* Tickless mode is not used. */

/* Some of the standard demo test tasks assume a tick rate of 1KHz, even
though that is faster than would normally be warranted by a real
application. */
#define configTICK_RATE_HZ (1000)

/* Energy saving modes. */
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
#define configUSE_TICKLESS_IDLE 1
#else
#define configUSE_TICKLESS_IDLE 0
#endif
#endif //SL_CATALOG_POWER_MANAGER_PRESENT

#define configTICK_RATE_HZ (1000)
/* Definition used by Keil to replace default system clock source. */
#define configOVERRIDE_DEFAULT_TICK_CONFIGURATION 1

Expand All @@ -164,30 +145,6 @@ application. */
#define configUSE_MALLOC_FAILED_HOOK (1)
#define configUSE_IDLE_HOOK (1)

#define configENERGY_MODE (sleepEM1)

#else

/* Tickless idle mode, generating RTOS tick interrupts from the RTC, fed
by the LXFO clock. */

/* The slow clock used to generate the tick interrupt in the low power demo
runs at 32768/8=4096Hz. Ensure the tick rate is a multiple of the clock. */
#define configTICK_RATE_HZ (128)

/* The low power demo uses the tickless idle feature. */
#define configUSE_TICKLESS_IDLE (1)
#define configOVERRIDE_DEFAULT_TICK_CONFIGURATION (1)

/* Hook function related definitions. */
#define configUSE_TICK_HOOK (0)
#define configCHECK_FOR_STACK_OVERFLOW (0)
#define configUSE_MALLOC_FAILED_HOOK (0)
#define configUSE_IDLE_HOOK (1)

#define configENERGY_MODE (sleepEM3)
#endif

/* Main functions*/
/* Run time stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS (0)
Expand Down
7 changes: 7 additions & 0 deletions examples/lighting-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,14 @@ int main(void)
appError(ret);
}

#if CHIP_DEVICE_CONFIG_THREAD_FTD
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router);
#else // CHIP_DEVICE_CONFIG_THREAD_FTD
#if CHIP_DEVICE_CONFIG_ENABLE_SED
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SleepyEndDevice);
#endif // CHIP_DEVICE_CONFIG_ENABLE_SED
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice);
#endif // CHIP_DEVICE_CONFIG_THREAD_FTD
if (ret != CHIP_NO_ERROR)
{
EFR32_LOG("ConnectivityMgr().SetThreadDeviceType() failed");
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/efr32/.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ check_system_includes = true
default_args = {
target_cpu = "arm"
target_os = "freertos"

chip_openthread_ftd = true
import("//args.gni")
}
3 changes: 3 additions & 0 deletions examples/lock-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ declare_args() {

# Monitor & log memory usage at runtime.
enable_heap_monitoring = false

# Enable Sleepy end device
sleepy_device = false

# Wifi related stuff - they are overriden by gn -args="use_wf200=true"
use_wf200 = false
Expand Down
1 change: 0 additions & 1 deletion examples/lock-app/efr32/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ import("${chip_root}/src/platform/EFR32/args.gni")
efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain")

chip_enable_openthread = true
chip_openthread_ftd = true
pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip"
pw_assert_BACKEND = "$dir_pw_assert_log"
47 changes: 2 additions & 45 deletions examples/lock-app/efr32/include/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,34 +127,15 @@ extern "C" {
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/

/* Set configCREATE_LOW_POWER_DEMO as follows:
*
* 0: Build the full test and demo application.
* 1: Build the simple blinky tickless low power demo, generating the tick
* interrupt from the RTCC. EM2 will be entered. The LXFO clock is used.
* See the comments at the top of main.c, main_full.c and main_low_power.c for
* more information.
*/

#define configCREATE_LOW_POWER_DEMO (0)

/* Some configuration is dependent on the demo being built. */
#if (configCREATE_LOW_POWER_DEMO == 0)

/* Tickless mode is not used. */

/* Some of the standard demo test tasks assume a tick rate of 1KHz, even
though that is faster than would normally be warranted by a real
application. */
#define configTICK_RATE_HZ (1000)

/* Energy saving modes. */
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
#define configUSE_TICKLESS_IDLE 1
#else
#define configUSE_TICKLESS_IDLE 0
#endif
#endif //SL_CATALOG_POWER_MANAGER_PRESENT

#define configTICK_RATE_HZ (1000)
/* Definition used by Keil to replace default system clock source. */
#define configOVERRIDE_DEFAULT_TICK_CONFIGURATION 1

Expand All @@ -164,30 +145,6 @@ application. */
#define configUSE_MALLOC_FAILED_HOOK (1)
#define configUSE_IDLE_HOOK (1)

#define configENERGY_MODE (sleepEM1)

#else

/* Tickless idle mode, generating RTOS tick interrupts from the RTC, fed
by the LXFO clock. */

/* The slow clock used to generate the tick interrupt in the low power demo
runs at 32768/8=4096Hz. Ensure the tick rate is a multiple of the clock. */
#define configTICK_RATE_HZ (128)

/* The low power demo uses the tickless idle feature. */
#define configUSE_TICKLESS_IDLE (1)
#define configOVERRIDE_DEFAULT_TICK_CONFIGURATION (1)

/* Hook function related definitions. */
#define configUSE_TICK_HOOK (0)
#define configCHECK_FOR_STACK_OVERFLOW (0)
#define configUSE_MALLOC_FAILED_HOOK (0)
#define configUSE_IDLE_HOOK (1)

#define configENERGY_MODE (sleepEM3)
#endif

/* Main functions*/
/* Run time stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS (0)
Expand Down
7 changes: 7 additions & 0 deletions examples/lock-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,14 @@ int main(void)
appError(ret);
}

#if CHIP_DEVICE_CONFIG_THREAD_FTD
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router);
#else // CHIP_DEVICE_CONFIG_THREAD_FTD
#if CHIP_DEVICE_CONFIG_ENABLE_SED
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SleepyEndDevice);
#endif // CHIP_DEVICE_CONFIG_ENABLE_SED
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice);
#endif // CHIP_DEVICE_CONFIG_THREAD_FTD
if (ret != CHIP_NO_ERROR)
{
EFR32_LOG("ConnectivityMgr().SetThreadDeviceType() failed");
Expand Down
2 changes: 1 addition & 1 deletion examples/window-app/efr32/.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ check_system_includes = true
default_args = {
target_cpu = "arm"
target_os = "freertos"

chip_openthread_ftd = true
import("//args.gni")
}
3 changes: 3 additions & 0 deletions examples/window-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ declare_args() {
# Monitor & log memory usage at runtime.
enable_heap_monitoring = false

# Enable Sleepy end device
sleepy_device = false

# Wifi related stuff - they are overriden by gn -args="use_wf200=true"
use_wf200 = false
use_rs911x = false
Expand Down
1 change: 0 additions & 1 deletion examples/window-app/efr32/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain")
pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip"
pw_assert_BACKEND = "$dir_pw_assert_log"
chip_enable_openthread = true
chip_openthread_ftd = true
47 changes: 2 additions & 45 deletions examples/window-app/efr32/include/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,34 +127,15 @@ extern "C" {
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/

/* Set configCREATE_LOW_POWER_DEMO as follows:
*
* 0: Build the full test and demo application.
* 1: Build the simple blinky tickless low power demo, generating the tick
* interrupt from the RTCC. EM2 will be entered. The LXFO clock is used.
* See the comments at the top of main.c, main_full.c and main_low_power.c for
* more information.
*/

#define configCREATE_LOW_POWER_DEMO (0)

/* Some configuration is dependent on the demo being built. */
#if (configCREATE_LOW_POWER_DEMO == 0)

/* Tickless mode is not used. */

/* Some of the standard demo test tasks assume a tick rate of 1KHz, even
though that is faster than would normally be warranted by a real
application. */
#define configTICK_RATE_HZ (1000)

/* Energy saving modes. */
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
#define configUSE_TICKLESS_IDLE 1
#else
#define configUSE_TICKLESS_IDLE 0
#endif
#endif //SL_CATALOG_POWER_MANAGER_PRESENT

#define configTICK_RATE_HZ (1000)
/* Definition used by Keil to replace default system clock source. */
#define configOVERRIDE_DEFAULT_TICK_CONFIGURATION 1

Expand All @@ -164,30 +145,6 @@ application. */
#define configUSE_MALLOC_FAILED_HOOK (1)
#define configUSE_IDLE_HOOK (1)

#define configENERGY_MODE (sleepEM1)

#else

/* Tickless idle mode, generating RTOS tick interrupts from the RTC, fed
by the LXFO clock. */

/* The slow clock used to generate the tick interrupt in the low power demo
runs at 32768/8=4096Hz. Ensure the tick rate is a multiple of the clock. */
#define configTICK_RATE_HZ (128)

/* The low power demo uses the tickless idle feature. */
#define configUSE_TICKLESS_IDLE (1)
#define configOVERRIDE_DEFAULT_TICK_CONFIGURATION (1)

/* Hook function related definitions. */
#define configUSE_TICK_HOOK (0)
#define configCHECK_FOR_STACK_OVERFLOW (0)
#define configUSE_MALLOC_FAILED_HOOK (0)
#define configUSE_IDLE_HOOK (1)

#define configENERGY_MODE (sleepEM3)
#endif

/* Main functions*/
/* Run time stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS (0)
Expand Down
5 changes: 4 additions & 1 deletion examples/window-app/efr32/src/WindowAppImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,10 @@ void WindowAppImpl::UpdateLCD()
}
else
{
LCDWriteQRCode((uint8_t *) mQRCode.c_str());
if (GetQRCode(mQRCode, chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)) == CHIP_NO_ERROR)
{
LCDWriteQRCode((uint8_t *) mQRCode.c_str());
}
}
#endif
}
Expand Down
7 changes: 7 additions & 0 deletions examples/window-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,14 @@ int main(void)
appError(err);
}

#if CHIP_DEVICE_CONFIG_THREAD_FTD
err = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router);
#else // CHIP_DEVICE_CONFIG_THREAD_FTD
#if CHIP_DEVICE_CONFIG_ENABLE_SED
err = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SleepyEndDevice);
#endif // CHIP_DEVICE_CONFIG_ENABLE_SED
err = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice);
#endif // CHIP_DEVICE_CONFIG_THREAD_FTD
if (err != CHIP_NO_ERROR)
{
EFR32_LOG("ConnectivityMgr().SetThreadDeviceType() failed");
Expand Down
12 changes: 12 additions & 0 deletions third_party/efr32_sdk/efr32_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ template("efr32_sdk") {

defines += board_defines

if (defined(invoker.sleepy_device))
{
if (invoker.sleepy_device) {
print("INVOKER SLEEPY")
defines += [
"CHIP_DEVICE_CONFIG_ENABLE_SED=1",
"SL_CATALOG_POWER_MANAGER_PRESENT",
"SL_CATALOG_SLEEPTIMER_PRESENT",
]
}
}

if (chip_build_libshell) {
defines += [
"ENABLE_CHIP_SHELL",
Expand Down

0 comments on commit 9dd2eb5

Please sign in to comment.