usb.c 194 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910
  1. //*****************************************************************************
  2. //
  3. // usb.c - Driver for the USB Interface.
  4. //
  5. // Copyright (c) 2007-2020 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions
  10. // are met:
  11. //
  12. // Redistributions of source code must retain the above copyright
  13. // notice, this list of conditions and the following disclaimer.
  14. //
  15. // Redistributions in binary form must reproduce the above copyright
  16. // notice, this list of conditions and the following disclaimer in the
  17. // documentation and/or other materials provided with the
  18. // distribution.
  19. //
  20. // Neither the name of Texas Instruments Incorporated nor the names of
  21. // its contributors may be used to endorse or promote products derived
  22. // from this software without specific prior written permission.
  23. //
  24. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. // This is part of revision 2.2.0.295 of the Tiva Peripheral Driver Library.
  37. //
  38. //*****************************************************************************
  39. //*****************************************************************************
  40. //
  41. //! \addtogroup usb_api
  42. //! @{
  43. //
  44. //*****************************************************************************
  45. #include <stdbool.h>
  46. #include <stdint.h>
  47. #include "inc/hw_ints.h"
  48. #include "inc/hw_memmap.h"
  49. #include "inc/hw_types.h"
  50. #include "inc/hw_sysctl.h"
  51. #include "inc/hw_usb.h"
  52. #include "driverlib/debug.h"
  53. #include "driverlib/interrupt.h"
  54. #include "driverlib/sysctl.h"
  55. #include "driverlib/udma.h"
  56. #include "driverlib/usb.h"
  57. //*****************************************************************************
  58. //
  59. // Amount to shift the RX interrupt sources by in the flags used in the
  60. // interrupt calls.
  61. //
  62. //*****************************************************************************
  63. #define USB_INTEP_RX_SHIFT 16
  64. //*****************************************************************************
  65. //
  66. // Amount to shift the RX endpoint status sources by in the flags used in the
  67. // calls.
  68. //
  69. //*****************************************************************************
  70. #define USB_RX_EPSTATUS_SHIFT 16
  71. //*****************************************************************************
  72. //
  73. // Converts from an endpoint specifier to the offset of the endpoint's
  74. // control/status registers.
  75. //
  76. //*****************************************************************************
  77. #define EP_OFFSET(Endpoint) (Endpoint - 0x10)
  78. //*****************************************************************************
  79. //
  80. // Sets one of the indexed registers.
  81. //
  82. // \param ui32Base specifies the USB module base address.
  83. // \param ui32Endpoint is the endpoint index to target for this write.
  84. // \param ui32IndexedReg is the indexed register to write to.
  85. // \param ui8Value is the value to write to the register.
  86. //
  87. // This function is used to access the indexed registers for each endpoint.
  88. // The only registers that are indexed are the FIFO configuration registers,
  89. // which are not used after configuration.
  90. //
  91. // \return None.
  92. //
  93. //*****************************************************************************
  94. static void
  95. _USBIndexWrite(uint32_t ui32Base, uint32_t ui32Endpoint,
  96. uint32_t ui32IndexedReg, uint32_t ui32Value, uint32_t ui32Size)
  97. {
  98. uint32_t ui32Index;
  99. //
  100. // Check the arguments.
  101. //
  102. ASSERT(ui32Base == USB0_BASE);
  103. ASSERT((ui32Endpoint == 0) || (ui32Endpoint == 1) || (ui32Endpoint == 2) ||
  104. (ui32Endpoint == 3));
  105. ASSERT((ui32Size == 1) || (ui32Size == 2));
  106. //
  107. // Save the old index in case it was in use.
  108. //
  109. ui32Index = HWREGB(ui32Base + USB_O_EPIDX);
  110. //
  111. // Set the index.
  112. //
  113. HWREGB(ui32Base + USB_O_EPIDX) = ui32Endpoint;
  114. //
  115. // Determine the size of the register value.
  116. //
  117. if(ui32Size == 1)
  118. {
  119. //
  120. // Set the value.
  121. //
  122. HWREGB(ui32Base + ui32IndexedReg) = ui32Value;
  123. }
  124. else
  125. {
  126. //
  127. // Set the value.
  128. //
  129. HWREGH(ui32Base + ui32IndexedReg) = ui32Value;
  130. }
  131. //
  132. // Restore the old index in case it was in use.
  133. //
  134. HWREGB(ui32Base + USB_O_EPIDX) = ui32Index;
  135. }
  136. //*****************************************************************************
  137. //
  138. // Reads one of the indexed registers.
  139. //
  140. // \param ui32Base specifies the USB module base address.
  141. // \param ui32Endpoint is the endpoint index to target for this write.
  142. // \param ui32IndexedReg is the indexed register to write to.
  143. // \param ui32Size is a value of 1 or 2 indicating the byte size of the read.
  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. uint32_t ui32Value;
  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. ui32Value = HWREGB(ui32Base + ui32IndexedReg);
  182. }
  183. else
  184. {
  185. //
  186. // Get the value.
  187. //
  188. ui32Value = 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(ui32Value);
  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. //! Enables or disables USB high-speed negotiation.
  265. //!
  266. //! \param ui32Base specifies the USB module base address.
  267. //! \param bEnable specifies whether to enable or disable high-speed
  268. //! negotiation.
  269. //!
  270. //! High-speed negotiations for both host and device mode are enabled when this
  271. //! function is called with the \e bEnable parameter set to \b true. In device
  272. //! mode this causes the device to negotiate for high speed when the
  273. //! USB controller receives a reset from the host. In host mode, the USB host
  274. //! enables high-speed negotiations when resetting the connected device. If
  275. //! \e bEnable is set to \b false the controller only operates only in
  276. //! full-speed or low-speed.
  277. //!
  278. //! \b Example: Enable USB high-speed mode.
  279. //!
  280. //! \verbatim
  281. //! //
  282. //! // Enable USB high-speed mode.
  283. //! //
  284. //! USBHighSpeed(USB0_BASE, true);
  285. //! \endverbatim
  286. //!
  287. //! \note This feature is not available on all Tiva devices and should only be
  288. //! called when the USB is connected to an external ULPI PHY. Please
  289. //! check the data sheet to determine if the USB controller can interface with
  290. //! a ULPI PHY.
  291. //!
  292. //! \return None.
  293. //
  294. //*****************************************************************************
  295. void
  296. USBHighSpeed(uint32_t ui32Base, bool bEnable)
  297. {
  298. //
  299. // Check the arguments.
  300. //
  301. ASSERT(ui32Base == USB0_BASE);
  302. if(bEnable)
  303. {
  304. //
  305. // Enable high speed mode negotiations in hosts or device mode.
  306. //
  307. HWREGB(ui32Base + USB_O_POWER) |= USB_POWER_HSENAB;
  308. }
  309. else
  310. {
  311. //
  312. // Enable high speed mode negotiations in hosts or device mode.
  313. //
  314. HWREGB(ui32Base + USB_O_POWER) &= ~USB_POWER_HSENAB;
  315. }
  316. }
  317. //*****************************************************************************
  318. //
  319. //! Handles the USB bus resume condition.
  320. //!
  321. //! \param ui32Base specifies the USB module base address.
  322. //! \param bStart specifies if the USB controller is entering or leaving the
  323. //! resume signaling state.
  324. //!
  325. //! When in device mode, this function brings the USB controller out of the
  326. //! suspend state. This call must first be made with the \e bStart parameter
  327. //! set to \b true to start resume signaling. The device application must
  328. //! then delay at least 10ms but not more than 15ms before calling this
  329. //! function with the \e bStart parameter set to \b false.
  330. //!
  331. //! When in host mode, this function signals devices to leave the suspend
  332. //! state. This call must first be made with the \e bStart parameter set to
  333. //! \b true to start resume signaling. The host application must then delay
  334. //! at least 20ms before calling this function with the \e bStart parameter set
  335. //! to \b false. This action causes the controller to complete the resume
  336. //! signaling on the USB bus.
  337. //!
  338. //! \note This function must only be called in host mode.
  339. //!
  340. //! \return None.
  341. //
  342. //*****************************************************************************
  343. void
  344. USBHostResume(uint32_t ui32Base, bool bStart)
  345. {
  346. //
  347. // Check the arguments.
  348. //
  349. ASSERT(ui32Base == USB0_BASE);
  350. //
  351. // Send a resume signal to the bus.
  352. //
  353. if(bStart)
  354. {
  355. HWREGB(ui32Base + USB_O_POWER) |= USB_POWER_RESUME;
  356. }
  357. else
  358. {
  359. HWREGB(ui32Base + USB_O_POWER) &= ~USB_POWER_RESUME;
  360. }
  361. }
  362. //*****************************************************************************
  363. //
  364. //! Returns the current speed of the USB device connected.
  365. //!
  366. //! \param ui32Base specifies the USB module base address.
  367. //!
  368. //! This function returns the current speed of the USB bus in host mode.
  369. //!
  370. //! \b Example: Get the USB connection speed.
  371. //!
  372. //! \verbatim
  373. //! //
  374. //! // Get the connection speed of the device connected to the USB controller.
  375. //! //
  376. //! USBHostSpeedGet(USB0_BASE);
  377. //! \endverbatim
  378. //!
  379. //! \note This function must only be called in host mode.
  380. //!
  381. //! \return Returns one of the following: \b USB_LOW_SPEED, \b USB_FULL_SPEED,
  382. //! \b USB_HIGH_SPEED, or \b USB_UNDEF_SPEED.
  383. //
  384. //*****************************************************************************
  385. uint32_t
  386. USBHostSpeedGet(uint32_t ui32Base)
  387. {
  388. //
  389. // Check the arguments.
  390. //
  391. ASSERT(ui32Base == USB0_BASE);
  392. //
  393. // If the Full Speed device bit is set, then this is a full speed device.
  394. //
  395. if(HWREGB(ui32Base + USB_O_POWER) & USB_POWER_HSMODE)
  396. {
  397. return(USB_HIGH_SPEED);
  398. }
  399. //
  400. // If the Full Speed device bit is set, then this is a full speed device.
  401. //
  402. if(HWREGB(ui32Base + USB_O_DEVCTL) & USB_DEVCTL_FSDEV)
  403. {
  404. return(USB_FULL_SPEED);
  405. }
  406. //
  407. // If the Low Speed device bit is set, then this is a low speed device.
  408. //
  409. if(HWREGB(ui32Base + USB_O_DEVCTL) & USB_DEVCTL_LSDEV)
  410. {
  411. return(USB_LOW_SPEED);
  412. }
  413. //
  414. // The device speed is not known.
  415. //
  416. return(USB_UNDEF_SPEED);
  417. }
  418. //*****************************************************************************
  419. //
  420. //! Returns the current speed of the USB controller in device mode.
  421. //!
  422. //! \param ui32Base specifies the USB module base address.
  423. //!
  424. //! This function returns the operating speed of the connection to the USB host
  425. //! controller. This function returns either \b USB_HIGH_SPEED or
  426. //! \b USB_FULL_SPEED to indicate the connection speed in device mode.
  427. //!
  428. //! \b Example: Get the USB connection speed.
  429. //!
  430. //! \verbatim
  431. //! //
  432. //! // Get the connection speed of the USB controller.
  433. //! //
  434. //! USBDevSpeedGet(USB0_BASE);
  435. //! \endverbatim
  436. //!
  437. //! \note This function must only be called in device mode.
  438. //!
  439. //! \return Returns either \b USB_HIGH_SPEED or \b USB_FULL_SPEED.
  440. //
  441. //*****************************************************************************
  442. uint32_t
  443. USBDevSpeedGet(uint32_t ui32Base)
  444. {
  445. //
  446. // Check the arguments.
  447. //
  448. ASSERT(ui32Base == USB0_BASE);
  449. //
  450. // If the Full Speed device bit is set, then this is a full speed device.
  451. //
  452. if(HWREGB(ui32Base + USB_O_POWER) & USB_POWER_HSMODE)
  453. {
  454. return(USB_HIGH_SPEED);
  455. }
  456. return(USB_FULL_SPEED);
  457. }
  458. //*****************************************************************************
  459. //
  460. //! Disables control interrupts on a specified USB controller.
  461. //!
  462. //! \param ui32Base specifies the USB module base address.
  463. //! \param ui32Flags specifies which control interrupts to disable.
  464. //!
  465. //! This function disables the control interrupts for the USB controller
  466. //! specified by the \e ui32Base parameter. The \e ui32Flags parameter
  467. //! specifies which control interrupts to disable. The flags passed in the
  468. //! \e ui32Flags parameters must be the definitions that start with
  469. //! \b USB_INTCTRL_* and not any other \b USB_INT flags.
  470. //!
  471. //! \return None.
  472. //
  473. //*****************************************************************************
  474. void
  475. USBIntDisableControl(uint32_t ui32Base, uint32_t ui32Flags)
  476. {
  477. //
  478. // Check the arguments.
  479. //
  480. ASSERT(ui32Base == USB0_BASE);
  481. ASSERT((ui32Flags & ~(USB_INTCTRL_ALL)) == 0);
  482. //
  483. // If any general interrupts were disabled then write the general interrupt
  484. // settings out to the hardware.
  485. //
  486. if(ui32Flags & USB_INTCTRL_STATUS)
  487. {
  488. HWREGB(ui32Base + USB_O_IE) &= ~(ui32Flags & USB_INTCTRL_STATUS);
  489. }
  490. //
  491. // Disable the power fault interrupt.
  492. //
  493. if(ui32Flags & USB_INTCTRL_POWER_FAULT)
  494. {
  495. HWREG(ui32Base + USB_O_EPCIM) = 0;
  496. }
  497. //
  498. // Disable the ID pin detect interrupt.
  499. //
  500. if(ui32Flags & USB_INTCTRL_MODE_DETECT)
  501. {
  502. HWREG(USB0_BASE + USB_O_IDVIM) = 0;
  503. }
  504. }
  505. //*****************************************************************************
  506. //
  507. //! Enables control interrupts on a specified USB controller.
  508. //!
  509. //! \param ui32Base specifies the USB module base address.
  510. //! \param ui32Flags specifies which control interrupts to enable.
  511. //!
  512. //! This function enables the control interrupts for the USB controller
  513. //! specified by the \e ui32Base parameter. The \e ui32Flags parameter
  514. //! specifies which control interrupts to enable. The flags passed in the
  515. //! \e ui32Flags parameters must be the definitions that start with
  516. //! \b USB_INTCTRL_* and not any other \b USB_INT flags.
  517. //!
  518. //! \return None.
  519. //
  520. //*****************************************************************************
  521. void
  522. USBIntEnableControl(uint32_t ui32Base, uint32_t ui32Flags)
  523. {
  524. //
  525. // Check the arguments.
  526. //
  527. ASSERT(ui32Base == USB0_BASE);
  528. ASSERT((ui32Flags & (~USB_INTCTRL_ALL)) == 0);
  529. //
  530. // If any general interrupts were enabled, then write the general
  531. // interrupt settings out to the hardware.
  532. //
  533. if(ui32Flags & USB_INTCTRL_STATUS)
  534. {
  535. HWREGB(ui32Base + USB_O_IE) |= ui32Flags;
  536. }
  537. //
  538. // Enable the power fault interrupt.
  539. //
  540. if(ui32Flags & USB_INTCTRL_POWER_FAULT)
  541. {
  542. HWREG(ui32Base + USB_O_EPCIM) = USB_EPCIM_PF;
  543. }
  544. //
  545. // Enable the ID pin detect interrupt.
  546. //
  547. if(ui32Flags & USB_INTCTRL_MODE_DETECT)
  548. {
  549. HWREG(USB0_BASE + USB_O_IDVIM) = USB_IDVIM_ID;
  550. }
  551. }
  552. //*****************************************************************************
  553. //
  554. //! Returns the control interrupt status on a specified USB controller.
  555. //!
  556. //! \param ui32Base specifies the USB module base address.
  557. //!
  558. //! This function reads control interrupt status for a USB controller. This
  559. //! call returns the current status for control interrupts only, the endpoint
  560. //! interrupt status is retrieved by calling USBIntStatusEndpoint(). The bit
  561. //! values returned are compared against the \b USB_INTCTRL_* values.
  562. //!
  563. //! The following are the meanings of all \b USB_INCTRL_ flags and the modes
  564. //! for which they are valid. These values apply to any calls to
  565. //! USBIntStatusControl(), USBIntEnableControl(), and USBIntDisableControl().
  566. //! Some of these flags are only valid in the following modes as indicated in
  567. //! the parentheses: Host, Device, and OTG.
  568. //!
  569. //! - \b USB_INTCTRL_ALL - A full mask of all control interrupt sources.
  570. //! - \b USB_INTCTRL_VBUS_ERR - A VBUS error has occurred (Host Only).
  571. //! - \b USB_INTCTRL_SESSION - Session Start Detected on A-side of cable
  572. //! (OTG Only).
  573. //! - \b USB_INTCTRL_SESSION_END - Session End Detected (Device Only)
  574. //! - \b USB_INTCTRL_DISCONNECT - Device Disconnect Detected (Host Only)
  575. //! - \b USB_INTCTRL_CONNECT - Device Connect Detected (Host Only)
  576. //! - \b USB_INTCTRL_SOF - Start of Frame Detected.
  577. //! - \b USB_INTCTRL_BABBLE - USB controller detected a device signaling past
  578. //! the end of a frame (Host Only)
  579. //! - \b USB_INTCTRL_RESET - Reset signaling detected by device (Device Only)
  580. //! - \b USB_INTCTRL_RESUME - Resume signaling detected.
  581. //! - \b USB_INTCTRL_SUSPEND - Suspend signaling detected by device (Device
  582. //! Only)
  583. //! - \b USB_INTCTRL_MODE_DETECT - OTG cable mode detection has completed
  584. //! (OTG Only)
  585. //! - \b USB_INTCTRL_POWER_FAULT - Power Fault detected (Host Only)
  586. //!
  587. //! \note This call clears the source of all of the control status interrupts.
  588. //!
  589. //! \return Returns the status of the control interrupts for a USB controller.
  590. //
  591. //*****************************************************************************
  592. uint32_t
  593. USBIntStatusControl(uint32_t ui32Base)
  594. {
  595. uint32_t ui32Status;
  596. //
  597. // Check the arguments.
  598. //
  599. ASSERT(ui32Base == USB0_BASE);
  600. //
  601. // Get the general interrupt status, these bits go into the upper 8 bits
  602. // of the returned value.
  603. //
  604. ui32Status = HWREGB(ui32Base + USB_O_IS);
  605. //
  606. // Add the power fault status.
  607. //
  608. if(HWREG(ui32Base + USB_O_EPCISC) & USB_EPCISC_PF)
  609. {
  610. //
  611. // Indicate a power fault was detected.
  612. //
  613. ui32Status |= USB_INTCTRL_POWER_FAULT;
  614. //
  615. // Clear the power fault interrupt.
  616. //
  617. HWREGB(ui32Base + USB_O_EPCISC) |= USB_EPCISC_PF;
  618. }
  619. if(HWREG(USB0_BASE + USB_O_IDVISC) & USB_IDVRIS_ID)
  620. {
  621. //
  622. // Indicate an id detection.
  623. //
  624. ui32Status |= USB_INTCTRL_MODE_DETECT;
  625. //
  626. // Clear the id detection interrupt.
  627. //
  628. HWREG(USB0_BASE + USB_O_IDVISC) |= USB_IDVRIS_ID;
  629. }
  630. //
  631. // Return the combined interrupt status.
  632. //
  633. return(ui32Status);
  634. }
  635. //*****************************************************************************
  636. //
  637. //! Disables endpoint interrupts on a specified USB controller.
  638. //!
  639. //! \param ui32Base specifies the USB module base address.
  640. //! \param ui32Flags specifies which endpoint interrupts to disable.
  641. //!
  642. //! This function disables endpoint interrupts for the USB controller specified
  643. //! by the \e ui32Base parameter. The \e ui32Flags parameter specifies which
  644. //! endpoint interrupts to disable. The flags passed in the \e ui32Flags
  645. //! parameters must be the definitions that start with \b USB_INTEP_* and not
  646. //! any other \b USB_INT flags.
  647. //!
  648. //! \return None.
  649. //
  650. //*****************************************************************************
  651. void
  652. USBIntDisableEndpoint(uint32_t ui32Base, uint32_t ui32Flags)
  653. {
  654. //
  655. // Check the arguments.
  656. //
  657. ASSERT(ui32Base == USB0_BASE);
  658. //
  659. // If any transmit interrupts were disabled, then write the transmit
  660. // interrupt settings out to the hardware.
  661. //
  662. HWREGH(ui32Base + USB_O_TXIE) &=
  663. ~(ui32Flags & (USB_INTEP_HOST_OUT | USB_INTEP_DEV_IN | USB_INTEP_0));
  664. //
  665. // If any receive interrupts were disabled, then write the receive
  666. // interrupt settings out to the hardware.
  667. //
  668. HWREGH(ui32Base + USB_O_RXIE) &=
  669. ~((ui32Flags & (USB_INTEP_HOST_IN | USB_INTEP_DEV_OUT)) >>
  670. USB_INTEP_RX_SHIFT);
  671. }
  672. //*****************************************************************************
  673. //
  674. //! Enables endpoint interrupts on a specified USB controller.
  675. //!
  676. //! \param ui32Base specifies the USB module base address.
  677. //! \param ui32Flags specifies which endpoint interrupts to enable.
  678. //!
  679. //! This function enables endpoint interrupts for the USB controller specified
  680. //! by the \e ui32Base parameter. The \e ui32Flags parameter specifies which
  681. //! endpoint interrupts to enable. The flags passed in the \e ui32Flags
  682. //! parameters must be the definitions that start with \b USB_INTEP_* and not
  683. //! any other \b USB_INT flags.
  684. //!
  685. //! \return None.
  686. //
  687. //*****************************************************************************
  688. void
  689. USBIntEnableEndpoint(uint32_t ui32Base, uint32_t ui32Flags)
  690. {
  691. //
  692. // Check the arguments.
  693. //
  694. ASSERT(ui32Base == USB0_BASE);
  695. //
  696. // Enable any transmit endpoint interrupts.
  697. //
  698. HWREGH(ui32Base + USB_O_TXIE) |=
  699. ui32Flags & (USB_INTEP_HOST_OUT | USB_INTEP_DEV_IN | USB_INTEP_0);
  700. //
  701. // Enable any receive endpoint interrupts.
  702. //
  703. HWREGH(ui32Base + USB_O_RXIE) |=
  704. ((ui32Flags & (USB_INTEP_HOST_IN | USB_INTEP_DEV_OUT)) >>
  705. USB_INTEP_RX_SHIFT);
  706. }
  707. //*****************************************************************************
  708. //
  709. //! Returns the endpoint interrupt status on a specified USB controller.
  710. //!
  711. //! \param ui32Base specifies the USB module base address.
  712. //!
  713. //! This function reads endpoint interrupt status for a USB controller. This
  714. //! call returns the current status for endpoint interrupts only, the control
  715. //! interrupt status is retrieved by calling USBIntStatusControl(). The bit
  716. //! values returned are compared against the \b USB_INTEP_* values.
  717. //! These values are grouped into classes for \b USB_INTEP_HOST_* and
  718. //! \b USB_INTEP_DEV_* values to handle both host and device modes with all
  719. //! endpoints.
  720. //!
  721. //! \note This call clears the source of all of the endpoint interrupts.
  722. //!
  723. //! \return Returns the status of the endpoint interrupts for a USB controller.
  724. //
  725. //*****************************************************************************
  726. uint32_t
  727. USBIntStatusEndpoint(uint32_t ui32Base)
  728. {
  729. uint32_t ui32Status;
  730. //
  731. // Check the arguments.
  732. //
  733. ASSERT(ui32Base == USB0_BASE);
  734. //
  735. // Get the transmit interrupt status.
  736. //
  737. ui32Status = HWREGH(ui32Base + USB_O_TXIS);
  738. ui32Status |= (HWREGH(ui32Base + USB_O_RXIS) << USB_INTEP_RX_SHIFT);
  739. //
  740. // Return the combined interrupt status.
  741. //
  742. return(ui32Status);
  743. }
  744. //*****************************************************************************
  745. //
  746. //! Returns the interrupt number for a specified USB module.
  747. //!
  748. //! \param ui32Base is the base address of the USB module.
  749. //!
  750. //! This function returns the interrupt number for the USB module with the base
  751. //! address passed in the \e ui32Base parameter.
  752. //!
  753. //! \return Returns the USB interrupt number or 0 if the interrupt does not
  754. //! exist.
  755. //
  756. //*****************************************************************************
  757. static uint32_t
  758. _USBIntNumberGet(uint32_t ui32Base)
  759. {
  760. uint32_t ui32Int;
  761. if(CLASS_IS_TM4C123)
  762. {
  763. ui32Int = INT_USB0_TM4C123;
  764. }
  765. else if(CLASS_IS_TM4C129)
  766. {
  767. ui32Int = INT_USB0_TM4C129;
  768. }
  769. else
  770. {
  771. ui32Int = 0;
  772. }
  773. return(ui32Int);
  774. }
  775. //*****************************************************************************
  776. //
  777. //! Registers an interrupt handler for the USB controller.
  778. //!
  779. //! \param ui32Base specifies the USB module base address.
  780. //! \param pfnHandler is a pointer to the function to be called when a USB
  781. //! interrupt occurs.
  782. //!
  783. //! This function registers the handler to be called when a USB interrupt
  784. //! occurs and enables the global USB interrupt in the interrupt controller.
  785. //! The specific desired USB interrupts must be enabled via a separate call to
  786. //! USBIntEnable(). It is the interrupt handler's responsibility to clear the
  787. //! interrupt sources via calls to USBIntStatusControl() and
  788. //! USBIntStatusEndpoint().
  789. //!
  790. //! \sa IntRegister() for important information about registering interrupt
  791. //! handlers.
  792. //!
  793. //! \return None.
  794. //
  795. //*****************************************************************************
  796. void
  797. USBIntRegister(uint32_t ui32Base, void (*pfnHandler)(void))
  798. {
  799. uint32_t ui32Int;
  800. //
  801. // Check the arguments.
  802. //
  803. ASSERT(ui32Base == USB0_BASE);
  804. ui32Int = _USBIntNumberGet(ui32Base);
  805. ASSERT(ui32Int != 0);
  806. //
  807. // Register the interrupt handler.
  808. //
  809. IntRegister(ui32Int, pfnHandler);
  810. //
  811. // Enable the USB interrupt.
  812. //
  813. IntEnable(ui32Int);
  814. }
  815. //*****************************************************************************
  816. //
  817. //! Unregisters an interrupt handler for the USB controller.
  818. //!
  819. //! \param ui32Base specifies the USB module base address.
  820. //!
  821. //! This function unregisters the interrupt handler. This function also
  822. //! disables the USB interrupt in the interrupt controller.
  823. //!
  824. //! \sa IntRegister() for important information about registering or
  825. //! unregistering interrupt handlers.
  826. //!
  827. //! \return None.
  828. //
  829. //*****************************************************************************
  830. void
  831. USBIntUnregister(uint32_t ui32Base)
  832. {
  833. uint32_t ui32Int;
  834. //
  835. // Check the arguments.
  836. //
  837. ASSERT(ui32Base == USB0_BASE);
  838. ui32Int = _USBIntNumberGet(ui32Base);
  839. ASSERT(ui32Int != 0);
  840. //
  841. // Disable the USB interrupt.
  842. //
  843. IntDisable(ui32Int);
  844. //
  845. // Unregister the interrupt handler.
  846. //
  847. IntUnregister(ui32Int);
  848. }
  849. //*****************************************************************************
  850. //
  851. //! Returns the current status of an endpoint.
  852. //!
  853. //! \param ui32Base specifies the USB module base address.
  854. //! \param ui32Endpoint is the endpoint to access.
  855. //!
  856. //! This function returns the status of a specified endpoint. If any of these
  857. //! status bits must be cleared, then the USBDevEndpointStatusClear() or the
  858. //! USBHostEndpointStatusClear() functions must be called.
  859. //!
  860. //! The following are the status flags for host mode:
  861. //!
  862. //! - \b USB_HOST_IN_PID_ERROR - PID error on the specified endpoint.
  863. //! - \b USB_HOST_IN_NOT_COMP - The device failed to respond to an IN request.
  864. //! - \b USB_HOST_IN_STALL - A stall was received on an IN endpoint.
  865. //! - \b USB_HOST_IN_DATA_ERROR - There was a CRC or bit-stuff error on an IN
  866. //! endpoint in Isochronous mode.
  867. //! - \b USB_HOST_IN_NAK_TO - NAKs received on this IN endpoint for more than
  868. //! the specified timeout period.
  869. //! - \b USB_HOST_IN_ERROR - Failed to communicate with a device using this IN
  870. //! endpoint.
  871. //! - \b USB_HOST_IN_FIFO_FULL - This IN endpoint's FIFO is full.
  872. //! - \b USB_HOST_IN_PKTRDY - Data packet ready on this IN endpoint.
  873. //! - \b USB_HOST_OUT_NAK_TO - NAKs received on this OUT endpoint for more than
  874. //! the specified timeout period.
  875. //! - \b USB_HOST_OUT_NOT_COMP - The device failed to respond to an OUT
  876. //! request.
  877. //! - \b USB_HOST_OUT_STALL - A stall was received on this OUT endpoint.
  878. //! - \b USB_HOST_OUT_ERROR - Failed to communicate with a device using this
  879. //! OUT endpoint.
  880. //! - \b USB_HOST_OUT_FIFO_NE - This endpoint's OUT FIFO is not empty.
  881. //! - \b USB_HOST_OUT_PKTPEND - The data transfer on this OUT endpoint has not
  882. //! completed.
  883. //! - \b USB_HOST_EP0_NAK_TO - NAKs received on endpoint zero for more than the
  884. //! specified timeout period.
  885. //! - \b USB_HOST_EP0_ERROR - The device failed to respond to a request on
  886. //! endpoint zero.
  887. //! - \b USB_HOST_EP0_IN_STALL - A stall was received on endpoint zero for an
  888. //! IN transaction.
  889. //! - \b USB_HOST_EP0_IN_PKTRDY - Data packet ready on endpoint zero for an IN
  890. //! transaction.
  891. //!
  892. //! The following are the status flags for device mode:
  893. //!
  894. //! - \b USB_DEV_OUT_SENT_STALL - A stall was sent on this OUT endpoint.
  895. //! - \b USB_DEV_OUT_DATA_ERROR - There was a CRC or bit-stuff error on an OUT
  896. //! endpoint.
  897. //! - \b USB_DEV_OUT_OVERRUN - An OUT packet was not loaded due to a full FIFO.
  898. //! - \b USB_DEV_OUT_FIFO_FULL - The OUT endpoint's FIFO is full.
  899. //! - \b USB_DEV_OUT_PKTRDY - There is a data packet ready in the OUT
  900. //! endpoint's FIFO.
  901. //! - \b USB_DEV_IN_NOT_COMP - A larger packet was split up, more data to come.
  902. //! - \b USB_DEV_IN_SENT_STALL - A stall was sent on this IN endpoint.
  903. //! - \b USB_DEV_IN_UNDERRUN - Data was requested on the IN endpoint and no
  904. //! data was ready.
  905. //! - \b USB_DEV_IN_FIFO_NE - The IN endpoint's FIFO is not empty.
  906. //! - \b USB_DEV_IN_PKTPEND - The data transfer on this IN endpoint has not
  907. //! completed.
  908. //! - \b USB_DEV_EP0_SETUP_END - A control transaction ended before Data End
  909. //! condition was sent.
  910. //! - \b USB_DEV_EP0_SENT_STALL - A stall was sent on endpoint zero.
  911. //! - \b USB_DEV_EP0_IN_PKTPEND - The data transfer on endpoint zero has not
  912. //! completed.
  913. //! - \b USB_DEV_EP0_OUT_PKTRDY - There is a data packet ready in endpoint
  914. //! zero's OUT FIFO.
  915. //!
  916. //! \return The current status flags for the endpoint depending on mode.
  917. //
  918. //*****************************************************************************
  919. uint32_t
  920. USBEndpointStatus(uint32_t ui32Base, uint32_t ui32Endpoint)
  921. {
  922. uint32_t ui32Status;
  923. //
  924. // Check the arguments.
  925. //
  926. ASSERT(ui32Base == USB0_BASE);
  927. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  928. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  929. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  930. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  931. //
  932. // Get the TX portion of the endpoint status.
  933. //
  934. ui32Status = HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRL1);
  935. //
  936. // Get the RX portion of the endpoint status.
  937. //
  938. ui32Status |=
  939. ((HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRL1)) <<
  940. USB_RX_EPSTATUS_SHIFT);
  941. //
  942. // Return the endpoint status.
  943. //
  944. return(ui32Status);
  945. }
  946. //*****************************************************************************
  947. //
  948. //! Clears the status bits in this endpoint in host mode.
  949. //!
  950. //! \param ui32Base specifies the USB module base address.
  951. //! \param ui32Endpoint is the endpoint to access.
  952. //! \param ui32Flags are the status bits that are cleared.
  953. //!
  954. //! This function clears the status of any bits that are passed in the
  955. //! \e ui32Flags parameter. The \e ui32Flags parameter can take the value
  956. //! returned from the USBEndpointStatus() call.
  957. //!
  958. //! \note This function must only be called in host mode.
  959. //!
  960. //! \return None.
  961. //
  962. //*****************************************************************************
  963. void
  964. USBHostEndpointStatusClear(uint32_t ui32Base, uint32_t ui32Endpoint,
  965. uint32_t ui32Flags)
  966. {
  967. //
  968. // Check the arguments.
  969. //
  970. ASSERT(ui32Base == USB0_BASE);
  971. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  972. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  973. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  974. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  975. //
  976. // Clear the specified flags for the endpoint.
  977. //
  978. if(ui32Endpoint == USB_EP_0)
  979. {
  980. HWREGB(ui32Base + USB_O_CSRL0) &= ~ui32Flags;
  981. }
  982. else
  983. {
  984. HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
  985. ~ui32Flags;
  986. HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
  987. ~(ui32Flags >> USB_RX_EPSTATUS_SHIFT);
  988. }
  989. }
  990. //*****************************************************************************
  991. //
  992. //! Clears the status bits in this endpoint in device mode.
  993. //!
  994. //! \param ui32Base specifies the USB module base address.
  995. //! \param ui32Endpoint is the endpoint to access.
  996. //! \param ui32Flags are the status bits that are cleared.
  997. //!
  998. //! This function clears the status of any bits that are passed in the
  999. //! \e ui32Flags parameter. The \e ui32Flags parameter can take the value
  1000. //! returned from the USBEndpointStatus() call.
  1001. //!
  1002. //! \note This function must only be called in device mode.
  1003. //!
  1004. //! \return None.
  1005. //
  1006. //*****************************************************************************
  1007. void
  1008. USBDevEndpointStatusClear(uint32_t ui32Base, uint32_t ui32Endpoint,
  1009. uint32_t ui32Flags)
  1010. {
  1011. //
  1012. // Check the arguments.
  1013. //
  1014. ASSERT(ui32Base == USB0_BASE);
  1015. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  1016. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  1017. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  1018. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  1019. //
  1020. // If this is endpoint 0, then the bits have different meaning and map
  1021. // into the TX memory location.
  1022. //
  1023. if(ui32Endpoint == USB_EP_0)
  1024. {
  1025. //
  1026. // Set the Serviced RxPktRdy bit to clear the RxPktRdy.
  1027. //
  1028. if(ui32Flags & USB_DEV_EP0_OUT_PKTRDY)
  1029. {
  1030. HWREGB(ui32Base + USB_O_CSRL0) |= USB_CSRL0_RXRDYC;
  1031. }
  1032. //
  1033. // Set the serviced Setup End bit to clear the SetupEnd status.
  1034. //
  1035. if(ui32Flags & USB_DEV_EP0_SETUP_END)
  1036. {
  1037. HWREGB(ui32Base + USB_O_CSRL0) |= USB_CSRL0_SETENDC;
  1038. }
  1039. //
  1040. // Clear the Sent Stall status flag.
  1041. //
  1042. if(ui32Flags & USB_DEV_EP0_SENT_STALL)
  1043. {
  1044. HWREGB(ui32Base + USB_O_CSRL0) &= ~(USB_DEV_EP0_SENT_STALL);
  1045. }
  1046. }
  1047. else
  1048. {
  1049. //
  1050. // Clear out any TX flags that were passed in. Only
  1051. // USB_DEV_TX_SENT_STALL and USB_DEV_TX_UNDERRUN must be cleared.
  1052. //
  1053. HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
  1054. ~(ui32Flags & (USB_DEV_TX_SENT_STALL | USB_DEV_TX_UNDERRUN));
  1055. //
  1056. // Clear out valid RX flags that were passed in. Only
  1057. // USB_DEV_RX_SENT_STALL, USB_DEV_RX_DATA_ERROR, and USB_DEV_RX_OVERRUN
  1058. // must be cleared.
  1059. //
  1060. HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
  1061. ~((ui32Flags & (USB_DEV_RX_SENT_STALL | USB_DEV_RX_DATA_ERROR |
  1062. USB_DEV_RX_OVERRUN)) >> USB_RX_EPSTATUS_SHIFT);
  1063. }
  1064. }
  1065. //*****************************************************************************
  1066. //
  1067. //! Sets the value data toggle on an endpoint in host mode.
  1068. //!
  1069. //! \param ui32Base specifies the USB module base address.
  1070. //! \param ui32Endpoint specifies the endpoint to reset the data toggle.
  1071. //! \param bDataToggle specifies whether to set the state to DATA0 or DATA1.
  1072. //! \param ui32Flags specifies whether to set the IN or OUT endpoint.
  1073. //!
  1074. //! This function is used to force the state of the data toggle in host mode.
  1075. //! If the value passed in the \e bDataToggle parameter is \b false, then the
  1076. //! data toggle is set to the DATA0 state, and if it is \b true it is set to
  1077. //! the DATA1 state. The \e ui32Flags parameter can be \b USB_EP_HOST_IN or
  1078. //! \b USB_EP_HOST_OUT to access the desired portion of this endpoint. The
  1079. //! \e ui32Flags parameter is ignored for endpoint zero.
  1080. //!
  1081. //! \note This function must only be called in host mode.
  1082. //!
  1083. //! \return None.
  1084. //
  1085. //*****************************************************************************
  1086. void
  1087. USBHostEndpointDataToggle(uint32_t ui32Base, uint32_t ui32Endpoint,
  1088. bool bDataToggle, uint32_t ui32Flags)
  1089. {
  1090. uint32_t ui32DataToggle;
  1091. //
  1092. // Check the arguments.
  1093. //
  1094. ASSERT(ui32Base == USB0_BASE);
  1095. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  1096. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  1097. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  1098. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  1099. //
  1100. // The data toggle defaults to DATA0.
  1101. //
  1102. ui32DataToggle = 0;
  1103. //
  1104. // See if the data toggle must be set to DATA1.
  1105. //
  1106. if(bDataToggle)
  1107. {
  1108. //
  1109. // Select the data toggle bit based on the endpoint.
  1110. //
  1111. if(ui32Endpoint == USB_EP_0)
  1112. {
  1113. ui32DataToggle = USB_CSRH0_DT;
  1114. }
  1115. else if(ui32Flags == USB_EP_HOST_IN)
  1116. {
  1117. ui32DataToggle = USB_RXCSRH1_DT;
  1118. }
  1119. else
  1120. {
  1121. ui32DataToggle = USB_TXCSRH1_DT;
  1122. }
  1123. }
  1124. //
  1125. // Set the data toggle based on the endpoint.
  1126. //
  1127. if(ui32Endpoint == USB_EP_0)
  1128. {
  1129. //
  1130. // Set the write enable and the bit value for endpoint zero.
  1131. //
  1132. HWREGB(ui32Base + USB_O_CSRH0) =
  1133. ((HWREGB(ui32Base + USB_O_CSRH0) &
  1134. ~(USB_CSRH0_DTWE | USB_CSRH0_DT)) |
  1135. (ui32DataToggle | USB_CSRH0_DTWE));
  1136. }
  1137. else if(ui32Flags == USB_EP_HOST_IN)
  1138. {
  1139. //
  1140. // Set the Write enable and the bit value for an IN endpoint.
  1141. //
  1142. HWREGB(ui32Base + USB_O_RXCSRH1 + EP_OFFSET(ui32Endpoint)) =
  1143. ((HWREGB(ui32Base + USB_O_RXCSRH1 + EP_OFFSET(ui32Endpoint)) &
  1144. ~(USB_RXCSRH1_DTWE | USB_RXCSRH1_DT)) |
  1145. (ui32DataToggle | USB_RXCSRH1_DTWE));
  1146. }
  1147. else
  1148. {
  1149. //
  1150. // Set the Write enable and the bit value for an OUT endpoint.
  1151. //
  1152. HWREGB(ui32Base + USB_O_TXCSRH1 + EP_OFFSET(ui32Endpoint)) =
  1153. ((HWREGB(ui32Base + USB_O_TXCSRH1 + EP_OFFSET(ui32Endpoint)) &
  1154. ~(USB_TXCSRH1_DTWE | USB_TXCSRH1_DT)) |
  1155. (ui32DataToggle | USB_TXCSRH1_DTWE));
  1156. }
  1157. }
  1158. //*****************************************************************************
  1159. //
  1160. //! Sets the data toggle on an endpoint to zero.
  1161. //!
  1162. //! \param ui32Base specifies the USB module base address.
  1163. //! \param ui32Endpoint specifies the endpoint to reset the data toggle.
  1164. //! \param ui32Flags specifies whether to access the IN or OUT endpoint.
  1165. //!
  1166. //! This function causes the USB controller to clear the data toggle for an
  1167. //! endpoint. This call is not valid for endpoint zero and can be made with
  1168. //! host or device controllers.
  1169. //!
  1170. //! The \e ui32Flags parameter must be one of \b USB_EP_HOST_OUT,
  1171. //! \b USB_EP_HOST_IN, \b USB_EP_DEV_OUT, or \b USB_EP_DEV_IN.
  1172. //!
  1173. //! \return None.
  1174. //
  1175. //*****************************************************************************
  1176. void
  1177. USBEndpointDataToggleClear(uint32_t ui32Base, uint32_t ui32Endpoint,
  1178. uint32_t ui32Flags)
  1179. {
  1180. //
  1181. // Check the arguments.
  1182. //
  1183. ASSERT(ui32Base == USB0_BASE);
  1184. ASSERT((ui32Endpoint == USB_EP_1) || (ui32Endpoint == USB_EP_2) ||
  1185. (ui32Endpoint == USB_EP_3) || (ui32Endpoint == USB_EP_4) ||
  1186. (ui32Endpoint == USB_EP_5) || (ui32Endpoint == USB_EP_6) ||
  1187. (ui32Endpoint == USB_EP_7));
  1188. //
  1189. // See if the transmit or receive data toggle must be cleared.
  1190. //
  1191. if(ui32Flags & (USB_EP_HOST_OUT | USB_EP_DEV_IN))
  1192. {
  1193. HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
  1194. USB_TXCSRL1_CLRDT;
  1195. }
  1196. else
  1197. {
  1198. HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
  1199. USB_RXCSRL1_CLRDT;
  1200. }
  1201. }
  1202. //*****************************************************************************
  1203. //
  1204. //! Enables or disables ping tokens for an endpoint using high-speed control
  1205. //! transfers in host mode.
  1206. //!
  1207. //! \param ui32Base specifies the USB module base address.
  1208. //! \param ui32Endpoint specifies the endpoint to enable/disable ping tokens.
  1209. //! \param bEnable specifies whether enable or disable ping tokens.
  1210. //!
  1211. //! This function configures the USB controller to either send or not send ping
  1212. //! tokens during the data and status phase of high speed control transfers.
  1213. //! The only supported value for \e ui32Endpoint is \b USB_EP_0 because all
  1214. //! control transfers are handled using this endpoint. If the \e bEnable is
  1215. //! \b true then ping tokens are enabled, if \b false then ping tokens are
  1216. //! disabled. This must be used if the controller must support
  1217. //! communications with devices that do not support ping tokens in high speed
  1218. //! mode.
  1219. //!
  1220. //! \b Example: Disable ping transactions in host mode on endpoint 0.
  1221. //!
  1222. //! \verbatim
  1223. //! //
  1224. //! // Disable ping transaction on endpoint 0.
  1225. //! //
  1226. //! USBHostEndpointPing(USB0_BASE, USB_EP_0, false);
  1227. //! \endverbatim
  1228. //!
  1229. //! \note This function must only be called in host mode.
  1230. //!
  1231. //! \return None.
  1232. //
  1233. //*****************************************************************************
  1234. void
  1235. USBHostEndpointPing(uint32_t ui32Base, uint32_t ui32Endpoint, bool bEnable)
  1236. {
  1237. //
  1238. // Check the arguments.
  1239. //
  1240. ASSERT(ui32Base == USB0_BASE);
  1241. ASSERT((ui32Endpoint == USB_EP_0));
  1242. //
  1243. // Handle the endpoint 0 case separately.
  1244. //
  1245. if(bEnable)
  1246. {
  1247. HWREGB(USB0_BASE + USB_O_CSRH0) &= ~USB_CSRH0_DISPING;
  1248. }
  1249. else
  1250. {
  1251. HWREGB(USB0_BASE + USB_O_CSRH0) |= USB_CSRH0_DISPING;
  1252. }
  1253. }
  1254. //*****************************************************************************
  1255. //
  1256. //! Stalls the specified endpoint in device mode.
  1257. //!
  1258. //! \param ui32Base specifies the USB module base address.
  1259. //! \param ui32Endpoint specifies the endpoint to stall.
  1260. //! \param ui32Flags specifies whether to stall the IN or OUT endpoint.
  1261. //!
  1262. //! This function causes the endpoint number passed in to go into a stall
  1263. //! condition. If the \e ui32Flags parameter is \b USB_EP_DEV_IN, then the
  1264. //! stall is issued on the IN portion of this endpoint. If the \e ui32Flags
  1265. //! parameter is \b USB_EP_DEV_OUT, then the stall is issued on the OUT portion
  1266. //! of this endpoint.
  1267. //!
  1268. //! \note This function must only be called in device mode.
  1269. //!
  1270. //! \return None.
  1271. //
  1272. //*****************************************************************************
  1273. void
  1274. USBDevEndpointStall(uint32_t ui32Base, uint32_t ui32Endpoint,
  1275. uint32_t ui32Flags)
  1276. {
  1277. //
  1278. // Check the arguments.
  1279. //
  1280. ASSERT(ui32Base == USB0_BASE);
  1281. ASSERT((ui32Flags & ~(USB_EP_DEV_IN | USB_EP_DEV_OUT)) == 0);
  1282. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  1283. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  1284. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  1285. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  1286. //
  1287. // Determine how to stall this endpoint.
  1288. //
  1289. if(ui32Endpoint == USB_EP_0)
  1290. {
  1291. //
  1292. // Perform a stall on endpoint zero.
  1293. //
  1294. HWREGB(ui32Base + USB_O_CSRL0) |= USB_CSRL0_STALL | USB_CSRL0_RXRDYC;
  1295. }
  1296. else if(ui32Flags == USB_EP_DEV_IN)
  1297. {
  1298. //
  1299. // Perform a stall on an IN endpoint.
  1300. //
  1301. HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
  1302. USB_TXCSRL1_STALL;
  1303. }
  1304. else
  1305. {
  1306. //
  1307. // Perform a stall on an OUT endpoint.
  1308. //
  1309. HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
  1310. USB_RXCSRL1_STALL;
  1311. }
  1312. }
  1313. //*****************************************************************************
  1314. //
  1315. //! Clears the stall condition on the specified endpoint in device mode.
  1316. //!
  1317. //! \param ui32Base specifies the USB module base address.
  1318. //! \param ui32Endpoint specifies which endpoint to remove the stall condition.
  1319. //! \param ui32Flags specifies whether to remove the stall condition from the
  1320. //! IN or the OUT portion of this endpoint.
  1321. //!
  1322. //! This function causes the endpoint number passed in to exit the stall
  1323. //! condition. If the \e ui32Flags parameter is \b USB_EP_DEV_IN, then the
  1324. //! stall is cleared on the IN portion of this endpoint. If the \e ui32Flags
  1325. //! parameter is \b USB_EP_DEV_OUT, then the stall is cleared on the OUT
  1326. //! portion of this endpoint.
  1327. //!
  1328. //! \note This function must only be called in device mode.
  1329. //!
  1330. //! \return None.
  1331. //
  1332. //*****************************************************************************
  1333. void
  1334. USBDevEndpointStallClear(uint32_t ui32Base, uint32_t ui32Endpoint,
  1335. uint32_t ui32Flags)
  1336. {
  1337. //
  1338. // Check the arguments.
  1339. //
  1340. ASSERT(ui32Base == USB0_BASE);
  1341. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  1342. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  1343. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  1344. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  1345. ASSERT((ui32Flags & ~(USB_EP_DEV_IN | USB_EP_DEV_OUT)) == 0);
  1346. //
  1347. // Determine how to clear the stall on this endpoint.
  1348. //
  1349. if(ui32Endpoint == USB_EP_0)
  1350. {
  1351. //
  1352. // Clear the stall on endpoint zero.
  1353. //
  1354. HWREGB(ui32Base + USB_O_CSRL0) &= ~USB_CSRL0_STALLED;
  1355. }
  1356. else if(ui32Flags == USB_EP_DEV_IN)
  1357. {
  1358. //
  1359. // Clear the stall on an IN endpoint.
  1360. //
  1361. HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
  1362. ~(USB_TXCSRL1_STALL | USB_TXCSRL1_STALLED);
  1363. //
  1364. // Reset the data toggle.
  1365. //
  1366. HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
  1367. USB_TXCSRL1_CLRDT;
  1368. }
  1369. else
  1370. {
  1371. //
  1372. // Clear the stall on an OUT endpoint.
  1373. //
  1374. HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
  1375. ~(USB_RXCSRL1_STALL | USB_RXCSRL1_STALLED);
  1376. //
  1377. // Reset the data toggle.
  1378. //
  1379. HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
  1380. USB_RXCSRL1_CLRDT;
  1381. }
  1382. }
  1383. //*****************************************************************************
  1384. //
  1385. //! Connects the USB controller to the bus in device mode.
  1386. //!
  1387. //! \param ui32Base specifies the USB module base address.
  1388. //!
  1389. //! This function causes the soft connect feature of the USB controller to
  1390. //! be enabled. Call USBDevDisconnect() to remove the USB device from the bus.
  1391. //!
  1392. //! \note This function must only be called in device mode.
  1393. //!
  1394. //! \return None.
  1395. //
  1396. //*****************************************************************************
  1397. void
  1398. USBDevConnect(uint32_t ui32Base)
  1399. {
  1400. //
  1401. // Check the arguments.
  1402. //
  1403. ASSERT(ui32Base == USB0_BASE);
  1404. //
  1405. // Enable connection to the USB bus.
  1406. //
  1407. HWREGB(ui32Base + USB_O_POWER) |= USB_POWER_SOFTCONN;
  1408. }
  1409. //*****************************************************************************
  1410. //
  1411. //! Removes the USB controller from the bus in device mode.
  1412. //!
  1413. //! \param ui32Base specifies the USB module base address.
  1414. //!
  1415. //! This function causes the soft connect feature of the USB controller to
  1416. //! remove the device from the USB bus. A call to USBDevConnect() is needed to
  1417. //! reconnect to the bus.
  1418. //!
  1419. //! \note This function must only be called in device mode.
  1420. //!
  1421. //! \return None.
  1422. //
  1423. //*****************************************************************************
  1424. void
  1425. USBDevDisconnect(uint32_t ui32Base)
  1426. {
  1427. //
  1428. // Check the arguments.
  1429. //
  1430. ASSERT(ui32Base == USB0_BASE);
  1431. //
  1432. // Disable connection to the USB bus.
  1433. //
  1434. HWREGB(ui32Base + USB_O_POWER) &= (~USB_POWER_SOFTCONN);
  1435. }
  1436. //*****************************************************************************
  1437. //
  1438. //! Sets the address in device mode.
  1439. //!
  1440. //! \param ui32Base specifies the USB module base address.
  1441. //! \param ui32Address is the address to use for a device.
  1442. //!
  1443. //! This function configures the device address on the USB bus. This address
  1444. //! was likely received via a SET ADDRESS command from the host controller.
  1445. //!
  1446. //! \note This function must only be called in device mode.
  1447. //!
  1448. //! \return None.
  1449. //
  1450. //*****************************************************************************
  1451. void
  1452. USBDevAddrSet(uint32_t ui32Base, uint32_t ui32Address)
  1453. {
  1454. //
  1455. // Check the arguments.
  1456. //
  1457. ASSERT(ui32Base == USB0_BASE);
  1458. //
  1459. // Set the function address in the correct location.
  1460. //
  1461. HWREGB(ui32Base + USB_O_FADDR) = (uint8_t)ui32Address;
  1462. }
  1463. //*****************************************************************************
  1464. //
  1465. //! Returns the current device address in device mode.
  1466. //!
  1467. //! \param ui32Base specifies the USB module base address.
  1468. //!
  1469. //! This function returns the current device address. This address was set
  1470. //! by a call to USBDevAddrSet().
  1471. //!
  1472. //! \note This function must only be called in device mode.
  1473. //!
  1474. //! \return The current device address.
  1475. //
  1476. //*****************************************************************************
  1477. uint32_t
  1478. USBDevAddrGet(uint32_t ui32Base)
  1479. {
  1480. //
  1481. // Check the arguments.
  1482. //
  1483. ASSERT(ui32Base == USB0_BASE);
  1484. //
  1485. // Return the function address.
  1486. //
  1487. return(HWREGB(ui32Base + USB_O_FADDR));
  1488. }
  1489. //*****************************************************************************
  1490. //
  1491. //! Sets the base configuration for a host endpoint.
  1492. //!
  1493. //! \param ui32Base specifies the USB module base address.
  1494. //! \param ui32Endpoint is the endpoint to access.
  1495. //! \param ui32MaxPayload is the maximum payload for this endpoint.
  1496. //! \param ui32NAKPollInterval is the either the NAK timeout limit or the
  1497. //! polling interval, depending on the type of endpoint.
  1498. //! \param ui32TargetEndpoint is the endpoint that the host endpoint is
  1499. //! targeting.
  1500. //! \param ui32Flags are used to configure other endpoint settings.
  1501. //!
  1502. //! This function sets the basic configuration for the transmit or receive
  1503. //! portion of an endpoint in host mode. The \e ui32Flags parameter determines
  1504. //! some of the configuration while the other parameters provide the rest. The
  1505. //! \e ui32Flags parameter determines whether this is an IN endpoint
  1506. //! (\b USB_EP_HOST_IN or \b USB_EP_DEV_IN) or an OUT endpoint
  1507. //! (\b USB_EP_HOST_OUT or \b USB_EP_DEV_OUT), whether this is a Full speed
  1508. //! endpoint (\b USB_EP_SPEED_FULL) or a Low speed endpoint
  1509. //! (\b USB_EP_SPEED_LOW).
  1510. //!
  1511. //! The \b USB_EP_MODE_ flags control the type of the endpoint.
  1512. //! - \b USB_EP_MODE_CTRL is a control endpoint.
  1513. //! - \b USB_EP_MODE_ISOC is an isochronous endpoint.
  1514. //! - \b USB_EP_MODE_BULK is a bulk endpoint.
  1515. //! - \b USB_EP_MODE_INT is an interrupt endpoint.
  1516. //!
  1517. //! The \e ui32NAKPollInterval parameter has different meanings based on the
  1518. //! \b USB_EP_MODE value and whether or not this call is being made for
  1519. //! endpoint zero or another endpoint. For endpoint zero or any Bulk
  1520. //! endpoints, this value always indicates the number of frames to allow a
  1521. //! device to NAK before considering it a timeout. If this endpoint is an
  1522. //! isochronous or interrupt endpoint, this value is the polling interval for
  1523. //! this endpoint.
  1524. //!
  1525. //! For interrupt endpoints, the polling interval is the number of frames
  1526. //! between interrupt IN requests to an endpoint and has a range of 1 to 255.
  1527. //! For isochronous endpoints this value represents a polling interval of
  1528. //! 2 ^ (\e ui32NAKPollInterval - 1) frames. When used as a NAK timeout, the
  1529. //! \e ui32NAKPollInterval value specifies 2 ^ (\e ui32NAKPollInterval - 1)
  1530. //! frames before issuing a time out.
  1531. //!
  1532. //! There are two special time out values that can be specified when setting
  1533. //! the \e ui32NAKPollInterval value. The first is \b MAX_NAK_LIMIT, which is
  1534. //! the maximum value that can be passed in this variable. The other is
  1535. //! \b DISABLE_NAK_LIMIT, which indicates that there is no limit on the
  1536. //! number of NAKs.
  1537. //!
  1538. //! The \b USB_EP_DMA_MODE_ flags determine the type of DMA access to the
  1539. //! endpoint data FIFOs. The choice of the DMA mode depends on how the DMA
  1540. //! controller is configured and how it is being used. See the ``Using USB
  1541. //! with the uDMA Controller'' or the ''Using the integrated USB DMA
  1542. //! Controller'' section for more information on DMA configuration depending
  1543. //! on the type of DMA that is supported by the USB controller.
  1544. //!
  1545. //! When configuring the OUT portion of an endpoint, the \b USB_EP_AUTO_SET bit
  1546. //! is specified to cause the transmission of data on the USB bus to start
  1547. //! as soon as the number of bytes specified by \e ui32MaxPayload has been
  1548. //! written into the OUT FIFO for this endpoint.
  1549. //!
  1550. //! When configuring the IN portion of an endpoint, the \b USB_EP_AUTO_REQUEST
  1551. //! bit can be specified to trigger the request for more data once the FIFO has
  1552. //! been drained enough to fit \e ui32MaxPayload bytes. The
  1553. //! \b USB_EP_AUTO_CLEAR bit can be used to clear the data packet ready flag
  1554. //! automatically once the data has been read from the FIFO. If this option is
  1555. //! not used, this flag must be manually cleared via a call to
  1556. //! USBDevEndpointStatusClear() or USBHostEndpointStatusClear().
  1557. //!
  1558. //! For interrupt endpoints in low or full speed mode, the polling interval
  1559. //! (\e ui32NAKPollInterval) is the number of frames between interrupt IN
  1560. //! requests to an endpoint and has a range of 1 to 255. For interrupt
  1561. //! endpoints in high speed mode the polling interval is
  1562. //! 2 ^ (\e ui32NAKPollInterval - 1) microframes between interrupt IN requests
  1563. //! to an endpoint and has a range of 1 to 16.
  1564. //!
  1565. //! \note This function must only be called in host mode.
  1566. //!
  1567. //! \return None.
  1568. //
  1569. //*****************************************************************************
  1570. void
  1571. USBHostEndpointConfig(uint32_t ui32Base, uint32_t ui32Endpoint,
  1572. uint32_t ui32MaxPayload, uint32_t ui32NAKPollInterval,
  1573. uint32_t ui32TargetEndpoint, uint32_t ui32Flags)
  1574. {
  1575. uint32_t ui32Register;
  1576. //
  1577. // Check the arguments.
  1578. //
  1579. ASSERT(ui32Base == USB0_BASE);
  1580. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  1581. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  1582. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  1583. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  1584. ASSERT(ui32NAKPollInterval <= MAX_NAK_LIMIT);
  1585. //
  1586. // Endpoint zero is configured differently than the other endpoints, so see
  1587. // if this is endpoint zero.
  1588. //
  1589. if(ui32Endpoint == USB_EP_0)
  1590. {
  1591. //
  1592. // Set the NAK timeout.
  1593. //
  1594. HWREGB(ui32Base + USB_O_NAKLMT) = ui32NAKPollInterval;
  1595. //
  1596. // Set the transfer type information.
  1597. //
  1598. //
  1599. // Set the speed of this endpoint.
  1600. //
  1601. if(ui32Flags & USB_EP_SPEED_HIGH)
  1602. {
  1603. HWREGB(ui32Base + USB_O_TYPE0) = USB_TYPE0_SPEED_HIGH;
  1604. }
  1605. else if(ui32Flags & USB_EP_SPEED_FULL)
  1606. {
  1607. HWREGB(ui32Base + USB_O_TYPE0) = USB_TYPE0_SPEED_FULL;
  1608. }
  1609. else
  1610. {
  1611. HWREGB(ui32Base + USB_O_TYPE0) = USB_TYPE0_SPEED_LOW;
  1612. }
  1613. }
  1614. else
  1615. {
  1616. //
  1617. // Start with the target endpoint.
  1618. //
  1619. ui32Register = ui32TargetEndpoint;
  1620. //
  1621. // Set the speed for the device using this endpoint.
  1622. //
  1623. if(ui32Flags & USB_EP_SPEED_HIGH)
  1624. {
  1625. ui32Register |= USB_TXTYPE1_SPEED_HIGH;
  1626. }
  1627. else if(ui32Flags & USB_EP_SPEED_FULL)
  1628. {
  1629. ui32Register |= USB_TXTYPE1_SPEED_FULL;
  1630. }
  1631. else
  1632. {
  1633. ui32Register |= USB_TXTYPE1_SPEED_LOW;
  1634. }
  1635. //
  1636. // Set the protocol for the device using this endpoint.
  1637. //
  1638. switch(ui32Flags & USB_EP_MODE_MASK)
  1639. {
  1640. //
  1641. // The bulk protocol is being used.
  1642. //
  1643. case USB_EP_MODE_BULK:
  1644. {
  1645. ui32Register |= USB_TXTYPE1_PROTO_BULK;
  1646. break;
  1647. }
  1648. //
  1649. // The isochronous protocol is being used.
  1650. //
  1651. case USB_EP_MODE_ISOC:
  1652. {
  1653. ui32Register |= USB_TXTYPE1_PROTO_ISOC;
  1654. break;
  1655. }
  1656. //
  1657. // The interrupt protocol is being used.
  1658. //
  1659. case USB_EP_MODE_INT:
  1660. {
  1661. ui32Register |= USB_TXTYPE1_PROTO_INT;
  1662. break;
  1663. }
  1664. //
  1665. // The control protocol is being used.
  1666. //
  1667. case USB_EP_MODE_CTRL:
  1668. {
  1669. ui32Register |= USB_TXTYPE1_PROTO_CTRL;
  1670. break;
  1671. }
  1672. }
  1673. //
  1674. // See if the transmit or receive endpoint is being configured.
  1675. //
  1676. if(ui32Flags & USB_EP_HOST_OUT)
  1677. {
  1678. //
  1679. // Set the transfer type information.
  1680. //
  1681. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXTYPE1) =
  1682. ui32Register;
  1683. //
  1684. // Set the NAK timeout or polling interval.
  1685. //
  1686. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXINTERVAL1) =
  1687. ui32NAKPollInterval;
  1688. //
  1689. // Set the Maximum Payload per transaction.
  1690. //
  1691. HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXMAXP1) =
  1692. ui32MaxPayload;
  1693. //
  1694. // Set the transmit control value to zero.
  1695. //
  1696. ui32Register = 0;
  1697. //
  1698. // Allow auto setting of TxPktRdy when max packet size has been
  1699. // loaded into the FIFO.
  1700. //
  1701. if(ui32Flags & USB_EP_AUTO_SET)
  1702. {
  1703. ui32Register |= USB_TXCSRH1_AUTOSET;
  1704. }
  1705. //
  1706. // Configure the DMA Mode.
  1707. //
  1708. if(ui32Flags & USB_EP_DMA_MODE_1)
  1709. {
  1710. ui32Register |= USB_TXCSRH1_DMAEN | USB_TXCSRH1_DMAMOD;
  1711. }
  1712. else if(ui32Flags & USB_EP_DMA_MODE_0)
  1713. {
  1714. ui32Register |= USB_TXCSRH1_DMAEN;
  1715. }
  1716. //
  1717. // Write out the transmit control value.
  1718. //
  1719. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRH1) =
  1720. (uint8_t)ui32Register;
  1721. }
  1722. else
  1723. {
  1724. //
  1725. // Set the transfer type information.
  1726. //
  1727. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXTYPE1) =
  1728. ui32Register;
  1729. //
  1730. // Set the NAK timeout or polling interval.
  1731. //
  1732. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXINTERVAL1) =
  1733. ui32NAKPollInterval;
  1734. //
  1735. // Set the Maximum Payload per transaction.
  1736. //
  1737. HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXMAXP1) =
  1738. ui32MaxPayload;
  1739. //
  1740. // Set the receive control value to zero.
  1741. //
  1742. ui32Register = 0;
  1743. //
  1744. // Allow auto clearing of RxPktRdy when packet of size max packet
  1745. // has been unloaded from the FIFO.
  1746. //
  1747. if(ui32Flags & USB_EP_AUTO_CLEAR)
  1748. {
  1749. ui32Register |= USB_RXCSRH1_AUTOCL;
  1750. }
  1751. //
  1752. // Allow auto generation of DMA requests.
  1753. //
  1754. if(ui32Flags & USB_EP_AUTO_REQUEST)
  1755. {
  1756. ui32Register |= USB_RXCSRH1_AUTORQ;
  1757. }
  1758. //
  1759. // Configure the DMA Mode.
  1760. //
  1761. if(ui32Flags & USB_EP_DMA_MODE_1)
  1762. {
  1763. ui32Register |= USB_RXCSRH1_DMAEN | USB_RXCSRH1_DMAMOD;
  1764. }
  1765. else if(ui32Flags & USB_EP_DMA_MODE_0)
  1766. {
  1767. ui32Register |= USB_RXCSRH1_DMAEN;
  1768. }
  1769. //
  1770. // Write out the receive control value.
  1771. //
  1772. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRH1) =
  1773. (uint8_t)ui32Register;
  1774. }
  1775. }
  1776. }
  1777. //*****************************************************************************
  1778. //
  1779. //! Changes the speed of the connection for a host endpoint.
  1780. //!
  1781. //! \param ui32Base specifies the USB module base address.
  1782. //! \param ui32Endpoint is the endpoint to access.
  1783. //! \param ui32Flags are used to configure other endpoint settings.
  1784. //!
  1785. //! This function sets the USB speed for an IN or OUT endpoint in host mode.
  1786. //! The \e ui32Flags parameter specifies the speed using one of the following
  1787. //! values: \b USB_EP_SPEED_LOW, \b USB_EP_SPEED_FULL, or \b USB_EP_SPEED_HIGH.
  1788. //! The \e ui32Flags parameter also specifies which direction is set by
  1789. //! adding the logical OR in either \b USB_EP_HOST_IN or \b USB_EP_HOST_OUT.
  1790. //! All other flags are ignored. This function is typically only used for
  1791. //! endpoint 0, but could be used with other endpoints as well.
  1792. //!
  1793. //! \b Example: Set host transactions on endpoint 0 to full speed..
  1794. //!
  1795. //! \verbatim
  1796. //! //
  1797. //! // Set host endpoint 0 transactions to full speed.
  1798. //! //
  1799. //! USBHostEndpointSpeed(USB0_BASE, USB_EP_0, USB_EP_SPEED_FULL);
  1800. //! \endverbatim
  1801. //!
  1802. //! \note This function must only be called in host mode.
  1803. //!
  1804. //! \return None.
  1805. //
  1806. //*****************************************************************************
  1807. void
  1808. USBHostEndpointSpeed(uint32_t ui32Base, uint32_t ui32Endpoint,
  1809. uint32_t ui32Flags)
  1810. {
  1811. uint32_t ui32Reg;
  1812. uint32_t ui32Speed;
  1813. //
  1814. // Check the arguments.
  1815. //
  1816. ASSERT(ui32Base == USB0_BASE);
  1817. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  1818. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  1819. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  1820. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  1821. //
  1822. // Create the register speed value.
  1823. //
  1824. if(ui32Flags & USB_EP_SPEED_HIGH)
  1825. {
  1826. ui32Speed = USB_TYPE0_SPEED_HIGH;
  1827. }
  1828. else if(ui32Flags & USB_EP_SPEED_FULL)
  1829. {
  1830. ui32Speed = USB_TYPE0_SPEED_FULL;
  1831. }
  1832. else
  1833. {
  1834. ui32Speed = USB_TYPE0_SPEED_LOW;
  1835. }
  1836. //
  1837. // Endpoint 0 is handled differently as it is bi-directional.
  1838. //
  1839. if(ui32Endpoint == USB_EP_0)
  1840. {
  1841. HWREGB(ui32Base + USB_O_TYPE0) = ui32Speed;
  1842. }
  1843. else if(ui32Flags & USB_EP_HOST_OUT)
  1844. {
  1845. //
  1846. // Clear the current speed and set the new speed.
  1847. //
  1848. ui32Reg = (HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXTYPE1) &
  1849. ~(USB_TXTYPE1_SPEED_M));
  1850. ui32Reg |= ui32Speed;
  1851. HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXTYPE1) |= ui32Reg;
  1852. }
  1853. else
  1854. {
  1855. //
  1856. // Clear the current speed and set the new speed.
  1857. //
  1858. ui32Reg = (HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXTYPE1) &
  1859. ~(USB_RXTYPE1_SPEED_M));
  1860. ui32Reg |= ui32Speed;
  1861. HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXTYPE1) |= ui32Reg;
  1862. }
  1863. }
  1864. //*****************************************************************************
  1865. //
  1866. //! Sets the configuration for an endpoint.
  1867. //!
  1868. //! \param ui32Base specifies the USB module base address.
  1869. //! \param ui32Endpoint is the endpoint to access.
  1870. //! \param ui32MaxPacketSize is the maximum packet size for this endpoint.
  1871. //! \param ui32Flags are used to configure other endpoint settings.
  1872. //!
  1873. //! This function sets the basic configuration for an endpoint in device mode.
  1874. //! Endpoint zero does not have a dynamic configuration, so this function
  1875. //! must not be called for endpoint zero. The \e ui32Flags parameter
  1876. //! determines some of the configuration while the other parameters provide the
  1877. //! rest.
  1878. //!
  1879. //! The \b USB_EP_MODE_ flags define what the type is for the specified endpoint.
  1880. //!
  1881. //! - \b USB_EP_MODE_CTRL is a control endpoint.
  1882. //! - \b USB_EP_MODE_ISOC is an isochronous endpoint.
  1883. //! - \b USB_EP_MODE_BULK is a bulk endpoint.
  1884. //! - \b USB_EP_MODE_INT is an interrupt endpoint.
  1885. //!
  1886. //! The \b USB_EP_DMA_MODE_ flags determine the type of DMA access to the
  1887. //! endpoint data FIFOs. The choice of the DMA mode depends on how the DMA
  1888. //! controller is configured and how it is being used. See the ``Using USB
  1889. //! with the uDMA Controller'' or the ''Using the integrated USB DMA
  1890. //! Controller'' section for more information on DMA configuration depending
  1891. //! on the type of DMA that is supported by the USB controller.
  1892. //!
  1893. //! When configuring an IN endpoint, the \b USB_EP_AUTO_SET bit can be
  1894. //! specified to cause the automatic transmission of data on the USB bus as
  1895. //! soon as \e ui32MaxPacketSize bytes of data are written into the FIFO for
  1896. //! this endpoint. This option is commonly used with DMA (both on devices
  1897. //! with integrated USB DMA as well as those that use uDMA) as no interaction
  1898. //! is required to start the transmission of data.
  1899. //!
  1900. //! When configuring an OUT endpoint, the \b USB_EP_AUTO_REQUEST bit is
  1901. //! specified to trigger the request for more data once the FIFO has been
  1902. //! drained enough to receive \e ui32MaxPacketSize more bytes of data. Also
  1903. //! for OUT endpoints, the \b USB_EP_AUTO_CLEAR bit can be used to clear the
  1904. //! data packet ready flag automatically once the data has been read from the
  1905. //! FIFO. If this option is not used, this flag must be manually cleared via a
  1906. //! call to USBDevEndpointStatusClear(). Both of these settings can be used to
  1907. //! remove the need for extra calls when using the controller with DMA.
  1908. //!
  1909. //! \note This function must only be called in device mode.
  1910. //!
  1911. //! \return None.
  1912. //
  1913. //*****************************************************************************
  1914. void
  1915. USBDevEndpointConfigSet(uint32_t ui32Base, uint32_t ui32Endpoint,
  1916. uint32_t ui32MaxPacketSize, uint32_t ui32Flags)
  1917. {
  1918. uint32_t ui32Register;
  1919. //
  1920. // Check the arguments.
  1921. //
  1922. ASSERT(ui32Base == USB0_BASE);
  1923. ASSERT((ui32Endpoint == USB_EP_1) || (ui32Endpoint == USB_EP_2) ||
  1924. (ui32Endpoint == USB_EP_3) || (ui32Endpoint == USB_EP_4) ||
  1925. (ui32Endpoint == USB_EP_5) || (ui32Endpoint == USB_EP_6) ||
  1926. (ui32Endpoint == USB_EP_7));
  1927. //
  1928. // Determine if a transmit or receive endpoint is being configured.
  1929. //
  1930. if(ui32Flags & USB_EP_DEV_IN)
  1931. {
  1932. //
  1933. // Set the maximum packet size.
  1934. //
  1935. HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXMAXP1) =
  1936. ui32MaxPacketSize;
  1937. //
  1938. // The transmit control value is zero unless options are enabled.
  1939. //
  1940. ui32Register = 0;
  1941. //
  1942. // Allow auto setting of TxPktRdy when max packet size has been loaded
  1943. // into the FIFO.
  1944. //
  1945. if(ui32Flags & USB_EP_AUTO_SET)
  1946. {
  1947. ui32Register |= USB_TXCSRH1_AUTOSET;
  1948. }
  1949. //
  1950. // Configure the DMA mode.
  1951. //
  1952. if(ui32Flags & USB_EP_DMA_MODE_1)
  1953. {
  1954. ui32Register |= USB_TXCSRH1_DMAEN | USB_TXCSRH1_DMAMOD;
  1955. }
  1956. else if(ui32Flags & USB_EP_DMA_MODE_0)
  1957. {
  1958. ui32Register |= USB_TXCSRH1_DMAEN;
  1959. }
  1960. //
  1961. // Enable isochronous mode if requested.
  1962. //
  1963. if((ui32Flags & USB_EP_MODE_MASK) == USB_EP_MODE_ISOC)
  1964. {
  1965. ui32Register |= USB_TXCSRH1_ISO;
  1966. }
  1967. //
  1968. // Write the transmit control value.
  1969. //
  1970. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRH1) =
  1971. (uint8_t)ui32Register;
  1972. //
  1973. // Reset the Data toggle to zero.
  1974. //
  1975. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRL1) =
  1976. USB_TXCSRL1_CLRDT;
  1977. }
  1978. else
  1979. {
  1980. //
  1981. // Set the MaxPacketSize.
  1982. //
  1983. HWREGH(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXMAXP1) =
  1984. ui32MaxPacketSize;
  1985. //
  1986. // The receive control value is zero unless options are enabled.
  1987. //
  1988. ui32Register = 0;
  1989. //
  1990. // Allow auto clearing of RxPktRdy when packet of size max packet
  1991. // has been unloaded from the FIFO.
  1992. //
  1993. if(ui32Flags & USB_EP_AUTO_CLEAR)
  1994. {
  1995. ui32Register = USB_RXCSRH1_AUTOCL;
  1996. }
  1997. //
  1998. // Configure the DMA mode.
  1999. //
  2000. if(ui32Flags & USB_EP_DMA_MODE_1)
  2001. {
  2002. ui32Register |= USB_RXCSRH1_DMAEN | USB_RXCSRH1_DMAMOD;
  2003. }
  2004. else if(ui32Flags & USB_EP_DMA_MODE_0)
  2005. {
  2006. ui32Register |= USB_RXCSRH1_DMAEN;
  2007. }
  2008. //
  2009. // If requested, disable NYET responses for high-speed bulk and
  2010. // interrupt endpoints.
  2011. //
  2012. if(ui32Flags & USB_EP_DIS_NYET)
  2013. {
  2014. ui32Register |= USB_RXCSRH1_DISNYET;
  2015. }
  2016. //
  2017. // Enable isochronous mode if requested.
  2018. //
  2019. if((ui32Flags & USB_EP_MODE_MASK) == USB_EP_MODE_ISOC)
  2020. {
  2021. ui32Register |= USB_RXCSRH1_ISO;
  2022. }
  2023. //
  2024. // Write the receive control value.
  2025. //
  2026. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRH1) =
  2027. (uint8_t)ui32Register;
  2028. //
  2029. // Reset the Data toggle to zero.
  2030. //
  2031. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRL1) =
  2032. USB_RXCSRL1_CLRDT;
  2033. }
  2034. }
  2035. //*****************************************************************************
  2036. //
  2037. //! Gets the current configuration for an endpoint.
  2038. //!
  2039. //! \param ui32Base specifies the USB module base address.
  2040. //! \param ui32Endpoint is the endpoint to access.
  2041. //! \param pui32MaxPacketSize is a pointer which is written with the maximum
  2042. //! packet size for this endpoint.
  2043. //! \param pui32Flags is a pointer which is written with the current endpoint
  2044. //! settings. On entry to the function, this pointer must contain either
  2045. //! \b USB_EP_DEV_IN or \b USB_EP_DEV_OUT to indicate whether the IN or OUT
  2046. //! endpoint is to be queried.
  2047. //!
  2048. //! This function returns the basic configuration for an endpoint in device
  2049. //! mode. The values returned in \e *pui32MaxPacketSize and \e *pui32Flags are
  2050. //! equivalent to the \e ui32MaxPacketSize and \e ui32Flags previously passed
  2051. //! to USBDevEndpointConfigSet() for this endpoint.
  2052. //!
  2053. //! \note This function must only be called in device mode.
  2054. //!
  2055. //! \return None.
  2056. //
  2057. //*****************************************************************************
  2058. void
  2059. USBDevEndpointConfigGet(uint32_t ui32Base, uint32_t ui32Endpoint,
  2060. uint32_t *pui32MaxPacketSize, uint32_t *pui32Flags)
  2061. {
  2062. uint32_t ui32Register;
  2063. //
  2064. // Check the arguments.
  2065. //
  2066. ASSERT(ui32Base == USB0_BASE);
  2067. ASSERT(pui32MaxPacketSize && pui32Flags);
  2068. ASSERT((ui32Endpoint == USB_EP_1) || (ui32Endpoint == USB_EP_2) ||
  2069. (ui32Endpoint == USB_EP_3) || (ui32Endpoint == USB_EP_4) ||
  2070. (ui32Endpoint == USB_EP_5) || (ui32Endpoint == USB_EP_6) ||
  2071. (ui32Endpoint == USB_EP_7));
  2072. //
  2073. // Determine if a transmit or receive endpoint is being queried.
  2074. //
  2075. if(*pui32Flags & USB_EP_DEV_IN)
  2076. {
  2077. //
  2078. // Clear the flags other than the direction bit.
  2079. //
  2080. *pui32Flags = USB_EP_DEV_IN;
  2081. //
  2082. // Get the maximum packet size.
  2083. //
  2084. *pui32MaxPacketSize = (uint32_t)HWREGH(ui32Base +
  2085. EP_OFFSET(ui32Endpoint) +
  2086. USB_O_TXMAXP1);
  2087. //
  2088. // Get the current transmit control register value.
  2089. //
  2090. ui32Register = (uint32_t)HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) +
  2091. USB_O_TXCSRH1);
  2092. //
  2093. // Are we allowing auto setting of TxPktRdy when max packet size has
  2094. // been loaded into the FIFO?
  2095. //
  2096. if(ui32Register & USB_TXCSRH1_AUTOSET)
  2097. {
  2098. *pui32Flags |= USB_EP_AUTO_SET;
  2099. }
  2100. //
  2101. // Get the DMA mode.
  2102. //
  2103. if(ui32Register & USB_TXCSRH1_DMAEN)
  2104. {
  2105. if(ui32Register & USB_TXCSRH1_DMAMOD)
  2106. {
  2107. *pui32Flags |= USB_EP_DMA_MODE_1;
  2108. }
  2109. else
  2110. {
  2111. *pui32Flags |= USB_EP_DMA_MODE_0;
  2112. }
  2113. }
  2114. //
  2115. // Are we in isochronous mode?
  2116. //
  2117. if(ui32Register & USB_TXCSRH1_ISO)
  2118. {
  2119. *pui32Flags |= USB_EP_MODE_ISOC;
  2120. }
  2121. else
  2122. {
  2123. //
  2124. // The hardware doesn't differentiate between bulk, interrupt
  2125. // and control mode for the endpoint so we just set something
  2126. // that isn't isochronous. This protocol ensures that anyone
  2127. // modifying the returned flags in preparation for a call to
  2128. // USBDevEndpointConfigSet do not see an unexpected mode change.
  2129. // If they decode the returned mode, however, they may be in for
  2130. // a surprise.
  2131. //
  2132. *pui32Flags |= USB_EP_MODE_BULK;
  2133. }
  2134. }
  2135. else
  2136. {
  2137. //
  2138. // Clear the flags other than the direction bit.
  2139. //
  2140. *pui32Flags = USB_EP_DEV_OUT;
  2141. //
  2142. // Get the MaxPacketSize.
  2143. //
  2144. *pui32MaxPacketSize = (uint32_t)HWREGH(ui32Base +
  2145. EP_OFFSET(ui32Endpoint) +
  2146. USB_O_RXMAXP1);
  2147. //
  2148. // Get the current receive control register value.
  2149. //
  2150. ui32Register = (uint32_t)HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) +
  2151. USB_O_RXCSRH1);
  2152. //
  2153. // Are we allowing auto clearing of RxPktRdy when packet of size max
  2154. // packet has been unloaded from the FIFO?
  2155. //
  2156. if(ui32Register & USB_RXCSRH1_AUTOCL)
  2157. {
  2158. *pui32Flags |= USB_EP_AUTO_CLEAR;
  2159. }
  2160. //
  2161. // Get the DMA mode.
  2162. //
  2163. if(ui32Register & USB_RXCSRH1_DMAEN)
  2164. {
  2165. if(ui32Register & USB_RXCSRH1_DMAMOD)
  2166. {
  2167. *pui32Flags |= USB_EP_DMA_MODE_1;
  2168. }
  2169. else
  2170. {
  2171. *pui32Flags |= USB_EP_DMA_MODE_0;
  2172. }
  2173. }
  2174. //
  2175. // Are we in isochronous mode?
  2176. //
  2177. if(ui32Register & USB_RXCSRH1_ISO)
  2178. {
  2179. *pui32Flags |= USB_EP_MODE_ISOC;
  2180. }
  2181. else
  2182. {
  2183. //
  2184. // The hardware doesn't differentiate between bulk, interrupt
  2185. // and control mode for the endpoint so we just set something
  2186. // that isn't isochronous. This protocol ensures that anyone
  2187. // modifying the returned flags in preparation for a call to
  2188. // USBDevEndpointConfigSet do not see an unexpected mode change.
  2189. // If they decode the returned mode, however, they may be in for
  2190. // a surprise.
  2191. //
  2192. *pui32Flags |= USB_EP_MODE_BULK;
  2193. }
  2194. }
  2195. }
  2196. //*****************************************************************************
  2197. //
  2198. //! Sets the FIFO configuration for an endpoint.
  2199. //!
  2200. //! \param ui32Base specifies the USB module base address.
  2201. //! \param ui32Endpoint is the endpoint to access.
  2202. //! \param ui32FIFOAddress is the starting address for the FIFO.
  2203. //! \param ui32FIFOSize is the size of the FIFO specified by one of the
  2204. //! \b USB_FIFO_SZ_ values.
  2205. //! \param ui32Flags specifies what information to set in the FIFO
  2206. //! configuration.
  2207. //!
  2208. //! This function configures the starting FIFO RAM address and size of the FIFO
  2209. //! for a specified endpoint. Endpoint zero does not have a dynamically
  2210. //! configurable FIFO, so this function must not be called for endpoint zero.
  2211. //! The \e ui32FIFOSize parameter must be one of the values in the
  2212. //! \b USB_FIFO_SZ_ values.
  2213. //!
  2214. //! The \e ui32FIFOAddress value must be a multiple of 8 bytes and directly
  2215. //! indicates the starting address in the USB controller's FIFO RAM. For
  2216. //! example, a value of 64 indicates that the FIFO starts 64 bytes into
  2217. //! the USB controller's FIFO memory. The \e ui32Flags value specifies whether
  2218. //! the endpoint's OUT or IN FIFO must be configured. If in host mode, use
  2219. //! \b USB_EP_HOST_OUT or \b USB_EP_HOST_IN, and if in device mode, use
  2220. //! \b USB_EP_DEV_OUT or \b USB_EP_DEV_IN.
  2221. //!
  2222. //! \return None.
  2223. //
  2224. //*****************************************************************************
  2225. void
  2226. USBFIFOConfigSet(uint32_t ui32Base, uint32_t ui32Endpoint,
  2227. uint32_t ui32FIFOAddress, uint32_t ui32FIFOSize,
  2228. uint32_t ui32Flags)
  2229. {
  2230. //
  2231. // Check the arguments.
  2232. //
  2233. ASSERT(ui32Base == USB0_BASE);
  2234. ASSERT((ui32Endpoint == USB_EP_1) || (ui32Endpoint == USB_EP_2) ||
  2235. (ui32Endpoint == USB_EP_3) || (ui32Endpoint == USB_EP_4) ||
  2236. (ui32Endpoint == USB_EP_5) || (ui32Endpoint == USB_EP_6) ||
  2237. (ui32Endpoint == USB_EP_7));
  2238. //
  2239. // See if the transmit or receive FIFO is being configured.
  2240. //
  2241. if(ui32Flags & (USB_EP_HOST_OUT | USB_EP_DEV_IN))
  2242. {
  2243. //
  2244. // Set the transmit FIFO location and size for this endpoint.
  2245. //
  2246. _USBIndexWrite(ui32Base, ui32Endpoint >> 4, USB_O_TXFIFOSZ,
  2247. ui32FIFOSize, 1);
  2248. _USBIndexWrite(ui32Base, ui32Endpoint >> 4, USB_O_TXFIFOADD,
  2249. ui32FIFOAddress >> 3, 2);
  2250. }
  2251. else
  2252. {
  2253. //
  2254. // Set the receive FIFO location and size for this endpoint.
  2255. //
  2256. _USBIndexWrite(ui32Base, ui32Endpoint >> 4, USB_O_RXFIFOSZ,
  2257. ui32FIFOSize, 1);
  2258. _USBIndexWrite(ui32Base, ui32Endpoint >> 4, USB_O_RXFIFOADD,
  2259. ui32FIFOAddress >> 3, 2);
  2260. }
  2261. }
  2262. //*****************************************************************************
  2263. //
  2264. //! Returns the FIFO configuration for an endpoint.
  2265. //!
  2266. //! \param ui32Base specifies the USB module base address.
  2267. //! \param ui32Endpoint is the endpoint to access.
  2268. //! \param pui32FIFOAddress is the starting address for the FIFO.
  2269. //! \param pui32FIFOSize is the size of the FIFO as specified by one of the
  2270. //! \b USB_FIFO_SZ_ values.
  2271. //! \param ui32Flags specifies what information to retrieve from the FIFO
  2272. //! configuration.
  2273. //!
  2274. //! This function returns the starting address and size of the FIFO for a
  2275. //! specified endpoint. Endpoint zero does not have a dynamically configurable
  2276. //! FIFO, so this function must not be called for endpoint zero. The
  2277. //! \e ui32Flags parameter specifies whether the endpoint's OUT or IN FIFO must
  2278. //! be read. If in host mode, the \e ui32Flags parameter must be
  2279. //! \b USB_EP_HOST_OUT or \b USB_EP_HOST_IN, and if in device mode, the
  2280. //! \e ui32Flags parameter must be either \b USB_EP_DEV_OUT or
  2281. //! \b USB_EP_DEV_IN.
  2282. //!
  2283. //! \return None.
  2284. //
  2285. //*****************************************************************************
  2286. void
  2287. USBFIFOConfigGet(uint32_t ui32Base, uint32_t ui32Endpoint,
  2288. uint32_t *pui32FIFOAddress, uint32_t *pui32FIFOSize,
  2289. uint32_t ui32Flags)
  2290. {
  2291. //
  2292. // Check the arguments.
  2293. //
  2294. ASSERT(ui32Base == USB0_BASE);
  2295. ASSERT((ui32Endpoint == USB_EP_1) || (ui32Endpoint == USB_EP_2) ||
  2296. (ui32Endpoint == USB_EP_3) || (ui32Endpoint == USB_EP_4) ||
  2297. (ui32Endpoint == USB_EP_5) || (ui32Endpoint == USB_EP_6) ||
  2298. (ui32Endpoint == USB_EP_7));
  2299. //
  2300. // See if the transmit or receive FIFO is being configured.
  2301. //
  2302. if(ui32Flags & (USB_EP_HOST_OUT | USB_EP_DEV_IN))
  2303. {
  2304. //
  2305. // Get the transmit FIFO location and size for this endpoint.
  2306. //
  2307. *pui32FIFOAddress = (_USBIndexRead(ui32Base, ui32Endpoint >> 4,
  2308. (uint32_t)USB_O_TXFIFOADD,
  2309. 2)) << 3;
  2310. *pui32FIFOSize = _USBIndexRead(ui32Base, ui32Endpoint >> 4,
  2311. (uint32_t)USB_O_TXFIFOSZ, 1);
  2312. }
  2313. else
  2314. {
  2315. //
  2316. // Get the receive FIFO location and size for this endpoint.
  2317. //
  2318. *pui32FIFOAddress = (_USBIndexRead(ui32Base, ui32Endpoint >> 4,
  2319. (uint32_t)USB_O_RXFIFOADD,
  2320. 2)) << 3;
  2321. *pui32FIFOSize = _USBIndexRead(ui32Base, ui32Endpoint >> 4,
  2322. (uint32_t)USB_O_RXFIFOSZ, 1);
  2323. }
  2324. }
  2325. //*****************************************************************************
  2326. //
  2327. //! Configure the DMA settings for an endpoint.
  2328. //!
  2329. //! \param ui32Base specifies the USB module base address.
  2330. //! \param ui32Endpoint is the endpoint to access.
  2331. //! \param ui32Config specifies the configuration options for an endpoint.
  2332. //!
  2333. //! This function configures the DMA settings for a specified endpoint without
  2334. //! changing other options that may already be configured. In order for the
  2335. //! DMA transfer to be enabled, the USBEndpointDMAEnable() function must be
  2336. //! called before starting the DMA transfer. The configuration
  2337. //! options are passed in the \e ui32Config parameter and can have the values
  2338. //! described below.
  2339. //!
  2340. //! One of the following values to specify direction:
  2341. //! - \b USB_EP_HOST_OUT or \b USB_EP_DEV_IN - This setting is used with
  2342. //! DMA transfers from memory to the USB controller.
  2343. //! - \b USB_EP_HOST_IN or \b USB_EP_DEV_OUT - This setting is used with
  2344. //! DMA transfers from the USB controller to memory.
  2345. //!
  2346. //! One of the following values:
  2347. //! - \b USB_EP_DMA_MODE_0(default) - This setting is typically used for
  2348. //! transfers that do not span multiple packets or when interrupts are
  2349. //! required for each packet.
  2350. //! - \b USB_EP_DMA_MODE_1 - This setting is typically used for
  2351. //! transfers that span multiple packets and do not require interrupts
  2352. //! between packets.
  2353. //!
  2354. //! Values only used with \b USB_EP_HOST_OUT or \b USB_EP_DEV_IN:
  2355. //! - \b USB_EP_AUTO_SET - This setting is used to allow transmit DMA transfers
  2356. //! to automatically be sent when a full packet is loaded into a FIFO.
  2357. //! This is needed with \b USB_EP_DMA_MODE_1 to ensure that packets go
  2358. //! out when the FIFO becomes full and the DMA has more data to send.
  2359. //!
  2360. //! Values only used with \b USB_EP_HOST_IN or \b USB_EP_DEV_OUT:
  2361. //! - \b USB_EP_AUTO_CLEAR - This setting is used to allow receive DMA
  2362. //! transfers to automatically be acknowledged as they are received. This is
  2363. //! needed with \b USB_EP_DMA_MODE_1 to ensure that packets continue to
  2364. //! be received and acknowledged when the FIFO is emptied by the DMA
  2365. //! transfer.
  2366. //!
  2367. //! Values only used with \b USB_EP_HOST_IN:
  2368. //! - \b USB_EP_AUTO_REQUEST - This setting is used to allow receive DMA
  2369. //! transfers to automatically request a new IN transaction when the
  2370. //! previous transfer has emptied the FIFO. This is typically used in
  2371. //! conjunction with \b USB_EP_AUTO_CLEAR so that receive DMA transfers
  2372. //! can continue without interrupting the main processor.
  2373. //!
  2374. //! \b Example: Set endpoint 1 receive endpoint to automatically acknowledge
  2375. //! request and automatically generate a new IN request in host mode.
  2376. //!
  2377. //! \verbatim
  2378. //! //
  2379. //! // Configure endpoint 1 for receiving multiple packets using DMA.
  2380. //! //
  2381. //! USBEndpointDMAConfigSet(USB0_BASE, USB_EP_1, USB_EP_HOST_IN |
  2382. //! USB_EP_DMA_MODE_1 |
  2383. //! USB_EP_AUTO_CLEAR |
  2384. //! USB_EP_AUTO_REQUEST);
  2385. //! \endverbatim
  2386. //!
  2387. //! \b Example: Set endpoint 2 transmit endpoint to automatically send each
  2388. //! packet in host mode when spanning multiple packets.
  2389. //!
  2390. //! \verbatim
  2391. //! //
  2392. //! // Configure endpoint 1 for transmitting multiple packets using DMA.
  2393. //! //
  2394. //! USBEndpointDMAConfigSet(USB0_BASE, USB_EP_2, USB_EP_HOST_OUT |
  2395. //! USB_EP_DMA_MODE_1 |
  2396. //! USB_EP_AUTO_SET);
  2397. //! \endverbatim
  2398. //!
  2399. //! \return None.
  2400. //
  2401. //*****************************************************************************
  2402. void
  2403. USBEndpointDMAConfigSet(uint32_t ui32Base, uint32_t ui32Endpoint,
  2404. uint32_t ui32Config)
  2405. {
  2406. uint32_t ui32NewConfig;
  2407. if(ui32Config & USB_EP_HOST_OUT)
  2408. {
  2409. //
  2410. // Clear mode and DMA enable.
  2411. //
  2412. ui32NewConfig =
  2413. (HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRH1) &
  2414. ~(USB_TXCSRH1_DMAMOD | USB_TXCSRH1_AUTOSET));
  2415. if(ui32Config & USB_EP_DMA_MODE_1)
  2416. {
  2417. ui32NewConfig |= USB_TXCSRH1_DMAMOD;
  2418. }
  2419. if(ui32Config & USB_EP_AUTO_SET)
  2420. {
  2421. ui32NewConfig |= USB_TXCSRH1_AUTOSET;
  2422. }
  2423. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRH1) =
  2424. ui32NewConfig;
  2425. }
  2426. else
  2427. {
  2428. ui32NewConfig =
  2429. (HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRH1) &
  2430. ~(USB_RXCSRH1_AUTORQ | USB_RXCSRH1_AUTOCL | USB_RXCSRH1_DMAMOD));
  2431. if(ui32Config & USB_EP_DMA_MODE_1)
  2432. {
  2433. ui32NewConfig |= USB_RXCSRH1_DMAMOD;
  2434. }
  2435. if(ui32Config & USB_EP_AUTO_CLEAR)
  2436. {
  2437. ui32NewConfig |= USB_RXCSRH1_AUTOCL;
  2438. }
  2439. if(ui32Config & USB_EP_AUTO_REQUEST)
  2440. {
  2441. ui32NewConfig |= USB_RXCSRH1_AUTORQ;
  2442. }
  2443. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRH1) =
  2444. ui32NewConfig;
  2445. }
  2446. }
  2447. //*****************************************************************************
  2448. //
  2449. //! Enable DMA on a specified endpoint.
  2450. //!
  2451. //! \param ui32Base specifies the USB module base address.
  2452. //! \param ui32Endpoint is the endpoint to access.
  2453. //! \param ui32Flags specifies which direction and what mode to use when
  2454. //! enabling DMA.
  2455. //!
  2456. //! This function enables DMA on a specified endpoint and configures the mode
  2457. //! according to the values in the \e ui32Flags parameter. The \e ui32Flags
  2458. //! parameter must have \b USB_EP_DEV_IN or \b USB_EP_DEV_OUT set. Once this
  2459. //! function is called the only DMA or error interrupts are generated by the
  2460. //! USB controller.
  2461. //!
  2462. //! \note If this function is called when an endpoint is configured in DMA
  2463. //! mode 0 the USB controller does not generate an interrupt.
  2464. //!
  2465. //! \return None.
  2466. //
  2467. //*****************************************************************************
  2468. void
  2469. USBEndpointDMAEnable(uint32_t ui32Base, uint32_t ui32Endpoint,
  2470. uint32_t ui32Flags)
  2471. {
  2472. //
  2473. // See if the transmit DMA is being enabled.
  2474. //
  2475. if(ui32Flags & USB_EP_DEV_IN)
  2476. {
  2477. //
  2478. // Enable DMA on the transmit endpoint.
  2479. //
  2480. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRH1) |=
  2481. USB_TXCSRH1_DMAEN;
  2482. }
  2483. else
  2484. {
  2485. //
  2486. // Enable DMA on the receive endpoint.
  2487. //
  2488. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRH1) |=
  2489. USB_RXCSRH1_DMAEN;
  2490. }
  2491. }
  2492. //*****************************************************************************
  2493. //
  2494. //! Disable DMA on a specified endpoint.
  2495. //!
  2496. //! \param ui32Base specifies the USB module base address.
  2497. //! \param ui32Endpoint is the endpoint to access.
  2498. //! \param ui32Flags specifies which direction to disable.
  2499. //!
  2500. //! This function disables DMA on a specified endpoint to allow non-DMA USB
  2501. //! transactions to generate interrupts normally. The \e ui32Flags parameter
  2502. //! must be \b USB_EP_DEV_IN or \b USB_EP_DEV_OUT; all other bits are ignored.
  2503. //!
  2504. //! \return None.
  2505. //
  2506. //*****************************************************************************
  2507. void
  2508. USBEndpointDMADisable(uint32_t ui32Base, uint32_t ui32Endpoint,
  2509. uint32_t ui32Flags)
  2510. {
  2511. //
  2512. // If this was a request to disable DMA on the IN portion of the endpoint
  2513. // then handle it.
  2514. //
  2515. if(ui32Flags & USB_EP_DEV_IN)
  2516. {
  2517. //
  2518. // Just disable DMA leave the mode setting.
  2519. //
  2520. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_TXCSRH1) &=
  2521. ~USB_TXCSRH1_DMAEN;
  2522. }
  2523. else
  2524. {
  2525. //
  2526. // Just disable DMA leave the mode setting.
  2527. //
  2528. HWREGB(ui32Base + EP_OFFSET(ui32Endpoint) + USB_O_RXCSRH1) &=
  2529. ~USB_RXCSRH1_DMAEN;
  2530. }
  2531. }
  2532. //*****************************************************************************
  2533. //
  2534. //! Determines the number of bytes of data available in a specified endpoint's
  2535. //! FIFO.
  2536. //!
  2537. //! \param ui32Base specifies the USB module base address.
  2538. //! \param ui32Endpoint is the endpoint to access.
  2539. //!
  2540. //! This function returns the number of bytes of data currently available in
  2541. //! the FIFO for the specified receive (OUT) endpoint. It may be used prior to
  2542. //! calling USBEndpointDataGet() to determine the size of buffer required to
  2543. //! hold the newly-received packet.
  2544. //!
  2545. //! \return This call returns the number of bytes available in a specified endpoint
  2546. //! FIFO.
  2547. //
  2548. //*****************************************************************************
  2549. uint32_t
  2550. USBEndpointDataAvail(uint32_t ui32Base, uint32_t ui32Endpoint)
  2551. {
  2552. uint32_t ui32Register;
  2553. //
  2554. // Check the arguments.
  2555. //
  2556. ASSERT(ui32Base == USB0_BASE);
  2557. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  2558. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  2559. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  2560. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  2561. //
  2562. // Get the address of the receive status register to use, based on the
  2563. // endpoint.
  2564. //
  2565. if(ui32Endpoint == USB_EP_0)
  2566. {
  2567. ui32Register = USB_O_CSRL0;
  2568. }
  2569. else
  2570. {
  2571. ui32Register = USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint);
  2572. }
  2573. //
  2574. // Is there a packet ready in the FIFO?
  2575. //
  2576. if((HWREGH(ui32Base + ui32Register) & USB_CSRL0_RXRDY) == 0)
  2577. {
  2578. return(0);
  2579. }
  2580. //
  2581. // Return the byte count in the FIFO.
  2582. //
  2583. return(HWREGH(ui32Base + USB_O_COUNT0 + ui32Endpoint));
  2584. }
  2585. //*****************************************************************************
  2586. //
  2587. //! Retrieves data from the specified endpoint's FIFO.
  2588. //!
  2589. //! \param ui32Base specifies the USB module base address.
  2590. //! \param ui32Endpoint is the endpoint to access.
  2591. //! \param pui8Data is a pointer to the data area used to return the data from
  2592. //! the FIFO.
  2593. //! \param pui32Size is initially the size of the buffer passed into this call
  2594. //! via the \e pui8Data parameter. It is set to the amount of data returned in
  2595. //! the buffer.
  2596. //!
  2597. //! This function returns the data from the FIFO for the specified endpoint.
  2598. //! The \e pui32Size parameter indicates the size of the buffer passed in
  2599. //! the \e pui32Data parameter. The data in the \e pui32Size parameter is
  2600. //! changed to match the amount of data returned in the \e pui8Data parameter.
  2601. //! If a zero-byte packet is received, this call does not return an error but
  2602. //! instead just returns a zero in the \e pui32Size parameter. The only error
  2603. //! case occurs when there is no data packet available.
  2604. //!
  2605. //! \return This call returns 0, or -1 if no packet was received.
  2606. //
  2607. //*****************************************************************************
  2608. int32_t
  2609. USBEndpointDataGet(uint32_t ui32Base, uint32_t ui32Endpoint,
  2610. uint8_t *pui8Data, uint32_t *pui32Size)
  2611. {
  2612. uint32_t ui32Register, ui32ByteCount, ui32FIFO;
  2613. //
  2614. // Check the arguments.
  2615. //
  2616. ASSERT(ui32Base == USB0_BASE);
  2617. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  2618. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  2619. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  2620. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  2621. //
  2622. // Get the address of the receive status register to use, based on the
  2623. // endpoint.
  2624. //
  2625. if(ui32Endpoint == USB_EP_0)
  2626. {
  2627. ui32Register = USB_O_CSRL0;
  2628. }
  2629. else
  2630. {
  2631. ui32Register = USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint);
  2632. }
  2633. //
  2634. // Don't allow reading of data if the RxPktRdy bit is not set.
  2635. //
  2636. if((HWREGH(ui32Base + ui32Register) & USB_CSRL0_RXRDY) == 0)
  2637. {
  2638. //
  2639. // Can't read the data because none is available.
  2640. //
  2641. *pui32Size = 0;
  2642. //
  2643. // Return a failure since there is no data to read.
  2644. //
  2645. return(-1);
  2646. }
  2647. //
  2648. // Get the byte count in the FIFO.
  2649. //
  2650. ui32ByteCount = HWREGH(ui32Base + USB_O_COUNT0 + ui32Endpoint);
  2651. //
  2652. // Determine how many bytes are copied.
  2653. //
  2654. ui32ByteCount = (ui32ByteCount < *pui32Size) ? ui32ByteCount : *pui32Size;
  2655. //
  2656. // Return the number of bytes we are going to read.
  2657. //
  2658. *pui32Size = ui32ByteCount;
  2659. //
  2660. // Calculate the FIFO address.
  2661. //
  2662. ui32FIFO = ui32Base + USB_O_FIFO0 + (ui32Endpoint >> 2);
  2663. //
  2664. // Read the data out of the FIFO.
  2665. //
  2666. for(; ui32ByteCount > 0; ui32ByteCount--)
  2667. {
  2668. //
  2669. // Read a byte at a time from the FIFO.
  2670. //
  2671. *pui8Data++ = HWREGB(ui32FIFO);
  2672. }
  2673. //
  2674. // Success.
  2675. //
  2676. return(0);
  2677. }
  2678. //*****************************************************************************
  2679. //
  2680. //! Acknowledge that data was read from the specified endpoint's FIFO in device
  2681. //! mode.
  2682. //!
  2683. //! \param ui32Base specifies the USB module base address.
  2684. //! \param ui32Endpoint is the endpoint to access.
  2685. //! \param bIsLastPacket indicates if this packet is the last one.
  2686. //!
  2687. //! This function acknowledges that the data was read from the endpoint's FIFO.
  2688. //! The \e bIsLastPacket parameter is set to a \b true value if this is the
  2689. //! last in a series of data packets on endpoint zero. The \e bIsLastPacket
  2690. //! parameter is not used for endpoints other than endpoint zero. This call
  2691. //! can be used if processing is required between reading the data and
  2692. //! acknowledging that the data has been read.
  2693. //!
  2694. //! \note This function must only be called in device mode.
  2695. //!
  2696. //! \return None.
  2697. //
  2698. //*****************************************************************************
  2699. void
  2700. USBDevEndpointDataAck(uint32_t ui32Base, uint32_t ui32Endpoint,
  2701. bool bIsLastPacket)
  2702. {
  2703. //
  2704. // Check the arguments.
  2705. //
  2706. ASSERT(ui32Base == USB0_BASE);
  2707. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  2708. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  2709. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  2710. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  2711. //
  2712. // Determine which endpoint is being acked.
  2713. //
  2714. if(ui32Endpoint == USB_EP_0)
  2715. {
  2716. //
  2717. // Clear RxPktRdy, and optionally DataEnd, on endpoint zero.
  2718. //
  2719. HWREGB(ui32Base + USB_O_CSRL0) =
  2720. USB_CSRL0_RXRDYC | (bIsLastPacket ? USB_CSRL0_DATAEND : 0);
  2721. }
  2722. else
  2723. {
  2724. //
  2725. // Clear RxPktRdy on all other endpoints.
  2726. //
  2727. HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
  2728. ~(USB_RXCSRL1_RXRDY);
  2729. }
  2730. }
  2731. //*****************************************************************************
  2732. //
  2733. //! Acknowledge that data was read from the specified endpoint's FIFO in host
  2734. //! mode.
  2735. //!
  2736. //! \param ui32Base specifies the USB module base address.
  2737. //! \param ui32Endpoint is the endpoint to access.
  2738. //!
  2739. //! This function acknowledges that the data was read from the endpoint's FIFO.
  2740. //! This call is used if processing is required between reading the data and
  2741. //! acknowledging that the data has been read.
  2742. //!
  2743. //! \note This function must only be called in host mode.
  2744. //!
  2745. //! \return None.
  2746. //
  2747. //*****************************************************************************
  2748. void
  2749. USBHostEndpointDataAck(uint32_t ui32Base, uint32_t ui32Endpoint)
  2750. {
  2751. //
  2752. // Check the arguments.
  2753. //
  2754. ASSERT(ui32Base == USB0_BASE);
  2755. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  2756. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  2757. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  2758. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  2759. //
  2760. // Clear RxPktRdy.
  2761. //
  2762. if(ui32Endpoint == USB_EP_0)
  2763. {
  2764. HWREGB(ui32Base + USB_O_CSRL0) &= ~USB_CSRL0_RXRDY;
  2765. }
  2766. else
  2767. {
  2768. HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) &=
  2769. ~(USB_RXCSRL1_RXRDY);
  2770. }
  2771. }
  2772. //*****************************************************************************
  2773. //
  2774. //! Puts data into the specified endpoint's FIFO.
  2775. //!
  2776. //! \param ui32Base specifies the USB module base address.
  2777. //! \param ui32Endpoint is the endpoint to access.
  2778. //! \param pui8Data is a pointer to the data area used as the source for the
  2779. //! data to put into the FIFO.
  2780. //! \param ui32Size is the amount of data to put into the FIFO.
  2781. //!
  2782. //! This function puts the data from the \e pui8Data parameter into the FIFO
  2783. //! for this endpoint. If a packet is already pending for transmission, then
  2784. //! this call does not put any of the data into the FIFO and returns -1. Care
  2785. //! must be taken to not write more data than can fit into the FIFO
  2786. //! allocated by the call to USBFIFOConfigSet().
  2787. //!
  2788. //! \return This call returns 0 on success, or -1 to indicate that the FIFO
  2789. //! is in use and cannot be written.
  2790. //
  2791. //*****************************************************************************
  2792. int32_t
  2793. USBEndpointDataPut(uint32_t ui32Base, uint32_t ui32Endpoint,
  2794. uint8_t *pui8Data, uint32_t ui32Size)
  2795. {
  2796. uint32_t ui32FIFO;
  2797. uint8_t ui8TxPktRdy;
  2798. //
  2799. // Check the arguments.
  2800. //
  2801. ASSERT(ui32Base == USB0_BASE);
  2802. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  2803. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  2804. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  2805. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  2806. //
  2807. // Get the bit position of TxPktRdy based on the endpoint.
  2808. //
  2809. if(ui32Endpoint == USB_EP_0)
  2810. {
  2811. ui8TxPktRdy = USB_CSRL0_TXRDY;
  2812. }
  2813. else
  2814. {
  2815. ui8TxPktRdy = USB_TXCSRL1_TXRDY;
  2816. }
  2817. //
  2818. // Don't allow transmit of data if the TxPktRdy bit is already set.
  2819. //
  2820. if(HWREGB(ui32Base + USB_O_CSRL0 + ui32Endpoint) & ui8TxPktRdy)
  2821. {
  2822. return(-1);
  2823. }
  2824. //
  2825. // Calculate the FIFO address.
  2826. //
  2827. ui32FIFO = ui32Base + USB_O_FIFO0 + (ui32Endpoint >> 2);
  2828. //
  2829. // Write the data to the FIFO.
  2830. //
  2831. for(; ui32Size > 0; ui32Size--)
  2832. {
  2833. HWREGB(ui32FIFO) = *pui8Data++;
  2834. }
  2835. //
  2836. // Success.
  2837. //
  2838. return(0);
  2839. }
  2840. //*****************************************************************************
  2841. //
  2842. //! Starts the transfer of data from an endpoint's FIFO.
  2843. //!
  2844. //! \param ui32Base specifies the USB module base address.
  2845. //! \param ui32Endpoint is the endpoint to access.
  2846. //! \param ui32TransType is set to indicate what type of data is being sent.
  2847. //!
  2848. //! This function starts the transfer of data from the FIFO for a specified
  2849. //! endpoint. This function is called if the \b USB_EP_AUTO_SET bit was
  2850. //! not enabled for the endpoint. Setting the \e ui32TransType parameter
  2851. //! allows the appropriate signaling on the USB bus for the type of transaction
  2852. //! being requested. The \e ui32TransType parameter must be one of the
  2853. //! following:
  2854. //!
  2855. //! - \b USB_TRANS_OUT for OUT transaction on any endpoint in host mode.
  2856. //! - \b USB_TRANS_IN for IN transaction on any endpoint in device mode.
  2857. //! - \b USB_TRANS_IN_LAST for the last IN transaction on endpoint zero in a
  2858. //! sequence of IN transactions.
  2859. //! - \b USB_TRANS_SETUP for setup transactions on endpoint zero.
  2860. //! - \b USB_TRANS_STATUS for status results on endpoint zero.
  2861. //!
  2862. //! \return This call returns 0 on success, or -1 if a transmission is already
  2863. //! in progress.
  2864. //
  2865. //*****************************************************************************
  2866. int32_t
  2867. USBEndpointDataSend(uint32_t ui32Base, uint32_t ui32Endpoint,
  2868. uint32_t ui32TransType)
  2869. {
  2870. uint32_t ui32TxPktRdy;
  2871. //
  2872. // Check the arguments.
  2873. //
  2874. ASSERT(ui32Base == USB0_BASE);
  2875. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  2876. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  2877. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  2878. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  2879. //
  2880. // Get the bit position of TxPktRdy based on the endpoint.
  2881. //
  2882. if(ui32Endpoint == USB_EP_0)
  2883. {
  2884. //
  2885. // Don't allow transmit of data if the TxPktRdy bit is already set.
  2886. //
  2887. if(HWREGB(ui32Base + USB_O_CSRL0) & USB_CSRL0_TXRDY)
  2888. {
  2889. return(-1);
  2890. }
  2891. ui32TxPktRdy = ui32TransType & 0xff;
  2892. }
  2893. else
  2894. {
  2895. //
  2896. // Don't allow transmit of data if the TxPktRdy bit is already set.
  2897. //
  2898. if(HWREGB(ui32Base + USB_O_CSRL0 + ui32Endpoint) & USB_TXCSRL1_TXRDY)
  2899. {
  2900. return(-1);
  2901. }
  2902. ui32TxPktRdy = (ui32TransType >> 8) & 0xff;
  2903. }
  2904. //
  2905. // Set TxPktRdy in order to send the data.
  2906. //
  2907. HWREGB(ui32Base + USB_O_CSRL0 + ui32Endpoint) = ui32TxPktRdy;
  2908. //
  2909. // Success.
  2910. //
  2911. return(0);
  2912. }
  2913. //*****************************************************************************
  2914. //
  2915. //! Forces a flush of an endpoint's FIFO.
  2916. //!
  2917. //! \param ui32Base specifies the USB module base address.
  2918. //! \param ui32Endpoint is the endpoint to access.
  2919. //! \param ui32Flags specifies if the IN or OUT endpoint is accessed.
  2920. //!
  2921. //! This function forces the USB controller to flush out the data in the FIFO.
  2922. //! The function can be called with either host or device controllers and
  2923. //! requires the \e ui32Flags parameter be one of \b USB_EP_HOST_OUT,
  2924. //! \b USB_EP_HOST_IN, \b USB_EP_DEV_OUT, or \b USB_EP_DEV_IN.
  2925. //!
  2926. //! \return None.
  2927. //
  2928. //*****************************************************************************
  2929. void
  2930. USBFIFOFlush(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags)
  2931. {
  2932. //
  2933. // Check the arguments.
  2934. //
  2935. ASSERT(ui32Base == USB0_BASE);
  2936. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  2937. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  2938. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  2939. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  2940. //
  2941. // Endpoint zero has a different register set for FIFO flushing.
  2942. //
  2943. if(ui32Endpoint == USB_EP_0)
  2944. {
  2945. //
  2946. // Nothing in the FIFO if neither of these bits are set.
  2947. //
  2948. if((HWREGB(ui32Base + USB_O_CSRL0) &
  2949. (USB_CSRL0_RXRDY | USB_CSRL0_TXRDY)) != 0)
  2950. {
  2951. //
  2952. // Hit the Flush FIFO bit.
  2953. //
  2954. HWREGB(ui32Base + USB_O_CSRH0) = USB_CSRH0_FLUSH;
  2955. }
  2956. }
  2957. else
  2958. {
  2959. //
  2960. // Only reset the IN or OUT FIFO.
  2961. //
  2962. if(ui32Flags & (USB_EP_HOST_OUT | USB_EP_DEV_IN))
  2963. {
  2964. //
  2965. // Make sure the FIFO is not empty.
  2966. //
  2967. if(HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) &
  2968. USB_TXCSRL1_TXRDY)
  2969. {
  2970. //
  2971. // Hit the Flush FIFO bit.
  2972. //
  2973. HWREGB(ui32Base + USB_O_TXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
  2974. USB_TXCSRL1_FLUSH;
  2975. }
  2976. }
  2977. else
  2978. {
  2979. //
  2980. // Make sure that the FIFO is not empty.
  2981. //
  2982. if(HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) &
  2983. USB_RXCSRL1_RXRDY)
  2984. {
  2985. //
  2986. // Hit the Flush FIFO bit.
  2987. //
  2988. HWREGB(ui32Base + USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint)) |=
  2989. USB_RXCSRL1_FLUSH;
  2990. }
  2991. }
  2992. }
  2993. }
  2994. //*****************************************************************************
  2995. //
  2996. //! Schedules a request for an IN transaction on an endpoint in host mode.
  2997. //!
  2998. //! \param ui32Base specifies the USB module base address.
  2999. //! \param ui32Endpoint is the endpoint to access.
  3000. //!
  3001. //! This function schedules a request for an IN transaction. When the USB
  3002. //! device being communicated with responds with the data, the data can be
  3003. //! retrieved by calling USBEndpointDataGet() or via a DMA transfer.
  3004. //!
  3005. //! \note This function must only be called in host mode and only for IN
  3006. //! endpoints.
  3007. //!
  3008. //! \return None.
  3009. //
  3010. //*****************************************************************************
  3011. void
  3012. USBHostRequestIN(uint32_t ui32Base, uint32_t ui32Endpoint)
  3013. {
  3014. uint32_t ui32Register;
  3015. //
  3016. // Check the arguments.
  3017. //
  3018. ASSERT(ui32Base == USB0_BASE);
  3019. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  3020. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  3021. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  3022. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  3023. //
  3024. // Endpoint zero uses a different offset than the other endpoints.
  3025. //
  3026. if(ui32Endpoint == USB_EP_0)
  3027. {
  3028. ui32Register = USB_O_CSRL0;
  3029. }
  3030. else
  3031. {
  3032. ui32Register = USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint);
  3033. }
  3034. //
  3035. // Set the request for an IN transaction.
  3036. //
  3037. HWREGB(ui32Base + ui32Register) = USB_RXCSRL1_REQPKT;
  3038. }
  3039. //*****************************************************************************
  3040. //
  3041. //! Clears a scheduled IN transaction for an endpoint in host mode.
  3042. //!
  3043. //! \param ui32Base specifies the USB module base address.
  3044. //! \param ui32Endpoint is the endpoint to access.
  3045. //!
  3046. //! This function clears a previously scheduled IN transaction if it is still
  3047. //! pending. This function is used to safely disable any scheduled IN
  3048. //! transactions if the endpoint specified by \e ui32Endpoint is reconfigured
  3049. //! for communications with other devices.
  3050. //!
  3051. //! \note This function must only be called in host mode and only for IN
  3052. //! endpoints.
  3053. //!
  3054. //! \return None.
  3055. //
  3056. //*****************************************************************************
  3057. void
  3058. USBHostRequestINClear(uint32_t ui32Base, uint32_t ui32Endpoint)
  3059. {
  3060. uint32_t ui32Register;
  3061. //
  3062. // Check the arguments.
  3063. //
  3064. ASSERT(ui32Base == USB0_BASE);
  3065. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  3066. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  3067. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  3068. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  3069. //
  3070. // Endpoint zero uses a different offset than the other endpoints.
  3071. //
  3072. if(ui32Endpoint == USB_EP_0)
  3073. {
  3074. ui32Register = USB_O_CSRL0;
  3075. }
  3076. else
  3077. {
  3078. ui32Register = USB_O_RXCSRL1 + EP_OFFSET(ui32Endpoint);
  3079. }
  3080. //
  3081. // Clear the request for an IN transaction.
  3082. //
  3083. HWREGB(ui32Base + ui32Register) &= ~USB_RXCSRL1_REQPKT;
  3084. }
  3085. //*****************************************************************************
  3086. //
  3087. //! Issues a request for a status IN transaction on endpoint zero.
  3088. //!
  3089. //! \param ui32Base specifies the USB module base address.
  3090. //!
  3091. //! This function is used to cause a request for a status IN transaction from
  3092. //! a device on endpoint zero. This function can only be used with endpoint
  3093. //! zero as that is the only control endpoint that supports this ability. This
  3094. //! function is used to complete the last phase of a control transaction to a
  3095. //! device and an interrupt is signaled when the status packet has been
  3096. //! received.
  3097. //!
  3098. //! \note This function must only be called in host mode.
  3099. //!
  3100. //! \return None.
  3101. //
  3102. //*****************************************************************************
  3103. void
  3104. USBHostRequestStatus(uint32_t ui32Base)
  3105. {
  3106. //
  3107. // Check the arguments.
  3108. //
  3109. ASSERT(ui32Base == USB0_BASE);
  3110. //
  3111. // Set the request for a status IN transaction.
  3112. //
  3113. HWREGB(ui32Base + USB_O_CSRL0) = USB_CSRL0_REQPKT | USB_CSRL0_STATUS;
  3114. }
  3115. //*****************************************************************************
  3116. //
  3117. //! Sets the functional address for the device that is connected to an
  3118. //! endpoint in host mode.
  3119. //!
  3120. //! \param ui32Base specifies the USB module base address.
  3121. //! \param ui32Endpoint is the endpoint to access.
  3122. //! \param ui32Addr is the functional address for the controller to use for
  3123. //! this endpoint.
  3124. //! \param ui32Flags determines if this is an IN or an OUT endpoint.
  3125. //!
  3126. //! This function configures the functional address for a device that is using
  3127. //! this endpoint for communication. This \e ui32Addr parameter is the address
  3128. //! of the target device that this endpoint is communicating with. The
  3129. //! \e ui32Flags parameter indicates if the IN or OUT endpoint is set.
  3130. //!
  3131. //! \note This function must only be called in host mode.
  3132. //!
  3133. //! \return None.
  3134. //
  3135. //*****************************************************************************
  3136. void
  3137. USBHostAddrSet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Addr,
  3138. uint32_t ui32Flags)
  3139. {
  3140. //
  3141. // Check the arguments.
  3142. //
  3143. ASSERT(ui32Base == USB0_BASE);
  3144. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  3145. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  3146. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  3147. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  3148. //
  3149. // See if the transmit or receive address is set.
  3150. //
  3151. if(ui32Flags & USB_EP_HOST_OUT)
  3152. {
  3153. //
  3154. // Set the transmit address.
  3155. //
  3156. HWREGB(ui32Base + USB_O_TXFUNCADDR0 + (ui32Endpoint >> 1)) = ui32Addr;
  3157. }
  3158. else
  3159. {
  3160. //
  3161. // Set the receive address.
  3162. //
  3163. HWREGB(ui32Base + USB_O_TXFUNCADDR0 + 4 + (ui32Endpoint >> 1)) =
  3164. ui32Addr;
  3165. }
  3166. }
  3167. //*****************************************************************************
  3168. //
  3169. //! Gets the current functional device address for an endpoint.
  3170. //!
  3171. //! \param ui32Base specifies the USB module base address.
  3172. //! \param ui32Endpoint is the endpoint to access.
  3173. //! \param ui32Flags determines if this is an IN or an OUT endpoint.
  3174. //!
  3175. //! This function returns the current functional address that an endpoint is
  3176. //! using to communicate with a device. The \e ui32Flags parameter determines
  3177. //! if the IN or OUT endpoint's device address is returned.
  3178. //!
  3179. //! \note This function must only be called in host mode.
  3180. //!
  3181. //! \return Returns the current function address being used by an endpoint.
  3182. //
  3183. //*****************************************************************************
  3184. uint32_t
  3185. USBHostAddrGet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags)
  3186. {
  3187. //
  3188. // Check the arguments.
  3189. //
  3190. ASSERT(ui32Base == USB0_BASE);
  3191. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  3192. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  3193. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  3194. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  3195. //
  3196. // See if the transmit or receive address is returned.
  3197. //
  3198. if(ui32Flags & USB_EP_HOST_OUT)
  3199. {
  3200. //
  3201. // Return this endpoint's transmit address.
  3202. //
  3203. return(HWREGB(ui32Base + USB_O_TXFUNCADDR0 + (ui32Endpoint >> 1)));
  3204. }
  3205. else
  3206. {
  3207. //
  3208. // Return this endpoint's receive address.
  3209. //
  3210. return(HWREGB(ui32Base + USB_O_TXFUNCADDR0 + 4 + (ui32Endpoint >> 1)));
  3211. }
  3212. }
  3213. //*****************************************************************************
  3214. //
  3215. //! Sets the hub address for the device that is connected to an endpoint.
  3216. //!
  3217. //! \param ui32Base specifies the USB module base address.
  3218. //! \param ui32Endpoint is the endpoint to access.
  3219. //! \param ui32Addr is the hub address and port for the device using this
  3220. //! endpoint. The hub address must be defined in bits 0 through 6 with the
  3221. //! port number in bits 8 through 14.
  3222. //! \param ui32Flags determines if this is an IN or an OUT endpoint.
  3223. //!
  3224. //! This function configures the hub address for a device that is using this
  3225. //! endpoint for communication. The \e ui32Flags parameter determines if the
  3226. //! device address for the IN or the OUT endpoint is configured by this call
  3227. //! and sets the speed of the downstream device. Valid values are one of
  3228. //! \b USB_EP_HOST_OUT or \b USB_EP_HOST_IN optionally ORed with
  3229. //! \b USB_EP_SPEED_LOW.
  3230. //!
  3231. //! \note This function must only be called in host mode.
  3232. //!
  3233. //! \return None.
  3234. //
  3235. //*****************************************************************************
  3236. void
  3237. USBHostHubAddrSet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Addr,
  3238. uint32_t ui32Flags)
  3239. {
  3240. //
  3241. // Check the arguments.
  3242. //
  3243. ASSERT(ui32Base == USB0_BASE);
  3244. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  3245. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  3246. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  3247. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  3248. //
  3249. // See if the hub transmit or receive address is being set.
  3250. //
  3251. if(ui32Flags & USB_EP_HOST_OUT)
  3252. {
  3253. //
  3254. // Set the hub transmit address and port number for this endpoint.
  3255. //
  3256. HWREGH(ui32Base + USB_O_TXHUBADDR0 + (ui32Endpoint >> 1)) = ui32Addr;
  3257. }
  3258. else
  3259. {
  3260. //
  3261. // Set the hub receive address and port number for this endpoint.
  3262. //
  3263. HWREGH(ui32Base + USB_O_TXHUBADDR0 + 4 + (ui32Endpoint >> 1)) =
  3264. ui32Addr;
  3265. }
  3266. //
  3267. // Set the speed of communication for endpoint 0. This configuration is
  3268. // done here because it changes on a transaction-by-transaction basis for
  3269. // EP0. For other endpoints, this is set in USBHostEndpointConfig().
  3270. //
  3271. if(ui32Endpoint == USB_EP_0)
  3272. {
  3273. if(ui32Flags & USB_EP_SPEED_FULL)
  3274. {
  3275. HWREGB(ui32Base + USB_O_TYPE0) = USB_TYPE0_SPEED_FULL;
  3276. }
  3277. else if(ui32Flags & USB_EP_SPEED_HIGH)
  3278. {
  3279. HWREGB(ui32Base + USB_O_TYPE0) = USB_TYPE0_SPEED_HIGH;
  3280. }
  3281. else
  3282. {
  3283. HWREGB(ui32Base + USB_O_TYPE0) = USB_TYPE0_SPEED_LOW;
  3284. }
  3285. }
  3286. }
  3287. //*****************************************************************************
  3288. //
  3289. //! Gets the current device hub address for this endpoint.
  3290. //!
  3291. //! \param ui32Base specifies the USB module base address.
  3292. //! \param ui32Endpoint is the endpoint to access.
  3293. //! \param ui32Flags determines if this is an IN or an OUT endpoint.
  3294. //!
  3295. //! This function returns the current hub address that an endpoint is using
  3296. //! to communicate with a device. The \e ui32Flags parameter determines if the
  3297. //! device address for the IN or OUT endpoint is returned.
  3298. //!
  3299. //! \note This function must only be called in host mode.
  3300. //!
  3301. //! \return This function returns the current hub address being used by an
  3302. //! endpoint.
  3303. //
  3304. //*****************************************************************************
  3305. uint32_t
  3306. USBHostHubAddrGet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t ui32Flags)
  3307. {
  3308. //
  3309. // Check the arguments.
  3310. //
  3311. ASSERT(ui32Base == USB0_BASE);
  3312. ASSERT((ui32Endpoint == USB_EP_0) || (ui32Endpoint == USB_EP_1) ||
  3313. (ui32Endpoint == USB_EP_2) || (ui32Endpoint == USB_EP_3) ||
  3314. (ui32Endpoint == USB_EP_4) || (ui32Endpoint == USB_EP_5) ||
  3315. (ui32Endpoint == USB_EP_6) || (ui32Endpoint == USB_EP_7));
  3316. //
  3317. // See if the hub transmit or receive address is returned.
  3318. //
  3319. if(ui32Flags & USB_EP_HOST_OUT)
  3320. {
  3321. //
  3322. // Return the hub transmit address for this endpoint.
  3323. //
  3324. return(HWREGB(ui32Base + USB_O_TXHUBADDR0 + (ui32Endpoint >> 1)));
  3325. }
  3326. else
  3327. {
  3328. //
  3329. // Return the hub receive address for this endpoint.
  3330. //
  3331. return(HWREGB(ui32Base + USB_O_TXHUBADDR0 + 4 + (ui32Endpoint >> 1)));
  3332. }
  3333. }
  3334. //*****************************************************************************
  3335. //
  3336. //! Sets the configuration for USB power fault.
  3337. //!
  3338. //! \param ui32Base specifies the USB module base address.
  3339. //! \param ui32Flags specifies the configuration of the power fault.
  3340. //!
  3341. //! This function controls how the USB controller uses its external power
  3342. //! control pins (USBnPFLT and USBnEPEN). The flags specify the power
  3343. //! fault level sensitivity, the power fault action, and the power enable level
  3344. //! and source.
  3345. //!
  3346. //! One of the following can be selected as the power fault level sensitivity:
  3347. //!
  3348. //! - \b USB_HOST_PWRFLT_LOW - An external power fault is indicated by the pin
  3349. //! being driven low.
  3350. //! - \b USB_HOST_PWRFLT_HIGH - An external power fault is indicated by the pin
  3351. //! being driven high.
  3352. //!
  3353. //! One of the following can be selected as the power fault action:
  3354. //!
  3355. //! - \b USB_HOST_PWRFLT_EP_NONE - No automatic action when power fault
  3356. //! detected.
  3357. //! - \b USB_HOST_PWRFLT_EP_TRI - Automatically tri-state the USBnEPEN pin on a
  3358. //! power fault.
  3359. //! - \b USB_HOST_PWRFLT_EP_LOW - Automatically drive USBnEPEN pin low on a
  3360. //! power fault.
  3361. //! - \b USB_HOST_PWRFLT_EP_HIGH - Automatically drive USBnEPEN pin high on a
  3362. //! power fault.
  3363. //!
  3364. //! One of the following can be selected as the power enable level and source:
  3365. //!
  3366. //! - \b USB_HOST_PWREN_MAN_LOW - USBnEPEN is driven low by the USB controller
  3367. //! when USBHostPwrEnable() is called.
  3368. //! - \b USB_HOST_PWREN_MAN_HIGH - USBnEPEN is driven high by the USB
  3369. //! controller when USBHostPwrEnable() is
  3370. //! called.
  3371. //! - \b USB_HOST_PWREN_AUTOLOW - USBnEPEN is driven low by the USB controller
  3372. //! automatically if USBOTGSessionRequest() has
  3373. //! enabled a session.
  3374. //! - \b USB_HOST_PWREN_AUTOHIGH - USBnEPEN is driven high by the USB
  3375. //! controller automatically if
  3376. //! USBOTGSessionRequest() has enabled a
  3377. //! session.
  3378. //!
  3379. //! When using the VBUS glitch filter, the \b USB_HOST_PWREN_FILTER can be
  3380. //! addded to ignore small, short drops in VBUS level caused by high power
  3381. //! consumption. This feature is mainly used to avoid causing VBUS errors
  3382. //! caused by devices with high in-rush current.
  3383. //!
  3384. //! \note This function must only be called on microcontrollers that support
  3385. //! host mode or OTG operation. The \b USB_HOST_PWREN_AUTOLOW and
  3386. //! \b USB_HOST_PWREN_AUTOHIGH parameters can only be specified on devices that
  3387. //! support OTG operation.
  3388. //!
  3389. //! \return None.
  3390. //
  3391. //*****************************************************************************
  3392. void
  3393. USBHostPwrConfig(uint32_t ui32Base, uint32_t ui32Flags)
  3394. {
  3395. //
  3396. // Check the arguments.
  3397. //
  3398. ASSERT(ui32Base == USB0_BASE);
  3399. ASSERT((ui32Flags & ~(USB_HOST_PWREN_FILTER | USB_EPC_PFLTACT_M |
  3400. USB_EPC_PFLTAEN | USB_EPC_PFLTSEN_HIGH |
  3401. USB_EPC_EPEN_M)) == 0);
  3402. //
  3403. // If requested, enable VBUS droop detection on parts that support this
  3404. // feature.
  3405. //
  3406. HWREG(ui32Base + USB_O_VDC) = ui32Flags >> 16;
  3407. //
  3408. // Set the power fault configuration as specified. This configuration
  3409. // does not change whether fault detection is enabled or not.
  3410. //
  3411. HWREGH(ui32Base + USB_O_EPC) =
  3412. (ui32Flags | (HWREGH(ui32Base + USB_O_EPC) &
  3413. ~(USB_EPC_PFLTACT_M | USB_EPC_PFLTAEN |
  3414. USB_EPC_PFLTSEN_HIGH | USB_EPC_EPEN_M)));
  3415. }
  3416. //*****************************************************************************
  3417. //
  3418. //! Enables power fault detection.
  3419. //!
  3420. //! \param ui32Base specifies the USB module base address.
  3421. //!
  3422. //! This function enables power fault detection in the USB controller. If the
  3423. //! USBnPFLT pin is not in use, this function must not be used.
  3424. //!
  3425. //! \note This function must only be called in host mode.
  3426. //!
  3427. //! \return None.
  3428. //
  3429. //*****************************************************************************
  3430. void
  3431. USBHostPwrFaultEnable(uint32_t ui32Base)
  3432. {
  3433. //
  3434. // Check the arguments.
  3435. //
  3436. ASSERT(ui32Base == USB0_BASE);
  3437. //
  3438. // Enable power fault input.
  3439. //
  3440. HWREGH(ui32Base + USB_O_EPC) |= USB_EPC_PFLTEN;
  3441. }
  3442. //*****************************************************************************
  3443. //
  3444. //! Disables power fault detection.
  3445. //!
  3446. //! \param ui32Base specifies the USB module base address.
  3447. //!
  3448. //! This function disables power fault detection in the USB controller.
  3449. //!
  3450. //! \note This function must only be called in host mode.
  3451. //!
  3452. //! \return None.
  3453. //
  3454. //*****************************************************************************
  3455. void
  3456. USBHostPwrFaultDisable(uint32_t ui32Base)
  3457. {
  3458. //
  3459. // Check the arguments.
  3460. //
  3461. ASSERT(ui32Base == USB0_BASE);
  3462. //
  3463. // Enable power fault input.
  3464. //
  3465. HWREGH(ui32Base + USB_O_EPC) &= ~USB_EPC_PFLTEN;
  3466. }
  3467. //*****************************************************************************
  3468. //
  3469. //! Enables the external power pin.
  3470. //!
  3471. //! \param ui32Base specifies the USB module base address.
  3472. //!
  3473. //! This function enables the USBnEPEN signal, which enables an external power
  3474. //! supply in host mode operation.
  3475. //!
  3476. //! \note This function must only be called in host mode.
  3477. //!
  3478. //! \return None.
  3479. //
  3480. //*****************************************************************************
  3481. void
  3482. USBHostPwrEnable(uint32_t ui32Base)
  3483. {
  3484. //
  3485. // Check the arguments.
  3486. //
  3487. ASSERT(ui32Base == USB0_BASE);
  3488. //
  3489. // Enable the external power supply enable signal.
  3490. //
  3491. HWREGH(ui32Base + USB_O_EPC) |= USB_EPC_EPENDE;
  3492. }
  3493. //*****************************************************************************
  3494. //
  3495. //! Disables the external power pin.
  3496. //!
  3497. //! \param ui32Base specifies the USB module base address.
  3498. //!
  3499. //! This function disables the USBnEPEN signal, which disables an external
  3500. //! power supply in host mode operation.
  3501. //!
  3502. //! \note This function must only be called in host mode.
  3503. //!
  3504. //! \return None.
  3505. //
  3506. //*****************************************************************************
  3507. void
  3508. USBHostPwrDisable(uint32_t ui32Base)
  3509. {
  3510. //
  3511. // Check the arguments.
  3512. //
  3513. ASSERT(ui32Base == USB0_BASE);
  3514. //
  3515. // Disable the external power supply enable signal.
  3516. //
  3517. HWREGH(ui32Base + USB_O_EPC) &= ~USB_EPC_EPENDE;
  3518. }
  3519. //*****************************************************************************
  3520. //
  3521. //! Gets the current frame number.
  3522. //!
  3523. //! \param ui32Base specifies the USB module base address.
  3524. //!
  3525. //! This function returns the last frame number received.
  3526. //!
  3527. //! \return The last frame number received.
  3528. //
  3529. //*****************************************************************************
  3530. uint32_t
  3531. USBFrameNumberGet(uint32_t ui32Base)
  3532. {
  3533. //
  3534. // Check the arguments.
  3535. //
  3536. ASSERT(ui32Base == USB0_BASE);
  3537. //
  3538. // Return the most recent frame number.
  3539. //
  3540. return(HWREGH(ui32Base + USB_O_FRAME));
  3541. }
  3542. //*****************************************************************************
  3543. //
  3544. //! Starts or ends a session.
  3545. //!
  3546. //! \param ui32Base specifies the USB module base address.
  3547. //! \param bStart specifies if this call starts or ends a session.
  3548. //!
  3549. //! This function is used in OTG mode to start a session request or end a
  3550. //! session. If the \e bStart parameter is set to \b true, then this function
  3551. //! starts a session and if it is \b false it ends a session.
  3552. //!
  3553. //! \return None.
  3554. //
  3555. //*****************************************************************************
  3556. void
  3557. USBOTGSessionRequest(uint32_t ui32Base, bool bStart)
  3558. {
  3559. //
  3560. // Check the arguments.
  3561. //
  3562. ASSERT(ui32Base == USB0_BASE);
  3563. //
  3564. // Start or end the session as directed.
  3565. //
  3566. if(bStart)
  3567. {
  3568. HWREGB(ui32Base + USB_O_DEVCTL) |= USB_DEVCTL_SESSION;
  3569. }
  3570. else
  3571. {
  3572. HWREGB(ui32Base + USB_O_DEVCTL) &= ~USB_DEVCTL_SESSION;
  3573. }
  3574. }
  3575. //*****************************************************************************
  3576. //
  3577. //! Returns the absolute FIFO address for a specified endpoint.
  3578. //!
  3579. //! \param ui32Base specifies the USB module base address.
  3580. //! \param ui32Endpoint specifies which endpoint's FIFO address to return.
  3581. //!
  3582. //! This function returns the actual physical address of the FIFO. This
  3583. //! address is needed when the USB is going to be used with the uDMA
  3584. //! controller and the source or destination address must be set to the
  3585. //! physical FIFO address for a specified endpoint. This function can also be
  3586. //! used to provide the physical address to manually read data from an
  3587. //! endpoints FIFO.
  3588. //!
  3589. //! \return None.
  3590. //
  3591. //*****************************************************************************
  3592. uint32_t
  3593. USBFIFOAddrGet(uint32_t ui32Base, uint32_t ui32Endpoint)
  3594. {
  3595. //
  3596. // Return the FIFO address for this endpoint.
  3597. //
  3598. return(ui32Base + USB_O_FIFO0 + (ui32Endpoint >> 2));
  3599. }
  3600. //*****************************************************************************
  3601. //
  3602. //! Returns the current operating mode of the controller.
  3603. //!
  3604. //! \param ui32Base specifies the USB module base address.
  3605. //!
  3606. //! This function returns the current operating mode on USB controllers with
  3607. //! OTG or Dual mode functionality.
  3608. //!
  3609. //! For OTG controllers:
  3610. //!
  3611. //! The function returns one of the following values on OTG controllers:
  3612. //!
  3613. //! \b USB_OTG_MODE_ASIDE_HOST indicates that the controller is in host mode
  3614. //! on the A-side of the cable.
  3615. //!
  3616. //! \b USB_OTG_MODE_ASIDE_DEV indicates that the controller is in device mode
  3617. //! on the A-side of the cable.
  3618. //!
  3619. //! \b USB_OTG_MODE_BSIDE_HOST indicates that the controller is in host mode
  3620. //! on the B-side of the cable.
  3621. //!
  3622. //! \b USB_OTG_MODE_BSIDE_DEV indicates that the controller is in device mode
  3623. //! on the B-side of the cable. If an OTG session request is started with no
  3624. //! cable in place, this mode is the default.
  3625. //!
  3626. //! \b USB_OTG_MODE_NONE indicates that the controller is not attempting to
  3627. //! determine its role in the system.
  3628. //!
  3629. //! For Dual Mode controllers:
  3630. //!
  3631. //! The function returns one of the following values:
  3632. //!
  3633. //! \b USB_DUAL_MODE_HOST indicates that the controller is acting as a host.
  3634. //!
  3635. //! \b USB_DUAL_MODE_DEVICE indicates that the controller acting as a device.
  3636. //!
  3637. //! \b USB_DUAL_MODE_NONE indicates that the controller is not active as
  3638. //! either a host or device.
  3639. //!
  3640. //! \return Returns \b USB_OTG_MODE_ASIDE_HOST, \b USB_OTG_MODE_ASIDE_DEV,
  3641. //! \b USB_OTG_MODE_BSIDE_HOST, \b USB_OTG_MODE_BSIDE_DEV,
  3642. //! \b USB_OTG_MODE_NONE, \b USB_DUAL_MODE_HOST, \b USB_DUAL_MODE_DEVICE, or
  3643. //! \b USB_DUAL_MODE_NONE.
  3644. //
  3645. //*****************************************************************************
  3646. uint32_t
  3647. USBModeGet(uint32_t ui32Base)
  3648. {
  3649. //
  3650. // Check the arguments.
  3651. //
  3652. ASSERT(ui32Base == USB0_BASE);
  3653. //
  3654. // Checks the current mode in the USB_O_DEVCTL and returns the current
  3655. // mode.
  3656. //
  3657. // USB_OTG_MODE_ASIDE_HOST: USB_DEVCTL_HOST | USB_DEVCTL_SESSION
  3658. // USB_OTG_MODE_ASIDE_DEV: USB_DEVCTL_SESSION
  3659. // USB_OTG_MODE_BSIDE_HOST: USB_DEVCTL_DEV | USB_DEVCTL_SESSION |
  3660. // USB_DEVCTL_HOST
  3661. // USB_OTG_MODE_BSIDE_DEV: USB_DEVCTL_DEV | USB_DEVCTL_SESSION
  3662. // USB_OTG_MODE_NONE: USB_DEVCTL_DEV
  3663. //
  3664. return(HWREGB(ui32Base + USB_O_DEVCTL) &
  3665. (USB_DEVCTL_DEV | USB_DEVCTL_HOST | USB_DEVCTL_SESSION |
  3666. USB_DEVCTL_VBUS_M));
  3667. }
  3668. //*****************************************************************************
  3669. //
  3670. //! Sets the DMA channel to use for a specified endpoint.
  3671. //!
  3672. //! \param ui32Base specifies the USB module base address.
  3673. //! \param ui32Endpoint specifies which endpoint's FIFO address to return.
  3674. //! \param ui32Channel specifies which DMA channel to use for which endpoint.
  3675. //!
  3676. //! This function is used to configure which DMA channel to use with a specified
  3677. //! endpoint. Receive DMA channels can only be used with receive endpoints
  3678. //! and transmit DMA channels can only be used with transmit endpoints. As a
  3679. //! result, the 3 receive and 3 transmit DMA channels can be mapped to any
  3680. //! endpoint other than 0. The values that are passed into the
  3681. //! \e ui32Channel value are the UDMA_CHANNEL_USBEP* values defined in udma.h.
  3682. //!
  3683. //! \note This function only has an effect on microcontrollers that have the
  3684. //! ability to change the DMA channel for an endpoint. Calling this function
  3685. //! on other devices has no effect.
  3686. //!
  3687. //! \return None.
  3688. //!
  3689. //*****************************************************************************
  3690. void
  3691. USBEndpointDMAChannel(uint32_t ui32Base, uint32_t ui32Endpoint,
  3692. uint32_t ui32Channel)
  3693. {
  3694. uint32_t ui32Mask;
  3695. //
  3696. // Check the arguments.
  3697. //
  3698. ASSERT(ui32Base == USB0_BASE);
  3699. ASSERT((ui32Endpoint == USB_EP_1) || (ui32Endpoint == USB_EP_2) ||
  3700. (ui32Endpoint == USB_EP_3) || (ui32Endpoint == USB_EP_4) ||
  3701. (ui32Endpoint == USB_EP_5) || (ui32Endpoint == USB_EP_6) ||
  3702. (ui32Endpoint == USB_EP_7));
  3703. ASSERT(ui32Channel <= UDMA_CHANNEL_USBEP3TX);
  3704. //
  3705. // The input select mask must be shifted into the correct position
  3706. // based on the channel.
  3707. //
  3708. ui32Mask = 0xf << (ui32Channel * 4);
  3709. //
  3710. // Clear out the current selection for the channel.
  3711. //
  3712. ui32Mask = HWREG(ui32Base + USB_O_DMASEL) & (~ui32Mask);
  3713. //
  3714. // The input select is now shifted into the correct position based on the
  3715. // channel.
  3716. //
  3717. ui32Mask |= (USBEPToIndex(ui32Endpoint)) << (ui32Channel * 4);
  3718. //
  3719. // Write the value out to the register.
  3720. //
  3721. HWREG(ui32Base + USB_O_DMASEL) = ui32Mask;
  3722. }
  3723. //*****************************************************************************
  3724. //
  3725. //! Change the mode of the USB controller to host.
  3726. //!
  3727. //! \param ui32Base specifies the USB module base address.
  3728. //!
  3729. //! This function changes the mode of the USB controller to host mode.
  3730. //!
  3731. //! \note This function must only be called on microcontrollers that support
  3732. //! OTG operation.
  3733. //!
  3734. //! \return None.
  3735. //
  3736. //*****************************************************************************
  3737. void
  3738. USBHostMode(uint32_t ui32Base)
  3739. {
  3740. //
  3741. // Check the arguments.
  3742. //
  3743. ASSERT(ui32Base == USB0_BASE);
  3744. //
  3745. // Force mode in OTG parts that support forcing USB controller mode.
  3746. // This bit is not writable in USB controllers that do not support
  3747. // forcing the mode. Not setting the USB_GPCS_DEVMOD bit makes this a
  3748. // force of host mode.
  3749. //
  3750. HWREGB(ui32Base + USB_O_GPCS) = USB_GPCS_DEVMODOTG;
  3751. }
  3752. //*****************************************************************************
  3753. //
  3754. //! Change the mode of the USB controller to device.
  3755. //!
  3756. //! \param ui32Base specifies the USB module base address.
  3757. //!
  3758. //! This function changes the mode of the USB controller to device mode.
  3759. //!
  3760. //! \note This function must only be called on microcontrollers that support
  3761. //! OTG operation.
  3762. //!
  3763. //! \return None.
  3764. //
  3765. //*****************************************************************************
  3766. void
  3767. USBDevMode(uint32_t ui32Base)
  3768. {
  3769. //
  3770. // Check the arguments.
  3771. //
  3772. ASSERT(ui32Base == USB0_BASE);
  3773. //
  3774. // Set the USB controller mode to device.
  3775. //
  3776. HWREGB(ui32Base + USB_O_GPCS) = USB_GPCS_DEVMODOTG | USB_GPCS_DEVMOD;
  3777. }
  3778. //*****************************************************************************
  3779. //
  3780. //! Changes the mode of the USB controller to OTG.
  3781. //!
  3782. //! \param ui32Base specifies the USB module base address.
  3783. //!
  3784. //! This function changes the mode of the USB controller to OTG mode. This
  3785. //! function is only valid on microcontrollers that have the OTG capabilities.
  3786. //!
  3787. //! \return None.
  3788. //
  3789. //*****************************************************************************
  3790. void
  3791. USBOTGMode(uint32_t ui32Base)
  3792. {
  3793. //
  3794. // Check the arguments.
  3795. //
  3796. ASSERT(ui32Base == USB0_BASE);
  3797. //
  3798. // Disable the override of the USB controller mode when running on an OTG
  3799. // device.
  3800. //
  3801. HWREGB(ui32Base + USB_O_GPCS) = 0;
  3802. }
  3803. //*****************************************************************************
  3804. //
  3805. //! Change the operating mode of the USB controller.
  3806. //!
  3807. //! \param ui32Base specifies the USB module base address.
  3808. //! \param ui32Mode specifies the operating mode of the USB OTG pins.
  3809. //!
  3810. //! This function changes the operating modes of the USB controller. When
  3811. //! operating in full OTG mode, the USB controller uses the VBUS and ID pins to
  3812. //! detect mode and voltage changes. While these pins are primarily used in
  3813. //! OTG mode, they can also affect the operation of host and device modes. In
  3814. //! device mode, the USB controller can be configured to monitor or ignore
  3815. //! VBUS. Monitoring VBUS allows the controller to determine if it has been
  3816. //! disconnected from the host. In host mode, the USB controller uses the
  3817. //! VBUS pin to detect loss of VBUS caused by excessive power draw due to a
  3818. //! drop in the VBUS voltage. This call takes the place of USBHostMode(),
  3819. //! USBDevMode(), and USBOTGMode(). The \e ui32Mode value should be one of
  3820. //! the following values:
  3821. //!
  3822. //! - \b USB_MODE_OTG enables operating in full OTG mode, VBUS and ID are
  3823. //! used by the controller.
  3824. //! - \b USB_MODE_HOST enables operating only as a host with no monitoring of
  3825. //! VBUS or ID pins.
  3826. //! - \b USB_MODE_HOST_VBUS enables operating only as a host with monitoring of
  3827. //! VBUS pin. This configuration enables detection of VBUS droop while still
  3828. //! forcing host mode.
  3829. //! - \b USB_MODE_DEVICE enables operating only as a device with no monitoring
  3830. //! of VBUS or ID pins.
  3831. //! - \b USB_MODE_DEVICE_VBUS enables operating only as a device with
  3832. //! monitoring of VBUS pin. This configuration enables disconnect detection
  3833. //! while still forcing device mode.
  3834. //!
  3835. //! \note Some of the options above are not available on some Tiva devices.
  3836. //! Please check the data sheet to determine if the USB controller supports a
  3837. //! particular mode.
  3838. //!
  3839. //! \b Example: Force device mode but allow monitoring of the USB VBUS pin.
  3840. //!
  3841. //! \verbatim
  3842. //! //
  3843. //! // Force device mode but allow monitoring of VBUS for disconnect.
  3844. //! //
  3845. //! USBModeConfig(USB_MODE_DEVICE_VBUS);
  3846. //! \endverbatim
  3847. //!
  3848. //! \return None.
  3849. //
  3850. //*****************************************************************************
  3851. void
  3852. USBModeConfig(uint32_t ui32Base, uint32_t ui32Mode)
  3853. {
  3854. //
  3855. // Check the arguments.
  3856. //
  3857. ASSERT(ui32Base == USB0_BASE);
  3858. HWREG(ui32Base + USB_O_GPCS) = ui32Mode;
  3859. }
  3860. //*****************************************************************************
  3861. //
  3862. //! Powers off the internal USB PHY.
  3863. //!
  3864. //! \param ui32Base specifies the USB module base address.
  3865. //!
  3866. //! This function powers off the internal USB PHY, reducing the current
  3867. //! consumption of the device. While in the powered-off state, the USB
  3868. //! controller is unable to operate.
  3869. //!
  3870. //! \return None.
  3871. //
  3872. //*****************************************************************************
  3873. void
  3874. USBPHYPowerOff(uint32_t ui32Base)
  3875. {
  3876. //
  3877. // Set the PWRDNPHY bit in the PHY, putting it into its low power mode.
  3878. //
  3879. HWREGB(ui32Base + USB_O_POWER) |= USB_POWER_PWRDNPHY;
  3880. }
  3881. //*****************************************************************************
  3882. //
  3883. //! Powers on the internal USB PHY.
  3884. //!
  3885. //! \param ui32Base specifies the USB module base address.
  3886. //!
  3887. //! This function powers on the internal USB PHY, enabling it return to normal
  3888. //! operation. By default, the PHY is powered on, so this function must
  3889. //! only be called if USBPHYPowerOff() has previously been called.
  3890. //!
  3891. //! \return None.
  3892. //
  3893. //*****************************************************************************
  3894. void
  3895. USBPHYPowerOn(uint32_t ui32Base)
  3896. {
  3897. //
  3898. // Clear the PWRDNPHY bit in the PHY, putting it into normal operating
  3899. // mode.
  3900. //
  3901. HWREGB(ui32Base + USB_O_POWER) &= ~USB_POWER_PWRDNPHY;
  3902. }
  3903. //*****************************************************************************
  3904. //
  3905. //! Sets the number of packets to request when transferring multiple bulk
  3906. //! packets.
  3907. //!
  3908. //! \param ui32Base specifies the USB module base address.
  3909. //! \param ui32Endpoint is the endpoint index to target for this write.
  3910. //! \param ui32Count is the number of packets to request.
  3911. //!
  3912. //! This function sets the number of consecutive bulk packets to request
  3913. //! when transferring multiple bulk packets with DMA.
  3914. //!
  3915. //! \note This feature is not available on all Tiva devices. Please
  3916. //! check the data sheet to determine if the USB controller has a DMA
  3917. //! controller or if it must use the uDMA controller for DMA transfers.
  3918. //!
  3919. //! \return None.
  3920. //
  3921. //*****************************************************************************
  3922. void
  3923. USBEndpointPacketCountSet(uint32_t ui32Base, uint32_t ui32Endpoint,
  3924. uint32_t ui32Count)
  3925. {
  3926. HWREG(ui32Base + USB_O_RQPKTCOUNT1 +
  3927. (0x4 * (USBEPToIndex(ui32Endpoint) - 1))) = ui32Count;
  3928. }
  3929. //*****************************************************************************
  3930. //
  3931. //! Returns the number of USB endpoint pairs on the device.
  3932. //!
  3933. //! \param ui32Base specifies the USB module base address.
  3934. //!
  3935. //! This function returns the number of endpoint pairs supported by the USB
  3936. //! controller corresponding to the passed base address. The value returned is
  3937. //! the number of IN or OUT endpoints available and does not include endpoint 0
  3938. //! (the control endpoint). For example, if 15 is returned, there are 15 IN
  3939. //! and 15 OUT endpoints available in addition to endpoint 0.
  3940. //!
  3941. //! \return Returns the number of IN or OUT endpoints available.
  3942. //
  3943. //*****************************************************************************
  3944. uint32_t
  3945. USBNumEndpointsGet(uint32_t ui32Base)
  3946. {
  3947. //
  3948. // Read the number of endpoints from the hardware. The number of TX and
  3949. // RX endpoints are always the same.
  3950. //
  3951. return(HWREGB(ui32Base + USB_O_EPINFO) & USB_EPINFO_TXEP_M);
  3952. }
  3953. //*****************************************************************************
  3954. //
  3955. //! Returns the version of the USB controller.
  3956. //!
  3957. //! \param ui32Base specifies the USB module base address.
  3958. //!
  3959. //! This function returns the version number of the USB controller, which can
  3960. //! be be used to adjust for slight differences between the USB controllers in
  3961. //! the Tiva family. The values that are returned are
  3962. //! \b USB_CONTROLLER_VER_0 and \b USB_CONTROLLER_VER_1.
  3963. //!
  3964. //! \note The most significant difference between \b USB_CONTROLLER_VER_0 and
  3965. //! \b USB_CONTROLLER_VER_1 is that \b USB_CONTROLLER_VER_1 supports the USB
  3966. //! controller's own bus master DMA controller, while the
  3967. //! \b USB_CONTROLLER_VER_0 only supports using the uDMA controller with the
  3968. //! USB module.
  3969. //!
  3970. //! \b Example: Get the version of the Tiva USB controller.
  3971. //!
  3972. //! \verbatim
  3973. //! uint32_t ui32Version;
  3974. //!
  3975. //! //
  3976. //! // Retrieve the version of the Tiva USB controller.
  3977. //! //
  3978. //! ui32Version = USBControllerVersion(USB0_BASE);
  3979. //! \endverbatim
  3980. //!
  3981. //! \return This function returns one of the \b USB_CONTROLLER_VER_ values.
  3982. //
  3983. //*****************************************************************************
  3984. uint32_t
  3985. USBControllerVersion(uint32_t ui32Base)
  3986. {
  3987. //
  3988. // Return the type field of the peripheral properties. This returns
  3989. // zero for all parts that did not have a peripheral property.
  3990. //
  3991. return(HWREG(ui32Base + USB_O_PP) & USB_PP_TYPE_M);
  3992. }
  3993. //*****************************************************************************
  3994. //
  3995. //! Configures and enables the clocking to the USB controller's PHY.
  3996. //!
  3997. //! \param ui32Base specifies the USB module base address.
  3998. //! \param ui32Div specifies the divider for the internal USB PHY clock.
  3999. //! \param ui32Flags configures the internal USB PHY clock and specifies the
  4000. //! clock source for a ULPI-connected PHY.
  4001. //!
  4002. //! This function configures and enables the USB PHY clock. In addition, for
  4003. //! systems that use a ULPI-connected external PHY, this function configures
  4004. //! the source for the PHY clock. The \e ui32Flags parameter specifies the
  4005. //! clock source with the following values:
  4006. //!
  4007. //! - \b USB_CLOCK_INTERNAL uses the internal PLL combined with the \e ui32Div
  4008. //! value to generate the USB clock that is used by the internal USB PHY. In
  4009. //! addition, when using an external ULPI-connected USB PHY, the specified
  4010. //! clock is output on the USB0CLK pin.
  4011. //! - \b USB_CLOCK_EXTERNAL specifies that USB0CLK is an input from the
  4012. //! ULPI-connected external PHY.
  4013. //!
  4014. //! The \e ui32Div parameter is used to specify a divider for the internal
  4015. //! clock if the \b USB_CLOCK_INTERNAL is specified and is ignored if
  4016. //! \b USB_CLOCK_EXTERNAL is specified. When the \b USB_CLOCK_INTERNAL is
  4017. //! specified, the \e ui32Div value must be set so that the PLL_VCO/\e ui32Div
  4018. //! results in a 60-MHz clock.
  4019. //!
  4020. //! \b Example: Enable the USB clock with a 480-MHz PLL setting.
  4021. //!
  4022. //! \verbatim
  4023. //! //
  4024. //! // Enable the USB clock using a 480-MHz PLL.
  4025. //! // (480-MHz/8 = 60-MHz)
  4026. //! //
  4027. //! USBClockEnable(USB0_BASE, 8, USB_CLOCK_INTERNAL);
  4028. //! \endverbatim
  4029. //!
  4030. //! \note The ability to configure the USB PHY clock is not available on
  4031. //! all Tiva devices. Please consult the data sheet for the Tiva
  4032. //! device that you are using to determine if this feature is available.
  4033. //!
  4034. //! \return None.
  4035. //
  4036. //*****************************************************************************
  4037. void
  4038. USBClockEnable(uint32_t ui32Base, uint32_t ui32Div, uint32_t ui32Flags)
  4039. {
  4040. ASSERT(ui32Base == USB0_BASE);
  4041. //
  4042. // Configure and enable the USB clock input.
  4043. //
  4044. HWREG(ui32Base + USB_O_CC) = (ui32Div - 1) | ui32Flags;
  4045. }
  4046. //*****************************************************************************
  4047. //
  4048. //! Disables the clocking of the USB controller's PHY.
  4049. //!
  4050. //! \param ui32Base specifies the USB module base address.
  4051. //!
  4052. //! This function disables the USB PHY clock. This function should not be
  4053. //! called in applications where the USB controller is used.
  4054. //!
  4055. //! \b Example: Disable the USB PHY clock input.
  4056. //!
  4057. //! \verbatim
  4058. //! //
  4059. //! // Disable clocking of the USB controller's PHY.
  4060. //! //
  4061. //! USBClockDisable(USB0_BASE);
  4062. //! \endverbatim
  4063. //!
  4064. //! \note The ability to configure the USB PHY clock is not available on all
  4065. //! Tiva devices. Please consult the data sheet for the Tiva device
  4066. //! that you are using to determine if this feature is available.
  4067. //!
  4068. //! \return None.
  4069. //
  4070. //*****************************************************************************
  4071. void
  4072. USBClockDisable(uint32_t ui32Base)
  4073. {
  4074. ASSERT(ui32Base == USB0_BASE);
  4075. //
  4076. // Disable the USB clock input.
  4077. //
  4078. HWREG(ui32Base + USB_O_CC) = 0;
  4079. }
  4080. //*****************************************************************************
  4081. //
  4082. // Close the Doxygen group.
  4083. //! @}
  4084. //
  4085. //*****************************************************************************
  4086. //*****************************************************************************
  4087. //
  4088. //! \addtogroup usb_dma
  4089. //! @{
  4090. //
  4091. //*****************************************************************************
  4092. //*****************************************************************************
  4093. //
  4094. //! Enable interrupts for a specified integrated USB DMA channel.
  4095. //!
  4096. //! \param ui32Base specifies the USB module base address.
  4097. //! \param ui32Channel specifies which DMA channel interrupt to enable.
  4098. //!
  4099. //! This function enables the USB DMA channel interrupt based on the
  4100. //! \e ui32Channel parameter. The \e ui32Channel value is a zero-based
  4101. //! index of the USB DMA channel. Once enabled, the USBDMAChannelIntStatus()
  4102. //! function returns if a DMA channel has generated an interrupt.
  4103. //!
  4104. //! \b Example: Enable the USB DMA channel 3 interrupt.
  4105. //!
  4106. //! \verbatim
  4107. //! //
  4108. //! // Enable the USB DMA channel 3 interrupt
  4109. //! //
  4110. //! USBDMAChannelIntEnable(USB0_BASE, 3);
  4111. //! \endverbatim
  4112. //!
  4113. //! \note This feature is not available on all Tiva devices. Please
  4114. //! check the data sheet to determine if the USB controller has a DMA
  4115. //! controller or if it must use the uDMA controller for DMA transfers.
  4116. //!
  4117. //! \return None.
  4118. //
  4119. //*****************************************************************************
  4120. void
  4121. USBDMAChannelIntEnable(uint32_t ui32Base, uint32_t ui32Channel)
  4122. {
  4123. ASSERT(ui32Base == USB0_BASE);
  4124. ASSERT(ui32Channel < 8);
  4125. //
  4126. // Enable the specified DMA channel interrupts.
  4127. //
  4128. HWREG(ui32Base + USB_O_DMACTL0 + (0x10 * ui32Channel)) |= USB_DMACTL0_IE;
  4129. }
  4130. //*****************************************************************************
  4131. //
  4132. //! Disable interrupts for a specified integrated USB DMA channel.
  4133. //!
  4134. //! \param ui32Base specifies the USB module base address.
  4135. //! \param ui32Channel specifies which USB DMA channel interrupt to disable.
  4136. //!
  4137. //! This function disables the USB DMA channel interrupt based on the
  4138. //! \e ui32Channel parameter. The \e ui32Channel value is a zero-based
  4139. //! index of the USB DMA channel.
  4140. //!
  4141. //! \b Example: Disable the USB DMA channel 3 interrupt.
  4142. //!
  4143. //! \verbatim
  4144. //! //
  4145. //! // Disable the USB DMA channel 3 interrupt
  4146. //! //
  4147. //! USBDMAChannelIntDisable(USB0_BASE, 3);
  4148. //! \endverbatim
  4149. //!
  4150. //! \note This feature is not available on all Tiva devices. Please
  4151. //! check the data sheet to determine if the USB controller has a DMA
  4152. //! controller or if it must use the uDMA controller for DMA transfers.
  4153. //!
  4154. //! \return None.
  4155. //
  4156. //*****************************************************************************
  4157. void
  4158. USBDMAChannelIntDisable(uint32_t ui32Base, uint32_t ui32Channel)
  4159. {
  4160. ASSERT(ui32Base == USB0_BASE);
  4161. ASSERT(ui32Channel < 8);
  4162. //
  4163. // Enable the specified DMA channel interrupts.
  4164. //
  4165. HWREG(ui32Base + USB_O_DMACTL0 + (0x10 * ui32Channel)) &= ~USB_DMACTL0_IE;
  4166. }
  4167. //*****************************************************************************
  4168. //
  4169. //! Return the current status of the integrated USB DMA interrupts.
  4170. //!
  4171. //! \param ui32Base specifies the USB module base address.
  4172. //!
  4173. //! This function returns the current bit-mapped interrupt status for all USB
  4174. //! DMA channel interrupt sources. Calling this function automatically clears
  4175. //! all currently pending USB DMA interrupts.
  4176. //!
  4177. //! \note This feature is not available on all Tiva devices. Please
  4178. //! check the data sheet to determine if the USB controller has a DMA
  4179. //! controller or if it must use the uDMA controller for DMA transfers.
  4180. //!
  4181. //! \b Example: Get the pending USB DMA interrupts.
  4182. //!
  4183. //! \verbatim
  4184. //! uint32_t ui32Ints;
  4185. //!
  4186. //! //
  4187. //! // Get the pending USB DMA interrupts.
  4188. //! //
  4189. //! ui32Ints = USBDMAChannelIntStatus(USB0_BASE);
  4190. //! \endverbatim
  4191. //!
  4192. //! \return The bit-mapped interrupts for the DMA channels.
  4193. //
  4194. //*****************************************************************************
  4195. uint32_t
  4196. USBDMAChannelIntStatus(uint32_t ui32Base)
  4197. {
  4198. ASSERT(ui32Base == USB0_BASE);
  4199. return(HWREG(ui32Base + USB_O_DMAINTR));
  4200. }
  4201. //*****************************************************************************
  4202. //
  4203. //! Enables integrated USB DMA for a specified channel.
  4204. //!
  4205. //! \param ui32Base specifies the USB module base address.
  4206. //! \param ui32Channel specifies the USB DMA channel to enable.
  4207. //!
  4208. //! This function enables the USB DMA channel passed in the \e ui32Channel
  4209. //! parameter. The \e ui32Channel value is a zero-based index of the USB DMA
  4210. //! channel.
  4211. //!
  4212. //! \b Example: Enable USB DMA channel 2.
  4213. //!
  4214. //! \verbatim
  4215. //! //
  4216. //! // Enable USB DMA channel 2.
  4217. //! //
  4218. //! USBDMAChannelEnable(2);
  4219. //! \endverbatim
  4220. //!
  4221. //! \note This feature is not available on all Tiva devices. Please
  4222. //! check the data sheet to determine if the USB controller has a DMA
  4223. //! controller or if it must use the uDMA controller for DMA transfers.
  4224. //!
  4225. //! \return None.
  4226. //
  4227. //*****************************************************************************
  4228. void
  4229. USBDMAChannelEnable(uint32_t ui32Base, uint32_t ui32Channel)
  4230. {
  4231. ASSERT(ui32Base == USB0_BASE);
  4232. ASSERT(ui32Channel < 8);
  4233. //
  4234. // Enable the USB DMA channel.
  4235. //
  4236. HWREG(ui32Base + USB_O_DMACTL0 + (0x10 * ui32Channel)) |=
  4237. USB_DMACTL0_ENABLE;
  4238. }
  4239. //*****************************************************************************
  4240. //
  4241. //! Disables integrated USB DMA for a specified channel.
  4242. //!
  4243. //! \param ui32Base specifies the USB module base address.
  4244. //! \param ui32Channel specifies the USB DMA channel to disable.
  4245. //!
  4246. //! This function disables the USB DMA channel passed in the \e ui32Channel
  4247. //! parameter. The \e ui32Channel parameter is a zero-based index of the DMA
  4248. //! channel.
  4249. //!
  4250. //! \b Example: Disable USB DMA channel 2.
  4251. //!
  4252. //! \verbatim
  4253. //! //
  4254. //! // Disable USB DMA channel 2.
  4255. //! //
  4256. //! USBDMAChannelDisable(2);
  4257. //! \endverbatim
  4258. //!
  4259. //! \note This feature is not available on all Tiva devices. Please
  4260. //! check the data sheet to determine if the USB controller has a DMA
  4261. //! controller or if it must use the uDMA controller for DMA transfers.
  4262. //!
  4263. //! \return None.
  4264. //
  4265. //*****************************************************************************
  4266. void
  4267. USBDMAChannelDisable(uint32_t ui32Base, uint32_t ui32Channel)
  4268. {
  4269. ASSERT(ui32Base == USB0_BASE);
  4270. ASSERT(ui32Channel < 8);
  4271. //
  4272. // Disable the USB DMA channel.
  4273. //
  4274. HWREG(ui32Base + USB_O_DMACTL0 + (0x10 * ui32Channel)) &=
  4275. ~USB_DMACTL0_ENABLE;
  4276. }
  4277. //*****************************************************************************
  4278. //
  4279. //! Assigns and configures an endpoint to a specified integrated USB DMA
  4280. //! channel.
  4281. //!
  4282. //! \param ui32Base specifies the USB module base address.
  4283. //! \param ui32Channel specifies which DMA channel to access.
  4284. //! \param ui32Endpoint is the endpoint to assign to the USB DMA channel.
  4285. //! \param ui32Config is used to specify the configuration of the USB DMA
  4286. //! channel.
  4287. //!
  4288. //! This function assigns an endpoint and configures the settings for a
  4289. //! USB DMA channel. The \e ui32Endpoint parameter is one of the
  4290. //! \b USB_EP_* values and the \e ui32Channel value is a zero-based index of
  4291. //! the DMA channel to configure. The \e ui32Config parameter is a combination
  4292. //! of the \b USB_DMA_CFG_* values using the following guidelines.
  4293. //!
  4294. //! Use one of the following to set the DMA burst mode:
  4295. //! - \b USB_DMA_CFG_BURST_NONE disables bursting.
  4296. //! - \b USB_DMA_CFG_BURST_4 sets the DMA burst size to 4 words.
  4297. //! - \b USB_DMA_CFG_BURST_8 sets the DMA burst size to 8 words.
  4298. //! - \b USB_DMA_CFG_BURST_16 sets the DMA burst size to 16 words.
  4299. //!
  4300. //! Use one of the following to set the DMA mode:
  4301. //! - \b USB_DMA_CFG_MODE_0 is typically used when only a single packet is
  4302. //! being sent via DMA and triggers one completion interrupt per packet.
  4303. //! - \b USB_DMA_CFG_MODE_1 is typically used when multiple packets are being
  4304. //! sent via DMA and triggers one completion interrupt per transfer.
  4305. //!
  4306. //! Use one of the following to set the direction of the transfer:
  4307. //! - \b USB_DMA_CFG_DIR_RX selects a DMA transfer from the endpoint to a
  4308. //! memory location.
  4309. //! - \b USB_DMA_CFG_DIR_TX selects a DMA transfer to the endpoint from a
  4310. //! memory location.
  4311. //!
  4312. //! The following two optional settings allow an application to immediately
  4313. //! enable the DMA transfer and/or DMA interrupts when configuring the DMA
  4314. //! channel:
  4315. //! - \b USB_DMA_CFG_INT_EN enables interrupts for this channel immediately so
  4316. //! that an added call to USBDMAChannelIntEnable() is not necessary.
  4317. //! - \b USB_DMA_CFG_EN enables the DMA channel immediately so that an added
  4318. //! call to USBDMAChannelEnable() is not necessary.
  4319. //!
  4320. //! \b Example: Assign channel 0 to endpoint 1 in DMA mode 0, 4 word burst,
  4321. //! enable interrupts and immediately enable the transfer.
  4322. //!
  4323. //! \verbatim
  4324. //! //
  4325. //! // Assign channel 0 to endpoint 1 in DMA mode 0, 4 word bursts,
  4326. //! // enable interrupts and immediately enable the transfer.
  4327. //! //
  4328. //! USBDMAChannelConfigSet(USB0_BASE, 0, USB_EP_1,
  4329. //! (USB_DMA_CFG_BURST_4 | USB_DMA_CFG_MODE0 |
  4330. //! USB_DMA_CFG_DIR_RX | USB_DMA_CFG_INT_EN |
  4331. //! USB_DMA_CFG_EN));
  4332. //! \endverbatim
  4333. //!
  4334. //! \note This feature is not available on all Tiva devices. Please
  4335. //! check the data sheet to determine if the USB controller has a DMA
  4336. //! controller or if it must use the uDMA controller for DMA transfers.
  4337. //!
  4338. //! \return None.
  4339. //
  4340. //*****************************************************************************
  4341. void
  4342. USBDMAChannelConfigSet(uint32_t ui32Base, uint32_t ui32Channel,
  4343. uint32_t ui32Endpoint, uint32_t ui32Config)
  4344. {
  4345. ASSERT(ui32Base == USB0_BASE);
  4346. ASSERT(ui32Channel < 8);
  4347. ASSERT((ui32Endpoint & ~USB_EP_7) == 0);
  4348. //
  4349. // Reset this USB DMA channel.
  4350. //
  4351. HWREG(ui32Base + USB_O_DMACTL0 + (0x10 * ui32Channel)) = 0;
  4352. //
  4353. // Set the configuration of the requested channel.
  4354. //
  4355. HWREG(ui32Base + USB_O_DMACTL0 + (0x10 * ui32Channel)) =
  4356. ui32Config | ui32Endpoint;
  4357. }
  4358. //*****************************************************************************
  4359. //
  4360. //! Returns the current status for an integrated USB DMA channel.
  4361. //!
  4362. //! \param ui32Base specifies the USB module base address.
  4363. //! \param ui32Channel specifies which DMA channel to query.
  4364. //!
  4365. //! This function returns the current status for the USB DMA channel specified
  4366. //! by the \e ui32Channel parameter. The \e ui32Channel value is a zero-based
  4367. //! index of the USB DMA channel to query.
  4368. //!
  4369. //! \b Example: Get the current USB DMA status for channel 2.
  4370. //!
  4371. //! \verbatim
  4372. //! uint32_t ui32Status;
  4373. //!
  4374. //! //
  4375. //! // Get the current USB DMA status for channel 2.
  4376. //! //
  4377. //! ui32Status = USBDMAChannelStatus(USB0_BASE, 2);
  4378. //! \endverbatim
  4379. //!
  4380. //! \note This feature is not available on all Tiva devices. Please
  4381. //! check the data sheet to determine if the USB controller has a DMA
  4382. //! controller or if it must use the uDMA controller for DMA transfers.
  4383. //!
  4384. //! \return Returns zero or \b USB_DMACTL0_ERR if there is a pending error
  4385. //! condition on a DMA channel.
  4386. //
  4387. //*****************************************************************************
  4388. uint32_t
  4389. USBDMAChannelStatus(uint32_t ui32Base, uint32_t ui32Channel)
  4390. {
  4391. ASSERT(ui32Base == USB0_BASE);
  4392. ASSERT(ui32Channel < 8);
  4393. //
  4394. // Return a non-zero value if there is a pending error condition.
  4395. //
  4396. return(HWREG(ui32Base + USB_O_DMACTL0 + (0x10 * ui32Channel)) &
  4397. USB_DMACTL0_ERR);
  4398. }
  4399. //*****************************************************************************
  4400. //
  4401. //! Clears the integrated USB DMA status for a specified channel.
  4402. //!
  4403. //! \param ui32Base specifies the USB module base address.
  4404. //! \param ui32Channel specifies which DMA channel to clear.
  4405. //! \param ui32Status holds the status bits to clear.
  4406. //!
  4407. //! This function clears the USB DMA channel status for the channel specified
  4408. //! by the \e ui32Channel parameter. The \e ui32Channel value is a zero-based
  4409. //! index of the USB DMA channel to query. The \e ui32Status parameter
  4410. //! specifies the status bits to clear and must be the valid values that are
  4411. //! returned from a call to the USBDMAChannelStatus() function.
  4412. //!
  4413. //! \b Example: Clear the current USB DMA status for channel 2.
  4414. //!
  4415. //! \verbatim
  4416. //! //
  4417. //! // Clear the any pending USB DMA status for channel 2.
  4418. //! //
  4419. //! USBDMAChannelStatusClear(USB0_BASE, 2, USBDMAChannelStatus(USB0_BASE, 2));
  4420. //! \endverbatim
  4421. //!
  4422. //! \note This feature is not available on all Tiva devices. Please
  4423. //! check the data sheet to determine if the USB controller has a DMA
  4424. //! controller or if it must use the uDMA controller for DMA transfers.
  4425. //!
  4426. //! \return None.
  4427. //
  4428. //*****************************************************************************
  4429. void
  4430. USBDMAChannelStatusClear(uint32_t ui32Base, uint32_t ui32Channel,
  4431. uint32_t ui32Status)
  4432. {
  4433. ASSERT(ui32Base == USB0_BASE);
  4434. ASSERT(ui32Channel < 8);
  4435. //
  4436. // The only status is the error bit.
  4437. //
  4438. ui32Status &= USB_DMACTL0_ERR;
  4439. //
  4440. // Clear the specified error condition.
  4441. //
  4442. HWREG(ui32Base + USB_O_DMACTL0 + (0x10 * ui32Channel)) &= ~ui32Status;
  4443. }
  4444. //*****************************************************************************
  4445. //
  4446. //! Sets the source or destination address for an integrated USB DMA transfer
  4447. //! on a specified channel.
  4448. //!
  4449. //! \param ui32Base specifies the USB module base address.
  4450. //! \param ui32Channel specifies which DMA channel to configure.
  4451. //! \param pvAddress specifies the source or destination address for the USB
  4452. //! DMA transfer.
  4453. //!
  4454. //! This function sets the source or destination address for the USB DMA
  4455. //! channel number specified in the \e ui32Channel parameter. The
  4456. //! \e ui32Channel value is a zero-based index of the USB DMA channel. The
  4457. //! \e pvAddress parameter is a source address if the transfer type for the DMA
  4458. //! channel is transmit and a destination address if the transfer type is
  4459. //! receive.
  4460. //!
  4461. //! \b Example: Set the transfer address for USB DMA channel 1.
  4462. //!
  4463. //! \verbatim
  4464. //! void *pvBuffer;
  4465. //!
  4466. //! //
  4467. //! // Set the address for USB DMA channel 1.
  4468. //! //
  4469. //! USBDMAChannelAddressSet(USB0_BASE, 1, pvBuffer);
  4470. //! \endverbatim
  4471. //!
  4472. //! \note This feature is not available on all Tiva devices. Please
  4473. //! check the data sheet to determine if the USB controller has a DMA
  4474. //! controller or if it must use the uDMA controller for DMA transfers.
  4475. //!
  4476. //! \return None.
  4477. //
  4478. //*****************************************************************************
  4479. void
  4480. USBDMAChannelAddressSet(uint32_t ui32Base, uint32_t ui32Channel,
  4481. void *pvAddress)
  4482. {
  4483. ASSERT(ui32Base == USB0_BASE);
  4484. ASSERT(ui32Channel < 8);
  4485. //
  4486. // Set the DMA address.
  4487. //
  4488. HWREG(ui32Base + USB_O_DMAADDR0 + (0x10 * ui32Channel)) =
  4489. (uint32_t)pvAddress;
  4490. }
  4491. //*****************************************************************************
  4492. //
  4493. //! Returns the source or destination address for the specified integrated USB
  4494. //! DMA channel.
  4495. //!
  4496. //! \param ui32Base specifies the USB module base address.
  4497. //! \param ui32Channel specifies the USB DMA channel.
  4498. //!
  4499. //! This function returns the DMA address for the channel number specified
  4500. //! in the \e ui32Channel parameter. The \e ui32Channel value is a zero-based
  4501. //! index of the DMA channel to query. This function must not be used on
  4502. //! devices that return \b USB_CONTROLLER_VER_0 from the USBControllerVersion()
  4503. //! function.
  4504. //!
  4505. //! \b Example: Get the transfer address for USB DMA channel 1.
  4506. //!
  4507. //! \verbatim
  4508. //! void *pvBuffer;
  4509. //!
  4510. //! //
  4511. //! // Retrieve the current DMA address for channel 1.
  4512. //! //
  4513. //! pvBuffer = USBDMAChannelAddressGet(USB0_BASE, 1);
  4514. //! \endverbatim
  4515. //!
  4516. //! \note This feature is not available on all Tiva devices. Please
  4517. //! check the data sheet to determine if the USB controller has a DMA
  4518. //! controller or if it must use the uDMA controller for DMA transfers.
  4519. //!
  4520. //! \return The current DMA address for a USB DMA channel.
  4521. //
  4522. //*****************************************************************************
  4523. void *
  4524. USBDMAChannelAddressGet(uint32_t ui32Base, uint32_t ui32Channel)
  4525. {
  4526. ASSERT(ui32Base == USB0_BASE);
  4527. ASSERT(ui32Channel < 8);
  4528. //
  4529. // Return the current DMA address.
  4530. //
  4531. return((void *)HWREG(ui32Base + USB_O_DMAADDR0 + (0x10 * ui32Channel)));
  4532. }
  4533. //*****************************************************************************
  4534. //
  4535. //! Sets the transfer count for an integrated USB DMA channel.
  4536. //!
  4537. //! \param ui32Base specifies the USB module base address.
  4538. //! \param ui32Channel specifies which DMA channel to access.
  4539. //! \param ui32Count specifies the number of bytes to transfer.
  4540. //!
  4541. //! This function sets the USB DMA transfer count in bytes for the channel
  4542. //! number specified in the \e ui32Channel parameter. The \e ui32Channel
  4543. //! value is a zero-based index of the DMA channel.
  4544. //!
  4545. //! \b Example: Set the transfer count to 512 bytes for USB DMA channel 1.
  4546. //!
  4547. //! \verbatim
  4548. //! //
  4549. //! // Set the transfer count to 512 bytes for USB DMA channel 1.
  4550. //! //
  4551. //! USBDMAChannelCountSet(USB0_BASE, 1, 512);
  4552. //! \endverbatim
  4553. //!
  4554. //! \note This feature is not available on all Tiva devices. Please
  4555. //! check the data sheet to determine if the USB controller has a DMA
  4556. //! controller or if it must use the uDMA controller for DMA transfers.
  4557. //!
  4558. //! \return None.
  4559. //
  4560. //*****************************************************************************
  4561. void
  4562. USBDMAChannelCountSet(uint32_t ui32Base, uint32_t ui32Channel,
  4563. uint32_t ui32Count)
  4564. {
  4565. ASSERT(ui32Base == USB0_BASE);
  4566. ASSERT(ui32Channel < 8);
  4567. //
  4568. // Set the USB DMA count for the channel.
  4569. //
  4570. HWREG(ui32Base + USB_O_DMACOUNT0 + (0x10 * ui32Channel)) = ui32Count;
  4571. }
  4572. //*****************************************************************************
  4573. //
  4574. //! Returns the transfer count for an integrated USB DMA channel.
  4575. //!
  4576. //! \param ui32Base specifies the USB module base address.
  4577. //! \param ui32Channel specifies which DMA channel to access.
  4578. //!
  4579. //! This function returns the USB DMA transfer count in bytes for the channel
  4580. //! number specified in the \e ui32Channel parameter. The \e ui32Channel value
  4581. //! is a zero-based index of the DMA channel to query.
  4582. //!
  4583. //! \b Example: Get the transfer count for USB DMA channel 1.
  4584. //!
  4585. //! \verbatim
  4586. //! uint32_t ui32Count;
  4587. //!
  4588. //! //
  4589. //! // Get the transfer count for USB DMA channel 1.
  4590. //! //
  4591. //! ui32Count = USBDMAChannelCountGet(USB0_BASE, 1);
  4592. //! \endverbatim
  4593. //!
  4594. //! \note This feature is not available on all Tiva devices. Please
  4595. //! check the data sheet to determine if the USB controller has a DMA
  4596. //! controller or if it must use the uDMA controller for DMA transfers.
  4597. //!
  4598. //! \return The current count for a USB DMA channel.
  4599. //
  4600. //*****************************************************************************
  4601. uint32_t
  4602. USBDMAChannelCountGet(uint32_t ui32Base, uint32_t ui32Channel)
  4603. {
  4604. ASSERT(ui32Base == USB0_BASE);
  4605. ASSERT(ui32Channel < 8);
  4606. //
  4607. // Return the current DMA count.
  4608. //
  4609. return(HWREG(ui32Base + USB_O_DMACOUNT0 + (0x10 * ui32Channel)));
  4610. }
  4611. //*****************************************************************************
  4612. //
  4613. //! Returns the available number of integrated USB DMA channels.
  4614. //!
  4615. //! \param ui32Base specifies the USB module base address.
  4616. //!
  4617. //! This function returns the total number of DMA channels available when using
  4618. //! the integrated USB DMA controller. This function returns 0 if the
  4619. //! integrated controller is not present.
  4620. //!
  4621. //! \b Example: Get the number of integrated DMA channels.
  4622. //!
  4623. //! \verbatim
  4624. //! uint32_t ui32Count;
  4625. //!
  4626. //! //
  4627. //! // Get the number of integrated DMA channels.
  4628. //! //
  4629. //! ui32Count = USBDMANumChannels(USB0_BASE);
  4630. //! \endverbatim
  4631. //!
  4632. //! \return The number of integrated USB DMA channels or zero if the
  4633. //! integrated USB DMA controller is not present.
  4634. //
  4635. //*****************************************************************************
  4636. uint32_t
  4637. USBDMANumChannels(uint32_t ui32Base)
  4638. {
  4639. ASSERT(ui32Base == USB0_BASE);
  4640. //
  4641. // Return the number of DMA channels for the integrated DMA controller.
  4642. //
  4643. return(HWREG(ui32Base + USB_O_RAMINFO) >> USB_RAMINFO_DMACHAN_S);
  4644. }
  4645. //*****************************************************************************
  4646. //
  4647. // Close the Doxygen group.
  4648. //! @}
  4649. //
  4650. //*****************************************************************************
  4651. //*****************************************************************************
  4652. //
  4653. //! \addtogroup usb_ulpi
  4654. //! @{
  4655. //
  4656. //*****************************************************************************
  4657. //*****************************************************************************
  4658. //
  4659. //! Configures the USB controller's ULPI function.
  4660. //!
  4661. //! \param ui32Base specifies the USB module base address.
  4662. //! \param ui32Config contains the configuration options.
  4663. //!
  4664. //! This function is used to configure the USB controller's ULPI function.
  4665. //! The configuration options are set in the \e ui32Config parameter and are a
  4666. //! logical OR of the following values:
  4667. //!
  4668. //! - \b USB_ULPI_EXTVBUS enables the external ULPI PHY as the source for VBUS
  4669. //! signaling.
  4670. //! - \b USB_ULPI_EXTVBUS_IND enables the external ULPI PHY to detect external
  4671. //! VBUS over-current condition.
  4672. //!
  4673. //! \b Example: Enable ULPI PHY with full VBUS control.
  4674. //!
  4675. //! \verbatim
  4676. //! //
  4677. //! // Enable ULPI PHY with full VBUS control.
  4678. //! //
  4679. //! USBULPIConfig(USB0_BASE, USB_ULPI_EXTVBUS | USB_ULPI_EXTVBUS_IND);
  4680. //! \endverbatim
  4681. //!
  4682. //! \note The USB ULPI feature is not available on all Tiva devices.
  4683. //! Please consult the data sheet for the Tiva device that you
  4684. //! are using to determine if this feature is available.
  4685. //!
  4686. //! \return None.
  4687. //
  4688. //*****************************************************************************
  4689. void
  4690. USBULPIConfig(uint32_t ui32Base, uint32_t ui32Config)
  4691. {
  4692. HWREGB(ui32Base + USB_O_ULPIVBUSCTL) = (uint8_t)ui32Config;
  4693. }
  4694. //*****************************************************************************
  4695. //
  4696. //! Enables the USB controller's ULPI function.
  4697. //!
  4698. //! \param ui32Base specifies the USB module base address.
  4699. //!
  4700. //! This function enables the USB controller's ULPI function and must be
  4701. //! called before attempting to access an external ULPI-connected USB PHY.
  4702. //!
  4703. //! \b Example: Enable ULPI function.
  4704. //!
  4705. //! \verbatim
  4706. //! //
  4707. //! // Enable ULPI function.
  4708. //! //
  4709. //! USBULPIEnable(USB0_BASE);
  4710. //! \endverbatim
  4711. //!
  4712. //! \note The USB ULPI feature is not available on all Tiva devices.
  4713. //! Please consult the data sheet for the Tiva device that you
  4714. //! are using to determine if this feature is available.
  4715. //!
  4716. //! \return None.
  4717. //
  4718. //*****************************************************************************
  4719. void
  4720. USBULPIEnable(uint32_t ui32Base)
  4721. {
  4722. HWREG(ui32Base + USB_O_PC) |= USB_PC_ULPIEN;
  4723. }
  4724. //*****************************************************************************
  4725. //
  4726. //! Disables the USB controller's ULPI function.
  4727. //!
  4728. //! \param ui32Base specifies the USB module base address.
  4729. //!
  4730. //! This function disables the USB controller's ULPI function. Accesses to
  4731. //! the external ULPI-connected PHY cannot succeed after this function has been
  4732. //! called.
  4733. //!
  4734. //! \b Example: Disable ULPI function.
  4735. //!
  4736. //! \verbatim
  4737. //! //
  4738. //! // Disable ULPI function.
  4739. //! //
  4740. //! USBULPIDisable(USB0_BASE);
  4741. //! \endverbatim
  4742. //!
  4743. //! \note The USB ULPI feature is not available on all Tiva devices.
  4744. //! Please consult the data sheet for the Tiva device that you
  4745. //! are using to determine if this feature is available.
  4746. //!
  4747. //! \return None.
  4748. //
  4749. //*****************************************************************************
  4750. void
  4751. USBULPIDisable(uint32_t ui32Base)
  4752. {
  4753. HWREG(ui32Base + USB_O_PC) &= ~USB_PC_ULPIEN;
  4754. }
  4755. //*****************************************************************************
  4756. //
  4757. //! Reads a register from an external ULPI-connected USB PHY.
  4758. //!
  4759. //! \param ui32Base specifies the USB module base address.
  4760. //! \param ui8Reg specifies the register address to read.
  4761. //!
  4762. //! This function reads the register address specified in the \e ui8Reg
  4763. //! parameter using the ULPI function. This function is blocking and only
  4764. //! returns when the read access completes. The function does not return if
  4765. //! there is not a ULPI-connected USB PHY present.
  4766. //!
  4767. //! \b Example: Read a register from the ULPI PHY.
  4768. //!
  4769. //! \verbatim
  4770. //! uint8_t ui8Value;
  4771. //!
  4772. //! //
  4773. //! // Read a register from the ULPI PHY register at 0x10.
  4774. //! //
  4775. //! ui8Value = USBULPIRegRead(USB0_BASE, 0x10);
  4776. //! \endverbatim
  4777. //!
  4778. //! \note The USB ULPI feature is not available on all Tiva devices.
  4779. //! Please consult the data sheet for the Tiva device that you
  4780. //! are using to determine if this feature is available.
  4781. //!
  4782. //! \return The value of the requested ULPI register.
  4783. //
  4784. //*****************************************************************************
  4785. uint8_t
  4786. USBULPIRegRead(uint32_t ui32Base, uint8_t ui8Reg)
  4787. {
  4788. ASSERT(ui32Base == USB0_BASE);
  4789. //
  4790. // Set the register address and initiate a read access.
  4791. //
  4792. HWREGB(ui32Base + USB_O_ULPIREGADDR) = ui8Reg;
  4793. HWREGB(ui32Base + USB_O_ULPIREGCTL) =
  4794. USB_ULPIREGCTL_RDWR | USB_ULPIREGCTL_REGACC;
  4795. //
  4796. // Wait for the access to complete.
  4797. //
  4798. while((HWREGB(ui32Base + USB_O_ULPIREGCTL) & USB_ULPIREGCTL_REGCMPLT) == 0)
  4799. {
  4800. }
  4801. //
  4802. // Clear the register access complete flag.
  4803. //
  4804. HWREGB(ui32Base + USB_O_ULPIREGCTL) = 0;
  4805. return(HWREGB(ui32Base + USB_O_ULPIREGDATA));
  4806. }
  4807. //*****************************************************************************
  4808. //
  4809. //! Writes a value to a register on an external ULPI-connected USB PHY.
  4810. //!
  4811. //! \param ui32Base specifies the USB module base address.
  4812. //! \param ui8Reg specifies the register address to write.
  4813. //! \param ui8Data specifies the data to write.
  4814. //!
  4815. //! This function writes the register address specified in the \e ui8Reg
  4816. //! parameter with the value specified in the \e ui8Data parameter using the
  4817. //! ULPI function. This function is blocking and only returns when the
  4818. //! write access completes. The function does not return if there is not a
  4819. //! ULPI-connected USB PHY present.
  4820. //!
  4821. //! \b Example: Write a register from the external ULPI PHY.
  4822. //!
  4823. //! \verbatim
  4824. //! //
  4825. //! // Write the ULPI PHY register at 0x10 with 0x20.
  4826. //! //
  4827. //! USBULPIRegWrite(USB0_BASE, 0x10, 0x20);
  4828. //! \endverbatim
  4829. //!
  4830. //! \note The USB ULPI feature is not available on all Tiva devices.
  4831. //! Please consult the data sheet for the Tiva device that you
  4832. //! are using to determine if this feature is available.
  4833. //!
  4834. //! \return None.
  4835. //
  4836. //*****************************************************************************
  4837. void
  4838. USBULPIRegWrite(uint32_t ui32Base, uint8_t ui8Reg, uint8_t ui8Data)
  4839. {
  4840. ASSERT(ui32Base == USB0_BASE);
  4841. //
  4842. // Set the register address and initiate a read access.
  4843. //
  4844. HWREGB(ui32Base + USB_O_ULPIREGADDR) = ui8Reg;
  4845. HWREGB(ui32Base + USB_O_ULPIREGDATA) = ui8Data;
  4846. HWREGB(ui32Base + USB_O_ULPIREGCTL) = USB_ULPIREGCTL_REGACC;
  4847. //
  4848. // Wait for the access to complete.
  4849. //
  4850. while((HWREGB(ui32Base + USB_O_ULPIREGCTL) & USB_ULPIREGCTL_REGCMPLT) == 0)
  4851. {
  4852. }
  4853. //
  4854. // Clear the register access complete flag.
  4855. //
  4856. HWREGB(ui32Base + USB_O_ULPIREGCTL) = 0;
  4857. }
  4858. //*****************************************************************************
  4859. //
  4860. // Close the Doxygen group.
  4861. //! @}
  4862. //
  4863. //*****************************************************************************
  4864. //*****************************************************************************
  4865. //
  4866. //! \addtogroup usb_lpm
  4867. //! @{
  4868. //
  4869. //*****************************************************************************
  4870. //*****************************************************************************
  4871. //
  4872. //! Sends an LPM request to a device at a specified address and endpoint number.
  4873. //!
  4874. //! \param ui32Base specifies the USB module base address.
  4875. //! \param ui32Address is the target device address for the LPM request.
  4876. //! \param ui32Endpoint is the target endpoint for the LPM request.
  4877. //!
  4878. //! This function sends an LPM request to a connected device in host mode.
  4879. //! The \e ui32Address parameter specifies the device address and has a range
  4880. //! of values from 1 to 127. The \e ui32Endpoint parameter specifies the
  4881. //! endpoint on the device to which to send the LPM request and must be one of
  4882. //! the \b USB_EP_* values. The function returns before the LPM request is
  4883. //! sent, requiring the caller to poll the USBLPMIntStatus() function or wait
  4884. //! for an interrupt to signal completion of the LPM transaction. This
  4885. //! function must only be called after the USBHostLPMConfig() has configured
  4886. //! the LPM transaction settings.
  4887. //!
  4888. //! \b Example: Send an LPM request to the device at address 1 on endpoint 0.
  4889. //!
  4890. //! \verbatim
  4891. //! //
  4892. //! // Send an LPM request to the device at address 1 on endpoint 0.
  4893. //! //
  4894. //! USBHostLPMSend(USB0_BASE, 1, USB_EP_0);
  4895. //! \endverbatim
  4896. //!
  4897. //! \note This function must only be called in host mode. The USB LPM feature
  4898. //! is not available on all Tiva devices. Please consult the data sheet for
  4899. //! the Tiva device that you are using to determine if this feature is
  4900. //! available.
  4901. //!
  4902. //! \return None.
  4903. //
  4904. //*****************************************************************************
  4905. void
  4906. USBHostLPMSend(uint32_t ui32Base, uint32_t ui32Address, uint32_t ui32Endpoint)
  4907. {
  4908. uint32_t ui32Reg;
  4909. ASSERT(ui32Base == USB0_BASE);
  4910. ASSERT(ui32Address < 127);
  4911. //
  4912. // Set the address and endpoint.
  4913. //
  4914. HWREGB(ui32Base + USB_O_LPMFADDR) = ui32Address;
  4915. ui32Reg = HWREGH(ui32Base + USB_O_LPMATTR) & ~USB_LPMATTR_ENDPT_M;
  4916. ui32Reg |= (USBEPToIndex(ui32Endpoint) << USB_LPMATTR_ENDPT_S);
  4917. HWREGH(ui32Base + USB_O_LPMATTR) = ui32Reg;
  4918. //
  4919. // Send the LPM transaction.
  4920. //
  4921. HWREGB(ui32Base + USB_O_LPMCNTRL) |= USB_LPMCNTRL_TXLPM;
  4922. }
  4923. //*****************************************************************************
  4924. //
  4925. //! Sets the global configuration for all LPM requests.
  4926. //!
  4927. //! \param ui32Base specifies the USB module base address.
  4928. //! \param ui32ResumeTime specifies the resume signaling duration in 75us
  4929. //! increments.
  4930. //! \param ui32Config specifies the combination of configuration options for
  4931. //! LPM transactions.
  4932. //!
  4933. //! This function sets the global configuration options for LPM transactions
  4934. //! and must be called at least once before ever calling USBHostLPMSend(). The
  4935. //! \e ui32ResumeTime specifies the length of time that the host drives resume
  4936. //! signaling on the bus in microseconds. The valid values
  4937. //! for \e ui32ResumeTime are from 50us to 1175us in 75us increments. The
  4938. //! remaining configuration is specified by the \e ui32Config parameter and
  4939. //! includes the following options:
  4940. //!
  4941. //! - \b USB_HOST_LPM_RMTWAKE allows the device to signal a remote wake from
  4942. //! the LPM state.
  4943. //! - \b USB_HOST_LPM_L1 is the LPM mode to enter and must always be included
  4944. //! in the configuration.
  4945. //!
  4946. //! \b Example: Set the LPM configuration to allow remote wake with a resume
  4947. //! duration of 500us.
  4948. //!
  4949. //! \verbatim
  4950. //! //
  4951. //! // Set the LPM configuration to allow remote wake with a resume
  4952. //! // duration of 500us.
  4953. //! //
  4954. //! USBHostLPMConfig(USB0_BASE, 500, USB_HOST_LPM_RMTWAKE | USB_HOST_LPM_L1);
  4955. //! \endverbatim
  4956. //!
  4957. //! \note This function must only be called in host mode. The USB LPM feature
  4958. //! is not available on all Tiva devices. Please consult the data sheet for
  4959. //! the Tiva device that you are using to determine if this feature is
  4960. //! available.
  4961. //!
  4962. //! \return None.
  4963. //
  4964. //*****************************************************************************
  4965. void
  4966. USBHostLPMConfig(uint32_t ui32Base, uint32_t ui32ResumeTime,
  4967. uint32_t ui32Config)
  4968. {
  4969. ASSERT(ui32Base == USB0_BASE);
  4970. ASSERT(ui32ResumeTime <= 1175);
  4971. ASSERT(ui32ResumeTime >= 50);
  4972. //
  4973. // Set the Host Initiated Resume Duration, Remote wake and Suspend mode.
  4974. //
  4975. HWREGH(ui32Base + USB_O_LPMATTR) =
  4976. ui32Config | ((ui32ResumeTime - 50) / 75) << USB_LPMATTR_HIRD_S;
  4977. }
  4978. //*****************************************************************************
  4979. //
  4980. //! Initiates resume signaling to wake a device from LPM suspend mode.
  4981. //!
  4982. //! \param ui32Base specifies the USB module base address.
  4983. //!
  4984. //! In host mode, this function initiates resume signaling to wake a device
  4985. //! that has entered an LPM-triggered low power mode. This LPM-triggered low
  4986. //! power mode is entered when the USBHostLPMSend() is called to put a specific
  4987. //! device into a low power state.
  4988. //!
  4989. //! \b Example: Initiate resume signaling.
  4990. //!
  4991. //! \verbatim
  4992. //! //
  4993. //! // Initiate resume signaling.
  4994. //! //
  4995. //! USBHostLPMResume(USB0_BASE);
  4996. //! \endverbatim
  4997. //!
  4998. //! \note This function must only be called in host mode. The USB LPM feature
  4999. //! is not available on all Tiva devices. Please consult the data sheet for
  5000. //! the Tiva device that you are using to determine if this feature is
  5001. //! available.
  5002. //!
  5003. //! \return None.
  5004. //
  5005. //*****************************************************************************
  5006. void
  5007. USBHostLPMResume(uint32_t ui32Base)
  5008. {
  5009. ASSERT(ui32Base == USB0_BASE);
  5010. //
  5011. // Send Resume signaling.
  5012. //
  5013. HWREGB(ui32Base + USB_O_LPMCNTRL) |= USB_LPMCNTRL_RES;
  5014. }
  5015. //*****************************************************************************
  5016. //
  5017. //! Initiates remote wake signaling to request the device to leave LPM
  5018. //! suspend mode.
  5019. //!
  5020. //! \param ui32Base specifies the USB module base address.
  5021. //!
  5022. //! This function initiates remote wake signaling to request that the host
  5023. //! wake a device that has entered an LPM-triggered low power mode.
  5024. //!
  5025. //! \b Example: Initiate remote wake signaling.
  5026. //!
  5027. //! \verbatim
  5028. //! //
  5029. //! // Initiate remote wake signaling.
  5030. //! //
  5031. //! USBDevLPMRemoteWake(USB0_BASE);
  5032. //! \endverbatim
  5033. //!
  5034. //! \note This function must only be called in device mode. The USB LPM feature
  5035. //! is not available on all Tiva devices. Please consult the data sheet for
  5036. //! the Tiva device that you are using to determine if this feature is
  5037. //! available.
  5038. //!
  5039. //! \return None.
  5040. //
  5041. //*****************************************************************************
  5042. void
  5043. USBDevLPMRemoteWake(uint32_t ui32Base)
  5044. {
  5045. ASSERT(ui32Base == USB0_BASE);
  5046. //
  5047. // Send remote wake signaling.
  5048. //
  5049. HWREGB(ui32Base + USB_O_LPMCNTRL) |= USB_LPMCNTRL_RES;
  5050. }
  5051. //*****************************************************************************
  5052. //
  5053. //! Configures the USB device mode response to LPM requests.
  5054. //!
  5055. //! \param ui32Base specifies the USB module base address.
  5056. //! \param ui32Config is the combination of configuration options for LPM
  5057. //! transactions in device mode.
  5058. //!
  5059. //! This function sets the global configuration options for LPM
  5060. //! transactions in device mode and must be called before ever calling
  5061. //! USBDevLPMEnable() to set the configuration for LPM transactions. The
  5062. //! configuration options in device mode are specified in the \e ui32Config
  5063. //! parameter and include one of the following:
  5064. //!
  5065. //! - \b USB_DEV_LPM_NONE disables the USB controller from responding to LPM
  5066. //! transactions.
  5067. //! - \b USB_DEV_LPM_EN enables the USB controller to respond to LPM
  5068. //! and extended transactions.
  5069. //! - \b USB_DEV_LPM_EXTONLY enables the USB controller to respond to
  5070. //! extended transactions, but not LPM transactions.
  5071. //!
  5072. //! The \e ui32Config option can also optionally include the
  5073. //! \b USB_DEV_LPM_NAK value to cause the USB controller to NAK all
  5074. //! transactions other than an LPM transaction once the USB controller is in
  5075. //! LPM suspend mode. If this value is not included in the \e ui32Config
  5076. //! parameter, the USB controller does not respond in suspend mode.
  5077. //!
  5078. //! The USB controller does not enter LPM suspend mode until the application
  5079. //! calls the USBDevLPMEnable() function.
  5080. //!
  5081. //! \b Example: Enable LPM transactions and NAK while in LPM suspend mode.
  5082. //!
  5083. //! \verbatim
  5084. //! //
  5085. //! // Enable LPM transactions and NAK while in LPM suspend mode.
  5086. //! //
  5087. //! USBDevLPMConfig(USB0_BASE, USB_DEV_LPM_NAK | USB_DEV_LPM_EN);
  5088. //! \endverbatim
  5089. //!
  5090. //! \note This function must only be called in device mode. The USB LPM feature
  5091. //! is not available on all Tiva devices. Please consult the data sheet for
  5092. //! the Tiva device that you are using to determine if this feature is
  5093. //! available.
  5094. //!
  5095. //! \return None.
  5096. //
  5097. //*****************************************************************************
  5098. void
  5099. USBDevLPMConfig(uint32_t ui32Base, uint32_t ui32Config)
  5100. {
  5101. ASSERT(ui32Base == USB0_BASE);
  5102. //
  5103. // Set the device LPM configuration.
  5104. //
  5105. HWREGB(ui32Base + USB_O_LPMCNTRL) = ui32Config;
  5106. }
  5107. //*****************************************************************************
  5108. //
  5109. //! Enables the USB controller to respond to LPM suspend requests.
  5110. //!
  5111. //! \param ui32Base specifies the USB module base address.
  5112. //!
  5113. //! This function is used to automatically respond to an LPM sleep request from
  5114. //! the USB host controller. If there is no data pending in any transmit
  5115. //! FIFOs, then the USB controller acknowledges the packet and enters the
  5116. //! LPM L1 state and generates the \b USB_INTLPM_ACK interrupt. If the USB
  5117. //! controller has pending transmit data in at least one FIFO, then the USB
  5118. //! controller responds with NYET and signals the \b USB_INTLPM_INCOMPLETE or
  5119. //! \b USB_INTLPM_NYET depending on if data is pending in receive or transmit
  5120. //! FIFOs. A call to USBDevLPMEnable() is required after every
  5121. //! LPM resume event to re-enable LPM mode.
  5122. //!
  5123. //! \b Example: Enable LPM suspend mode.
  5124. //!
  5125. //! \verbatim
  5126. //! //
  5127. //! // Enable LPM suspend mode.
  5128. //! //
  5129. //! USBDevLPMEnable(USB0_BASE);
  5130. //! \endverbatim
  5131. //!
  5132. //! \note This function must only be called in device mode. The USB LPM feature
  5133. //! is not available on all Tiva devices. Please consult the data sheet for
  5134. //! the Tiva device that you are using to determine if this feature is
  5135. //! available.
  5136. //!
  5137. //! \return None.
  5138. //
  5139. //*****************************************************************************
  5140. void
  5141. USBDevLPMEnable(uint32_t ui32Base)
  5142. {
  5143. ASSERT(ui32Base == USB0_BASE);
  5144. //
  5145. // Enable L1 mode on the next LPM transaction.
  5146. //
  5147. HWREGB(ui32Base + USB_O_LPMCNTRL) |=
  5148. USB_LPMCNTRL_EN_LPMEXT | USB_LPMCNTRL_TXLPM;
  5149. }
  5150. //*****************************************************************************
  5151. //
  5152. //! Disables the USB controller from responding to LPM suspend requests.
  5153. //!
  5154. //! \param ui32Base specifies the USB module base address.
  5155. //!
  5156. //! This function disables the USB controller from responding to LPM
  5157. //! transactions. When the device enters LPM L1 mode, the USB controller
  5158. //! automatically disables responding to further LPM transactions.
  5159. //!
  5160. //! \note If LPM transactions were enabled before calling this function, then
  5161. //! an LPM request can still occur before this function returns. As a result,
  5162. //! the application must continue to handle LPM requests until this function
  5163. //! returns.
  5164. //!
  5165. //! \b Example: Disable LPM suspend mode.
  5166. //!
  5167. //! \verbatim
  5168. //! //
  5169. //! // Disable LPM suspend mode.
  5170. //! //
  5171. //! USBDevLPMDisable(USB0_BASE);
  5172. //! \endverbatim
  5173. //!
  5174. //! \note This function must only be called in device mode. The USB LPM feature
  5175. //! is not available on all Tiva devices. Please consult the data sheet for
  5176. //! the Tiva device that you are using to determine if this feature is
  5177. //! available.
  5178. //!
  5179. //! \return None.
  5180. //
  5181. //*****************************************************************************
  5182. void
  5183. USBDevLPMDisable(uint32_t ui32Base)
  5184. {
  5185. ASSERT(ui32Base == USB0_BASE);
  5186. //
  5187. // Disable auto entering L1 mode on LPM transactions.
  5188. //
  5189. HWREGB(ui32Base + USB_O_LPMCNTRL) &= ~USB_LPMCNTRL_TXLPM;
  5190. }
  5191. //*****************************************************************************
  5192. //
  5193. //! Returns the current link state setting.
  5194. //!
  5195. //! \param ui32Base specifies the USB module base address.
  5196. //!
  5197. //! This function returns the current link state setting for the USB
  5198. //! controller. When the controller is operating as a host, this link
  5199. //! state is sent with an LPM request. When the controller is acting
  5200. //! as a device, this link state was received by the last LPM transaction
  5201. //! whether it was acknowledged or stalled because the requested
  5202. //! LPM mode is not supported.
  5203. //!
  5204. //! \b Example: Get the link state for the last LPM transaction.
  5205. //!
  5206. //! \verbatim
  5207. //! uint32_t ui32LinkState;
  5208. //!
  5209. //! //
  5210. //! // Get the endpoint number that received the LPM request.
  5211. //! //
  5212. //! ui32LinkState = USBLPMLinkStateGet(USB0_BASE);
  5213. //!
  5214. //! //
  5215. //! // Check if this was a supported link state.
  5216. //! //
  5217. //! if(ui32LinkState == USB_HOST_LPM_L1)
  5218. //! {
  5219. //! //
  5220. //! // Handle the supported L1 link state.
  5221. //! //
  5222. //! }
  5223. //! else
  5224. //! {
  5225. //! //
  5226. //! // Handle the unsupported link state.
  5227. //! //
  5228. //! }
  5229. //! \endverbatim
  5230. //!
  5231. //! \note The USB LPM feature is not available on all Tiva devices.
  5232. //! Please consult the data sheet for the Tiva device that you
  5233. //! are using to determine if this feature is available.
  5234. //!
  5235. //! \return The current LPM link state.
  5236. //
  5237. //*****************************************************************************
  5238. uint32_t
  5239. USBLPMLinkStateGet(uint32_t ui32Base)
  5240. {
  5241. ASSERT(ui32Base == USB0_BASE);
  5242. return(HWREGH(ui32Base + USB_O_LPMATTR) & USB_LPMATTR_LS_M);
  5243. }
  5244. //*****************************************************************************
  5245. //
  5246. //! Returns the current LPM endpoint value.
  5247. //!
  5248. //! \param ui32Base specifies the USB module base address.
  5249. //!
  5250. //! This function returns the current LPM endpoint value. The meaning of the
  5251. //! value depends on the mode of operation of the USB controller. When in
  5252. //! device mode, the value returned is the endpoint that received the last
  5253. //! LPM transaction. When in host mode this is the endpoint that was last
  5254. //! sent an LPM transaction, or the endpoint that is configured to be sent when
  5255. //! the LPM transaction is triggered. The value returned is in the
  5256. //! \b USB_EP_[0-7] value and a direct endpoint index.
  5257. //!
  5258. //! \b Example: Get the endpoint for the last LPM transaction.
  5259. //!
  5260. //! \verbatim
  5261. //! uint32_t ui32Endpoint;
  5262. //!
  5263. //! //
  5264. //! // Get the endpoint number that received the LPM request.
  5265. //! //
  5266. //! ui32LinkState = USBLPMEndpointGet(USB0_BASE);
  5267. //!
  5268. //! \endverbatim
  5269. //!
  5270. //! \note The USB LPM feature is not available on all Tiva devices. Please
  5271. //! consult the data sheet for the Tiva device that you are using to determine
  5272. //! if this feature is available.
  5273. //!
  5274. //! \return The last endpoint to receive an LPM request in device mode or the
  5275. //! endpoint that the host sends an LPM request as one of the \b USB_EP_[0-7]
  5276. //! values.
  5277. //
  5278. //*****************************************************************************
  5279. uint32_t
  5280. USBLPMEndpointGet(uint32_t ui32Base)
  5281. {
  5282. uint32_t ui32Endpoint;
  5283. ASSERT(ui32Base == USB0_BASE);
  5284. ui32Endpoint = (HWREGH(ui32Base + USB_O_LPMATTR) & USB_LPMATTR_ENDPT_M) >>
  5285. USB_LPMATTR_ENDPT_S;
  5286. return(IndexToUSBEP(ui32Endpoint));
  5287. }
  5288. //*****************************************************************************
  5289. //
  5290. //! Returns if remote wake is currently enabled.
  5291. //!
  5292. //! \param ui32Base specifies the USB module base address.
  5293. //!
  5294. //! This function returns the current state of the remote wake setting for host
  5295. //! or device mode operation. If the controller is acting as a host this
  5296. //! returns the current setting that is sent to devices when LPM requests are
  5297. //! sent to a device. If the controller is in device mode, this function
  5298. //! returns the state of the last LPM request sent from the host and indicates
  5299. //! if the host enabled remote wakeup.
  5300. //!
  5301. //! \b Example: Issue remote wake if remote wake is enabled.
  5302. //!
  5303. //! \verbatim
  5304. //!
  5305. //! if(USBLPMRemoteWakeEnabled(USB0_BASE))
  5306. //! {
  5307. //! USBDevLPMRemoteWake(USB0_BASE);
  5308. //! }
  5309. //!
  5310. //! \endverbatim
  5311. //!
  5312. //! \note The USB LPM feature is not available on all Tiva devices.
  5313. //! Please consult the data sheet for the Tiva device that you
  5314. //! are using to determine if this feature is available.
  5315. //!
  5316. //! \return The \b true if remote wake is enabled or \b false if it is not.
  5317. //
  5318. //*****************************************************************************
  5319. bool
  5320. USBLPMRemoteWakeEnabled(uint32_t ui32Base)
  5321. {
  5322. ASSERT(ui32Base == USB0_BASE);
  5323. if(HWREGH(ui32Base + USB_O_LPMATTR) & USB_LPMATTR_RMTWAK)
  5324. {
  5325. return(true);
  5326. }
  5327. return(false);
  5328. }
  5329. //*****************************************************************************
  5330. //
  5331. //! Returns the current LPM interrupt status.
  5332. //!
  5333. //! \param ui32Base specifies the USB module base address.
  5334. //!
  5335. //! This function returns the current LPM interrupt status for the USB
  5336. //! controller.
  5337. //!
  5338. //! The valid interrupt status bits when the USB controller is acting as a host
  5339. //! are the following:
  5340. //!
  5341. //! - \b USB_INTLPM_ERROR a bus error occurred in the transmission of an LPM
  5342. //! transaction.
  5343. //! - \b USB_INTLPM_RESUME the USB controller has resumed from the LPM low
  5344. //! power state.
  5345. //! - \b USB_INTLPM_INCOMPLETE the LPM transaction failed because a timeout
  5346. //! occurred or there were bit errors in the response for three attempts.
  5347. //! - \b USB_INTLPM_ACK the device has acknowledged an LPM transaction.
  5348. //! - \b USB_INTLPM_NYET the device has responded with a NYET to an LPM
  5349. //! transaction.
  5350. //! - \b USB_INTLPM_STALL the device has stalled an LPM transaction.
  5351. //!
  5352. //! The valid interrupt status bits when the USB controller is acting as a
  5353. //! device are the following:
  5354. //!
  5355. //! - \b USB_INTLPM_ERROR an LPM transaction was received that has an
  5356. //! unsupported link state field. The transaction was stalled, but the
  5357. //! requested link state can still be read using the USBLPMLinkStateGet()
  5358. //! function.
  5359. //! - \b USB_INTLPM_RESUME the USB controller has resumed from the LPM low
  5360. //! power state.
  5361. //! - \b USB_INTLPM_INCOMPLETE the USB controller responded to an LPM
  5362. //! transaction with a NYET because data was still in the transmit FIFOs.
  5363. //! - \b USB_INTLPM_ACK the USB controller acknowledged an LPM transaction and
  5364. //! is now in the LPM suspend mode.
  5365. //! - \b USB_INTLPM_NYET the USB controller responded to an LPM transaction
  5366. //! with a NYET because LPM transactions are not yet enabled by a call to
  5367. //! USBDevLPMEnable().
  5368. //! - \b USB_INTLPM_STALL the USB controller has stalled an incoming LPM
  5369. //! transaction.
  5370. //!
  5371. //! \note This call clears the source of all LPM status interrupts, so the
  5372. //! caller must take care to save the value returned because a subsequent call
  5373. //! to USBLPMIntStatus() does not return the previous value.
  5374. //!
  5375. //! \b Example: Get the current LPM interrupt status.
  5376. //!
  5377. //! \verbatim
  5378. //! uint32_t ui32LPMIntStatus;
  5379. //!
  5380. //! //
  5381. //! // Get the current LPM interrupt status.
  5382. //! //
  5383. //! ui32LPMIntStatus = USBLPMIntStatus(USB0_BASE);
  5384. //!
  5385. //! //
  5386. //! // Check if an LPM transaction was acknowledged.
  5387. //! //
  5388. //! if(ui32LPMIntStatus & USB_INTLPM_ACK)
  5389. //! {
  5390. //! //
  5391. //! // Handle entering LPM suspend mode.
  5392. //! //
  5393. //! ...
  5394. //! }
  5395. //! \endverbatim
  5396. //!
  5397. //! \note The USB LPM feature is not available on all Tiva devices.
  5398. //! Please consult the data sheet for the Tiva device that you
  5399. //! are using to determine if this feature is available.
  5400. //!
  5401. //! \return The current LPM interrupt status.
  5402. //
  5403. //*****************************************************************************
  5404. uint32_t
  5405. USBLPMIntStatus(uint32_t ui32Base)
  5406. {
  5407. ASSERT(ui32Base == USB0_BASE);
  5408. //
  5409. // Return the current raw interrupt status.
  5410. //
  5411. return(HWREGB(ui32Base + USB_O_LPMRIS));
  5412. }
  5413. //*****************************************************************************
  5414. //
  5415. //! Enables LPM interrupts.
  5416. //!
  5417. //! \param ui32Base specifies the USB module base address.
  5418. //! \param ui32Ints specifies which LPM interrupts to enable.
  5419. //!
  5420. //! This function enables a set of LPM interrupts so that they can trigger a
  5421. //! USB interrupt. The \e ui32Ints parameter specifies which of the
  5422. //! \b USB_INTLPM_* to enable.
  5423. //!
  5424. //! The valid interrupt status bits when the USB controller is acting as a host
  5425. //! are the following:
  5426. //!
  5427. //! - \b USB_INTLPM_ERROR a bus error occurred in the transmission of an LPM
  5428. //! transaction.
  5429. //! - \b USB_INTLPM_RESUME the USB controller has resumed from LPM low power
  5430. //! state.
  5431. //! - \b USB_INTLPM_INCOMPLETE the LPM transaction failed because a timeout
  5432. //! occurred or there were bit errors in the response for three attempts.
  5433. //! - \b USB_INTLPM_ACK the device has acknowledged an LPM transaction.
  5434. //! - \b USB_INTLPM_NYET the device has responded with a NYET to an LPM
  5435. //! transaction.
  5436. //! - \b USB_INTLPM_STALL the device has stalled an LPM transaction.
  5437. //!
  5438. //! The valid interrupt status bits when the USB controller is acting as a
  5439. //! device are the following:
  5440. //!
  5441. //! - \b USB_INTLPM_ERROR an LPM transaction was received that has an
  5442. //! unsupported link state field. The transaction was stalled, but the
  5443. //! requested link state can still be read using the USBLPMLinkStateGet()
  5444. //! function.
  5445. //! - \b USB_INTLPM_RESUME the USB controller has resumed from the LPM low
  5446. //! power state.
  5447. //! - \b USB_INTLPM_INCOMPLETE the USB controller responded to an LPM
  5448. //! transaction with a NYET because data was still in the transmit FIFOs.
  5449. //! - \b USB_INTLPM_ACK the USB controller acknowledged an LPM transaction and
  5450. //! is now in the LPM suspend mode.
  5451. //! - \b USB_INTLPM_NYET the USB controller responded to an LPM transaction
  5452. //! with a NYET because LPM transactions are not yet enabled by a call to
  5453. //! USBDevLPMEnable().
  5454. //! - \b USB_INTLPM_STALL the USB controller has stalled an incoming LPM
  5455. //! transaction.
  5456. //!
  5457. //! \b Example: Enable all LPM interrupt sources.
  5458. //!
  5459. //! \verbatim
  5460. //! //
  5461. //! // Enable all LPM interrupt sources.
  5462. //! //
  5463. //! USBLPMIntEnable(USB0_BASE, USB_INTLPM_ERROR | USB_INTLPM_RESUME |
  5464. //! USB_INTLPM_INCOMPLETE | USB_INTLPM_ACK |
  5465. //! USB_INTLPM_NYET | USB_INTLPM_STALL);
  5466. //! \endverbatim
  5467. //!
  5468. //! \note The USB LPM feature is not available on all Tiva devices.
  5469. //! Please consult the data sheet for the Tiva device that you
  5470. //! are using to determine if this feature is available.
  5471. //!
  5472. //! \return None.
  5473. //
  5474. //*****************************************************************************
  5475. void
  5476. USBLPMIntEnable(uint32_t ui32Base, uint32_t ui32Ints)
  5477. {
  5478. ASSERT(ui32Base == USB0_BASE);
  5479. //
  5480. // Enable the requested interrupts.
  5481. //
  5482. HWREGB(ui32Base + USB_O_LPMIM) |= ui32Ints;
  5483. }
  5484. //*****************************************************************************
  5485. //
  5486. //! Disables LPM interrupts.
  5487. //!
  5488. //! \param ui32Base specifies the USB module base address.
  5489. //! \param ui32Ints specifies which LPM interrupts to disable.
  5490. //!
  5491. //! This function disables the LPM interrupts specified in the \e ui32Ints
  5492. //! parameter, preventing them from triggering a USB interrupt.
  5493. //!
  5494. //! The valid interrupt status bits when the USB controller is acting as a host
  5495. //! are the following:
  5496. //!
  5497. //! - \b USB_INTLPM_ERROR a bus error occurred in the transmission of an LPM
  5498. //! transaction.
  5499. //! - \b USB_INTLPM_RESUME the USB controller has resumed from LPM low power
  5500. //! state.
  5501. //! - \b USB_INTLPM_INCOMPLETE the LPM transaction failed because a timeout
  5502. //! occurred or there were bit errors in the response for three attempts.
  5503. //! - \b USB_INTLPM_ACK the device has acknowledged an LPM transaction.
  5504. //! - \b USB_INTLPM_NYET the device has responded with a NYET to an LPM
  5505. //! transaction.
  5506. //! - \b USB_INTLPM_STALL the device has stalled an LPM transaction.
  5507. //!
  5508. //! The valid interrupt status bits when the USB controller is acting as a
  5509. //! device are the following:
  5510. //!
  5511. //! - \b USB_INTLPM_ERROR an LPM transaction was received that has an
  5512. //! unsupported link state field. The transaction was stalled, but the
  5513. //! requested link state can still be read using the USBLPMLinkStateGet()
  5514. //! function.
  5515. //! - \b USB_INTLPM_RESUME the USB controller has resumed from the LPM low
  5516. //! power state.
  5517. //! - \b USB_INTLPM_INCOMPLETE the USB controller responded to an LPM
  5518. //! transaction with a NYET because data was still in the transmit FIFOs.
  5519. //! - \b USB_INTLPM_ACK the USB controller acknowledged an LPM transaction and
  5520. //! is now in the LPM suspend mode.
  5521. //! - \b USB_INTLPM_NYET the USB controller responded to an LPM transaction
  5522. //! with a NYET because LPM transactions are not yet enabled by a call to
  5523. //! USBDevLPMEnable().
  5524. //! - \b USB_INTLPM_STALL the USB controller has stalled an incoming LPM
  5525. //! transaction.
  5526. //!
  5527. //! \b Example: Disable all LPM interrupt sources.
  5528. //!
  5529. //! \verbatim
  5530. //! //
  5531. //! // Disable all LPM interrupt sources.
  5532. //! //
  5533. //! USBLPMIntDisable(USB0_BASE, USB_INTLPM_ERROR | USB_INTLPM_RESUME |
  5534. //! USB_INTLPM_INCOMPLETE | USB_INTLPM_ACK |
  5535. //! USB_INTLPM_NYET | USB_INTLPM_STALL);
  5536. //! \endverbatim
  5537. //!
  5538. //! \note The USB LPM feature is not available on all Tiva devices.
  5539. //! Please consult the data sheet for the Tiva device that you
  5540. //! are using to determine if this feature is available.
  5541. //!
  5542. //! \return None.
  5543. //
  5544. //*****************************************************************************
  5545. void
  5546. USBLPMIntDisable(uint32_t ui32Base, uint32_t ui32Ints)
  5547. {
  5548. ASSERT(ui32Base == USB0_BASE);
  5549. //
  5550. // Disable the requested interrupts.
  5551. //
  5552. HWREGB(ui32Base + USB_O_LPMIM) &= ~ui32Ints;
  5553. }
  5554. //*****************************************************************************
  5555. //
  5556. // Close the Doxygen group.
  5557. //! @}
  5558. //
  5559. //*****************************************************************************