/**@brief Function for the application main entry. */ int main(void) { uint32_t err_code; load_app(); gpio_init(); ble_stack_init(); device_manager_init(); juma_init(); // initialize Bluetooth Stack parameters. gap_params_init(); advertising_init(); services_init(); dispatch_init(); flash_init(); if (app) { device_current_statue_set(DEVICE_STATUE_APP); data_storage_init(); on_ready(); } else { device_current_statue_set(DEVICE_STATUE_OTA); ble_device_set_name("OTA Mode"); ota_init(); ble_device_set_advertising_interval(200); ble_device_start_advertising(); } // Enter main loop. for (;;) { watchDog_sys_SDK_dog1_RR(); if(0 != enter_ota_mode_statue) { enter_ota_process(NULL); } else { dispatch(); } serial_get(); // Switch to a low power state until an event is available for the application err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); } }
/** * @brief Get the image file with the specified protocol and write to flash * @param[in] protocol Pointer to the protocol of getting image file * @param[in] url URL of the image file * @retval ota_status_t, OTA_STATUS_OK on success */ ota_status_t ota_get_image(ota_protocol_t protocol, void *url) { if (url == NULL) { OTA_ERR("url %p\n", url); return OTA_STATUS_ERROR; } ota_init(); switch (protocol) { #if OTA_OPT_PROTOCOL_FILE case OTA_PROTOCOL_FILE: return ota_update_image(url, ota_update_file_init, ota_update_file_get); #endif #if OTA_OPT_PROTOCOL_HTTP case OTA_PROTOCOL_HTTP: return ota_update_image(url, ota_update_http_init, ota_update_http_get); #endif default: OTA_ERR("invalid protocol %d\n", protocol); return OTA_STATUS_ERROR; } }
static void modules_init() { int ret; struct partition_entry *p; flash_desc_t fl; /* * Initialize wmstdio prints */ ret = wmstdio_init(UART0_ID, 115200); if (ret != WM_SUCCESS) { appln_critical_error_handler((void *) -WM_FAIL); } /* Initialize time subsystem. * * Initializes time to 1/1/1970 epoch 0. */ ret = wmtime_init(); if (ret != WM_SUCCESS) { wmprintf("Error: wmtime_init failed"); appln_critical_error_handler((void *) -WM_FAIL); } /* * Initialize CLI Commands */ ret = cli_init(); if (ret != WM_SUCCESS) { LOG_ERROR("Error: cli_init failed"); appln_critical_error_handler((void *) -WM_FAIL); } /* Initialize the partition module */ ret = part_init(); if (ret != 0) { LOG_ERROR("Failed to initialize partition\r\n"); appln_critical_error_handler((void *) -WM_FAIL); } p = part_get_layout_by_id(FC_COMP_PSM, NULL); if (!p) { LOG_ERROR("Error: no psm partition found"); appln_critical_error_handler((void *) -WM_FAIL); } part_to_flash_desc(p, &fl); #if defined CONFIG_CPU_MC200 && defined CONFIG_WiFi_8801 //check psm _format psm_format_check(&fl); #endif /* Initilize psm module */ ret = app_psm_init(); if (ret != 0) { LOG_ERROR("Failed to initialize psm module\r\n"); appln_critical_error_handler((void *) -WM_FAIL); } wmprintf("\n\r"); wmprintf("_| _| _|_|_| _|_|_| _|_| \n\r"); wmprintf("_|_| _|_| _| _| _| _|\n\r"); wmprintf("_| _| _| _| _| _| _|\n\r"); wmprintf("_| _| _| _| _| _|\n\r"); wmprintf("_| _| _|_|_| _|_|_| _|_| \n\r"); print_versions(); read_provision_status(); #ifndef RELEASE /* Initilize cli for psm module */ ret = psm_cli_init(); if (ret != 0) { LOG_ERROR("Failed to register psm-cli commands\r\n"); appln_critical_error_handler((void *) -WM_FAIL); } #endif ret = gpio_drv_init(); if (ret != WM_SUCCESS) { LOG_ERROR("Error: gpio_drv_init failed"); appln_critical_error_handler((void *) -WM_FAIL); } ret = aes_drv_init(); if (ret != WM_SUCCESS) { LOG_ERROR("Error: aes drv init failed"); appln_critical_error_handler((void *) -WM_FAIL); } ret = factory_cli_init(); if (ret != 0) { LOG_ERROR("Error: factory_cli_init failed"); appln_critical_error_handler((void *) -WM_FAIL); } ret = miio_chip_rpc_init(); if (ret != 0) { LOG_ERROR("Error: miio_chip_rpc_cli_init failed"); appln_critical_error_handler((void *) -WM_FAIL); } #ifndef RELEASE ret = appln_cli_init(); if (ret != 0) { LOG_ERROR("Error: appln init failed"); appln_critical_error_handler((void *) -WM_FAIL); } #endif /* init add on interface */ init_addon_interface(); ret = ota_init(); if (ret != 0) { LOG_ERROR("Error: ota init failed"); appln_critical_error_handler((void *) -WM_FAIL); } #ifdef MIIO_COMMANDS ret = mcmd_create(UART1_ID); if (ret < 0) { LOG_ERROR("Error: miio command init failed(%d)\r\n", ret); appln_critical_error_handler((void *) -WM_FAIL); } #endif /* * Initialize Power Management Subsystem */ ret = pm_init(); if (ret != WM_SUCCESS) { LOG_ERROR("Error: pm_init failed"); appln_critical_error_handler((void *) -WM_FAIL); } }