diff options
author | Damien George <damien.p.george@gmail.com> | 2017-09-04 17:32:14 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-09-04 17:32:14 +1000 |
commit | 689dae1211b4a3a6384a08ec2d7cdf2bb786d53a (patch) | |
tree | 487e0730ea4cd7b28f3cda8ade5c7d335ccbe3a7 | |
parent | ab9d7619fcad204b7f7d303e1663f70fd3fffc6a (diff) | |
download | micropython-689dae1211b4a3a6384a08ec2d7cdf2bb786d53a.tar.gz micropython-689dae1211b4a3a6384a08ec2d7cdf2bb786d53a.zip |
cc3200: Use standard implementation of keyboard interrupt.
-rw-r--r-- | cc3200/application.mk | 1 | ||||
-rw-r--r-- | cc3200/hal/cc3200_hal.c | 4 | ||||
-rw-r--r-- | cc3200/misc/mpexception.c | 51 | ||||
-rw-r--r-- | cc3200/misc/mpexception.h | 8 | ||||
-rw-r--r-- | cc3200/mods/pybuart.c | 5 | ||||
-rw-r--r-- | cc3200/mptask.c | 2 | ||||
-rw-r--r-- | cc3200/telnet/telnet.c | 5 |
7 files changed, 7 insertions, 69 deletions
diff --git a/cc3200/application.mk b/cc3200/application.mk index 3ac28823a1..64891a2e7d 100644 --- a/cc3200/application.mk +++ b/cc3200/application.mk @@ -147,6 +147,7 @@ APP_LIB_SRC_C = $(addprefix lib/,\ netutils/netutils.c \ timeutils/timeutils.c \ utils/pyexec.c \ + utils/interrupt_char.c \ utils/sys_stdio_mphal.c \ ) diff --git a/cc3200/hal/cc3200_hal.c b/cc3200/hal/cc3200_hal.c index b4848e99e8..9718980e75 100644 --- a/cc3200/hal/cc3200_hal.c +++ b/cc3200/hal/cc3200_hal.c @@ -143,10 +143,6 @@ void mp_hal_delay_ms(mp_uint_t delay) { } } -void mp_hal_set_interrupt_char (int c) { - mpexception_set_interrupt_char (c); -} - void mp_hal_stdout_tx_str(const char *str) { mp_hal_stdout_tx_strn(str, strlen(str)); } diff --git a/cc3200/misc/mpexception.c b/cc3200/misc/mpexception.c index 72b203fae3..2dfcbfdef9 100644 --- a/cc3200/misc/mpexception.c +++ b/cc3200/misc/mpexception.c @@ -33,59 +33,8 @@ /****************************************************************************** -DECLARE PRIVATE FUNCTIONS - ******************************************************************************/ -STATIC void mpexception_set_user_interrupt (int chr, void *data); - -/****************************************************************************** DECLARE EXPORTED DATA ******************************************************************************/ const char mpexception_value_invalid_arguments[] = "invalid argument(s) value"; const char mpexception_num_type_invalid_arguments[] = "invalid argument(s) num/type"; const char mpexception_uncaught[] = "uncaught exception"; - -int user_interrupt_char = -1; - -/****************************************************************************** -DECLARE PRIVATE DATA - ******************************************************************************/ -STATIC void *user_interrupt_data = NULL; - -/****************************************************************************** -DEFINE PUBLIC FUNCTIONS - ******************************************************************************/ - -void mpexception_init0 (void) { - // Create an exception object for interrupting through the stdin uart - MP_STATE_PORT(mp_const_user_interrupt) = mp_obj_new_exception(&mp_type_KeyboardInterrupt); - mpexception_set_user_interrupt (-1, MP_STATE_PORT(mp_const_user_interrupt)); -} - -void mpexception_set_interrupt_char (int c) { - if (c != -1) { - mp_obj_exception_clear_traceback(MP_STATE_PORT(mp_const_user_interrupt)); - } - mpexception_set_user_interrupt(c, MP_STATE_PORT(mp_const_user_interrupt)); -} - -// Call this function to raise a pending exception during an interrupt. -// It will try to raise the exception "softly" by setting the -// mp_pending_exception variable hoping that the VM will notice it. -void mpexception_nlr_jump (void *o) { - if (MP_STATE_PORT(mp_pending_exception) == MP_OBJ_NULL) { - MP_STATE_PORT(mp_pending_exception) = o; - } -} - -void mpexception_keyboard_nlr_jump (void) { - mpexception_nlr_jump (user_interrupt_data); -} - -/****************************************************************************** -DEFINE PRIVATE FUNCTIONS - ******************************************************************************/ - -STATIC void mpexception_set_user_interrupt (int chr, void *data) { - user_interrupt_char = chr; - user_interrupt_data = data; -} diff --git a/cc3200/misc/mpexception.h b/cc3200/misc/mpexception.h index 88134857c1..e84a1edb21 100644 --- a/cc3200/misc/mpexception.h +++ b/cc3200/misc/mpexception.h @@ -31,12 +31,4 @@ extern const char mpexception_value_invalid_arguments[]; extern const char mpexception_num_type_invalid_arguments[]; extern const char mpexception_uncaught[]; -extern int user_interrupt_char; - - -extern void mpexception_init0 (void); -extern void mpexception_set_interrupt_char (int c); -extern void mpexception_nlr_jump (void *o); -extern void mpexception_keyboard_nlr_jump (void); - #endif // MICROPY_INCLUDED_CC3200_MISC_MPEXCEPTION_H diff --git a/cc3200/mods/pybuart.c b/cc3200/mods/pybuart.c index ecd3d441bf..135e0f2a3d 100644 --- a/cc3200/mods/pybuart.c +++ b/cc3200/mods/pybuart.c @@ -35,6 +35,7 @@ #include "py/objlist.h" #include "py/stream.h" #include "py/mphal.h" +#include "lib/utils/interrupt_char.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" #include "inc/hw_memmap.h" @@ -251,9 +252,9 @@ STATIC void UARTGenericIntHandler(uint32_t uart_id) { MAP_UARTIntClear(self->reg, UART_INT_RX | UART_INT_RT); while (UARTCharsAvail(self->reg)) { int data = MAP_UARTCharGetNonBlocking(self->reg); - if (MP_STATE_PORT(os_term_dup_obj) && MP_STATE_PORT(os_term_dup_obj)->stream_o == self && data == user_interrupt_char) { + if (MP_STATE_PORT(os_term_dup_obj) && MP_STATE_PORT(os_term_dup_obj)->stream_o == self && data == mp_interrupt_char) { // raise an exception when interrupts are finished - mpexception_keyboard_nlr_jump(); + mp_keyboard_interrupt(); } else { // there's always a read buffer available uint16_t next_head = (self->read_buf_head + 1) % PYBUART_RX_BUFFER_LEN; if (next_head != self->read_buf_tail) { diff --git a/cc3200/mptask.c b/cc3200/mptask.c index 09be8c441d..6143f72a7a 100644 --- a/cc3200/mptask.c +++ b/cc3200/mptask.c @@ -61,7 +61,6 @@ #include "telnet.h" #include "debug.h" #include "sflash_diskio.h" -#include "mpexception.h" #include "random.h" #include "pybi2c.h" #include "pins.h" @@ -143,7 +142,6 @@ soft_reset: mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script) // execute all basic initializations - mpexception_init0(); mp_irq_init0(); pyb_sleep_init0(); pin_init0(); diff --git a/cc3200/telnet/telnet.c b/cc3200/telnet/telnet.c index 2f0818f6ba..dbb77cd6d7 100644 --- a/cc3200/telnet/telnet.c +++ b/cc3200/telnet/telnet.c @@ -29,6 +29,7 @@ #include "py/mpconfig.h" #include "py/obj.h" #include "py/mphal.h" +#include "lib/utils/interrupt_char.h" #include "telnet.h" #include "simplelink.h" #include "modnetwork.h" @@ -445,9 +446,9 @@ static void telnet_parse_input (uint8_t *str, int16_t *len) { for (uint8_t *_str = b_str; _str < b_str + b_len; ) { if (*_str <= 127) { - if (telnet_data.state == E_TELNET_STE_LOGGED_IN && *_str == user_interrupt_char) { + if (telnet_data.state == E_TELNET_STE_LOGGED_IN && *_str == mp_interrupt_char) { // raise a keyboard exception - mpexception_keyboard_nlr_jump(); + mp_keyboard_interrupt(); (*len)--; _str++; } |