main.c 1023 Bytes
Newer Older
Rahix's avatar
Rahix committed
1
#include "epicardium.h"
2
#include "mphalport.h"
Rahix's avatar
Rahix committed
3
#include "card10-version.h"
4

Rahix's avatar
Rahix committed
5
6
#include "max32665.h"

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

Rahix's avatar
Rahix committed
12
#include <stdio.h>
13

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

Rahix's avatar
Rahix committed
18
19
20
21
22
23
24
static const char header[] =
	"--------------------------------\r\n"
	"          Pycardium\r\n"
	" Version: " CARD10_VERSION
	"\r\n"
	"--------------------------------\r\n";

Rahix's avatar
Rahix committed
25
26
int main(void)
{
Rahix's avatar
Rahix committed
27
28
	epic_uart_write_str(header, sizeof(header));

29
30
	pycardium_hal_init();

31
32
	mp_stack_set_top(&__StackTop);
	mp_stack_set_limit((mp_int_t)&__StackLimit);
Rahix's avatar
Rahix committed
33
34

	while (1) {
35
		gc_init(&__HeapBase + 1024 * 10, &__HeapLimit);
Rahix's avatar
Rahix committed
36
37

		mp_init();
38
		pyexec_file_if_exists("main.py");
Rahix's avatar
Rahix committed
39
40
		pyexec_friendly_repl();
		mp_deinit();
Rahix's avatar
Rahix committed
41
42
43
44
45
	}
}

void gc_collect(void)
{
46
	void *sp = (void *)__get_MSP();
Rahix's avatar
Rahix committed
47
48

	gc_collect_start();
Rahix's avatar
Rahix committed
49
	gc_collect_root(
50
51
		sp,
		((mp_uint_t)&__StackTop - (mp_uint_t)sp) / sizeof(mp_uint_t)
Rahix's avatar
Rahix committed
52
	);
Rahix's avatar
Rahix committed
53
54
	gc_collect_end();
}