1 //==========================================================================
5 // Driver for the AT91 USB device
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 2006 eCosCentric
12 // Copyright (C) 2006 Andrew Lunn
14 // eCos is free software; you can redistribute it and/or modify it under
15 // the terms of the GNU General Public License as published by the Free
16 // Software Foundation; either version 2 or (at your option) any later version.
18 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 // You should have received a copy of the GNU General Public License along
24 // with eCos; if not, write to the Free Software Foundation, Inc.,
25 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 // As a special exception, if other files instantiate templates or use macros
28 // or inline functions from this file, or you compile this file and link it
29 // with other works to produce a work based on this file, this file does not
30 // by itself cause the resulting work to be covered by the GNU General Public
31 // License. However the source code for this file must still be made available
32 // in accordance with section (3) of the GNU General Public License.
34 // This exception does not invalidate any other reasons why a work based on
35 // this file might be covered by the GNU General Public License.
36 // -------------------------------------------
37 //####ECOSGPLCOPYRIGHTEND####
38 //==========================================================================
39 //#####DESCRIPTIONBEGIN####
41 // Author(s): Oliver Munz,
42 // Contributors: Andrew Lunn, bartv
45 // This code implements support for the on-chip USB port on the AT91
46 // family of processors. The code has been developed on the AT91SAM7S
47 // and may or may not work on other members of the AT91 family.
49 //####DESCRIPTIONEND####
50 //==========================================================================
52 #include <pkgconf/devs_usb_at91.h>
53 #include <cyg/io/usb/usb.h>
54 #include <cyg/io/usb/usbs.h>
55 #include <cyg/io/usb/usbs_at91.h>
57 #include <cyg/hal/hal_io.h>
58 #include <cyg/hal/drv_api.h>
59 #include <cyg/hal/hal_io.h>
60 #include <cyg/hal/hal_platform_ints.h>
61 #include <cyg/infra/cyg_ass.h>
62 #include <cyg/infra/diag.h>
67 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
70 #define AT91_UDP_CSR0 (AT91_UDP_CSR)
71 #define AT91_UDP_FDR0 (AT91_UDP_FDR)
73 #define pIER (AT91_UDP + AT91_UDP_IER)
74 #define pIDR (AT91_UDP + AT91_UDP_IDR)
75 #define pISR (AT91_UDP + AT91_UDP_ISR)
76 #define pIMR (AT91_UDP + AT91_UDP_IMR)
77 #define pICR (AT91_UDP + AT91_UDP_ICR)
79 #define pCSR0 (AT91_UDP + AT91_UDP_CSR0)
80 #define pFDR0 (AT91_UDP + AT91_UDP_FDR0)
82 #define pCSRn(N) (pCSR0 + (N * 4))
83 #define pFDRn(N) (pFDR0 + (N * 4))
85 #define AT91_UDP_ALLOWED_IRQs \
86 (AT91_UDP_WAKEUP | AT91_UDP_ENDBUSRES | AT91_UDP_EXTRSM | \
87 AT91_UDP_RXRSM | AT91_UDP_RXSUSP | AT91_UDP_EPINT0 | \
88 AT91_UDP_EPINT1 | AT91_UDP_EPINT2 | AT91_UDP_EPINT3)
90 #define THERE_IS_A_NEW_PACKET_IN_THE_UDP 0xffff
92 // Fifo size for each end point.
93 static const cyg_uint16 usbs_at91_endpoint_fifo_size[AT91_USB_ENDPOINTS] = {
100 // Does an endpoint support ping pong buffering?
101 static const bool usbs_at91_endpoint_pingpong[AT91_USB_ENDPOINTS] = {
108 static cyg_uint8 *usbs_at91_endpoint_pbegin[AT91_USB_ENDPOINTS] =
110 static cyg_uint8 *usbs_at91_endpoint_pend[AT91_USB_ENDPOINTS] =
112 static bool usbs_at91_endpoint_bank1[AT91_USB_ENDPOINTS] =
113 { false, false, false, false };
114 static cyg_uint16 usbs_at91_endpoint_bytes_in_fifo[AT91_USB_ENDPOINTS] =
116 static cyg_uint16 usbs_at91_endpoint_bytes_received[AT91_USB_ENDPOINTS] =
117 { THERE_IS_A_NEW_PACKET_IN_THE_UDP, THERE_IS_A_NEW_PACKET_IN_THE_UDP,
118 THERE_IS_A_NEW_PACKET_IN_THE_UDP, THERE_IS_A_NEW_PACKET_IN_THE_UDP};
120 static cyg_interrupt usbs_at91_intr_data;
121 static cyg_handle_t usbs_at91_intr_handle;
123 static void usbs_at91_ep0_start(usbs_control_endpoint *);
124 static void usbs_at91_poll(usbs_control_endpoint *);
126 static void usbs_at91_endpoint_start(usbs_rx_endpoint * pep);
127 static void usbs_at91_endpoint_set_halted(usbs_rx_endpoint * pep,
129 void usbs_at91_endpoint_init(usbs_rx_endpoint * pep,
130 cyg_uint8 endpoint_type,
133 // Endpoint 0, the control endpoint, structure.
134 usbs_control_endpoint usbs_at91_ep0 = {
135 // The hardware does not distinguish between detached, attached and powered.
136 state: USBS_STATE_POWERED,
137 enumeration_data: (usbs_enumeration_data *) 0,
138 start_fn: usbs_at91_ep0_start,
139 poll_fn: usbs_at91_poll,
140 interrupt_vector: CYGNUM_HAL_INTERRUPT_UDP,
141 control_buffer: {0, 0, 0, 0, 0, 0, 0, 0},
142 state_change_fn: (void (*) (usbs_control_endpoint *,
143 void *, usbs_state_change, int)) 0,
144 state_change_data: (void *) 0,
145 standard_control_fn: (usbs_control_return (*)
146 (usbs_control_endpoint *, void *)) 0,
147 standard_control_data: (void *) 0,
148 class_control_fn: (usbs_control_return (*)
149 (usbs_control_endpoint *, void *)) 0,
150 class_control_data: (void *) 0,
151 vendor_control_fn: (usbs_control_return (*)
152 (usbs_control_endpoint *, void *)) 0,
153 vendor_control_data: (void *) 0,
154 reserved_control_fn: (usbs_control_return (*)
155 (usbs_control_endpoint *, void *)) 0,
156 reserved_control_data: (void *) 0,
157 buffer: (unsigned char *) 0,
159 fill_buffer_fn: (void (*)(usbs_control_endpoint *)) 0,
160 fill_data: (void *) 0,
162 complete_fn: (usbs_control_return (*)(usbs_control_endpoint *,
166 // Endpoint 1 receive control structure
167 usbs_rx_endpoint usbs_at91_ep1 = {
168 start_rx_fn: usbs_at91_endpoint_start,
169 set_halted_fn: usbs_at91_endpoint_set_halted,
170 complete_fn: (void (*)(void *, int)) 0,
171 complete_data: (void *) 0,
172 buffer: (unsigned char *) 0,
177 // Endpoint 2 Receive control structure
178 usbs_rx_endpoint usbs_at91_ep2 = {
179 start_rx_fn: usbs_at91_endpoint_start,
180 set_halted_fn: usbs_at91_endpoint_set_halted,
181 complete_fn: (void (*)(void *, int)) 0,
182 complete_data: (void *) 0,
183 buffer: (unsigned char *) 0,
188 // Endpoint 3 Receive control structure
189 usbs_rx_endpoint usbs_at91_ep3 = {
190 start_rx_fn: usbs_at91_endpoint_start,
191 set_halted_fn: usbs_at91_endpoint_set_halted,
192 complete_fn: (void (*)(void *, int)) 0,
193 complete_data: (void *) 0,
194 buffer: (unsigned char *) 0,
199 // Array of end points. Used for translating end point pointer to an
201 static const void *usbs_at91_endpoints[AT91_USB_ENDPOINTS] = {
202 (void *) &usbs_at91_ep0,
203 (void *) &usbs_at91_ep1,
204 (void *) &usbs_at91_ep2,
205 (void *) &usbs_at91_ep3
208 // Convert an endpoint pointer to an endpoint number, using the array
209 // of endpoint structures
211 usbs_at91_pep_to_number(const usbs_rx_endpoint * pep)
215 for(epn=0; epn < AT91_USB_ENDPOINTS; epn++) {
216 if (pep == usbs_at91_endpoints[epn])
219 CYG_FAIL("Unknown endpoint");
223 typedef enum ep0_low_level_status_t {
228 EP0_LL_RECEIVE_READY,
232 } ep0_low_level_status_t;
234 // Enable/Disable interrupts for a specific endpoint.
236 usbs_at91_endpoint_interrupt_enable (cyg_uint8 epn, bool enable)
238 CYG_ASSERT (epn < AT91_USB_ENDPOINTS, "Invalid endpoint");
241 HAL_WRITE_UINT32 (pIER, 1 << epn);
243 HAL_WRITE_UINT32 (pIDR, 1 << epn);
248 read_fifo_uint8 (cyg_uint8 * pdest, cyg_addrword_t psource, cyg_uint32 size)
250 cyg_uint8 *preqbyte = pdest;
254 HAL_READ_UINT8 (psource, reqbyte);
263 write_fifo_uint8 (cyg_addrword_t pdest, cyg_uint8 * psource,
264 cyg_uint8 * psource_end)
268 for (preqbyte = psource; preqbyte < psource_end; preqbyte++) {
269 HAL_WRITE_UINT8 (pdest, (*preqbyte));
275 /* Tell the host that the device is ready to start communication */
277 usbs_at91_set_pullup (bool set)
280 #ifndef CYGDAT_DEVS_USB_AT91_GPIO_SET_PULLUP_PIN_NONE
282 #ifdef CYGNUM_DEVS_USB_AT91_GPIO_SET_PULLUP_INVERTED
288 HAL_ARM_AT91_GPIO_SET(CYGDAT_DEVS_USB_AT91_GPIO_SET_PULLUP_PIN);
290 HAL_ARM_AT91_GPIO_RESET(CYGDAT_DEVS_USB_AT91_GPIO_SET_PULLUP_PIN);
295 /* Is the USB powered? */
297 usbs_at91_read_power (void)
299 #ifndef CYGDAT_DEVS_USB_AT91_GPIO_READ_POWER_PIN_NONE
302 HAL_ARM_AT91_GPIO_GET(CYGDAT_DEVS_USB_AT91_GPIO_READ_POWER_PIN, state);
303 #ifdef CYGNUM_DEVS_USB_AT91_GPIO_READ_POWER_INVERTED
312 // Stop all transfers that are currently active.
314 usbs_end_all_transfers (usbs_control_return returncode)
317 usbs_rx_endpoint *pep;
319 for (epn = 1; epn < AT91_USB_ENDPOINTS; epn++) {
320 if (BITS_ARE_SET (pIMR, 1 << epn)) {
321 // If the end point is transmitting, call the complete function
322 // to terminate to transfer
323 pep = (usbs_rx_endpoint *) usbs_at91_endpoints[epn];
325 if (pep->complete_fn) {
326 (*pep->complete_fn) (pep->complete_data, returncode);
328 // Disable interrupts from the endpoint
329 usbs_at91_endpoint_interrupt_enable (epn, false);
334 // There has been a change in state. Update the end point.
336 usbs_state_notify (usbs_control_endpoint * pcep)
338 static int old_state = USBS_STATE_CHANGE_POWERED;
339 int state = pcep->state & USBS_STATE_MASK;
341 if (pcep->state != old_state) {
342 usbs_end_all_transfers (-EPIPE);
344 case USBS_STATE_DETACHED:
345 case USBS_STATE_ATTACHED:
346 case USBS_STATE_POWERED:
349 case USBS_STATE_DEFAULT:
350 HAL_WRITE_UINT32 (AT91_UDP + AT91_UDP_GLB_STATE, 0);
352 case USBS_STATE_ADDRESSED:
353 HAL_WRITE_UINT32 (AT91_UDP + AT91_UDP_GLB_STATE, AT91_UDP_GLB_FADDEN);
355 case USBS_STATE_CONFIGURED:
356 HAL_WRITE_UINT32 (AT91_UDP + AT91_UDP_GLB_STATE, AT91_UDP_GLB_CONFG);
359 CYG_FAIL("Unknown endpoint state");
362 if (pcep->state_change_fn) {
363 (*pcep->state_change_fn) (pcep, 0, pcep->state, old_state);
366 old_state = pcep->state;
370 static usbs_control_return
371 usbs_parse_host_get_command (usbs_control_endpoint * pcep)
373 usbs_control_return retcode;
374 cyg_uint8 dev_req_type =
375 (((usb_devreq *) pcep->control_buffer)->type) & USB_DEVREQ_TYPE_MASK;
377 switch (dev_req_type) {
378 case USB_DEVREQ_TYPE_STANDARD:
379 if (!pcep->standard_control_fn) {
380 return usbs_handle_standard_control (pcep);
384 (*pcep->standard_control_fn) (pcep, pcep->standard_control_data);
386 if (retcode == USBS_CONTROL_RETURN_UNKNOWN) {
387 return usbs_handle_standard_control (pcep);
391 case USB_DEVREQ_TYPE_CLASS:
392 if (!pcep->class_control_fn) {
393 return USBS_CONTROL_RETURN_STALL;
395 return (*pcep->class_control_fn) (pcep, pcep->class_control_data);
397 case USB_DEVREQ_TYPE_VENDOR:
398 if (!pcep->class_control_fn) {
399 return USBS_CONTROL_RETURN_STALL;
401 return (*pcep->class_control_fn) (pcep, pcep->vendor_control_data);
403 case USB_DEVREQ_TYPE_RESERVED:
404 if (!pcep->reserved_control_fn) {
405 return USBS_CONTROL_RETURN_STALL;
407 return (*pcep->reserved_control_fn) (pcep, pcep->reserved_control_data);
409 return USBS_CONTROL_RETURN_STALL;
414 usbs_at91_endpoint_set_halted (usbs_rx_endpoint * pep, cyg_bool new_value)
416 int epn = usbs_at91_pep_to_number(pep);
417 cyg_addrword_t pCSR = pCSRn(epn);
421 if (pep->halted != new_value) {
422 /* There is something is to do */
423 pep->halted = new_value;
425 if (new_value && BITS_ARE_SET (pIMR, 1 << epn)) {
426 /* Ready to transmit */
427 if (pep->complete_fn) {
428 (*pep->complete_fn) (pep->complete_data, -EAGAIN);
430 usbs_at91_endpoint_interrupt_enable (epn, false);
431 SET_BITS (pCSR, AT91_UDP_CSR_FORCESTALL);
433 CLEAR_BITS (pCSR, AT91_UDP_CSR_FORCESTALL);
436 cyg_drv_dsr_unlock ();
440 usbs_at91_endpoint_init (usbs_rx_endpoint * pep, cyg_uint8 endpoint_type,
443 int epn = usbs_at91_pep_to_number(pep);
444 cyg_addrword_t pCSR = pCSRn(epn);
446 CYG_ASSERT (AT91_USB_ENDPOINTS > epn, "Invalid end point");
448 usbs_at91_endpoint_interrupt_enable (epn, false);
450 HAL_WRITE_UINT32 (AT91_UDP + AT91_UDP_RST_EP, 1 << epn);
451 HAL_WRITE_UINT32 (AT91_UDP + AT91_UDP_RST_EP, 0);
456 HAL_WRITE_UINT32 (pCSR, (((((cyg_uint32) endpoint_type) & 0x03) << 8) |
457 ((((cyg_uint32) endpoint_type) & 0x80) << 3)));
459 usbs_at91_endpoint_bytes_in_fifo[epn] = 0;
460 usbs_at91_endpoint_bytes_received[epn] = THERE_IS_A_NEW_PACKET_IN_THE_UDP;
461 usbs_at91_endpoint_bank1[epn] = false;
464 SET_BITS (pCSR, AT91_UDP_CSR_EPEDS);
469 usbs_at91_handle_reset (void)
472 const usb_endpoint_descriptor *usb_endpoints;
473 cyg_uint8 endpoint_type;
475 cyg_uint8 endpoint_number;
477 usbs_end_all_transfers (-EPIPE);
479 HAL_WRITE_UINT32 (AT91_UDP + AT91_UDP_IDR, 0xffffffff);
480 HAL_WRITE_UINT32 (AT91_UDP + AT91_UDP_ICR, 0xffffffff);
481 HAL_WRITE_UINT32 (AT91_UDP + AT91_UDP_RST_EP, 0xffffffff);
482 HAL_WRITE_UINT32 (AT91_UDP + AT91_UDP_RST_EP, 0x00000000);
484 HAL_WRITE_UINT32 (AT91_UDP + AT91_UDP_FADDR, AT91_UDP_FADDR_FEN);
485 HAL_WRITE_UINT32 (AT91_UDP + AT91_UDP_CSR0,
486 AT91_UDP_CSR_EPEDS | AT91_UDP_CSR_EPTYPE_CTRL);
487 HAL_WRITE_UINT32 (AT91_UDP + AT91_UDP_IER, AT91_UDP_ALLOWED_IRQs);
489 for (epn=1; epn < AT91_USB_ENDPOINTS; epn++) {
490 usbs_at91_endpoint_init ((usbs_rx_endpoint *)usbs_at91_endpoints[epn],
494 // Now walk the endpoints configuring them correctly. This only
495 // works if there is one interface.
496 usb_endpoints = usbs_at91_ep0.enumeration_data->endpoints;
499 epn <= usbs_at91_ep0.enumeration_data->total_number_endpoints;
502 endpoint_type = (usb_endpoints[epn-1].attributes |
503 (usb_endpoints[epn-1].endpoint &
504 USB_ENDPOINT_DESCRIPTOR_ENDPOINT_IN ?
505 USB_ENDPOINT_DESCRIPTOR_ENDPOINT_IN :
506 USB_ENDPOINT_DESCRIPTOR_ENDPOINT_OUT));
507 endpoint_number = usb_endpoints[epn-1].endpoint & ~(USB_ENDPOINT_DESCRIPTOR_ENDPOINT_IN);
508 if ( endpoint_number < AT91_USB_ENDPOINTS )
510 usbs_at91_endpoint_init((usbs_rx_endpoint *)usbs_at91_endpoints[endpoint_number],
518 usbs_at91_ep0_start (usbs_control_endpoint * endpoint)
520 usbs_at91_handle_reset ();
522 // If there is additional platform-specific initialization to
523 // perform, do it now. This macro can come from the platform HAL,
524 // but may not be available on all platforms.
525 #ifdef AT91_USB_PLATFORM_INIT
526 AT91_USB_PLATFORM_INIT ();
529 usbs_at91_set_pullup (true);
533 usbs_at91_endpoint_start (usbs_rx_endpoint * pep)
535 int epn = usbs_at91_pep_to_number(pep);
536 cyg_addrword_t pCSR = pCSRn(epn);
537 cyg_addrword_t pFDR = pFDRn(epn);
538 cyg_uint16 space = 0;
539 cyg_uint16 endpoint_size = usbs_at91_endpoint_fifo_size[epn];
540 cyg_uint8 **ppbegin = &usbs_at91_endpoint_pbegin[epn];
541 cyg_uint8 **ppend = &usbs_at91_endpoint_pend[epn];
543 CYG_ASSERT (pep->complete_fn, "No complete_fn()");
546 if (usbs_at91_ep0.state != USBS_STATE_CONFIGURED) {
547 /* If not configured it means there is nothing to do */
548 cyg_drv_dsr_unlock ();
550 if (pep->complete_fn) {
551 (*pep->complete_fn) (pep->complete_data, -EPIPE);
557 /* Halted means nothing to do */
558 cyg_drv_dsr_unlock ();
560 if (pep->complete_fn) {
561 (*pep->complete_fn) (pep->complete_data, -EAGAIN);
566 if (BITS_ARE_SET (pIMR, 1 << epn)) {
567 cyg_drv_dsr_unlock ();
569 if (pep->complete_fn) {
570 (*pep->complete_fn) (pep->complete_data, -EIO);
576 CYG_ASSERT (BITS_ARE_SET (pCSR, 1 << 9), "Wrong endpoint type");
578 *ppbegin = pep->buffer; /* Set the working pointers */
579 *ppend = (cyg_uint8 *) ((cyg_uint32) pep->buffer + pep->buffer_size);
581 if (BITS_ARE_SET (pCSR, 0x400)) { /* IN: tx_endpoint */
582 space = (cyg_uint32) * ppend - (cyg_uint32) * ppbegin;
583 if (space == endpoint_size) {
584 *ppend = *ppbegin; /* Send zero-packet */
588 write_fifo_uint8 (pFDR, *ppbegin,
589 (cyg_uint8 *) ((cyg_uint32) * ppbegin +
590 MIN (space, endpoint_size)));
591 SET_BITS (pCSR, AT91_UDP_CSR_TXPKTRDY);
593 if (*ppend == *ppbegin) { /* Last packet ? */
594 *ppend = *ppbegin - 1; /* The packet hasn't been sent yet */
598 usbs_at91_endpoint_interrupt_enable (epn, true);
600 cyg_drv_dsr_unlock ();
603 // Perform transmit handling on an endpoint
605 usbs_at91_endpoint_isr_tx(cyg_uint8 epn)
607 cyg_addrword_t pCSR = pCSRn(epn);
608 cyg_addrword_t pFDR = pFDRn(epn);
609 cyg_uint8 **ppbegin = &usbs_at91_endpoint_pbegin[epn];
610 cyg_uint8 **ppend = &usbs_at91_endpoint_pend[epn];
611 cyg_uint32 space = 0;
612 cyg_uint16 endpoint_size = usbs_at91_endpoint_fifo_size[epn];
614 CLEAR_BITS (pCSR, AT91_UDP_CSR_TXCOMP);
616 if (BITS_ARE_CLEARED (pCSR, AT91_UDP_CSR_TXPKTRDY)) {
617 /* Ready to transmit ? */
618 if (*ppend > *ppbegin) {
619 /* Something to send */
621 space = (cyg_uint32) * ppend - (cyg_uint32) * ppbegin;
622 if (space == endpoint_size) {
623 *ppend = *ppbegin; /* Send zero-packet */
627 write_fifo_uint8 (pFDR, *ppbegin,
628 (cyg_uint8 *) ((cyg_uint32) * ppbegin +
629 MIN (space, endpoint_size)));
630 SET_BITS (pCSR, AT91_UDP_CSR_TXPKTRDY);
632 if (*ppend == *ppbegin) { /* Last packet ? */
633 *ppend = *ppbegin - 1; /* The packet isn't sent yet */
636 if (*ppend + 1 == *ppbegin) {
637 *ppend = *ppbegin; /* Flag for DSR */
640 *ppend = *ppbegin - 1; /* Flag for zero-packet */
641 SET_BITS (pCSR, AT91_UDP_CSR_TXPKTRDY); /* Send no data */
647 AT91_UDP_CSR_RX_DATA_BK0 | AT91_UDP_CSR_RX_DATA_BK1 |
648 AT91_UDP_CSR_RXSETUP | AT91_UDP_CSR_ISOERROR);
653 usbs_at91_endpoint_isr_rx(cyg_uint8 epn)
655 cyg_addrword_t pCSR = pCSRn(epn);
656 cyg_addrword_t pFDR = pFDRn(epn);
657 cyg_uint16 *pinfifo = &usbs_at91_endpoint_bytes_in_fifo[epn];
658 cyg_uint8 **ppbegin = &usbs_at91_endpoint_pbegin[epn];
659 cyg_uint8 **ppend = &usbs_at91_endpoint_pend[epn];
660 cyg_uint16 *preceived = &usbs_at91_endpoint_bytes_received[epn];
661 cyg_uint16 endpoint_size = usbs_at91_endpoint_fifo_size[epn];
663 if (*preceived == THERE_IS_A_NEW_PACKET_IN_THE_UDP) {
664 /* There is a new packet */
665 *preceived = ((*(cyg_uint32 *)pCSR) >> 16) & 0x7ff;
666 *pinfifo = *preceived;
669 while ((*ppbegin < *ppend) && *pinfifo) {
670 /* If we have buffer-space AND data in the FIFO */
671 HAL_READ_UINT8(pFDR, **ppbegin);
676 if (*ppbegin == *ppend) {
677 /* The buffer is full... call the DSR */
682 /* If the FIFO is empty, then we can release it */
683 if (usbs_at91_endpoint_pingpong[epn]) {
684 /* Time to clear the interrupt flag */
686 if (usbs_at91_endpoint_bank1[epn]) {
687 CLEAR_BITS (pCSR, AT91_UDP_CSR_RX_DATA_BK1);
689 CLEAR_BITS (pCSR, AT91_UDP_CSR_RX_DATA_BK0);
691 usbs_at91_endpoint_bank1[epn] = !usbs_at91_endpoint_bank1[epn];
693 CLEAR_BITS (pCSR, AT91_UDP_CSR_RX_DATA_BK0);
696 if (*preceived < endpoint_size) {
697 /* If the last packet was smaller then the endpoint-size... */
699 *preceived = THERE_IS_A_NEW_PACKET_IN_THE_UDP; /* Set flag */
701 return true; /* We can call the completion-function in the DSR */
704 *preceived = THERE_IS_A_NEW_PACKET_IN_THE_UDP; /* Set flag */
709 // ISR for an endpoint. Handle receive and transmit interrupts.
711 usbs_at91_endpoint_isr (cyg_uint8 epn)
713 cyg_addrword_t pCSR = pCSRn(epn);
715 CYG_ASSERT (AT91_USB_ENDPOINTS > epn && epn, "Invalid end point");
717 if (BITS_ARE_SET (pCSR, 0x400)) { /* IN: tx_endpoint */
718 if (usbs_at91_endpoint_isr_tx(epn))
719 return true; // Call the DSR
720 } else { /* OUT: rx_endpoint */
721 if (!BITS_ARE_CLEARED (pCSR, AT91_UDP_CSR_RX_DATA_BK0) ||
722 !BITS_ARE_CLEARED (pCSR, AT91_UDP_CSR_RX_DATA_BK1)) {
723 /* Sometime something received ? */
724 if(usbs_at91_endpoint_isr_rx(epn))
725 return true; // Call the DSR;
729 AT91_UDP_CSR_TXCOMP | AT91_UDP_CSR_RXSETUP |
730 AT91_UDP_CSR_ISOERROR);
736 // Handle a DSR for an endpoint
738 usbs_at91_endpoint_dsr (cyg_uint8 epn)
740 usbs_rx_endpoint *pep = (usbs_rx_endpoint *) usbs_at91_endpoints[epn];
741 cyg_uint8 **ppbegin = &usbs_at91_endpoint_pbegin[epn];
742 cyg_uint8 **ppend = &usbs_at91_endpoint_pend[epn];
744 CYG_ASSERT (AT91_USB_ENDPOINTS > epn && epn, "Invalid end point");
745 CYG_ASSERT (pep->complete_fn, "No complete_fn()");
747 if (*ppend == *ppbegin) { /* Transmitted/Received ? */
749 pep->buffer_size = (cyg_uint32) * ppbegin - (cyg_uint32) pep->buffer;
750 if (pep->buffer_size && pep->complete_fn) {
752 (*pep->complete_fn) (pep->complete_data, pep->buffer_size);
754 (*pep->complete_fn) (pep->complete_data, -EAGAIN);
757 usbs_at91_endpoint_interrupt_enable (epn, false);
761 // Handle an error condition on the control endpoint
762 static ep0_low_level_status_t
763 usbs_at91_control_error(ep0_low_level_status_t status)
765 cyg_uint8 **ppbegin = &usbs_at91_endpoint_pbegin[0];
766 cyg_uint8 **ppend = &usbs_at91_endpoint_pend[0];
768 usbs_at91_ep0.buffer_size = 0;
769 usbs_at91_ep0.fill_buffer_fn = 0;
770 usbs_at91_ep0.complete_fn = 0;
772 *ppbegin = usbs_at91_ep0.buffer;
775 if (status == EP0_LL_IDLE) {
776 if (usbs_at91_ep0.complete_fn) {
777 (*usbs_at91_ep0.complete_fn) (&usbs_at91_ep0,
778 USBS_CONTROL_RETURN_STALL);
782 status = EP0_LL_IDLE;
784 CLEAR_BITS (pCSR0, AT91_UDP_CSR_ISOERROR | AT91_UDP_CSR_FORCESTALL);
789 // Handle a get status setup message on the control end point
790 static ep0_low_level_status_t
791 usbs_at91_control_setup_get_status(void)
793 ep0_low_level_status_t status;
794 usb_devreq *req = (usb_devreq *)usbs_at91_ep0.control_buffer;
795 cyg_uint8 recipient = req->type & USB_DEVREQ_RECIPIENT_MASK;
796 cyg_uint8 **ppbegin = &usbs_at91_endpoint_pbegin[0];
797 cyg_uint8 **ppend = &usbs_at91_endpoint_pend[0];
800 status = EP0_LL_SEND_READY;
803 case USB_DEVREQ_RECIPIENT_DEVICE:
804 case USB_DEVREQ_RECIPIENT_INTERFACE:
807 case USB_DEVREQ_RECIPIENT_ENDPOINT:
808 if ((usbs_at91_ep0.state == USBS_STATE_CONFIGURED) &&
809 (req->index_lo > 0) &&
810 (req->index_lo < AT91_USB_ENDPOINTS)) {
813 HAL_READ_UINT32(pCSRn(req->index_lo), CSR);
814 if (CSR & AT91_UDP_CSR_EPEDS) {
818 status = EP0_LL_STALL;
822 status = EP0_LL_STALL;
825 *ppbegin = (cyg_uint8 *)&word;
826 *ppend = *ppbegin + sizeof (word);
830 // Setup the begin and end pointers such that an ACK is sent
832 usbs_at91_control_setup_send_ack(void)
834 cyg_uint8 **ppbegin = &usbs_at91_endpoint_pbegin[0];
835 cyg_uint8 **ppend = &usbs_at91_endpoint_pend[0];
837 *ppbegin = usbs_at91_ep0.buffer;
841 // Handle a get status set feature message on the control endpoint
842 static ep0_low_level_status_t
843 usbs_at91_control_setup_set_feature(void)
845 ep0_low_level_status_t status;
846 usb_devreq *req = (usb_devreq *)usbs_at91_ep0.control_buffer;
847 cyg_uint8 recipient = req->type & USB_DEVREQ_RECIPIENT_MASK;
849 usbs_at91_control_setup_send_ack();
850 status = EP0_LL_SEND_READY;
853 case USB_DEVREQ_RECIPIENT_DEVICE:
854 status = EP0_LL_STALL;
856 case USB_DEVREQ_RECIPIENT_INTERFACE:
859 case USB_DEVREQ_RECIPIENT_ENDPOINT:
860 if ((usbs_at91_ep0.state == USBS_STATE_CONFIGURED) &&
861 (req->index_lo > 0) &&
862 (req->index_lo < AT91_USB_ENDPOINTS)) {
865 HAL_READ_UINT32(pCSRn(req->index_lo), CSR);
866 if (CSR & AT91_UDP_CSR_EPEDS) {
870 status = EP0_LL_STALL;
873 status = EP0_LL_STALL;
878 // Handle a get status clear feature message on the control endpoint
879 static ep0_low_level_status_t
880 usbs_at91_control_setup_clear_feature(void)
882 ep0_low_level_status_t status;
883 usb_devreq *req = (usb_devreq *)usbs_at91_ep0.control_buffer;
884 cyg_uint8 recipient = req->type & USB_DEVREQ_RECIPIENT_MASK;
886 usbs_at91_control_setup_send_ack();
887 status = EP0_LL_SEND_READY;
890 case USB_DEVREQ_RECIPIENT_DEVICE:
891 status = EP0_LL_STALL;
893 case USB_DEVREQ_RECIPIENT_INTERFACE:
896 case USB_DEVREQ_RECIPIENT_ENDPOINT:
897 if ((usbs_at91_ep0.state == USBS_STATE_CONFIGURED) &&
898 (req->index_lo > 0) &&
899 (req->index_lo < AT91_USB_ENDPOINTS)) {
902 HAL_READ_UINT32(pCSRn(req->index_lo), CSR);
903 if (CSR & AT91_UDP_CSR_EPEDS) {
907 status = EP0_LL_STALL;
910 status = EP0_LL_STALL;
915 // Handle a setup message from the host
916 static ep0_low_level_status_t
917 usbs_at91_control_setup(ep0_low_level_status_t status)
919 cyg_uint8 **ppbegin = &usbs_at91_endpoint_pbegin[0];
920 cyg_uint8 **ppend = &usbs_at91_endpoint_pend[0];
921 usb_devreq *req = (usb_devreq *) usbs_at91_ep0.control_buffer;
925 usbs_control_return usbcode;
926 bool handled = false;
928 usbs_at91_ep0.buffer_size = 0;
929 usbs_at91_ep0.fill_buffer_fn = 0;
930 usbs_at91_ep0.complete_fn = 0;
932 read_fifo_uint8 ((cyg_uint8 *)req, pFDR0, sizeof (usb_devreq));
934 length = (req->length_hi << 8) | req->length_lo;;
935 dev_to_host = req->type & USB_DEVREQ_DIRECTION_IN;
937 CLEAR_BITS (pCSR0, AT91_UDP_CSR_DTGLE);
939 status = EP0_LL_REQUEST;
941 protocol = req->type & (USB_DEVREQ_TYPE_MASK);
943 // Set the next transfer direction
945 SET_BITS (pCSR0, AT91_UDP_CSR_DIR); /* Set IN direction */
947 CLEAR_BITS (pCSR0, AT91_UDP_CSR_DIR); /* Set OUT direction */
950 if (protocol == USB_DEVREQ_TYPE_STANDARD) {
952 switch (req->request) {
953 case USB_DEVREQ_GET_STATUS:
954 status = usbs_at91_control_setup_get_status();
956 case USB_DEVREQ_SET_ADDRESS:
957 // Most of the hard work is done by the hardware. We just need
959 usbs_at91_control_setup_send_ack();
960 status = EP0_LL_SEND_READY;
962 case USB_DEVREQ_SET_FEATURE:
963 status = usbs_at91_control_setup_set_feature();
965 case USB_DEVREQ_CLEAR_FEATURE:
966 status = usbs_at91_control_setup_clear_feature();
972 if ((protocol != USB_DEVREQ_TYPE_STANDARD) || !handled) {
973 // Ask the layer above to process the message
974 usbcode = usbs_parse_host_get_command (&usbs_at91_ep0);
975 usbs_at91_ep0.buffer_size = MIN (usbs_at91_ep0.buffer_size, length);
977 *ppbegin = usbs_at91_ep0.buffer;
978 *ppend = *ppbegin + usbs_at91_ep0.buffer_size; /* Ready to send... */
980 if (usbcode == USBS_CONTROL_RETURN_HANDLED) { /* OK */
982 status = EP0_LL_SEND_READY;
984 status = EP0_LL_RECEIVE_READY;
987 status = EP0_LL_STALL;
990 // Clear the setup bit so indicating we have processed the message
991 CLEAR_BITS (pCSR0, AT91_UDP_CSR_RXSETUP);
996 static ep0_low_level_status_t
997 usbs_at91_control_data_recv(ep0_low_level_status_t status)
999 cyg_uint32 received = 0;
1001 cyg_uint8 **ppbegin = &usbs_at91_endpoint_pbegin[0];
1002 cyg_uint8 **ppend = &usbs_at91_endpoint_pend[0];
1003 usbs_control_return usbcode;
1005 if (status == EP0_LL_RECEIVE_READY) {
1006 received = ((*(cyg_uint32 *) pCSR0) >> 16) & 0x7ff;
1007 length = MIN (received, (cyg_uint32) *ppend - (cyg_uint32) *ppbegin);
1008 *ppbegin = read_fifo_uint8 (*ppbegin, pFDR0, length);
1010 if (received < usbs_at91_endpoint_fifo_size[0]) { /* Last packet ? */
1014 if (*ppbegin == *ppend) { /* All received ? */
1015 usbs_at91_ep0.buffer_size =
1016 (cyg_uint32) *ppend - (cyg_uint32) usbs_at91_ep0.buffer;
1017 usbcode = USBS_CONTROL_RETURN_STALL;
1019 if (usbs_at91_ep0.complete_fn) {
1020 usbcode = (*usbs_at91_ep0.complete_fn) (&usbs_at91_ep0, 0);
1023 if (usbcode == USBS_CONTROL_RETURN_HANDLED) {
1024 status = EP0_LL_SEND_READY;
1026 status = EP0_LL_STALL;
1031 CLEAR_BITS (pCSR0, AT91_UDP_CSR_RX_DATA_BK0);
1036 static ep0_low_level_status_t
1037 usbs_at91_control_data_sent(ep0_low_level_status_t status)
1039 cyg_uint8 **ppbegin = &usbs_at91_endpoint_pbegin[0];
1040 cyg_uint8 **ppend = &usbs_at91_endpoint_pend[0];
1041 cyg_uint32 bytes_to_write = 0;
1042 usb_devreq *req = (usb_devreq *)usbs_at91_ep0.control_buffer;
1046 case EP0_LL_SEND_READY:
1047 if (*ppbegin == *ppend &&
1048 usbs_at91_ep0.fill_buffer_fn == NULL) {
1049 // All bytes are sent, send ACK
1050 status = EP0_LL_ACK;
1051 SET_BITS (pCSR0, AT91_UDP_CSR_TXPKTRDY); // Signal FIFO loaded
1053 // We have more bytes to send
1055 MIN (*ppend - *ppbegin, usbs_at91_endpoint_fifo_size[0]);
1056 *ppbegin = write_fifo_uint8 (pFDR0, *ppbegin, (cyg_uint8 *)
1057 ((cyg_uint32) *ppbegin + bytes_to_write));
1058 // Send next few bytes
1059 if (*ppbegin == *ppend) { /* Control-Endoints don't need ACK's */
1060 if (usbs_at91_ep0.fill_buffer_fn) { // More Records ?
1061 (*usbs_at91_ep0.fill_buffer_fn) (&usbs_at91_ep0);
1063 *ppbegin = usbs_at91_ep0.buffer;
1064 *ppend = *ppbegin + usbs_at91_ep0.buffer_size;
1066 /* Ready to send... */
1068 MIN (*ppend - *ppbegin,
1069 usbs_at91_endpoint_fifo_size[0] - bytes_to_write);
1071 *ppbegin = write_fifo_uint8 (pFDR0, *ppbegin, (cyg_uint8 *)
1072 ((cyg_uint32) *ppbegin + bytes_to_write));
1073 // Send next few bytes
1075 if (bytes_to_write == usbs_at91_endpoint_fifo_size[0]) {
1076 // Last packet is full, so we need to send a zero bytes
1078 status = EP0_LL_SEND_READY;
1080 status = EP0_LL_IDLE;
1085 SET_BITS (pCSR0, AT91_UDP_CSR_TXPKTRDY); // Signal FIFO loaded
1088 case EP0_LL_RECEIVE_READY:
1089 /* Maybe we have to send an ACK */
1090 if (*ppbegin == *ppend) { // All bytes are received, send ACK
1091 status = EP0_LL_ACK;
1092 SET_BITS (pCSR0, AT91_UDP_CSR_TXPKTRDY); // Signal FIFO loaded
1096 if (req->request == USB_DEVREQ_SET_ADDRESS) { // Special-processing
1097 HAL_WRITE_UINT32 (AT91_UDP + AT91_UDP_FADDR,
1098 req->value_lo | AT91_UDP_FADDR_FEN);
1099 value = (req->value_hi << 8) | req->value_lo;
1101 usbs_at91_ep0.state = USBS_STATE_ADDRESSED;
1105 if (usbs_at91_ep0.complete_fn) {
1106 (*usbs_at91_ep0.complete_fn) (&usbs_at91_ep0,
1107 USBS_CONTROL_RETURN_HANDLED);
1109 status = EP0_LL_IDLE;
1110 usbs_state_notify (&usbs_at91_ep0);
1119 usbs_at91_control_dsr (void)
1121 static ep0_low_level_status_t status = EP0_LL_IDLE;
1123 while (!BITS_ARE_CLEARED(pCSR0,
1124 AT91_UDP_CSR_TXCOMP | AT91_UDP_CSR_RX_DATA_BK0 |
1125 AT91_UDP_CSR_RXSETUP | AT91_UDP_CSR_ISOERROR |
1126 AT91_UDP_CSR_RX_DATA_BK1)) {
1128 // Check and handle any error conditions
1129 if (BITS_ARE_SET (pCSR0, AT91_UDP_CSR_ISOERROR)) {
1130 status = usbs_at91_control_error(status);
1133 // Check for a setup message and handle it
1134 if (BITS_ARE_SET (pCSR0, AT91_UDP_CSR_RXSETUP)) {
1135 status = usbs_at91_control_setup(status);
1138 // Check for received data on the control endpoint
1139 if (BITS_ARE_SET (pCSR0, AT91_UDP_CSR_RX_DATA_BK0)) {
1140 status = usbs_at91_control_data_recv(status);
1143 // Check if the last packet has been sent
1144 if (BITS_ARE_CLEARED (pCSR0, AT91_UDP_CSR_TXPKTRDY)) {
1145 status = usbs_at91_control_data_sent(status);
1148 // Received an ACK packet
1149 if (BITS_ARE_SET (pCSR0, AT91_UDP_CSR_TXCOMP)) {
1150 CLEAR_BITS (pCSR0, AT91_UDP_CSR_TXCOMP);
1153 if (status == EP0_LL_STALL) {
1154 CLEAR_BITS (pCSR0, 0x7f);
1155 SET_BITS (pCSR0, AT91_UDP_CSR_FORCESTALL);
1161 usbs_at91_dsr (cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
1165 CYG_ASSERT (CYGNUM_HAL_INTERRUPT_UDP == vector, "Wrong interrupts");
1166 CYG_ASSERT (0 == data, "DSR needs no data");
1168 CLEAR_BITS (AT91_UDP + AT91_UDP_GLB_STATE, 0x10);
1170 if (BITS_ARE_SET (pISR, AT91_UDP_WAKEUP)) {
1171 usbs_at91_ep0.state = USBS_STATE_DEFAULT;
1172 usbs_state_notify (&usbs_at91_ep0);
1174 HAL_WRITE_UINT32 (pICR, AT91_UDP_WAKEUP);
1177 if (BITS_ARE_SET (pISR, AT91_UDP_ENDBUSRES)) { // RESET UDP
1178 usbs_at91_ep0.state = USBS_STATE_POWERED;
1179 usbs_state_notify (&usbs_at91_ep0);
1180 usbs_at91_handle_reset ();
1182 HAL_WRITE_UINT32 (pCSR0, AT91_UDP_CSR_EPEDS | AT91_UDP_CSR_EPTYPE_CTRL);
1183 HAL_WRITE_UINT32 (pIER, AT91_UDP_EPINT0);
1185 usbs_at91_ep0.state = USBS_STATE_DEFAULT;
1186 usbs_state_notify (&usbs_at91_ep0);
1188 HAL_WRITE_UINT32 (pICR, AT91_UDP_ENDBUSRES);
1191 if (BITS_ARE_SET (pISR, AT91_UDP_SOFINT)) {
1192 HAL_WRITE_UINT32 (pICR, AT91_UDP_SOFINT);
1195 if (BITS_ARE_SET (pISR, AT91_UDP_EXTRSM)) {
1196 usbs_at91_ep0.state = usbs_at91_ep0.state & ~USBS_STATE_SUSPENDED;
1197 usbs_state_notify (&usbs_at91_ep0);
1198 HAL_WRITE_UINT32 (pICR, AT91_UDP_EXTRSM);
1201 if (BITS_ARE_SET (pISR, AT91_UDP_RXRSM)) {
1202 usbs_at91_ep0.state = usbs_at91_ep0.state & ~USBS_STATE_SUSPENDED;
1203 usbs_state_notify (&usbs_at91_ep0);
1204 HAL_WRITE_UINT32 (pICR, AT91_UDP_RXRSM);
1207 if (BITS_ARE_SET (pISR, AT91_UDP_RXSUSP)) {
1208 usbs_at91_ep0.state = usbs_at91_ep0.state | USBS_STATE_SUSPENDED;
1209 usbs_state_notify (&usbs_at91_ep0);
1210 HAL_WRITE_UINT32 (pICR, AT91_UDP_RXSUSP);
1213 if (BITS_ARE_SET (pISR, AT91_UDP_EPINT0)) {
1214 usbs_at91_control_dsr ();
1217 for (n = 1; n < AT91_USB_ENDPOINTS; n++) {
1218 if (*(cyg_uint32 *) pIMR & (1 << n)) {
1219 usbs_at91_endpoint_dsr (n);
1223 cyg_drv_interrupt_unmask (vector);
1227 usbs_at91_isr (cyg_vector_t vector, cyg_addrword_t data)
1230 bool need_dsr = false;
1234 CYG_ASSERT (CYGNUM_HAL_INTERRUPT_UDP == vector, "Wrong interrupts");
1235 CYG_ASSERT (0 == data, "ISR needs no data");
1237 HAL_READ_UINT32(pIMR, IMR);
1238 HAL_READ_UINT32(pISR, ISR);
1240 for (n = 1; n < AT91_USB_ENDPOINTS; n++) {
1241 /* Do any data endpoint need a data transfer ? */
1242 if (IMR & ISR & (1 << n)) {
1243 need_dsr = usbs_at91_endpoint_isr (n) || need_dsr;
1246 /* If we don't need any DSR re-enable interrupts and finish */
1247 if (BITS_ARE_CLEARED (pISR, AT91_UDP_ALLOWED_IRQs & 0xffffff01)
1249 cyg_drv_interrupt_acknowledge (vector);
1250 return CYG_ISR_HANDLED;
1254 cyg_drv_interrupt_mask (vector);
1255 cyg_drv_interrupt_acknowledge (vector);
1257 return CYG_ISR_HANDLED | CYG_ISR_CALL_DSR;
1262 // ----------------------------------------------------------------------------
1263 // Polling support. It is not clear that this is going to work particularly
1264 // well since according to the documentation the hardware does not generate
1265 // NAKs automatically - instead the ISR has to set the appropriate bits
1266 // sufficiently quickly to avoid confusing the host.
1268 // Calling the isr directly avoids duplicating code, but means that
1269 // cyg_drv_interrupt_acknowledge() will get called when not inside a
1270 // real interrupt handler. This should be harmless.
1273 usbs_at91_poll (usbs_control_endpoint * endpoint)
1275 CYG_ASSERT (endpoint == &usbs_at91_ep0, "Wrong endpoint");
1276 if (CYG_ISR_CALL_DSR == usbs_at91_isr (CYGNUM_HAL_INTERRUPT_UDP, 0)) {
1277 usbs_at91_dsr (CYGNUM_HAL_INTERRUPT_UDP, 0, 0);
1281 // ----------------------------------------------------------------------------
1284 // This routine gets called from a prioritized static constructor during
1288 usbs_at91_init (void)
1293 HAL_READ_UINT32 (AT91_PMC + AT91_PMC_PLLR, reg);
1295 /* Set USB divider so we have a 48MHz clock */
1296 #if ((CYGNUM_HAL_ARM_AT91_CLOCK_SPEED < 48120000) && \
1297 (CYGNUM_HAL_ARM_AT91_CLOCK_SPEED > 47880000))
1299 // 48MHz clock, divider set to 1
1300 HAL_WRITE_UINT32 (AT91_PMC + AT91_PMC_PLLR,
1301 (reg & 0x0fffffff) | AT91_PMC_PLLR_USBDIV_1);
1303 #elif ((CYGNUM_HAL_ARM_AT91_CLOCK_SPEED < 96240000) && \
1304 (CYGNUM_HAL_ARM_AT91_CLOCK_SPEED > 95760000))
1306 // 96MHz clock, divider set to 2
1307 HAL_WRITE_UINT32 (AT91_PMC + AT91_PMC_PLLR,
1308 (reg & 0x0fffffff) | AT91_PMC_PLLR_USBDIV_2);
1310 #error CYGNUM_HAL_ARM_AT91_CLOCK_SPEED is not 48, 96 or 192MHz plusminus 0.25% ...
1313 /* Enable USB clock */
1314 HAL_WRITE_UINT32 (AT91_PMC + AT91_PMC_SCER, AT91_PMC_SCER_UDP);
1315 HAL_WRITE_UINT32 (AT91_PMC + AT91_PMC_PCER, AT91_PMC_PCER_UDP);
1317 usbs_at91_set_pullup (false);
1318 #ifndef CYGDAT_DEVS_USB_AT91_GPIO_SET_PULLUP_PIN_NONE
1319 HAL_ARM_AT91_GPIO_CFG_DIRECTION(CYGDAT_DEVS_USB_AT91_GPIO_SET_PULLUP_PIN,
1322 #ifndef CYGDAT_DEVS_USB_AT91_GPIO_READ_POWER_PIN_NONE
1323 HAL_ARM_AT91_GPIO_CFG_DIRECTION(CYGDAT_DEVS_USB_AT91_GPIO_READ_POWER_PIN,
1326 usbs_at91_handle_reset ();
1328 cyg_drv_interrupt_create (CYGNUM_HAL_INTERRUPT_UDP,
1333 &usbs_at91_intr_handle, &usbs_at91_intr_data);
1335 cyg_drv_interrupt_attach (usbs_at91_intr_handle);
1336 cyg_drv_interrupt_unmask (CYGNUM_HAL_INTERRUPT_UDP);
1338 HAL_WRITE_UINT32 (AT91_UDP + AT91_UDP_TXVC, 0);
1340 usbs_at91_ep0.state = USBS_STATE_POWERED;
1341 usbs_state_notify (&usbs_at91_ep0);
1344 // ----------------------------------------------------------------------------
1346 usbs_testing_endpoint usbs_testing_endpoints[] = {
1348 endpoint_type : USB_ENDPOINT_DESCRIPTOR_ATTR_CONTROL,
1349 endpoint_number : 0,
1350 endpoint_direction : USB_ENDPOINT_DESCRIPTOR_ENDPOINT_IN,
1351 endpoint : (void*) &usbs_at91_ep0,
1352 #ifdef CYGVAR_DEVS_USB_AT91_EP0_DEVTAB_ENTRY
1353 devtab_entry : CYGDAT_DEVS_USB_AT91_DEVTAB_BASENAME "0c",
1355 devtab_entry : (const char*) 0,
1357 min_size : 1, // zero-byte control transfers are meaningless
1358 max_size : 0x0FFFF, // limit imposed by protocol
1363 endpoint_type : USB_ENDPOINT_DESCRIPTOR_ATTR_BULK,
1364 endpoint_number : 1,
1365 endpoint_direction : USB_ENDPOINT_DESCRIPTOR_ENDPOINT_OUT,
1366 endpoint : (void*) &usbs_at91_ep1,
1367 #ifdef CYGVAR_DEVS_USB_AT91_EP1_DEVTAB_ENTRY
1368 devtab_entry : CYGDAT_DEVS_USB_AT91_DEVTAB_BASENAME "1r",
1370 devtab_entry : (const char*) 0,
1373 max_size : -1, // No hardware or driver limitation
1378 endpoint_type : USB_ENDPOINT_DESCRIPTOR_ATTR_BULK,
1379 endpoint_number : 2,
1380 endpoint_direction : USB_ENDPOINT_DESCRIPTOR_ENDPOINT_IN,
1381 endpoint : (void*) &usbs_at91_ep2,
1382 #ifdef CYGVAR_DEVS_USB_AT91_EP2_DEVTAB_ENTRY
1383 devtab_entry : CYGDAT_DEVS_USB_AT91_DEVTAB_BASENAME "2w",
1385 devtab_entry : (const char*) 0,
1388 max_size : -1, // No hardware or driver limitation
1389 max_in_padding : 1, // hardware limitation
1393 endpoint_type : USB_ENDPOINT_DESCRIPTOR_ATTR_BULK,
1394 endpoint_number : 3,
1395 endpoint_direction : USB_ENDPOINT_DESCRIPTOR_ENDPOINT_IN,
1396 endpoint : (void*) &usbs_at91_ep3,
1397 #ifdef CYGVAR_DEVS_USB_AT91_EP3_DEVTAB_ENTRY
1398 devtab_entry : CYGDAT_DEVS_USB_AT91_DEVTAB_BASENAME "3w",
1400 devtab_entry : (const char*) 0,
1403 max_size : -1, // No hardware or driver limitation
1404 max_in_padding : 1, // hardware limitation
1407 USBS_TESTING_ENDPOINTS_TERMINATOR