2015-02-06 09:35:48 -05:00
|
|
|
/*
|
|
|
|
* This file is part of the Micro Python project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013, 2014 Damien P. George
|
|
|
|
* Copyright (c) 2015 Daniel Campora
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2015-02-21 13:58:43 -05:00
|
|
|
#include "py/mpconfig.h"
|
2015-02-06 09:35:48 -05:00
|
|
|
#include MICROPY_HAL_H
|
2015-02-21 13:58:43 -05:00
|
|
|
#include "py/obj.h"
|
|
|
|
#include "py/runtime.h"
|
|
|
|
#include "py/gc.h"
|
2015-02-06 09:35:48 -05:00
|
|
|
#include "inc/hw_memmap.h"
|
2015-02-10 07:11:27 -05:00
|
|
|
#include "inc/hw_types.h"
|
2015-03-12 15:59:15 -04:00
|
|
|
#include "inc/hw_ints.h"
|
|
|
|
#include "inc/hw_memmap.h"
|
|
|
|
#include "rom_map.h"
|
2015-02-10 07:11:27 -05:00
|
|
|
#include "pin.h"
|
2015-03-12 15:59:15 -04:00
|
|
|
#include "prcm.h"
|
2015-03-26 05:25:28 -04:00
|
|
|
#include "interrupt.h"
|
2015-02-06 09:35:48 -05:00
|
|
|
#include "pybuart.h"
|
2015-02-09 13:38:02 -05:00
|
|
|
#include "pybpin.h"
|
2015-02-06 09:35:48 -05:00
|
|
|
#include "pybrtc.h"
|
|
|
|
#include "pyexec.h"
|
|
|
|
#include "gccollect.h"
|
|
|
|
#include "gchelper.h"
|
|
|
|
#include "readline.h"
|
|
|
|
#include "mperror.h"
|
|
|
|
#include "simplelink.h"
|
|
|
|
#include "modnetwork.h"
|
|
|
|
#include "modwlan.h"
|
|
|
|
#include "serverstask.h"
|
|
|
|
#include "telnet.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "ff.h"
|
|
|
|
#include "diskio.h"
|
|
|
|
#include "sflash_diskio.h"
|
|
|
|
#include "mpexception.h"
|
|
|
|
#include "random.h"
|
2015-02-10 07:11:27 -05:00
|
|
|
#include "pybi2c.h"
|
2015-02-21 08:10:33 -05:00
|
|
|
#include "pybsd.h"
|
2015-02-10 07:11:27 -05:00
|
|
|
#include "pins.h"
|
2015-02-27 10:50:06 -05:00
|
|
|
#include "pybsleep.h"
|
2015-05-09 11:46:16 -04:00
|
|
|
#include "pybtimer.h"
|
2015-03-04 07:52:39 -05:00
|
|
|
#include "mpcallback.h"
|
2015-05-19 18:23:13 -04:00
|
|
|
#include "cryptohash.h"
|
2015-02-06 09:35:48 -05:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
DECLARE PRIVATE CONSTANTS
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
DECLARE PRIVATE FUNCTIONS
|
|
|
|
******************************************************************************/
|
2015-03-02 08:11:02 -05:00
|
|
|
STATIC void mptask_pre_init (void);
|
|
|
|
STATIC void mptask_init_sflash_filesystem (void);
|
|
|
|
STATIC void mptask_enter_ap_mode (void);
|
|
|
|
STATIC void mptask_create_main_py (void);
|
2015-02-06 09:35:48 -05:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
DECLARE PUBLIC DATA
|
|
|
|
******************************************************************************/
|
|
|
|
#ifdef DEBUG
|
|
|
|
OsiTaskHandle svTaskHandle;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
DECLARE PRIVATE DATA
|
|
|
|
******************************************************************************/
|
|
|
|
static FATFS *sflash_fatfs;
|
|
|
|
|
|
|
|
static const char fresh_main_py[] = "# main.py -- put your code here!\r\n";
|
|
|
|
static const char fresh_boot_py[] = "# boot.py -- run on boot-up\r\n"
|
|
|
|
"# can run arbitrary Python, but best to keep it minimal\r\n";
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
DECLARE PUBLIC FUNCTIONS
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
void TASK_Micropython (void *pvParameters) {
|
2015-03-25 06:21:44 -04:00
|
|
|
// initialize the garbage collector with the top of our stack
|
2015-02-06 09:35:48 -05:00
|
|
|
uint32_t sp = gc_helper_get_sp();
|
|
|
|
gc_collect_init (sp);
|
2015-03-12 15:59:15 -04:00
|
|
|
bool safeboot = false;
|
2015-02-06 09:35:48 -05:00
|
|
|
FRESULT res;
|
|
|
|
|
2015-03-12 15:59:15 -04:00
|
|
|
mptask_pre_init();
|
2015-02-06 09:35:48 -05:00
|
|
|
|
|
|
|
soft_reset:
|
|
|
|
|
|
|
|
// GC init
|
2015-03-02 08:11:02 -05:00
|
|
|
gc_init(&_boot, &_eheap);
|
2015-02-06 09:35:48 -05:00
|
|
|
|
2015-03-25 06:21:44 -04:00
|
|
|
// MicroPython init
|
2015-02-06 09:35:48 -05:00
|
|
|
mp_init();
|
|
|
|
mp_obj_list_init(mp_sys_path, 0);
|
|
|
|
mp_obj_list_init(mp_sys_argv, 0);
|
|
|
|
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script)
|
|
|
|
|
2015-03-04 07:52:39 -05:00
|
|
|
// execute all basic initializations
|
2015-02-06 09:35:48 -05:00
|
|
|
mpexception_init0();
|
2015-03-04 07:52:39 -05:00
|
|
|
mpcallback_init0();
|
2015-03-14 04:59:47 -04:00
|
|
|
pybsleep_init0();
|
2015-03-25 09:14:25 -04:00
|
|
|
mperror_init0();
|
2015-02-06 09:35:48 -05:00
|
|
|
uart_init0();
|
2015-02-10 07:11:27 -05:00
|
|
|
pin_init0();
|
2015-05-09 11:46:16 -04:00
|
|
|
timer_init0();
|
2015-03-04 07:52:39 -05:00
|
|
|
readline_init0();
|
|
|
|
mod_network_init0();
|
|
|
|
#if MICROPY_HW_ENABLE_RNG
|
|
|
|
rng_init0();
|
|
|
|
#endif
|
2015-02-06 09:35:48 -05:00
|
|
|
|
2015-03-25 06:21:44 -04:00
|
|
|
// we are alive, so let the world know it
|
|
|
|
mperror_enable_heartbeat();
|
|
|
|
|
2015-04-07 04:41:46 -04:00
|
|
|
#ifdef LAUNCHXL
|
2015-03-26 05:25:28 -04:00
|
|
|
// configure the stdio uart pins with the correct alternate functions
|
2015-02-10 07:11:27 -05:00
|
|
|
// param 3 ("mode") is DON'T CARE" for AFs others than GPIO
|
2015-04-07 03:13:56 -04:00
|
|
|
pin_config ((pin_obj_t *)&pin_GPIO1, PIN_MODE_3, 0, PIN_TYPE_STD_PU, PIN_STRENGTH_2MA);
|
|
|
|
pin_config ((pin_obj_t *)&pin_GPIO2, PIN_MODE_3, 0, PIN_TYPE_STD_PU, PIN_STRENGTH_2MA);
|
2015-03-26 05:25:28 -04:00
|
|
|
// instantiate the stdio uart
|
2015-02-06 09:35:48 -05:00
|
|
|
mp_obj_t args[2] = {
|
|
|
|
mp_obj_new_int(MICROPY_STDIO_UART),
|
|
|
|
mp_obj_new_int(MICROPY_STDIO_UART_BAUD),
|
|
|
|
};
|
2015-02-20 10:31:30 -05:00
|
|
|
pyb_stdio_uart = pyb_uart_type.make_new((mp_obj_t)&pyb_uart_type, MP_ARRAY_SIZE(args), 0, args);
|
2015-03-26 05:25:28 -04:00
|
|
|
// create a callback for the uart, in order to enable the rx interrupts
|
|
|
|
uart_callback_new (pyb_stdio_uart, mp_const_none, MICROPY_STDIO_UART_RX_BUF_SIZE, INT_PRIORITY_LVL_3);
|
2015-04-07 04:41:46 -04:00
|
|
|
#else
|
|
|
|
pyb_stdio_uart = MP_OBJ_NULL;
|
|
|
|
#endif
|
2015-02-06 09:35:48 -05:00
|
|
|
|
2015-03-25 06:21:44 -04:00
|
|
|
pybsleep_reset_cause_t rstcause = pybsleep_get_reset_cause();
|
|
|
|
if (rstcause < PYB_SLP_SOFT_RESET) {
|
|
|
|
if (rstcause == PYB_SLP_HIB_RESET) {
|
|
|
|
// when waking up from hibernate we just want
|
|
|
|
// to enable simplelink and leave it as is
|
|
|
|
wlan_first_start();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// only if not comming out of hibernate or a soft reset
|
|
|
|
mptask_enter_ap_mode();
|
|
|
|
#ifndef DEBUG
|
|
|
|
safeboot = PRCMIsSafeBootRequested();
|
|
|
|
#endif
|
|
|
|
}
|
2015-02-26 09:03:52 -05:00
|
|
|
|
2015-03-25 06:21:44 -04:00
|
|
|
// enable telnet and ftp
|
|
|
|
servers_start();
|
2015-03-12 15:59:15 -04:00
|
|
|
}
|
2015-02-06 09:35:48 -05:00
|
|
|
|
|
|
|
// initialize the serial flash file system
|
2015-03-02 08:11:02 -05:00
|
|
|
mptask_init_sflash_filesystem();
|
2015-02-06 09:35:48 -05:00
|
|
|
|
2015-04-10 15:02:07 -04:00
|
|
|
// append the flash paths to the system path
|
|
|
|
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_flash));
|
|
|
|
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_flash_slash_lib));
|
2015-02-06 09:35:48 -05:00
|
|
|
|
|
|
|
// reset config variables; they should be set by boot.py
|
|
|
|
MP_STATE_PORT(pyb_config_main) = MP_OBJ_NULL;
|
|
|
|
|
2015-02-25 16:38:33 -05:00
|
|
|
if (!safeboot) {
|
|
|
|
// run boot.py, if it exists
|
2015-04-10 15:02:07 -04:00
|
|
|
const char *boot_py = "boot.py";
|
2015-02-25 16:38:33 -05:00
|
|
|
res = f_stat(boot_py, NULL);
|
|
|
|
if (res == FR_OK) {
|
|
|
|
int ret = pyexec_file(boot_py);
|
|
|
|
if (ret & PYEXEC_FORCED_EXIT) {
|
|
|
|
goto soft_reset_exit;
|
|
|
|
}
|
|
|
|
if (!ret) {
|
|
|
|
// flash the system led
|
|
|
|
mperror_signal_error();
|
|
|
|
}
|
2015-02-06 09:35:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 06:21:44 -04:00
|
|
|
// now we initialise sub-systems that need configuration from boot.py,
|
2015-02-06 09:35:48 -05:00
|
|
|
// or whose initialisation can be safely deferred until after running
|
|
|
|
// boot.py.
|
|
|
|
|
2015-03-25 06:21:44 -04:00
|
|
|
// at this point everything is fully configured and initialised.
|
2015-02-06 09:35:48 -05:00
|
|
|
|
2015-02-25 16:38:33 -05:00
|
|
|
if (!safeboot) {
|
2015-03-25 06:21:44 -04:00
|
|
|
// run the main script from the current directory.
|
2015-02-25 16:38:33 -05:00
|
|
|
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
|
|
|
|
const char *main_py;
|
|
|
|
if (MP_STATE_PORT(pyb_config_main) == MP_OBJ_NULL) {
|
2015-04-10 15:02:07 -04:00
|
|
|
main_py = "main.py";
|
2015-02-25 16:38:33 -05:00
|
|
|
} else {
|
|
|
|
main_py = mp_obj_str_get_str(MP_STATE_PORT(pyb_config_main));
|
2015-02-06 09:35:48 -05:00
|
|
|
}
|
2015-02-25 16:38:33 -05:00
|
|
|
res = f_stat(main_py, NULL);
|
|
|
|
if (res == FR_OK) {
|
|
|
|
int ret = pyexec_file(main_py);
|
|
|
|
if (ret & PYEXEC_FORCED_EXIT) {
|
|
|
|
goto soft_reset_exit;
|
|
|
|
}
|
|
|
|
if (!ret) {
|
|
|
|
// flash the system led
|
|
|
|
mperror_signal_error();
|
|
|
|
}
|
2015-02-06 09:35:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 06:21:44 -04:00
|
|
|
// main script is finished, so now go into REPL mode.
|
|
|
|
// the REPL mode can change, or it can request a soft reset.
|
2015-03-20 08:39:43 -04:00
|
|
|
for ( ; ; ) {
|
2015-02-06 09:35:48 -05:00
|
|
|
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
|
|
|
|
if (pyexec_raw_repl() != 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (pyexec_friendly_repl() != 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
soft_reset_exit:
|
|
|
|
|
|
|
|
// soft reset
|
2015-03-14 04:59:47 -04:00
|
|
|
pybsleep_signal_soft_reset();
|
2015-04-18 09:29:28 -04:00
|
|
|
mp_printf(&mp_plat_print, "PYB: soft reboot\n");
|
2015-03-25 06:21:44 -04:00
|
|
|
|
2015-05-09 11:46:16 -04:00
|
|
|
// disable all peripherals that could trigger a callback
|
|
|
|
pyb_rtc_callback_disable(NULL);
|
|
|
|
timer_disable_all();
|
|
|
|
uart_disable_all();
|
|
|
|
|
|
|
|
// flush the serial flash buffer
|
2015-02-06 09:35:48 -05:00
|
|
|
sflash_disk_flush();
|
|
|
|
|
2015-02-25 05:08:51 -05:00
|
|
|
#if MICROPY_HW_HAS_SDCARD
|
|
|
|
pybsd_deinit();
|
|
|
|
#endif
|
|
|
|
|
2015-05-09 11:46:16 -04:00
|
|
|
// wait for pending transactions to complete
|
|
|
|
HAL_Delay(20);
|
|
|
|
|
2015-02-06 09:35:48 -05:00
|
|
|
goto soft_reset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
DEFINE PRIVATE FUNCTIONS
|
|
|
|
******************************************************************************/
|
2015-03-02 08:11:02 -05:00
|
|
|
__attribute__ ((section (".boot")))
|
|
|
|
STATIC void mptask_pre_init (void) {
|
|
|
|
#if MICROPY_HW_ENABLE_RTC
|
|
|
|
pybrtc_init();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Create the simple link spawn task
|
|
|
|
ASSERT (OSI_OK == VStartSimpleLinkSpawnTask(SIMPLELINK_SPAWN_TASK_PRIORITY));
|
|
|
|
|
|
|
|
// Allocate memory for the flash file system
|
|
|
|
ASSERT ((sflash_fatfs = mem_Malloc(sizeof(FATFS))) != NULL);
|
|
|
|
|
2015-03-14 04:59:47 -04:00
|
|
|
// this one allocates memory for the nvic vault
|
|
|
|
pybsleep_pre_init();
|
|
|
|
|
2015-04-29 10:01:51 -04:00
|
|
|
// this one allocates mameory for the WLAN semaphore
|
2015-05-01 17:09:29 -04:00
|
|
|
wlan_pre_init();
|
2015-04-29 10:01:51 -04:00
|
|
|
|
2015-03-02 08:11:02 -05:00
|
|
|
#if MICROPY_HW_HAS_SDCARD
|
|
|
|
pybsd_init0();
|
|
|
|
#endif
|
|
|
|
|
2015-05-19 18:23:13 -04:00
|
|
|
CRYPTOHASH_Init();
|
|
|
|
|
2015-03-02 08:11:02 -05:00
|
|
|
#ifdef DEBUG
|
|
|
|
ASSERT (OSI_OK == osi_TaskCreate(TASK_Servers,
|
|
|
|
(const signed char *)"Servers",
|
|
|
|
SERVERS_STACK_SIZE, NULL, SERVERS_PRIORITY, &svTaskHandle));
|
|
|
|
#else
|
|
|
|
ASSERT (OSI_OK == osi_TaskCreate(TASK_Servers,
|
|
|
|
(const signed char *)"Servers",
|
|
|
|
SERVERS_STACK_SIZE, NULL, SERVERS_PRIORITY, NULL));
|
|
|
|
#endif
|
|
|
|
}
|
2015-02-06 09:35:48 -05:00
|
|
|
|
2015-03-02 08:11:02 -05:00
|
|
|
STATIC void mptask_init_sflash_filesystem (void) {
|
2015-04-10 15:02:07 -04:00
|
|
|
FILINFO fno;
|
|
|
|
#if _USE_LFN
|
|
|
|
fno.lfname = NULL;
|
|
|
|
fno.lfsize = 0;
|
|
|
|
#endif
|
|
|
|
|
2015-02-06 09:35:48 -05:00
|
|
|
// Initialise the local flash filesystem.
|
2015-04-10 15:02:07 -04:00
|
|
|
// Create it if needed, and mount in on /flash.
|
2015-02-06 09:35:48 -05:00
|
|
|
// try to mount the flash
|
2015-04-10 15:02:07 -04:00
|
|
|
FRESULT res = f_mount(sflash_fatfs, "/flash", 1);
|
2015-02-06 09:35:48 -05:00
|
|
|
if (res == FR_NO_FILESYSTEM) {
|
|
|
|
// no filesystem, so create a fresh one
|
2015-04-10 15:02:07 -04:00
|
|
|
res = f_mkfs("/flash", 1, 0);
|
2015-02-06 09:35:48 -05:00
|
|
|
if (res == FR_OK) {
|
|
|
|
// success creating fresh LFS
|
|
|
|
} else {
|
2015-04-10 15:02:07 -04:00
|
|
|
__fatal_error("failed to create /flash");
|
2015-02-06 09:35:48 -05:00
|
|
|
}
|
|
|
|
// create empty main.py
|
2015-03-02 08:11:02 -05:00
|
|
|
mptask_create_main_py();
|
2015-02-06 09:35:48 -05:00
|
|
|
} else if (res == FR_OK) {
|
|
|
|
// mount sucessful
|
2015-04-10 15:02:07 -04:00
|
|
|
if (FR_OK != f_stat("/flash/main.py", &fno)) {
|
2015-02-06 09:35:48 -05:00
|
|
|
// create empty main.py
|
2015-03-02 08:11:02 -05:00
|
|
|
mptask_create_main_py();
|
2015-02-06 09:35:48 -05:00
|
|
|
}
|
|
|
|
} else {
|
2015-04-10 15:02:07 -04:00
|
|
|
__fatal_error("failed to create /flash");
|
2015-02-06 09:35:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// The current directory is used as the boot up directory.
|
|
|
|
// It is set to the internal flash filesystem by default.
|
2015-04-10 15:02:07 -04:00
|
|
|
f_chdrive("/flash");
|
2015-02-06 09:35:48 -05:00
|
|
|
|
|
|
|
// Make sure we have a /flash/boot.py. Create it if needed.
|
2015-04-10 15:02:07 -04:00
|
|
|
res = f_stat("/flash/boot.py", &fno);
|
2015-02-06 09:35:48 -05:00
|
|
|
if (res == FR_OK) {
|
|
|
|
if (fno.fattrib & AM_DIR) {
|
|
|
|
// exists as a directory
|
|
|
|
// TODO handle this case
|
|
|
|
// see http://elm-chan.org/fsw/ff/img/app2.c for a "rm -rf" implementation
|
|
|
|
} else {
|
|
|
|
// exists as a file, good!
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// doesn't exist, create fresh file
|
|
|
|
FIL fp;
|
2015-04-10 15:02:07 -04:00
|
|
|
f_open(&fp, "/flash/boot.py", FA_WRITE | FA_CREATE_ALWAYS);
|
2015-02-06 09:35:48 -05:00
|
|
|
UINT n;
|
|
|
|
f_write(&fp, fresh_boot_py, sizeof(fresh_boot_py) - 1 /* don't count null terminator */, &n);
|
|
|
|
// TODO check we could write n bytes
|
|
|
|
f_close(&fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-02 08:11:02 -05:00
|
|
|
STATIC void mptask_enter_ap_mode (void) {
|
2015-03-31 10:28:13 -04:00
|
|
|
// enable simplelink in low power mode
|
|
|
|
wlan_sl_enable (ROLE_AP, MICROPY_PORT_WLAN_AP_SSID, strlen(MICROPY_PORT_WLAN_AP_SSID), MICROPY_PORT_WLAN_AP_SECURITY,
|
|
|
|
MICROPY_PORT_WLAN_AP_KEY, strlen(MICROPY_PORT_WLAN_AP_KEY), MICROPY_PORT_WLAN_AP_CHANNEL);
|
2015-02-06 09:35:48 -05:00
|
|
|
}
|
|
|
|
|
2015-03-02 08:11:02 -05:00
|
|
|
STATIC void mptask_create_main_py (void) {
|
2015-02-06 09:35:48 -05:00
|
|
|
// create empty main.py
|
|
|
|
FIL fp;
|
2015-04-10 15:02:07 -04:00
|
|
|
f_open(&fp, "/flash/main.py", FA_WRITE | FA_CREATE_ALWAYS);
|
2015-02-06 09:35:48 -05:00
|
|
|
UINT n;
|
|
|
|
f_write(&fp, fresh_main_py, sizeof(fresh_main_py) - 1 /* don't count null terminator */, &n);
|
|
|
|
f_close(&fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
STATIC mp_obj_t pyb_main(mp_obj_t main) {
|
|
|
|
if (MP_OBJ_IS_STR(main)) {
|
|
|
|
MP_STATE_PORT(pyb_config_main) = main;
|
|
|
|
}
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
MP_DEFINE_CONST_FUN_OBJ_1(pyb_main_obj, pyb_main);
|