Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wink
firmware
Commits
7fefa791
Verified
Commit
7fefa791
authored
Jul 21, 2019
by
Rahix
Browse files
feat: Port everything to auto-generated IRQ system
Signed-off-by:
Rahix
<
rahix@rahix.de
>
parent
cce8a4cf
Changes
7
Hide whitespace changes
Inline
Side-by-side
epicardium/api/interrupt-receiver.c
View file @
7fefa791
...
...
@@ -3,33 +3,12 @@
#include
"api/common.h"
#include
"epicardium.h"
void
api_interrupt_handler_ctrl_c
(
api_int_id_t
id
)
__attribute__
((
weak
,
alias
(
"api_interrupt_handler_default"
)));
void
api_interrupt_handler_bhi160
(
api_int_id_t
id
)
__attribute__
((
weak
,
alias
(
"api_interrupt_handler_default"
)));
void
__dispatch_isr
(
api_int_id_t
);
/* Timer Interrupt used for control char notification */
void
TMR5_IRQHandler
(
void
)
{
TMR_IntClear
(
MXC_TMR5
);
switch
(
API_CALL_MEM
->
int_id
)
{
case
API_INT_CTRL_C
:
api_interrupt_handler_ctrl_c
(
API_CALL_MEM
->
int_id
);
break
;
case
API_INT_BHI160
:
api_interrupt_handler_bhi160
(
API_CALL_MEM
->
int_id
);
break
;
}
__dispatch_isr
(
API_CALL_MEM
->
int_id
);
API_CALL_MEM
->
int_id
=
0
;
}
__attribute__
((
weak
))
void
api_interrupt_handler_catch_all
(
api_int_id_t
id
)
{
}
void
api_interrupt_handler_default
(
api_int_id_t
id
)
{
api_interrupt_handler_catch_all
(
id
);
}
epicardium/api/interrupt-sender.c
View file @
7fefa791
...
...
@@ -2,15 +2,15 @@
#include
"api/common.h"
#include
"tmr_utils.h"
static
bool
enabled
[
A
PI_INT_
MAX
+
1
];
static
bool
int_
enabled
[
E
PI
C
_INT_
NUM
];
int
api_interrupt_trigger
(
api_int_id_t
id
)
{
if
(
id
>
A
PI_INT_
MAX
)
{
if
(
id
>
=
E
PI
C
_INT_
NUM
)
{
return
-
EINVAL
;
}
if
(
enabled
[
id
])
{
if
(
int_
enabled
[
id
])
{
while
(
API_CALL_MEM
->
int_id
)
;
API_CALL_MEM
->
int_id
=
id
;
...
...
@@ -21,30 +21,29 @@ int api_interrupt_trigger(api_int_id_t id)
void
api_interrupt_init
(
void
)
{
int
i
;
API_CALL_MEM
->
int_id
=
0
;
for
(
i
=
0
;
i
<
=
A
PI_INT_
MAX
;
i
++
)
{
enabled
[
i
]
=
false
;
for
(
int
i
=
0
;
i
<
E
PI
C
_INT_
NUM
;
i
++
)
{
int_
enabled
[
i
]
=
false
;
}
}
int
epic_interrupt_enable
(
api_int_id_t
int_id
)
{
if
(
int_id
>
A
PI_INT_
MAX
)
{
if
(
int_id
>
=
E
PI
C
_INT_
NUM
)
{
return
-
EINVAL
;
}
enabled
[
int_id
]
=
true
;
int_
enabled
[
int_id
]
=
true
;
return
0
;
}
int
epic_interrupt_disable
(
api_int_id_t
int_id
)
{
if
(
int_id
>
A
PI_INT_
MAX
)
{
if
(
int_id
>
=
E
PI
C
_INT_
NUM
)
{
return
-
EINVAL
;
}
enabled
[
int_id
]
=
false
;
int_
enabled
[
int_id
]
=
false
;
return
0
;
}
epicardium/api/interrupt-sender.h
View file @
7fefa791
#pragma once
#include
"api/common.h"
void
api_interrupt_init
(
void
);
int
api_interrupt_trigger
(
api_int_id_t
id
);
epicardium/epicardium.h
View file @
7fefa791
...
...
@@ -11,18 +11,22 @@
typedef
unsigned
int
size_t
;
#endif
/* __SPHINX_DOC */
/* clang-format off */
#define API_INT_CTRL_C 1
#define API_INT_BHI160 2
#define API_INT_MAX API_INT_BHI160
/*
* These definitions are required for the code-generator. Please don't touch!
*/
#ifndef API
#define API(id, def) def
#endif
#ifndef API_ISR
#define API_ISR(id, isr) void isr(void);
#endif
/*
* IDs for all defined API calls. These IDs should not be needed in application
* code on any side.
*/
/* clang-format off */
#define API_UART_WRITE 0x1
#define API_UART_READ 0x2
#define API_LEDS_SET 0x3
...
...
@@ -31,9 +35,53 @@ typedef unsigned int size_t;
#define API_STREAM_READ 0x6
#define API_INTERRUPT_ENABLE 0x7
#define API_INTERRUPT_DISABLE 0x8
/* clang-format on */
typedef
uint32_t
api_int_id_t
;
/**
* Interrupts
* ==========
* Next to API calls, Epicardium API also has an interrupt mechanism to serve
* the other direction. These interrupts can be enabled/disabled
* (masked/unmasked) using :c:func:`epic_interrupt_enable` and
* :c:func:`epic_interrupt_disable`.
*/
/**
* Enable/unmask an API interrupt.
*
* :param int_id: The interrupt to be enabled
*/
API
(
API_INTERRUPT_ENABLE
,
int
epic_interrupt_enable
(
api_int_id_t
int_id
));
/**
* Disable/mask an API interrupt.
*
* :param int_id: The interrupt to be disabled
*/
API
(
API_INTERRUPT_DISABLE
,
int
epic_interrupt_disable
(
api_int_id_t
int_id
));
/**
* The following interrupts are defined:
*/
/* clang-format off */
/** Reset Handler? **TODO** */
#define EPIC_INT_RESET 0
/** ``^C`` interrupt. See :c:func:`epic_isr_ctrl_c` for details. */
#define EPIC_INT_CTRL_C 1
/* Debug interrupt, please ignore */
#define EPIC_INT_BHI160_TEST 2
API_ISR
(
EPIC_INT_BHI160_TEST
,
epic_isr_bhi160_test
);
/* Number of defined interrupts. */
#define EPIC_INT_NUM 3
/* clang-format on */
API_ISR
(
EPIC_INT_RESET
,
epic_isr_reset
);
/**
* UART/Serial Interface
* =====================
...
...
@@ -60,6 +108,21 @@ API(API_UART_WRITE, void epic_uart_write_str(const char *str, intptr_t length));
*/
API
(
API_UART_READ
,
char
epic_uart_read_chr
(
void
));
/**
* **Interrupt Service Routine**
*
* A user-defineable ISR which is triggered when a ``^C`` (``0x04``) is received
* on any serial input device. This function is weakly aliased to
* :c:func:`epic_isr_default` by default.
*
* To enable this interrupt, you need to enable :c:data:`EPIC_INT_CTRL_C`:
*
* .. code-block:: cpp
*
* epic_interrupt_enable(EPIC_INT_CTRL_C);
*/
API_ISR
(
EPIC_INT_CTRL_C
,
epic_isr_ctrl_c
);
/**
* LEDs
* ====
...
...
@@ -156,23 +219,4 @@ API(API_VIBRA_SET, void epic_vibra_set(int status));
*/
API
(
API_VIBRA_VIBRATE
,
void
epic_vibra_vibrate
(
int
millis
));
/**
* API interrupt type
*/
typedef
uint32_t
api_int_id_t
;
/**
* Enable/unmask an API interrupt
*
* :param int_id: The interrupt to be enabled
*/
API
(
API_INTERRUPT_ENABLE
,
int
epic_interrupt_enable
(
api_int_id_t
int_id
));
/**
* Disable/mask an API interrupt
*
* :param int_id: The interrupt to be disabled
*/
API
(
API_INTERRUPT_DISABLE
,
int
epic_interrupt_disable
(
api_int_id_t
int_id
));
#endif
/* _EPICARDIUM_H */
epicardium/modules/serial.c
View file @
7fefa791
...
...
@@ -57,12 +57,12 @@ static void enqueue_char(char chr)
{
if
(
chr
==
0x3
)
{
/* Control-C */
api_interrupt_trigger
(
A
PI_INT_CTRL_C
);
api_interrupt_trigger
(
E
PI
C
_INT_CTRL_C
);
}
if
(
chr
==
0x0e
)
{
/* Control-N */
api_interrupt_trigger
(
A
PI_INT_BHI160
);
api_interrupt_trigger
(
E
PI
C
_INT_BHI160
_TEST
);
}
if
(
xQueueSend
(
read_queue
,
&
chr
,
100
)
==
errQUEUE_FULL
)
{
...
...
pycardium/modules/interrupt.c
View file @
7fefa791
...
...
@@ -6,15 +6,15 @@
#include
"mphalport.h"
// TODO: these should be intialized as mp_const_none
mp_obj_t
callbacks
[
A
PI_INT_
MAX
+
1
]
=
{
mp_obj_t
callbacks
[
E
PI
C
_INT_
NUM
]
=
{
0
,
};
void
a
pi_i
nterrupt_handler_catch_all
(
api_int_id_t
id
)
void
e
pi
c
_i
sr_default_handler
(
api_int_id_t
id
)
{
// TODO: check if id is out of rante
// TOOD: check against mp_const_none
if
(
id
<
=
A
PI_INT_
MAX
)
{
if
(
id
<
E
PI
C
_INT_
NUM
)
{
if
(
callbacks
[
id
])
{
mp_sched_schedule
(
callbacks
[
id
],
MP_OBJ_NEW_SMALL_INT
(
id
)
...
...
@@ -32,7 +32,7 @@ STATIC mp_obj_t mp_interrupt_set_callback(mp_obj_t id_in, mp_obj_t callback_obj)
}
// TODO: throw error if id is out of range
if
(
id
<
=
A
PI_INT_
MAX
)
{
if
(
id
<
E
PI
C
_INT_
NUM
)
{
callbacks
[
id
]
=
callback_obj
;
}
...
...
pycardium/mphalport.c
View file @
7fefa791
...
...
@@ -62,7 +62,7 @@ long _write(int fd, const char *buf, size_t cnt)
return
cnt
;
}
void
a
pi_i
nterrupt_handle
r_ctrl_c
(
void
)
void
e
pi
c
_i
s
r_ctrl_c
(
void
)
{
/* Taken from lib/micropython/micropython/lib/utils/interrupt_char.c */
MP_STATE_VM
(
mp_pending_exception
)
=
...
...
@@ -83,9 +83,9 @@ void mp_hal_set_interrupt_char(char c)
}
if
(
c
==
0x03
)
{
epic_interrupt_enable
(
A
PI_INT_CTRL_C
);
epic_interrupt_enable
(
E
PI
C
_INT_CTRL_C
);
}
else
{
epic_interrupt_disable
(
A
PI_INT_CTRL_C
);
epic_interrupt_disable
(
E
PI
C
_INT_CTRL_C
);
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment