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

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

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

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

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

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

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

28
29
	pycardium_hal_init();

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

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

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

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

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