Verified Commit 3e0a8fbb authored by Rahix's avatar Rahix
Browse files

feat: Send KeyboardException when pressing ^C


Signed-off-by: Rahix's avatarRahix <rahix@rahix.de>
parent f87de543
Pipeline #907 passed with stage
in 1 minute and 59 seconds
......@@ -5,6 +5,7 @@
#include "cdcacm.h"
#include "uart.h"
#include "tmr_utils.h"
#include "FreeRTOS.h"
#include "task.h"
......@@ -60,6 +61,11 @@ void vSerialTask(void*pvParameters)
continue;
}
if (chr == 0x3) {
/* Control-C */
TMR_TO_Start(MXC_TMR5, 1, 0);
}
if (xQueueSend(read_queue, &chr, 100) == errQUEUE_FULL) {
/* Queue overran, wait a bit */
vTaskDelay(portTICK_PERIOD_MS * 50);
......
......@@ -2,6 +2,8 @@
#include "py/gc.h"
#include "lib/utils/pyexec.h"
#include "max32665.h"
static char* stack_top;
static char heap[4096];
......@@ -11,6 +13,9 @@ int main(void)
int stack_dummy;
stack_top = (char*)&stack_dummy;
/* TMR5 is used to notify on keyboard interrupt */
NVIC_EnableIRQ(TMR5_IRQn);
gc_init(heap, heap + sizeof(heap));
mp_init();
......
......@@ -8,7 +8,11 @@
* Right now, we do not support importing external modules
* though this might change in the future.
*/
#define MICROPY_ENABLE_EXTERNAL_IMPORT (0)
#define MICROPY_ENABLE_EXTERNAL_IMPORT (0)
/* We raise asynchronously from an interrupt handler */
#define MICROPY_ASYNC_KBD_INTR (1)
#define MICROPY_KBD_EXCEPTION (1)
#define MICROPY_ENABLE_DOC_STRING (1)
#define MICROPY_ENABLE_GC (1)
......
......@@ -3,11 +3,15 @@
#include "py/lexer.h"
#include "py/mpconfig.h"
#include "py/mperrno.h"
#include "py/mpstate.h"
#include "py/obj.h"
#include "py/runtime.h"
#include "epicardium.h"
#include "mxc_delay.h"
#include "max32665.h"
#include "tmr.h"
#include "epicardium.h"
/******************************************************************************
* Serial Communication
......@@ -25,6 +29,27 @@ void mp_hal_stdout_tx_strn(const char* str, mp_uint_t len)
epic_uart_write_str(str, len);
}
bool do_interrupt = false;
/* Timer Interrupt used for control char notification */
void TMR5_IRQHandler(void)
{
TMR_IntClear(MXC_TMR5);
if (do_interrupt) {
/* Taken from lib/micropython/micropython/ports/unix/unix_mphal.c */
mp_obj_exception_clear_traceback(
MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception))
);
nlr_raise(MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)));
}
}
void mp_hal_set_interrupt_char(char c)
{
do_interrupt = (c == 0x03);
}
/******************************************************************************
* Time & Delay
*/
......
......@@ -3,5 +3,4 @@
/* TODO: Replace this with a proper implementation */
static inline mp_uint_t mp_hal_ticks_ms(void) { return 0; }
/* TODO: Replace this with a proper implementation */
static inline void mp_hal_set_interrupt_char(char c) {}
void mp_hal_set_interrupt_char(char c);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment