kopia lustrzana https://github.com/micropython/micropython
ports/modmachine: Set a minimum delay time for lightsleep/deepsleep.
rp2: enforce a minimal delay time of 1 ms, if supplied. samd: return immediately if the delay value is <= 0. mimxrt: set the delay to 1000 if a smaller value is supplied. This behaviour matches the other ports, which return fast for a too small or negative delay value. Signed-off-by: robert-hh <robert@hammelrath.com>pull/13145/head
rodzic
b3c62f3169
commit
5ac719cc01
|
@ -44,6 +44,8 @@
|
|||
|
||||
#include CPU_HEADER_H
|
||||
|
||||
#define MIMXRT_DEEPSLEEP_MIN (1)
|
||||
|
||||
#if defined(MICROPY_HW_LED1_PIN)
|
||||
#define MICROPY_PY_MACHINE_LED_ENTRY { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&machine_led_type) },
|
||||
#else
|
||||
|
@ -129,7 +131,9 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
|||
NORETURN static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_args != 0) {
|
||||
mp_int_t seconds = mp_obj_get_int(args[0]) / 1000;
|
||||
if (seconds > 0) {
|
||||
if (seconds < MIMXRT_DEEPSLEEP_MIN) {
|
||||
seconds = MIMXRT_DEEPSLEEP_MIN;
|
||||
}
|
||||
machine_rtc_alarm_helper(seconds, false);
|
||||
#ifdef MIMXRT117x_SERIES
|
||||
GPC_CM_EnableIrqWakeup(GPC_CPU_MODE_CTRL_0, SNVS_HP_NON_TZ_IRQn, true);
|
||||
|
@ -137,7 +141,6 @@ NORETURN static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
|||
GPC_EnableIRQ(GPC, SNVS_HP_WRAPPER_IRQn);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(MIMXRT117x_SERIES)
|
||||
machine_pin_config(pin_WAKEUP_DIG, PIN_MODE_IT_RISING, PIN_PULL_DISABLED, PIN_DRIVE_OFF, 0, PIN_AF_MODE_ALT5);
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
|
||||
#define RP2_RESET_PWRON (1)
|
||||
#define RP2_RESET_WDT (3)
|
||||
#define RP2_LIGHTSLEEP_MIN (1)
|
||||
|
||||
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
|
||||
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) }, \
|
||||
|
@ -111,9 +112,9 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
|||
|
||||
if (n_args == 1) {
|
||||
delay_ms = mp_obj_get_int(args[0]);
|
||||
if (delay_ms <= 1) {
|
||||
// Sleep is too small, just use standard delay.
|
||||
mp_hal_delay_ms(delay_ms);
|
||||
if (delay_ms <= RP2_LIGHTSLEEP_MIN) {
|
||||
// Sleep time is too small, just use standard delay.
|
||||
mp_hal_delay_ms(RP2_LIGHTSLEEP_MIN);
|
||||
return;
|
||||
}
|
||||
use_timer_alarm = delay_ms < (1ULL << 32) / 1000;
|
||||
|
|
|
@ -117,6 +117,9 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
|||
uint32_t freq = get_cpu_freq();
|
||||
if (n_args > 0) {
|
||||
duration = mp_obj_get_int(args[0]);
|
||||
if (duration <= 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
EIC_occured = false;
|
||||
// Slow down
|
||||
|
@ -130,7 +133,7 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
|||
GCLK->CLKCTRL.reg = GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK3 | EIC_GCLK_ID;
|
||||
if (duration > 0) {
|
||||
uint32_t t0 = systick_ms;
|
||||
while ((systick_ms - t0 < duration) && (EIC_occured == false)) {
|
||||
while (((systick_ms - t0) < duration) && (EIC_occured == false)) {
|
||||
__WFI();
|
||||
}
|
||||
} else {
|
||||
|
|
Ładowanie…
Reference in New Issue