added Ctrl+C interrupt

This commit is contained in:
hathach 2017-12-29 22:43:31 +07:00
parent a021a9e5f0
commit 7f79a0e78c
3 changed files with 122 additions and 110 deletions

View File

@ -151,6 +151,7 @@ SRC_C += \
lib/timeutils/timeutils.c \ lib/timeutils/timeutils.c \
lib/utils/buffer_helper.c \ lib/utils/buffer_helper.c \
lib/utils/context_manager_helpers.c \ lib/utils/context_manager_helpers.c \
lib/utils/interrupt_char.c \
lib/utils/pyexec.c \ lib/utils/pyexec.c \
lib/libc/string0.c \ lib/libc/string0.c \
lib/mp-readline/readline.c \ lib/mp-readline/readline.c \

View File

@ -32,6 +32,8 @@
#include "hal_uart.h" #include "hal_uart.h"
#include "fifo.h" #include "fifo.h"
#include "lib/utils/interrupt_char.h"
#ifdef HAL_UART_MODULE_ENABLED #ifdef HAL_UART_MODULE_ENABLED
FIFO_DEF(_ff_uart, 128, uint8_t, true, UARTE0_UART0_IRQn); FIFO_DEF(_ff_uart, 128, uint8_t, true, UARTE0_UART0_IRQn);
@ -162,7 +164,15 @@ void UARTE0_UART0_IRQHandler(void)
if (p_instance->EVENTS_RXDRDY) if (p_instance->EVENTS_RXDRDY)
{ {
uint8_t ch = (uint8_t) p_instance->RXD; uint8_t ch = (uint8_t) p_instance->RXD;
fifo_write(_ff_uart, &ch);
// Keyboard interrupt
if (mp_interrupt_char != -1 && ch == mp_interrupt_char)
{
mp_keyboard_interrupt();
}else
{
fifo_write(_ff_uart, &ch);
}
p_instance->EVENTS_RXDRDY = 0x0UL; p_instance->EVENTS_RXDRDY = 0x0UL;
} }

View File

@ -30,46 +30,45 @@
#include <mpconfigboard.h> #include <mpconfigboard.h>
// options to control how MicroPython is built // options to control how MicroPython is built
#define MICROPY_ALLOC_PATH_MAX (512) #define MICROPY_ALLOC_PATH_MAX (512)
#define MICROPY_PERSISTENT_CODE_LOAD (1) #define MICROPY_PERSISTENT_CODE_LOAD (1)
#define MICROPY_EMIT_THUMB (0) #define MICROPY_EMIT_THUMB (0)
#define MICROPY_EMIT_INLINE_THUMB (0) #define MICROPY_EMIT_INLINE_THUMB (0)
#define MICROPY_COMP_MODULE_CONST (0) #define MICROPY_COMP_MODULE_CONST (0)
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0) #define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0)
#define MICROPY_READER_VFS (MICROPY_VFS) #define MICROPY_READER_VFS (MICROPY_VFS)
#define MICROPY_ENABLE_GC (1) #define MICROPY_ENABLE_GC (1)
#define MICROPY_ENABLE_FINALISER (1) #define MICROPY_ENABLE_FINALISER (1)
#define MICROPY_STACK_CHECK (0) #define MICROPY_STACK_CHECK (0)
#define MICROPY_HELPER_REPL (1) #define MICROPY_HELPER_REPL (1)
#define MICROPY_REPL_EMACS_KEYS (0) #define MICROPY_REPL_EMACS_KEYS (0)
#define MICROPY_REPL_AUTO_INDENT (1) #define MICROPY_REPL_AUTO_INDENT (1)
#define MICROPY_ENABLE_SOURCE_LINE (0) #define MICROPY_ENABLE_SOURCE_LINE (0)
//CP UPDATE: See mpconfigport.h for LONGINT implementation //CP UPDATE: See mpconfigport.h for LONGINT implementation
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
#if NRF51 #if NRF51
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE) #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE)
#else #else
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
#endif #endif
#define MICROPY_OPT_COMPUTED_GOTO (0) #define MICROPY_OPT_COMPUTED_GOTO (0)
#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (0) #define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (0)
#define MICROPY_OPT_MPZ_BITWISE (0) #define MICROPY_OPT_MPZ_BITWISE (0)
// fatfs configuration used in ffconf.h // fatfs configuration used in ffconf.h
#define MICROPY_FATFS_ENABLE_LFN (1) #define MICROPY_FATFS_ENABLE_LFN (1)
#define MICROPY_FATFS_LFN_CODE_PAGE (437) /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */ #define MICROPY_FATFS_LFN_CODE_PAGE (437) /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */
#define MICROPY_FATFS_USE_LABEL (1) #define MICROPY_FATFS_USE_LABEL (1)
#define MICROPY_FATFS_RPATH (2) #define MICROPY_FATFS_RPATH (2)
#define MICROPY_FATFS_MULTI_PARTITION (0) #define MICROPY_FATFS_MULTI_PARTITION (0)
#define MICROPY_FATFS_NUM_PERSISTENT (1) #define MICROPY_FATFS_NUM_PERSISTENT (1)
//#define MICROPY_FATFS_MAX_SS (4096) //#define MICROPY_FATFS_MAX_SS (4096)
#define FILESYSTEM_BLOCK_SIZE (512)
#define FILESYSTEM_BLOCK_SIZE 512 #define MICROPY_VFS (1)
#define MICROPY_VFS_FAT (MICROPY_VFS)
#define MICROPY_VFS (1)
#define MICROPY_VFS_FAT (MICROPY_VFS)
// TODO these should be generic, not bound to fatfs // TODO these should be generic, not bound to fatfs
#define mp_type_fileio fatfs_type_fileio #define mp_type_fileio fatfs_type_fileio
@ -82,101 +81,104 @@
#define mp_builtin_open_obj mp_vfs_open_obj #define mp_builtin_open_obj mp_vfs_open_obj
#endif #endif
#define MICROPY_STREAMS_NON_BLOCK (1) #define MICROPY_STREAMS_NON_BLOCK (1)
#define MICROPY_MODULE_WEAK_LINKS (1) #define MICROPY_MODULE_WEAK_LINKS (1)
#define MICROPY_CAN_OVERRIDE_BUILTINS (1) #define MICROPY_CAN_OVERRIDE_BUILTINS (1)
#define MICROPY_USE_INTERNAL_ERRNO (1) #define MICROPY_USE_INTERNAL_ERRNO (1)
#define MICROPY_PY_FUNCTION_ATTRS (1) #define MICROPY_PY_FUNCTION_ATTRS (1)
#define MICROPY_PY_BUILTINS_STR_UNICODE (1) #define MICROPY_PY_BUILTINS_STR_UNICODE (1)
#define MICROPY_PY_BUILTINS_STR_CENTER (0) #define MICROPY_PY_BUILTINS_STR_CENTER (0)
#define MICROPY_PY_BUILTINS_STR_PARTITION (0) #define MICROPY_PY_BUILTINS_STR_PARTITION (0)
#define MICROPY_PY_BUILTINS_STR_SPLITLINES (0) #define MICROPY_PY_BUILTINS_STR_SPLITLINES (0)
#define MICROPY_PY_BUILTINS_MEMORYVIEW (1) #define MICROPY_PY_BUILTINS_MEMORYVIEW (1)
#define MICROPY_PY_BUILTINS_FROZENSET (1) #define MICROPY_PY_BUILTINS_FROZENSET (1)
#define MICROPY_PY_BUILTINS_EXECFILE (0) #define MICROPY_PY_BUILTINS_EXECFILE (0)
#define MICROPY_PY_BUILTINS_COMPILE (1) #define MICROPY_PY_BUILTINS_COMPILE (1)
#define MICROPY_PY_BUILTINS_HELP (1) #define MICROPY_PY_BUILTINS_HELP (1)
#define MICROPY_PY_BUILTINS_HELP_TEXT nrf5_help_text #define MICROPY_PY_BUILTINS_HELP_TEXT nrf5_help_text
#define MICROPY_PY_BUILTINS_HELP_MODULES (1) #define MICROPY_PY_BUILTINS_HELP_MODULES (1)
#define MICROPY_MODULE_BUILTIN_INIT (1) #define MICROPY_PY_BUILTINS_INPUT (1)
#define MICROPY_PY_ALL_SPECIAL_METHODS (0) #define MICROPY_MODULE_BUILTIN_INIT (1)
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1) #define MICROPY_PY_ALL_SPECIAL_METHODS (0)
#define MICROPY_PY_ARRAY_SLICE_ASSIGN (0) #define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
#define MICROPY_PY_BUILTINS_SLICE_ATTRS (0) #define MICROPY_PY_ARRAY_SLICE_ASSIGN (0)
#define MICROPY_PY_SYS_EXIT (1) #define MICROPY_PY_BUILTINS_SLICE_ATTRS (0)
#define MICROPY_PY_SYS_MAXSIZE (1) #define MICROPY_PY_SYS_EXIT (1)
#define MICROPY_PY_SYS_STDFILES (0) #define MICROPY_PY_SYS_MAXSIZE (1)
#define MICROPY_PY_SYS_STDIO_BUFFER (0) #define MICROPY_PY_SYS_STDFILES (0)
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (0) #define MICROPY_PY_SYS_STDIO_BUFFER (0)
#define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (0) #define MICROPY_PY_COLLECTIONS_ORDEREDDICT (0)
#define MICROPY_PY_CMATH (0) #define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (0)
#define MICROPY_PY_IO (0) #define MICROPY_PY_CMATH (0)
#define MICROPY_PY_IO_FILEIO (0) #define MICROPY_PY_IO (0)
#define MICROPY_PY_UERRNO (0) #define MICROPY_PY_IO_FILEIO (0)
#define MICROPY_PY_UBINASCII (0) #define MICROPY_PY_UERRNO (0)
#define MICROPY_PY_URANDOM (0) #define MICROPY_PY_UBINASCII (0)
#define MICROPY_PY_URANDOM_EXTRA_FUNCS (0) #define MICROPY_PY_URANDOM (0)
#define MICROPY_PY_UCTYPES (0) #define MICROPY_PY_URANDOM_EXTRA_FUNCS (0)
#define MICROPY_PY_UZLIB (0) #define MICROPY_PY_UCTYPES (0)
#define MICROPY_PY_UJSON (0) #define MICROPY_PY_UZLIB (0)
#define MICROPY_PY_URE (0) #define MICROPY_PY_UJSON (0)
#define MICROPY_PY_UHEAPQ (0) #define MICROPY_PY_URE (0)
#define MICROPY_PY_UHASHLIB (0) #define MICROPY_PY_UHEAPQ (0)
#define MICROPY_PY_UTIME_MP_HAL (1) #define MICROPY_PY_UHASHLIB (0)
#define MICROPY_PY_MACHINE (1) #define MICROPY_PY_UTIME_MP_HAL (1)
#define MICROPY_PY_MACHINE_PULSE (0) #define MICROPY_PY_MACHINE (1)
#define MICROPY_PY_MACHINE_I2C_MAKE_NEW machine_hard_i2c_make_new #define MICROPY_PY_MACHINE_PULSE (0)
#define MICROPY_PY_MACHINE_SPI (0) #define MICROPY_PY_MACHINE_I2C_MAKE_NEW machine_hard_i2c_make_new
#define MICROPY_PY_MACHINE_SPI_MIN_DELAY (0) #define MICROPY_PY_MACHINE_SPI (0)
#define MICROPY_PY_FRAMEBUF (0) #define MICROPY_PY_MACHINE_SPI_MIN_DELAY (0)
#define MICROPY_PY_FRAMEBUF (0)
#define MICROPY_KBD_EXCEPTION (1)
#ifndef MICROPY_HW_LED_COUNT #ifndef MICROPY_HW_LED_COUNT
#define MICROPY_HW_LED_COUNT (0) #define MICROPY_HW_LED_COUNT (0)
#endif #endif
#ifndef MICROPY_HW_LED_PULLUP #ifndef MICROPY_HW_LED_PULLUP
#define MICROPY_HW_LED_PULLUP (0) #define MICROPY_HW_LED_PULLUP (0)
#endif #endif
#ifndef MICROPY_PY_MUSIC #ifndef MICROPY_PY_MUSIC
#define MICROPY_PY_MUSIC (0) #define MICROPY_PY_MUSIC (0)
#endif #endif
#ifndef MICROPY_PY_MACHINE_ADC #ifndef MICROPY_PY_MACHINE_ADC
#define MICROPY_PY_MACHINE_ADC (0) #define MICROPY_PY_MACHINE_ADC (0)
#endif #endif
#ifndef MICROPY_PY_MACHINE_I2C #ifndef MICROPY_PY_MACHINE_I2C
#define MICROPY_PY_MACHINE_I2C (0) #define MICROPY_PY_MACHINE_I2C (0)
#endif #endif
#ifndef MICROPY_PY_MACHINE_HW_SPI #ifndef MICROPY_PY_MACHINE_HW_SPI
#define MICROPY_PY_MACHINE_HW_SPI (1) #define MICROPY_PY_MACHINE_HW_SPI (1)
#endif #endif
#ifndef MICROPY_PY_MACHINE_HW_PWM #ifndef MICROPY_PY_MACHINE_HW_PWM
#define MICROPY_PY_MACHINE_HW_PWM (0) #define MICROPY_PY_MACHINE_HW_PWM (0)
#endif #endif
#ifndef MICROPY_PY_MACHINE_SOFT_PWM #ifndef MICROPY_PY_MACHINE_SOFT_PWM
#define MICROPY_PY_MACHINE_SOFT_PWM (0) #define MICROPY_PY_MACHINE_SOFT_PWM (0)
#endif #endif
#ifndef MICROPY_PY_MACHINE_TIMER #ifndef MICROPY_PY_MACHINE_TIMER
#define MICROPY_PY_MACHINE_TIMER (0) #define MICROPY_PY_MACHINE_TIMER (0)
#endif #endif
#ifndef MICROPY_PY_MACHINE_RTC #ifndef MICROPY_PY_MACHINE_RTC
#define MICROPY_PY_MACHINE_RTC (0) #define MICROPY_PY_MACHINE_RTC (0)
#endif #endif
#ifndef MICROPY_PY_HW_RNG #ifndef MICROPY_PY_HW_RNG
#define MICROPY_PY_HW_RNG (1) #define MICROPY_PY_HW_RNG (1)
#endif #endif
#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0) #define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0)
// if sdk is in use, import configuration // if sdk is in use, import configuration
#if BLUETOOTH_SD #if BLUETOOTH_SD
@ -256,39 +258,38 @@ extern const struct _mp_obj_module_t ble_module;
#endif #endif
#define MICROPY_PORT_BUILTIN_MODULES \ #define MICROPY_PORT_BUILTIN_MODULES \
{ MP_OBJ_NEW_QSTR(MP_QSTR_board), (mp_obj_t)&board_module }, \ { MP_OBJ_NEW_QSTR (MP_QSTR_board ), (mp_obj_t)&board_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_busio), (mp_obj_t)&busio_module }, \ { MP_OBJ_NEW_QSTR (MP_QSTR_busio ), (mp_obj_t)&busio_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_analogio), (mp_obj_t)&analogio_module }, \ { MP_OBJ_NEW_QSTR (MP_QSTR_analogio ), (mp_obj_t)&analogio_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_digitalio), (mp_obj_t)&digitalio_module }, \ { MP_OBJ_NEW_QSTR (MP_QSTR_digitalio ), (mp_obj_t)&digitalio_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_pulseio), (mp_obj_t)&pulseio_module }, \ { MP_OBJ_NEW_QSTR (MP_QSTR_pulseio ), (mp_obj_t)&pulseio_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_microcontroller), (mp_obj_t)&microcontroller_module }, \ { MP_OBJ_NEW_QSTR (MP_QSTR_microcontroller ), (mp_obj_t)&microcontroller_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&os_module }, \ { MP_OBJ_NEW_QSTR (MP_QSTR_os ), (mp_obj_t)&os_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_random), (mp_obj_t)&random_module }, \ { MP_OBJ_NEW_QSTR (MP_QSTR_random ), (mp_obj_t)&random_module }, \
/*{ MP_OBJ_NEW_QSTR(MP_QSTR_storage), (mp_obj_t)&storage_module },*/\ { MP_OBJ_NEW_QSTR (MP_QSTR_storage ), (mp_obj_t)&storage_module },\
{ MP_ROM_QSTR(MP_QSTR_pyb), MP_ROM_PTR(&pyb_module) }, \ { MP_OBJ_NEW_QSTR (MP_QSTR_supervisor ), (mp_obj_t)&supervisor_module }, \
{ MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&machine_module) }, \ { MP_OBJ_NEW_QSTR (MP_QSTR_time ), (mp_obj_t)&time_module }, \
{ MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&mp_module_utime) }, \ { MP_ROM_QSTR (MP_QSTR_pyb ), MP_ROM_PTR(&pyb_module) }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_supervisor), (mp_obj_t)&supervisor_module }, \ { MP_ROM_QSTR (MP_QSTR_utime ), MP_ROM_PTR(&mp_module_utime) }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module }, \
MUSIC_MODULE \ MUSIC_MODULE \
RANDOM_MODULE \ RANDOM_MODULE \
/*BLE_MODULE \ /*BLE_MODULE \
UBLUEPY_MODULE \*/ UBLUEPY_MODULE \*/
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \ #define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mp_module_utime) }, \ { MP_ROM_QSTR (MP_QSTR_time ), MP_ROM_PTR(&mp_module_utime) }, \
// extra built in names to add to the global namespace // extra built in names to add to the global namespace
#define MICROPY_PORT_BUILTINS \ #define MICROPY_PORT_BUILTINS \
{ MP_ROM_QSTR(MP_QSTR_help), MP_ROM_PTR(&mp_builtin_help_obj) }, \ { MP_ROM_QSTR (MP_QSTR_help), MP_ROM_PTR(&mp_builtin_help_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, \ { MP_OBJ_NEW_QSTR (MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \
{ MP_ROM_QSTR (MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, \
// extra constants // extra constants
#define MICROPY_PORT_CONSTANTS \ #define MICROPY_PORT_CONSTANTS \
{ MP_ROM_QSTR(MP_QSTR_pyb), MP_ROM_PTR(&pyb_module) }, \ { MP_ROM_QSTR (MP_QSTR_pyb ), MP_ROM_PTR(&pyb_module) }, \
{ MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&machine_module) }, \ { MP_ROM_QSTR (MP_QSTR_machine ), MP_ROM_PTR(&machine_module) }, \
BLE_MODULE \ BLE_MODULE \
#define MP_STATE_PORT MP_STATE_VM #define MP_STATE_PORT MP_STATE_VM