usb.c 182 KB

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