usbdcdc.h 12 KB

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