trezor-core/embed/firmware/main.c

96 lines
2.1 KiB
C
Raw Normal View History

2017-02-24 04:19:00 -08:00
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "py/nlr.h"
#include "py/compile.h"
#include "py/runtime.h"
#include "py/stackctrl.h"
#include "py/repl.h"
#include "py/gc.h"
2017-03-26 14:11:57 -07:00
#include "py/mperrno.h"
2017-02-24 04:19:00 -08:00
#include "lib/utils/pyexec.h"
2017-03-07 05:50:09 -08:00
#include "gccollect.h"
2017-02-24 04:19:00 -08:00
#include "pendsv.h"
#include "common.h"
#include "display.h"
2017-03-07 06:52:19 -08:00
#include "flash.h"
#include "rng.h"
#include "sdcard.h"
#include "touch.h"
2017-03-24 08:38:46 -07:00
int main(void)
{
2017-02-24 04:19:00 -08:00
pendsv_init();
display_orientation(0);
sdcard_init();
touch_init();
2017-03-07 06:52:19 -08:00
2017-02-24 04:19:00 -08:00
for (;;) {
2017-05-15 10:33:35 -07:00
printf("CORE: Starting main loop\n");
2017-02-24 04:19:00 -08:00
// Stack limit should be less than real stack size, so we have a chance
// to recover from limit hit.
mp_stack_set_top(&_estack);
mp_stack_set_limit((char*)&_estack - (char*)&_heap_end - 1024);
// GC init
gc_init(&_heap_start, &_heap_end);
// Interpreter init
mp_init();
mp_obj_list_init(mp_sys_argv, 0);
mp_obj_list_init(mp_sys_path, 0);
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script)
// Run the main script
2017-05-15 10:33:35 -07:00
printf("CORE: Executing main script\n");
2017-02-24 04:19:00 -08:00
pyexec_frozen_module("main.py");
// Run REPL
2017-05-15 10:33:35 -07:00
printf("CORE: Executing REPL\n");
for (;;) {
if (pyexec_friendly_repl() != 0) {
break;
}
}
2017-02-24 04:19:00 -08:00
// Clean up
mp_deinit();
}
return 0;
}
// MicroPython default exception handler
void __attribute__((noreturn)) nlr_jump_fail(void *val) {
2017-10-12 07:06:53 -07:00
ensure(0, "uncaught exception");
}
2017-10-11 14:11:59 -07:00
void PendSV_Handler(void) {
pendsv_isr_handler();
}
// MicroPython file I/O stubs
2017-02-24 04:19:00 -08:00
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
return NULL;
}
mp_import_stat_t mp_import_stat(const char *path) {
return MP_IMPORT_STAT_NO_EXIST;
}
mp_obj_t mp_builtin_open(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) {
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
2017-03-26 14:11:57 -07:00
void mp_reader_new_file(mp_reader_t *reader, const char *filename) {
mp_raise_OSError(MP_ENOENT); // assume "file not found"
2017-03-06 08:33:42 -08:00
}