📄 usbdl_usbacm_drv.c
字号:
USB_Register_Drv_Info(USB_DRV_HDLR_EP_RX, ep_out_id, USB_Acm_BulkOut_Hdr);
g_UsbACM.data_ep_out_info->ep_reset = USB_Acm_BulkOut_Reset;
/* endpoint descriptor */
g_UsbACM.data_ep_in_info->epdesc.stdep.bLength = USB_EPDSC_LENGTH;
g_UsbACM.data_ep_in_info->epdesc.stdep.bDescriptorType = USB_ENDPOINT;
g_UsbACM.data_ep_in_info->epdesc.stdep.bEndpointAddress = (USB_EP_DIR_IN | ep_in_id); /*InPipe*/
g_UsbACM.data_ep_in_info->epdesc.stdep.bmAttributes = USB_EP_BULK;
g_UsbACM.data_ep_in_info->epdesc.stdep.wMaxPacketSize[0] = USBDL_EP_BULK_MAXP&0xff;
g_UsbACM.data_ep_in_info->epdesc.stdep.wMaxPacketSize[1] = (USBDL_EP_BULK_MAXP>>8)&0xff;
g_UsbACM.data_ep_in_info->epdesc.stdep.bInterval = 0;
g_UsbACM.data_ep_in_info->ep_status.epin_status.byEP = ep_in_id;
g_UsbACM.data_ep_in_info->ep_status.epin_status.nBytesLeft = USB_EP_NODATA;
g_UsbACM.data_ep_out_info->epdesc.stdep.bLength = USB_EPDSC_LENGTH;
g_UsbACM.data_ep_out_info->epdesc.stdep.bDescriptorType = USB_ENDPOINT;
g_UsbACM.data_ep_out_info->epdesc.stdep.bEndpointAddress = (USB_EP_DIR_OUT | ep_out_id); /*OutPipe*/
g_UsbACM.data_ep_out_info->epdesc.stdep.bmAttributes = USB_EP_BULK;
g_UsbACM.data_ep_out_info->epdesc.stdep.wMaxPacketSize[0] = USBDL_EP_BULK_MAXP&0xff;
g_UsbACM.data_ep_out_info->epdesc.stdep.wMaxPacketSize[1] = (USBDL_EP_BULK_MAXP>>8)&0xff;
g_UsbACM.data_ep_out_info->epdesc.stdep.bInterval = 0;
g_UsbACM.data_ep_out_info->ep_status.epout_status.byEP = ep_out_id;
}
/* data interface reset function, enable EP*/
void USB_Acm_DataIf_Reset(void)
{
g_UsbACM.txpipe = &g_UsbACM.data_ep_in_info->ep_status.epin_status;
g_UsbACM.rxpipe = &g_UsbACM.data_ep_out_info->ep_status.epout_status;
/* Non-DMA */
USB_TxEPEn(g_UsbACM.txpipe->byEP, KAL_FALSE, KAL_TRUE);
/*Non-DMA*/
USB_RxEPEn(g_UsbACM.rxpipe->byEP, KAL_FALSE, KAL_TRUE);
}
/************************************************************
global variable g_UsbACM initialize and release functions
*************************************************************/
/* initialize global variable g_UsbACM */
void USB_Init_Acm_Status(void)
{
g_UsbACM.txpipe = NULL;
g_UsbACM.rxpipe = NULL;
g_UsbACM.intrpipe = NULL;
g_UsbACM.data_interface_id = 0;
// g_UsbACM.break_detect = KAL_FALSE;
// g_UsbACM.break_number = 0;
// g_UsbACM.out_pipe_race = KAL_FALSE;
// g_UsbACM.send_Txilm = KAL_FALSE;
// g_UsbACM.send_Rxilm = KAL_TRUE;
// g_UsbACM.send_UARTilm = KAL_FALSE;
// g_UsbACM.ring_buffer_timer_counting = KAL_FALSE;
}
#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
/************************************************************
EP0 handle functions
************************************************************/
/* set USB request line coding to UART DCB structure */
static void USB_Acm_Ep0_SetLineCoding(void *data)
{
kal_uint32 nCount;
/* read setting and set to UART structure*/
nCount = USB_EP0_Pkt_Len();
if(nCount > 0)
{
USB_EPFIFORead(0, nCount, &g_UsbACM.line_coding);
USB2UART_LineCoding2DCB(&g_UsbACM.line_coding, &USB2UARTPort.DCB);
gUsbDevice.ep0_state = USB_EP0_RX_STATUS;
USB_Update_EP0_State(USB_EP0_DRV_STATE_READ_END, KAL_FALSE, KAL_TRUE);
}
}
/* parse class specific request */
static void USB_Acm_Ep0_Command(Usb_Ep0_Status* pep0state,Usb_Command* pcmd)
{
kal_uint8 bError = KAL_FALSE;
switch (pcmd->bRequest)
{
case USB_ACM_SET_LINE_CODING:
/* register handler to handle the get data*/
USB_Register_EP0_RxHdlr(USB_Acm_Ep0_SetLineCoding);
gUsbDevice.ep0_state =USB_EP0_RX;
break;
case USB_ACM_GET_LINE_CODING:
/* tell host the current setting */
USB_Generate_EP0Data(pep0state, pcmd, &g_UsbACM.line_coding, 7);
break;
case USB_ACM_SET_CONTROL_LINE_STATE:
case USB_ACM_SEND_BREAK:
/* do not need to do anything */
break;
case USB_ACM_SEND_ENCAPSULATED_COMMAND:
case USB_ACM_GET_ENCAPSULATED_RESPONSE:
case USB_ACM_SET_COMM_FEATURE:
case USB_ACM_GET_COMM_FEATURE:
case USB_ACM_CLEAR_COMM_FEATURE:
default:
#ifdef __PRODUCTION_RELEASE__
bError = KAL_TRUE;
#else
ASSERT(0);
#endif
break;
}
/* Stall command if an error occured */
if (gUsbDevice.ep0_state == USB_EP0_IDLE)
{
gUsbDevice.ep0_state = USB_EP0_RX_STATUS;
USB_Update_EP0_State(USB_EP0_DRV_STATE_READ_END, bError, KAL_TRUE);
}
else
{
USB_Update_EP0_State(USB_EP0_DRV_STATE_READ_END, bError, KAL_FALSE);
}
}
/************************************************************
Bulk EP OUT handle functions
*************************************************************/
/*
Used to retreive exception log, all interrupts are disabled
Note that this is special for sending exception log since interrupt is disabled when exception occurs
It must not be used in normal time
*/
/*
void USB2UART_Polling_Recv_Data(void)
{
USB_Polling_Recv_Data(g_UsbACM.rxpipe->byEP);
}
*/
//#define USBDL_DEBUG
#ifdef USBDL_DEBUG
#pragma arm section zidata = "LARGE_BUFFER"
typedef struct{
kal_int32 roomleft;
kal_uint32 count;
}acm_bulkout_array;
acm_bulkout_array bulkarray[256];
kal_uint8 bulkindex;
static kal_uint32 total_count;
#pragma arm section zidata
#endif
/* EP Bulk Out interrupt handler, called by EP interrupt */
#if 1
static void USB_Acm_BulkOut_Hdr(void )
{
kal_uint32 nCount;
if(usbacm_rx_buf.len != 0)
ASSERT(0);
nCount = USB_EP_Rx_Pkt_Len(g_UsbACM.rxpipe->byEP);
usbacm_rx_buf.len = nCount;
USB_EPFIFORead(g_UsbACM.rxpipe->byEP, nCount, usbacm_rx_buf.data);
USB_EP_Bulk_Rx_Ready(g_UsbACM.rxpipe->byEP);
}
#else
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#ifdef USBDL_DEBUG
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
/* EP Bulk In reset handler */
static void USB_Acm_BulkIn_Reset(void)
{
g_UsbACM.txpipe = &g_UsbACM.data_ep_in_info->ep_status.epin_status;
usbacm_tx_buf.len = 0;
}
static void USB_Acm_BulkIn_Hdr(void)
{
#if defined(__USB_DOWNLOAD__) && defined(USBACM_TX_WITHOUT_DMA)
gUSBAcm_IsInEPComplete = KAL_TRUE;
#endif
}
/* EP Bulk Out reset handler */
static void USB_Acm_BulkOut_Reset(void)
{
g_UsbACM.rxpipe = &g_UsbACM.data_ep_out_info->ep_status.epout_status;
usbacm_rx_buf.len = 0;
}
#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
#endif /* __USB_DOWNLOAD__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -