From 9dd2eb5b7e54b76c3633cc04d8d0a7ce28b18035 Mon Sep 17 00:00:00 2001 From: Junior Martinez Date: Wed, 19 Jan 2022 16:56:58 -0500 Subject: [PATCH] Add support for Sleepy End Device in EFR32 examples and add power manager to enable and handle MCU sleep modes --- examples/lighting-app/efr32/.gn | 2 +- examples/lighting-app/efr32/BUILD.gn | 3 ++ examples/lighting-app/efr32/args.gni | 1 - .../efr32/include/FreeRTOSConfig.h | 47 +------------------ examples/lighting-app/efr32/src/main.cpp | 7 +++ examples/lock-app/efr32/.gn | 2 +- examples/lock-app/efr32/BUILD.gn | 3 ++ examples/lock-app/efr32/args.gni | 1 - .../lock-app/efr32/include/FreeRTOSConfig.h | 47 +------------------ examples/lock-app/efr32/src/main.cpp | 7 +++ examples/window-app/efr32/.gn | 2 +- examples/window-app/efr32/BUILD.gn | 3 ++ examples/window-app/efr32/args.gni | 1 - .../window-app/efr32/include/FreeRTOSConfig.h | 47 +------------------ .../window-app/efr32/src/WindowAppImpl.cpp | 5 +- examples/window-app/efr32/src/main.cpp | 7 +++ third_party/efr32_sdk/efr32_sdk.gni | 12 +++++ third_party/efr32_sdk/repo | 2 +- third_party/zap/repo | 2 +- 19 files changed, 57 insertions(+), 144 deletions(-) diff --git a/examples/lighting-app/efr32/.gn b/examples/lighting-app/efr32/.gn index 3d48789e30ab3d..0ff42d50e06ef0 100644 --- a/examples/lighting-app/efr32/.gn +++ b/examples/lighting-app/efr32/.gn @@ -23,6 +23,6 @@ check_system_includes = true default_args = { target_cpu = "arm" target_os = "freertos" - + chip_openthread_ftd = true import("//args.gni") } diff --git a/examples/lighting-app/efr32/BUILD.gn b/examples/lighting-app/efr32/BUILD.gn index b9bbca9a8dc80f..f3b4bf14f642b7 100644 --- a/examples/lighting-app/efr32/BUILD.gn +++ b/examples/lighting-app/efr32/BUILD.gn @@ -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 diff --git a/examples/lighting-app/efr32/args.gni b/examples/lighting-app/efr32/args.gni index 0f2b60d59f6054..42061052611489 100644 --- a/examples/lighting-app/efr32/args.gni +++ b/examples/lighting-app/efr32/args.gni @@ -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 diff --git a/examples/lighting-app/efr32/include/FreeRTOSConfig.h b/examples/lighting-app/efr32/include/FreeRTOSConfig.h index 17bc3975fe19af..dc4cb5385fcbe5 100644 --- a/examples/lighting-app/efr32/include/FreeRTOSConfig.h +++ b/examples/lighting-app/efr32/include/FreeRTOSConfig.h @@ -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 @@ -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) diff --git a/examples/lighting-app/efr32/src/main.cpp b/examples/lighting-app/efr32/src/main.cpp index 297601ac6f8670..44d958f2588377 100644 --- a/examples/lighting-app/efr32/src/main.cpp +++ b/examples/lighting-app/efr32/src/main.cpp @@ -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"); diff --git a/examples/lock-app/efr32/.gn b/examples/lock-app/efr32/.gn index 3d48789e30ab3d..0ff42d50e06ef0 100644 --- a/examples/lock-app/efr32/.gn +++ b/examples/lock-app/efr32/.gn @@ -23,6 +23,6 @@ check_system_includes = true default_args = { target_cpu = "arm" target_os = "freertos" - + chip_openthread_ftd = true import("//args.gni") } diff --git a/examples/lock-app/efr32/BUILD.gn b/examples/lock-app/efr32/BUILD.gn index 7dcc8802659fdc..4056216e804f11 100644 --- a/examples/lock-app/efr32/BUILD.gn +++ b/examples/lock-app/efr32/BUILD.gn @@ -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 diff --git a/examples/lock-app/efr32/args.gni b/examples/lock-app/efr32/args.gni index 3ea3fd22b6bd13..5e298bdae486b6 100644 --- a/examples/lock-app/efr32/args.gni +++ b/examples/lock-app/efr32/args.gni @@ -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" diff --git a/examples/lock-app/efr32/include/FreeRTOSConfig.h b/examples/lock-app/efr32/include/FreeRTOSConfig.h index cd1c6a4a845f6c..cd89cfe3802846 100644 --- a/examples/lock-app/efr32/include/FreeRTOSConfig.h +++ b/examples/lock-app/efr32/include/FreeRTOSConfig.h @@ -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 @@ -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) diff --git a/examples/lock-app/efr32/src/main.cpp b/examples/lock-app/efr32/src/main.cpp index 7e25365142199d..bbee37bd7c7a9e 100644 --- a/examples/lock-app/efr32/src/main.cpp +++ b/examples/lock-app/efr32/src/main.cpp @@ -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"); diff --git a/examples/window-app/efr32/.gn b/examples/window-app/efr32/.gn index 3d48789e30ab3d..0ff42d50e06ef0 100644 --- a/examples/window-app/efr32/.gn +++ b/examples/window-app/efr32/.gn @@ -23,6 +23,6 @@ check_system_includes = true default_args = { target_cpu = "arm" target_os = "freertos" - + chip_openthread_ftd = true import("//args.gni") } diff --git a/examples/window-app/efr32/BUILD.gn b/examples/window-app/efr32/BUILD.gn index 2f3c814e4a83cb..2bbfd2ac19c21f 100644 --- a/examples/window-app/efr32/BUILD.gn +++ b/examples/window-app/efr32/BUILD.gn @@ -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 diff --git a/examples/window-app/efr32/args.gni b/examples/window-app/efr32/args.gni index 1b73ad66dcea58..3061e39359d252 100644 --- a/examples/window-app/efr32/args.gni +++ b/examples/window-app/efr32/args.gni @@ -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 diff --git a/examples/window-app/efr32/include/FreeRTOSConfig.h b/examples/window-app/efr32/include/FreeRTOSConfig.h index cd1c6a4a845f6c..cd89cfe3802846 100644 --- a/examples/window-app/efr32/include/FreeRTOSConfig.h +++ b/examples/window-app/efr32/include/FreeRTOSConfig.h @@ -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 @@ -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) diff --git a/examples/window-app/efr32/src/WindowAppImpl.cpp b/examples/window-app/efr32/src/WindowAppImpl.cpp index 7bff2706e5b5cb..c62067380a185d 100644 --- a/examples/window-app/efr32/src/WindowAppImpl.cpp +++ b/examples/window-app/efr32/src/WindowAppImpl.cpp @@ -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 } diff --git a/examples/window-app/efr32/src/main.cpp b/examples/window-app/efr32/src/main.cpp index 2a8704b949dc9d..de64dab6cec4b7 100644 --- a/examples/window-app/efr32/src/main.cpp +++ b/examples/window-app/efr32/src/main.cpp @@ -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"); diff --git a/third_party/efr32_sdk/efr32_sdk.gni b/third_party/efr32_sdk/efr32_sdk.gni index 0bd7a6faf8bd9d..b1ca399851c0b8 100644 --- a/third_party/efr32_sdk/efr32_sdk.gni +++ b/third_party/efr32_sdk/efr32_sdk.gni @@ -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", diff --git a/third_party/efr32_sdk/repo b/third_party/efr32_sdk/repo index 5705278b0c2ad5..d505a886028bcc 160000 --- a/third_party/efr32_sdk/repo +++ b/third_party/efr32_sdk/repo @@ -1 +1 @@ -Subproject commit 5705278b0c2ad5d502705f88e77ac1e4e347637b +Subproject commit d505a886028bccd9592fc53f613228af48ae5532 diff --git a/third_party/zap/repo b/third_party/zap/repo index 85a7080f6d1c17..d57a2656ed73c1 160000 --- a/third_party/zap/repo +++ b/third_party/zap/repo @@ -1 +1 @@ -Subproject commit 85a7080f6d1c17ec0bc4a6698a3dfd1f6bff7ce7 +Subproject commit d57a2656ed73c12a72e393ab65cb0a729b9593a9