From 349a311d81a32e66bafbe96ac24fd55c6a6c1eb7 Mon Sep 17 00:00:00 2001 From: Serhii Salamakha Date: Wed, 15 Mar 2023 21:15:30 +0200 Subject: [PATCH] [Telink] Ability to disable Zephyr PM during BLE --- config/telink/chip-module/Kconfig | 6 ++++++ examples/all-clusters-app/telink/prj.conf | 1 + examples/contact-sensor-app/telink/prj.conf | 1 + examples/light-switch-app/telink/prj.conf | 1 + examples/lighting-app/telink/prj.conf | 1 + examples/lock-app/telink/prj.conf | 1 + examples/ota-requestor-app/telink/prj.conf | 1 + examples/pump-app/telink/prj.conf | 1 + examples/pump-controller-app/telink/prj.conf | 1 + examples/temperature-measurement-app/telink/prj.conf | 1 + examples/thermostat/telink/prj.conf | 1 + examples/window-app/telink/prj.conf | 1 + src/platform/telink/BLEManagerImpl.cpp | 11 +++++++++++ 13 files changed, 28 insertions(+) diff --git a/config/telink/chip-module/Kconfig b/config/telink/chip-module/Kconfig index 80d8770e8ed7e3..f047a9cace7526 100644 --- a/config/telink/chip-module/Kconfig +++ b/config/telink/chip-module/Kconfig @@ -162,3 +162,9 @@ config CHIP_ENABLE_APPLICATION_STATUS_LED default y help Enable application status LED. + +config CHIP_ENABLE_PM_DURING_BLE + bool "Enable PM during BLE operation" + default y + help + Enable PM during BLE operation. diff --git a/examples/all-clusters-app/telink/prj.conf b/examples/all-clusters-app/telink/prj.conf index 867ef065f12fe0..bc8ce45c357204 100644 --- a/examples/all-clusters-app/telink/prj.conf +++ b/examples/all-clusters-app/telink/prj.conf @@ -72,3 +72,4 @@ CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED=y # Enable Power Management CONFIG_PM=n CONFIG_PM_DEVICE=n +CONFIG_CHIP_ENABLE_PM_DURING_BLE=n diff --git a/examples/contact-sensor-app/telink/prj.conf b/examples/contact-sensor-app/telink/prj.conf index 8ad82c35fab3a8..7b643ece5322c4 100755 --- a/examples/contact-sensor-app/telink/prj.conf +++ b/examples/contact-sensor-app/telink/prj.conf @@ -72,3 +72,4 @@ CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED=y # Enable Power Management CONFIG_PM=n CONFIG_PM_DEVICE=n +CONFIG_CHIP_ENABLE_PM_DURING_BLE=n diff --git a/examples/light-switch-app/telink/prj.conf b/examples/light-switch-app/telink/prj.conf index 6a715e8b05e6da..9b8262eca31d06 100755 --- a/examples/light-switch-app/telink/prj.conf +++ b/examples/light-switch-app/telink/prj.conf @@ -73,3 +73,4 @@ CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED=y # Enable Power Management CONFIG_PM=n CONFIG_PM_DEVICE=n +CONFIG_CHIP_ENABLE_PM_DURING_BLE=n diff --git a/examples/lighting-app/telink/prj.conf b/examples/lighting-app/telink/prj.conf index cebd1abc50fdce..28f890f98bd9eb 100644 --- a/examples/lighting-app/telink/prj.conf +++ b/examples/lighting-app/telink/prj.conf @@ -73,6 +73,7 @@ CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED=y # Enable Power Management CONFIG_PM=n CONFIG_PM_DEVICE=n +CONFIG_CHIP_ENABLE_PM_DURING_BLE=n # Custom RF power values CONFIG_B91_BLE_CTRL_RF_POWER_P9P11DBM=y diff --git a/examples/lock-app/telink/prj.conf b/examples/lock-app/telink/prj.conf index 0f34d45d8f9cd4..e57b152edb82f8 100755 --- a/examples/lock-app/telink/prj.conf +++ b/examples/lock-app/telink/prj.conf @@ -72,3 +72,4 @@ CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED=y # Enable Power Management CONFIG_PM=n CONFIG_PM_DEVICE=n +CONFIG_CHIP_ENABLE_PM_DURING_BLE=n diff --git a/examples/ota-requestor-app/telink/prj.conf b/examples/ota-requestor-app/telink/prj.conf index a5946d1a0f3fc4..de139770a43d74 100755 --- a/examples/ota-requestor-app/telink/prj.conf +++ b/examples/ota-requestor-app/telink/prj.conf @@ -66,3 +66,4 @@ CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED=y # Enable Power Management CONFIG_PM=n CONFIG_PM_DEVICE=n +CONFIG_CHIP_ENABLE_PM_DURING_BLE=n diff --git a/examples/pump-app/telink/prj.conf b/examples/pump-app/telink/prj.conf index 93c255aacc7e76..6bd026d01cc298 100755 --- a/examples/pump-app/telink/prj.conf +++ b/examples/pump-app/telink/prj.conf @@ -72,3 +72,4 @@ CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED=y # Enable Power Management CONFIG_PM=n CONFIG_PM_DEVICE=n +CONFIG_CHIP_ENABLE_PM_DURING_BLE=n diff --git a/examples/pump-controller-app/telink/prj.conf b/examples/pump-controller-app/telink/prj.conf index 60a7f8ef53ed99..07b9cd80e6bee4 100755 --- a/examples/pump-controller-app/telink/prj.conf +++ b/examples/pump-controller-app/telink/prj.conf @@ -72,3 +72,4 @@ CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED=y # Enable Power Management CONFIG_PM=n CONFIG_PM_DEVICE=n +CONFIG_CHIP_ENABLE_PM_DURING_BLE=n diff --git a/examples/temperature-measurement-app/telink/prj.conf b/examples/temperature-measurement-app/telink/prj.conf index 57d38353f586fb..581d7714188ff6 100644 --- a/examples/temperature-measurement-app/telink/prj.conf +++ b/examples/temperature-measurement-app/telink/prj.conf @@ -73,6 +73,7 @@ CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED=y # Enable Power Management CONFIG_PM=n CONFIG_PM_DEVICE=n +CONFIG_CHIP_ENABLE_PM_DURING_BLE=n # Custom RF power values CONFIG_B91_BLE_CTRL_RF_POWER_P9P11DBM=y diff --git a/examples/thermostat/telink/prj.conf b/examples/thermostat/telink/prj.conf index 74e9f2b682d607..f2994ffd67ed78 100755 --- a/examples/thermostat/telink/prj.conf +++ b/examples/thermostat/telink/prj.conf @@ -73,3 +73,4 @@ CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED=y # Enable Power Management CONFIG_PM=n CONFIG_PM_DEVICE=n +CONFIG_CHIP_ENABLE_PM_DURING_BLE=n diff --git a/examples/window-app/telink/prj.conf b/examples/window-app/telink/prj.conf index a148cdaac140c9..0abc1f68818e50 100644 --- a/examples/window-app/telink/prj.conf +++ b/examples/window-app/telink/prj.conf @@ -72,6 +72,7 @@ CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED=y # Enable Power Management CONFIG_PM=n CONFIG_PM_DEVICE=n +CONFIG_CHIP_ENABLE_PM_DURING_BLE=n # Custom RF power values CONFIG_B91_BLE_CTRL_RF_POWER_P9P11DBM=y diff --git a/src/platform/telink/BLEManagerImpl.cpp b/src/platform/telink/BLEManagerImpl.cpp index dd330a743a1066..4f09f525bced75 100644 --- a/src/platform/telink/BLEManagerImpl.cpp +++ b/src/platform/telink/BLEManagerImpl.cpp @@ -43,6 +43,10 @@ #include #include +#if defined(CONFIG_PM) && !defined(CONFIG_CHIP_ENABLE_PM_DURING_BLE) +#include +#endif + #include // Includes for ieee802154 switchings @@ -316,6 +320,9 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void) VerifyOrReturnError(err == 0, MapErrorZephyr(err)); (void) bt_set_name(bt_dev_name); BLERadioInitialized = true; +#if defined(CONFIG_PM) && !defined(CONFIG_CHIP_ENABLE_PM_DURING_BLE) + pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES); +#endif } // Prepare advertising request @@ -959,6 +966,10 @@ void BLEManagerImpl::SwitchToIeee802154(void) // irq_disable(IRQ1_SYSTIMER); BLERadioInitialized = false; +#if defined(CONFIG_PM) && !defined(CONFIG_CHIP_ENABLE_PM_DURING_BLE) + pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES); +#endif + const struct device * radio_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_ieee802154)); __ASSERT(radio_dev != NULL, "Get radio_dev fail");