cc3200: Use standard implementation of keyboard interrupt.

This commit is contained in:
Damien George 2017-09-04 17:32:14 +10:00
parent ab9d7619fc
commit 689dae1211
7 changed files with 7 additions and 69 deletions

View File

@ -147,6 +147,7 @@ APP_LIB_SRC_C = $(addprefix lib/,\
netutils/netutils.c \ netutils/netutils.c \
timeutils/timeutils.c \ timeutils/timeutils.c \
utils/pyexec.c \ utils/pyexec.c \
utils/interrupt_char.c \
utils/sys_stdio_mphal.c \ utils/sys_stdio_mphal.c \
) )

View File

@ -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) { void mp_hal_stdout_tx_str(const char *str) {
mp_hal_stdout_tx_strn(str, strlen(str)); mp_hal_stdout_tx_strn(str, strlen(str));
} }

View File

@ -32,60 +32,9 @@
#include "mpexception.h" #include "mpexception.h"
/******************************************************************************
DECLARE PRIVATE FUNCTIONS
******************************************************************************/
STATIC void mpexception_set_user_interrupt (int chr, void *data);
/****************************************************************************** /******************************************************************************
DECLARE EXPORTED DATA DECLARE EXPORTED DATA
******************************************************************************/ ******************************************************************************/
const char mpexception_value_invalid_arguments[] = "invalid argument(s) value"; 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_num_type_invalid_arguments[] = "invalid argument(s) num/type";
const char mpexception_uncaught[] = "uncaught exception"; 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;
}

View File

@ -31,12 +31,4 @@ extern const char mpexception_value_invalid_arguments[];
extern const char mpexception_num_type_invalid_arguments[]; extern const char mpexception_num_type_invalid_arguments[];
extern const char mpexception_uncaught[]; 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 #endif // MICROPY_INCLUDED_CC3200_MISC_MPEXCEPTION_H

View File

@ -35,6 +35,7 @@
#include "py/objlist.h" #include "py/objlist.h"
#include "py/stream.h" #include "py/stream.h"
#include "py/mphal.h" #include "py/mphal.h"
#include "lib/utils/interrupt_char.h"
#include "inc/hw_types.h" #include "inc/hw_types.h"
#include "inc/hw_ints.h" #include "inc/hw_ints.h"
#include "inc/hw_memmap.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); MAP_UARTIntClear(self->reg, UART_INT_RX | UART_INT_RT);
while (UARTCharsAvail(self->reg)) { while (UARTCharsAvail(self->reg)) {
int data = MAP_UARTCharGetNonBlocking(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 // raise an exception when interrupts are finished
mpexception_keyboard_nlr_jump(); mp_keyboard_interrupt();
} else { // there's always a read buffer available } else { // there's always a read buffer available
uint16_t next_head = (self->read_buf_head + 1) % PYBUART_RX_BUFFER_LEN; uint16_t next_head = (self->read_buf_head + 1) % PYBUART_RX_BUFFER_LEN;
if (next_head != self->read_buf_tail) { if (next_head != self->read_buf_tail) {

View File

@ -61,7 +61,6 @@
#include "telnet.h" #include "telnet.h"
#include "debug.h" #include "debug.h"
#include "sflash_diskio.h" #include "sflash_diskio.h"
#include "mpexception.h"
#include "random.h" #include "random.h"
#include "pybi2c.h" #include "pybi2c.h"
#include "pins.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) 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 // execute all basic initializations
mpexception_init0();
mp_irq_init0(); mp_irq_init0();
pyb_sleep_init0(); pyb_sleep_init0();
pin_init0(); pin_init0();

View File

@ -29,6 +29,7 @@
#include "py/mpconfig.h" #include "py/mpconfig.h"
#include "py/obj.h" #include "py/obj.h"
#include "py/mphal.h" #include "py/mphal.h"
#include "lib/utils/interrupt_char.h"
#include "telnet.h" #include "telnet.h"
#include "simplelink.h" #include "simplelink.h"
#include "modnetwork.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; ) { for (uint8_t *_str = b_str; _str < b_str + b_len; ) {
if (*_str <= 127) { 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 // raise a keyboard exception
mpexception_keyboard_nlr_jump(); mp_keyboard_interrupt();
(*len)--; (*len)--;
_str++; _str++;
} }