USBLibAPIGuide  1.00.00.01
usbdcdc.h
Go to the documentation of this file.
1 //*****************************************************************************
2 //
3 // usbdcdc.h - USBLib support for generic CDC ACM (serial) device.
4 //
5 // Copyright (c) 2008-2017 Texas Instruments Incorporated. All rights reserved.
6 // Software License Agreement
7 //
8 // Texas Instruments (TI) is supplying this software for use solely and
9 // exclusively on TI's microcontroller products. The software is owned by
10 // TI and/or its suppliers, and is protected under applicable copyright
11 // laws. You may not combine this software with "viral" open-source
12 // software in order to form a larger program.
13 //
14 // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
15 // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
16 // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
18 // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
19 // DAMAGES, FOR ANY REASON WHATSOEVER.
20 //
21 //
22 //*****************************************************************************
23 
24 #ifndef __USBDCDC_H__
25 #define __USBDCDC_H__
26 
27 //*****************************************************************************
28 //
29 // If building with a C++ compiler, make all of the definitions in this header
30 // have a C binding.
31 //
32 //*****************************************************************************
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #endif
37 
38 //*****************************************************************************
39 //
42 //
43 //*****************************************************************************
44 
45 //*****************************************************************************
46 //
47 // PRIVATE
48 //
49 // The first few sections of this header are private defines that are used by
50 // the USB CDC Serial code and are here only to help with the application
51 // allocating the correct amount of memory for the CDC Serial device code.
52 //
53 //*****************************************************************************
54 
55 //*****************************************************************************
56 //
57 // PRIVATE
58 //
59 // This enumeration holds the various states that the device can be in during
60 // normal operation.
61 //
62 //*****************************************************************************
63 typedef enum
64 {
65  //
66  // Unconfigured.
67  //
69 
70  //
71  // No outstanding transaction remains to be completed.
72  //
74 
75  //
76  // Waiting on completion of a send or receive transaction.
77  //
79 
80  //
81  // Waiting for client to process data.
82  //
84 }
85 tCDCState;
86 
87 //*****************************************************************************
88 //
89 // PRIVATE
90 //
91 // This structure defines the private instance data and state variables for the
92 // CDC Serial device. The memory for this structure is allocated in the
93 // tUSBDCDCDevice structure passed on USBDCDCInit().
94 //
95 //*****************************************************************************
96 typedef struct
97 {
98  //
99  // Base address for the USB controller.
100  //
101  uint32_t ui32USBBase;
102 
103  //
104  // The device info to interact with the lower level DCD code.
105  //
107 
108  //
109  // The state of the serial receive state.
110  //
111  volatile tCDCState iCDCRxState;
112 
113  //
114  // The state of the serial transmit state.
115  //
116  volatile tCDCState iCDCTxState;
117 
118  //
119  // The state of the serial request state.
120  //
121  volatile tCDCState iCDCRequestState;
122 
123  //
124  // The state of the serial interrupt state.
125  //
126  volatile tCDCState iCDCInterruptState;
127 
128  //
129  // The current pending request.
130  //
131  volatile uint8_t ui8PendingRequest;
132 
133  //
134  // The current break duration used during send break requests.
135  //
137 
138  //
139  // The current line control state for the serial port.
140  //
142 
143  //
144  // The general serial state.
145  //
146  uint16_t ui16SerialState;
147 
148  //
149  // State of any pending operations that could not be handled immediately
150  // upon receipt.
151  //
152  volatile uint16_t ui16DeferredOpFlags;
153 
154  //
155  // Size of the last transmit.
156  //
157  uint16_t ui16LastTxSize;
158 
159  //
160  // The current serial line coding.
161  //
162  tLineCoding sLineCoding;
163 
164  //
165  // Serial port receive is blocked.
166  //
167  volatile bool bRxBlocked;
168 
169  //
170  // Serial control port is blocked.
171  //
172  volatile bool bControlBlocked;
173 
174  //
175  // The connection status of the device.
176  //
177  volatile bool bConnected;
178 
179  //
180  // The control endpoint number, this is modified in composite devices.
181  //
183 
184  //
185  // The IN endpoint number, this is modified in composite devices.
186  //
188 
189  //
190  // The OUT endpoint number, this is modified in composite devices.
191  //
193 
194  //
195  // The interface number for the control interface, this is modified in
196  // composite devices.
197  //
199 
200  //
201  // The interface number for the data interface, this is modified in
202  // composite devices.
203  //
205 }
207 
208 //*****************************************************************************
209 //
210 // The following defines are used when working with composite devices.
211 //
212 //*****************************************************************************
213 
214 //*****************************************************************************
215 //
216 // This is the size of the g_pui8IADSerDescriptor array in bytes.
217 //
218 //*****************************************************************************
219 #define SERDESCRIPTOR_SIZE (8)
220 
221 //*****************************************************************************
222 //
223 // This is the size of the g_pui8CDCSerCommInterface array in bytes.
224 //
225 //*****************************************************************************
226 #define SERCOMMINTERFACE_SIZE (35)
227 
228 //*****************************************************************************
229 //
230 // This is the size of the g_pui8CDCSerDataInterface array in bytes.
231 //
232 //*****************************************************************************
233 #define SERDATAINTERFACE_SIZE (23)
234 
235 //*****************************************************************************
236 //
241 //
242 //*****************************************************************************
243 #define COMPOSITE_DCDC_SIZE (SERDESCRIPTOR_SIZE + SERCOMMINTERFACE_SIZE + \
244  SERDATAINTERFACE_SIZE)
245 
246 //*****************************************************************************
247 //
248 // CDC-specific events These events are provided to the application in the
249 // \e ui32Msg parameter of the tUSBCallback function.
250 //
251 //*****************************************************************************
252 
253 //
257 //
258 #define USBD_CDC_EVENT_SEND_BREAK (USBD_CDC_EVENT_BASE + 0)
259 
260 //
263 //
264 #define USBD_CDC_EVENT_CLEAR_BREAK (USBD_CDC_EVENT_BASE + 1)
265 
266 //
274 //
275 #define USBD_CDC_EVENT_SET_CONTROL_LINE_STATE (USBD_CDC_EVENT_BASE + 2)
276 
277 //
282 //
283 #define USBD_CDC_EVENT_SET_LINE_CODING (USBD_CDC_EVENT_BASE + 3)
284 
285 //
290 //
291 #define USBD_CDC_EVENT_GET_LINE_CODING (USBD_CDC_EVENT_BASE + 4)
292 
293 //*****************************************************************************
294 //
297 //
298 //*****************************************************************************
299 typedef struct
300 {
301  //
303  //
304  const uint16_t ui16VID;
305 
306  //
308  //
309  const uint16_t ui16PID;
310 
311  //
313  //
314  const uint16_t ui16MaxPowermA;
315 
316  //
320  //
321  const uint8_t ui8PwrAttributes;
322 
323  //
327  //
329 
330  //
334  //
336 
337  //
340  //
342 
343  //
347  //
348  void *pvRxCBData;
349 
350  //
354  //
356 
357  //
361  //
362  void *pvTxCBData;
363 
364  //
375  //
376  const uint8_t * const *ppui8StringDescriptors;
377 
378  //
381  //
382  const uint32_t ui32NumStringDescriptors;
383 
384  //
388  //
390 }
392 
393 //*****************************************************************************
394 //
395 // API Function Prototypes
396 //
397 //*****************************************************************************
398 extern void *USBDCDCCompositeInit(uint32_t ui32Index,
399  tUSBDCDCDevice *psCDCDevice,
400  tCompositeEntry *psCompEntry);
401 extern void *USBDCDCInit(uint32_t ui32Index,
402  tUSBDCDCDevice *psCDCDevice);
403 extern void USBDCDCTerm(void *pvCDCDevice);
404 extern void *USBDCDCSetControlCBData(void *pvCDCDevice, void *pvCBData);
405 extern void *USBDCDCSetRxCBData(void *pvCDCDevice, void *pvCBData);
406 extern void *USBDCDCSetTxCBData(void *pvCDCDevice, void *pvCBData);
407 extern uint32_t USBDCDCPacketWrite(void *pvCDCDevice, uint8_t *pi8Data,
408  uint32_t ui32Length, bool bLast);
409 extern uint32_t USBDCDCPacketRead(void *pvCDCDevice, uint8_t *pi8Data,
410  uint32_t ui32Length, bool bLast);
411 extern uint32_t USBDCDCTxPacketAvailable(void *pvCDCDevice);
412 extern uint32_t USBDCDCRxPacketAvailable(void *pvCDCDevice);
413 extern void USBDCDCSerialStateChange(void *pvCDCDevice, uint16_t ui16State);
414 extern bool USBDCDCRemoteWakeupRequest(void *pvCDCDevice);
415 
416 //*****************************************************************************
417 //
418 // Close the Doxygen group.
420 //
421 //*****************************************************************************
422 
423 //*****************************************************************************
424 //
425 // The following APIs are deprecated.
426 //
427 //*****************************************************************************
428 #ifndef DEPRECATED
429 
430 //
431 // Use USBDCDFeatureSet() or USBHCDFeatureSet() with \b USBLIB_FEATURE_POWER
432 // configuration option.
433 //
434 extern void USBDCDCPowerStatusSet(void *pvCDCDevice, uint8_t ui8Power);
435 #endif
436 
437 //*****************************************************************************
438 //
439 // Mark the end of the C bindings section for C++ compilers.
440 //
441 //*****************************************************************************
442 #ifdef __cplusplus
443 }
444 #endif
445 
446 #endif // __USBDCDC_H__
volatile bool bRxBlocked
Definition: usbdcdc.h:167
void * USBDCDCSetTxCBData(void *pvCDCDevice, void *pvCBData)
Definition: usbdcdc.c:2632
const uint16_t ui16PID
The product ID that this device is to present in the device descriptor.
Definition: usbdcdc.h:309
void * USBDCDCSetControlCBData(void *pvCDCDevice, void *pvCBData)
Definition: usbdcdc.c:2536
tDeviceInfo sDevInfo
Definition: usbdcdc.h:106
void * USBDCDCSetRxCBData(void *pvCDCDevice, void *pvCBData)
Definition: usbdcdc.c:2584
volatile uint8_t ui8PendingRequest
Definition: usbdcdc.h:131
uint8_t ui8BulkINEndpoint
Definition: usbdcdc.h:187
Definition: usbdcdc.h:83
uint16_t ui16ControlLineState
Definition: usbdcdc.h:141
tLineCoding sLineCoding
Definition: usbdcdc.h:162
Definition: usbdcdc.h:96
uint32_t USBDCDCPacketRead(void *pvCDCDevice, uint8_t *pi8Data, uint32_t ui32Length, bool bLast)
Definition: usbdcdc.c:2792
volatile tCDCState iCDCRxState
Definition: usbdcdc.h:111
Definition: usbdcdc.h:73
uint32_t ui32USBBase
Definition: usbdcdc.h:101
const uint16_t ui16MaxPowermA
The maximum power consumption of the device, expressed in milliamps.
Definition: usbdcdc.h:314
Definition: usbdevice.h:135
uint32_t USBDCDCRxPacketAvailable(void *pvCDCDevice)
Definition: usbdcdc.c:2953
const tUSBCallback pfnControlCallback
Definition: usbdcdc.h:328
const uint8_t ui8PwrAttributes
Definition: usbdcdc.h:321
bool USBDCDCRemoteWakeupRequest(void *pvCDCDevice)
Definition: usbdcdc.c:3135
tCDCSerInstance sPrivateData
Definition: usbdcdc.h:389
volatile bool bConnected
Definition: usbdcdc.h:177
uint16_t ui16SerialState
Definition: usbdcdc.h:146
const uint32_t ui32NumStringDescriptors
Definition: usbdcdc.h:382
const uint16_t ui16VID
The vendor ID that this device is to present in the device descriptor.
Definition: usbdcdc.h:304
void USBDCDCSerialStateChange(void *pvCDCDevice, uint16_t ui16State)
Definition: usbdcdc.c:3030
uint32_t USBDCDCPacketWrite(void *pvCDCDevice, uint8_t *pi8Data, uint32_t ui32Length, bool bLast)
Definition: usbdcdc.c:2690
Definition: usbdcdc.h:68
volatile tCDCState iCDCTxState
Definition: usbdcdc.h:116
uint8_t ui8BulkOUTEndpoint
Definition: usbdcdc.h:192
const tUSBCallback pfnRxCallback
Definition: usbdcdc.h:341
void USBDCDCPowerStatusSet(void *pvCDCDevice, uint8_t ui8Power)
Definition: usbdcdc.c:3104
Definition: usbdevice.h:66
uint32_t(* tUSBCallback)(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgParam, void *pvMsgData)
Definition: usblib.h:1220
uint16_t ui16LastTxSize
Definition: usbdcdc.h:157
uint8_t ui8ControlEndpoint
Definition: usbdcdc.h:182
Definition: usbdcdc.h:78
volatile tCDCState iCDCInterruptState
Definition: usbdcdc.h:126
void * pvRxCBData
Definition: usbdcdc.h:348
const uint8_t *const * ppui8StringDescriptors
Definition: usbdcdc.h:376
volatile uint16_t ui16DeferredOpFlags
Definition: usbdcdc.h:152
uint16_t ui16BreakDuration
Definition: usbdcdc.h:136
volatile bool bControlBlocked
Definition: usbdcdc.h:172
const tUSBCallback pfnTxCallback
Definition: usbdcdc.h:355
void USBDCDCTerm(void *pvCDCDevice)
Definition: usbdcdc.c:2492
uint8_t ui8InterfaceControl
Definition: usbdcdc.h:198
uint8_t ui8InterfaceData
Definition: usbdcdc.h:204
void * pvControlCBData
Definition: usbdcdc.h:335
tCDCState
Definition: usbdcdc.h:63
volatile tCDCState iCDCRequestState
Definition: usbdcdc.h:121
uint32_t USBDCDCTxPacketAvailable(void *pvCDCDevice)
Definition: usbdcdc.c:2905
void * USBDCDCCompositeInit(uint32_t ui32Index, tUSBDCDCDevice *psCDCDevice, tCompositeEntry *psCompEntry)
Definition: usbdcdc.c:2236
Definition: usbdcdc.h:299
void * USBDCDCInit(uint32_t ui32Index, tUSBDCDCDevice *psCDCDevice)
Definition: usbdcdc.c:2417
void * pvTxCBData
Definition: usbdcdc.h:362
© Copyright 1995-2020, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale