90 lines
1.8 KiB
C
90 lines
1.8 KiB
C
#include <stdio.h>
|
|
|
|
/* Board */
|
|
#include "board.h"
|
|
#include "clock_config.h"
|
|
#include "peripherals.h"
|
|
#include "pin_mux.h"
|
|
|
|
/* FreeRTOS */
|
|
#include "FreeRTOS.h"
|
|
#include "task.h"
|
|
|
|
/* App */
|
|
#include "app_aux_ctrl.h"
|
|
#include "app_mrb_repl.h"
|
|
#include "app_syscalls.h"
|
|
|
|
#ifndef APP_LOG_SUCCESSFUL_ALLOC
|
|
#define APP_LOG_SUCCESSFUL_ALLOC false
|
|
#endif
|
|
|
|
static volatile bool s_aux_available = false;
|
|
|
|
static void app_mrb_runtime_task(void *parameters);
|
|
|
|
int main(void) {
|
|
BOARD_InitBootPins();
|
|
BOARD_InitBootClocks();
|
|
BOARD_InitBootPeripherals();
|
|
|
|
if(app_aux_ctrl_init() != 0) {
|
|
s_aux_available = false;
|
|
} else {
|
|
s_aux_available = true;
|
|
}
|
|
|
|
if (app_syscalls_init() != 0) {
|
|
goto dead_loop;
|
|
}
|
|
|
|
if (xTaskCreate(app_mrb_runtime_task, "MRB_RT", 6144, NULL, 2, NULL) != pdPASS) {
|
|
goto dead_loop;
|
|
}
|
|
|
|
vTaskStartScheduler();
|
|
|
|
dead_loop:
|
|
for (;;) {
|
|
__WFI();
|
|
}
|
|
}
|
|
|
|
/* TODO: Split runtime and REPL so that user can interrupt with Ctrl-C input. */
|
|
|
|
static void app_mrb_runtime_task(void *parameters) {
|
|
bool exit_repl;
|
|
|
|
if(!s_aux_available) {
|
|
printf("Aux initialization failed, some APIs may not available.\n");
|
|
}
|
|
|
|
for (;;) {
|
|
exit_repl = false;
|
|
|
|
if (app_mrb_repl_init() != 0) {
|
|
printf("Failed to initialize mruby REPL engine.\n");
|
|
goto task_fail;
|
|
}
|
|
|
|
while (!exit_repl) {
|
|
if (app_mrb_repl_exec(&exit_repl) != 0) {
|
|
printf("REPL execution failed.\n");
|
|
|
|
goto deinit_fail;
|
|
}
|
|
}
|
|
|
|
if (app_mrb_repl_deinit() != 0) {
|
|
printf("Failed to deinitialize murby REPL engine.\n");
|
|
goto task_fail;
|
|
}
|
|
}
|
|
|
|
deinit_fail:
|
|
app_mrb_repl_deinit();
|
|
|
|
task_fail:
|
|
vTaskDelete(NULL);
|
|
}
|