USBLibAPIGuide  1.00.00.01
usblibpriv.h
Go to the documentation of this file.
1 //*****************************************************************************
2 //
3 // usblibpriv.h - Private header file used to share internal variables and
4 // function prototypes between the various modules in the USB
5 // library. This header MUST NOT be used by application code.
6 //
7 // Copyright (c) 2008-2017 Texas Instruments Incorporated. All rights reserved.
8 // Software License Agreement
9 //
10 // Texas Instruments (TI) is supplying this software for use solely and
11 // exclusively on TI's microcontroller products. The software is owned by
12 // TI and/or its suppliers, and is protected under applicable copyright
13 // laws. You may not combine this software with "viral" open-source
14 // software in order to form a larger program.
15 //
16 // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
17 // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
18 // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
20 // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
21 // DAMAGES, FOR ANY REASON WHATSOEVER.
22 //
23 //*****************************************************************************
24 
25 #ifndef __USBLIBPRIV_H__
26 #define __USBLIBPRIV_H__
27 
28 //*****************************************************************************
29 //
30 // If building with a C++ compiler, make all of the definitions in this header
31 // have a C binding.
32 //
33 //*****************************************************************************
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #endif
38 
39 //*****************************************************************************
40 //
43 //
44 //*****************************************************************************
45 
46 //*****************************************************************************
47 //
48 // Internal interrupt handlers called from the main vectors in device and
49 // host mode.
50 //
51 //*****************************************************************************
52 extern void USBDeviceIntHandlerInternal(uint32_t ui32Index,
53  uint32_t ui32Status);
54 extern void USBHostIntHandlerInternal(uint32_t ui32Index, uint32_t ui32Status);
55 
56 //*****************************************************************************
57 //
58 // The maximum number of tick handlers that can be registered in a system.
59 //
60 //*****************************************************************************
61 #define MAX_USB_TICK_HANDLERS 6
62 
63 //*****************************************************************************
64 //
65 // This value defines the number of SOF ticks that must pass before a call
66 // is made to InternalUSBStartOfFrameTick. The value 5 ensures that the
67 // function is called every 5 milliseconds assuming that SOF interrupts are
68 // enabled and SOF is present.
69 //
70 //*****************************************************************************
71 #define USB_SOF_TICK_DIVIDE 5
72 
73 //*****************************************************************************
74 //
75 // Tick handler function pointer type.
76 //
77 //*****************************************************************************
78 typedef void(* tUSBTickHandler)(void *pvInstance, uint32_t ui32TicksmS);
79 
80 //*****************************************************************************
81 //
82 // Internal functions use to initialize the tick handler and register tick
83 // callbacks.
84 //
85 //*****************************************************************************
86 extern void InternalUSBTickInit(void);
87 extern void InternalUSBTickReset(void);
88 extern int32_t InternalUSBRegisterTickHandler(tUSBTickHandler pfnHandler,
89  void *pvInstance);
90 extern void InternalUSBStartOfFrameTick(uint32_t ui32TicksmS);
91 extern void InternalUSBHCDSendEvent(uint32_t ui32Index, tEventInfo *psEvent,
92  uint32_t ui32EvFlag);
93 
94 //*****************************************************************************
95 //
96 // g_ui32CurrentUSBTick holds the elapsed time in milliseconds since the
97 // tick module was first initialized based on calls to the function
98 // InternalUSBStartOfFrameTick. The granularity is USB_SOF_TICK_DIVIDE
99 // milliseconds.
100 //
101 //*****************************************************************************
102 extern uint32_t g_ui32CurrentUSBTick;
103 
104 //*****************************************************************************
105 //
106 // g_ui32USBSOFCount is a global counter for Start of Frame interrupts. It is
107 // incremented by the low level device- or host-mode interrupt handlers.
108 //
109 //*****************************************************************************
110 extern uint32_t g_ui32USBSOFCount;
111 
112 //*****************************************************************************
113 //
114 // InternalUSBGetTime is a macro which will return the system time in
115 // milliseconds as calculated based on calls to the function
116 // InternalUSBStartOfFrameTick. The granularity is USB_SOF_TICK_DIVIDE
117 // milliseconds.
118 //
119 // Currently, this merely returns the value of a global variable.
120 //
121 //*****************************************************************************
122 #define InternalUSBGetTime() g_ui32CurrentUSBTick
123 
124 //*****************************************************************************
125 //
126 // Macros to convert between USB controller base address and an index. These
127 // are currently trivial but are included to allow for the possibility of
128 // supporting more than one controller in the future.
129 //
130 //*****************************************************************************
131 #define USBBaseToIndex(BaseAddr)(0)
132 #define USBIndexToBase(Index) (USB0_BASE)
133 
134 //
135 // Maximum number of channels for Type 0 USB controllers.
136 //
137 #define USB_MAX_DMA_CHANNELS_0 6
138 
139 //
140 // Maximum number of channels for all other USB controllers.
141 //
142 #define USB_MAX_DMA_CHANNELS 8
143 
144 //*****************************************************************************
145 //
146 // Values returned by the USBLibDMAChannelStatus() function.
147 //
148 //*****************************************************************************
149 #define USBLIBSTATUS_DMA_IDLE 0x00000000
150 #define USBLIBSTATUS_DMA_COMPLETE \
151  0x00000001
152 #define USBLIBSTATUS_DMA_ERROR 0x00000002
153 #define USBLIBSTATUS_DMA_PENDING \
154  0x00000004
155 
156 //*****************************************************************************
157 //
158 // DMA endpoint types used with the USBLibDMAChannelAllocate() function.
159 //
160 //*****************************************************************************
161 #define USB_DMA_EP_RX 0x00000080
162 #define USB_DMA_EP_TX 0x00000000
163 #define USB_DMA_EP_HOST 0x00000040
164 #define USB_DMA_EP_DEVICE 0x00000000
165 #define USB_DMA_EP_TYPE_CTRL 0x00000000
166 #define USB_DMA_EP_TYPE_ISOC 0x00000001
167 #define USB_DMA_EP_TYPE_BULK 0x00000002
168 #define USB_DMA_EP_TYPE_INT 0x00000003
169 #define USB_DMA_EP_TYPE_M 0x00000003
170 
171 //*****************************************************************************
172 //
173 // This is the internal instance data for the DMA functions and should not
174 // be modified outside the usbdma.c file.
175 //
176 //*****************************************************************************
178 {
179  uint32_t ui32Base;
180 
181  uint32_t ui32IntNum;
182 
184 
186 
188 
190 
192 
194 
196 
197  uint32_t ui32Pending;
198 
199  uint32_t ui32Complete;
200 
201  void (* pfnArbSizeSet)(tUSBDMAInstance *psUSBDMAInst, uint32_t ui32Channel,
202  uint32_t ui32ArbSize);
203  uint32_t (* pfnChannelAllocate)(tUSBDMAInstance *psUSBDMAInst,
204  uint8_t ui8Endpoint,
205  uint32_t ui32MaxPacketSize,
206  uint32_t ui32Config);
207  void (* pfnChannelEnable)(tUSBDMAInstance *psUSBDMAInst,
208  uint32_t ui32Channel);
209  void (* pfnChannelDisable)(tUSBDMAInstance *psUSBDMAInst,
210  uint32_t ui32Channel);
211  void (* pfnChannelRelease)(tUSBDMAInstance *psUSBDMAInst,
212  uint8_t ui8Endpoint);
213  uint32_t (* pfnChannelStatus)(tUSBDMAInstance *psUSBDMAInst,
214  uint32_t ui32Channel);
215  void (* pfnChannelIntDisable)(tUSBDMAInstance *psUSBDMAInst,
216  uint32_t ui32Channel);
217  void (* pfnChannelIntEnable)(tUSBDMAInstance *psUSBDMAInst,
218  uint32_t ui32Channel);
219  void (* pfnIntHandler)(tUSBDMAInstance *psUSBDMAInst,
220  uint32_t ui32Status);
221  uint32_t (* pfnIntStatus)(tUSBDMAInstance *psUSBDMAInst);
222  void (* pfnIntStatusClear)(tUSBDMAInstance *psUSBDMAInst,
223  uint32_t ui32Status);
224  uint32_t (* pfnStatus)(tUSBDMAInstance *psUSBDMAInst);
225  uint32_t (* pfnTransfer)(tUSBDMAInstance *psUSBDMAInst,
226  uint32_t ui32Channel, void *pvBuffer,
227  uint32_t ui32Size);
228  void (* pfnUnitSizeSet)(tUSBDMAInstance *psUSBDMAInst,
229  uint32_t ui32Channel,
230  uint32_t ui32BitSize);
231 };
232 
233 //*****************************************************************************
234 //
235 // These are the USB libraries DMA functions.
236 //
237 //*****************************************************************************
238 extern tUSBDMAInstance * USBLibDMAInit(uint32_t ui32Index);
239 extern void * USBLibDMAAddrGet(tUSBDMAInstance *psUSBDMAInst,
240  uint32_t ui32Channel);
241 extern uint32_t USBLibDMASizeGet(tUSBDMAInstance *psUSBDMAInst,
242  uint32_t ui32Channel);
243 
244 //*****************************************************************************
245 //
256 //
257 //*****************************************************************************
258 #define USBLibDMAChannelStatus(psUSBDMAInst, ui32Channel) \
259  psUSBDMAInst->pfnChannelStatus(psUSBDMAInst, ui32Channel)
260 
261 //*****************************************************************************
262 //
272 //
273 //*****************************************************************************
274 #define USBLibDMAStatus(psUSBDMAInst) psUSBDMAInst->pfnStatus(psUSBDMAInst)
275 
276 //*****************************************************************************
277 //
290 //
291 //*****************************************************************************
292 #define USBLibDMAIntStatus(psUSBDMAInst) \
293  psUSBDMAInst->pfnIntStatus(psUSBDMAInst)
294 
295 //*****************************************************************************
296 //
310 //
311 //*****************************************************************************
312 #define USBLibDMAIntStatusClear(psUSBDMAInst, ui32Status) \
313  psUSBDMAInst->pfnIntStatusClear(psUSBDMAInst, ui32Status)
314 
315 //*****************************************************************************
316 //
326 //
327 //*****************************************************************************
328 #define USBLibDMAChannelEnable(psUSBDMAInst, ui32Channel) \
329  psUSBDMAInst->pfnChannelEnable(psUSBDMAInst, ui32Channel)
330 
331 //*****************************************************************************
332 //
342 //
343 //*****************************************************************************
344 #define USBLibDMAChannelDisable(psUSBDMAInst, ui32Channel) \
345  psUSBDMAInst->pfnChannelDisable(psUSBDMAInst, ui32Channel)
346 
347 //*****************************************************************************
348 //
365 //
366 //*****************************************************************************
367 #define USBLibDMATransfer(psUSBDMAInst, ui32Channel, pvBuffer, ui32Size) \
368  psUSBDMAInst->pfnTransfer(psUSBDMAInst, ui32Channel, \
369  pvBuffer, ui32Size)
370 
371 //*****************************************************************************
372 //
386 //
387 //*****************************************************************************
388 #define USBLibDMAIntHandler(psUSBDMAInst, ui32Status) \
389  psUSBDMAInst->pfnIntHandler(psUSBDMAInst, ui32Status)
390 
391 //*****************************************************************************
392 //
412 //
413 //*****************************************************************************
414 #define USBLibDMAChannelAllocate(psUSBDMAInst, ui8Endpoint, ui32MaxPacketSize,\
415  ui32Config) \
416  psUSBDMAInst->pfnChannelAllocate(psUSBDMAInst, \
417  ui8Endpoint, \
418  ui32MaxPacketSize, \
419  ui32Config)
420 
421 //*****************************************************************************
422 //
433 //
434 //*****************************************************************************
435 #define USBLibDMAChannelRelease(psUSBDMAInst, ui8Endpoint) \
436  psUSBDMAInst->pfnChannelRelease(psUSBDMAInst, ui8Endpoint)
437 
438 //*****************************************************************************
439 //
453 //
454 //*****************************************************************************
455 #define USBLibDMAUnitSizeSet(psUSBDMAInst, ui32Channel, ui32BitSize) \
456  psUSBDMAInst->pfnUnitSizeSet(psUSBDMAInst, ui32Channel, \
457  ui32BitSize);
458 
459 //*****************************************************************************
460 //
473 //
474 //*****************************************************************************
475 #define USBLibDMAArbSizeSet(psUSBDMAInst, ui32Channel, ui32ArbSize) \
476  psUSBDMAInst->pfnArbSizeSet(psUSBDMAInst, ui32Channel, \
477  ui32ArbSize);
478 
479 //*****************************************************************************
480 //
490 //
491 //*****************************************************************************
492 #define USBLibDMAChannelIntEnable(psUSBDMAInst, ui32Channel) \
493  psUSBDMAInst->pfnChannelIntEnable(psUSBDMAInst, ui32Channel)
494 
495 //*****************************************************************************
496 //
506 //
507 //*****************************************************************************
508 #define USBLibDMAChannelIntDisable(psUSBDMAInst, ui32Channel) \
509  psUSBDMAInst->pfnChannelIntDisable(psUSBDMAInst, ui32Channel)
510 
511 //*****************************************************************************
512 //
513 // Mark the end of the C bindings section for C++ compilers.
514 //
515 //*****************************************************************************
516 #ifdef __cplusplus
517 }
518 #endif
519 
520 //*****************************************************************************
521 //
522 // Close the Doxygen group.
524 //
525 //*****************************************************************************
526 
527 #endif // __USBLIBPRIV_H__
void InternalUSBStartOfFrameTick(uint32_t ui32TicksmS)
Definition: usbtick.c:191
#define USB_MAX_DMA_CHANNELS
Definition: usblibpriv.h:142
void(* pfnIntStatusClear)(tUSBDMAInstance *psUSBDMAInst, uint32_t ui32Status)
Definition: usblibpriv.h:222
uint32_t(* pfnStatus)(tUSBDMAInstance *psUSBDMAInst)
Definition: usblibpriv.h:224
void USBHostIntHandlerInternal(uint32_t ui32Index, uint32_t ui32Status)
Definition: usbhostenum.c:3797
uint32_t g_ui32CurrentUSBTick
Definition: usbtick.c:60
uint32_t pui32Count[USB_MAX_DMA_CHANNELS]
Definition: usblibpriv.h:189
int32_t InternalUSBRegisterTickHandler(tUSBTickHandler pfnHandler, void *pvInstance)
Definition: usbtick.c:142
uint32_t(* pfnTransfer)(tUSBDMAInstance *psUSBDMAInst, uint32_t ui32Channel, void *pvBuffer, uint32_t ui32Size)
Definition: usblibpriv.h:225
uint32_t(* pfnIntStatus)(tUSBDMAInstance *psUSBDMAInst)
Definition: usblibpriv.h:221
void(* pfnChannelRelease)(tUSBDMAInstance *psUSBDMAInst, uint8_t ui8Endpoint)
Definition: usblibpriv.h:211
void InternalUSBHCDSendEvent(uint32_t ui32Index, tEventInfo *psEvent, uint32_t ui32EvFlag)
Definition: usbhostenum.c:4564
uint32_t * ppui32Data[USB_MAX_DMA_CHANNELS]
Definition: usblibpriv.h:187
void(* pfnChannelIntDisable)(tUSBDMAInstance *psUSBDMAInst, uint32_t ui32Channel)
Definition: usblibpriv.h:215
uint32_t ui32Base
Definition: usblibpriv.h:179
void(* pfnUnitSizeSet)(tUSBDMAInstance *psUSBDMAInst, uint32_t ui32Channel, uint32_t ui32BitSize)
Definition: usblibpriv.h:228
uint32_t ui32IntNum
Definition: usblibpriv.h:181
void(* pfnIntHandler)(tUSBDMAInstance *psUSBDMAInst, uint32_t ui32Status)
Definition: usblibpriv.h:219
uint32_t g_ui32USBSOFCount
Definition: usbtick.c:69
uint32_t ui32Complete
Definition: usblibpriv.h:199
uint32_t pui32EPDMAMode0[USB_MAX_DMA_CHANNELS]
Definition: usblibpriv.h:193
void USBDeviceIntHandlerInternal(uint32_t ui32Index, uint32_t ui32Status)
Definition: usbdenum.c:3005
void(* tUSBTickHandler)(void *pvInstance, uint32_t ui32TicksmS)
Definition: usblibpriv.h:78
void(* pfnChannelDisable)(tUSBDMAInstance *psUSBDMAInst, uint32_t ui32Channel)
Definition: usblibpriv.h:209
uint32_t ui32Pending
Definition: usblibpriv.h:197
void * USBLibDMAAddrGet(tUSBDMAInstance *psUSBDMAInst, uint32_t ui32Channel)
Definition: usbdma.c:661
uint32_t pui32MaxPacketSize[USB_MAX_DMA_CHANNELS]
Definition: usblibpriv.h:185
void InternalUSBTickInit(void)
Definition: usbtick.c:84
void(* pfnChannelEnable)(tUSBDMAInstance *psUSBDMAInst, uint32_t ui32Channel)
Definition: usblibpriv.h:207
Definition: usblibpriv.h:177
uint32_t(* pfnChannelStatus)(tUSBDMAInstance *psUSBDMAInst, uint32_t ui32Channel)
Definition: usblibpriv.h:213
void(* pfnArbSizeSet)(tUSBDMAInstance *psUSBDMAInst, uint32_t ui32Channel, uint32_t ui32ArbSize)
Definition: usblibpriv.h:201
void(* pfnChannelIntEnable)(tUSBDMAInstance *psUSBDMAInst, uint32_t ui32Channel)
Definition: usblibpriv.h:217
tUSBDMAInstance * USBLibDMAInit(uint32_t ui32Index)
Definition: usbdma.c:704
uint8_t pui8Endpoint[USB_MAX_DMA_CHANNELS]
Definition: usblibpriv.h:191
void InternalUSBTickReset(void)
Definition: usbtick.c:112
uint32_t pui32EPDMAMode1[USB_MAX_DMA_CHANNELS]
Definition: usblibpriv.h:195
Definition: usblib.h:1340
uint32_t(* pfnChannelAllocate)(tUSBDMAInstance *psUSBDMAInst, uint8_t ui8Endpoint, uint32_t ui32MaxPacketSize, uint32_t ui32Config)
Definition: usblibpriv.h:203
uint32_t pui32Config[USB_MAX_DMA_CHANNELS]
Definition: usblibpriv.h:183
uint32_t USBLibDMASizeGet(tUSBDMAInstance *psUSBDMAInst, uint32_t ui32Channel)
Definition: usbdma.c:682
© Copyright 1995-2020, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale