/** * This function will be invoked when usb device plug out is detected and it would clean * and release all hub class related resources. * * @param arg the argument. * * @return the error code, RT_EOK on successfully. */ static rt_err_t rt_usb_adk_stop(void* arg) { uadkinst_t adkinst; uifinst_t ifinst = (uifinst_t)arg; RT_ASSERT(ifinst != RT_NULL); RT_DEBUG_LOG(RT_DEBUG_USB, ("rt_usb_adk_stop\n")); adkinst = (uadkinst_t)ifinst->user_data; if(adkinst == RT_NULL) { rt_free(ifinst); return RT_EOK; } if(adkinst->pipe_in != RT_NULL) rt_usb_hcd_free_pipe(ifinst->uinst->hcd, adkinst->pipe_in); if(adkinst->pipe_out != RT_NULL) rt_usb_hcd_free_pipe(ifinst->uinst->hcd, adkinst->pipe_out); /* unregister adk device */ rt_device_unregister(&adkinst->device); /* free adk instance */ if(adkinst != RT_NULL) rt_free(adkinst); /* free interface instance */ rt_free(ifinst); return RT_EOK; }
/** * @brief USBH_USR_DeInit * Deint User state and associated variables * @param None * @retval None */ void USBH_USR_DeInit( void ) { rt_kprintf( "%s\r\n", __func__ ); //USBH_USR_ApplicationState = USH_USR_FS_INIT; dfs_unmount( "/udisk" ); rt_device_unregister( &mscdev ); diskinited = 0; }
/** * @brief USBH_USR_DeInit * Deint User state and associated variables * @param None * @retval None */ void USBH_USR_DeInit( void ) { rt_kprintf( "\n%s", __func__ ); //USBH_USR_ApplicationState = USH_USR_FS_INIT; //dfs_unmount( "/udisk" ); f_mount(USB, RT_NULL); rt_device_unregister( &mscdev ); diskinited = 0; }
/* ethernetif APIs */ Int32 eth_device_init(struct eth_device* dev, const char* name) { struct netif* netif; uip_ipaddr_t ipaddr; netif = (struct netif*) malloc (sizeof(struct netif)); if (netif == NULL) { printf("malloc netif failed\n"); return -RT_ERROR; } memset(netif, 0, sizeof(struct netif)); /* set netif */ dev->netif = netif; /* register to rt-thread device manager */ rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR); dev->parent.type = RT_Device_Class_NetIf; rt_sem_init(&(dev->tx_ack), name, 0, RT_IPC_FLAG_FIFO); /* set name */ netif->name[0] = name[0]; netif->name[1] = name[1]; /* set hw address to 6 */ netif->hwaddr_len = 6; /* maximum transfer unit */ netif->mtu = ETHERNET_MTU; /* broadcast capability */ netif->flags = NETIF_FLAG_BROADCAST; #if LWIP_IGMP /* igmp support */ netif->flags |= NETIF_FLAG_IGMP; #endif /* get hardware address */ rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr); /* set output */ netif->output = ethernetif_output; netif->linkoutput = ethernetif_linkoutput; /* add netif to lwip */ if (netif_add(netif, IP_ADDR_ANY, IP_ADDR_BROADCAST, IP_ADDR_ANY, dev, eth_init, eth_input) == NULL) { /* failed, unregister device and free netif */ rt_device_unregister(&(dev->parent)); rt_free(netif); return -RT_ERROR; } netif_set_default(netif); return RT_EOK; }
/** * @brief This function is called when an error occurs on the connection * @param arg * @parm err * @retval None */ static void telnetd_conn_err(void *arg, err_t err) { struct telnetio_dev *teldev = arg; finsh_set_device(CONSOLE_DEVICE); rt_console_set_device(CONSOLE_DEVICE); rt_device_unregister(&teldev->dev); telnetio_dev_delete(teldev); return; }
rt_err_t rt_i2c_bus_device_exit(struct rt_i2c_bus* bus) { struct rt_device *device; struct rt_i2c_device *i2c_device; RT_ASSERT(bus != RT_NULL); device = bus->parent; i2c_device = device->user_data;; /* register to device manager */ rt_device_unregister(device); rt_free(i2c_device); return RT_EOK; }
/* ethernetif APIs */ rt_err_t eth_device_init(struct eth_device* dev, const char* name) { struct netif* pnetif; /* allocate memory */ pnetif = (struct netif*) rt_malloc (sizeof(struct netif)); if (pnetif == RT_NULL) { rt_kprintf("malloc netif failed\n"); return -RT_ERROR; } rt_memset(pnetif, 0, sizeof(struct netif)); /* set netif */ dev->netif = pnetif; /* register to rt-thread device manager */ rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR); dev->parent.type = RT_Device_Class_NetIf; rt_sem_init(&(dev->tx_ack), name, 0, RT_IPC_FLAG_FIFO); /* add netif to lwip */ /* NOTE: eth_init will be called back by netif_add, we should put some initialization code to eth_init(). See include/lwip/netif.h line 97 */ eth_dev = dev; if (netif_add(pnetif, IP_ADDR_ANY, IP_ADDR_BROADCAST, IP_ADDR_ANY, dev, ethernetif_init, ethernet_input) == RT_NULL) { /* failed, unregister device and free netif */ rt_device_unregister(&(dev->parent)); rt_free(pnetif); eth_dev = RT_NULL; return -RT_ERROR; } eth_dev = RT_NULL; netif_set_default(pnetif); /* We bring up the netif here cause we still don't have a call back function which indicates the ethernet interface status from the ethernet driver. */ netif_set_up(pnetif); netif_set_link_up(pnetif); return RT_EOK; }
int test_tdc_gp21(void) { rt_device_t tdc = RT_NULL; #if 0 struct spi_tdc_gp21_tof_data tof_data; struct spi_tdc_gp21_temp_scales temp_scales; #endif if(RT_EOK != tdc_gp21_register()) { return -RT_ERROR; } tdc = rt_device_find("tdc1"); if(RT_NULL == tdc) { return -RT_ERROR; } if(RT_EOK != rt_device_open(tdc, RT_NULL)) { return -RT_ERROR; } #if 0 if(RT_EOK != rt_device_control(tdc, SPI_TDC_GP21_CTRL_MEASURE_TEMP, &temp_scales)) { return -RT_ERROR; } if(RT_EOK != rt_device_control(tdc, SPI_TDC_GP21_CTRL_MEASURE_TOF2, &tof_data)) { return -RT_ERROR; } if(RT_EOK != rt_device_close(tdc)) { return -RT_ERROR; } if(RT_EOK != rt_device_unregister(tdc)) { return -RT_ERROR; } #endif return RT_EOK; }
/** * @brief Called when a data is received on the telnet connection * @param arg the user argument * @param pcb the tcp_pcb that has received the data * @param p the packet buffer, 存放接收到的数据 * @param err the error value linked with the received data * @retval error value */ static err_t telnetd_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) { struct telnetio_dev *teldev = arg; TELNETD_DEBUG(("line:%d, %s(), p:0x%x, err:%d, teldev:0x%x\n", __LINE__, __FUNCTION__, p, err, teldev)); /* We perform here any necessary processing on the pbuf */ if (p != NULL) { /* We call this function to tell the LwIp that we have processed the data */ /* This lets the stack advertise a larger window, so more data can be received*/ tcp_recved(pcb, p->tot_len); /* Check the name if NULL, no data passed, return withh illegal argument error */ if(NULL == teldev) { pbuf_free(p); return ERR_ARG; } proc_rx_data(pcb, teldev, p); /* End of processing, we free the pbuf */ pbuf_free(p); } else if (err == ERR_OK) { /* When the pbuf is NULL and the err is ERR_OK, the remote end is closing the connection. */ /* We free the allocated memory and we close the connection */ //rt_device_close(&teldev->dev); finsh_set_device(CONSOLE_DEVICE); rt_console_set_device(CONSOLE_DEVICE); rt_device_unregister(&teldev->dev); telnetio_dev_delete(teldev); return tcp_close(pcb); } return ERR_OK; }
/** * This function will be invoked when usb device plug out is detected and it would clean * and release all hub class related resources. * * @param arg the argument. * * @return the error code, RT_EOK on successfully. */ static rt_err_t rt_usbh_adk_disable(void* arg) { uadk_t adk; struct uintf* intf = (struct uintf*)arg; RT_ASSERT(intf != RT_NULL); RT_DEBUG_LOG(RT_DEBUG_USB, ("rt_usbh_adk_stop\n")); adk = (uadk_t)intf->user_data; if(adk == RT_NULL) { rt_free(intf); return RT_EOK; } if(adk->pipe_in != RT_NULL) rt_usb_hcd_free_pipe(intf->device->hcd, adk->pipe_in); if(adk->pipe_out != RT_NULL) rt_usb_hcd_free_pipe(intf->device->hcd, adk->pipe_out); /* unregister adk device */ rt_device_unregister(&adk->device); /* free adk instance */ if(adk != RT_NULL) { rt_free(adk); } /* free interface instance */ rt_free(intf); return RT_EOK; }