#define USB_SET_VENDOR_NO_DATA (0x0000U)
#define USB_SET_VENDOR (0x0100U)
#define USB_GET_VENDOR (0x0200U)
#if (BSP_CFG_RTOS == 2)
void usb_apl_callback (usb_event_info_t * p_api_event, usb_hdl_t cur_task,
usb_onoff_t usb_state)
{
(void) usb_state;
(void) cur_task;
xQueueSend(g_apl_mbx_hdl, (const void *) &p_api_event, (TickType_t) (0))
}
#endif
void usb_pvnd_example (void)
{
#if (BSP_CFG_RTOS == 2)
usb_event_info_t * p_mess;
#endif
usb_event_info_t event_info;
uint8_t bulk_out_pipe = 0;
uint8_t bulk_in_pipe = 0;
uint8_t int_out_pipe = 0;
uint8_t int_in_pipe = 0;
uint16_t buf_type = 0;
uint8_t pipe = 0;
uint8_t is_zlp[2] = {0, 0};
uint32_t request_length = 0;
uint16_t used_pipe = 0;
usb_pipe_t pipe_info;
g_usb_on_usb.
open(&g_basic0_ctrl, &g_basic0_cfg);
memset(&event_info, 0, sizeof(usb_event_info_t));
while (1)
{
#if (BSP_CFG_RTOS == 2)
xQueueReceive(g_apl_mbx_hdl, (void *) &p_mess, portMAX_DELAY);
event_info = *p_mess;
event = event_info.event;
#else
g_usb_on_usb.
eventGet(&event_info, &event);
#endif
switch (event)
{
{
buffer_init();
is_zlp[0] = 0;
is_zlp[1] = 0;
for (pipe = START_PIPE; pipe < END_PIPE; pipe++)
{
if (0 != (used_pipe & (1 << pipe)))
{
g_usb_on_usb.
pipeInfoGet(&g_basic0_ctrl, &pipe_info, pipe);
{
{
buf_type = BUF_BULK;
bulk_out_pipe = pipe;
}
else
{
buf_type = BUF_INT;
int_out_pipe = pipe;
}
}
else
{
{
buf_type = BUF_BULK;
bulk_in_pipe = pipe;
}
else
{
buf_type = BUF_INT;
int_in_pipe = pipe;
}
}
}
}
break;
}
{
if (FSP_ERR_USB_FAILED != event_info.status)
{
if (bulk_out_pipe == event_info.pipe)
{
buf_type = BUF_BULK;
pipe = bulk_in_pipe;
}
else if (int_out_pipe == event_info.pipe)
{
buf_type = BUF_INT;
pipe = int_in_pipe;
}
else
{
while (1)
{
;
}
}
buffer_check(buf_type, event_info.data_size);
g_usb_on_usb.
pipeWrite(&g_basic0_ctrl, &g_buf[buf_type][0], event_info.data_size, pipe);
}
break;
}
{
if (bulk_in_pipe == event_info.pipe)
{
buf_type = BUF_BULK;
if (1 == is_zlp[buf_type])
{
pipe = bulk_out_pipe;
}
}
else if (int_in_pipe == event_info.pipe)
{
buf_type = BUF_INT;
if (1 == is_zlp[buf_type])
{
pipe = int_out_pipe;
}
}
else
{
}
if (1 == is_zlp[buf_type])
{
is_zlp[buf_type] = 0;
buffer_clear(buf_type);
g_usb_on_usb.
pipeRead(&g_basic0_ctrl, &g_buf[buf_type][0], BUF_SIZE, pipe);
}
else
{
is_zlp[buf_type] = 1;
g_usb_on_usb.
pipeWrite(&g_basic0_ctrl, 0, 0, event_info.pipe);
}
break;
}
{
if (USB_SET_VENDOR_NO_DATA == (event_info.setup.request_type &
USB_BREQUEST))
{
}
else if (USB_SET_VENDOR == (event_info.setup.request_type &
USB_BREQUEST))
{
request_length = event_info.setup.request_length;
}
else if (USB_GET_VENDOR == (event_info.setup.request_type &
USB_BREQUEST))
{
}
else
{
}
break;
}
{
if (USB_GET_VENDOR == (event_info.setup.request_type &
USB_BREQUEST))
{
g_usb_on_usb.
pipeRead(&g_basic0_ctrl, &g_buf[BUF_BULK][0], BUF_SIZE, bulk_out_pipe);
g_usb_on_usb.
pipeRead(&g_basic0_ctrl, &g_buf[BUF_INT][0], BUF_SIZE, int_out_pipe);
}
break;
}
{
break;
}
default:
{
break;
}
}
}
}
static void buffer_init (void)
{
uint16_t i;
uint16_t j;
for (j = 0; j < 2; j++)
{
for (i = 0; i < BUF_SIZE; i++)
{
g_buf[j][i] = (uint8_t) i;
}
}
}
static void buffer_check (uint16_t buf_type, uint32_t size)
{
uint16_t i;
for (i = 0; i < (uint16_t) size; i++)
{
if ((uint8_t) (i & USB_VALUE_FF) != g_buf[buf_type][i])
{
while (1)
{
;
}
}
}
}
static void buffer_clear (uint16_t buf_type)
{
uint16_t i;
for (i = 0; i < BUF_SIZE; i++)
{
g_buf[buf_type][i] = 0;
}
}