From a099bfe89cbdf7275bb244899a454f261914a462 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 11 Mar 2016 09:38:20 +0700 Subject: [PATCH] esp8266/esp_mphal: Add higher-level event polling function. ets_event_poll() polls both system events and uPy pending exception. --- esp8266/esp_mphal.c | 10 ++++++++++ esp8266/esp_mphal.h | 1 + 2 files changed, 11 insertions(+) diff --git a/esp8266/esp_mphal.c b/esp8266/esp_mphal.c index c78b3600f0..3fd2c636d9 100644 --- a/esp8266/esp_mphal.c +++ b/esp8266/esp_mphal.c @@ -30,6 +30,7 @@ #include "uart.h" #include "esp_mphal.h" #include "user_interface.h" +#include "ets_alt_task.h" #include "py/obj.h" #include "py/mpstate.h" @@ -105,6 +106,15 @@ void mp_hal_set_interrupt_char(int c) { interrupt_char = c; } +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); + } +} + void __assert_func(const char *file, int line, const char *func, const char *expr) { printf("assert:%s:%d:%s: %s\n", file, line, func, expr); nlr_raise(mp_obj_new_exception_msg(&mp_type_AssertionError, diff --git a/esp8266/esp_mphal.h b/esp8266/esp_mphal.h index b335470de7..4edf266a50 100644 --- a/esp8266/esp_mphal.h +++ b/esp8266/esp_mphal.h @@ -39,5 +39,6 @@ uint32_t mp_hal_get_cpu_freq(void); #define UART_TASK_ID 0 void uart_task_init(); +void ets_event_poll(void); #endif // _INCLUDED_MPHAL_H_