You've already forked Core2forAWS-MicroPython
mirror of
https://github.com/m5stack/Core2forAWS-MicroPython.git
synced 2026-05-20 10:30:31 -07:00
cc3200: Rewrite the PRCM RTC functionality methods.
This allows to use the On-Chip retention registers for both the RTC and to share notification flags between the bootloader and the application. The two flags being shared right now are the "safe boot" request and the WDT reset cause. we still have 2 more bits free for future use.
This commit is contained in:
@@ -148,7 +148,7 @@ static void bootmgr_board_init(void) {
|
||||
// Mandatory MCU Initialization
|
||||
PRCMCC3200MCUInit();
|
||||
|
||||
mperror_check_reset_cause();
|
||||
mperror_bootloader_check_reset_cause();
|
||||
|
||||
// Enable the Data Hashing Engine
|
||||
HASH_Init();
|
||||
@@ -156,9 +156,8 @@ static void bootmgr_board_init(void) {
|
||||
// Init the system led and the system switch
|
||||
mperror_init0();
|
||||
|
||||
// clear the safe boot request, since we should not trust
|
||||
// the register's state after reset
|
||||
mperror_clear_safe_boot();
|
||||
// clear the safe boot flag, since we can't trust its content after reset
|
||||
PRCMClearSafeBootRequest();
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
@@ -266,7 +265,7 @@ static void bootmgr_image_loader(sBootInfo_t *psBootInfo) {
|
||||
// turn the led off
|
||||
MAP_GPIOPinWrite(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN, 0);
|
||||
// request a safe boot to the application
|
||||
mperror_request_safe_boot();
|
||||
PRCMRequestSafeBoot();
|
||||
}
|
||||
// do we have a new update image that needs to be verified?
|
||||
else if ((psBootInfo->ActiveImg == IMG_ACT_UPDATE) && (psBootInfo->Status == IMG_STATUS_CHECK)) {
|
||||
|
||||
+200
-124
File diff suppressed because it is too large
Load Diff
@@ -197,6 +197,12 @@ unsigned char ulRstReg;
|
||||
// API Function prototypes
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern void PRCMRequestSafeBoot(void);
|
||||
extern void PRCMClearSafeBootRequest(void);
|
||||
extern tBoolean PRCMIsSafeBootRequested(void);
|
||||
extern void PRCMSignalWDTReset(void);
|
||||
extern void PRCMClearWDTResetSignal(void);
|
||||
extern tBoolean PRCMWasResetBecauseOfWDT(void);
|
||||
extern void PRCMSOCReset(void);
|
||||
extern void PRCMMCUReset(tBoolean bIncludeSubsystem);
|
||||
extern unsigned long PRCMSysResetCauseGet(void);
|
||||
@@ -250,6 +256,7 @@ extern void PRCMIntEnable(unsigned long ulIntFlags);
|
||||
extern void PRCMIntDisable(unsigned long ulIntFlags);
|
||||
extern unsigned long PRCMIntStatus(void);
|
||||
extern void PRCMRTCInUseSet(void);
|
||||
extern void PRCMRTCInUseClear(void);
|
||||
extern tBoolean PRCMRTCInUseGet(void);
|
||||
extern void PRCMRTCSet(unsigned long ulSecs, unsigned short usMsec);
|
||||
extern void PRCMRTCGet(unsigned long *ulSecs, unsigned short *usMsec);
|
||||
|
||||
@@ -46,7 +46,6 @@
|
||||
#undef ROM_IntEnable
|
||||
#undef ROM_IntDisable
|
||||
#undef ROM_IntPendSet
|
||||
#undef ROM_PRCMHibernateWakeUpGPIOSelect
|
||||
#undef ROM_SDHostCardErrorMaskSet
|
||||
#undef ROM_SDHostCardErrorMaskGet
|
||||
#undef ROM_TimerConfigure
|
||||
|
||||
+5
-18
@@ -56,8 +56,6 @@
|
||||
#define MPERROR_HEARTBEAT_ON_MS (80)
|
||||
#define MPERROR_HEARTBEAT_OFF_MS (4920)
|
||||
|
||||
#define MPERROR_SAFE_BOOT_REG_IDX (0)
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE DATA
|
||||
******************************************************************************/
|
||||
@@ -102,7 +100,7 @@ void mperror_init0 (void) {
|
||||
mperror_heart_beat.beating = false;
|
||||
}
|
||||
|
||||
void mperror_check_reset_cause (void) {
|
||||
void mperror_bootloader_check_reset_cause (void) {
|
||||
// if we are recovering from a WDT reset, trigger
|
||||
// a hibernate cycle for a clean boot
|
||||
if (MAP_PRCMSysResetCauseGet() == PRCM_WDT_RESET) {
|
||||
@@ -115,6 +113,10 @@ void mperror_check_reset_cause (void) {
|
||||
UtilsDelay(800);
|
||||
HWREG(0x4402F024) &= 0xF7FFFFFF;
|
||||
|
||||
// since the reset cause will be changed, we must store the right reason
|
||||
// so that the application knows we booting the next time
|
||||
PRCMSignalWDTReset();
|
||||
|
||||
MAP_PRCMHibernateWakeupSourceEnable(PRCM_HIB_SLOW_CLK_CTR);
|
||||
// set the sleep interval to 10ms
|
||||
MAP_PRCMHibernateIntervalSet(330);
|
||||
@@ -136,21 +138,6 @@ void mperror_signal_error (void) {
|
||||
}
|
||||
}
|
||||
|
||||
void mperror_request_safe_boot (void) {
|
||||
MAP_PRCMOCRRegisterWrite(MPERROR_SAFE_BOOT_REG_IDX, 1);
|
||||
}
|
||||
|
||||
void mperror_clear_safe_boot (void) {
|
||||
MAP_PRCMOCRRegisterWrite(MPERROR_SAFE_BOOT_REG_IDX, 0);
|
||||
}
|
||||
|
||||
// returns the last state of the safe boot request and clears the register
|
||||
bool mperror_safe_boot_requested (void) {
|
||||
bool ret = MAP_PRCMOCRRegisterRead(MPERROR_SAFE_BOOT_REG_IDX);
|
||||
mperror_clear_safe_boot();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void mperror_enable_heartbeat (void) {
|
||||
mperror_heart_beat.enabled = true;
|
||||
}
|
||||
|
||||
@@ -35,12 +35,9 @@ extern const mp_obj_base_t pyb_heartbeat_obj;
|
||||
extern void NORETURN __fatal_error(const char *msg);
|
||||
|
||||
void mperror_init0 (void);
|
||||
void mperror_check_reset_cause (void);
|
||||
void mperror_bootloader_check_reset_cause (void);
|
||||
void mperror_deinit_sfe_pin (void);
|
||||
void mperror_signal_error (void);
|
||||
void mperror_request_safe_boot (void);
|
||||
void mperror_clear_safe_boot (void);
|
||||
bool mperror_safe_boot_requested (void);
|
||||
void mperror_enable_heartbeat (void);
|
||||
void mperror_disable_heartbeat (void);
|
||||
void mperror_heartbeat_signal (void);
|
||||
|
||||
@@ -278,7 +278,7 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
|
||||
#endif
|
||||
|
||||
#if MICROPY_HW_ENABLE_RTC
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_RTC), (mp_obj_t)&pyb_rtc_type },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_RTC), (mp_obj_t)&pyb_rtc_obj },
|
||||
#endif
|
||||
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_Pin), (mp_obj_t)&pin_type },
|
||||
|
||||
@@ -911,7 +911,7 @@ STATIC mp_obj_t wlan_scan(mp_obj_t self_in) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_scan_obj, wlan_scan);
|
||||
|
||||
/// \method callback(method, intmode, value, priority, pwrmode)
|
||||
/// \method callback(handler, intmode, value, priority, pwrmode)
|
||||
/// Creates a callback object associated with WLAN
|
||||
/// min num of arguments is 1 (pwrmode)
|
||||
STATIC mp_obj_t wlan_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
|
||||
+88
-21
@@ -38,6 +38,8 @@
|
||||
#include "rom_map.h"
|
||||
#include "prcm.h"
|
||||
#include "pybrtc.h"
|
||||
#include "pybsleep.h"
|
||||
#include "mpcallback.h"
|
||||
|
||||
/// \moduleref pyb
|
||||
/// \class RTC - real time clock
|
||||
@@ -51,6 +53,25 @@
|
||||
/// rtc.datetime((2014, 5, 1, 4, 13, 0, 0, 0))
|
||||
/// print(rtc.datetime())
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE TYPES
|
||||
******************************************************************************/
|
||||
typedef struct {
|
||||
mp_obj_t callback;
|
||||
uint32_t alarm_sec;
|
||||
uint16_t alarm_msec;
|
||||
uint8_t pwrmode;
|
||||
} pybrtc_data_t;
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE DATA
|
||||
******************************************************************************/
|
||||
STATIC pybrtc_data_t pybrtc_data = {.callback = mp_const_none};
|
||||
STATIC const mp_cb_methods_t pybrtc_cb_methods;
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PUBLIC FUNCTIONS
|
||||
******************************************************************************/
|
||||
__attribute__ ((section (".boot")))
|
||||
void pybrtc_init(void) {
|
||||
// if the RTC was previously set, leave it alone
|
||||
@@ -60,32 +81,28 @@ void pybrtc_init(void) {
|
||||
// set the time to 00:00:00
|
||||
uint32_t seconds = mod_time_seconds_since_2000(2015, 1, 1, 0, 0, 0);
|
||||
|
||||
MAP_PRCMRTCSet(seconds, 0);
|
||||
|
||||
// Mark the RTC in use
|
||||
// Mark the RTC in use first
|
||||
MAP_PRCMRTCInUseSet();
|
||||
|
||||
// Now set the RTC calendar seconds
|
||||
MAP_PRCMRTCSet(seconds, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC void pyb_rtc_callback_enable (mp_obj_t self_in) {
|
||||
|
||||
}
|
||||
|
||||
STATIC void pyb_rtc_callback_disable (mp_obj_t self_in) {
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// Micro Python bindings
|
||||
|
||||
typedef struct _pyb_rtc_obj_t {
|
||||
mp_obj_base_t base;
|
||||
} pyb_rtc_obj_t;
|
||||
|
||||
STATIC const pyb_rtc_obj_t pyb_rtc_obj = {{&pyb_rtc_type}};
|
||||
|
||||
/// \classmethod \constructor()
|
||||
/// Create an RTC object.
|
||||
STATIC mp_obj_t pyb_rtc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
|
||||
// return constant object
|
||||
return (mp_obj_t)&pyb_rtc_obj;
|
||||
}
|
||||
|
||||
/// \method datetime([datetimetuple])
|
||||
/// Get or set the date and time of the RTC.
|
||||
///
|
||||
@@ -144,14 +161,64 @@ mp_obj_t pyb_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_datetime_obj, 1, 2, pyb_rtc_datetime);
|
||||
|
||||
/// \method callback(handler, intmode, value, priority, pwrmode)
|
||||
/// Creates a callback object associated with the real time clock
|
||||
/// min num of arguments is 1 (value). The value is the alarm time
|
||||
/// in the future, in msec
|
||||
STATIC mp_obj_t pyb_rtc_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_arg_val_t args[mpcallback_INIT_NUM_ARGS];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mpcallback_INIT_NUM_ARGS, mpcallback_init_args, args);
|
||||
|
||||
// check if any parameters were passed
|
||||
if (kw_args->used > 0 || pybrtc_data.callback == mp_const_none) {
|
||||
uint32_t seconds;
|
||||
uint16_t mseconds;
|
||||
// get the seconds and the milliseconds from the RTC
|
||||
MAP_PRCMRTCGet(&seconds, &mseconds);
|
||||
mseconds = RTC_CYCLES_U16MS(mseconds);
|
||||
|
||||
// configure the rtc alarm accordingly
|
||||
seconds += args[3].u_int / 1000;
|
||||
mseconds += args[3].u_int - ((args[3].u_int / 1000) * 1000);
|
||||
if (mseconds > 1000) {
|
||||
seconds++;
|
||||
mseconds -= 1000;
|
||||
}
|
||||
|
||||
// check the wake from param
|
||||
if (args[4].u_int & PYB_PWR_MODE_ACTIVE) {
|
||||
MAP_PRCMRTCMatchSet(seconds, mseconds);
|
||||
}
|
||||
|
||||
// save the alarm config for later
|
||||
pybrtc_data.alarm_sec = seconds;
|
||||
pybrtc_data.alarm_msec = mseconds;
|
||||
pybrtc_data.pwrmode = args[4].u_int;
|
||||
|
||||
// create the callback
|
||||
pybrtc_data.callback = mpcallback_new ((mp_obj_t)&pyb_rtc_obj, args[1].u_obj, &pybrtc_cb_methods);
|
||||
}
|
||||
|
||||
return pybrtc_data.callback;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_callback_obj, 1, pyb_rtc_callback);
|
||||
|
||||
STATIC const mp_map_elem_t pyb_rtc_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_datetime), (mp_obj_t)&pyb_rtc_datetime_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_callback), (mp_obj_t)&pyb_rtc_callback_obj },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t pyb_rtc_type = {
|
||||
STATIC const mp_obj_type_t pyb_rtc_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_RTC,
|
||||
.make_new = pyb_rtc_make_new,
|
||||
.locals_dict = (mp_obj_t)&pyb_rtc_locals_dict,
|
||||
};
|
||||
|
||||
STATIC const mp_cb_methods_t pybrtc_cb_methods = {
|
||||
.init = pyb_rtc_callback,
|
||||
.enable = pyb_rtc_callback_enable,
|
||||
.disable = pyb_rtc_callback_disable,
|
||||
};
|
||||
|
||||
const mp_obj_base_t pyb_rtc_obj = {&pyb_rtc_type};
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#define RTC_U16MS_CYCLES(msec) ((msec * 1024) / 1000)
|
||||
#define RTC_CYCLES_U16MS(cycles) ((cycles * 1000) / 1024)
|
||||
|
||||
extern const mp_obj_type_t pyb_rtc_type;
|
||||
extern const mp_obj_base_t pyb_rtc_obj;
|
||||
|
||||
void pybrtc_init(void);
|
||||
|
||||
|
||||
+88
-29
@@ -61,6 +61,12 @@
|
||||
#define SPIFLASH_INSTR_DEEP_POWER_DOWN (0xB9)
|
||||
#define SPIFLASH_STATUS_BUSY (0x01)
|
||||
|
||||
#define LPDS_UP_TIME (425) // 13 msec
|
||||
#define LPDS_DOWN_TIME (98) // 3 msec
|
||||
#define USER_OFFSET (131) // 4 smec
|
||||
#define WAKEUP_TIME_LPDS (LPDS_UP_TIME + LPDS_DOWN_TIME + USER_OFFSET) // 20 msec
|
||||
#define WAKEUP_TIME_HIB (32768) // 1 s
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE TYPES
|
||||
******************************************************************************/
|
||||
@@ -101,9 +107,9 @@ typedef struct {
|
||||
} pybsleep_obj_t;
|
||||
|
||||
typedef struct {
|
||||
mp_obj_t wlan_wake_cb;
|
||||
mp_obj_t timer_wake_cb;
|
||||
mp_obj_t gpio_wake_cb;
|
||||
mp_obj_t wlan_lpds_wake_cb;
|
||||
mp_obj_t timer_lpds_wake_cb;
|
||||
mp_obj_t gpio_lpds_wake_cb;
|
||||
} pybsleep_wake_cb_t;
|
||||
|
||||
/******************************************************************************
|
||||
@@ -113,6 +119,7 @@ STATIC const mp_obj_type_t pybsleep_type;
|
||||
STATIC nvic_reg_store_t *nvic_reg_store;
|
||||
STATIC pybsleep_wake_cb_t pybsleep_wake_cb;
|
||||
volatile arm_cm4_core_regs_t vault_arm_registers;
|
||||
STATIC pybsleep_reset_cause_t pybsleep_reset_cause = PYB_SLP_PWRON_RESET;
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE FUNCTIONS
|
||||
@@ -128,17 +135,49 @@ STATIC void pybsleep_iopark (void);
|
||||
/******************************************************************************
|
||||
DEFINE PUBLIC FUNCTIONS
|
||||
******************************************************************************/
|
||||
void pyblsleep_init0 (void) {
|
||||
__attribute__ ((section (".boot")))
|
||||
void pybsleep_pre_init (void) {
|
||||
// allocate memory for nvic registers vault
|
||||
ASSERT ((nvic_reg_store = mem_Malloc(sizeof(nvic_reg_store_t))) != NULL);
|
||||
}
|
||||
|
||||
void pybsleep_init0 (void) {
|
||||
// initialize the sleep objects list
|
||||
mp_obj_list_init(&MP_STATE_PORT(pybsleep_obj_list), 0);
|
||||
|
||||
// allocate memory for nvic registers vault
|
||||
ASSERT ((nvic_reg_store = mem_Malloc(sizeof(nvic_reg_store_t))) != NULL);
|
||||
|
||||
// enable and register the PRCM interrupt
|
||||
// register and enable the PRCM interrupt
|
||||
osi_InterruptRegister(INT_PRCM, (P_OSI_INTR_ENTRY)PRCMInterruptHandler, INT_PRIORITY_LVL_1);
|
||||
MAP_IntPendClear(INT_PRCM);
|
||||
MAP_PRCMIntEnable(PRCM_INT_SLOW_CLK_CTR);
|
||||
|
||||
// store the reset casue (if it's soft reset, leave it as it is)
|
||||
if (pybsleep_reset_cause != PYB_SLP_SOFT_RESET) {
|
||||
switch (MAP_PRCMSysResetCauseGet()) {
|
||||
case PRCM_POWER_ON:
|
||||
pybsleep_reset_cause = PYB_SLP_PWRON_RESET;
|
||||
break;
|
||||
case PRCM_CORE_RESET:
|
||||
case PRCM_MCU_RESET:
|
||||
case PRCM_SOC_RESET:
|
||||
pybsleep_reset_cause = PYB_SLP_HARD_RESET;
|
||||
break;
|
||||
case PRCM_WDT_RESET:
|
||||
pybsleep_reset_cause = PYB_SLP_WDT_RESET;
|
||||
break;
|
||||
case PRCM_HIB_EXIT:
|
||||
if (PRCMWasResetBecauseOfWDT()) {
|
||||
pybsleep_reset_cause = PYB_SLP_WDT_RESET;
|
||||
}
|
||||
else {
|
||||
pybsleep_reset_cause = PYB_SLP_HIB_RESET;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pybsleep_signal_soft_reset (void) {
|
||||
pybsleep_reset_cause = PYB_SLP_SOFT_RESET;
|
||||
}
|
||||
|
||||
void pybsleep_add (const mp_obj_t obj, WakeUpCB_t wakeup) {
|
||||
@@ -160,15 +199,15 @@ void pybsleep_remove (const mp_obj_t obj) {
|
||||
}
|
||||
|
||||
void pybsleep_set_wlan_lpds_callback (mp_obj_t cb_obj) {
|
||||
pybsleep_wake_cb.wlan_wake_cb = cb_obj;
|
||||
pybsleep_wake_cb.wlan_lpds_wake_cb = cb_obj;
|
||||
}
|
||||
|
||||
void pybsleep_set_gpio_lpds_callback (mp_obj_t cb_obj) {
|
||||
pybsleep_wake_cb.gpio_wake_cb = cb_obj;
|
||||
pybsleep_wake_cb.gpio_lpds_wake_cb = cb_obj;
|
||||
}
|
||||
|
||||
void pybsleep_set_timer_lpds_callback (mp_obj_t cb_obj) {
|
||||
pybsleep_wake_cb.timer_wake_cb = cb_obj;
|
||||
pybsleep_wake_cb.timer_lpds_wake_cb = cb_obj;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@@ -341,31 +380,27 @@ void pybsleep_suspend_exit (void) {
|
||||
STATIC void PRCMInterruptHandler (void) {
|
||||
// reading the interrupt status automatically clears the interrupt
|
||||
if (PRCM_INT_SLOW_CLK_CTR == MAP_PRCMIntStatus()) {
|
||||
if (pybsleep_wake_cb.timer_wake_cb) {
|
||||
mpcallback_handler(pybsleep_wake_cb.timer_wake_cb);
|
||||
// this interrupt is triggered during active mode
|
||||
if (pybsleep_wake_cb.timer_lpds_wake_cb) {
|
||||
mpcallback_handler(pybsleep_wake_cb.timer_lpds_wake_cb);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// interrupt has been triggered while waking up from LPDS
|
||||
switch (MAP_PRCMLPDSWakeupCauseGet()) {
|
||||
case PRCM_LPDS_HOST_IRQ:
|
||||
if (pybsleep_wake_cb.wlan_wake_cb) {
|
||||
mpcallback_handler(pybsleep_wake_cb.wlan_wake_cb);
|
||||
if (pybsleep_wake_cb.wlan_lpds_wake_cb) {
|
||||
mpcallback_handler(pybsleep_wake_cb.wlan_lpds_wake_cb);
|
||||
}
|
||||
break;
|
||||
case PRCM_LPDS_GPIO:
|
||||
if (pybsleep_wake_cb.gpio_wake_cb) {
|
||||
mpcallback_handler(pybsleep_wake_cb.gpio_wake_cb);
|
||||
if (pybsleep_wake_cb.gpio_lpds_wake_cb) {
|
||||
mpcallback_handler(pybsleep_wake_cb.gpio_lpds_wake_cb);
|
||||
}
|
||||
// clear all pending GPIO interrupts in order to
|
||||
// avoid duplicated calls to the handler
|
||||
MAP_IntPendClear(INT_GPIOA0);
|
||||
MAP_IntPendClear(INT_GPIOA1);
|
||||
MAP_IntPendClear(INT_GPIOA2);
|
||||
MAP_IntPendClear(INT_GPIOA3);
|
||||
break;
|
||||
case PRCM_LPDS_TIMER:
|
||||
if (pybsleep_wake_cb.timer_wake_cb) {
|
||||
mpcallback_handler(pybsleep_wake_cb.timer_wake_cb);
|
||||
if (pybsleep_wake_cb.timer_lpds_wake_cb) {
|
||||
mpcallback_handler(pybsleep_wake_cb.timer_lpds_wake_cb);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -443,7 +478,7 @@ STATIC mp_obj_t pyb_sleep_suspend (mp_obj_t self_in) {
|
||||
nlr_buf_t nlr;
|
||||
|
||||
// check if we need to enable network wake-up
|
||||
if (pybsleep_wake_cb.wlan_wake_cb) {
|
||||
if (pybsleep_wake_cb.wlan_lpds_wake_cb) {
|
||||
MAP_PRCMLPDSWakeupSourceEnable (PRCM_LPDS_HOST_IRQ);
|
||||
}
|
||||
else {
|
||||
@@ -466,7 +501,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_sleep_suspend_obj, pyb_sleep_suspend);
|
||||
|
||||
/// \function hibernate()
|
||||
/// Enters hibernate mode. Wake up sources should have been enable prior to
|
||||
// calling this method.
|
||||
/// calling this method.
|
||||
STATIC mp_obj_t pyb_sleep_hibernate (mp_obj_t self_in) {
|
||||
wlan_stop();
|
||||
pybsleep_flash_powerdown();
|
||||
@@ -475,16 +510,40 @@ STATIC mp_obj_t pyb_sleep_hibernate (mp_obj_t self_in) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_sleep_hibernate_obj, pyb_sleep_hibernate);
|
||||
|
||||
/// \function reset_cause()
|
||||
/// Returns the last reset casue
|
||||
STATIC mp_obj_t pyb_sleep_reset_cause (mp_obj_t self_in) {
|
||||
return MP_OBJ_NEW_SMALL_INT(pybsleep_reset_cause);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_sleep_reset_cause_obj, pyb_sleep_reset_cause);
|
||||
|
||||
/// \function wake_reason()
|
||||
/// Returns the wake up reson from ldps or hibernate
|
||||
STATIC mp_obj_t pyb_sleep_wake_reason (mp_obj_t self_in) {
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_sleep_wake_reason_obj, pyb_sleep_wake_reason);
|
||||
|
||||
STATIC const mp_map_elem_t pybsleep_locals_dict_table[] = {
|
||||
// instance methods
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_idle), (mp_obj_t)&pyb_sleep_idle_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_suspend), (mp_obj_t)&pyb_sleep_suspend_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_hibernate), (mp_obj_t)&pyb_sleep_hibernate_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_reset_cause), (mp_obj_t)&pyb_sleep_reset_cause_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_wake_reason), (mp_obj_t)&pyb_sleep_wake_reason_obj },
|
||||
|
||||
// class constants
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_ACTIVE), MP_OBJ_NEW_SMALL_INT(PYB_PWR_MODE_ACTIVE) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_SUSPENDED), MP_OBJ_NEW_SMALL_INT(PYB_PWR_MODE_LPDS) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_HIBERNATING), MP_OBJ_NEW_SMALL_INT(PYB_PWR_MODE_HIBERNATE) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_PWR_ON_RESET), MP_OBJ_NEW_SMALL_INT(PYB_SLP_PWRON_RESET) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_HARD_RESET), MP_OBJ_NEW_SMALL_INT(PYB_SLP_HARD_RESET) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_WDT_RESET), MP_OBJ_NEW_SMALL_INT(PYB_SLP_WDT_RESET) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_HIB_RESET), MP_OBJ_NEW_SMALL_INT(PYB_SLP_HIB_RESET) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_SOFT_RESET), MP_OBJ_NEW_SMALL_INT(PYB_SLP_SOFT_RESET) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_WLAN_WAKE), MP_OBJ_NEW_SMALL_INT(PYB_SLP_WAKED_BY_WLAN) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_PIN_WAKE), MP_OBJ_NEW_SMALL_INT(PYB_SLP_WAKED_BY_PIN) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_RTC_WAKE), MP_OBJ_NEW_SMALL_INT(PYB_SLP_WAKED_BY_RTC) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pybsleep_locals_dict, pybsleep_locals_dict_table);
|
||||
|
||||
+19
-1
@@ -37,6 +37,22 @@
|
||||
/******************************************************************************
|
||||
DEFINE TYPES
|
||||
******************************************************************************/
|
||||
typedef enum {
|
||||
PYB_SLP_PWRON_RESET = 0,
|
||||
PYB_SLP_HARD_RESET,
|
||||
PYB_SLP_WDT_RESET,
|
||||
PYB_SLP_HIB_RESET,
|
||||
PYB_SLP_SOFT_RESET,
|
||||
|
||||
} pybsleep_reset_cause_t;
|
||||
|
||||
typedef enum {
|
||||
PYB_SLP_WAKED_BY_WLAN,
|
||||
PYB_SLP_WAKED_BY_PIN,
|
||||
PYB_SLP_WAKED_BY_RTC
|
||||
|
||||
} pybsleep_wake_reason_t;
|
||||
|
||||
typedef void (*WakeUpCB_t)(const mp_obj_t self);
|
||||
|
||||
/******************************************************************************
|
||||
@@ -47,7 +63,9 @@ extern const mp_obj_base_t pyb_sleep_obj;
|
||||
/******************************************************************************
|
||||
DECLARE FUNCTIONS
|
||||
******************************************************************************/
|
||||
void pyblsleep_init0 (void);
|
||||
void pybsleep_pre_init (void);
|
||||
void pybsleep_init0 (void);
|
||||
void pybsleep_signal_soft_reset (void);
|
||||
void pybsleep_add (const mp_obj_t obj, WakeUpCB_t wakeup);
|
||||
void pybsleep_remove (const mp_obj_t obj);
|
||||
void pybsleep_set_wlan_lpds_callback (mp_obj_t cb_obj);
|
||||
|
||||
+6
-2
@@ -121,7 +121,7 @@ soft_reset:
|
||||
mperror_init0();
|
||||
mpexception_init0();
|
||||
mpcallback_init0();
|
||||
pyblsleep_init0();
|
||||
pybsleep_init0();
|
||||
uart_init0();
|
||||
pin_init0();
|
||||
readline_init0();
|
||||
@@ -149,7 +149,7 @@ soft_reset:
|
||||
mptask_enter_ap_mode();
|
||||
// don't check for safeboot when comming out of hibernate
|
||||
#ifndef DEBUG
|
||||
safeboot = mperror_safe_boot_requested();
|
||||
safeboot = PRCMIsSafeBootRequested();
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
@@ -233,6 +233,7 @@ soft_reset:
|
||||
soft_reset_exit:
|
||||
|
||||
// soft reset
|
||||
pybsleep_signal_soft_reset();
|
||||
|
||||
sflash_disk_flush();
|
||||
|
||||
@@ -269,6 +270,9 @@ STATIC void mptask_pre_init (void) {
|
||||
// Allocate memory for the flash file system
|
||||
ASSERT ((sflash_fatfs = mem_Malloc(sizeof(FATFS))) != NULL);
|
||||
|
||||
// this one allocates memory for the nvic vault
|
||||
pybsleep_pre_init();
|
||||
|
||||
#if MICROPY_HW_HAS_SDCARD
|
||||
pybsd_init0();
|
||||
#endif
|
||||
|
||||
@@ -251,6 +251,17 @@ Q(Sleep)
|
||||
Q(idle)
|
||||
Q(suspend)
|
||||
Q(hibernate)
|
||||
Q(reset_cause)
|
||||
Q(wake_reason)
|
||||
Q(ACTIVE)
|
||||
Q(SUSPENDED)
|
||||
Q(HIBERNATING)
|
||||
Q(PWR_ON_RESET)
|
||||
Q(HARD_RESET)
|
||||
Q(WDT_RESET)
|
||||
Q(HIB_RESET)
|
||||
Q(SOFT_RESET)
|
||||
Q(WLAN_WAKE)
|
||||
Q(PIN_WAKE)
|
||||
Q(RTC_WAKE)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user