Skip to content
Snippets Groups Projects
Verified Commit c5730693 authored by rahix's avatar rahix
Browse files

feat(pycardium): Add proper stack implementation


This is the first part of #15.

Signed-off-by: default avatarRahix <rahix@rahix.de>
parent e563593e
No related branches found
No related tags found
No related merge requests found
#include "py/runtime.h" #include "py/runtime.h"
#include "py/gc.h" #include "py/gc.h"
#include "lib/utils/pyexec.h" #include "lib/utils/pyexec.h"
#include "py/stackctrl.h"
#include <stdio.h>
#include "max32665.h" #include "max32665.h"
static char *stack_top;
static char heap[4096]; static char heap[4096];
extern int __StackTop, __StackLimit;
int main(void) int main(void)
{ {
/* TODO: Replace this with a proper heap implementation */ if (0) {
int stack_dummy; mp_stack_set_top(&__StackTop);
stack_top = (char *)&stack_dummy; mp_stack_set_limit((mp_int_t)&__StackLimit);
}
/* TMR5 is used to notify on keyboard interrupt */ /* TMR5 is used to notify on keyboard interrupt */
NVIC_EnableIRQ(TMR5_IRQn); NVIC_EnableIRQ(TMR5_IRQn);
...@@ -27,13 +31,12 @@ int main(void) ...@@ -27,13 +31,12 @@ int main(void)
void gc_collect(void) void gc_collect(void)
{ {
/* TODO: Replace this with a proper heap implementation */ void *sp = (void *)__get_MSP();
void *dummy;
gc_collect_start(); gc_collect_start();
gc_collect_root( gc_collect_root(
&dummy, sp,
((mp_uint_t)stack_top - (mp_uint_t)&dummy) / sizeof(mp_uint_t) ((mp_uint_t)&__StackTop - (mp_uint_t)sp) / sizeof(mp_uint_t)
); );
gc_collect_end(); gc_collect_end();
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment