mimxrt/modmachine: Add support for machine.deepsleep.
Signed-off-by: "Kwabena W. Agyeman" <kwagyeman@live.com>
This commit is contained in:
parent
433158076f
commit
e78471416b
|
@ -128,6 +128,7 @@ SRC_HAL_IMX_C += \
|
|||
$(MCU_DIR)/drivers/fsl_edma.c \
|
||||
$(MCU_DIR)/drivers/fsl_flexram.c \
|
||||
$(MCU_DIR)/drivers/fsl_flexspi.c \
|
||||
$(MCU_DIR)/drivers/fsl_gpc.c \
|
||||
$(MCU_DIR)/drivers/fsl_gpio.c \
|
||||
$(MCU_DIR)/drivers/fsl_gpt.c \
|
||||
$(MCU_DIR)/drivers/fsl_lpi2c.c \
|
||||
|
|
|
@ -50,7 +50,11 @@ void machine_rtc_alarm_set_en() {
|
|||
|
||||
void machine_rtc_alarm_off(bool clear) {
|
||||
machine_rtc_alarm_clear_en();
|
||||
#ifdef MIMXRT117x_SERIES
|
||||
DisableIRQ(SNVS_HP_NON_TZ_IRQn);
|
||||
#else
|
||||
DisableIRQ(SNVS_HP_WRAPPER_IRQn);
|
||||
#endif
|
||||
|
||||
if (clear) {
|
||||
SNVS->LPTAR = 0;
|
||||
|
@ -60,7 +64,11 @@ void machine_rtc_alarm_off(bool clear) {
|
|||
}
|
||||
|
||||
void machine_rtc_alarm_on() {
|
||||
#ifdef MIMXRT117x_SERIES
|
||||
EnableIRQ(SNVS_HP_NON_TZ_IRQn);
|
||||
#else
|
||||
EnableIRQ(SNVS_HP_WRAPPER_IRQn);
|
||||
#endif
|
||||
machine_rtc_alarm_set_en();
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,12 @@
|
|||
#include "led.h"
|
||||
#include "pin.h"
|
||||
#include "modmachine.h"
|
||||
#include "fsl_gpc.h"
|
||||
#ifdef MIMXRT117x_SERIES
|
||||
#include "fsl_soc_src.h"
|
||||
#else
|
||||
#include "fsl_src.h"
|
||||
#endif
|
||||
#include "fsl_wdog.h"
|
||||
#if FSL_FEATURE_BOOT_ROM_HAS_ROMAPI
|
||||
#include "fsl_romapi.h"
|
||||
|
@ -74,6 +80,14 @@ STATIC mp_obj_t machine_reset(void) {
|
|||
MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
|
||||
|
||||
STATIC mp_obj_t machine_reset_cause(void) {
|
||||
#ifdef MIMXRT117x_SERIES
|
||||
uint32_t user_reset_flag = kSRC_M7CoreIppUserResetFlag;
|
||||
#else
|
||||
uint32_t user_reset_flag = kSRC_IppUserResetFlag;
|
||||
#endif
|
||||
if (SRC->SRSR & user_reset_flag) {
|
||||
return MP_OBJ_NEW_SMALL_INT(MP_DEEPSLEEP_RESET);
|
||||
}
|
||||
uint16_t reset_cause =
|
||||
WDOG_GetStatusFlags(WDOG1) & (kWDOG_PowerOnResetFlag | kWDOG_TimeoutResetFlag | kWDOG_SoftwareResetFlag);
|
||||
if (reset_cause == kWDOG_PowerOnResetFlag) {
|
||||
|
@ -98,6 +112,37 @@ STATIC mp_obj_t machine_idle(void) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle);
|
||||
|
||||
STATIC mp_obj_t 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) {
|
||||
machine_rtc_alarm_helper(seconds, false);
|
||||
#ifdef MIMXRT117x_SERIES
|
||||
GPC_CM_EnableIrqWakeup(GPC_CPU_MODE_CTRL_0, SNVS_HP_NON_TZ_IRQn, true);
|
||||
#else
|
||||
GPC_EnableIRQ(GPC, SNVS_HP_WRAPPER_IRQn);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MIMXRT117x_SERIES
|
||||
machine_pin_config(&pin_WAKEUP_DIG, PIN_MODE_IT_RISING, PIN_PULL_DISABLED, PIN_DRIVE_OFF, 0, PIN_AF_MODE_ALT5);
|
||||
GPC_CM_EnableIrqWakeup(GPC_CPU_MODE_CTRL_0, GPIO13_Combined_0_31_IRQn, true);
|
||||
#elif defined IOMUXC_SNVS_WAKEUP_GPIO5_IO00
|
||||
machine_pin_config(&pin_WAKEUP, PIN_MODE_IT_RISING, PIN_PULL_DISABLED, PIN_DRIVE_OFF, 0, PIN_AF_MODE_ALT5);
|
||||
GPC_EnableIRQ(GPC, GPIO5_Combined_0_15_IRQn);
|
||||
#endif
|
||||
|
||||
SNVS->LPCR |= SNVS_LPCR_TOP_MASK;
|
||||
|
||||
while (true) {
|
||||
;
|
||||
}
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_deepsleep_obj, 0, 1, machine_deepsleep);
|
||||
|
||||
STATIC mp_obj_t machine_disable_irq(void) {
|
||||
uint32_t state = MICROPY_BEGIN_ATOMIC_SECTION();
|
||||
return mp_obj_new_int(state);
|
||||
|
@ -162,6 +207,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
|
|||
{ MP_ROM_QSTR(MP_QSTR_WDT), MP_ROM_PTR(&machine_wdt_type) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_idle), MP_ROM_PTR(&machine_idle_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&machine_deepsleep_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) },
|
||||
|
|
|
@ -51,7 +51,7 @@ void mimxrt_sdram_init(void);
|
|||
void machine_i2s_init0();
|
||||
void machine_i2s_deinit_all(void);
|
||||
void machine_rtc_start(void);
|
||||
|
||||
void machine_rtc_alarm_helper(int seconds, bool repeat);
|
||||
void machine_uart_set_baudrate(mp_obj_t uart, uint32_t baudrate);
|
||||
|
||||
#endif // MICROPY_INCLUDED_MIMXRT_MODMACHINE_H
|
||||
|
|
Loading…
Reference in New Issue