usblib.h 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903
  1. //
  2. // usblib.h - Main header file for the USB Library.
  3. //
  4. // Copyright (c) 2008-2010 Texas Instruments Incorporated. All rights reserved.
  5. // Software License Agreement
  6. //
  7. // Texas Instruments (TI) is supplying this software for use solely and
  8. // exclusively on TI's microcontroller products. The software is owned by
  9. // TI and/or its suppliers, and is protected under applicable copyright
  10. // laws. You may not combine this software with "viral" open-source
  11. // software in order to form a larger program.
  12. //
  13. // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
  14. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
  15. // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  16. // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
  17. // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
  18. // DAMAGES, FOR ANY REASON WHATSOEVER.
  19. //
  20. // This is part of AM1808 StarterWare USB Library and reused from revision 6288
  21. // of the Stellaris USB Library.
  22. //
  23. //*****************************************************************************
  24. #ifndef __USBLIB_H__
  25. #define __USBLIB_H__
  26. //*****************************************************************************
  27. //
  28. // If building with a C++ compiler, make all of the definitions in this header
  29. // have a C binding.
  30. //
  31. //*****************************************************************************
  32. #ifdef __cplusplus
  33. extern "C"
  34. {
  35. #endif
  36. #include "hw_usb.h"
  37. //*****************************************************************************
  38. //
  39. // This is the maximum number of endpoints supported by the usblib.
  40. //
  41. //*****************************************************************************
  42. #define USBLIB_NUM_EP 16 // Number of supported endpoints.
  43. //*****************************************************************************
  44. //
  45. // The following macro allows compiler-independent syntax to be used to
  46. // define packed structures. A typical structure definition using these
  47. // macros will look similar to the following example:
  48. //
  49. // #ifdef ewarm
  50. // #pragma pack(1)
  51. // #endif
  52. //
  53. // typedef struct _PackedStructName
  54. // {
  55. // unsigned int ulFirstField;
  56. // char cCharMember;
  57. // unsigned short usShort;
  58. // }
  59. // USBLIB_PACKED tPackedStructName;
  60. //
  61. // #ifdef ewarm
  62. // #pragma pack()
  63. // #endif
  64. //
  65. // The conditional blocks related to ewarm include the #pragma pack() lines
  66. // only if the IAR Embedded Workbench compiler is being used. Unfortunately,
  67. // it is not possible to emit a #pragma from within a macro definition so this
  68. // must be done explicitly.
  69. //
  70. //*****************************************************************************
  71. #if defined(ccs) || \
  72. defined(codered) || \
  73. defined(gcc) || \
  74. defined(rvmdk) || \
  75. defined(__ARMCC_VERSION) || \
  76. defined(sourcerygxx)
  77. #define USBLIB_PACKED __attribute__ ((packed))
  78. #elif defined(ewarm) || defined(__IAR_SYSTEMS_ICC__)
  79. #define USBLIB_PACKED
  80. #elif defined(__TMS470__)
  81. #if defined(__TI_TMS470_V7__) || (__TI_COMPILER_VERSION__ >= 5000000)
  82. #define USBLIB_PACKED __attribute__ ((packed))
  83. #else
  84. #warn The packed attribute is not supported by this version of the TI ARM CGT. \
  85. Please upgrade to version 5.x or use an alternate toolchain instead.
  86. #define USBLIB_PACKED
  87. #endif
  88. #elif defined(_TMS320C6X)
  89. #define USBLIB_PACKED __attribute__ ((packed))
  90. #else
  91. #error Unrecognized COMPILER!
  92. #endif
  93. //*****************************************************************************
  94. //
  95. // Assorted language IDs from the document "USB_LANGIDs.pdf" provided by the
  96. // USB Implementers' Forum (Version 1.0).
  97. //
  98. //*****************************************************************************
  99. #define USB_LANG_CHINESE_PRC 0x0804 // Chinese (PRC)
  100. #define USB_LANG_CHINESE_TAIWAN 0x0404 // Chinese (Taiwan)
  101. #define USB_LANG_EN_US 0x0409 // English (United States)
  102. #define USB_LANG_EN_UK 0x0809 // English (United Kingdom)
  103. #define USB_LANG_EN_AUS 0x0C09 // English (Australia)
  104. #define USB_LANG_EN_CA 0x1009 // English (Canada)
  105. #define USB_LANG_EN_NZ 0x1409 // English (New Zealand)
  106. #define USB_LANG_FRENCH 0x040C // French (Standard)
  107. #define USB_LANG_GERMAN 0x0407 // German (Standard)
  108. #define USB_LANG_HINDI 0x0439 // Hindi
  109. #define USB_LANG_ITALIAN 0x0410 // Italian (Standard)
  110. #define USB_LANG_JAPANESE 0x0411 // Japanese
  111. #define USB_LANG_KOREAN 0x0412 // Korean
  112. #define USB_LANG_ES_TRAD 0x040A // Spanish (Traditional)
  113. #define USB_LANG_ES_MODERN 0x0C0A // Spanish (Modern)
  114. #define USB_LANG_SWAHILI 0x0441 // Swahili (Kenya)
  115. #define USB_LANG_URDU_IN 0x0820 // Urdu (India)
  116. #define USB_LANG_URDU_PK 0x0420 // Urdu (Pakistan)
  117. //*****************************************************************************
  118. //
  119. //! \addtogroup usbchap9_src
  120. //! @{
  121. //
  122. //*****************************************************************************
  123. //*****************************************************************************
  124. //
  125. // Note:
  126. //
  127. // Structure definitions which are derived directly from the USB specification
  128. // use field names from the specification. Since a somewhat different version
  129. // of Hungarian prefix notation is used from the Stellaris standard, beware of
  130. // making assumptions about field sizes based on the field prefix when using
  131. // these structures. Of particular note is the difference in the meaning of
  132. // the 'i' prefix. In USB structures, this indicates a single byte index
  133. // whereas in Stellaris code, this is a 32 bit integer.
  134. //
  135. //*****************************************************************************
  136. //*****************************************************************************
  137. //
  138. // All structures defined in this section of the header require byte packing of
  139. // fields. This is usually accomplished using the USBLIB_PACKED macro but, for IAR
  140. // Embedded Workbench, this requires a pragma.
  141. //
  142. //*****************************************************************************
  143. #if defined(ewarm) || defined(__IAR_SYSTEMS_ICC__)
  144. #pragma pack(1)
  145. #endif
  146. //*****************************************************************************
  147. //
  148. // Definitions related to standard USB device requests (sections 9.3 & 9.4)
  149. //
  150. //*****************************************************************************
  151. //*****************************************************************************
  152. //
  153. //! The standard USB request header as defined in section 9.3 of the USB 2.0
  154. //! specification.
  155. //
  156. //*****************************************************************************
  157. typedef struct
  158. {
  159. //
  160. //! Determines the type and direction of the request.
  161. //
  162. unsigned char bmRequestType;
  163. //
  164. //! Identifies the specific request being made.
  165. //
  166. unsigned char bRequest;
  167. //
  168. //! Word-sized field that varies according to the request.
  169. //
  170. unsigned short wValue;
  171. //
  172. //! Word-sized field that varies according to the request; typically used
  173. //! to pass an index or offset.
  174. //
  175. unsigned short wIndex;
  176. //
  177. //! The number of bytes to transfer if there is a data stage to the
  178. //! request.
  179. //
  180. unsigned short wLength;
  181. }
  182. USBLIB_PACKED tUSBRequest;
  183. //*****************************************************************************
  184. //
  185. // The following defines are used with the bmRequestType member of tUSBRequest.
  186. //
  187. // Request types have 3 bit fields:
  188. // 4:0 - Is the recipient type.
  189. // 6:5 - Is the request type.
  190. // 7 - Is the direction of the request.
  191. //
  192. //*****************************************************************************
  193. #define USB_RTYPE_DIR_IN 0x80
  194. #define USB_RTYPE_DIR_OUT 0x00
  195. #define USB_RTYPE_TYPE_M 0x60
  196. #define USB_RTYPE_VENDOR 0x40
  197. #define USB_RTYPE_CLASS 0x20
  198. #define USB_RTYPE_STANDARD 0x00
  199. #define USB_RTYPE_RECIPIENT_M 0x1f
  200. #define USB_RTYPE_OTHER 0x03
  201. #define USB_RTYPE_ENDPOINT 0x02
  202. #define USB_RTYPE_INTERFACE 0x01
  203. #define USB_RTYPE_DEVICE 0x00
  204. //*****************************************************************************
  205. //
  206. // Standard USB requests IDs used in the bRequest field of tUSBRequest.
  207. //
  208. //*****************************************************************************
  209. #define USBREQ_GET_STATUS 0x00
  210. #define USBREQ_CLEAR_FEATURE 0x01
  211. #define USBREQ_SET_FEATURE 0x03
  212. #define USBREQ_SET_ADDRESS 0x05
  213. #define USBREQ_GET_DESCRIPTOR 0x06
  214. #define USBREQ_SET_DESCRIPTOR 0x07
  215. #define USBREQ_GET_CONFIG 0x08
  216. #define USBREQ_SET_CONFIG 0x09
  217. #define USBREQ_GET_INTERFACE 0x0a
  218. #define USBREQ_SET_INTERFACE 0x0b
  219. #define USBREQ_SYNC_FRAME 0x0c
  220. //*****************************************************************************
  221. //
  222. // Data returned from a USBREQ_GET_STATUS request to a device.
  223. //
  224. //*****************************************************************************
  225. #define USB_STATUS_SELF_PWR 0x0001 // Currently self powered.
  226. #define USB_STATUS_BUS_PWR 0x0000 // Currently bus-powered.
  227. #define USB_STATUS_PWR_M 0x0001 // Mask for power mode.
  228. #define USB_STATUS_REMOTE_WAKE 0x0002 // Remote wake-up is currently enabled.
  229. //*****************************************************************************
  230. //
  231. // Feature Selectors (tUSBRequest.wValue) passed on USBREQ_CLEAR_FEATURE and
  232. // USBREQ_SET_FEATURE.
  233. //
  234. //*****************************************************************************
  235. #define USB_FEATURE_EP_HALT 0x0000 // Endpoint halt feature.
  236. #define USB_FEATURE_REMOTE_WAKE 0x0001 // Remote wake feature, device only.
  237. #define USB_FEATURE_TEST_MODE 0x0002 // Test mode
  238. //*****************************************************************************
  239. //
  240. // Endpoint Selectors (tUSBRequest.wIndex) passed on USBREQ_CLEAR_FEATURE,
  241. // USBREQ_SET_FEATURE and USBREQ_GET_STATUS.
  242. //
  243. //*****************************************************************************
  244. #define USB_REQ_EP_NUM_M 0x007F
  245. #define USB_REQ_EP_DIR_M 0x0080
  246. #define USB_REQ_EP_DIR_IN 0x0080
  247. #define USB_REQ_EP_DIR_OUT 0x0000
  248. //*****************************************************************************
  249. //
  250. // Standard USB descriptor types. These values are passed in the upper bytes
  251. // of tUSBRequest.wValue on USBREQ_GET_DESCRIPTOR and also appear in the
  252. // bDescriptorType field of standard USB descriptors.
  253. //
  254. //*****************************************************************************
  255. #define USB_DTYPE_DEVICE 1
  256. #define USB_DTYPE_CONFIGURATION 2
  257. #define USB_DTYPE_STRING 3
  258. #define USB_DTYPE_INTERFACE 4
  259. #define USB_DTYPE_ENDPOINT 5
  260. #define USB_DTYPE_DEVICE_QUAL 6
  261. #define USB_DTYPE_OSPEED_CONF 7
  262. #define USB_DTYPE_INTERFACE_PWR 8
  263. #define USB_DTYPE_OTG 9
  264. #define USB_DTYPE_INTERFACE_ASC 11
  265. #define USB_DTYPE_CS_INTERFACE 36
  266. //*****************************************************************************
  267. //
  268. // Definitions related to USB descriptors (sections 9.5 & 9.6)
  269. //
  270. //*****************************************************************************
  271. //*****************************************************************************
  272. //
  273. //! This structure describes a generic descriptor header. These fields are to
  274. //! be found at the beginning of all valid USB descriptors.
  275. //
  276. //*****************************************************************************
  277. typedef struct
  278. {
  279. //
  280. //! The length of this descriptor (including this length byte) expressed
  281. //! in bytes.
  282. //
  283. unsigned char bLength;
  284. //
  285. //! The type identifier of the descriptor whose information follows. For
  286. //! standard descriptors, this field could contain, for example,
  287. //! USB_DTYPE_DEVICE to identify a device descriptor or USB_DTYPE_ENDPOINT
  288. //! to identify an endpoint descriptor.
  289. //
  290. unsigned char bDescriptorType;
  291. }
  292. USBLIB_PACKED tDescriptorHeader;
  293. //*****************************************************************************
  294. //
  295. //! This structure describes the USB device descriptor as defined in USB
  296. //! 2.0 specification section 9.6.1.
  297. //
  298. //*****************************************************************************
  299. typedef struct
  300. {
  301. //
  302. //! The length of this descriptor in bytes. All device descriptors are
  303. //! 18 bytes long.
  304. //
  305. unsigned char bLength;
  306. //
  307. //! The type of the descriptor. For a device descriptor, this will be
  308. //! USB_DTYPE_DEVICE (1).
  309. //
  310. unsigned char bDescriptorType;
  311. //
  312. //! The USB Specification Release Number in BCD format. For USB 2.0, this
  313. //! will be 0x0200.
  314. //
  315. unsigned short bcdUSB;
  316. //
  317. //! The device class code.
  318. //
  319. unsigned char bDeviceClass;
  320. //
  321. //! The device subclass code. This value qualifies the value found in the
  322. //! bDeviceClass field.
  323. //
  324. unsigned char bDeviceSubClass;
  325. //
  326. //! The device protocol code. This value is qualified by the values of
  327. //! bDeviceClass and bDeviceSubClass.
  328. //
  329. unsigned char bDeviceProtocol;
  330. //
  331. //! The maximum packet size for endpoint zero. Valid values are 8, 16, 32
  332. //! and 64.
  333. //
  334. unsigned char bMaxPacketSize0;
  335. //
  336. //! The device Vendor ID (VID) as assigned by the USB-IF.
  337. //
  338. unsigned short idVendor;
  339. //
  340. //! The device Product ID (PID) as assigned by the manufacturer.
  341. //
  342. unsigned short idProduct;
  343. //
  344. //! The device release number in BCD format.
  345. //
  346. unsigned short bcdDevice;
  347. //
  348. //! The index of a string descriptor describing the manufacturer.
  349. //
  350. unsigned char iManufacturer;
  351. //
  352. //! The index of a string descriptor describing the product.
  353. //
  354. unsigned char iProduct;
  355. //
  356. //! The index of a string descriptor describing the device's serial
  357. //! number.
  358. //
  359. unsigned char iSerialNumber;
  360. //
  361. //! The number of possible configurations offered by the device. This
  362. //! field indicates the number of distinct configuration descriptors that
  363. //! the device offers.
  364. //
  365. unsigned char bNumConfigurations;
  366. }
  367. USBLIB_PACKED tDeviceDescriptor;
  368. //*****************************************************************************
  369. //
  370. // USB Device Class codes used in the tDeviceDescriptor.bDeviceClass field.
  371. // Definitions for the bDeviceSubClass and bDeviceProtocol fields are device
  372. // specific and can be found in the appropriate device class header files.
  373. //
  374. //*****************************************************************************
  375. #define USB_CLASS_DEVICE 0x00
  376. #define USB_CLASS_AUDIO 0x01
  377. #define USB_CLASS_CDC 0x02
  378. #define USB_CLASS_HID 0x03
  379. #define USB_CLASS_PHYSICAL 0x05
  380. #define USB_CLASS_IMAGE 0x06
  381. #define USB_CLASS_PRINTER 0x07
  382. #define USB_CLASS_MASS_STORAGE 0x08
  383. #define USB_CLASS_HUB 0x09
  384. #define USB_CLASS_CDC_DATA 0x0a
  385. #define USB_CLASS_SMART_CARD 0x0b
  386. #define USB_CLASS_SECURITY 0x0d
  387. #define USB_CLASS_VIDEO 0x0e
  388. #define USB_CLASS_HEALTHCARE 0x0f
  389. #define USB_CLASS_DIAG_DEVICE 0xdc
  390. #define USB_CLASS_WIRELESS 0xe0
  391. #define USB_CLASS_MISC 0xef
  392. #define USB_CLASS_APP_SPECIFIC 0xfe
  393. #define USB_CLASS_VEND_SPECIFIC 0xff
  394. #define USB_CLASS_EVENTS 0xffffffff
  395. //*****************************************************************************
  396. //
  397. // Generic values for undefined subclass and protocol.
  398. //
  399. //*****************************************************************************
  400. #define USB_SUBCLASS_UNDEFINED 0x00
  401. #define USB_PROTOCOL_UNDEFINED 0x00
  402. //*****************************************************************************
  403. //
  404. // The following are the miscellaneous subclass values.
  405. //
  406. //*****************************************************************************
  407. #define USB_MISC_SUBCLASS_SYNC 0x01
  408. #define USB_MISC_SUBCLASS_COMMON 0x02
  409. //*****************************************************************************
  410. //
  411. // These following are miscellaneous protocol values.
  412. //
  413. //*****************************************************************************
  414. #define USB_MISC_PROTOCOL_IAD 0x01
  415. //*****************************************************************************
  416. //
  417. //! This structure describes the USB device qualifier descriptor as defined in
  418. //! the USB 2.0 specification, section 9.6.2.
  419. //
  420. //*****************************************************************************
  421. typedef struct
  422. {
  423. //
  424. //! The length of this descriptor in bytes. All device qualifier
  425. //! descriptors are 10 bytes long.
  426. //
  427. unsigned char bLength;
  428. //
  429. //! The type of the descriptor. For a device descriptor, this will be
  430. //! USB_DTYPE_DEVICE_QUAL (6).
  431. //
  432. unsigned char bDescriptorType;
  433. //
  434. //! The USB Specification Release Number in BCD format. For USB 2.0, this
  435. //! will be 0x0200.
  436. //
  437. unsigned short bcdUSB;
  438. //
  439. //! The device class code.
  440. //
  441. unsigned char bDeviceClass;
  442. //
  443. //! The device subclass code. This value qualifies the value found in the
  444. //! bDeviceClass field.
  445. //
  446. unsigned char bDeviceSubClass;
  447. //
  448. //! The device protocol code. This value is qualified by the values of
  449. //! bDeviceClass and bDeviceSubClass.
  450. //
  451. unsigned char bDeviceProtocol;
  452. //
  453. //! The maximum packet size for endpoint zero when operating at a speed
  454. //! other than high speed.
  455. //
  456. unsigned char bMaxPacketSize0;
  457. //
  458. //! The number of other-speed configurations supported.
  459. //
  460. unsigned char bNumConfigurations;
  461. //
  462. //! Reserved for future use. Must be set to zero.
  463. //
  464. unsigned char bReserved;
  465. }
  466. USBLIB_PACKED tDeviceQualifierDescriptor;
  467. //*****************************************************************************
  468. //
  469. //! This structure describes the USB configuration descriptor as defined in
  470. //! USB 2.0 specification section 9.6.3. This structure also applies to the
  471. //! USB other speed configuration descriptor defined in section 9.6.4.
  472. //
  473. //*****************************************************************************
  474. typedef struct
  475. {
  476. //
  477. //! The length of this descriptor in bytes. All configuration descriptors
  478. //! are 9 bytes long.
  479. //
  480. unsigned char bLength;
  481. //
  482. //! The type of the descriptor. For a configuration descriptor, this will
  483. //! be USB_DTYPE_CONFIGURATION (2).
  484. //
  485. unsigned char bDescriptorType;
  486. //
  487. //! The total length of data returned for this configuration. This
  488. //! includes the combined length of all descriptors (configuration,
  489. //! interface, endpoint and class- or vendor-specific) returned for this
  490. //! configuration.
  491. //
  492. unsigned short wTotalLength;
  493. //
  494. //! The number of interface supported by this configuration.
  495. //
  496. unsigned char bNumInterfaces;
  497. //
  498. //! The value used as an argument to the SetConfiguration standard request
  499. //! to select this configuration.
  500. //
  501. unsigned char bConfigurationValue;
  502. //
  503. //! The index of a string descriptor describing this configuration.
  504. //
  505. unsigned char iConfiguration;
  506. //
  507. //! Attributes of this configuration.
  508. //
  509. unsigned char bmAttributes;
  510. //
  511. //! The maximum power consumption of the USB device from the bus in this
  512. //! configuration when the device is fully operational. This is expressed
  513. //! in units of 2mA so, for example, 100 represents 200mA.
  514. //
  515. unsigned char bMaxPower;
  516. }
  517. USBLIB_PACKED tConfigDescriptor;
  518. //*****************************************************************************
  519. //
  520. // Flags used in constructing the value assigned to the field
  521. // tConfigDescriptor.bmAttributes. Note that bit 7 is reserved and must be set
  522. // to 1.
  523. //
  524. //*****************************************************************************
  525. #define USB_CONF_ATTR_PWR_M 0xC0
  526. #define USB_CONF_ATTR_SELF_PWR 0xC0
  527. #define USB_CONF_ATTR_BUS_PWR 0x80
  528. #define USB_CONF_ATTR_RWAKE 0xA0
  529. //*****************************************************************************
  530. //
  531. //! This structure describes the USB interface descriptor as defined in USB
  532. //! 2.0 specification section 9.6.5.
  533. //
  534. //*****************************************************************************
  535. typedef struct
  536. {
  537. //
  538. //! The length of this descriptor in bytes. All interface descriptors
  539. //! are 9 bytes long.
  540. //
  541. unsigned char bLength;
  542. //
  543. //! The type of the descriptor. For an interface descriptor, this will
  544. //! be USB_DTYPE_INTERFACE (4).
  545. //
  546. unsigned char bDescriptorType;
  547. //
  548. //! The number of this interface. This is a zero based index into the
  549. //! array of concurrent interfaces supported by this configuration.
  550. //
  551. unsigned char bInterfaceNumber;
  552. //
  553. //! The value used to select this alternate setting for the interface
  554. //! defined in bInterfaceNumber.
  555. //
  556. unsigned char bAlternateSetting;
  557. //
  558. //! The number of endpoints used by this interface (excluding endpoint
  559. //! zero).
  560. //
  561. unsigned char bNumEndpoints;
  562. //
  563. //! The interface class code as assigned by the USB-IF.
  564. //
  565. unsigned char bInterfaceClass;
  566. //
  567. //! The interface subclass code as assigned by the USB-IF.
  568. //
  569. unsigned char bInterfaceSubClass;
  570. //
  571. //! The interface protocol code as assigned by the USB-IF.
  572. //
  573. unsigned char bInterfaceProtocol;
  574. //
  575. //! The index of a string descriptor describing this interface.
  576. //
  577. unsigned char iInterface;
  578. }
  579. USBLIB_PACKED tInterfaceDescriptor;
  580. //*****************************************************************************
  581. //
  582. //! This structure describes the USB endpoint descriptor as defined in USB
  583. //! 2.0 specification section 9.6.6.
  584. //
  585. //*****************************************************************************
  586. typedef struct
  587. {
  588. //
  589. //! The length of this descriptor in bytes. All endpoint descriptors
  590. //! are 7 bytes long.
  591. //
  592. unsigned char bLength;
  593. //
  594. //! The type of the descriptor. For an endpoint descriptor, this will
  595. //! be USB_DTYPE_ENDPOINT (5).
  596. //
  597. unsigned char bDescriptorType;
  598. //
  599. //! The address of the endpoint. This field contains the endpoint number
  600. //! ORed with flag USB_EP_DESC_OUT or USB_EP_DESC_IN to indicate the
  601. //! endpoint direction.
  602. //
  603. unsigned char bEndpointAddress;
  604. //
  605. //! The endpoint transfer type, USB_EP_ATTR_CONTROL, USB_EP_ATTR_ISOC,
  606. //! USB_EP_ATTR_BULK or USB_EP_ATTR_INT and, if isochronous, additional
  607. //! flags indicating usage type and synchronization method.
  608. //
  609. unsigned char bmAttributes;
  610. //
  611. //! The maximum packet size this endpoint is capable of sending or
  612. //! receiving when this configuration is selected. For high speed
  613. //! isochronous or interrupt endpoints, bits 11 and 12 are used to
  614. //! pass additional information.
  615. //
  616. unsigned short wMaxPacketSize;
  617. //
  618. //! The polling interval for data transfers expressed in frames or
  619. //! micro frames depending upon the operating speed.
  620. //
  621. unsigned char bInterval;
  622. }
  623. USBLIB_PACKED tEndpointDescriptor;
  624. //*****************************************************************************
  625. //
  626. // Flags used in constructing the value assigned to the field
  627. // tEndpointDescriptor.bEndpointAddress.
  628. //
  629. //*****************************************************************************
  630. #define USB_EP_DESC_OUT 0x00
  631. #define USB_EP_DESC_IN 0x80
  632. #define USB_EP_DESC_NUM_M 0x0f
  633. //*****************************************************************************
  634. //
  635. // Mask used to extract the maximum packet size (in bytes) from the
  636. // wMaxPacketSize field of the endpoint descriptor.
  637. //
  638. //*****************************************************************************
  639. #define USB_EP_MAX_PACKET_COUNT_M 0x07FF
  640. //*****************************************************************************
  641. //
  642. // Endpoint attributes used in tEndpointDescriptor.bmAttributes.
  643. //
  644. //*****************************************************************************
  645. #define USB_EP_ATTR_CONTROL 0x00
  646. #define USB_EP_ATTR_ISOC 0x01
  647. #define USB_EP_ATTR_BULK 0x02
  648. #define USB_EP_ATTR_INT 0x03
  649. #define USB_EP_ATTR_TYPE_M 0x03
  650. #define USB_EP_ATTR_ISOC_M 0x0c
  651. #define USB_EP_ATTR_ISOC_NOSYNC 0x00
  652. #define USB_EP_ATTR_ISOC_ASYNC 0x04
  653. #define USB_EP_ATTR_ISOC_ADAPT 0x08
  654. #define USB_EP_ATTR_ISOC_SYNC 0x0c
  655. #define USB_EP_ATTR_USAGE_M 0x30
  656. #define USB_EP_ATTR_USAGE_DATA 0x00
  657. #define USB_EP_ATTR_USAGE_FEEDBACK 0x10
  658. #define USB_EP_ATTR_USAGE_IMPFEEDBACK 0x20
  659. //*****************************************************************************
  660. //
  661. //! This structure describes the USB string descriptor for index 0 as defined
  662. //! in USB 2.0 specification section 9.6.7. Note that the number of language
  663. //! IDs is variable and can be determined by examining bLength. The number of
  664. //! language IDs present in the descriptor is given by ((bLength - 2) / 2).
  665. //
  666. //*****************************************************************************
  667. typedef struct
  668. {
  669. //
  670. //! The length of this descriptor in bytes. This value will vary
  671. //! depending upon the number of language codes provided in the descriptor.
  672. //
  673. unsigned char bLength;
  674. //
  675. //! The type of the descriptor. For a string descriptor, this will be
  676. //! USB_DTYPE_STRING (3).
  677. //
  678. unsigned char bDescriptorType;
  679. //
  680. //! The language code (LANGID) for the first supported language. Note that
  681. //! this descriptor may support multiple languages, in which case, the
  682. //! number of elements in the wLANGID array will increase and bLength will
  683. //! be updated accordingly.
  684. //
  685. unsigned short wLANGID[1];
  686. }
  687. USBLIB_PACKED tString0Descriptor;
  688. //*****************************************************************************
  689. //
  690. //! This structure describes the USB string descriptor for all string indexes
  691. //! other than 0 as defined in USB 2.0 specification section 9.6.7.
  692. //
  693. //*****************************************************************************
  694. typedef struct
  695. {
  696. //
  697. //! The length of this descriptor in bytes. This value will be 2 greater
  698. //! than the number of bytes comprising the UNICODE string that the
  699. //! descriptor contains.
  700. //
  701. unsigned char bLength;
  702. //
  703. //! The type of the descriptor. For a string descriptor, this will be
  704. //! USB_DTYPE_STRING (3).
  705. //
  706. unsigned char bDescriptorType;
  707. //
  708. //! The first byte of the UNICODE string. This string is not NULL
  709. //! terminated. Its length (in bytes) can be computed by subtracting 2
  710. //! from the value in the bLength field.
  711. //
  712. unsigned char bString;
  713. }
  714. USBLIB_PACKED tStringDescriptor;
  715. //*****************************************************************************
  716. //
  717. //! Write a 2 byte unsigned short value to a USB descriptor block.
  718. //!
  719. //! \param usValue is the two byte unsigned short that is to be written to
  720. //! the descriptor.
  721. //!
  722. //! This helper macro is used in descriptor definitions to write two-byte
  723. //! values. Since the configuration descriptor contains all interface and
  724. //! endpoint descriptors in a contiguous block of memory, these descriptors are
  725. //! typically defined using an array of bytes rather than as packed structures.
  726. //!
  727. //! \return Not a function.
  728. //
  729. //*****************************************************************************
  730. #define USBShort(usValue) (usValue & 0xff), (usValue >> 8)
  731. //*****************************************************************************
  732. //
  733. //! Write a 3 byte unsigned long value to a USB descriptor block.
  734. //!
  735. //! \param ulValue is the three byte unsigned value that is to be written to the
  736. //! descriptor.
  737. //!
  738. //! This helper macro is used in descriptor definitions to write three-byte
  739. //! values. Since the configuration descriptor contains all interface and
  740. //! endpoint descriptors in a contiguous block of memory, these descriptors are
  741. //! typically defined using an array of bytes rather than as packed structures.
  742. //!
  743. //! \return Not a function.
  744. //
  745. //*****************************************************************************
  746. #define USB3Byte(ulValue) (ulValue & 0xff), \
  747. ((ulValue >> 8) & 0xff), \
  748. ((ulValue >> 16) & 0xff)
  749. //*****************************************************************************
  750. //
  751. //! Write a 4 byte unsigned long value to a USB descriptor block.
  752. //!
  753. //! \param ulValue is the four byte unsigned long that is to be written to the
  754. //! descriptor.
  755. //!
  756. //! This helper macro is used in descriptor definitions to write four-byte
  757. //! values. Since the configuration descriptor contains all interface and
  758. //! endpoint descriptors in a contiguous block of memory, these descriptors are
  759. //! typically defined using an array of bytes rather than as packed structures.
  760. //!
  761. //! \return Not a function.
  762. //
  763. //*****************************************************************************
  764. #define USBLong(ulValue) (ulValue & 0xff), \
  765. ((ulValue >> 8) & 0xff), \
  766. ((ulValue >> 16) & 0xff), \
  767. ((ulValue >> 24) & 0xff)
  768. //*****************************************************************************
  769. //
  770. //! Traverse to the next USB descriptor in a block.
  771. //!
  772. //! \param ptr points to the first byte of a descriptor in a block of
  773. //! USB descriptors.
  774. //!
  775. //! This macro aids in traversing lists of descriptors by returning a pointer
  776. //! to the next descriptor in the list given a pointer to the current one.
  777. //!
  778. //! \return Returns a pointer to the next descriptor in the block following
  779. //! \e ptr.
  780. //!
  781. //*****************************************************************************
  782. #define NEXT_USB_DESCRIPTOR(ptr) \
  783. (tDescriptorHeader *)(((unsigned char *)(ptr)) + \
  784. *((unsigned char *)(ptr)))
  785. //*****************************************************************************
  786. //
  787. // Return to default packing when using the IAR Embedded Workbench compiler.
  788. //
  789. //*****************************************************************************
  790. #if defined(ewarm) || defined(__IAR_SYSTEMS_ICC__)
  791. #pragma pack()
  792. #endif
  793. //*****************************************************************************
  794. //
  795. // Close the usbchap9_src Doxygen group.
  796. //! @}
  797. //
  798. //*****************************************************************************
  799. //*****************************************************************************
  800. //
  801. //! \addtogroup device_api
  802. //! @{
  803. //
  804. //*****************************************************************************
  805. //*****************************************************************************
  806. //
  807. // Function prototype for any standard USB request.
  808. //
  809. //*****************************************************************************
  810. typedef void (* tStdRequest)(void *pvInstance, tUSBRequest *pUSBRequest,
  811. unsigned int ulIndex);
  812. //*****************************************************************************
  813. //
  814. // Data callback for receiving data from an endpoint.
  815. //
  816. //*****************************************************************************
  817. typedef void (* tInfoCallback)(void *pvInstance, unsigned int ulInfo,
  818. unsigned int ulIndex);
  819. //*****************************************************************************
  820. //
  821. // Callback made to indicate that an interface alternate setting change has
  822. // occurred.
  823. //
  824. //*****************************************************************************
  825. typedef void (* tInterfaceCallback)(void *pvInstance,
  826. unsigned char ucInterfaceNum,
  827. unsigned char ucAlternateSetting);
  828. //*****************************************************************************
  829. //
  830. // Generic interrupt handler callbacks.
  831. //
  832. //*****************************************************************************
  833. typedef void (* tUSBIntHandler)(void *pvInstance);
  834. //*****************************************************************************
  835. //
  836. // Interrupt handler callbacks that have status information.
  837. //
  838. //*****************************************************************************
  839. typedef void (* tUSBEPIntHandler)(void *pvInstance,
  840. unsigned int ulStatus, unsigned int ulIndex);
  841. //*****************************************************************************
  842. //
  843. // Generic handler callbacks that are used when the callers needs to call into
  844. // an instance of class.
  845. //
  846. //*****************************************************************************
  847. typedef void (* tUSBDeviceHandler)(void *pvInstance,
  848. unsigned int ulRequest,
  849. void *pvRequestData);
  850. //*****************************************************************************
  851. //
  852. //! USB event handler functions used during enumeration and operation of the
  853. //! device stack.
  854. //
  855. //*****************************************************************************
  856. typedef struct
  857. {
  858. //
  859. //! This callback is made whenever the USB host requests a non-standard
  860. //! descriptor from the device.
  861. //
  862. tStdRequest pfnGetDescriptor;
  863. //
  864. //! This callback is made whenever the USB host makes a non-standard
  865. //! request.
  866. //
  867. tStdRequest pfnRequestHandler;
  868. //
  869. //! This callback is made in response to a SetInterface request from the
  870. //! host.
  871. //
  872. tInterfaceCallback pfnInterfaceChange;
  873. //
  874. //! This callback is made in response to a SetConfiguration request from
  875. //! the host.
  876. //
  877. tInfoCallback pfnConfigChange;
  878. //
  879. //! This callback is made when data has been received following to a call
  880. //! to USBDCDRequestDataEP0.
  881. //
  882. tInfoCallback pfnDataReceived;
  883. //
  884. //! This callback is made when data has been transmitted following a call
  885. //! to USBDCDSendDataEP0.
  886. //
  887. tInfoCallback pfnDataSent;
  888. //
  889. //! This callback is made when a USB reset is detected.
  890. //
  891. tUSBIntHandler pfnResetHandler;
  892. //
  893. //! This callback is made when the bus has been inactive long enough to
  894. //! trigger a suspend condition.
  895. //
  896. tUSBIntHandler pfnSuspendHandler;
  897. //
  898. //! This is called when resume signaling is detected.
  899. //
  900. tUSBIntHandler pfnResumeHandler;
  901. //
  902. //! This callback is made when the device is disconnected from the USB bus.
  903. //
  904. tUSBIntHandler pfnDisconnectHandler;
  905. //
  906. //! This callback is made to inform the device of activity on all endpoints
  907. //! other than endpoint zero.
  908. //
  909. tUSBEPIntHandler pfnEndpointHandler;
  910. //
  911. //! This generic handler is provided to allow requests based on
  912. //! a given instance to be passed into a device. This is commonly used
  913. //! by a top level composite device that is using multiple instances of
  914. //! a class.
  915. //
  916. tUSBDeviceHandler pfnDeviceHandler;
  917. }
  918. tCustomHandlers;
  919. //*****************************************************************************
  920. //
  921. //! This structure defines how a given endpoint's FIFO is configured in
  922. //! relation to the maximum packet size for the endpoint as specified in the
  923. //! endpoint descriptor.
  924. //
  925. //*****************************************************************************
  926. typedef struct
  927. {
  928. //
  929. //! The multiplier to apply to an endpoint's maximum packet size when
  930. //! configuring the FIFO for that endpoint. For example, setting this
  931. //! value to 2 will result in a 128 byte FIFO being configured if
  932. //! bDoubleBuffer is false and the associated endpoint is set to use a 64
  933. //! byte maximum packet size.
  934. //
  935. unsigned char cMultiplier;
  936. //
  937. //! This field indicates whether to configure an endpoint's FIFO to be
  938. //! double- or single-buffered. If true, a double-buffered FIFO is
  939. //! created and the amount of required FIFO storage is multiplied by two.
  940. //
  941. tBoolean bDoubleBuffer;
  942. //
  943. //! This field defines endpoint mode flags which cannot be deduced from
  944. //! the configuration descriptor, namely any in the set USB_EP_AUTO_xxx or
  945. //! USB_EP_DMA_MODE_x. USBDCDConfig adds these flags to the endpoint
  946. //! mode and direction determined from the config descriptor before it
  947. //! configures the endpoint using a call to USBDevEndpointConfigSet().
  948. //
  949. unsigned short usEPFlags;
  950. }
  951. tFIFOEntry;
  952. //*****************************************************************************
  953. //
  954. //! This structure defines endpoint and FIFO configuration information for
  955. //! all endpoints that the device wishes to use. This information cannot be
  956. //! determined by examining the USB configuration descriptor and is
  957. //! provided to USBDCDConfig by the application to allow the USB controller
  958. //! endpoints to be correctly configured.
  959. //
  960. //*****************************************************************************
  961. typedef struct
  962. {
  963. //
  964. //! An array containing one FIFO entry for each of the IN endpoints.
  965. //! Note that endpoint 0 is configured and managed by the USB device stack
  966. //! so is excluded from this array. The index 0 entry of the array
  967. //! corresponds to endpoint 1, index 1 to endpoint 2, etc.
  968. //
  969. tFIFOEntry sIn[USBLIB_NUM_EP - 1];
  970. //
  971. //! An array containing one FIFO entry for each of the OUT endpoints.
  972. //! Note that endpoint 0 is configured and managed by the USB device stack
  973. //! so is excluded from this array. The index 0 entry of the array
  974. //! corresponds to endpoint 1, index 1 to endpoint 2, etc.
  975. //
  976. tFIFOEntry sOut[USBLIB_NUM_EP - 1];
  977. }
  978. tFIFOConfig;
  979. //*****************************************************************************
  980. //
  981. //! This structure defines a contiguous block of data which contains a group
  982. //! of descriptors that form part of a configuration descriptor for a device.
  983. //! It is assumed that a config section contains only whole descriptors. It is
  984. //! not valid to split a single descriptor across multiple sections.
  985. //!
  986. //*****************************************************************************
  987. typedef struct
  988. {
  989. //
  990. //! The number of bytes of descriptor data pointed to by pucData.
  991. //
  992. unsigned char ucSize;
  993. //
  994. //! A pointer to a block of data containing an integral number of
  995. //! USB descriptors which form part of a larger configuration descriptor.
  996. //
  997. const unsigned char *pucData;
  998. }
  999. tConfigSection;
  1000. //*****************************************************************************
  1001. //
  1002. //! This is the top level structure defining a USB device configuration
  1003. //! descriptor. A configuration descriptor contains a collection of device-
  1004. //! specific descriptors in addition to the basic config, interface and
  1005. //! endpoint descriptors. To allow flexibility in constructing the
  1006. //! configuration, the descriptor is described in terms of a list of data
  1007. //! blocks. The first block must contain the configuration descriptor itself
  1008. //! and the following blocks are appended to this in order to produce the
  1009. //! full descriptor sent to the host in response to a GetDescriptor request
  1010. //! for the configuration descriptor.
  1011. //!
  1012. //*****************************************************************************
  1013. typedef struct
  1014. {
  1015. //
  1016. //! The number of sections comprising the full descriptor for this
  1017. //! configuration.
  1018. //
  1019. unsigned char ucNumSections;
  1020. //
  1021. //! A pointer to an array of ucNumSections section pointers which must
  1022. //! be concatenated to form the configuration descriptor.
  1023. //
  1024. const tConfigSection * const *psSections;
  1025. }
  1026. tConfigHeader;
  1027. //*****************************************************************************
  1028. //
  1029. //! This structure is passed to the USB library on a call to USBDCDInit and
  1030. //! provides the library with information about the device that the
  1031. //! application is implementing. It contains functions pointers for the
  1032. //! various USB event handlers and pointers to each of the standard device
  1033. //! descriptors.
  1034. //
  1035. //*****************************************************************************
  1036. typedef struct
  1037. {
  1038. //
  1039. //! A pointer to a structure containing pointers to event handler functions
  1040. //! provided by the client to support the operation of this device.
  1041. //
  1042. tCustomHandlers sCallbacks;
  1043. //
  1044. //! A pointer to the device descriptor for this device.
  1045. //
  1046. const unsigned char *pDeviceDescriptor;
  1047. //
  1048. //! A pointer to an array of configuration descriptor pointers. Each entry
  1049. //! in the array corresponds to one configuration that the device may be set
  1050. //! to use by the USB host. The number of entries in the array must
  1051. //! match the bNumConfigurations value in the device descriptor
  1052. //! array, pDeviceDescriptor.
  1053. //
  1054. const tConfigHeader * const *ppConfigDescriptors;
  1055. //
  1056. //! A pointer to the string descriptor array for this device. This array
  1057. //! must be arranged as follows:
  1058. //!
  1059. //! - [0] - Standard descriptor containing supported language codes.
  1060. //! - [1] - String 1 for the first language listed in descriptor 0.
  1061. //! - [2] - String 2 for the first language listed in descriptor 0.
  1062. //! - ...
  1063. //! - [n] - String n for the first language listed in descriptor 0.
  1064. //! - [n+1] - String 1 for the second language listed in descriptor 0.
  1065. //! - ...
  1066. //! - [2n] - String n for the second language listed in descriptor 0.
  1067. //! - [2n+1]- String 1 for the third language listed in descriptor 0.
  1068. //! - ...
  1069. //! - [3n] - String n for the third language listed in descriptor 0.
  1070. //!
  1071. //! and so on.
  1072. //
  1073. const unsigned char * const *ppStringDescriptors;
  1074. //
  1075. //! The total number of descriptors provided in the ppStringDescriptors
  1076. //! array.
  1077. //
  1078. unsigned int ulNumStringDescriptors;
  1079. //
  1080. //! A structure defining how the USB controller FIFO is to be partitioned
  1081. //! between the various endpoints. This member can be set to point to
  1082. //! g_sUSBDefaultFIFOConfig if the default FIFO configuration is acceptable
  1083. //! This configuration sets each endpoint FIFO to be single buffered and
  1084. //! sized to hold the maximum packet size for the endpoint.
  1085. //
  1086. const tFIFOConfig *psFIFOConfig;
  1087. //
  1088. //! This value will be passed back to all call back functions so that
  1089. //! they have access to individual instance data based on the this pointer.
  1090. //
  1091. void *pvInstance;
  1092. }
  1093. tDeviceInfo;
  1094. //*****************************************************************************
  1095. //
  1096. // Close the Doxygen group.
  1097. //! @}
  1098. //
  1099. //*****************************************************************************
  1100. //*****************************************************************************
  1101. //
  1102. //! \addtogroup general_usblib_api
  1103. //! @{
  1104. //
  1105. //*****************************************************************************
  1106. //*****************************************************************************
  1107. //
  1108. // USB descriptor parsing functions found in usbdesc.c
  1109. //
  1110. //*****************************************************************************
  1111. //*****************************************************************************
  1112. //
  1113. //! The USB_DESC_ANY label is used as a wild card in several of the descriptor
  1114. //! parsing APIs to determine whether or not particular search criteria should
  1115. //! be ignored.
  1116. //
  1117. //*****************************************************************************
  1118. #define USB_DESC_ANY 0xFFFFFFFF
  1119. extern unsigned int USBDescGetNum(tDescriptorHeader *psDesc,
  1120. unsigned int ulSize, unsigned int ulType);
  1121. extern tDescriptorHeader *USBDescGet(tDescriptorHeader *psDesc,
  1122. unsigned int ulSize,
  1123. unsigned int ulType,
  1124. unsigned int ulIndex);
  1125. extern unsigned int
  1126. USBDescGetNumAlternateInterfaces(tConfigDescriptor *psConfig,
  1127. unsigned char ucInterfaceNumber);
  1128. extern tInterfaceDescriptor *USBDescGetInterface(tConfigDescriptor *psConfig,
  1129. unsigned int ulIndex,
  1130. unsigned int ulAltCfg);
  1131. extern tEndpointDescriptor *
  1132. USBDescGetInterfaceEndpoint(tInterfaceDescriptor *psInterface,
  1133. unsigned int ulIndex,
  1134. unsigned int ulSize);
  1135. //*****************************************************************************
  1136. //
  1137. //! The operating mode required by the USB library client. This type is used
  1138. //! by applications which wish to be able to switch between host and device
  1139. //! modes by calling the USBStackModeSet() API.
  1140. //
  1141. //*****************************************************************************
  1142. typedef enum
  1143. {
  1144. //
  1145. //! The application wishes to operate as a USB device.
  1146. //
  1147. USB_MODE_DEVICE = 0,
  1148. //
  1149. //! The application wishes to operate as a USB host.
  1150. //
  1151. USB_MODE_HOST,
  1152. //
  1153. //! The application wishes to operate as both a host and device using
  1154. //! On-The-Go protocols to negotiate.
  1155. //
  1156. USB_MODE_OTG,
  1157. //
  1158. //! A marker indicating that no USB mode has yet been set by the
  1159. //! application.
  1160. //
  1161. USB_MODE_NONE
  1162. } tUSBMode;
  1163. //*****************************************************************************
  1164. //
  1165. // A pointer to a USB mode callback function. This function is called by the
  1166. // USB library to indicate to the application which operating mode it should
  1167. // use, host or device.
  1168. //
  1169. //*****************************************************************************
  1170. typedef void (*tUSBModeCallback)(unsigned int ulIndex, tUSBMode eMode);
  1171. //*****************************************************************************
  1172. //
  1173. // Mode selection and dual mode interrupt steering functions.
  1174. //
  1175. //*****************************************************************************
  1176. extern void USBStackModeSet(unsigned int ulIndex, tUSBMode eUSBMode,
  1177. tUSBModeCallback pfnCallback);
  1178. extern void USBDualModeInit(unsigned int ulIndex);
  1179. extern void USBDualModeTerm(unsigned int ulIndex);
  1180. extern void USBOTGMain(unsigned int ulMsTicks);
  1181. extern void USBOTGPollRate(unsigned int ulIndex, unsigned int ulPollRate);
  1182. extern void USBOTGModeInit(unsigned int ulIndex, unsigned int ulPollRate,
  1183. void *pHostData, unsigned int ulHostDataSize);
  1184. extern void USBOTGModeTerm(unsigned int ulIndex);
  1185. extern void USB0OTGModeIntHandler(void);
  1186. extern void USB0DualModeIntHandler(void);
  1187. //*****************************************************************************
  1188. //
  1189. //! USB callback function.
  1190. //!
  1191. //! \param pvCBData is the callback pointer associated with the instance
  1192. //! generating the callback. This is a value provided by the client during
  1193. //! initialization of the instance making the callback.
  1194. //! \param ulEvent is the identifier of the asynchronous event which is being
  1195. //! notified to the client.
  1196. //! \param ulMsgParam is an event-specific parameter.
  1197. //! \param pvMsgData is an event-specific data pointer.
  1198. //!
  1199. //! A function pointer provided to the USB layer by the application
  1200. //! which will be called to notify it of all asynchronous events relating to
  1201. //! data transmission or reception. This callback is used by device class
  1202. //! drivers and host pipe functions.
  1203. //!
  1204. //! \return Returns an event-dependent value.
  1205. //
  1206. //*****************************************************************************
  1207. typedef unsigned int (* tUSBCallback)(void *pvCBData, unsigned int ulEvent,
  1208. unsigned int ulMsgParam,
  1209. void *pvMsgData);
  1210. //*****************************************************************************
  1211. //
  1212. // Base identifiers for groups of USB events. These are used by both the
  1213. // device class drivers and host layer.
  1214. //
  1215. // USB_CLASS_EVENT_BASE is the lowest identifier that should be used for
  1216. // a class-specific event. Individual event bases are defined for each
  1217. // of the supported device class drivers. Events with IDs between
  1218. // USB_EVENT_BASE and USB_CLASS_EVENT_BASE are reserved for stack use.
  1219. //
  1220. //*****************************************************************************
  1221. #define USB_EVENT_BASE 0x0000
  1222. #define USB_CLASS_EVENT_BASE 0x8000
  1223. //*****************************************************************************
  1224. // The below macro defines the number USB Instances.
  1225. //
  1226. //*****************************************************************************
  1227. #define USB_NUM_INSTANCE USB_CONTROLLER_NUM_INSTANCES
  1228. //
  1229. // Event base identifiers for the various device classes supported in host
  1230. // and device modes.
  1231. // The first 0x800 values of a range are reserved for the device specific
  1232. // messages and the second 0x800 values of a range are used for the host
  1233. // specific messages for a given class.
  1234. //
  1235. //*****************************************************************************
  1236. #define USBD_CDC_EVENT_BASE (USB_CLASS_EVENT_BASE + 0)
  1237. #define USBD_HID_EVENT_BASE (USB_CLASS_EVENT_BASE + 0x1000)
  1238. #define USBD_HID_KEYB_EVENT_BASE (USBD_HID_EVENT_BASE + 0x100)
  1239. #define USBD_BULK_EVENT_BASE (USB_CLASS_EVENT_BASE + 0x2000)
  1240. #define USBD_MSC_EVENT_BASE (USB_CLASS_EVENT_BASE + 0x3000)
  1241. #define USBD_AUDIO_EVENT_BASE (USB_CLASS_EVENT_BASE + 0x4000)
  1242. #define USBH_CDC_EVENT_BASE (USBD_CDC_EVENT_BASE + 0x800)
  1243. #define USBH_HID_EVENT_BASE (USBD_HID_EVENT_BASE + 0x800)
  1244. #define USBH_BULK_EVENT_BASE (USBD_BULK_EVENT_BASE + 0x800)
  1245. #define USBH_MSC_EVENT_BASE (USBD_MSC_EVENT_BASE + 0x800)
  1246. #define USBH_AUDIO_EVENT_BASE (USBD_AUDIO_EVENT_BASE + 0x800)
  1247. //*****************************************************************************
  1248. //
  1249. // General events supported by device classes and host pipes.
  1250. //
  1251. //*****************************************************************************
  1252. //
  1253. //! The device is now attached to a USB host and ready to begin sending
  1254. //! and receiving data (used by device classes only).
  1255. //
  1256. #define USB_EVENT_CONNECTED (USB_EVENT_BASE + 0)
  1257. //
  1258. //! The device has been disconnected from the USB host (used by device classes
  1259. //! only).
  1260. //!
  1261. //! Note: Due to a hardware erratum in revision A of LM3S3748, this
  1262. //! event is not posted to self-powered USB devices when they are disconnected
  1263. //! from the USB host.
  1264. //
  1265. #define USB_EVENT_DISCONNECTED (USB_EVENT_BASE + 1)
  1266. //
  1267. //! Data has been received and is in the buffer provided.
  1268. //
  1269. #define USB_EVENT_RX_AVAILABLE (USB_EVENT_BASE + 2)
  1270. //
  1271. //! This event is sent by a lower layer to inquire about the amount of
  1272. //! unprocessed data buffered in the layers above. It is used in cases
  1273. //! where a low level driver needs to ensure that all preceding data has
  1274. //! been processed prior to performing some action or making some notification.
  1275. //! Clients receiving this event should return the number of bytes of data
  1276. //! that are unprocessed or 0 if no outstanding data remains.
  1277. //
  1278. #define USB_EVENT_DATA_REMAINING (USB_EVENT_BASE + 3)
  1279. //
  1280. //! This event is sent by a lower layer supporting DMA to request a buffer in
  1281. //! which the next received packet may be stored. The \e ulMsgValue parameter
  1282. //! indicates the maximum size of packet that can be received in this channel
  1283. //! and \e pvMsgData points to storage which should be written with the
  1284. //! returned buffer pointer. The return value from the callback should be the
  1285. //! size of the buffer allocated (which may be less than the maximum size
  1286. //! passed in \e ulMsgValue if the client knows that fewer bytes are expected
  1287. //! to be received) or 0 if no buffer is being returned.
  1288. //
  1289. #define USB_EVENT_REQUEST_BUFFER (USB_EVENT_BASE + 4)
  1290. //
  1291. //! Data has been sent and acknowledged. If this event is received via the
  1292. //! USB buffer callback, the \e ulMsgValue parameter indicates the number of
  1293. //! bytes from the transmit buffer that have been successfully transmitted
  1294. //! and acknowledged.
  1295. //
  1296. #define USB_EVENT_TX_COMPLETE (USB_EVENT_BASE + 5)
  1297. //
  1298. //! An error has been reported on the channel or pipe. The \e ulMsgValue
  1299. //! parameter indicates the source(s) of the error and is the logical OR
  1300. //! combination of "USBERR_" flags defined below.
  1301. //
  1302. #define USB_EVENT_ERROR (USB_EVENT_BASE + 6)
  1303. //
  1304. //! The bus has entered suspend state.
  1305. //
  1306. #define USB_EVENT_SUSPEND (USB_EVENT_BASE + 7)
  1307. //
  1308. //! The bus has left suspend state.
  1309. //
  1310. #define USB_EVENT_RESUME (USB_EVENT_BASE + 8)
  1311. //
  1312. //! A scheduler event has occurred.
  1313. //
  1314. #define USB_EVENT_SCHEDULER (USB_EVENT_BASE + 9)
  1315. //
  1316. //! A device or host has detected a stall condition.
  1317. //
  1318. #define USB_EVENT_STALL (USB_EVENT_BASE + 10)
  1319. //
  1320. //! The host detected a power fault condition.
  1321. //
  1322. #define USB_EVENT_POWER_FAULT (USB_EVENT_BASE + 11)
  1323. //
  1324. //! The controller has detected a A-Side cable and needs power applied This is
  1325. //! only generated on OTG parts if automatic power control is disabled.
  1326. //
  1327. #define USB_EVENT_POWER_ENABLE (USB_EVENT_BASE + 12)
  1328. //
  1329. //! The controller needs power removed, This is only generated on OTG parts
  1330. //! if automatic power control is disabled.
  1331. //
  1332. #define USB_EVENT_POWER_DISABLE (USB_EVENT_BASE + 13)
  1333. //
  1334. //! Used with pfnDeviceHandler handler function is classes to indicate changes
  1335. //! in the interface number by a class outside the class being accessed.
  1336. //! Typically this is when composite device class is in use.
  1337. //!
  1338. //! The \e pvInstance value should point to an instance of the device being
  1339. //! accessed.
  1340. //!
  1341. //! The \e ulRequest should be USB_EVENT_COMP_IFACE_CHANGE.
  1342. //!
  1343. //! The \e pvRequestData should point to a two byte array where the first value
  1344. //! is the old interface number and the second is the new interface number.
  1345. //
  1346. #define USB_EVENT_COMP_IFACE_CHANGE (USB_EVENT_BASE + 14)
  1347. //
  1348. //! Used with pfnDeviceHandler handler function is classes to indicate changes
  1349. //! in endpoint number by a class outside the class being accessed.
  1350. //! Typically this is when composite device class is in use.
  1351. //!
  1352. //! The \e pvInstance value should point to an instance of the device being
  1353. //! accessed.
  1354. //!
  1355. //! The \e ulRequest should be USB_EVENT_COMP_EP_CHANGE.
  1356. //!
  1357. //! The \e pvRequestData should point to a two byte array where the first value
  1358. //! is the old endpoint number and the second is the new endpoint number. The
  1359. //! endpoint numbers should be exactly as USB specification defines them and
  1360. //! bit 7 set indicates an IN endpoint and bit 7 clear indicates an OUT
  1361. //! endpoint.
  1362. //
  1363. #define USB_EVENT_COMP_EP_CHANGE (USB_EVENT_BASE + 15)
  1364. //
  1365. //! Used with pfnDeviceHandler handler function is classes to indicate changes
  1366. //! in string index number by a class outside the class being accessed.
  1367. //! Typically this is when composite device class is in use.
  1368. //!
  1369. //! The \e pvInstance value should point to an instance of the device being
  1370. //! accessed.
  1371. //!
  1372. //! The \e ulRequest should be USB_EVENT_COMP_STR_CHANGE.
  1373. //!
  1374. //! The \e pvRequestData should point to a two byte array where the first value
  1375. //! is the old string index and the second is the new string index.
  1376. //
  1377. #define USB_EVENT_COMP_STR_CHANGE (USB_EVENT_BASE + 16)
  1378. //
  1379. //! Used with pfnDeviceHandler handler function is classes to allow the device
  1380. //! class to make final adjustments to the configuration descriptor.
  1381. //! This is only used when a device class is used in a composite device class
  1382. //! is in use.
  1383. //!
  1384. //! The \e pvInstance value should point to an instance of the device being
  1385. //! accessed.
  1386. //!
  1387. //! The \e ulRequest should be USB_EVENT_COMP_CONFIG.
  1388. //!
  1389. //! The \e pvRequestData should point to the beginning of the configuration
  1390. //! descriptor for the device instance.
  1391. //
  1392. #define USB_EVENT_COMP_CONFIG (USB_EVENT_BASE + 17)
  1393. #define USB_EVENT_BABBLE_ERROR (USB_EVENT_BASE + 18)
  1394. //*****************************************************************************
  1395. //
  1396. // Error sources reported via USB_EVENT_ERROR.
  1397. //
  1398. //*****************************************************************************
  1399. //
  1400. //! The host received an invalid PID in a transaction.
  1401. //
  1402. #define USBERR_HOST_IN_PID_ERROR 0x01000000
  1403. //
  1404. //! The host did not receive a response from a device.
  1405. //
  1406. #define USBERR_HOST_IN_NOT_COMP 0x00100000
  1407. //
  1408. //! The host received a stall on an IN endpoint.
  1409. //
  1410. #define USBERR_HOST_IN_STALL 0x00400000
  1411. //
  1412. //! The host detected a CRC or bit-stuffing error (isochronous mode).
  1413. //
  1414. #define USBERR_HOST_IN_DATA_ERROR 0x00080000
  1415. //
  1416. //! The host received NAK on an IN endpoint for longer than the specified
  1417. //! timeout period (interrupt, bulk and control modes).
  1418. //
  1419. #define USBERR_HOST_IN_NAK_TO 0x00080000
  1420. //
  1421. //! The host failed to communicate with a device via an IN endpoint.
  1422. //
  1423. #define USBERR_HOST_IN_ERROR 0x00040000
  1424. //
  1425. //! The host receive FIFO is full.
  1426. //
  1427. #define USBERR_HOST_IN_FIFO_FULL 0x00020000 // RX FIFO full
  1428. //
  1429. //! The host received NAK on an OUT endpoint for longer than the specified
  1430. //! timeout period (bulk, interrupt and control modes).
  1431. //
  1432. #define USBERR_HOST_OUT_NAK_TO 0x00000080
  1433. //
  1434. //! The host did not receive a response from a device (isochronous mode).
  1435. //
  1436. #define USBERR_HOST_OUT_NOT_COMP 0x00000080
  1437. //
  1438. //! The host received a stall on an OUT endpoint.
  1439. //
  1440. #define USBERR_HOST_OUT_STALL 0x00000020
  1441. //
  1442. //! The host failed to communicate with a device via an OUT endpoint.
  1443. //
  1444. #define USBERR_HOST_OUT_ERROR 0x00000004
  1445. //
  1446. //! The host received NAK on endpoint 0 for longer than the configured
  1447. //! timeout.
  1448. //
  1449. #define USBERR_HOST_EP0_NAK_TO 0x00000080
  1450. //
  1451. //! The host failed to communicate with a device via an endpoint zero.
  1452. //
  1453. #define USBERR_HOST_EP0_ERROR 0x00000010
  1454. //
  1455. //! The device detected a CRC error in received data.
  1456. //
  1457. #define USBERR_DEV_RX_DATA_ERROR 0x00080000
  1458. //
  1459. //! The device was unable to receive a packet from the host since the receive
  1460. //! FIFO is full.
  1461. //
  1462. #define USBERR_DEV_RX_OVERRUN 0x00040000
  1463. //
  1464. //! The device receive FIFO is full.
  1465. //
  1466. #define USBERR_DEV_RX_FIFO_FULL 0x00020000 // RX FIFO full
  1467. //*****************************************************************************
  1468. //
  1469. // Close the general_usblib_api Doxygen group.
  1470. //! @}
  1471. //
  1472. //*****************************************************************************
  1473. //*****************************************************************************
  1474. //
  1475. //! \addtogroup usblib_buffer_api
  1476. //! @{
  1477. //
  1478. //*****************************************************************************
  1479. //*****************************************************************************
  1480. //
  1481. //! A function pointer type which describes either a class driver packet read
  1482. //! or packet write function (both have the same prototype) to the USB
  1483. //! buffer object.
  1484. //
  1485. //*****************************************************************************
  1486. typedef unsigned int (* tUSBPacketTransfer)(void *pvHandle,
  1487. unsigned char *pcData,
  1488. unsigned int ulLength,
  1489. tBoolean bLast);
  1490. //*****************************************************************************
  1491. //
  1492. //! A function pointer type which describes either a class driver transmit
  1493. //! or receive packet available function (both have the same prototype) to the
  1494. //! USB buffer object.
  1495. //
  1496. //*****************************************************************************
  1497. typedef unsigned int (* tUSBPacketAvailable)(void *pvHandle);
  1498. //*****************************************************************************
  1499. //
  1500. //! The number of bytes of workspace that each USB buffer object requires.
  1501. //! This workspace memory is provided to the buffer on USBBufferInit() in
  1502. //! the \e pvWorkspace field of the \e tUSBBuffer structure.
  1503. //
  1504. //*****************************************************************************
  1505. #define USB_BUFFER_WORKSPACE_SIZE 16
  1506. //*****************************************************************************
  1507. //
  1508. //! The structure used by the application to initialize a buffer object that
  1509. //! will provide buffered access to either a transmit or receive channel.
  1510. //
  1511. //*****************************************************************************
  1512. typedef struct
  1513. {
  1514. //
  1515. //! This field sets the mode of the buffer. If true, the buffer
  1516. //! operates as a transmit buffer and supports calls to USBBufferWrite
  1517. //! by the client. If false, the buffer operates as a receive buffer
  1518. //! and supports calls to USBBufferRead.
  1519. //
  1520. tBoolean bTransmitBuffer;
  1521. //
  1522. //! A pointer to the callback function which will be called to notify
  1523. //! the application of all asynchronous events related to the operation
  1524. //! of the buffer.
  1525. //
  1526. tUSBCallback pfnCallback;
  1527. //
  1528. //! A pointer that the buffer will pass back to the client in the
  1529. //! first parameter of all callbacks related to this instance.
  1530. //
  1531. void *pvCBData;
  1532. //
  1533. //! The function which should be called to transmit a packet of data
  1534. //! in transmit mode or receive a packet in receive mode.
  1535. //
  1536. tUSBPacketTransfer pfnTransfer;
  1537. //
  1538. //! The function which should be called to determine if the endpoint is
  1539. //! ready to accept a new packet for transmission in transmit mode or
  1540. //! to determine the size of the buffer required to read a packet in
  1541. //! receive mode.
  1542. //
  1543. tUSBPacketAvailable pfnAvailable;
  1544. //
  1545. //! The handle to pass to the low level function pointers
  1546. //! provided in the pfnTransfer and pfnAvailable members. For USB device
  1547. //! use, this is the psDevice parameter required by the relevant device
  1548. //! class driver APIs. For USB host use, this is the pipe identifier
  1549. //! returned by USBHCDPipeAlloc.
  1550. //
  1551. void *pvHandle;
  1552. //
  1553. //! A pointer to memory to be used as the ring buffer for this
  1554. //! instance.
  1555. //
  1556. unsigned char *pcBuffer;
  1557. //
  1558. //! The size, in bytes, of the buffer pointed to by pcBuffer.
  1559. //
  1560. unsigned int ulBufferSize;
  1561. //
  1562. //! A pointer to USB_BUFFER_WORKSPACE_SIZE bytes of RAM that the buffer
  1563. //! object can use for workspace.
  1564. //
  1565. void *pvWorkspace;
  1566. }
  1567. tUSBBuffer;
  1568. //*****************************************************************************
  1569. //
  1570. //! The structure used for encapsulating all the items associated with a
  1571. //! ring buffer.
  1572. //
  1573. //*****************************************************************************
  1574. typedef struct
  1575. {
  1576. //
  1577. //! The ring buffer size.
  1578. //
  1579. unsigned int ulSize;
  1580. //
  1581. //! The ring buffer write index.
  1582. //
  1583. volatile unsigned int ulWriteIndex;
  1584. //
  1585. //! The ring buffer read index.
  1586. //
  1587. volatile unsigned int ulReadIndex;
  1588. //
  1589. //! The ring buffer.
  1590. //
  1591. unsigned char *pucBuf;
  1592. }
  1593. tUSBRingBufObject;
  1594. typedef struct
  1595. {
  1596. //
  1597. //USB Instance Number;
  1598. //
  1599. unsigned int uiUSBInstance;
  1600. //
  1601. //Base address of the USB instance
  1602. //
  1603. unsigned int uiBaseAddr;
  1604. //
  1605. //Base address of the USB sub system
  1606. //
  1607. unsigned int uiSubBaseAddr;
  1608. //
  1609. //USB Interuppt number
  1610. //
  1611. unsigned int uiInterruptNum;
  1612. //
  1613. //USB subsystem interrupt number
  1614. //
  1615. unsigned int uiSubInterruptNum;
  1616. //
  1617. //PHY config register address
  1618. //
  1619. unsigned int uiPHYConfigRegAddr;
  1620. } tUSBInstanceObject;
  1621. extern tUSBInstanceObject g_USBInstance[];
  1622. typedef struct _tUSBPerfInfo_
  1623. {
  1624. unsigned int ulBytesToTransfer;
  1625. unsigned int ulTimeInTicks;
  1626. }tUSBPerfInfo;
  1627. extern tUSBPerfInfo g_USBPerfInfo[];
  1628. extern unsigned int ulPerfInfoCounter;
  1629. extern unsigned int fReadEnabled;
  1630. extern unsigned int fWriteEnabled;
  1631. extern unsigned int fUSBDisconnected;
  1632. //#define PROFILE_USB_MSC_READ
  1633. //#define PROFILE_USB_MSC_WRITE
  1634. //*****************************************************************************
  1635. //
  1636. // USB buffer API function prototypes.
  1637. //
  1638. //*****************************************************************************
  1639. extern const tUSBBuffer *USBBufferInit(const tUSBBuffer *psBuffer);
  1640. extern void USBBufferInfoGet(const tUSBBuffer *psBuffer,
  1641. tUSBRingBufObject *psRingBuf);
  1642. extern void *USBBufferCallbackDataSet(tUSBBuffer *psBuffer, void *pvCBData);
  1643. extern unsigned int USBBufferWrite(const tUSBBuffer *psBuffer,
  1644. const unsigned char *pucData,
  1645. unsigned int ulLength);
  1646. extern void USBBufferDataWritten(const tUSBBuffer *psBuffer,
  1647. unsigned int ulLength);
  1648. extern void USBBufferDataRemoved(const tUSBBuffer *psBuffer,
  1649. unsigned int ulLength);
  1650. extern void USBBufferFlush(const tUSBBuffer *psBuffer);
  1651. extern unsigned int USBBufferRead(const tUSBBuffer *psBuffer,
  1652. unsigned char *pucData,
  1653. unsigned int ulLength);
  1654. extern unsigned int USBBufferDataAvailable(const tUSBBuffer *psBuffer);
  1655. extern unsigned int USBBufferSpaceAvailable(const tUSBBuffer *psBuffer);
  1656. extern unsigned int USBBufferEventCallback(void *pvCBData,
  1657. unsigned int ulEvent,
  1658. unsigned int ulMsgValue,
  1659. void *pvMsgData);
  1660. extern tBoolean USBRingBufFull(tUSBRingBufObject *ptUSBRingBuf);
  1661. extern tBoolean USBRingBufEmpty(tUSBRingBufObject *ptUSBRingBuf);
  1662. extern void USBRingBufFlush(tUSBRingBufObject *ptUSBRingBuf);
  1663. extern unsigned int USBRingBufUsed(tUSBRingBufObject *ptUSBRingBuf);
  1664. extern unsigned int USBRingBufFree(tUSBRingBufObject *ptUSBRingBuf);
  1665. extern unsigned int USBRingBufContigUsed(tUSBRingBufObject *ptUSBRingBuf);
  1666. extern unsigned int USBRingBufContigFree(tUSBRingBufObject *ptUSBRingBuf);
  1667. extern unsigned int USBRingBufSize(tUSBRingBufObject *ptUSBRingBuf);
  1668. extern unsigned char USBRingBufReadOne(tUSBRingBufObject *ptUSBRingBuf);
  1669. extern void USBRingBufRead(tUSBRingBufObject *ptUSBRingBuf,
  1670. unsigned char *pucData, unsigned int ulLength);
  1671. extern void USBRingBufWriteOne(tUSBRingBufObject *ptUSBRingBuf,
  1672. unsigned char ucData);
  1673. extern void USBRingBufWrite(tUSBRingBufObject *ptUSBRingBuf,
  1674. const unsigned char *pucData,
  1675. unsigned int ulLength);
  1676. extern void USBRingBufAdvanceWrite(tUSBRingBufObject *ptUSBRingBuf,
  1677. unsigned int ulNumBytes);
  1678. extern void USBRingBufAdvanceRead(tUSBRingBufObject *ptUSBRingBuf,
  1679. unsigned int ulNumBytes);
  1680. extern void USBRingBufInit(tUSBRingBufObject *ptUSBRingBuf,
  1681. unsigned char *pucBuf, unsigned int ulSize);
  1682. //*****************************************************************************
  1683. //
  1684. // Close the Doxygen group.
  1685. //! @}
  1686. //
  1687. //*****************************************************************************
  1688. //*****************************************************************************
  1689. //
  1690. // Mark the end of the C bindings section for C++ compilers.
  1691. //
  1692. //*****************************************************************************
  1693. #ifdef __cplusplus
  1694. }
  1695. #endif
  1696. #endif // __USBLIB_H__