emac.c 198 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979
  1. //*****************************************************************************
  2. //
  3. // emac.c - Driver for the Integrated Ethernet Controller
  4. //
  5. // Copyright (c) 2013-2017 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions
  10. // are met:
  11. //
  12. // Redistributions of source code must retain the above copyright
  13. // notice, this list of conditions and the following disclaimer.
  14. //
  15. // Redistributions in binary form must reproduce the above copyright
  16. // notice, this list of conditions and the following disclaimer in the
  17. // documentation and/or other materials provided with the
  18. // distribution.
  19. //
  20. // Neither the name of Texas Instruments Incorporated nor the names of
  21. // its contributors may be used to endorse or promote products derived
  22. // from this software without specific prior written permission.
  23. //
  24. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. //*****************************************************************************
  37. //*****************************************************************************
  38. //
  39. //! \addtogroup emac_api
  40. //! @{
  41. //
  42. //*****************************************************************************
  43. #include <ti/devices/msp432e4/inc/msp432e411y.h>
  44. #include "types.h"
  45. #include <stdbool.h>
  46. #include <stdint.h>
  47. #include "inc/hw_emac.h"
  48. #include "debug.h"
  49. #include "emac.h"
  50. #include "sysctl.h"
  51. #include "interrupt.h"
  52. #include "sw_crc.h"
  53. //*****************************************************************************
  54. //
  55. // Combined defines used in parameter validity checks.
  56. //
  57. //*****************************************************************************
  58. //*****************************************************************************
  59. //
  60. // Combined valid configuration flags.
  61. //
  62. //*****************************************************************************
  63. #define VALID_CONFIG_FLAGS (EMAC_CONFIG_USE_MACADDR1 | \
  64. EMAC_CONFIG_SA_INSERT | \
  65. EMAC_CONFIG_SA_REPLACE | \
  66. EMAC_CONFIG_2K_PACKETS | \
  67. EMAC_CONFIG_STRIP_CRC | \
  68. EMAC_CONFIG_JABBER_DISABLE | \
  69. EMAC_CONFIG_JUMBO_ENABLE | \
  70. EMAC_CONFIG_IF_GAP_MASK | \
  71. EMAC_CONFIG_CS_DISABLE | \
  72. EMAC_CONFIG_100MBPS | \
  73. EMAC_CONFIG_RX_OWN_DISABLE | \
  74. EMAC_CONFIG_LOOPBACK | \
  75. EMAC_CONFIG_FULL_DUPLEX | \
  76. EMAC_CONFIG_CHECKSUM_OFFLOAD | \
  77. EMAC_CONFIG_RETRY_DISABLE | \
  78. EMAC_CONFIG_AUTO_CRC_STRIPPING | \
  79. EMAC_CONFIG_BO_MASK | \
  80. EMAC_CONFIG_DEFERRAL_CHK_ENABLE | \
  81. EMAC_CONFIG_PREAMBLE_MASK)
  82. //*****************************************************************************
  83. //
  84. // Combined valid frame filter flags.
  85. //
  86. //*****************************************************************************
  87. #define VALID_FRMFILTER_FLAGS (EMAC_FRMFILTER_RX_ALL | \
  88. EMAC_FRMFILTER_VLAN | \
  89. EMAC_FRMFILTER_HASH_AND_PERFECT | \
  90. EMAC_FRMFILTER_SADDR | \
  91. EMAC_FRMFILTER_INV_SADDR | \
  92. EMAC_FRMFILTER_PASS_NO_PAUSE | \
  93. EMAC_FRMFILTER_PASS_ALL_CTRL | \
  94. EMAC_FRMFILTER_PASS_ADDR_CTRL | \
  95. EMAC_FRMFILTER_BROADCAST | \
  96. EMAC_FRMFILTER_PASS_MULTICAST | \
  97. EMAC_FRMFILTER_INV_DADDR | \
  98. EMAC_FRMFILTER_HASH_MULTICAST | \
  99. EMAC_FRMFILTER_HASH_UNICAST | \
  100. EMAC_FRMFILTER_PROMISCUOUS)
  101. //*****************************************************************************
  102. //
  103. // Combined valid maskable interrupts.
  104. //
  105. //*****************************************************************************
  106. #define EMAC_MASKABLE_INTS (EMAC_INT_EARLY_RECEIVE | \
  107. EMAC_INT_BUS_ERROR | \
  108. EMAC_INT_EARLY_TRANSMIT | \
  109. EMAC_INT_RX_WATCHDOG | \
  110. EMAC_INT_RX_STOPPED | \
  111. EMAC_INT_RX_NO_BUFFER | \
  112. EMAC_INT_RECEIVE | \
  113. EMAC_INT_TX_UNDERFLOW | \
  114. EMAC_INT_RX_OVERFLOW | \
  115. EMAC_INT_TX_JABBER | \
  116. EMAC_INT_TX_NO_BUFFER | \
  117. EMAC_INT_TX_STOPPED | \
  118. EMAC_INT_TRANSMIT | \
  119. EMAC_INT_NORMAL_INT | \
  120. EMAC_INT_ABNORMAL_INT | \
  121. EMAC_INT_PHY)
  122. //*****************************************************************************
  123. //
  124. // Combined valid normal interrupts.
  125. //
  126. //*****************************************************************************
  127. #define EMAC_NORMAL_INTS (EMAC_INT_TRANSMIT | \
  128. EMAC_INT_RECEIVE | \
  129. EMAC_INT_EARLY_RECEIVE | \
  130. EMAC_INT_TX_NO_BUFFER)
  131. //*****************************************************************************
  132. //
  133. // Combined valid abnormal interrupts.
  134. //
  135. //*****************************************************************************
  136. #define EMAC_ABNORMAL_INTS (EMAC_INT_TX_STOPPED | \
  137. EMAC_INT_TX_JABBER | \
  138. EMAC_INT_RX_OVERFLOW | \
  139. EMAC_INT_TX_UNDERFLOW | \
  140. EMAC_INT_RX_NO_BUFFER | \
  141. EMAC_INT_RX_STOPPED | \
  142. EMAC_INT_RX_WATCHDOG | \
  143. EMAC_INT_EARLY_TRANSMIT | \
  144. EMAC_INT_BUS_ERROR)
  145. //*****************************************************************************
  146. //
  147. // Interrupt sources reported via the DMARIS register but which are not
  148. // masked (or enabled) via the DMAIM register.
  149. //
  150. //*****************************************************************************
  151. #define EMAC_NON_MASKED_INTS (EMAC_DMARIS_LPI | \
  152. EMAC_DMARIS_TT | \
  153. EMAC_DMARIS_PMT | \
  154. EMAC_DMARIS_MMC)
  155. //*****************************************************************************
  156. //
  157. // The number of MAC addresses the module can store for filtering purposes.
  158. //
  159. //*****************************************************************************
  160. #define NUM_MAC_ADDR 4
  161. //*****************************************************************************
  162. //
  163. // Macros aiding access to the MAC address registers.
  164. //
  165. //*****************************************************************************
  166. #define MAC_ADDR_OFFSET (EMAC_O_ADDR1L - EMAC_O_ADDR0L)
  167. #define EMAC_O_ADDRL(n) (EMAC_O_ADDR0L + (MAC_ADDR_OFFSET * (n)))
  168. #define EMAC_O_ADDRH(n) (EMAC_O_ADDR0H + (MAC_ADDR_OFFSET * (n)))
  169. //*****************************************************************************
  170. //
  171. // A structure used to help in choosing the correct clock divisor for the MII
  172. // based on the current system clock rate.
  173. //
  174. //*****************************************************************************
  175. static const struct
  176. {
  177. uint32_t ui32SysClockMax;
  178. uint32_t ui32Divisor;
  179. }
  180. g_pi16MIIClockDiv[] =
  181. {
  182. { 64000000, EMAC_MIIADDR_CR_35_60 },
  183. { 104000000, EMAC_MIIADDR_CR_60_100 },
  184. { 150000000, EMAC_MIIADDR_CR_100_150 }
  185. };
  186. //*****************************************************************************
  187. //
  188. // The number of clock divisors in the above table.
  189. //
  190. //*****************************************************************************
  191. #define NUM_CLOCK_DIVISORS (sizeof(g_pi16MIIClockDiv) / \
  192. sizeof(g_pi16MIIClockDiv[0]))
  193. //*****************************************************************************
  194. //
  195. // The define for accessing PHY registers in the MMD address space.
  196. //
  197. //*****************************************************************************
  198. #define DEV_ADDR(x) ((x & 0xF000) >> 12)
  199. #define REG_ADDR(x) ((x & 0x0FFF))
  200. //*****************************************************************************
  201. //
  202. //! Initializes the Ethernet MAC and sets bus-related DMA parameters.
  203. //!
  204. //! \param ui32Base is the base address of the Ethernet controller.
  205. //! \param ui32SysClk is the current system clock frequency in Hertz.
  206. //! \param ui32BusConfig defines the bus operating mode for the Ethernet MAC
  207. //! DMA controller.
  208. //! \param ui32RxBurst is the maximum receive burst size in words.
  209. //! \param ui32TxBurst is the maximum transmit burst size in words.
  210. //! \param ui32DescSkipSize is the number of 32-bit words to skip between
  211. //! two unchained DMA descriptors. Values in the range 0 to 31 are valid.
  212. //!
  213. //! This function sets bus-related parameters for the Ethernet MAC DMA
  214. //! engines. It must be called after EMACPHYConfigSet() and called again
  215. //! after any subsequent call to EMACPHYConfigSet().
  216. //!
  217. //! The \e ui32BusConfig parameter is the logical OR of various fields. The
  218. //! first sets the DMA channel priority weight:
  219. //!
  220. //! - \b EMAC_BCONFIG_DMA_PRIO_WEIGHT_1
  221. //! - \b EMAC_BCONFIG_DMA_PRIO_WEIGHT_2
  222. //! - \b EMAC_BCONFIG_DMA_PRIO_WEIGHT_3
  223. //! - \b EMAC_BCONFIG_DMA_PRIO_WEIGHT_4
  224. //!
  225. //! The second field sets the receive and transmit priorities used when
  226. //! arbitrating between the Rx and Tx DMA. The priorities are Rx:Tx unless
  227. //! \b EMAC_BCONFIG_TX_PRIORITY is also specified, in which case they become
  228. //! Tx:Rx. The priority provided here is ignored if
  229. //! \b EMAC_BCONFIG_PRIORITY_FIXED is specified.
  230. //!
  231. //! - \b EMAC_BCONFIG_PRIORITY_1_1
  232. //! - \b EMAC_BCONFIG_PRIORITY_2_1
  233. //! - \b EMAC_BCONFIG_PRIORITY_3_1
  234. //! - \b EMAC_BCONFIG_PRIORITY_4_1
  235. //!
  236. //! The following additional flags may also be defined:
  237. //!
  238. //! - \b EMAC_BCONFIG_TX_PRIORITY indicates that the transmit DMA should be
  239. //! higher priority in all arbitration for the system-side bus. If this is not
  240. //! defined, the receive DMA has higher priority.
  241. //! - \b EMAC_BCONFIG_ADDR_ALIGNED works in tandem with
  242. //! \b EMAC_BCONFIG_FIXED_BURST to control address alignment of AHB bursts.
  243. //! When both flags are specified, all bursts are aligned to the start address
  244. //! least significant bits. If \b EMAC_BCONFIG_FIXED_BURST is not specified,
  245. //! the first burst is unaligned but subsequent bursts are aligned to the
  246. //! address.
  247. //! - \b EMAC_BCONFIG_ALT_DESCRIPTORS indicates that the DMA engine should
  248. //! use the alternate descriptor format as defined in type
  249. //! \b tEMACDMADescriptor. If absent, the basic descriptor type is used.
  250. //! Alternate descriptors are required if using IEEE 1588-2008 advanced
  251. //! timestamping, VLAN or TCP/UDP/ICMP CRC insertion features. Note that,
  252. //! for clarity, emac.h does not contain type definitions for the basic
  253. //! descriptor type. Please see the technical reference manual/datasheet
  254. //! for information on basic descriptor structures.
  255. //! - \b EMAC_BCONFIG_PRIORITY_FIXED indicates that a fixed priority scheme
  256. //! should be employed when arbitrating between the transmit and receive DMA
  257. //! for system-side bus access. In this case, the receive channel always has
  258. //! priority unless \b EMAC_BCONFIG_TX_PRIORITY is set, in which case the
  259. //! transmit channel has priority. If \b EMAC_BCONFIG_PRIORITY_FIXED is not
  260. //! specified, a weighted round-robin arbitration scheme is used with the
  261. //! weighting defined using \b EMAC_BCONFIG_PRIORITY_1_1,
  262. //! \b EMAC_BCONFIG_PRIORITY_2_1, \b EMAC_BCONFIG_PRIORITY_3_1 or
  263. //! \b EMAC_BCONFIG_PRIORITY_4_1, and \b EMAC_BCONFIG_TX_PRIORITY.
  264. //! - \b EMAC_BCONFIG_FIXED_BURST indicates that fixed burst transfers should
  265. //! be used.
  266. //! - \b EMAC_BCONFIG_MIXED_BURST indicates that the DMA engine should use
  267. //! mixed burst types depending on the length of data to be transferred
  268. //! across the system bus.
  269. //!
  270. //! The \e ui32RxBurst and \e ui32TxBurst parameters indicate the maximum
  271. //! number of words that the relevant DMA should transfer in a single
  272. //! transaction. Valid values are 1, 2, 4, 8, 16 and 32. Any other value
  273. //! results in undefined behavior.
  274. //!
  275. //! The \e ui32DescSkipSize parameter is used when the descriptor lists are
  276. //! using ring mode (where descriptors are contiguous in memory with the last
  277. //! descriptor marked with the \b END_OF_RING flag) rather than chained mode
  278. //! (where each descriptor includes a field that points to the next descriptor
  279. //! in the list). In ring mode, the hardware uses the \e ui32DescSkipSize to
  280. //! skip past any application-defined fields after the end of the hardware-
  281. //! defined descriptor fields. The parameter value indicates the number of
  282. //! 32-bit words to skip after the last field of the hardware-defined
  283. //! descriptor to get to the first field of the next descriptor. When using
  284. //! arrays of either the \b tEMACDMADescriptor or \b tEMACAltDMADescriptor
  285. //! types defined for this driver, \e ui32DescSkipSize must be set to 1 to skip
  286. //! the \e pvNext pointer added to the end of each of these structures.
  287. //! Applications may modify these structure definitions to include their own
  288. //! application-specific data and modify \e ui32DescSkipSize appropriately if
  289. //! desired.
  290. //!
  291. //! \return None.
  292. //
  293. //*****************************************************************************
  294. void
  295. EMACInit(uint32_t ui32Base, uint32_t ui32SysClk, uint32_t ui32BusConfig,
  296. uint32_t ui32RxBurst, uint32_t ui32TxBurst, uint32_t ui32DescSkipSize)
  297. {
  298. uint32_t ui32Val, ui32Div;
  299. //
  300. // Parameter sanity checks.
  301. //
  302. ASSERT(ui32DescSkipSize < 32);
  303. ASSERT(ui32TxBurst < (32 * 8));
  304. ASSERT(ui32RxBurst < (32 * 8));
  305. //
  306. // Make sure that the DMA software reset is clear before continuing.
  307. //
  308. while (HWREG(EMAC0_BASE + EMAC_O_DMABUSMOD) & EMAC_DMABUSMOD_SWR)
  309. {
  310. }
  311. //
  312. // Set common flags. Note that this driver assumes we are always using
  313. // 8 word descriptors so we need to OR in EMAC_DMABUSMOD_ATDS here.
  314. //
  315. ui32Val = (ui32BusConfig | (ui32DescSkipSize << EMAC_DMABUSMOD_DSL_S) |
  316. EMAC_DMABUSMOD_ATDS);
  317. //
  318. // Do we need to use the 8X burst length multiplier?
  319. //
  320. if ((ui32TxBurst > 32) || (ui32RxBurst > 32))
  321. {
  322. //
  323. // Divide both burst lengths by 8 and set the 8X burst length
  324. // multiplier.
  325. //
  326. ui32Val |= EMAC_DMABUSMOD_8XPBL;
  327. ui32TxBurst >>= 3;
  328. ui32RxBurst >>= 3;
  329. //
  330. // Sanity check - neither burst length should have become zero. If
  331. // they did, this indicates that the values passed are invalid.
  332. //
  333. ASSERT(ui32RxBurst);
  334. ASSERT(ui32TxBurst);
  335. }
  336. //
  337. // Are the receive and transmit burst lengths the same?
  338. //
  339. if (ui32RxBurst == ui32TxBurst)
  340. {
  341. //
  342. // Yes - set up to use a single burst length.
  343. //
  344. ui32Val |= (ui32TxBurst << EMAC_DMABUSMOD_PBL_S);
  345. }
  346. else
  347. {
  348. //
  349. // No - we need to use separate burst lengths for each.
  350. //
  351. ui32Val |= (EMAC_DMABUSMOD_USP |
  352. (ui32TxBurst << EMAC_DMABUSMOD_PBL_S) |
  353. (ui32RxBurst << EMAC_DMABUSMOD_RPBL_S));
  354. }
  355. //
  356. // Finally, write the bus mode register.
  357. //
  358. HWREG(ui32Base + EMAC_O_DMABUSMOD) = ui32Val;
  359. //
  360. // Default the MII CSR clock divider based on the fastest system clock.
  361. //
  362. ui32Div = g_pi16MIIClockDiv[NUM_CLOCK_DIVISORS - 1].ui32Divisor;
  363. //
  364. // Find the MII CSR clock divider to use based on the current system clock.
  365. //
  366. for (ui32Val = 0; ui32Val < NUM_CLOCK_DIVISORS; ui32Val++)
  367. {
  368. if (ui32SysClk <= g_pi16MIIClockDiv[ui32Val].ui32SysClockMax)
  369. {
  370. ui32Div = g_pi16MIIClockDiv[ui32Val].ui32Divisor;
  371. break;
  372. }
  373. }
  374. //
  375. // Set the MII CSR clock speed.
  376. //
  377. HWREG(ui32Base + EMAC_O_MIIADDR) = ((HWREG(ui32Base + EMAC_O_MIIADDR) &
  378. ~EMAC_MIIADDR_CR_M) | ui32Div);
  379. //
  380. // Disable all the MMC interrupts as these are enabled by default at reset.
  381. //
  382. HWREG(ui32Base + EMAC_O_MMCRXIM) = 0xFFFFFFFF;
  383. HWREG(ui32Base + EMAC_O_MMCTXIM) = 0xFFFFFFFF;
  384. }
  385. //*****************************************************************************
  386. //
  387. //! Resets the Ethernet MAC.
  388. //!
  389. //! \param ui32Base is the base address of the Ethernet controller.
  390. //!
  391. //! This function performs a reset of the Ethernet MAC by resetting all logic
  392. //! and returning all registers to their default values. The function returns
  393. //! only after the hardware indicates that the reset has completed.
  394. //!
  395. //! \note To ensure that the reset completes, the selected PHY clock must be
  396. //! enabled when this function is called. If the PHY clock is absent, this
  397. //! function does not return.
  398. //!
  399. //! \return None.
  400. //
  401. //*****************************************************************************
  402. void
  403. EMACReset(uint32_t ui32Base)
  404. {
  405. //
  406. // Reset the Ethernet MAC.
  407. //
  408. HWREG(ui32Base + EMAC_O_DMABUSMOD) |= EMAC_DMABUSMOD_SWR;
  409. //
  410. // Wait for the reset to complete.
  411. //
  412. while (HWREG(ui32Base + EMAC_O_DMABUSMOD) & EMAC_DMABUSMOD_SWR)
  413. {
  414. }
  415. }
  416. //*****************************************************************************
  417. //
  418. //! Selects the Ethernet PHY in use.
  419. //!
  420. //! \param ui32Base is the base address of the Ethernet controller.
  421. //! \param ui32Config selects the PHY in use and, when using the internal
  422. //! PHY, allows various various PHY parameters to be configured.
  423. //!
  424. //! This function must be called prior to EMACInit() and EMACConfigSet() to
  425. //! select the Ethernet PHY to be used. If the internal PHY is selected, the
  426. //! function also allows configuration of various PHY parameters. Note that
  427. //! the Ethernet MAC is reset during this function call because parameters used
  428. //! by this function are latched by the hardware only on a MAC reset. The call
  429. //! sequence to select and configure the PHY, therefore, must be as follows:
  430. //!
  431. //! \verbatim
  432. //! // Enable and reset the MAC.
  433. //! SysCtlPeripheralEnable(SYSCTL_PERIPH_EMAC0);
  434. //! SysCtlPeripheralReset(SYSCTL_PERIPH_EMAC0);
  435. //! if(<using internal PHY>)
  436. //! {
  437. //! // Enable and reset the internal PHY.
  438. //! SysCtlPeripheralEnable(SYSCTL_PERIPH_EPHY0);
  439. //! SysCtlPeripheralReset(SYSCTL_PERIPH_EPHY0);
  440. //! }
  441. //!
  442. //! // Ensure the MAC is completed its reset.
  443. //! while(!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_EMAC0))
  444. //! {
  445. //! }
  446. //!
  447. //! // Set the PHY type and configuration options.
  448. //! EMACPHYConfigSet(EMAC0_BASE, <config>);
  449. //!
  450. //! // Initialize and configure the MAC.
  451. //! EMACInit(EMAC0_BASE, <system clock rate>, <bus config>,
  452. //! <Rx burst size>, <Tx burst size>, <desc skip>);
  453. //! EMACConfigSet(EMAC0_BASE, <parameters>);
  454. //! \endverbatim
  455. //!
  456. //! The \e ui32Config parameter must specify one of the following values:
  457. //!
  458. //! - \b EMAC_PHY_TYPE_INTERNAL selects the internal Ethernet PHY.
  459. //! - \b EMAC_PHY_TYPE_EXTERNAL_MII selects an external PHY connected via the
  460. //! MII interface.
  461. //! - \b EMAC_PHY_TYPE_EXTERNAL_RMII selects an external PHY connected via the
  462. //! RMII interface.
  463. //!
  464. //! If \b EMAC_PHY_TYPE_INTERNAL is selected, the following flags may be ORed
  465. //! into \e ui32Config to control various PHY features and modes. These flags
  466. //! are ignored if an external PHY is selected.
  467. //!
  468. //! - \b EMAC_PHY_INT_NIB_TXERR_DET_DIS disables odd nibble transmit error
  469. //! detection (sets the default value of PHY register MR10, bit 1).
  470. //! - \b EMAC_PHY_INT_RX_ER_DURING_IDLE enables receive error detection during
  471. //! idle (sets the default value of PHY register MR10, bit 2).
  472. //! - \b EMAC_PHY_INT_ISOLATE_MII_LLOSS ties the MII outputs low if no link is
  473. //! established in 100B-T and full duplex modes (sets the default value of PHY
  474. //! register MR10, bit 3).
  475. //! - \b EMAC_PHY_INT_LINK_LOSS_RECOVERY enables link loss recovery (sets the
  476. //! default value of PHY register MR9, bit 7).
  477. //! - \b EMAC_PHY_INT_TDRRUN enables execution of the TDR procedure after a link
  478. //! down event (sets the default value of PHY register MR9, bit 8).
  479. //! - \b EMAC_PHY_INT_LD_ON_RX_ERR_COUNT enables link down if the receiver
  480. //! error count reaches 32 within a 10-us interval (sets the default value of
  481. //! PHY register MR11 bit 3).
  482. //! - \b EMAC_PHY_INT_LD_ON_MTL3_ERR_COUNT enables link down if the MTL3 error
  483. //! count reaches 20 in a 10 us-interval (sets the default value of PHY register
  484. //! MR11 bit 2).
  485. //! - \b EMAC_PHY_INT_LD_ON_LOW_SNR enables link down if the low SNR threshold
  486. //! is crossed 20 times in a 10 us-interval (sets the default value of PHY
  487. //! register MR11 bit 1).
  488. //! - \b EMAC_PHY_INT_LD_ON_SIGNAL_ENERGY enables link down if energy detector
  489. //! indicates Energy Loss (sets the default value of PHY register MR11 bit 0).
  490. //! - \b EMAC_PHY_INT_POLARITY_SWAP inverts the polarity on both TPTD and TPRD
  491. //! pairs (sets the default value of PHY register MR11 bit 5).
  492. //! - \b EMAC_PHY_INT_MDI_SWAP swaps the MDI pairs putting receive on the TPTD
  493. //! pair and transmit on TPRD (sets the default value of PHY register MR11 bit
  494. //! 6).
  495. //! - \b EMAC_PHY_INT_ROBUST_MDIX enables robust auto MDI-X resolution (sets the
  496. //! default value of PHY register MR9 bit 5).
  497. //! - \b EMAC_PHY_INT_FAST_MDIX enables fast auto-MDI/MDIX resolution (sets the
  498. //! default value of PHY register MR9 bit 6).
  499. //! - \b EMAC_PHY_INT_MDIX_EN enables auto-MDI/MDIX crossover (sets the
  500. //! default value of PHY register MR9 bit 14).
  501. //! - \b EMAC_PHY_INT_FAST_RXDV_DETECT enables fast RXDV detection (set the
  502. //! default value of PHY register MR9 bit 1).
  503. //! - \b EMAC_PHY_INT_FAST_L_UP_DETECT enables fast link-up time during parallel
  504. //! detection (sets the default value of PHY register MR10 bit 6)
  505. //! - \b EMAC_PHY_INT_EXT_FULL_DUPLEX forces full-duplex while working with a
  506. //! link partner in forced 100B-TX (sets the default value of PHY register
  507. //! MR10 bit 5).
  508. //! - \b EMAC_PHY_INT_FAST_AN_80_50_35 enables fast auto-negotiation using
  509. //! break link, link fail inhibit and wait timers set to 80, 50 and 35
  510. //! respectively (sets the default value of PHY register MR9 bits [4:2] to
  511. //! 3b100).
  512. //! - \b EMAC_PHY_INT_FAST_AN_120_75_50 enables fast auto-negotiation using
  513. //! break link, link fail inhibit and wait timers set to 120, 75 and 50
  514. //! respectively (sets the default value of PHY register MR9 bits [4:2] to
  515. //! 3b101).
  516. //! - \b EMAC_PHY_INT_FAST_AN_140_150_100 enables fast auto-negotiation using
  517. //! break link, link fail inhibit and wait timers set to 140, 150 and 100
  518. //! respectively (sets the default value of PHY register MR9 bits [4:2] to
  519. //! 3b110).
  520. //! - \b EMAC_PHY_FORCE_10B_T_HALF_DUPLEX disables auto-negotiation and forces
  521. //! operation in 10Base-T, half duplex mode (sets the default value of PHY
  522. //! register MR9 bits [13:11] to 3b000).
  523. //! - \b EMAC_PHY_FORCE_10B_T_FULL_DUPLEX disables auto-negotiation and forces
  524. //! operation in 10Base-T, full duplex mode (sets the default value of PHY
  525. //! register MR9 bits [13:11] to 3b001).
  526. //! - \b EMAC_PHY_FORCE_100B_T_HALF_DUPLEX disables auto-negotiation and forces
  527. //! operation in 100Base-T, half duplex mode (sets the default value of PHY
  528. //! register MR9 bits [13:11] to 3b010).
  529. //! - \b EMAC_PHY_FORCE_100B_T_FULL_DUPLEX disables auto-negotiation and forces
  530. //! operation in 100Base-T, full duplex mode (sets the default value of PHY
  531. //! register MR9 bits [13:11] to 3b011).
  532. //! - \b EMAC_PHY_AN_10B_T_HALF_DUPLEX enables auto-negotiation and advertises
  533. //! 10Base-T, half duplex mode (sets the default value of PHY register MR9 bits
  534. //! [13:11] to 3b100).
  535. //! - \b EMAC_PHY_AN_10B_T_FULL_DUPLEX enables auto-negotiation and advertises
  536. //! 10Base-T half or full duplex modes (sets the default value of PHY register
  537. //! MR9 bits [13:11] to 3b101).
  538. //! - \b EMAC_PHY_AN_100B_T_HALF_DUPLEX enables auto-negotiation and advertises
  539. //! 10Base-T half or full duplex, and 100Base-T half duplex modes (sets the
  540. //! default value of PHY register MR9 bits [13:11] to 3b110).
  541. //! - \b EMAC_PHY_AN_100B_T_FULL_DUPLEX enables auto-negotiation and advertises
  542. //! 10Base-T half or full duplex, and 100Base-T half or full duplex modes (sets
  543. //! the default value of PHY register MR9 bits [13:11] to 3b111).
  544. //! - \b EMAC_PHY_INT_HOLD prevents the PHY from transmitting energy on the
  545. //! line.
  546. //!
  547. //! As a side effect of this function, the Ethernet MAC is reset so any
  548. //! previous MAC configuration is lost.
  549. //!
  550. //! \return None.
  551. //
  552. //*****************************************************************************
  553. void
  554. EMACPHYConfigSet(uint32_t ui32Base, uint32_t ui32Config)
  555. {
  556. //
  557. // Write the Ethernet PHY configuration to the peripheral configuration
  558. // register.
  559. //
  560. HWREG(ui32Base + EMAC_O_PC) = ui32Config;
  561. //
  562. // If using the internal PHY, reset it to ensure that new configuration is
  563. // latched there.
  564. //
  565. if ((ui32Config & EMAC_PHY_TYPE_MASK) == EMAC_PHY_TYPE_INTERNAL)
  566. {
  567. SysCtlPeripheralReset(SYSCTL_PERIPH_EPHY0);
  568. while (!SysCtlPeripheralReady(SYSCTL_PERIPH_EPHY0))
  569. {
  570. //
  571. // Wait for the PHY reset to complete.
  572. //
  573. }
  574. //
  575. // Delay a bit longer to ensure that the PHY reset has completed.
  576. //
  577. SysCtlDelay(10000);
  578. }
  579. //
  580. // If using an external RMII PHY, we must set 2 bits in the Ethernet MAC
  581. // Clock Configuration Register.
  582. //
  583. if ((ui32Config & EMAC_PHY_TYPE_MASK) == EMAC_PHY_TYPE_EXTERNAL_RMII)
  584. {
  585. //
  586. // Select and enable the external clock from the RMII PHY.
  587. //
  588. HWREG(EMAC0_BASE + EMAC_O_CC) |= EMAC_CC_CLKEN;
  589. }
  590. else
  591. {
  592. //
  593. // Disable the external clock.
  594. //
  595. HWREG(EMAC0_BASE + EMAC_O_CC) &= ~EMAC_CC_CLKEN;
  596. }
  597. //
  598. // Reset the MAC regardless of whether the PHY connection changed or not.
  599. //
  600. EMACReset(EMAC0_BASE);
  601. SysCtlDelay(1000);
  602. }
  603. //*****************************************************************************
  604. //
  605. //! Configures basic Ethernet MAC operation parameters.
  606. //!
  607. //! \param ui32Base is the base address of the Ethernet controller.
  608. //! \param ui32Config provides various flags and values configuring the MAC.
  609. //! \param ui32ModeFlags provides configuration relating to the transmit and
  610. //! receive DMA engines.
  611. //! \param ui32RxMaxFrameSize sets the maximum receive frame size above which
  612. //! an error is reported.
  613. //!
  614. //! This function is called to configure basic operating parameters for the
  615. //! MAC and its DMA engines.
  616. //!
  617. //! The \e ui32Config parameter is the logical OR of various fields and
  618. //! flags. The first field determines which MAC address is used during
  619. //! insertion or replacement for all transmitted frames. Valid options are
  620. //!
  621. //! - \b EMAC_CONFIG_USE_MACADDR1 and
  622. //! - \b EMAC_CONFIG_USE_MACADDR0
  623. //!
  624. //! The interframe gap between transmitted frames is controlled using one of
  625. //! the following values:
  626. //!
  627. //! - \b EMAC_CONFIG_IF_GAP_96BITS
  628. //! - \b EMAC_CONFIG_IF_GAP_88BITS
  629. //! - \b EMAC_CONFIG_IF_GAP_80BITS
  630. //! - \b EMAC_CONFIG_IF_GAP_72BITS
  631. //! - \b EMAC_CONFIG_IF_GAP_64BITS
  632. //! - \b EMAC_CONFIG_IF_GAP_56BITS
  633. //! - \b EMAC_CONFIG_IF_GAP_48BITS
  634. //! - \b EMAC_CONFIG_IF_GAP_40BITS
  635. //!
  636. //! The number of bytes of preamble added to the beginning of every transmitted
  637. //! frame is selected using one of the following values:
  638. //!
  639. //! - \b EMAC_CONFIG_7BYTE_PREAMBLE
  640. //! - \b EMAC_CONFIG_5BYTE_PREAMBLE
  641. //! - \b EMAC_CONFIG_3BYTE_PREAMBLE
  642. //!
  643. //! The back-off limit determines the range of the random time that the MAC
  644. //! delays after a collision and before attempting to retransmit a frame. One
  645. //! of the following values must be used to select this limit. In each case,
  646. //! the retransmission delay in terms of 512 bit time slots, is the lower of
  647. //! (2 ** N) and a random number between 0 and the selected backoff-limit.
  648. //!
  649. //! - \b EMAC_CONFIG_BO_LIMIT_1024
  650. //! - \b EMAC_CONFIG_BO_LIMIT_256
  651. //! - \b EMAC_CONFIG_BO_LIMIT_16
  652. //! - \b EMAC_CONFIG_BO_LIMIT_2
  653. //!
  654. //! Control over insertion or replacement of the source address in all
  655. //! transmitted frames is provided by using one of the following fields:
  656. //!
  657. //! - \b EMAC_CONFIG_SA_INSERT causes the MAC address (0 or 1 depending
  658. //! on whether \b EMAC_CONFIG_USE_MACADDR0 or \b EMAC_CONFIG_USE_MACADDR1
  659. //! was specified) to be inserted into all transmitted frames.
  660. //! - \b EMAC_CONFIG_SA_REPLACE causes the MAC address to be replaced with
  661. //! the selected address in all transmitted frames.
  662. //! - \b EMAC_CONFIG_SA_FROM_DESCRIPTOR causes control of source address
  663. //! insertion or deletion to be controlled by fields in the DMA transmit
  664. //! descriptor, allowing control on a frame-by-frame basis.
  665. //!
  666. //! Whether the interface attempts to operate in full- or half-duplex mode is
  667. //! controlled by one of the following flags:
  668. //!
  669. //! - \b EMAC_CONFIG_FULL_DUPLEX
  670. //! - \b EMAC_CONFIG_HALF_DUPLEX
  671. //!
  672. //! The following additional flags may also be specified:
  673. //!
  674. //! - \b EMAC_CONFIG_2K_PACKETS enables IEEE802.3as support for 2K packets.
  675. //! When specified, the MAC considers all frames up to 2000 bytes in length as
  676. //! normal packets. When \b EMAC_CONFIG_JUMBO_ENABLE is not specified, all
  677. //! frames larger than 2000 bytes are treated as Giant frames. This flag is
  678. //! ignored if \b EMAC_CONFIG_JUMBO_ENABLE is specified.
  679. //! - \b EMAC_CONFIG_STRIP_CRC causes the 4-byte CRC of all Ethernet type
  680. //! frames to be stripped and dropped before the frame is forwarded to the
  681. //! application.
  682. //! - \b EMAC_CONFIG_JABBER_DISABLE disables the jabber timer on the
  683. //! transmitter and enables frames of up to 16384 bytes to be transmitted. If
  684. //! this flag is absent, the MAC does not allow more than 2048 (or 10240 if
  685. //! \b EMAC_CONFIG_JUMBO_ENABLE is specified) bytes to be sent in any one
  686. //! frame.
  687. //! - \b EMAC_CONFIG_JUMBO_ENABLE enables Jumbo Frames, allowing frames of
  688. //! up to 9018 (or 9022 if using VLAN tagging) to be handled without reporting
  689. //! giant frame errors.
  690. //! - \b EMAC_CONFIG_100MBPS forces the MAC to communicate with the PHY using
  691. //! 100Mbps signaling. If this option is not specified, the MAC uses 10Mbps
  692. //! signaling. This speed setting is important when using an external RMII
  693. //! PHY where the selected rate must match the PHY's setting which may have
  694. //! been made as a result of auto-negotiation. When using the internal PHY
  695. //! or an external MII PHY, the signaling rate is controlled by the PHY-
  696. //! provided transmit and receive clocks.
  697. //! - \b EMAC_CONFIG_CS_DISABLE disables Carrier Sense during transmission
  698. //! when operating in half-duplex mode.
  699. //! - \b EMAC_CONFIG_RX_OWN_DISABLE disables reception of transmitted frames
  700. //! when operating in half-duplex mode.
  701. //! - \b EMAC_CONFIG_LOOPBACK enables internal loopback.
  702. //! - \b EMAC_CONFIG_CHECKSUM_OFFLOAD enables IPv4 header checksum checking
  703. //! and IPv4 or IPv6 TCP, UPD or ICMP payload checksum checking. The results
  704. //! of the checksum calculations are reported via status fields in the DMA
  705. //! receive descriptors.
  706. //! - \b EMAC_CONFIG_RETRY_DISABLE disables retransmission in cases where
  707. //! half-duplex mode is in use and a collision occurs. This condition causes
  708. //! the current frame to be ignored and a frame abort to be reported in the
  709. //! transmit frame status.
  710. //! - \b EMAC_CONFIG_AUTO_CRC_STRIPPING strips the last 4 bytes (frame check
  711. //! sequence) from all Ether type frames before forwarding the frames to the
  712. //! application.
  713. //! - \b EMAC_CONFIG_DEFERRAL_CHK_ENABLE enables transmit deferral checking
  714. //! in half-duplex mode. When enabled, the transmitter reports an error if it
  715. //! is unable to transmit a frame for more than 24288 bit times (or 155680
  716. //! bit times in Jumbo frame mode) due to an active carrier sense signal on
  717. //! the MII.
  718. //!
  719. //! The \e ui32ModeFlags parameter sets operating parameters related to the
  720. //! internal MAC FIFOs. It comprises a logical OR of the following fields.
  721. //! The first selects the transmit FIFO threshold. Transmission of a frame
  722. //! begins when this amount of data or a full frame exists in the transmit
  723. //! FIFO. This field is ignored if \b EMAC_MODE_TX_STORE_FORWARD is
  724. //! included. One of the following must be specified:
  725. //!
  726. //! - \b EMAC_MODE_TX_THRESHOLD_16_BYTES
  727. //! - \b EMAC_MODE_TX_THRESHOLD_24_BYTES
  728. //! - \b EMAC_MODE_TX_THRESHOLD_32_BYTES
  729. //! - \b EMAC_MODE_TX_THRESHOLD_40_BYTES
  730. //! - \b EMAC_MODE_TX_THRESHOLD_64_BYTES
  731. //! - \b EMAC_MODE_TX_THRESHOLD_128_BYTES
  732. //! - \b EMAC_MODE_TX_THRESHOLD_192_BYTES
  733. //! - \b EMAC_MODE_TX_THRESHOLD_256_BYTES
  734. //!
  735. //! The second field controls the receive FIFO threshold. DMA transfers of
  736. //! received data begin either when the receive FIFO contains a full frame
  737. //! or this number of bytes. This field is ignored if
  738. //! \b EMAC_MODE_RX_STORE_FORWARD is included. One of the following must be
  739. //! specified:
  740. //!
  741. //! - \b EMAC_MODE_RX_THRESHOLD_64_BYTES
  742. //! - \b EMAC_MODE_RX_THRESHOLD_32_BYTES
  743. //! - \b EMAC_MODE_RX_THRESHOLD_96_BYTES
  744. //! - \b EMAC_MODE_RX_THRESHOLD_128_BYTES
  745. //!
  746. //! The following additional flags may be specified:
  747. //!
  748. //! - \b EMAC_MODE_KEEP_BAD_CRC causes frames with TCP/IP checksum errors
  749. //! to be forwarded to the application if those frames do not have any errors
  750. //! (including FCS errors) in the Ethernet framing. In these cases, the frames
  751. //! have errors only in the payload. If this flag is not specified, all frames
  752. //! with any detected error are discarded unless \b EMAC_MODE_RX_ERROR_FRAMES
  753. //! is also specified.
  754. //! - \b EMAC_MODE_RX_STORE_FORWARD causes the receive DMA to read frames
  755. //! from the FIFO only after the complete frame has been written to it. If
  756. //! this mode is enabled, the receive threshold is ignored.
  757. //! - \b EMAC_MODE_RX_FLUSH_DISABLE disables the flushing of received frames
  758. //! in cases where receive descriptors or buffers are unavailable.
  759. //! - \b EMAC_MODE_TX_STORE_FORWARD causes the transmitter to start
  760. //! transmitting a frame only after the whole frame has been written to the
  761. //! transmit FIFO. If this mode is enabled, the transmit threshold is ignored.
  762. //! - \b EMAC_MODE_RX_ERROR_FRAMES causes all frames other than runt error
  763. //! frames to be forwarded to the receive DMA regardless of any errors detected
  764. //! in the frames.
  765. //! - \b EMAC_MODE_RX_UNDERSIZED_FRAMES causes undersized frames (frames
  766. //! shorter than 64 bytes but with no errors) to the application. If this
  767. //! option is not selected, all undersized frames are dropped by the receiver
  768. //! unless it has already started transferring them to the receive FIFO due to
  769. //! the receive threshold setting.
  770. //! - \b EMAC_MODE_OPERATE_2ND_FRAME enables the transmit DMA to operate on a
  771. //! second frame while waiting for the previous frame to be transmitted and
  772. //! associated status and timestamps to be reported. If absent, the transmit
  773. //! DMA works on a single frame at any one time, waiting for that frame to be
  774. //! transmitted and its status to be received before moving on to the next
  775. //! frame.
  776. //!
  777. //! The \e ui32RxMaxFrameSize parameter may be used to override the default
  778. //! setting for the maximum number of bytes that can be received in a frame
  779. //! before that frame is flagged as being in error. If the parameter is set
  780. //! to 0, the default hardware settings are applied. If non-zero, any frame
  781. //! received which is longer than the \e ui32RxMaxFrameSize, regardless of
  782. //! whether the MAC is configured for normal or Jumbo frame operation, is
  783. //! flagged as an error.
  784. //!
  785. //! \return None.
  786. //
  787. //*****************************************************************************
  788. void
  789. EMACConfigSet(uint32_t ui32Base, uint32_t ui32Config, uint32_t ui32ModeFlags,
  790. uint32_t ui32RxMaxFrameSize)
  791. {
  792. //
  793. // Parameter sanity check. Note that we allow TX_ENABLED and RX_ENABLED
  794. // here because we'll mask them off before writing the value and this
  795. // makes back-to-back EMACConfigGet/EMACConfigSet calls work without the
  796. // caller needing to explicitly remove these bits from the parameter.
  797. //
  798. ASSERT((ui32Config & ~(VALID_CONFIG_FLAGS | EMAC_CONFIG_TX_ENABLED |
  799. EMAC_CONFIG_RX_ENABLED)) == 0);
  800. ASSERT(!ui32RxMaxFrameSize || ((ui32RxMaxFrameSize < 0x4000) &&
  801. (ui32RxMaxFrameSize > 1522)));
  802. //
  803. // Set the configuration flags as specified. Note that we unconditionally
  804. // OR in the EMAC_CFG_PS bit here since this implementation supports only
  805. // MII and RMII interfaces to the PHYs.
  806. //
  807. HWREG(ui32Base + EMAC_O_CFG) =
  808. ((HWREG(ui32Base + EMAC_O_CFG) & ~VALID_CONFIG_FLAGS) | ui32Config |
  809. EMAC_CFG_PS);
  810. //
  811. // Set the maximum receive frame size. If 0 is passed, this implies
  812. // that the default maximum frame size should be used so just turn off
  813. // the override.
  814. //
  815. if (ui32RxMaxFrameSize)
  816. {
  817. HWREG(ui32Base + EMAC_O_WDOGTO) = ui32RxMaxFrameSize | EMAC_WDOGTO_PWE;
  818. }
  819. else
  820. {
  821. HWREG(ui32Base + EMAC_O_WDOGTO) &= ~EMAC_WDOGTO_PWE;
  822. }
  823. //
  824. // Set the operating mode register.
  825. //
  826. HWREG(ui32Base + EMAC_O_DMAOPMODE) = ui32ModeFlags;
  827. }
  828. //*****************************************************************************
  829. //
  830. //! Returns the Ethernet MAC's current basic configuration parameters.
  831. //!
  832. //! \param ui32Base is the base address of the Ethernet controller.
  833. //! \param pui32Config points to storage that is written with Ethernet MAC
  834. //! configuration.
  835. //! \param pui32Mode points to storage that is written with Ethernet MAC mode
  836. //! information.
  837. //! \param pui32RxMaxFrameSize points to storage that is written with the
  838. //! maximum receive frame size.
  839. //!
  840. //! This function is called to query the basic operating parameters for the
  841. //! MAC and its DMA engines.
  842. //!
  843. //! The \e pui32Config parameter is written with the logical OR of various
  844. //! fields and flags. The first field describes which MAC address is used
  845. //! during insertion or replacement for all transmitted frames. Valid options
  846. //! are
  847. //!
  848. //! - \b EMAC_CONFIG_USE_MACADDR1
  849. //! - \b EMAC_CONFIG_USE_MACADDR0
  850. //!
  851. //! The interframe gap between transmitted frames is given using one of the
  852. //! following values:
  853. //!
  854. //! - \b EMAC_CONFIG_IF_GAP_96BITS
  855. //! - \b EMAC_CONFIG_IF_GAP_88BITS
  856. //! - \b EMAC_CONFIG_IF_GAP_80BITS
  857. //! - \b EMAC_CONFIG_IF_GAP_72BITS
  858. //! - \b EMAC_CONFIG_IF_GAP_64BITS
  859. //! - \b EMAC_CONFIG_IF_GAP_56BITS
  860. //! - \b EMAC_CONFIG_IF_GAP_48BITS
  861. //! - \b EMAC_CONFIG_IF_GAP_40BITS
  862. //!
  863. //! The number of bytes of preamble added to the beginning of every transmitted
  864. //! frame is described using one of the following values:
  865. //!
  866. //! - \b EMAC_CONFIG_7BYTE_PREAMBLE
  867. //! - \b EMAC_CONFIG_5BYTE_PREAMBLE
  868. //! - \b EMAC_CONFIG_3BYTE_PREAMBLE
  869. //!
  870. //! The back-off limit determines the range of the random time that the MAC
  871. //! delays after a collision and before attempting to retransmit a frame. One
  872. //! of the following values provides the currently selected limit. In each
  873. //! case the retransmission delay in terms of 512 bit time slots, is the
  874. //! lower of (2 ** N) and a random number between 0 and the reported
  875. //! backoff-limit.
  876. //!
  877. //! - \b EMAC_CONFIG_BO_LIMIT_1024
  878. //! - \b EMAC_CONFIG_BO_LIMIT_256
  879. //! - \b EMAC_CONFIG_BO_LIMIT_16
  880. //! - \b EMAC_CONFIG_BO_LIMIT_2
  881. //!
  882. //! Handling of insertion or replacement of the source address in all
  883. //! transmitted frames is described by one of the following fields:
  884. //!
  885. //! - \b EMAC_CONFIG_SA_INSERT causes the MAC address (0 or 1 depending
  886. //! on whether \b EMAC_CONFIG_USE_MACADDR0 or \b EMAC_CONFIG_USE_MACADDR1
  887. //! was specified) to be inserted into all transmitted frames.
  888. //! - \b EMAC_CONFIG_SA_REPLACE causes the MAC address to be replaced with
  889. //! the selected address in all transmitted frames.
  890. //! - \b EMAC_CONFIG_SA_FROM_DESCRIPTOR causes control of source address
  891. //! insertion or deletion to be controlled by fields in the DMA transmit
  892. //! descriptor, allowing control on a frame-by-frame basis.
  893. //!
  894. //! Whether the interface attempts to operate in full- or half-duplex mode is
  895. //! reported by one of the following flags:
  896. //!
  897. //! - \b EMAC_CONFIG_FULL_DUPLEX
  898. //! - \b EMAC_CONFIG_HALF_DUPLEX
  899. //!
  900. //! The following additional flags may also be included:
  901. //!
  902. //! - \b EMAC_CONFIG_2K_PACKETS indicates that IEEE802.3as support for 2K
  903. //! packets is enabled. When present, the MAC considers all frames up to 2000
  904. //! bytes in length as normal packets. When \b EMAC_CONFIG_JUMBO_ENABLE is
  905. //! not reported, all frames larger than 2000 bytes are treated as Giant
  906. //! frames. The value of this flag should be ignored if
  907. //! \b EMAC_CONFIG_JUMBO_ENABLE is also reported.
  908. //! - \b EMAC_CONFIG_STRIP_CRC indicates that the 4-byte CRC of all Ethernet
  909. //! type frames is being stripped and dropped before the frame is forwarded to
  910. //! the application.
  911. //! - \b EMAC_CONFIG_JABBER_DISABLE indicates that the the jabber timer on the
  912. //! transmitter is disabled, allowing frames of up to 16384 bytes to be
  913. //! transmitted. If this flag is absent, the MAC does not allow more than 2048
  914. //! (or 10240 if \b EMAC_CONFIG_JUMBO_ENABLE is reported) bytes to be sent in
  915. //! any one frame.
  916. //! - \b EMAC_CONFIG_JUMBO_ENABLE indicates that Jumbo Frames of up to 9018
  917. //! (or 9022 if using VLAN tagging) are enabled.
  918. //! - \b EMAC_CONFIG_CS_DISABLE indicates that Carrier Sense is disabled
  919. //! during transmission when operating in half-duplex mode.
  920. //! - \b EMAC_CONFIG_100MBPS indicates that the MAC is using 100Mbps
  921. //! signaling to communicate with the PHY.
  922. //! - \b EMAC_CONFIG_RX_OWN_DISABLE indicates that reception of transmitted
  923. //! frames is disabled when operating in half-duplex mode.
  924. //! - \b EMAC_CONFIG_LOOPBACK indicates that internal loopback is enabled.
  925. //! - \b EMAC_CONFIG_CHECKSUM_OFFLOAD indicates that IPv4 header checksum
  926. //! checking and IPv4 or IPv6 TCP, UPD or ICMP payload checksum checking is
  927. //! enabled. The results of the checksum calculations are reported via status
  928. //! fields in the DMA receive descriptors.
  929. //! - \b EMAC_CONFIG_RETRY_DISABLE indicates that retransmission is disabled
  930. //! in cases where half-duplex mode is in use and a collision occurs. This
  931. //! condition causes the current frame to be ignored and a frame abort to be
  932. //! reported in the transmit frame status.
  933. //! - \b EMAC_CONFIG_AUTO_CRC_STRIPPING indicates that the last 4 bytes
  934. //! (frame check sequence) from all Ether type frames are being stripped before
  935. //! frames are forwarded to the application.
  936. //! - \b EMAC_CONFIG_DEFERRAL_CHK_ENABLE indicates that transmit deferral
  937. //! checking is disabled in half-duplex mode. When enabled, the transmitter
  938. //! reports an error if it is unable to transmit a frame for more than 24288
  939. //! bit times (or 155680 bit times in Jumbo frame mode) due to an active
  940. //! carrier sense signal on the MII.
  941. //! - \b EMAC_CONFIG_TX_ENABLED indicates that the MAC transmitter is
  942. //! currently enabled.
  943. //! - \b EMAC_CONFIG_RX_ENABLED indicates that the MAC receiver is
  944. //! currently enabled.
  945. //!
  946. //! The \e pui32ModeFlags parameter is written with operating parameters
  947. //! related to the internal MAC FIFOs. It comprises a logical OR of the
  948. //! following fields. The first field reports the transmit FIFO threshold.
  949. //! Transmission of a frame begins when this amount of data or a full frame
  950. //! exists in the transmit FIFO. This field should be ignored if
  951. //! \b EMAC_MODE_TX_STORE_FORWARD is also reported. One of the following
  952. //! values is reported:
  953. //!
  954. //! - \b EMAC_MODE_TX_THRESHOLD_16_BYTES
  955. //! - \b EMAC_MODE_TX_THRESHOLD_24_BYTES
  956. //! - \b EMAC_MODE_TX_THRESHOLD_32_BYTES
  957. //! - \b EMAC_MODE_TX_THRESHOLD_40_BYTES
  958. //! - \b EMAC_MODE_TX_THRESHOLD_64_BYTES
  959. //! - \b EMAC_MODE_TX_THRESHOLD_128_BYTES
  960. //! - \b EMAC_MODE_TX_THRESHOLD_192_BYTES
  961. //! - \b EMAC_MODE_TX_THRESHOLD_256_BYTES
  962. //!
  963. //! The second field reports the receive FIFO threshold. DMA transfers of
  964. //! received data begin either when the receive FIFO contains a full frame
  965. //! or this number of bytes. This field should be ignored if
  966. //! \b EMAC_MODE_RX_STORE_FORWARD is included. One of the following values
  967. //! is reported:
  968. //!
  969. //! - \b EMAC_MODE_RX_THRESHOLD_64_BYTES
  970. //! - \b EMAC_MODE_RX_THRESHOLD_32_BYTES
  971. //! - \b EMAC_MODE_RX_THRESHOLD_96_BYTES
  972. //! - \b EMAC_MODE_RX_THRESHOLD_128_BYTES
  973. //!
  974. //! The following additional flags may be included:
  975. //!
  976. //! - \b EMAC_MODE_KEEP_BAD_CRC indicates that frames with TCP/IP checksum
  977. //! errors are being forwarded to the application if those frames do not have
  978. //! any errors (including FCS errors) in the Ethernet framing. In these cases,
  979. //! the frames have errors only in the payload. If this flag is not reported,
  980. //! all frames with any detected error are discarded unless
  981. //! \b EMAC_MODE_RX_ERROR_FRAMES is also reported.
  982. //! - \b EMAC_MODE_RX_STORE_FORWARD indicates that the receive DMA is
  983. //! configured to read frames from the FIFO only after the complete frame has
  984. //! been written to it. If this mode is enabled, the receive threshold is
  985. //! ignored.
  986. //! - \b EMAC_MODE_RX_FLUSH_DISABLE indicates that the flushing of received
  987. //! frames is disabled in cases where receive descriptors or buffers are
  988. //! unavailable.
  989. //! - \b EMAC_MODE_TX_STORE_FORWARD indicates that the transmitter is
  990. //! configured to transmit a frame only after the whole frame has been written
  991. //! to the transmit FIFO. If this mode is enabled, the transmit threshold is
  992. //! ignored.
  993. //! - \b EMAC_MODE_RX_ERROR_FRAMES indicates that all frames other than runt
  994. //! error frames are being forwarded to the receive DMA regardless of any
  995. //! errors detected in the frames.
  996. //! - \b EMAC_MODE_RX_UNDERSIZED_FRAMES indicates that undersized frames
  997. //! (frames shorter than 64 bytes but with no errors) are being forwarded to
  998. //! the application. If this option is not reported, all undersized frames are
  999. //! dropped by the receiver unless it has already started transferring them to
  1000. //! the receive FIFO due to the receive threshold setting.
  1001. //! - \b EMAC_MODE_OPERATE_2ND_FRAME indicates that the transmit DMA is
  1002. //! configured to operate on a second frame while waiting for the previous
  1003. //! frame to be transmitted and associated status and timestamps to be reported.
  1004. //! If absent, the transmit DMA works on a single frame at any one time,
  1005. //! waiting for that frame to be transmitted and its status to be received
  1006. //! before moving on to the next frame.
  1007. //! - \b EMAC_MODE_TX_DMA_ENABLED indicates that the transmit DMA engine is
  1008. //! currently enabled.
  1009. //! - \b EMAC_MODE_RX_DMA_ENABLED indicates that the receive DMA engine is
  1010. //! currently enabled.
  1011. //!
  1012. //! The \e pui32RxMaxFrameSize is written with the currently configured maximum
  1013. //! receive packet size. Packets larger than this are flagged as being in
  1014. //! error.
  1015. //!
  1016. //! \return None.
  1017. //
  1018. //*****************************************************************************
  1019. void
  1020. EMACConfigGet(uint32_t ui32Base, uint32_t *pui32Config, uint32_t *pui32Mode,
  1021. uint32_t *pui32RxMaxFrameSize)
  1022. {
  1023. uint32_t ui32Value;
  1024. //
  1025. // Parameter sanity check.
  1026. //
  1027. ASSERT(pui32Mode);
  1028. ASSERT(pui32Config);
  1029. ASSERT(pui32RxMaxFrameSize);
  1030. //
  1031. // Return the mode information from the operation mode register.
  1032. //
  1033. *pui32Mode = HWREG(ui32Base + EMAC_O_DMAOPMODE);
  1034. //
  1035. // Return the current configuration flags from the EMAC_O_CFG register.
  1036. //
  1037. *pui32Config = (HWREG(ui32Base + EMAC_O_CFG) &
  1038. (VALID_CONFIG_FLAGS | EMAC_CONFIG_TX_ENABLED |
  1039. EMAC_CONFIG_RX_ENABLED));
  1040. //
  1041. // Get the receive packet size watchdog value.
  1042. //
  1043. ui32Value = HWREG(ui32Base + EMAC_O_WDOGTO);
  1044. if (ui32Value & EMAC_WDOGTO_PWE)
  1045. {
  1046. //
  1047. // The watchdog is enables so the maximum packet length can be read
  1048. // from the watchdog timeout register.
  1049. //
  1050. *pui32RxMaxFrameSize = ui32Value & EMAC_WDOGTO_WTO_M;
  1051. }
  1052. else
  1053. {
  1054. //
  1055. // The maximum packet size override found in the watchdog timer
  1056. // register is not enabled so the maximum packet size is determined
  1057. // by whether or not jumbo frame mode is enabled.
  1058. //
  1059. if (HWREG(ui32Base + EMAC_O_CFG) & EMAC_CFG_JFEN)
  1060. {
  1061. //
  1062. // Jumbo frames are enabled so the watchdog kicks in at 10240
  1063. // bytes.
  1064. //
  1065. *pui32RxMaxFrameSize = 10240;
  1066. }
  1067. else
  1068. {
  1069. //
  1070. // Jumbo frames are not enabled so the watchdog kicks in at
  1071. // 2048 bytes.
  1072. //
  1073. *pui32RxMaxFrameSize = 2048;
  1074. }
  1075. }
  1076. }
  1077. //*****************************************************************************
  1078. //
  1079. //! Sets the MAC address of the Ethernet controller.
  1080. //!
  1081. //! \param ui32Base is the base address of the Ethernet controller.
  1082. //! \param ui32Index is the zero-based index of the MAC address to set.
  1083. //! \param pui8MACAddr is the pointer to the array of MAC-48 address octets.
  1084. //!
  1085. //! This function programs the IEEE-defined MAC-48 address specified in
  1086. //! \e pui8MACAddr into the Ethernet controller. This address is used by the
  1087. //! Ethernet controller for hardware-level filtering of incoming Ethernet
  1088. //! packets (when promiscuous mode is not enabled). Index 0 is used to hold
  1089. //! the local node's MAC address which is inserted into all transmitted
  1090. //! packets.
  1091. //!
  1092. //! The controller may support several Ethernet MAC address slots, each of which
  1093. //! may be programmed independently and used to filter incoming packets. The
  1094. //! number of MAC addresses that the hardware supports may be queried using a
  1095. //! call to EMACNumAddrGet(). The value of the \e ui32Index parameter must
  1096. //! lie in the range from 0 to (number of MAC addresses - 1) inclusive.
  1097. //!
  1098. //! The MAC-48 address is defined as 6 octets, illustrated by the following
  1099. //! example address. The numbers are shown in hexadecimal format.
  1100. //!
  1101. //! AC-DE-48-00-00-80
  1102. //!
  1103. //! In this representation, the first three octets (AC-DE-48) are the
  1104. //! Organizationally Unique Identifier (OUI). This is a number assigned by
  1105. //! the IEEE to an organization that requests a block of MAC addresses. The
  1106. //! last three octets (00-00-80) are a 24-bit number managed by the OUI owner
  1107. //! to uniquely identify a piece of hardware within that organization that is
  1108. //! to be connected to the Ethernet.
  1109. //!
  1110. //! In this representation, the octets are transmitted from left to right,
  1111. //! with the ``AC'' octet being transmitted first and the ``80'' octet being
  1112. //! transmitted last. Within an octet, the bits are transmitted LSB to MSB.
  1113. //! For this address, the first bit to be transmitted would be ``0'', the LSB
  1114. //! of ``AC'', and the last bit to be transmitted would be ``1'', the MSB of
  1115. //! ``80''.
  1116. //!
  1117. //! The address passed to this function in the \e pui8MACAddr array is
  1118. //! ordered with the first byte to be transmitted in the first array entry.
  1119. //! For example, the address given above could be represented using the
  1120. //! following array:
  1121. //!
  1122. //! uint8_t g_pui8MACAddr[] = { 0xAC, 0xDE, 0x48, 0x00, 0x00, 0x80 };
  1123. //!
  1124. //! If the MAC address set by this function is currently enabled, it remains
  1125. //! enabled following this call. Similarly, any filter configured for
  1126. //! the MAC address remains unaffected by a change in the address.
  1127. //!
  1128. //! \return None.
  1129. //
  1130. //*****************************************************************************
  1131. void
  1132. EMACAddrSet(uint32_t ui32Base, uint32_t ui32Index, const uint8_t *pui8MACAddr)
  1133. {
  1134. //
  1135. // Parameter sanity check.
  1136. //
  1137. ASSERT(ui32Index < NUM_MAC_ADDR);
  1138. ASSERT(pui8MACAddr);
  1139. //
  1140. // Set the high 2 bytes of the MAC address. Note that we must set the
  1141. // registers in this order since the address is latched internally
  1142. // on the write to EMAC_O_ADDRL.
  1143. //
  1144. HWREG(ui32Base + EMAC_O_ADDRH(ui32Index)) =
  1145. ((HWREG(ui32Base + EMAC_O_ADDRH(ui32Index)) & 0xFFFF0000) |
  1146. pui8MACAddr[4] | (pui8MACAddr[5] << 8));
  1147. //
  1148. // Set the first 4 bytes of the MAC address
  1149. //
  1150. HWREG(ui32Base + EMAC_O_ADDRL(ui32Index)) =
  1151. (pui8MACAddr[0] | (pui8MACAddr[1] << 8) | (pui8MACAddr[2] << 16) |
  1152. (pui8MACAddr[3] << 24));
  1153. }
  1154. //*****************************************************************************
  1155. //
  1156. //! Gets one of the MAC addresses stored in the Ethernet controller.
  1157. //!
  1158. //! \param ui32Base is the base address of the controller.
  1159. //! \param ui32Index is the zero-based index of the MAC address to return.
  1160. //! \param pui8MACAddr is the pointer to the location in which to store the
  1161. //! array of MAC-48 address octets.
  1162. //!
  1163. //! This function reads the currently programmed MAC address into the
  1164. //! \e pui8MACAddr buffer. The \e ui32Index parameter defines which of the
  1165. //! hardware's MAC addresses to return. The number of MAC addresses supported
  1166. //! by the controller may be queried using a call to EMACNumAddrGet().
  1167. //! Index 0 refers to the MAC address of the local node. Other indices are
  1168. //! used to define MAC addresses when filtering incoming packets.
  1169. //!
  1170. //! The address is written to the pui8MACAddr array ordered with the first byte
  1171. //! to be transmitted in the first array entry. For example, if the address
  1172. //! is written in its usual form with the Organizationally Unique Identifier
  1173. //! (OUI) shown first as:
  1174. //!
  1175. //! AC-DE-48-00-00-80
  1176. //!
  1177. //! the data is returned with 0xAC in the first byte of the array, 0xDE in
  1178. //! the second, 0x48 in the third and so on.
  1179. //!
  1180. //! \return None.
  1181. //
  1182. //*****************************************************************************
  1183. void
  1184. EMACAddrGet(uint32_t ui32Base, uint32_t ui32Index, uint8_t *pui8MACAddr)
  1185. {
  1186. uint32_t ui32Val;
  1187. //
  1188. // Parameter sanity check.
  1189. //
  1190. ASSERT(ui32Index < NUM_MAC_ADDR);
  1191. ASSERT(pui8MACAddr);
  1192. //
  1193. // Get the first 4 bytes of the MAC address.
  1194. //
  1195. ui32Val = HWREG(ui32Base + EMAC_O_ADDRL(ui32Index));
  1196. pui8MACAddr[0] = ui32Val & 0xFF;
  1197. pui8MACAddr[1] = (ui32Val >> 8) & 0xFF;
  1198. pui8MACAddr[2] = (ui32Val >> 16) & 0xFF;
  1199. pui8MACAddr[3] = (ui32Val >> 24) & 0xFF;
  1200. //
  1201. // Get the last 2 bytes of the MAC address.
  1202. //
  1203. ui32Val = HWREG(ui32Base + EMAC_O_ADDRH(ui32Index));
  1204. pui8MACAddr[4] = ui32Val & 0xFF;
  1205. pui8MACAddr[5] = (ui32Val >> 8) & 0xFF;
  1206. }
  1207. //*****************************************************************************
  1208. //
  1209. //! Returns the number of MAC addresses supported by the Ethernet controller.
  1210. //!
  1211. //! \param ui32Base is the base address of the Ethernet controller.
  1212. //!
  1213. //! This function may be used to determine the number of MAC addresses that the
  1214. //! given controller supports. MAC address slots may be used when performing
  1215. //! perfect (rather than hash table) filtering of packets.
  1216. //!
  1217. //! \return Returns the number of supported MAC addresses.
  1218. //
  1219. //*****************************************************************************
  1220. uint32_t
  1221. EMACNumAddrGet(uint32_t ui32Base)
  1222. {
  1223. //
  1224. // The only Ethernet controller on MSP432E4 supports 4 MAC addresses.
  1225. //
  1226. return (NUM_MAC_ADDR);
  1227. }
  1228. //*****************************************************************************
  1229. //
  1230. //! Sets filtering parameters associated with one of the configured MAC
  1231. //! addresses.
  1232. //!
  1233. //! \param ui32Base is the base address of the controller.
  1234. //! \param ui32Index is the index of the MAC address slot for which the filter
  1235. //! is to be set.
  1236. //! \param ui32Config sets the filter parameters for the given MAC address.
  1237. //!
  1238. //! This function sets filtering parameters associated with one of the MAC
  1239. //! address slots that the controller supports. This configuration is used
  1240. //! when perfect filtering (rather than hash table filtering) is selected.
  1241. //!
  1242. //! Valid values for \e ui32Index are from 1 to (number of MAC address
  1243. //! slots - 1). The number of supported MAC address slots may be found by
  1244. //! calling EMACNumAddrGet(). MAC index 0 is the local MAC address and does
  1245. //! not have filtering parameters associated with it.
  1246. //!
  1247. //! The \e ui32Config parameter determines how the given MAC address is used
  1248. //! when filtering incoming Ethernet frames. It is comprised of a logical OR
  1249. //! of the fields:
  1250. //!
  1251. //! - \b EMAC_FILTER_ADDR_ENABLE indicates that this MAC address is enabled
  1252. //! and should be used when performing perfect filtering. If this flag is
  1253. //! absent, the MAC address at the given index is disabled and is not used
  1254. //! in filtering.
  1255. //! - \b EMAC_FILTER_SOURCE_ADDR indicates that the MAC address at the given
  1256. //! index is compared to the source address of incoming frames while
  1257. //! performing perfect filtering. If absent, the MAC address is compared
  1258. //! against the destination address.
  1259. //! - \b EMAC_FILTER_MASK_BYTE_6 indicates that the MAC should ignore the
  1260. //! sixth byte of the source or destination address when filtering.
  1261. //! - \b EMAC_FILTER_MASK_BYTE_5 indicates that the MAC should ignore the
  1262. //! fifth byte of the source or destination address when filtering.
  1263. //! - \b EMAC_FILTER_MASK_BYTE_4 indicates that the MAC should ignore the
  1264. //! fourth byte of the source or destination address when filtering.
  1265. //! - \b EMAC_FILTER_MASK_BYTE_3 indicates that the MAC should ignore the
  1266. //! third byte of the source or destination address when filtering.
  1267. //! - \b EMAC_FILTER_MASK_BYTE_2 indicates that the MAC should ignore the
  1268. //! second byte of the source or destination address when filtering.
  1269. //! - \b EMAC_FILTER_MASK_BYTE_1 indicates that the MAC should ignore the
  1270. //! first byte of the source or destination address when filtering.
  1271. //!
  1272. //! \return None.
  1273. //
  1274. //*****************************************************************************
  1275. void
  1276. EMACAddrFilterSet(uint32_t ui32Base, uint32_t ui32Index, uint32_t ui32Config)
  1277. {
  1278. uint32_t ui32Val;
  1279. //
  1280. // Parameter sanity check.
  1281. //
  1282. ASSERT(ui32Index < NUM_MAC_ADDR);
  1283. ASSERT((ui32Config & ~(EMAC_FILTER_BYTE_MASK_M |
  1284. EMAC_FILTER_ADDR_ENABLE |
  1285. EMAC_FILTER_SOURCE_ADDR)) == 0);
  1286. ASSERT(ui32Index);
  1287. //
  1288. // Set the filter configuration for a particular MAC address.
  1289. //
  1290. HWREG(ui32Base + EMAC_O_ADDRH(ui32Index)) =
  1291. (HWREG(ui32Base + EMAC_O_ADDRH(ui32Index)) & 0xFFFF) | ui32Config;
  1292. //
  1293. // Read and rewrite the low half of the MAC address register to ensure
  1294. // that the upper half's data is latched.
  1295. //
  1296. ui32Val = HWREG(ui32Base + EMAC_O_ADDRL(ui32Index));
  1297. HWREG(ui32Base + EMAC_O_ADDRL(ui32Index)) = ui32Val;
  1298. }
  1299. //*****************************************************************************
  1300. //
  1301. //! Gets filtering parameters associated with one of the configured MAC
  1302. //! addresses.
  1303. //!
  1304. //! \param ui32Base is the base address of the controller.
  1305. //! \param ui32Index is the index of the MAC address slot for which the filter
  1306. //! is to be queried.
  1307. //!
  1308. //! This function returns filtering parameters associated with one of the MAC
  1309. //! address slots that the controller supports. This configuration is used
  1310. //! when perfect filtering (rather than hash table filtering) is selected.
  1311. //!
  1312. //! Valid values for \e ui32Index are from 1 to (number of MAC address
  1313. //! slots - 1). The number of supported MAC address slots may be found by
  1314. //! calling EMACNumAddrGet(). MAC index 0 is the local MAC address and does
  1315. //! not have filtering parameters associated with it.
  1316. //!
  1317. //! \return Returns the filter configuration as the logical OR of the
  1318. //! following labels:
  1319. //!
  1320. //! - \b EMAC_FILTER_ADDR_ENABLE indicates that this MAC address is enabled
  1321. //! and is used when performing perfect filtering. If this flag is absent,
  1322. //! the MAC address at the given index is disabled and is not used in
  1323. //! filtering.
  1324. //! - \b EMAC_FILTER_SOURCE_ADDR indicates that the MAC address at the given
  1325. //! index is compared to the source address of incoming frames while performing
  1326. //! perfect filtering. If absent, the MAC address is compared against the
  1327. //! destination address.
  1328. //! - \b EMAC_FILTER_MASK_BYTE_6 indicates that the MAC ignores the
  1329. //! sixth byte of the source or destination address when filtering.
  1330. //! - \b EMAC_FILTER_MASK_BYTE_5 indicates that the MAC ignores the
  1331. //! fifth byte of the source or destination address when filtering.
  1332. //! - \b EMAC_FILTER_MASK_BYTE_4 indicates that the MAC ignores the
  1333. //! fourth byte of the source or destination address when filtering.
  1334. //! - \b EMAC_FILTER_MASK_BYTE_3 indicates that the MAC ignores the
  1335. //! third byte of the source or destination address when filtering.
  1336. //! - \b EMAC_FILTER_MASK_BYTE_2 indicates that the MAC ignores the
  1337. //! second byte of the source or destination address when filtering.
  1338. //! - \b EMAC_FILTER_MASK_BYTE_1 indicates that the MAC ignores the
  1339. //! first byte of the source or destination address when filtering.
  1340. //
  1341. //*****************************************************************************
  1342. uint32_t
  1343. EMACAddrFilterGet(uint32_t ui32Base, uint32_t ui32Index)
  1344. {
  1345. //
  1346. // Parameter sanity check.
  1347. //
  1348. ASSERT(ui32Index < NUM_MAC_ADDR);
  1349. ASSERT(ui32Index);
  1350. //
  1351. // Read and return the filter settings for the requested MAC address slot.
  1352. //
  1353. return (HWREG(ui32Base + EMAC_O_ADDRH(ui32Index)) &
  1354. (EMAC_FILTER_BYTE_MASK_M | EMAC_FILTER_ADDR_ENABLE |
  1355. EMAC_FILTER_SOURCE_ADDR));
  1356. }
  1357. //*****************************************************************************
  1358. //
  1359. //! Sets options related to Ethernet frame filtering.
  1360. //!
  1361. //! \param ui32Base is the base address of the controller.
  1362. //! \param ui32FilterOpts is a logical OR of flags defining the required MAC
  1363. //! address filtering options.
  1364. //!
  1365. //! This function allows various filtering options to be defined and allows
  1366. //! an application to control which frames are received based on various
  1367. //! criteria related to the frame source and destination MAC addresses or VLAN
  1368. //! tagging.
  1369. //!
  1370. //! The \e ui32FilterOpts parameter is a logical OR of any of the following
  1371. //! flags:
  1372. //!
  1373. //! - \b EMAC_FRMFILTER_RX_ALL configures the MAC to pass all received frames
  1374. //! regardless of whether or not they pass any address filter that is
  1375. //! configured. The receive status word in the relevant DMA descriptor is
  1376. //! updated to indicate whether the configured filter passed or failed for
  1377. //! the frame.
  1378. //! - \b EMAC_FRMFILTER_VLAN configures the MAC to drop any frames that do
  1379. //! not pass the VLAN tag comparison.
  1380. //! - \b EMAC_FRMFILTER_HASH_AND_PERFECT configures the MAC to filter frames
  1381. //! based on both any perfect filters set and the hash filter if enabled using
  1382. //! \b EMAC_FRMFILTER_HASH_UNICAST or \b EMAC_FRMFILTER_HASH_MULTICAST. In
  1383. //! this case, only if both filters fail is the packet rejected. If this
  1384. //! option is absent, only one of the filter types is used, as controlled by
  1385. //! \b EMAC_FRMFILTER_HASH_UNICAST and \b EMAC_FRMFILTER_HASH_MULTICAST
  1386. //! for unicast and multicast frames respectively.
  1387. //! - \b EMAC_FRMFILTER_SADDR configures the MAC to drop received frames
  1388. //! when the source address field in the frame does not match the values
  1389. //! programmed into the enabled SA registers.
  1390. //! - \b EMAC_FRMFILTER_INV_SADDR enables inverse source address filtering.
  1391. //! When this option is specified, frames for which the SA does not match the
  1392. //! SA registers are marked as passing the source address filter.
  1393. //! - \b EMAC_FRMFILTER_BROADCAST configures the MAC to discard all incoming
  1394. //! broadcast frames.
  1395. //! - \b EMAC_FRMFILTER_PASS_MULTICAST configures the MAC to pass all
  1396. //! incoming frames with multicast destinations addresses.
  1397. //! - \b EMAC_FRMFILTER_INV_DADDR inverts the sense of the destination
  1398. //! address filtering for both unicast and multicast frames.
  1399. //! - \b EMAC_FRMFILTER_HASH_MULTICAST enables destination address filtering
  1400. //! of received multicast frames using the hash table. If absent, perfect
  1401. //! destination address filtering is used. If used in conjunction with \b
  1402. //! EMAC_FRMFILTER_HASH_AND_PERFECT, this flag indicates that the hash filter
  1403. //! should be used for incoming multicast packets along with the perfect
  1404. //! filter.
  1405. //! - \b EMAC_FRMFILTER_HASH_UNICAST enables destination address filtering
  1406. //! of received unicast frames using the hash table. If absent, perfect
  1407. //! destination address filtering is used. If used in conjunction with \b
  1408. //! EMAC_FRMFILTER_HASH_AND_PERFECT, this flag indicates that the hash filter
  1409. //! should be used for incoming unicast packets along with the perfect filter.
  1410. //! - \b EMAC_FRMFILTER_PROMISCUOUS configures the MAC to operate in
  1411. //! promiscuous mode where all received frames are passed to the application
  1412. //! and the SA and DA filter status bits of the descriptor receive status word
  1413. //! are always cleared.
  1414. //!
  1415. //! Control frame filtering may be configured by ORing one of the following
  1416. //! values into \e ui32FilterOpts:
  1417. //!
  1418. //! - \b EMAC_FRMFILTER_PASS_NO_CTRL prevents any control frame from reaching
  1419. //! the application.
  1420. //! - \b EMAC_FRMFILTER_PASS_NO_PAUSE passes all control frames other than
  1421. //! PAUSE even if they fail the configured address filter.
  1422. //! - \b EMAC_FRMFILTER_PASS_ALL_CTRL passes all control frames, including
  1423. //! PAUSE even if they fail the configured address filter.
  1424. //! - \b EMAC_FRMFILTER_PASS_ADDR_CTRL passes all control frames only if they
  1425. //! pass the configured address filter.
  1426. //!
  1427. //! \return None.
  1428. //
  1429. //*****************************************************************************
  1430. void
  1431. EMACFrameFilterSet(uint32_t ui32Base, uint32_t ui32FilterOpts)
  1432. {
  1433. ASSERT((ui32FilterOpts & ~VALID_FRMFILTER_FLAGS) == 0);
  1434. //
  1435. // Set the Ethernet MAC frame filter according to the flags passed.
  1436. //
  1437. HWREG(ui32Base + EMAC_O_FRAMEFLTR) =
  1438. ((HWREG(ui32Base + EMAC_O_FRAMEFLTR) & ~VALID_FRMFILTER_FLAGS) |
  1439. ui32FilterOpts);
  1440. }
  1441. //*****************************************************************************
  1442. //
  1443. //! Returns the current Ethernet frame filtering settings.
  1444. //!
  1445. //! \param ui32Base is the base address of the controller.
  1446. //!
  1447. //! This function may be called to retrieve the frame filtering configuration
  1448. //! set using a prior call to EMACFrameFilterSet().
  1449. //!
  1450. //! \return Returns a value comprising the logical OR of various flags
  1451. //! indicating the frame filtering options in use. Possible flags are:
  1452. //!
  1453. //! - \b EMAC_FRMFILTER_RX_ALL indicates that the MAC to is configured to
  1454. //! pass all received frames regardless of whether or not they pass any
  1455. //! address filter that is configured. The receive status word in the
  1456. //! relevant DMA descriptor is updated to indicate whether the configured
  1457. //! filter passed or failed for the frame.
  1458. //! - \b EMAC_FRMFILTER_VLAN indicates that the MAC is configured to drop any
  1459. //! frames which do not pass the VLAN tag comparison.
  1460. //! - \b EMAC_FRMFILTER_HASH_AND_PERFECT indicates that the MAC is configured
  1461. //! to pass frames if they match either the hash filter or the perfect filter.
  1462. //! If this flag is absent, frames passing based on the result of a single
  1463. //! filter, the perfect filter if \b EMAC_FRMFILTER_HASH_MULTICAST or
  1464. //! \b EMAC_FRMFILTER_HASH_UNICAST are clear or the hash filter otherwise.
  1465. //! - \b EMAC_FRMFILTER_SADDR indicates that the MAC is configured to drop
  1466. //! received frames when the source address field in the frame does not match
  1467. //! the values programmed into the enabled SA registers.
  1468. //! - \b EMAC_FRMFILTER_INV_SADDR enables inverse source address filtering.
  1469. //! When this option is specified, frames for which the SA does not match the
  1470. //! SA registers are marked as passing the source address filter.
  1471. //! - \b EMAC_FRMFILTER_BROADCAST indicates that the MAC is configured to
  1472. //! discard all incoming broadcast frames.
  1473. //! - \b EMAC_FRMFILTER_PASS_MULTICAST indicates that the MAC is configured
  1474. //! to pass all incoming frames with multicast destinations addresses.
  1475. //! - \b EMAC_FRMFILTER_INV_DADDR indicates that the sense of the destination
  1476. //! address filtering for both unicast and multicast frames is inverted.
  1477. //! - \b EMAC_FRMFILTER_HASH_MULTICAST indicates that destination address
  1478. //! filtering of received multicast frames is enabled using the hash table. If
  1479. //! absent, perfect destination address filtering is used. If used in
  1480. //! conjunction with \b EMAC_FRMFILTER_HASH_AND_PERFECT, this flag indicates
  1481. //! that the hash filter should be used for incoming multicast packets along
  1482. //! with the perfect filter.
  1483. //! - \b EMAC_FRMFILTER_HASH_UNICAST indicates that destination address
  1484. //! filtering of received unicast frames is enabled using the hash table. If
  1485. //! absent, perfect destination address filtering is used. If used in
  1486. //! conjunction with \b EMAC_FRMFILTER_HASH_AND_PERFECT, this flag indicates
  1487. //! that the hash filter should be used for incoming unicast packets along with
  1488. //! the perfect filter.
  1489. //! - \b EMAC_FRMFILTER_PROMISCUOUS indicates that the MAC is configured to
  1490. //! operate in promiscuous mode where all received frames are passed to the
  1491. //! application and the SA and DA filter status bits of the descriptor receive
  1492. //! status word are always cleared.
  1493. //!
  1494. //! Control frame filtering configuration is indicated by one of the following
  1495. //! values which may be extracted from the returned value using the mask
  1496. //! \b EMAC_FRMFILTER_PASS_MASK:
  1497. //!
  1498. //! - \b EMAC_FRMFILTER_PASS_NO_CTRL prevents any control frame from reaching
  1499. //! the application.
  1500. //! - \b EMAC_FRMFILTER_PASS_NO_PAUSE passes all control frames other than
  1501. //! PAUSE even if they fail the configured address filter.
  1502. //! - \b EMAC_FRMFILTER_PASS_ALL_CTRL passes all control frames, including
  1503. //! PAUSE even if they fail the configured address filter.
  1504. //! - \b EMAC_FRMFILTER_PASS_ADDR_CTRL passes all control frames only if they
  1505. //! pass the configured address filter.
  1506. //
  1507. //*****************************************************************************
  1508. uint32_t
  1509. EMACFrameFilterGet(uint32_t ui32Base)
  1510. {
  1511. //
  1512. // Return the current MAC frame filter setting.
  1513. //
  1514. return (HWREG(ui32Base + EMAC_O_FRAMEFLTR) & VALID_FRMFILTER_FLAGS);
  1515. }
  1516. //*****************************************************************************
  1517. //
  1518. //! Sets the MAC address hash filter table.
  1519. //!
  1520. //! \param ui32Base is the base address of the controller.
  1521. //! \param ui32HashHi is the upper 32 bits of the current 64-bit hash filter
  1522. //! table to set.
  1523. //! \param ui32HashLo is the lower 32 bits of the current 64-bit hash filter
  1524. //! table to set.
  1525. //!
  1526. //! This function may be used to set the current 64-bit hash filter table
  1527. //! used by the MAC to filter incoming packets when hash filtering is enabled.
  1528. //! Hash filtering is enabled by passing \b EMAC_FRMFILTER_HASH_UNICAST
  1529. //! and/or \b EMAC_FRMFILTER_HASH_MULTICAST in the \e ui32FilterOpts parameter
  1530. //! to EMACFrameFilterSet(). The current hash filter may be retrieved
  1531. //! by calling EMACHashFilterGet().
  1532. //!
  1533. //! Hash table filtering allows many different MAC addresses to be filtered
  1534. //! simultaneously at the cost of some false-positive results (in the form of
  1535. //! packets passing the filter when their MAC address was not one of those
  1536. //! required). A CRC of the packet source or destination MAC address is
  1537. //! calculated and the bottom 6 bits are used as a bit index into the 64-bit
  1538. //! hash filter table. If the bit in the hash table is set, the filter is
  1539. //! considered to have passed. If the bit is clear, the filter fails and the
  1540. //! packet is rejected (assuming normal rather than inverse filtering is
  1541. //! configured).
  1542. //!
  1543. //! \return None.
  1544. //
  1545. //*****************************************************************************
  1546. void
  1547. EMACHashFilterSet(uint32_t ui32Base, uint32_t ui32HashHi, uint32_t ui32HashLo)
  1548. {
  1549. // Set the hash table with the values provided.
  1550. HWREG(ui32Base + EMAC_O_HASHTBLL) = ui32HashLo;
  1551. HWREG(ui32Base + EMAC_O_HASHTBLH) = ui32HashHi;
  1552. }
  1553. //*****************************************************************************
  1554. //
  1555. //! Returns the current MAC address hash filter table.
  1556. //!
  1557. //! \param ui32Base is the base address of the controller.
  1558. //! \param pui32HashHi points to storage to be written with the upper 32 bits
  1559. //! of the current 64-bit hash filter table.
  1560. //! \param pui32HashLo points to storage to be written with the lower 32 bits
  1561. //! of the current 64-bit hash filter table.
  1562. //!
  1563. //! This function may be used to retrieve the current 64-bit hash filter table
  1564. //! from the MAC prior to making changes and setting the new hash filter via a
  1565. //! call to EMACHashFilterSet().
  1566. //!
  1567. //! Hash table filtering allows many different MAC addresses to be filtered
  1568. //! simultaneously at the cost of some false-positive results in the form of
  1569. //! packets passing the filter when their MAC address was not one of those
  1570. //! required. A CRC of the packet source or destination MAC address is
  1571. //! calculated and the bottom 6 bits are used as a bit index into the 64-bit
  1572. //! hash filter table. If the bit in the hash table is set, the filter is
  1573. //! considered to have passed. If the bit is clear, the filter fails and the
  1574. //! packet is rejected (assuming normal rather than inverse filtering is
  1575. //! configured).
  1576. //!
  1577. //! \return None.
  1578. //
  1579. //*****************************************************************************
  1580. void
  1581. EMACHashFilterGet(uint32_t ui32Base, uint32_t *pui32HashHi,
  1582. uint32_t *pui32HashLo)
  1583. {
  1584. ASSERT(pui32HashHi);
  1585. ASSERT(pui32HashLo);
  1586. //
  1587. // Get the current hash table values.
  1588. //
  1589. *pui32HashLo = HWREG(ui32Base + EMAC_O_HASHTBLL);
  1590. *pui32HashHi = HWREG(ui32Base + EMAC_O_HASHTBLH);
  1591. }
  1592. //*****************************************************************************
  1593. //
  1594. //! Returns the bit number to set in the MAC hash filter corresponding to a
  1595. //! given MAC address.
  1596. //!
  1597. //! \param pui8MACAddr points to a buffer containing the 6-byte MAC address
  1598. //! for which the hash filter bit is to be determined.
  1599. //!
  1600. //! This function may be used to determine which bit in the MAC address hash
  1601. //! filter to set to describe a given 6-byte MAC address. The returned value is
  1602. //! a 6-bit number where bit 5 indicates which of the two hash table words is
  1603. //! affected and the bottom 5 bits indicate the bit number to set within that
  1604. //! word. For example, if 0x22 (100010b) is returned, this indicates that bit
  1605. //! 2 of word 1 (\e ui32HashHi as passed to EMACHashFilterSet()) must be set
  1606. //! to describe the passed MAC address.
  1607. //!
  1608. //! \return Returns the bit number to set in the MAC hash table to describe the
  1609. //! passed MAC address.
  1610. //
  1611. //*****************************************************************************
  1612. uint32_t
  1613. EMACHashFilterBitCalculate(uint8_t *pui8MACAddr)
  1614. {
  1615. uint32_t ui32CRC, ui32Mask, ui32Loop;
  1616. //
  1617. // Parameter sanity check.
  1618. //
  1619. ASSERT(pui8MACAddr);
  1620. //
  1621. // Calculate the CRC for the MAC address.
  1622. //
  1623. ui32CRC = Crc32(0xFFFFFFFF, pui8MACAddr, 6);
  1624. ui32CRC ^= 0xFFFFFFFF;
  1625. //
  1626. // Determine the hash bit to use from the calculated CRC. This is the
  1627. // top 6 bits of the reversed CRC (or the bottom 6 bits of the calculated
  1628. // CRC with the bit order of those 6 bits reversed).
  1629. //
  1630. ui32Mask = 0;
  1631. //
  1632. // Reverse the order of the bottom 6 bits of the calculated CRC.
  1633. //
  1634. for (ui32Loop = 0; ui32Loop < 6; ui32Loop++)
  1635. {
  1636. ui32Mask <<= 1;
  1637. ui32Mask |= (ui32CRC & 1);
  1638. ui32CRC >>= 1;
  1639. }
  1640. //
  1641. // Return the final hash table bit index.
  1642. //
  1643. return (ui32Mask);
  1644. }
  1645. //*****************************************************************************
  1646. //
  1647. //! Sets the receive interrupt watchdog timer period.
  1648. //!
  1649. //! \param ui32Base is the base address of the Ethernet controller.
  1650. //! \param ui8Timeout is the desired timeout expressed as a number of 256
  1651. //! system clock periods.
  1652. //!
  1653. //! This function configures the receive interrupt watchdog timer.
  1654. //! The \e uiTimeout parameter specifies the number of 256 system clock periods
  1655. //! that elapse before the timer expires. In cases where the DMA has
  1656. //! transferred a frame using a descriptor that has
  1657. //! \b DES1_RX_CTRL_DISABLE_INT set, the watchdog causes a receive
  1658. //! interrupt to be generated when it times out. The watchdog timer is reset
  1659. //! whenever a packet is transferred to memory using a DMA descriptor that
  1660. //! does not disable the receive interrupt.
  1661. //!
  1662. //! To disable the receive interrupt watchdog function, set \e ui8Timeout to 0.
  1663. //!
  1664. //! \return None.
  1665. //
  1666. //*****************************************************************************
  1667. void
  1668. EMACRxWatchdogTimerSet(uint32_t ui32Base, uint8_t ui8Timeout)
  1669. {
  1670. //
  1671. // Set the receive interrupt watchdog timeout period.
  1672. //
  1673. HWREG(ui32Base + EMAC_O_RXINTWDT) = (uint32_t)ui8Timeout;
  1674. }
  1675. //*****************************************************************************
  1676. //
  1677. //! Returns the current Ethernet MAC status.
  1678. //!
  1679. //! \param ui32Base is the base address of the Ethernet controller.
  1680. //!
  1681. //! This function returns information on the current status of all the main
  1682. //! modules in the MAC transmit and receive data paths.
  1683. //!
  1684. //! \return Returns the current MAC status as a logical OR of any of the
  1685. //! following flags:
  1686. //!
  1687. //! - \b EMAC_STATUS_TX_NOT_EMPTY
  1688. //! - \b EMAC_STATUS_TX_WRITING_FIFO
  1689. //! - \b EMAC_STATUS_TX_PAUSED
  1690. //! - \b EMAC_STATUS_MAC_NOT_IDLE
  1691. //! - \b EMAC_STATUS_RWC_ACTIVE
  1692. //! - \b EMAC_STATUS_RPE_ACTIVE
  1693. //!
  1694. //! The transmit frame controller status can be extracted from the returned
  1695. //! value by ANDing with \b EMAC_STATUS_TFC_STATE_MASK and is one of the
  1696. //! following:
  1697. //!
  1698. //! - \b EMAC_STATUS_TFC_STATE_IDLE
  1699. //! - \b EMAC_STATUS_TFC_STATE_WAITING
  1700. //! - \b EMAC_STATUS_TFC_STATE_PAUSING
  1701. //! - \b EMAC_STATUS_TFC_STATE_WRITING
  1702. //!
  1703. //! The transmit FIFO read controller status can be extracted from the returned
  1704. //! value by ANDing with \b EMAC_STATUS_TRC_STATE_MASK and is one of the
  1705. //! following:
  1706. //!
  1707. //! - \b EMAC_STATUS_TRC_STATE_IDLE
  1708. //! - \b EMAC_STATUS_TRC_STATE_READING
  1709. //! - \b EMAC_STATUS_TRC_STATE_WAITING
  1710. //! - \b EMAC_STATUS_TRC_STATE_STATUS
  1711. //!
  1712. //! The current receive FIFO levels can be extracted from the returned value
  1713. //! by ANDing with \b EMAC_STATUS_RX_FIFO_LEVEL_MASK and is one of the
  1714. //! following:
  1715. //!
  1716. //! - \b EMAC_STATUS_RX_FIFO_EMPTY indicating that the FIFO is empty.
  1717. //! - \b EMAC_STATUS_RX_FIFO_BELOW indicating that the FIFO fill level is
  1718. //! below the flow-control deactivate threshold.
  1719. //! - \b EMAC_STATUS_RX_FIFO_ABOVE indicating that the FIFO fill level is
  1720. //! above the flow-control activate threshold.
  1721. //! - \b EMAC_STATUS_RX_FIFO_FULL indicating that the FIFO is full.
  1722. //!
  1723. //! The current receive FIFO state can be extracted from the returned value
  1724. //! by ANDing with \b EMAC_STATUS_RX_FIFO_STATE_MASK and is one of the
  1725. //! following:
  1726. //!
  1727. //! - \b EMAC_STATUS_RX_FIFO_IDLE
  1728. //! - \b EMAC_STATUS_RX_FIFO_READING
  1729. //! - \b EMAC_STATUS_RX_FIFO_STATUS
  1730. //! - \b EMAC_STATUS_RX_FIFO_FLUSHING
  1731. //
  1732. //*****************************************************************************
  1733. uint32_t
  1734. EMACStatusGet(uint32_t ui32Base)
  1735. {
  1736. //
  1737. // Read and return the MAC status register content.
  1738. //
  1739. return (HWREG(ui32Base + EMAC_O_STATUS));
  1740. }
  1741. //*****************************************************************************
  1742. //
  1743. //! Orders the MAC DMA controller to attempt to acquire the next transmit
  1744. //! descriptor.
  1745. //!
  1746. //! \param ui32Base is the base address of the Ethernet controller.
  1747. //!
  1748. //! This function must be called to restart the transmitter if it has been
  1749. //! suspended due to the current transmit DMA descriptor being owned by the
  1750. //! host. Once the application writes new values to the descriptor and marks
  1751. //! it as being owned by the MAC DMA, this function causes the hardware to
  1752. //! attempt to acquire the descriptor and start transmission of the new
  1753. //! data.
  1754. //!
  1755. //! \return None.
  1756. //
  1757. //*****************************************************************************
  1758. void
  1759. EMACTxDMAPollDemand(uint32_t ui32Base)
  1760. {
  1761. //
  1762. // Any write to the MACTXPOLLD register causes the transmit DMA to attempt
  1763. // to resume.
  1764. //
  1765. HWREG(ui32Base + EMAC_O_TXPOLLD) = 0;
  1766. }
  1767. //*****************************************************************************
  1768. //
  1769. //! Orders the MAC DMA controller to attempt to acquire the next receive
  1770. //! descriptor.
  1771. //!
  1772. //! \param ui32Base is the base address of the Ethernet controller.
  1773. //!
  1774. //! This function must be called to restart the receiver if it has been
  1775. //! suspended due to the current receive DMA descriptor being owned by the
  1776. //! host. Once the application reads any data from the descriptor and marks
  1777. //! it as being owned by the MAC DMA, this function causes the hardware to
  1778. //! attempt to acquire the descriptor before writing the next received packet
  1779. //! into its buffer(s).
  1780. //!
  1781. //! \return None.
  1782. //
  1783. //*****************************************************************************
  1784. void
  1785. EMACRxDMAPollDemand(uint32_t ui32Base)
  1786. {
  1787. //
  1788. // Any write to the MACRXPOLLD register causes the receive DMA to attempt
  1789. // to resume.
  1790. //
  1791. HWREG(ui32Base + EMAC_O_RXPOLLD) = 0;
  1792. }
  1793. //*****************************************************************************
  1794. //
  1795. //! Sets the DMA receive descriptor list pointer.
  1796. //!
  1797. //! \param ui32Base is the base address of the controller.
  1798. //! \param pDescriptor points to the first DMA descriptor in the list to
  1799. //! be passed to the receive DMA engine.
  1800. //!
  1801. //! This function sets the Ethernet MAC's receive DMA descriptor list pointer.
  1802. //! The \e pDescriptor pointer must point to one or more descriptor
  1803. //! structures.
  1804. //!
  1805. //! When multiple descriptors are provided, they can be either chained or
  1806. //! unchained. Chained descriptors are indicated by setting the
  1807. //! \b DES0_TX_CTRL_CHAINED or \b DES1_RX_CTRL_CHAINED bit in the relevant
  1808. //! word of the transmit or receive descriptor. If this bit is clear,
  1809. //! unchained descriptors are assumed.
  1810. //!
  1811. //! Chained descriptors use a link pointer in each descriptor to
  1812. //! point to the next descriptor in the chain.
  1813. //!
  1814. //! Unchained descriptors are assumed to be contiguous in memory with a
  1815. //! consistent offset between the start of one descriptor and the next.
  1816. //! If unchained descriptors are used, the \e pvLink field in the descriptor
  1817. //! becomes available to store a second buffer pointer, allowing each
  1818. //! descriptor to point to two buffers rather than one. In this case,
  1819. //! the \e ui32DescSkipSize parameter to EMACInit() must previously have
  1820. //! been set to the number of words between the end of one descriptor and
  1821. //! the start of the next. This value must be 0 in cases where a packed array
  1822. //! of \b tEMACDMADescriptor structures is used. If the application wishes to
  1823. //! add new state fields to the end of the descriptor structure, the skip size
  1824. //! should be set to accommodate the newly sized structure.
  1825. //!
  1826. //! Applications are responsible for initializing all descriptor fields
  1827. //! appropriately before passing the descriptor list to the hardware.
  1828. //!
  1829. //! \return None.
  1830. //
  1831. //*****************************************************************************
  1832. void
  1833. EMACRxDMADescriptorListSet(uint32_t ui32Base, tEMACDMADescriptor *pDescriptor)
  1834. {
  1835. //
  1836. // Parameter sanity check.
  1837. //
  1838. ASSERT(pDescriptor);
  1839. ASSERT(((uint32_t)pDescriptor & 3) == 0);
  1840. //
  1841. // Write the supplied address to the MACRXDLADDR register.
  1842. //
  1843. HWREG(ui32Base + EMAC_O_RXDLADDR) = (uint32_t)pDescriptor;
  1844. }
  1845. //*****************************************************************************
  1846. //
  1847. //! Returns a pointer to the start of the DMA receive descriptor list.
  1848. //!
  1849. //! \param ui32Base is the base address of the controller.
  1850. //!
  1851. //! This function returns a pointer to the head of the Ethernet MAC's receive
  1852. //! DMA descriptor list. This value corresponds to the pointer originally set
  1853. //! using a call to EMACRxDMADescriptorListSet().
  1854. //!
  1855. //! \return Returns a pointer to the start of the DMA receive descriptor list.
  1856. //
  1857. //*****************************************************************************
  1858. tEMACDMADescriptor *
  1859. EMACRxDMADescriptorListGet(uint32_t ui32Base)
  1860. {
  1861. //
  1862. // Return the current receive DMA descriptor list pointer.
  1863. //
  1864. return ((tEMACDMADescriptor *)HWREG(ui32Base + EMAC_O_RXDLADDR));
  1865. }
  1866. //*****************************************************************************
  1867. //
  1868. //! Returns the current DMA receive descriptor pointer.
  1869. //!
  1870. //! \param ui32Base is the base address of the controller.
  1871. //!
  1872. //! This function returns a pointer to the current Ethernet receive descriptor
  1873. //! read by the DMA.
  1874. //!
  1875. //! \return Returns a pointer to the start of the current receive DMA
  1876. //! descriptor.
  1877. //
  1878. //*****************************************************************************
  1879. tEMACDMADescriptor *
  1880. EMACRxDMACurrentDescriptorGet(uint32_t ui32Base)
  1881. {
  1882. //
  1883. // Return the address of the current receive descriptor written by the DMA.
  1884. //
  1885. return ((tEMACDMADescriptor *)HWREG(ui32Base + EMAC_O_HOSRXDESC));
  1886. }
  1887. //*****************************************************************************
  1888. //
  1889. //! Returns the current DMA receive buffer pointer.
  1890. //!
  1891. //! \param ui32Base is the base address of the controller.
  1892. //!
  1893. //! This function may be called to determine which buffer the receive DMA
  1894. //! engine is currently writing to.
  1895. //!
  1896. //! \return Returns the receive buffer address currently being written by
  1897. //! the DMA engine.
  1898. //
  1899. //*****************************************************************************
  1900. uint8_t *
  1901. EMACRxDMACurrentBufferGet(uint32_t ui32Base)
  1902. {
  1903. //
  1904. // Return the receive buffer address currently being written by the DMA.
  1905. //
  1906. return ((uint8_t *)HWREG(ui32Base + EMAC_O_HOSRXBA));
  1907. }
  1908. //*****************************************************************************
  1909. //
  1910. //! Sets the DMA transmit descriptor list pointer.
  1911. //!
  1912. //! \param ui32Base is the base address of the controller.
  1913. //! \param pDescriptor points to the first DMA descriptor in the list to
  1914. //! be passed to the transmit DMA engine.
  1915. //!
  1916. //! This function sets the Ethernet MAC's transmit DMA descriptor list pointer.
  1917. //! The \e pDescriptor pointer must point to one or more descriptor
  1918. //! structures.
  1919. //!
  1920. //! When multiple descriptors are provided, they can be either chained or
  1921. //! unchained. Chained descriptors are indicated by setting the
  1922. //! \b DES0_TX_CTRL_CHAINED or \b DES1_RX_CTRL_CHAINED bit in the relevant
  1923. //! word of the transmit or receive descriptor. If this bit is clear,
  1924. //! unchained descriptors are assumed.
  1925. //!
  1926. //! Chained descriptors use a link pointer in each descriptor to
  1927. //! point to the next descriptor in the chain.
  1928. //!
  1929. //! Unchained descriptors are assumed to be contiguous in memory with a
  1930. //! consistent offset between the start of one descriptor and the next.
  1931. //! If unchained descriptors are used, the \e pvLink field in the descriptor
  1932. //! becomes available to store a second buffer pointer, allowing each
  1933. //! descriptor to point to two buffers rather than one. In this case,
  1934. //! the \e ui32DescSkipSize parameter to EMACInit() must previously have
  1935. //! been set to the number of words between the end of one descriptor and
  1936. //! the start of the next. This value must be 0 in cases where a packed array
  1937. //! of \b tEMACDMADescriptor structures is used. If the application wishes to
  1938. //! add new state fields to the end of the descriptor structure, the skip size
  1939. //! should be set to accommodate the newly sized structure.
  1940. //!
  1941. //! Applications are responsible for initializing all descriptor fields
  1942. //! appropriately before passing the descriptor list to the hardware.
  1943. //!
  1944. //! \return None.
  1945. //
  1946. //*****************************************************************************
  1947. void
  1948. EMACTxDMADescriptorListSet(uint32_t ui32Base, tEMACDMADescriptor *pDescriptor)
  1949. {
  1950. //
  1951. // Parameter sanity check.
  1952. //
  1953. ASSERT(pDescriptor);
  1954. ASSERT(((uint32_t)pDescriptor & 3) == 0);
  1955. //
  1956. // Write the supplied address to the MACTXDLADDR register.
  1957. //
  1958. HWREG(ui32Base + EMAC_O_TXDLADDR) = (uint32_t)pDescriptor;
  1959. }
  1960. //*****************************************************************************
  1961. //
  1962. //! Returns a pointer to the start of the DMA transmit descriptor list.
  1963. //!
  1964. //! \param ui32Base is the base address of the controller.
  1965. //!
  1966. //! This function returns a pointer to the head of the Ethernet MAC's transmit
  1967. //! DMA descriptor list. This value corresponds to the pointer originally set
  1968. //! using a call to EMACTxDMADescriptorListSet().
  1969. //!
  1970. //! \return Returns a pointer to the start of the DMA transmit descriptor list.
  1971. //
  1972. //*****************************************************************************
  1973. tEMACDMADescriptor *
  1974. EMACTxDMADescriptorListGet(uint32_t ui32Base)
  1975. {
  1976. //
  1977. // Return the current transmit DMA descriptor list pointer.
  1978. //
  1979. return ((tEMACDMADescriptor *)HWREG(ui32Base + EMAC_O_TXDLADDR));
  1980. }
  1981. //*****************************************************************************
  1982. //
  1983. //! Returns the current DMA transmit descriptor pointer.
  1984. //!
  1985. //! \param ui32Base is the base address of the controller.
  1986. //!
  1987. //! This function returns a pointer to the current Ethernet transmit descriptor
  1988. //! read by the DMA.
  1989. //!
  1990. //! \return Returns a pointer to the start of the current transmit DMA
  1991. //! descriptor.
  1992. //
  1993. //*****************************************************************************
  1994. tEMACDMADescriptor *
  1995. EMACTxDMACurrentDescriptorGet(uint32_t ui32Base)
  1996. {
  1997. //
  1998. // Return the address of the current transmit descriptor read by the DMA.
  1999. //
  2000. return ((tEMACDMADescriptor *)HWREG(ui32Base + EMAC_O_HOSTXDESC));
  2001. }
  2002. //*****************************************************************************
  2003. //
  2004. //! Returns the current DMA transmit buffer pointer.
  2005. //!
  2006. //! \param ui32Base is the base address of the controller.
  2007. //!
  2008. //! This function may be called to determine which buffer the transmit DMA
  2009. //! engine is currently reading from.
  2010. //!
  2011. //! \return Returns the transmit buffer address currently being read by the
  2012. //! DMA engine.
  2013. //
  2014. //*****************************************************************************
  2015. uint8_t *
  2016. EMACTxDMACurrentBufferGet(uint32_t ui32Base)
  2017. {
  2018. //
  2019. // Return the transmit buffer address currently being read by the DMA.
  2020. //
  2021. return ((uint8_t *)HWREG(ui32Base + EMAC_O_HOSTXBA));
  2022. }
  2023. //*****************************************************************************
  2024. //
  2025. //! Returns the current states of the Ethernet MAC transmit and receive DMA
  2026. //! engines.
  2027. //!
  2028. //! \param ui32Base is the base address of the controller.
  2029. //!
  2030. //! This function may be used to query the current states of the transmit and
  2031. //! receive DMA engines. The return value contains two fields, one providing
  2032. //! the transmit state and the other the receive state. Macros
  2033. //! \b EMAC_TX_DMA_STATE() and \b EMAC_RX_DMA_STATE() may be used to
  2034. //! extract these fields from the returned value. Alternatively, masks
  2035. //! \b EMAC_DMA_TXSTAT_MASK and \b EMAC_DMA_RXSTAT_MASK may be used
  2036. //! directly to mask out the individual states from the returned value.
  2037. //!
  2038. //! \return Returns the states of the transmit and receive DMA engines. These
  2039. //! states are ORed together into a single word containing one of:
  2040. //!
  2041. //! - \b EMAC_DMA_TXSTAT_STOPPED indicating that the transmit engine is
  2042. //! stopped.
  2043. //! - \b EMAC_DMA_TXSTAT_RUN_FETCH_DESC indicating that the transmit engine
  2044. //! is fetching the next descriptor.
  2045. //! - \b EMAC_DMA_TXSTAT_RUN_WAIT_STATUS indicating that the transmit engine
  2046. //! is waiting for status from the MAC.
  2047. //! - \b EMAC_DMA_TXSTAT_RUN_READING indicating that the transmit engine is
  2048. //! currently transferring data from memory to the MAC transmit FIFO.
  2049. //! - \b EMAC_DMA_TXSTAT_RUN_CLOSE_DESC indicating that the transmit engine
  2050. //! is closing the descriptor after transmission of the buffer data.
  2051. //! - \b EMAC_DMA_TXSTAT_TS_WRITE indicating that the transmit engine is
  2052. //! currently writing timestamp information to the descriptor.
  2053. //! - \b EMAC_DMA_TXSTAT_SUSPENDED indicating that the transmit engine is
  2054. //! suspended due to the next descriptor being unavailable (owned by the host)
  2055. //! or a transmit buffer underflow.
  2056. //!
  2057. //! and one of:
  2058. //!
  2059. //! - \b EMAC_DMA_RXSTAT_STOPPED indicating that the receive engine is
  2060. //! stopped.
  2061. //! - \b EMAC_DMA_RXSTAT_RUN_FETCH_DESC indicating that the receive engine
  2062. //! is fetching the next descriptor.
  2063. //! - \b EMAC_DMA_RXSTAT_RUN_WAIT_PACKET indicating that the receive engine
  2064. //! is waiting for the next packet.
  2065. //! - \b EMAC_DMA_RXSTAT_SUSPENDED indicating that the receive engine is
  2066. //! suspended due to the next descriptor being unavailable.
  2067. //! - \b EMAC_DMA_RXSTAT_RUN_CLOSE_DESC indicating that the receive engine
  2068. //! is closing the descriptor after receiving a buffer of data.
  2069. //! - \b EMAC_DMA_RXSTAT_TS_WRITE indicating that the transmit engine is
  2070. //! currently writing timestamp information to the descriptor.
  2071. //! - \b EMAC_DMA_RXSTAT_RUN_RECEIVING indicating that the receive engine is
  2072. //! currently transferring data from the MAC receive FIFO to memory.
  2073. //!
  2074. //! Additionally, a DMA bus error may be signaled using \b EMAC_DMA_ERROR.
  2075. //! If this flag is present, the source of the error is identified using one
  2076. //! of the following values which may be extracted from the return value using
  2077. //! \b EMAC_DMA_ERR_MASK:
  2078. //!
  2079. //! - \b EMAC_DMA_ERR_RX_DATA_WRITE indicates that an error occurred when
  2080. //! writing received data to memory.
  2081. //! - \b EMAC_DMA_ERR_TX_DATA_READ indicates that an error occurred when
  2082. //! reading data from memory for transmission.
  2083. //! - \b EMAC_DMA_ERR_RX_DESC_WRITE indicates that an error occurred when
  2084. //! writing to the receive descriptor.
  2085. //! - \b EMAC_DMA_ERR_TX_DESC_WRITE indicates that an error occurred when
  2086. //! writing to the transmit descriptor.
  2087. //! - \b EMAC_DMA_ERR_RX_DESC_READ indicates that an error occurred when
  2088. //! reading the receive descriptor.
  2089. //! - \b EMAC_DMA_ERR_TX_DESC_READ indicates that an error occurred when
  2090. //! reading the transmit descriptor.
  2091. //
  2092. //*****************************************************************************
  2093. uint32_t
  2094. EMACDMAStateGet(uint32_t ui32Base)
  2095. {
  2096. //
  2097. // Return the status of the DMA channels.
  2098. //
  2099. return (HWREG(ui32Base + EMAC_O_DMARIS) &
  2100. (EMAC_DMARIS_FBI | EMAC_DMARIS_AE_M | EMAC_DMARIS_RS_M |
  2101. EMAC_DMARIS_TS_M));
  2102. }
  2103. //*****************************************************************************
  2104. //
  2105. //! Flushes the Ethernet controller transmit FIFO.
  2106. //!
  2107. //! \param ui32Base is the base address of the controller.
  2108. //!
  2109. //! This function flushes any data currently held in the Ethernet transmit
  2110. //! FIFO. Data that has already been passed to the MAC for transmission is
  2111. //! transmitted, possibly resulting in a transmit underflow or runt frame
  2112. //! transmission.
  2113. //!
  2114. //! \return None.
  2115. //
  2116. //*****************************************************************************
  2117. void
  2118. EMACTxFlush(uint32_t ui32Base)
  2119. {
  2120. //
  2121. // Check to make sure that the FIFO is not already empty.
  2122. //
  2123. if (HWREG(ui32Base + EMAC_O_STATUS) & EMAC_STATUS_TXFE)
  2124. {
  2125. //
  2126. // Flush the transmit FIFO since it is not currently empty.
  2127. //
  2128. HWREG(ui32Base + EMAC_O_DMAOPMODE) |= EMAC_DMAOPMODE_FTF;
  2129. //
  2130. // Wait for the flush to complete.
  2131. //
  2132. while (HWREG(ui32Base + EMAC_O_DMAOPMODE) & EMAC_DMAOPMODE_FTF)
  2133. {
  2134. }
  2135. }
  2136. }
  2137. //*****************************************************************************
  2138. //
  2139. //! Enables the Ethernet controller transmitter.
  2140. //!
  2141. //! \param ui32Base is the base address of the controller.
  2142. //!
  2143. //! When starting operations on the Ethernet interface, this function should
  2144. //! be called to enable the transmitter after all configuration has been
  2145. //! completed.
  2146. //!
  2147. //! \return None.
  2148. //
  2149. //*****************************************************************************
  2150. void
  2151. EMACTxEnable(uint32_t ui32Base)
  2152. {
  2153. //
  2154. // Enable the MAC transmit path in the opmode register.
  2155. //
  2156. HWREG(ui32Base + EMAC_O_DMAOPMODE) |= EMAC_DMAOPMODE_ST;
  2157. //
  2158. // Enable transmission in the MAC configuration register.
  2159. //
  2160. HWREG(ui32Base + EMAC_O_CFG) |= EMAC_CFG_TE;
  2161. }
  2162. //*****************************************************************************
  2163. //
  2164. //! Disables the Ethernet controller transmitter.
  2165. //!
  2166. //! \param ui32Base is the base address of the controller.
  2167. //!
  2168. //! When terminating operations on the Ethernet interface, this function should
  2169. //! be called. This function disables the transmitter.
  2170. //!
  2171. //! \return None.
  2172. //
  2173. //*****************************************************************************
  2174. void
  2175. EMACTxDisable(uint32_t ui32Base)
  2176. {
  2177. //
  2178. // Disable transmission in the MAC configuration register.
  2179. //
  2180. HWREG(ui32Base + EMAC_O_CFG) &= ~EMAC_CFG_TE;
  2181. //
  2182. // Disable the MAC transmit path in the opmode register.
  2183. //
  2184. HWREG(ui32Base + EMAC_O_DMAOPMODE) &= ~EMAC_DMAOPMODE_ST;
  2185. }
  2186. //*****************************************************************************
  2187. //
  2188. //! Enables the Ethernet controller receiver.
  2189. //!
  2190. //! \param ui32Base is the base address of the controller.
  2191. //!
  2192. //! When starting operations on the Ethernet interface, this function should
  2193. //! be called to enable the receiver after all configuration has been
  2194. //! completed.
  2195. //!
  2196. //! \return None.
  2197. //
  2198. //*****************************************************************************
  2199. void
  2200. EMACRxEnable(uint32_t ui32Base)
  2201. {
  2202. //
  2203. // Enable the MAC receive path.
  2204. //
  2205. HWREG(ui32Base + EMAC_O_DMAOPMODE) |= EMAC_DMAOPMODE_SR;
  2206. //
  2207. // Enable receive in the MAC configuration register.
  2208. //
  2209. HWREG(ui32Base + EMAC_O_CFG) |= EMAC_CFG_RE;
  2210. }
  2211. //*****************************************************************************
  2212. //
  2213. //! Disables the Ethernet controller receiver.
  2214. //!
  2215. //! \param ui32Base is the base address of the controller.
  2216. //!
  2217. //! When terminating operations on the Ethernet interface, this function should
  2218. //! be called. This function disables the receiver.
  2219. //!
  2220. //! \return None.
  2221. //
  2222. //*****************************************************************************
  2223. void
  2224. EMACRxDisable(uint32_t ui32Base)
  2225. {
  2226. //
  2227. // Disable reception in the MAC configuration register.
  2228. //
  2229. HWREG(ui32Base + EMAC_O_CFG) &= ~EMAC_CFG_RE;
  2230. //
  2231. // Disable the MAC receive path.
  2232. //
  2233. HWREG(ui32Base + EMAC_O_DMAOPMODE) &= ~EMAC_DMAOPMODE_SR;
  2234. }
  2235. //*****************************************************************************
  2236. //
  2237. //! Registers an interrupt handler for an Ethernet interrupt.
  2238. //!
  2239. //! \param ui32Base is the base address of the controller.
  2240. //! \param pfnHandler is a pointer to the function to be called when the
  2241. //! enabled Ethernet interrupts occur.
  2242. //!
  2243. //! This function sets the handler to be called when the Ethernet interrupt
  2244. //! occurs. This function enables the global interrupt in the interrupt
  2245. //! controller; specific Ethernet interrupts must be enabled via
  2246. //! EMACIntEnable(). It is the interrupt handler's responsibility to clear
  2247. //! the interrupt source.
  2248. //!
  2249. //! \sa IntRegister() for important information about registering interrupt
  2250. //! handlers.
  2251. //!
  2252. //! \return None.
  2253. //
  2254. //*****************************************************************************
  2255. void
  2256. EMACIntRegister(uint32_t ui32Base, void (*pfnHandler)(void))
  2257. {
  2258. //
  2259. // Check the arguments.
  2260. //
  2261. ASSERT(pfnHandler != 0);
  2262. //
  2263. // Register the interrupt handler.
  2264. //
  2265. IntRegister(INT_EMAC0, pfnHandler);
  2266. //
  2267. // Enable the Ethernet interrupt.
  2268. //
  2269. IntEnable(INT_EMAC0);
  2270. }
  2271. //*****************************************************************************
  2272. //
  2273. //! Unregisters an interrupt handler for an Ethernet interrupt.
  2274. //!
  2275. //! \param ui32Base is the base address of the controller.
  2276. //!
  2277. //! This function unregisters the interrupt handler. This function disables
  2278. //! the global interrupt in the interrupt controller so that the interrupt
  2279. //! handler is no longer called.
  2280. //!
  2281. //! \sa IntRegister() for important information about registering interrupt
  2282. //! handlers.
  2283. //!
  2284. //! \return None.
  2285. //
  2286. //*****************************************************************************
  2287. void
  2288. EMACIntUnregister(uint32_t ui32Base)
  2289. {
  2290. //
  2291. // Disable the interrupt.
  2292. //
  2293. IntDisable(INT_EMAC0);
  2294. //
  2295. // Unregister the interrupt handler.
  2296. //
  2297. IntUnregister(INT_EMAC0);
  2298. }
  2299. //*****************************************************************************
  2300. //
  2301. //! Enables individual Ethernet MAC interrupt sources.
  2302. //!
  2303. //! \param ui32Base is the base address of the Ethernet MAC.
  2304. //! \param ui32IntFlags is the bit mask of the interrupt sources to be enabled.
  2305. //!
  2306. //! This function enables the indicated Ethernet MAC interrupt sources. Only
  2307. //! the sources that are enabled can be reflected to the processor interrupt;
  2308. //! disabled sources have no effect on the processor.
  2309. //!
  2310. //! The \e ui32IntFlags parameter is the logical OR of any of the following:
  2311. //!
  2312. //! - \b EMAC_INT_PHY indicates that the PHY has signaled a change of state.
  2313. //! Software must read and write the appropriate PHY registers to enable and
  2314. //! disable particular notifications.
  2315. //! - \b EMAC_INT_EARLY_RECEIVE indicates that the DMA engine has filled the
  2316. //! first data buffer of a packet.
  2317. //! - \b EMAC_INT_BUS_ERROR indicates that a fatal bus error has occurred and
  2318. //! that the DMA engine has been disabled.
  2319. //! - \b EMAC_INT_EARLY_TRANSMIT indicates that a frame to be transmitted has
  2320. //! been fully written from memory into the MAC transmit FIFO.
  2321. //! - \b EMAC_INT_RX_WATCHDOG indicates that a frame with length greater than
  2322. //! 2048 bytes (of 10240 bytes in Jumbo Frame mode) was received.
  2323. //! - \b EMAC_INT_RX_STOPPED indicates that the receive process has entered
  2324. //! the stopped state.
  2325. //! - \b EMAC_INT_RX_NO_BUFFER indicates that the host owns the next buffer
  2326. //! in the DMA's receive descriptor list and the DMA cannot, therefore, acquire
  2327. //! a buffer. The receive process is suspended and can be resumed by changing
  2328. //! the descriptor ownership and calling EMACRxDMAPollDemand().
  2329. //! - \b EMAC_INT_RECEIVE indicates that reception of a frame has completed
  2330. //! and all requested status has been written to the appropriate DMA receive
  2331. //! descriptor.
  2332. //! - \b EMAC_INT_TX_UNDERFLOW indicates that the transmitter experienced an
  2333. //! underflow during transmission. The transmit process is suspended.
  2334. //! - \b EMAC_INT_RX_OVERFLOW indicates that an overflow was experienced
  2335. //! during reception.
  2336. //! - \b EMAC_INT_TX_JABBER indicates that the transmit jabber timer expired.
  2337. //! This condition occurs when the frame size exceeds 2048 bytes (or 10240
  2338. //! bytes in Jumbo Frame mode) and causes the transmit process to abort and
  2339. //! enter the Stopped state.
  2340. //! - \b EMAC_INT_TX_NO_BUFFER indicates that the host owns the next buffer
  2341. //! in the DMA's transmit descriptor list and that the DMA cannot, therefore,
  2342. //! acquire a buffer. Transmission is suspended and can be resumed by changing
  2343. //! the descriptor ownership and calling EMACTxDMAPollDemand().
  2344. //! - \b EMAC_INT_TX_STOPPED indicates that the transmit process has stopped.
  2345. //! - \b EMAC_INT_TRANSMIT indicates that transmission of a frame has
  2346. //! completed and that all requested status has been updated in the descriptor.
  2347. //!
  2348. //! Summary interrupt bits \b EMAC_INT_NORMAL_INT and
  2349. //! \b EMAC_INT_ABNORMAL_INT are enabled automatically by the driver if any
  2350. //! of their constituent sources are enabled. Applications do not need to
  2351. //! explicitly enable these bits.
  2352. //!
  2353. //! \note Timestamp-related interrupts from the IEEE 1588 module must be
  2354. //! enabled independently by using a call to EMACTimestampTargetIntEnable().
  2355. //!
  2356. //! \return None.
  2357. //
  2358. //*****************************************************************************
  2359. void
  2360. EMACIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
  2361. {
  2362. //
  2363. // Parameter sanity check.
  2364. //
  2365. ASSERT((ui32IntFlags & ~EMAC_MASKABLE_INTS) == 0);
  2366. //
  2367. // Enable the normal interrupt if any of its individual sources are
  2368. // enabled.
  2369. //
  2370. if (ui32IntFlags & EMAC_NORMAL_INTS)
  2371. {
  2372. ui32IntFlags |= EMAC_INT_NORMAL_INT;
  2373. }
  2374. //
  2375. // Similarly, enable the abnormal interrupt if any of its individual
  2376. // sources are enabled.
  2377. //
  2378. if (ui32IntFlags & EMAC_ABNORMAL_INTS)
  2379. {
  2380. ui32IntFlags |= EMAC_INT_ABNORMAL_INT;
  2381. }
  2382. //
  2383. // Set the MAC DMA interrupt mask appropriately if any of the sources
  2384. // we've been asked to enable are found in that register.
  2385. //
  2386. if (ui32IntFlags & ~EMAC_INT_PHY)
  2387. {
  2388. HWREG(ui32Base + EMAC_O_DMAIM) |= ui32IntFlags & ~EMAC_INT_PHY;
  2389. }
  2390. //
  2391. // Enable the PHY interrupt if we've been asked to do this.
  2392. //
  2393. if (ui32IntFlags & EMAC_INT_PHY)
  2394. {
  2395. HWREG(ui32Base + EMAC_O_EPHYIM) |= EMAC_EPHYIM_INT;
  2396. }
  2397. }
  2398. //*****************************************************************************
  2399. //
  2400. //! Disables individual Ethernet MAC interrupt sources.
  2401. //!
  2402. //! \param ui32Base is the base address of the Ethernet MAC.
  2403. //! \param ui32IntFlags is the bit mask of the interrupt sources to be disabled.
  2404. //!
  2405. //! This function disables the indicated Ethernet MAC interrupt sources.
  2406. //!
  2407. //! The \e ui32IntFlags parameter is the logical OR of any of the following:
  2408. //!
  2409. //! - \b EMAC_INT_PHY indicates that the PHY has signaled a change of state.
  2410. //! Software must read and write the appropriate PHY registers to enable and
  2411. //! disable particular notifications.
  2412. //! - \b EMAC_INT_EARLY_RECEIVE indicates that the DMA engine has filled the
  2413. //! first data buffer of a packet.
  2414. //! - \b EMAC_INT_BUS_ERROR indicates that a fatal bus error has occurred and
  2415. //! that the DMA engine has been disabled.
  2416. //! - \b EMAC_INT_EARLY_TRANSMIT indicates that a frame to be transmitted has
  2417. //! been fully written from memory into the MAC transmit FIFO.
  2418. //! - \b EMAC_INT_RX_WATCHDOG indicates that a frame with length greater than
  2419. //! 2048 bytes (of 10240 bytes in Jumbo Frame mode) was received.
  2420. //! - \b EMAC_INT_RX_STOPPED indicates that the receive process has entered
  2421. //! the stopped state.
  2422. //! - \b EMAC_INT_RX_NO_BUFFER indicates that the host owns the next buffer
  2423. //! in the DMA's receive descriptor list and the DMA cannot, therefore, acquire
  2424. //! a buffer. The receive process is suspended and can be resumed by changing
  2425. //! the descriptor ownership and calling EMACRxDMAPollDemand().
  2426. //! - \b EMAC_INT_RECEIVE indicates that reception of a frame has completed
  2427. //! and all requested status has been written to the appropriate DMA receive
  2428. //! descriptor.
  2429. //! - \b EMAC_INT_TX_UNDERFLOW indicates that the transmitter experienced an
  2430. //! underflow during transmission. The transmit process is suspended.
  2431. //! - \b EMAC_INT_RX_OVERFLOW indicates that an overflow was experienced
  2432. //! during reception.
  2433. //! - \b EMAC_INT_TX_JABBER indicates that the transmit jabber timer expired.
  2434. //! This condition occurs when the frame size exceeds 2048 bytes (or 10240
  2435. //! bytes in Jumbo Frame mode) and causes the transmit process to abort and
  2436. //! enter the Stopped state.
  2437. //! - \b EMAC_INT_TX_NO_BUFFER indicates that the host owns the next buffer
  2438. //! in the DMA's transmit descriptor list and that the DMA cannot, therefore,
  2439. //! acquire a buffer. Transmission is suspended and can be resumed by changing
  2440. //! the descriptor ownership and calling EMACTxDMAPollDemand().
  2441. //! - \b EMAC_INT_TX_STOPPED indicates that the transmit process has stopped.
  2442. //! - \b EMAC_INT_TRANSMIT indicates that transmission of a frame has
  2443. //! completed and that all requested status has been updated in the descriptor.
  2444. //! - \b EMAC_INT_TIMESTAMP indicates that an interrupt from the timestamp
  2445. //! module has occurred. This precise source of the interrupt can be
  2446. //! determined by calling EMACTimestampIntStatus(), which also clears this
  2447. //! bit.
  2448. //!
  2449. //! Summary interrupt bits \b EMAC_INT_NORMAL_INT and
  2450. //! \b EMAC_INT_ABNORMAL_INT are disabled automatically by the driver if none
  2451. //! of their constituent sources are enabled. Applications do not need to
  2452. //! explicitly disable these bits.
  2453. //!
  2454. //! \note Timestamp-related interrupts from the IEEE 1588 module must be
  2455. //! disabled independently by using a call to EMACTimestampTargetIntDisable().
  2456. //!
  2457. //! \return None.
  2458. //
  2459. //*****************************************************************************
  2460. void
  2461. EMACIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
  2462. {
  2463. uint32_t ui32Mask;
  2464. //
  2465. // Parameter sanity check.
  2466. //
  2467. ASSERT(ui32Base == EMAC0_BASE);
  2468. ASSERT((ui32IntFlags & ~EMAC_MASKABLE_INTS) == 0);
  2469. //
  2470. // Get the current interrupt mask.
  2471. //
  2472. ui32Mask = HWREG(ui32Base + EMAC_O_DMAIM);
  2473. //
  2474. // Clear the requested bits.
  2475. //
  2476. ui32Mask &= ~(ui32IntFlags & ~EMAC_INT_PHY);
  2477. //
  2478. // If none of the normal interrupt sources are enabled, disable the
  2479. // normal interrupt.
  2480. //
  2481. if (!(ui32Mask & EMAC_NORMAL_INTS))
  2482. {
  2483. ui32Mask &= ~EMAC_INT_NORMAL_INT;
  2484. }
  2485. //
  2486. // Similarly, if none of the abnormal interrupt sources are enabled,
  2487. // disable the abnormal interrupt.
  2488. //
  2489. if (!(ui32Mask & EMAC_ABNORMAL_INTS))
  2490. {
  2491. ui32Mask &= ~EMAC_INT_ABNORMAL_INT;
  2492. }
  2493. //
  2494. // Write the new mask back to the hardware.
  2495. //
  2496. HWREG(ui32Base + EMAC_O_DMAIM) = ui32Mask;
  2497. //
  2498. // Disable the PHY interrupt if we've been asked to do this.
  2499. //
  2500. if (ui32IntFlags & EMAC_INT_PHY)
  2501. {
  2502. HWREG(ui32Base + EMAC_O_EPHYIM) &= ~EMAC_EPHYIM_INT;
  2503. }
  2504. }
  2505. //*****************************************************************************
  2506. //
  2507. //! Gets the current Ethernet MAC interrupt status.
  2508. //!
  2509. //! \param ui32Base is the base address of the Ethernet MAC.
  2510. //! \param bMasked is \b true to return the masked interrupt status or \b false
  2511. //! to return the unmasked status.
  2512. //!
  2513. //! This function returns the interrupt status for the Ethernet MAC. Either
  2514. //! the raw interrupt status or the status of interrupts that are allowed
  2515. //! to reflect to the processor can be returned.
  2516. //!
  2517. //! \return Returns the current interrupt status as the logical OR of any of
  2518. //! the following:
  2519. //!
  2520. //! - \b EMAC_INT_PHY indicates that the PHY interrupt has occurred.
  2521. //! Software must read the relevant PHY interrupt status register to determine
  2522. //! the cause.
  2523. //! - \b EMAC_INT_EARLY_RECEIVE indicates that the DMA engine has filled the
  2524. //! first data buffer of a packet.
  2525. //! - \b EMAC_INT_BUS_ERROR indicates that a fatal bus error has occurred and
  2526. //! that the DMA engine has been disabled. The cause of the error can be
  2527. //! determined by calling EMACDMAStateGet().
  2528. //! - \b EMAC_INT_EARLY_TRANSMIT indicates that a frame to be transmitted has
  2529. //! been fully written from memory into the MAC transmit FIFO.
  2530. //! - \b EMAC_INT_RX_WATCHDOG indicates that a frame with length greater than
  2531. //! 2048 bytes (of 10240 bytes in Jumbo Frame mode) was received.
  2532. //! - \b EMAC_INT_RX_STOPPED indicates that the receive process has entered
  2533. //! the stopped state.
  2534. //! - \b EMAC_INT_RX_NO_BUFFER indicates that the host owns the next buffer
  2535. //! in the DMA's receive descriptor list and the DMA cannot, therefore, acquire
  2536. //! a buffer. The receive process is suspended and can be resumed by changing
  2537. //! the descriptor ownership and calling EMACRxDMAPollDemand().
  2538. //! - \b EMAC_INT_RECEIVE indicates that reception of a frame has completed
  2539. //! and all requested status has been written to the appropriate DMA receive
  2540. //! descriptor.
  2541. //! - \b EMAC_INT_TX_UNDERFLOW indicates that the transmitter experienced an
  2542. //! underflow during transmission. The transmit process is suspended.
  2543. //! - \b EMAC_INT_RX_OVERFLOW indicates that an overflow was experienced
  2544. //! during reception.
  2545. //! - \b EMAC_INT_TX_JABBER indicates that the transmit jabber timer expired.
  2546. //! This condition occurs when the frame size exceeds 2048 bytes (or 10240
  2547. //! bytes in Jumbo Frame mode) and causes the transmit process to abort and
  2548. //! enter the Stopped state.
  2549. //! - \b EMAC_INT_TX_NO_BUFFER indicates that the host owns the next buffer
  2550. //! in the DMA's transmit descriptor list and that the DMA cannot, therefore,
  2551. //! acquire a buffer. Transmission is suspended and can be resumed by changing
  2552. //! the descriptor ownership and calling EMACTxDMAPollDemand().
  2553. //! - \b EMAC_INT_TX_STOPPED indicates that the transmit process has stopped.
  2554. //! - \b EMAC_INT_TRANSMIT indicates that transmission of a frame has
  2555. //! completed and that all requested status has been updated in the descriptor.
  2556. //! - \b EMAC_INT_NORMAL_INT is a summary interrupt comprising the logical
  2557. //! OR of the masked state of \b EMAC_INT_TRANSMIT, \b EMAC_INT_RECEIVE,
  2558. //! \b EMAC_INT_TX_NO_BUFFER and \b EMAC_INT_EARLY_RECEIVE.
  2559. //! - \b EMAC_INT_ABNORMAL_INT is a summary interrupt comprising the logical
  2560. //! OR of the masked state of \b EMAC_INT_TX_STOPPED, \b EMAC_INT_TX_JABBER,
  2561. //! \b EMAC_INT_RX_OVERFLOW, \b EMAC_INT_TX_UNDERFLOW,
  2562. //! \b EMAC_INT_RX_NO_BUFFER, \b EMAC_INT_RX_STOPPED,
  2563. //! \b EMAC_INT_RX_WATCHDOG, \b EMAC_INT_EARLY_TRANSMIT and
  2564. //! \b EMAC_INT_BUS_ERROR.
  2565. //
  2566. //*****************************************************************************
  2567. uint32_t
  2568. EMACIntStatus(uint32_t ui32Base, bool bMasked)
  2569. {
  2570. uint32_t ui32Val, ui32PHYStat;
  2571. //
  2572. // Parameter sanity check.
  2573. //
  2574. ASSERT(ui32Base == EMAC0_BASE);
  2575. //
  2576. // Get the unmasked interrupt status and clear any unwanted status fields.
  2577. //
  2578. ui32Val = HWREG(ui32Base + EMAC_O_DMARIS);
  2579. ui32Val &= ~(EMAC_DMARIS_AE_M | EMAC_DMARIS_TS_M | EMAC_DMARIS_RS_M);
  2580. //
  2581. // This peripheral doesn't have a masked interrupt status register
  2582. // so perform the masking manually. Note that only the bottom 16 bits
  2583. // of the register can be masked so make sure we take this into account.
  2584. //
  2585. if (bMasked)
  2586. {
  2587. ui32Val &= (EMAC_NON_MASKED_INTS | HWREG(ui32Base + EMAC_O_DMAIM));
  2588. }
  2589. //
  2590. // Read the PHY interrupt status.
  2591. //
  2592. if (bMasked)
  2593. {
  2594. ui32PHYStat = HWREG(ui32Base + EMAC_O_EPHYMISC);
  2595. }
  2596. else
  2597. {
  2598. ui32PHYStat = HWREG(ui32Base + EMAC_O_EPHYRIS);
  2599. }
  2600. //
  2601. // If the PHY interrupt is reported, add the appropriate flag to the
  2602. // return value.
  2603. //
  2604. if (ui32PHYStat & EMAC_EPHYMISC_INT)
  2605. {
  2606. ui32Val |= EMAC_INT_PHY;
  2607. }
  2608. return (ui32Val);
  2609. }
  2610. //*****************************************************************************
  2611. //
  2612. //! Clears individual Ethernet MAC interrupt sources.
  2613. //!
  2614. //! \param ui32Base is the base address of the Ethernet MAC.
  2615. //! \param ui32IntFlags is the bit mask of the interrupt sources to be cleared.
  2616. //!
  2617. //! This function disables the indicated Ethernet MAC interrupt sources.
  2618. //!
  2619. //! The \e ui32IntFlags parameter is the logical OR of any of the following:
  2620. //!
  2621. //! - \b EMAC_INT_PHY indicates that the PHY has signaled a change of state.
  2622. //! Software must read and write the appropriate PHY registers to enable,
  2623. //! disable and clear particular notifications.
  2624. //! - \b EMAC_INT_EARLY_RECEIVE indicates that the DMA engine has filled the
  2625. //! first data buffer of a packet.
  2626. //! - \b EMAC_INT_BUS_ERROR indicates that a fatal bus error has occurred and
  2627. //! that the DMA engine has been disabled.
  2628. //! - \b EMAC_INT_EARLY_TRANSMIT indicates that a frame to be transmitted has
  2629. //! been fully written from memory into the MAC transmit FIFO.
  2630. //! - \b EMAC_INT_RX_WATCHDOG indicates that a frame with length greater than
  2631. //! 2048 bytes (of 10240 bytes in Jumbo Frame mode) was received.
  2632. //! - \b EMAC_INT_RX_STOPPED indicates that the receive process has entered
  2633. //! the stopped state.
  2634. //! - \b EMAC_INT_RX_NO_BUFFER indicates that the host owns the next buffer
  2635. //! in the DMA's receive descriptor list and the DMA cannot, therefore, acquire
  2636. //! a buffer. The receive process is suspended and can be resumed by changing
  2637. //! the descriptor ownership and calling EMACRxDMAPollDemand().
  2638. //! - \b EMAC_INT_RECEIVE indicates that reception of a frame has completed
  2639. //! and all requested status has been written to the appropriate DMA receive
  2640. //! descriptor.
  2641. //! - \b EMAC_INT_TX_UNDERFLOW indicates that the transmitter experienced an
  2642. //! underflow during transmission. The transmit process is suspended.
  2643. //! - \b EMAC_INT_RX_OVERFLOW indicates that an overflow was experienced
  2644. //! during reception.
  2645. //! - \b EMAC_INT_TX_JABBER indicates that the transmit jabber timer expired.
  2646. //! This condition occurs when the frame size exceeds 2048 bytes (or 10240
  2647. //! bytes in Jumbo Frame mode) and causes the transmit process to abort and
  2648. //! enter the Stopped state.
  2649. //! - \b EMAC_INT_TX_NO_BUFFER indicates that the host owns the next buffer
  2650. //! in the DMA's transmit descriptor list and that the DMA cannot, therefore,
  2651. //! acquire a buffer. Transmission is suspended and can be resumed by changing
  2652. //! the descriptor ownership and calling EMACTxDMAPollDemand().
  2653. //! - \b EMAC_INT_TX_STOPPED indicates that the transmit process has stopped.
  2654. //! - \b EMAC_INT_TRANSMIT indicates that transmission of a frame has
  2655. //! completed and that all requested status has been updated in the descriptor.
  2656. //!
  2657. //! Summary interrupt bits \b EMAC_INT_NORMAL_INT and
  2658. //! \b EMAC_INT_ABNORMAL_INT are cleared automatically by the driver if any
  2659. //! of their constituent sources are cleared. Applications do not need to
  2660. //! explicitly clear these bits.
  2661. //!
  2662. //! \return None.
  2663. //
  2664. //*****************************************************************************
  2665. void
  2666. EMACIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
  2667. {
  2668. //
  2669. // Parameter sanity check.
  2670. //
  2671. ASSERT(ui32Base == EMAC0_BASE);
  2672. //
  2673. // Mask in the normal interrupt if one of the sources it relates to is
  2674. // specified.
  2675. //
  2676. if (ui32IntFlags & EMAC_NORMAL_INTS)
  2677. {
  2678. ui32IntFlags |= EMAC_INT_NORMAL_INT;
  2679. }
  2680. //
  2681. // Similarly, mask in the abnormal interrupt if one of the sources it
  2682. // relates to is specified.
  2683. //
  2684. if (ui32IntFlags & EMAC_ABNORMAL_INTS)
  2685. {
  2686. ui32IntFlags |= EMAC_INT_ABNORMAL_INT;
  2687. }
  2688. //
  2689. // Clear the maskable interrupt sources. We write exactly the value passed
  2690. // (with the summary sources added if necessary) but remember that only
  2691. // the bottom 17 bits of the register are actually clearable. Only do
  2692. // this if some bits are actually set that refer to the DMA interrupt
  2693. // sources.
  2694. //
  2695. if (ui32IntFlags & ~EMAC_INT_PHY)
  2696. {
  2697. HWREG(ui32Base + EMAC_O_DMARIS) = (ui32IntFlags & ~EMAC_INT_PHY);
  2698. }
  2699. //
  2700. // Clear the PHY interrupt if we've been asked to do this.
  2701. //
  2702. if (ui32IntFlags & EMAC_INT_PHY)
  2703. {
  2704. HWREG(ui32Base + EMAC_O_EPHYMISC) |= EMAC_EPHYMISC_INT;
  2705. }
  2706. }
  2707. //*****************************************************************************
  2708. //
  2709. //! Writes to the PHY register.
  2710. //!
  2711. //! \param ui32Base is the base address of the controller.
  2712. //! \param ui8PhyAddr is the physical address of the PHY to access.
  2713. //! \param ui8RegAddr is the address of the PHY register to be accessed.
  2714. //! \param ui16Data is the data to be written to the PHY register.
  2715. //!
  2716. //! This function writes the \e ui16Data value to the PHY register specified by
  2717. //! \e ui8RegAddr.
  2718. //!
  2719. //! \return None.
  2720. //
  2721. //*****************************************************************************
  2722. void
  2723. EMACPHYWrite(uint32_t ui32Base, uint8_t ui8PhyAddr, uint8_t ui8RegAddr,
  2724. uint16_t ui16Data)
  2725. {
  2726. //
  2727. // Parameter sanity check.
  2728. //
  2729. ASSERT(ui32Base == EMAC0_BASE);
  2730. //
  2731. // Parameter sanity check.
  2732. //
  2733. ASSERT(ui8PhyAddr < 32);
  2734. //
  2735. // Make sure the MII is idle.
  2736. //
  2737. while (HWREG(ui32Base + EMAC_O_MIIADDR) & EMAC_MIIADDR_MIIB)
  2738. {
  2739. }
  2740. //
  2741. // Write the value provided.
  2742. //
  2743. HWREG(ui32Base + EMAC_O_MIIDATA) = ui16Data;
  2744. //
  2745. // Tell the MAC to write the given PHY register.
  2746. //
  2747. HWREG(ui32Base + EMAC_O_MIIADDR) =
  2748. ((HWREG(ui32Base + EMAC_O_MIIADDR) &
  2749. EMAC_MIIADDR_CR_M) | (ui8RegAddr << EMAC_MIIADDR_MII_S) |
  2750. (ui8PhyAddr << EMAC_MIIADDR_PLA_S) | EMAC_MIIADDR_MIIW |
  2751. EMAC_MIIADDR_MIIB);
  2752. //
  2753. // Wait for the write to complete.
  2754. //
  2755. while (HWREG(ui32Base + EMAC_O_MIIADDR) & EMAC_MIIADDR_MIIB)
  2756. {
  2757. }
  2758. }
  2759. //*****************************************************************************
  2760. //
  2761. //! Reads from a PHY register.
  2762. //!
  2763. //! \param ui32Base is the base address of the controller.
  2764. //! \param ui8PhyAddr is the physical address of the PHY to access.
  2765. //! \param ui8RegAddr is the address of the PHY register to be accessed.
  2766. //!
  2767. //! This function returns the contents of the PHY register specified by
  2768. //! \e ui8RegAddr.
  2769. //!
  2770. //! \return Returns the 16-bit value read from the PHY.
  2771. //
  2772. //*****************************************************************************
  2773. uint16_t
  2774. EMACPHYRead(uint32_t ui32Base, uint8_t ui8PhyAddr, uint8_t ui8RegAddr)
  2775. {
  2776. //
  2777. // Parameter sanity check.
  2778. //
  2779. ASSERT(ui8PhyAddr < 32);
  2780. ASSERT(ui32Base == EMAC0_BASE);
  2781. //
  2782. // Make sure the MII is idle.
  2783. //
  2784. while (HWREG(ui32Base + EMAC_O_MIIADDR) & EMAC_MIIADDR_MIIB)
  2785. {
  2786. }
  2787. //
  2788. // Tell the MAC to read the given PHY register.
  2789. //
  2790. HWREG(ui32Base + EMAC_O_MIIADDR) =
  2791. ((HWREG(ui32Base + EMAC_O_MIIADDR) & EMAC_MIIADDR_CR_M) |
  2792. (ui8RegAddr << EMAC_MIIADDR_MII_S) |
  2793. (ui8PhyAddr << EMAC_MIIADDR_PLA_S) | EMAC_MIIADDR_MIIB);
  2794. //
  2795. // Wait for the read to complete.
  2796. //
  2797. while (HWREG(ui32Base + EMAC_O_MIIADDR) & EMAC_MIIADDR_MIIB)
  2798. {
  2799. }
  2800. //
  2801. // Return the result.
  2802. //
  2803. return (HWREG(ui32Base + EMAC_O_MIIDATA) & EMAC_MIIDATA_DATA_M);
  2804. }
  2805. //*****************************************************************************
  2806. //
  2807. //! Reads from an extended PHY register.
  2808. //!
  2809. //! \param ui32Base is the base address of the controller.
  2810. //! \param ui8PhyAddr is the physical address of the PHY to access.
  2811. //! \param ui16RegAddr is the address of the PHY extended register to be
  2812. //! accessed.
  2813. //!
  2814. //! When using the internal PHY or when connected to an external PHY
  2815. //! supporting extended registers, this function returns the contents of the
  2816. //! extended PHY register specified by \e ui16RegAddr.
  2817. //!
  2818. //! \return Returns the 16-bit value read from the PHY.
  2819. //
  2820. //*****************************************************************************
  2821. uint16_t
  2822. EMACPHYExtendedRead(uint32_t ui32Base, uint8_t ui8PhyAddr,
  2823. uint16_t ui16RegAddr)
  2824. {
  2825. //
  2826. // Parameter sanity check.
  2827. //
  2828. ASSERT(ui8PhyAddr < 32);
  2829. ASSERT(ui32Base == EMAC0_BASE);
  2830. //
  2831. // Set the address of the register we're about to read.
  2832. //
  2833. EMACPHYWrite(EMAC0_BASE, ui8PhyAddr, EPHY_REGCTL, 0x001F);
  2834. EMACPHYWrite(EMAC0_BASE, ui8PhyAddr, EPHY_ADDAR, ui16RegAddr);
  2835. //
  2836. // Read the extended register value.
  2837. //
  2838. EMACPHYWrite(EMAC0_BASE, ui8PhyAddr, EPHY_REGCTL, 0x401F);
  2839. return (EMACPHYRead(EMAC0_BASE, ui8PhyAddr, EPHY_ADDAR));
  2840. }
  2841. //*****************************************************************************
  2842. //
  2843. //! Writes a value to an extended PHY register.
  2844. //!
  2845. //! \param ui32Base is the base address of the controller.
  2846. //! \param ui8PhyAddr is the physical address of the PHY to access.
  2847. //! \param ui16RegAddr is the address of the PHY extended register to be
  2848. //! accessed.
  2849. //! \param ui16Value is the value to write to the register.
  2850. //!
  2851. //! When using the internal PHY or when connected to an external PHY
  2852. //! supporting extended registers, this function allows a value to be written
  2853. //! to the extended PHY register specified by \e ui16RegAddr.
  2854. //!
  2855. //! \return None.
  2856. //
  2857. //*****************************************************************************
  2858. void
  2859. EMACPHYExtendedWrite(uint32_t ui32Base, uint8_t ui8PhyAddr,
  2860. uint16_t ui16RegAddr, uint16_t ui16Value)
  2861. {
  2862. //
  2863. // Parameter sanity check.
  2864. //
  2865. ASSERT(ui8PhyAddr < 32);
  2866. ASSERT(ui32Base == EMAC0_BASE);
  2867. //
  2868. // Set the address of the register we're about to write.
  2869. //
  2870. EMACPHYWrite(EMAC0_BASE, ui8PhyAddr, EPHY_REGCTL, 0x001F);
  2871. EMACPHYWrite(EMAC0_BASE, ui8PhyAddr, EPHY_ADDAR, ui16RegAddr);
  2872. //
  2873. // Write the extended register.
  2874. //
  2875. EMACPHYWrite(EMAC0_BASE, ui8PhyAddr, EPHY_REGCTL, 0x401F);
  2876. EMACPHYWrite(EMAC0_BASE, ui8PhyAddr, EPHY_ADDAR, ui16Value);
  2877. }
  2878. //*****************************************************************************
  2879. //
  2880. //! Powers off the Ethernet PHY.
  2881. //!
  2882. //! \param ui32Base is the base address of the controller.
  2883. //! \param ui8PhyAddr is the physical address of the PHY to power down.
  2884. //!
  2885. //! This function powers off the Ethernet PHY, reducing the current
  2886. //! consumption of the device. While in the powered-off state, the Ethernet
  2887. //! controller is unable to connect to Ethernet.
  2888. //!
  2889. //! \return None.
  2890. //
  2891. //*****************************************************************************
  2892. void
  2893. EMACPHYPowerOff(uint32_t ui32Base, uint8_t ui8PhyAddr)
  2894. {
  2895. //
  2896. // Set the PWRDN bit and clear the ANEN bit in the PHY, putting it into
  2897. // its low power mode.
  2898. //
  2899. EMACPHYWrite(ui32Base, ui8PhyAddr, EPHY_BMCR,
  2900. (EMACPHYRead(ui32Base, ui8PhyAddr, EPHY_BMCR) &
  2901. ~EPHY_BMCR_ANEN) | EPHY_BMCR_PWRDWN);
  2902. }
  2903. //*****************************************************************************
  2904. //
  2905. //! Powers on the Ethernet PHY.
  2906. //!
  2907. //! \param ui32Base is the base address of the controller.
  2908. //! \param ui8PhyAddr is the physical address of the PHY to power up.
  2909. //!
  2910. //! This function powers on the Ethernet PHY, enabling it return to normal
  2911. //! operation. By default, the PHY is powered on, so this function is only
  2912. //! called if EMACPHYPowerOff() has previously been called.
  2913. //!
  2914. //! \return None.
  2915. //
  2916. //*****************************************************************************
  2917. void
  2918. EMACPHYPowerOn(uint32_t ui32Base, uint8_t ui8PhyAddr)
  2919. {
  2920. //
  2921. // Clear the PWRDN bit and set the ANEGEN bit in the PHY, putting it into
  2922. // normal operating mode.
  2923. //
  2924. EMACPHYWrite(ui32Base, ui8PhyAddr, EPHY_BMCR,
  2925. (EMACPHYRead(ui32Base, ui8PhyAddr, EPHY_BMCR) &
  2926. ~EPHY_BMCR_PWRDWN) | EPHY_BMCR_ANEN);
  2927. }
  2928. //*****************************************************************************
  2929. //
  2930. //! Configures the Ethernet MAC's IEEE 1588 timestamping options.
  2931. //!
  2932. //! \param ui32Base is the base address of the controller.
  2933. //! \param ui32Config contains flags selecting particular configuration
  2934. //! options.
  2935. //! \param ui32SubSecondInc is the number that the IEEE 1588 subsecond clock
  2936. //! should increment on each tick.
  2937. //!
  2938. //! This function is used to configure the operation of the Ethernet MAC's
  2939. //! internal timestamping clock. This clock is used to timestamp incoming
  2940. //! and outgoing packets and as an accurate system time reference when
  2941. //! IEEE 1588 Precision Time Protocol is in use.
  2942. //!
  2943. //! The \e ui32Config parameter contains a collection of flags selecting the
  2944. //! desired options. Valid flags are:
  2945. //!
  2946. //! One of the following to determine whether IEEE 1588 version 1 or version 2
  2947. //! packet format is to be processed:
  2948. //!
  2949. //! - \b EMAC_TS_PTP_VERSION_2
  2950. //! - \b EMAC_TS_PTP_VERSION_1
  2951. //!
  2952. //! One of the following to determine how the IEEE 1588 clock's subsecond
  2953. //! value should be interpreted and handled:
  2954. //!
  2955. //! - \b EMAC_TS_DIGITAL_ROLLOVER causes the clock's subsecond value to roll
  2956. //! over at 0x3BA9C9FF (999999999 decimal). In this mode, it can be considered
  2957. //! as a nanosecond counter with each digit representing 1 ns.
  2958. //! - \b EMAC_TS_BINARY_ROLLOVER causes the clock's subsecond value to roll
  2959. //! over at 0x7FFFFFFF. In this mode, the subsecond value counts 0.465 ns
  2960. //! periods.
  2961. //!
  2962. //! One of the following to enable or disable MAC address filtering. When
  2963. //! enabled, PTP frames are filtered unless the destination MAC address matches
  2964. //! any of the currently programmed MAC addresses.
  2965. //!
  2966. //! - \b EMAC_TS_MAC_FILTER_ENABLE
  2967. //! - \b EMAC_TS_MAC_FILTER_DISABLE
  2968. //!
  2969. //! One of the following to determine how the clock is updated:
  2970. //! - \b EMAC_TS_UPDATE_COARSE causes the IEEE 1588 clock to advance by
  2971. //! the value supplied in the \e ui32SubSecondInc parameter on each main
  2972. //! oscillator clock cycle.
  2973. //! - \b EMAC_TS_UPDATE_FINE selects the fine update method which causes the
  2974. //! IEEE 1588 clock to advance by the the value supplied in the
  2975. //! \e ui32SubSecondInc parameter each time a carry is generated from the
  2976. //! addend accumulator register.
  2977. //!
  2978. //! One of the following to determine which IEEE 1588 messages are timestamped:
  2979. //!
  2980. //! - \b EMAC_TS_SYNC_FOLLOW_DREQ_DRESP timestamps SYNC, Follow_Up, Delay_Req
  2981. //! and Delay_Resp messages.
  2982. //! - \b EMAC_TS_SYNC_ONLY timestamps only SYNC messages.
  2983. //! - \b EMAC_TS_DELAYREQ_ONLY timestamps only Delay_Req messages.
  2984. //! - \b EMAC_TS_ALL timestamps all IEEE 1588 messages.
  2985. //! - \b EMAC_TS_SYNC_PDREQ_PDRESP timestamps only SYNC, Pdelay_Req and
  2986. //! Pdelay_Resp messages.
  2987. //! - \b EMAC_TS_DREQ_PDREQ_PDRESP timestamps only Delay_Req, Pdelay_Req and
  2988. //! Pdelay_Resp messages.
  2989. //! - \b EMAC_TS_SYNC_DELAYREQ timestamps only Delay_Req messages.
  2990. //! - \b EMAC_TS_PDREQ_PDRESP timestamps only Pdelay_Req and Pdelay_Resp
  2991. //! messages.
  2992. //!
  2993. //! Optional, additional flags are:
  2994. //!
  2995. //! - \b EMAC_TS_PROCESS_IPV4_UDP processes PTP packets encapsulated in UDP
  2996. //! over IPv4 packets. If absent, the MAC ignores these frames.
  2997. //! - \b EMAC_TS_PROCESS_IPV6_UDP processes PTP packets encapsulated in UDP
  2998. //! over IPv6 packets. If absent, the MAC ignores these frames.
  2999. //! - \b EMAC_TS_PROCESS_ETHERNET processes PTP packets encapsulated directly
  3000. //! in Ethernet frames. If absent, the MAC ignores these frames.
  3001. //! - \b EMAC_TS_ALL_RX_FRAMES enables timestamping for all frames received
  3002. //! by the MAC, regardless of type.
  3003. //!
  3004. //! The \e ui32SubSecondInc controls the rate at which the timestamp clock's
  3005. //! subsecond count increments. Its meaning depends on which of \b
  3006. //! EMAC_TS_DIGITAL_ROLLOVER or \b EMAC_TS_BINARY_ROLLOVER and
  3007. //! \b EMAC_TS_UPDATE_FINE or \b EMAC_TS_UPDATE_COARSE were included
  3008. //! in \e ui32Config.
  3009. //!
  3010. //! The timestamp second counter is incremented each time the subsecond counter
  3011. //! rolls over. In digital rollover mode, the subsecond counter acts as a
  3012. //! simple 31-bit counter, rolling over to 0 after reaching 0x7FFFFFFF. In
  3013. //! this case, each lsb of the subsecond counter represents 0.465 ns (assuming
  3014. //! the definition of 1 second resolution for the seconds counter). When
  3015. //! binary rollover mode is selected, the subsecond counter acts as a
  3016. //! nanosecond counter and rolls over to 0 after reaching 999,999,999 making
  3017. //! each lsb represent 1 nanosecond.
  3018. //!
  3019. //! In coarse update mode, the timestamp subsecond counter is incremented by
  3020. //! \e ui32SubSecondInc on each main oscillator clock tick. Setting
  3021. //! \e ui32SubSecondInc to the main oscillator clock period in either 1 ns or
  3022. //! 0.465 ns units ensures that the time stamp, read as seconds and
  3023. //! subseconds, increments at the same rate as the main oscillator clock. For
  3024. //! example, if the main oscillator is 25 MHz, \e ui32SubSecondInc is set to 40
  3025. //! if digital rollover mode is selected or (40 / 0.465) = 86 in binary
  3026. //! rollover mode.
  3027. //!
  3028. //! In fine update mode, the subsecond increment value must be set according
  3029. //! to the desired accuracy of the recovered IEEE 1588 clock which must be
  3030. //! lower than the system clock rate. Fine update mode is typically used when
  3031. //! synchronizing the local clock to the IEEE 1588 master clock. The subsecond
  3032. //! counter is incremented by \e ui32SubSecondInc counts each time a 32-bit
  3033. //! accumulator register generates a carry. The accumulator register is
  3034. //! incremented by the addend value on each main oscillator tick and this
  3035. //! addend value is modified to allow fine control over the rate of change of
  3036. //! the timestamp counter. The addend value is calculated using the ratio of
  3037. //! the main oscillator clock rate and the desired IEEE 1588 clock rate and the
  3038. //! \e ui32SubSecondInc value is set to correspond to the desired IEEE 1588
  3039. //! clock rate. As an example, using digital rollover mode and a 25-MHz
  3040. //! main oscillator clock with a desired IEEE 1588 clock accuracy of 12.5 MHz,
  3041. //! we would set \e ui32SubSecondInc to the 12.5-MHz clock period of 80 ns and
  3042. //! set the initial addend value to 0x80000000 to generate a carry on every
  3043. //! second system clock.
  3044. //!
  3045. //! \sa EMACTimestampAddendSet()
  3046. //!
  3047. //! \return None.
  3048. //
  3049. //*****************************************************************************
  3050. void
  3051. EMACTimestampConfigSet(uint32_t ui32Base, uint32_t ui32Config,
  3052. uint32_t ui32SubSecondInc)
  3053. {
  3054. //
  3055. // Parameter sanity check.
  3056. //
  3057. ASSERT(ui32Base == EMAC0_BASE);
  3058. //
  3059. // Ensure that the PTP module clock is enabled.
  3060. //
  3061. HWREG(ui32Base + EMAC_O_CC) |= EMAC_CC_PTPCEN;
  3062. //
  3063. // Write the subsecond increment value.
  3064. //
  3065. HWREG(ui32Base + EMAC_O_SUBSECINC) = ((ui32SubSecondInc <<
  3066. EMAC_SUBSECINC_SSINC_S) &
  3067. EMAC_SUBSECINC_SSINC_M);
  3068. //
  3069. // Set the timestamp configuration.
  3070. //
  3071. HWREG(ui32Base + EMAC_O_TIMSTCTRL) = ui32Config;
  3072. }
  3073. //*****************************************************************************
  3074. //
  3075. //! Returns the current IEEE 1588 timestamping configuration.
  3076. //!
  3077. //! \param ui32Base is the base address of the controller.
  3078. //! \param pui32SubSecondInc points to storage that is written with the
  3079. //! current subsecond increment value for the IEEE 1588 clock.
  3080. //!
  3081. //! This function may be used to retreive the current MAC timestamping
  3082. //! configuration.
  3083. //!
  3084. //! \sa EMACTimestampConfigSet()
  3085. //!
  3086. //! \return Returns the current timestamping configuration as a logical OR of
  3087. //! the following flags:
  3088. //!
  3089. //! - \b EMAC_TS_PTP_VERSION_2 indicates that the MAC is processing PTP
  3090. //! version 2 messages. If this flag is absent, PTP version 1 messages are
  3091. //! expected.
  3092. //! - \b EMAC_TS_DIGITAL_ROLLOVER causes the clock's subsecond value to roll
  3093. //! over at 0x3BA9C9FF (999999999 decimal). In this mode, it can be considered
  3094. //! as a nanosecond counter with each digit representing 1 ns. If this flag is
  3095. //! absent, the subsecond value rolls over at 0x7FFFFFFF, effectively counting
  3096. //! increments of 0.465 ns.
  3097. //! - \b EMAC_TS_MAC_FILTER_ENABLE indicates that incoming PTP messages
  3098. //! are filtered using any of the configured MAC addresses. Messages with a
  3099. //! destination address programmed into the MAC address filter are passed,
  3100. //! others are discarded. If this flag is absent, the MAC address is ignored.
  3101. //! - \b EMAC_TS_UPDATE_FINE implements the fine update method that causes the
  3102. //! IEEE 1588 clock to advance by the the value returned in the
  3103. //! \e *pui32SubSecondInc parameter each time a carry is generated from the
  3104. //! addend accumulator register. If this flag is absent, the coarse update
  3105. //! method is in use and the clock is advanced by the \e *pui32SubSecondInc
  3106. //! value on each system clock tick.
  3107. //! - \b EMAC_TS_SYNC_ONLY indicates that timestamps are only generated for
  3108. //! SYNC messages.
  3109. //! - \b EMAC_TS_DELAYREQ_ONLY indicates that timestamps are only generated
  3110. //! for Delay_Req messages.
  3111. //! - \b EMAC_TS_ALL indicates that timestamps are generated for all
  3112. //! IEEE 1588 messages.
  3113. //! - \b EMAC_TS_SYNC_PDREQ_PDRESP timestamps only SYNC, Pdelay_Req and
  3114. //! Pdelay_Resp messages.
  3115. //! - \b EMAC_TS_DREQ_PDREQ_PDRESP indicates that timestamps are only
  3116. //! generated for Delay_Req, Pdelay_Req and Pdelay_Resp messages.
  3117. //! - \b EMAC_TS_SYNC_DELAYREQ indicates that timestamps are only generated
  3118. //! for Delay_Req messages.
  3119. //! - \b EMAC_TS_PDREQ_PDRESP indicates that timestamps are only generated
  3120. //! for Pdelay_Req and Pdelay_Resp messages.
  3121. //! - \b EMAC_TS_PROCESS_IPV4_UDP indicates that PTP packets encapsulated in
  3122. //! UDP over IPv4 packets are being processed. If absent, the MAC ignores
  3123. //! these frames.
  3124. //! - \b EMAC_TS_PROCESS_IPV6_UDP indicates that PTP packets encapsulated in
  3125. //! UDP over IPv6 packets are being processed. If absent, the MAC ignores
  3126. //! these frames.
  3127. //! - \b EMAC_TS_PROCESS_ETHERNET indicates that PTP packets encapsulated
  3128. //! directly in Ethernet frames are being processd. If absent, the MAC ignores
  3129. //! these frames.
  3130. //! - \b EMAC_TS_ALL_RX_FRAMES indicates that timestamping is enabled for all
  3131. //! frames received by the MAC, regardless of type.
  3132. //!
  3133. //! If \b EMAC_TS_ALL_RX_FRAMES and none of the options specifying subsets
  3134. //! of PTP packets to timestamp are set, the MAC is configured to timestamp
  3135. //! SYNC, Follow_Up, Delay_Req and Delay_Resp messages only.
  3136. //
  3137. //*****************************************************************************
  3138. uint32_t
  3139. EMACTimestampConfigGet(uint32_t ui32Base, uint32_t *pui32SubSecondInc)
  3140. {
  3141. //
  3142. // Parameter sanity check.
  3143. //
  3144. ASSERT(ui32Base == EMAC0_BASE);
  3145. ASSERT(pui32SubSecondInc);
  3146. //
  3147. // Read the current subsecond increment value.
  3148. //
  3149. *pui32SubSecondInc = (HWREG(ui32Base + EMAC_O_SUBSECINC) &
  3150. EMAC_SUBSECINC_SSINC_M) >> EMAC_SUBSECINC_SSINC_S;
  3151. //
  3152. // Return the current timestamp configuration.
  3153. //
  3154. return (HWREG(ui32Base + EMAC_O_TIMSTCTRL));
  3155. }
  3156. //*****************************************************************************
  3157. //
  3158. //! Enables packet timestamping and starts the system clock running.
  3159. //!
  3160. //! \param ui32Base is the base address of the controller.
  3161. //!
  3162. //! This function is used to enable the system clock used to timestamp
  3163. //! Ethernet frames and to enable that timestamping.
  3164. //!
  3165. //! \return None.
  3166. //
  3167. //*****************************************************************************
  3168. void
  3169. EMACTimestampEnable(uint32_t ui32Base)
  3170. {
  3171. //
  3172. // Parameter sanity check.
  3173. //
  3174. ASSERT(ui32Base == EMAC0_BASE);
  3175. //
  3176. // Enable IEEE 1588 timestamping.
  3177. //
  3178. HWREG(ui32Base + EMAC_O_TIMSTCTRL) |= EMAC_TIMSTCTRL_TSEN;
  3179. //
  3180. // If necessary, initialize the timestamping system. This bit self-clears
  3181. // once the system time is loaded. Only do this if initialization is not
  3182. // currently ongoing.
  3183. //
  3184. if (!(HWREG(ui32Base + EMAC_O_TIMSTCTRL) & EMAC_TIMSTCTRL_TSINIT))
  3185. {
  3186. HWREG(ui32Base + EMAC_O_TIMSTCTRL) |= EMAC_TIMSTCTRL_TSINIT;
  3187. }
  3188. }
  3189. //*****************************************************************************
  3190. //
  3191. //! Disables packet timestamping and stops the system clock.
  3192. //!
  3193. //! \param ui32Base is the base address of the controller.
  3194. //!
  3195. //! This function is used to stop the system clock used to timestamp
  3196. //! Ethernet frames and to disable timestamping.
  3197. //!
  3198. //! \return None.
  3199. //
  3200. //*****************************************************************************
  3201. void
  3202. EMACTimestampDisable(uint32_t ui32Base)
  3203. {
  3204. //
  3205. // Parameter sanity check.
  3206. //
  3207. ASSERT(ui32Base == EMAC0_BASE);
  3208. //
  3209. // Disable IEEE 1588 timestamping.
  3210. //
  3211. HWREG(ui32Base + EMAC_O_TIMSTCTRL) &= ~EMAC_TIMSTCTRL_TSEN;
  3212. }
  3213. //*****************************************************************************
  3214. //
  3215. //! Sets the current system time.
  3216. //!
  3217. //! \param ui32Base is the base address of the controller.
  3218. //! \param ui32Seconds is the seconds value of the new system clock setting.
  3219. //! \param ui32SubSeconds is the subseconds value of the new system clock
  3220. //! setting.
  3221. //!
  3222. //! This function may be used to set the current system time. The system
  3223. //! clock is set to the value passed in the \e ui32Seconds and
  3224. //! \e ui32SubSeconds parameters.
  3225. //!
  3226. //! The meaning of \e ui32SubSeconds depends on the current system time
  3227. //! configuration. If EMACTimestampConfigSet() was previously called with
  3228. //! the \e EMAC_TS_DIGITAL_ROLLOVER configuration option, each bit in the
  3229. //! \e ui32SubSeconds value represents 1 ns. If \e EMAC_TS_BINARY_ROLLOVER was
  3230. //! specified instead, a \e ui32SubSeconds bit represents 0.46 ns.
  3231. //!
  3232. //! \return None.
  3233. //
  3234. //*****************************************************************************
  3235. void
  3236. EMACTimestampSysTimeSet(uint32_t ui32Base, uint32_t ui32Seconds,
  3237. uint32_t ui32SubSeconds)
  3238. {
  3239. //
  3240. // Parameter sanity check.
  3241. //
  3242. ASSERT(ui32Base == EMAC0_BASE);
  3243. //
  3244. // Write the new time to the system time update registers.
  3245. //
  3246. HWREG(ui32Base + EMAC_O_TIMSECU) = ui32Seconds;
  3247. HWREG(ui32Base + EMAC_O_TIMNANOU) = ui32SubSeconds;
  3248. //
  3249. // Wait for any previous update to complete.
  3250. //
  3251. while (HWREG(ui32Base + EMAC_O_TIMSTCTRL) & EMAC_TIMSTCTRL_TSINIT)
  3252. {
  3253. //
  3254. // Spin for a while.
  3255. //
  3256. }
  3257. //
  3258. // Force the system clock to reset.
  3259. //
  3260. HWREG(ui32Base + EMAC_O_TIMSTCTRL) |= EMAC_TIMSTCTRL_TSINIT;
  3261. }
  3262. //*****************************************************************************
  3263. //
  3264. //! Gets the current system time.
  3265. //!
  3266. //! \param ui32Base is the base address of the controller.
  3267. //! \param pui32Seconds points to storage for the current seconds value.
  3268. //! \param pui32SubSeconds points to storage for the current subseconds value.
  3269. //!
  3270. //! This function may be used to get the current system time.
  3271. //!
  3272. //! The meaning of \e ui32SubSeconds depends on the current system time
  3273. //! configuration. If EMACTimestampConfigSet() was previously called with
  3274. //! the \e EMAC_TS_DIGITAL_ROLLOVER configuration option, each bit in the
  3275. //! \e ui32SubSeconds value represents 1 ns. If \e EMAC_TS_BINARY_ROLLOVER was
  3276. //! specified instead, a \e ui32SubSeconds bit represents 0.46 ns.
  3277. //!
  3278. //! \return None.
  3279. //
  3280. //*****************************************************************************
  3281. void
  3282. EMACTimestampSysTimeGet(uint32_t ui32Base, uint32_t *pui32Seconds,
  3283. uint32_t *pui32SubSeconds)
  3284. {
  3285. //
  3286. // Parameter sanity check.
  3287. //
  3288. ASSERT(ui32Base == EMAC0_BASE);
  3289. ASSERT(pui32Seconds);
  3290. ASSERT(pui32SubSeconds);
  3291. //
  3292. // Read the two-part system time from the seconds and nanoseconds
  3293. // registers. We do this in a way that should guard against us reading
  3294. // the registers across a nanosecond wrap.
  3295. //
  3296. do
  3297. {
  3298. *pui32Seconds = HWREG(ui32Base + EMAC_O_TIMSEC);
  3299. *pui32SubSeconds = HWREG(ui32Base + EMAC_O_TIMNANO);
  3300. }
  3301. while (*pui32Seconds != HWREG(ui32Base + EMAC_O_TIMNANO));
  3302. }
  3303. //*****************************************************************************
  3304. //
  3305. //! Adjusts the current system time upwards or downwards by a given amount.
  3306. //!
  3307. //! \param ui32Base is the base address of the controller.
  3308. //! \param ui32Seconds is the seconds value of the time update to apply.
  3309. //! \param ui32SubSeconds is the subseconds value of the time update to apply.
  3310. //! \param bInc defines the direction of the update.
  3311. //!
  3312. //! This function may be used to adjust the current system time either upwards
  3313. //! or downwards by a given amount. The size of the adjustment is given by
  3314. //! the \e ui32Seconds and \e ui32SubSeconds parameter and the direction
  3315. //! by the \e bInc parameter. When \e bInc is \e true, the system time is
  3316. //! advanced by the interval given. When it is \e false, the time is retarded
  3317. //! by the interval.
  3318. //!
  3319. //! The meaning of \e ui32SubSeconds depends on the current system time
  3320. //! configuration. If EMACTimestampConfigSet() was previously called with
  3321. //! the \e EMAC_TS_DIGITAL_ROLLOVER configuration option, each bit in the
  3322. //! subsecond value represents 1 ns. If \e EMAC_TS_BINARY_ROLLOVER was
  3323. //! specified instead, a subsecond bit represents 0.46 ns.
  3324. //!
  3325. //! \return None.
  3326. //
  3327. //*****************************************************************************
  3328. void
  3329. EMACTimestampSysTimeUpdate(uint32_t ui32Base, uint32_t ui32Seconds,
  3330. uint32_t ui32SubSeconds, bool bInc)
  3331. {
  3332. //
  3333. // Parameter sanity check.
  3334. //
  3335. ASSERT(ui32Base == EMAC0_BASE);
  3336. //
  3337. // Write the new time to the system time update registers.
  3338. //
  3339. HWREG(ui32Base + EMAC_O_TIMSECU) = ui32Seconds;
  3340. HWREG(ui32Base + EMAC_O_TIMNANOU) = ui32SubSeconds |
  3341. (bInc ? 0 : EMAC_TIMNANOU_ADDSUB);
  3342. //
  3343. // Wait for any previous update to complete.
  3344. //
  3345. while (HWREG(ui32Base + EMAC_O_TIMSTCTRL) & EMAC_TIMSTCTRL_TSUPDT)
  3346. {
  3347. //
  3348. // Spin for a while.
  3349. //
  3350. }
  3351. //
  3352. // Force the system clock to update by the value provided.
  3353. //
  3354. HWREG(ui32Base + EMAC_O_TIMSTCTRL) |= EMAC_TIMSTCTRL_TSUPDT;
  3355. }
  3356. //*****************************************************************************
  3357. //
  3358. //! Adjusts the system time update rate when using the fine correction method.
  3359. //!
  3360. //! \param ui32Base is the base address of the controller.
  3361. //! \param ui32Increment is the number to add to the accumulator register on
  3362. //! each tick of the 25-MHz main oscillator.
  3363. //!
  3364. //! This function is used to control the rate of update of the system time
  3365. //! when in fine update mode. Fine correction mode is selected if
  3366. //! \e EMAC_TS_UPDATE_FINE is supplied in the \e ui32Config parameter passed
  3367. //! to a previous call to EMACTimestampConfigSet(). Fine update mode is
  3368. //! typically used when synchronizing the local clock to the IEEE 1588 master
  3369. //! clock. The subsecond counter is incremented by the number passed to
  3370. //! EMACTimestampConfigSet() in the \e ui32SubSecondInc parameter each time a
  3371. //! 32-bit accumulator register generates a carry. The accumulator register is
  3372. //! incremented by the "addend" value on each main oscillator tick, and this
  3373. //! addend value is modified to allow fine control over the rate of change of
  3374. //! the timestamp counter. The addend value is calculated using the ratio of
  3375. //! the main oscillator clock rate and the desired IEEE 1588 clock rate and the
  3376. //! \e ui32SubSecondInc value is set to correspond to the desired IEEE 1588
  3377. //! clock rate.
  3378. //!
  3379. //! As an example, using digital rollover mode and a 25-MHz main oscillator
  3380. //! clock with a desired IEEE 1588 clock accuracy of 12.5 MHz, and having made
  3381. //! a previous call to EMACTimestampConfigSet() with \e ui32SubSecondInc set to
  3382. //! the 12.5-MHz clock period of 80 ns, the initial \e ui32Increment value
  3383. //! would be set to 0x80000000 to generate a carry on every second main
  3384. //! oscillator tick. Because the system time updates each time the accumulator
  3385. //! overflows, small changes in the \e ui32Increment value can be used to very
  3386. //! finely control the system time rate.
  3387. //!
  3388. //! \return None.
  3389. //!
  3390. //! \sa EMACTimestampConfigSet()
  3391. //
  3392. //*****************************************************************************
  3393. void
  3394. EMACTimestampAddendSet(uint32_t ui32Base, uint32_t ui32Increment)
  3395. {
  3396. //
  3397. // Parameter sanity check.
  3398. //
  3399. ASSERT(ui32Base == EMAC0_BASE);
  3400. HWREG(ui32Base + EMAC_O_TIMADD) = ui32Increment;
  3401. //
  3402. // Wait for any previous update to complete.
  3403. //
  3404. while (HWREG(ui32Base + EMAC_O_TIMSTCTRL) & EMAC_TIMSTCTRL_ADDREGUP)
  3405. {
  3406. //
  3407. // Spin for a while.
  3408. //
  3409. }
  3410. //
  3411. // Force the system clock to update by the value provided.
  3412. //
  3413. HWREG(ui32Base + EMAC_O_TIMSTCTRL) |= EMAC_TIMSTCTRL_ADDREGUP;
  3414. }
  3415. //*****************************************************************************
  3416. //
  3417. //! Sets the target system time at which the next Ethernet timer interrupt is
  3418. //! generated.
  3419. //!
  3420. //! \param ui32Base is the base address of the controller.
  3421. //! \param ui32Seconds is the second value of the desired target time.
  3422. //! \param ui32SubSeconds is the subseconds value of the desired target time.
  3423. //!
  3424. //! This function may be used to schedule an interrupt at some future time.
  3425. //! The time reference for the function is the IEEE 1588 time as returned by
  3426. //! EMACTimestampSysTimeGet(). To generate an interrupt when the system
  3427. //! time exceeds a given value, call this function to set the desired time,
  3428. //! then EMACTimestampTargetIntEnable() to enable the interrupt. When the
  3429. //! system time increments past the target time, an Ethernet interrupt with
  3430. //! status \b EMAC_INT_TIMESTAMP is generated.
  3431. //!
  3432. //! The accuracy of the interrupt timing depends on the Ethernet timer
  3433. //! update frequency and the subsecond increment value currently in use. The
  3434. //! interrupt is generated on the first timer increment that causes the
  3435. //! system time to be greater than or equal to the target time set.
  3436. //!
  3437. //! \return None.
  3438. //
  3439. //*****************************************************************************
  3440. void
  3441. EMACTimestampTargetSet(uint32_t ui32Base, uint32_t ui32Seconds,
  3442. uint32_t ui32SubSeconds)
  3443. {
  3444. //
  3445. // Parameter sanity check.
  3446. //
  3447. ASSERT(ui32Base == EMAC0_BASE);
  3448. //
  3449. // Wait for any previous write to complete.
  3450. //
  3451. while (HWREG(ui32Base + EMAC_O_TARGNANO) & EMAC_TARGNANO_TRGTBUSY)
  3452. {
  3453. }
  3454. //
  3455. // Write the new target time.
  3456. //
  3457. HWREG(ui32Base + EMAC_O_TARGSEC) = ui32Seconds;
  3458. HWREG(ui32Base + EMAC_O_TARGNANO) = ui32SubSeconds;
  3459. }
  3460. //*****************************************************************************
  3461. //
  3462. //! Enables the Ethernet system time interrupt.
  3463. //!
  3464. //! \param ui32Base is the base address of the controller.
  3465. //!
  3466. //! This function may be used after EMACTimestampTargetSet() to schedule an
  3467. //! interrupt at some future time. The time reference for the function is
  3468. //! the IEEE 1588 time as returned by EMACTimestampSysTimeGet(). To generate
  3469. //! an interrupt when the system time exceeds a given value, call this function
  3470. //! to set the desired time, then EMACTimestampTargetIntEnable() to enable the
  3471. //! interrupt. When the system time increments past the target time, an
  3472. //! Ethernet interrupt with status \b EMAC_INT_TIMESTAMP is generated.
  3473. //!
  3474. //! \return None.
  3475. //
  3476. //*****************************************************************************
  3477. void
  3478. EMACTimestampTargetIntEnable(uint32_t ui32Base)
  3479. {
  3480. //
  3481. // Parameter sanity check.
  3482. //
  3483. ASSERT(ui32Base == EMAC0_BASE);
  3484. //
  3485. // Set the bit to enable the timestamp target interrupt. This bit clears
  3486. // automatically when the interrupt fires after which point, you must
  3487. // set a new target time and re-enable the interrupts.
  3488. //
  3489. HWREG(ui32Base + EMAC_O_TIMSTCTRL) |= EMAC_TIMSTCTRL_INTTRIG;
  3490. }
  3491. //*****************************************************************************
  3492. //
  3493. //! Disables the Ethernet system time interrupt.
  3494. //!
  3495. //! \param ui32Base is the base address of the controller.
  3496. //!
  3497. //! This function may be used to disable any pending Ethernet system time
  3498. //! interrupt previously scheduled using calls to EMACTimestampTargetSet()
  3499. //! and EMACTimestampTargetIntEnable().
  3500. //!
  3501. //! \return None.
  3502. //
  3503. //*****************************************************************************
  3504. void
  3505. EMACTimestampTargetIntDisable(uint32_t ui32Base)
  3506. {
  3507. //
  3508. // Parameter sanity check.
  3509. //
  3510. ASSERT(ui32Base == EMAC0_BASE);
  3511. //
  3512. // Clear the bit to disable the timestamp target interrupt. This bit
  3513. // clears automatically when the interrupt fires, so it only must be
  3514. // disabled if you want to cancel a previously-set interrupt.
  3515. //
  3516. HWREG(ui32Base + EMAC_O_TIMSTCTRL) &= ~EMAC_TIMSTCTRL_INTTRIG;
  3517. }
  3518. //*****************************************************************************
  3519. //
  3520. //! Reads the status of the Ethernet system time interrupt.
  3521. //!
  3522. //! \param ui32Base is the base address of the controller.
  3523. //!
  3524. //! When an Ethernet interrupt occurs and \b EMAC_INT_TIMESTAMP is reported
  3525. //! bu EMACIntStatus(), this function must be called to read and clear the
  3526. //! timer interrupt status.
  3527. //!
  3528. //! \return The return value is the logical OR of the values
  3529. //! \b EMAC_TS_INT_TS_SEC_OVERFLOW and \b EMAC_TS_INT_TARGET_REACHED.
  3530. //!
  3531. //! - \b EMAC_TS_INT_TS_SEC_OVERFLOW indicates that the second counter in the
  3532. //! hardware timer has rolled over.
  3533. //! - \b EMAC_TS_INT_TARGET_REACHED indicates that the system time incremented
  3534. //! past the value set in an earlier call to EMACTimestampTargetSet(). When
  3535. //! this occurs, a new target time may be set and the interrupt re-enabled
  3536. //! using calls to EMACTimestampTargetSet() and
  3537. //! EMACTimestampTargetIntEnable().
  3538. //
  3539. //*****************************************************************************
  3540. uint32_t
  3541. EMACTimestampIntStatus(uint32_t ui32Base)
  3542. {
  3543. //
  3544. // Parameter sanity check.
  3545. //
  3546. ASSERT(ui32Base == EMAC0_BASE);
  3547. //
  3548. // Return the current interrupt status from the timestamp module.
  3549. //
  3550. return (HWREG(ui32Base + EMAC_O_TIMSTAT));
  3551. }
  3552. //*****************************************************************************
  3553. //
  3554. //! Configures the Ethernet MAC PPS output in simple mode.
  3555. //!
  3556. //! \param ui32Base is the base address of the controller.
  3557. //! \param ui32FreqConfig determines the frequency of the output generated on
  3558. //! the PPS pin.
  3559. //!
  3560. //! This function configures the Ethernet MAC PPS (Pulse Per Second) engine to
  3561. //! operate in its simple mode which allows the generation of a few, fixed
  3562. //! frequencies and pulse widths on the PPS pin. If more complex pulse
  3563. //! train generation is required, the MAC also provides a command-based
  3564. //! PPS control mode that can be selected by calling
  3565. //! EMACTimestampPPSCommandModeSet().
  3566. //!
  3567. //! The \e ui32FreqConfig parameter may take one of the following values:
  3568. //!
  3569. //! - \b EMAC_PPS_SINGLE_PULSE generates a single high pulse on the PPS
  3570. //! output once per second. The pulse width is the same as the system clock
  3571. //! period.
  3572. //! - \b EMAC_PPS_1HZ generates a 1Hz signal on the PPS output. This option
  3573. //! is not available if the system time subsecond counter is currently
  3574. //! configured to operate in binary rollover mode.
  3575. //! - \b EMAC_PPS_2HZ, \b EMAC_PPS_4HZ, \b EMAC_PPS_8HZ,
  3576. //! \b EMAC_PPS_16HZ, \b EMAC_PPS_32HZ, \b EMAC_PPS_64HZ,
  3577. //! \b EMAC_PPS_128HZ, \b EMAC_PPS_256HZ, \b EMAC_PPS_512HZ,
  3578. //! \b EMAC_PPS_1024HZ, \b EMAC_PPS_2048HZ, \b EMAC_PPS_4096HZ,
  3579. //! \b EMAC_PPS_8192HZ, \b EMAC_PPS_16384HZ generate the requested
  3580. //! frequency on the PPS output in both binary and digital rollover modes.
  3581. //! - \b EMAC_PPS_32768HZ generates a 32KHz signal on the PPS output. This
  3582. //! option is not available if the system time subsecond counter is currently
  3583. //! configured to operate in digital rollover mode.
  3584. //!
  3585. //! Except when \b EMAC_PPS_SINGLE_PULSE is specified, the signal generated
  3586. //! on PPS has a duty cycle of 50% when binary rollover mode is used for the
  3587. //! system time subsecond count. In digital mode, the output frequency
  3588. //! averages the value requested and is resynchronized each second. For
  3589. //! example, if \b EMAC_PPS_4HZ is selected in digital rollover mode, the
  3590. //! output generates three clocks with 50 percent duty cycle and 268 ms
  3591. //! period followed by a fourth clock of 195 ms period, 134 ms low and 61 ms high.
  3592. //!
  3593. //! \return None.
  3594. //
  3595. //*****************************************************************************
  3596. void
  3597. EMACTimestampPPSSimpleModeSet(uint32_t ui32Base, uint32_t ui32FreqConfig)
  3598. {
  3599. bool bDigital;
  3600. //
  3601. // Parameter sanity check.
  3602. //
  3603. ASSERT(ui32Base == EMAC0_BASE);
  3604. //
  3605. // Are we currently running the clock in digital or binary rollover mode?
  3606. //
  3607. bDigital = (HWREG(ui32Base + EMAC_O_TIMSTCTRL) &
  3608. EMAC_TS_DIGITAL_ROLLOVER) ? true : false;
  3609. //
  3610. // Weed out some unsupported frequencies. The hardware can't produce a
  3611. // 1Hz output when we are in binary rollover mode and can't produce a
  3612. // 32KHz output when we are digital rollover mode.
  3613. //
  3614. ASSERT(bDigital || (ui32FreqConfig != EMAC_PPS_1HZ));
  3615. ASSERT(!bDigital || (ui32FreqConfig != EMAC_PPS_32768HZ));
  3616. //
  3617. // Adjust the supplied frequency if we are currently in binary update mode
  3618. // where the control value generates an output that is twice as fast as
  3619. // in digital mode.
  3620. //
  3621. if ((ui32FreqConfig != EMAC_PPS_SINGLE_PULSE) && !bDigital)
  3622. {
  3623. ui32FreqConfig--;
  3624. }
  3625. //
  3626. // Write the frequency control value to the PPS control register, clearing
  3627. // the PPSEN0 bit to ensure that the PPS engine is in simple mode and not
  3628. // waiting for a command. We also clear the TRGMODS0 field to revert to
  3629. // the default operation of the target time registers.
  3630. //
  3631. HWREG(ui32Base + EMAC_O_PPSCTRL) = ui32FreqConfig;
  3632. }
  3633. //*****************************************************************************
  3634. //
  3635. //! Configures the Ethernet MAC PPS output in command mode.
  3636. //! \param ui32Base is the base address of the controller.
  3637. //! \param ui32Config determines how the system target time is used.
  3638. //!
  3639. //! The simple mode of operation offered by the PPS (Pulse Per Second) engine
  3640. //! may be too restrictive for some applications. The second mode, however,
  3641. //! allows complex pulse trains to be generated using commands that tell the
  3642. //! engine to send individual pulses or start and stop trains if pulses. In
  3643. //! this mode, the pulse width and period may be set arbitrarily based on
  3644. //! ticks of the clock used to update the system time. Commands are triggered
  3645. //! at specific times using the target time last set using a call to
  3646. //! EMACTimestampTargetSet().
  3647. //!
  3648. //! The \e ui32Config parameter may be used to control whether the target
  3649. //! time is used to trigger commands only or can also generate an interrupt
  3650. //! to the CPU. Valid values are:
  3651. //!
  3652. //! - \b EMAC_PPS_TARGET_INT configures the target time to only raise
  3653. //! an interrupt and not to trigger any pending PPS command.
  3654. //! - \b EMAC_PPS_TARGET_PPS configures the target time to trigger a pending
  3655. //! PPS command but not raise an interrupt.
  3656. //! - \b EMAC_PPS_TARGET_BOTH configures the target time to trigger any
  3657. //! pending PPS command and also raise an interrupt.
  3658. //!
  3659. //! To use command mode, an application must call this function to enable the
  3660. //! mode, then call:
  3661. //!
  3662. //! - EMACTimestampPPSPeriodSet() to set the desired pulse width and period
  3663. //! then
  3664. //! - EMACTimestampTargetSet() to set the time at which the next command is
  3665. //! executed, and finally
  3666. //! - EMACTimestampPPSCommand() to send a command to cause the pulse or
  3667. //! pulse train to be started at the required time.
  3668. //!
  3669. //! \return None.
  3670. //
  3671. //*****************************************************************************
  3672. void
  3673. EMACTimestampPPSCommandModeSet(uint32_t ui32Base, uint32_t ui32Config)
  3674. {
  3675. //
  3676. // Parameter sanity check.
  3677. //
  3678. ASSERT(ui32Base == EMAC0_BASE);
  3679. ASSERT(!(ui32Config & (EMAC_PPS_TARGET_INT | EMAC_PPS_TARGET_PPS |
  3680. EMAC_PPS_TARGET_BOTH)));
  3681. //
  3682. // Wait for any previous command write to complete.
  3683. //
  3684. while (HWREG(ui32Base + EMAC_O_PPSCTRL) & EMAC_PPSCTRL_PPSCTRL_M)
  3685. {
  3686. //
  3687. // Wait a bit.
  3688. //
  3689. }
  3690. //
  3691. // Write the configuration value to the PPS control register, setting the
  3692. // PPSEN0 bit to ensure that the PPS engine is in command mode and
  3693. // clearing the command in the PPSCTRL field.
  3694. //
  3695. HWREG(ui32Base + EMAC_O_PPSCTRL) = (EMAC_PPSCTRL_PPSEN0 | ui32Config);
  3696. }
  3697. //*****************************************************************************
  3698. //
  3699. //! Sends a command to control the PPS output from the Ethernet MAC.
  3700. //!
  3701. //! \param ui32Base is the base address of the controller.
  3702. //! \param ui8Cmd identifies the command to be sent.
  3703. //!
  3704. //! This function may be used to send a command to the MAC PPS (Pulse Per
  3705. //! Second) controller when it is operating in command mode. Command mode
  3706. //! is selected by calling EMACTimestampPPSCommandModeSet(). Valid
  3707. //! commands are as follow:
  3708. //!
  3709. //! - \b EMAC_PPS_COMMAND_NONE indicates no command.
  3710. //! - \b EMAC_PPS_COMMAND_START_SINGLE indicates that a single high pulse
  3711. //! should be generated when the system time reaches the current target time.
  3712. //! - \b EMAC_PPS_COMMAND_START_TRAIN indicates that a train of pulses
  3713. //! should be started when the system time reaches the current target time.
  3714. //! - \b EMAC_PPS_COMMAND_CANCEL_START cancels any pending start command if
  3715. //! the system time has not yet reached the programmed target time.
  3716. //! - \b EMAC_PPS_COMMAND_STOP_AT_TIME indicates that the current pulse
  3717. //! train should be stopped when the system time reaches the current target
  3718. //! time.
  3719. //! - \b EMAC_PPS_COMMAND_STOP_NOW indicates that the current pulse train
  3720. //! should be stopped immediately.
  3721. //! - \b EMAC_PPS_COMMAND_CANCEL_STOP cancels any pending stop command if
  3722. //! the system time has not yet reached the programmed target time.
  3723. //!
  3724. //! In all cases, the width of the pulses generated is governed by the
  3725. //! \e ui32Width parameter passed to EMACTimestampPPSPeriodSet(). If a
  3726. //! command starts a train of pulses, the period of the pulses is governed
  3727. //! by the \e ui32Period parameter passed to the same function.
  3728. //! Target times associated with PPS commands are set by calling
  3729. //! EMACTimestampTargetSet().
  3730. //!
  3731. //! \return None.
  3732. //
  3733. //*****************************************************************************
  3734. void
  3735. EMACTimestampPPSCommand(uint32_t ui32Base, uint8_t ui8Cmd)
  3736. {
  3737. //
  3738. // Parameter sanity check.
  3739. //
  3740. ASSERT(ui32Base == EMAC0_BASE);
  3741. //
  3742. // Wait for any previous command write to complete.
  3743. //
  3744. while (HWREG(ui32Base + EMAC_O_PPSCTRL) & EMAC_PPSCTRL_PPSCTRL_M)
  3745. {
  3746. //
  3747. // Wait a bit.
  3748. //
  3749. }
  3750. //
  3751. // Write the command to the PPS control register.
  3752. //
  3753. HWREG(ui32Base + EMAC_O_PPSCTRL) = (EMAC_PPSCTRL_PPSEN0 | ui8Cmd);
  3754. }
  3755. //*****************************************************************************
  3756. //
  3757. //! Sets the period and width of the pulses on the Ethernet MAC PPS output.
  3758. //!
  3759. //! \param ui32Base is the base address of the controller.
  3760. //! \param ui32Period is the period of the PPS output expressed in terms of
  3761. //! system time update ticks.
  3762. //! \param ui32Width is the width of the high portion of the PPS output
  3763. //! expressed in terms of system time update ticks.
  3764. //!
  3765. //! This function may be used to control the period and duty cycle of the
  3766. //! signal output on the Ethernet MAC PPS pin when the PPS generator is
  3767. //! operating in command mode and a command to send one or more pulses has been
  3768. //! executed. Command mode is selected by calling
  3769. //! EMACTimestampPPSCommandModeSet().
  3770. //!
  3771. //! In simple mode, the PPS output signal frequency is controlled by the
  3772. //! \e ui32FreqConfig parameter passed to EMACTimestampPPSSimpleModeSet().
  3773. //!
  3774. //! The \e ui32Period and \e ui32Width parameters are expressed in terms of
  3775. //! system time update ticks. When the system time is operating in coarse
  3776. //! update mode, each tick is equivalent to the system clock. In fine update
  3777. //! mode, a tick occurs every time the 32-bit system time accumulator overflows
  3778. //! and this, in turn, is determined by the value passed to the function
  3779. //! EMACTimestampAddendSet(). Regardless of the tick source, each tick
  3780. //! increments the actual system time, queried using EMACTimestampSysTimeGet()
  3781. //! by the subsecond increment value passed in the \e ui32SubSecondInc to
  3782. //! EMACTimestampConfigSet().
  3783. //!
  3784. //! \return None.
  3785. //
  3786. //*****************************************************************************
  3787. void
  3788. EMACTimestampPPSPeriodSet(uint32_t ui32Base, uint32_t ui32Period,
  3789. uint32_t ui32Width)
  3790. {
  3791. //
  3792. // Parameter sanity check.
  3793. //
  3794. ASSERT(ui32Base == EMAC0_BASE);
  3795. //
  3796. // Write the desired PPS period and pulse width.
  3797. //
  3798. HWREG(ui32Base + EMAC_O_PPS0INTVL) = ui32Period;
  3799. HWREG(ui32Base + EMAC_O_PPS0WIDTH) = ui32Width;
  3800. }
  3801. //*****************************************************************************
  3802. //
  3803. //! Sets options related to reception of VLAN-tagged frames.
  3804. //!
  3805. //! \param ui32Base is the base address of the controller.
  3806. //! \param ui16Tag is the IEEE 802.1Q VLAN tag expected for incoming frames.
  3807. //! \param ui32Config determines how the receiver handles VLAN-tagged frames.
  3808. //!
  3809. //! This function configures the receiver's handling of IEEE 802.1Q VLAN
  3810. //! tagged frames. Incoming tagged frames are filtered using either a perfect
  3811. //! filter or a hash filter. When hash filtering is disabled, VLAN frames
  3812. //! tagged with the value of \e ui16Tag pass the filter and all others are
  3813. //! rejected. The tag comparison may involve all 16 bits or only the 12-bit
  3814. //! VLAN ID portion of the tag.
  3815. //!
  3816. //! The \e ui32Config parameter is a logical OR of the following values:
  3817. //!
  3818. //! - \b EMAC_VLAN_RX_HASH_ENABLE enables hash filtering for VLAN tags. If
  3819. //! this flag is absent, perfect filtering using the tag supplied in \e ui16Tag
  3820. //! is performed. The hash filter may be set using EMACVLANHashFilterSet(),
  3821. //! and EMACVLANHashFilterBitCalculate() may be used to determine which bits
  3822. //! to set in the filter for given VLAN tags.
  3823. //! - \b EMAC_VLAN_RX_SVLAN_ENABLE causes the receiver to recognize S-VLAN
  3824. //! (Type = 0x88A8) frames as valid VLAN-tagged frames. If absent, only
  3825. //! frames with type 0x8100 are considered valid VLAN frames.
  3826. //! - \b EMAC_VLAN_RX_INVERSE_MATCH causes the receiver to pass all VLAN
  3827. //! frames for which the tags do not match the supplied \e ui16Tag value. If
  3828. //! this flag is absent, only tagged frames matching \e ui16Tag are passed.
  3829. //! - \b EMAC_VLAN_RX_12BIT_TAG causes the receiver to compare only the
  3830. //! bottom 12 bits of \e ui16Tag when performing either perfect or hash
  3831. //! filtering of VLAN frames. If this flag is absent, all 16 bits of the frame
  3832. //! tag are examined when filtering. If this flag is set and \e ui16Tag has
  3833. //! all bottom 12 bits clear, the receiver passes all frames with types
  3834. //! 0x8100 or 0x88A8 regardless of the tag values they contain.
  3835. //!
  3836. //! \note To ensure that VLAN frames that fail the tag filter are dropped
  3837. //! by the MAC, EMACFrameFilterSet() must be called with the \b
  3838. //! EMAC_FRMFILTER_VLAN flag set in the \e ui32FilterOpts parameter. If
  3839. //! this flag is not set, failing VLAN packets are received by the
  3840. //! application, but bit 10 of RDES0 (\b EMAC_FRMFILTER_VLAN) is clear
  3841. //! indicating that the packet did not match the current VLAG tag filter.
  3842. //!
  3843. //! \sa EMACVLANRxConfigGet()
  3844. //!
  3845. //! \return None
  3846. //
  3847. //*****************************************************************************
  3848. void
  3849. EMACVLANRxConfigSet(uint32_t ui32Base, uint16_t ui16Tag, uint32_t ui32Config)
  3850. {
  3851. //
  3852. // Parameter sanity check.
  3853. //
  3854. ASSERT(ui32Base == EMAC0_BASE);
  3855. //
  3856. // Write the VLAN tag register.
  3857. //
  3858. HWREG(ui32Base + EMAC_O_VLANTG) =
  3859. ui32Config | (((uint32_t)ui16Tag) << EMAC_VLANTG_VL_S);
  3860. }
  3861. //*****************************************************************************
  3862. //
  3863. //! Returns the currently-set options related to reception of VLAN-tagged
  3864. //! frames.
  3865. //!
  3866. //! \param ui32Base is the base address of the controller.
  3867. //! \param pui16Tag points to storage which is written with the currently
  3868. //! configured VLAN tag used for perfect filtering.
  3869. //!
  3870. //! This function returns information on how the receiver is currently
  3871. //! handling IEEE 802.1Q VLAN-tagged frames.
  3872. //!
  3873. //! \sa EMACVLANRxConfigSet()
  3874. //!
  3875. //! \return Returns flags defining how VLAN-tagged frames are handled. The
  3876. //! value is a logical OR of the following flags:
  3877. //!
  3878. //! - \b EMAC_VLAN_RX_HASH_ENABLE indicates that hash filtering is enabled
  3879. //! for VLAN tags. If this flag is absent, perfect filtering using the tag
  3880. //! returned in \e *pui16Tag is performed.
  3881. //! - \b EMAC_VLAN_RX_SVLAN_ENABLE indicates that the receiver recognizes
  3882. //! S-VLAN (Type = 0x88A8) frames as valid VLAN-tagged frames. If absent, only
  3883. //! frames with type 0x8100 are considered valid VLAN frames.
  3884. //! - \b EMAC_VLAN_RX_INVERSE_MATCH indicates that the receiver passes all
  3885. //! VLAN frames for which the tags do not match the \e *pui16Tag value. If
  3886. //! this flag is absent, only tagged frames matching \e *pui16Tag are passed.
  3887. //! - \b EMAC_VLAN_RX_12BIT_TAG indicates that the receiver is comparing only
  3888. //! the bottom 12 bits of \e *pui16Tag when performing either perfect or hash
  3889. //! filtering of VLAN frames. If this flag is absent, all 16 bits of the frame
  3890. //! tag are examined when filtering. If this flag is set and \e *pui16Tag has
  3891. //! all bottom 12 bits clear, the receiver passes all frames with types
  3892. //! 0x8100 or 0x88A8 regardless of the tag values they contain.
  3893. //
  3894. //*****************************************************************************
  3895. uint32_t
  3896. EMACVLANRxConfigGet(uint32_t ui32Base, uint16_t *pui16Tag)
  3897. {
  3898. uint32_t ui32Value;
  3899. //
  3900. // Parameter sanity check.
  3901. //
  3902. ASSERT(ui32Base == EMAC0_BASE);
  3903. ASSERT(pui16Tag);
  3904. //
  3905. // Read the VLAN tag register.
  3906. //
  3907. ui32Value = HWREG(ui32Base + EMAC_O_VLANTG);
  3908. //
  3909. // Extract the VLAN tag from the register.
  3910. //
  3911. *pui16Tag = (ui32Value & EMAC_VLANTG_VL_M) >> EMAC_VLANTG_VL_S;
  3912. //
  3913. // Return the configuration flags.
  3914. //
  3915. return (ui32Value & ~EMAC_VLANTG_VL_M);
  3916. }
  3917. //*****************************************************************************
  3918. //
  3919. //! Sets options related to transmission of VLAN-tagged frames.
  3920. //!
  3921. //! \param ui32Base is the base address of the controller.
  3922. //! \param ui16Tag is the VLAN tag to be used when inserting or replacing tags
  3923. //! in transmitted frames.
  3924. //! \param ui32Config determines the VLAN-related processing performed by
  3925. //! the transmitter.
  3926. //!
  3927. //! This function is used to configure transmitter options relating to
  3928. //! IEEE 802.1Q VLAN tagging. The transmitter may be set to insert tagging
  3929. //! into untagged frames or replace existing tags with new values.
  3930. //!
  3931. //! The \e ui16Tag parameter contains the VLAN tag to be used in outgoing
  3932. //! tagged frames. The \e ui32Config parameter is a logical OR of the
  3933. //! following labels:
  3934. //!
  3935. //! - \b EMAC_VLAN_TX_SVLAN uses the S-VLAN type (0x88A8) when inserting or
  3936. //! replacing tags in transmitted frames. If this label is absent, C-VLAN
  3937. //! type (0x8100) is used.
  3938. //! - \b EMAC_VLAN_TX_USE_VLC informs the transmitter that the VLAN tag
  3939. //! handling should be defined by the VLAN control (VLC) value provided in
  3940. //! this function call. If this tag is absent, VLAN handling is controlled
  3941. //! by fields in the transmit descriptor.
  3942. //!
  3943. //! If \b EMAC_VLAN_TX_USE_VLC is set, one of the following four labels
  3944. //! must also be included to define the transmit VLAN tag handling:
  3945. //!
  3946. //! - \b EMAC_VLAN_TX_VLC_NONE instructs the transmitter to perform no VLAN
  3947. //! tag insertion, deletion or replacement.
  3948. //! - \b EMAC_VLAN_TX_VLC_DELETE instructs the transmitter to remove VLAN
  3949. //! tags from all transmitted frames that contain them. As a result, bytes
  3950. //! 13, 14, 15 and 16 are removed from all frames with types 0x8100 or 0x88A8.
  3951. //! - \b EMAC_VLAN_TX_VLC_INSERT instructs the transmitter to insert a VLAN
  3952. //! type and tag into all outgoing frames regardless of whether or not they
  3953. //! already contain a VLAN tag.
  3954. //! - \b EMAC_VLAN_TX_VLC_REPLACE instructs the transmitter to replace the
  3955. //! VLAN tag in all frames of type 0x8100 or 0x88A8 with the value provided to
  3956. //! this function in the \e ui16Tag parameter.
  3957. //!
  3958. //! \return None
  3959. //
  3960. //*****************************************************************************
  3961. void
  3962. EMACVLANTxConfigSet(uint32_t ui32Base, uint16_t ui16Tag, uint32_t ui32Config)
  3963. {
  3964. //
  3965. // Parameter sanity check.
  3966. //
  3967. ASSERT(ui32Base == EMAC0_BASE);
  3968. //
  3969. // Write the VLAN Tag Inclusion or Replacement register.
  3970. //
  3971. HWREG(ui32Base + EMAC_O_VLNINCREP) =
  3972. ui32Config | ((uint32_t)ui16Tag << EMAC_VLNINCREP_VLT_S);
  3973. }
  3974. //*****************************************************************************
  3975. //
  3976. //! Returns currently-selected options related to transmission of VLAN-tagged
  3977. //! frames.
  3978. //!
  3979. //! \param ui32Base is the base address of the controller.
  3980. //! \param pui16Tag points to storage that is written with the VLAN tag
  3981. //! currently being used for insertion or replacement.
  3982. //!
  3983. //! This function returns information on the current settings related to VLAN
  3984. //! tagging of transmitted frames.
  3985. //!
  3986. //! \sa EMACVLANTxConfigSet()
  3987. //!
  3988. //! \return Returns flags describing the current VLAN configuration relating
  3989. //! to frame transmission. The return value is a logical OR of the following
  3990. //! values:
  3991. //!
  3992. //! - \b EMAC_VLAN_TX_SVLAN indicates that the S-VLAN type (0x88A8) is
  3993. //! being used when inserting or replacing tags in transmitted frames. If
  3994. //! this label is absent, C-VLAN type (0x8100) is being used.
  3995. //! - \b EMAC_VLAN_TX_USE_VLC indicates that the transmitter is processing
  3996. //! VLAN frames according to the VLAN control (VLC) value returned here. If
  3997. //! this tag is absent, VLAN handling is controlled by fields in the transmit
  3998. //! descriptor.
  3999. //!
  4000. //! If \b EMAC_VLAN_TX_USE_VLC is returned, one of the following four labels
  4001. //! is also included to define the transmit VLAN tag handling. Note that this
  4002. //! value may be extracted from the return value using the mask \b
  4003. //! EMAC_VLAN_TX_VLC_MASK.
  4004. //!
  4005. //! - \b EMAC_VLAN_TX_VLC_NONE indicates that the transmitter is not
  4006. //! performing VLAN tag insertion, deletion or replacement.
  4007. //! - \b EMAC_VLAN_TX_VLC_DELETE indicates that the transmitter is removing
  4008. //! VLAN tags from all transmitted frames which contain them.
  4009. //! - \b EMAC_VLAN_TX_VLC_INSERT indicates that the transmitter is inserting
  4010. //! a VLAN type and tag into all outgoing frames regardless of whether or not
  4011. //! they already contain a VLAN tag.
  4012. //! - \b EMAC_VLAN_TX_VLC_REPLACE indicates that the transmitter is replacing
  4013. //! the VLAN tag in all transmitted frames of type 0x8100 or 0x88A8 with the
  4014. //! value returned in \e *pui16Tag.
  4015. //
  4016. //*****************************************************************************
  4017. uint32_t
  4018. EMACVLANTxConfigGet(uint32_t ui32Base, uint16_t *pui16Tag)
  4019. {
  4020. uint32_t ui32Value;
  4021. //
  4022. // Parameter sanity check.
  4023. //
  4024. ASSERT(ui32Base == EMAC0_BASE);
  4025. ASSERT(pui16Tag);
  4026. //
  4027. // Read the VLAN Tag Inclusion or Replacement register.
  4028. //
  4029. ui32Value = HWREG(ui32Base + EMAC_O_VLNINCREP);
  4030. //
  4031. // Extract the tag.
  4032. //
  4033. *pui16Tag = (uint16_t)((ui32Value & EMAC_VLNINCREP_VLT_M) >>
  4034. EMAC_VLNINCREP_VLT_S);
  4035. //
  4036. // Return the configuration flags.
  4037. //
  4038. return (ui32Value & ~EMAC_VLNINCREP_VLT_M);
  4039. }
  4040. //*****************************************************************************
  4041. //
  4042. //! Returns the bit number to set in the VLAN hash filter corresponding to a
  4043. //! given tag.
  4044. //!
  4045. //! \param ui16Tag is the VLAN tag for which the hash filter bit number is to
  4046. //! be determined.
  4047. //!
  4048. //! This function may be used to determine which bit in the VLAN hash filter
  4049. //! to set to describe a given 12- or 16-bit VLAN tag. The returned value is
  4050. //! a 4-bit value indicating the bit number to set within the 16-bit VLAN
  4051. //! hash filter. For example, if 0x02 is returned, this indicates that bit
  4052. //! 2 of the hash filter must be set to pass the supplied VLAN tag.
  4053. //!
  4054. //! \return Returns the bit number to set in the VLAN hash filter to describe
  4055. //! the passed tag.
  4056. //
  4057. //*****************************************************************************
  4058. uint32_t
  4059. EMACVLANHashFilterBitCalculate(uint16_t ui16Tag)
  4060. {
  4061. uint32_t ui32CRC, ui32Mask, ui32Loop;
  4062. //
  4063. // Calculate the CRC for the MAC address.
  4064. //
  4065. ui32CRC = Crc32(0xFFFFFFFF, (uint8_t *)&ui16Tag, 2);
  4066. ui32CRC ^= 0xFFFFFFFF;
  4067. //
  4068. // Determine the hash bit to use from the calculated CRC. This is the
  4069. // top 4 bits of the reversed CRC (or the bottom 4 bits of the calculated
  4070. // CRC with the bit order of those 4 bits reversed).
  4071. //
  4072. ui32Mask = 0;
  4073. //
  4074. // Reverse the order of the bottom 4 bits of the calculated CRC.
  4075. //
  4076. for (ui32Loop = 0; ui32Loop < 4; ui32Loop++)
  4077. {
  4078. ui32Mask <<= 1;
  4079. ui32Mask |= (ui32CRC & 1);
  4080. ui32CRC >>= 1;
  4081. }
  4082. //
  4083. // Return the final hash filter bit index.
  4084. //
  4085. return (ui32Mask);
  4086. }
  4087. //*****************************************************************************
  4088. //
  4089. //! Sets the hash filter used to control reception of VLAN-tagged frames.
  4090. //!
  4091. //! \param ui32Base is the base address of the controller.
  4092. //! \param ui32Hash is the hash filter value to set.
  4093. //!
  4094. //! This function allows the VLAG tag hash filter to be set. By using hash
  4095. //! filtering, several different VLAN tags can be filtered very easily at the
  4096. //! cost of some false positive results that must be removed by software.
  4097. //!
  4098. //! The hash filter value passed in \e ui32Hash may be built up by calling
  4099. //! EMACVLANHashFilterBitCalculate() for each VLAN tag that is to pass the
  4100. //! filter and then set each of the bits for which the numbers are returned by
  4101. //! that function. Care must be taken when clearing bits in the hash filter
  4102. //! due to the fact that there is a many-to-one correspondence between VLAN
  4103. //! tags and hash filter bits.
  4104. //!
  4105. //! \return None
  4106. //
  4107. //*****************************************************************************
  4108. void
  4109. EMACVLANHashFilterSet(uint32_t ui32Base, uint32_t ui32Hash)
  4110. {
  4111. //
  4112. // Parameter sanity check.
  4113. //
  4114. ASSERT(ui32Base == EMAC0_BASE);
  4115. //
  4116. // Write the VLAN Hash Table register.
  4117. //
  4118. HWREG(ui32Base + EMAC_O_VLANHASH) = ui32Hash;
  4119. }
  4120. //*****************************************************************************
  4121. //
  4122. //! Returns the current value of the hash filter used to control reception of
  4123. //! VLAN-tagged frames.
  4124. //!
  4125. //! \param ui32Base is the base address of the controller.
  4126. //!
  4127. //! This function allows the current VLAN tag hash filter value to be returned.
  4128. //! Additional VLAN tags may be added to this filter by setting the appropriate
  4129. //! bits, determined by calling EMACVLANHashFilterBitCalculate(), and then
  4130. //! calling EMACVLANHashFilterSet() to set the new filter value.
  4131. //!
  4132. //! \return Returns the current value of the VLAN hash filter.
  4133. //
  4134. //*****************************************************************************
  4135. uint32_t
  4136. EMACVLANHashFilterGet(uint32_t ui32Base)
  4137. {
  4138. //
  4139. // Parameter sanity check.
  4140. //
  4141. ASSERT(ui32Base == EMAC0_BASE);
  4142. //
  4143. // Return the VLAN Hash Table register.
  4144. //
  4145. return (HWREG(ui32Base + EMAC_O_VLANHASH));
  4146. }
  4147. //*****************************************************************************
  4148. //
  4149. //! Sets values defining up to four frames used to trigger a remote wake-up.
  4150. //!
  4151. //! \param ui32Base is the base address of the controller.
  4152. //! \param pFilter points to the structure containing remote wake-up frame
  4153. //! filter information.
  4154. //!
  4155. //! This function may be used to define up to four different frames that
  4156. //! are considered by the Ethernet MAC to be remote wake-up signals. The
  4157. //! data passed to the function describes a wake-up frame in terms of a CRC
  4158. //! calculated on up to 31 payload bytes in the frame. The actual bytes used
  4159. //! in the CRC calculation are defined by means of a bit mask where a ``1''
  4160. //! indicates that a byte in the frame should contribute to the CRC
  4161. //! calculation and a ``0'' indicates that the byte should be skipped, as well
  4162. //! as an offset from the start of the frame to the payload byte that represents
  4163. //! the first byte in the 31-byte CRC-checked sequence.
  4164. //!
  4165. //! The \e pFilter parameter points to a structure containing the information
  4166. //! necessary to set up the filters. This structure contains the following
  4167. //! fields, each of which is replicated 4 times, once for each possible wake-up
  4168. //! frame:
  4169. //!
  4170. //! - \b pui32ByteMask defines whether a given byte in the chosen 31-byte
  4171. //! sequence within the frame should contribute to the CRC calculation or not.
  4172. //! A 1 indicates that the byte should contribute to the calculation, a 0
  4173. //! causes the byte to be skipped.
  4174. //! - \b pui8Command contains flags defining whether this filter is enabled
  4175. //! and, if so, whether it refers to unicast or multicast packets. Valid
  4176. //! values are one of \b EMAC_RWU_FILTER_MULTICAST or \b
  4177. //! EMAC_RWU_FILTER_UNICAST ORed with one of \b EMAC_RWU_FILTER_ENABLE or
  4178. //! \b EMAC_RWU_FILTER_DISABLE.
  4179. //! - \b pui8Offset defines the zero-based index of the byte within the frame
  4180. //! at which CRC checking defined by \b pui32ByteMask begins.
  4181. //! Alternatively, this value can be thought of as the number of bytes in the
  4182. //! frame that the MAC skips before accumulating the CRC based on the pattern
  4183. //! in \b pui32ByteMask.
  4184. //! - \b pui16CRC provides the value of the calculated CRC for a valid remote
  4185. //! wake-up frame. If the incoming frame is processed according to the filter
  4186. //! values provided and the final CRC calculation equals this value, the
  4187. //! frame is considered to be a valid remote wake-up frame.
  4188. //!
  4189. //! Note that this filter uses CRC16 rather than CRC32 as used in frame
  4190. //! checksums. The required CRC uses a direct algorithm with polynomial 0x8005,
  4191. //! initial seed value 0xFFFF, no final XOR and reversed data order. CRCs
  4192. //! for use in this function may be determined using the online calculator
  4193. //! found at http://www.zorc.breitbandkatze.de/crc.html.
  4194. //!
  4195. //! \return None.
  4196. //
  4197. //*****************************************************************************
  4198. void
  4199. EMACRemoteWakeUpFrameFilterSet(uint32_t ui32Base,
  4200. const tEMACWakeUpFrameFilter *pFilter)
  4201. {
  4202. uint32_t *pui32Data;
  4203. uint32_t ui32Loop;
  4204. //
  4205. // Parameter sanity check.
  4206. //
  4207. ASSERT(ui32Base == EMAC0_BASE);
  4208. ASSERT(pFilter);
  4209. //
  4210. // Make sure that the internal register counter for the frame filter
  4211. // is reset. This bit automatically resets after 1 clock cycle.
  4212. //
  4213. HWREG(ui32Base + EMAC_O_PMTCTLSTAT) |= EMAC_PMTCTLSTAT_WUPFRRST;
  4214. //
  4215. // Get a word pointer to the supplied structure.
  4216. //
  4217. pui32Data = (uint32_t *)pFilter;
  4218. //
  4219. // Write the 8 words of the wake-up filter definition to the hardware.
  4220. //
  4221. for (ui32Loop = 0; ui32Loop < 8; ui32Loop++)
  4222. {
  4223. //
  4224. // Write a word of the filter definition.
  4225. //
  4226. HWREG(ui32Base + EMAC_O_RWUFF) = pui32Data[ui32Loop];
  4227. }
  4228. }
  4229. //*****************************************************************************
  4230. //
  4231. //! Returns the current remote wake-up frame filter configuration.
  4232. //!
  4233. //! \param ui32Base is the base address of the controller.
  4234. //! \param pFilter points to the structure that is written with the current
  4235. //! remote wake-up frame filter information.
  4236. //!
  4237. //! This function may be used to read the current wake-up frame filter
  4238. //! settings. The data returned by the function describes wake-up frames in
  4239. //! terms of a CRC calculated on up to 31 payload bytes in the frame. The
  4240. //! actual bytes used in the CRC calculation are defined by means of a bit mask
  4241. //! where a ``1'' indicates that a byte in the frame should contribute to the
  4242. //! CRC calculation and a ``0'' indicates that the byte should be skipped, and
  4243. //! an offset from the start of the frame to the payload byte that represents
  4244. //! the first byte in the 31-byte CRC-checked sequence.
  4245. //!
  4246. //! The \e pFilter parameter points to storage that is written with a
  4247. //! structure containing the information defining the frame filters. This
  4248. //! structure contains the following fields, each of which is replicated 4
  4249. //! times, once for each possible wake-up frame:
  4250. //!
  4251. //! - \b pui32ByteMask defines whether a given byte in the chosen 31-byte
  4252. //! sequence within the frame should contribute to the CRC calculation or not.
  4253. //! A 1 indicates that the byte should contribute to the calculation, a 0
  4254. //! causes the byte to be skipped.
  4255. //! - \b pui8Command contains flags defining whether this filter is enabled
  4256. //! and, if so, whether it refers to unicast or multicast packets. Valid
  4257. //! values are one of \b EMAC_RWU_FILTER_MULTICAST or \b
  4258. //! EMAC_RWU_FILTER_UNICAST ORed with one of \b EMAC_RWU_FILTER_ENABLE or
  4259. //! \b EMAC_RWU_FILTER_DISABLE.
  4260. //! - \b pui8Offset defines the zero-based index of the byte within the frame
  4261. //! at which CRC checking defined by \b pui32ByteMask begins.
  4262. //! Alternatively, this value can be thought of as the number of bytes in the
  4263. //! frame that the MAC skips before accumulating the CRC based on the pattern
  4264. //! in \b pui32ByteMask.
  4265. //! - \b pui16CRC provides the value of the calculated CRC for a valid remote
  4266. //! wake-up frame. If the incoming frame is processed according to the filter
  4267. //! values provided and the final CRC calculation equals this value, the
  4268. //! frame is considered to be a valid remote wake-up frame.
  4269. //!
  4270. //! Note that this filter uses CRC16 rather than CRC32 as used in frame
  4271. //! checksums.
  4272. //!
  4273. //! \return None.
  4274. //
  4275. //*****************************************************************************
  4276. void
  4277. EMACRemoteWakeUpFrameFilterGet(uint32_t ui32Base,
  4278. tEMACWakeUpFrameFilter *pFilter)
  4279. {
  4280. uint32_t *pui32Data;
  4281. uint32_t ui32Loop;
  4282. //
  4283. // Parameter sanity check.
  4284. //
  4285. ASSERT(ui32Base == EMAC0_BASE);
  4286. ASSERT(pFilter);
  4287. //
  4288. // Make sure that the internal register counter for the frame filter
  4289. // is reset. This bit automatically resets after 1 clock cycle.
  4290. //
  4291. HWREG(ui32Base + EMAC_O_PMTCTLSTAT) |= EMAC_PMTCTLSTAT_WUPFRRST;
  4292. //
  4293. // Get a word pointer to the supplied structure.
  4294. //
  4295. pui32Data = (uint32_t *)pFilter;
  4296. //
  4297. // Read the 8 words of the wake-up filter definition from the hardware.
  4298. //
  4299. for (ui32Loop = 0; ui32Loop < 8; ui32Loop++)
  4300. {
  4301. //
  4302. // Read a word of the filter definition.
  4303. //
  4304. pui32Data[ui32Loop] = HWREG(ui32Base + EMAC_O_RWUFF);
  4305. }
  4306. }
  4307. //*****************************************************************************
  4308. //
  4309. //! Sets the Ethernet MAC remote wake-up configuration.
  4310. //!
  4311. //! \param ui32Base is the base address of the controller.
  4312. //! \param ui32Flags defines which types of frame should trigger a remote
  4313. //! wake-up and allows the MAC to be put into power-down mode.
  4314. //!
  4315. //! This function allows the MAC's remote wake-up features to be configured,
  4316. //! determining which types of frame should trigger a wake-up event and
  4317. //! allowing an application to place the MAC in power-down mode. In this
  4318. //! mode, the MAC ignores all received frames until one matching a
  4319. //! configured remote wake-up frame is received, at which point the MAC
  4320. //! automatically exits power-down mode and continues to receive frames.
  4321. //!
  4322. //! The \e ui32Flags parameter is a logical OR of the following flags:
  4323. //!
  4324. //! - \b EMAC_PMT_GLOBAL_UNICAST_ENABLE instructs the MAC to wake up when any
  4325. //! unicast frame matching the MAC destination address filter is received.
  4326. //! - \b EMAC_PMT_WAKEUP_PACKET_ENABLE instructs the MAC to wake up when any
  4327. //! received frame matches the remote wake-up filter configured via a call
  4328. //! to EMACRemoteWakeUpFrameFilterSet().
  4329. //! - \b EMAC_PMT_MAGIC_PACKET_ENABLE instructs the MAC to wake up when a
  4330. //! standard Wake-on-LAN "magic packet" is received. The magic packet contains
  4331. //! 6 bytes of 0xFF followed immediately by 16 repetitions of the destination
  4332. //! MAC address.
  4333. //! - \b EMAC_PMT_POWER_DOWN instructs the MAC to enter power-down mode and
  4334. //! wait for an incoming frame matching the remote wake-up frames as described
  4335. //! by other flags and via the remote wake-up filter. This flag should only
  4336. //! set set if at least one other flag is specified to configure a wake-up
  4337. //! frame type.
  4338. //!
  4339. //! When the MAC is in power-down mode, software may exit the mode by calling
  4340. //! this function with the \b EMAC_PMT_POWER_DOWN flag absent from \e ui32Flags.
  4341. //! If a configured wake-up frame is received while in power-down mode, the
  4342. //! \b EMAC_INT_POWER_MGMNT interrupt is signaled and may be cleared by reading
  4343. //! the status using EMACPowerManagementStatusGet().
  4344. //!
  4345. //! \note While it is possible to gate the clock to the MAC while it is in
  4346. //! power-down mode, doing so prevents the reading of the registers required
  4347. //! to determine the interrupt status and also prevents power-down mode from
  4348. //! exiting via another call to this function.
  4349. //!
  4350. //! \return None.
  4351. //
  4352. //*****************************************************************************
  4353. void
  4354. EMACPowerManagementControlSet(uint32_t ui32Base, uint32_t ui32Flags)
  4355. {
  4356. uint32_t ui32Value;
  4357. //
  4358. // Parameter sanity check.
  4359. //
  4360. ASSERT(ui32Base == EMAC0_BASE);
  4361. ASSERT(~(ui32Flags & ~(EMAC_PMT_GLOBAL_UNICAST_ENABLE |
  4362. EMAC_PMT_WAKEUP_PACKET_ENABLE |
  4363. EMAC_PMT_MAGIC_PACKET_ENABLE |
  4364. EMAC_PMT_POWER_DOWN)));
  4365. //
  4366. // Read the control/status register, clear all the bits we can set, mask
  4367. // in the new values then rewrite the new register value.
  4368. //
  4369. ui32Value = HWREG(ui32Base + EMAC_O_PMTCTLSTAT);
  4370. ui32Value &= ~(EMAC_PMTCTLSTAT_GLBLUCAST | EMAC_PMTCTLSTAT_WUPFREN |
  4371. EMAC_PMTCTLSTAT_MGKPKTEN | EMAC_PMTCTLSTAT_PWRDWN);
  4372. ui32Value |= ui32Flags;
  4373. HWREG(ui32Base + EMAC_O_PMTCTLSTAT) = ui32Value;
  4374. }
  4375. //*****************************************************************************
  4376. //
  4377. //! Queries the current Ethernet MAC remote wake-up configuration.
  4378. //!
  4379. //! \param ui32Base is the base address of the controller.
  4380. //!
  4381. //! This function allows the MAC's remote wake-up settings to be queried.
  4382. //! These settings determine which types of frame should trigger a remote
  4383. //! wake-up event
  4384. //!
  4385. //! \return Returns a logical OR of the following flags:
  4386. //!
  4387. //! - \b EMAC_PMT_GLOBAL_UNICAST_ENABLE indicates that the MAC wakes up when
  4388. //! any unicast frame matching the MAC destination address filter is received.
  4389. //! - \b EMAC_PMT_WAKEUP_PACKET_ENABLE indicates that the MAC wakes up when any
  4390. //! received frame matches the remote wake-up filter configured via a call
  4391. //! to EMACRemoteWakeUpFrameFilterSet().
  4392. //! - \b EMAC_PMT_MAGIC_PACKET_ENABLE indicates that the MAC wakes up when a
  4393. //! standard Wake-on-LAN "magic packet" is received. The magic packet contains
  4394. //! 6 bytes of 0xFF followed immediately by 16 repetitions of the destination
  4395. //! MAC address.
  4396. //! - \b EMAC_PMT_POWER_DOWN indicates that the MAC is currently in power-down
  4397. //! mode and is waiting for an incoming frame matching the remote wake-up
  4398. //! frames as described by other returned flags and via the remote wake-up
  4399. //! filter.
  4400. //
  4401. //*****************************************************************************
  4402. uint32_t
  4403. EMACPowerManagementControlGet(uint32_t ui32Base)
  4404. {
  4405. //
  4406. // Parameter sanity check.
  4407. //
  4408. ASSERT(ui32Base == EMAC0_BASE);
  4409. //
  4410. // Read the control/status register and mask off the control bits to return
  4411. // them to the caller.
  4412. //
  4413. return (HWREG(ui32Base + EMAC_O_PMTCTLSTAT) &
  4414. (EMAC_PMTCTLSTAT_GLBLUCAST | EMAC_PMTCTLSTAT_WUPFREN |
  4415. EMAC_PMTCTLSTAT_MGKPKTEN | EMAC_PMTCTLSTAT_PWRDWN));
  4416. }
  4417. //*****************************************************************************
  4418. //
  4419. //! Queries the current Ethernet MAC remote wake-up status.
  4420. //!
  4421. //! \param ui32Base is the base address of the controller.
  4422. //!
  4423. //! This function returns information on the remote wake-up state of the
  4424. //! Ethernet MAC. If the MAC has been woken up since the last call, the
  4425. //! returned value indicates the type of received frame that caused the MAC
  4426. //! to exit power-down state.
  4427. //!
  4428. //! \return Returns a logical OR of the following flags:
  4429. //!
  4430. //! - \b EMAC_PMT_POWER_DOWN indicates that the MAC is currently in power-down
  4431. //! mode.
  4432. //! - \b EMAC_PMT_WAKEUP_PACKET_RECEIVED indicates that the MAC exited
  4433. //! power-down mode due to a remote wake-up frame being received. This
  4434. //! function call clears this flag.
  4435. //! - \b EMAC_PMT_MAGIC_PACKET_RECEIVED indicates that the MAC exited
  4436. //! power-down mode due to a wake-on-LAN magic packet being received. This
  4437. //! function call clears this flag.
  4438. //
  4439. //*****************************************************************************
  4440. uint32_t
  4441. EMACPowerManagementStatusGet(uint32_t ui32Base)
  4442. {
  4443. //
  4444. // Parameter sanity check.
  4445. //
  4446. ASSERT(ui32Base == EMAC0_BASE);
  4447. //
  4448. // Read the control/status register and mask off the status bits to return
  4449. // them to the caller.
  4450. //
  4451. return (HWREG(ui32Base + EMAC_O_PMTCTLSTAT) &
  4452. (EMAC_PMTCTLSTAT_WUPRX | EMAC_PMTCTLSTAT_MGKPRX |
  4453. EMAC_PMTCTLSTAT_PWRDWN));
  4454. }
  4455. //*****************************************************************************
  4456. //
  4457. //! Enables the wake-on-LAN feature of the MAC controller.
  4458. //!
  4459. //! \param ui32Base is the base address of the controller.
  4460. //!
  4461. //! This function is used to enable the wake-on-LAN feature of the MAC
  4462. //! controller. It is done by first checking if the transmit path is idle and
  4463. //! disabling the trasnmitter and the transmit DMA controller. Then it checks
  4464. //! if any data from the network is being actively received and if not then it
  4465. //! disables the receive DMA controller.
  4466. //!
  4467. //! \return None.
  4468. //
  4469. //*****************************************************************************
  4470. void
  4471. EMACWoLEnter(uint32_t ui32Base)
  4472. {
  4473. //
  4474. // Parameter sanity check.
  4475. //
  4476. ASSERT(ui32Base == EMAC0_BASE);
  4477. //
  4478. // Check if the Transmit interrupt bit is clear.
  4479. //
  4480. while (HWREG(ui32Base + EMAC_O_DMARIS) == EMAC_DMARIS_TI)
  4481. {
  4482. }
  4483. //
  4484. // Disable transmission in the MAC configuration register.
  4485. //
  4486. HWREG(ui32Base + EMAC_O_CFG) &= ~EMAC_CFG_TE;
  4487. //
  4488. // Disable the MAC transmit path in the opmode register.
  4489. //
  4490. HWREG(ui32Base + EMAC_O_DMAOPMODE) &= ~EMAC_DMAOPMODE_ST;
  4491. //
  4492. // Check if the Receive FIFO is empty.
  4493. //
  4494. while ((HWREG(ui32Base + EMAC_O_STATUS) & EMAC_STATUS_RX_FIFO_LEVEL_MASK) ==
  4495. EMAC_STATUS_RX_FIFO_EMPTY)
  4496. {
  4497. }
  4498. //
  4499. // Disable the MAC receive path.
  4500. //
  4501. HWREG(ui32Base + EMAC_O_DMAOPMODE) &= ~EMAC_DMAOPMODE_SR;
  4502. }
  4503. //*****************************************************************************
  4504. //
  4505. //! Configures the LPI timers and control register.
  4506. //!
  4507. //! \param ui32Base is the base address of the controller.
  4508. //! \param bLPIConfig is state of LPI trasnmit automate bit.
  4509. //! \param ui16LPILSTimer is the value of LS timer in milli-seconds.
  4510. //! \param ui16LPITWTimer is the value of TW timer in micro-seconds.
  4511. //!
  4512. //! This function is used to configure the LPI timer and control registers when
  4513. //! the link is established as EEE mode or when the link is lost. When the link
  4514. //! is established as EEE, then \e ui16LPILSTimer is programmed as the link
  4515. //! status timer value and \e ui16LPITWTimer is programmed as the transmit wait
  4516. //! timer value. The parameter \e bLPIConfig is used to decide if the transmit
  4517. //! path must be automated or should be under user control.
  4518. //!
  4519. //! \return None.
  4520. //
  4521. //*****************************************************************************
  4522. void
  4523. EMACLPIConfig(uint32_t ui32Base, bool bLPIConfig, uint16_t ui16LPILSTimer,
  4524. uint16_t ui16LPITWTimer)
  4525. {
  4526. uint32_t ui32TimerValue;
  4527. //
  4528. // Parameter sanity check.
  4529. //
  4530. ASSERT(ui32Base == EMAC0_BASE);
  4531. ui32TimerValue = ((ui16LPILSTimer << EMAC_LPITIMERCTL_LST_S) &
  4532. EMAC_LPITIMERCTL_LST_M);
  4533. ui32TimerValue |= ui16LPITWTimer & EMAC_LPITIMERCTL_TWT_M;
  4534. //
  4535. // Update the LPI Timer.
  4536. //
  4537. HWREG(ui32Base + EMAC_O_LPITIMERCTL) = ui32TimerValue;
  4538. //
  4539. // Configure the LPI Control registers.
  4540. //
  4541. if (bLPIConfig)
  4542. {
  4543. HWREG(ui32Base + EMAC_O_LPICTLSTAT) |= EMAC_LPICTLSTAT_LPITXA;
  4544. }
  4545. else
  4546. {
  4547. HWREG(ui32Base + EMAC_O_LPICTLSTAT) = 0x0;
  4548. }
  4549. }
  4550. //*****************************************************************************
  4551. //
  4552. //! Enables the transmit path for LPI mode entry.
  4553. //!
  4554. //! \param ui32Base is the base address of the controller.
  4555. //!
  4556. //! This function is used to enable the transmit path in LPI mode when there
  4557. //! is no more data to be transmitted by the MAC controller.
  4558. //!
  4559. //! \return None.
  4560. //
  4561. //*****************************************************************************
  4562. void
  4563. EMACLPIEnter(uint32_t ui32Base)
  4564. {
  4565. //
  4566. // Parameter sanity check.
  4567. //
  4568. ASSERT(ui32Base == EMAC0_BASE);
  4569. HWREG(ui32Base + EMAC_O_LPICTLSTAT) |= EMAC_LPICTLSTAT_LPIEN;
  4570. }
  4571. //*****************************************************************************
  4572. //
  4573. //! Returns the status of the LPI link.
  4574. //!
  4575. //! \param ui32Base is the base address of the controller.
  4576. //!
  4577. //! This function may be used to read the status of the transmit and receive
  4578. //! path when the link is configured in LPI mode.
  4579. //!
  4580. //! \return Returns the lower 16 bits of the LPI Control and Status register.
  4581. //
  4582. //*****************************************************************************
  4583. uint16_t
  4584. EMACLPIStatus(uint32_t ui32Base)
  4585. {
  4586. //
  4587. // Parameter sanity check.
  4588. //
  4589. ASSERT(ui32Base == EMAC0_BASE);
  4590. //
  4591. // Configure the LPI Control registers.
  4592. //
  4593. return (HWREG(ui32Base + EMAC_O_LPICTLSTAT) & 0xFFFF);
  4594. }
  4595. //*****************************************************************************
  4596. //
  4597. //! Sets the link status of the external PHY.
  4598. //!
  4599. //! \param ui32Base is the base address of the controller.
  4600. //!
  4601. //! This function is used to set the link status of the external PHY when the
  4602. //! link is established in EEE mode.
  4603. //!
  4604. //! \return None.
  4605. //
  4606. //*****************************************************************************
  4607. void
  4608. EMACLPILinkSet(uint32_t ui32Base)
  4609. {
  4610. //
  4611. // Parameter sanity check.
  4612. //
  4613. ASSERT(ui32Base == EMAC0_BASE);
  4614. //
  4615. // Configure the LPI Control registers.
  4616. //
  4617. HWREG(ui32Base + EMAC_O_LPICTLSTAT) |= EMAC_LPICTLSTAT_PLS;
  4618. }
  4619. //*****************************************************************************
  4620. //
  4621. //! Clears the link status of the external PHY.
  4622. //!
  4623. //! \param ui32Base is the base address of the controller.
  4624. //!
  4625. //! This function is used to clear the link status of the external PHY when the
  4626. //! link is lost due to a disconnect or EEE mode link is not established.
  4627. //!
  4628. //! \return None.
  4629. //
  4630. //*****************************************************************************
  4631. void
  4632. EMACLPILinkClear(uint32_t ui32Base)
  4633. {
  4634. //
  4635. // Parameter sanity check.
  4636. //
  4637. ASSERT(ui32Base == EMAC0_BASE);
  4638. //
  4639. // Configure the LPI Control registers.
  4640. //
  4641. HWREG(ui32Base + EMAC_O_LPICTLSTAT) &= ~(EMAC_LPICTLSTAT_PLS);
  4642. }
  4643. //*****************************************************************************
  4644. //
  4645. //! Writes a value to an extended PHY register in MMD address space.
  4646. //!
  4647. //! \param ui32Base is the base address of the controller.
  4648. //! \param ui8PhyAddr is the physical address of the PHY to access.
  4649. //! \param ui16RegAddr is the address of the PHY extended register to be
  4650. //! accessed.
  4651. //! \param ui16Value is the value to write to the register.
  4652. //!
  4653. //! When uhen connected to an external PHY supporting extended registers in MMD
  4654. //! address space, this function allows a value to be written to the MMD
  4655. //! register specified by \e ui16RegAddr.
  4656. //!
  4657. //! \return None.
  4658. //
  4659. //*****************************************************************************
  4660. void
  4661. EMACPHYMMDWrite(uint32_t ui32Base, uint8_t ui8PhyAddr, uint16_t ui16RegAddr,
  4662. uint16_t ui16Data)
  4663. {
  4664. //
  4665. // Parameter sanity check.
  4666. //
  4667. ASSERT(ui8PhyAddr < 32);
  4668. //
  4669. // Set the address of the register we're about to write.
  4670. //
  4671. EMACPHYWrite(ui32Base, ui8PhyAddr, EPHY_REGCTL, DEV_ADDR(ui16RegAddr));
  4672. EMACPHYWrite(ui32Base, ui8PhyAddr, EPHY_ADDAR, REG_ADDR(ui16RegAddr));
  4673. //
  4674. // Write the extended register value.
  4675. //
  4676. EMACPHYWrite(ui32Base, ui8PhyAddr, EPHY_REGCTL,
  4677. (0x4000 | DEV_ADDR(ui16RegAddr)));
  4678. EMACPHYWrite(ui32Base, ui8PhyAddr, EPHY_REGCTL, ui16Data);
  4679. }
  4680. //*****************************************************************************
  4681. //
  4682. //! Reads from an extended PHY register in MMD address space.
  4683. //!
  4684. //! \param ui32Base is the base address of the controller.
  4685. //! \param ui8PhyAddr is the physical address of the PHY to access.
  4686. //! \param ui16RegAddr is the address of the PHY extended register to be
  4687. //! accessed.
  4688. //!
  4689. //! When connected to an external PHY supporting extended registers, this
  4690. //! this function returns the contents of the MMD register specified by
  4691. //! \e ui16RegAddr.
  4692. //!
  4693. //! \return Returns the 16-bit value read from the PHY.
  4694. //
  4695. //*****************************************************************************
  4696. uint16_t
  4697. EMACPHYMMDRead(uint32_t ui32Base, uint8_t ui8PhyAddr, uint16_t ui16RegAddr)
  4698. {
  4699. //
  4700. // Parameter sanity check.
  4701. //
  4702. ASSERT(ui8PhyAddr < 32);
  4703. //
  4704. // Set the address of the register we're about to read.
  4705. //
  4706. EMACPHYWrite(ui32Base, ui8PhyAddr, EPHY_REGCTL, DEV_ADDR(ui16RegAddr));
  4707. EMACPHYWrite(ui32Base, ui8PhyAddr, EPHY_ADDAR, REG_ADDR(ui16RegAddr));
  4708. //
  4709. // Read the extended register value.
  4710. //
  4711. EMACPHYWrite(ui32Base, ui8PhyAddr, EPHY_REGCTL,
  4712. (0x4000 | DEV_ADDR(ui16RegAddr)));
  4713. return (EMACPHYRead(ui32Base, ui8PhyAddr, EPHY_ADDAR));
  4714. }
  4715. //*****************************************************************************
  4716. //
  4717. // Close the Doxygen group.
  4718. //! @}
  4719. //
  4720. //*****************************************************************************