EE445M RTOS
Taken at the University of Texas Spring 2015
usb.c
Go to the documentation of this file.
1 //*****************************************************************************
2 //
3 // usb.c - Driver for the USB Interface.
4 //
5 // Copyright (c) 2007-2014 Texas Instruments Incorporated. All rights reserved.
6 // Software License Agreement
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above copyright
16 // notice, this list of conditions and the following disclaimer in the
17 // documentation and/or other materials provided with the
18 // distribution.
19 //
20 // Neither the name of Texas Instruments Incorporated nor the names of
21 // its contributors may be used to endorse or promote products derived
22 // from this software without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
36 // This is part of revision 2.1.0.12573 of the Tiva Peripheral Driver Library.
37 //
38 //*****************************************************************************
39 
40 //*****************************************************************************
41 //
44 //
45 //*****************************************************************************
46 
47 #include <stdbool.h>
48 #include <stdint.h>
49 #include "inc/hw_ints.h"
50 #include "inc/hw_memmap.h"
51 #include "inc/hw_types.h"
52 #include "inc/hw_sysctl.h"
53 #include "inc/hw_usb.h"
54 #include "driverlib/debug.h"
55 #include "driverlib/interrupt.h"
56 #include "driverlib/sysctl.h"
57 #include "driverlib/udma.h"
58 #include "driverlib/usb.h"
59 
60 //*****************************************************************************
61 //
62 // Amount to shift the RX interrupt sources by in the flags used in the
63 // interrupt calls.
64 //
65 //*****************************************************************************
66 #define USB_INTEP_RX_SHIFT 16
67 
68 //*****************************************************************************
69 //
70 // Amount to shift the RX endpoint status sources by in the flags used in the
71 // calls.
72 //
73 //*****************************************************************************
74 #define USB_RX_EPSTATUS_SHIFT 16
75 
76 //*****************************************************************************
77 //
78 // Converts from an endpoint specifier to the offset of the endpoint's
79 // control/status registers.
80 //
81 //*****************************************************************************
82 #define EP_OFFSET(Endpoint) (Endpoint - 0x10)
83 
84 //*****************************************************************************
85 //
86 // Sets one of the indexed registers.
87 //
88 // \param ui32Base specifies the USB module base address.
89 // \param ui32Endpoint is the endpoint index to target for this write.
90 // \param ui32IndexedReg is the indexed register to write to.
91 // \param ui8Value is the value to write to the register.
92 //
93 // This function is used to access the indexed registers for each endpoint.
94 // The only registers that are indexed are the FIFO configuration registers,
95 // which are not used after configuration.
96 //
97 // \return None.
98 //
99 //*****************************************************************************
100 static void
101 _USBIndexWrite(uint32_t ui32Base, uint32_t ui32Endpoint,
102  uint32_t ui32IndexedReg, uint32_t ui32Value, uint32_t ui32Size)
103 {
104  uint32_t ui32Index;
105 
106  //
107  // Check the arguments.
108  //
109  ASSERT(ui32Base == USB0_BASE);
110  ASSERT((ui32Endpoint == 0) || (ui32Endpoint == 1) || (ui32Endpoint == 2) ||
111  (ui32Endpoint == 3));
112  ASSERT((ui32Size == 1) || (ui32Size == 2));
113 
114  //
115  // Save the old index in case it was in use.
116  //
117  ui32Index = HWREGB(ui32Base + USB_O_EPIDX);
118 
119  //
120  // Set the index.
121  //
122  HWREGB(ui32Base + USB_O_EPIDX) = ui32Endpoint;
123 
124  //
125  // Determine the size of the register value.
126  //
127  if(ui32Size == 1)
128  {
129  //
130  // Set the value.
131  //
132  HWREGB(ui32Base + ui32IndexedReg) = ui32Value;
133  }
134  else
135  {
136  //
137  // Set the value.
138  //
139  HWREGH(ui32Base + ui32IndexedReg) = ui32Value;
140  }
141 
142  //
143  // Restore the old index in case it was in use.
144  //
145  HWREGB(ui32Base + USB_O_EPIDX) = ui32Index;
146 }
147 
148 //*****************************************************************************
149 //
150 // Reads one of the indexed registers.
151 //
152 // \param ui32Base specifies the USB module base address.
153 // \param ui32Endpoint is the endpoint index to target for this write.
154 // \param ui32IndexedReg is the indexed register to write to.
155 //
156 // This function is used internally to access the indexed registers for each
157 // endpoint. The only registers that are indexed are the FIFO configuration
158 // registers, which are not used after configuration.
159 //
160 // \return The value in the register requested.
161 //
162 //*****************************************************************************
163 static uint32_t
164 _USBIndexRead(uint32_t ui32Base, uint32_t ui32Endpoint,
165  uint32_t ui32IndexedReg, uint32_t ui32Size)
166 {
167  uint8_t ui8Index;
168  uint8_t ui8Value;
169 
170  //
171  // Check the arguments.
172  //
173  ASSERT(ui32Base == USB0_BASE);
174  ASSERT((ui32Endpoint == 0) || (ui32Endpoint == 1) || (ui32Endpoint == 2) ||
175  (ui32Endpoint == 3));
176  ASSERT((ui32Size == 1) || (ui32Size == 2));
177 
178  //
179  // Save the old index in case it was in use.
180  //
181  ui8Index = HWREGB(ui32Base + USB_O_EPIDX);
182 
183  //
184  // Set the index.
185  //
186  HWREGB(ui32Base + USB_O_EPIDX) = ui32Endpoint;
187 
188  //
189  // Determine the size of the register value.
190  //
191  if(ui32Size == 1)
192  {
193  //
194  // Get the value.
195  //
196  ui8Value = HWREGB(ui32Base + ui32IndexedReg);
197  }
198  else
199  {
200  //
201  // Get the value.
202  //
203  ui8Value = HWREGH(ui32Base + ui32IndexedReg);
204  }
205 
206  //
207  // Restore the old index in case it was in use.
208  //
209  HWREGB(ui32Base + USB_O_EPIDX) = ui8Index;
210 
211  //
212  // Return the register's value.
213  //
214  return(ui8Value);
215 }
216 
217 //*****************************************************************************
218 //
229 //
230 //*****************************************************************************
231 void
232 USBHostSuspend(uint32_t ui32Base)
233 {
234  //
235  // Check the arguments.
236  //
237  ASSERT(ui32Base == USB0_BASE);
238 
239  //
240  // Send the suspend signaling to the USB bus.
241  //
242  HWREGB(ui32Base + USB_O_POWER) |= USB_POWER_SUSPEND;
243 }
244 
245 //*****************************************************************************
246 //
261 //
262 //*****************************************************************************
263 void
264 USBHostReset(uint32_t ui32Base, bool bStart)
265 {
266  //
267  // Check the arguments.
268  //
269  ASSERT(ui32Base == USB0_BASE);
270 
271  //
272  // Send a reset signal to the bus.
273  //
274  if(bStart)
275  {
276  HWREGB(ui32Base + USB_O_POWER) |= USB_POWER_RESET;
277  }
278  else
279  {
280  HWREGB(ui32Base + USB_O_POWER) &= ~USB_POWER_RESET;
281  }
282 }
283 
284 //*****************************************************************************
285 //
315 //
316 //*****************************************************************************
317 void
318 USBHighSpeed(uint32_t ui32Base, bool bEnable)
319 {
320  //
321  // Check the arguments.
322  //
323  ASSERT(ui32Base == USB0_BASE);
324 
325  if(bEnable)
326  {
327  //
328  // Enable high speed mode negotiations in hosts or device mode.
329  //
330  HWREGB(ui32Base + USB_O_POWER) |= USB_POWER_HSENAB;
331  }
332  else
333  {
334  //
335  // Enable high speed mode negotiations in hosts or device mode.
336  //
337  HWREGB(ui32Base + USB_O_POWER) &= ~USB_POWER_HSENAB;
338  }
339 }
340 
341 //*****************************************************************************
342 //
365 //
366 //*****************************************************************************
367 void
368 USBHostResume(uint32_t ui32Base, bool bStart)
369 {
370  //
371  // Check the arguments.
372  //
373  ASSERT(ui32Base == USB0_BASE);
374 
375  //
376  // Send a resume signal to the bus.
377  //
378  if(bStart)
379  {
380  HWREGB(ui32Base + USB_O_POWER) |= USB_POWER_RESUME;
381  }
382  else
383  {
384  HWREGB(ui32Base + USB_O_POWER) &= ~USB_POWER_RESUME;
385  }
386 }
387 
388 //*****************************************************************************
389 //
409 //
410 //*****************************************************************************
411 uint32_t
412 USBHostSpeedGet(uint32_t ui32Base)
413 {
414  //
415  // Check the arguments.
416  //
417  ASSERT(ui32Base == USB0_BASE);
418 
419  //
420  // If the Full Speed device bit is set, then this is a full speed device.
421  //
422  if(HWREGB(ui32Base + USB_O_POWER) & USB_POWER_HSMODE)
423  {
424  return(USB_HIGH_SPEED);
425  }
426 
427  //
428  // If the Full Speed device bit is set, then this is a full speed device.
429  //
430  if(HWREGB(ui32Base + USB_O_DEVCTL) & USB_DEVCTL_FSDEV)
431  {
432  return(USB_FULL_SPEED);
433  }
434 
435  //
436  // If the Low Speed device bit is set, then this is a low speed device.
437  //
438  if(HWREGB(ui32Base + USB_O_DEVCTL) & USB_DEVCTL_LSDEV)
439  {
440  return(USB_LOW_SPEED);
441  }
442 
443  //
444  // The device speed is not known.
445  //
446  return(USB_UNDEF_SPEED);
447 }
448 
449 //*****************************************************************************
450 //
471 //
472 //*****************************************************************************
473 uint32_t
474 USBDevSpeedGet(uint32_t ui32Base)
475 {
476  //
477  // Check the arguments.
478  //
479  ASSERT(ui32Base == USB0_BASE);
480 
481  //
482  // If the Full Speed device bit is set, then this is a full speed device.
483  //
484  if(HWREGB(ui32Base + USB_O_POWER) & USB_POWER_HSMODE)
485  {
486  return(USB_HIGH_SPEED);
487  }
488 
489  return(USB_FULL_SPEED);
490 }
491 
492 //*****************************************************************************
493 //
506 //
507 //*****************************************************************************
508 void
509 USBIntDisableControl(uint32_t ui32Base, uint32_t ui32Flags)
510 {
511  //
512  // Check the arguments.
513  //
514  ASSERT(ui32Base == USB0_BASE);
515  ASSERT((ui32Flags & ~(USB_INTCTRL_ALL)) == 0);
516 
517  //
518  // If any general interrupts were disabled then write the general interrupt
519  // settings out to the hardware.
520  //
521  if(ui32Flags & USB_INTCTRL_STATUS)
522  {
523  HWREGB(ui32Base + USB_O_IE) &= ~(ui32Flags & USB_INTCTRL_STATUS);
524  }
525 
526  //
527  // Disable the power fault interrupt.
528  //
529  if(ui32Flags & USB_INTCTRL_POWER_FAULT)
530  {
531  HWREG(ui32Base + USB_O_EPCIM) = 0;
532  }
533 
534  //
535  // Disable the ID pin detect interrupt.
536  //
537  if(ui32Flags & USB_INTCTRL_MODE_DETECT)
538  {
539  HWREG(USB0_BASE + USB_O_IDVIM) = 0;
540  }
541 }
542 
543 //*****************************************************************************
544 //
557 //
558 //*****************************************************************************
559 void
560 USBIntEnableControl(uint32_t ui32Base, uint32_t ui32Flags)
561 {
562  //
563  // Check the arguments.
564  //
565  ASSERT(ui32Base == USB0_BASE);
566  ASSERT((ui32Flags & (~USB_INTCTRL_ALL)) == 0);
567 
568  //
569  // If any general interrupts were enabled, then write the general
570  // interrupt settings out to the hardware.
571  //
572  if(ui32Flags & USB_INTCTRL_STATUS)
573  {
574  HWREGB(ui32Base + USB_O_IE) |= ui32Flags;
575  }
576 
577  //
578  // Enable the power fault interrupt.
579  //
580  if(ui32Flags & USB_INTCTRL_POWER_FAULT)
581  {
582  HWREG(ui32Base + USB_O_EPCIM) = USB_EPCIM_PF;
583  }
584 
585  //
586  // Enable the ID pin detect interrupt.
587  //
588  if(ui32Flags & USB_INTCTRL_MODE_DETECT)
589  {
591  }
592 }
593 
594 //*****************************************************************************
595 //
632 //
633 //*****************************************************************************
634 uint32_t
635 USBIntStatusControl(uint32_t ui32Base)
636 {
637  uint32_t ui32Status;
638 
639  //
640  // Check the arguments.
641  //
642  ASSERT(ui32Base == USB0_BASE);
643 
644  //
645  // Get the general interrupt status, these bits go into the upper 8 bits
646  // of the returned value.
647  //
648  ui32Status = HWREGB(ui32Base + USB_O_IS);
649 
650  //
651  // Add the power fault status.
652  //
653  if(HWREG(ui32Base + USB_O_EPCISC) & USB_EPCISC_PF)
654  {
655  //
656  // Indicate a power fault was detected.
657  //
658  ui32Status |= USB_INTCTRL_POWER_FAULT;
659 
660  //
661  // Clear the power fault interrupt.
662  //
663  HWREGB(ui32Base + USB_O_EPCISC) |= USB_EPCISC_PF;
664  }
665 
667  {
668  //
669  // Indicate an id detection.
670  //
671  ui32Status |= USB_INTCTRL_MODE_DETECT;
672 
673  //
674  // Clear the id detection interrupt.
675  //
677  }
678 
679  //
680  // Return the combined interrupt status.
681  //
682  return(ui32Status);
683 }
684 
685 //*****************************************************************************
686 //
699 //
700 //*****************************************************************************
701 void
702 USBIntDisableEndpoint(uint32_t ui32Base, uint32_t ui32Flags)
703 {
704  //
705  // Check the arguments.
706  //
707  ASSERT(ui32Base == USB0_BASE);
708 
709  //
710  // If any transmit interrupts were disabled, then write the transmit
711  // interrupt settings out to the hardware.
712  //
713  HWREGH(ui32Base + USB_O_TXIE) &=
714  ~(ui32Flags & (USB_INTEP_HOST_OUT | USB_INTEP_DEV_IN | USB_INTEP_0));
715 
716  //
717  // If any receive interrupts were disabled, then write the receive
718  // interrupt settings out to the hardware.
719  //
720  HWREGH(ui32Base + USB_O_RXIE) &=
721  ~((ui32Flags & (USB_INTEP_HOST_IN | USB_INTEP_DEV_OUT)) >>
723 }
724 
725 //*****************************************************************************
726 //
739 //
740 //*****************************************************************************
741 void
742 USBIntEnableEndpoint(uint32_t ui32Base, uint32_t ui32Flags)
743 {
744  //
745  // Check the arguments.
746  //
747  ASSERT(ui32Base == USB0_BASE);
748 
749  //
750  // Enable any transmit endpoint interrupts.
751  //
752  HWREGH(ui32Base + USB_O_TXIE) |=
754 
755  //
756  // Enable any receive endpoint interrupts.
757  //
758  HWREGH(ui32Base + USB_O_RXIE) |=
759  ((ui32Flags & (USB_INTEP_HOST_IN | USB_INTEP_DEV_OUT)) >>
761 }
762 
763 //*****************************************************************************
764 //
780 //
781 //*****************************************************************************
782 uint32_t
783 USBIntStatusEndpoint(uint32_t ui32Base)
784 {
785  uint32_t ui32Status;
786 
787  //
788  // Check the arguments.
789  //
790  ASSERT(ui32Base == USB0_BASE);
791 
792  //
793  // Get the transmit interrupt status.
794  //
795  ui32Status = HWREGH(ui32Base + USB_O_TXIS);
796  ui32Status |= (HWREGH(ui32Base + USB_O_RXIS) << USB_INTEP_RX_SHIFT);
797 
798  //
799  // Return the combined interrupt status.
800  //
801  return(ui32Status);
802 }
803 
804 //*****************************************************************************
805 //
815 //
816 //*****************************************************************************
817 static uint32_t
818 _USBIntNumberGet(uint32_t ui32Base)
819 {
820  uint32_t ui32Int;
821 
822  if(CLASS_IS_TM4C123)
823  {
824  ui32Int = INT_USB0_TM4C123;
825  }
826  else if(CLASS_IS_TM4C129)
827  {
828  ui32Int = INT_USB0_TM4C129;
829  }
830  else
831  {
832  ui32Int = 0;
833  }
834  return(ui32Int);
835 }
836 
837 //*****************************************************************************
838 //
856 //
857 //*****************************************************************************
858 void
859 USBIntRegister(uint32_t ui32Base, void (*pfnHandler)(void))
860 {
861  uint32_t ui32Int;
862 
863  //
864  // Check the arguments.
865  //
866  ASSERT(ui32Base == USB0_BASE);
867 
868  ui32Int = _USBIntNumberGet(ui32Base);
869 
870  ASSERT(ui32Int != 0);
871 
872  //
873  // Register the interrupt handler.
874  //
875  IntRegister(ui32Int, pfnHandler);
876 
877  //
878  // Enable the USB interrupt.
879  //
880  IntEnable(ui32Int);
881 }
882 
883 //*****************************************************************************
884 //
896 //
897 //*****************************************************************************
898 void
899 USBIntUnregister(uint32_t ui32Base)
900 {
901  uint32_t ui32Int;
902 
903  //
904  // Check the arguments.
905  //
906  ASSERT(ui32Base == USB0_BASE);
907 
908  ui32Int = _USBIntNumberGet(ui32Base);
909 
910  ASSERT(ui32Int != 0);
911 
912  //
913  // Disable the USB interrupt.
914  //
915  IntDisable(ui32Int);
916 
917  //
918  // Unregister the interrupt handler.
919  //
920  IntUnregister(ui32Int);
921 }
922 
923 //*****************************************************************************
924 //
991 //
992 //*****************************************************************************
993 uint32_t
994 USBEndpointStatus(uint32_t ui32Base, uint32_t ui32Endpoint)
995 {
996  uint32_t ui32Status;
997 
998  //
999  // Check the arguments.
1000  //
1001  ASSERT(ui32Base == USB0_BASE);
1002  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
1003  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
1004  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
1005  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
1006 
1007  //
1008  // Get the TX portion of the endpoint status.
1009  //
1010  ui32Status = HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRL1);
1011 
1012  //
1013  // Get the RX portion of the endpoint status.
1014  //
1015  ui32Status |=
1016  ((HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRL1)) <<
1018 
1019  //
1020  // Return the endpoint status.
1021  //
1022  return(ui32Status);
1023 }
1024 
1025 //*****************************************************************************
1026 //
1040 //
1041 //*****************************************************************************
1042 void
1043 USBHostEndpointStatusClear(uint32_t ui32Base, uint32_t ui32Endpoint,
1044  uint32_t ui32Flags)
1045 {
1046  //
1047  // Check the arguments.
1048  //
1049  ASSERT(ui32Base == USB0_BASE);
1050  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
1051  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
1052  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
1053  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
1054 
1055  //
1056  // Clear the specified flags for the endpoint.
1057  //
1058  if(ui32Endpoint == USB_EP_0)
1059  {
1060  HWREGB(ui32Base + USB_O_CSRL0) &= ~ui32Flags;
1061  }
1062  else
1063  {
1064  HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
1065  ~ui32Flags;
1066  HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
1067  ~(ui32Flags >> USB_RX_EPSTATUS_SHIFT);
1068  }
1069 }
1070 
1071 //*****************************************************************************
1072 //
1086 //
1087 //*****************************************************************************
1088 void
1089 USBDevEndpointStatusClear(uint32_t ui32Base, uint32_t ui32Endpoint,
1090  uint32_t ui32Flags)
1091 {
1092  //
1093  // Check the arguments.
1094  //
1095  ASSERT(ui32Base == USB0_BASE);
1096  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
1097  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
1098  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
1099  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
1100 
1101  //
1102  // If this is endpoint 0, then the bits have different meaning and map
1103  // into the TX memory location.
1104  //
1105  if(ui32Endpoint == USB_EP_0)
1106  {
1107  //
1108  // Set the Serviced RxPktRdy bit to clear the RxPktRdy.
1109  //
1110  if(ui32Flags & USB_DEV_EP0_OUT_PKTRDY)
1111  {
1112  HWREGB(ui32Base + USB_O_CSRL0) |= USB_CSRL0_RXRDYC;
1113  }
1114 
1115  //
1116  // Set the serviced Setup End bit to clear the SetupEnd status.
1117  //
1118  if(ui32Flags & USB_DEV_EP0_SETUP_END)
1119  {
1120  HWREGB(ui32Base + USB_O_CSRL0) |= USB_CSRL0_SETENDC;
1121  }
1122 
1123  //
1124  // Clear the Sent Stall status flag.
1125  //
1126  if(ui32Flags & USB_DEV_EP0_SENT_STALL)
1127  {
1128  HWREGB(ui32Base + USB_O_CSRL0) &= ~(USB_DEV_EP0_SENT_STALL);
1129  }
1130  }
1131  else
1132  {
1133  //
1134  // Clear out any TX flags that were passed in. Only
1135  // USB_DEV_TX_SENT_STALL and USB_DEV_TX_UNDERRUN must be cleared.
1136  //
1137  HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
1138  ~(ui32Flags & (USB_DEV_TX_SENT_STALL | USB_DEV_TX_UNDERRUN));
1139 
1140  //
1141  // Clear out valid RX flags that were passed in. Only
1142  // USB_DEV_RX_SENT_STALL, USB_DEV_RX_DATA_ERROR, and USB_DEV_RX_OVERRUN
1143  // must be cleared.
1144  //
1145  HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
1146  ~((ui32Flags & (USB_DEV_RX_SENT_STALL | USB_DEV_RX_DATA_ERROR |
1148  }
1149 }
1150 
1151 //*****************************************************************************
1152 //
1170 //
1171 //*****************************************************************************
1172 void
1173 USBHostEndpointDataToggle(uint32_t ui32Base, uint32_t ui32Endpoint,
1174  bool bDataToggle, uint32_t ui32Flags)
1175 {
1176  uint32_t ui32DataToggle;
1177 
1178  //
1179  // Check the arguments.
1180  //
1181  ASSERT(ui32Base == USB0_BASE);
1182  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
1183  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
1184  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
1185  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
1186 
1187  //
1188  // The data toggle defaults to DATA0.
1189  //
1190  ui32DataToggle = 0;
1191 
1192  //
1193  // See if the data toggle must be set to DATA1.
1194  //
1195  if(bDataToggle)
1196  {
1197  //
1198  // Select the data toggle bit based on the endpoint.
1199  //
1200  if(ui32Endpoint == USB_EP_0)
1201  {
1202  ui32DataToggle = USB_CSRH0_DT;
1203  }
1204  else if(ui32Flags == USB_EP_HOST_IN)
1205  {
1206  ui32DataToggle = USB_RXCSRH1_DT;
1207  }
1208  else
1209  {
1210  ui32DataToggle = USB_TXCSRH1_DT;
1211  }
1212  }
1213 
1214  //
1215  // Set the data toggle based on the endpoint.
1216  //
1217  if(ui32Endpoint == USB_EP_0)
1218  {
1219  //
1220  // Set the write enable and the bit value for endpoint zero.
1221  //
1222  HWREGB(ui32Base + USB_O_CSRH0) =
1223  ((HWREGB(ui32Base + USB_O_CSRH0) &
1225  (ui32DataToggle | USB_CSRH0_DTWE));
1226  }
1227  else if(ui32Flags == USB_EP_HOST_IN)
1228  {
1229  //
1230  // Set the Write enable and the bit value for an IN endpoint.
1231  //
1232  HWREGB(ui32Base + USB_O_RXCSRH1 + EP_OFFSET(ui32Endpoint)) =
1233  ((HWREGB(ui32Base + USB_O_RXCSRH1 + EP_OFFSET(ui32Endpoint)) &
1235  (ui32DataToggle | USB_RXCSRH1_DTWE));
1236  }
1237  else
1238  {
1239  //
1240  // Set the Write enable and the bit value for an OUT endpoint.
1241  //
1242  HWREGB(ui32Base + USB_O_TXCSRH1 + EP_OFFSET(ui32Endpoint)) =
1243  ((HWREGB(ui32Base + USB_O_TXCSRH1 + EP_OFFSET(ui32Endpoint)) &
1245  (ui32DataToggle | USB_TXCSRH1_DTWE));
1246  }
1247 }
1248 
1249 //*****************************************************************************
1250 //
1265 //
1266 //*****************************************************************************
1267 void
1268 USBEndpointDataToggleClear(uint32_t ui32Base, uint32_t ui32Endpoint,
1269  uint32_t ui32Flags)
1270 {
1271  //
1272  // Check the arguments.
1273  //
1274  ASSERT(ui32Base == USB0_BASE);
1275  ASSERT((ui32Endpoint == USB_EP_1) || (ui32Endpoint == USB_EP_2) ||
1276  (ui32Endpoint == USB_EP_3) || (ui32Endpoint == USB_EP_4) ||
1277  (ui32Endpoint == USB_EP_5) || (ui32Endpoint == USB_EP_6) ||
1278  (ui32Endpoint == USB_EP_7));
1279 
1280  //
1281  // See if the transmit or receive data toggle must be cleared.
1282  //
1283  if(ui32Flags & (USB_EP_HOST_OUT | USB_EP_DEV_IN))
1284  {
1285  HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
1287  }
1288  else
1289  {
1290  HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
1292  }
1293 }
1294 
1295 //*****************************************************************************
1296 //
1325 //
1326 //*****************************************************************************
1327 void
1328 USBHostEndpointPing(uint32_t ui32Base, uint32_t ui32Endpoint, bool bEnable)
1329 {
1330  //
1331  // Check the arguments.
1332  //
1333  ASSERT(ui32Base == USB0_BASE);
1334  ASSERT((ui32Endpoint == USB_EP_0));
1335 
1336  //
1337  // Handle the endpoint 0 case separately.
1338  //
1339  if(bEnable)
1340  {
1342  }
1343  else
1344  {
1346  }
1347 }
1348 
1349 //*****************************************************************************
1350 //
1366 //
1367 //*****************************************************************************
1368 void
1369 USBDevEndpointStall(uint32_t ui32Base, uint32_t ui32Endpoint,
1370  uint32_t ui32Flags)
1371 {
1372  //
1373  // Check the arguments.
1374  //
1375  ASSERT(ui32Base == USB0_BASE);
1376  ASSERT((ui32Flags & ~(USB_EP_DEV_IN | USB_EP_DEV_OUT)) == 0);
1377  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
1378  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
1379  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
1380  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
1381 
1382  //
1383  // Determine how to stall this endpoint.
1384  //
1385  if(ui32Endpoint == USB_EP_0)
1386  {
1387  //
1388  // Perform a stall on endpoint zero.
1389  //
1391  }
1392  else if(ui32Flags == USB_EP_DEV_IN)
1393  {
1394  //
1395  // Perform a stall on an IN endpoint.
1396  //
1397  HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
1399  }
1400  else
1401  {
1402  //
1403  // Perform a stall on an OUT endpoint.
1404  //
1405  HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
1407  }
1408 }
1409 
1410 //*****************************************************************************
1411 //
1428 //
1429 //*****************************************************************************
1430 void
1431 USBDevEndpointStallClear(uint32_t ui32Base, uint32_t ui32Endpoint,
1432  uint32_t ui32Flags)
1433 {
1434  //
1435  // Check the arguments.
1436  //
1437  ASSERT(ui32Base == USB0_BASE);
1438  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
1439  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
1440  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
1441  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
1442  ASSERT((ui32Flags & ~(USB_EP_DEV_IN | USB_EP_DEV_OUT)) == 0);
1443 
1444  //
1445  // Determine how to clear the stall on this endpoint.
1446  //
1447  if(ui32Endpoint == USB_EP_0)
1448  {
1449  //
1450  // Clear the stall on endpoint zero.
1451  //
1452  HWREGB(ui32Base + USB_O_CSRL0) &= ~USB_CSRL0_STALLED;
1453  }
1454  else if(ui32Flags == USB_EP_DEV_IN)
1455  {
1456  //
1457  // Clear the stall on an IN endpoint.
1458  //
1459  HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
1461 
1462  //
1463  // Reset the data toggle.
1464  //
1465  HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
1467  }
1468  else
1469  {
1470  //
1471  // Clear the stall on an OUT endpoint.
1472  //
1473  HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
1475 
1476  //
1477  // Reset the data toggle.
1478  //
1479  HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
1481  }
1482 }
1483 
1484 //*****************************************************************************
1485 //
1496 //
1497 //*****************************************************************************
1498 void
1499 USBDevConnect(uint32_t ui32Base)
1500 {
1501  //
1502  // Check the arguments.
1503  //
1504  ASSERT(ui32Base == USB0_BASE);
1505 
1506  //
1507  // Enable connection to the USB bus.
1508  //
1509  HWREGB(ui32Base + USB_O_POWER) |= USB_POWER_SOFTCONN;
1510 }
1511 
1512 //*****************************************************************************
1513 //
1525 //
1526 //*****************************************************************************
1527 void
1528 USBDevDisconnect(uint32_t ui32Base)
1529 {
1530  //
1531  // Check the arguments.
1532  //
1533  ASSERT(ui32Base == USB0_BASE);
1534 
1535  //
1536  // Disable connection to the USB bus.
1537  //
1538  HWREGB(ui32Base + USB_O_POWER) &= (~USB_POWER_SOFTCONN);
1539 }
1540 
1541 //*****************************************************************************
1542 //
1554 //
1555 //*****************************************************************************
1556 void
1557 USBDevAddrSet(uint32_t ui32Base, uint32_t ui32Address)
1558 {
1559  //
1560  // Check the arguments.
1561  //
1562  ASSERT(ui32Base == USB0_BASE);
1563 
1564  //
1565  // Set the function address in the correct location.
1566  //
1567  HWREGB(ui32Base + USB_O_FADDR) = (uint8_t)ui32Address;
1568 }
1569 
1570 //*****************************************************************************
1571 //
1582 //
1583 //*****************************************************************************
1584 uint32_t
1585 USBDevAddrGet(uint32_t ui32Base)
1586 {
1587  //
1588  // Check the arguments.
1589  //
1590  ASSERT(ui32Base == USB0_BASE);
1591 
1592  //
1593  // Return the function address.
1594  //
1595  return(HWREGB(ui32Base + USB_O_FADDR));
1596 }
1597 
1598 //*****************************************************************************
1599 //
1677 //
1678 //*****************************************************************************
1679 void
1680 USBHostEndpointConfig(uint32_t ui32Base, uint32_t ui32Endpoint,
1681  uint32_t ui32MaxPayload, uint32_t ui32NAKPollInterval,
1682  uint32_t ui32TargetEndpoint, uint32_t ui32Flags)
1683 {
1684  uint32_t ui32Register;
1685 
1686  //
1687  // Check the arguments.
1688  //
1689  ASSERT(ui32Base == USB0_BASE);
1690  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
1691  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
1692  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
1693  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
1694  ASSERT(ui32NAKPollInterval <= MAX_NAK_LIMIT);
1695 
1696  //
1697  // Endpoint zero is configured differently than the other endpoints, so see
1698  // if this is endpoint zero.
1699  //
1700  if(ui32Endpoint == USB_EP_0)
1701  {
1702  //
1703  // Set the NAK timeout.
1704  //
1705  HWREGB(ui32Base + USB_O_NAKLMT) = ui32NAKPollInterval;
1706 
1707  //
1708  // Set the transfer type information.
1709  //
1710  //
1711  // Set the speed of this endpoint.
1712  //
1713  if(ui32Flags & USB_EP_SPEED_HIGH)
1714  {
1715  HWREGB(ui32Base + USB_O_TYPE0) = USB_TYPE0_SPEED_HIGH;
1716  }
1717  else if(ui32Flags & USB_EP_SPEED_FULL)
1718  {
1719  HWREGB(ui32Base + USB_O_TYPE0) = USB_TYPE0_SPEED_FULL;
1720  }
1721  else
1722  {
1723  HWREGB(ui32Base + USB_O_TYPE0) = USB_TYPE0_SPEED_LOW;
1724  }
1725  }
1726  else
1727  {
1728  //
1729  // Start with the target endpoint.
1730  //
1731  ui32Register = ui32TargetEndpoint;
1732 
1733  //
1734  // Set the speed for the device using this endpoint.
1735  //
1736  if(ui32Flags & USB_EP_SPEED_HIGH)
1737  {
1738  ui32Register |= USB_TXTYPE1_SPEED_HIGH;
1739  }
1740  else if(ui32Flags & USB_EP_SPEED_FULL)
1741  {
1742  ui32Register |= USB_TXTYPE1_SPEED_FULL;
1743  }
1744  else
1745  {
1746  ui32Register |= USB_TXTYPE1_SPEED_LOW;
1747  }
1748 
1749  //
1750  // Set the protocol for the device using this endpoint.
1751  //
1752  switch(ui32Flags & USB_EP_MODE_MASK)
1753  {
1754  //
1755  // The bulk protocol is being used.
1756  //
1757  case USB_EP_MODE_BULK:
1758  {
1759  ui32Register |= USB_TXTYPE1_PROTO_BULK;
1760  break;
1761  }
1762 
1763  //
1764  // The isochronous protocol is being used.
1765  //
1766  case USB_EP_MODE_ISOC:
1767  {
1768  ui32Register |= USB_TXTYPE1_PROTO_ISOC;
1769  break;
1770  }
1771 
1772  //
1773  // The interrupt protocol is being used.
1774  //
1775  case USB_EP_MODE_INT:
1776  {
1777  ui32Register |= USB_TXTYPE1_PROTO_INT;
1778  break;
1779  }
1780 
1781  //
1782  // The control protocol is being used.
1783  //
1784  case USB_EP_MODE_CTRL:
1785  {
1786  ui32Register |= USB_TXTYPE1_PROTO_CTRL;
1787  break;
1788  }
1789  }
1790 
1791  //
1792  // See if the transmit or receive endpoint is being configured.
1793  //
1794  if(ui32Flags & USB_EP_HOST_OUT)
1795  {
1796  //
1797  // Set the transfer type information.
1798  //
1799  HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXTYPE1) =
1800  ui32Register;
1801 
1802  //
1803  // Set the NAK timeout or polling interval.
1804  //
1805  HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXINTERVAL1) =
1806  ui32NAKPollInterval;
1807 
1808  //
1809  // Set the Maximum Payload per transaction.
1810  //
1811  HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXMAXP1) =
1812  ui32MaxPayload;
1813 
1814  //
1815  // Set the transmit control value to zero.
1816  //
1817  ui32Register = 0;
1818 
1819  //
1820  // Allow auto setting of TxPktRdy when max packet size has been
1821  // loaded into the FIFO.
1822  //
1823  if(ui32Flags & USB_EP_AUTO_SET)
1824  {
1825  ui32Register |= USB_TXCSRH1_AUTOSET;
1826  }
1827 
1828  //
1829  // Configure the DMA Mode.
1830  //
1831  if(ui32Flags & USB_EP_DMA_MODE_1)
1832  {
1833  ui32Register |= USB_TXCSRH1_DMAEN | USB_TXCSRH1_DMAMOD;
1834  }
1835  else if(ui32Flags & USB_EP_DMA_MODE_0)
1836  {
1837  ui32Register |= USB_TXCSRH1_DMAEN;
1838  }
1839 
1840  //
1841  // Write out the transmit control value.
1842  //
1843  HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRH1) =
1844  (uint8_t)ui32Register;
1845  }
1846  else
1847  {
1848  //
1849  // Set the transfer type information.
1850  //
1851  HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXTYPE1) =
1852  ui32Register;
1853 
1854  //
1855  // Set the NAK timeout or polling interval.
1856  //
1857  HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXINTERVAL1) =
1858  ui32NAKPollInterval;
1859 
1860  //
1861  // Set the Maximum Payload per transaction.
1862  //
1863  HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXMAXP1) =
1864  ui32MaxPayload;
1865 
1866  //
1867  // Set the receive control value to zero.
1868  //
1869  ui32Register = 0;
1870 
1871  //
1872  // Allow auto clearing of RxPktRdy when packet of size max packet
1873  // has been unloaded from the FIFO.
1874  //
1875  if(ui32Flags & USB_EP_AUTO_CLEAR)
1876  {
1877  ui32Register |= USB_RXCSRH1_AUTOCL;
1878  }
1879 
1880  //
1881  // Allow auto generation of DMA requests.
1882  //
1883  if(ui32Flags & USB_EP_AUTO_REQUEST)
1884  {
1885  ui32Register |= USB_RXCSRH1_AUTORQ;
1886  }
1887 
1888  //
1889  // Configure the DMA Mode.
1890  //
1891  if(ui32Flags & USB_EP_DMA_MODE_1)
1892  {
1893  ui32Register |= USB_RXCSRH1_DMAEN | USB_RXCSRH1_DMAMOD;
1894  }
1895  else if(ui32Flags & USB_EP_DMA_MODE_0)
1896  {
1897  ui32Register |= USB_RXCSRH1_DMAEN;
1898  }
1899 
1900  //
1901  // Write out the receive control value.
1902  //
1903  HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRH1) =
1904  (uint8_t)ui32Register;
1905  }
1906  }
1907 }
1908 
1909 //*****************************************************************************
1910 //
1937 //
1938 //*****************************************************************************
1939 void
1940 USBHostEndpointSpeed(uint32_t ui32Base, uint32_t ui32Endpoint,
1941  uint32_t ui32Flags)
1942 {
1943  uint32_t ui32Reg;
1944  uint32_t ui32Speed;
1945 
1946  //
1947  // Check the arguments.
1948  //
1949  ASSERT(ui32Base == USB0_BASE);
1950  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
1951  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
1952  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
1953  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
1954 
1955  //
1956  // Create the register speed value.
1957  //
1958  if(ui32Flags & USB_EP_SPEED_HIGH)
1959  {
1960  ui32Speed = USB_TYPE0_SPEED_HIGH;
1961  }
1962  else if(ui32Flags & USB_EP_SPEED_FULL)
1963  {
1964  ui32Speed = USB_TYPE0_SPEED_FULL;
1965  }
1966  else
1967  {
1968  ui32Speed = USB_TYPE0_SPEED_LOW;
1969  }
1970 
1971  //
1972  // Endpoint 0 is handled differently as it is bi-directional.
1973  //
1974  if(ui32Endpoint == USB_EP_0)
1975  {
1976  HWREGB(ui32Base + USB_O_TYPE0) = ui32Speed;
1977  }
1978  else if(ui32Flags & USB_EP_HOST_OUT)
1979  {
1980  //
1981  // Clear the current speed and set the new speed.
1982  //
1983  ui32Reg = (HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXTYPE1) &
1984  ~(USB_TXTYPE1_SPEED_M));
1985  ui32Reg |= ui32Speed;
1986 
1987  HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXTYPE1) |= ui32Reg;
1988  }
1989  else
1990  {
1991  //
1992  // Clear the current speed and set the new speed.
1993  //
1994  ui32Reg = (HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXTYPE1) &
1995  ~(USB_RXTYPE1_SPEED_M));
1996  ui32Reg |= ui32Speed;
1997 
1998  HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXTYPE1) |= ui32Reg;
1999  }
2000 }
2001 
2002 //*****************************************************************************
2003 //
2050 //
2051 //*****************************************************************************
2052 void
2053 USBDevEndpointConfigSet(uint32_t ui32Base, uint32_t ui32Endpoint,
2054  uint32_t ui32MaxPacketSize, uint32_t ui32Flags)
2055 {
2056  uint32_t ui32Register;
2057 
2058  //
2059  // Check the arguments.
2060  //
2061  ASSERT(ui32Base == USB0_BASE);
2062  ASSERT((ui32Endpoint == USB_EP_1) || (ui32Endpoint == USB_EP_2) ||
2063  (ui32Endpoint == USB_EP_3) || (ui32Endpoint == USB_EP_4) ||
2064  (ui32Endpoint == USB_EP_5) || (ui32Endpoint == USB_EP_6) ||
2065  (ui32Endpoint == USB_EP_7));
2066 
2067  //
2068  // Determine if a transmit or receive endpoint is being configured.
2069  //
2070  if(ui32Flags & USB_EP_DEV_IN)
2071  {
2072  //
2073  // Set the maximum packet size.
2074  //
2075  HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXMAXP1) =
2076  ui32MaxPacketSize;
2077 
2078  //
2079  // The transmit control value is zero unless options are enabled.
2080  //
2081  ui32Register = 0;
2082 
2083  //
2084  // Allow auto setting of TxPktRdy when max packet size has been loaded
2085  // into the FIFO.
2086  //
2087  if(ui32Flags & USB_EP_AUTO_SET)
2088  {
2089  ui32Register |= USB_TXCSRH1_AUTOSET;
2090  }
2091 
2092  //
2093  // Configure the DMA mode.
2094  //
2095  if(ui32Flags & USB_EP_DMA_MODE_1)
2096  {
2097  ui32Register |= USB_TXCSRH1_DMAEN | USB_TXCSRH1_DMAMOD;
2098  }
2099  else if(ui32Flags & USB_EP_DMA_MODE_0)
2100  {
2101  ui32Register |= USB_TXCSRH1_DMAEN;
2102  }
2103 
2104  //
2105  // Enable isochronous mode if requested.
2106  //
2107  if((ui32Flags & USB_EP_MODE_MASK) == USB_EP_MODE_ISOC)
2108  {
2109  ui32Register |= USB_TXCSRH1_ISO;
2110  }
2111 
2112  //
2113  // Write the transmit control value.
2114  //
2115  HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRH1) =
2116  (uint8_t)ui32Register;
2117 
2118  //
2119  // Reset the Data toggle to zero.
2120  //
2121  HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRL1) =
2123  }
2124  else
2125  {
2126  //
2127  // Set the MaxPacketSize.
2128  //
2129  HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXMAXP1) =
2130  ui32MaxPacketSize;
2131 
2132  //
2133  // The receive control value is zero unless options are enabled.
2134  //
2135  ui32Register = 0;
2136 
2137  //
2138  // Allow auto clearing of RxPktRdy when packet of size max packet
2139  // has been unloaded from the FIFO.
2140  //
2141  if(ui32Flags & USB_EP_AUTO_CLEAR)
2142  {
2143  ui32Register = USB_RXCSRH1_AUTOCL;
2144  }
2145 
2146  //
2147  // Configure the DMA mode.
2148  //
2149  if(ui32Flags & USB_EP_DMA_MODE_1)
2150  {
2151  ui32Register |= USB_RXCSRH1_DMAEN | USB_RXCSRH1_DMAMOD;
2152  }
2153  else if(ui32Flags & USB_EP_DMA_MODE_0)
2154  {
2155  ui32Register |= USB_RXCSRH1_DMAEN;
2156  }
2157 
2158  //
2159  // If requested, disable NYET responses for high-speed bulk and
2160  // interrupt endpoints.
2161  //
2162  if(ui32Flags & USB_EP_DIS_NYET)
2163  {
2164  ui32Register |= USB_RXCSRH1_DISNYET;
2165  }
2166 
2167  //
2168  // Enable isochronous mode if requested.
2169  //
2170  if((ui32Flags & USB_EP_MODE_MASK) == USB_EP_MODE_ISOC)
2171  {
2172  ui32Register |= USB_RXCSRH1_ISO;
2173  }
2174 
2175  //
2176  // Write the receive control value.
2177  //
2178  HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRH1) =
2179  (uint8_t)ui32Register;
2180 
2181  //
2182  // Reset the Data toggle to zero.
2183  //
2184  HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRL1) =
2186  }
2187 }
2188 
2189 //*****************************************************************************
2190 //
2210 //
2211 //*****************************************************************************
2212 void
2213 USBDevEndpointConfigGet(uint32_t ui32Base, uint32_t ui32Endpoint,
2214  uint32_t *pui32MaxPacketSize, uint32_t *pui32Flags)
2215 {
2216  uint32_t ui32Register;
2217 
2218  //
2219  // Check the arguments.
2220  //
2221  ASSERT(ui32Base == USB0_BASE);
2222  ASSERT(pui32MaxPacketSize && pui32Flags);
2223  ASSERT((ui32Endpoint == USB_EP_1) || (ui32Endpoint == USB_EP_2) ||
2224  (ui32Endpoint == USB_EP_3) || (ui32Endpoint == USB_EP_4) ||
2225  (ui32Endpoint == USB_EP_5) || (ui32Endpoint == USB_EP_6) ||
2226  (ui32Endpoint == USB_EP_7));
2227 
2228  //
2229  // Determine if a transmit or receive endpoint is being queried.
2230  //
2231  if(*pui32Flags & USB_EP_DEV_IN)
2232  {
2233  //
2234  // Clear the flags other than the direction bit.
2235  //
2236  *pui32Flags = USB_EP_DEV_IN;
2237 
2238  //
2239  // Get the maximum packet size.
2240  //
2241  *pui32MaxPacketSize = (uint32_t)HWREGH(ui32Base +
2242  EP_OFFSET(ui32Endpoint) +
2243  USB_O_TXMAXP1);
2244 
2245  //
2246  // Get the current transmit control register value.
2247  //
2248  ui32Register = (uint32_t)HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) +
2249  USB_O_TXCSRH1);
2250 
2251  //
2252  // Are we allowing auto setting of TxPktRdy when max packet size has
2253  // been loaded into the FIFO?
2254  //
2255  if(ui32Register & USB_TXCSRH1_AUTOSET)
2256  {
2257  *pui32Flags |= USB_EP_AUTO_SET;
2258  }
2259 
2260  //
2261  // Get the DMA mode.
2262  //
2263  if(ui32Register & USB_TXCSRH1_DMAEN)
2264  {
2265  if(ui32Register & USB_TXCSRH1_DMAMOD)
2266  {
2267  *pui32Flags |= USB_EP_DMA_MODE_1;
2268  }
2269  else
2270  {
2271  *pui32Flags |= USB_EP_DMA_MODE_0;
2272  }
2273  }
2274 
2275  //
2276  // Are we in isochronous mode?
2277  //
2278  if(ui32Register & USB_TXCSRH1_ISO)
2279  {
2280  *pui32Flags |= USB_EP_MODE_ISOC;
2281  }
2282  else
2283  {
2284  //
2285  // The hardware doesn't differentiate between bulk, interrupt
2286  // and control mode for the endpoint so we just set something
2287  // that isn't isochronous. This protocol ensures that anyone
2288  // modifying the returned flags in preparation for a call to
2289  // USBDevEndpointConfigSet do not see an unexpected mode change.
2290  // If they decode the returned mode, however, they may be in for
2291  // a surprise.
2292  //
2293  *pui32Flags |= USB_EP_MODE_BULK;
2294  }
2295  }
2296  else
2297  {
2298  //
2299  // Clear the flags other than the direction bit.
2300  //
2301  *pui32Flags = USB_EP_DEV_OUT;
2302 
2303  //
2304  // Get the MaxPacketSize.
2305  //
2306  *pui32MaxPacketSize = (uint32_t)HWREGH(ui32Base +
2307  EP_OFFSET(ui32Endpoint) +
2308  USB_O_RXMAXP1);
2309 
2310  //
2311  // Get the current receive control register value.
2312  //
2313  ui32Register = (uint32_t)HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) +
2314  USB_O_RXCSRH1);
2315 
2316  //
2317  // Are we allowing auto clearing of RxPktRdy when packet of size max
2318  // packet has been unloaded from the FIFO?
2319  //
2320  if(ui32Register & USB_RXCSRH1_AUTOCL)
2321  {
2322  *pui32Flags |= USB_EP_AUTO_CLEAR;
2323  }
2324 
2325  //
2326  // Get the DMA mode.
2327  //
2328  if(ui32Register & USB_RXCSRH1_DMAEN)
2329  {
2330  if(ui32Register & USB_RXCSRH1_DMAMOD)
2331  {
2332  *pui32Flags |= USB_EP_DMA_MODE_1;
2333  }
2334  else
2335  {
2336  *pui32Flags |= USB_EP_DMA_MODE_0;
2337  }
2338  }
2339 
2340  //
2341  // Are we in isochronous mode?
2342  //
2343  if(ui32Register & USB_RXCSRH1_ISO)
2344  {
2345  *pui32Flags |= USB_EP_MODE_ISOC;
2346  }
2347  else
2348  {
2349  //
2350  // The hardware doesn't differentiate between bulk, interrupt
2351  // and control mode for the endpoint so we just set something
2352  // that isn't isochronous. This protocol ensures that anyone
2353  // modifying the returned flags in preparation for a call to
2354  // USBDevEndpointConfigSet do not see an unexpected mode change.
2355  // If they decode the returned mode, however, they may be in for
2356  // a surprise.
2357  //
2358  *pui32Flags |= USB_EP_MODE_BULK;
2359  }
2360  }
2361 }
2362 
2363 //*****************************************************************************
2364 //
2390 //
2391 //*****************************************************************************
2392 void
2393 USBFIFOConfigSet(uint32_t ui32Base, uint32_t ui32Endpoint,
2394  uint32_t ui32FIFOAddress, uint32_t ui32FIFOSize,
2395  uint32_t ui32Flags)
2396 {
2397  //
2398  // Check the arguments.
2399  //
2400  ASSERT(ui32Base == USB0_BASE);
2401  ASSERT((ui32Endpoint == USB_EP_1) || (ui32Endpoint == USB_EP_2) ||
2402  (ui32Endpoint == USB_EP_3) || (ui32Endpoint == USB_EP_4) ||
2403  (ui32Endpoint == USB_EP_5) || (ui32Endpoint == USB_EP_6) ||
2404  (ui32Endpoint == USB_EP_7));
2405 
2406  //
2407  // See if the transmit or receive FIFO is being configured.
2408  //
2409  if(ui32Flags & (USB_EP_HOST_OUT | USB_EP_DEV_IN))
2410  {
2411  //
2412  // Set the transmit FIFO location and size for this endpoint.
2413  //
2414  _USBIndexWrite(ui32Base, ui32Endpoint >> 4, USB_O_TXFIFOSZ,
2415  ui32FIFOSize, 1);
2416  _USBIndexWrite(ui32Base, ui32Endpoint >> 4, USB_O_TXFIFOADD,
2417  ui32FIFOAddress >> 3, 2);
2418  }
2419  else
2420  {
2421  //
2422  // Set the receive FIFO location and size for this endpoint.
2423  //
2424  _USBIndexWrite(ui32Base, ui32Endpoint >> 4, USB_O_RXFIFOSZ,
2425  ui32FIFOSize, 1);
2426  _USBIndexWrite(ui32Base, ui32Endpoint >> 4, USB_O_RXFIFOADD,
2427  ui32FIFOAddress >> 3, 2);
2428  }
2429 }
2430 
2431 //*****************************************************************************
2432 //
2453 //
2454 //*****************************************************************************
2455 void
2456 USBFIFOConfigGet(uint32_t ui32Base, uint32_t ui32Endpoint,
2457  uint32_t *pui32FIFOAddress, uint32_t *pui32FIFOSize,
2458  uint32_t ui32Flags)
2459 {
2460  //
2461  // Check the arguments.
2462  //
2463  ASSERT(ui32Base == USB0_BASE);
2464  ASSERT((ui32Endpoint == USB_EP_1) || (ui32Endpoint == USB_EP_2) ||
2465  (ui32Endpoint == USB_EP_3) || (ui32Endpoint == USB_EP_4) ||
2466  (ui32Endpoint == USB_EP_5) || (ui32Endpoint == USB_EP_6) ||
2467  (ui32Endpoint == USB_EP_7));
2468 
2469  //
2470  // See if the transmit or receive FIFO is being configured.
2471  //
2472  if(ui32Flags & (USB_EP_HOST_OUT | USB_EP_DEV_IN))
2473  {
2474  //
2475  // Get the transmit FIFO location and size for this endpoint.
2476  //
2477  *pui32FIFOAddress = (_USBIndexRead(ui32Base, ui32Endpoint >> 4,
2478  (uint32_t)USB_O_TXFIFOADD,
2479  2)) << 3;
2480  *pui32FIFOSize = _USBIndexRead(ui32Base, ui32Endpoint >> 4,
2481  (uint32_t)USB_O_TXFIFOSZ, 1);
2482  }
2483  else
2484  {
2485  //
2486  // Get the receive FIFO location and size for this endpoint.
2487  //
2488  *pui32FIFOAddress = (_USBIndexRead(ui32Base, ui32Endpoint >> 4,
2489  (uint32_t)USB_O_RXFIFOADD,
2490  2)) << 3;
2491  *pui32FIFOSize = _USBIndexRead(ui32Base, ui32Endpoint >> 4,
2492  (uint32_t)USB_O_RXFIFOSZ, 1);
2493  }
2494 }
2495 
2496 //*****************************************************************************
2497 //
2571 //
2572 //*****************************************************************************
2573 void
2574 USBEndpointDMAConfigSet(uint32_t ui32Base, uint32_t ui32Endpoint,
2575  uint32_t ui32Config)
2576 {
2577  uint32_t ui32NewConfig;
2578 
2579  if(ui32Config & USB_EP_HOST_OUT)
2580  {
2581  //
2582  // Clear mode and DMA enable.
2583  //
2584  ui32NewConfig =
2585  (HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRH1) &
2587 
2588  if(ui32Config & USB_EP_DMA_MODE_1)
2589  {
2590  ui32NewConfig |= USB_TXCSRH1_DMAMOD;
2591  }
2592 
2593  if(ui32Config & USB_EP_AUTO_SET)
2594  {
2595  ui32NewConfig |= USB_TXCSRH1_AUTOSET;
2596  }
2597 
2598  HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRH1) =
2599  ui32NewConfig;
2600  }
2601  else
2602  {
2603  ui32NewConfig =
2604  (HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRH1) &
2606 
2607  if(ui32Config & USB_EP_DMA_MODE_1)
2608  {
2609  ui32NewConfig |= USB_RXCSRH1_DMAMOD;
2610  }
2611 
2612  if(ui32Config & USB_EP_AUTO_CLEAR)
2613  {
2614  ui32NewConfig |= USB_RXCSRH1_AUTOCL;
2615  }
2616  if(ui32Config & USB_EP_AUTO_REQUEST)
2617  {
2618  ui32NewConfig |= USB_RXCSRH1_AUTORQ;
2619  }
2620  HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRH1) =
2621  ui32NewConfig;
2622  }
2623 }
2624 
2625 //*****************************************************************************
2626 //
2644 //
2645 //*****************************************************************************
2646 void
2647 USBEndpointDMAEnable(uint32_t ui32Base, uint32_t ui32Endpoint,
2648  uint32_t ui32Flags)
2649 {
2650  //
2651  // See if the transmit DMA is being enabled.
2652  //
2653  if(ui32Flags & USB_EP_DEV_IN)
2654  {
2655  //
2656  // Enable DMA on the transmit endpoint.
2657  //
2658  HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRH1) |=
2660  }
2661  else
2662  {
2663  //
2664  // Enable DMA on the receive endpoint.
2665  //
2666  HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRH1) |=
2668  }
2669 }
2670 
2671 //*****************************************************************************
2672 //
2684 //
2685 //*****************************************************************************
2686 void
2687 USBEndpointDMADisable(uint32_t ui32Base, uint32_t ui32Endpoint,
2688  uint32_t ui32Flags)
2689 {
2690  //
2691  // If this was a request to disable DMA on the IN portion of the endpoint
2692  // then handle it.
2693  //
2694  if(ui32Flags & USB_EP_DEV_IN)
2695  {
2696  //
2697  // Just disable DMA leave the mode setting.
2698  //
2699  HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRH1) &=
2701  }
2702  else
2703  {
2704  //
2705  // Just disable DMA leave the mode setting.
2706  //
2707  HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRH1) &=
2709  }
2710 }
2711 
2712 //*****************************************************************************
2713 //
2727 //
2728 //*****************************************************************************
2729 uint32_t
2730 USBEndpointDataAvail(uint32_t ui32Base, uint32_t ui32Endpoint)
2731 {
2732  uint32_t ui32Register;
2733 
2734  //
2735  // Check the arguments.
2736  //
2737  ASSERT(ui32Base == USB0_BASE);
2738  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
2739  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
2740  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
2741  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
2742 
2743  //
2744  // Get the address of the receive status register to use, based on the
2745  // endpoint.
2746  //
2747  if(ui32Endpoint == USB_EP_0)
2748  {
2749  ui32Register = USB_O_CSRL0;
2750  }
2751  else
2752  {
2753  ui32Register = USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint);
2754  }
2755 
2756  //
2757  // Is there a packet ready in the FIFO?
2758  //
2759  if((HWREGH(ui32Base + ui32Register) & USB_CSRL0_RXRDY) == 0)
2760  {
2761  return(0);
2762  }
2763 
2764  //
2765  // Return the byte count in the FIFO.
2766  //
2767  return(HWREGH(ui32Base + USB_O_COUNT0 + ui32Endpoint));
2768 }
2769 
2770 //*****************************************************************************
2771 //
2791 //
2792 //*****************************************************************************
2793 int32_t
2794 USBEndpointDataGet(uint32_t ui32Base, uint32_t ui32Endpoint,
2795  uint8_t *pui8Data, uint32_t *pui32Size)
2796 {
2797  uint32_t ui32Register, ui32ByteCount, ui32FIFO;
2798 
2799  //
2800  // Check the arguments.
2801  //
2802  ASSERT(ui32Base == USB0_BASE);
2803  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
2804  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
2805  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
2806  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
2807 
2808  //
2809  // Get the address of the receive status register to use, based on the
2810  // endpoint.
2811  //
2812  if(ui32Endpoint == USB_EP_0)
2813  {
2814  ui32Register = USB_O_CSRL0;
2815  }
2816  else
2817  {
2818  ui32Register = USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint);
2819  }
2820 
2821  //
2822  // Don't allow reading of data if the RxPktRdy bit is not set.
2823  //
2824  if((HWREGH(ui32Base + ui32Register) & USB_CSRL0_RXRDY) == 0)
2825  {
2826  //
2827  // Can't read the data because none is available.
2828  //
2829  *pui32Size = 0;
2830 
2831  //
2832  // Return a failure since there is no data to read.
2833  //
2834  return(-1);
2835  }
2836 
2837  //
2838  // Get the byte count in the FIFO.
2839  //
2840  ui32ByteCount = HWREGH(ui32Base + USB_O_COUNT0 + ui32Endpoint);
2841 
2842  //
2843  // Determine how many bytes are copied.
2844  //
2845  ui32ByteCount = (ui32ByteCount < *pui32Size) ? ui32ByteCount : *pui32Size;
2846 
2847  //
2848  // Return the number of bytes we are going to read.
2849  //
2850  *pui32Size = ui32ByteCount;
2851 
2852  //
2853  // Calculate the FIFO address.
2854  //
2855  ui32FIFO = ui32Base + USB_O_FIFO0 + (ui32Endpoint >> 2);
2856 
2857  //
2858  // Read the data out of the FIFO.
2859  //
2860  for(; ui32ByteCount > 0; ui32ByteCount--)
2861  {
2862  //
2863  // Read a byte at a time from the FIFO.
2864  //
2865  *pui8Data++ = HWREGB(ui32FIFO);
2866  }
2867 
2868  //
2869  // Success.
2870  //
2871  return(0);
2872 }
2873 
2874 //*****************************************************************************
2875 //
2893 //
2894 //*****************************************************************************
2895 void
2896 USBDevEndpointDataAck(uint32_t ui32Base, uint32_t ui32Endpoint,
2897  bool bIsLastPacket)
2898 {
2899  //
2900  // Check the arguments.
2901  //
2902  ASSERT(ui32Base == USB0_BASE);
2903  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
2904  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
2905  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
2906  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
2907 
2908  //
2909  // Determine which endpoint is being acked.
2910  //
2911  if(ui32Endpoint == USB_EP_0)
2912  {
2913  //
2914  // Clear RxPktRdy, and optionally DataEnd, on endpoint zero.
2915  //
2916  HWREGB(ui32Base + USB_O_CSRL0) =
2917  USB_CSRL0_RXRDYC | (bIsLastPacket ? USB_CSRL0_DATAEND : 0);
2918  }
2919  else
2920  {
2921  //
2922  // Clear RxPktRdy on all other endpoints.
2923  //
2924  HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
2925  ~(USB_RXCSRL1_RXRDY);
2926  }
2927 }
2928 
2929 //*****************************************************************************
2930 //
2944 //
2945 //*****************************************************************************
2946 void
2947 USBHostEndpointDataAck(uint32_t ui32Base, uint32_t ui32Endpoint)
2948 {
2949  //
2950  // Check the arguments.
2951  //
2952  ASSERT(ui32Base == USB0_BASE);
2953  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
2954  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
2955  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
2956  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
2957 
2958  //
2959  // Clear RxPktRdy.
2960  //
2961  if(ui32Endpoint == USB_EP_0)
2962  {
2963  HWREGB(ui32Base + USB_O_CSRL0) &= ~USB_CSRL0_RXRDY;
2964  }
2965  else
2966  {
2967  HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
2968  ~(USB_RXCSRL1_RXRDY);
2969  }
2970 }
2971 
2972 //*****************************************************************************
2973 //
2990 //
2991 //*****************************************************************************
2992 int32_t
2993 USBEndpointDataPut(uint32_t ui32Base, uint32_t ui32Endpoint,
2994  uint8_t *pui8Data, uint32_t ui32Size)
2995 {
2996  uint32_t ui32FIFO;
2997  uint8_t ui8TxPktRdy;
2998 
2999  //
3000  // Check the arguments.
3001  //
3002  ASSERT(ui32Base == USB0_BASE);
3003  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
3004  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
3005  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
3006  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
3007 
3008  //
3009  // Get the bit position of TxPktRdy based on the endpoint.
3010  //
3011  if(ui32Endpoint == USB_EP_0)
3012  {
3013  ui8TxPktRdy = USB_CSRL0_TXRDY;
3014  }
3015  else
3016  {
3017  ui8TxPktRdy = USB_TXCSRL1_TXRDY;
3018  }
3019 
3020  //
3021  // Don't allow transmit of data if the TxPktRdy bit is already set.
3022  //
3023  if(HWREGB(ui32Base + USB_O_CSRL0 + ui32Endpoint) & ui8TxPktRdy)
3024  {
3025  return(-1);
3026  }
3027 
3028  //
3029  // Calculate the FIFO address.
3030  //
3031  ui32FIFO = ui32Base + USB_O_FIFO0 + (ui32Endpoint >> 2);
3032 
3033  //
3034  // Write the data to the FIFO.
3035  //
3036  for(; ui32Size > 0; ui32Size--)
3037  {
3038  HWREGB(ui32FIFO) = *pui8Data++;
3039  }
3040 
3041  //
3042  // Success.
3043  //
3044  return(0);
3045 }
3046 
3047 //*****************************************************************************
3048 //
3071 //
3072 //*****************************************************************************
3073 int32_t
3074 USBEndpointDataSend(uint32_t ui32Base, uint32_t ui32Endpoint,
3075  uint32_t ui32TransType)
3076 {
3077  uint32_t ui32TxPktRdy;
3078 
3079  //
3080  // Check the arguments.
3081  //
3082  ASSERT(ui32Base == USB0_BASE);
3083  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
3084  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
3085  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
3086  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
3087 
3088  //
3089  // Get the bit position of TxPktRdy based on the endpoint.
3090  //
3091  if(ui32Endpoint == USB_EP_0)
3092  {
3093  //
3094  // Don't allow transmit of data if the TxPktRdy bit is already set.
3095  //
3096  if(HWREGB(ui32Base + USB_O_CSRL0) & USB_CSRL0_TXRDY)
3097  {
3098  return(-1);
3099  }
3100 
3101  ui32TxPktRdy = ui32TransType & 0xff;
3102  }
3103  else
3104  {
3105  //
3106  // Don't allow transmit of data if the TxPktRdy bit is already set.
3107  //
3108  if(HWREGB(ui32Base + USB_O_CSRL0 + ui32Endpoint) & USB_TXCSRL1_TXRDY)
3109  {
3110  return(-1);
3111  }
3112 
3113  ui32TxPktRdy = (ui32TransType >> 8) & 0xff;
3114  }
3115 
3116  //
3117  // Set TxPktRdy in order to send the data.
3118  //
3119  HWREGB(ui32Base + USB_O_CSRL0 + ui32Endpoint) = ui32TxPktRdy;
3120 
3121  //
3122  // Success.
3123  //
3124  return(0);
3125 }
3126 
3127 //*****************************************************************************
3128 //
3141 //
3142 //*****************************************************************************
3143 void
3144 USBFIFOFlush(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags)
3145 {
3146  //
3147  // Check the arguments.
3148  //
3149  ASSERT(ui32Base == USB0_BASE);
3150  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
3151  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
3152  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
3153  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
3154 
3155  //
3156  // Endpoint zero has a different register set for FIFO flushing.
3157  //
3158  if(ui32Endpoint == USB_EP_0)
3159  {
3160  //
3161  // Nothing in the FIFO if neither of these bits are set.
3162  //
3163  if((HWREGB(ui32Base + USB_O_CSRL0) &
3164  (USB_CSRL0_RXRDY | USB_CSRL0_TXRDY)) != 0)
3165  {
3166  //
3167  // Hit the Flush FIFO bit.
3168  //
3169  HWREGB(ui32Base + USB_O_CSRH0) = USB_CSRH0_FLUSH;
3170  }
3171  }
3172  else
3173  {
3174  //
3175  // Only reset the IN or OUT FIFO.
3176  //
3177  if(ui32Flags & (USB_EP_HOST_OUT | USB_EP_DEV_IN))
3178  {
3179  //
3180  // Make sure the FIFO is not empty.
3181  //
3182  if(HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) &
3184  {
3185  //
3186  // Hit the Flush FIFO bit.
3187  //
3188  HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
3190  }
3191  }
3192  else
3193  {
3194  //
3195  // Make sure that the FIFO is not empty.
3196  //
3197  if(HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) &
3199  {
3200  //
3201  // Hit the Flush FIFO bit.
3202  //
3203  HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
3205  }
3206  }
3207  }
3208 }
3209 
3210 //*****************************************************************************
3211 //
3225 //
3226 //*****************************************************************************
3227 void
3228 USBHostRequestIN(uint32_t ui32Base, uint32_t ui32Endpoint)
3229 {
3230  uint32_t ui32Register;
3231 
3232  //
3233  // Check the arguments.
3234  //
3235  ASSERT(ui32Base == USB0_BASE);
3236  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
3237  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
3238  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
3239  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
3240 
3241  //
3242  // Endpoint zero uses a different offset than the other endpoints.
3243  //
3244  if(ui32Endpoint == USB_EP_0)
3245  {
3246  ui32Register = USB_O_CSRL0;
3247  }
3248  else
3249  {
3250  ui32Register = USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint);
3251  }
3252 
3253  //
3254  // Set the request for an IN transaction.
3255  //
3256  HWREGB(ui32Base + ui32Register) = USB_RXCSRL1_REQPKT;
3257 }
3258 
3259 //*****************************************************************************
3260 //
3275 //
3276 //*****************************************************************************
3277 void
3278 USBHostRequestINClear(uint32_t ui32Base, uint32_t ui32Endpoint)
3279 {
3280  uint32_t ui32Register;
3281 
3282  //
3283  // Check the arguments.
3284  //
3285  ASSERT(ui32Base == USB0_BASE);
3286  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
3287  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
3288  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
3289  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
3290 
3291  //
3292  // Endpoint zero uses a different offset than the other endpoints.
3293  //
3294  if(ui32Endpoint == USB_EP_0)
3295  {
3296  ui32Register = USB_O_CSRL0;
3297  }
3298  else
3299  {
3300  ui32Register = USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint);
3301  }
3302 
3303  //
3304  // Clear the request for an IN transaction.
3305  //
3306  HWREGB(ui32Base + ui32Register) &= ~USB_RXCSRL1_REQPKT;
3307 }
3308 
3309 //*****************************************************************************
3310 //
3325 //
3326 //*****************************************************************************
3327 void
3328 USBHostRequestStatus(uint32_t ui32Base)
3329 {
3330  //
3331  // Check the arguments.
3332  //
3333  ASSERT(ui32Base == USB0_BASE);
3334 
3335  //
3336  // Set the request for a status IN transaction.
3337  //
3339 }
3340 
3341 //*****************************************************************************
3342 //
3360 //
3361 //*****************************************************************************
3362 void
3363 USBHostAddrSet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Addr,
3364  uint32_t ui32Flags)
3365 {
3366  //
3367  // Check the arguments.
3368  //
3369  ASSERT(ui32Base == USB0_BASE);
3370  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
3371  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
3372  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
3373  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
3374 
3375  //
3376  // See if the transmit or receive address is set.
3377  //
3378  if(ui32Flags & USB_EP_HOST_OUT)
3379  {
3380  //
3381  // Set the transmit address.
3382  //
3383  HWREGB(ui32Base + USB_O_TXFUNCADDR0 + (ui32Endpoint >> 1)) = ui32Addr;
3384  }
3385  else
3386  {
3387  //
3388  // Set the receive address.
3389  //
3390  HWREGB(ui32Base + USB_O_TXFUNCADDR0 + 4 + (ui32Endpoint >> 1)) =
3391  ui32Addr;
3392  }
3393 }
3394 
3395 //*****************************************************************************
3396 //
3410 //
3411 //*****************************************************************************
3412 uint32_t
3413 USBHostAddrGet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags)
3414 {
3415  //
3416  // Check the arguments.
3417  //
3418  ASSERT(ui32Base == USB0_BASE);
3419  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
3420  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
3421  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
3422  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
3423 
3424  //
3425  // See if the transmit or receive address is returned.
3426  //
3427  if(ui32Flags & USB_EP_HOST_OUT)
3428  {
3429  //
3430  // Return this endpoint's transmit address.
3431  //
3432  return(HWREGB(ui32Base + USB_O_TXFUNCADDR0 + (ui32Endpoint >> 1)));
3433  }
3434  else
3435  {
3436  //
3437  // Return this endpoint's receive address.
3438  //
3439  return(HWREGB(ui32Base + USB_O_TXFUNCADDR0 + 4 + (ui32Endpoint >> 1)));
3440  }
3441 }
3442 
3443 //*****************************************************************************
3444 //
3464 //
3465 //*****************************************************************************
3466 void
3467 USBHostHubAddrSet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Addr,
3468  uint32_t ui32Flags)
3469 {
3470  //
3471  // Check the arguments.
3472  //
3473  ASSERT(ui32Base == USB0_BASE);
3474  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
3475  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
3476  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
3477  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
3478 
3479  //
3480  // See if the hub transmit or receive address is being set.
3481  //
3482  if(ui32Flags & USB_EP_HOST_OUT)
3483  {
3484  //
3485  // Set the hub transmit address and port number for this endpoint.
3486  //
3487  HWREGH(ui32Base + USB_O_TXHUBADDR0 + (ui32Endpoint >> 1)) = ui32Addr;
3488  }
3489  else
3490  {
3491  //
3492  // Set the hub receive address and port number for this endpoint.
3493  //
3494  HWREGH(ui32Base + USB_O_TXHUBADDR0 + 4 + (ui32Endpoint >> 1)) =
3495  ui32Addr;
3496  }
3497 
3498  //
3499  // Set the speed of communication for endpoint 0. This configuration is
3500  // done here because it changes on a transaction-by-transaction basis for
3501  // EP0. For other endpoints, this is set in USBHostEndpointConfig().
3502  //
3503  if(ui32Endpoint == USB_EP_0)
3504  {
3505  if(ui32Flags & USB_EP_SPEED_FULL)
3506  {
3507  HWREGB(ui32Base + USB_O_TYPE0) = USB_TYPE0_SPEED_FULL;
3508  }
3509  else if(ui32Flags & USB_EP_SPEED_HIGH)
3510  {
3511  HWREGB(ui32Base + USB_O_TYPE0) = USB_TYPE0_SPEED_HIGH;
3512  }
3513  else
3514  {
3515  HWREGB(ui32Base + USB_O_TYPE0) = USB_TYPE0_SPEED_LOW;
3516  }
3517  }
3518 }
3519 
3520 //*****************************************************************************
3521 //
3536 //
3537 //*****************************************************************************
3538 uint32_t
3539 USBHostHubAddrGet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags)
3540 {
3541  //
3542  // Check the arguments.
3543  //
3544  ASSERT(ui32Base == USB0_BASE);
3545  ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
3546  (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
3547  (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
3548  (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
3549 
3550  //
3551  // See if the hub transmit or receive address is returned.
3552  //
3553  if(ui32Flags & USB_EP_HOST_OUT)
3554  {
3555  //
3556  // Return the hub transmit address for this endpoint.
3557  //
3558  return(HWREGB(ui32Base + USB_O_TXHUBADDR0 + (ui32Endpoint >> 1)));
3559  }
3560  else
3561  {
3562  //
3563  // Return the hub receive address for this endpoint.
3564  //
3565  return(HWREGB(ui32Base + USB_O_TXHUBADDR0 + 4 + (ui32Endpoint >> 1)));
3566  }
3567 }
3568 
3569 //*****************************************************************************
3570 //
3625 //
3626 //*****************************************************************************
3627 void
3628 USBHostPwrConfig(uint32_t ui32Base, uint32_t ui32Flags)
3629 {
3630  //
3631  // Check the arguments.
3632  //
3633  ASSERT(ui32Base == USB0_BASE);
3636  USB_EPC_EPEN_M)) == 0);
3637 
3638  //
3639  // If requested, enable VBUS droop detection on parts that support this
3640  // feature.
3641  //
3642  HWREG(ui32Base + USB_O_VDC) = ui32Flags >> 16;
3643 
3644  //
3645  // Set the power fault configuration as specified. This configuration
3646  // does not change whether fault detection is enabled or not.
3647  //
3648  HWREGH(ui32Base + USB_O_EPC) =
3649  (ui32Flags | (HWREGH(ui32Base + USB_O_EPC) &
3652 }
3653 
3654 //*****************************************************************************
3655 //
3666 //
3667 //*****************************************************************************
3668 void
3669 USBHostPwrFaultEnable(uint32_t ui32Base)
3670 {
3671  //
3672  // Check the arguments.
3673  //
3674  ASSERT(ui32Base == USB0_BASE);
3675 
3676  //
3677  // Enable power fault input.
3678  //
3679  HWREGH(ui32Base + USB_O_EPC) |= USB_EPC_PFLTEN;
3680 }
3681 
3682 //*****************************************************************************
3683 //
3693 //
3694 //*****************************************************************************
3695 void
3696 USBHostPwrFaultDisable(uint32_t ui32Base)
3697 {
3698  //
3699  // Check the arguments.
3700  //
3701  ASSERT(ui32Base == USB0_BASE);
3702 
3703  //
3704  // Enable power fault input.
3705  //
3706  HWREGH(ui32Base + USB_O_EPC) &= ~USB_EPC_PFLTEN;
3707 }
3708 
3709 //*****************************************************************************
3710 //
3721 //
3722 //*****************************************************************************
3723 void
3724 USBHostPwrEnable(uint32_t ui32Base)
3725 {
3726  //
3727  // Check the arguments.
3728  //
3729  ASSERT(ui32Base == USB0_BASE);
3730 
3731  //
3732  // Enable the external power supply enable signal.
3733  //
3734  HWREGH(ui32Base + USB_O_EPC) |= USB_EPC_EPENDE;
3735 }
3736 
3737 //*****************************************************************************
3738 //
3749 //
3750 //*****************************************************************************
3751 void
3752 USBHostPwrDisable(uint32_t ui32Base)
3753 {
3754  //
3755  // Check the arguments.
3756  //
3757  ASSERT(ui32Base == USB0_BASE);
3758 
3759  //
3760  // Disable the external power supply enable signal.
3761  //
3762  HWREGH(ui32Base + USB_O_EPC) &= ~USB_EPC_EPENDE;
3763 }
3764 
3765 //*****************************************************************************
3766 //
3774 //
3775 //*****************************************************************************
3776 uint32_t
3777 USBFrameNumberGet(uint32_t ui32Base)
3778 {
3779  //
3780  // Check the arguments.
3781  //
3782  ASSERT(ui32Base == USB0_BASE);
3783 
3784  //
3785  // Return the most recent frame number.
3786  //
3787  return(HWREGH(ui32Base + USB_O_FRAME));
3788 }
3789 
3790 //*****************************************************************************
3791 //
3802 //
3803 //*****************************************************************************
3804 void
3805 USBOTGSessionRequest(uint32_t ui32Base, bool bStart)
3806 {
3807  //
3808  // Check the arguments.
3809  //
3810  ASSERT(ui32Base == USB0_BASE);
3811 
3812  //
3813  // Start or end the session as directed.
3814  //
3815  if(bStart)
3816  {
3817  HWREGB(ui32Base + USB_O_DEVCTL) |= USB_DEVCTL_SESSION;
3818  }
3819  else
3820  {
3821  HWREGB(ui32Base + USB_O_DEVCTL) &= ~USB_DEVCTL_SESSION;
3822  }
3823 }
3824 
3825 //*****************************************************************************
3826 //
3840 //
3841 //*****************************************************************************
3842 uint32_t
3843 USBFIFOAddrGet(uint32_t ui32Base, uint32_t ui32Endpoint)
3844 {
3845  //
3846  // Return the FIFO address for this endpoint.
3847  //
3848  return(ui32Base + USB_O_FIFO0 + (ui32Endpoint >> 2));
3849 }
3850 
3851 //*****************************************************************************
3852 //
3895 //
3896 //*****************************************************************************
3897 uint32_t
3898 USBModeGet(uint32_t ui32Base)
3899 {
3900  //
3901  // Check the arguments.
3902  //
3903  ASSERT(ui32Base == USB0_BASE);
3904 
3905  //
3906  // Checks the current mode in the USB_O_DEVCTL and returns the current
3907  // mode.
3908  //
3909  // USB_OTG_MODE_ASIDE_HOST: USB_DEVCTL_HOST | USB_DEVCTL_SESSION
3910  // USB_OTG_MODE_ASIDE_DEV: USB_DEVCTL_SESSION
3911  // USB_OTG_MODE_BSIDE_HOST: USB_DEVCTL_DEV | USB_DEVCTL_SESSION |
3912  // USB_DEVCTL_HOST
3913  // USB_OTG_MODE_BSIDE_DEV: USB_DEVCTL_DEV | USB_DEVCTL_SESSION
3914  // USB_OTG_MODE_NONE: USB_DEVCTL_DEV
3915  //
3916  return(HWREGB(ui32Base + USB_O_DEVCTL) &
3919 }
3920 
3921 //*****************************************************************************
3922 //
3942 //*****************************************************************************
3943 void
3944 USBEndpointDMAChannel(uint32_t ui32Base, uint32_t ui32Endpoint,
3945  uint32_t ui32Channel)
3946 {
3947  uint32_t ui32Mask;
3948 
3949  //
3950  // Check the arguments.
3951  //
3952  ASSERT(ui32Base == USB0_BASE);
3953  ASSERT((ui32Endpoint == USB_EP_1) || (ui32Endpoint == USB_EP_2) ||
3954  (ui32Endpoint == USB_EP_3) || (ui32Endpoint == USB_EP_4) ||
3955  (ui32Endpoint == USB_EP_5) || (ui32Endpoint == USB_EP_6) ||
3956  (ui32Endpoint == USB_EP_7));
3957  ASSERT(ui32Channel <= UDMA_CHANNEL_USBEP3TX);
3958 
3959  //
3960  // The input select mask must be shifted into the correct position
3961  // based on the channel.
3962  //
3963  ui32Mask = 0xf << (ui32Channel * 4);
3964 
3965  //
3966  // Clear out the current selection for the channel.
3967  //
3968  ui32Mask = HWREG(ui32Base + USB_O_DMASEL) & (~ui32Mask);
3969 
3970  //
3971  // The input select is now shifted into the correct position based on the
3972  // channel.
3973  //
3974  ui32Mask |= (USBEPToIndex(ui32Endpoint)) << (ui32Channel * 4);
3975 
3976  //
3977  // Write the value out to the register.
3978  //
3979  HWREG(ui32Base + USB_O_DMASEL) = ui32Mask;
3980 }
3981 
3982 //*****************************************************************************
3983 //
3994 //
3995 //*****************************************************************************
3996 void
3997 USBHostMode(uint32_t ui32Base)
3998 {
3999  //
4000  // Check the arguments.
4001  //
4002  ASSERT(ui32Base == USB0_BASE);
4003 
4004  //
4005  // Force mode in OTG parts that support forcing USB controller mode.
4006  // This bit is not writable in USB controllers that do not support
4007  // forcing the mode. Not setting the USB_GPCS_DEVMOD bit makes this a
4008  // force of host mode.
4009  //
4010  HWREGB(ui32Base + USB_O_GPCS) = USB_GPCS_DEVMODOTG;
4011 }
4012 
4013 //*****************************************************************************
4014 //
4025 //
4026 //*****************************************************************************
4027 void
4028 USBDevMode(uint32_t ui32Base)
4029 {
4030  //
4031  // Check the arguments.
4032  //
4033  ASSERT(ui32Base == USB0_BASE);
4034 
4035  //
4036  // Set the USB controller mode to device.
4037  //
4039 }
4040 
4041 //*****************************************************************************
4042 //
4051 //
4052 //*****************************************************************************
4053 void
4054 USBOTGMode(uint32_t ui32Base)
4055 {
4056  //
4057  // Check the arguments.
4058  //
4059  ASSERT(ui32Base == USB0_BASE);
4060 
4061  //
4062  // Disable the override of the USB controller mode when running on an OTG
4063  // device.
4064  //
4065  HWREGB(ui32Base + USB_O_GPCS) = 0;
4066 }
4067 
4068 //*****************************************************************************
4069 //
4114 //
4115 //*****************************************************************************
4116 void
4117 USBModeConfig(uint32_t ui32Base, uint32_t ui32Mode)
4118 {
4119  //
4120  // Check the arguments.
4121  //
4122  ASSERT(ui32Base == USB0_BASE);
4123 
4124  HWREG(ui32Base + USB_O_GPCS) = ui32Mode;
4125 }
4126 
4127 //*****************************************************************************
4128 //
4138 //
4139 //*****************************************************************************
4140 void
4141 USBPHYPowerOff(uint32_t ui32Base)
4142 {
4143  //
4144  // Set the PWRDNPHY bit in the PHY, putting it into its low power mode.
4145  //
4146  HWREGB(ui32Base + USB_O_POWER) |= USB_POWER_PWRDNPHY;
4147 }
4148 
4149 //*****************************************************************************
4150 //
4160 //
4161 //*****************************************************************************
4162 void
4163 USBPHYPowerOn(uint32_t ui32Base)
4164 {
4165  //
4166  // Clear the PWRDNPHY bit in the PHY, putting it into normal operating
4167  // mode.
4168  //
4169  HWREGB(ui32Base + USB_O_POWER) &= ~USB_POWER_PWRDNPHY;
4170 }
4171 
4172 //*****************************************************************************
4173 //
4189 //
4190 //*****************************************************************************
4191 void
4192 USBEndpointPacketCountSet(uint32_t ui32Base, uint32_t ui32Endpoint,
4193  uint32_t ui32Count)
4194 {
4195  HWREG(ui32Base + USB_O_RQPKTCOUNT1 +
4196  (0x4 * (USBEPToIndex(ui32Endpoint) - 1))) = ui32Count;
4197 }
4198 
4199 //*****************************************************************************
4200 //
4212 //
4213 //*****************************************************************************
4214 uint32_t
4215 USBNumEndpointsGet(uint32_t ui32Base)
4216 {
4217  //
4218  // Read the number of endpoints from the hardware. The number of TX and
4219  // RX endpoints are always the same.
4220  //
4221  return(HWREGB(ui32Base + USB_O_EPINFO) & USB_EPINFO_TXEP_M);
4222 }
4223 
4224 //*****************************************************************************
4225 //
4253 //
4254 //*****************************************************************************
4255 uint32_t
4256 USBControllerVersion(uint32_t ui32Base)
4257 {
4258  //
4259  // Return the type field of the peripheral properties. This returns
4260  // zero for all parts that did not have a peripheral property.
4261  //
4262  return(HWREG(ui32Base + USB_O_PP) & USB_PP_TYPE_M);
4263 }
4264 
4265 //*****************************************************************************
4266 //
4307 //
4308 //*****************************************************************************
4309 void
4310 USBClockEnable(uint32_t ui32Base, uint32_t ui32Div, uint32_t ui32Flags)
4311 {
4312  ASSERT(ui32Base == USB0_BASE);
4313 
4314  //
4315  // Configure and enable the USB clock input.
4316  //
4317  HWREG(ui32Base + USB_O_CC) = (ui32Div - 1) | ui32Flags;
4318 }
4319 
4320 //*****************************************************************************
4321 //
4343 //
4344 //*****************************************************************************
4345 void
4346 USBClockDisable(uint32_t ui32Base)
4347 {
4348  ASSERT(ui32Base == USB0_BASE);
4349 
4350  //
4351  // Disable the USB clock input.
4352  //
4353  HWREG(ui32Base + USB_O_CC) = 0;
4354 }
4355 
4356 //*****************************************************************************
4357 //
4358 // Close the Doxygen group.
4360 //
4361 //*****************************************************************************
4362 //*****************************************************************************
4363 //
4366 //
4367 //*****************************************************************************
4368 
4369 //*****************************************************************************
4370 //
4395 //
4396 //*****************************************************************************
4397 void
4398 USBDMAChannelIntEnable(uint32_t ui32Base, uint32_t ui32Channel)
4399 {
4400  ASSERT(ui32Base == USB0_BASE);
4401  ASSERT(ui32Channel < 8);
4402 
4403  //
4404  // Enable the specified DMA channel interrupts.
4405  //
4406  HWREG(ui32Base + USB_O_DMACTL0 + (0x10 * ui32Channel)) |= USB_DMACTL0_IE;
4407 }
4408 
4409 //*****************************************************************************
4410 //
4434 //
4435 //*****************************************************************************
4436 void
4437 USBDMAChannelIntDisable(uint32_t ui32Base, uint32_t ui32Channel)
4438 {
4439  ASSERT(ui32Base == USB0_BASE);
4440  ASSERT(ui32Channel < 8);
4441 
4442  //
4443  // Enable the specified DMA channel interrupts.
4444  //
4445  HWREG(ui32Base + USB_O_DMACTL0 + (0x10 * ui32Channel)) &= ~USB_DMACTL0_IE;
4446 }
4447 
4448 //*****************************************************************************
4449 //
4474 //
4475 //*****************************************************************************
4476 uint32_t
4477 USBDMAChannelIntStatus(uint32_t ui32Base)
4478 {
4479  ASSERT(ui32Base == USB0_BASE);
4480 
4481  return(HWREG(ui32Base + USB_O_DMAINTR));
4482 }
4483 
4484 //*****************************************************************************
4485 //
4509 //
4510 //*****************************************************************************
4511 void
4512 USBDMAChannelEnable(uint32_t ui32Base, uint32_t ui32Channel)
4513 {
4514  ASSERT(ui32Base == USB0_BASE);
4515  ASSERT(ui32Channel < 8);
4516 
4517  //
4518  // Enable the USB DMA channel.
4519  //
4520  HWREG(ui32Base + USB_O_DMACTL0 + (0x10 * ui32Channel)) |=
4522 }
4523 
4524 //*****************************************************************************
4525 //
4549 //
4550 //*****************************************************************************
4551 void
4552 USBDMAChannelDisable(uint32_t ui32Base, uint32_t ui32Channel)
4553 {
4554  ASSERT(ui32Base == USB0_BASE);
4555  ASSERT(ui32Channel < 8);
4556 
4557  //
4558  // Disable the USB DMA channel.
4559  //
4560  HWREG(ui32Base + USB_O_DMACTL0 + (0x10 * ui32Channel)) &=
4562 }
4563 
4564 //*****************************************************************************
4565 //
4626 //
4627 //*****************************************************************************
4628 void
4629 USBDMAChannelConfigSet(uint32_t ui32Base, uint32_t ui32Channel,
4630  uint32_t ui32Endpoint, uint32_t ui32Config)
4631 {
4632  ASSERT(ui32Base == USB0_BASE);
4633  ASSERT(ui32Channel < 8);
4634  ASSERT((ui32Endpoint & ~USB_EP_7) == 0);
4635 
4636  //
4637  // Reset this USB DMA channel.
4638  //
4639  HWREG(ui32Base + USB_O_DMACTL0 + (0x10 * ui32Channel)) = 0;
4640 
4641  //
4642  // Set the configuration of the requested channel.
4643  //
4644  HWREG(ui32Base + USB_O_DMACTL0 + (0x10 * ui32Channel)) =
4645  ui32Config | ui32Endpoint;
4646 }
4647 
4648 //*****************************************************************************
4649 //
4676 //
4677 //*****************************************************************************
4678 uint32_t
4679 USBDMAChannelStatus(uint32_t ui32Base, uint32_t ui32Channel)
4680 {
4681  ASSERT(ui32Base == USB0_BASE);
4682  ASSERT(ui32Channel < 8);
4683 
4684  //
4685  // Return a non-zero value if there is a pending error condition.
4686  //
4687  return(HWREG(ui32Base + USB_O_DMACTL0 + (0x10 * ui32Channel)) &
4688  USB_DMACTL0_ERR);
4689 }
4690 
4691 //*****************************************************************************
4692 //
4719 //
4720 //*****************************************************************************
4721 void
4722 USBDMAChannelStatusClear(uint32_t ui32Base, uint32_t ui32Channel,
4723  uint32_t ui32Status)
4724 {
4725  ASSERT(ui32Base == USB0_BASE);
4726  ASSERT(ui32Channel < 8);
4727 
4728  //
4729  // The only status is the error bit.
4730  //
4731  ui32Status &= USB_DMACTL0_ERR;
4732 
4733  //
4734  // Clear the specified error condition.
4735  //
4736  HWREG(ui32Base + USB_O_DMACTL0 + (0x10 * ui32Channel)) &= ~ui32Status;
4737 }
4738 
4739 //*****************************************************************************
4740 //
4772 //
4773 //*****************************************************************************
4774 void
4775 USBDMAChannelAddressSet(uint32_t ui32Base, uint32_t ui32Channel,
4776  void *pvAddress)
4777 {
4778  ASSERT(ui32Base == USB0_BASE);
4779  ASSERT(ui32Channel < 8);
4780 
4781  //
4782  // Set the DMA address.
4783  //
4784  HWREG(ui32Base + USB_O_DMAADDR0 + (0x10 * ui32Channel)) =
4785  (uint32_t)pvAddress;
4786 }
4787 
4788 //*****************************************************************************
4789 //
4818 //
4819 //*****************************************************************************
4820 void *
4821 USBDMAChannelAddressGet(uint32_t ui32Base, uint32_t ui32Channel)
4822 {
4823  ASSERT(ui32Base == USB0_BASE);
4824  ASSERT(ui32Channel < 8);
4825 
4826  //
4827  // Return the current DMA address.
4828  //
4829  return((void *)HWREG(ui32Base + USB_O_DMAADDR0 + (0x10 * ui32Channel)));
4830 }
4831 
4832 //*****************************************************************************
4833 //
4858 //
4859 //*****************************************************************************
4860 void
4861 USBDMAChannelCountSet(uint32_t ui32Base, uint32_t ui32Channel,
4862  uint32_t ui32Count)
4863 {
4864  ASSERT(ui32Base == USB0_BASE);
4865  ASSERT(ui32Channel < 8);
4866 
4867  //
4868  // Set the USB DMA count for the channel.
4869  //
4870  HWREG(ui32Base + USB_O_DMACOUNT0 + (0x10 * ui32Channel)) = ui32Count;
4871 }
4872 
4873 //*****************************************************************************
4874 //
4900 //
4901 //*****************************************************************************
4902 uint32_t
4903 USBDMAChannelCountGet(uint32_t ui32Base, uint32_t ui32Channel)
4904 {
4905  ASSERT(ui32Base == USB0_BASE);
4906  ASSERT(ui32Channel < 8);
4907 
4908  //
4909  // Return the current DMA count.
4910  //
4911  return(HWREG(ui32Base + USB_O_DMACOUNT0 + (0x10 * ui32Channel)));
4912 }
4913 
4914 //*****************************************************************************
4915 //
4937 //
4938 //*****************************************************************************
4939 uint32_t
4940 USBDMANumChannels(uint32_t ui32Base)
4941 {
4942  ASSERT(ui32Base == USB0_BASE);
4943 
4944  //
4945  // Return the number of DMA channels for the integrated DMA controller.
4946  //
4947  return(HWREG(ui32Base + USB_O_RAMINFO) >> USB_RAMINFO_DMACHAN_S);
4948 }
4949 //*****************************************************************************
4950 //
4951 // Close the Doxygen group.
4953 //
4954 //*****************************************************************************
4955 //*****************************************************************************
4956 //
4959 //
4960 //*****************************************************************************
4961 
4962 //*****************************************************************************
4963 //
4992 //
4993 //*****************************************************************************
4994 void
4995 USBULPIConfig(uint32_t ui32Base, uint32_t ui32Config)
4996 {
4997  HWREGB(ui32Base + USB_O_ULPIVBUSCTL) = (uint8_t)ui32Config;
4998 }
4999 
5000 //*****************************************************************************
5001 //
5023 //
5024 //*****************************************************************************
5025 void
5026 USBULPIEnable(uint32_t ui32Base)
5027 {
5028  HWREG(ui32Base + USB_O_PC) |= USB_PC_ULPIEN;
5029 }
5030 
5031 //*****************************************************************************
5032 //
5055 //
5056 //*****************************************************************************
5057 void
5058 USBULPIDisable(uint32_t ui32Base)
5059 {
5060  HWREG(ui32Base + USB_O_PC) &= ~USB_PC_ULPIEN;
5061 }
5062 
5063 //*****************************************************************************
5064 //
5091 //
5092 //*****************************************************************************
5093 uint8_t
5094 USBULPIRegRead(uint32_t ui32Base, uint8_t ui8Reg)
5095 {
5096  ASSERT(ui32Base == USB0_BASE);
5097 
5098  //
5099  // Set the register address and initiate a read access.
5100  //
5101  HWREGB(ui32Base + USB_O_ULPIREGADDR) = ui8Reg;
5102  HWREGB(ui32Base + USB_O_ULPIREGCTL) =
5104 
5105  //
5106  // Wait for the access to complete.
5107  //
5108  while((HWREGB(ui32Base + USB_O_ULPIREGCTL) & USB_ULPIREGCTL_REGCMPLT) == 0)
5109  {
5110  }
5111 
5112  //
5113  // Clear the register access complete flag.
5114  //
5115  HWREGB(ui32Base + USB_O_ULPIREGCTL) = 0;
5116 
5117  return(HWREGB(ui32Base + USB_O_ULPIREGDATA));
5118 }
5119 
5120 //*****************************************************************************
5121 //
5148 //
5149 //*****************************************************************************
5150 void
5151 USBULPIRegWrite(uint32_t ui32Base, uint8_t ui8Reg, uint8_t ui8Data)
5152 {
5153  ASSERT(ui32Base == USB0_BASE);
5154 
5155  //
5156  // Set the register address and initiate a read access.
5157  //
5158  HWREGB(ui32Base + USB_O_ULPIREGADDR) = ui8Reg;
5159  HWREGB(ui32Base + USB_O_ULPIREGDATA) = ui8Data;
5161 
5162  //
5163  // Wait for the access to complete.
5164  //
5165  while((HWREGB(ui32Base + USB_O_ULPIREGCTL) & USB_ULPIREGCTL_REGCMPLT) == 0)
5166  {
5167  }
5168 
5169  //
5170  // Clear the register access complete flag.
5171  //
5172  HWREGB(ui32Base + USB_O_ULPIREGCTL) = 0;
5173 }
5174 
5175 //*****************************************************************************
5176 //
5177 // Close the Doxygen group.
5179 //
5180 //*****************************************************************************
5181 //*****************************************************************************
5182 //
5185 //
5186 //*****************************************************************************
5187 
5188 //*****************************************************************************
5189 //
5221 //
5222 //*****************************************************************************
5223 void
5224 USBHostLPMSend(uint32_t ui32Base, uint32_t ui32Address, uint32_t ui32Endpoint)
5225 {
5226  uint32_t ui32Reg;
5227 
5228  ASSERT(ui32Base == USB0_BASE);
5229  ASSERT(ui32Address < 127);
5230 
5231  //
5232  // Set the address and endpoint.
5233  //
5234  HWREGB(ui32Base + USB_O_LPMFADDR) = ui32Address;
5235 
5236  ui32Reg = HWREGH(ui32Base + USB_O_LPMATTR) & ~USB_LPMATTR_ENDPT_M;
5237  ui32Reg |= (USBEPToIndex(ui32Endpoint) << USB_LPMATTR_ENDPT_S);
5238 
5239  HWREGH(ui32Base + USB_O_LPMATTR) = ui32Reg;
5240 
5241  //
5242  // Send the LPM transaction.
5243  //
5244  HWREGB(ui32Base + USB_O_LPMCNTRL) |= USB_LPMCNTRL_TXLPM;
5245 }
5246 
5247 //*****************************************************************************
5248 //
5287 //
5288 //*****************************************************************************
5289 void
5290 USBHostLPMConfig(uint32_t ui32Base, uint32_t ui32ResumeTime,
5291  uint32_t ui32Config)
5292 {
5293  ASSERT(ui32Base == USB0_BASE);
5294  ASSERT(ui32ResumeTime <= 1175);
5295  ASSERT(ui32ResumeTime >= 50);
5296 
5297  //
5298  // Set the Host Initiated Resume Duration, Remote wake and Suspend mode.
5299  //
5300  HWREGH(ui32Base + USB_O_LPMATTR) =
5301  ui32Config | ((ui32ResumeTime - 50) / 75) << USB_LPMATTR_HIRD_S;
5302 }
5303 
5304 //*****************************************************************************
5305 //
5330 //
5331 //*****************************************************************************
5332 void
5333 USBHostLPMResume(uint32_t ui32Base)
5334 {
5335  ASSERT(ui32Base == USB0_BASE);
5336 
5337  //
5338  // Send Resume signaling.
5339  //
5340  HWREGB(ui32Base + USB_O_LPMCNTRL) |= USB_LPMCNTRL_RES;
5341 }
5342 
5343 //*****************************************************************************
5344 //
5368 //
5369 //*****************************************************************************
5370 void
5371 USBDevLPMRemoteWake(uint32_t ui32Base)
5372 {
5373  ASSERT(ui32Base == USB0_BASE);
5374 
5375  //
5376  // Send remote wake signaling.
5377  //
5378  HWREGB(ui32Base + USB_O_LPMCNTRL) |= USB_LPMCNTRL_RES;
5379 }
5380 
5381 //*****************************************************************************
5382 //
5426 //
5427 //*****************************************************************************
5428 void
5429 USBDevLPMConfig(uint32_t ui32Base, uint32_t ui32Config)
5430 {
5431  ASSERT(ui32Base == USB0_BASE);
5432 
5433  //
5434  // Set the device LPM configuration.
5435  //
5436  HWREGB(ui32Base + USB_O_LPMCNTRL) = ui32Config;
5437 }
5438 
5439 //*****************************************************************************
5440 //
5470 //
5471 //*****************************************************************************
5472 void
5473 USBDevLPMEnable(uint32_t ui32Base)
5474 {
5475  ASSERT(ui32Base == USB0_BASE);
5476 
5477  //
5478  // Enable L1 mode on the next LPM transaction.
5479  //
5480  HWREGB(ui32Base + USB_O_LPMCNTRL) |=
5482 }
5483 
5484 //*****************************************************************************
5485 //
5514 //
5515 //*****************************************************************************
5516 void
5517 USBDevLPMDisable(uint32_t ui32Base)
5518 {
5519  ASSERT(ui32Base == USB0_BASE);
5520 
5521  //
5522  // Disable auto entering L1 mode on LPM transactions.
5523  //
5524  HWREGB(ui32Base + USB_O_LPMCNTRL) &= ~USB_LPMCNTRL_TXLPM;
5525 }
5526 
5527 //*****************************************************************************
5528 //
5572 //
5573 //*****************************************************************************
5574 uint32_t
5575 USBLPMLinkStateGet(uint32_t ui32Base)
5576 {
5577  ASSERT(ui32Base == USB0_BASE);
5578 
5579  return(HWREGH(ui32Base + USB_O_LPMATTR) & USB_LPMATTR_LS_M);
5580 }
5581 
5582 //*****************************************************************************
5583 //
5615 //
5616 //*****************************************************************************
5617 uint32_t
5618 USBLPMEndpointGet(uint32_t ui32Base)
5619 {
5620  uint32_t ui32Endpoint;
5621 
5622  ASSERT(ui32Base == USB0_BASE);
5623 
5624  ui32Endpoint = (HWREGH(ui32Base + USB_O_LPMATTR) & USB_LPMATTR_ENDPT_M) >>
5626 
5627  return(IndexToUSBEP(ui32Endpoint));
5628 }
5629 
5630 //*****************************************************************************
5631 //
5659 //
5660 //*****************************************************************************
5661 bool
5662 USBLPMRemoteWakeEnabled(uint32_t ui32Base)
5663 {
5664  ASSERT(ui32Base == USB0_BASE);
5665 
5666  if(HWREGH(ui32Base + USB_O_LPMATTR) & USB_LPMATTR_RMTWAK)
5667  {
5668  return(true);
5669  }
5670  return(false);
5671 }
5672 
5673 //*****************************************************************************
5674 //
5746 //
5747 //*****************************************************************************
5748 uint32_t
5749 USBLPMIntStatus(uint32_t ui32Base)
5750 {
5751  ASSERT(ui32Base == USB0_BASE);
5752 
5753  //
5754  // Return the current raw interrupt status.
5755  //
5756  return(HWREGB(ui32Base + USB_O_LPMRIS));
5757 }
5758 
5759 //*****************************************************************************
5760 //
5819 //
5820 //*****************************************************************************
5821 void
5822 USBLPMIntEnable(uint32_t ui32Base, uint32_t ui32Ints)
5823 {
5824  ASSERT(ui32Base == USB0_BASE);
5825 
5826  //
5827  // Enable the requested interrupts.
5828  //
5829  HWREGB(ui32Base + USB_O_LPMIM) |= ui32Ints;
5830 }
5831 
5832 //*****************************************************************************
5833 //
5891 //
5892 //*****************************************************************************
5893 void
5894 USBLPMIntDisable(uint32_t ui32Base, uint32_t ui32Ints)
5895 {
5896  ASSERT(ui32Base == USB0_BASE);
5897 
5898  //
5899  // Disable the requested interrupts.
5900  //
5901  HWREGB(ui32Base + USB_O_LPMIM) &= ~ui32Ints;
5902 }
5903 
5904 //*****************************************************************************
5905 //
5906 // Close the Doxygen group.
5908 //
5909 //*****************************************************************************
#define USB_INTEP_RX_SHIFT
Definition: usb.c:66
#define USB_DEV_EP0_SENT_STALL
Definition: usb.h:216
#define USB_O_IE
Definition: hw_usb.h:55
#define USB_TXTYPE1_PROTO_CTRL
Definition: hw_usb.h:1350
void USBDevEndpointStall(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags)
Definition: usb.c:1369
void USBModeConfig(uint32_t ui32Base, uint32_t ui32Mode)
Definition: usb.c:4117
int32_t USBEndpointDataPut(uint32_t ui32Base, uint32_t ui32Endpoint, uint8_t *pui8Data, uint32_t ui32Size)
Definition: usb.c:2993
#define USB_RXCSRH1_DMAEN
Definition: hw_usb.h:1322
#define USB_EP_MODE_ISOC
Definition: usb.h:234
#define USB_O_RXFIFOADD
Definition: hw_usb.h:72
void USBIntEnableEndpoint(uint32_t ui32Base, uint32_t ui32Flags)
Definition: usb.c:742
#define USB_O_EPCISC
Definition: hw_usb.h:381
static uint32_t _USBIndexRead(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32IndexedReg, uint32_t ui32Size)
Definition: usb.c:164
#define USB_TXCSRH1_DMAMOD
Definition: hw_usb.h:1285
#define USB_EP_DEV_IN
Definition: usb.h:244
#define USB_INTCTRL_STATUS
Definition: usb.h:62
void USBPHYPowerOn(uint32_t ui32Base)
Definition: usb.c:4163
void USBDevLPMEnable(uint32_t ui32Base)
Definition: usb.c:5473
void USBHostAddrSet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Addr, uint32_t ui32Flags)
Definition: usb.c:3363
#define USB_TXCSRH1_ISO
Definition: hw_usb.h:1281
void USBHostEndpointDataAck(uint32_t ui32Base, uint32_t ui32Endpoint)
Definition: usb.c:2947
#define USB_RX_EPSTATUS_SHIFT
Definition: usb.c:74
#define USB_O_CSRH0
Definition: hw_usb.h:164
#define USB_O_TYPE0
Definition: hw_usb.h:168
#define USB_O_IDVIM
Definition: hw_usb.h:399
static uint32_t _USBIntNumberGet(uint32_t ui32Base)
Definition: usb.c:818
#define USB_O_RXTYPE1
Definition: hw_usb.h:188
#define USB_EPC_PFLTSEN_HIGH
Definition: hw_usb.h:2850
#define USB_TYPE0_SPEED_HIGH
Definition: hw_usb.h:1239
uint32_t USBDMAChannelCountGet(uint32_t ui32Base, uint32_t ui32Channel)
Definition: usb.c:4903
void USBEndpointDMAEnable(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags)
Definition: usb.c:2647
#define USB_CSRL0_RXRDYC
Definition: hw_usb.h:1204
#define USB_O_DMACTL0
Definition: hw_usb.h:325
#define USB_CSRL0_REQPKT
Definition: hw_usb.h:1205
#define HWREG(x)
Definition: hw_types.h:48
#define USB_RXCSRH1_DMAMOD
Definition: hw_usb.h:1325
void * USBDMAChannelAddressGet(uint32_t ui32Base, uint32_t ui32Channel)
Definition: usb.c:4821
uint32_t USBModeGet(uint32_t ui32Base)
Definition: usb.c:3898
#define USB_LPMATTR_LS_M
Definition: hw_usb.h:2777
#define USB_POWER_HSMODE
Definition: hw_usb.h:424
void USBDMAChannelDisable(uint32_t ui32Base, uint32_t ui32Channel)
Definition: usb.c:4552
void USBIntDisableControl(uint32_t ui32Base, uint32_t ui32Flags)
Definition: usb.c:509
#define USB_EP_DMA_MODE_1
Definition: usb.h:230
#define USB_CSRL0_DATAEND
Definition: hw_usb.h:1209
#define USB_O_FRAME
Definition: hw_usb.h:56
static void _USBIndexWrite(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32IndexedReg, uint32_t ui32Value, uint32_t ui32Size)
Definition: usb.c:101
#define USB_O_TXIS
Definition: hw_usb.h:50
#define USB_RXCSRH1_DT
Definition: hw_usb.h:1327
uint32_t USBDevSpeedGet(uint32_t ui32Base)
Definition: usb.c:474
void USBEndpointDMAChannel(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Channel)
Definition: usb.c:3944
#define USB_LPMATTR_ENDPT_M
Definition: hw_usb.h:2774
#define USB_EP_DEV_OUT
Definition: usb.h:245
#define IndexToUSBEP(x)
Definition: usb.h:363
#define USB_INTCTRL_POWER_FAULT
Definition: usb.h:74
void USBHostRequestStatus(uint32_t ui32Base)
Definition: usb.c:3328
#define USB_DEV_TX_UNDERRUN
Definition: usb.h:211
#define USB_POWER_RESET
Definition: hw_usb.h:425
#define USB_EP_HOST_IN
Definition: usb.h:242
#define USB_O_RQPKTCOUNT1
Definition: hw_usb.h:349
#define USB_RXCSRH1_DISNYET
Definition: hw_usb.h:1323
#define USB_EP_MODE_MASK
Definition: usb.h:238
#define USB_GPCS_DEVMOD
Definition: hw_usb.h:2921
void USBHostEndpointDataToggle(uint32_t ui32Base, uint32_t ui32Endpoint, bool bDataToggle, uint32_t ui32Flags)
Definition: usb.c:1173
#define USB_O_VDC
Definition: hw_usb.h:390
#define USB_O_EPINFO
Definition: hw_usb.h:77
#define USB_TXCSRH1_DT
Definition: hw_usb.h:1287
#define USB_EP_4
Definition: usb.h:351
void USBHostEndpointStatusClear(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags)
Definition: usb.c:1043
#define USB_LOW_SPEED
Definition: usb.h:162
#define ASSERT(expr)
Definition: debug.h:67
uint32_t USBEndpointDataAvail(uint32_t ui32Base, uint32_t ui32Endpoint)
Definition: usb.c:2730
#define USB_RXCSRL1_RXRDY
Definition: hw_usb.h:1312
#define USB_DEVCTL_FSDEV
Definition: hw_usb.h:617
#define USB_INTEP_0
Definition: usb.h:152
#define USB_EP_DIS_NYET
Definition: usb.h:231
#define USB_CSRH0_DTWE
Definition: hw_usb.h:1221
#define USB_LPMATTR_RMTWAK
Definition: hw_usb.h:2775
void USBDMAChannelAddressSet(uint32_t ui32Base, uint32_t ui32Channel, void *pvAddress)
Definition: usb.c:4775
#define USB_O_RXCSRH1
Definition: hw_usb.h:180
#define USB_CSRL0_TXRDY
Definition: hw_usb.h:1212
uint32_t USBFIFOAddrGet(uint32_t ui32Base, uint32_t ui32Endpoint)
Definition: usb.c:3843
void USBHostPwrEnable(uint32_t ui32Base)
Definition: usb.c:3724
#define USB_LPMATTR_HIRD_S
Definition: hw_usb.h:2780
#define USB_RXCSRH1_DTWE
Definition: hw_usb.h:1326
#define USB_O_LPMCNTRL
Definition: hw_usb.h:372
#define USB_PC_ULPIEN
Definition: hw_usb.h:3020
#define USB_RAMINFO_DMACHAN_S
Definition: hw_usb.h:746
#define USB_DEVCTL_VBUS_M
Definition: hw_usb.h:619
#define USB_O_RXCSRL1
Definition: hw_usb.h:178
#define USB_O_RXINTERVAL1
Definition: hw_usb.h:190
#define USB_O_TXCSRH1
Definition: hw_usb.h:174
uint32_t USBEndpointStatus(uint32_t ui32Base, uint32_t ui32Endpoint)
Definition: usb.c:994
#define USB_HIGH_SPEED
Definition: usb.h:160
#define USB_O_TXFIFOADD
Definition: hw_usb.h:71
#define USB_EPC_PFLTEN
Definition: hw_usb.h:2851
#define USB_ULPIREGCTL_RDWR
Definition: hw_usb.h:725
void USBDMAChannelIntEnable(uint32_t ui32Base, uint32_t ui32Channel)
Definition: usb.c:4398
#define USB_O_ULPIREGADDR
Definition: hw_usb.h:75
#define USB_POWER_RESUME
Definition: hw_usb.h:426
#define USB_GPCS_DEVMODOTG
Definition: hw_usb.h:2920
#define USB_EP_MODE_INT
Definition: usb.h:236
void USBDMAChannelStatusClear(uint32_t ui32Base, uint32_t ui32Channel, uint32_t ui32Status)
Definition: usb.c:4722
void USBIntDisableEndpoint(uint32_t ui32Base, uint32_t ui32Flags)
Definition: usb.c:702
#define USB_INTEP_HOST_OUT
Definition: usb.h:118
#define USB_TXTYPE1_SPEED_FULL
Definition: hw_usb.h:1347
void USBDevMode(uint32_t ui32Base)
Definition: usb.c:4028
void USBHostPwrFaultDisable(uint32_t ui32Base)
Definition: usb.c:3696
#define USB_O_DMACOUNT0
Definition: hw_usb.h:327
#define USB_INTEP_DEV_OUT
Definition: usb.h:101
#define USB_EPC_EPEN_M
Definition: hw_usb.h:2853
#define USB_INTCTRL_MODE_DETECT
Definition: usb.h:73
#define INT_USB0_TM4C129
Definition: hw_ints.h:218
void USBDevLPMConfig(uint32_t ui32Base, uint32_t ui32Config)
Definition: usb.c:5429
uint32_t USBDMAChannelStatus(uint32_t ui32Base, uint32_t ui32Channel)
Definition: usb.c:4679
#define USB_PP_TYPE_M
Definition: hw_usb.h:3005
#define USB_DEV_RX_SENT_STALL
Definition: usb.h:202
#define USB_O_DMAADDR0
Definition: hw_usb.h:326
void USBHostLPMSend(uint32_t ui32Base, uint32_t ui32Address, uint32_t ui32Endpoint)
Definition: usb.c:5224
#define USB_INTCTRL_ALL
Definition: usb.h:61
uint32_t USBFrameNumberGet(uint32_t ui32Base)
Definition: usb.c:3777
void USBLPMIntEnable(uint32_t ui32Base, uint32_t ui32Ints)
Definition: usb.c:5822
#define USB_CSRH0_DISPING
Definition: hw_usb.h:1220
#define USB_UNDEF_SPEED
Definition: usb.h:159
void USBHostSuspend(uint32_t ui32Base)
Definition: usb.c:232
void USBFIFOFlush(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags)
Definition: usb.c:3144
int32_t USBEndpointDataGet(uint32_t ui32Base, uint32_t ui32Endpoint, uint8_t *pui8Data, uint32_t *pui32Size)
Definition: usb.c:2794
#define USB_TXCSRL1_STALL
Definition: hw_usb.h:1267
void USBEndpointPacketCountSet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Count)
Definition: usb.c:4192
#define USB_TXCSRL1_CLRDT
Definition: hw_usb.h:1265
#define USB_DEV_EP0_SETUP_END
Definition: usb.h:214
#define USB_O_PC
Definition: hw_usb.h:405
#define USB_INTEP_DEV_IN
Definition: usb.h:135
#define USB_EP_SPEED_FULL
Definition: usb.h:240
#define USB_DEV_RX_DATA_ERROR
Definition: usb.h:203
#define USB_HOST_PWREN_FILTER
Definition: usb.h:263
void USBDevConnect(uint32_t ui32Base)
Definition: usb.c:1499
#define USB_CSRL0_STALL
Definition: hw_usb.h:1206
#define USB_EP_5
Definition: usb.h:352
#define USB_O_RXFIFOSZ
Definition: hw_usb.h:70
void USBULPIRegWrite(uint32_t ui32Base, uint8_t ui8Reg, uint8_t ui8Data)
Definition: usb.c:5151
#define USB_DMACTL0_ERR
Definition: hw_usb.h:2355
#define USB_DEV_RX_OVERRUN
Definition: usb.h:204
#define USB_O_IS
Definition: hw_usb.h:54
void USBClockEnable(uint32_t ui32Base, uint32_t ui32Div, uint32_t ui32Flags)
Definition: usb.c:4310
void USBHostMode(uint32_t ui32Base)
Definition: usb.c:3997
#define USB_EP_AUTO_REQUEST
Definition: usb.h:227
#define USB_O_EPIDX
Definition: hw_usb.h:57
#define USB_RXTYPE1_SPEED_M
Definition: hw_usb.h:1377
#define HWREGH(x)
Definition: hw_types.h:50
#define USB_TXTYPE1_PROTO_ISOC
Definition: hw_usb.h:1351
#define USB_EP_HOST_OUT
Definition: usb.h:243
#define USB_DEV_TX_SENT_STALL
Definition: usb.h:210
#define USB_O_DMASEL
Definition: hw_usb.h:403
#define USB_O_TXTYPE1
Definition: hw_usb.h:184
#define USB_RXCSRH1_AUTORQ
Definition: hw_usb.h:1320
#define USB_O_NAKLMT
Definition: hw_usb.h:169
void USBHostPwrDisable(uint32_t ui32Base)
Definition: usb.c:3752
void USBDevLPMRemoteWake(uint32_t ui32Base)
Definition: usb.c:5371
void USBHostResume(uint32_t ui32Base, bool bStart)
Definition: usb.c:368
#define USB_O_LPMFADDR
Definition: hw_usb.h:375
#define USB_DEVCTL_LSDEV
Definition: hw_usb.h:618
#define USB_EPC_EPENDE
Definition: hw_usb.h:2852
void USBULPIEnable(uint32_t ui32Base)
Definition: usb.c:5026
void USBOTGMode(uint32_t ui32Base)
Definition: usb.c:4054
#define USB_FULL_SPEED
Definition: usb.h:161
#define USB_EP_MODE_CTRL
Definition: usb.h:237
void USBEndpointDataToggleClear(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags)
Definition: usb.c:1268
#define USB_EP_AUTO_SET
Definition: usb.h:226
#define USB_CSRH0_FLUSH
Definition: hw_usb.h:1223
#define USB_O_TXIE
Definition: hw_usb.h:52
#define USB_O_PP
Definition: hw_usb.h:404
#define USB_LPMATTR_ENDPT_S
Definition: hw_usb.h:2779
void USBHostPwrConfig(uint32_t ui32Base, uint32_t ui32Flags)
Definition: usb.c:3628
#define USB_LPMCNTRL_TXLPM
Definition: hw_usb.h:2805
uint32_t USBHostSpeedGet(uint32_t ui32Base)
Definition: usb.c:412
#define USB_O_DMAINTR
Definition: hw_usb.h:324
void USBHostEndpointPing(uint32_t ui32Base, uint32_t ui32Endpoint, bool bEnable)
Definition: usb.c:1328
void USBHighSpeed(uint32_t ui32Base, bool bEnable)
Definition: usb.c:318
#define USB_O_RXIS
Definition: hw_usb.h:51
#define USB_POWER_SOFTCONN
Definition: hw_usb.h:422
#define USB_O_ULPIREGDATA
Definition: hw_usb.h:74
#define USB_O_EPCIM
Definition: hw_usb.h:379
#define USB_RXCSRL1_STALLED
Definition: hw_usb.h:1303
uint32_t USBLPMIntStatus(uint32_t ui32Base)
Definition: usb.c:5749
#define USB_POWER_HSENAB
Definition: hw_usb.h:423
#define USB_O_FADDR
Definition: hw_usb.h:48
#define USB_O_TXHUBADDR0
Definition: hw_usb.h:89
#define USB_O_LPMATTR
Definition: hw_usb.h:371
#define USB_RXCSRH1_AUTOCL
Definition: hw_usb.h:1319
void USBEndpointDMADisable(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags)
Definition: usb.c:2687
#define CLASS_IS_TM4C123
Definition: hw_types.h:93
#define USB_ULPIREGCTL_REGCMPLT
Definition: hw_usb.h:726
#define USB_O_TXFUNCADDR0
Definition: hw_usb.h:87
void USBIntUnregister(uint32_t ui32Base)
Definition: usb.c:899
#define USB_O_CC
Definition: hw_usb.h:406
#define USB_O_RXIE
Definition: hw_usb.h:53
#define USB_TXCSRL1_STALLED
Definition: hw_usb.h:1266
bool USBLPMRemoteWakeEnabled(uint32_t ui32Base)
Definition: usb.c:5662
#define USB_TXCSRH1_DTWE
Definition: hw_usb.h:1286
#define MAX_NAK_LIMIT
Definition: usb.h:331
#define USB_O_IDVISC
Definition: hw_usb.h:401
#define USB_LPMCNTRL_RES
Definition: hw_usb.h:2804
#define USB_POWER_SUSPEND
Definition: hw_usb.h:427
void USBDevEndpointDataAck(uint32_t ui32Base, uint32_t ui32Endpoint, bool bIsLastPacket)
Definition: usb.c:2896
#define USB_POWER_PWRDNPHY
Definition: hw_usb.h:428
#define USB_EPINFO_TXEP_M
Definition: hw_usb.h:735
void USBClockDisable(uint32_t ui32Base)
Definition: usb.c:4346
#define USB_EPCIM_PF
Definition: hw_usb.h:2874
#define USB_TYPE0_SPEED_FULL
Definition: hw_usb.h:1240
uint32_t USBNumEndpointsGet(uint32_t ui32Base)
Definition: usb.c:4215
#define USB_EP_DMA_MODE_0
Definition: usb.h:229
void USBLPMIntDisable(uint32_t ui32Base, uint32_t ui32Ints)
Definition: usb.c:5894
#define USB_EP_6
Definition: usb.h:353
void USBDevEndpointStatusClear(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags)
Definition: usb.c:1089
void USBULPIConfig(uint32_t ui32Base, uint32_t ui32Config)
Definition: usb.c:4995
#define USB_CSRL0_STALLED
Definition: hw_usb.h:1211
#define USB_TXTYPE1_PROTO_INT
Definition: hw_usb.h:1353
#define USB_RXCSRL1_CLRDT
Definition: hw_usb.h:1302
#define USB_EPCISC_PF
Definition: hw_usb.h:2881
void USBDMAChannelEnable(uint32_t ui32Base, uint32_t ui32Channel)
Definition: usb.c:4512
#define USB_O_LPMRIS
Definition: hw_usb.h:374
#define USB_CSRL0_STATUS
Definition: hw_usb.h:1203
#define USB_EP_MODE_BULK
Definition: usb.h:235
void IntUnregister(uint32_t ui32Interrupt)
Definition: interrupt.c:381
#define USB_O_TXCSRL1
Definition: hw_usb.h:172
#define USB_EPC_PFLTAEN
Definition: hw_usb.h:2849
#define USB_TXTYPE1_SPEED_LOW
Definition: hw_usb.h:1348
void USBHostPwrFaultEnable(uint32_t ui32Base)
Definition: usb.c:3669
#define USB_O_ULPIREGCTL
Definition: hw_usb.h:76
#define USB_O_POWER
Definition: hw_usb.h:49
void USBHostEndpointSpeed(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags)
Definition: usb.c:1940
void USBDMAChannelCountSet(uint32_t ui32Base, uint32_t ui32Channel, uint32_t ui32Count)
Definition: usb.c:4861
#define USB_O_GPCS
Definition: hw_usb.h:388
uint32_t USBDMANumChannels(uint32_t ui32Base)
Definition: usb.c:4940
#define USB_RXCSRL1_STALL
Definition: hw_usb.h:1304
#define USB_O_EPC
Definition: hw_usb.h:376
uint8_t USBULPIRegRead(uint32_t ui32Base, uint8_t ui8Reg)
Definition: usb.c:5094
void USBFIFOConfigGet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t *pui32FIFOAddress, uint32_t *pui32FIFOSize, uint32_t ui32Flags)
Definition: usb.c:2456
uint32_t USBLPMEndpointGet(uint32_t ui32Base)
Definition: usb.c:5618
#define USBEPToIndex(x)
Definition: usb.h:364
#define USB_EP_3
Definition: usb.h:350
void USBDevEndpointConfigSet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32MaxPacketSize, uint32_t ui32Flags)
Definition: usb.c:2053
#define USB_CSRL0_SETENDC
Definition: hw_usb.h:1202
#define USB_DEVCTL_DEV
Definition: hw_usb.h:616
void USBDevEndpointConfigGet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t *pui32MaxPacketSize, uint32_t *pui32Flags)
Definition: usb.c:2213
#define USB_CSRH0_DT
Definition: hw_usb.h:1222
void USBIntEnableControl(uint32_t ui32Base, uint32_t ui32Flags)
Definition: usb.c:560
#define USB_EP_0
Definition: usb.h:347
uint32_t USBHostHubAddrGet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags)
Definition: usb.c:3539
void USBHostReset(uint32_t ui32Base, bool bStart)
Definition: usb.c:264
#define USB_TXCSRH1_AUTOSET
Definition: hw_usb.h:1280
#define USB_O_FIFO0
Definition: hw_usb.h:59
uint32_t USBIntStatusEndpoint(uint32_t ui32Base)
Definition: usb.c:783
#define USB_TXTYPE1_PROTO_BULK
Definition: hw_usb.h:1352
#define USB_EP_2
Definition: usb.h:349
void USBHostRequestIN(uint32_t ui32Base, uint32_t ui32Endpoint)
Definition: usb.c:3228
int32_t USBEndpointDataSend(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32TransType)
Definition: usb.c:3074
#define USB_TYPE0_SPEED_LOW
Definition: hw_usb.h:1241
void USBOTGSessionRequest(uint32_t ui32Base, bool bStart)
Definition: usb.c:3805
#define USB_O_TXMAXP1
Definition: hw_usb.h:170
#define USB_EP_1
Definition: usb.h:348
#define USB_TXCSRH1_DMAEN
Definition: hw_usb.h:1283
uint32_t USBLPMLinkStateGet(uint32_t ui32Base)
Definition: usb.c:5575
void USBDMAChannelIntDisable(uint32_t ui32Base, uint32_t ui32Channel)
Definition: usb.c:4437
#define USB_O_DEVCTL
Definition: hw_usb.h:67
#define UDMA_CHANNEL_USBEP3TX
Definition: udma.h:261
#define USB_O_TXINTERVAL1
Definition: hw_usb.h:186
uint32_t USBHostAddrGet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags)
Definition: usb.c:3413
#define USB_DEVCTL_HOST
Definition: hw_usb.h:624
#define USB_LPMCNTRL_EN_LPMEXT
Definition: hw_usb.h:2799
void USBHostLPMResume(uint32_t ui32Base)
Definition: usb.c:5333
#define USB_RXCSRL1_FLUSH
Definition: hw_usb.h:1306
#define USB_INTEP_HOST_IN
Definition: usb.h:84
void USBDevLPMDisable(uint32_t ui32Base)
Definition: usb.c:5517
#define USB_O_RAMINFO
Definition: hw_usb.h:78
void USBHostRequestINClear(uint32_t ui32Base, uint32_t ui32Endpoint)
Definition: usb.c:3278
#define USB_CSRL0_RXRDY
Definition: hw_usb.h:1213
#define CLASS_IS_TM4C129
Definition: hw_types.h:99
void USBHostLPMConfig(uint32_t ui32Base, uint32_t ui32ResumeTime, uint32_t ui32Config)
Definition: usb.c:5290
#define USB_EPC_PFLTACT_M
Definition: hw_usb.h:2844
#define USB_DMACTL0_ENABLE
Definition: hw_usb.h:2360
#define USB_DEVCTL_SESSION
Definition: hw_usb.h:626
uint32_t USBDevAddrGet(uint32_t ui32Base)
Definition: usb.c:1585
void USBHostHubAddrSet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Addr, uint32_t ui32Flags)
Definition: usb.c:3467
#define USB_ULPIREGCTL_REGACC
Definition: hw_usb.h:727
void USBULPIDisable(uint32_t ui32Base)
Definition: usb.c:5058
#define USB_IDVRIS_ID
Definition: hw_usb.h:2957
#define USB_DMACTL0_IE
Definition: hw_usb.h:2357
uint32_t USBControllerVersion(uint32_t ui32Base)
Definition: usb.c:4256
void USBDMAChannelConfigSet(uint32_t ui32Base, uint32_t ui32Channel, uint32_t ui32Endpoint, uint32_t ui32Config)
Definition: usb.c:4629
#define USB_RXCSRL1_REQPKT
Definition: hw_usb.h:1305
#define USB_RXCSRH1_ISO
Definition: hw_usb.h:1321
void USBIntRegister(uint32_t ui32Base, void(*pfnHandler)(void))
Definition: usb.c:859
#define USB_IDVIM_ID
Definition: hw_usb.h:2965
void USBDevEndpointStallClear(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags)
Definition: usb.c:1431
#define USB_O_COUNT0
Definition: hw_usb.h:166
#define USB_DEV_EP0_OUT_PKTRDY
Definition: usb.h:218
#define USB_TXCSRL1_FLUSH
Definition: hw_usb.h:1269
#define USB_EP_AUTO_CLEAR
Definition: usb.h:228
void USBDevDisconnect(uint32_t ui32Base)
Definition: usb.c:1528
#define HWREGB(x)
Definition: hw_types.h:52
#define USB_TXTYPE1_SPEED_HIGH
Definition: hw_usb.h:1346
#define USB_TXTYPE1_SPEED_M
Definition: hw_usb.h:1344
void USBFIFOConfigSet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32FIFOAddress, uint32_t ui32FIFOSize, uint32_t ui32Flags)
Definition: usb.c:2393
void USBDevAddrSet(uint32_t ui32Base, uint32_t ui32Address)
Definition: usb.c:1557
#define USB_O_RXMAXP1
Definition: hw_usb.h:176
#define USB_EP_SPEED_HIGH
Definition: usb.h:241
#define EP_OFFSET(Endpoint)
Definition: usb.c:82
void IntDisable(uint32_t ui32Interrupt)
Definition: interrupt.c:684
#define USB_O_LPMIM
Definition: hw_usb.h:373
void IntRegister(uint32_t ui32Interrupt, void(*pfnHandler)(void))
Definition: interrupt.c:309
#define INT_USB0_TM4C123
Definition: hw_ints.h:107
#define USB_O_ULPIVBUSCTL
Definition: hw_usb.h:73
uint32_t USBIntStatusControl(uint32_t ui32Base)
Definition: usb.c:635
void IntEnable(uint32_t ui32Interrupt)
Definition: interrupt.c:610
#define USB_TXCSRL1_TXRDY
Definition: hw_usb.h:1273
#define USB0_BASE
Definition: hw_memmap.h:99
void USBHostEndpointConfig(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32MaxPayload, uint32_t ui32NAKPollInterval, uint32_t ui32TargetEndpoint, uint32_t ui32Flags)
Definition: usb.c:1680
void USBEndpointDMAConfigSet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Config)
Definition: usb.c:2574
void USBPHYPowerOff(uint32_t ui32Base)
Definition: usb.c:4141
#define USB_O_CSRL0
Definition: hw_usb.h:162
#define USB_O_TXFIFOSZ
Definition: hw_usb.h:69
#define USB_EP_7
Definition: usb.h:354
uint32_t USBDMAChannelIntStatus(uint32_t ui32Base)
Definition: usb.c:4477