STATIC mp_obj_t machine_deepsleep(void) { // default to sleep forever uint32_t sleep_us = 0; // see if RTC.ALARM0 should wake the device if (pyb_rtc_alarm0_wake & MACHINE_WAKE_DEEPSLEEP) { uint64_t t = pyb_rtc_get_us_since_2000(); if (pyb_rtc_alarm0_expiry <= t) { sleep_us = 1; // alarm already expired so wake immediately } else { uint64_t delta = pyb_rtc_alarm0_expiry - t; if (delta <= 0xffffffff) { // sleep for the desired time sleep_us = delta; } else { // overflow, just set to maximum sleep time sleep_us = 0xffffffff; } } } // prepare for RTC reset at wake up rtc_prepare_deepsleep(sleep_us); // put the device in a deep-sleep state system_deep_sleep_set_option(0); // default power down mode; TODO check this system_deep_sleep(sleep_us); for (;;) { // we must not return ets_loop_iter(); } return mp_const_none; }
bool ets_run(void) { #if USE_ETS_TASK #if SDK_BELOW_1_1_1 ets_isr_attach(10, my_timer_isr, NULL); #endif _ets_run(); #else // ets_timer_init(); *(char*)0x3FFFC6FC = 0; ets_intr_lock(); printf("ets_alt_task: ets_run\n"); #if DEBUG dump_tasks(); #endif ets_intr_unlock(); while (1) { if (!ets_loop_iter()) { //printf("idle\n"); ets_intr_lock(); if (idle_cb) { idle_cb(idle_arg); } asm("waiti 0"); ets_intr_unlock(); } } #endif }
void ets_event_poll(void) { ets_loop_iter(); if (MP_STATE_VM(mp_pending_exception) != NULL) { mp_obj_t obj = MP_STATE_VM(mp_pending_exception); MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL; nlr_raise(obj); } }
STATIC void machine_hspi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { (void)self_in; if (dest == NULL) { // fast case when we only need to write data size_t chunk_size = 1024; size_t count = len / chunk_size; size_t i = 0; for (size_t j = 0; j < count; ++j) { for (size_t k = 0; k < chunk_size; ++k) { spi_tx8fast(HSPI, src[i]); ++i; } ets_loop_iter(); } while (i < len) { spi_tx8fast(HSPI, src[i]); ++i; } } else { // we need to read and write data // Process data in chunks, let the pending tasks run in between size_t chunk_size = 1024; // TODO this should depend on baudrate size_t count = len / chunk_size; size_t i = 0; for (size_t j = 0; j < count; ++j) { for (size_t k = 0; k < chunk_size; ++k) { dest[i] = spi_transaction(HSPI, 0, 0, 0, 0, 8, src[i], 8, 0); ++i; } ets_loop_iter(); } while (i < len) { dest[i] = spi_transaction(HSPI, 0, 0, 0, 0, 8, src[i], 8, 0); ++i; } } }
int mp_hal_stdin_rx_chr(void) { for (;;) { int c = ringbuf_get(&stdin_ringbuf); if (c != -1) { return c; } #if 0 // Idles CPU but need more testing before enabling if (!ets_loop_iter()) { asm("waiti 0"); } #else mp_hal_delay_us(1); #endif } }
void ets_event_poll(void) { ets_loop_iter(); mp_handle_pending(); }