static void isr(void) { gstrHifCxt.u8Interrupt++; #ifdef NM_LEVEL_INTERRUPT nm_bsp_interrupt_ctrl(0); #endif }
void isr(void) { gu8Interrupt++; #ifdef NM_LEVEL_INTERRUPT nm_bsp_interrupt_ctrl(0); #endif }
static sint8 hif_set_rx_done(void) { uint32 reg; sint8 ret = M2M_SUCCESS; gstrHifCxt.u8HifRXDone = 0; #ifdef NM_EDGE_INTERRUPT nm_bsp_interrupt_ctrl(1); #endif ret = nm_read_reg_with_ret(WIFI_HOST_RCV_CTRL_0,®); if(ret != M2M_SUCCESS)goto ERR1; /* Set RX Done */ reg |= NBIT1; ret = nm_write_reg(WIFI_HOST_RCV_CTRL_0,reg); if(ret != M2M_SUCCESS)goto ERR1; #ifdef NM_LEVEL_INTERRUPT nm_bsp_interrupt_ctrl(1); #endif ERR1: return ret; }
/** * @fn hif_isr * @brief Host interface interrupt service routine * @author M. Abdelmawla * @date 15 July 2012 * @return 1 in case of interrupt received else 0 will be returned * @version 1.0 */ static sint8 hif_isr(void) { sint8 ret = M2M_SUCCESS; uint32 reg; volatile tstrHifHdr strHif; ret = nm_read_reg_with_ret(WIFI_HOST_RCV_CTRL_0, ®); if(M2M_SUCCESS == ret) { if(reg & 0x1) /* New interrupt has been received */ { uint16 size; nm_bsp_interrupt_ctrl(0); /*Clearing RX interrupt*/ reg &= ~NBIT0; ret = nm_write_reg(WIFI_HOST_RCV_CTRL_0,reg); if(ret != M2M_SUCCESS)goto ERR1; gstrHifCxt.u8HifRXDone = 1; size = (uint16)((reg >> 2) & 0xfff); if (size > 0) { uint32 address = 0; /** start bus transfer **/ ret = nm_read_reg_with_ret(WIFI_HOST_RCV_CTRL_1, &address); if(M2M_SUCCESS != ret) { M2M_ERR("(hif) WIFI_HOST_RCV_CTRL_1 bus fail\n"); nm_bsp_interrupt_ctrl(1); goto ERR1; } gstrHifCxt.u32RxAddr = address; gstrHifCxt.u32RxSize = size; ret = nm_read_block(address, (uint8*)&strHif, sizeof(tstrHifHdr)); strHif.u16Length = NM_BSP_B_L_16(strHif.u16Length); if(M2M_SUCCESS != ret) { M2M_ERR("(hif) address bus fail\n"); nm_bsp_interrupt_ctrl(1); goto ERR1; } if(strHif.u16Length != size) { if((size - strHif.u16Length) > 4) { M2M_ERR("(hif) Corrupted packet Size = %u <L = %u, G = %u, OP = %02X>\n", size, strHif.u16Length, strHif.u8Gid, strHif.u8Opcode); nm_bsp_interrupt_ctrl(1); ret = M2M_ERR_BUS_FAIL; goto ERR1; } } if(M2M_REQ_GROUP_WIFI == strHif.u8Gid) { if(gstrHifCxt.pfWifiCb) gstrHifCxt.pfWifiCb(strHif.u8Opcode,strHif.u16Length - M2M_HIF_HDR_OFFSET, address + M2M_HIF_HDR_OFFSET); else M2M_ERR("WIFI callback is not registered\n"); } else if(M2M_REQ_GROUP_IP == strHif.u8Gid) { if(gstrHifCxt.pfIpCb) gstrHifCxt.pfIpCb(strHif.u8Opcode,strHif.u16Length - M2M_HIF_HDR_OFFSET, address + M2M_HIF_HDR_OFFSET); else M2M_ERR("Scoket callback is not registered\n"); } else if(M2M_REQ_GROUP_OTA == strHif.u8Gid) { if(gstrHifCxt.pfOtaCb) gstrHifCxt.pfOtaCb(strHif.u8Opcode,strHif.u16Length - M2M_HIF_HDR_OFFSET, address + M2M_HIF_HDR_OFFSET); else M2M_ERR("Ota callback is not registered\n"); } else if(M2M_REQ_GROUP_CRYPTO == strHif.u8Gid) { if(gstrHifCxt.pfCryptoCb) gstrHifCxt.pfCryptoCb(strHif.u8Opcode,strHif.u16Length - M2M_HIF_HDR_OFFSET, address + M2M_HIF_HDR_OFFSET); else M2M_ERR("Crypto callback is not registered\n"); } else if(M2M_REQ_GROUP_SIGMA == strHif.u8Gid) { if(gstrHifCxt.pfSigmaCb) gstrHifCxt.pfSigmaCb(strHif.u8Opcode,strHif.u16Length - M2M_HIF_HDR_OFFSET, address + M2M_HIF_HDR_OFFSET); else M2M_ERR("Sigma callback is not registered\n"); } else if(M2M_REQ_GROUP_SSL == strHif.u8Gid) { if(gstrHifCxt.pfSslCb) gstrHifCxt.pfSslCb(strHif.u8Opcode,strHif.u16Length - M2M_HIF_HDR_OFFSET, address + M2M_HIF_HDR_OFFSET); } else { M2M_ERR("(hif) invalid group ID\n"); ret = M2M_ERR_BUS_FAIL; goto ERR1; } if(gstrHifCxt.u8HifRXDone) { M2M_ERR("(hif) host app didn't set RX Done <%u><%X>\n", strHif.u8Gid, strHif.u8Opcode); ret = hif_set_rx_done(); if(ret != M2M_SUCCESS) goto ERR1; } } else { M2M_ERR("(hif) Wrong Size\n"); ret = M2M_ERR_RCV; goto ERR1; } } else {
static s8_t spi_rw(u8_t *mosi, u8_t *miso, u16_t size) { const struct spi_buf buf_tx = { .buf = mosi, .len = size }; const struct spi_buf_set tx = { .buffers = &buf_tx, .count = 1 }; const struct spi_buf buf_rx = { .buf = miso, .len = miso ? size : 0 }; const struct spi_buf_set rx = { .buffers = &buf_rx, .count = 1 }; if (spi_transceive(winc1500.spi, &winc1500.spi_cfg, &tx, &rx)) { LOG_ERR("spi_transceive fail"); return M2M_ERR_BUS_FAIL; } return M2M_SUCCESS; } #endif s8_t nm_bus_init(void *pvinit) { /* configure GPIOs */ winc1500.gpios = winc1500_configure_gpios(); #ifdef CONF_WINC_USE_I2C /* Not implemented */ #elif defined CONF_WINC_USE_SPI /* setup SPI device */ winc1500.spi = device_get_binding(DT_ATMEL_WINC1500_0_BUS_NAME); if (!winc1500.spi) { LOG_ERR("spi device binding"); return -1; } winc1500.spi_cfg.operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB; winc1500.spi_cfg.frequency = DT_ATMEL_WINC1500_0_SPI_MAX_FREQUENCY; winc1500.spi_cfg.slave = DT_ATMEL_WINC1500_0_BASE_ADDRESS; #ifdef CONFIG_WIFI_WINC1500_GPIO_SPI_CS cs_ctrl.gpio_dev = device_get_binding( DT_ATMEL_WINC1500_0_CS_GPIO_CONTROLLER); if (!cs_ctrl.gpio_dev) { LOG_ERR("Unable to get GPIO SPI CS device"); return -ENODEV; } cs_ctrl.gpio_pin = DT_ATMEL_WINC1500_0_CS_GPIO_PIN; cs_ctrl.delay = 0U; winc1500.spi_cfg.cs = &cs_ctrl; LOG_DBG("SPI GPIO CS configured on %s:%u", DT_ATMEL_WINC1500_0_CS_GPIO_CONTROLLER, DT_ATMEL_WINC1500_0_CS_GPIO_PIN); #endif /* CONFIG_WIFI_WINC1500_GPIO_SPI_CS */ nm_bsp_reset(); nm_bsp_sleep(1); nm_bsp_interrupt_ctrl(1); LOG_DBG("NOTICE:DONE"); #endif return 0; } s8_t nm_bus_ioctl(u8_t cmd, void *parameter) { sint8 ret = 0; switch (cmd) { #ifdef CONF_WINC_USE_I2C case NM_BUS_IOCTL_R: { struct nm_i2c_default *param = (struct nm_i2c_default *)parameter; ret = nm_i2c_read(param->buffer, param->size); } break; case NM_BUS_IOCTL_W: { struct nm_i2c_default *param = (struct nm_i2c_default *)parameter; ret = nm_i2c_write(param->buffer, param->size); } break; case NM_BUS_IOCTL_W_SPECIAL: { struct nm_i2c_special *param = (struct nm_i2c_special *)parameter; ret = nm_i2c_write_special(param->buffer1, param->size1, param->buffer2, param->size2); } break; #elif defined CONF_WINC_USE_SPI case NM_BUS_IOCTL_RW: { tstrNmSpiRw *param = (tstrNmSpiRw *)parameter; ret = spi_rw(param->pu8InBuf, param->pu8OutBuf, param->u16Sz); } break; #endif default: ret = -1; M2M_ERR("ERROR:invalid ioclt cmd\n"); break; } return ret; } s8_t nm_bus_deinit(void) { return M2M_SUCCESS; } s8_t nm_bus_reinit(void *config) { return 0; }
/** * @fn hif_isr * @brief Host interface interrupt service routine * @author M. Abdelmawla * @date 15 July 2012 * @return 1 in case of interrupt received else 0 will be returned * @version 1.0 */ static sint8 hif_isr(void) { sint8 ret = M2M_ERR_BUS_FAIL; uint32 reg; volatile tstrHifHdr strHif; ret = hif_chip_wake(); if(ret == M2M_SUCCESS) { ret = nm_read_reg_with_ret(WIFI_HOST_RCV_CTRL_0, ®); if(M2M_SUCCESS == ret) { if(reg & 0x1) /* New interrupt has been received */ { uint16 size; nm_bsp_interrupt_ctrl(0); /*Clearing RX interrupt*/ reg &= ~(1<<0); ret = nm_write_reg(WIFI_HOST_RCV_CTRL_0,reg); if(ret != M2M_SUCCESS)goto ERR1; gu8HifSizeDone = 0; size = (uint16)((reg >> 2) & 0xfff); if (size > 0) { uint32 address = 0; /** start bus transfer **/ ret = nm_read_reg_with_ret(WIFI_HOST_RCV_CTRL_1, &address); if(M2M_SUCCESS != ret) { M2M_ERR("(hif) WIFI_HOST_RCV_CTRL_1 bus fail\n"); nm_bsp_interrupt_ctrl(1); goto ERR1; } ret = nm_read_block(address, (uint8*)&strHif, sizeof(tstrHifHdr)); strHif.u16Length = NM_BSP_B_L_16(strHif.u16Length); if(M2M_SUCCESS != ret) { M2M_ERR("(hif) address bus fail\n"); nm_bsp_interrupt_ctrl(1); goto ERR1; } if(strHif.u16Length != size) { if((size - strHif.u16Length) > 4) { M2M_ERR("(hif) Corrupted packet Size = %u <L = %u, G = %u, OP = %02X>\n", size, strHif.u16Length, strHif.u8Gid, strHif.u8Opcode); nm_bsp_interrupt_ctrl(1); ret = M2M_ERR_BUS_FAIL; goto ERR1; } } if(M2M_REQ_GROUP_WIFI == strHif.u8Gid) { if(pfWifiCb) pfWifiCb(strHif.u8Opcode,strHif.u16Length - M2M_HIF_HDR_OFFSET, address + M2M_HIF_HDR_OFFSET); } else if(M2M_REQ_GROUP_IP == strHif.u8Gid) { if(pfIpCb) pfIpCb(strHif.u8Opcode,strHif.u16Length - M2M_HIF_HDR_OFFSET, address + M2M_HIF_HDR_OFFSET); } else if(M2M_REQ_GROUP_OTA == strHif.u8Gid) { if(pfOtaCb) pfOtaCb(strHif.u8Opcode,strHif.u16Length - M2M_HIF_HDR_OFFSET, address + M2M_HIF_HDR_OFFSET); } else if(M2M_REQ_GROUP_CRYPTO == strHif.u8Gid) { if(pfCryptoCb) pfCryptoCb(strHif.u8Opcode,strHif.u16Length - M2M_HIF_HDR_OFFSET, address + M2M_HIF_HDR_OFFSET); } else if(M2M_REQ_GROUP_SIGMA == strHif.u8Gid) { if(pfSigmaCb) pfSigmaCb(strHif.u8Opcode,strHif.u16Length - M2M_HIF_HDR_OFFSET, address + M2M_HIF_HDR_OFFSET); } else { M2M_ERR("(hif) invalid group ID\n"); ret = M2M_ERR_BUS_FAIL; goto ERR1; } #ifndef ENABLE_UNO_BOARD if(!gu8HifSizeDone) { M2M_ERR("(hif) host app didn't set RX Done\n"); ret = hif_set_rx_done(); } #endif } else { ret = M2M_ERR_RCV; M2M_ERR("(hif) Wrong Size\n"); goto ERR1; } } else {