Skip to content

Commit 682816d

Browse files
committed
Sleep: Disallow sleep for targets turning of the systick clock at sleep entry.
When the RTOS is present and the tickless mode is not implemented, it is expected that the next tick issued by the Systick timer will wake up the MCU. However nothing prevents an implementation of the ARM architecture to gate the systick clock signal upon sleep entry. Therefore on those targets sleep shall be prohibited if the RTOS is present and the tickless mode is not implemented. To ease life of porters , a new option has been added in the device add list: STCLK_OF_DURING_SLEEP. This option expose that the target turn of the systick clock during sleep. Targets which exhibit such behavior shall add this define in their device_has list.
1 parent 3f2e986 commit 682816d

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

platform/mbed_sleep.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,22 @@ extern "C" {
6262

6363
/** Lock the deep sleep mode
6464
*
65-
* This locks the automatic deep mode selection.
65+
* This locks the automatic deep mode selection.
6666
* sleep_manager_sleep_auto() will ignore deepsleep mode if
6767
* this function is invoked at least once (the internal counter is non-zero)
6868
*
6969
* Use this locking mechanism for interrupt driven API that are
7070
* running in the background and deepsleep could affect their functionality
71-
*
71+
*
7272
* The lock is a counter, can be locked up to USHRT_MAX
7373
* This function is IRQ and thread safe
7474
*/
7575
void sleep_manager_lock_deep_sleep(void);
7676

7777
/** Unlock the deep sleep mode
7878
*
79-
* Use unlocking in pair with sleep_manager_lock_deep_sleep().
80-
*
79+
* Use unlocking in pair with sleep_manager_lock_deep_sleep().
80+
*
8181
* The lock is a counter, should be equally unlocked as locked
8282
* This function is IRQ and thread safe
8383
*/
@@ -97,7 +97,7 @@ bool sleep_manager_can_deep_sleep(void);
9797
* @note
9898
* If MBED_DEBUG is defined, only hal_sleep is allowed. This ensures the debugger
9999
* to be active for debug modes.
100-
*
100+
*
101101
*/
102102
void sleep_manager_sleep_auto(void);
103103

@@ -106,6 +106,10 @@ void sleep_manager_sleep_auto(void);
106106
* @note This function can be a noop if not implemented by the platform.
107107
* @note This function will be a noop in debug mode (debug build profile when MBED_DEBUG is defined).
108108
* @note This function will be a noop while uVisor is in use.
109+
* @note This function will be a noop if the following conditions are met:
110+
* - The RTOS is present
111+
* - The processor turn off the Systick clock during sleep
112+
* - The target does not implement tickless mode
109113
*
110114
* The processor is setup ready for sleep, and sent to sleep using __WFI(). In this mode, the
111115
* system clock to the core is stopped until a reset or an interrupt occurs. This eliminates
@@ -123,7 +127,9 @@ __INLINE static void sleep(void)
123127
{
124128
#if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED))
125129
#if DEVICE_SLEEP
130+
#if (MBED_CONF_RTOS_PRESENT == 0) || (DEVICE_STCLK_OFF_DURING_SLEEP == 0) || defined(MBED_TICKLESS)
126131
sleep_manager_sleep_auto();
132+
#endif /* (MBED_CONF_RTOS_PRESENT == 0) || (DEVICE_STCLK_OFF_DURING_SLEEP == 0) || defined(MBED_TICKLESS) */
127133
#endif /* DEVICE_SLEEP */
128134
#endif /* !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) */
129135
}

targets/targets.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,6 +3000,7 @@
30003000
"inherits": ["Target"],
30013001
"core": "Cortex-M4F",
30023002
"macros": ["NRF52", "TARGET_NRF52832", "BLE_STACK_SUPPORT_REQD", "SOFTDEVICE_PRESENT", "S132", "CMSIS_VECTAB_VIRTUAL", "CMSIS_VECTAB_VIRTUAL_HEADER_FILE=\"cmsis_nvic.h\"", "MBED_TICKLESS"],
3003+
"device_has": ["STCLK_OFF_DURING_SLEEP"],
30033004
"extra_labels": ["NORDIC", "MCU_NRF52", "MCU_NRF52832", "NRF5", "SDK11", "NRF52_COMMON"],
30043005
"OUTPUT_EXT": "hex",
30053006
"is_disk_virtual": true,
@@ -3037,14 +3038,14 @@
30373038
"supported_form_factors": ["ARDUINO"],
30383039
"inherits": ["MCU_NRF52"],
30393040
"macros_add": ["BOARD_PCA10040", "NRF52_PAN_12", "NRF52_PAN_15", "NRF52_PAN_58", "NRF52_PAN_55", "NRF52_PAN_54", "NRF52_PAN_31", "NRF52_PAN_30", "NRF52_PAN_51", "NRF52_PAN_36", "NRF52_PAN_53", "S132", "CONFIG_GPIO_AS_PINRESET", "BLE_STACK_SUPPORT_REQD", "SWI_DISABLE0", "NRF52_PAN_20", "NRF52_PAN_64", "NRF52_PAN_62", "NRF52_PAN_63"],
3040-
"device_has": ["ANALOGIN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
3041+
"device_has_add": ["ANALOGIN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
30413042
"release_versions": ["2", "5"],
30423043
"device_name": "nRF52832_xxAA"
30433044
},
30443045
"UBLOX_EVA_NINA": {
30453046
"inherits": ["MCU_NRF52"],
30463047
"macros_add": ["BOARD_PCA10040", "NRF52_PAN_12", "NRF52_PAN_15", "NRF52_PAN_58", "NRF52_PAN_55", "NRF52_PAN_54", "NRF52_PAN_31", "NRF52_PAN_30", "NRF52_PAN_51", "NRF52_PAN_36", "NRF52_PAN_53", "S132", "CONFIG_GPIO_AS_PINRESET", "BLE_STACK_SUPPORT_REQD", "SWI_DISABLE0", "NRF52_PAN_20", "NRF52_PAN_64", "NRF52_PAN_62", "NRF52_PAN_63"],
3047-
"device_has": ["ANALOGIN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
3048+
"device_has_add": ["ANALOGIN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
30483049
"release_versions": ["2", "5"],
30493050
"overrides": {"uart_hwfc": 0},
30503051
"device_name": "nRF52832_xxAA"
@@ -3053,15 +3054,15 @@
30533054
"supported_form_factors": ["ARDUINO"],
30543055
"inherits": ["MCU_NRF52"],
30553056
"macros_add": ["BOARD_PCA10040", "NRF52_PAN_12", "NRF52_PAN_15", "NRF52_PAN_58", "NRF52_PAN_55", "NRF52_PAN_54", "NRF52_PAN_31", "NRF52_PAN_30", "NRF52_PAN_51", "NRF52_PAN_36", "NRF52_PAN_53", "S132", "CONFIG_GPIO_AS_PINRESET", "BLE_STACK_SUPPORT_REQD", "SWI_DISABLE0", "NRF52_PAN_20", "NRF52_PAN_64", "NRF52_PAN_62", "NRF52_PAN_63"],
3056-
"device_has": ["ANALOGIN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
3057+
"device_has_add": ["ANALOGIN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
30573058
"release_versions": ["2", "5"],
30583059
"device_name": "nRF52832_xxAA"
30593060
},
30603061
"DELTA_DFBM_NQ620": {
30613062
"supported_form_factors": ["ARDUINO"],
30623063
"inherits": ["MCU_NRF52"],
30633064
"macros_add": ["BOARD_PCA10040", "NRF52_PAN_12", "NRF52_PAN_15", "NRF52_PAN_58", "NRF52_PAN_55", "NRF52_PAN_54", "NRF52_PAN_31", "NRF52_PAN_30", "NRF52_PAN_51", "NRF52_PAN_36", "NRF52_PAN_53", "S132", "CONFIG_GPIO_AS_PINRESET", "BLE_STACK_SUPPORT_REQD", "SWI_DISABLE0", "NRF52_PAN_20", "NRF52_PAN_64", "NRF52_PAN_62", "NRF52_PAN_63"],
3064-
"device_has": ["ANALOGIN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
3065+
"device_has_had": ["ANALOGIN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
30653066
"release_versions": ["2", "5"],
30663067
"overrides": {"lf_clock_src": "NRF_LF_SRC_RC"},
30673068
"config": {

tools/targets/lint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def check_inherits(dict):
8282
"LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT",
8383
"PWMOUT", "RTC", "TRNG","SERIAL", "SERIAL_ASYNCH",
8484
"SERIAL_FC", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE",
85-
"STORAGE"]
85+
"STORAGE", "STCLK_OFF_DURING_SLEEP"]
8686
def check_device_has(dict):
8787
for name in dict.get("device_has", []):
8888
if name not in DEVICE_HAS_ALLOWED:

0 commit comments

Comments
 (0)