usb.c 194 KB

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