void user_init() { #ifdef ESP8266_GDBSTUB gdbstub_init(); #endif //Uncomment the line below if you want to step through the initialization function in the debugger without getting a reset from a watchdog. //system_soft_wdt_stop(); struct ip_info info; struct softap_config cfg; wifi_softap_get_config(&cfg); strcpy((char *)cfg.ssid, "$$com.sysprogs.esp8266.http.ssid$$"); cfg.ssid_len = strlen((char*)cfg.ssid); wifi_softap_set_config_current(&cfg); wifi_set_opmode(SOFTAP_MODE); wifi_softap_dhcps_stop(); IP4_ADDR(&info.ip, 192, 168, $$com.sysprogs.esp8266.http.subnet$$, 1); IP4_ADDR(&info.gw, 192, 168, $$com.sysprogs.esp8266.http.subnet$$, 1); IP4_ADDR(&info.netmask, 255, 255, 255, 0); wifi_set_ip_info(SOFTAP_IF, &info); dhcps_lease_test(); wifi_softap_dhcps_start(); static struct espconn httpdConn; static esp_tcp httpdTcp; httpdConn.type = ESPCONN_TCP; httpdConn.state = ESPCONN_NONE; httpdTcp.local_port = 80; httpdConn.proto.tcp = &httpdTcp; espconn_regist_connectcb(&httpdConn, httpdConnectCb); espconn_accept(&httpdConn); }
/** * @brief System main loop called by the ETS * * This function is called by ETS after all initializations has been * finished to start periodic processing of defined ETS tasks. We * overwrite this ETS function to take over the control and to start RIOT. */ void ets_run(void) { #if ENABLE_DEBUG register uint32_t *sp __asm__ ("a1"); ets_uart_printf("_stack %p\n", sp); ets_uart_printf("_bss_start %p\n", &_bss_start); ets_uart_printf("_bss_end %p\n", &_bss_end); ets_uart_printf("_heap_start %p\n", &_sheap); ets_uart_printf("_heap_end %p\n", &_eheap); ets_uart_printf("_heap_free %lu\n", get_free_heap_size()); #endif /* init min task priority */ ets_task_min_prio = 0; #ifdef MODULE_NEWLIB_SYSCALLS_DEFAULT _init(); #endif ets_tasks_init(); /* enable interrupts used by ETS/SDK */ #ifndef MODULE_ESP_SDK_INT_HANDLING ets_isr_unmask(BIT(ETS_FRC2_INUM)); ets_isr_unmask(BIT(ETS_WDEV_INUM)); ets_isr_unmask(BIT(ETS_WDT_INUM)); #endif #ifdef MODULE_ESP_GDBSTUB gdbstub_init(); #endif #if ENABLE_DEBUG==0 /* disable SDK messages */ system_set_os_print(0); #endif #ifdef CONTEXT_SWITCH_BY_INT extern void IRAM thread_yield_isr(void* arg); ets_isr_attach(ETS_SOFT_INUM, thread_yield_isr, NULL); ets_isr_unmask(BIT(ETS_SOFT_INUM)); #endif /* initialize dummy lwIP library to link it even if esp_wifi is not used */ extern void esp_lwip_init(void); esp_lwip_init(); thread_create(ets_task_stack, sizeof(ets_task_stack), ETS_TASK_PRIORITY, THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST, ets_task_func, NULL, "ets"); /* does not return */ kernel_init(); }
extern "C" void __attribute__((weak)) user_init(void) { printf("Sming RTOS Proof of Concept \r\n"); printf("SDK version:%s\n", system_get_sdk_version()); printf("FreeHeapSize = %d\r\n",xPortGetFreeHeapSize()); #ifdef ENABLE_GDB gdbstub_init(); #endif init(); }
/****************************************************************************** * FunctionName : user_init * Description : entry of user application, init user function here * Parameters : none * Returns : none *******************************************************************************/ void ICACHE_FLASH_ATTR user_init(void) { sys_read_cfg(); if(!syscfg.cfg.b.debug_print_enable) system_set_os_print(0); GPIO0_MUX = VAL_MUX_GPIO0_SDK_DEF; GPIO4_MUX = VAL_MUX_GPIO4_SDK_DEF; GPIO5_MUX = VAL_MUX_GPIO5_SDK_DEF; GPIO12_MUX = VAL_MUX_GPIO12_SDK_DEF; GPIO13_MUX = VAL_MUX_GPIO13_SDK_DEF; GPIO14_MUX = VAL_MUX_GPIO14_SDK_DEF; GPIO15_MUX = VAL_MUX_GPIO15_SDK_DEF; // vad7 //power_meter_init(); // //uart_init(); // in tcp2uart.h system_timer_reinit(); #if (DEBUGSOO > 0 && defined(USE_WEB)) os_printf("\nSimple WEB version: " WEB_SVERSION "\n"); #endif //if(syscfg.cfg.b.pin_clear_cfg_enable) test_pin_clr_wifi_config(); // сброс настроек, если замкнут пин RX set_cpu_clk(); // select cpu frequency 80 or 160 MHz #ifdef USE_GDBSTUB extern void gdbstub_init(void); gdbstub_init(); #endif #if DEBUGSOO > 0 if(eraminfo.size > 0) os_printf("Found free IRAM: base: %p, size: %d bytes\n", eraminfo.base, eraminfo.size); os_printf("System memory:\n"); system_print_meminfo(); os_printf("bssi : 0x%x ~ 0x%x, len: %d\n", &_lit4_start, &_lit4_end, (uint32)(&_lit4_end) - (uint32)(&_lit4_start)); os_printf("free : 0x%x ~ 0x%x, len: %d\n", (uint32)(&_lit4_end), (uint32)(eraminfo.base) + eraminfo.size, (uint32)(eraminfo.base) + eraminfo.size - (uint32)(&_lit4_end)); os_printf("Start 'heap' size: %d bytes\n", system_get_free_heap_size()); #endif #if DEBUGSOO > 0 os_printf("Set CPU CLK: %u MHz\n", ets_get_cpu_frequency()); #endif Setup_WiFi(); WEBFSInit(); // файловая система system_deep_sleep_set_option(0); system_init_done_cb(init_done_cb); }
/****************************************************************************** * FunctionName : user_init * Description : entry of user application, init user function here * Parameters : none * Returns : none *******************************************************************************/ void ICACHE_FLASH_ATTR user_init(void) { sys_read_cfg(); if(!syscfg.cfg.b.debug_print_enable) system_set_os_print(0); uart_init(); GPIO0_MUX = VAL_MUX_GPIO0_SDK_DEF; GPIO4_MUX = VAL_MUX_GPIO4_SDK_DEF; GPIO5_MUX = VAL_MUX_GPIO5_SDK_DEF; GPIO12_MUX = VAL_MUX_GPIO12_SDK_DEF; GPIO14_MUX = VAL_MUX_GPIO14_SDK_DEF; system_timer_reinit(); #if (DEBUGSOO > 0 && defined(USE_WEB)) os_printf("\nSimple WEB version: " WEB_SVERSION "\nOpenLoaderSDK v1.2\n"); #endif if(syscfg.cfg.b.pin_clear_cfg_enable) test_pin_clr_wifi_config(); set_cpu_clk(); // select cpu frequency 80 or 160 MHz #ifdef USE_GDBSTUB extern void gdbstub_init(void); gdbstub_init(); #endif #if DEBUGSOO > 0 if(eraminfo.size > 0) os_printf("Found free IRAM: base: %p, size: %d bytes\n", eraminfo.base, eraminfo.size); os_printf("System memory:\n"); system_print_meminfo(); os_printf("Start 'heap' size: %d bytes\n", system_get_free_heap_size()); #endif #if DEBUGSOO > 0 os_printf("Set CPU CLK: %u MHz\n", ets_get_cpu_frequency()); #endif Setup_WiFi(); #ifdef USE_WDRV init_wdrv(); #endif Set_WiFi(&wificonfig, Cmp_WiFi_chg(&wificonfig) & (WIFI_MASK_SLEEP|WIFI_MASK_STDHCP|WIFI_MASK_APIPDHCP)); WEBFSInit(); // файловая система system_deep_sleep_set_option(0); system_init_done_cb(init_done_cb); }
void RAMFUNC user_init(void) { #ifdef ESP32_GDBSTUB gdbstub_init(); #endif struct ip_info info; struct softap_config cfg; wifi_softap_get_config(&cfg); strcpy((char *)cfg.ssid, "$$com.sysprogs.esp32.http.ssid$$"); cfg.ssid_len = strlen((char*)cfg.ssid); wifi_softap_set_config_current(&cfg); wifi_set_opmode(SOFTAP_MODE); wifi_softap_dhcps_stop(); IP4_ADDR(&info.ip, 192, 168, $$com.sysprogs.esp32.http.subnet$$, 1); IP4_ADDR(&info.gw, 192, 168, $$com.sysprogs.esp32.http.subnet$$, 1); IP4_ADDR(&info.netmask, 255, 255, 255, 0); wifi_set_ip_info(SOFTAP_IF, &info); dhcps_lease_test(); wifi_softap_dhcps_start(); xTaskCreate(ServerTask, "Server", 256, NULL, 2, NULL); }
int main(int argc,char **argv) { if(sizeof(byte) != 1 || sizeof(wyde) != 2 || sizeof(tetra) != 4 || sizeof(octa) != 8) error("Type-sizes are wrong. Please change the typedefs in common.h for your platform!"); bool interactive = false; for(int i = 1; i < argc; i++) { if(strcmp(argv[i],"-i") == 0) interactive = true; else if(strncmp(argv[i],"--postcmds=",sizeof("--postcmds=") - 1) == 0) postCmds = argv[i] + sizeof("--postcmds=") - 1; else if(strncmp(argv[i],"--script=",sizeof("--script=") - 1) == 0) { script = argv[i] + sizeof("--script=") - 1; interactive = true; } else if(strncmp(argv[i],"--start=",sizeof("--start=") - 1) == 0) { octa cpc = mstrtoo(argv[i] + sizeof("--start=") - 1,NULL,0); cfg_setStartAddr(cpc); } else if(strcmp(argv[i],"--user") == 0) { cfg_setUserMode(true); cfg_setStartAddr(0x1000); cfg_setRAMSize((octa)32 * 1024 * 1024 * 1024); } else if(strcmp(argv[i],"--test") == 0) cfg_setTestMode(true); else if(strcmp(argv[i],"-t") == 0) { if(i >= argc - 1) error(usage,argv[0]); cfg_setTermCount(mstrtoo(argv[i + 1],NULL,0)); i++; } else if(strcmp(argv[i],"-l") == 0) { if(i >= argc - 1) error(usage,argv[0]); cfg_setProgram(argv[i + 1]); i++; } else if(strcmp(argv[i],"-r") == 0) { if(i >= argc - 1) error(usage,argv[0]); cfg_setROM(argv[i + 1]); cfg_setStartAddr(MSB(64) | ROM_START_ADDR); i++; } else if(strcmp(argv[i],"-d") == 0) { if(i >= argc - 1) error(usage,argv[0]); cfg_setDiskImage(argv[i + 1]); i++; } else if(strcmp(argv[i],"-o") == 0) { if(i >= argc - 1) error(usage,argv[0]); cfg_setOutputFile(argv[i + 1]); i++; } else if(strcmp(argv[i],"-m") == 0) { if(i >= argc - 1) error(usage,argv[0]); cfg_setRAMSize(mstrtoo(argv[i + 1],NULL,0) * 1024 * 1024); i++; } else if(strcmp(argv[i],"-c") == 0) cfg_setUseDspKbd(true); else if(strcmp(argv[i],"-p") == 0) { if(i >= argc - 1) error(usage,argv[0]); gdbport = atoi(argv[i + 1]); i++; } else if(strcmp(argv[i],"-b") == 0) cfg_setUseBacktracing(true); else if(strcmp(argv[i],"-s") == 0) { const char *mapNames[MAX_MAPS]; for(int x = 0; x < MAX_MAPS; x++) mapNames[x] = NULL; if(i == argc - 1 || mapNames[0] != NULL) error(usage,argv[0]); for(int x = 0; x < MAX_MAPS && i < argc - 1; x++) { mapNames[x] = argv[++i]; if(mapNames[x][0] == '-') { mapNames[x] = NULL; i--; break; } } cfg_setMaps(mapNames); } else error(usage,argv[0]); } // in non-interactive mode, either a program or ROM is required if(!interactive && cfg_getProgram() == NULL && cfg_getROM() == NULL) error(usage,argv[0]); // catch exceptions that are not catched by anybody else. it may occur an exception during // initialization for example. jmp_buf env; int ex = setjmp(env); if(ex != EX_NONE) mprintf("Exception: %s\n",ex_toString(ex,ex_getBits())); else { ex_push(&env); sim_init(); if(gdbport != -1) gdbstub_init(gdbport); else if(interactive) { cons_init(); if(script) cons_exec(script,true); cons_start(); cons_shutdown(); } else { cpu_run(); if(postCmds) postcmds_perform(postCmds); } } ex_pop(); sim_shutdown(); // ignore errors raised by the gcov stuff fclose(stderr); return EXIT_SUCCESS; }
bool emu_start(unsigned int port_gdb, unsigned int port_rdbg, const char *snapshot_file) { gui_busy_raii gui_busy; if(snapshot_file) { // Open snapshot size_t snapshot_size = gzip_filesize(snapshot_file); if(snapshot_size < sizeof(emu_snapshot)) return false; FILE *fp = fopen_utf8(snapshot_file, "rb"); if(!fp) return false; int dupfd = dup(fileno(fp)); fclose(fp); fp = nullptr; // gzdopen takes ownership of the fd gzFile gzf = gzdopen(dupfd, "r"); if(!gzf) { close(dupfd); return false; } auto snapshot = (struct emu_snapshot *) malloc(snapshot_size); if(!snapshot) { gzclose(gzf); return false; } if((size_t) gzread(gzf, snapshot, snapshot_size) != snapshot_size) { gzclose(gzf); free(snapshot); return false; } gzclose(gzf); //sched_reset(); sched.items[SCHED_THROTTLE].clock = CLOCK_27M; sched.items[SCHED_THROTTLE].proc = throttle_interval_event; // TODO: Max length path_boot1 = std::string(snapshot->path_boot1); path_flash = std::string(snapshot->path_flash); // TODO: Pass snapshot_size to flash_resume to avoid reading after the buffer // Resume components uint32_t sdram_size; if(snapshot->sig != SNAPSHOT_SIG || snapshot->version != SNAPSHOT_VER || !flash_resume(snapshot) || !flash_read_settings(&sdram_size, &product, &features, &asic_user_flags) || !cpu_resume(snapshot) || !memory_resume(snapshot) || !sched_resume(snapshot)) { emu_cleanup(); free(snapshot); return false; } free(snapshot); } else { if (!flash_open(path_flash.c_str())) return false; uint32_t sdram_size; flash_read_settings(&sdram_size, &product, &features, &asic_user_flags); flash_set_bootorder(boot_order); if(!memory_initialize(sdram_size)) { emu_cleanup(); return false; } } if(debug_on_start) cpu_events |= EVENT_DEBUG_STEP; uint8_t *rom = mem_areas[0].ptr; memset(rom, -1, 0x80000); for (int i = 0x00000; i < 0x80000; i += 4) RAM_FLAGS(&rom[i]) = RF_READ_ONLY; /* Load the ROM */ FILE *f = fopen_utf8(path_boot1.c_str(), "rb"); if (!f) { gui_perror(path_boot1.c_str()); emu_cleanup(); return false; } (void)fread(rom, 1, 0x80000, f); fclose(f); #ifndef NO_TRANSLATION if(!translate_init()) { gui_debug_printf("Could not init JIT, disabling translation.\n"); do_translate = false; } #endif addr_cache_init(); throttle_timer_on(); if(port_gdb) gdbstub_init(port_gdb); if(port_rdbg) rdebug_bind(port_rdbg); usblink_queue_reset(); if(!snapshot_file) emu_reset(); return true; }