1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-14 17:13:50 +01:00
2025-07-10 22:06:44 +02:00

75 lines
1.7 KiB
C

/*
* SPDX-FileCopyrightText: 2019 Kaspar Schleiser <kaspar@schleiser.de>
* SPDX-License-Identifier: LGPL-2.1-only
*/
/**
* @ingroup examples
* @{
*
* @file
* @brief micropython example application
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
*
* @}
*/
#include <stdio.h>
#include "thread.h"
#include "micropython.h"
#include "py/stackctrl.h"
#include "lib/utils/pyexec.h"
#include "blob/boot.py.h"
static char mp_heap[MP_RIOT_HEAPSIZE];
int main(void)
{
int coldboot = 1;
/* let MicroPython know the top of this thread's stack */
uint32_t stack_dummy;
mp_stack_set_top((char*)&stack_dummy);
/* Make MicroPython's stack limit somewhat smaller than actual stack limit */
mp_stack_set_limit(THREAD_STACKSIZE_MAIN - MP_STACK_SAFEAREA);
while (1) {
/* configure MicroPython's heap */
mp_riot_init(mp_heap, sizeof(mp_heap));
/* execute boot.py
*
* MicroPython's test suite gets confused by extra output, so only do
* this the first time after the node boots up, not on following soft
* reboots.
*/
if (coldboot) {
puts("-- Executing boot.py");
mp_do_str((const char *)boot_py, boot_py_len);
puts("-- boot.py exited. Starting REPL..");
coldboot = 0;
}
/* loop over REPL input */
while (1) {
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
if (pyexec_raw_repl() != 0) {
break;
}
} else {
if (pyexec_friendly_repl() != 0) {
break;
}
}
}
puts("soft reboot");
}
return 0;
}