2 #include <usb-interrupt.h>
3 #include <AT91SAM7S64.h>
5 #include <debug-uart.h>
10 #define PRINTF(...) printf(__VA_ARGS__)
15 #define USB_PULLUP_PIN AT91C_PIO_PA16
17 #ifndef AT91C_UDP_STALLSENT
18 #define AT91C_UDP_STALLSENT AT91C_UDP_ISOERROR
24 #define NO_EFFECT_BITS (AT91C_UDP_TXCOMP | AT91C_UDP_RX_DATA_BK0 | AT91C_UDP_RXSETUP \
25 | AT91C_UDP_ISOERROR | AT91C_UDP_RX_DATA_BK1)
27 #define NO_EFFECT_MASK (NO_EFFECT_BITS | AT91C_UDP_TXPKTRDY)
29 #define RXBYTECNT(s) (((s)>>16)&0x7ff)
33 udp_set_ep_ctrl_flags(AT91_REG *reg,
unsigned int flags,
34 unsigned int write_mask,
unsigned int check_mask)
36 while ( (*reg & check_mask) != (flags & check_mask)) {
37 *reg = (*reg & ~write_mask) | flags;
41 #define UDP_SET_EP_CTRL_FLAGS(reg, flags, mask) \
42 udp_set_ep_ctrl_flags((reg), \
43 (NO_EFFECT_BITS & ~(mask)) | ((flags) & (mask)), (mask) | NO_EFFECT_MASK,\
47 #define USB_DISABLE_INT *AT91C_AIC_IDCR = (1 << AT91C_ID_UDP)
48 #define USB_ENABLE_INT *AT91C_AIC_IECR = (1 << AT91C_ID_UDP)
50 #define USB_DISABLE_EP_INT(hw_ep) *AT91C_UDP_IDR = (1 << (hw_ep))
51 #define USB_ENABLE_EP_INT(hw_ep) *AT91C_UDP_IER = (1 << (hw_ep))
54 #error Control endpoint size too big
58 #error Endpoint 1 size too big
62 #error Endpoint 2 size too big
66 #error Endpoint 3 size too big
69 static const uint16_t ep_xfer_size[8] =
77 #define USB_EP_XFER_SIZE(ep) ep_xfer_size[ep]
79 typedef struct _USBEndpoint USBEndpoint;
86 struct process *event_process;
91 #define USB_EP_FLAGS_TYPE_MASK 0x03
92 #define USB_EP_FLAGS_TYPE_BULK 0x00
93 #define USB_EP_FLAGS_TYPE_CONTROL 0x01
94 #define USB_EP_FLAGS_TYPE_ISO 0x02
95 #define USB_EP_FLAGS_TYPE_INTERRUPT 0x03
97 #define EP_TYPE(ep) ((ep)->flags & USB_EP_FLAGS_TYPE_MASK)
98 #define IS_EP_TYPE(ep, type) (EP_TYPE(ep) == (type))
99 #define IS_CONTROL_EP(ep) IS_EP_TYPE(ep, USB_EP_FLAGS_TYPE_CONTROL)
100 #define IS_BULK_EP(ep) IS_EP_TYPE(ep, USB_EP_FLAGS_TYPE_BULK)
102 #define USB_EP_FLAGS_ENABLED 0x04
105 #define USB_EP_FLAGS_RECV_PENDING 0x08
107 #define USB_EP_FLAGS_SETUP_PENDING 0x10
110 #define USB_EP_FLAGS_TRANSMITTING 0x20
113 #define USB_EP_FLAGS_RECEIVING 0x40
117 #define USB_EP_FLAGS_DOUBLE 0x80
120 #define USB_EP_FLAGS_BANK_1_RECV_NEXT 0x10
141 #define EP_INDEX(addr) ((addr) & 0x7f)
144 #define EP_STRUCT(addr) &usb_endpoints[EP_INDEX(addr)];
147 #define EP_HW_NUM(addr) ((addr) & 0x7f)
150 static USBEndpoint usb_endpoints[USB_MAX_ENDPOINTS];
151 struct process *event_process = 0;
152 volatile unsigned int events = 0;
155 notify_process(
unsigned int e)
164 notify_ep_process(USBEndpoint *ep,
unsigned int e)
167 if (ep->event_process) {
177 for (e = 0; e < USB_MAX_ENDPOINTS; e++) {
178 if (usb_endpoints[e].flags &USB_EP_FLAGS_ENABLED) {
179 USBBuffer *buffer = usb_endpoints[e].buffer;
180 usb_endpoints[e].flags = 0;
181 usb_disable_endpoint(e);
183 buffer->flags &= ~USB_BUFFER_SUBMITTED;
184 buffer = buffer->next;
188 usb_arch_setup_control_endpoint(0);
197 *AT91C_CKGR_PLLR = ((*AT91C_CKGR_PLLR & ~AT91C_CKGR_USBDIV)
198 | AT91C_CKGR_USBDIV_1);
200 *AT91C_PMC_SCER = AT91C_PMC_UDP;
202 *AT91C_PMC_PCER = (1 << AT91C_ID_UDP);
205 *AT91C_PIOA_PER = USB_PULLUP_PIN;
206 *AT91C_PIOA_OER = USB_PULLUP_PIN;
207 *AT91C_PIOA_CODR = USB_PULLUP_PIN;
209 for(i = 0; i < USB_MAX_ENDPOINTS; i++) {
210 usb_endpoints[i].flags = 0;
211 usb_endpoints[i].event_process = 0;
216 AT91C_AIC_SMR[AT91C_ID_UDP] = AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | 4;
217 AT91C_AIC_SVR[AT91C_ID_UDP] = (
unsigned long) usb_int;
218 *AT91C_AIC_IECR = (1 << AT91C_ID_UDP);
223 usb_arch_setup_endpoint(
unsigned char addr,
unsigned int hw_type)
225 unsigned int ei = EP_HW_NUM(addr);
226 USBEndpoint *ep = EP_STRUCT(addr);
228 ep->flags = USB_EP_FLAGS_ENABLED;
234 *AT91C_UDP_IDR = 1<<ei;
236 UDP_SET_EP_CTRL_FLAGS(&AT91C_UDP_CSR[ei], hw_type | AT91C_UDP_EPEDS,
237 AT91C_UDP_EPTYPE | AT91C_UDP_EPEDS);
239 *AT91C_UDP_IER = 1<<ei;
243 usb_arch_setup_control_endpoint(
unsigned char addr)
245 unsigned int ei = EP_HW_NUM(addr);
246 USBEndpoint *ep = EP_STRUCT(addr);
247 usb_arch_setup_endpoint(addr, AT91C_UDP_EPTYPE_CTRL);
248 ep->flags |= USB_EP_FLAGS_TYPE_CONTROL;
249 ep->xfer_size = ep_xfer_size[ei];
254 usb_arch_setup_bulk_endpoint(
unsigned char addr)
256 unsigned int ei = EP_HW_NUM(addr);
257 USBEndpoint *ep = EP_STRUCT(addr);
258 usb_arch_setup_endpoint(addr, ((addr & 0x80)
259 ? AT91C_UDP_EPTYPE_BULK_IN
260 : AT91C_UDP_EPTYPE_BULK_OUT));
261 ep->flags |= USB_EP_FLAGS_TYPE_BULK;
262 ep->xfer_size = ep_xfer_size[ei];
266 usb_arch_setup_interrupt_endpoint(
unsigned char addr)
268 unsigned int ei = EP_HW_NUM(addr);
269 USBEndpoint *ep = EP_STRUCT(addr);
270 usb_arch_setup_endpoint(addr, ((addr & 0x80)
271 ? AT91C_UDP_EPTYPE_INT_IN
272 : AT91C_UDP_EPTYPE_INT_OUT));
273 ep->flags |= USB_EP_FLAGS_TYPE_BULK;
274 ep->xfer_size = ep_xfer_size[ei];
278 usb_arch_disable_endpoint(uint8_t addr)
280 USBEndpoint *ep = EP_STRUCT(addr);
281 ep->flags &= ~USB_EP_FLAGS_ENABLED;
283 *AT91C_UDP_IDR = 1<<EP_HW_NUM(addr);
284 UDP_SET_EP_CTRL_FLAGS(&AT91C_UDP_CSR[EP_HW_NUM(addr)], 0, AT91C_UDP_EPEDS);
288 #define USB_READ_BLOCK 0x01
292 #define USB_READ_NOTIFY 0x02
295 #define USB_READ_FAIL 0x04
301 skip_buffers_until(USBBuffer *buffer,
unsigned int mask,
unsigned int flags,
304 while(buffer && !((buffer->flags & mask) == flags)) {
305 USBBuffer *
next = buffer->next;
306 buffer->flags &= ~USB_BUFFER_SUBMITTED ;
307 buffer->flags |= USB_BUFFER_FAILED;
308 if (buffer->flags & USB_BUFFER_NOTIFY) *resp |= USB_READ_NOTIFY;
315 read_hw_buffer(uint8_t *data,
unsigned int hw_ep,
unsigned int len)
318 fdr = &AT91C_UDP_FDR[hw_ep];
325 #define USB_WRITE_BLOCK 0x01
326 #define USB_WRITE_NOTIFY 0x02
329 write_hw_buffer(
const uint8_t *data,
unsigned int hw_ep,
unsigned int len)
332 fdr = &AT91C_UDP_FDR[hw_ep];
340 get_receive_capacity(USBBuffer *buffer)
342 unsigned int capacity = 0;
343 while(buffer && !(buffer->flags & (USB_BUFFER_IN| USB_BUFFER_SETUP|USB_BUFFER_HALT))) {
344 capacity += buffer->left;
345 buffer = buffer->next;
351 handle_pending_receive(USBEndpoint *ep)
356 unsigned int res = 0;
357 unsigned int hw_ep = EP_HW_NUM(ep->addr);
358 USBBuffer *buffer = ep->buffer;
359 uint8_t *setup_data =
NULL;
360 unsigned int flags = ep->flags;
361 if (!(flags & USB_EP_FLAGS_ENABLED) || !buffer)
return USB_READ_BLOCK;
362 len = RXBYTECNT(AT91C_UDP_CSR[hw_ep]);
363 PRINTF(
"handle_pending_receive: %d\n", len);
364 switch(flags & USB_EP_FLAGS_TYPE_MASK) {
365 case USB_EP_FLAGS_TYPE_CONTROL:
366 if (flags & USB_EP_FLAGS_SETUP_PENDING) {
369 skip_buffers_until(buffer, USB_BUFFER_SETUP, USB_BUFFER_SETUP, &res);
371 if (!buffer || buffer->left < len) {
372 res |= USB_READ_BLOCK;
376 if (buffer->left < len) {
377 buffer->flags |= USB_BUFFER_FAILED;
378 buffer->flags &= ~USB_BUFFER_SUBMITTED ;
379 if (buffer->flags & USB_BUFFER_NOTIFY) res |= USB_READ_NOTIFY;
380 ep->buffer = buffer->next;
381 res |= USB_READ_FAIL;
384 setup_data = buffer->data;
386 if (buffer->flags & (USB_BUFFER_SETUP|USB_BUFFER_IN)) {
387 buffer->flags |= USB_BUFFER_FAILED;
389 buffer->flags &= ~USB_BUFFER_SUBMITTED ;
390 if (buffer->flags & USB_BUFFER_NOTIFY) res |= USB_READ_NOTIFY;
391 ep->buffer = buffer->next;
392 res |= USB_READ_FAIL;
398 if (buffer->left > 0) {
399 buffer->flags |= USB_BUFFER_FAILED;
400 res |= USB_READ_FAIL;
402 buffer->flags &= ~USB_BUFFER_SUBMITTED ;
403 if (buffer->flags & USB_BUFFER_NOTIFY) res |= USB_READ_NOTIFY;
404 ep->buffer = buffer->next;
407 if (get_receive_capacity(buffer) < len)
return USB_READ_BLOCK;
410 case USB_EP_FLAGS_TYPE_INTERRUPT:
411 case USB_EP_FLAGS_TYPE_BULK:
412 case USB_EP_FLAGS_TYPE_ISO:
413 if (get_receive_capacity(buffer) < len) {
414 return USB_READ_BLOCK;
419 short_packet = len < ep->xfer_size;
422 if (buffer->left < len) {
428 buffer->left -= copy;
429 read_hw_buffer(buffer->data, hw_ep, copy);
430 buffer->data += copy;
435 buffer->flags &= ~(USB_BUFFER_SUBMITTED | USB_BUFFER_SHORT_PACKET);
436 if (buffer->flags & USB_BUFFER_NOTIFY) res |= USB_READ_NOTIFY;
438 buffer = buffer->next;
442 buffer->flags |= USB_BUFFER_SHORT_PACKET;
445 if ((buffer->left == 0)
446 || (buffer->flags & USB_BUFFER_PACKET_END)
447 || (short_packet && (buffer->flags & USB_BUFFER_SHORT_END))) {
449 buffer->flags &= ~USB_BUFFER_SUBMITTED;
450 if (buffer->flags & USB_BUFFER_NOTIFY) res |= USB_READ_NOTIFY;
452 buffer = buffer->next;
458 UDP_SET_EP_CTRL_FLAGS(&AT91C_UDP_CSR[0],
459 ((setup_data[0] & 0x80)
460 ? AT91C_UDP_DIR : 0), AT91C_UDP_DIR);
467 start_receive(USBEndpoint *ep)
469 ep->flags |= USB_EP_FLAGS_RECEIVING;
474 get_transmit_length(USBBuffer *buffer)
476 unsigned int length = 0;
477 while(buffer && (buffer->flags & USB_BUFFER_IN)) {
478 length += buffer->left;
479 buffer = buffer->next;
486 start_transmit(USBEndpoint *ep)
488 unsigned int res = 0;
489 USBBuffer *buffer = ep->buffer;
491 unsigned int hw_ep = EP_HW_NUM(ep->addr);
492 unsigned int ep_flags = ep->flags;
494 if (!(ep_flags & USB_EP_FLAGS_ENABLED) || !buffer)
return USB_WRITE_BLOCK;
495 switch(ep_flags & USB_EP_FLAGS_TYPE_MASK) {
496 case USB_EP_FLAGS_TYPE_BULK:
497 if (buffer->flags & USB_BUFFER_HALT) {
498 if (ep->status & 0x01)
return USB_WRITE_BLOCK;
500 if (!(ep->flags & USB_EP_FLAGS_TRANSMITTING)) {
501 UDP_SET_EP_CTRL_FLAGS(&AT91C_UDP_CSR[hw_ep],
502 AT91C_UDP_FORCESTALL, AT91C_UDP_FORCESTALL);
505 return USB_WRITE_BLOCK;
507 case USB_EP_FLAGS_TYPE_ISO:
508 if (!(ep->flags & USB_EP_FLAGS_TRANSMITTING)) {
509 if (AT91C_UDP_CSR[hw_ep] & AT91C_UDP_TXPKTRDY)
return USB_WRITE_BLOCK;
513 if (AT91C_UDP_CSR[hw_ep] & AT91C_UDP_TXPKTRDY)
return USB_WRITE_BLOCK;
519 if (buffer->left < len) {
525 buffer->left -= copy;
526 write_hw_buffer(buffer->data, hw_ep, copy);
527 buffer->data += copy;
528 if (buffer->left == 0) {
529 if (buffer->flags & USB_BUFFER_SHORT_END) {
538 buffer->flags &= ~USB_BUFFER_SUBMITTED;
539 if (buffer->flags & USB_BUFFER_NOTIFY) res = USB_WRITE_NOTIFY;
541 buffer = buffer->next;
546 if (ep->flags & USB_EP_FLAGS_TRANSMITTING) {
547 ep->flags |= USB_EP_FLAGS_DOUBLE;
549 ep->flags |= USB_EP_FLAGS_TRANSMITTING;
552 PRINTF(
"start_transmit: sent %08x\n",AT91C_UDP_CSR[hw_ep]);
554 UDP_SET_EP_CTRL_FLAGS(&AT91C_UDP_CSR[hw_ep],
555 AT91C_UDP_TXPKTRDY, AT91C_UDP_TXPKTRDY);
561 start_transfer(USBEndpoint *ep)
563 unsigned int hw_ep = EP_HW_NUM(ep->addr);
566 if (!(ep->addr & 0x80)) {
567 if (ep->buffer && (ep->buffer->flags & USB_BUFFER_HALT)) {
568 if (ep->status & 0x01) return ;
570 UDP_SET_EP_CTRL_FLAGS(&AT91C_UDP_CSR[EP_HW_NUM(ep->addr)],
571 AT91C_UDP_FORCESTALL, AT91C_UDP_FORCESTALL);
572 PRINTF(
"HALT OUT\n");
573 *AT91C_UDP_IDR = 1<<hw_ep;
577 if (!(ep->flags & USB_EP_FLAGS_RECV_PENDING))
break;
578 res = handle_pending_receive(ep);
579 if (res & USB_READ_NOTIFY) {
580 notify_ep_process(ep, USB_EP_EVENT_NOTIFICATION);
582 PRINTF(
"received res = %d\n", res);
583 if (res & USB_READ_BLOCK) {
584 *AT91C_UDP_IDR = 1<<hw_ep;
587 if (AT91C_UDP_CSR[hw_ep] & AT91C_UDP_RXSETUP) {
589 UDP_SET_EP_CTRL_FLAGS(&AT91C_UDP_CSR[hw_ep],0, AT91C_UDP_RXSETUP);
590 }
else if (AT91C_UDP_CSR[hw_ep] & (AT91C_UDP_RX_DATA_BK1)) {
592 UDP_SET_EP_CTRL_FLAGS(&AT91C_UDP_CSR[hw_ep],0,
593 (ep->flags & USB_EP_FLAGS_BANK_1_RECV_NEXT)
594 ? AT91C_UDP_RX_DATA_BK1
595 : AT91C_UDP_RX_DATA_BK0);
596 ep->flags ^= USB_EP_FLAGS_BANK_1_RECV_NEXT;
599 UDP_SET_EP_CTRL_FLAGS(&AT91C_UDP_CSR[hw_ep],0,
600 AT91C_UDP_RX_DATA_BK0);
601 ep->flags |= USB_EP_FLAGS_BANK_1_RECV_NEXT;
604 if (ep->flags & USB_EP_FLAGS_DOUBLE) {
605 ep->flags &= ~USB_EP_FLAGS_DOUBLE;
606 }
else if IS_CONTROL_EP(ep) {
607 ep->flags &= ~(USB_EP_FLAGS_RECV_PENDING|USB_EP_FLAGS_SETUP_PENDING);
609 ep->flags &= ~USB_EP_FLAGS_RECV_PENDING;
611 if (res & USB_READ_FAIL) {
613 usb_arch_control_stall(ep->addr);
616 *AT91C_UDP_IER = 1<<hw_ep;
618 if (ep->flags & (USB_EP_FLAGS_TRANSMITTING | USB_EP_FLAGS_RECEIVING)) {
620 if (!IS_BULK_EP(ep) || (ep->flags & USB_EP_FLAGS_DOUBLE)) {
628 if (ep->status & 0x01)
return;
630 if (ep->buffer->flags & USB_BUFFER_IN) {
631 res = start_transmit(ep);
632 if (res & USB_WRITE_NOTIFY) {
633 notify_ep_process(ep, USB_EP_EVENT_NOTIFICATION);
643 usb_arch_transfer_complete(
unsigned int hw_ep)
645 unsigned int status = AT91C_UDP_CSR[hw_ep];
646 USBEndpoint *ep = &usb_endpoints[hw_ep];
647 PRINTF(
"transfer_complete: %d\n", hw_ep);
648 if (status & AT91C_UDP_STALLSENT) {
650 UDP_SET_EP_CTRL_FLAGS(&AT91C_UDP_CSR[hw_ep],0, AT91C_UDP_STALLSENT);
652 if (status & (AT91C_UDP_RXSETUP
653 | AT91C_UDP_RX_DATA_BK1 | AT91C_UDP_RX_DATA_BK0)) {
654 if (status & AT91C_UDP_RXSETUP) {
656 ep->flags |= USB_EP_FLAGS_SETUP_PENDING;
658 if (ep->flags & USB_EP_FLAGS_DOUBLE) {
659 ep->flags &= ~USB_EP_FLAGS_DOUBLE;
661 ep->flags &= ~USB_EP_FLAGS_RECEIVING;
663 if ( ep->flags & USB_EP_FLAGS_RECV_PENDING) {
664 ep->flags |= USB_EP_FLAGS_DOUBLE;
666 ep->flags |= USB_EP_FLAGS_RECV_PENDING;
670 if (status & AT91C_UDP_TXCOMP) {
671 PRINTF(
"Sent packet\n");
672 if (ep->flags & USB_EP_FLAGS_DOUBLE) {
673 ep->flags &= ~USB_EP_FLAGS_DOUBLE;
675 ep->flags &= ~USB_EP_FLAGS_TRANSMITTING;
677 UDP_SET_EP_CTRL_FLAGS(&AT91C_UDP_CSR[hw_ep],0, AT91C_UDP_TXCOMP);
678 if (ep->status & 0x01) {
679 UDP_SET_EP_CTRL_FLAGS(&AT91C_UDP_CSR[hw_ep],
680 AT91C_UDP_FORCESTALL, AT91C_UDP_FORCESTALL);
691 usb_set_ep_event_process(
unsigned char addr,
struct process *p)
693 USBEndpoint *ep = &usb_endpoints[EP_INDEX(addr)];
694 ep->event_process = p;
699 usb_arch_set_global_event_process(
struct process *p)
705 usb_arch_get_global_events(
void)
716 usb_get_ep_events(
unsigned char addr)
719 unsigned int ei = EP_HW_NUM(addr);
721 e = usb_endpoints[ei].events;
722 usb_endpoints[ei].events = 0;
729 usb_submit_recv_buffer(
unsigned char ep_addr, USBBuffer *buffer)
732 USBEndpoint *ep = &usb_endpoints[EP_INDEX(ep_addr)];
733 if (!(ep->flags & USB_EP_FLAGS_ENABLED))
return;
737 tailp = (USBBuffer**)&ep->buffer;
739 tailp = &(*tailp)->next;
743 buffer->flags |= USB_BUFFER_SUBMITTED;
744 buffer = buffer->next;
752 usb_submit_xmit_buffer(
unsigned char ep_addr, USBBuffer *buffer)
755 USBEndpoint *ep = &usb_endpoints[EP_INDEX(ep_addr)];
756 if (!(ep->flags & USB_EP_FLAGS_ENABLED))
return;
759 tailp = (USBBuffer**)&ep->buffer;
761 tailp = &(*tailp)->next;
765 buffer->flags |= USB_BUFFER_SUBMITTED | USB_BUFFER_IN;
766 buffer = buffer->next;
773 usb_arch_discard_all_buffers(
unsigned char ep_addr)
776 volatile USBEndpoint *ep = &usb_endpoints[EP_INDEX(ep_addr)];
777 USB_DISABLE_EP_INT(EP_HW_NUM(ep_addr));
781 USB_ENABLE_EP_INT(EP_HW_NUM(ep_addr));
783 buffer->flags &= ~USB_BUFFER_SUBMITTED;
784 buffer = buffer->next;
789 usb_arch_get_ep_status(uint8_t addr)
791 if (EP_INDEX(addr) > USB_MAX_ENDPOINTS)
return 0;
792 return usb_endpoints[EP_INDEX(addr)].status;
796 usb_arch_set_configuration(uint8_t usb_configuration_value)
802 usb_arch_control_stall(
unsigned char addr)
804 if (EP_INDEX(addr) > USB_MAX_ENDPOINTS)
return;
805 UDP_SET_EP_CTRL_FLAGS(&AT91C_UDP_CSR[EP_HW_NUM(addr)],
806 AT91C_UDP_FORCESTALL, AT91C_UDP_FORCESTALL);
811 usb_arch_halt_endpoint(
unsigned char ep_addr,
int halt)
813 if (EP_INDEX(ep_addr) > USB_MAX_ENDPOINTS)
return;
814 if (!usb_endpoints[EP_INDEX(ep_addr)].flags & USB_EP_FLAGS_ENABLED)
return;
815 *AT91C_UDP_IDR = 1<<EP_HW_NUM(ep_addr);
817 usb_endpoints[EP_INDEX(ep_addr)].status |= 0x01;
819 if (!(usb_endpoints[EP_INDEX(ep_addr)].flags & USB_EP_FLAGS_TRANSMITTING)){
820 UDP_SET_EP_CTRL_FLAGS(&AT91C_UDP_CSR[EP_HW_NUM(ep_addr)],
821 AT91C_UDP_FORCESTALL, AT91C_UDP_FORCESTALL);
824 USBEndpoint *ep = &usb_endpoints[EP_INDEX(ep_addr)];
826 *AT91C_UDP_IDR = 1<<EP_HW_NUM(ep_addr);
827 UDP_SET_EP_CTRL_FLAGS(&AT91C_UDP_CSR[EP_HW_NUM(ep_addr)],
828 0, AT91C_UDP_FORCESTALL);
829 *AT91C_UDP_RSTEP = 1<<EP_HW_NUM(ep_addr);
830 *AT91C_UDP_RSTEP = 0;
833 if (ep->buffer && (ep->buffer->flags & USB_BUFFER_HALT)) {
834 ep->buffer->flags &= ~USB_BUFFER_SUBMITTED;
835 if (ep->buffer->flags & USB_BUFFER_NOTIFY) {
836 notify_ep_process(ep,USB_EP_EVENT_NOTIFICATION);
838 ep->buffer = ep->buffer->next;
842 start_transfer(&usb_endpoints[EP_INDEX(ep_addr)]);
844 *AT91C_UDP_IER = 1<<EP_HW_NUM(ep_addr);
848 usb_arch_send_pending(uint8_t ep_addr)
850 return usb_endpoints[EP_INDEX(ep_addr)].flags & USB_EP_FLAGS_TRANSMITTING;
854 usb_arch_set_address(
unsigned char addr)
856 *AT91C_UDP_FADDR = AT91C_UDP_FEN | addr;
857 *AT91C_UDP_GLBSTATE |= AT91C_UDP_FADDEN;
864 notify_process(USB_EVENT_RESET);
868 usb_arch_suspend_int()
870 notify_process(USB_EVENT_SUSPEND);
874 usb_arch_resume_int()
876 notify_process(USB_EVENT_RESUME);