Revert "Allow main.py to be interrupted by ctrl-C" (#381)

* Revert "Read serial input as a background task so we can check for the interrupt character."

This reverts commit 046092e8a2.

* Revert "Check INTERNAL_LIBM make flag in a safer way."

This reverts commit 2b80add22f.
This commit is contained in:
Dan Halbert 2017-10-27 17:14:57 -04:00
parent 2487226dff
commit 7f88ba3b26
6 changed files with 13 additions and 28 deletions

1
main.c
View File

@ -127,7 +127,6 @@ bool start_mp(safe_mode_t safe_mode) {
pyexec_result_t result; pyexec_result_t result;
bool found_main = false; bool found_main = false;
if (safe_mode != NO_SAFE_MODE) { if (safe_mode != NO_SAFE_MODE) {
serial_write(MSG_SAFE_MODE_NO_MAIN); serial_write(MSG_SAFE_MODE_NO_MAIN);
} else { } else {

View File

@ -238,10 +238,10 @@ SRC_C = \
# Choose which flash filesystem impl to use. # Choose which flash filesystem impl to use.
# (Right now INTERNAL_FLASH_FILESYSTEM and SPI_FLASH_FILESYSTEM are mutually exclusive. # (Right now INTERNAL_FLASH_FILESYSTEM and SPI_FLASH_FILESYSTEM are mutually exclusive.
# But that might not be true in the future.) # But that might not be true in the future.)
ifeq ($(INTERNAL_FLASH_FILESYSTEM),1) ifdef INTERNAL_FLASH_FILESYSTEM
SRC_C += internal_flash.c SRC_C += internal_flash.c
endif endif
ifeq ($(SPI_FLASH_FILESYSTEM),1) ifdef SPI_FLASH_FILESYSTEM
SRC_C += spi_flash.c SRC_C += spi_flash.c
endif endif
@ -278,7 +278,7 @@ SRC_COMMON_HAL = \
usb_hid/__init__.c \ usb_hid/__init__.c \
usb_hid/Device.c usb_hid/Device.c
ifeq ($(INTERNAL_LIBM),1) ifdef INTERNAL_LIBM
SRC_LIBM = $(addprefix lib/,\ SRC_LIBM = $(addprefix lib/,\
libm/math.c \ libm/math.c \
libm/fmodf.c \ libm/fmodf.c \
@ -338,7 +338,7 @@ OBJ = $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_ASF:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_ASF:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o))
ifeq ($(INTERNAL_LIBM),1) ifdef INTERNAL_LIBM
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
endif endif

View File

@ -26,11 +26,9 @@
#include "background.h" #include "background.h"
// #include "common-hal/audioio/AudioOut.h" // #include "common-hal/audioio/AudioOut.h"
#include "usb.h"
#include "usb_mass_storage.h" #include "usb_mass_storage.h"
void run_background_tasks(void) { void run_background_tasks(void) {
// audioout_background(); // audioout_background();
usb_msc_background(); usb_msc_background();
usb_cdc_background();
} }

View File

@ -3,5 +3,5 @@
# This should correspond to the MICROPY_LONGINT_IMPL definition in mpconfigport.h. # This should correspond to the MICROPY_LONGINT_IMPL definition in mpconfigport.h.
MPY_TOOL_LONGINT_IMPL = -mlongint-impl=none MPY_TOOL_LONGINT_IMPL = -mlongint-impl=none
INTERNAL_LIBM = 1 INTERNAL_LIBM = (1)

View File

@ -56,13 +56,13 @@
static uint8_t usb_rx_buf[USB_RX_BUF_SIZE]; static uint8_t usb_rx_buf[USB_RX_BUF_SIZE];
// Receive buffer head // Receive buffer head
static volatile uint8_t usb_rx_buf_head = 0; static volatile uint8_t usb_rx_buf_head;
// Receive buffer tail // Receive buffer tail
static volatile uint8_t usb_rx_buf_tail = 0; static volatile uint8_t usb_rx_buf_tail;
// Number of bytes in receive buffer // Number of bytes in receive buffer
volatile uint8_t usb_rx_count = 0; volatile uint8_t usb_rx_count;
volatile bool mp_cdc_enabled = false; volatile bool mp_cdc_enabled = false;
volatile bool usb_transmitting = false; volatile bool usb_transmitting = false;
@ -133,11 +133,8 @@ static bool read_complete(const uint8_t ep, const enum usb_xfer_code rc, const u
uint8_t c = cdc_packet_buffer[i]; uint8_t c = cdc_packet_buffer[i];
if (c == mp_interrupt_char) { if (c == mp_interrupt_char) {
mp_keyboard_interrupt(); mp_keyboard_interrupt();
// If interrupted, flush all the input. // Don't put the interrupt into the buffer, just continue.
usb_rx_count = 0; continue;
usb_rx_buf_head = 0;
usb_rx_buf_tail = 0;
break;
} else { } else {
// The count of characters present in receive buffer is // The count of characters present in receive buffer is
// incremented. // incremented.
@ -147,7 +144,7 @@ static bool read_complete(const uint8_t ep, const enum usb_xfer_code rc, const u
if (usb_rx_buf_tail == USB_RX_BUF_SIZE) { if (usb_rx_buf_tail == USB_RX_BUF_SIZE) {
// Reached the end of buffer, revert back to beginning of // Reached the end of buffer, revert back to beginning of
// buffer. // buffer.
usb_rx_buf_tail = 0; usb_rx_buf_tail = 0x00;
} }
} }
} }
@ -222,7 +219,8 @@ void init_usb(void) {
mscdf_register_callback(MSCDF_CB_TEST_DISK_READY, (FUNC_PTR)usb_msc_disk_is_ready); mscdf_register_callback(MSCDF_CB_TEST_DISK_READY, (FUNC_PTR)usb_msc_disk_is_ready);
mscdf_register_callback(MSCDF_CB_XFER_BLOCKS_DONE, (FUNC_PTR)usb_msc_xfer_done); mscdf_register_callback(MSCDF_CB_XFER_BLOCKS_DONE, (FUNC_PTR)usb_msc_xfer_done);
usbdc_start(&multi_desc); int32_t result = usbdc_start(&multi_desc);
while (result != ERR_NONE) {}
usbdc_attach(); usbdc_attach();
} }
@ -317,12 +315,3 @@ void usb_write(const char* buffer, uint32_t len) {
bool usb_connected(void) { bool usb_connected(void) {
return cdc_enabled(); return cdc_enabled();
} }
// Poll for input if keyboard interrupts are enabled,
// so that we can check for the interrupt char. read_complete() does the checking.
void usb_cdc_background() {
//
if (mp_interrupt_char != -1 && cdc_enabled() && !pending_read) {
start_read();
}
}

View File

@ -37,6 +37,5 @@ int usb_read(void);
void usb_write(const char* buffer, uint32_t len); void usb_write(const char* buffer, uint32_t len);
bool usb_bytes_available(void); bool usb_bytes_available(void);
bool usb_connected(void); bool usb_connected(void);
void usb_cdc_background(void);
#endif // __MICROPY_INCLUDED_ATMEL_SAMD_USB_H__ #endif // __MICROPY_INCLUDED_ATMEL_SAMD_USB_H__