/** * This function will stop cdc function, it will be called on handle set configuration request. * * @param func the usb function object. * * @return RT_EOK on successful. */ static rt_err_t _function_disable(ufunction_t func) { struct vcom *data; RT_ASSERT(func != RT_NULL); RT_DEBUG_LOG(RT_DEBUG_USB, ("cdc function disable\n")); _vcom_reset_state(func); data = (struct vcom*)func->user_data; if(data->ep_out->buffer != RT_NULL) { rt_free(data->ep_out->buffer); data->ep_out->buffer = RT_NULL; } return RT_EOK; }
/** * This function will run cdc function, it will be called on handle set configuration request. * * @param func the usb function object. * * @return RT_EOK on successful. */ static rt_err_t _function_enable(ufunction_t func) { struct vcom *data; RT_ASSERT(func != RT_NULL); RT_DEBUG_LOG(RT_DEBUG_USB, ("cdc function enable\n")); _vcom_reset_state(func); data = (struct vcom*)func->user_data; data->ep_out->buffer = rt_malloc(CDC_RX_BUFSIZE); data->ep_out->request.buffer = data->ep_out->buffer; data->ep_out->request.size = EP_MAXPACKET(data->ep_out); data->ep_out->request.req_type = UIO_REQUEST_READ_MOST; rt_usbd_io_request(func->device, data->ep_out, &data->ep_out->request); return RT_EOK; }
static int _vcom_putc(struct rt_serial_device *serial, char c) { rt_uint32_t level; int cnt; /*if (vcom_connected != RT_TRUE) { return 0; }*/ /* if the buffer is full, there is a chance that the host would pull some * data out soon. But we cannot rely on that and if we wait to long, just * return. */ for (cnt = 500; RT_RINGBUFFER_EMPTY(&tx_ringbuffer) == 0 && cnt; cnt--) { /*rt_kprintf("wait for %d\n", cnt);*/ /*if (vcom_connected != RT_TRUE) return 0;*/ } if (cnt == 0) { /* OK, we believe that the connection is lost. So don't send any more * data and act as the USB cable is not plugged in. Reset the VCOM * state machine */ _vcom_reset_state(); return 0; } level = rt_hw_interrupt_disable(); if (RT_RINGBUFFER_EMPTY(&tx_ringbuffer)) { rt_ringbuffer_putchar(&tx_ringbuffer, c); } rt_hw_interrupt_enable(level); return 1; }