main.c 745 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
11
/* Defined in linker script */
extern void *__StackTop, *__StackLimit;
extern void *__HeapBase, *__HeapLimit;
12

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

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

Rahix's avatar
Rahix committed
21
	while (1) {
22
		gc_init(&__HeapBase + 1024 * 10, &__HeapLimit);
Rahix's avatar
Rahix committed
23
24
25
26

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

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

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