📄 usbtty.lst
字号:
ep_descriptors[i - 1].bmAttributes;
endpoint_instance[i].tx_packetSize =
ep_descriptors[i - 1].wMaxPacketSize;
endpoint_instance[i].tx_attributes =
ep_descriptors[i - 1].bmAttributes;
urb_link_init (&endpoint_instance[i].rcv);
urb_link_init (&endpoint_instance[i].rdy);
urb_link_init (&endpoint_instance[i].tx);
urb_link_init (&endpoint_instance[i].done);
if (endpoint_instance[i].endpoint_address & USB_DIR_IN)
endpoint_instance[i].tx_urb =
usbd_alloc_urb (device_instance,
&endpoint_instance[i]);
else
endpoint_instance[i].rcv_urb =
usbd_alloc_urb (device_instance,
&endpoint_instance[i]);
}
}
static void usbtty_init_endpoints (void)
{
int i;
bus_instance->max_endpoints = NUM_ENDPOINTS + 1;
for (i = 0; i <= NUM_ENDPOINTS; i++) {
udc_setup_ep (device_instance, i, &endpoint_instance[i]);
}
}
/*********************************************************************************/
static struct urb *next_urb (struct usb_device_instance *device,
struct usb_endpoint_instance *endpoint)
C51 COMPILER V8.09 USBTTY 05/05/2008 19:48:27 PAGE 12
{
struct urb *current_urb = NULL;
int space;
/* If there's a queue, then we should add to the last urb */
if (!endpoint->tx_queue) {
current_urb = endpoint->tx_urb;
} else {
/* Last urb from tx chain */
current_urb =
p2surround (struct urb, link, endpoint->tx.prev);
}
/* Make sure this one has enough room */
space = current_urb->buffer_length - current_urb->actual_length;
if (space > 0) {
return current_urb;
} else { /* No space here */
/* First look at done list */
current_urb = first_urb_detached (&endpoint->done);
if (!current_urb) {
current_urb = usbd_alloc_urb (device, endpoint);
}
urb_append (&endpoint->tx, current_urb);
endpoint->tx_queue++;
}
return current_urb;
}
static int write_buffer (circbuf_t * buf)
{
if (!usbtty_configured ()) {
return 0;
}
if (buf->size) {
struct usb_endpoint_instance *endpoint =
&endpoint_instance[TX_ENDPOINT];
struct urb *current_urb = NULL;
char *dest;
int space_avail;
int popnum, popped;
int total = 0;
/* Break buffer into urb sized pieces, and link each to the endpoint */
while (buf->size > 0) {
current_urb = next_urb (device_instance, endpoint);
if (!current_urb) {
TTYERR ("current_urb is NULL, buf->size %d\n",
buf->size);
return total;
}
dest = current_urb->buffer +
current_urb->actual_length;
space_avail =
current_urb->buffer_length -
current_urb->actual_length;
C51 COMPILER V8.09 USBTTY 05/05/2008 19:48:27 PAGE 13
popnum = MIN (space_avail, buf->size);
if (popnum == 0)
break;
popped = buf_pop (buf, dest, popnum);
if (popped == 0)
break;
current_urb->actual_length += popped;
total += popped;
/* If endpoint->last == 0, then transfers have not started on this endpoint */
if (endpoint->last == 0) {
udc_endpoint_write (endpoint);
}
} /* end while */
return total;
} /* end if tx_urb */
return 0;
}
static int fill_buffer (circbuf_t * buf)
{
struct usb_endpoint_instance *endpoint =
&endpoint_instance[RECV_ENDPOINT];
if (endpoint->rcv_urb && endpoint->rcv_urb->actual_length) {
unsigned int nb = endpoint->rcv_urb->actual_length;
char *src = (char *) endpoint->rcv_urb->buffer;
buf_push (buf, src, nb);
endpoint->rcv_urb->actual_length = 0;
return nb;
}
return 0;
}
static int usbtty_configured (void)
{
return usbtty_configured_flag;
}
/*********************************************************************************/
static void usbtty_event_handler (struct usb_device_instance *device,
usb_device_event_t event, int data)
{
switch (event) {
case DEVICE_RESET:
case DEVICE_BUS_INACTIVE:
usbtty_configured_flag = 0;
break;
case DEVICE_CONFIGURED:
usbtty_configured_flag = 1;
break;
case DEVICE_ADDRESS_ASSIGNED:
usbtty_init_endpoints ();
C51 COMPILER V8.09 USBTTY 05/05/2008 19:48:27 PAGE 14
default:
break;
}
}
/*********************************************************************************/
/*
* Since interrupt handling has not yet been implemented, we use this function
* to handle polling. This is called by the tstc,getc,putc,puts routines to
* update the USB state.
*/
void usbtty_poll (void)
{
/* New interrupts? */
pretend_interrupts ();
/* Write any output data to host buffer (do this before checking interrupts to avoid missing one) */
if (usbtty_configured ()) {
write_buffer (&usbtty_output);
}
/* New interrupts? */
pretend_interrupts ();
/* Check for new data from host.. (do this after checking interrupts to get latest data) */
if (usbtty_configured ()) {
fill_buffer (&usbtty_input);
}
/* New interrupts? */
pretend_interrupts ();
}
static void pretend_interrupts (void)
{
/* Loop while we have interrupts.
* If we don't do this, the input chain
* polling delay is likely to miss
* host requests.
*/
while (inw (UDC_IRQ_SRC) & ~UDC_SOF_Flg) {
/* Handle any new IRQs */
omap1510_udc_irq ();
omap1510_udc_noniso_irq ();
}
}
#endif
C51 COMPILATION COMPLETE. 10 WARNING(S), 172 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -