int wm_core_init(void) { int ret = 0; static char init_done; if (init_done) return WM_SUCCESS; wmstdio_init(UART0_ID, 0); ret = cli_init(); if (ret != WM_SUCCESS) { init_e("Cli init failed."); goto out; } ret = wmtime_init(); if (ret != WM_SUCCESS) { init_e("Wmtime init failed."); goto out; } ret = pm_init(); if (ret != WM_SUCCESS) { init_e("Power manager init failed."); goto out; } ret = healthmon_init(); if (ret != WM_SUCCESS) { init_e("Healthmon init failed."); goto out; } boot_report_flags(); wmlog("boot", "Reset Cause Register: 0x%x", boot_reset_cause()); if (boot_reset_cause() & (1<<5)) wmlog("boot", " - Watchdog reset bit is set"); /* Read partition table layout from flash */ part_init(); out: if (ret == WM_SUCCESS) init_done = 1; return ret; }
int main() { int ret; modules_init();//模块的初始化 user_init(); /* system tag data */ store_or_retrive_taged_config(); get_mcu_version_from_psm(); LOG_DEBUG("rst cause is %x\r\n", boot_reset_cause()); #ifdef MIIO_COMMANDS mcmd_enqueue_raw("MIIO_model_req"); mcmd_enqueue_raw("MIIO_mcu_version_req"); #endif ret = os_mutex_create(&network_state_mutex,"network_state",OS_MUTEX_INHERIT); if(WM_SUCCESS != ret) { LOG_ERROR("create network_state_mutex fail"); goto main_error; } register_device_network_state_observer(led_network_state_observer); /*set wifi calbration data*/ product_set_wifi_cal_data(); /* Start the application framework */ if ((ret = app_framework_start(common_event_handler)) != WM_SUCCESS) { LOG_ERROR("Failed to start application framework.\r\n"); #if defined(CONFIG_CPU_MC200) if (-WLAN_ERROR_FW_DNLD_FAILED == ret || -WLAN_ERROR_FW_NOT_DETECTED == ret || -WLAN_ERROR_FW_NOT_READY == ret) { LOG_WARN("Wifi firmware broken, trying to recover.\r\n"); if (recover_wifi_fw() != WM_SUCCESS) { LOG_FATAL("Recovering wifi fw failed!!!\r\n"); } else { LOG_WARN("Recovering wifi fw success.\r\n"); pm_reboot_soc(); } } #endif appln_critical_error_handler((void *) -WM_FAIL); } ret = is_factory_mode_enable(); LOG_DEBUG("factory mode magic is %x\r\n" ,get_factory_mode_enable()); if (0 == ret) { // user mode static xTaskHandle task_handle; if (app_thread) { xTaskCreate(app_thread, (signed char*) "app", 2000, NULL, APPLICATION_PRIORITY, &task_handle); xTaskCreate(app_uart_thread, (signed char*) "app_uart", 2000, NULL, APPLICATION_PRIORITY, &task_handle); LOG_INFO("App thread and App uart thread started.\r\n"); } } else { // factory mode static xTaskHandle task_handle; if (app_test_thread) { xTaskCreate(app_test_thread, (signed char*) "test", 2000, NULL, 2, &task_handle); LOG_INFO("Test thread started.\r\n"); } } // Initialize power management hp_pm_init(); //enter main loop, main loop will be used as a worker thread main_loop_run(); //main loop return means error main_error: pm_reboot_soc(); //error occure on main thread , reboot return 1; }