diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-09-29 10:13:17 -0700 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-09-29 10:15:38 -0700 |
commit | 6ab2c5e6cc6359c3419a9d8ee61b4e586864d048 (patch) | |
tree | b27471a8e09a8cff12978cc7930a3ddf31cb2cde /esp8266 | |
parent | 53bfcc9e848c43e58694c7cb7a2356b31fc67445 (diff) | |
download | micropython-6ab2c5e6cc6359c3419a9d8ee61b4e586864d048.tar.gz micropython-6ab2c5e6cc6359c3419a9d8ee61b4e586864d048.zip |
lib/interrupt_char: Factor out typical Ctrl+C handling from esp8266 port.
Utility functions for keyboard interrupt handling, to be reused across
(baremetal) ports.
Diffstat (limited to 'esp8266')
-rw-r--r-- | esp8266/Makefile | 1 | ||||
-rw-r--r-- | esp8266/esp_mphal.c | 10 | ||||
-rw-r--r-- | esp8266/esp_mphal.h | 2 | ||||
-rw-r--r-- | esp8266/main.c | 4 | ||||
-rw-r--r-- | esp8266/uart.c | 4 |
5 files changed, 4 insertions, 17 deletions
diff --git a/esp8266/Makefile b/esp8266/Makefile index 26b5e8626b..9008f20365 100644 --- a/esp8266/Makefile +++ b/esp8266/Makefile @@ -128,6 +128,7 @@ LIB_SRC_C = $(addprefix lib/,\ timeutils/timeutils.c \ utils/pyexec.c \ utils/pyhelp.c \ + utils/interrupt_char.c \ fatfs/ff.c \ fatfs/option/ccsbcs.c \ ) diff --git a/esp8266/esp_mphal.c b/esp8266/esp_mphal.c index b0755239fc..f5e284fde6 100644 --- a/esp8266/esp_mphal.c +++ b/esp8266/esp_mphal.c @@ -128,14 +128,6 @@ void mp_hal_delay_ms(uint32_t delay) { mp_hal_delay_us(delay * 1000); } -void mp_hal_set_interrupt_char(int c) { - if (c != -1) { - mp_obj_exception_clear_traceback(MP_STATE_PORT(mp_kbd_exception)); - } - extern int interrupt_char; - interrupt_char = c; -} - void ets_event_poll(void) { ets_loop_iter(); if (MP_STATE_VM(mp_pending_exception) != NULL) { @@ -180,7 +172,7 @@ static int call_dupterm_read(void) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(MP_STATE_PORT(dupterm_arr_obj), &bufinfo, MP_BUFFER_READ); nlr_pop(); - if (*(byte*)bufinfo.buf == interrupt_char) { + if (*(byte*)bufinfo.buf == mp_interrupt_char) { mp_keyboard_interrupt(); return -2; } diff --git a/esp8266/esp_mphal.h b/esp8266/esp_mphal.h index fa52ae53a2..7a71c0f032 100644 --- a/esp8266/esp_mphal.h +++ b/esp8266/esp_mphal.h @@ -28,10 +28,10 @@ #define _INCLUDED_MPHAL_H_ #include "py/ringbuf.h" +#include "lib/utils/interrupt_char.h" #include "xtirq.h" void mp_keyboard_interrupt(void); -extern int interrupt_char; struct _mp_print_t; // Structure for UART-only output via mp_printf() diff --git a/esp8266/main.c b/esp8266/main.c index 71dfeb2ac6..22abb22d78 100644 --- a/esp8266/main.c +++ b/esp8266/main.c @@ -141,10 +141,6 @@ mp_obj_t mp_builtin_open(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) { } MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open); -void mp_keyboard_interrupt(void) { - MP_STATE_VM(mp_pending_exception) = MP_STATE_PORT(mp_kbd_exception); -} - void nlr_jump_fail(void *val) { printf("NLR jump failed\n"); for (;;) { diff --git a/esp8266/uart.c b/esp8266/uart.c index d724331c41..001a9c673c 100644 --- a/esp8266/uart.c +++ b/esp8266/uart.c @@ -39,8 +39,6 @@ static void uart0_rx_intr_handler(void *para); void soft_reset(void); void mp_keyboard_interrupt(void); -int interrupt_char; - /****************************************************************************** * FunctionName : uart_config * Description : Internal used function @@ -172,7 +170,7 @@ static void uart0_rx_intr_handler(void *para) { while (READ_PERI_REG(UART_STATUS(uart_no)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S)) { uint8 RcvChar = READ_PERI_REG(UART_FIFO(uart_no)) & 0xff; - if (RcvChar == interrupt_char) { + if (RcvChar == mp_interrupt_char) { mp_keyboard_interrupt(); } else { ringbuf_put(&input_buf, RcvChar); |