/** * @fn spi_flash_enable * @brief Enable spi flash operations */ sint8 spi_flash_enable(uint8 enable) { sint8 s8Ret = M2M_SUCCESS; if(REV(nmi_get_chipid()) >= REV_3A0) { uint32 u32Val; /* Enable pinmux to SPI flash. */ s8Ret = nm_read_reg_with_ret(0x1410, &u32Val); if(s8Ret != M2M_SUCCESS) { goto ERR1; } /* GPIO15/16/17/18 */ u32Val &= ~((0x7777ul) << 12); u32Val |= ((0x1111ul) << 12); nm_write_reg(0x1410, u32Val); if(enable) { spi_flash_leave_low_power_mode(); } else { spi_flash_enter_low_power_mode(); } /* Disable pinmux to SPI flash to minimize leakage. */ u32Val &= ~((0x7777ul) << 12); u32Val |= ((0x0010ul) << 12); nm_write_reg(0x1410, u32Val); } ERR1: return s8Ret; }
/** * @fn nm_get_firmware_info(tstrM2mRev* M2mRev) * @brief Get Firmware version info * @param [out] M2mRev * pointer holds address of structure "tstrM2mRev" that contains the firmware version parameters * @author Ahmad.Mohammad.Yahya * @date 27 MARCH 2013 * @version 1.0 */ sint8 nm_get_firmware_info(tstrM2mRev* M2mRev) { uint16 curr_drv_ver, min_req_drv_ver,curr_firm_ver; uint32 reg = 0; sint8 ret = M2M_SUCCESS; ret = nm_read_reg_with_ret(NMI_REV_REG, ®); M2mRev->u8DriverMajor = M2M_GET_DRV_MAJOR(reg); M2mRev->u8DriverMinor = M2M_GET_DRV_MINOR(reg); M2mRev->u8DriverPatch = M2M_GET_DRV_PATCH(reg); M2mRev->u8FirmwareMajor = M2M_GET_FW_MAJOR(reg); M2mRev->u8FirmwareMinor = M2M_GET_FW_MINOR(reg); M2mRev->u8FirmwarePatch = M2M_GET_FW_PATCH(reg); M2mRev->u32Chipid = nmi_get_chipid(); curr_firm_ver = M2M_MAKE_VERSION(M2mRev->u8FirmwareMajor, M2mRev->u8FirmwareMinor,M2mRev->u8FirmwarePatch); curr_drv_ver = M2M_MAKE_VERSION(M2M_DRIVER_VERSION_MAJOR_NO, M2M_DRIVER_VERSION_MINOR_NO, M2M_DRIVER_VERSION_PATCH_NO); min_req_drv_ver = M2M_MAKE_VERSION(M2mRev->u8DriverMajor, M2mRev->u8DriverMinor,M2mRev->u8DriverPatch); if(curr_drv_ver < min_req_drv_ver) { /*The current driver version should be larger or equal than the min driver that the current firmware support */ ret = M2M_ERR_FW_VER_MISMATCH; } if(curr_drv_ver > curr_firm_ver) { /*The current driver should be equal or less than the firmware version*/ ret = M2M_ERR_FW_VER_MISMATCH; } return ret; }
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; }
void restore_pmu_settings_after_global_reset(void) { /* * Must restore PMU register value after * global reset if PMU toggle is done at * least once since the last hard reset. */ if(REV(nmi_get_chipid()) >= REV_2B0) { nm_write_reg(0x1e48, 0xb78469ce); } }
/* * @fn nm_drv_init_download_mode * @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 Viswanathan Murugesan * @date 10 Oct 2014 * @version 1.0 */ sint8 nm_drv_init_download_mode() { sint8 ret = M2M_SUCCESS; ret = nm_bus_iface_init(NULL); if (M2M_SUCCESS != ret) { M2M_ERR("[nmi start]: fail init bus\n"); goto ERR1; } #ifdef CONF_WINC_USE_SPI /* Must do this after global reset to set SPI data packet size. */ nm_spi_init(); #endif M2M_INFO("Chip ID %lx\n", nmi_get_chipid()); /*disable all interrupt in ROM (to disable uart) in 2b0 chip*/ nm_write_reg(0x20300,0); ERR1: return ret; }
/** * \brief Main application function. * * Application entry point. * Initialize board and WINC1500 Wi-Fi module. * Display WINC1500 chip id and rf revision id. * * \return program return value. */ int main(void) { tstrWifiInitParam param; int8_t ret; /* Initialize the board. */ system_init(); /* Initialize the UART console. */ configure_console(); printf(STRING_HEADER); /* Initialize the BSP. */ nm_bsp_init(); /* Initialize Wi-Fi parameters structure. */ memset((uint8_t *)¶m, 0, sizeof(tstrWifiInitParam)); /* Initialize Wi-Fi driver with data and status callbacks. */ ret = m2m_wifi_init(¶m); if (M2M_SUCCESS != ret) { printf("main: m2m_wifi_init call error!(%d)\r\n", ret); while (1) { } } /* Display WINC1500 chip information. */ printf("Chip ID : \r\t\t\t%x\r\n", (unsigned int)nmi_get_chipid()); printf("RF Revision ID : \r\t\t\t%x\r\n", (unsigned int)nmi_get_rfrevid()); printf("Done.\r\n\r\n"); while (1) { } return 0; }
/* * @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 #ifdef NO_HW_CHIP_EN ret = chip_wake(); nm_bsp_sleep(10); if (M2M_SUCCESS != ret) { M2M_ERR("[nmi start]: fail chip_wakeup\n"); goto ERR2; } /** Go... **/ ret = chip_reset(); if (M2M_SUCCESS != ret) { goto ERR2; } #endif M2M_INFO("Chip ID %lx\n", nmi_get_chipid()); #ifdef CONF_WINC_USE_SPI /* Must do this after global reset to set SPI data packet size. */ nm_spi_init(); #endif #ifdef NO_HW_CHIP_EN /*return power save to default value*/ chip_idle(); ret = cpu_start(); if (M2M_SUCCESS != ret) { goto ERR2; } #endif 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; } ret = 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; }
static uint8 check_3000_id(void) { return ((nmi_get_chipid() & (0xf00000)) == 0x300000); }