1
0

usb.c 129 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972
  1. //###########################################################################
  2. //
  3. // FILE: usb.c
  4. //
  5. // TITLE: Driver for the USB Interface.
  6. //
  7. //###########################################################################
  8. // $TI Release: F2837xD Support Library v3.05.00.00 $
  9. // $Release Date: Tue Jun 26 03:15:23 CDT 2018 $
  10. // $Copyright:
  11. // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/
  12. //
  13. // Redistribution and use in source and binary forms, with or without
  14. // modification, are permitted provided that the following conditions
  15. // are met:
  16. //
  17. // Redistributions of source code must retain the above copyright
  18. // notice, this list of conditions and the following disclaimer.
  19. //
  20. // Redistributions in binary form must reproduce the above copyright
  21. // notice, this list of conditions and the following disclaimer in the
  22. // documentation and/or other materials provided with the
  23. // distribution.
  24. //
  25. // Neither the name of Texas Instruments Incorporated nor the names of
  26. // its contributors may be used to endorse or promote products derived
  27. // from this software without specific prior written permission.
  28. //
  29. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  31. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  32. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  33. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  34. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  35. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  36. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  37. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. // $
  41. //###########################################################################
  42. //*****************************************************************************
  43. //
  44. //! \addtogroup usb_api
  45. //! @{
  46. //
  47. //*****************************************************************************
  48. #include <stdbool.h>
  49. #include <stdint.h>
  50. #include "inc/hw_ints.h"
  51. #include "inc/hw_memmap.h"
  52. #include "inc/hw_types.h"
  53. #include "inc/hw_usb.h"
  54. #include "driverlib/debug.h"
  55. #include "driverlib/interrupt.h"
  56. #include "driverlib/sysctl.h"
  57. #include "usb.h"
  58. //*****************************************************************************
  59. //
  60. // Amount to shift the RX interrupt sources by in the flags used in the
  61. // interrupt calls.
  62. //
  63. //*****************************************************************************
  64. #define USB_INTEP_RX_SHIFT 16
  65. //*****************************************************************************
  66. //
  67. // Amount to shift the RX endpoint status sources by in the flags used in the
  68. // calls.
  69. //
  70. //*****************************************************************************
  71. #define USB_RX_EPSTATUS_SHIFT 16
  72. //*****************************************************************************
  73. //
  74. // Converts from an endpoint specifier to the offset of the endpoint's
  75. // control/status registers.
  76. //
  77. //*****************************************************************************
  78. #define EP_OFFSET(Endpoint) (Endpoint - 0x10)
  79. //*****************************************************************************
  80. //
  81. // Sets one of the indexed registers.
  82. //
  83. // \param ui32Base specifies the USB module base address.
  84. // \param ui32Endpoint is the endpoint index to target for this write.
  85. // \param ui32IndexedReg is the indexed register to write to.
  86. // \param ui8Value is the value to write to the register.
  87. //
  88. // This function is used to access the indexed registers for each endpoint.
  89. // The only registers that are indexed are the FIFO configuration registers,
  90. // which are not used after configuration.
  91. //
  92. // \return None.
  93. //
  94. //*****************************************************************************
  95. static void
  96. _USBIndexWrite(uint32_t ui32Base, uint32_t ui32Endpoint,
  97. uint32_t ui32IndexedReg, uint32_t ui32Value, uint32_t ui32Size)
  98. {
  99. uint32_t ui32Index;
  100. //
  101. // Check the arguments.
  102. //
  103. ASSERT(ui32Base == USB0_BASE);
  104. ASSERT((ui32Endpoint == 0) || (ui32Endpoint == 1) || (ui32Endpoint == 2) ||
  105. (ui32Endpoint == 3));
  106. ASSERT((ui32Size == 1) || (ui32Size == 2));
  107. //
  108. // Save the old index in case it was in use.
  109. //
  110. ui32Index = HWREGB(ui32Base + USB_O_EPIDX);
  111. //
  112. // Set the index.
  113. //
  114. HWREGB(ui32Base + USB_O_EPIDX) = ui32Endpoint;
  115. //
  116. // Determine the size of the register value.
  117. //
  118. if(ui32Size == 1)
  119. {
  120. //
  121. // Set the value.
  122. //
  123. HWREGB(ui32Base + ui32IndexedReg) = ui32Value;
  124. }
  125. else
  126. {
  127. //
  128. // Set the value.
  129. //
  130. HWREGH(ui32Base + ui32IndexedReg) = ui32Value;
  131. }
  132. //
  133. // Restore the old index in case it was in use.
  134. //
  135. HWREGB(ui32Base + USB_O_EPIDX) = ui32Index;
  136. }
  137. //*****************************************************************************
  138. //
  139. // Reads one of the indexed registers.
  140. //
  141. // \param ui32Base specifies the USB module base address.
  142. // \param ui32Endpoint is the endpoint index to target for this write.
  143. // \param ui32IndexedReg is the indexed register to write to.
  144. //
  145. // This function is used internally to access the indexed registers for each
  146. // endpoint. The only registers that are indexed are the FIFO configuration
  147. // registers, which are not used after configuration.
  148. //
  149. // \return The value in the register requested.
  150. //
  151. //*****************************************************************************
  152. static uint32_t
  153. _USBIndexRead(uint32_t ui32Base, uint32_t ui32Endpoint,
  154. uint32_t ui32IndexedReg, uint32_t ui32Size)
  155. {
  156. uint8_t ui8Index;
  157. uint8_t ui8Value;
  158. //
  159. // Check the arguments.
  160. //
  161. ASSERT(ui32Base == USB0_BASE);
  162. ASSERT((ui32Endpoint == 0) || (ui32Endpoint == 1) || (ui32Endpoint == 2) ||
  163. (ui32Endpoint == 3));
  164. ASSERT((ui32Size == 1) || (ui32Size == 2));
  165. //
  166. // Save the old index in case it was in use.
  167. //
  168. ui8Index = HWREGB(ui32Base + USB_O_EPIDX);
  169. //
  170. // Set the index.
  171. //
  172. HWREGB(ui32Base + USB_O_EPIDX) = ui32Endpoint;
  173. //
  174. // Determine the size of the register value.
  175. //
  176. if(ui32Size == 1)
  177. {
  178. //
  179. // Get the value.
  180. //
  181. ui8Value = HWREGB(ui32Base + ui32IndexedReg);
  182. }
  183. else
  184. {
  185. //
  186. // Get the value.
  187. //
  188. ui8Value = HWREGH(ui32Base + ui32IndexedReg);
  189. }
  190. //
  191. // Restore the old index in case it was in use.
  192. //
  193. HWREGB(ui32Base + USB_O_EPIDX) = ui8Index;
  194. //
  195. // Return the register's value.
  196. //
  197. return(ui8Value);
  198. }
  199. //*****************************************************************************
  200. //
  201. //! Puts the USB bus in a suspended state.
  202. //!
  203. //! \param ui32Base specifies the USB module base address.
  204. //!
  205. //! When used in host mode, this function puts the USB bus in the suspended
  206. //! state.
  207. //!
  208. //! \note This function must only be called in host mode.
  209. //!
  210. //! \return None.
  211. //
  212. //*****************************************************************************
  213. void
  214. USBHostSuspend(uint32_t ui32Base)
  215. {
  216. //
  217. // Check the arguments.
  218. //
  219. ASSERT(ui32Base == USB0_BASE);
  220. //
  221. // Send the suspend signaling to the USB bus.
  222. //
  223. HWREGB(ui32Base + USB_O_POWER) |= USB_POWER_SUSPEND;
  224. }
  225. //*****************************************************************************
  226. //
  227. //! Handles the USB bus reset condition.
  228. //!
  229. //! \param ui32Base specifies the USB module base address.
  230. //! \param bStart specifies whether to start or stop signaling reset on the USB
  231. //! bus.
  232. //!
  233. //! When this function is called with the \e bStart parameter set to \b true,
  234. //! this function causes the start of a reset condition on the USB bus.
  235. //! The caller must then delay at least 20ms before calling this function
  236. //! again with the \e bStart parameter set to \b false.
  237. //!
  238. //! \note This function must only be called in host mode.
  239. //!
  240. //! \return None.
  241. //
  242. //*****************************************************************************
  243. void
  244. USBHostReset(uint32_t ui32Base, bool bStart)
  245. {
  246. //
  247. // Check the arguments.
  248. //
  249. ASSERT(ui32Base == USB0_BASE);
  250. //
  251. // Send a reset signal to the bus.
  252. //
  253. if(bStart)
  254. {
  255. HWREGB(ui32Base + USB_O_POWER) |= USB_POWER_RESET;
  256. }
  257. else
  258. {
  259. HWREGB(ui32Base + USB_O_POWER) &= ~USB_POWER_RESET;
  260. }
  261. }
  262. //*****************************************************************************
  263. //
  264. //! Handles the USB bus resume condition.
  265. //!
  266. //! \param ui32Base specifies the USB module base address.
  267. //! \param bStart specifies if the USB controller is entering or leaving the
  268. //! resume signaling state.
  269. //!
  270. //! When in device mode, this function brings the USB controller out of the
  271. //! suspend state. This call must first be made with the \e bStart parameter
  272. //! set to \b true to start resume signaling. The device application must
  273. //! then delay at least 10ms but not more than 15ms before calling this
  274. //! function with the \e bStart parameter set to \b false.
  275. //!
  276. //! When in host mode, this function signals devices to leave the suspend
  277. //! state. This call must first be made with the \e bStart parameter set to
  278. //! \b true to start resume signaling. The host application must then delay
  279. //! at least 20ms before calling this function with the \e bStart parameter set
  280. //! to \b false. This action causes the controller to complete the resume
  281. //! signaling on the USB bus.
  282. //!
  283. //! \return None.
  284. //
  285. //*****************************************************************************
  286. void
  287. USBHostResume(uint32_t ui32Base, bool bStart)
  288. {
  289. //
  290. // Check the arguments.
  291. //
  292. ASSERT(ui32Base == USB0_BASE);
  293. //
  294. // Send a resume signal to the bus.
  295. //
  296. if(bStart)
  297. {
  298. HWREGB(ui32Base + USB_O_POWER) |= USB_POWER_RESUME;
  299. }
  300. else
  301. {
  302. HWREGB(ui32Base + USB_O_POWER) &= ~USB_POWER_RESUME;
  303. }
  304. }
  305. //*****************************************************************************
  306. //
  307. //! Returns the current speed of the USB device connected.
  308. //!
  309. //! \param ui32Base specifies the USB module base address.
  310. //!
  311. //! This function returns the current speed of the USB bus in host mode.
  312. //!
  313. //! \b Example: Get the USB connection speed.
  314. //!
  315. //! \verbatim
  316. //! //
  317. //! // Get the connection speed of the device connected to the USB controller.
  318. //! //
  319. //! USBHostSpeedGet(USB0_BASE);
  320. //! \endverbatim
  321. //!
  322. //! \note This function must only be called in host mode.
  323. //!
  324. //! \return Returns one of the following: \b USB_LOW_SPEED, \b USB_FULL_SPEED,
  325. //! or \b USB_UNDEF_SPEED.
  326. //
  327. //*****************************************************************************
  328. uint32_t
  329. USBHostSpeedGet(uint32_t ui32Base)
  330. {
  331. //
  332. // Check the arguments.
  333. //
  334. ASSERT(ui32Base == USB0_BASE);
  335. //
  336. // If the Full Speed device bit is set, then this is a full speed device.
  337. //
  338. if(HWREGB(ui32Base + USB_O_DEVCTL) & USB_DEVCTL_FSDEV)
  339. {
  340. return(USB_FULL_SPEED);
  341. }
  342. //
  343. // If the Low Speed device bit is set, then this is a low speed device.
  344. //
  345. if(HWREGB(ui32Base + USB_O_DEVCTL) & USB_DEVCTL_LSDEV)
  346. {
  347. return(USB_LOW_SPEED);
  348. }
  349. //
  350. // The device speed is not known.
  351. //
  352. return(USB_UNDEF_SPEED);
  353. }
  354. //*****************************************************************************
  355. //
  356. //! Disables control interrupts on a given USB controller.
  357. //!
  358. //! \param ui32Base specifies the USB module base address.
  359. //! \param ui32Flags specifies which control interrupts to disable.
  360. //!
  361. //! This function disables the control interrupts for the USB controller
  362. //! specified by the \e ui32Base parameter. The \e ui32Flags parameter
  363. //! specifies which control interrupts to disable. The flags passed in the
  364. //! \e ui32Flags parameters must be the definitions that start with
  365. //! \b USB_INTCTRL_* and not any other \b USB_INT flags.
  366. //!
  367. //! \return None.
  368. //
  369. //*****************************************************************************
  370. void
  371. USBIntDisableControl(uint32_t ui32Base, uint32_t ui32Flags)
  372. {
  373. //
  374. // Check the arguments.
  375. //
  376. ASSERT(ui32Base == USB0_BASE);
  377. ASSERT((ui32Flags & ~(USB_INTCTRL_ALL)) == 0);
  378. //
  379. // If any general interrupts were disabled then write the general interrupt
  380. // settings out to the hardware.
  381. //
  382. if(ui32Flags & USB_INTCTRL_STATUS)
  383. {
  384. HWREGB(ui32Base + USB_O_IE) &= ~(ui32Flags & USB_INTCTRL_STATUS);
  385. }
  386. //
  387. // Disable the power fault interrupt.
  388. //
  389. if(ui32Flags & USB_INTCTRL_POWER_FAULT)
  390. {
  391. HWREG(ui32Base + USB_O_EPCIM) = 0;
  392. }
  393. //
  394. // Disable the ID pin detect interrupt.
  395. //
  396. if(ui32Flags & USB_INTCTRL_MODE_DETECT)
  397. {
  398. HWREG(USB0_BASE + USB_O_IDVIM) = 0;
  399. }
  400. }
  401. //*****************************************************************************
  402. //
  403. //! Enables control interrupts on a given USB controller.
  404. //!
  405. //! \param ui32Base specifies the USB module base address.
  406. //! \param ui32Flags specifies which control interrupts to enable.
  407. //!
  408. //! This function enables the control interrupts for the USB controller
  409. //! specified by the \e ui32Base parameter. The \e ui32Flags parameter
  410. //! specifies which control interrupts to enable. The flags passed in the
  411. //! \e ui32Flags parameters must be the definitions that start with
  412. //! \b USB_INTCTRL_* and not any other \b USB_INT flags.
  413. //!
  414. //! \return None.
  415. //
  416. //*****************************************************************************
  417. void
  418. USBIntEnableControl(uint32_t ui32Base, uint32_t ui32Flags)
  419. {
  420. //
  421. // Check the arguments.
  422. //
  423. ASSERT(ui32Base == USB0_BASE);
  424. ASSERT((ui32Flags & (~USB_INTCTRL_ALL)) == 0);
  425. //
  426. // If any general interrupts were enabled, then write the general
  427. // interrupt settings out to the hardware.
  428. //
  429. if(ui32Flags & USB_INTCTRL_STATUS)
  430. {
  431. HWREGB(ui32Base + USB_O_IE) |= ui32Flags;
  432. }
  433. //
  434. // Enable the power fault interrupt.
  435. //
  436. if(ui32Flags & USB_INTCTRL_POWER_FAULT)
  437. {
  438. HWREG(ui32Base + USB_O_EPCIM) = USB_EPCIM_PF;
  439. }
  440. //
  441. // Enable the ID pin detect interrupt.
  442. //
  443. if(ui32Flags & USB_INTCTRL_MODE_DETECT)
  444. {
  445. HWREG(USB0_BASE + USB_O_IDVIM) = USB_IDVIM_ID;
  446. }
  447. }
  448. //*****************************************************************************
  449. //
  450. //! Returns the control interrupt status on a given USB controller.
  451. //!
  452. //! \param ui32Base specifies the USB module base address.
  453. //! \param ui32IntStatusEP is a pointer to the variable which holds the
  454. //! endpoint interrupt status from RXIS And TXIS.
  455. //!
  456. //! This function reads control interrupt status for a USB controller. This
  457. //! call returns the current status for control interrupts only, the endpoint
  458. //! interrupt status is retrieved by calling USBIntStatusEndpoint(). The bit
  459. //! values returned are compared against the \b USB_INTCTRL_* values.
  460. //!
  461. //! The following are the meanings of all \b USB_INCTRL_ flags and the modes
  462. //! for which they are valid. These values apply to any calls to
  463. //! USBIntStatusControl(), USBIntEnableControl(), and USBIntDisableControl().
  464. //! Some of these flags are only valid in the following modes as indicated in
  465. //! the parentheses: Host, Device, and OTG.
  466. //!
  467. //! - \b USB_INTCTRL_ALL - A full mask of all control interrupt sources.
  468. //! - \b USB_INTCTRL_VBUS_ERR - A VBUS error has occurred (Host Only).
  469. //! - \b USB_INTCTRL_SESSION - Session Start Detected on A-side of cable
  470. //! (OTG Only).
  471. //! - \b USB_INTCTRL_SESSION_END - Session End Detected (Device Only)
  472. //! - \b USB_INTCTRL_DISCONNECT - Device Disconnect Detected (Host Only)
  473. //! - \b USB_INTCTRL_CONNECT - Device Connect Detected (Host Only)
  474. //! - \b USB_INTCTRL_SOF - Start of Frame Detected.
  475. //! - \b USB_INTCTRL_BABBLE - USB controller detected a device signaling past
  476. //! the end of a frame (Host Only)
  477. //! - \b USB_INTCTRL_RESET - Reset signaling detected by device (Device Only)
  478. //! - \b USB_INTCTRL_RESUME - Resume signaling detected.
  479. //! - \b USB_INTCTRL_SUSPEND - Suspend signaling detected by device (Device
  480. //! Only)
  481. //! - \b USB_INTCTRL_MODE_DETECT - OTG cable mode detection has completed
  482. //! (OTG Only)
  483. //! - \b USB_INTCTRL_POWER_FAULT - Power Fault detected (Host Only)
  484. //!
  485. //! \note This call clears the source of all of the control status interrupts.
  486. //!
  487. //! \return Returns the status of the control interrupts for a USB controller.
  488. //! This is the value of USBIS.
  489. //
  490. //*****************************************************************************
  491. uint32_t
  492. USBIntStatus(uint32_t ui32Base, uint32_t *pui32IntStatusEP)
  493. {
  494. uint32_t ui32Status = 0;
  495. *pui32IntStatusEP = 0;
  496. uint32_t usbis = 0;
  497. uint32_t rxis = 0;
  498. uint32_t txis = 0;
  499. //
  500. // Check the arguments.
  501. //
  502. ASSERT(ui32Base == USB0_BASE);
  503. //
  504. // Do-While to make sure that all status registers are cleared before continuing.
  505. // This eliminates the race condition which can cause the USB interrupt to stay high
  506. // and never get triggered again.
  507. //
  508. do
  509. {
  510. // Get the general interrupt status.
  511. usbis = (uint32_t)HWREGB(ui32Base + USB_O_IS);
  512. // Get the transmit interrupt status.
  513. txis = (uint32_t)HWREGH(ui32Base + USB_O_TXIS);
  514. // Get the receive interrupt status.
  515. rxis = (uint32_t)HWREGH(ui32Base + USB_O_RXIS);
  516. // Get the general interrupt status, these bits go into the upper 8 bits
  517. // of the returned value.
  518. ui32Status |= usbis;
  519. // Get the transmit interrupt status.
  520. *pui32IntStatusEP |= txis;
  521. // Get the receive interrupt status, these bits go into the second byte of
  522. // the returned value.
  523. *pui32IntStatusEP |= ((uint32_t)rxis << USB_INTEP_RX_SHIFT);
  524. } while(usbis != 0x0000 || txis != 0x0000 || rxis != 0x0000);
  525. //
  526. // Add the power fault status.
  527. //
  528. if(HWREG(ui32Base + USB_O_EPCISC) & USB_EPCISC_PF)
  529. {
  530. //
  531. // Indicate a power fault was detected.
  532. //
  533. ui32Status |= USB_INTCTRL_POWER_FAULT;
  534. //
  535. // Clear the power fault interrupt.
  536. //
  537. HWREGB(ui32Base + USB_O_EPCISC) |= USB_EPCISC_PF;
  538. }
  539. if(HWREG(USB0_BASE + USB_O_IDVISC) & USB_IDVRIS_ID)
  540. {
  541. //
  542. // Indicate an id detection.
  543. //
  544. ui32Status |= USB_INTCTRL_MODE_DETECT;
  545. //
  546. // Clear the id detection interrupt.
  547. //
  548. HWREG(USB0_BASE + USB_O_IDVISC) |= USB_IDVRIS_ID;
  549. }
  550. //
  551. // Return the combined interrupt status.
  552. //
  553. return(ui32Status);
  554. }
  555. //*****************************************************************************
  556. //
  557. //! Returns the control interrupt status on a given USB controller.
  558. //!
  559. //! \param ui32Base specifies the USB module base address.
  560. //!
  561. //! This function reads control interrupt status for a USB controller. This
  562. //! call returns the current status for control interrupts only, the endpoint
  563. //! interrupt status is retrieved by calling USBIntStatusEndpoint(). The bit
  564. //! values returned are compared against the \b USB_INTCTRL_* values.
  565. //!
  566. //! The following are the meanings of all \b USB_INCTRL_ flags and the modes
  567. //! for which they are valid. These values apply to any calls to
  568. //! USBIntStatusControl(), USBIntEnableControl(), and USBIntDisableControl().
  569. //! Some of these flags are only valid in the following modes as indicated in
  570. //! the parentheses: Host, Device, and OTG.
  571. //!
  572. //! - \b USB_INTCTRL_ALL - A full mask of all control interrupt sources.
  573. //! - \b USB_INTCTRL_VBUS_ERR - A VBUS error has occurred (Host Only).
  574. //! - \b USB_INTCTRL_SESSION - Session Start Detected on A-side of cable
  575. //! (OTG Only).
  576. //! - \b USB_INTCTRL_SESSION_END - Session End Detected (Device Only)
  577. //! - \b USB_INTCTRL_DISCONNECT - Device Disconnect Detected (Host Only)
  578. //! - \b USB_INTCTRL_CONNECT - Device Connect Detected (Host Only)
  579. //! - \b USB_INTCTRL_SOF - Start of Frame Detected.
  580. //! - \b USB_INTCTRL_BABBLE - USB controller detected a device signaling past
  581. //! the end of a frame (Host Only)
  582. //! - \b USB_INTCTRL_RESET - Reset signaling detected by device (Device Only)
  583. //! - \b USB_INTCTRL_RESUME - Resume signaling detected.
  584. //! - \b USB_INTCTRL_SUSPEND - Suspend signaling detected by device (Device
  585. //! Only)
  586. //! - \b USB_INTCTRL_MODE_DETECT - OTG cable mode detection has completed
  587. //! (OTG Only)
  588. //! - \b USB_INTCTRL_POWER_FAULT - Power Fault detected (Host Only)
  589. //!
  590. //! \note This call clears the source of all of the control status interrupts.
  591. //!
  592. //! \return Returns the status of the control interrupts for a USB controller.
  593. //
  594. //*****************************************************************************
  595. uint32_t
  596. USBIntStatusControl(uint32_t ui32Base)
  597. {
  598. uint32_t ui32Status;
  599. //
  600. // Check the arguments.
  601. //
  602. ASSERT(ui32Base == USB0_BASE);
  603. //
  604. // Get the general interrupt status, these bits go into the upper 8 bits
  605. // of the returned value.
  606. //
  607. ui32Status = HWREGB(ui32Base + USB_O_IS);
  608. //*ui32EPStatus = USBIntStatusEndpoint(ui32Base);
  609. //
  610. // Add the power fault status.
  611. //
  612. if(HWREG(ui32Base + USB_O_EPCISC) & USB_EPCISC_PF)
  613. {
  614. //
  615. // Indicate a power fault was detected.
  616. //
  617. ui32Status |= USB_INTCTRL_POWER_FAULT;
  618. //
  619. // Clear the power fault interrupt.
  620. //
  621. HWREGB(ui32Base + USB_O_EPCISC) |= USB_EPCISC_PF;
  622. }
  623. if(HWREG(USB0_BASE + USB_O_IDVISC) & USB_IDVRIS_ID)
  624. {
  625. //
  626. // Indicate an id detection.
  627. //
  628. ui32Status |= USB_INTCTRL_MODE_DETECT;
  629. //
  630. // Clear the id detection interrupt.
  631. //
  632. HWREG(USB0_BASE + USB_O_IDVISC) |= USB_IDVRIS_ID;
  633. }
  634. //
  635. // Return the combined interrupt status.
  636. //
  637. return(ui32Status);
  638. }
  639. //*****************************************************************************
  640. //
  641. //! Disables endpoint interrupts on a given USB controller.
  642. //!
  643. //! \param ui32Base specifies the USB module base address.
  644. //! \param ui32Flags specifies which endpoint interrupts to disable.
  645. //!
  646. //! This function disables endpoint interrupts for the USB controller specified
  647. //! by the \e ui32Base parameter. The \e ui32Flags parameter specifies which
  648. //! endpoint interrupts to disable. The flags passed in the \e ui32Flags
  649. //! parameters must be the definitions that start with \b USB_INTEP_* and not
  650. //! any other \b USB_INT flags.
  651. //!
  652. //! \return None.
  653. //
  654. //*****************************************************************************
  655. void
  656. USBIntDisableEndpoint(uint32_t ui32Base, uint32_t ui32Flags)
  657. {
  658. //
  659. // Check the arguments.
  660. //
  661. ASSERT(ui32Base == USB0_BASE);
  662. //
  663. // If any transmit interrupts were disabled, then write the transmit
  664. // interrupt settings out to the hardware.
  665. //
  666. HWREGH(ui32Base + USB_O_TXIE) &=
  667. ~(ui32Flags & (USB_INTEP_HOST_OUT | USB_INTEP_DEV_IN | USB_INTEP_0));
  668. //
  669. // If any receive interrupts were disabled, then write the receive
  670. // interrupt settings out to the hardware.
  671. //
  672. HWREGH(ui32Base + USB_O_RXIE) &=
  673. ~((ui32Flags & (USB_INTEP_HOST_IN | USB_INTEP_DEV_OUT)) >>
  674. USB_INTEP_RX_SHIFT);
  675. }
  676. //*****************************************************************************
  677. //
  678. //! Enables endpoint interrupts on a given USB controller.
  679. //!
  680. //! \param ui32Base specifies the USB module base address.
  681. //! \param ui32Flags specifies which endpoint interrupts to enable.
  682. //!
  683. //! This function enables endpoint interrupts for the USB controller specified
  684. //! by the \e ui32Base parameter. The \e ui32Flags parameter specifies which
  685. //! endpoint interrupts to enable. The flags passed in the \e ui32Flags
  686. //! parameters must be the definitions that start with \b USB_INTEP_* and not
  687. //! any other \b USB_INT flags.
  688. //!
  689. //! \return None.
  690. //
  691. //*****************************************************************************
  692. void
  693. USBIntEnableEndpoint(uint32_t ui32Base, uint32_t ui32Flags)
  694. {
  695. //
  696. // Check the arguments.
  697. //
  698. ASSERT(ui32Base == USB0_BASE);
  699. //
  700. // Enable any transmit endpoint interrupts.
  701. //
  702. HWREGH(ui32Base + USB_O_TXIE) |=
  703. ui32Flags & (USB_INTEP_HOST_OUT | USB_INTEP_DEV_IN | USB_INTEP_0);
  704. //
  705. // Enable any receive endpoint interrupts.
  706. //
  707. HWREGH(ui32Base + USB_O_RXIE) |=
  708. ((ui32Flags & (USB_INTEP_HOST_IN | USB_INTEP_DEV_OUT)) >>
  709. USB_INTEP_RX_SHIFT);
  710. }
  711. //*****************************************************************************
  712. //
  713. //! Returns the endpoint interrupt status on a given USB controller.
  714. //!
  715. //! \param ui32Base specifies the USB module base address.
  716. //!
  717. //! This function reads endpoint interrupt status for a USB controller. This
  718. //! call returns the current status for endpoint interrupts only, the control
  719. //! interrupt status is retrieved by calling USBIntStatusControl(). The bit
  720. //! values returned are compared against the \b USB_INTEP_* values.
  721. //! These values are grouped into classes for \b USB_INTEP_HOST_* and
  722. //! \b USB_INTEP_DEV_* values to handle both host and device modes with all
  723. //! endpoints.
  724. //!
  725. //! \note This call clears the source of all of the endpoint interrupts.
  726. //!
  727. //! \return Returns the status of the endpoint interrupts for a USB controller.
  728. //
  729. //*****************************************************************************
  730. uint32_t
  731. USBIntStatusEndpoint(uint32_t ui32Base)
  732. {
  733. uint32_t ui32Status;
  734. //
  735. // Check the arguments.
  736. //
  737. ASSERT(ui32Base == USB0_BASE);
  738. //
  739. // Get the transmit interrupt status.
  740. //
  741. ui32Status = HWREGH(ui32Base + USB_O_TXIS);
  742. ui32Status |= ((uint32_t)HWREGH(ui32Base + USB_O_RXIS) << USB_INTEP_RX_SHIFT);
  743. //
  744. // Return the combined interrupt status.
  745. //
  746. return(ui32Status);
  747. }
  748. //*****************************************************************************
  749. //
  750. //! Returns the interrupt number for a given USB module.
  751. //!
  752. //! \param ui32Base is the base address of the USB module.
  753. //!
  754. //! This function returns the interrupt number for the USB module with the base
  755. //! address passed in the \e ui32Base parameter.
  756. //!
  757. //! \return Returns the USB interrupt number or 0 if the interrupt does not
  758. //! exist.
  759. //
  760. //*****************************************************************************
  761. static uint32_t
  762. _USBIntNumberGet(uint32_t ui32Base)
  763. {
  764. return(INT_USB0);
  765. }
  766. //*****************************************************************************
  767. //
  768. //! Registers an interrupt handler for the USB controller.
  769. //!
  770. //! \param ui32Base specifies the USB module base address.
  771. //! \param pfnHandler is a pointer to the function to be called when a USB
  772. //! interrupt occurs.
  773. //!
  774. //! This function registers the handler to be called when a USB interrupt
  775. //! occurs and enables the global USB interrupt in the interrupt controller.
  776. //! The specific desired USB interrupts must be enabled via a separate call to
  777. //! USBIntEnable(). It is the interrupt handler's responsibility to clear the
  778. //! interrupt sources via calls to USBIntStatusControl() and
  779. //! USBIntStatusEndpoint().
  780. //!
  781. //! \sa IntRegister() for important information about registering interrupt
  782. //! handlers.
  783. //!
  784. //! \return None.
  785. //
  786. //*****************************************************************************
  787. void
  788. USBIntRegister(uint32_t ui32Base, void (*pfnHandler)(void))
  789. {
  790. uint32_t ui32Int;
  791. //
  792. // Check the arguments.
  793. //
  794. ASSERT(ui32Base == USB0_BASE);
  795. ui32Int = _USBIntNumberGet(ui32Base);
  796. ASSERT(ui32Int != 0);
  797. //
  798. // Register the interrupt handler.
  799. //
  800. IntRegister(ui32Int, pfnHandler);
  801. //
  802. // Enable the USB interrupt.
  803. //
  804. IntEnable(ui32Int);
  805. }
  806. //*****************************************************************************
  807. //
  808. //! Unregisters an interrupt handler for the USB controller.
  809. //!
  810. //! \param ui32Base specifies the USB module base address.
  811. //!
  812. //! This function unregisters the interrupt handler. This function also
  813. //! disables the USB interrupt in the interrupt controller.
  814. //!
  815. //! \sa IntRegister() for important information about registering or
  816. //! unregistering interrupt handlers.
  817. //!
  818. //! \return None.
  819. //
  820. //*****************************************************************************
  821. void
  822. USBIntUnregister(uint32_t ui32Base)
  823. {
  824. uint32_t ui32Int;
  825. //
  826. // Check the arguments.
  827. //
  828. ASSERT(ui32Base == USB0_BASE);
  829. ui32Int = _USBIntNumberGet(ui32Base);
  830. ASSERT(ui32Int != 0);
  831. //
  832. // Disable the USB interrupt.
  833. //
  834. IntDisable(ui32Int);
  835. //
  836. // Unregister the interrupt handler.
  837. //
  838. IntUnregister(ui32Int);
  839. }
  840. //*****************************************************************************
  841. //
  842. //! Returns the current status of an endpoint.
  843. //!
  844. //! \param ui32Base specifies the USB module base address.
  845. //! \param ui32Endpoint is the endpoint to access.
  846. //!
  847. //! This function returns the status of a given endpoint. If any of these
  848. //! status bits must be cleared, then the USBDevEndpointStatusClear() or the
  849. //! USBHostEndpointStatusClear() functions must be called.
  850. //!
  851. //! The following are the status flags for host mode:
  852. //!
  853. //! - \b USB_HOST_IN_PID_ERROR - PID error on the given endpoint.
  854. //! - \b USB_HOST_IN_NOT_COMP - The device failed to respond to an IN request.
  855. //! - \b USB_HOST_IN_STALL - A stall was received on an IN endpoint.
  856. //! - \b USB_HOST_IN_DATA_ERROR - There was a CRC or bit-stuff error on an IN
  857. //! endpoint in Isochronous mode.
  858. //! - \b USB_HOST_IN_NAK_TO - NAKs received on this IN endpoint for more than
  859. //! the specified timeout period.
  860. //! - \b USB_HOST_IN_ERROR - Failed to communicate with a device using this IN
  861. //! endpoint.
  862. //! - \b USB_HOST_IN_FIFO_FULL - This IN endpoint's FIFO is full.
  863. //! - \b USB_HOST_IN_PKTRDY - Data packet ready on this IN endpoint.
  864. //! - \b USB_HOST_OUT_NAK_TO - NAKs received on this OUT endpoint for more than
  865. //! the specified timeout period.
  866. //! - \b USB_HOST_OUT_NOT_COMP - The device failed to respond to an OUT
  867. //! request.
  868. //! - \b USB_HOST_OUT_STALL - A stall was received on this OUT endpoint.
  869. //! - \b USB_HOST_OUT_ERROR - Failed to communicate with a device using this
  870. //! OUT endpoint.
  871. //! - \b USB_HOST_OUT_FIFO_NE - This endpoint's OUT FIFO is not empty.
  872. //! - \b USB_HOST_OUT_PKTPEND - The data transfer on this OUT endpoint has not
  873. //! completed.
  874. //! - \b USB_HOST_EP0_NAK_TO - NAKs received on endpoint zero for more than the
  875. //! specified timeout period.
  876. //! - \b USB_HOST_EP0_ERROR - The device failed to respond to a request on
  877. //! endpoint zero.
  878. //! - \b USB_HOST_EP0_IN_STALL - A stall was received on endpoint zero for an
  879. //! IN transaction.
  880. //! - \b USB_HOST_EP0_IN_PKTRDY - Data packet ready on endpoint zero for an IN
  881. //! transaction.
  882. //!
  883. //! The following are the status flags for device mode:
  884. //!
  885. //! - \b USB_DEV_OUT_SENT_STALL - A stall was sent on this OUT endpoint.
  886. //! - \b USB_DEV_OUT_DATA_ERROR - There was a CRC or bit-stuff error on an OUT
  887. //! endpoint.
  888. //! - \b USB_DEV_OUT_OVERRUN - An OUT packet was not loaded due to a full FIFO.
  889. //! - \b USB_DEV_OUT_FIFO_FULL - The OUT endpoint's FIFO is full.
  890. //! - \b USB_DEV_OUT_PKTRDY - There is a data packet ready in the OUT
  891. //! endpoint's FIFO.
  892. //! - \b USB_DEV_IN_NOT_COMP - A larger packet was split up, more data to come.
  893. //! - \b USB_DEV_IN_SENT_STALL - A stall was sent on this IN endpoint.
  894. //! - \b USB_DEV_IN_UNDERRUN - Data was requested on the IN endpoint and no
  895. //! data was ready.
  896. //! - \b USB_DEV_IN_FIFO_NE - The IN endpoint's FIFO is not empty.
  897. //! - \b USB_DEV_IN_PKTPEND - The data transfer on this IN endpoint has not
  898. //! completed.
  899. //! - \b USB_DEV_EP0_SETUP_END - A control transaction ended before Data End
  900. //! condition was sent.
  901. //! - \b USB_DEV_EP0_SENT_STALL - A stall was sent on endpoint zero.
  902. //! - \b USB_DEV_EP0_IN_PKTPEND - The data transfer on endpoint zero has not
  903. //! completed.
  904. //! - \b USB_DEV_EP0_OUT_PKTRDY - There is a data packet ready in endpoint
  905. //! zero's OUT FIFO.
  906. //!
  907. //! \return The current status flags for the endpoint depending on mode.
  908. //
  909. //*****************************************************************************
  910. uint32_t
  911. USBEndpointStatus(uint32_t ui32Base, uint32_t ui32Endpoint)
  912. {
  913. uint32_t ui32Status;
  914. //
  915. // Check the arguments.
  916. //
  917. ASSERT(ui32Base == USB0_BASE);
  918. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  919. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  920. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  921. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  922. //
  923. // Get the TX portion of the endpoint status.
  924. //
  925. ui32Status = HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRL1);
  926. //
  927. // Get the RX portion of the endpoint status.
  928. //
  929. ui32Status |=
  930. (((uint32_t)HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRL1)) <<
  931. USB_RX_EPSTATUS_SHIFT);
  932. //
  933. // Return the endpoint status.
  934. //
  935. return(ui32Status);
  936. }
  937. //*****************************************************************************
  938. //
  939. //! Clears the status bits in this endpoint in host mode.
  940. //!
  941. //! \param ui32Base specifies the USB module base address.
  942. //! \param ui32Endpoint is the endpoint to access.
  943. //! \param ui32Flags are the status bits that are cleared.
  944. //!
  945. //! This function clears the status of any bits that are passed in the
  946. //! \e ui32Flags parameter. The \e ui32Flags parameter can take the value
  947. //! returned from the USBEndpointStatus() call.
  948. //!
  949. //! \note This function must only be called in host mode.
  950. //!
  951. //! \return None.
  952. //
  953. //*****************************************************************************
  954. void
  955. USBHostEndpointStatusClear(uint32_t ui32Base, uint32_t ui32Endpoint,
  956. uint32_t ui32Flags)
  957. {
  958. //
  959. // Check the arguments.
  960. //
  961. ASSERT(ui32Base == USB0_BASE);
  962. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  963. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  964. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  965. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  966. //
  967. // Clear the specified flags for the endpoint.
  968. //
  969. if(ui32Endpoint == USB_EP_0)
  970. {
  971. HWREGB(ui32Base + USB_O_CSRL0) &= ~ui32Flags;
  972. }
  973. else
  974. {
  975. HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
  976. ~ui32Flags;
  977. HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
  978. ~(ui32Flags >> USB_RX_EPSTATUS_SHIFT);
  979. }
  980. }
  981. //*****************************************************************************
  982. //
  983. //! Clears the status bits in this endpoint in device mode.
  984. //!
  985. //! \param ui32Base specifies the USB module base address.
  986. //! \param ui32Endpoint is the endpoint to access.
  987. //! \param ui32Flags are the status bits that are cleared.
  988. //!
  989. //! This function clears the status of any bits that are passed in the
  990. //! \e ui32Flags parameter. The \e ui32Flags parameter can take the value
  991. //! returned from the USBEndpointStatus() call.
  992. //!
  993. //! \note This function must only be called in device mode.
  994. //!
  995. //! \return None.
  996. //
  997. //*****************************************************************************
  998. void
  999. USBDevEndpointStatusClear(uint32_t ui32Base, uint32_t ui32Endpoint,
  1000. uint32_t ui32Flags)
  1001. {
  1002. //
  1003. // Check the arguments.
  1004. //
  1005. ASSERT(ui32Base == USB0_BASE);
  1006. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  1007. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  1008. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  1009. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  1010. //
  1011. // If this is endpoint 0, then the bits have different meaning and map
  1012. // into the TX memory location.
  1013. //
  1014. if(ui32Endpoint == USB_EP_0)
  1015. {
  1016. //
  1017. // Set the Serviced RxPktRdy bit to clear the RxPktRdy.
  1018. //
  1019. if(ui32Flags & USB_DEV_EP0_OUT_PKTRDY)
  1020. {
  1021. HWREGB(ui32Base + USB_O_CSRL0) |= USB_CSRL0_RXRDYC;
  1022. }
  1023. //
  1024. // Set the serviced Setup End bit to clear the SetupEnd status.
  1025. //
  1026. if(ui32Flags & USB_DEV_EP0_SETUP_END)
  1027. {
  1028. HWREGB(ui32Base + USB_O_CSRL0) |= USB_CSRL0_SETENDC;
  1029. }
  1030. //
  1031. // Clear the Sent Stall status flag.
  1032. //
  1033. if(ui32Flags & USB_DEV_EP0_SENT_STALL)
  1034. {
  1035. HWREGB(ui32Base + USB_O_CSRL0) &= ~(USB_DEV_EP0_SENT_STALL);
  1036. }
  1037. }
  1038. else
  1039. {
  1040. //
  1041. // Clear out any TX flags that were passed in. Only
  1042. // USB_DEV_TX_SENT_STALL and USB_DEV_TX_UNDERRUN must be cleared.
  1043. //
  1044. HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
  1045. ~(ui32Flags & (USB_DEV_TX_SENT_STALL | USB_DEV_TX_UNDERRUN));
  1046. //
  1047. // Clear out valid RX flags that were passed in. Only
  1048. // USB_DEV_RX_SENT_STALL, USB_DEV_RX_DATA_ERROR, and USB_DEV_RX_OVERRUN
  1049. // must be cleared.
  1050. //
  1051. HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
  1052. ~((ui32Flags & (USB_DEV_RX_SENT_STALL | USB_DEV_RX_DATA_ERROR |
  1053. USB_DEV_RX_OVERRUN)) >> USB_RX_EPSTATUS_SHIFT);
  1054. }
  1055. }
  1056. //*****************************************************************************
  1057. //
  1058. //! Sets the value data toggle on an endpoint in host mode.
  1059. //!
  1060. //! \param ui32Base specifies the USB module base address.
  1061. //! \param ui32Endpoint specifies the endpoint to reset the data toggle.
  1062. //! \param bDataToggle specifies whether to set the state to DATA0 or DATA1.
  1063. //! \param ui32Flags specifies whether to set the IN or OUT endpoint.
  1064. //!
  1065. //! This function is used to force the state of the data toggle in host mode.
  1066. //! If the value passed in the \e bDataToggle parameter is \b false, then the
  1067. //! data toggle is set to the DATA0 state, and if it is \b true it is set to
  1068. //! the DATA1 state. The \e ui32Flags parameter can be \b USB_EP_HOST_IN or
  1069. //! \b USB_EP_HOST_OUT to access the desired portion of this endpoint. The
  1070. //! \e ui32Flags parameter is ignored for endpoint zero.
  1071. //!
  1072. //! \note This function must only be called in host mode.
  1073. //!
  1074. //! \return None.
  1075. //
  1076. //*****************************************************************************
  1077. void
  1078. USBHostEndpointDataToggle(uint32_t ui32Base, uint32_t ui32Endpoint,
  1079. bool bDataToggle, uint32_t ui32Flags)
  1080. {
  1081. uint32_t ui32DataToggle;
  1082. //
  1083. // Check the arguments.
  1084. //
  1085. ASSERT(ui32Base == USB0_BASE);
  1086. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  1087. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  1088. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  1089. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  1090. //
  1091. // The data toggle defaults to DATA0.
  1092. //
  1093. ui32DataToggle = 0;
  1094. //
  1095. // See if the data toggle must be set to DATA1.
  1096. //
  1097. if(bDataToggle)
  1098. {
  1099. //
  1100. // Select the data toggle bit based on the endpoint.
  1101. //
  1102. if(ui32Endpoint == USB_EP_0)
  1103. {
  1104. ui32DataToggle = USB_CSRH0_DT;
  1105. }
  1106. else if(ui32Flags == USB_EP_HOST_IN)
  1107. {
  1108. ui32DataToggle = USB_RXCSRH1_DT;
  1109. }
  1110. else
  1111. {
  1112. ui32DataToggle = USB_TXCSRH1_DT;
  1113. }
  1114. }
  1115. //
  1116. // Set the data toggle based on the endpoint.
  1117. //
  1118. if(ui32Endpoint == USB_EP_0)
  1119. {
  1120. //
  1121. // Set the write enable and the bit value for endpoint zero.
  1122. //
  1123. HWREGB(ui32Base + USB_O_CSRH0) =
  1124. ((HWREGB(ui32Base + USB_O_CSRH0) &
  1125. ~(USB_CSRH0_DTWE | USB_CSRH0_DT)) |
  1126. (ui32DataToggle | USB_CSRH0_DTWE));
  1127. }
  1128. else if(ui32Flags == USB_EP_HOST_IN)
  1129. {
  1130. //
  1131. // Set the Write enable and the bit value for an IN endpoint.
  1132. //
  1133. HWREGB(ui32Base + USB_O_RXCSRH1 + EP_OFFSET(ui32Endpoint)) =
  1134. ((HWREGB(ui32Base + USB_O_RXCSRH1 + EP_OFFSET(ui32Endpoint)) &
  1135. ~(USB_RXCSRH1_DTWE | USB_RXCSRH1_DT)) |
  1136. (ui32DataToggle | USB_RXCSRH1_DTWE));
  1137. }
  1138. else
  1139. {
  1140. //
  1141. // Set the Write enable and the bit value for an OUT endpoint.
  1142. //
  1143. HWREGB(ui32Base + USB_O_TXCSRH1 + EP_OFFSET(ui32Endpoint)) =
  1144. ((HWREGB(ui32Base + USB_O_TXCSRH1 + EP_OFFSET(ui32Endpoint)) &
  1145. ~(USB_TXCSRH1_DTWE | USB_TXCSRH1_DT)) |
  1146. (ui32DataToggle | USB_TXCSRH1_DTWE));
  1147. }
  1148. }
  1149. //*****************************************************************************
  1150. //
  1151. //! Sets the data toggle on an endpoint to zero.
  1152. //!
  1153. //! \param ui32Base specifies the USB module base address.
  1154. //! \param ui32Endpoint specifies the endpoint to reset the data toggle.
  1155. //! \param ui32Flags specifies whether to access the IN or OUT endpoint.
  1156. //!
  1157. //! This function causes the USB controller to clear the data toggle for an
  1158. //! endpoint. This call is not valid for endpoint zero and can be made with
  1159. //! host or device controllers.
  1160. //!
  1161. //! The \e ui32Flags parameter must be one of \b USB_EP_HOST_OUT,
  1162. //! \b USB_EP_HOST_IN, \b USB_EP_DEV_OUT, or \b USB_EP_DEV_IN.
  1163. //!
  1164. //! \return None.
  1165. //
  1166. //*****************************************************************************
  1167. void
  1168. USBEndpointDataToggleClear(uint32_t ui32Base, uint32_t ui32Endpoint,
  1169. uint32_t ui32Flags)
  1170. {
  1171. //
  1172. // Check the arguments.
  1173. //
  1174. ASSERT(ui32Base == USB0_BASE);
  1175. ASSERT((ui32Endpoint == USB_EP_1) || (ui32Endpoint == USB_EP_2) ||
  1176. (ui32Endpoint == USB_EP_3) || (ui32Endpoint == USB_EP_4) ||
  1177. (ui32Endpoint == USB_EP_5) || (ui32Endpoint == USB_EP_6) ||
  1178. (ui32Endpoint == USB_EP_7));
  1179. //
  1180. // See if the transmit or receive data toggle must be cleared.
  1181. //
  1182. if(ui32Flags & (USB_EP_HOST_OUT | USB_EP_DEV_IN))
  1183. {
  1184. HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
  1185. USB_TXCSRL1_CLRDT;
  1186. }
  1187. else
  1188. {
  1189. HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
  1190. USB_RXCSRL1_CLRDT;
  1191. }
  1192. }
  1193. //*****************************************************************************
  1194. //
  1195. //! Stalls the specified endpoint in device mode.
  1196. //!
  1197. //! \param ui32Base specifies the USB module base address.
  1198. //! \param ui32Endpoint specifies the endpoint to stall.
  1199. //! \param ui32Flags specifies whether to stall the IN or OUT endpoint.
  1200. //!
  1201. //! This function causes the endpoint number passed in to go into a stall
  1202. //! condition. If the \e ui32Flags parameter is \b USB_EP_DEV_IN, then the
  1203. //! stall is issued on the IN portion of this endpoint. If the \e ui32Flags
  1204. //! parameter is \b USB_EP_DEV_OUT, then the stall is issued on the OUT portion
  1205. //! of this endpoint.
  1206. //!
  1207. //! \note This function must only be called in device mode.
  1208. //!
  1209. //! \return None.
  1210. //
  1211. //*****************************************************************************
  1212. void
  1213. USBDevEndpointStall(uint32_t ui32Base, uint32_t ui32Endpoint,
  1214. uint32_t ui32Flags)
  1215. {
  1216. //
  1217. // Check the arguments.
  1218. //
  1219. ASSERT(ui32Base == USB0_BASE);
  1220. ASSERT((ui32Flags & ~(USB_EP_DEV_IN | USB_EP_DEV_OUT)) == 0);
  1221. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  1222. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  1223. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  1224. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  1225. //
  1226. // Determine how to stall this endpoint.
  1227. //
  1228. if(ui32Endpoint == USB_EP_0)
  1229. {
  1230. //
  1231. // Perform a stall on endpoint zero.
  1232. //
  1233. HWREGB(ui32Base + USB_O_CSRL0) |= USB_CSRL0_STALL | USB_CSRL0_RXRDYC;
  1234. }
  1235. else if(ui32Flags == USB_EP_DEV_IN)
  1236. {
  1237. //
  1238. // Perform a stall on an IN endpoint.
  1239. //
  1240. HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
  1241. USB_TXCSRL1_STALL;
  1242. }
  1243. else
  1244. {
  1245. //
  1246. // Perform a stall on an OUT endpoint.
  1247. //
  1248. HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
  1249. USB_RXCSRL1_STALL;
  1250. }
  1251. }
  1252. //*****************************************************************************
  1253. //
  1254. //! Clears the stall condition on the specified endpoint in device mode.
  1255. //!
  1256. //! \param ui32Base specifies the USB module base address.
  1257. //! \param ui32Endpoint specifies which endpoint to remove the stall condition.
  1258. //! \param ui32Flags specifies whether to remove the stall condition from the
  1259. //! IN or the OUT portion of this endpoint.
  1260. //!
  1261. //! This function causes the endpoint number passed in to exit the stall
  1262. //! condition. If the \e ui32Flags parameter is \b USB_EP_DEV_IN, then the
  1263. //! stall is cleared on the IN portion of this endpoint. If the \e ui32Flags
  1264. //! parameter is \b USB_EP_DEV_OUT, then the stall is cleared on the OUT
  1265. //! portion of this endpoint.
  1266. //!
  1267. //! \note This function must only be called in device mode.
  1268. //!
  1269. //! \return None.
  1270. //
  1271. //*****************************************************************************
  1272. void
  1273. USBDevEndpointStallClear(uint32_t ui32Base, uint32_t ui32Endpoint,
  1274. uint32_t ui32Flags)
  1275. {
  1276. //
  1277. // Check the arguments.
  1278. //
  1279. ASSERT(ui32Base == USB0_BASE);
  1280. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  1281. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  1282. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  1283. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  1284. ASSERT((ui32Flags & ~(USB_EP_DEV_IN | USB_EP_DEV_OUT)) == 0);
  1285. //
  1286. // Determine how to clear the stall on this endpoint.
  1287. //
  1288. if(ui32Endpoint == USB_EP_0)
  1289. {
  1290. //
  1291. // Clear the stall on endpoint zero.
  1292. //
  1293. HWREGB(ui32Base + USB_O_CSRL0) &= ~USB_CSRL0_STALLED;
  1294. }
  1295. else if(ui32Flags == USB_EP_DEV_IN)
  1296. {
  1297. //
  1298. // Clear the stall on an IN endpoint.
  1299. //
  1300. HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
  1301. ~(USB_TXCSRL1_STALL | USB_TXCSRL1_STALLED);
  1302. //
  1303. // Reset the data toggle.
  1304. //
  1305. HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
  1306. USB_TXCSRL1_CLRDT;
  1307. }
  1308. else
  1309. {
  1310. //
  1311. // Clear the stall on an OUT endpoint.
  1312. //
  1313. HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
  1314. ~(USB_RXCSRL1_STALL | USB_RXCSRL1_STALLED);
  1315. //
  1316. // Reset the data toggle.
  1317. //
  1318. HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
  1319. USB_RXCSRL1_CLRDT;
  1320. }
  1321. }
  1322. //*****************************************************************************
  1323. //
  1324. //! Connects the USB controller to the bus in device mode.
  1325. //!
  1326. //! \param ui32Base specifies the USB module base address.
  1327. //!
  1328. //! This function causes the soft connect feature of the USB controller to
  1329. //! be enabled. Call USBDevDisconnect() to remove the USB device from the bus.
  1330. //!
  1331. //! \note This function must only be called in device mode.
  1332. //!
  1333. //! \return None.
  1334. //
  1335. //*****************************************************************************
  1336. void
  1337. USBDevConnect(uint32_t ui32Base)
  1338. {
  1339. //
  1340. // Check the arguments.
  1341. //
  1342. ASSERT(ui32Base == USB0_BASE);
  1343. //
  1344. // Enable connection to the USB bus.
  1345. //
  1346. HWREGB(ui32Base + USB_O_POWER) |= USB_POWER_SOFTCONN;
  1347. }
  1348. //*****************************************************************************
  1349. //
  1350. //! Removes the USB controller from the bus in device mode.
  1351. //!
  1352. //! \param ui32Base specifies the USB module base address.
  1353. //!
  1354. //! This function causes the soft connect feature of the USB controller to
  1355. //! remove the device from the USB bus. A call to USBDevConnect() is needed to
  1356. //! reconnect to the bus.
  1357. //!
  1358. //! \note This function must only be called in device mode.
  1359. //!
  1360. //! \return None.
  1361. //
  1362. //*****************************************************************************
  1363. void
  1364. USBDevDisconnect(uint32_t ui32Base)
  1365. {
  1366. //
  1367. // Check the arguments.
  1368. //
  1369. ASSERT(ui32Base == USB0_BASE);
  1370. //
  1371. // Disable connection to the USB bus.
  1372. //
  1373. HWREGB(ui32Base + USB_O_POWER) &= (~USB_POWER_SOFTCONN);
  1374. }
  1375. //*****************************************************************************
  1376. //
  1377. //! Sets the address in device mode.
  1378. //!
  1379. //! \param ui32Base specifies the USB module base address.
  1380. //! \param ui32Address is the address to use for a device.
  1381. //!
  1382. //! This function configures the device address on the USB bus. This address
  1383. //! was likely received via a SET ADDRESS command from the host controller.
  1384. //!
  1385. //! \note This function must only be called in device mode.
  1386. //!
  1387. //! \return None.
  1388. //
  1389. //*****************************************************************************
  1390. void
  1391. USBDevAddrSet(uint32_t ui32Base, uint32_t ui32Address)
  1392. {
  1393. //
  1394. // Check the arguments.
  1395. //
  1396. ASSERT(ui32Base == USB0_BASE);
  1397. //
  1398. // Set the function address in the correct location.
  1399. //
  1400. HWREGB(ui32Base + USB_O_FADDR) = (uint8_t)ui32Address;
  1401. }
  1402. //*****************************************************************************
  1403. //
  1404. //! Returns the current device address in device mode.
  1405. //!
  1406. //! \param ui32Base specifies the USB module base address.
  1407. //!
  1408. //! This function returns the current device address. This address was set
  1409. //! by a call to USBDevAddrSet().
  1410. //!
  1411. //! \note This function must only be called in device mode.
  1412. //!
  1413. //! \return The current device address.
  1414. //
  1415. //*****************************************************************************
  1416. uint32_t
  1417. USBDevAddrGet(uint32_t ui32Base)
  1418. {
  1419. //
  1420. // Check the arguments.
  1421. //
  1422. ASSERT(ui32Base == USB0_BASE);
  1423. //
  1424. // Return the function address.
  1425. //
  1426. return(HWREGB(ui32Base + USB_O_FADDR));
  1427. }
  1428. //*****************************************************************************
  1429. //
  1430. //! Sets the base configuration for a host endpoint.
  1431. //!
  1432. //! \param ui32Base specifies the USB module base address.
  1433. //! \param ui32Endpoint is the endpoint to access.
  1434. //! \param ui32MaxPayload is the maximum payload for this endpoint.
  1435. //! \param ui32NAKPollInterval is the either the NAK timeout limit or the
  1436. //! polling interval, depending on the type of endpoint.
  1437. //! \param ui32TargetEndpoint is the endpoint that the host endpoint is
  1438. //! targeting.
  1439. //! \param ui32Flags are used to configure other endpoint settings.
  1440. //!
  1441. //! This function sets the basic configuration for the transmit or receive
  1442. //! portion of an endpoint in host mode. The \e ui32Flags parameter determines
  1443. //! some of the configuration while the other parameters provide the rest. The
  1444. //! \e ui32Flags parameter determines whether this is an IN endpoint
  1445. //! (\b USB_EP_HOST_IN or \b USB_EP_DEV_IN) or an OUT endpoint
  1446. //! (\b USB_EP_HOST_OUT or \b USB_EP_DEV_OUT), whether this is a Full speed
  1447. //! endpoint (\b USB_EP_SPEED_FULL) or a Low speed endpoint
  1448. //! (\b USB_EP_SPEED_LOW).
  1449. //!
  1450. //! The \b USB_EP_MODE_ flags control the type of the endpoint.
  1451. //! - \b USB_EP_MODE_CTRL is a control endpoint.
  1452. //! - \b USB_EP_MODE_ISOC is an isochronous endpoint.
  1453. //! - \b USB_EP_MODE_BULK is a bulk endpoint.
  1454. //! - \b USB_EP_MODE_INT is an interrupt endpoint.
  1455. //!
  1456. //! The \e ui32NAKPollInterval parameter has different meanings based on the
  1457. //! \b USB_EP_MODE value and whether or not this call is being made for
  1458. //! endpoint zero or another endpoint. For endpoint zero or any Bulk
  1459. //! endpoints, this value always indicates the number of frames to allow a
  1460. //! device to NAK before considering it a timeout. If this endpoint is an
  1461. //! isochronous or interrupt endpoint, this value is the polling interval for
  1462. //! this endpoint.
  1463. //!
  1464. //! For interrupt endpoints, the polling interval is the number of frames
  1465. //! between interrupt IN requests to an endpoint and has a range of 1 to 255.
  1466. //! For isochronous endpoints this value represents a polling interval of
  1467. //! 2 ^ (\e ui32NAKPollInterval - 1) frames. When used as a NAK timeout, the
  1468. //! \e ui32NAKPollInterval value specifies 2 ^ (\e ui32NAKPollInterval - 1)
  1469. //! frames before issuing a time out.
  1470. //!
  1471. //! There are two special time out values that can be specified when setting
  1472. //! the \e ui32NAKPollInterval value. The first is \b MAX_NAK_LIMIT, which is
  1473. //! the maximum value that can be passed in this variable. The other is
  1474. //! \b DISABLE_NAK_LIMIT, which indicates that there is no limit on the
  1475. //! number of NAKs.
  1476. //!
  1477. //! The \b USB_EP_DMA_MODE_ flags enable the type of DMA used to access the
  1478. //! endpoint's data FIFOs. The choice of the DMA mode depends on how the DMA
  1479. //! controller is configured and how it is being used. See the ``Using USB
  1480. //! with the uDMA Controller'' section for more information on DMA
  1481. //! configuration.
  1482. //!
  1483. //! When configuring the OUT portion of an endpoint, the \b USB_EP_AUTO_SET bit
  1484. //! is specified to cause the transmission of data on the USB bus to start
  1485. //! as soon as the number of bytes specified by \e ui32MaxPayload has been
  1486. //! written into the OUT FIFO for this endpoint.
  1487. //!
  1488. //! When configuring the IN portion of an endpoint, the \b USB_EP_AUTO_REQUEST
  1489. //! bit can be specified to trigger the request for more data once the FIFO has
  1490. //! been drained enough to fit \e ui32MaxPayload bytes. The
  1491. //! \b USB_EP_AUTO_CLEAR bit can be used to clear the data packet ready flag
  1492. //! automatically once the data has been read from the FIFO. If this option is
  1493. //! not used, this flag must be manually cleared via a call to
  1494. //! USBDevEndpointStatusClear() or USBHostEndpointStatusClear().
  1495. //!
  1496. //! \note This function must only be called in host mode.
  1497. //!
  1498. //! \return None.
  1499. //
  1500. //*****************************************************************************
  1501. void
  1502. USBHostEndpointConfig(uint32_t ui32Base, uint32_t ui32Endpoint,
  1503. uint32_t ui32MaxPayload, uint32_t ui32NAKPollInterval,
  1504. uint32_t ui32TargetEndpoint, uint32_t ui32Flags)
  1505. {
  1506. uint32_t ui32Register;
  1507. //
  1508. // Check the arguments.
  1509. //
  1510. ASSERT(ui32Base == USB0_BASE);
  1511. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  1512. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  1513. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  1514. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  1515. ASSERT(ui32NAKPollInterval <= MAX_NAK_LIMIT);
  1516. //
  1517. // Endpoint zero is configured differently than the other endpoints, so see
  1518. // if this is endpoint zero.
  1519. //
  1520. if(ui32Endpoint == USB_EP_0)
  1521. {
  1522. //
  1523. // Set the NAK timeout.
  1524. //
  1525. HWREGB(ui32Base + USB_O_NAKLMT) = ui32NAKPollInterval;
  1526. //
  1527. // Set the transfer type information.
  1528. //
  1529. HWREGB(ui32Base + USB_O_TYPE0) =
  1530. ((ui32Flags & USB_EP_SPEED_FULL) ? USB_TYPE0_SPEED_FULL :
  1531. USB_TYPE0_SPEED_LOW);
  1532. }
  1533. else
  1534. {
  1535. //
  1536. // Start with the target endpoint.
  1537. //
  1538. ui32Register = ui32TargetEndpoint;
  1539. //
  1540. // Set the speed for the device using this endpoint.
  1541. //
  1542. if(ui32Flags & USB_EP_SPEED_FULL)
  1543. {
  1544. ui32Register |= USB_TXTYPE1_SPEED_FULL;
  1545. }
  1546. else
  1547. {
  1548. ui32Register |= USB_TXTYPE1_SPEED_LOW;
  1549. }
  1550. //
  1551. // Set the protocol for the device using this endpoint.
  1552. //
  1553. switch(ui32Flags & USB_EP_MODE_MASK)
  1554. {
  1555. //
  1556. // The bulk protocol is being used.
  1557. //
  1558. case USB_EP_MODE_BULK:
  1559. {
  1560. ui32Register |= USB_TXTYPE1_PROTO_BULK;
  1561. break;
  1562. }
  1563. //
  1564. // The isochronous protocol is being used.
  1565. //
  1566. case USB_EP_MODE_ISOC:
  1567. {
  1568. ui32Register |= USB_TXTYPE1_PROTO_ISOC;
  1569. break;
  1570. }
  1571. //
  1572. // The interrupt protocol is being used.
  1573. //
  1574. case USB_EP_MODE_INT:
  1575. {
  1576. ui32Register |= USB_TXTYPE1_PROTO_INT;
  1577. break;
  1578. }
  1579. //
  1580. // The control protocol is being used.
  1581. //
  1582. case USB_EP_MODE_CTRL:
  1583. {
  1584. ui32Register |= USB_TXTYPE1_PROTO_CTRL;
  1585. break;
  1586. }
  1587. }
  1588. //
  1589. // See if the transmit or receive endpoint is being configured.
  1590. //
  1591. if(ui32Flags & USB_EP_HOST_OUT)
  1592. {
  1593. //
  1594. // Set the transfer type information.
  1595. //
  1596. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXTYPE1) =
  1597. ui32Register;
  1598. //
  1599. // Set the NAK timeout or polling interval.
  1600. //
  1601. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXINTERVAL1) =
  1602. ui32NAKPollInterval;
  1603. //
  1604. // Set the Maximum Payload per transaction.
  1605. //
  1606. HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXMAXP1) =
  1607. ui32MaxPayload;
  1608. //
  1609. // Set the transmit control value to zero.
  1610. //
  1611. ui32Register = 0;
  1612. //
  1613. // Allow auto setting of TxPktRdy when max packet size has been
  1614. // loaded into the FIFO.
  1615. //
  1616. if(ui32Flags & USB_EP_AUTO_SET)
  1617. {
  1618. ui32Register |= USB_TXCSRH1_AUTOSET;
  1619. }
  1620. //
  1621. // Configure the DMA Mode.
  1622. //
  1623. if(ui32Flags & USB_EP_DMA_MODE_1)
  1624. {
  1625. ui32Register |= USB_TXCSRH1_DMAEN | USB_TXCSRH1_DMAMOD;
  1626. }
  1627. else if(ui32Flags & USB_EP_DMA_MODE_0)
  1628. {
  1629. ui32Register |= USB_TXCSRH1_DMAEN;
  1630. }
  1631. //
  1632. // Write out the transmit control value.
  1633. //
  1634. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRH1) =
  1635. (uint8_t)ui32Register;
  1636. }
  1637. else
  1638. {
  1639. //
  1640. // Set the transfer type information.
  1641. //
  1642. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXTYPE1) =
  1643. ui32Register;
  1644. //
  1645. // Set the NAK timeout or polling interval.
  1646. //
  1647. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXINTERVAL1) =
  1648. ui32NAKPollInterval;
  1649. //
  1650. // Set the Maximum Payload per transaction.
  1651. //
  1652. HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXMAXP1) =
  1653. ui32MaxPayload;
  1654. //
  1655. // Set the receive control value to zero.
  1656. //
  1657. ui32Register = 0;
  1658. //
  1659. // Allow auto clearing of RxPktRdy when packet of size max packet
  1660. // has been unloaded from the FIFO.
  1661. //
  1662. if(ui32Flags & USB_EP_AUTO_CLEAR)
  1663. {
  1664. ui32Register |= USB_RXCSRH1_AUTOCL;
  1665. }
  1666. //
  1667. // Allow auto generation of DMA requests.
  1668. //
  1669. if(ui32Flags & USB_EP_AUTO_REQUEST)
  1670. {
  1671. ui32Register |= USB_RXCSRH1_AUTORQ;
  1672. }
  1673. //
  1674. // Configure the DMA Mode.
  1675. //
  1676. if(ui32Flags & USB_EP_DMA_MODE_1)
  1677. {
  1678. ui32Register |= USB_RXCSRH1_DMAEN | USB_RXCSRH1_DMAMOD;
  1679. }
  1680. else if(ui32Flags & USB_EP_DMA_MODE_0)
  1681. {
  1682. ui32Register |= USB_RXCSRH1_DMAEN;
  1683. }
  1684. //
  1685. // Write out the receive control value.
  1686. //
  1687. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRH1) =
  1688. (uint8_t)ui32Register;
  1689. }
  1690. }
  1691. }
  1692. //*****************************************************************************
  1693. //
  1694. //! Sets the configuration for an endpoint.
  1695. //!
  1696. //! \param ui32Base specifies the USB module base address.
  1697. //! \param ui32Endpoint is the endpoint to access.
  1698. //! \param ui32MaxPacketSize is the maximum packet size for this endpoint.
  1699. //! \param ui32Flags are used to configure other endpoint settings.
  1700. //!
  1701. //! This function sets the basic configuration for an endpoint in device mode.
  1702. //! Endpoint zero does not have a dynamic configuration, so this function
  1703. //! must not be called for endpoint zero. The \e ui32Flags parameter
  1704. //! determines some of the configuration while the other parameters provide the
  1705. //! rest.
  1706. //!
  1707. //! The \b USB_EP_MODE_ flags define what the type is for the given endpoint.
  1708. //!
  1709. //! - \b USB_EP_MODE_CTRL is a control endpoint.
  1710. //! - \b USB_EP_MODE_ISOC is an isochronous endpoint.
  1711. //! - \b USB_EP_MODE_BULK is a bulk endpoint.
  1712. //! - \b USB_EP_MODE_INT is an interrupt endpoint.
  1713. //!
  1714. //! The \b USB_EP_DMA_MODE_ flags determine the type of DMA access to the
  1715. //! endpoint data FIFOs. The choice of the DMA mode depends on how the DMA
  1716. //! controller is configured and how it is being used. See the ``Using USB
  1717. //! with the uDMA Controller'' section for more information on DMA
  1718. //! configuration.
  1719. //!
  1720. //! When configuring an IN endpoint, the \b USB_EP_AUTO_SET bit can be
  1721. //! specified to cause the automatic transmission of data on the USB bus as
  1722. //! soon as \e ui32MaxPacketSize bytes of data are written into the FIFO for
  1723. //! this endpoint. This option is commonly used with DMA as no interaction is
  1724. //! required to start the transmission of data.
  1725. //!
  1726. //! When configuring an OUT endpoint, the \b USB_EP_AUTO_REQUEST bit is
  1727. //! specified to trigger the request for more data once the FIFO has been
  1728. //! drained enough to receive \e ui32MaxPacketSize more bytes of data. Also
  1729. //! for OUT endpoints, the \b USB_EP_AUTO_CLEAR bit can be used to clear the
  1730. //! data packet ready flag automatically once the data has been read from the
  1731. //! FIFO. If this option is not used, this flag must be manually cleared via a
  1732. //! call to USBDevEndpointStatusClear(). Both of these settings can be used to
  1733. //! remove the need for extra calls when using the controller in DMA mode.
  1734. //!
  1735. //! \note This function must only be called in device mode.
  1736. //!
  1737. //! \return None.
  1738. //
  1739. //*****************************************************************************
  1740. void
  1741. USBDevEndpointConfigSet(uint32_t ui32Base, uint32_t ui32Endpoint,
  1742. uint32_t ui32MaxPacketSize, uint32_t ui32Flags)
  1743. {
  1744. uint32_t ui32Register;
  1745. //
  1746. // Check the arguments.
  1747. //
  1748. ASSERT(ui32Base == USB0_BASE);
  1749. ASSERT((ui32Endpoint == USB_EP_1) || (ui32Endpoint == USB_EP_2) ||
  1750. (ui32Endpoint == USB_EP_3) || (ui32Endpoint == USB_EP_4) ||
  1751. (ui32Endpoint == USB_EP_5) || (ui32Endpoint == USB_EP_6) ||
  1752. (ui32Endpoint == USB_EP_7));
  1753. //
  1754. // Determine if a transmit or receive endpoint is being configured.
  1755. //
  1756. if(ui32Flags & USB_EP_DEV_IN)
  1757. {
  1758. //
  1759. // Set the maximum packet size.
  1760. //
  1761. HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXMAXP1) =
  1762. ui32MaxPacketSize;
  1763. //
  1764. // The transmit control value is zero unless options are enabled.
  1765. //
  1766. ui32Register = 0;
  1767. //
  1768. // Allow auto setting of TxPktRdy when max packet size has been loaded
  1769. // into the FIFO.
  1770. //
  1771. if(ui32Flags & USB_EP_AUTO_SET)
  1772. {
  1773. ui32Register |= USB_TXCSRH1_AUTOSET;
  1774. }
  1775. //
  1776. // Configure the DMA mode.
  1777. //
  1778. if(ui32Flags & USB_EP_DMA_MODE_1)
  1779. {
  1780. ui32Register |= USB_TXCSRH1_DMAEN | USB_TXCSRH1_DMAMOD;
  1781. }
  1782. else if(ui32Flags & USB_EP_DMA_MODE_0)
  1783. {
  1784. ui32Register |= USB_TXCSRH1_DMAEN;
  1785. }
  1786. //
  1787. // Enable isochronous mode if requested.
  1788. //
  1789. if((ui32Flags & USB_EP_MODE_MASK) == USB_EP_MODE_ISOC)
  1790. {
  1791. ui32Register |= USB_TXCSRH1_ISO;
  1792. }
  1793. //
  1794. // Write the transmit control value.
  1795. //
  1796. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRH1) =
  1797. (uint8_t)ui32Register;
  1798. //
  1799. // Reset the Data toggle to zero.
  1800. //
  1801. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRL1) =
  1802. USB_TXCSRL1_CLRDT;
  1803. }
  1804. else
  1805. {
  1806. //
  1807. // Set the MaxPacketSize.
  1808. //
  1809. HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXMAXP1) =
  1810. ui32MaxPacketSize;
  1811. //
  1812. // The receive control value is zero unless options are enabled.
  1813. //
  1814. ui32Register = 0;
  1815. //
  1816. // Allow auto clearing of RxPktRdy when packet of size max packet
  1817. // has been unloaded from the FIFO.
  1818. //
  1819. if(ui32Flags & USB_EP_AUTO_CLEAR)
  1820. {
  1821. ui32Register = USB_RXCSRH1_AUTOCL;
  1822. }
  1823. //
  1824. // Configure the DMA mode.
  1825. //
  1826. if(ui32Flags & USB_EP_DMA_MODE_1)
  1827. {
  1828. ui32Register |= USB_RXCSRH1_DMAEN | USB_RXCSRH1_DMAMOD;
  1829. }
  1830. else if(ui32Flags & USB_EP_DMA_MODE_0)
  1831. {
  1832. ui32Register |= USB_RXCSRH1_DMAEN;
  1833. }
  1834. //
  1835. // Enable isochronous mode if requested.
  1836. //
  1837. if((ui32Flags & USB_EP_MODE_MASK) == USB_EP_MODE_ISOC)
  1838. {
  1839. ui32Register |= USB_RXCSRH1_ISO;
  1840. }
  1841. //
  1842. // Write the receive control value.
  1843. //
  1844. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRH1) =
  1845. (uint8_t)ui32Register;
  1846. //
  1847. // Reset the Data toggle to zero.
  1848. //
  1849. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRL1) =
  1850. USB_RXCSRL1_CLRDT;
  1851. }
  1852. }
  1853. //*****************************************************************************
  1854. //
  1855. //! Gets the current configuration for an endpoint.
  1856. //!
  1857. //! \param ui32Base specifies the USB module base address.
  1858. //! \param ui32Endpoint is the endpoint to access.
  1859. //! \param pui32MaxPacketSize is a pointer which is written with the maximum
  1860. //! packet size for this endpoint.
  1861. //! \param pui32Flags is a pointer which is written with the current endpoint
  1862. //! settings. On entry to the function, this pointer must contain either
  1863. //! \b USB_EP_DEV_IN or \b USB_EP_DEV_OUT to indicate whether the IN or OUT
  1864. //! endpoint is to be queried.
  1865. //!
  1866. //! This function returns the basic configuration for an endpoint in device
  1867. //! mode. The values returned in \e *pui32MaxPacketSize and \e *pui32Flags are
  1868. //! equivalent to the \e ui32MaxPacketSize and \e ui32Flags previously passed
  1869. //! to USBDevEndpointConfigSet() for this endpoint.
  1870. //!
  1871. //! \note This function must only be called in device mode.
  1872. //!
  1873. //! \return None.
  1874. //
  1875. //*****************************************************************************
  1876. void
  1877. USBDevEndpointConfigGet(uint32_t ui32Base, uint32_t ui32Endpoint,
  1878. uint32_t *pui32MaxPacketSize, uint32_t *pui32Flags)
  1879. {
  1880. uint32_t ui32Register;
  1881. //
  1882. // Check the arguments.
  1883. //
  1884. ASSERT(ui32Base == USB0_BASE);
  1885. ASSERT(pui32MaxPacketSize && pui32Flags);
  1886. ASSERT((ui32Endpoint == USB_EP_1) || (ui32Endpoint == USB_EP_2) ||
  1887. (ui32Endpoint == USB_EP_3) || (ui32Endpoint == USB_EP_4) ||
  1888. (ui32Endpoint == USB_EP_5) || (ui32Endpoint == USB_EP_6) ||
  1889. (ui32Endpoint == USB_EP_7));
  1890. //
  1891. // Determine if a transmit or receive endpoint is being queried.
  1892. //
  1893. if(*pui32Flags & USB_EP_DEV_IN)
  1894. {
  1895. //
  1896. // Clear the flags other than the direction bit.
  1897. //
  1898. *pui32Flags = USB_EP_DEV_IN;
  1899. //
  1900. // Get the maximum packet size.
  1901. //
  1902. *pui32MaxPacketSize = (uint32_t)HWREGH(ui32Base +
  1903. EP_OFFSET(ui32Endpoint) +
  1904. USB_O_TXMAXP1);
  1905. //
  1906. // Get the current transmit control register value.
  1907. //
  1908. ui32Register = (uint32_t)HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) +
  1909. USB_O_TXCSRH1);
  1910. //
  1911. // Are we allowing auto setting of TxPktRdy when max packet size has
  1912. // been loaded into the FIFO?
  1913. //
  1914. if(ui32Register & USB_TXCSRH1_AUTOSET)
  1915. {
  1916. *pui32Flags |= USB_EP_AUTO_SET;
  1917. }
  1918. //
  1919. // Get the DMA mode.
  1920. //
  1921. if(ui32Register & USB_TXCSRH1_DMAEN)
  1922. {
  1923. if(ui32Register & USB_TXCSRH1_DMAMOD)
  1924. {
  1925. *pui32Flags |= USB_EP_DMA_MODE_1;
  1926. }
  1927. else
  1928. {
  1929. *pui32Flags |= USB_EP_DMA_MODE_0;
  1930. }
  1931. }
  1932. //
  1933. // Are we in isochronous mode?
  1934. //
  1935. if(ui32Register & USB_TXCSRH1_ISO)
  1936. {
  1937. *pui32Flags |= USB_EP_MODE_ISOC;
  1938. }
  1939. else
  1940. {
  1941. //
  1942. // The hardware doesn't differentiate between bulk, interrupt
  1943. // and control mode for the endpoint so we just set something
  1944. // that isn't isochronous. This protocol ensures that anyone
  1945. // modifying the returned flags in preparation for a call to
  1946. // USBDevEndpointConfigSet do not see an unexpected mode change.
  1947. // If they decode the returned mode, however, they may be in for
  1948. // a surprise.
  1949. //
  1950. *pui32Flags |= USB_EP_MODE_BULK;
  1951. }
  1952. }
  1953. else
  1954. {
  1955. //
  1956. // Clear the flags other than the direction bit.
  1957. //
  1958. *pui32Flags = USB_EP_DEV_OUT;
  1959. //
  1960. // Get the MaxPacketSize.
  1961. //
  1962. *pui32MaxPacketSize = (uint32_t)HWREGH(ui32Base +
  1963. EP_OFFSET(ui32Endpoint) +
  1964. USB_O_RXMAXP1);
  1965. //
  1966. // Get the current receive control register value.
  1967. //
  1968. ui32Register = (uint32_t)HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) +
  1969. USB_O_RXCSRH1);
  1970. //
  1971. // Are we allowing auto clearing of RxPktRdy when packet of size max
  1972. // packet has been unloaded from the FIFO?
  1973. //
  1974. if(ui32Register & USB_RXCSRH1_AUTOCL)
  1975. {
  1976. *pui32Flags |= USB_EP_AUTO_CLEAR;
  1977. }
  1978. //
  1979. // Get the DMA mode.
  1980. //
  1981. if(ui32Register & USB_RXCSRH1_DMAEN)
  1982. {
  1983. if(ui32Register & USB_RXCSRH1_DMAMOD)
  1984. {
  1985. *pui32Flags |= USB_EP_DMA_MODE_1;
  1986. }
  1987. else
  1988. {
  1989. *pui32Flags |= USB_EP_DMA_MODE_0;
  1990. }
  1991. }
  1992. //
  1993. // Are we in isochronous mode?
  1994. //
  1995. if(ui32Register & USB_RXCSRH1_ISO)
  1996. {
  1997. *pui32Flags |= USB_EP_MODE_ISOC;
  1998. }
  1999. else
  2000. {
  2001. //
  2002. // The hardware doesn't differentiate between bulk, interrupt
  2003. // and control mode for the endpoint so we just set something
  2004. // that isn't isochronous. This protocol ensures that anyone
  2005. // modifying the returned flags in preparation for a call to
  2006. // USBDevEndpointConfigSet do not see an unexpected mode change.
  2007. // If they decode the returned mode, however, they may be in for
  2008. // a surprise.
  2009. //
  2010. *pui32Flags |= USB_EP_MODE_BULK;
  2011. }
  2012. }
  2013. }
  2014. //*****************************************************************************
  2015. //
  2016. //! Sets the FIFO configuration for an endpoint.
  2017. //!
  2018. //! \param ui32Base specifies the USB module base address.
  2019. //! \param ui32Endpoint is the endpoint to access.
  2020. //! \param ui32FIFOAddress is the starting address for the FIFO.
  2021. //! \param ui32FIFOSize is the size of the FIFO specified by one of the
  2022. //! USB_FIFO_SZ_ values.
  2023. //! \param ui32Flags specifies what information to set in the FIFO
  2024. //! configuration.
  2025. //!
  2026. //! This function configures the starting FIFO RAM address and size of the FIFO
  2027. //! for a given endpoint. Endpoint zero does not have a dynamically
  2028. //! configurable FIFO, so this function must not be called for endpoint zero.
  2029. //! The \e ui32FIFOSize parameter must be one of the values in the
  2030. //! \b USB_FIFO_SZ_ values.
  2031. //!
  2032. //! The \e ui32FIFOAddress value must be a multiple of 8 bytes and directly
  2033. //! indicates the starting address in the USB controller's FIFO RAM. For
  2034. //! example, a value of 64 indicates that the FIFO starts 64 bytes into
  2035. //! the USB controller's FIFO memory. The \e ui32Flags value specifies whether
  2036. //! the endpoint's OUT or IN FIFO must be configured. If in host mode, use
  2037. //! \b USB_EP_HOST_OUT or \b USB_EP_HOST_IN, and if in device mode, use
  2038. //! \b USB_EP_DEV_OUT or \b USB_EP_DEV_IN.
  2039. //!
  2040. //! \return None.
  2041. //
  2042. //*****************************************************************************
  2043. void
  2044. USBFIFOConfigSet(uint32_t ui32Base, uint32_t ui32Endpoint,
  2045. uint32_t ui32FIFOAddress, uint32_t ui32FIFOSize,
  2046. uint32_t ui32Flags)
  2047. {
  2048. //
  2049. // Check the arguments.
  2050. //
  2051. ASSERT(ui32Base == USB0_BASE);
  2052. ASSERT((ui32Endpoint == USB_EP_1) || (ui32Endpoint == USB_EP_2) ||
  2053. (ui32Endpoint == USB_EP_3) || (ui32Endpoint == USB_EP_4) ||
  2054. (ui32Endpoint == USB_EP_5) || (ui32Endpoint == USB_EP_6) ||
  2055. (ui32Endpoint == USB_EP_7));
  2056. //
  2057. // See if the transmit or receive FIFO is being configured.
  2058. //
  2059. if(ui32Flags & (USB_EP_HOST_OUT | USB_EP_DEV_IN))
  2060. {
  2061. //
  2062. // Set the transmit FIFO location and size for this endpoint.
  2063. //
  2064. _USBIndexWrite(ui32Base, ui32Endpoint >> 4, USB_O_TXFIFOSZ,
  2065. ui32FIFOSize, 1);
  2066. _USBIndexWrite(ui32Base, ui32Endpoint >> 4, USB_O_TXFIFOADD,
  2067. ui32FIFOAddress >> 3, 2);
  2068. }
  2069. else
  2070. {
  2071. //
  2072. // Set the receive FIFO location and size for this endpoint.
  2073. //
  2074. _USBIndexWrite(ui32Base, ui32Endpoint >> 4, USB_O_RXFIFOSZ,
  2075. ui32FIFOSize, 1);
  2076. _USBIndexWrite(ui32Base, ui32Endpoint >> 4, USB_O_RXFIFOADD,
  2077. ui32FIFOAddress >> 3, 2);
  2078. }
  2079. }
  2080. //*****************************************************************************
  2081. //
  2082. //! Returns the FIFO configuration for an endpoint.
  2083. //!
  2084. //! \param ui32Base specifies the USB module base address.
  2085. //! \param ui32Endpoint is the endpoint to access.
  2086. //! \param pui32FIFOAddress is the starting address for the FIFO.
  2087. //! \param pui32FIFOSize is the size of the FIFO as specified by one of the
  2088. //! USB_FIFO_SZ_ values.
  2089. //! \param ui32Flags specifies what information to retrieve from the FIFO
  2090. //! configuration.
  2091. //!
  2092. //! This function returns the starting address and size of the FIFO for a
  2093. //! given endpoint. Endpoint zero does not have a dynamically configurable
  2094. //! FIFO, so this function must not be called for endpoint zero. The
  2095. //! \e ui32Flags parameter specifies whether the endpoint's OUT or IN FIFO must
  2096. //! be read. If in host mode, the \e ui32Flags parameter must be
  2097. //! \b USB_EP_HOST_OUT or \b USB_EP_HOST_IN, and if in device mode, the
  2098. //! \e ui32Flags parameter must be either \b USB_EP_DEV_OUT or
  2099. //! \b USB_EP_DEV_IN.
  2100. //!
  2101. //! \return None.
  2102. //
  2103. //*****************************************************************************
  2104. void
  2105. USBFIFOConfigGet(uint32_t ui32Base, uint32_t ui32Endpoint,
  2106. uint32_t *pui32FIFOAddress, uint32_t *pui32FIFOSize,
  2107. uint32_t ui32Flags)
  2108. {
  2109. //
  2110. // Check the arguments.
  2111. //
  2112. ASSERT(ui32Base == USB0_BASE);
  2113. ASSERT((ui32Endpoint == USB_EP_1) || (ui32Endpoint == USB_EP_2) ||
  2114. (ui32Endpoint == USB_EP_3) || (ui32Endpoint == USB_EP_4) ||
  2115. (ui32Endpoint == USB_EP_5) || (ui32Endpoint == USB_EP_6) ||
  2116. (ui32Endpoint == USB_EP_7));
  2117. //
  2118. // See if the transmit or receive FIFO is being configured.
  2119. //
  2120. if(ui32Flags & (USB_EP_HOST_OUT | USB_EP_DEV_IN))
  2121. {
  2122. //
  2123. // Get the transmit FIFO location and size for this endpoint.
  2124. //
  2125. *pui32FIFOAddress = (_USBIndexRead(ui32Base, ui32Endpoint >> 4,
  2126. (uint32_t)USB_O_TXFIFOADD,
  2127. 2)) << 3;
  2128. *pui32FIFOSize = _USBIndexRead(ui32Base, ui32Endpoint >> 4,
  2129. (uint32_t)USB_O_TXFIFOSZ, 1);
  2130. }
  2131. else
  2132. {
  2133. //
  2134. // Get the receive FIFO location and size for this endpoint.
  2135. //
  2136. *pui32FIFOAddress = (_USBIndexRead(ui32Base, ui32Endpoint >> 4,
  2137. (uint32_t)USB_O_RXFIFOADD,
  2138. 2)) << 3;
  2139. *pui32FIFOSize = _USBIndexRead(ui32Base, ui32Endpoint >> 4,
  2140. (uint32_t)USB_O_RXFIFOSZ, 1);
  2141. }
  2142. }
  2143. //*****************************************************************************
  2144. //
  2145. //! Configure the DMA settings for an endpoint.
  2146. //!
  2147. //! \param ui32Base specifies the USB module base address.
  2148. //! \param ui32Endpoint is the endpoint to access.
  2149. //! \param ui32Config specifies the configuration options for an endpoint.
  2150. //!
  2151. //! This function configures the DMA settings for a given endpoint without
  2152. //! changing other options that may already be configured. In order for the
  2153. //! DMA transfer to be enabled, the USBEndpointDMAEnable() function must be
  2154. //! called before starting the DMA transfer. The configuration
  2155. //! options are passed in the \e ui32Config parameter and can have the values
  2156. //! described below.
  2157. //!
  2158. //! One of the following values to specify direction:
  2159. //! - \b USB_EP_HOST_OUT or \b USB_EP_DEV_IN - This setting is used with
  2160. //! DMA transfers from memory to the USB controller.
  2161. //! - \b USB_EP_HOST_IN or \b USB_EP_DEV_OUT - This setting is used with
  2162. //! DMA transfers from the USB controller to memory.
  2163. //!
  2164. //! One of the following values:
  2165. //! - \b USB_EP_DMA_MODE_0(default) - This setting is typically used for
  2166. //! transfers that do not span multiple packets or when interrupts are
  2167. //! required for each packet.
  2168. //! - \b USB_EP_DMA_MODE_1 - This setting is typically used for
  2169. //! transfers that span multiple packets and do not require interrupts
  2170. //! between packets.
  2171. //!
  2172. //! Values only used with \b USB_EP_HOST_OUT or \b USB_EP_DEV_IN:
  2173. //! - \b USB_EP_AUTO_SET - This setting is used to allow transmit DMA transfers
  2174. //! to automatically be sent when a full packet is loaded into a FIFO.
  2175. //! This is needed with \b USB_EP_DMA_MODE_1 to ensure that packets go
  2176. //! out when the FIFO becomes full and the DMA has more data to send.
  2177. //!
  2178. //! Values only used with \b USB_EP_HOST_IN or \b USB_EP_DEV_OUT:
  2179. //! - \b USB_EP_AUTO_CLEAR - This setting is used to allow receive DMA
  2180. //! transfers to automatically be acknowledged as they are received. This is
  2181. //! needed with \b USB_EP_DMA_MODE_1 to ensure that packets continue to
  2182. //! be received and acknowledged when the FIFO is emptied by the DMA
  2183. //! transfer.
  2184. //!
  2185. //! Values only used with \b USB_EP_HOST_IN:
  2186. //! - \b USB_EP_AUTO_REQUEST - This setting is used to allow receive DMA
  2187. //! transfers to automatically request a new IN transaction when the
  2188. //! previous transfer has emptied the FIFO. This is typically used in
  2189. //! conjunction with \b USB_EP_AUTO_CLEAR so that receive DMA transfers
  2190. //! can continue without interrupting the main processor.
  2191. //!
  2192. //! \b Example: Set endpoint 1 receive endpoint to automatically acknowledge
  2193. //! request and automatically generate a new IN request in host mode.
  2194. //!
  2195. //! \verbatim
  2196. //! //
  2197. //! // Configure endpoint 1 for receiving multiple packets using DMA.
  2198. //! //
  2199. //! USBEndpointDMAConfigSet(USB0_BASE, USB_EP_1, USB_EP_HOST_IN |
  2200. //! USB_EP_DMA_MODE_1 |
  2201. //! USB_EP_AUTO_CLEAR |
  2202. //! USB_EP_AUTO_REQUEST);
  2203. //! \endverbatim
  2204. //!
  2205. //! \b Example: Set endpoint 2 transmit endpoint to automatically send each
  2206. //! packet in host mode when spanning multiple packets.
  2207. //!
  2208. //! \verbatim
  2209. //! //
  2210. //! // Configure endpoint 1 for transmitting multiple packets using DMA.
  2211. //! //
  2212. //! USBEndpointDMAConfigSet(USB0_BASE, USB_EP_2, USB_EP_HOST_OUT |
  2213. //! USB_EP_DMA_MODE_1 |
  2214. //! USB_EP_AUTO_SET);
  2215. //! \endverbatim
  2216. //!
  2217. //! \return None.
  2218. //
  2219. //*****************************************************************************
  2220. void
  2221. USBEndpointDMAConfigSet(uint32_t ui32Base, uint32_t ui32Endpoint,
  2222. uint32_t ui32Config)
  2223. {
  2224. uint32_t ui32NewConfig;
  2225. if(ui32Config & USB_EP_HOST_OUT)
  2226. {
  2227. //
  2228. // Clear mode and DMA enable.
  2229. //
  2230. ui32NewConfig =
  2231. (HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRH1) &
  2232. ~(USB_TXCSRH1_DMAMOD | USB_TXCSRH1_AUTOSET));
  2233. if(ui32Config & USB_EP_DMA_MODE_1)
  2234. {
  2235. ui32NewConfig |= USB_TXCSRH1_DMAMOD;
  2236. }
  2237. if(ui32Config & USB_EP_AUTO_SET)
  2238. {
  2239. ui32NewConfig |= USB_TXCSRH1_AUTOSET;
  2240. }
  2241. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRH1) =
  2242. ui32NewConfig;
  2243. }
  2244. else
  2245. {
  2246. ui32NewConfig =
  2247. (HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRH1) &
  2248. ~(USB_RXCSRH1_AUTORQ | USB_RXCSRH1_AUTOCL | USB_RXCSRH1_DMAMOD));
  2249. if(ui32Config & USB_EP_DMA_MODE_1)
  2250. {
  2251. ui32NewConfig |= USB_RXCSRH1_DMAMOD;
  2252. }
  2253. if(ui32Config & USB_EP_AUTO_CLEAR)
  2254. {
  2255. ui32NewConfig |= USB_RXCSRH1_AUTOCL;
  2256. }
  2257. if(ui32Config & USB_EP_AUTO_REQUEST)
  2258. {
  2259. ui32NewConfig |= USB_RXCSRH1_AUTORQ;
  2260. }
  2261. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRH1) =
  2262. ui32NewConfig;
  2263. }
  2264. }
  2265. //*****************************************************************************
  2266. //
  2267. //! Enable DMA on a given endpoint.
  2268. //!
  2269. //! \param ui32Base specifies the USB module base address.
  2270. //! \param ui32Endpoint is the endpoint to access.
  2271. //! \param ui32Flags specifies which direction and what mode to use when
  2272. //! enabling DMA.
  2273. //!
  2274. //! This function enables DMA on a given endpoint and configures the mode
  2275. //! according to the values in the \e ui32Flags parameter. The \e ui32Flags
  2276. //! parameter must have \b USB_EP_DEV_IN or \b USB_EP_DEV_OUT set. Once this
  2277. //! function is called the only DMA or error interrupts are generated by the
  2278. //! USB controller.
  2279. //!
  2280. //! \note If this function is called when an endpoint is configured in DMA
  2281. //! mode 0 the USB controller does not generate an interrupt.
  2282. //!
  2283. //! \return None.
  2284. //
  2285. //*****************************************************************************
  2286. void
  2287. USBEndpointDMAEnable(uint32_t ui32Base, uint32_t ui32Endpoint,
  2288. uint32_t ui32Flags)
  2289. {
  2290. //
  2291. // See if the transmit DMA is being enabled.
  2292. //
  2293. if(ui32Flags & USB_EP_DEV_IN)
  2294. {
  2295. //
  2296. // Enable DMA on the transmit endpoint.
  2297. //
  2298. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRH1) |=
  2299. USB_TXCSRH1_DMAEN;
  2300. }
  2301. else
  2302. {
  2303. //
  2304. // Enable DMA on the receive endpoint.
  2305. //
  2306. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRH1) |=
  2307. USB_RXCSRH1_DMAEN;
  2308. }
  2309. }
  2310. //*****************************************************************************
  2311. //
  2312. //! Disable DMA on a given endpoint.
  2313. //!
  2314. //! \param ui32Base specifies the USB module base address.
  2315. //! \param ui32Endpoint is the endpoint to access.
  2316. //! \param ui32Flags specifies which direction to disable.
  2317. //!
  2318. //! This function disables DMA on a given endpoint to allow non-DMA USB
  2319. //! transactions to generate interrupts normally. The \e ui32Flags parameter
  2320. //! must be \b USB_EP_DEV_IN or \b USB_EP_DEV_OUT; all other bits are ignored.
  2321. //!
  2322. //! \return None.
  2323. //
  2324. //*****************************************************************************
  2325. void
  2326. USBEndpointDMADisable(uint32_t ui32Base, uint32_t ui32Endpoint,
  2327. uint32_t ui32Flags)
  2328. {
  2329. //
  2330. // If this was a request to disable DMA on the IN portion of the endpoint
  2331. // then handle it.
  2332. //
  2333. if(ui32Flags & USB_EP_DEV_IN)
  2334. {
  2335. //
  2336. // Just disable DMA leave the mode setting.
  2337. //
  2338. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRH1) &=
  2339. ~USB_TXCSRH1_DMAEN;
  2340. }
  2341. else
  2342. {
  2343. //
  2344. // Just disable DMA leave the mode setting.
  2345. //
  2346. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRH1) &=
  2347. ~USB_RXCSRH1_DMAEN;
  2348. }
  2349. }
  2350. //*****************************************************************************
  2351. //
  2352. //! Determine the number of bytes of data available in a given endpoint's FIFO.
  2353. //!
  2354. //! \param ui32Base specifies the USB module base address.
  2355. //! \param ui32Endpoint is the endpoint to access.
  2356. //!
  2357. //! This function returns the number of bytes of data currently available in
  2358. //! the FIFO for the given receive (OUT) endpoint. It may be used prior to
  2359. //! calling USBEndpointDataGet() to determine the size of buffer required to
  2360. //! hold the newly-received packet.
  2361. //!
  2362. //! \return This call returns the number of bytes available in a given endpoint
  2363. //! FIFO.
  2364. //
  2365. //*****************************************************************************
  2366. uint32_t
  2367. USBEndpointDataAvail(uint32_t ui32Base, uint32_t ui32Endpoint)
  2368. {
  2369. uint32_t ui32Register;
  2370. //
  2371. // Check the arguments.
  2372. //
  2373. ASSERT(ui32Base == USB0_BASE);
  2374. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  2375. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  2376. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  2377. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  2378. //
  2379. // Get the address of the receive status register to use, based on the
  2380. // endpoint.
  2381. //
  2382. if(ui32Endpoint == USB_EP_0)
  2383. {
  2384. ui32Register = USB_O_CSRL0;
  2385. }
  2386. else
  2387. {
  2388. ui32Register = USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint);
  2389. }
  2390. //
  2391. // Is there a packet ready in the FIFO?
  2392. //
  2393. if((HWREGH(ui32Base + ui32Register) & USB_CSRL0_RXRDY) == 0)
  2394. {
  2395. return(0);
  2396. }
  2397. //
  2398. // Return the byte count in the FIFO.
  2399. //
  2400. return(HWREGH(ui32Base + USB_O_COUNT0 + ui32Endpoint));
  2401. }
  2402. //*****************************************************************************
  2403. //
  2404. //! Retrieves data from the given endpoint's FIFO.
  2405. //!
  2406. //! \param ui32Base specifies the USB module base address.
  2407. //! \param ui32Endpoint is the endpoint to access.
  2408. //! \param pui8Data is a pointer to the data area used to return the data from
  2409. //! the FIFO.
  2410. //! \param pui32Size is initially the size of the buffer passed into this call
  2411. //! via the \e pui8Data parameter. It is set to the amount of data returned in
  2412. //! the buffer.
  2413. //!
  2414. //! This function returns the data from the FIFO for the given endpoint.
  2415. //! The \e pui32Size parameter indicates the size of the buffer passed in
  2416. //! the \e pui32Data parameter. The data in the \e pui32Size parameter is
  2417. //! changed to match the amount of data returned in the \e pui8Data parameter.
  2418. //! If a zero-byte packet is received, this call does not return an error but
  2419. //! instead just returns a zero in the \e pui32Size parameter. The only error
  2420. //! case occurs when there is no data packet available.
  2421. //!
  2422. //! \return This call returns 0, or -1 if no packet was received.
  2423. //
  2424. //*****************************************************************************
  2425. int32_t
  2426. USBEndpointDataGet(uint32_t ui32Base, uint32_t ui32Endpoint,
  2427. uint8_t *pui8Data, uint32_t *pui32Size)
  2428. {
  2429. uint32_t ui32Register, ui32ByteCount, ui32FIFO;
  2430. //
  2431. // Check the arguments.
  2432. //
  2433. ASSERT(ui32Base == USB0_BASE);
  2434. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  2435. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  2436. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  2437. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  2438. //
  2439. // Get the address of the receive status register to use, based on the
  2440. // endpoint.
  2441. //
  2442. if(ui32Endpoint == USB_EP_0)
  2443. {
  2444. ui32Register = USB_O_CSRL0;
  2445. }
  2446. else
  2447. {
  2448. ui32Register = USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint);
  2449. }
  2450. //
  2451. // Don't allow reading of data if the RxPktRdy bit is not set.
  2452. //
  2453. if((HWREGH(ui32Base + ui32Register) & USB_CSRL0_RXRDY) == 0)
  2454. {
  2455. //
  2456. // Can't read the data because none is available.
  2457. //
  2458. *pui32Size = 0;
  2459. //
  2460. // Return a failure since there is no data to read.
  2461. //
  2462. return(-1);
  2463. }
  2464. //
  2465. // Get the byte count in the FIFO.
  2466. //
  2467. ui32ByteCount = HWREGH(ui32Base + USB_O_COUNT0 + ui32Endpoint);
  2468. //
  2469. // Determine how many bytes are copied.
  2470. //
  2471. ui32ByteCount = (ui32ByteCount < *pui32Size) ? ui32ByteCount : *pui32Size;
  2472. //
  2473. // Return the number of bytes we are going to read.
  2474. //
  2475. *pui32Size = ui32ByteCount;
  2476. //
  2477. // Calculate the FIFO address.
  2478. //
  2479. ui32FIFO = ui32Base + USB_O_FIFO0 + (ui32Endpoint >> 2);
  2480. //
  2481. // Read the data out of the FIFO.
  2482. //
  2483. for(; ui32ByteCount > 0; ui32ByteCount--)
  2484. {
  2485. //
  2486. // Read a byte at a time from the FIFO.
  2487. //
  2488. *pui8Data++ = HWREGB(ui32FIFO);
  2489. }
  2490. //
  2491. // Success.
  2492. //
  2493. return(0);
  2494. }
  2495. //*****************************************************************************
  2496. //
  2497. //! Acknowledge that data was read from the given endpoint's FIFO in device
  2498. //! mode.
  2499. //!
  2500. //! \param ui32Base specifies the USB module base address.
  2501. //! \param ui32Endpoint is the endpoint to access.
  2502. //! \param bIsLastPacket indicates if this packet is the last one.
  2503. //!
  2504. //! This function acknowledges that the data was read from the endpoint's FIFO.
  2505. //! The \e bIsLastPacket parameter is set to a \b true value if this is the
  2506. //! last in a series of data packets on endpoint zero. The \e bIsLastPacket
  2507. //! parameter is not used for endpoints other than endpoint zero. This call
  2508. //! can be used if processing is required between reading the data and
  2509. //! acknowledging that the data has been read.
  2510. //!
  2511. //! \note This function must only be called in device mode.
  2512. //!
  2513. //! \return None.
  2514. //
  2515. //*****************************************************************************
  2516. void
  2517. USBDevEndpointDataAck(uint32_t ui32Base, uint32_t ui32Endpoint,
  2518. bool bIsLastPacket)
  2519. {
  2520. //
  2521. // Check the arguments.
  2522. //
  2523. ASSERT(ui32Base == USB0_BASE);
  2524. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  2525. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  2526. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  2527. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  2528. //
  2529. // Determine which endpoint is being acked.
  2530. //
  2531. if(ui32Endpoint == USB_EP_0)
  2532. {
  2533. //
  2534. // Clear RxPktRdy, and optionally DataEnd, on endpoint zero.
  2535. //
  2536. HWREGB(ui32Base + USB_O_CSRL0) =
  2537. USB_CSRL0_RXRDYC | (bIsLastPacket ? USB_CSRL0_DATAEND : 0);
  2538. }
  2539. else
  2540. {
  2541. //
  2542. // Clear RxPktRdy on all other endpoints.
  2543. //
  2544. HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
  2545. ~(USB_RXCSRL1_RXRDY);
  2546. }
  2547. }
  2548. //*****************************************************************************
  2549. //
  2550. //! Acknowledge that data was read from the given endpoint's FIFO in host
  2551. //! mode.
  2552. //!
  2553. //! \param ui32Base specifies the USB module base address.
  2554. //! \param ui32Endpoint is the endpoint to access.
  2555. //!
  2556. //! This function acknowledges that the data was read from the endpoint's FIFO.
  2557. //! This call is used if processing is required between reading the data and
  2558. //! acknowledging that the data has been read.
  2559. //!
  2560. //! \note This function must only be called in host mode.
  2561. //!
  2562. //! \return None.
  2563. //
  2564. //*****************************************************************************
  2565. void
  2566. USBHostEndpointDataAck(uint32_t ui32Base, uint32_t ui32Endpoint)
  2567. {
  2568. //
  2569. // Check the arguments.
  2570. //
  2571. ASSERT(ui32Base == USB0_BASE);
  2572. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  2573. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  2574. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  2575. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  2576. //
  2577. // Clear RxPktRdy.
  2578. //
  2579. if(ui32Endpoint == USB_EP_0)
  2580. {
  2581. HWREGB(ui32Base + USB_O_CSRL0) &= ~USB_CSRL0_RXRDY;
  2582. }
  2583. else
  2584. {
  2585. HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
  2586. ~(USB_RXCSRL1_RXRDY);
  2587. }
  2588. }
  2589. //*****************************************************************************
  2590. //
  2591. //! Puts data into the given endpoint's FIFO.
  2592. //!
  2593. //! \param ui32Base specifies the USB module base address.
  2594. //! \param ui32Endpoint is the endpoint to access.
  2595. //! \param pui8Data is a pointer to the data area used as the source for the
  2596. //! data to put into the FIFO.
  2597. //! \param ui32Size is the amount of data to put into the FIFO.
  2598. //!
  2599. //! This function puts the data from the \e pui8Data parameter into the FIFO
  2600. //! for this endpoint. If a packet is already pending for transmission, then
  2601. //! this call does not put any of the data into the FIFO and returns -1. Care
  2602. //! must be taken to not write more data than can fit into the FIFO
  2603. //! allocated by the call to USBFIFOConfigSet().
  2604. //!
  2605. //! \return This call returns 0 on success, or -1 to indicate that the FIFO
  2606. //! is in use and cannot be written.
  2607. //
  2608. //*****************************************************************************
  2609. int32_t
  2610. USBEndpointDataPut(uint32_t ui32Base, uint32_t ui32Endpoint,
  2611. uint8_t *pui8Data, uint32_t ui32Size)
  2612. {
  2613. uint32_t ui32FIFO;
  2614. uint8_t ui8TxPktRdy;
  2615. //
  2616. // Check the arguments.
  2617. //
  2618. ASSERT(ui32Base == USB0_BASE);
  2619. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  2620. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  2621. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  2622. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  2623. //
  2624. // Get the bit position of TxPktRdy based on the endpoint.
  2625. //
  2626. if(ui32Endpoint == USB_EP_0)
  2627. {
  2628. ui8TxPktRdy = USB_CSRL0_TXRDY;
  2629. }
  2630. else
  2631. {
  2632. ui8TxPktRdy = USB_TXCSRL1_TXRDY;
  2633. }
  2634. //
  2635. // Don't allow transmit of data if the TxPktRdy bit is already set.
  2636. //
  2637. if(HWREGB(ui32Base + USB_O_CSRL0 + ui32Endpoint) & ui8TxPktRdy)
  2638. {
  2639. return(-1);
  2640. }
  2641. //
  2642. // Calculate the FIFO address.
  2643. //
  2644. ui32FIFO = ui32Base + USB_O_FIFO0 + (ui32Endpoint >> 2);
  2645. //
  2646. // Write the data to the FIFO.
  2647. //
  2648. for(; ui32Size > 0; ui32Size--)
  2649. {
  2650. HWREGB(ui32FIFO) = *pui8Data++;
  2651. }
  2652. //
  2653. // Success.
  2654. //
  2655. return(0);
  2656. }
  2657. //*****************************************************************************
  2658. //
  2659. //! Starts the transfer of data from an endpoint's FIFO.
  2660. //!
  2661. //! \param ui32Base specifies the USB module base address.
  2662. //! \param ui32Endpoint is the endpoint to access.
  2663. //! \param ui32TransType is set to indicate what type of data is being sent.
  2664. //!
  2665. //! This function starts the transfer of data from the FIFO for a given
  2666. //! endpoint. This function is called if the \b USB_EP_AUTO_SET bit was
  2667. //! not enabled for the endpoint. Setting the \e ui32TransType parameter
  2668. //! allows the appropriate signaling on the USB bus for the type of transaction
  2669. //! being requested. The \e ui32TransType parameter must be one of the
  2670. //! following:
  2671. //!
  2672. //! - \b USB_TRANS_OUT for OUT transaction on any endpoint in host mode.
  2673. //! - \b USB_TRANS_IN for IN transaction on any endpoint in device mode.
  2674. //! - \b USB_TRANS_IN_LAST for the last IN transaction on endpoint zero in a
  2675. //! sequence of IN transactions.
  2676. //! - \b USB_TRANS_SETUP for setup transactions on endpoint zero.
  2677. //! - \b USB_TRANS_STATUS for status results on endpoint zero.
  2678. //!
  2679. //! \return This call returns 0 on success, or -1 if a transmission is already
  2680. //! in progress.
  2681. //
  2682. //*****************************************************************************
  2683. int32_t
  2684. USBEndpointDataSend(uint32_t ui32Base, uint32_t ui32Endpoint,
  2685. uint32_t ui32TransType)
  2686. {
  2687. uint32_t ui32TxPktRdy;
  2688. //
  2689. // Check the arguments.
  2690. //
  2691. ASSERT(ui32Base == USB0_BASE);
  2692. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  2693. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  2694. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  2695. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  2696. //
  2697. // Get the bit position of TxPktRdy based on the endpoint.
  2698. //
  2699. if(ui32Endpoint == USB_EP_0)
  2700. {
  2701. //
  2702. // Don't allow transmit of data if the TxPktRdy bit is already set.
  2703. //
  2704. if(HWREGB(ui32Base + USB_O_CSRL0) & USB_CSRL0_TXRDY)
  2705. {
  2706. return(-1);
  2707. }
  2708. ui32TxPktRdy = ui32TransType & 0xff;
  2709. }
  2710. else
  2711. {
  2712. //
  2713. // Don't allow transmit of data if the TxPktRdy bit is already set.
  2714. //
  2715. if(HWREGB(ui32Base + USB_O_CSRL0 + ui32Endpoint) & USB_TXCSRL1_TXRDY)
  2716. {
  2717. return(-1);
  2718. }
  2719. ui32TxPktRdy = (ui32TransType >> 8) & 0xff;
  2720. }
  2721. //
  2722. // Set TxPktRdy in order to send the data.
  2723. //
  2724. HWREGB(ui32Base + USB_O_CSRL0 + ui32Endpoint) = ui32TxPktRdy;
  2725. //
  2726. // Success.
  2727. //
  2728. return(0);
  2729. }
  2730. //*****************************************************************************
  2731. //
  2732. //! Forces a flush of an endpoint's FIFO.
  2733. //!
  2734. //! \param ui32Base specifies the USB module base address.
  2735. //! \param ui32Endpoint is the endpoint to access.
  2736. //! \param ui32Flags specifies if the IN or OUT endpoint is accessed.
  2737. //!
  2738. //! This function forces the USB controller to flush out the data in the FIFO.
  2739. //! The function can be called with either host or device controllers and
  2740. //! requires the \e ui32Flags parameter be one of \b USB_EP_HOST_OUT,
  2741. //! \b USB_EP_HOST_IN, \b USB_EP_DEV_OUT, or \b USB_EP_DEV_IN.
  2742. //!
  2743. //! \return None.
  2744. //
  2745. //*****************************************************************************
  2746. void
  2747. USBFIFOFlush(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags)
  2748. {
  2749. //
  2750. // Check the arguments.
  2751. //
  2752. ASSERT(ui32Base == USB0_BASE);
  2753. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  2754. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  2755. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  2756. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  2757. //
  2758. // Endpoint zero has a different register set for FIFO flushing.
  2759. //
  2760. if(ui32Endpoint == USB_EP_0)
  2761. {
  2762. //
  2763. // Nothing in the FIFO if neither of these bits are set.
  2764. //
  2765. if((HWREGB(ui32Base + USB_O_CSRL0) &
  2766. (USB_CSRL0_RXRDY | USB_CSRL0_TXRDY)) != 0)
  2767. {
  2768. //
  2769. // Hit the Flush FIFO bit.
  2770. //
  2771. HWREGB(ui32Base + USB_O_CSRH0) = USB_CSRH0_FLUSH;
  2772. }
  2773. }
  2774. else
  2775. {
  2776. //
  2777. // Only reset the IN or OUT FIFO.
  2778. //
  2779. if(ui32Flags & (USB_EP_HOST_OUT | USB_EP_DEV_IN))
  2780. {
  2781. //
  2782. // Make sure the FIFO is not empty.
  2783. //
  2784. if(HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) &
  2785. USB_TXCSRL1_TXRDY)
  2786. {
  2787. //
  2788. // Hit the Flush FIFO bit.
  2789. //
  2790. HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
  2791. USB_TXCSRL1_FLUSH;
  2792. }
  2793. }
  2794. else
  2795. {
  2796. //
  2797. // Make sure that the FIFO is not empty.
  2798. //
  2799. if(HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) &
  2800. USB_RXCSRL1_RXRDY)
  2801. {
  2802. //
  2803. // Hit the Flush FIFO bit.
  2804. //
  2805. HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
  2806. USB_RXCSRL1_FLUSH;
  2807. }
  2808. }
  2809. }
  2810. }
  2811. //*****************************************************************************
  2812. //
  2813. //! Schedules a request for an IN transaction on an endpoint in host mode.
  2814. //!
  2815. //! \param ui32Base specifies the USB module base address.
  2816. //! \param ui32Endpoint is the endpoint to access.
  2817. //!
  2818. //! This function schedules a request for an IN transaction. When the USB
  2819. //! device being communicated with responds with the data, the data can be
  2820. //! retrieved by calling USBEndpointDataGet() or via a DMA transfer.
  2821. //!
  2822. //! \note This function must only be called in host mode and only for IN
  2823. //! endpoints.
  2824. //!
  2825. //! \return None.
  2826. //
  2827. //*****************************************************************************
  2828. void
  2829. USBHostRequestIN(uint32_t ui32Base, uint32_t ui32Endpoint)
  2830. {
  2831. uint32_t ui32Register;
  2832. //
  2833. // Check the arguments.
  2834. //
  2835. ASSERT(ui32Base == USB0_BASE);
  2836. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  2837. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  2838. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  2839. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  2840. //
  2841. // Endpoint zero uses a different offset than the other endpoints.
  2842. //
  2843. if(ui32Endpoint == USB_EP_0)
  2844. {
  2845. ui32Register = USB_O_CSRL0;
  2846. }
  2847. else
  2848. {
  2849. ui32Register = USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint);
  2850. }
  2851. //
  2852. // Set the request for an IN transaction.
  2853. //
  2854. HWREGB(ui32Base + ui32Register) = USB_RXCSRL1_REQPKT;
  2855. }
  2856. //*****************************************************************************
  2857. //
  2858. //! Clears a scheduled IN transaction for an endpoint in host mode.
  2859. //!
  2860. //! \param ui32Base specifies the USB module base address.
  2861. //! \param ui32Endpoint is the endpoint to access.
  2862. //!
  2863. //! This function clears a previously scheduled IN transaction if it is still
  2864. //! pending. This function is used to safely disable any scheduled IN
  2865. //! transactions if the endpoint specified by \e ui32Endpoint is reconfigured
  2866. //! for communications with other devices.
  2867. //!
  2868. //! \note This function must only be called in host mode and only for IN
  2869. //! endpoints.
  2870. //!
  2871. //! \return None.
  2872. //
  2873. //*****************************************************************************
  2874. void
  2875. USBHostRequestINClear(uint32_t ui32Base, uint32_t ui32Endpoint)
  2876. {
  2877. uint32_t ui32Register;
  2878. //
  2879. // Check the arguments.
  2880. //
  2881. ASSERT(ui32Base == USB0_BASE);
  2882. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  2883. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  2884. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  2885. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  2886. //
  2887. // Endpoint zero uses a different offset than the other endpoints.
  2888. //
  2889. if(ui32Endpoint == USB_EP_0)
  2890. {
  2891. ui32Register = USB_O_CSRL0;
  2892. }
  2893. else
  2894. {
  2895. ui32Register = USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint);
  2896. }
  2897. //
  2898. // Clear the request for an IN transaction.
  2899. //
  2900. HWREGB(ui32Base + ui32Register) &= ~USB_RXCSRL1_REQPKT;
  2901. }
  2902. //*****************************************************************************
  2903. //
  2904. //! Issues a request for a status IN transaction on endpoint zero.
  2905. //!
  2906. //! \param ui32Base specifies the USB module base address.
  2907. //!
  2908. //! This function is used to cause a request for a status IN transaction from
  2909. //! a device on endpoint zero. This function can only be used with endpoint
  2910. //! zero as that is the only control endpoint that supports this ability. This
  2911. //! function is used to complete the last phase of a control transaction to a
  2912. //! device and an interrupt is signaled when the status packet has been
  2913. //! received.
  2914. //!
  2915. //! \return None.
  2916. //
  2917. //*****************************************************************************
  2918. void
  2919. USBHostRequestStatus(uint32_t ui32Base)
  2920. {
  2921. //
  2922. // Check the arguments.
  2923. //
  2924. ASSERT(ui32Base == USB0_BASE);
  2925. //
  2926. // Set the request for a status IN transaction.
  2927. //
  2928. HWREGB(ui32Base + USB_O_CSRL0) = USB_CSRL0_REQPKT | USB_CSRL0_STATUS;
  2929. }
  2930. //*****************************************************************************
  2931. //
  2932. //! Sets the functional address for the device that is connected to an
  2933. //! endpoint in host mode.
  2934. //!
  2935. //! \param ui32Base specifies the USB module base address.
  2936. //! \param ui32Endpoint is the endpoint to access.
  2937. //! \param ui32Addr is the functional address for the controller to use for
  2938. //! this endpoint.
  2939. //! \param ui32Flags determines if this is an IN or an OUT endpoint.
  2940. //!
  2941. //! This function configures the functional address for a device that is using
  2942. //! this endpoint for communication. This \e ui32Addr parameter is the address
  2943. //! of the target device that this endpoint is communicating with. The
  2944. //! \e ui32Flags parameter indicates if the IN or OUT endpoint is set.
  2945. //!
  2946. //! \note This function must only be called in host mode.
  2947. //!
  2948. //! \return None.
  2949. //
  2950. //*****************************************************************************
  2951. void
  2952. USBHostAddrSet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Addr,
  2953. uint32_t ui32Flags)
  2954. {
  2955. //
  2956. // Check the arguments.
  2957. //
  2958. ASSERT(ui32Base == USB0_BASE);
  2959. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  2960. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  2961. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  2962. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  2963. //
  2964. // See if the transmit or receive address is set.
  2965. //
  2966. if(ui32Flags & USB_EP_HOST_OUT)
  2967. {
  2968. //
  2969. // Set the transmit address.
  2970. //
  2971. HWREGB(ui32Base + USB_O_TXFUNCADDR0 + (ui32Endpoint >> 1)) = ui32Addr;
  2972. }
  2973. else
  2974. {
  2975. //
  2976. // Set the receive address.
  2977. //
  2978. HWREGB(ui32Base + USB_O_TXFUNCADDR0 + 4 + (ui32Endpoint >> 1)) =
  2979. ui32Addr;
  2980. }
  2981. }
  2982. //*****************************************************************************
  2983. //
  2984. //! Gets the current functional device address for an endpoint.
  2985. //!
  2986. //! \param ui32Base specifies the USB module base address.
  2987. //! \param ui32Endpoint is the endpoint to access.
  2988. //! \param ui32Flags determines if this is an IN or an OUT endpoint.
  2989. //!
  2990. //! This function returns the current functional address that an endpoint is
  2991. //! using to communicate with a device. The \e ui32Flags parameter determines
  2992. //! if the IN or OUT endpoint's device address is returned.
  2993. //!
  2994. //! \note This function must only be called in host mode.
  2995. //!
  2996. //! \return Returns the current function address being used by an endpoint.
  2997. //
  2998. //*****************************************************************************
  2999. uint32_t
  3000. USBHostAddrGet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags)
  3001. {
  3002. //
  3003. // Check the arguments.
  3004. //
  3005. ASSERT(ui32Base == USB0_BASE);
  3006. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  3007. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  3008. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  3009. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  3010. //
  3011. // See if the transmit or receive address is returned.
  3012. //
  3013. if(ui32Flags & USB_EP_HOST_OUT)
  3014. {
  3015. //
  3016. // Return this endpoint's transmit address.
  3017. //
  3018. return(HWREGB(ui32Base + USB_O_TXFUNCADDR0 + (ui32Endpoint >> 1)));
  3019. }
  3020. else
  3021. {
  3022. //
  3023. // Return this endpoint's receive address.
  3024. //
  3025. return(HWREGB(ui32Base + USB_O_TXFUNCADDR0 + 4 + (ui32Endpoint >> 1)));
  3026. }
  3027. }
  3028. //*****************************************************************************
  3029. //
  3030. //! Sets the hub address for the device that is connected to an endpoint.
  3031. //!
  3032. //! \param ui32Base specifies the USB module base address.
  3033. //! \param ui32Endpoint is the endpoint to access.
  3034. //! \param ui32Addr is the hub address and port for the device using this
  3035. //! endpoint. The hub address must be defined in bits 0 through 6 with the
  3036. //! port number in bits 8 through 14.
  3037. //! \param ui32Flags determines if this is an IN or an OUT endpoint.
  3038. //!
  3039. //! This function configures the hub address for a device that is using this
  3040. //! endpoint for communication. The \e ui32Flags parameter determines if the
  3041. //! device address for the IN or the OUT endpoint is configured by this call
  3042. //! and sets the speed of the downstream device. Valid values are one of
  3043. //! \b USB_EP_HOST_OUT or \b USB_EP_HOST_IN optionally ORed with
  3044. //! \b USB_EP_SPEED_LOW.
  3045. //!
  3046. //! \note This function must only be called in host mode.
  3047. //!
  3048. //! \return None.
  3049. //
  3050. //*****************************************************************************
  3051. void
  3052. USBHostHubAddrSet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Addr,
  3053. uint32_t ui32Flags)
  3054. {
  3055. //
  3056. // Check the arguments.
  3057. //
  3058. ASSERT(ui32Base == USB0_BASE);
  3059. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  3060. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  3061. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  3062. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  3063. //
  3064. // See if the hub transmit or receive address is being set.
  3065. //
  3066. if(ui32Flags & USB_EP_HOST_OUT)
  3067. {
  3068. //
  3069. // Set the hub transmit address and port number for this endpoint.
  3070. //
  3071. HWREGH(ui32Base + USB_O_TXHUBADDR0 + (ui32Endpoint >> 1)) = ui32Addr;
  3072. }
  3073. else
  3074. {
  3075. //
  3076. // Set the hub receive address and port number for this endpoint.
  3077. //
  3078. HWREGH(ui32Base + USB_O_TXHUBADDR0 + 4 + (ui32Endpoint >> 1)) =
  3079. ui32Addr;
  3080. }
  3081. //
  3082. // Set the speed of communication for endpoint 0. This configuration is
  3083. // done here because it changes on a transaction-by-transaction basis for
  3084. // EP0. For other endpoints, this is set in USBHostEndpointConfig().
  3085. //
  3086. if(ui32Endpoint == USB_EP_0)
  3087. {
  3088. if(ui32Flags & USB_EP_SPEED_FULL)
  3089. {
  3090. HWREGB(ui32Base + USB_O_TYPE0) = USB_TYPE0_SPEED_FULL;
  3091. }
  3092. else
  3093. {
  3094. HWREGB(ui32Base + USB_O_TYPE0) = USB_TYPE0_SPEED_LOW;
  3095. }
  3096. }
  3097. }
  3098. //*****************************************************************************
  3099. //
  3100. //! Gets the current device hub address for this endpoint.
  3101. //!
  3102. //! \param ui32Base specifies the USB module base address.
  3103. //! \param ui32Endpoint is the endpoint to access.
  3104. //! \param ui32Flags determines if this is an IN or an OUT endpoint.
  3105. //!
  3106. //! This function returns the current hub address that an endpoint is using
  3107. //! to communicate with a device. The \e ui32Flags parameter determines if the
  3108. //! device address for the IN or OUT endpoint is returned.
  3109. //!
  3110. //! \note This function must only be called in host mode.
  3111. //!
  3112. //! \return This function returns the current hub address being used by an
  3113. //! endpoint.
  3114. //
  3115. //*****************************************************************************
  3116. uint32_t
  3117. USBHostHubAddrGet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags)
  3118. {
  3119. //
  3120. // Check the arguments.
  3121. //
  3122. ASSERT(ui32Base == USB0_BASE);
  3123. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  3124. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  3125. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  3126. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  3127. //
  3128. // See if the hub transmit or receive address is returned.
  3129. //
  3130. if(ui32Flags & USB_EP_HOST_OUT)
  3131. {
  3132. //
  3133. // Return the hub transmit address for this endpoint.
  3134. //
  3135. return(HWREGB(ui32Base + USB_O_TXHUBADDR0 + (ui32Endpoint >> 1)));
  3136. }
  3137. else
  3138. {
  3139. //
  3140. // Return the hub receive address for this endpoint.
  3141. //
  3142. return(HWREGB(ui32Base + USB_O_TXHUBADDR0 + 4 + (ui32Endpoint >> 1)));
  3143. }
  3144. }
  3145. //*****************************************************************************
  3146. //
  3147. //! Sets the configuration for USB power fault.
  3148. //!
  3149. //! \param ui32Base specifies the USB module base address.
  3150. //! \param ui32Flags specifies the configuration of the power fault.
  3151. //!
  3152. //! This function controls how the USB controller uses its external power
  3153. //! control pins (USBnPFLT and USBnEPEN). The flags specify the power
  3154. //! fault level sensitivity, the power fault action, and the power enable level
  3155. //! and source.
  3156. //!
  3157. //! One of the following can be selected as the power fault level sensitivity:
  3158. //!
  3159. //! - \b USB_HOST_PWRFLT_LOW - An external power fault is indicated by the pin
  3160. //! being driven low.
  3161. //! - \b USB_HOST_PWRFLT_HIGH - An external power fault is indicated by the pin
  3162. //! being driven high.
  3163. //!
  3164. //! One of the following can be selected as the power fault action:
  3165. //!
  3166. //! - \b USB_HOST_PWRFLT_EP_NONE - No automatic action when power fault
  3167. //! detected.
  3168. //! - \b USB_HOST_PWRFLT_EP_TRI - Automatically tri-state the USBnEPEN pin on a
  3169. //! power fault.
  3170. //! - \b USB_HOST_PWRFLT_EP_LOW - Automatically drive USBnEPEN pin low on a
  3171. //! power fault.
  3172. //! - \b USB_HOST_PWRFLT_EP_HIGH - Automatically drive USBnEPEN pin high on a
  3173. //! power fault.
  3174. //!
  3175. //! One of the following can be selected as the power enable level and source:
  3176. //!
  3177. //! - \b USB_HOST_PWREN_MAN_LOW - USBnEPEN is driven low by the USB controller
  3178. //! when USBHostPwrEnable() is called.
  3179. //! - \b USB_HOST_PWREN_MAN_HIGH - USBnEPEN is driven high by the USB
  3180. //! controller when USBHostPwrEnable() is
  3181. //! called.
  3182. //! - \b USB_HOST_PWREN_AUTOLOW - USBnEPEN is driven low by the USB controller
  3183. //! automatically if USBOTGSessionRequest() has
  3184. //! enabled a session.
  3185. //! - \b USB_HOST_PWREN_AUTOHIGH - USBnEPEN is driven high by the USB
  3186. //! controller automatically if
  3187. //! USBOTGSessionRequest() has enabled a
  3188. //! session.
  3189. //!
  3190. //! On devices that support the VBUS glitch filter, the
  3191. //! \b USB_HOST_PWREN_FILTER can be added to ignore small, short drops in VBUS
  3192. //! level caused by high power consumption. This feature is mainly used to
  3193. //! avoid causing VBUS errors caused by devices with high in-rush current.
  3194. //!
  3195. //! \note This function must only be called on microcontrollers that support
  3196. //! host mode or OTG operation.
  3197. //!
  3198. //! \return None.
  3199. //
  3200. //*****************************************************************************
  3201. void
  3202. USBHostPwrConfig(uint32_t ui32Base, uint32_t ui32Flags)
  3203. {
  3204. //
  3205. // Check the arguments.
  3206. //
  3207. ASSERT(ui32Base == USB0_BASE);
  3208. ASSERT((ui32Flags & ~(USB_HOST_PWREN_FILTER | USB_EPC_PFLTACT_M |
  3209. USB_EPC_PFLTAEN | USB_EPC_PFLTSEN_HIGH |
  3210. USB_EPC_EPEN_M)) == 0);
  3211. //
  3212. // If requested, enable VBUS droop detection on parts that support this
  3213. // feature.
  3214. //
  3215. HWREG(ui32Base + USB_O_VDC) = ui32Flags >> 16;
  3216. //
  3217. // Set the power fault configuration as specified. This configuration
  3218. // does not change whether fault detection is enabled or not.
  3219. //
  3220. HWREGH(ui32Base + USB_O_EPC) =
  3221. (ui32Flags | (HWREGH(ui32Base + USB_O_EPC) &
  3222. ~(USB_EPC_PFLTACT_M | USB_EPC_PFLTAEN |
  3223. USB_EPC_PFLTSEN_HIGH | USB_EPC_EPEN_M)));
  3224. }
  3225. //*****************************************************************************
  3226. //
  3227. //! Enables power fault detection.
  3228. //!
  3229. //! \param ui32Base specifies the USB module base address.
  3230. //!
  3231. //! This function enables power fault detection in the USB controller. If the
  3232. //! USBnPFLT pin is not in use, this function must not be used.
  3233. //!
  3234. //! \note This function must only be called in host mode.
  3235. //!
  3236. //! \return None.
  3237. //
  3238. //*****************************************************************************
  3239. void
  3240. USBHostPwrFaultEnable(uint32_t ui32Base)
  3241. {
  3242. //
  3243. // Check the arguments.
  3244. //
  3245. ASSERT(ui32Base == USB0_BASE);
  3246. //
  3247. // Enable power fault input.
  3248. //
  3249. HWREGH(ui32Base + USB_O_EPC) |= USB_EPC_PFLTEN;
  3250. }
  3251. //*****************************************************************************
  3252. //
  3253. //! Disables power fault detection.
  3254. //!
  3255. //! \param ui32Base specifies the USB module base address.
  3256. //!
  3257. //! This function disables power fault detection in the USB controller.
  3258. //!
  3259. //! \note This function must only be called in host mode.
  3260. //!
  3261. //! \return None.
  3262. //
  3263. //*****************************************************************************
  3264. void
  3265. USBHostPwrFaultDisable(uint32_t ui32Base)
  3266. {
  3267. //
  3268. // Check the arguments.
  3269. //
  3270. ASSERT(ui32Base == USB0_BASE);
  3271. //
  3272. // Enable power fault input.
  3273. //
  3274. HWREGH(ui32Base + USB_O_EPC) &= ~USB_EPC_PFLTEN;
  3275. }
  3276. //*****************************************************************************
  3277. //
  3278. //! Enables the external power pin.
  3279. //!
  3280. //! \param ui32Base specifies the USB module base address.
  3281. //!
  3282. //! This function enables the USBnEPEN signal, which enables an external power
  3283. //! supply in host mode operation.
  3284. //!
  3285. //! \note This function must only be called in host mode.
  3286. //!
  3287. //! \return None.
  3288. //
  3289. //*****************************************************************************
  3290. void
  3291. USBHostPwrEnable(uint32_t ui32Base)
  3292. {
  3293. //
  3294. // Check the arguments.
  3295. //
  3296. ASSERT(ui32Base == USB0_BASE);
  3297. //
  3298. // Enable the external power supply enable signal.
  3299. //
  3300. HWREGH(ui32Base + USB_O_EPC) |= USB_EPC_EPENDE;
  3301. }
  3302. //*****************************************************************************
  3303. //
  3304. //! Disables the external power pin.
  3305. //!
  3306. //! \param ui32Base specifies the USB module base address.
  3307. //!
  3308. //! This function disables the USBnEPEN signal, which disables an external
  3309. //! power supply in host mode operation.
  3310. //!
  3311. //! \note This function must only be called in host mode.
  3312. //!
  3313. //! \return None.
  3314. //
  3315. //*****************************************************************************
  3316. void
  3317. USBHostPwrDisable(uint32_t ui32Base)
  3318. {
  3319. //
  3320. // Check the arguments.
  3321. //
  3322. ASSERT(ui32Base == USB0_BASE);
  3323. //
  3324. // Disable the external power supply enable signal.
  3325. //
  3326. HWREGH(ui32Base + USB_O_EPC) &= ~USB_EPC_EPENDE;
  3327. }
  3328. //*****************************************************************************
  3329. //
  3330. //! Get the current frame number.
  3331. //!
  3332. //! \param ui32Base specifies the USB module base address.
  3333. //!
  3334. //! This function returns the last frame number received.
  3335. //!
  3336. //! \return The last frame number received.
  3337. //
  3338. //*****************************************************************************
  3339. uint32_t
  3340. USBFrameNumberGet(uint32_t ui32Base)
  3341. {
  3342. //
  3343. // Check the arguments.
  3344. //
  3345. ASSERT(ui32Base == USB0_BASE);
  3346. //
  3347. // Return the most recent frame number.
  3348. //
  3349. return(HWREGH(ui32Base + USB_O_FRAME));
  3350. }
  3351. //*****************************************************************************
  3352. //
  3353. //! Starts or ends a session.
  3354. //!
  3355. //! \param ui32Base specifies the USB module base address.
  3356. //! \param bStart specifies if this call starts or ends a session.
  3357. //!
  3358. //! This function is used in OTG mode to start a session request or end a
  3359. //! session. If the \e bStart parameter is set to \b true, then this function
  3360. //! starts a session and if it is \b false it ends a session.
  3361. //!
  3362. //! \return None.
  3363. //
  3364. //*****************************************************************************
  3365. void
  3366. USBOTGSessionRequest(uint32_t ui32Base, bool bStart)
  3367. {
  3368. //
  3369. // Check the arguments.
  3370. //
  3371. ASSERT(ui32Base == USB0_BASE);
  3372. //
  3373. // Start or end the session as directed.
  3374. //
  3375. if(bStart)
  3376. {
  3377. HWREGB(ui32Base + USB_O_DEVCTL) |= USB_DEVCTL_SESSION;
  3378. }
  3379. else
  3380. {
  3381. HWREGB(ui32Base + USB_O_DEVCTL) &= ~USB_DEVCTL_SESSION;
  3382. }
  3383. }
  3384. //*****************************************************************************
  3385. //
  3386. //! Returns the absolute FIFO address for a given endpoint.
  3387. //!
  3388. //! \param ui32Base specifies the USB module base address.
  3389. //! \param ui32Endpoint specifies which endpoint's FIFO address to return.
  3390. //!
  3391. //! This function returns the actual physical address of the FIFO. This
  3392. //! address is needed when the USB is going to be used with the uDMA
  3393. //! controller and the source or destination address must be set to the
  3394. //! physical FIFO address for a given endpoint.
  3395. //!
  3396. //! \return None.
  3397. //
  3398. //*****************************************************************************
  3399. uint32_t
  3400. USBFIFOAddrGet(uint32_t ui32Base, uint32_t ui32Endpoint)
  3401. {
  3402. //
  3403. // Return the FIFO address for this endpoint.
  3404. //
  3405. return(ui32Base + USB_O_FIFO0 + (ui32Endpoint >> 2));
  3406. }
  3407. //*****************************************************************************
  3408. //
  3409. //! Returns the current operating mode of the controller.
  3410. //!
  3411. //! \param ui32Base specifies the USB module base address.
  3412. //!
  3413. //! This function returns the current operating mode on USB controllers with
  3414. //! OTG or Dual mode functionality.
  3415. //!
  3416. //! For OTG controllers:
  3417. //!
  3418. //! The function returns one of the following values on OTG controllers:
  3419. //! \b USB_OTG_MODE_ASIDE_HOST, \b USB_OTG_MODE_ASIDE_DEV,
  3420. //! \b USB_OTG_MODE_BSIDE_HOST, \b USB_OTG_MODE_BSIDE_DEV,
  3421. //! \b USB_OTG_MODE_NONE.
  3422. //!
  3423. //! \b USB_OTG_MODE_ASIDE_HOST indicates that the controller is in host mode
  3424. //! on the A-side of the cable.
  3425. //!
  3426. //! \b USB_OTG_MODE_ASIDE_DEV indicates that the controller is in device mode
  3427. //! on the A-side of the cable.
  3428. //!
  3429. //! \b USB_OTG_MODE_BSIDE_HOST indicates that the controller is in host mode
  3430. //! on the B-side of the cable.
  3431. //!
  3432. //! \b USB_OTG_MODE_BSIDE_DEV indicates that the controller is in device mode
  3433. //! on the B-side of the cable. If an OTG session request is started with no
  3434. //! cable in place, this mode is the default.
  3435. //!
  3436. //! \b USB_OTG_MODE_NONE indicates that the controller is not attempting to
  3437. //! determine its role in the system.
  3438. //!
  3439. //! For Dual Mode controllers:
  3440. //!
  3441. //! The function returns one of the following values:
  3442. //! \b USB_DUAL_MODE_HOST, \b USB_DUAL_MODE_DEVICE, or
  3443. //! \b USB_DUAL_MODE_NONE.
  3444. //!
  3445. //! \b USB_DUAL_MODE_HOST indicates that the controller is acting as a host.
  3446. //!
  3447. //! \b USB_DUAL_MODE_DEVICE indicates that the controller acting as a device.
  3448. //!
  3449. //! \b USB_DUAL_MODE_NONE indicates that the controller is not active as
  3450. //! either a host or device.
  3451. //!
  3452. //! \return Returns \b USB_OTG_MODE_ASIDE_HOST, \b USB_OTG_MODE_ASIDE_DEV,
  3453. //! \b USB_OTG_MODE_BSIDE_HOST, \b USB_OTG_MODE_BSIDE_DEV,
  3454. //! \b USB_OTG_MODE_NONE, \b USB_DUAL_MODE_HOST, \b USB_DUAL_MODE_DEVICE, or
  3455. //! \b USB_DUAL_MODE_NONE.
  3456. //
  3457. //*****************************************************************************
  3458. uint32_t
  3459. USBModeGet(uint32_t ui32Base)
  3460. {
  3461. //
  3462. // Check the arguments.
  3463. //
  3464. ASSERT(ui32Base == USB0_BASE);
  3465. //
  3466. // Checks the current mode in the USB_O_DEVCTL and returns the current
  3467. // mode.
  3468. //
  3469. // USB_OTG_MODE_ASIDE_HOST: USB_DEVCTL_HOST | USB_DEVCTL_SESSION
  3470. // USB_OTG_MODE_ASIDE_DEV: USB_DEVCTL_SESSION
  3471. // USB_OTG_MODE_BSIDE_HOST: USB_DEVCTL_DEV | USB_DEVCTL_SESSION |
  3472. // USB_DEVCTL_HOST
  3473. // USB_OTG_MODE_BSIDE_DEV: USB_DEVCTL_DEV | USB_DEVCTL_SESSION
  3474. // USB_OTG_MODE_NONE: USB_DEVCTL_DEV
  3475. //
  3476. return(HWREGB(ui32Base + USB_O_DEVCTL) &
  3477. (USB_DEVCTL_DEV | USB_DEVCTL_HOST | USB_DEVCTL_SESSION |
  3478. USB_DEVCTL_VBUS_M));
  3479. }
  3480. //*****************************************************************************
  3481. //
  3482. //! Sets the DMA channel to use for a given endpoint.
  3483. //!
  3484. //! \param ui32Base specifies the USB module base address.
  3485. //! \param ui32Endpoint specifies which endpoint's FIFO address to return.
  3486. //! \param ui32Channel specifies which DMA channel to use for which endpoint.
  3487. //!
  3488. //! This function is used to configure which DMA channel to use with a given
  3489. //! endpoint. Receive DMA channels can only be used with receive endpoints
  3490. //! and transmit DMA channels can only be used with transmit endpoints. As a
  3491. //! result, the 3 receive and 3 transmit DMA channels can be mapped to any
  3492. //! endpoint other than 0. The values that are passed into the
  3493. //! \e ui32Channel value are the UDMA_CHANNEL_USBEP* values defined in udma.h.
  3494. //!
  3495. //! \note This function only has an effect on microcontrollers that have the
  3496. //! ability to change the DMA channel for an endpoint. Calling this function
  3497. //! on other devices has no effect.
  3498. //!
  3499. //! \return None.
  3500. //!
  3501. //*****************************************************************************
  3502. void
  3503. USBEndpointDMAChannel(uint32_t ui32Base, uint32_t ui32Endpoint,
  3504. uint32_t ui32Channel)
  3505. {
  3506. uint32_t ui32Mask;
  3507. //
  3508. // Check the arguments.
  3509. //
  3510. ASSERT(ui32Base == USB0_BASE);
  3511. ASSERT((ui32Endpoint == USB_EP_1) || (ui32Endpoint == USB_EP_2) ||
  3512. (ui32Endpoint == USB_EP_3) || (ui32Endpoint == USB_EP_4) ||
  3513. (ui32Endpoint == USB_EP_5) || (ui32Endpoint == USB_EP_6) ||
  3514. (ui32Endpoint == USB_EP_7));
  3515. // ASSERT(ui32Channel <= UDMA_CHANNEL_USBEP3TX);
  3516. //
  3517. // The input select mask must be shifted into the correct position
  3518. // based on the channel.
  3519. //
  3520. ui32Mask = (uint32_t)0xf << (ui32Channel * 4);
  3521. //
  3522. // Clear out the current selection for the channel.
  3523. //
  3524. ui32Mask = HWREG(ui32Base + USB_O_DMASEL) & (~ui32Mask);
  3525. //
  3526. // The input select is now shifted into the correct position based on the
  3527. // channel.
  3528. //
  3529. ui32Mask |= ((uint32_t)USBEPToIndex(ui32Endpoint)) << (ui32Channel * 4);
  3530. //
  3531. // Write the value out to the register.
  3532. //
  3533. HWREG(ui32Base + USB_O_DMASEL) = ui32Mask;
  3534. }
  3535. //*****************************************************************************
  3536. //
  3537. //! Change the mode of the USB controller to host.
  3538. //!
  3539. //! \param ui32Base specifies the USB module base address.
  3540. //!
  3541. //! This function changes the mode of the USB controller to host mode.
  3542. //!
  3543. //! \note This function must only be called on microcontrollers that support
  3544. //! OTG operation and have the DEVMODOTG bit in the USBGPCS register.
  3545. //!
  3546. //! \return None.
  3547. //
  3548. //*****************************************************************************
  3549. void
  3550. USBHostMode(uint32_t ui32Base)
  3551. {
  3552. //
  3553. // Check the arguments.
  3554. //
  3555. ASSERT(ui32Base == USB0_BASE);
  3556. //
  3557. // Force mode in OTG parts that support forcing USB controller mode.
  3558. // This bit is not writable in USB controllers that do not support
  3559. // forcing the mode. Not setting the USB_GPCS_DEVMOD bit makes this a
  3560. // force of host mode.
  3561. //
  3562. HWREGB(ui32Base + USB_O_GPCS) = USB_GPCS_DEVMODOTG;
  3563. }
  3564. //*****************************************************************************
  3565. //
  3566. //! Change the mode of the USB controller to device.
  3567. //!
  3568. //! \param ui32Base specifies the USB module base address.
  3569. //!
  3570. //! This function changes the mode of the USB controller to device mode.
  3571. //!
  3572. //! \note This function must only be called on microcontrollers that support
  3573. //! OTG operation and have the DEVMODOTG bit in the USBGPCS register.
  3574. //!
  3575. //! \return None.
  3576. //
  3577. //*****************************************************************************
  3578. void
  3579. USBDevMode(uint32_t ui32Base)
  3580. {
  3581. //
  3582. // Check the arguments.
  3583. //
  3584. ASSERT(ui32Base == USB0_BASE);
  3585. //
  3586. // Set the USB controller mode to device.
  3587. //
  3588. HWREGB(ui32Base + USB_O_GPCS) = USB_GPCS_DEVMODOTG | USB_GPCS_DEVMOD;
  3589. }
  3590. //*****************************************************************************
  3591. //
  3592. //! Change the mode of the USB controller to OTG.
  3593. //!
  3594. //! \param ui32Base specifies the USB module base address.
  3595. //!
  3596. //! This function changes the mode of the USB controller to OTG mode. This
  3597. //! function is only valid on microcontrollers that have the OTG capabilities.
  3598. //!
  3599. //! \return None.
  3600. //
  3601. //*****************************************************************************
  3602. void
  3603. USBOTGMode(uint32_t ui32Base)
  3604. {
  3605. //
  3606. // Check the arguments.
  3607. //
  3608. ASSERT(ui32Base == USB0_BASE);
  3609. //
  3610. // Disable the override of the USB controller mode when running on an OTG
  3611. // device.
  3612. //
  3613. HWREGB(ui32Base + USB_O_GPCS) = 0;
  3614. }
  3615. //*****************************************************************************
  3616. //
  3617. //! Powers off the USB PHY.
  3618. //!
  3619. //! \param ui32Base specifies the USB module base address.
  3620. //!
  3621. //! This function powers off the USB PHY, reducing the current consuption
  3622. //! of the device. While in the powered-off state, the USB controller is
  3623. //! unable to operate.
  3624. //!
  3625. //! \return None.
  3626. //
  3627. //*****************************************************************************
  3628. void
  3629. USBPHYPowerOff(uint32_t ui32Base)
  3630. {
  3631. //
  3632. // Set the PWRDNPHY bit in the PHY, putting it into its low power mode.
  3633. //
  3634. HWREGB(ui32Base + USB_O_POWER) |= USB_POWER_PWRDNPHY;
  3635. }
  3636. //*****************************************************************************
  3637. //
  3638. //! Powers on the USB PHY.
  3639. //!
  3640. //! \param ui32Base specifies the USB module base address.
  3641. //!
  3642. //! This function powers on the USB PHY, enabling it return to normal
  3643. //! operation. By default, the PHY is powered on, so this function must
  3644. //! only be called if USBPHYPowerOff() has previously been called.
  3645. //!
  3646. //! \return None.
  3647. //
  3648. //*****************************************************************************
  3649. void
  3650. USBPHYPowerOn(uint32_t ui32Base)
  3651. {
  3652. //
  3653. // Clear the PWRDNPHY bit in the PHY, putting it into normal operating
  3654. // mode.
  3655. //
  3656. HWREGB(ui32Base + USB_O_POWER) &= ~USB_POWER_PWRDNPHY;
  3657. }
  3658. //*****************************************************************************
  3659. //
  3660. //! Sets the number of packets to request when transferring multiple bulk
  3661. //! packets.
  3662. //!
  3663. //! \param ui32Base specifies the USB module base address.
  3664. //! \param ui32Endpoint is the endpoint index to target for this write.
  3665. //! \param ui32Count is the number of packets to request.
  3666. //!
  3667. //! This function sets the number of consecutive bulk packets to request
  3668. //! when transferring multiple bulk packets with DMA.
  3669. //!
  3670. //! \note This feature is not available on all Tiva devices. Please
  3671. //! check the data sheet to determine if the USB controller has a DMA
  3672. //! controller or if it must use the uDMA controller for DMA transfers.
  3673. //!
  3674. //! \return None.
  3675. //
  3676. //*****************************************************************************
  3677. void
  3678. USBEndpointPacketCountSet(uint32_t ui32Base, uint32_t ui32Endpoint,
  3679. uint32_t ui32Count)
  3680. {
  3681. HWREG(ui32Base + USB_O_RQPKTCOUNT1 +
  3682. (0x4 * (USBEPToIndex(ui32Endpoint) - 1))) = ui32Count;
  3683. }
  3684. //*****************************************************************************
  3685. //
  3686. //! Returns the number of USB endpoint pairs on the device.
  3687. //!
  3688. //! \param ui32Base specifies the USB module base address.
  3689. //!
  3690. //! This function returns the number of endpoint pairs supported by the USB
  3691. //! controller corresponding to the passed base address. The value returned is
  3692. //! the number of IN or OUT endpoints available and does not include endpoint 0
  3693. //! (the control endpoint). For example, if 15 is returned, there are 15 IN
  3694. //! and 15 OUT endpoints available in addition to endpoint 0.
  3695. //!
  3696. //! \return Returns the number of IN or OUT endpoints available.
  3697. //
  3698. //*****************************************************************************
  3699. uint32_t
  3700. USBNumEndpointsGet(uint32_t ui32Base)
  3701. {
  3702. //
  3703. // Read the number of endpoints from the hardware. The number of TX and
  3704. // RX endpoints are always the same.
  3705. //
  3706. return(15);
  3707. }