main.c 700 Bytes
Newer Older
Rahix's avatar
Rahix committed
1
2
3
#include "py/runtime.h"
#include "py/gc.h"
#include "lib/utils/pyexec.h"
4
5
#include "py/stackctrl.h"
#include <stdio.h>
Rahix's avatar
Rahix committed
6

7
8
#include "max32665.h"

Rahix's avatar
Rahix committed
9
10
static char heap[4096];

11
12
extern int __StackTop, __StackLimit;

Rahix's avatar
Rahix committed
13
14
int main(void)
{
15
16
17
18
	if (0) {
		mp_stack_set_top(&__StackTop);
		mp_stack_set_limit((mp_int_t)&__StackLimit);
	}
Rahix's avatar
Rahix committed
19

20
21
22
	/* TMR5 is used to notify on keyboard interrupt */
	NVIC_EnableIRQ(TMR5_IRQn);

Rahix's avatar
Rahix committed
23
	while (1) {
Rahix's avatar
Rahix committed
24
25
26
27
28
		gc_init(heap, heap + sizeof(heap));

		mp_init();
		pyexec_friendly_repl();
		mp_deinit();
Rahix's avatar
Rahix committed
29
30
31
32
33
	}
}

void gc_collect(void)
{
34
	void *sp = (void *)__get_MSP();
Rahix's avatar
Rahix committed
35
36

	gc_collect_start();
Rahix's avatar
Rahix committed
37
	gc_collect_root(
38
39
		sp,
		((mp_uint_t)&__StackTop - (mp_uint_t)sp) / sizeof(mp_uint_t)
Rahix's avatar
Rahix committed
40
	);
Rahix's avatar
Rahix committed
41
42
	gc_collect_end();
}