main.c 782 Bytes
Newer Older
Rahix's avatar
Rahix committed
1
2
#include "max32665.h"

Rahix's avatar
Rahix committed
3
#include "lib/utils/pyexec.h"
Rahix's avatar
Rahix committed
4
5
#include "py/gc.h"
#include "py/runtime.h"
6
#include "py/stackctrl.h"
Rahix's avatar
Rahix committed
7

Rahix's avatar
Rahix committed
8
#include <stdio.h>
9

Rahix's avatar
Rahix committed
10
11
12
/* Defined in linker script */
extern void *__StackTop, *__StackLimit;
extern void *__HeapBase, *__HeapLimit;
13

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

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

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

		mp_init();
26
		pyexec_file_if_exists("main.py");
Rahix's avatar
Rahix committed
27
28
		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();
}