emac.c 198 KB

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