cc3200: Rename pyb module to machine.

This commit is contained in:
Daniel Campora 2015-09-27 13:45:48 +02:00
parent 0a7e4fa5ce
commit c92e6a45eb
35 changed files with 326 additions and 347 deletions

View File

@ -85,10 +85,10 @@ APP_MISC_SRC_C = $(addprefix misc/,\
)
APP_MODS_SRC_C = $(addprefix mods/,\
modmachine.c \
modnetwork.c \
moduhashlib.c \
modubinascii.c \
modpyb.c \
moduos.c \
modusocket.c \
modussl.c \

View File

@ -77,26 +77,23 @@ extern OsiTaskHandle xSimpleLinkSpawnTaskHndl;
#endif
/// \module pyb - functions related to the pyboard
/// \module machine - functions related to the SoC
///
/// The `pyb` module contains specific functions related to the pyboard.
/// \function reset()
/// Resets the pyboard in a manner similar to pushing the external
/// reset button.
STATIC mp_obj_t pyb_reset(void) {
/******************************************************************************/
// Micro Python bindings;
STATIC mp_obj_t machine_reset(void) {
// disable wlan
wlan_stop(SL_STOP_TIMEOUT_LONG);
// reset the cpu and it's peripherals
MAP_PRCMMCUReset(true);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_reset_obj, pyb_reset);
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
#ifdef DEBUG
/// \function info([dump_alloc_table])
/// Print out some run time info which is helpful during development.
STATIC mp_obj_t pyb_info(uint n_args, const mp_obj_t *args) {
STATIC mp_obj_t machine_info(uint n_args, const mp_obj_t *args) {
// FreeRTOS info
{
printf("---------------------------------------------\n");
@ -119,46 +116,74 @@ STATIC mp_obj_t pyb_info(uint n_args, const mp_obj_t *args) {
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_info_obj, 0, 1, pyb_info);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj, 0, 1, machine_info);
#endif
/// \function freq()
/// Returns the CPU frequency: (F_CPU).
STATIC mp_obj_t pyb_freq(void) {
STATIC mp_obj_t machine_freq(void) {
mp_obj_t tuple[1] = {
mp_obj_new_int(HAL_FCPU_HZ),
};
return mp_obj_new_tuple(1, tuple);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_freq_obj, pyb_freq);
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_freq_obj, machine_freq);
/// \function unique_id()
/// Returns a string of 6 bytes (48 bits), which is the unique ID for the MCU.
STATIC mp_obj_t pyb_unique_id(void) {
STATIC mp_obj_t machine_unique_id(void) {
uint8_t mac[SL_BSSID_LENGTH];
wlan_get_mac (mac);
return mp_obj_new_bytes(mac, SL_BSSID_LENGTH);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_unique_id_obj, pyb_unique_id);
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id);
MP_DECLARE_CONST_FUN_OBJ(pyb_main_obj); // defined in main.c
STATIC mp_obj_t machine_idle(void) {
__WFI();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle);
STATIC const mp_map_elem_t pyb_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_pyb) },
STATIC mp_obj_t machine_sleep (void) {
pyb_sleep_sleep();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_sleep_obj, machine_sleep);
{ MP_OBJ_NEW_QSTR(MP_QSTR_reset), (mp_obj_t)&pyb_reset_obj },
STATIC mp_obj_t machine_deepsleep (void) {
pyb_sleep_deepsleep();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_deepsleep_obj, machine_deepsleep);
STATIC mp_obj_t machine_reset_cause (void) {
return mp_obj_new_int(pyb_sleep_get_reset_cause());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause);
STATIC mp_obj_t machine_wake_reason (void) {
return mp_obj_new_int(pyb_sleep_get_wake_reason());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_wake_reason_obj, machine_wake_reason);
MP_DECLARE_CONST_FUN_OBJ(machine_main_obj); // defined in main.c
STATIC const mp_map_elem_t machine_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_machine) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_reset), (mp_obj_t)&machine_reset_obj },
#ifdef DEBUG
{ MP_OBJ_NEW_QSTR(MP_QSTR_info), (mp_obj_t)&pyb_info_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_info), (mp_obj_t)&machine_info_obj },
#endif
{ MP_OBJ_NEW_QSTR(MP_QSTR_freq), (mp_obj_t)&pyb_freq_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_unique_id), (mp_obj_t)&pyb_unique_id_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_freq), (mp_obj_t)&machine_freq_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_unique_id), (mp_obj_t)&machine_unique_id_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_main), (mp_obj_t)&machine_main_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_rng), (mp_obj_t)&machine_rng_get_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_idle), (mp_obj_t)&machine_idle_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_sleep), (mp_obj_t)&machine_sleep_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_deepsleep), (mp_obj_t)&machine_deepsleep_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_reset_cause), (mp_obj_t)&machine_reset_cause_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_wake_reason), (mp_obj_t)&machine_wake_reason_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_disable_irq), (mp_obj_t)&pyb_disable_irq_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable_irq), (mp_obj_t)&pyb_enable_irq_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_main), (mp_obj_t)&pyb_main_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_rng), (mp_obj_t)&pyb_rng_get_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_RTC), (mp_obj_t)&pyb_rtc_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_Pin), (mp_obj_t)&pin_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_ADC), (mp_obj_t)&pyb_adc_type },
@ -167,15 +192,27 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_UART), (mp_obj_t)&pyb_uart_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_Timer), (mp_obj_t)&pyb_timer_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_WDT), (mp_obj_t)&pyb_wdt_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_Sleep), (mp_obj_t)&pyb_sleep_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_HeartBeat), (mp_obj_t)&pyb_heartbeat_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SD), (mp_obj_t)&pyb_sd_type },
// class constants
{ MP_OBJ_NEW_QSTR(MP_QSTR_IDLE), MP_OBJ_NEW_SMALL_INT(PYB_PWR_MODE_ACTIVE) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SLEEP), MP_OBJ_NEW_SMALL_INT(PYB_PWR_MODE_LPDS) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_DEEPSLEEP), MP_OBJ_NEW_SMALL_INT(PYB_PWR_MODE_HIBERNATE) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_POWER_ON), 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_DEEPSLEEP_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_GPIO) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_RTC_WAKE), MP_OBJ_NEW_SMALL_INT(PYB_SLP_WAKED_BY_RTC) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_module_globals, pyb_module_globals_table);
STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table);
const mp_obj_module_t pyb_module = {
const mp_obj_module_t machine_module = {
.base = { &mp_type_module },
.name = MP_QSTR_pyb,
.globals = (mp_obj_dict_t*)&pyb_module_globals,
.name = MP_QSTR_machine,
.globals = (mp_obj_dict_t*)&machine_module_globals,
};

View File

@ -844,7 +844,7 @@ STATIC mp_obj_t wlan_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_k
wlan_init_helper(self, &args[1]);
// pass it to the sleep module
pybsleep_set_wlan_obj(self);
pyb_sleep_set_wlan_obj(self);
return (mp_obj_t)self;
}

View File

@ -164,7 +164,7 @@ STATIC mp_obj_t adc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw,
// initialize and register with the sleep module
pyb_adc_init(self);
pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)pyb_adc_init);
pyb_sleep_add ((const mp_obj_t)self, (WakeUpCB_t)pyb_adc_init);
return self;
}
@ -188,7 +188,7 @@ STATIC mp_obj_t adc_deinit(mp_obj_t self_in) {
MAP_ADCDisable(ADC_BASE);
self->enabled = false;
// unregister it with the sleep module
pybsleep_remove ((const mp_obj_t)self);
pyb_sleep_remove ((const mp_obj_t)self);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_deinit_obj, adc_deinit);
@ -224,7 +224,7 @@ STATIC mp_obj_t adc_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
self->base.type = &pyb_adc_channel_type;
pyb_adc_channel_init (self);
// register it with the sleep module
pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)pyb_adc_channel_init);
pyb_sleep_add ((const mp_obj_t)self, (WakeUpCB_t)pyb_adc_channel_init);
return self;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(adc_channel_obj, 1, adc_channel);
@ -267,7 +267,7 @@ STATIC mp_obj_t adc_channel_deinit(mp_obj_t self_in) {
MAP_ADCChannelDisable(ADC_BASE, self->channel);
// unregister it with the sleep module
pybsleep_remove ((const mp_obj_t)self);
pyb_sleep_remove ((const mp_obj_t)self);
self->enabled = false;
return mp_const_none;
}

View File

@ -305,7 +305,7 @@ STATIC mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self, const mp_arg_val_t *arg
i2c_init(self);
// register it with the sleep module
pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)i2c_init);
pyb_sleep_add ((const mp_obj_t)self, (WakeUpCB_t)i2c_init);
return mp_const_none;
@ -356,7 +356,7 @@ STATIC mp_obj_t pyb_i2c_deinit(mp_obj_t self_in) {
// invalidate the baudrate
pyb_i2c_obj.baudrate = 0;
// unregister it with the sleep module
pybsleep_remove ((const mp_obj_t)self_in);
pyb_sleep_remove ((const mp_obj_t)self_in);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_deinit_obj, pyb_i2c_deinit);

View File

@ -166,7 +166,7 @@ void pin_config (pin_obj_t *self, int af, uint mode, uint pull, int value, uint
pin_obj_configure ((const pin_obj_t *)self);
// register it with the sleep module
pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)pin_obj_configure);
pyb_sleep_add ((const mp_obj_t)self, (WakeUpCB_t)pin_obj_configure);
}
void pin_assign_pins_af (mp_obj_t *pins, uint32_t n_pins, uint32_t pull, uint32_t fn, uint32_t unit) {
@ -873,7 +873,7 @@ STATIC mp_obj_t pin_irq (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *k
// all checks have passed, we can create the irq object
mp_obj_t _irq = mp_irq_new (self, args[2].u_obj, &pin_irq_methods);
if (pwrmode & PYB_PWR_MODE_LPDS) {
pybsleep_set_gpio_lpds_callback (_irq);
pyb_sleep_set_gpio_lpds_callback (_irq);
}
// save the mp_trigge for later

View File

@ -306,7 +306,7 @@ STATIC mp_obj_t pyb_rtc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n
pyb_rtc_datetime((mp_obj_t)&pyb_rtc_obj, args[1].u_obj);
// pass it to the sleep module
pybsleep_set_rtc_obj (self);
pyb_sleep_set_rtc_obj (self);
// return constant object
return (mp_obj_t)&pyb_rtc_obj;

View File

@ -112,7 +112,7 @@ STATIC mp_obj_t pyb_sd_init_helper (pybsd_obj_t *self, const mp_arg_val_t *args)
}
// register it with the sleep module
pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)pyb_sd_hw_init);
pyb_sleep_add ((const mp_obj_t)self, (WakeUpCB_t)pyb_sd_hw_init);
return mp_const_none;
}
@ -159,7 +159,7 @@ STATIC mp_obj_t pyb_sd_deinit (mp_obj_t self_in) {
// de-initialze the sd card at diskio level
sd_disk_deinit();
// unregister it from the sleep module
pybsleep_remove (self);
pyb_sleep_remove (self);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_sd_deinit_obj, pyb_sd_deinit);

View File

@ -72,7 +72,7 @@
#define WAKEUP_TIME_HIB (32768) // 1 s
#define FORCED_TIMER_INTERRUPT_MS (PYB_RTC_MIN_ALARM_TIME_MS)
#define FAILED_SLEEP_DELAY_MS (FORCED_TIMER_INTERRUPT_MS * 2)
#define FAILED_SLEEP_DELAY_MS (FORCED_TIMER_INTERRUPT_MS * 3)
/******************************************************************************
DECLARE PRIVATE TYPES
@ -111,7 +111,7 @@ typedef struct {
mp_obj_base_t base;
mp_obj_t obj;
WakeUpCB_t wakeup;
} pybsleep_obj_t;
} pyb_sleep_obj_t;
typedef struct {
mp_obj_t gpio_lpds_wake_cb;
@ -122,23 +122,26 @@ typedef struct {
/******************************************************************************
DECLARE PRIVATE DATA
******************************************************************************/
STATIC const mp_obj_type_t pybsleep_type;
STATIC nvic_reg_store_t *nvic_reg_store;
STATIC pybsleep_data_t pybsleep_data = {NULL, NULL, NULL};
volatile arm_cm4_core_regs_t vault_arm_registers;
STATIC pybsleep_reset_cause_t pybsleep_reset_cause = PYB_SLP_PWRON_RESET;
STATIC pybsleep_wake_reason_t pybsleep_wake_reason = PYB_SLP_WAKED_PWRON;
STATIC const mp_obj_type_t pyb_sleep_type = {
{ &mp_type_type },
.name = MP_QSTR_sleep,
};
/******************************************************************************
DECLARE PRIVATE FUNCTIONS
******************************************************************************/
STATIC pybsleep_obj_t *pybsleep_find (mp_obj_t obj);
STATIC void pybsleep_flash_powerdown (void);
STATIC NORETURN void pybsleep_suspend_enter (void);
void pybsleep_suspend_exit (void);
STATIC void pybsleep_obj_wakeup (void);
STATIC pyb_sleep_obj_t *pyb_sleep_find (mp_obj_t obj);
STATIC void pyb_sleep_flash_powerdown (void);
STATIC NORETURN void pyb_sleep_suspend_enter (void);
void pyb_sleep_suspend_exit (void);
STATIC void pyb_sleep_obj_wakeup (void);
STATIC void PRCMInterruptHandler (void);
STATIC void pybsleep_iopark (bool hibernate);
STATIC void pyb_sleep_iopark (bool hibernate);
STATIC bool setup_timer_lpds_wake (void);
STATIC bool setup_timer_hibernate_wake (void);
@ -146,14 +149,14 @@ STATIC bool setup_timer_hibernate_wake (void);
DEFINE PUBLIC FUNCTIONS
******************************************************************************/
__attribute__ ((section (".boot")))
void pybsleep_pre_init (void) {
void pyb_sleep_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) {
void pyb_sleep_init0 (void) {
// initialize the sleep objects list
mp_obj_list_init(&MP_STATE_PORT(pybsleep_obj_list), 0);
mp_obj_list_init(&MP_STATE_PORT(pyb_sleep_obj_list), 0);
// register and enable the PRCM interrupt
osi_InterruptRegister(INT_PRCM, (P_OSI_INTR_ENTRY)PRCMInterruptHandler, INT_PRIORITY_LVL_1);
@ -204,50 +207,109 @@ void pybsleep_init0 (void) {
}
}
void pybsleep_signal_soft_reset (void) {
void pyb_sleep_signal_soft_reset (void) {
pybsleep_reset_cause = PYB_SLP_SOFT_RESET;
}
void pybsleep_add (const mp_obj_t obj, WakeUpCB_t wakeup) {
pybsleep_obj_t * sleep_obj = m_new_obj(pybsleep_obj_t);
sleep_obj->base.type = &pybsleep_type;
void pyb_sleep_add (const mp_obj_t obj, WakeUpCB_t wakeup) {
pyb_sleep_obj_t *sleep_obj = m_new_obj(pyb_sleep_obj_t);
sleep_obj->base.type = &pyb_sleep_type;
sleep_obj->obj = obj;
sleep_obj->wakeup = wakeup;
// remove it in case it was already registered
pybsleep_remove (obj);
mp_obj_list_append(&MP_STATE_PORT(pybsleep_obj_list), sleep_obj);
pyb_sleep_remove (obj);
mp_obj_list_append(&MP_STATE_PORT(pyb_sleep_obj_list), sleep_obj);
}
void pybsleep_remove (const mp_obj_t obj) {
pybsleep_obj_t *sleep_obj;
if ((sleep_obj = pybsleep_find(obj))) {
mp_obj_list_remove(&MP_STATE_PORT(pybsleep_obj_list), sleep_obj);
void pyb_sleep_remove (const mp_obj_t obj) {
pyb_sleep_obj_t *sleep_obj;
if ((sleep_obj = pyb_sleep_find(obj))) {
mp_obj_list_remove(&MP_STATE_PORT(pyb_sleep_obj_list), sleep_obj);
}
}
void pybsleep_set_gpio_lpds_callback (mp_obj_t cb_obj) {
void pyb_sleep_set_gpio_lpds_callback (mp_obj_t cb_obj) {
pybsleep_data.gpio_lpds_wake_cb = cb_obj;
}
void pybsleep_set_wlan_obj (mp_obj_t wlan_obj) {
void pyb_sleep_set_wlan_obj (mp_obj_t wlan_obj) {
pybsleep_data.wlan_obj = (wlan_obj_t *)wlan_obj;
}
void pybsleep_set_rtc_obj (mp_obj_t rtc_obj) {
void pyb_sleep_set_rtc_obj (mp_obj_t rtc_obj) {
pybsleep_data.rtc_obj = (pyb_rtc_obj_t *)rtc_obj;
}
pybsleep_reset_cause_t pybsleep_get_reset_cause (void) {
void pyb_sleep_sleep (void) {
nlr_buf_t nlr;
// check if we should enable timer wake-up
if (pybsleep_data.rtc_obj->irq_enabled && (pybsleep_data.rtc_obj->pwrmode & PYB_PWR_MODE_LPDS)) {
if (!setup_timer_lpds_wake()) {
// lpds entering is not possible, wait for the forced interrupt and return
HAL_Delay (FAILED_SLEEP_DELAY_MS);
return;
}
} else {
// disable the timer as wake source
MAP_PRCMLPDSWakeupSourceDisable(PRCM_LPDS_TIMER);
}
// do we need network wake-up?
if (pybsleep_data.wlan_obj->irq_enabled) {
MAP_PRCMLPDSWakeupSourceEnable (PRCM_LPDS_HOST_IRQ);
server_sleep_sockets();
} else {
MAP_PRCMLPDSWakeupSourceDisable (PRCM_LPDS_HOST_IRQ);
}
// entering and exiting suspended mode must be an atomic operation
// therefore interrupts need to be disabled
uint primsk = disable_irq();
if (nlr_push(&nlr) == 0) {
pyb_sleep_suspend_enter();
nlr_pop();
}
// an exception is always raised when exiting suspend mode
enable_irq(primsk);
}
void pyb_sleep_deepsleep (void) {
// check if we should enable timer wake-up
if (pybsleep_data.rtc_obj->irq_enabled && (pybsleep_data.rtc_obj->pwrmode & PYB_PWR_MODE_HIBERNATE)) {
if (!setup_timer_hibernate_wake()) {
// hibernating is not possible, wait for the forced interrupt and return
HAL_Delay (FAILED_SLEEP_DELAY_MS);
return;
}
} else {
// disable the timer as hibernate wake source
MAP_PRCMLPDSWakeupSourceDisable(PRCM_HIB_SLOW_CLK_CTR);
}
wlan_stop(SL_STOP_TIMEOUT);
pyb_sleep_flash_powerdown();
// must be done just before entering hibernate mode
pyb_sleep_iopark(true);
MAP_PRCMHibernateEnter();
}
pybsleep_reset_cause_t pyb_sleep_get_reset_cause (void) {
return pybsleep_reset_cause;
}
pybsleep_wake_reason_t pyb_sleep_get_wake_reason (void) {
return pybsleep_wake_reason;
}
/******************************************************************************
DEFINE PRIVATE FUNCTIONS
******************************************************************************/
STATIC pybsleep_obj_t *pybsleep_find (mp_obj_t obj) {
for (mp_uint_t i = 0; i < MP_STATE_PORT(pybsleep_obj_list).len; i++) {
STATIC pyb_sleep_obj_t *pyb_sleep_find (mp_obj_t obj) {
for (mp_uint_t i = 0; i < MP_STATE_PORT(pyb_sleep_obj_list).len; i++) {
// search for the object and then remove it
pybsleep_obj_t *sleep_obj = ((pybsleep_obj_t *)(MP_STATE_PORT(pybsleep_obj_list).items[i]));
pyb_sleep_obj_t *sleep_obj = ((pyb_sleep_obj_t *)(MP_STATE_PORT(pyb_sleep_obj_list).items[i]));
if (sleep_obj->obj == obj) {
return sleep_obj;
}
@ -255,7 +317,7 @@ STATIC pybsleep_obj_t *pybsleep_find (mp_obj_t obj) {
return NULL;
}
STATIC void pybsleep_flash_powerdown (void) {
STATIC void pyb_sleep_flash_powerdown (void) {
uint32_t status;
// Enable clock for SSPI module
@ -300,7 +362,7 @@ STATIC void pybsleep_flash_powerdown (void) {
MAP_SPICSDisable(SSPI_BASE);
}
STATIC NORETURN void pybsleep_suspend_enter (void) {
STATIC NORETURN void pyb_sleep_suspend_enter (void) {
// enable full RAM retention
MAP_PRCMSRAMRetentionEnable(PRCM_SRAM_COL_1 | PRCM_SRAM_COL_2 | PRCM_SRAM_COL_3 | PRCM_SRAM_COL_4, PRCM_SRAM_LPDS_RET);
@ -337,7 +399,7 @@ STATIC NORETURN void pybsleep_suspend_enter (void) {
mperror_heartbeat_switch_off();
// park the gpio pins
pybsleep_iopark(false);
pyb_sleep_iopark(false);
// store the cpu registers
sleep_store();
@ -350,7 +412,7 @@ STATIC NORETURN void pybsleep_suspend_enter (void) {
for ( ; ; );
}
void pybsleep_suspend_exit (void) {
void pyb_sleep_suspend_exit (void) {
// take the I2C semaphore
uint32_t reg = HWREG(COMMON_REG_BASE + COMMON_REG_O_I2C_Properties_Register);
reg = (reg & ~0x3) | 0x1;
@ -404,7 +466,7 @@ void pybsleep_suspend_exit (void) {
sl_IfOpen (NULL, 0);
// restore the configuration of all active peripherals
pybsleep_obj_wakeup();
pyb_sleep_obj_wakeup();
// reconfigure all the previously enabled interrupts
mp_irq_wake_all();
@ -459,14 +521,14 @@ STATIC void PRCMInterruptHandler (void) {
}
}
STATIC void pybsleep_obj_wakeup (void) {
for (mp_uint_t i = 0; i < MP_STATE_PORT(pybsleep_obj_list).len; i++) {
pybsleep_obj_t *sleep_obj = ((pybsleep_obj_t *)MP_STATE_PORT(pybsleep_obj_list).items[i]);
STATIC void pyb_sleep_obj_wakeup (void) {
for (mp_uint_t i = 0; i < MP_STATE_PORT(pyb_sleep_obj_list).len; i++) {
pyb_sleep_obj_t *sleep_obj = ((pyb_sleep_obj_t *)MP_STATE_PORT(pyb_sleep_obj_list).items[i]);
sleep_obj->wakeup(sleep_obj->obj);
}
}
STATIC void pybsleep_iopark (bool hibernate) {
STATIC void pyb_sleep_iopark (bool hibernate) {
mp_map_t *named_map = mp_obj_dict_get_map((mp_obj_t)&pin_board_pins_locals_dict);
for (uint i = 0; i < named_map->used; i++) {
pin_obj_t * pin = (pin_obj_t *)named_map->table[i].value;
@ -593,125 +655,3 @@ STATIC bool setup_timer_hibernate_wake (void) {
return false;
}
/******************************************************************************/
// Micro Python bindings; Sleep class
/// \function idle()
/// Gates the processor clock until an interrupt is triggered
STATIC mp_obj_t pyb_sleep_idle (mp_obj_t self_in) {
__WFI();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_sleep_idle_obj, pyb_sleep_idle);
/// \function suspend(wlan)
/// Enters suspended mode. Wake up sources should have been enable prior to
/// calling this method.
STATIC mp_obj_t pyb_sleep_suspend (mp_obj_t self_in) {
nlr_buf_t nlr;
// check if we should enable timer wake-up
if (pybsleep_data.rtc_obj->irq_enabled && (pybsleep_data.rtc_obj->pwrmode & PYB_PWR_MODE_LPDS)) {
if (!setup_timer_lpds_wake()) {
// lpds entering is not possible, wait for the forced interrupt and return
HAL_Delay (FAILED_SLEEP_DELAY_MS);
return mp_const_none;
}
} else {
// disable the timer as wake source
MAP_PRCMLPDSWakeupSourceDisable(PRCM_LPDS_TIMER);
}
// do we need network wake-up?
if (pybsleep_data.wlan_obj->irq_enabled) {
MAP_PRCMLPDSWakeupSourceEnable (PRCM_LPDS_HOST_IRQ);
server_sleep_sockets();
} else {
MAP_PRCMLPDSWakeupSourceDisable (PRCM_LPDS_HOST_IRQ);
}
// entering and exiting suspended mode must be an atomic operation
// therefore interrupts need to be disabled
uint primsk = disable_irq();
if (nlr_push(&nlr) == 0) {
pybsleep_suspend_enter();
nlr_pop();
}
// an exception is always raised when exiting suspend mode
enable_irq(primsk);
return mp_const_none;
}
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.
STATIC mp_obj_t pyb_sleep_hibernate (mp_obj_t self_in) {
// check if we should enable timer wake-up
if (pybsleep_data.rtc_obj->irq_enabled && (pybsleep_data.rtc_obj->pwrmode & PYB_PWR_MODE_HIBERNATE)) {
if (!setup_timer_hibernate_wake()) {
// hibernating is not possible, wait for the forced interrupt and return
HAL_Delay (FAILED_SLEEP_DELAY_MS);
return mp_const_none;
}
} else {
// disable the timer as hibernate wake source
MAP_PRCMLPDSWakeupSourceDisable(PRCM_HIB_SLOW_CLK_CTR);
}
wlan_stop(SL_STOP_TIMEOUT);
pybsleep_flash_powerdown();
// must be done just before entering hibernate mode
pybsleep_iopark(true);
MAP_PRCMHibernateEnter();
return mp_const_none;
}
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_OBJ_NEW_SMALL_INT(pybsleep_wake_reason);
}
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_POWER_ON), 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_GPIO) },
{ 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);
STATIC const mp_obj_type_t pybsleep_type = {
{ &mp_type_type },
.name = MP_QSTR_Sleep,
.locals_dict = (mp_obj_t)&pybsleep_locals_dict,
};
const mp_obj_base_t pyb_sleep_obj = {&pybsleep_type};

View File

@ -54,22 +54,20 @@ typedef enum {
typedef void (*WakeUpCB_t)(const mp_obj_t self);
/******************************************************************************
DECLARE EXPORTED VARIABLES
******************************************************************************/
extern const mp_obj_base_t pyb_sleep_obj;
/******************************************************************************
DECLARE FUNCTIONS
******************************************************************************/
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_gpio_lpds_callback (mp_obj_t cb_obj);
void pybsleep_set_wlan_obj (mp_obj_t wlan_obj);
void pybsleep_set_rtc_obj (mp_obj_t rtc_obj);
pybsleep_reset_cause_t pybsleep_get_reset_cause (void);
void pyb_sleep_pre_init (void);
void pyb_sleep_init0 (void);
void pyb_sleep_signal_soft_reset (void);
void pyb_sleep_add (const mp_obj_t obj, WakeUpCB_t wakeup);
void pyb_sleep_remove (const mp_obj_t obj);
void pyb_sleep_set_gpio_lpds_callback (mp_obj_t cb_obj);
void pyb_sleep_set_wlan_obj (mp_obj_t wlan_obj);
void pyb_sleep_set_rtc_obj (mp_obj_t rtc_obj);
void pyb_sleep_sleep (void);
void pyb_sleep_deepsleep (void);
pybsleep_reset_cause_t pyb_sleep_get_reset_cause (void);
pybsleep_wake_reason_t pyb_sleep_get_wake_reason (void);
#endif /* PYBSLEEP_H_ */

View File

@ -214,7 +214,7 @@ STATIC mp_obj_t pyb_spi_init_helper(pyb_spi_obj_t *self, const mp_arg_val_t *arg
pybspi_init((const pyb_spi_obj_t *)self);
// register it with the sleep module
pybsleep_add((const mp_obj_t)self, (WakeUpCB_t)pybspi_init);
pyb_sleep_add((const mp_obj_t)self, (WakeUpCB_t)pybspi_init);
return mp_const_none;
@ -271,7 +271,7 @@ STATIC mp_obj_t pyb_spi_deinit(mp_obj_t self_in) {
// invalidate the baudrate
pyb_spi_obj.baudrate = 0;
// unregister it with the sleep module
pybsleep_remove((const mp_obj_t)self_in);
pyb_sleep_remove((const mp_obj_t)self_in);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_spi_deinit_obj, pyb_spi_deinit);

View File

@ -344,7 +344,7 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *tim, mp_uint_t n_args, co
timer_init(tim);
// register it with the sleep module
pybsleep_add ((const mp_obj_t)tim, (WakeUpCB_t)timer_init);
pyb_sleep_add ((const mp_obj_t)tim, (WakeUpCB_t)timer_init);
return mp_const_none;
@ -479,7 +479,7 @@ STATIC mp_obj_t pyb_timer_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp
timer_channel_init(ch);
// register it with the sleep module
pybsleep_add ((const mp_obj_t)ch, (WakeUpCB_t)timer_channel_init);
pyb_sleep_add ((const mp_obj_t)ch, (WakeUpCB_t)timer_channel_init);
// add the timer to the list
pyb_timer_channel_add(ch);

View File

@ -423,7 +423,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, const mp_arg_val_t *a
// initialize and enable the uart
uart_init (self);
// register it with the sleep module
pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)uart_init);
pyb_sleep_add ((const mp_obj_t)self, (WakeUpCB_t)uart_init);
// enable the callback
uart_irq_new (self, UART_TRIGGER_RX_ANY, INT_PRIORITY_LVL_3, mp_const_none);
// disable the irq (from the user point of view)
@ -498,7 +498,7 @@ STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
pyb_uart_obj_t *self = self_in;
// unregister it with the sleep module
pybsleep_remove (self);
pyb_sleep_remove (self);
// invalidate the baudrate
self->baudrate = 0;
// free the read buffer

View File

@ -112,7 +112,7 @@ extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj;
{ MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, \
// extra built in modules to add to the list of known ones
extern const struct _mp_obj_module_t pyb_module;
extern const struct _mp_obj_module_t machine_module;
extern const struct _mp_obj_module_t mp_module_ure;
extern const struct _mp_obj_module_t mp_module_ujson;
extern const struct _mp_obj_module_t mp_module_uheapq;
@ -126,7 +126,7 @@ extern const struct _mp_obj_module_t mp_module_ubinascii;
extern const struct _mp_obj_module_t mp_module_ussl;
#define MICROPY_PORT_BUILTIN_MODULES \
{ MP_OBJ_NEW_QSTR(MP_QSTR_pyb), (mp_obj_t)&pyb_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&machine_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&mp_module_uos }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_utime), (mp_obj_t)&mp_module_utime }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_uselect), (mp_obj_t)&mp_module_uselect }, \
@ -151,15 +151,15 @@ extern const struct _mp_obj_module_t mp_module_ussl;
// extra constants
#define MICROPY_PORT_CONSTANTS \
{ MP_OBJ_NEW_QSTR(MP_QSTR_pyb), (mp_obj_t)&pyb_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&machine_module }, \
// vm state and root pointers for the gc
#define MP_STATE_PORT MP_STATE_VM
#define MICROPY_PORT_ROOT_POINTERS \
const char *readline_hist[8]; \
mp_obj_t mp_const_user_interrupt; \
mp_obj_t pyb_config_main; \
mp_obj_list_t pybsleep_obj_list; \
mp_obj_t machine_config_main; \
mp_obj_list_t pyb_sleep_obj_list; \
mp_obj_list_t mp_irq_obj_list; \
mp_obj_list_t pyb_timer_channel_obj_list; \
mp_obj_list_t mount_obj_list; \

View File

@ -128,7 +128,7 @@ soft_reset:
// execute all basic initializations
mpexception_init0();
mp_irq_init0();
pybsleep_init0();
pyb_sleep_init0();
pin_init0();
mperror_init0();
uart_init0();
@ -138,7 +138,7 @@ soft_reset:
moduos_init0();
rng_init0();
pybsleep_reset_cause_t rstcause = pybsleep_get_reset_cause();
pybsleep_reset_cause_t rstcause = pyb_sleep_get_reset_cause();
if (rstcause < PYB_SLP_SOFT_RESET) {
if (rstcause == PYB_SLP_HIB_RESET) {
// when waking up from hibernate we just want
@ -162,7 +162,7 @@ soft_reset:
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_flash_slash_lib));
// reset config variables; they should be set by boot.py
MP_STATE_PORT(pyb_config_main) = MP_OBJ_NULL;
MP_STATE_PORT(machine_config_main) = MP_OBJ_NULL;
if (!safeboot) {
// run boot.py
@ -186,10 +186,10 @@ soft_reset:
// run the main script from the current directory.
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
const char *main_py;
if (MP_STATE_PORT(pyb_config_main) == MP_OBJ_NULL) {
if (MP_STATE_PORT(machine_config_main) == MP_OBJ_NULL) {
main_py = "main.py";
} else {
main_py = mp_obj_str_get_str(MP_STATE_PORT(pyb_config_main));
main_py = mp_obj_str_get_str(MP_STATE_PORT(machine_config_main));
}
int ret = pyexec_file(main_py);
if (ret & PYEXEC_FORCED_EXIT) {
@ -219,7 +219,7 @@ soft_reset:
soft_reset_exit:
// soft reset
pybsleep_signal_soft_reset();
pyb_sleep_signal_soft_reset();
mp_printf(&mp_plat_print, "PYB: soft reboot\n");
// disable all callbacks to avoid undefined behaviour
@ -256,7 +256,7 @@ STATIC void mptask_pre_init (void) {
ASSERT ((sflash_fatfs = mem_Malloc(sizeof(FATFS))) != NULL);
// this one allocates memory for the nvic vault
pybsleep_pre_init();
pyb_sleep_pre_init();
// this one allocates memory for the WLAN semaphore
wlan_pre_init();
@ -366,10 +366,10 @@ STATIC void mptask_create_main_py (void) {
f_close(&fp);
}
STATIC mp_obj_t pyb_main(mp_obj_t main) {
STATIC mp_obj_t machine_main(mp_obj_t main) {
if (MP_OBJ_IS_STR(main)) {
MP_STATE_PORT(pyb_config_main) = main;
MP_STATE_PORT(machine_config_main) = main;
}
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(pyb_main_obj, pyb_main);
MP_DEFINE_CONST_FUN_OBJ_1(machine_main_obj, machine_main);

View File

@ -25,9 +25,8 @@
* THE SOFTWARE.
*/
// for pyb module
Q(pyb)
Q(help)
// for machine module
Q(machine)
#ifdef DEBUG
Q(info)
#endif
@ -39,11 +38,30 @@ Q(freq)
Q(unique_id)
Q(disable_irq)
Q(enable_irq)
Q(idle)
Q(sleep)
Q(deepsleep)
Q(reset_cause)
Q(wake_reason)
Q(IDLE)
Q(SLEEP)
Q(DEEPSLEEP)
Q(POWER_ON)
Q(HARD_RESET)
Q(WDT_RESET)
Q(DEEPSLEEP_RESET)
Q(SOFT_RESET)
Q(WLAN_WAKE)
Q(PIN_WAKE)
Q(RTC_WAKE)
// entries for sys.path
Q(/flash)
Q(/flash/lib)
// interactive help
Q(help)
// for module weak links
Q(struct)
Q(binascii)
@ -312,25 +330,6 @@ Q(handler)
Q(priority)
Q(wake)
// for Sleep class
Q(Sleep)
Q(idle)
Q(suspend)
Q(hibernate)
Q(reset_cause)
Q(wake_reason)
Q(ACTIVE)
Q(SUSPENDED)
Q(HIBERNATING)
Q(POWER_ON)
Q(HARD_RESET)
Q(WDT_RESET)
Q(HIB_RESET)
Q(SOFT_RESET)
Q(WLAN_WAKE)
Q(PIN_WAKE)
Q(RTC_WAKE)
// for SPI class
Q(SPI)
Q(id)

View File

@ -1,4 +1,6 @@
import pyb
from machine import Pin
from machine import RTC
import time
import os
"""
@ -13,31 +15,31 @@ test_bytes = os.urandom(1024)
def test_pin_read (pull):
# enable the pull resistor on all pins, then read the value
for p in pin_map:
pin = pyb.Pin('GP' + str(p), mode=pyb.Pin.IN, pull=pull)
pin = Pin('GP' + str(p), mode=Pin.IN, pull=pull)
# read the pin value
print(pin())
def test_pin_shorts (pull):
if pull == pyb.Pin.PULL_UP:
pull_inverted = pyb.Pin.PULL_DOWN
if pull == Pin.PULL_UP:
pull_inverted = Pin.PULL_DOWN
else:
pull_inverted = pyb.Pin.PULL_UP
pull_inverted = Pin.PULL_UP
# enable all pulls of the specified type
for p in pin_map:
pin = pyb.Pin('GP' + str(p), mode=pyb.Pin.IN, pull=pull_inverted)
pin = Pin('GP' + str(p), mode=Pin.IN, pull=pull_inverted)
# then change the pull one pin at a time and read its value
i = 0
while i < len(pin_map):
pin = pyb.Pin('GP' + str(pin_map[i]), mode=pyb.Pin.IN, pull=pull)
pyb.Pin('GP' + str(pin_map[i - 1]), mode=pyb.Pin.IN, pull=pull_inverted)
pin = Pin('GP' + str(pin_map[i]), mode=Pin.IN, pull=pull)
Pin('GP' + str(pin_map[i - 1]), mode=Pin.IN, pull=pull_inverted)
i += 1
# read the pin value
print(pin())
test_pin_read(pyb.Pin.PULL_UP)
test_pin_read(pyb.Pin.PULL_DOWN)
test_pin_shorts(pyb.Pin.PULL_UP)
test_pin_shorts(pyb.Pin.PULL_DOWN)
test_pin_read(Pin.PULL_UP)
test_pin_read(Pin.PULL_DOWN)
test_pin_shorts(Pin.PULL_UP)
test_pin_shorts(Pin.PULL_DOWN)
# create a test directory
os.mkdir('/flash/test')
@ -62,12 +64,12 @@ print('test' not in ls)
print(ls)
# test the real time clock
rtc = pyb.RTC()
rtc = RTC()
while rtc.now()[6] > 800:
pass
time1 = rtc.now()
pyb.delay(1000)
time.sleep_ms(1000)
time2 = rtc.now()
print(time2[5] - time1[5] == 1)
print(time2[6] - time1[6] < 5000) # microseconds

View File

@ -90,9 +90,9 @@ def reset_board(args):
time.sleep(1)
tn.write(b'\r\x02') # ctrl-B: enter friendly REPL
if b'Type "help()" for more information.' in tn.read_until(b'Type "help()" for more information.', timeout=5):
tn.write(b"import pyb\r\n")
tn.write(b"pyb.reset()\r\n")
time.sleep(1)
tn.write(b"import machine\r\n")
tn.write(b"machine.reset()\r\n")
time.sleep(2)
print("Reset performed")
success = True
else:

View File

@ -69,10 +69,10 @@ STATIC uint32_t lfsr (uint32_t input) {
/******************************************************************************/
// Micro Python bindings;
STATIC mp_obj_t pyb_rng_get(void) {
STATIC mp_obj_t machine_rng_get(void) {
return mp_obj_new_int(rng_get());
}
MP_DEFINE_CONST_FUN_OBJ_0(pyb_rng_get_obj, pyb_rng_get);
MP_DEFINE_CONST_FUN_OBJ_0(machine_rng_get_obj, machine_rng_get);
/******************************************************************************
* PUBLIC FUNCTIONS

View File

@ -30,6 +30,6 @@
void rng_init0 (void);
uint32_t rng_get (void);
MP_DECLARE_CONST_FUN_OBJ(pyb_rng_get_obj);
MP_DECLARE_CONST_FUN_OBJ(machine_rng_get_obj);
#endif // __RANDOM_H

View File

@ -7,7 +7,7 @@
@ global variable with the backup registers
.extern vault_arm_registers
@ global function that performs the wake up actions
.extern pybsleep_suspend_exit
.extern pyb_sleep_suspend_exit
@ uint sleep_store(void)
.global sleep_store
@ -58,4 +58,4 @@ sleep_restore:
msr basepri, r0
dsb
isb
bl pybsleep_suspend_exit
bl pyb_sleep_suspend_exit

View File

@ -2,14 +2,14 @@
ADC test for the CC3200 based boards.
'''
from pyb import ADC
from machine import ADC
import os
machine = os.uname().machine
if 'LaunchPad' in machine:
mch = os.uname().machine
if 'LaunchPad' in mch:
adc_pin = 'GP5'
adc_channel = 3
elif 'WiPy' in machine:
elif 'WiPy' in mch:
adc_pin = 'GP3'
adc_channel = 1
else:

View File

@ -3,14 +3,14 @@ I2C test for the CC3200 based boards.
A MPU-9150 sensor must be connected to the I2C bus.
'''
from pyb import I2C
from machine import I2C
import os
import time
machine = os.uname().machine
if 'LaunchPad' in machine:
mch = os.uname().machine
if 'LaunchPad' in mch:
i2c_pins = ('GP11', 'GP10')
elif 'WiPy' in machine:
elif 'WiPy' in mch:
i2c_pins = ('GP15', 'GP10')
else:
raise Exception('Board not supported!')

View File

@ -2,14 +2,13 @@
os module test for the CC3200 based boards
'''
from pyb import SD
import pyb
from machine import SD
import os
machine = os.uname().machine
if 'LaunchPad' in machine:
mch = os.uname().machine
if 'LaunchPad' in mch:
sd_pins = ('GP16', 'GP17', 'GP15')
elif 'WiPy' in machine:
elif 'WiPy' in mch:
sd_pins = ('GP10', 'GP11', 'GP15')
else:
raise Exception('Board not supported!')

View File

@ -1,14 +1,14 @@
""" This test need a set of pins which can be set as inputs and have no external
pull up or pull down connected.
"""
from pyb import Pin
from machine import Pin
import os
machine = os.uname().machine
if 'LaunchPad' in machine:
mch = os.uname().machine
if 'LaunchPad' in mch:
pin_map = ['GP24', 'GP12', 'GP14', 'GP15', 'GP16', 'GP17', 'GP28', 'GP8', 'GP6', 'GP30', 'GP31', 'GP3', 'GP0', 'GP4', 'GP5']
max_af_idx = 15
elif 'WiPy' in machine:
elif 'WiPy' in mch:
pin_map = ['GP23', 'GP24', 'GP12', 'GP13', 'GP14', 'GP9', 'GP17', 'GP28', 'GP22', 'GP8', 'GP30', 'GP31', 'GP0', 'GP4', 'GP5']
max_af_idx = 15
else:

View File

@ -2,15 +2,15 @@
Pin IRQ test for the CC3200 based boards.
'''
from pyb import Pin
from pyb import Sleep
from machine import Pin
import machine
import os
import time
machine = os.uname().machine
if 'LaunchPad' in machine:
mch = os.uname().machine
if 'LaunchPad' in mch:
pins = ['GP16', 'GP13']
elif 'WiPy' in machine:
elif 'WiPy' in mch:
pins = ['GP16', 'GP13']
else:
raise Exception('Board not supported!')
@ -78,16 +78,16 @@ print(pin_irq_count_total == 0)
# test waking up from suspended mode on low level
pin0(0)
t0 = time.ticks_ms()
pin1_irq.init(trigger=Pin.IRQ_LOW_LEVEL, wake=Sleep.SUSPENDED)
Sleep.suspend()
pin1_irq.init(trigger=Pin.IRQ_LOW_LEVEL, wake=machine.SLEEP)
machine.sleep()
print(time.ticks_ms() - t0 < 10)
print('Awake')
# test waking up from suspended mode on high level
pin0(1)
t0 = time.ticks_ms()
pin1_irq.init(trigger=Pin.IRQ_HIGH_LEVEL, wake=Sleep.SUSPENDED)
Sleep.suspend()
pin1_irq.init(trigger=Pin.IRQ_HIGH_LEVEL, wake=machine.SLEEP)
machine.sleep()
print(time.ticks_ms() - t0 < 10)
print('Awake')
@ -108,7 +108,7 @@ except:
print('Exception')
try:
pin0_irq = pin0.irq(trigger=Pin.IRQ_RISING, wake=Sleep.SUSPENDED) # GP16 can't wake up from DEEPSLEEP
pin0_irq = pin0.irq(trigger=Pin.IRQ_RISING, wake=machine.SLEEP) # GP16 can't wake up from DEEPSLEEP
except:
print('Exception')

View File

@ -4,8 +4,13 @@ This is needed to force the board to reboot
with the default WLAN AP settings
'''
from pyb import WDT
from machine import WDT
import time
import os
mch = os.uname().machine
if not 'LaunchPad' in mch and not 'WiPy' in mch:
raise Exception('Board not supported!')
wdt = WDT(timeout=1000)
print(wdt)

View File

@ -2,12 +2,12 @@
RTC test for the CC3200 based boards.
'''
from pyb import RTC
from machine import RTC
import os
import time
machine = os.uname().machine
if not 'LaunchPad' in machine and not 'WiPy' in machine:
mch = os.uname().machine
if not 'LaunchPad' in mch and not 'WiPy' in mch:
raise Exception('Board not supported!')
rtc = RTC()

View File

@ -2,13 +2,13 @@
RTC IRQ test for the CC3200 based boards.
'''
from pyb import RTC
from pyb import Sleep
from machine import RTC
import machine
import os
import time
machine = os.uname().machine
if not 'LaunchPad' in machine and not 'WiPy' in machine:
mch = os.uname().machine
if not 'LaunchPad' in mch and not 'WiPy' in mch:
raise Exception('Board not supported!')
def rtc_ticks_ms(rtc):
@ -47,9 +47,9 @@ print(rtc_irq_count == 10)
rtc.alarm_cancel()
rtc_irq_count = 0
rtc.alarm(time=50, repeat=True)
rtc_irq.init(trigger=RTC.ALARM0, handler=alarm_handler, wake=Sleep.SUSPENDED | Sleep.ACTIVE)
rtc_irq.init(trigger=RTC.ALARM0, handler=alarm_handler, wake=machine.SLEEP | machine.IDLE)
while rtc_irq_count < 3:
Sleep.suspend()
machine.sleep()
print(rtc_irq_count == 3)
# no repetition
@ -62,7 +62,7 @@ print(rtc_irq_count == 1)
rtc.alarm_cancel()
t0 = rtc_ticks_ms(rtc)
rtc.alarm(time=500, repeat=False)
Sleep.suspend()
machine.sleep()
t1 = rtc_ticks_ms(rtc)
print(abs(t1 - t0 - 500) < 20)
@ -71,9 +71,9 @@ rtc.alarm_cancel()
rtc_irq_count = 0
rtc.alarm(time=500, repeat=True)
t0 = rtc_ticks_ms(rtc)
rtc_irq = rtc.irq(trigger=RTC.ALARM0, handler=alarm_handler, wake=Sleep.SUSPENDED)
rtc_irq = rtc.irq(trigger=RTC.ALARM0, handler=alarm_handler, wake=machine.SLEEP)
while rtc_irq_count < 3:
Sleep.suspend()
machine.sleep()
t1 = rtc_ticks_ms(rtc)
print(abs(t1 - t0 - (500 * rtc_irq_count)) < 25)

View File

@ -2,13 +2,13 @@
SD card test for the CC3200 based boards.
'''
from pyb import SD
from machine import SD
import os
machine = os.uname().machine
if 'LaunchPad' in machine:
mch = os.uname().machine
if 'LaunchPad' in mch:
sd_pins = ('GP16', 'GP17', 'GP15')
elif 'WiPy' in machine:
elif 'WiPy' in mch:
sd_pins = ('GP10', 'GP11', 'GP15')
else:
raise Exception('Board not supported!')

View File

@ -2,13 +2,13 @@
SPI test for the CC3200 based boards.
'''
from pyb import SPI
from machine import SPI
import os
machine = os.uname().machine
if 'LaunchPad' in machine:
mch = os.uname().machine
if 'LaunchPad' in mch:
spi_pins = ('GP14', 'GP16', 'GP30')
elif 'WiPy' in machine:
elif 'WiPy' in mch:
spi_pins = ('GP14', 'GP16', 'GP30')
else:
raise Exception('Board not supported!')

View File

@ -3,16 +3,16 @@ UART test for the CC3200 based boards.
UART0 and UART1 must be connected together for this test to pass.
'''
from pyb import UART
from pyb import Pin
from machine import UART
from machine import Pin
import os
import time
machine = os.uname().machine
if 'LaunchPad' in machine:
mch = os.uname().machine
if 'LaunchPad' in mch:
uart_id_range = range(0, 2)
uart_pins = [[('GP12', 'GP13'), ('GP12', 'GP13', 'GP7', 'GP6')], [('GP16', 'GP17'), ('GP16', 'GP17', 'GP7', 'GP6')]]
elif 'WiPy' in machine:
elif 'WiPy' in mch:
uart_id_range = range(0, 2)
uart_pins = [[('GP12', 'GP13'), ('GP12', 'GP13', 'GP7', 'GP6')], [('GP16', 'GP17'), ('GP16', 'GP17', 'GP7', 'GP6')]]
else:

View File

@ -2,14 +2,14 @@
UART IRQ test for the CC3200 based boards.
'''
from pyb import UART
from machine import UART
import os
import time
machine = os.uname().machine
if 'LaunchPad' in machine:
mch = os.uname().machine
if 'LaunchPad' in mch:
uart_pins = [[('GP12', 'GP13'), ('GP12', 'GP13', 'GP7', 'GP6')], [('GP16', 'GP17'), ('GP16', 'GP17', 'GP7', 'GP6')]]
elif 'WiPy' in machine:
elif 'WiPy' in mch:
uart_pins = [[('GP12', 'GP13'), ('GP12', 'GP13', 'GP7', 'GP6')], [('GP16', 'GP17'), ('GP16', 'GP17', 'GP7', 'GP6')]]
else:
raise Exception('Board not supported!')

View File

@ -2,7 +2,7 @@
WDT test for the CC3200 based boards
'''
from pyb import WDT
from machine import WDT
import time
# test the invalid cases first

View File

@ -6,10 +6,9 @@ from network import WLAN
import os
import time
import testconfig
import pyb
machine = os.uname().machine
if not 'LaunchPad' in machine and not 'WiPy' in machine:
mch = os.uname().machine
if not 'LaunchPad' in mch and not 'WiPy' in mch:
raise Exception('Board not supported!')