Skip to content
Snippets Groups Projects
Commit b1f9cb44 authored by schneider's avatar schneider
Browse files

feat(interrupt): PoC for pyhton interrupts

parent 5a68588d
No related branches found
No related tags found
No related merge requests found
Pipeline #1301 failed
...@@ -37,4 +37,4 @@ struct api_call_mem { ...@@ -37,4 +37,4 @@ struct api_call_mem {
/* TODO: Make this address part of the linker script */ /* TODO: Make this address part of the linker script */
static __attribute__((unused)) struct api_call_mem* API_CALL_MEM = static __attribute__((unused)) struct api_call_mem* API_CALL_MEM =
(struct api_call_mem*)0x20080000; (struct api_call_mem*)0x20080100;
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
#define _EPICARDIUM_H #define _EPICARDIUM_H
#include <stdint.h> #include <stdint.h>
#define INT_CTRL_C 1
#define INT_BHI 2
#ifndef API #ifndef API
#define API(id, def) def #define API(id, def) def
#endif #endif
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "leds.h" #include "leds.h"
#include "api/dispatcher.h" #include "api/dispatcher.h"
#include "modules/modules.h" #include "modules/modules.h"
#include "interrupt/interrupt.h"
#include <Heart.h> #include <Heart.h>
#include "GUI_Paint.h" #include "GUI_Paint.h"
...@@ -46,6 +47,7 @@ int main(void) ...@@ -46,6 +47,7 @@ int main(void)
cdcacm_init(); cdcacm_init();
fatfs_init(); fatfs_init();
interrupt_init();
printf("=> Initializing tasks ...\n"); printf("=> Initializing tasks ...\n");
......
...@@ -39,6 +39,24 @@ api_dispatcher_lib = static_library( ...@@ -39,6 +39,24 @@ api_dispatcher_lib = static_library(
dependencies: periphdriver, dependencies: periphdriver,
) )
##########################################################################
#
# Interrupts
#
##########################################################################
int_receiver_lib = static_library(
'int-receiver',
'interrupt/receiver.c',
dependencies: periphdriver,
)
int_receiver = declare_dependency(
include_directories: include_directories('.'),
link_with: int_receiver_lib,
dependencies: periphdriver,
)
########################################################################## ##########################################################################
# #
# FreeRTOS # FreeRTOS
...@@ -69,6 +87,7 @@ elf = executable( ...@@ -69,6 +87,7 @@ elf = executable(
'cdcacm.c', 'cdcacm.c',
'main.c', 'main.c',
'support.c', 'support.c',
'interrupt/interrupt.c',
module_sources, module_sources,
dependencies: [libcard10, max32665_startup_core0, maxusb, libff13], dependencies: [libcard10, max32665_startup_core0, maxusb, libff13],
link_with: [api_dispatcher_lib, freertos], link_with: [api_dispatcher_lib, freertos],
......
...@@ -4,13 +4,14 @@ ...@@ -4,13 +4,14 @@
#include "max32665.h" #include "max32665.h"
#include "cdcacm.h" #include "cdcacm.h"
#include "uart.h" #include "uart.h"
#include "tmr_utils.h"
#include "FreeRTOS.h" #include "FreeRTOS.h"
#include "task.h" #include "task.h"
#include "queue.h" #include "queue.h"
#include "modules.h" #include "modules.h"
#include "interrupt/interrupt.h"
/* Task ID for the serial handler */ /* Task ID for the serial handler */
TaskHandle_t serial_task_id = NULL; TaskHandle_t serial_task_id = NULL;
...@@ -56,7 +57,12 @@ static void enqueue_char(char chr) ...@@ -56,7 +57,12 @@ static void enqueue_char(char chr)
{ {
if (chr == 0x3) { if (chr == 0x3) {
/* Control-C */ /* Control-C */
TMR_TO_Start(MXC_TMR5, 1, 0); interrupt_ctrl_c();
}
if (chr == 0x0e) {
/* Control-N */
interrupt_bhi();
} }
if (xQueueSend(read_queue, &chr, 100) == errQUEUE_FULL) { if (xQueueSend(read_queue, &chr, 100) == errQUEUE_FULL) {
......
...@@ -4,6 +4,7 @@ modsrc = files( ...@@ -4,6 +4,7 @@ modsrc = files(
'modules/utime.c', 'modules/utime.c',
'modules/leds.c', 'modules/leds.c',
'modules/vibra.c', 'modules/vibra.c',
'modules/interrupt.c',
) )
################################# #################################
...@@ -73,7 +74,7 @@ elf = executable( ...@@ -73,7 +74,7 @@ elf = executable(
modsrc, modsrc,
mp_headers, mp_headers,
include_directories: micropython_includes, include_directories: micropython_includes,
dependencies: [max32665_startup_core1, periphdriver, api_caller], dependencies: [max32665_startup_core1, periphdriver, api_caller, int_receiver],
link_with: upy, link_with: upy,
link_whole: [max32665_startup_core1_lib], link_whole: [max32665_startup_core1_lib],
link_args: [ link_args: [
......
...@@ -25,3 +25,5 @@ Q(ticks_diff) ...@@ -25,3 +25,5 @@ Q(ticks_diff)
/* vibra */ /* vibra */
Q(vibra) Q(vibra)
Q(vibrate) Q(vibrate)
Q(set_bhi)
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#define MICROPY_HELPER_REPL (1) #define MICROPY_HELPER_REPL (1)
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_LONGLONG) #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_LONGLONG)
#define MICROPY_ENABLE_SCHEDULER (1)
/* Builtin function and modules */ /* Builtin function and modules */
#define MICROPY_PY_BUILTINS_HELP (1) #define MICROPY_PY_BUILTINS_HELP (1)
#define MICROPY_PY_BUILTINS_HELP_MODULES (1) #define MICROPY_PY_BUILTINS_HELP_MODULES (1)
...@@ -37,6 +39,7 @@ ...@@ -37,6 +39,7 @@
#define MODULE_UTIME_ENABLED (1) #define MODULE_UTIME_ENABLED (1)
#define MODULE_LEDS_ENABLED (1) #define MODULE_LEDS_ENABLED (1)
#define MODULE_VIBRA_ENABLED (1) #define MODULE_VIBRA_ENABLED (1)
#define MODULE_INTERRUPT_ENABLED (1)
/* /*
* This port is intended to be 32-bit, but unfortunately, int32_t for * This port is intended to be 32-bit, but unfortunately, int32_t for
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "tmr.h" #include "tmr.h"
#include "epicardium.h" #include "epicardium.h"
#include "interrupt/int-common.h"
/****************************************************************************** /******************************************************************************
* Serial Communication * Serial Communication
*/ */
...@@ -64,11 +64,20 @@ long _write(int fd, const char *buf, size_t cnt) ...@@ -64,11 +64,20 @@ long _write(int fd, const char *buf, size_t cnt)
bool do_interrupt = false; bool do_interrupt = false;
mp_obj_t bhi_callback = NULL;
void mp_hal_interrupt_set_bhi(mp_obj_t func)
{
bhi_callback = func;
}
/* Timer Interrupt used for control char notification */ /* Timer Interrupt used for control char notification */
void TMR5_IRQHandler(void) void TMR5_IRQHandler(void)
{ {
TMR_IntClear(MXC_TMR5); TMR_IntClear(MXC_TMR5);
switch(INT_CALL_MEM->id) {
case INT_CTRL_C:
if (do_interrupt) { if (do_interrupt) {
/* Taken from lib/micropython/micropython/lib/utils/interrupt_char.c */ /* Taken from lib/micropython/micropython/lib/utils/interrupt_char.c */
MP_STATE_VM(mp_pending_exception) = MP_STATE_VM(mp_pending_exception) =
...@@ -79,6 +88,12 @@ void TMR5_IRQHandler(void) ...@@ -79,6 +88,12 @@ void TMR5_IRQHandler(void)
} }
#endif #endif
} }
break;
case INT_BHI:
mp_sched_schedule(bhi_callback, 0);
break;
}
INT_CALL_MEM->id = 0;
} }
void mp_hal_set_interrupt_char(char c) void mp_hal_set_interrupt_char(char c)
......
#include "py/mpconfig.h" #include "py/mpconfig.h"
#include "py/obj.h"
/* TODO: Replace this with a proper implementation */ /* TODO: Replace this with a proper implementation */
static inline mp_uint_t mp_hal_ticks_ms(void) static inline mp_uint_t mp_hal_ticks_ms(void)
...@@ -7,3 +8,5 @@ static inline mp_uint_t mp_hal_ticks_ms(void) ...@@ -7,3 +8,5 @@ static inline mp_uint_t mp_hal_ticks_ms(void)
} }
void mp_hal_set_interrupt_char(char c); void mp_hal_set_interrupt_char(char c);
void mp_hal_interrupt_set_bhi(mp_obj_t func);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment