From 785cf9a61f373ee871b4181c499d9d99ad081615 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 1 Apr 2016 14:02:36 +0300 Subject: [PATCH] esp8266: Support dedicated REPL loop (aka pull-style). Event-driven loop (push-style) is still supported and default (controlled by MICROPY_REPL_EVENT_DRIVEN setting, as expected). Dedicated loop worked even without adding ets_loop_iter(), though that needs to be revisited later. --- esp8266/esp_mphal.c | 4 +++- esp8266/main.c | 23 +++++++++++++++++++++++ esp8266/uart.c | 2 ++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/esp8266/esp_mphal.c b/esp8266/esp_mphal.c index 7068d8e609..2f813ca22f 100644 --- a/esp8266/esp_mphal.c +++ b/esp8266/esp_mphal.c @@ -66,7 +66,7 @@ void mp_hal_delay_us(uint32_t us) { int mp_hal_stdin_rx_chr(void) { for (;;) { - int c = uart0_rx(); + int c = ringbuf_get(&input_buf); if (c != -1) { return c; } @@ -156,7 +156,9 @@ void __assert_func(const char *file, int line, const char *func, const char *exp } void mp_hal_signal_input(void) { + #if MICROPY_REPL_EVENT_DRIVEN system_os_post(UART_TASK_ID, 0, 0); + #endif } static int call_dupterm_read(void) { diff --git a/esp8266/main.c b/esp8266/main.c index bb282462fd..de9df74135 100644 --- a/esp8266/main.c +++ b/esp8266/main.c @@ -62,15 +62,38 @@ void soft_reset(void) { mp_hal_stdout_tx_str("PYB: soft reboot\r\n"); mp_hal_delay_us(10000); // allow UART to flush output mp_reset(); + #if MICROPY_REPL_EVENT_DRIVEN pyexec_event_repl_init(); + #endif } void init_done(void) { + #if MICROPY_REPL_EVENT_DRIVEN uart_task_init(); + #endif mp_reset(); mp_hal_stdout_tx_str("\r\n"); + #if MICROPY_REPL_EVENT_DRIVEN pyexec_event_repl_init(); + #endif dupterm_task_init(); + + #if !MICROPY_REPL_EVENT_DRIVEN +soft_reset: + for (;;) { + if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) { + if (pyexec_raw_repl() != 0) { + break; + } + } else { + if (pyexec_friendly_repl() != 0) { + break; + } + } + } + soft_reset(); + goto soft_reset; + #endif } void user_init(void) { diff --git a/esp8266/uart.c b/esp8266/uart.c index 9b2bfb4c83..bfc380ae4a 100644 --- a/esp8266/uart.c +++ b/esp8266/uart.c @@ -233,6 +233,7 @@ void soft_reset(void); void mp_keyboard_interrupt(void); int interrupt_char; +#if MICROPY_REPL_EVENT_DRIVEN void uart_task_handler(os_event_t *evt) { if (pyexec_repl_active) { // TODO: Just returning here isn't exactly right. @@ -264,3 +265,4 @@ void uart_task_handler(os_event_t *evt) { void uart_task_init() { system_os_task(uart_task_handler, UART_TASK_ID, uart_evt_queue, sizeof(uart_evt_queue) / sizeof(*uart_evt_queue)); } +#endif