esp8266: Support raising KeyboardInterrupt on Ctrl+C.

This commit is contained in:
Paul Sokolovsky 2015-12-20 13:58:58 +02:00
parent 077448328a
commit d3a4d39687
4 changed files with 16 additions and 1 deletions

View File

@ -98,7 +98,11 @@ void mp_hal_delay_ms(uint32_t delay) {
}
void mp_hal_set_interrupt_char(int c) {
// TODO
if (c != -1) {
mp_obj_exception_clear_traceback(MP_STATE_PORT(mp_kbd_exception));
}
extern int interrupt_char;
interrupt_char = c;
}
void __assert_func(const char *file, int line, const char *func, const char *expr) {

View File

@ -47,6 +47,7 @@ STATIC void mp_reset(void) {
mp_init();
mp_obj_list_init(mp_sys_path, 0);
mp_obj_list_init(mp_sys_argv, 0);
MP_STATE_PORT(mp_kbd_exception) = mp_obj_new_exception(&mp_type_KeyboardInterrupt);
#if MICROPY_MODULE_FROZEN
pyexec_frozen_module("main");
#endif
@ -83,6 +84,10 @@ 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 (;;) {

View File

@ -99,6 +99,7 @@ extern const struct _mp_obj_module_t mp_module_machine;
#define MICROPY_PORT_ROOT_POINTERS \
const char *readline_hist[8]; \
mp_obj_t mp_kbd_exception; \
\
/* Singleton instance of scan callback, meaning that there can
be only one concurrent AP scan. */ \

View File

@ -210,10 +210,15 @@ void ICACHE_FLASH_ATTR uart_reattach() {
#include "lib/utils/pyexec.h"
void soft_reset(void);
void mp_keyboard_interrupt(void);
int interrupt_char;
void uart_task_handler(os_event_t *evt) {
int c, ret = 0;
while ((c = uart_rx_one_char(UART_REPL)) >= 0) {
if (c == interrupt_char) {
mp_keyboard_interrupt();
}
ret = pyexec_event_repl_process_char(c);
if (ret & PYEXEC_FORCED_EXIT) {
break;