main.c 749 Bytes
Newer Older
1
2
#include "mphalport.h"

Rahix's avatar
Rahix committed
3
4
#include "max32665.h"

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

Rahix's avatar
Rahix committed
10
#include <stdio.h>
11

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

Rahix's avatar
Rahix committed
16
17
int main(void)
{
18
19
	pycardium_hal_init();

20
21
	mp_stack_set_top(&__StackTop);
	mp_stack_set_limit((mp_int_t)&__StackLimit);
Rahix's avatar
Rahix committed
22
23

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

		mp_init();
27
		pyexec_file_if_exists("main.py");
Rahix's avatar
Rahix committed
28
29
		pyexec_friendly_repl();
		mp_deinit();
Rahix's avatar
Rahix committed
30
31
32
33
34
	}
}

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

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