Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
2137bc71
Commit
2137bc71
authored
Apr 08, 2014
by
Damien George
Browse files
stmhal: in EXTI interrupt handler wrap uPy calls in gc_lock and nlr_buf.
parent
72cfc6ef
Changes
1
Hide whitespace changes
Inline
Side-by-side
stmhal/exti.c
View file @
2137bc71
...
...
@@ -4,12 +4,13 @@
#include
<stm32f4xx_hal.h>
#include
"nlr.h"
#include
"misc.h"
#include
"mpconfig.h"
#include
"qstr.h"
#include
"gc.h"
#include
"obj.h"
#include
"runtime.h"
#include
"nlr.h"
#include
"pin.h"
#include
"exti.h"
...
...
@@ -297,14 +298,27 @@ void exti_init(void) {
}
}
// Interrupt handler
void
Handle_EXTI_Irq
(
uint32_t
line
)
{
if
(
__HAL_GPIO_EXTI_GET_FLAG
(
1
<<
line
))
{
__HAL_GPIO_EXTI_CLEAR_FLAG
(
1
<<
line
);
if
(
line
<
EXTI_NUM_VECTORS
)
{
exti_vector_t
*
v
=
&
exti_vector
[
line
];
if
(
v
->
callback_obj
!=
mp_const_none
)
{
// TODO need to wrap this in an nlr_buf; really need a general function for this
mp_call_function_1
(
v
->
callback_obj
,
MP_OBJ_NEW_SMALL_INT
(
line
));
// When executing code within a handler we must lock the GC to prevent
// any memory allocations. We must also catch any exceptions.
gc_lock
();
nlr_buf_t
nlr
;
if
(
nlr_push
(
&
nlr
)
==
0
)
{
mp_call_function_1
(
v
->
callback_obj
,
MP_OBJ_NEW_SMALL_INT
(
line
));
nlr_pop
();
}
else
{
// Uncaught exception; disable the callback so it doesn't run again.
v
->
callback_obj
=
mp_const_none
;
printf
(
"Uncaught exception in EXTI interrupt handler on line %lu
\n
"
,
line
);
mp_obj_print_exception
((
mp_obj_t
)
nlr
.
ret_val
);
}
gc_unlock
();
}
}
}
...
...
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