sint8 wait_for_bootrom(uint8 arg) { sint8 ret = M2M_SUCCESS; uint32 reg = 0, cnt = 0; reg = 0; while(1) { reg = nm_read_reg(0x1014); /* wait for efuse loading done */ if (reg & 0x80000000) { break; } nm_bsp_sleep(1); /* TODO: Why bus error if this delay is not here. */ } reg = nm_read_reg(M2M_WAIT_FOR_HOST_REG); reg &= 0x1; /* check if waiting for the host will be skipped or not */ if(reg == 0) { reg = 0; while(reg != M2M_FINISH_BOOT_ROM) { nm_bsp_sleep(1); reg = nm_read_reg(BOOTROM_REG); if(++cnt > TIMEOUT) { M2M_DBG("failed to load firmware from flash.\n"); ret = M2M_ERR_INIT; goto ERR2; } } } if(2 == arg) { nm_write_reg(NMI_REV_REG, M2M_ATE_FW_START_VALUE); } else { /*bypass this step*/ } if(REV(nmi_get_chipid()) == REV_3A0) { chip_apply_conf(rHAVE_USE_PMU_BIT); } else { chip_apply_conf(0); } nm_write_reg(BOOTROM_REG,M2M_START_FIRMWARE); #ifdef __ROM_TEST__ rom_test(); #endif /* __ROM_TEST__ */ ERR2: return ret; }
/* * @fn nm_drv_init * @brief Initialize NMC1000 driver * @return M2M_SUCCESS in case of success and Negative error code in case of failure * @param [in] arg * Generic argument * @author M. Abdelmawla * @date 15 July 2012 * @version 1.0 */ sint8 nm_drv_init(void * arg) { tstrM2mRev strtmp; sint8 ret = M2M_SUCCESS; uint8 u8Mode = M2M_WIFI_MODE_NORMAL; if(NULL != arg) { if(M2M_WIFI_MODE_CONFIG == *((uint8 *)arg)) { u8Mode = M2M_WIFI_MODE_CONFIG; } else { /*continue running*/ } } else { /*continue running*/ } ret = nm_bus_iface_init(NULL); if (M2M_SUCCESS != ret) { M2M_ERR("[nmi start]: fail init bus\n"); goto ERR1; } #ifdef BUS_ONLY return; #endif ret = chip_wake(); nm_bsp_sleep(10); if (M2M_SUCCESS != ret) { M2M_ERR("[nmi start]: fail chip_wakeup\n"); goto ERR2; } M2M_INFO("Chip ID %lx\n", nmi_get_chipid()); /** Go... **/ ret = chip_reset(); if (M2M_SUCCESS != ret) { goto ERR2; } #ifdef CONF_WINC_USE_SPI /* Must do this after global reset to set SPI data packet size. */ nm_spi_init(); #endif /*return power save to default value*/ chip_idle(); //M2M_INFO("Chip ID %x\n", (unsigned int)nmi_get_chipid()); ret = cpu_start(); if (M2M_SUCCESS != ret) { goto ERR2; } ret = wait_for_bootrom(u8Mode); if (M2M_SUCCESS != ret) { goto ERR2; } ret = wait_for_firmware_start(u8Mode); if (M2M_SUCCESS != ret) { goto ERR2; } if(M2M_WIFI_MODE_CONFIG == u8Mode) { goto ERR1; } else { /*continue running*/ } ret = enable_interrupts(); if (M2M_SUCCESS != ret) { M2M_ERR("failed to enable interrupts..\n"); goto ERR2; } chip_apply_conf(); nm_get_firmware_info(&strtmp); M2M_INFO("Firmware ver : %u.%u.%u\n", strtmp.u8FirmwareMajor, strtmp.u8FirmwareMinor, strtmp.u8FirmwarePatch); M2M_INFO("Min driver ver : %u.%u.%u\n", strtmp.u8DriverMajor, strtmp.u8DriverMinor, strtmp.u8DriverPatch); M2M_INFO("Curr driver ver: %u.%u.%u\n", M2M_DRIVER_VERSION_MAJOR_NO, M2M_DRIVER_VERSION_MINOR_NO, M2M_DRIVER_VERSION_PATCH_NO); if(strtmp.u8FirmwareMajor != M2M_DRIVER_VERSION_MAJOR_NO || strtmp.u8FirmwareMinor != M2M_DRIVER_VERSION_MINOR_NO) { ret = M2M_ERR_FW_VER_MISMATCH; M2M_ERR("Firmware version mismatch!\n"); } return ret; ERR2: nm_bus_iface_deinit(); ERR1: return ret; }