main.c 705 Bytes
Newer Older
Rahix's avatar
Rahix committed
1
2
3
4
#include "py/runtime.h"
#include "py/gc.h"
#include "lib/utils/pyexec.h"

5
6
#include "max32665.h"

Rahix's avatar
Rahix committed
7
static char* stack_top;
Rahix's avatar
Rahix committed
8
9
10
11
12
13
14
15
static char heap[4096];

int main(void)
{
	/* TODO: Replace this with a proper heap implementation */
	int stack_dummy;
	stack_top = (char*)&stack_dummy;

16
17
18
	/* TMR5 is used to notify on keyboard interrupt */
	NVIC_EnableIRQ(TMR5_IRQn);

Rahix's avatar
Rahix committed
19
	while (1) {
Rahix's avatar
Rahix committed
20
21
22
23
24
		gc_init(heap, heap + sizeof(heap));

		mp_init();
		pyexec_friendly_repl();
		mp_deinit();
Rahix's avatar
Rahix committed
25
26
27
28
29
30
	}
}

void gc_collect(void)
{
	/* TODO: Replace this with a proper heap implementation */
Rahix's avatar
Rahix committed
31
	void* dummy;
Rahix's avatar
Rahix committed
32
33

	gc_collect_start();
Rahix's avatar
Rahix committed
34
35
36
	gc_collect_root(
		&dummy,
		((mp_uint_t)stack_top - (mp_uint_t)&dummy) / sizeof(mp_uint_t));
Rahix's avatar
Rahix committed
37
38
	gc_collect_end();
}