12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434 |
- //*****************************************************************************
- //
- // usb.c - Driver for the USB Interface.
- //
- // Copyright (c) 2007-2009 Luminary Micro, Inc. All rights reserved.
- // Software License Agreement
- //
- // Luminary Micro, Inc. (LMI) is supplying this software for use solely and
- // exclusively on LMI's microcontroller products.
- //
- // The software is owned by LMI and/or its suppliers, and is protected under
- // applicable copyright laws. All rights are reserved. You may not combine
- // this software with "viral" open-source software in order to form a larger
- // program. Any use in violation of the foregoing restrictions may subject
- // the user to criminal sanctions under applicable laws, as well as to civil
- // liability for the breach of the terms and conditions of this license.
- //
- // THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
- // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
- // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
- // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
- // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
- //
- // This is part of revision 4694 of the Stellaris Peripheral Driver Library.
- //
- //*****************************************************************************
- //*****************************************************************************
- //
- //! \addtogroup usb_api
- //! @{
- //
- //*****************************************************************************
- #include "inc/hw_ints.h"
- #include "inc/hw_memmap.h"
- #include "inc/hw_types.h"
- #include "inc/hw_usb.h"
- #include "driverlib/debug.h"
- #include "driverlib/interrupt.h"
- #include "driverlib/udma.h"
- #include "driverlib/usb.h"
- //*****************************************************************************
- //
- // Amount to shift the RX interrupt sources by in the flags used in the
- // interrupt calls.
- //
- //*****************************************************************************
- #define USB_INT_RX_SHIFT 8
- //*****************************************************************************
- //
- // Amount to shift the status interrupt sources by in the flags used in the
- // interrupt calls.
- //
- //*****************************************************************************
- #define USB_INT_STATUS_SHIFT 24
- //*****************************************************************************
- //
- // Amount to shift the RX endpoint status sources by in the flags used in the
- // calls.
- //
- //*****************************************************************************
- #define USB_RX_EPSTATUS_SHIFT 16
- //*****************************************************************************
- //
- // Converts from an endpoint specifier to the offset of the endpoint's
- // control/status registers.
- //
- //*****************************************************************************
- #define EP_OFFSET(Endpoint) (Endpoint - 0x10)
- //*****************************************************************************
- //
- // Sets one of the indexed registers.
- //
- // \param ulBase specifies the USB module base address.
- // \param ulEndpoint is the endpoint index to target for this write.
- // \param ulIndexedReg is the indexed register to write to.
- // \param ucValue is the value to write to the register.
- //
- // This function is used to access the indexed registers for each endpoint.
- // The only registers that are indexed are the FIFO configuration registers
- // which are not used after configuration.
- //
- // \return None.
- //
- //*****************************************************************************
- static void
- USBIndexWrite(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long ulIndexedReg, unsigned long ulValue,
- unsigned long ulSize)
- {
- unsigned long ulIndex;
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == 0) || (ulEndpoint == 1) || (ulEndpoint == 2) ||
- (ulEndpoint == 3));
- ASSERT((ulSize == 1) || (ulSize == 2));
- //
- // Save the old index in case it was in use.
- //
- ulIndex = HWREGB(ulBase + USB_O_EPIDX);
- //
- // Set the index.
- //
- HWREGB(ulBase + USB_O_EPIDX) = ulEndpoint;
- //
- // Determine the size of the register value.
- //
- if(ulSize == 1)
- {
- //
- // Set the value.
- //
- HWREGB(ulBase + ulIndexedReg) = ulValue;
- }
- else
- {
- //
- // Set the value.
- //
- HWREGH(ulBase + ulIndexedReg) = ulValue;
- }
- //
- // Restore the old index in case it was in use.
- //
- HWREGB(ulBase + USB_O_EPIDX) = ulIndex;
- }
- //*****************************************************************************
- //
- // Reads one of the indexed registers.
- //
- // \param ulBase specifies the USB module base address.
- // \param ulEndpoint is the endpoint index to target for this write.
- // \param ulIndexedReg is the indexed register to write to.
- //
- // This function is used interally to access the indexed registers for each
- // endpoint. The only registers that are indexed are the FIFO configuration
- // registers which are not used after configuration.
- //
- // \return The value in the register requested.
- //
- //*****************************************************************************
- static unsigned long
- USBIndexRead(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long ulIndexedReg, unsigned long ulSize)
- {
- unsigned char ulIndex;
- unsigned char ulValue;
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == 0) || (ulEndpoint == 1) || (ulEndpoint == 2) ||
- (ulEndpoint == 3));
- ASSERT((ulSize == 1) || (ulSize == 2));
- //
- // Save the old index in case it was in use.
- //
- ulIndex = HWREGB(ulBase + USB_O_EPIDX);
- //
- // Set the index.
- //
- HWREGB(ulBase + USB_O_EPIDX) = ulEndpoint;
- //
- // Determine the size of the register value.
- //
- if(ulSize == 1)
- {
- //
- // Get the value.
- //
- ulValue = HWREGB(ulBase + ulIndexedReg);
- }
- else
- {
- //
- // Get the value.
- //
- ulValue = HWREGH(ulBase + ulIndexedReg);
- }
- //
- // Restore the old index in case it was in use.
- //
- HWREGB(ulBase + USB_O_EPIDX) = ulIndex;
- //
- // Return the register's value.
- //
- return(ulValue);
- }
- //*****************************************************************************
- //
- //! Puts the USB bus in a suspended state.
- //!
- //! \param ulBase specifies the USB module base address.
- //!
- //! When used in host mode, this function will put the USB bus in the suspended
- //! state.
- //!
- //! \note This function should only be called in host mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBHostSuspend(unsigned long ulBase)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- //
- // Send the suspend signaling to the USB bus.
- //
- HWREGB(ulBase + USB_O_POWER) |= USB_POWER_SUSPEND;
- }
- //*****************************************************************************
- //
- //! Handles the USB bus reset condition.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param bStart specifies whether to start or stop signaling reset on the USB
- //! bus.
- //!
- //! When this function is called with the \e bStart parameter set to \b true,
- //! this function will cause the start of a reset condition on the USB bus.
- //! The caller should then delay at least 20ms before calling this function
- //! again with the \e bStart parameter set to \b false.
- //!
- //! \note This function should only be called in host mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBHostReset(unsigned long ulBase, tBoolean bStart)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- //
- // Send a reset signal to the bus.
- //
- if(bStart)
- {
- HWREGB(ulBase + USB_O_POWER) |= USB_POWER_RESET;
- }
- else
- {
- HWREGB(ulBase + USB_O_POWER) &= ~USB_POWER_RESET;
- }
- }
- //*****************************************************************************
- //
- //! Handles the USB bus resume condition.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param bStart specifies if the USB controller is entering or leaving the
- //! resume signaling state.
- //!
- //! When in device mode this function will bring the USB controller out of the
- //! suspend state. This call should first be made with the \e bStart parameter
- //! set to \b true to start resume signaling. The device application should
- //! then delay at least 10ms but not more than 15ms before calling this
- //! function with the \e bStart parameter set to \b false.
- //!
- //! When in host mode this function will signal devices to leave the suspend
- //! state. This call should first be made with the \e bStart parameter set to
- //! \b true to start resume signaling. The host application should then delay
- //! at least 20ms before calling this function with the \e bStart parameter set
- //! to \b false. This will cause the controller to complete the resume
- //! signaling on the USB bus.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBHostResume(unsigned long ulBase, tBoolean bStart)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- //
- // Send a resume signal to the bus.
- //
- if(bStart)
- {
- HWREGB(ulBase + USB_O_POWER) |= USB_POWER_RESUME;
- }
- else
- {
- HWREGB(ulBase + USB_O_POWER) &= ~USB_POWER_RESUME;
- }
- }
- //*****************************************************************************
- //
- //! Returns the current speed of the USB device connected.
- //!
- //! \param ulBase specifies the USB module base address.
- //!
- //! This function will return the current speed of the USB bus.
- //!
- //! \note This function should only be called in host mode.
- //!
- //! \return Returns either \b USB_LOW_SPEED, \b USB_FULL_SPEED, or
- //! \b USB_UNDEF_SPEED.
- //
- //*****************************************************************************
- unsigned long
- USBHostSpeedGet(unsigned long ulBase)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- //
- // If the Full Speed device bit is set, then this is a full speed device.
- //
- if(HWREGB(ulBase + USB_O_DEVCTL) & USB_DEVCTL_FSDEV)
- {
- return(USB_FULL_SPEED);
- }
- //
- // If the Low Speed device bit is set, then this is a low speed device.
- //
- if(HWREGB(ulBase + USB_O_DEVCTL) & USB_DEVCTL_LSDEV)
- {
- return(USB_LOW_SPEED);
- }
- //
- // The device speed is not known.
- //
- return(USB_UNDEF_SPEED);
- }
- //*****************************************************************************
- //
- //! Returns the status of the USB interrupts.
- //!
- //! \param ulBase specifies the USB module base address.
- //!
- //! This function will read the source of the interrupt for the USB controller.
- //! There are three groups of interrupt sources, IN Endpoints, OUT Endpoints,
- //! and general status changes. This call will return the current status for
- //! all of these interrupts. The bit values returned should be compared
- //! against the \b USB_HOST_IN, \b USB_HOST_OUT, \b USB_HOST_EP0,
- //! \b USB_DEV_IN, \b USB_DEV_OUT, and \b USB_DEV_EP0 values.
- //!
- //! \note This call will clear the source of all of the general status
- //! interrupts.
- //!
- //! \return Returns the status of the sources for the USB controller's
- //! interrupt.
- //
- //*****************************************************************************
- unsigned long
- USBIntStatus(unsigned long ulBase)
- {
- unsigned long ulStatus;
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- //
- // Get the transmit interrupt status.
- //
- ulStatus = (HWREGH(ulBase + USB_O_TXIS));
- //
- // Get the receive interrupt status, these bits go into the second byte of
- // the returned value.
- //
- ulStatus |= (HWREGH(ulBase + USB_O_RXIS) << USB_INT_RX_SHIFT);
- //
- // Get the general interrupt status, these bits go into the upper 8 bits
- // of the returned value.
- //
- ulStatus |= (HWREGB(ulBase + USB_O_IS) << USB_INT_STATUS_SHIFT);
- //
- // Add the power fault status.
- //
- if(HWREG(ulBase + USB_O_EPCISC) & USB_EPCISC_PF)
- {
- //
- // Indicate a power fault was detected.
- //
- ulStatus |= USB_INT_POWER_FAULT;
- //
- // Clear the power fault interrupt.
- //
- HWREGB(ulBase + USB_O_EPCISC) |= USB_EPCISC_PF;
- }
- if(HWREG(USB0_BASE + USB_O_IDVISC) & USB_IDVRIS_ID)
- {
- //
- // Indicate a id detection was detected.
- //
- ulStatus |= USB_INT_MODE_DETECT;
- //
- // Clear the id detection interrupt.
- //
- HWREG(USB0_BASE + USB_O_IDVISC) |= USB_IDVRIS_ID;
- }
- //
- // Return the combined interrupt status.
- //
- return(ulStatus);
- }
- //*****************************************************************************
- //
- //! Disables the sources for USB interrupts.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulFlags specifies which interrupts to disable.
- //!
- //! This function will disable the USB controller from generating the
- //! interrupts indicated by the \e ulFlags parameter. There are three groups
- //! of interrupt sources, IN Endpoints, OUT Endpoints, and general status
- //! changes, specified by \b USB_INT_HOST_IN, \b USB_INT_HOST_OUT,
- //! \b USB_INT_DEV_IN, \b USB_INT_DEV_OUT, and \b USB_INT_STATUS. If
- //! \b USB_INT_ALL is specified then all interrupts will be disabled.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBIntDisable(unsigned long ulBase, unsigned long ulFlags)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulFlags & ~(USB_INT_ALL)) == 0);
- //
- // If any transmit interrupts were disabled then write the transmit
- // interrupt settings out to the hardware.
- //
- if(ulFlags & (USB_INT_HOST_OUT | USB_INT_DEV_IN | USB_INT_EP0))
- {
- HWREGH(ulBase + USB_O_TXIE) &=
- ~(ulFlags & (USB_INT_HOST_OUT | USB_INT_DEV_IN | USB_INT_EP0));
- }
- //
- // If any receive interrupts were disabled then write the receive interrupt
- // settings out to the hardware.
- //
- if(ulFlags & (USB_INT_HOST_IN | USB_INT_DEV_OUT))
- {
- HWREGH(ulBase + USB_O_RXIE) &=
- ~((ulFlags & (USB_INT_HOST_IN | USB_INT_DEV_OUT)) >>
- USB_INT_RX_SHIFT);
- }
- //
- // If any general interrupts were disabled then write the general interrupt
- // settings out to the hardware.
- //
- if(ulFlags & USB_INT_STATUS)
- {
- HWREGB(ulBase + USB_O_IE) &=
- ~((ulFlags & USB_INT_STATUS) >> USB_INT_STATUS_SHIFT);
- }
- //
- // Disable the power fault interrupt.
- //
- if(ulFlags & USB_INT_POWER_FAULT)
- {
- HWREG(ulBase + USB_O_EPCIM) = 0;
- }
- //
- // Disable the ID pin detect interrupt.
- //
- if(ulFlags & USB_INT_MODE_DETECT)
- {
- HWREG(USB0_BASE + USB_O_IDVIM) = 0;
- }
- }
- //*****************************************************************************
- //
- //! Enables the sources for USB interrupts.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulFlags specifies which interrupts to enable.
- //!
- //! This function will enable the USB controller's ability to generate the
- //! interrupts indicated by the \e ulFlags parameter. There are three
- //! groups of interrupt sources, IN Endpoints, OUT Endpoints, and
- //! general status changes, specified by \b USB_INT_HOST_IN,
- //! \b USB_INT_HOST_OUT, \b USB_INT_DEV_IN, \b USB_INT_DEV_OUT, and
- //! \b USB_STATUS. If \b USB_INT_ALL is specified then all interrupts will be
- //! enabled.
- //!
- //! \note A call must be made to enable the interrupt in the main interrupt
- //! controller to receive interrupts. The USBIntRegister() API performs this
- //! controller level interrupt enable. However if static interrupt handlers
- //! are used then then a call to IntEnable() must be made in order to allow any
- //! USB interrupts to occur.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBIntEnable(unsigned long ulBase, unsigned long ulFlags)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulFlags & (~USB_INT_ALL)) == 0);
- //
- // If any transmit interrupts were enabled then write the transmit
- // interrupt settings out to the hardware.
- //
- if(ulFlags & (USB_INT_HOST_OUT | USB_INT_DEV_IN | USB_INT_EP0))
- {
- HWREGH(ulBase + USB_O_TXIE) |=
- ulFlags & (USB_INT_HOST_OUT | USB_INT_DEV_IN | USB_INT_EP0);
- }
- //
- // If any receive interrupts were enabled then write the receive interrupt
- // settings out to the hardware.
- //
- if(ulFlags & (USB_INT_HOST_IN | USB_INT_DEV_OUT))
- {
- HWREGH(ulBase + USB_O_RXIE) |=
- ((ulFlags & (USB_INT_HOST_IN | USB_INT_DEV_OUT)) >>
- USB_INT_RX_SHIFT);
- }
- //
- // If any general interrupts were enabled then write the general interrupt
- // settings out to the hardware.
- //
- if(ulFlags & USB_INT_STATUS)
- {
- HWREGB(ulBase + USB_O_IE) |=
- (ulFlags & USB_INT_STATUS) >> USB_INT_STATUS_SHIFT;
- }
- //
- // Enable the power fault interrupt.
- //
- if(ulFlags & USB_INT_POWER_FAULT)
- {
- HWREG(ulBase + USB_O_EPCIM) = USB_EPCIM_PF;
- }
- //
- // Enable the ID pin detect interrupt.
- //
- if(ulFlags & USB_INT_MODE_DETECT)
- {
- HWREG(USB0_BASE + USB_O_IDVIM) = USB_IDVIM_ID;
- }
- }
- //*****************************************************************************
- //
- //! Registers an interrupt handler for the USB controller.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param pfnHandler is a pointer to the function to be called when a USB
- //! interrupt occurs.
- //!
- //! This sets the handler to be called when a USB interrupt occurs. This will
- //! also enable the global USB interrupt in the interrupt controller. The
- //! specific desired USB interrupts must be enabled via a separate call to
- //! USBIntEnable(). It is the interrupt handler's responsibility to clear the
- //! interrupt sources via a call to USBIntStatus().
- //!
- //! \sa IntRegister() for important information about registering interrupt
- //! handlers.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBIntRegister(unsigned long ulBase, void(*pfnHandler)(void))
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- //
- // Register the interrupt handler.
- //
- IntRegister(INT_USB0, pfnHandler);
- //
- // Enable the USB interrupt.
- //
- IntEnable(INT_USB0);
- }
- //*****************************************************************************
- //
- //! Unregisters an interrupt handler for the USB controller.
- //!
- //! \param ulBase specifies the USB module base address.
- //!
- //! This function unregister the interrupt handler. This function will also
- //! disable the USB interrupt in the interrupt controller.
- //!
- //! \sa IntRegister() for important information about registering or
- //! unregistering interrupt handlers.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBIntUnregister(unsigned long ulBase)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- //
- // Unregister the interrupt handler.
- //
- IntUnregister(INT_USB0);
- //
- // Disable the CAN interrupt.
- //
- IntDisable(INT_USB0);
- }
- //*****************************************************************************
- //
- //! Returns the current status of an endpoint.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //!
- //! This function will return the status of a given endpoint. If any of these
- //! status bits need to be cleared, then these these values must be cleared by
- //! calling the USBDevEndpointStatusClear() or USBHostEndpointStatusClear()
- //! functions.
- //!
- //! The following are the status flags for host mode:
- //!
- //! - \b USB_HOST_IN_PID_ERROR - PID error on the given endpoint.
- //! - \b USB_HOST_IN_NOT_COMP - The device failed to respond to an IN request.
- //! - \b USB_HOST_IN_STALL - A stall was received on an IN endpoint.
- //! - \b USB_HOST_IN_DATA_ERROR - There was a CRC or bit-stuff error on an IN
- //! endpoint in Isochronous mode.
- //! - \b USB_HOST_IN_NAK_TO - NAKs received on this IN endpoint for more than
- //! the specified timeout period.
- //! - \b USB_HOST_IN_ERROR - Failed to communicate with a device using this IN
- //! endpoint.
- //! - \b USB_HOST_IN_FIFO_FULL - This IN endpoint's FIFO is full.
- //! - \b USB_HOST_IN_PKTRDY - Data packet ready on this IN endpoint.
- //! - \b USB_HOST_OUT_NAK_TO - NAKs received on this OUT endpoint for more than
- //! the specified timeout period.
- //! - \b USB_HOST_OUT_NOT_COMP - The device failed to respond to an OUT
- //! request.
- //! - \b USB_HOST_OUT_STALL - A stall was received on this OUT endpoint.
- //! - \b USB_HOST_OUT_ERROR - Failed to communicate with a device using this
- //! OUT endpoint.
- //! - \b USB_HOST_OUT_FIFO_NE - This endpoint's OUT FIFO is not empty.
- //! - \b USB_HOST_OUT_PKTPEND - The data transfer on this OUT endpoint has not
- //! completed.
- //! - \b USB_HOST_EP0_NAK_TO - NAKs received on endpoint zero for more than the
- //! specified timeout period.
- //! - \b USB_HOST_EP0_ERROR - The device failed to respond to a request on
- //! endpoint zero.
- //! - \b USB_HOST_EP0_IN_STALL - A stall was received on endpoint zero for an
- //! IN transaction.
- //! - \b USB_HOST_EP0_IN_PKTRDY - Data packet ready on endpoint zero for an IN
- //! transaction.
- //!
- //! The following are the status flags for device mode:
- //!
- //! - \b USB_DEV_OUT_SENT_STALL - A stall was sent on this OUT endpoint.
- //! - \b USB_DEV_OUT_DATA_ERROR - There was a CRC or bit-stuff error on an OUT
- //! endpoint.
- //! - \b USB_DEV_OUT_OVERRUN - An OUT packet was not loaded due to a full FIFO.
- //! - \b USB_DEV_OUT_FIFO_FULL - The OUT endpoint's FIFO is full.
- //! - \b USB_DEV_OUT_PKTRDY - There is a data packet ready in the OUT
- //! endpoint's FIFO.
- //! - \b USB_DEV_IN_NOT_COMP - A larger packet was split up, more data to come.
- //! - \b USB_DEV_IN_SENT_STALL - A stall was sent on this IN endpoint.
- //! - \b USB_DEV_IN_UNDERRUN - Data was requested on the IN endpoint and no
- //! data was ready.
- //! - \b USB_DEV_IN_FIFO_NE - The IN endpoint's FIFO is not empty.
- //! - \b USB_DEV_IN_PKTPEND - The data transfer on this IN endpoint has not
- //! completed.
- //! - \b USB_DEV_EP0_SETUP_END - A control transaction ended before Data End
- //! condition was sent.
- //! - \b USB_DEV_EP0_SENT_STALL - A stall was sent on endpoint zero.
- //! - \b USB_DEV_EP0_IN_PKTPEND - The data transfer on endpoint zero has not
- //! completed.
- //! - \b USB_DEV_EP0_OUT_PKTRDY - There is a data packet ready in endpoint
- //! zero's OUT FIFO.
- //!
- //! \return The current status flags for the endpoint depending on mode.
- //
- //*****************************************************************************
- unsigned long
- USBEndpointStatus(unsigned long ulBase, unsigned long ulEndpoint)
- {
- unsigned long ulStatus;
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- //
- // Get the TX portion of the endpoint status.
- //
- ulStatus = HWREGH(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TXCSRL1);
- //
- // Get the RX portion of the endpoint status.
- //
- ulStatus |= ((HWREGH(ulBase + EP_OFFSET(ulEndpoint) + USB_O_RXCSRL1)) <<
- USB_RX_EPSTATUS_SHIFT);
- //
- // Return the endpoint status.
- //
- return(ulStatus);
- }
- //*****************************************************************************
- //
- //! Clears the status bits in this endpoint in host mode.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //! \param ulFlags are the status bits that will be cleared.
- //!
- //! This function will clear the status of any bits that are passed in the
- //! \e ulFlags parameter. The \e ulFlags parameter can take the value returned
- //! from the USBEndpointStatus() call.
- //!
- //! \note This function should only be called in host mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBHostEndpointStatusClear(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long ulFlags)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- //
- // Clear the specified flags for the endpoint.
- //
- if(ulEndpoint == USB_EP_0)
- {
- HWREGB(ulBase + USB_O_CSRL0) &= ~ulFlags;
- }
- else
- {
- HWREGB(ulBase + USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint)) &= ~ulFlags;
- HWREGB(ulBase + USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint)) &=
- ~(ulFlags >> USB_RX_EPSTATUS_SHIFT);
- }
- }
- //*****************************************************************************
- //
- //! Clears the status bits in this endpoint in device mode.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //! \param ulFlags are the status bits that will be cleared.
- //!
- //! This function will clear the status of any bits that are passed in the
- //! \e ulFlags parameter. The \e ulFlags parameter can take the value returned
- //! from the USBEndpointStatus() call.
- //!
- //! \note This function should only be called in device mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBDevEndpointStatusClear(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long ulFlags)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- //
- // If this is endpoint 0 then the bits have different meaning and map into
- // the TX memory location.
- //
- if(ulEndpoint == USB_EP_0)
- {
- //
- // Set the Serviced RxPktRdy bit to clear the RxPktRdy.
- //
- if(ulFlags & USB_DEV_EP0_OUT_PKTRDY)
- {
- HWREGB(ulBase + USB_O_CSRL0) |= USB_CSRL0_RXRDYC;
- }
- //
- // Set the serviced Setup End bit to clear the SetupEnd status.
- //
- if(ulFlags & USB_DEV_EP0_SETUP_END)
- {
- HWREGB(ulBase + USB_O_CSRL0) |= USB_CSRL0_SETENDC;
- }
- //
- // Clear the Sent Stall status flag.
- //
- if(ulFlags & USB_DEV_EP0_SENT_STALL)
- {
- HWREGB(ulBase + USB_O_CSRL0) &= ~(USB_DEV_EP0_SENT_STALL);
- }
- }
- else
- {
- //
- // Clear out any TX flags that were passed in. Only
- // USB_DEV_TX_SENT_STALL and USB_DEV_TX_UNDERRUN should be cleared.
- //
- HWREGB(ulBase + USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint)) &=
- ~(ulFlags & (USB_DEV_TX_SENT_STALL | USB_DEV_TX_UNDERRUN));
- //
- // Clear out valid RX flags that were passed in. Only
- // USB_DEV_RX_SENT_STALL, USB_DEV_RX_DATA_ERROR, and USB_DEV_RX_OVERRUN
- // should be cleared.
- //
- HWREGB(ulBase + USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint)) &=
- ~((ulFlags & (USB_DEV_RX_SENT_STALL | USB_DEV_RX_DATA_ERROR |
- USB_DEV_RX_OVERRUN)) >> USB_RX_EPSTATUS_SHIFT);
- }
- }
- //*****************************************************************************
- //
- //! Sets the value data toggle on an endpoint in host mode.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint specifies the endpoint to reset the data toggle.
- //! \param bDataToggle specifies whether to set the state to DATA0 or DATA1.
- //! \param ulFlags specifies whether to set the IN or OUT endpoint.
- //!
- //! This function is used to force the state of the data toggle in host mode.
- //! If the value passed in the \e bDataToggle parameter is \b false, then the
- //! data toggle will be set to the DATA0 state, and if it is \b true it will be
- //! set to the DATA1 state. The \e ulFlags parameter can be \b USB_EP_HOST_IN
- //! or \b USB_EP_HOST_OUT to access the desired portion of this endpoint. The
- //! \e ulFlags parameter is ignored for endpoint zero.
- //!
- //! \note This function should only be called in host mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBHostEndpointDataToggle(unsigned long ulBase, unsigned long ulEndpoint,
- tBoolean bDataToggle, unsigned long ulFlags)
- {
- unsigned long ulDataToggle;
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- //
- // The data toggle defaults to DATA0.
- //
- ulDataToggle = 0;
- //
- // See if the data toggle should be set to DATA1.
- //
- if(bDataToggle)
- {
- //
- // Select the data toggle bit based on the endpoint.
- //
- if(ulEndpoint == USB_EP_0)
- {
- ulDataToggle = USB_CSRH0_DT;
- }
- else if(ulFlags == USB_EP_HOST_IN)
- {
- ulDataToggle = USB_RXCSRH1_DT;
- }
- else
- {
- ulDataToggle = USB_TXCSRH1_DT;
- }
- }
- //
- // Set the data toggle based on the endpoint.
- //
- if(ulEndpoint == USB_EP_0)
- {
- //
- // Set the write enable and the bit value for endpoint zero.
- //
- HWREGB(ulBase + USB_O_CSRH0) =
- ((HWREGB(ulBase + USB_O_CSRH0) &
- ~(USB_CSRH0_DTWE | USB_CSRH0_DT)) |
- (ulDataToggle | USB_CSRH0_DTWE));
- }
- else if(ulFlags == USB_EP_HOST_IN)
- {
- //
- // Set the Write enable and the bit value for an IN endpoint.
- //
- HWREGB(ulBase + USB_O_RXCSRH1 + EP_OFFSET(ulEndpoint)) =
- ((HWREGB(ulBase + USB_O_RXCSRH1 + EP_OFFSET(ulEndpoint)) &
- ~(USB_RXCSRH1_DTWE | USB_RXCSRH1_DT)) |
- (ulDataToggle | USB_RXCSRH1_DTWE));
- }
- else
- {
- //
- // Set the Write enable and the bit value for an OUT endpoint.
- //
- HWREGB(ulBase + USB_O_TXCSRH1 + EP_OFFSET(ulEndpoint)) =
- ((HWREGB(ulBase + USB_O_TXCSRH1 + EP_OFFSET(ulEndpoint)) &
- ~(USB_TXCSRH1_DTWE | USB_TXCSRH1_DT)) |
- (ulDataToggle | USB_TXCSRH1_DTWE));
- }
- }
- //*****************************************************************************
- //
- //! Sets the Data toggle on an endpoint to zero.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint specifies the endpoint to reset the data toggle.
- //! \param ulFlags specifies whether to access the IN or OUT endpoint.
- //!
- //! This function will cause the controller to clear the data toggle for an
- //! endpoint. This call is not valid for endpoint zero and can be made with
- //! host or device controllers.
- //!
- //! The \e ulFlags parameter should be one of \b USB_EP_HOST_OUT,
- //! \b USB_EP_HOST_IN, \b USB_EP_DEV_OUT, or \b USB_EP_DEV_IN.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBEndpointDataToggleClear(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long ulFlags)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_1) || (ulEndpoint == USB_EP_2) ||
- (ulEndpoint == USB_EP_3) || (ulEndpoint == USB_EP_4) ||
- (ulEndpoint == USB_EP_5) || (ulEndpoint == USB_EP_6) ||
- (ulEndpoint == USB_EP_7) || (ulEndpoint == USB_EP_8) ||
- (ulEndpoint == USB_EP_9) || (ulEndpoint == USB_EP_10) ||
- (ulEndpoint == USB_EP_11) || (ulEndpoint == USB_EP_12) ||
- (ulEndpoint == USB_EP_13) || (ulEndpoint == USB_EP_14) ||
- (ulEndpoint == USB_EP_15));
- //
- // See if the transmit or receive data toggle should be cleared.
- //
- if(ulFlags & (USB_EP_HOST_OUT | USB_EP_DEV_IN))
- {
- HWREGB(ulBase + USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint)) |=
- USB_TXCSRL1_CLRDT;
- }
- else
- {
- HWREGB(ulBase + USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint)) |=
- USB_RXCSRL1_CLRDT;
- }
- }
- //*****************************************************************************
- //
- //! Stalls the specified endpoint in device mode.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint specifies the endpoint to stall.
- //! \param ulFlags specifies whether to stall the IN or OUT endpoint.
- //!
- //! This function will cause to endpoint number passed in to go into a stall
- //! condition. If the \e ulFlags parameter is \b USB_EP_DEV_IN then the stall
- //! will be issued on the IN portion of this endpoint. If the \e ulFlags
- //! parameter is \b USB_EP_DEV_OUT then the stall will be issued on the OUT
- //! portion of this endpoint.
- //!
- //! \note This function should only be called in device mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBDevEndpointStall(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long ulFlags)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulFlags & ~(USB_EP_DEV_IN | USB_EP_DEV_OUT)) == 0)
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- //
- // Determine how to stall this endpoint.
- //
- if(ulEndpoint == USB_EP_0)
- {
- //
- // Perform a stall on endpoint zero.
- //
- HWREGB(ulBase + USB_O_CSRL0) |=
- (USB_CSRL0_STALL | USB_CSRL0_RXRDYC);
- }
- else if(ulFlags == USB_EP_DEV_IN)
- {
- //
- // Perform a stall on an IN endpoint.
- //
- HWREGB(ulBase + USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint)) |=
- USB_TXCSRL1_STALL;
- }
- else
- {
- //
- // Perform a stall on an OUT endpoint.
- //
- HWREGB(ulBase + USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint)) |=
- USB_RXCSRL1_STALL;
- }
- }
- //*****************************************************************************
- //
- //! Clears the stall condition on the specified endpoint in device mode.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint specifies which endpoint to remove the stall condition.
- //! \param ulFlags specifies whether to remove the stall condition from the IN
- //! or the OUT portion of this endpoint.
- //!
- //! This function will cause the endpoint number passed in to exit the stall
- //! condition. If the \e ulFlags parameter is \b USB_EP_DEV_IN then the stall
- //! will be cleared on the IN portion of this endpoint. If the \e ulFlags
- //! parameter is \b USB_EP_DEV_OUT then the stall will be cleared on the OUT
- //! portion of this endpoint.
- //!
- //! \note This function should only be called in device mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBDevEndpointStallClear(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long ulFlags)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- ASSERT((ulFlags & ~(USB_EP_DEV_IN | USB_EP_DEV_OUT)) == 0)
- //
- // Determine how to clear the stall on this endpoint.
- //
- if(ulEndpoint == USB_EP_0)
- {
- //
- // Clear the stall on endpoint zero.
- //
- HWREGB(ulBase + USB_O_CSRL0) &= ~USB_CSRL0_STALLED;
- }
- else if(ulFlags == USB_EP_DEV_IN)
- {
- //
- // Clear the stall on an IN endpoint.
- //
- HWREGB(ulBase + USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint)) &=
- ~(USB_TXCSRL1_STALL | USB_TXCSRL1_STALLED);
- //
- // Reset the data toggle.
- //
- HWREGB(ulBase + USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint)) |=
- USB_TXCSRL1_CLRDT;
- }
- else
- {
- //
- // Clear the stall on an OUT endpoint.
- //
- HWREGB(ulBase + USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint)) &=
- ~(USB_RXCSRL1_STALL | USB_RXCSRL1_STALLED);
- //
- // Reset the data toggle.
- //
- HWREGB(ulBase + USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint)) |=
- USB_TXCSRL1_CLRDT;
- }
- }
- //*****************************************************************************
- //
- //! Connects the USB controller to the bus in device mode.
- //!
- //! \param ulBase specifies the USB module base address.
- //!
- //! This function will cause the soft connect feature of the USB controller to
- //! be enabled. Call USBDisconnect() to remove the USB device from the bus.
- //!
- //! \note This function should only be called in device mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBDevConnect(unsigned long ulBase)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- //
- // Enable connection to the USB bus.
- //
- HWREGB(ulBase + USB_O_POWER) |= USB_POWER_SOFTCONN;
- }
- //*****************************************************************************
- //
- //! Removes the USB controller from the bus in device mode.
- //!
- //! \param ulBase specifies the USB module base address.
- //!
- //! This function will cause the soft connect feature of the USB controller to
- //! remove the device from the USB bus. A call to USBDevConnect() is needed to
- //! reconnect to the bus.
- //!
- //! \note This function should only be called in device mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBDevDisconnect(unsigned long ulBase)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- //
- // Disable connection to the USB bus.
- //
- HWREGB(ulBase + USB_O_POWER) &= (~USB_POWER_SOFTCONN);
- }
- //*****************************************************************************
- //
- //! Sets the address in device mode.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulAddress is the address to use for a device.
- //!
- //! This function will set the device address on the USB bus. This address was
- //! likely received via a SET ADDRESS command from the host controller.
- //!
- //! \note This function should only be called in device mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBDevAddrSet(unsigned long ulBase, unsigned long ulAddress)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- //
- // Set the function address in the correct location.
- //
- HWREGB(ulBase + USB_O_FADDR) = (unsigned char)ulAddress;
- }
- //*****************************************************************************
- //
- //! Returns the current device address in device mode.
- //!
- //! \param ulBase specifies the USB module base address.
- //!
- //! This function will return the current device address. This address was set
- //! by a call to USBDevAddrSet().
- //!
- //! \note This function should only be called in device mode.
- //!
- //! \return The current device address.
- //
- //*****************************************************************************
- unsigned long
- USBDevAddrGet(unsigned long ulBase)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- //
- // Return the function address.
- //
- return(HWREGB(ulBase + USB_O_FADDR));
- }
- //*****************************************************************************
- //
- //! Sets the base configuration for a host endpoint.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //! \param ulMaxPayload is the maximum payload for this endpoint.
- //! \param ulNAKPollInterval is the either the NAK timeout limit or the polling
- //! interval depending on the type of endpoint.
- //! \param ulTargetEndpoint is the endpoint that the host endpoint is
- //! targeting.
- //! \param ulFlags are used to configure other endpoint settings.
- //!
- //! This function will set the basic configuration for the transmit or receive
- //! portion of an endpoint in host mode. The \e ulFlags parameter determines
- //! some of the configuration while the other parameters provide the rest. The
- //! \e ulFlags parameter determines whether this is an IN endpoint
- //! (USB_EP_HOST_IN or USB_EP_DEV_IN) or an OUT endpoint (USB_EP_HOST_OUT or
- //! USB_EP_DEV_OUT), whether this is a Full speed endpoint (USB_EP_SPEED_FULL)
- //! or a Low speed endpoint (USB_EP_SPEED_LOW).
- //!
- //! The \b USB_EP_MODE_ flags control the type of the endpoint.
- //! - \b USB_EP_MODE_CTRL is a control endpoint.
- //! - \b USB_EP_MODE_ISOC is an isochronous endpoint.
- //! - \b USB_EP_MODE_BULK is a bulk endpoint.
- //! - \b USB_EP_MODE_INT is an interrupt endpoint.
- //!
- //! The \e ulNAKPollInterval parameter has different meanings based on the
- //! \b USB_EP_MODE value and whether or not this call is being made for
- //! endpoint zero or another endpoint. For endpoint zero or any Bulk
- //! endpoints, this value always indicates the number of frames to allow a
- //! device to NAK before considering it a timeout. If this endpoint is an
- //! isochronous or interrupt endpoint, this value is the polling interval for
- //! this endpoint.
- //!
- //! For interrupt endpoints the polling interval is simply the number of
- //! frames between polling an interrupt endpoint. For isochronous endpoints
- //! this value represents a polling interval of 2 ^ (\e ulNAKPollInterval - 1)
- //! frames. When used as a NAK timeout, the \e ulNAKPollInterval value
- //! specifies 2 ^ (\e ulNAKPollInterval - 1) frames before issuing a time out.
- //! There are two special time out values that can be specified when setting
- //! the \e ulNAKPollInterval value. The first is \b MAX_NAK_LIMIT which is the
- //! maximum value that can be passed in this variable. The other is
- //! \b DISABLE_NAK_LIMIT which indicates that there should be no limit on the
- //! number of NAKs.
- //!
- //! The \b USB_EP_DMA_MODE_ flags enables the type of DMA used to access the
- //! endpoint's data FIFOs. The choice of the DMA mode depends on how the DMA
- //! controller is configured and how it is being used. See the ``Using USB
- //! with the uDMA Controller'' section for more information on DMA
- //! configuration.
- //!
- //! When configuring the OUT portion of an endpoint, the \b USB_EP_AUTO_SET bit
- //! is specified to cause the transmission of data on the USB bus to start
- //! as soon as the number of bytes specified by \e ulMaxPayload have been
- //! written into the OUT FIFO for this endpoint.
- //!
- //! When configuring the IN portion of an endpoint, the \b USB_EP_AUTO_REQUEST
- //! bit can be specified to trigger the request for more data once the FIFO has
- //! been drained enough to fit \e ulMaxPayload bytes. The \b USB_EP_AUTO_CLEAR
- //! bit can be used to clear the data packet ready flag automatically once the
- //! data has been read from the FIFO. If this is not used, this flag must be
- //! manually cleared via a call to USBDevEndpointStatusClear() or
- //! USBHostEndpointStatusClear().
- //!
- //! \note This function should only be called in host mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBHostEndpointConfig(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long ulMaxPayload,
- unsigned long ulNAKPollInterval,
- unsigned long ulTargetEndpoint, unsigned long ulFlags)
- {
- unsigned long ulRegister;
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- ASSERT(ulNAKPollInterval <= MAX_NAK_LIMIT);
- //
- // Endpoint zero is configured differently than the other endpoints, so see
- // if this is endpoint zero.
- //
- if(ulEndpoint == USB_EP_0)
- {
- //
- // Set the NAK timeout.
- //
- HWREGB(ulBase + USB_O_NAKLMT) = ulNAKPollInterval;
- //
- // Set the transfer type information.
- //
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TYPE0) =
- ((ulFlags & USB_EP_SPEED_FULL) ? USB_TYPE0_SPEED_FULL :
- USB_TYPE0_SPEED_LOW);
- }
- else
- {
- //
- // Start with the target endpoint.
- //
- ulRegister = ulTargetEndpoint;
- //
- // Set the speed for the device using this endpoint.
- //
- if(ulFlags & USB_EP_SPEED_FULL)
- {
- ulRegister |= USB_TXTYPE1_SPEED_FULL;
- }
- else
- {
- ulRegister |= USB_TXTYPE1_SPEED_LOW;
- }
- //
- // Set the protocol for the device using this endpoint.
- //
- switch(ulFlags & USB_EP_MODE_MASK)
- {
- //
- // The bulk protocol is being used.
- //
- case USB_EP_MODE_BULK:
- {
- ulRegister |= USB_TXTYPE1_PROTO_BULK;
- break;
- }
- //
- // The isochronous protocol is being used.
- //
- case USB_EP_MODE_ISOC:
- {
- ulRegister |= USB_TXTYPE1_PROTO_ISOC;
- break;
- }
- //
- // The interrupt protocol is being used.
- //
- case USB_EP_MODE_INT:
- {
- ulRegister |= USB_TXTYPE1_PROTO_INT;
- break;
- }
- //
- // The control protocol is being used.
- //
- case USB_EP_MODE_CTRL:
- {
- ulRegister |= USB_TXTYPE1_PROTO_CTRL;
- break;
- }
- }
- //
- // See if the transmit or receive endpoint is being configured.
- //
- if(ulFlags & USB_EP_HOST_OUT)
- {
- //
- // Set the transfer type information.
- //
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TXTYPE1) =
- ulRegister;
- //
- // Set the NAK timeout or polling interval.
- //
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TXINTERVAL1) =
- ulNAKPollInterval;
- //
- // Set the Maximum Payload per transaction.
- //
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TXMAXP1) =
- ulMaxPayload;
- //
- // Set the transmit control value to zero.
- //
- ulRegister = 0;
- //
- // Allow auto setting of TxPktRdy when max packet size has been
- // loaded into the FIFO.
- //
- if(ulFlags & USB_EP_AUTO_SET)
- {
- ulRegister |= USB_TXCSRH1_AUTOSET;
- }
- //
- // Configure the DMA Mode.
- //
- if(ulFlags & USB_EP_DMA_MODE_1)
- {
- ulRegister |= USB_TXCSRH1_DMAEN | USB_TXCSRH1_DMAMOD;
- }
- else if(ulFlags & USB_EP_DMA_MODE_0)
- {
- ulRegister |= USB_TXCSRH1_DMAEN;
- }
- //
- // Write out the transmit control value.
- //
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TXCSRH1) =
- (unsigned char)ulRegister;
- }
- else
- {
- //
- // Set the transfer type information.
- //
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_RXTYPE1) =
- ulRegister;
- //
- // Set the NAK timeout or polling interval.
- //
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_RXINTERVAL1) =
- ulNAKPollInterval;
- //
- // Set the receive control value to zero.
- //
- ulRegister = 0;
- //
- // Allow auto clearing of RxPktRdy when packet of size max packet
- // has been unloaded from the FIFO.
- //
- if(ulFlags & USB_EP_AUTO_CLEAR)
- {
- ulRegister |= USB_RXCSRH1_AUTOCL;
- }
- //
- // Configure the DMA Mode.
- //
- if(ulFlags & USB_EP_DMA_MODE_1)
- {
- ulRegister |= USB_RXCSRH1_DMAEN | USB_RXCSRH1_DMAMOD;
- }
- else if(ulFlags & USB_EP_DMA_MODE_0)
- {
- ulRegister |= USB_RXCSRH1_DMAEN;
- }
- //
- // Write out the receive control value.
- //
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_RXCSRH1) =
- (unsigned char)ulRegister;
- }
- }
- }
- //*****************************************************************************
- //
- //! Sets the configuration for an endpoint.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //! \param ulMaxPacketSize is the maximum packet size for this endpoint.
- //! \param ulFlags are used to configure other endpoint settings.
- //!
- //! This function will set the basic configuration for an endpoint in device
- //! mode. Endpoint zero does not have a dynamic configuration, so this
- //! function should not be called for endpoint zero. The \e ulFlags parameter
- //! determines some of the configuration while the other parameters provide the
- //! rest.
- //!
- //! The \b USB_EP_MODE_ flags define what the type is for the given endpoint.
- //!
- //! - \b USB_EP_MODE_CTRL is a control endpoint.
- //! - \b USB_EP_MODE_ISOC is an isochronous endpoint.
- //! - \b USB_EP_MODE_BULK is a bulk endpoint.
- //! - \b USB_EP_MODE_INT is an interrupt endpoint.
- //!
- //! The \b USB_EP_DMA_MODE_ flags determines the type of DMA access to the
- //! endpoint data FIFOs. The choice of the DMA mode depends on how the DMA
- //! controller is configured and how it is being used. See the ``Using USB
- //! with the uDMA Controller'' section for more information on DMA
- //! configuration.
- //!
- //! When configuring an IN endpoint, the \b USB_EP_AUTO_SET bit can be
- //! specified to cause the automatic transmission of data on the USB bus as
- //! soon as \e ulMaxPacketSize bytes of data are written into the FIFO for
- //! this endpoint. This is commonly used with DMA as no interaction is
- //! required to start the transmission of data.
- //!
- //! When configuring an OUT endpoint, the \b USB_EP_AUTO_REQUEST bit is
- //! specified to trigger the request for more data once the FIFO has been
- //! drained enough to receive \e ulMaxPacketSize more bytes of data. Also for
- //! OUT endpoints, the \b USB_EP_AUTO_CLEAR bit can be used to clear the data
- //! packet ready flag automatically once the data has been read from the FIFO.
- //! If this is not used, this flag must be manually cleared via a call to
- //! USBDevEndpointStatusClear(). Both of these settings can be used to remove
- //! the need for extra calls when using the controller in DMA mode.
- //!
- //! \note This function should only be called in device mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBDevEndpointConfig(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long ulMaxPacketSize, unsigned long ulFlags)
- {
- unsigned long ulRegister;
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_1) || (ulEndpoint == USB_EP_2) ||
- (ulEndpoint == USB_EP_3) || (ulEndpoint == USB_EP_4) ||
- (ulEndpoint == USB_EP_5) || (ulEndpoint == USB_EP_6) ||
- (ulEndpoint == USB_EP_7) || (ulEndpoint == USB_EP_8) ||
- (ulEndpoint == USB_EP_9) || (ulEndpoint == USB_EP_10) ||
- (ulEndpoint == USB_EP_11) || (ulEndpoint == USB_EP_12) ||
- (ulEndpoint == USB_EP_13) || (ulEndpoint == USB_EP_14) ||
- (ulEndpoint == USB_EP_15));
- //
- // Determine if a transmit or receive endpoint is being configured.
- //
- if(ulFlags & USB_EP_DEV_IN)
- {
- //
- // Set the maximum packet size.
- //
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TXMAXP1) =
- ulMaxPacketSize;
- //
- // The transmit control value is zero unless options are enabled.
- //
- ulRegister = 0;
- //
- // Allow auto setting of TxPktRdy when max packet size has been loaded
- // into the FIFO.
- //
- if(ulFlags & USB_EP_AUTO_SET)
- {
- ulRegister |= USB_TXCSRH1_AUTOSET;
- }
- //
- // Configure the DMA mode.
- //
- if(ulFlags & USB_EP_DMA_MODE_1)
- {
- ulRegister |= USB_TXCSRH1_DMAEN | USB_TXCSRH1_DMAMOD;
- }
- else if(ulFlags & USB_EP_DMA_MODE_0)
- {
- ulRegister |= USB_TXCSRH1_DMAEN;
- }
- //
- // Enable isochronous mode if requested.
- //
- if((ulFlags & USB_EP_MODE_MASK) == USB_EP_MODE_ISOC)
- {
- ulRegister |= USB_TXCSRH1_ISO;
- }
- //
- // Write the transmit control value.
- //
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TXCSRH1) =
- (unsigned char)ulRegister;
- //
- // Reset the Data toggle to zero.
- //
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TXCSRL1) =
- USB_TXCSRL1_CLRDT;
- }
- else
- {
- //
- // Set the MaxPacketSize.
- //
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_RXMAXP1) =
- ulMaxPacketSize;
- //
- // The receive control value is zero unless options are enabled.
- //
- ulRegister = 0;
- //
- // Allow auto clearing of RxPktRdy when packet of size max packet
- // has been unloaded from the FIFO.
- //
- if(ulFlags & USB_EP_AUTO_CLEAR)
- {
- ulRegister = USB_RXCSRH1_AUTOCL;
- }
- //
- // Configure the DMA mode.
- //
- if(ulFlags & USB_EP_DMA_MODE_1)
- {
- ulRegister |= USB_RXCSRH1_DMAEN | USB_RXCSRH1_DMAMOD;
- }
- else if(ulFlags & USB_EP_DMA_MODE_0)
- {
- ulRegister |= USB_RXCSRH1_DMAEN;
- }
- //
- // Enable isochronous mode if requested.
- //
- if(USB_EP_MODE_ISOC & (ulFlags & USB_EP_MODE_MASK))
- {
- ulRegister |= USB_RXCSRH1_ISO;
- }
- //
- // Write the receive control value.
- //
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_RXCSRH1) =
- (unsigned char)ulRegister;
- //
- // Reset the Data toggle to zero.
- //
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_RXCSRL1) =
- USB_RXCSRL1_CLRDT;
- }
- }
- //*****************************************************************************
- //
- //! Gets the current configuration for an endpoint.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //! \param pulMaxPacketSize is a pointer which will be written with the
- //! maximum packet size for this endpoint.
- //! \param pulFlags is a pointer which will be written with the current
- //! endpoint settings. On entry to the function, this pointer must contain
- //! either \b USB_EP_DEV_IN or \b USB_EP_DEV_OUT to indicate whether the IN or
- //! OUT endpoint is to be queried.
- //!
- //! This function will return the basic configuration for an endpoint in device
- //! mode. The values returned in \e *pulMaxPacketSize and \e *pulFlags are
- //! equivalent to the \e ulMaxPacketSize and \e ulFlags previously passed to
- //! USBDevEndpointConfig for this endpoint.
- //!
- //! \note This function should only be called in device mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBDevEndpointConfigGet(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long *pulMaxPacketSize,
- unsigned long *pulFlags)
- {
- unsigned long ulRegister;
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT(pulMaxPacketSize && pulFlags);
- ASSERT((ulEndpoint == USB_EP_1) || (ulEndpoint == USB_EP_2) ||
- (ulEndpoint == USB_EP_3) || (ulEndpoint == USB_EP_4) ||
- (ulEndpoint == USB_EP_5) || (ulEndpoint == USB_EP_6) ||
- (ulEndpoint == USB_EP_7) || (ulEndpoint == USB_EP_8) ||
- (ulEndpoint == USB_EP_9) || (ulEndpoint == USB_EP_10) ||
- (ulEndpoint == USB_EP_11) || (ulEndpoint == USB_EP_12) ||
- (ulEndpoint == USB_EP_13) || (ulEndpoint == USB_EP_14) ||
- (ulEndpoint == USB_EP_15));
- //
- // Determine if a transmit or receive endpoint is being queried.
- //
- if(*pulFlags & USB_EP_DEV_IN)
- {
- //
- // Clear the flags other than the direction bit.
- //
- *pulFlags = USB_EP_DEV_IN;
- //
- // Get the maximum packet size.
- //
- *pulMaxPacketSize = (unsigned long)HWREGB(ulBase +
- EP_OFFSET(ulEndpoint) +
- USB_O_TXMAXP1);
- //
- // Get the current transmit control register value.
- //
- ulRegister = (unsigned long)HWREGB(ulBase + EP_OFFSET(ulEndpoint) +
- USB_O_TXCSRH1);
- //
- // Are we allowing auto setting of TxPktRdy when max packet size has
- // been loaded into the FIFO?
- //
- if(ulRegister & USB_TXCSRH1_AUTOSET)
- {
- *pulFlags |= USB_EP_AUTO_SET;
- }
- //
- // Get the DMA mode.
- //
- if(ulRegister & USB_TXCSRH1_DMAEN)
- {
- if(ulRegister & USB_TXCSRH1_DMAMOD)
- {
- *pulFlags |= USB_EP_DMA_MODE_1;
- }
- else
- {
- *pulFlags |= USB_EP_DMA_MODE_0;
- }
- }
- //
- // Are we in isochronous mode?
- //
- if(ulRegister & USB_TXCSRH1_ISO)
- {
- *pulFlags |= USB_EP_MODE_ISOC;
- }
- else
- {
- //
- // The hardware doesn't differentiate between bulk, interrupt
- // and control mode for the endpoint so we just set something
- // that isn't isochronous. This ensures that anyone modifying
- // the returned flags in preparation for a call to
- // USBDevEndpointConfig will not see an unexpected mode change.
- // If they decode the returned mode, however, they may be in for
- // a surprise.
- //
- *pulFlags |= USB_EP_MODE_BULK;
- }
- }
- else
- {
- //
- // Clear the flags other than the direction bit.
- //
- *pulFlags = USB_EP_DEV_OUT;
- //
- // Get the MaxPacketSize.
- //
- *pulMaxPacketSize = (unsigned long)HWREGB(ulBase +
- EP_OFFSET(ulEndpoint) +
- USB_O_RXMAXP1);
- //
- // Get the current receive control register value.
- //
- ulRegister = (unsigned long)HWREGB(ulBase + EP_OFFSET(ulEndpoint) +
- USB_O_RXCSRH1);
- //
- // Are we allowing auto clearing of RxPktRdy when packet of size max
- // packet has been unloaded from the FIFO?
- //
- if(ulRegister & USB_RXCSRH1_AUTOCL)
- {
- *pulFlags |= USB_EP_AUTO_CLEAR;
- }
- //
- // Get the DMA mode.
- //
- if(ulRegister & USB_RXCSRH1_DMAEN)
- {
- if(ulRegister & USB_RXCSRH1_DMAMOD)
- {
- *pulFlags |= USB_EP_DMA_MODE_1;
- }
- else
- {
- *pulFlags |= USB_EP_DMA_MODE_0;
- }
- }
- //
- // Are we in isochronous mode?
- //
- if(ulRegister & USB_RXCSRH1_ISO)
- {
- *pulFlags |= USB_EP_MODE_ISOC;
- }
- else
- {
- //
- // The hardware doesn't differentiate between bulk, interrupt
- // and control mode for the endpoint so we just set something
- // that isn't isochronous. This ensures that anyone modifying
- // the returned flags in preparation for a call to
- // USBDevEndpointConfig will not see an unexpected mode change.
- // If they decode the returned mode, however, they may be in for
- // a surprise.
- //
- *pulFlags |= USB_EP_MODE_BULK;
- }
- }
- }
- //*****************************************************************************
- //
- //! Sets the FIFO configuration for an endpoint.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //! \param ulFIFOAddress is the starting address for the FIFO.
- //! \param ulFIFOSize is the size of the FIFO in bytes.
- //! \param ulFlags specifies what information to set in the FIFO configuration.
- //!
- //! This function will set the starting FIFO RAM address and size of the FIFO
- //! for a given endpoint. Endpoint zero does not have a dynamically
- //! configurable FIFO so this function should not be called for endpoint zero.
- //! The \e ulFIFOSize parameter should be one of the values in the
- //! \b USB_FIFO_SZ_ values. If the endpoint is going to use double buffering
- //! it should use the values with the \b _DB at the end of the value. For
- //! example, use \b USB_FIFO_SZ_16_DB to configure an endpoint to have a 16
- //! byte double buffered FIFO. If a double buffered FIFO is used, then the
- //! actual size of the FIFO will be twice the size indicated by the
- //! \e ulFIFOSize parameter. This means that the \b USB_FIFO_SZ_16_DB value
- //! will use 32 bytes of the USB controller's FIFO memory.
- //!
- //! The \e ulFIFOAddress value should be a multiple of 8 bytes and directly
- //! indicates the starting address in the USB controller's FIFO RAM. For
- //! example, a value of 64 indicates that the FIFO should start 64 bytes into
- //! the USB controller's FIFO memory. The \e ulFlags value specifies whether
- //! the endpoint's OUT or IN FIFO should be configured. If in host mode, use
- //! \b USB_EP_HOST_OUT or \b USB_EP_HOST_IN, and if in device mode use
- //! \b USB_EP_DEV_OUT or \b USB_EP_DEV_IN.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBFIFOConfigSet(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long ulFIFOAddress, unsigned long ulFIFOSize,
- unsigned long ulFlags)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_1) || (ulEndpoint == USB_EP_2) ||
- (ulEndpoint == USB_EP_3) || (ulEndpoint == USB_EP_4) ||
- (ulEndpoint == USB_EP_5) || (ulEndpoint == USB_EP_6) ||
- (ulEndpoint == USB_EP_7) || (ulEndpoint == USB_EP_8) ||
- (ulEndpoint == USB_EP_9) || (ulEndpoint == USB_EP_10) ||
- (ulEndpoint == USB_EP_11) || (ulEndpoint == USB_EP_12) ||
- (ulEndpoint == USB_EP_13) || (ulEndpoint == USB_EP_14) ||
- (ulEndpoint == USB_EP_15));
- //
- // See if the transmit or receive FIFO is being configured.
- //
- if(ulFlags & (USB_EP_HOST_OUT | USB_EP_DEV_IN))
- {
- //
- // Set the transmit FIFO location and size for this endpoint.
- //
- USBIndexWrite(ulBase, ulEndpoint >> 4, USB_O_TXFIFOSZ, ulFIFOSize, 1);
- USBIndexWrite(ulBase, ulEndpoint >> 4, USB_O_TXFIFOADD,
- ulFIFOAddress >> 3, 2);
- }
- else
- {
- //
- // Set the receive FIFO location and size for this endpoint.
- //
- USBIndexWrite(ulBase, ulEndpoint >> 4, USB_O_RXFIFOSZ, ulFIFOSize, 1);
- USBIndexWrite(ulBase, ulEndpoint >> 4, USB_O_RXFIFOADD,
- ulFIFOAddress >> 3, 2);
- }
- }
- //*****************************************************************************
- //
- //! Returns the FIFO configuration for an endpoint.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //! \param pulFIFOAddress is the starting address for the FIFO.
- //! \param pulFIFOSize is the size of the FIFO in bytes.
- //! \param ulFlags specifies what information to retrieve from the FIFO
- //! configuration.
- //!
- //! This function will return the starting address and size of the FIFO for a
- //! given endpoint. Endpoint zero does not have a dynamically configurable
- //! FIFO so this function should not be called for endpoint zero. The
- //! \e ulFlags parameter specifies whether the endpoint's OUT or IN FIFO should
- //! be read. If in host mode, the \e ulFlags parameter should be
- //! \b USB_EP_HOST_OUT or \b USB_EP_HOST_IN, and if in device mode the
- //! \e ulFlags parameter should be either \b USB_EP_DEV_OUT or
- //! \b USB_EP_DEV_IN.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBFIFOConfigGet(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long *pulFIFOAddress, unsigned long *pulFIFOSize,
- unsigned long ulFlags)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_1) || (ulEndpoint == USB_EP_2) ||
- (ulEndpoint == USB_EP_3) || (ulEndpoint == USB_EP_4) ||
- (ulEndpoint == USB_EP_5) || (ulEndpoint == USB_EP_6) ||
- (ulEndpoint == USB_EP_7) || (ulEndpoint == USB_EP_8) ||
- (ulEndpoint == USB_EP_9) || (ulEndpoint == USB_EP_10) ||
- (ulEndpoint == USB_EP_11) || (ulEndpoint == USB_EP_12) ||
- (ulEndpoint == USB_EP_13) || (ulEndpoint == USB_EP_14) ||
- (ulEndpoint == USB_EP_15));
- //
- // See if the transmit or receive FIFO is being configured.
- //
- if(ulFlags & (USB_EP_HOST_OUT | USB_EP_DEV_IN))
- {
- //
- // Get the transmit FIFO location and size for this endpoint.
- //
- *pulFIFOAddress = (USBIndexRead(ulBase, ulEndpoint >> 4,
- (unsigned long)USB_O_TXFIFOADD,
- 2)) << 3;
- *pulFIFOSize = USBIndexRead(ulBase, ulEndpoint >> 4,
- (unsigned long)USB_O_TXFIFOSZ, 1);
- }
- else
- {
- //
- // Get the receive FIFO location and size for this endpoint.
- //
- *pulFIFOAddress = (USBIndexRead(ulBase, ulEndpoint >> 4,
- (unsigned long)USB_O_RXFIFOADD,
- 2)) << 3;
- *pulFIFOSize = USBIndexRead(ulBase, ulEndpoint >> 4,
- (unsigned long)USB_O_RXFIFOSZ, 1);
- }
- }
- //*****************************************************************************
- //
- //! Enable DMA on a given endpoint.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //! \param ulFlags specifies which direction and what mode to use when enabling
- //! DMA.
- //!
- //! This function will enable DMA on a given endpoint and set the mode according
- //! to the values in the \e ulFlags parameter. The \e ulFlags parameter should
- //! have \b USB_EP_DEV_IN or \b USB_EP_DEV_OUT set.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBEndpointDMAEnable(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long ulFlags)
- {
- //
- // See if the transmit DMA is being enabled.
- //
- if(ulFlags & USB_EP_DEV_IN)
- {
- //
- // Enable DMA on this end point.
- //
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TXCSRH1) |=
- USB_TXCSRH1_DMAEN;
- }
- //
- // See if the receive DMA is being enabled.
- //
- if(ulFlags & USB_EP_DEV_OUT)
- {
- //
- // Enable DMA on this end point.
- //
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_RXCSRH1) |=
- USB_RXCSRH1_DMAEN;
- }
- }
- //*****************************************************************************
- //
- //! Disable DMA on a given endpoint.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //! \param ulFlags specifies which direction to disable.
- //!
- //! This function will disable DMA on a given end point to allow non-DMA
- //! USB transactions to generate interrupts normally. The ulFlags should be
- //! \b USB_EP_DEV_IN or \b USB_EP_DEV_OUT all other bits are ignored.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBEndpointDMADisable(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long ulFlags)
- {
- //
- // If this was a reques to disable DMA on the IN portion of the end point
- // then handle it.
- //
- if(ulFlags & USB_EP_DEV_IN)
- {
- //
- // Just disable DMA leave the mode setting.
- //
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TXCSRH1) &=
- ~USB_TXCSRH1_DMAEN;
- }
- //
- // If this was a request to disable DMA on the OUT portion of the end point
- // then handle it.
- //
- if(ulFlags & USB_EP_DEV_OUT)
- {
- //
- // Just disable DMA leave the mode setting.
- //
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_RXCSRH1) &=
- ~USB_RXCSRH1_DMAEN;
- }
- }
- //*****************************************************************************
- //
- //! Determine the number of bytes of data available in a given endpoint's FIFO.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //!
- //! This function will return the number of bytes of data currently available
- //! in the FIFO for the given receive (OUT) endpoint. It may be used prior to
- //! calling USBEndpointDataGet() to determine the size of buffer required to
- //! hold the newly-received packet.
- //!
- //! \return This call will return the number of bytes available in a given
- //! endpoint FIFO.
- //
- //*****************************************************************************
- unsigned long
- USBEndpointDataAvail(unsigned long ulBase, unsigned long ulEndpoint)
- {
- unsigned long ulRegister;
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- //
- // Get the address of the receive status register to use, based on the
- // endpoint.
- //
- if(ulEndpoint == USB_EP_0)
- {
- ulRegister = USB_O_CSRL0;
- }
- else
- {
- ulRegister = USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint);
- }
- //
- // Is there a packet ready in the FIFO?
- //
- if((HWREGH(ulBase + ulRegister) & USB_CSRL0_RXRDY) == 0)
- {
- return(0);
- }
- //
- // Return the byte count in the FIFO.
- //
- return(HWREGH(ulBase + USB_O_COUNT0 + ulEndpoint));
- }
- //*****************************************************************************
- //
- //! Retrieves data from the given endpoint's FIFO.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //! \param pucData is a pointer to the data area used to return the data from
- //! the FIFO.
- //! \param pulSize is initially the size of the buffer passed into this call
- //! via the \e pucData parameter. It will be set to the amount of data
- //! returned in the buffer.
- //!
- //! This function will return the data from the FIFO for the given endpoint.
- //! The \e pulSize parameter should indicate the size of the buffer passed in
- //! the \e pulData parameter. The data in the \e pulSize parameter will be
- //! changed to match the amount of data returned in the \e pucData parameter.
- //! If a zero byte packet was received this call will not return a error but
- //! will instead just return a zero in the \e pulSize parameter. The only
- //! error case occurs when there is no data packet available.
- //!
- //! \return This call will return 0, or -1 if no packet was received.
- //
- //*****************************************************************************
- long
- USBEndpointDataGet(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned char *pucData, unsigned long *pulSize)
- {
- unsigned long ulRegister, ulByteCount, ulFIFO;
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- //
- // Get the address of the receive status register to use, based on the
- // endpoint.
- //
- if(ulEndpoint == USB_EP_0)
- {
- ulRegister = USB_O_CSRL0;
- }
- else
- {
- ulRegister = USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint);
- }
- //
- // Don't allow reading of data if the RxPktRdy bit is not set.
- //
- if((HWREGH(ulBase + ulRegister) & USB_CSRL0_RXRDY) == 0)
- {
- //
- // Can't read the data because none is available.
- //
- *pulSize = 0;
- //
- // Return a failure since there is no data to read.
- //
- return(-1);
- }
- //
- // Get the byte count in the FIFO.
- //
- ulByteCount = HWREGH(ulBase + USB_O_COUNT0 + ulEndpoint);
- //
- // Determine how many bytes we will actually copy.
- //
- ulByteCount = (ulByteCount < *pulSize) ? ulByteCount : *pulSize;
- //
- // Return the number of bytes we are going to read.
- //
- *pulSize = ulByteCount;
- //
- // Calculate the FIFO address.
- //
- ulFIFO = ulBase + USB_O_FIFO0 + (ulEndpoint >> 2);
- //
- // Read the data out of the FIFO.
- //
- for(; ulByteCount > 0; ulByteCount--)
- {
- //
- // Read a byte at a time from the FIFO.
- //
- *pucData++ = HWREGB(ulFIFO);
- }
- //
- // Success.
- //
- return(0);
- }
- //*****************************************************************************
- //
- //! Acknowledge that data was read from the given endpoint's FIFO in device
- //! mode.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //! \param bIsLastPacket indicates if this is the last packet.
- //!
- //! This function acknowledges that the data was read from the endpoint's FIFO.
- //! The \e bIsLastPacket parameter is set to a \b true value if this is the
- //! last in a series of data packets on endpoint zero. The \e bIsLastPacket
- //! parameter is not used for endpoints other than endpoint zero. This call
- //! can be used if processing is required between reading the data and
- //! acknowledging that the data has been read.
- //!
- //! \note This function should only be called in device mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBDevEndpointDataAck(unsigned long ulBase, unsigned long ulEndpoint,
- tBoolean bIsLastPacket)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- //
- // Determine which endpoint is being acked.
- //
- if(ulEndpoint == USB_EP_0)
- {
- //
- // Clear RxPktRdy, and optionally DataEnd, on endpoint zero.
- //
- HWREGB(ulBase + USB_O_CSRL0) =
- USB_CSRL0_RXRDYC | (bIsLastPacket ? USB_CSRL0_DATAEND : 0);
- }
- else
- {
- //
- // Clear RxPktRdy on all other endpoints.
- //
- HWREGB(ulBase + USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint)) &=
- ~(USB_RXCSRL1_RXRDY);
- }
- }
- //*****************************************************************************
- //
- //! Acknowledge that data was read from the given endpoint's FIFO in host
- //! mode.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //!
- //! This function acknowledges that the data was read from the endpoint's FIFO.
- //! This call is used if processing is required between reading the data and
- //! acknowledging that the data has been read.
- //!
- //! \note This function should only be called in host mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBHostEndpointDataAck(unsigned long ulBase, unsigned long ulEndpoint)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- //
- // Clear RxPktRdy.
- //
- if(ulEndpoint == USB_EP_0)
- {
- HWREGB(ulBase + USB_O_CSRL0) &= ~USB_CSRL0_RXRDY;
- }
- else
- {
- HWREGB(ulBase + USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint)) &=
- ~(USB_RXCSRL1_RXRDY);
- }
- }
- //*****************************************************************************
- //
- //! Puts data into the given endpoint's FIFO.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //! \param pucData is a pointer to the data area used as the source for the
- //! data to put into the FIFO.
- //! \param ulSize is the amount of data to put into the FIFO.
- //!
- //! This function will put the data from the \e pucData parameter into the FIFO
- //! for this endpoint. If a packet is already pending for transmission then
- //! this call will not put any of the data into the FIFO and will return -1.
- //! Care should be taken to not write more data than can fit into the FIFO
- //! allocated by the call to USBFIFOConfig().
- //!
- //! \return This call will return 0 on success, or -1 to indicate that the FIFO
- //! is in use and cannot be written.
- //
- //*****************************************************************************
- long
- USBEndpointDataPut(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned char *pucData, unsigned long ulSize)
- {
- unsigned long ulFIFO;
- unsigned char ucTxPktRdy;
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- //
- // Get the bit position of TxPktRdy based on the endpoint.
- //
- if(ulEndpoint == USB_EP_0)
- {
- ucTxPktRdy = USB_CSRL0_TXRDY;
- }
- else
- {
- ucTxPktRdy = USB_TXCSRL1_TXRDY;
- }
- //
- // Don't allow transmit of data if the TxPktRdy bit is already set.
- //
- if(HWREGB(ulBase + USB_O_CSRL0 + ulEndpoint) & ucTxPktRdy)
- {
- return(-1);
- }
- //
- // Calculate the FIFO address.
- //
- ulFIFO = ulBase + USB_O_FIFO0 + (ulEndpoint >> 2);
- //
- // Write the data to the FIFO.
- //
- for(; ulSize > 0; ulSize--)
- {
- HWREGB(ulFIFO) = *pucData++;
- }
- //
- // Success.
- //
- return(0);
- }
- //*****************************************************************************
- //
- //! Starts the transfer of data from an endpoint's FIFO.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //! \param ulTransType is set to indicate what type of data is being sent.
- //!
- //! This function will start the transfer of data from the FIFO for a given
- //! endpoint. This is necessary if the \b USB_EP_AUTO_SET bit was not enabled
- //! for the endpoint. Setting the \e ulTransType parameter will allow the
- //! appropriate signaling on the USB bus for the type of transaction being
- //! requested. The \e ulTransType parameter should be one of the following:
- //!
- //! - USB_TRANS_OUT for OUT transaction on any endpoint in host mode.
- //! - USB_TRANS_IN for IN transaction on any endpoint in device mode.
- //! - USB_TRANS_IN_LAST for the last IN transactions on endpoint zero in a
- //! sequence of IN transactions.
- //! - USB_TRANS_SETUP for setup transactions on endpoint zero.
- //! - USB_TRANS_STATUS for status results on endpoint zero.
- //!
- //! \return This call will return 0 on success, or -1 if a transmission is
- //! already in progress.
- //
- //*****************************************************************************
- long
- USBEndpointDataSend(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long ulTransType)
- {
- unsigned long ulTxPktRdy;
- //
- // CHeck the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- //
- // Get the bit position of TxPktRdy based on the endpoint.
- //
- if(ulEndpoint == USB_EP_0)
- {
- ulTxPktRdy = ulTransType & 0xff;
- }
- else
- {
- ulTxPktRdy = (ulTransType >> 8) & 0xff;
- }
- //
- // Don't allow transmit of data if the TxPktRdy bit is already set.
- //
- if(HWREGB(ulBase + USB_O_CSRL0 + ulEndpoint) & USB_CSRL0_TXRDY)
- {
- return(-1);
- }
- //
- // Set TxPktRdy in order to send the data.
- //
- HWREGB(ulBase + USB_O_CSRL0 + ulEndpoint) = ulTxPktRdy;
- //
- // Success.
- //
- return(0);
- }
- //*****************************************************************************
- //
- //! Forces a flush of an endpoint's FIFO.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //! \param ulFlags specifies if the IN or OUT endpoint should be accessed.
- //!
- //! This function will force the controller to flush out the data in the FIFO.
- //! The function can be called with either host or device controllers and
- //! requires the \e ulFlags parameter be one of \b USB_EP_HOST_OUT,
- //! \b USB_EP_HOST_IN, \b USB_EP_DEV_OUT, or \b USB_EP_DEV_IN.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBFIFOFlush(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long ulFlags)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- //
- // Endpoint zero has a different register set for FIFO flushing.
- //
- if(ulEndpoint == USB_EP_0)
- {
- //
- // Nothing in the FIFO if neither of these bits are set.
- //
- if((HWREGB(ulBase + USB_O_CSRL0) &
- (USB_CSRL0_RXRDY | USB_CSRL0_TXRDY)) != 0)
- {
- //
- // Hit the Flush FIFO bit.
- //
- HWREGB(ulBase + USB_O_CSRH0) = USB_CSRH0_FLUSH;
- }
- }
- else
- {
- //
- // Only reset the IN or OUT FIFO.
- //
- if(ulFlags & (USB_EP_HOST_IN | USB_EP_DEV_OUT))
- {
- //
- // Nothing in the FIFO if neither of these bits are set.
- //
- if((HWREGB(ulBase + USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint)) &
- USB_RXCSRL1_RXRDY) == 0)
- {
- //
- // Hit the Flush FIFO bit.
- //
- HWREGB(ulBase + USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint)) |=
- USB_RXCSRL1_FLUSH;
- }
- }
- else
- {
- if((HWREGB(ulBase + USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint)) &
- USB_TXCSRL1_TXRDY) == 0)
- {
- //
- // Hit the Flush FIFO bit.
- //
- HWREGB(ulBase + USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint)) |=
- USB_TXCSRL1_FLUSH;
- }
- }
- }
- }
- //*****************************************************************************
- //
- //! Schedules a request for an IN transaction on an endpoint in host mode.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //!
- //! This function will schedule a request for an IN transaction. When the USB
- //! device being communicated with responds the data, the data can be retrieved
- //! by calling USBEndpointDataGet() or via a DMA transfer.
- //!
- //! \note This function should only be called in host mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBHostRequestIN(unsigned long ulBase, unsigned long ulEndpoint)
- {
- unsigned long ulRegister;
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- //
- // Endpoint zero uses a different offset than the other endpoints.
- //
- if(ulEndpoint == USB_EP_0)
- {
- ulRegister = USB_O_CSRL0;
- }
- else
- {
- ulRegister = USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint);
- }
- //
- // Set the request for an IN transaction.
- //
- HWREGB(ulBase + ulRegister) = USB_RXCSRL1_REQPKT;
- }
- //*****************************************************************************
- //
- //! Issues a request for a status IN transaction on endpoint zero.
- //!
- //! \param ulBase specifies the USB module base address.
- //!
- //! This function is used to cause a request for an status IN transaction from
- //! a device on endpoint zero. This function can only be used with endpoint
- //! zero as that is the only control endpoint that supports this ability. This
- //! is used to complete the last phase of a control transaction to a device and
- //! an interrupt will be signaled when the status packet has been received.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBHostRequestStatus(unsigned long ulBase)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- //
- // Set the request for a status IN transaction.
- //
- HWREGB(ulBase + USB_O_CSRL0) = USB_CSRL0_REQPKT | USB_CSRL0_STATUS;
- }
- //*****************************************************************************
- //
- //! Sets the functional address for the device that is connected to an
- //! endpoint in host mode.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //! \param ulAddr is the functional address for the controller to use for this
- //! endpoint.
- //! \param ulFlags determines if this is an IN or an OUT endpoint.
- //!
- //! This function will set the functional address for a device that is using
- //! this endpoint for communication. This \e ulAddr parameter is the address
- //! of the target device that this endpoint will be used to communicate with.
- //! The \e ulFlags parameter indicates if the IN or OUT endpoint should be set.
- //!
- //! \note This function should only be called in host mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBHostAddrSet(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long ulAddr, unsigned long ulFlags)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- //
- // See if the transmit or receive address should be set.
- //
- if(ulFlags & USB_EP_HOST_OUT)
- {
- //
- // Set the transmit address.
- //
- HWREGB(ulBase + USB_O_TXFUNCADDR0 + (ulEndpoint >> 1)) = ulAddr;
- }
- else
- {
- //
- // Set the receive address.
- //
- HWREGB(ulBase + USB_O_TXFUNCADDR0 + 4 + (ulEndpoint >> 1)) = ulAddr;
- }
- }
- //*****************************************************************************
- //
- //! Gets the current functional device address for an endpoint.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //! \param ulFlags determines if this is an IN or an OUT endpoint.
- //!
- //! This function returns the current functional address that an endpoint is
- //! using to communicate with a device. The \e ulFlags parameter determines if
- //! the IN or OUT endpoint's device address is returned.
- //!
- //! \note This function should only be called in host mode.
- //!
- //! \return Returns the current function address being used by an endpoint.
- //
- //*****************************************************************************
- unsigned long
- USBHostAddrGet(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long ulFlags)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- //
- // See if the transmit or receive address should be returned.
- //
- if(ulFlags & USB_EP_HOST_OUT)
- {
- //
- // Return this endpoint's transmit address.
- //
- return(HWREGB(ulBase + USB_O_TXFUNCADDR0 + (ulEndpoint >> 1)));
- }
- else
- {
- //
- // Return this endpoint's receive address.
- //
- return(HWREGB(ulBase + USB_O_TXFUNCADDR0 + 4 + (ulEndpoint >> 1)));
- }
- }
- //*****************************************************************************
- //
- //! Set the hub address for the device that is connected to an endpoint.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //! \param ulAddr is the hub address for the device using this endpoint.
- //! \param ulFlags determines if this is an IN or an OUT endpoint.
- //!
- //! This function will set the hub address for a device that is using this
- //! endpoint for communication. The \e ulFlags parameter determines if the
- //! device address for the IN or the OUT endpoint is set by this call.
- //!
- //! \note This function should only be called in host mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBHostHubAddrSet(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long ulAddr, unsigned long ulFlags)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- //
- // See if the hub transmit or receive address is being set.
- //
- if(ulFlags & USB_EP_HOST_OUT)
- {
- //
- // Set the hub transmit address for this endpoint.
- //
- HWREGB(ulBase + USB_O_TXHUBADDR0 + (ulEndpoint >> 1)) = ulAddr;
- }
- else
- {
- //
- // Set the hub receive address for this endpoint.
- //
- HWREGB(ulBase + USB_O_TXHUBADDR0 + 4 + (ulEndpoint >> 1)) = ulAddr;
- }
- }
- //*****************************************************************************
- //
- //! Get the current device hub address for this endpoint.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint is the endpoint to access.
- //! \param ulFlags determines if this is an IN or an OUT endpoint.
- //!
- //! This function will return the current hub address that an endpoint is using
- //! to communicate with a device. The \e ulFlags parameter determines if the
- //! device address for the IN or OUT endpoint is returned.
- //!
- //! \note This function should only be called in host mode.
- //!
- //! \return This function returns the current hub address being used by an
- //! endpoint.
- //
- //*****************************************************************************
- unsigned long
- USBHostHubAddrGet(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long ulFlags)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- //
- // See if the hub transmit or receive address should be returned.
- //
- if(ulFlags & USB_EP_HOST_OUT)
- {
- //
- // Return the hub transmit address for this endpoint.
- //
- return(HWREGB(ulBase + USB_O_TXHUBADDR0 + (ulEndpoint >> 1)));
- }
- else
- {
- //
- // Return the hub receive address for this endpoint.
- //
- return(HWREGB(ulBase + USB_O_TXHUBADDR0 + 4 + (ulEndpoint >> 1)));
- }
- }
- //*****************************************************************************
- //
- //! Sets the configuration for USB power fault.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulFlags specifies the configuration of the power fault.
- //!
- //! This function will set the behavior of the USB controller during a power
- //! fault and the behavior of the USBPEN pin. The flags specify the power
- //! fault level sensitivity, the power fault action, and the power enable level
- //! and source. One of the following can be selected as the power fault level
- //! sensitivity:
- //!
- //! - \b USB_HOST_PWRFLT_LOW - Power fault is indicated by the pin being driven
- //! low.
- //! - \b USB_HOST_PWRFLT_HIGH - Power fault is indicated by the pin being
- //! driven! high.
- //!
- //! One of the following can be selected as the power fault action:
- //!
- //! - \b USB_HOST_PWRFLT_EP_NONE - No automatic action when power fault
- //! detected.
- //! - \b USB_HOST_PWRFLT_EP_TRI - Automatically Tri-state the USBEPEN pin on a
- //! power fault.
- //! - \b USB_HOST_PWRFLT_EP_LOW - Automatically drive USBEPEN pin low on a
- //! power fault.
- //! - \b USB_HOST_PWRFLT_EP_HIGH - Automatically drive USBEPEN pin high on a
- //! power fault.
- //!
- //! One of the following can be selected as the power enable level and source:
- //!
- //! - \b USB_HOST_PWREN_LOW - USBEPEN is driven low when power is enabled.
- //! - \b USB_HOST_PWREN_HIGH - USBEPEN is driven high when power is enabled.
- //! - \b USB_HOST_PWREN_VBLOW - USBEPEN is driven high when VBUS is low.
- //! - \b USB_HOST_PWREN_VBHIGH - USBEPEN is driven high when VBUS is high.
- //!
- //! \note This function should only be called in host mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBHostPwrFaultConfig(unsigned long ulBase, unsigned long ulFlags)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulFlags & ~(USB_EPC_PFLTACT_M | USB_EPC_PFLTAEN |
- USB_EPC_PFLTSEN_HIGH | USB_EPC_EPEN_M)) == 0);
- //
- // Set the power fault configuration as specified. This will not change
- // whether fault detection is enabled or not.
- //
- HWREGH(ulBase + USB_O_EPC) =
- (ulFlags | (HWREGH(ulBase + USB_O_EPC) &
- ~(USB_EPC_PFLTACT_M | USB_EPC_PFLTAEN |
- USB_EPC_PFLTSEN_HIGH | USB_EPC_EPEN_M)));
- }
- //*****************************************************************************
- //
- //! Enables power fault detection.
- //!
- //! \param ulBase specifies the USB module base address.
- //!
- //! This function enables power fault detection in the USB controller. If the
- //! USBPFLT pin is not in use this function should not be used.
- //!
- //! \note This function should only be called in host mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBHostPwrFaultEnable(unsigned long ulBase)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- //
- // Enable power fault input.
- //
- HWREGH(ulBase + USB_O_EPC) |= USB_EPC_PFLTEN;
- }
- //*****************************************************************************
- //
- //! Disables power fault detection.
- //!
- //! \param ulBase specifies the USB module base address.
- //!
- //! This function disables power fault detection in the USB controller.
- //!
- //! \note This function should only be called in host mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBHostPwrFaultDisable(unsigned long ulBase)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- //
- // Enable power fault input.
- //
- HWREGH(ulBase + USB_O_EPC) &= ~USB_EPC_PFLTEN;
- }
- //*****************************************************************************
- //
- //! Enables the external power pin.
- //!
- //! \param ulBase specifies the USB module base address.
- //!
- //! This function enables the USBEPEN signal to enable an external power supply
- //! in host mode operation.
- //!
- //! \note This function should only be called in host mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBHostPwrEnable(unsigned long ulBase)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- //
- // Enable the external power suppply enable signal.
- //
- HWREGH(ulBase + USB_O_EPC) |= USB_EPC_EPENDE;
- }
- //*****************************************************************************
- //
- //! Disables the external power pin.
- //!
- //! \param ulBase specifies the USB module base address.
- //!
- //! This function disables the USBEPEN signal to disable an external power
- //! supply in host mode operation.
- //!
- //! \note This function should only be called in host mode.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBHostPwrDisable(unsigned long ulBase)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- //
- // Disable the external power supply enable signal.
- //
- HWREGH(ulBase + USB_O_EPC) &= ~USB_EPC_EPENDE;
- }
- //*****************************************************************************
- //
- //! Get the current frame number.
- //!
- //! \param ulBase specifies the USB module base address.
- //!
- //! This function returns the last frame number received.
- //!
- //! \return The last frame number received.
- //
- //*****************************************************************************
- unsigned long
- USBFrameNumberGet(unsigned long ulBase)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- //
- // Return the most recent frame number.
- //
- return(HWREGH(ulBase + USB_O_FRAME));
- }
- //*****************************************************************************
- //
- //! Starts or ends a session.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param bStart specifies if this call starts or ends a session.
- //!
- //! This function is used in OTG mode to start a session request or end a
- //! session. If the \e bStart parameter is set to \b true, then this function
- //! start a session and if it is \b false it will end a session.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBOTGSessionRequest(unsigned long ulBase, tBoolean bStart)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- //
- // Start or end the session as directed.
- //
- if(bStart)
- {
- HWREGB(ulBase + USB_O_DEVCTL) |= USB_DEVCTL_SESSION;
- }
- else
- {
- HWREGB(ulBase + USB_O_DEVCTL) &= ~USB_DEVCTL_SESSION;
- }
- }
- //*****************************************************************************
- //
- //! Returns the absolute FIFO address for a given endpoint.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint specifies which endpoint's FIFO address to return.
- //!
- //! This function returns the actual physical address of the FIFO. This is
- //! needed when the USB is going to be used with the uDMA controller and the
- //! source or destination address needs to be set to the physical FIFO address
- //! for a given endpoint.
- //!
- //! \return None.
- //
- //*****************************************************************************
- unsigned long
- USBFIFOAddrGet(unsigned long ulBase, unsigned long ulEndpoint)
- {
- //
- // Return the FIFO address for this endpoint.
- //
- return(ulBase + USB_O_FIFO0 + (ulEndpoint >> 2));
- }
- //*****************************************************************************
- //
- //! Returns the current operating mode of the controller.
- //!
- //! \param ulBase specifies the USB module base address.
- //!
- //! This function returns the current operating mode on USB controllers with
- //! OTG or Dual mode functionality.
- //!
- //! For OTG controllers:
- //!
- //! The function will return on of the following values on OTG controllers:
- //! \b USB_OTG_MODE_ASIDE_HOST, \b USB_OTG_MODE_ASIDE_DEV,
- //! \b USB_OTG_MODE_BSIDE_HOST, \b USB_OTG_MODE_BSIDE_DEV,
- //! \b USB_OTG_MODE_NONE.
- //!
- //! \b USB_OTG_MODE_ASIDE_HOST indicates that the controller is in host mode
- //! on the A-side of the cable.
- //!
- //! \b USB_OTG_MODE_ASIDE_DEV indicates that the controller is in device mode
- //! on the A-side of the cable.
- //!
- //! \b USB_OTG_MODE_BSIDE_HOST indicates that the controller is in host mode
- //! on the B-side of the cable.
- //!
- //! \b USB_OTG_MODE_BSIDE_DEV indicates that the controller is in device mode
- //! on the B-side of the cable. If and OTG session request is started with no
- //! cable in place this is the default mode for the controller.
- //!
- //! \b USB_OTG_MODE_NONE indicates that the controller is not attempting to
- //! determine its role in the system.
- //!
- //! For Dual Mode controllers:
- //!
- //! The function will return on of the following values:
- //! \b USB_DUAL_MODE_HOST, \b USB_DUAL_MODE_DEVICE, or
- //! \b USB_DUAL_MODE_NONE.
- //!
- //! \b USB_DUAL_MODE_HOST indicates that the controller is acting as a host.
- //!
- //! \b USB_DUAL_MODE_DEVICE indicates that the controller acting as a device.
- //!
- //! \b USB_DUAL_MODE_NONE indicates that the controller is not active as
- //! either a host or device.
- //!
- //! \return Returns \b USB_OTG_MODE_ASIDE_HOST, \b USB_OTG_MODE_ASIDE_DEV,
- //! \b USB_OTG_MODE_BSIDE_HOST, \b USB_OTG_MODE_BSIDE_DEV,
- //! \b USB_OTG_MODE_NONE, \b USB_DUAL_MODE_HOST, \b USB_DUAL_MODE_DEVICE, or
- //! \b USB_DUAL_MODE_NONE.
- //
- //*****************************************************************************
- unsigned long
- USBModeGet(unsigned long ulBase)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- //
- // Checks the current mode in the USB_O_DEVCTL and returns the current
- // mode.
- //
- // USB_OTG_MODE_ASIDE_HOST: USB_DEVCTL_HOST | USB_DEVCTL_SESSION
- // USB_OTG_MODE_ASIDE_DEV: USB_DEVCTL_SESSION
- // USB_OTG_MODE_BSIDE_HOST: USB_DEVCTL_DEV | USB_DEVCTL_SESSION |
- // USB_DEVCTL_HOST
- // USB_OTG_MODE_BSIDE_DEV: USB_DEVCTL_DEV | USB_DEVCTL_SESSION
- // USB_OTG_MODE_NONE: USB_DEVCTL_DEV
- //
- return(HWREGB(ulBase + USB_O_DEVCTL) &
- (USB_DEVCTL_DEV | USB_DEVCTL_HOST | USB_DEVCTL_SESSION |
- USB_DEVCTL_VBUS_M));
- }
- //*****************************************************************************
- //
- //! Sets the DMA channel to use for a given endpoint.
- //!
- //! \param ulBase specifies the USB module base address.
- //! \param ulEndpoint specifies which endpoint's FIFO address to return.
- //! \param ulChannel specifies which DMA channel to use for which endpoint.
- //!
- //! This function is used to configure which DMA channel to use with a given
- //! endpoint. Receive DMA channels can only be used with receive endpoints
- //! and transmit DMA channels can only be used with transmit endpoints. This
- //! allows the 3 receive and 3 transmit DMA channels to be mapped to any
- //! endpoint other than 0. The values that should be passed into the \e
- //! ulChannel value are the UDMA_CHANNEL_USBEP* values defined in udma.h.
- //!
- //! \note This function only has an effect on microcontrollers that have the
- //! ability to change the DMA channel for an endpoint. Calling this function
- //! on other devices will have no effect.
- //!
- //! \return None.
- //!
- //*****************************************************************************
- void
- USBEndpointDMAChannel(unsigned long ulBase, unsigned long ulEndpoint,
- unsigned long ulChannel)
- {
- unsigned long ulMask;
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- ASSERT((ulEndpoint == USB_EP_1) || (ulEndpoint == USB_EP_2) ||
- (ulEndpoint == USB_EP_3) || (ulEndpoint == USB_EP_4) ||
- (ulEndpoint == USB_EP_5) || (ulEndpoint == USB_EP_6) ||
- (ulEndpoint == USB_EP_7) || (ulEndpoint == USB_EP_8) ||
- (ulEndpoint == USB_EP_9) || (ulEndpoint == USB_EP_10) ||
- (ulEndpoint == USB_EP_11) || (ulEndpoint == USB_EP_12) ||
- (ulEndpoint == USB_EP_13) || (ulEndpoint == USB_EP_14) ||
- (ulEndpoint == USB_EP_15));
- ASSERT(ulChannel <= UDMA_CHANNEL_USBEP3TX);
- //
- // The input select mask needs to be shifted into the correct position
- // based on the channel.
- //
- ulMask = 0xf << (ulChannel * 4);
- //
- // Clear out the current selection for the channel.
- //
- ulMask = HWREG(ulBase + USB_O_EPS) & (~ulMask);
- //
- // The input select is now shifted into the correct position based on the
- // channel.
- //
- ulMask |= (USB_EP_TO_INDEX(ulEndpoint)) << (ulChannel * 4);
- //
- // Write the value out to the register.
- //
- HWREG(ulBase + USB_O_EPS) = ulMask;
- }
- //*****************************************************************************
- //
- //! Change the mode of the USB controller to host.
- //!
- //! \param ulBase specifies the USB module base address.
- //!
- //! This function changes the mode of the USB controller to host mode. This
- //! is only valid on microcontrollers that have the host and device
- //! capabilities and not the OTG capabilities.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- USBHostMode(unsigned long ulBase)
- {
- //
- // Check the arguments.
- //
- ASSERT(ulBase == USB0_BASE);
- //
- // Set the USB controller mode to host.
- //
- HWREGB(ulBase + USB_O_GPCS) &= ~(USB_GPCS_DEVMOD);
- }
- //*****************************************************************************
- //
- // Close the Doxygen group.
- //! @}
- //
- //*****************************************************************************
|