1 //*****************************************************************************
2 //
3 // usbdcdc.h - USBLib support for generic CDC ACM (serial) device.
4 //
5 // Copyright (c) 2008-2010 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 //
40 //! \addtogroup cdc_device_class_api
41 //! @{
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     //
68     CDC_STATE_UNCONFIGURED,
69 
70     //
71     // No outstanding transaction remains to be completed.
72     //
73     CDC_STATE_IDLE,
74 
75     //
76     // Waiting on completion of a send or receive transaction.
77     //
78     CDC_STATE_WAIT_DATA,
79 
80     //
81     // Waiting for client to process data.
82     //
83     CDC_STATE_WAIT_CLIENT
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 pointed to by the
93 // psPrivateCDCSerData field in the tUSBDCDCDevice structure passed on
94 // USBDCDCInit().
95 //
96 //*****************************************************************************
97 typedef struct
98 {
99     uint32 ulUSBBase;
100     tDeviceInfo *psDevInfo;
101     tConfigDescriptor *psConfDescriptor;
102     volatile tCDCState eCDCRxState;
103     volatile tCDCState eCDCTxState;
104     volatile tCDCState eCDCRequestState;
105     volatile tCDCState eCDCInterruptState;
106     volatile uint8 ucPendingRequest;
107     uint16 usBreakDuration;
108     uint16 usControlLineState;
109     uint16 usSerialState;
110     volatile uint16 usDeferredOpFlags;
111     uint16 usLastTxSize;
112     tLineCoding sLineCoding;
113     volatile tBoolean bRxBlocked;
114     volatile tBoolean bControlBlocked;
115     volatile tBoolean bConnected;
116     uint8 ucControlEndpoint;
117     uint8 ucBulkINEndpoint;
118     uint8 ucBulkOUTEndpoint;
119     uint8 ucInterfaceControl;
120     uint8 ucInterfaceData;
121 }
122 tCDCSerInstance;
123 
124 
125 #ifndef DEPRECATED
126 //*****************************************************************************
127 //
128 // The number of bytes of workspace required by the CDC device class driver.
129 // The client must provide a block of RAM of at least this size in the
130 // psPrivateCDCSerData field of the tUSBCDCDevice structure passed on
131 // USBDCDCInit().
132 //
133 // This value is deprecated and should not be used, any new code should just
134 // pass in a tUSBCDCDevice structure in the psPrivateCDCSerData field.
135 //
136 //*****************************************************************************
137 #define USB_CDCSER_WORKSPACE_SIZE (sizeof(tCDCSerInstance))
138 #endif
139 
140 //*****************************************************************************
141 //
142 // The following defines are used when working with composite devices.
143 //
144 //*****************************************************************************
145 
146 //*****************************************************************************
147 //
148 //! The size of the memory that should be allocated to create a configuration
149 //! descriptor for a single instance of the USB Serial CDC Device.
150 //! This does not include the configuration descriptor which is automatically
151 //! ignored by the composite device class.
152 //
153 // For reference this is sizeof(g_pIADSerDescriptor) +
154 // sizeof(g_pCDCSerCommInterface) + sizeof(g_pCDCSerDataInterface)
155 //
156 //*****************************************************************************
157 #define COMPOSITE_DCDC_SIZE     (8 + 35 + 23)
158 
159 //*****************************************************************************
160 //
161 // CDC-specific events These events are provided to the application in the
162 // \e ulMsg parameter of the tUSBCallback function.
163 //
164 //*****************************************************************************
165 
166 //
167 //! The host requests that the device send a BREAK condition on its
168 //! serial communication channel.  The BREAK should remain active until
169 //! a USBD_CDC_EVENT_CLEAR_BREAK event is received.
170 //
171 #define USBD_CDC_EVENT_SEND_BREAK (USBD_CDC_EVENT_BASE + 0)
172 
173 //
174 //! The host requests that the device stop sending a BREAK condition on its
175 //! serial communication channel.
176 //
177 #define USBD_CDC_EVENT_CLEAR_BREAK (USBD_CDC_EVENT_BASE + 1)
178 
179 //
180 //! The host requests that the device set the RS232 signaling lines to
181 //! a particular state.  The ulMsgValue parameter contains the RTS and
182 //! DTR control line states as defined in table 51 of the USB CDC class
183 //! definition and is a combination of the following values:
184 //!
185 //! (RTS) USB_CDC_DEACTIVATE_CARRIER or USB_CDC_ACTIVATE_CARRIER
186 //! (DTR) USB_CDC_DTE_NOT_PRESENT or USB_CDC_DTE_PRESENT
187 //
188 #define USBD_CDC_EVENT_SET_CONTROL_LINE_STATE (USBD_CDC_EVENT_BASE + 2)
189 
190 //
191 //! The host requests that the device set the RS232 communication
192 //! parameters.  The pvMsgData parameter points to a tLineCoding structure
193 //! defining the required number of bits per character, parity mode,
194 //! number of stop bits and the baud rate.
195 //
196 #define USBD_CDC_EVENT_SET_LINE_CODING (USBD_CDC_EVENT_BASE + 3)
197 
198 //
199 //! The host is querying the current RS232 communication parameters.  The
200 //! pvMsgData parameter points to a tLineCoding structure that the
201 //! application must fill with the current settings prior to returning
202 //! from the callback.
203 //
204 #define USBD_CDC_EVENT_GET_LINE_CODING (USBD_CDC_EVENT_BASE + 4)
205 
206 //*****************************************************************************
207 //
208 //! The structure used by the application to define operating parameters for
209 //! the CDC device.
210 //
211 //*****************************************************************************
212 typedef struct
213 {
214     //
215     //! The vendor ID that this device is to present in the device descriptor.
216     //
217     uint16 usVID;
218 
219     //
220     //! The product ID that this device is to present in the device descriptor.
221     //
222     uint16 usPID;
223 
224     //
225     //! The maximum power consumption of the device, expressed in milliamps.
226     //
227     uint16 usMaxPowermA;
228 
229     //
230     //! Indicates whether the device is self- or bus-powered and whether or not
231     //! it supports remote wakeup.  Valid values are USB_CONF_ATTR_SELF_PWR or
232     //! USB_CONF_ATTR_BUS_PWR, optionally ORed with USB_CONF_ATTR_RWAKE.
233     //
234     uint8 ucPwrAttributes;
235 
236     //
237     //! A pointer to the callback function which will be called to notify
238     //! the application of all asynchronous control events related to the
239     //! operation of the device.
240     //
241     tUSBCallback pfnControlCallback;
242 
243     //
244     //! A client-supplied pointer which will be sent as the first
245     //! parameter in all calls made to the control channel callback,
246     //! pfnControlCallback.
247     //
248     void *pvControlCBData;
249 
250     //
251     //! A pointer to the callback function which will be called to notify
252     //! the application of events related to the device's data receive channel.
253     //
254     tUSBCallback pfnRxCallback;
255 
256     //
257     //! A client-supplied pointer which will be sent as the first
258     //! parameter in all calls made to the receive channel callback,
259     //! pfnRxCallback.
260     //
261     void *pvRxCBData;
262 
263     //
264     //! A pointer to the callback function which will be called to notify
265     //! the application of events related to the device's data transmit
266     //! channel.
267     //
268     tUSBCallback pfnTxCallback;
269 
270     //
271     //! A client-supplied pointer which will be sent as the first
272     //! parameter in all calls made to the transmit channel callback,
273     //! pfnTxCallback.
274     //
275     void *pvTxCBData;
276 
277     //
278     //! A pointer to the string descriptor array for this device.  This array
279     //! must contain the following string descriptor pointers in this order.
280     //! Language descriptor, Manufacturer name string (language 1), Product
281     //! name string (language 1), Serial number string (language 1),
282     //! Control interface description string (language 1), Configuration
283     //! description string (language 1).
284     //!
285     //! If supporting more than 1 language, the strings for indices 1 through 5
286     //! must be repeated for each of the other languages defined in the
287     //! language descriptor.
288     //
289     const uint8 * const *ppStringDescriptors;
290 
291     //
292     //! The number of descriptors provided in the ppStringDescriptors
293     //! array.  This must be 1 + (5 * number of supported languages).
294     //
295     uint32 ulNumStringDescriptors;
296 
297     //
298     //! A pointer to the private instance data for this device.  This memory
299     //! must remain accessible for as long as the CDC device is in use and must
300     //! not be modified by any code outside the CDC class driver.
301     //
302     tCDCSerInstance *psPrivateCDCSerData;
303 }
304 tUSBDCDCDevice;
305 
306 extern tDeviceInfo g_sCDCSerDeviceInfo;
307 
308 //*****************************************************************************
309 //
310 // API Function Prototypes
311 //
312 //*****************************************************************************
313 extern void * USBDCDCCompositeInit(uint32 ulIndex,
314                                    const tUSBDCDCDevice *psCDCDevice);
315 extern void *USBDCDCInit(uint32 ulIndex,
316                          const tUSBDCDCDevice *psCDCDevice);
317 extern void USBDCDCTerm(void *pvInstance);
318 extern void *USBDCDCSetControlCBData(void *pvInstance, void *pvCBData);
319 extern void *USBDCDCSetRxCBData(void *pvInstance, void *pvCBData);
320 extern void *USBDCDCSetTxCBData(void *pvInstance, void *pvCBData);
321 extern uint32 USBDCDCPacketWrite(void *pvInstance,
322                                         uint8 *pcData,
323                                         uint32 ulLength,
324                                         tBoolean bLast);
325 extern uint32 USBDCDCPacketRead(void *pvInstance,
326                                        uint8 *pcData,
327                                        uint32 ulLength,
328                                        tBoolean bLast);
329 extern uint32 USBDCDCTxPacketAvailable(void *pvInstance);
330 extern uint32 USBDCDCRxPacketAvailable(void *pvInstance);
331 extern void USBDCDCSerialStateChange(void *pvInstance,
332                                      uint16 usState);
333 extern void USBDCDCPowerStatusSet(void *pvInstance, uint8 ucPower);
334 extern tBoolean USBDCDCRemoteWakeupRequest(void *pvInstance);
335 
336 //*****************************************************************************
337 //
338 // Close the Doxygen group.
339 //! @}
340 //
341 //*****************************************************************************
342 
343 //*****************************************************************************
344 //
345 // Mark the end of the C bindings section for C++ compilers.
346 //
347 //*****************************************************************************
348 #ifdef __cplusplus
349 }
350 #endif
351 
352 #endif // __USBDCDC_H__
353