usbdcdc.h 13 KB

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