blob: 4fd1189288b14eb7ebb1c683af557ea193ade4ef [file] [log] [blame]
Damien George075d5972014-11-27 20:30:33 +00001/*
2 * This file is part of the Micro Python project, http://micropython.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2014 Damien P. George
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26
27#include <stdio.h>
28#include <string.h>
29
Damien Georgefe7d5422015-01-01 21:16:58 +000030#include "py/nlr.h"
Damien Georgefe7d5422015-01-01 21:16:58 +000031#include "py/compile.h"
32#include "py/runtime0.h"
33#include "py/runtime.h"
Damien Georgeb4b10fd2015-01-01 23:30:53 +000034#include "py/stackctrl.h"
Damien George731f3592015-10-30 23:03:58 +000035#include "py/mphal.h"
Damien Georgefe7d5422015-01-01 21:16:58 +000036#include "py/gc.h"
Damien George40274fe2015-11-09 13:13:09 +000037#include "lib/utils/pyexec.h"
Damien George075d5972014-11-27 20:30:33 +000038#include "gccollect.h"
Josef Gajdusek967f3232015-05-17 11:22:26 +020039#include "user_interface.h"
Damien George075d5972014-11-27 20:30:33 +000040
Paul Sokolovskyc6b87502015-01-15 00:21:57 +020041STATIC char heap[16384];
42
Damien Georgec98c1282015-05-06 00:02:58 +010043STATIC void mp_reset(void) {
Damien Georgeb4b10fd2015-01-01 23:30:53 +000044 mp_stack_set_limit(10240);
Damien George075d5972014-11-27 20:30:33 +000045 mp_hal_init();
Paul Sokolovskyc6b87502015-01-15 00:21:57 +020046 gc_init(heap, heap + sizeof(heap));
Damien George075d5972014-11-27 20:30:33 +000047 mp_init();
48 mp_obj_list_init(mp_sys_path, 0);
49 mp_obj_list_init(mp_sys_argv, 0);
Josef Gajdusekbda70412015-05-06 00:19:26 +020050#if MICROPY_MODULE_FROZEN
Damien George84b245f2015-12-26 12:32:33 +000051 pyexec_frozen_module("main");
Josef Gajdusekbda70412015-05-06 00:19:26 +020052#endif
Damien Georgec98c1282015-05-06 00:02:58 +010053}
Damien George075d5972014-11-27 20:30:33 +000054
Damien Georgec98c1282015-05-06 00:02:58 +010055void soft_reset(void) {
Damien George1febaf32015-12-22 14:28:02 +000056 mp_hal_stdout_tx_str("PYB: soft reboot\r\n");
Paul Sokolovsky5699fc92015-10-29 02:06:13 +030057 mp_hal_delay_us(10000); // allow UART to flush output
Damien Georgec98c1282015-05-06 00:02:58 +010058 mp_reset();
59 pyexec_event_repl_init();
60}
Damien George075d5972014-11-27 20:30:33 +000061
Josef Gajdusek967f3232015-05-17 11:22:26 +020062void init_done(void) {
Damien Georgec98c1282015-05-06 00:02:58 +010063 mp_reset();
64 mp_hal_stdout_tx_str("\r\n");
65 pyexec_event_repl_init();
Paul Sokolovskyf12ea7c2015-01-16 01:54:40 +020066 uart_task_init();
Damien George075d5972014-11-27 20:30:33 +000067}
68
Josef Gajdusek967f3232015-05-17 11:22:26 +020069void user_init(void) {
70 system_init_done_cb(init_done);
71}
72
Damien George075d5972014-11-27 20:30:33 +000073mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
74 return NULL;
75}
76
77mp_import_stat_t mp_import_stat(const char *path) {
78 return MP_IMPORT_STAT_NO_EXIST;
79}
80
81mp_obj_t mp_builtin_open(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) {
82 return mp_const_none;
83}
84MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
85
86void nlr_jump_fail(void *val) {
87 printf("NLR jump failed\n");
88 for (;;) {
89 }
90}
91
92//void __assert(const char *file, int line, const char *func, const char *expr) {
93void __assert(const char *file, int line, const char *expr) {
94 printf("Assertion '%s' failed, at file %s:%d\n", expr, file, line);
95 for (;;) {
96 }
97}