void start_cmd(void *dummy) { #ifndef V7_NO_FS #ifndef DISABLE_OTA fs_init(get_fs_addr(), FS_SIZE); #else fs_init(FS_ADDR, FS_SIZE); #endif #endif init_v7(&dummy); #if !defined(NO_PROMPT) uart_main_init(0); #endif #ifndef V7_NO_FS init_smartjs(); #endif #ifndef DISABLE_OTA finish_update(); #endif #if !defined(NO_PROMPT) sj_prompt_init(v7); #endif }
/* * SmartJS initialization; for non-RTOS env, called as an SDK timer callback * (`os_timer_...()`). For RTOS env, called by the dispatcher task. */ void sjs_init(void *dummy) { /* * In order to see debug output (at least errors) during boot we have to * initialize debug in this point. But default we put debug to UART0 with * level=LL_ERROR, then configuration is loaded this settings are overridden */ uart_debug_init(0, 0); uart_redirect_debug(1); cs_log_set_level(LL_ERROR); #ifndef V7_NO_FS #ifndef DISABLE_OTA fs_init(get_fs_addr(get_current_rom()), get_fs_size(get_current_rom())); finish_update(); #else fs_init(FS_ADDR, FS_SIZE); #endif #endif init_v7(&dummy); /* disable GC during further initialization */ v7_set_gc_enabled(v7, 0); #if !defined(NO_PROMPT) uart_main_init(0); #endif #ifndef V7_NO_FS init_smartjs(); #endif #if !defined(NO_PROMPT) sj_prompt_init(v7); #endif #ifdef ESP_UMM_ENABLE /* * We want to use our own heap functions instead of the ones provided by the * SDK. * * We have marked `pvPortMalloc` and friends weak, so that we can override * them with our own implementations, but to actually make it work, we have * to reference any function from the file with our implementation, so that * linker will not garbage-collect the whole compilation unit. * * So, we have a call to the no-op `esp_umm_init()` here. */ esp_umm_init(); #endif /* SJS initialized, enable GC back, and trigger it */ v7_set_gc_enabled(v7, 1); v7_gc(v7, 1); }
static void pre_init(struct v7 *v7) { sj_init_sys(v7); init_smartjs(v7); mongoose_init(); sj_init_uart(v7); init_device(v7); run_init_script(v7); }
void start_cmd(void *dummy) { #ifndef V7_NO_FS fs_init(); #endif init_v7(&dummy); #if !defined(NO_PROMPT) uart_main_init(0); #endif #ifndef V7_NO_FS init_smartjs(); #endif #if !defined(NO_PROMPT) sj_prompt_init(v7); #endif }
static void pre_init(struct v7 *v7) { static const char *init_files[] = {"smart.js", "user.js"}; const char *dir = s_argv0 + strlen(s_argv0) - 1; char path[512]; size_t i; v7_val_t res; /* * Point `dir` to the right-most directory separator of the smartjs binary. * Thus string between `s_argv0` and `dir` pointers would contain a directory * name where our executable lives. */ while (dir > s_argv0 && *dir != '/' && *dir != '\\') { dir--; } snprintf(path, sizeof(path), "%.*s/%s", (int) (dir - s_argv0), s_argv0, JS_FS_ROOT); /* All the files, conf, JS, etc are addressed relative to the current dir */ if (chdir(path) != 0) { fprintf(stderr, "cannot chdir to %s\n", path); } sj_init_v7_ext(v7); init_smartjs(v7); /* * Run startup scripts from the directory JS_DIR_NAME. * That directory should be located where the binary (s_argv0) lives. */ for (i = 0; i < sizeof(init_files) / sizeof(init_files[0]); i++) { if (v7_exec_file(v7, &res, init_files[i]) != V7_OK) { fprintf(stderr, "Failed to run %s: ", init_files[i]); v7_fprintln(stderr, v7, res); } } }