sysctl.c 133 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699
  1. //*****************************************************************************
  2. //
  3. // sysctl.c - Driver for the system controller.
  4. //
  5. // Copyright (c) 2005-2014 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions
  10. // are met:
  11. //
  12. // Redistributions of source code must retain the above copyright
  13. // notice, this list of conditions and the following disclaimer.
  14. //
  15. // Redistributions in binary form must reproduce the above copyright
  16. // notice, this list of conditions and the following disclaimer in the
  17. // documentation and/or other materials provided with the
  18. // distribution.
  19. //
  20. // Neither the name of Texas Instruments Incorporated nor the names of
  21. // its contributors may be used to endorse or promote products derived
  22. // from this software without specific prior written permission.
  23. //
  24. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. // This is part of revision 2.1.0.12573 of the Tiva Peripheral Driver Library.
  37. //
  38. //*****************************************************************************
  39. //*****************************************************************************
  40. //
  41. //! \addtogroup sysctl_api
  42. //! @{
  43. //
  44. //*****************************************************************************
  45. #include <stdbool.h>
  46. #include <stdint.h>
  47. #include "inc/hw_ints.h"
  48. #include "inc/hw_nvic.h"
  49. #include "inc/hw_sysctl.h"
  50. #include "inc/hw_types.h"
  51. #include "inc/hw_flash.h"
  52. #include "driverlib/cpu.h"
  53. #include "driverlib/debug.h"
  54. #include "driverlib/interrupt.h"
  55. #include "driverlib/sysctl.h"
  56. //*****************************************************************************
  57. //
  58. // The flash shift used in the math to calculate the flash sector size.
  59. //
  60. //*****************************************************************************
  61. #ifndef FLASH_PP_MAINSS_S
  62. #define FLASH_PP_MAINSS_S 16
  63. #endif
  64. //*****************************************************************************
  65. //
  66. // This macro converts the XTAL value provided in the ui32Config parameter to
  67. // an index to the g_pui32Xtals array.
  68. //
  69. //*****************************************************************************
  70. #define SysCtlXtalCfgToIndex(a) ((a & 0x7c0) >> 6)
  71. //*****************************************************************************
  72. //
  73. // An array that maps the crystal number in RCC to a frequency.
  74. //
  75. //*****************************************************************************
  76. static const uint32_t g_pui32Xtals[] =
  77. {
  78. 1000000,
  79. 1843200,
  80. 2000000,
  81. 2457600,
  82. 3579545,
  83. 3686400,
  84. 4000000,
  85. 4096000,
  86. 4915200,
  87. 5000000,
  88. 5120000,
  89. 6000000,
  90. 6144000,
  91. 7372800,
  92. 8000000,
  93. 8192000,
  94. 10000000,
  95. 12000000,
  96. 12288000,
  97. 13560000,
  98. 14318180,
  99. 16000000,
  100. 16384000,
  101. 18000000,
  102. 20000000,
  103. 24000000,
  104. 25000000
  105. };
  106. //*****************************************************************************
  107. //
  108. // Maximum number of VCO entries in the g_pui32XTALtoVCO and
  109. // g_pui32VCOFrequencies structures for a device.
  110. //
  111. //*****************************************************************************
  112. #define MAX_VCO_ENTRIES 2
  113. #define MAX_XTAL_ENTRIES 18
  114. //*****************************************************************************
  115. //
  116. // These macros are used in the g_pui32XTALtoVCO table to make it more
  117. // readable.
  118. //
  119. //*****************************************************************************
  120. #define PLL_M_TO_REG(mi, mf) \
  121. ((uint32_t)mi | (uint32_t)(mf << SYSCTL_PLLFREQ0_MFRAC_S))
  122. #define PLL_N_TO_REG(n) \
  123. ((uint32_t)(n - 1) << SYSCTL_PLLFREQ1_N_S)
  124. //*****************************************************************************
  125. //
  126. // Look up of the values that go into the PLLFREQ0 and PLLFREQ1 registers.
  127. //
  128. //*****************************************************************************
  129. static const uint32_t g_pppui32XTALtoVCO[MAX_VCO_ENTRIES][MAX_XTAL_ENTRIES][2] =
  130. {
  131. {
  132. //
  133. // VCO 320 MHz
  134. //
  135. { PLL_M_TO_REG(64, 0), PLL_N_TO_REG(1) }, // 5 MHz
  136. { PLL_M_TO_REG(62, 512), PLL_N_TO_REG(1) }, // 5.12 MHz
  137. { PLL_M_TO_REG(160, 0), PLL_N_TO_REG(3) }, // 6 MHz
  138. { PLL_M_TO_REG(52, 85), PLL_N_TO_REG(1) }, // 6.144 MHz
  139. { PLL_M_TO_REG(43, 412), PLL_N_TO_REG(1) }, // 7.3728 MHz
  140. { PLL_M_TO_REG(40, 0), PLL_N_TO_REG(1) }, // 8 MHz
  141. { PLL_M_TO_REG(39, 64), PLL_N_TO_REG(1) }, // 8.192 MHz
  142. { PLL_M_TO_REG(32, 0), PLL_N_TO_REG(1) }, // 10 MHz
  143. { PLL_M_TO_REG(80, 0), PLL_N_TO_REG(3) }, // 12 MHz
  144. { PLL_M_TO_REG(26, 43), PLL_N_TO_REG(1) }, // 12.288 MHz
  145. { PLL_M_TO_REG(23, 613), PLL_N_TO_REG(1) }, // 13.56 MHz
  146. { PLL_M_TO_REG(22, 358), PLL_N_TO_REG(1) }, // 14.318180 MHz
  147. { PLL_M_TO_REG(20, 0), PLL_N_TO_REG(1) }, // 16 MHz
  148. { PLL_M_TO_REG(19, 544), PLL_N_TO_REG(1) }, // 16.384 MHz
  149. { PLL_M_TO_REG(160, 0), PLL_N_TO_REG(9) }, // 18 MHz
  150. { PLL_M_TO_REG(16, 0), PLL_N_TO_REG(1) }, // 20 MHz
  151. { PLL_M_TO_REG(40, 0), PLL_N_TO_REG(3) }, // 24 MHz
  152. { PLL_M_TO_REG(64, 0), PLL_N_TO_REG(5) }, // 25 MHz
  153. },
  154. {
  155. //
  156. // VCO 480 MHz
  157. //
  158. { PLL_M_TO_REG(96, 0), PLL_N_TO_REG(1) }, // 5 MHz
  159. { PLL_M_TO_REG(93, 768), PLL_N_TO_REG(1) }, // 5.12 MHz
  160. { PLL_M_TO_REG(80, 0), PLL_N_TO_REG(1) }, // 6 MHz
  161. { PLL_M_TO_REG(78, 128), PLL_N_TO_REG(1) }, // 6.144 MHz
  162. { PLL_M_TO_REG(65, 107), PLL_N_TO_REG(1) }, // 7.3728 MHz
  163. { PLL_M_TO_REG(60, 0), PLL_N_TO_REG(1) }, // 8 MHz
  164. { PLL_M_TO_REG(58, 608), PLL_N_TO_REG(1) }, // 8.192 MHz
  165. { PLL_M_TO_REG(48, 0), PLL_N_TO_REG(1) }, // 10 MHz
  166. { PLL_M_TO_REG(40, 0), PLL_N_TO_REG(1) }, // 12 MHz
  167. { PLL_M_TO_REG(39, 64), PLL_N_TO_REG(1) }, // 12.288 MHz
  168. { PLL_M_TO_REG(35, 408), PLL_N_TO_REG(1) }, // 13.56 MHz
  169. { PLL_M_TO_REG(33, 536), PLL_N_TO_REG(1) }, // 14.318180 MHz
  170. { PLL_M_TO_REG(30, 0), PLL_N_TO_REG(1) }, // 16 MHz
  171. { PLL_M_TO_REG(29, 304), PLL_N_TO_REG(1) }, // 16.384 MHz
  172. { PLL_M_TO_REG(80, 0), PLL_N_TO_REG(3) }, // 18 MHz
  173. { PLL_M_TO_REG(24, 0), PLL_N_TO_REG(1) }, // 20 MHz
  174. { PLL_M_TO_REG(20, 0), PLL_N_TO_REG(1) }, // 24 MHz
  175. { PLL_M_TO_REG(96, 0), PLL_N_TO_REG(5) }, // 25 MHz
  176. },
  177. };
  178. //*****************************************************************************
  179. //
  180. // The mapping of system clock frequency to flash memory timing parameters.
  181. //
  182. //*****************************************************************************
  183. static const struct
  184. {
  185. uint32_t ui32Frequency;
  186. uint32_t ui32MemTiming;
  187. }
  188. g_sXTALtoMEMTIM[] =
  189. {
  190. { 16000000, (SYSCTL_MEMTIM0_FBCHT_0_5 | SYSCTL_MEMTIM0_FBCE |
  191. (0 << SYSCTL_MEMTIM0_FWS_S) |
  192. SYSCTL_MEMTIM0_EBCHT_0_5 | SYSCTL_MEMTIM0_EBCE |
  193. (0 << SYSCTL_MEMTIM0_EWS_S) |
  194. SYSCTL_MEMTIM0_MB1) },
  195. { 40000000, (SYSCTL_MEMTIM0_FBCHT_1_5 | (1 << SYSCTL_MEMTIM0_FWS_S) |
  196. SYSCTL_MEMTIM0_FBCHT_1_5 | (1 << SYSCTL_MEMTIM0_EWS_S) |
  197. SYSCTL_MEMTIM0_MB1) },
  198. { 60000000, (SYSCTL_MEMTIM0_FBCHT_2 | (2 << SYSCTL_MEMTIM0_FWS_S) |
  199. SYSCTL_MEMTIM0_EBCHT_2 | (2 << SYSCTL_MEMTIM0_EWS_S) |
  200. SYSCTL_MEMTIM0_MB1) },
  201. { 80000000, (SYSCTL_MEMTIM0_FBCHT_2_5 | (3 << SYSCTL_MEMTIM0_FWS_S) |
  202. SYSCTL_MEMTIM0_EBCHT_2_5 | (3 << SYSCTL_MEMTIM0_EWS_S) |
  203. SYSCTL_MEMTIM0_MB1) },
  204. { 100000000, (SYSCTL_MEMTIM0_FBCHT_3 | (4 << SYSCTL_MEMTIM0_FWS_S) |
  205. SYSCTL_MEMTIM0_EBCHT_3 | (4 << SYSCTL_MEMTIM0_EWS_S) |
  206. SYSCTL_MEMTIM0_MB1) },
  207. { 120000000, (SYSCTL_MEMTIM0_FBCHT_3_5 | (5 << SYSCTL_MEMTIM0_FWS_S) |
  208. SYSCTL_MEMTIM0_EBCHT_3_5 | (5 << SYSCTL_MEMTIM0_EWS_S) |
  209. SYSCTL_MEMTIM0_MB1) },
  210. };
  211. //*****************************************************************************
  212. //
  213. // Get the correct memory timings for a given system clock value.
  214. //
  215. //*****************************************************************************
  216. static uint32_t
  217. _SysCtlMemTimingGet(uint32_t ui32SysClock)
  218. {
  219. uint_fast8_t ui8Idx;
  220. //
  221. // Loop through the flash memory timings.
  222. //
  223. for(ui8Idx = 0;
  224. ui8Idx < (sizeof(g_sXTALtoMEMTIM) / sizeof(g_sXTALtoMEMTIM[0]));
  225. ui8Idx++)
  226. {
  227. //
  228. // See if the system clock frequency is less than the maximum frequency
  229. // for this flash memory timing.
  230. //
  231. if(ui32SysClock <= g_sXTALtoMEMTIM[ui8Idx].ui32Frequency)
  232. {
  233. //
  234. // This flash memory timing is the best choice for the system clock
  235. // frequency, so return it now.
  236. //
  237. return(g_sXTALtoMEMTIM[ui8Idx].ui32MemTiming);
  238. }
  239. }
  240. //
  241. // An appropriate flash memory timing could not be found, so the device is
  242. // being clocked too fast. Return the default flash memory timing.
  243. //
  244. return(0);
  245. }
  246. //*****************************************************************************
  247. //
  248. // Calculate the system frequency from the register settings base on the
  249. // oscillator input.
  250. //
  251. //*****************************************************************************
  252. static uint32_t
  253. _SysCtlFrequencyGet(uint32_t ui32Xtal)
  254. {
  255. uint32_t ui32Result;
  256. uint_fast16_t ui16F1, ui16F2;
  257. uint_fast16_t ui16PInt, ui16PFract;
  258. uint_fast8_t ui8Q, ui8N;
  259. //
  260. // Extract all of the values from the hardware registers.
  261. //
  262. ui16PFract = ((HWREG(SYSCTL_PLLFREQ0) & SYSCTL_PLLFREQ0_MFRAC_M) >>
  263. SYSCTL_PLLFREQ0_MFRAC_S);
  264. ui16PInt = HWREG(SYSCTL_PLLFREQ0) & SYSCTL_PLLFREQ0_MINT_M;
  265. ui8Q = (((HWREG(SYSCTL_PLLFREQ1) & SYSCTL_PLLFREQ1_Q_M) >>
  266. SYSCTL_PLLFREQ1_Q_S) + 1);
  267. ui8N = (((HWREG(SYSCTL_PLLFREQ1) & SYSCTL_PLLFREQ1_N_M) >>
  268. SYSCTL_PLLFREQ1_N_S) + 1);
  269. //
  270. // Divide the crystal value by N.
  271. //
  272. ui32Xtal /= (uint32_t)ui8N;
  273. //
  274. // Calculate the multiplier for bits 9:5.
  275. //
  276. ui16F1 = ui16PFract / 32;
  277. //
  278. // Calculate the multiplier for bits 4:0.
  279. //
  280. ui16F2 = ui16PFract - (ui16F1 * 32);
  281. //
  282. // Get the integer portion.
  283. //
  284. ui32Result = ui32Xtal * (uint32_t)ui16PInt;
  285. //
  286. // Add first fractional bits portion(9:0).
  287. //
  288. ui32Result += (ui32Xtal * (uint32_t)ui16F1) / 32;
  289. //
  290. // Add the second fractional bits portion(4:0).
  291. //
  292. ui32Result += (ui32Xtal * (uint32_t)ui16F2) / 1024;
  293. //
  294. // Divide the result by Q.
  295. //
  296. ui32Result = ui32Result / (uint32_t)ui8Q;
  297. //
  298. // Return the resulting PLL frequency.
  299. //
  300. return(ui32Result);
  301. }
  302. //*****************************************************************************
  303. //
  304. // Look up of the possible VCO frequencies.
  305. //
  306. //*****************************************************************************
  307. static const uint32_t g_pui32VCOFrequencies[MAX_VCO_ENTRIES] =
  308. {
  309. 320000000, // VCO 320
  310. 480000000, // VCO 480
  311. };
  312. //*****************************************************************************
  313. //
  314. // The base addresses of the various peripheral control registers.
  315. //
  316. //*****************************************************************************
  317. #define SYSCTL_PPBASE 0x400fe300
  318. #define SYSCTL_SRBASE 0x400fe500
  319. #define SYSCTL_RCGCBASE 0x400fe600
  320. #define SYSCTL_SCGCBASE 0x400fe700
  321. #define SYSCTL_DCGCBASE 0x400fe800
  322. #define SYSCTL_PCBASE 0x400fe900
  323. #define SYSCTL_PRBASE 0x400fea00
  324. //*****************************************************************************
  325. //
  326. //! \internal
  327. //! Checks a peripheral identifier.
  328. //!
  329. //! \param ui32Peripheral is the peripheral identifier.
  330. //!
  331. //! This function determines if a peripheral identifier is valid.
  332. //!
  333. //! \return Returns \b true if the peripheral identifier is valid and \b false
  334. //! otherwise.
  335. //
  336. //*****************************************************************************
  337. #ifdef DEBUG
  338. static bool
  339. _SysCtlPeripheralValid(uint32_t ui32Peripheral)
  340. {
  341. return((ui32Peripheral == SYSCTL_PERIPH_ADC0) ||
  342. (ui32Peripheral == SYSCTL_PERIPH_ADC1) ||
  343. (ui32Peripheral == SYSCTL_PERIPH_CAN0) ||
  344. (ui32Peripheral == SYSCTL_PERIPH_CAN1) ||
  345. (ui32Peripheral == SYSCTL_PERIPH_COMP0) ||
  346. (ui32Peripheral == SYSCTL_PERIPH_CCM0) ||
  347. (ui32Peripheral == SYSCTL_PERIPH_EEPROM0) ||
  348. (ui32Peripheral == SYSCTL_PERIPH_EPHY0) ||
  349. (ui32Peripheral == SYSCTL_PERIPH_EMAC0) ||
  350. (ui32Peripheral == SYSCTL_PERIPH_EPI0) ||
  351. (ui32Peripheral == SYSCTL_PERIPH_FAN0) ||
  352. (ui32Peripheral == SYSCTL_PERIPH_GPIOA) ||
  353. (ui32Peripheral == SYSCTL_PERIPH_GPIOB) ||
  354. (ui32Peripheral == SYSCTL_PERIPH_GPIOC) ||
  355. (ui32Peripheral == SYSCTL_PERIPH_GPIOD) ||
  356. (ui32Peripheral == SYSCTL_PERIPH_GPIOE) ||
  357. (ui32Peripheral == SYSCTL_PERIPH_GPIOF) ||
  358. (ui32Peripheral == SYSCTL_PERIPH_GPIOG) ||
  359. (ui32Peripheral == SYSCTL_PERIPH_GPIOH) ||
  360. (ui32Peripheral == SYSCTL_PERIPH_GPIOJ) ||
  361. (ui32Peripheral == SYSCTL_PERIPH_GPIOK) ||
  362. (ui32Peripheral == SYSCTL_PERIPH_GPIOL) ||
  363. (ui32Peripheral == SYSCTL_PERIPH_GPIOM) ||
  364. (ui32Peripheral == SYSCTL_PERIPH_GPION) ||
  365. (ui32Peripheral == SYSCTL_PERIPH_GPIOP) ||
  366. (ui32Peripheral == SYSCTL_PERIPH_GPIOQ) ||
  367. (ui32Peripheral == SYSCTL_PERIPH_GPIOR) ||
  368. (ui32Peripheral == SYSCTL_PERIPH_GPIOS) ||
  369. (ui32Peripheral == SYSCTL_PERIPH_GPIOT) ||
  370. (ui32Peripheral == SYSCTL_PERIPH_HIBERNATE) ||
  371. (ui32Peripheral == SYSCTL_PERIPH_I2C0) ||
  372. (ui32Peripheral == SYSCTL_PERIPH_I2C1) ||
  373. (ui32Peripheral == SYSCTL_PERIPH_I2C2) ||
  374. (ui32Peripheral == SYSCTL_PERIPH_I2C3) ||
  375. (ui32Peripheral == SYSCTL_PERIPH_I2C4) ||
  376. (ui32Peripheral == SYSCTL_PERIPH_I2C5) ||
  377. (ui32Peripheral == SYSCTL_PERIPH_I2C6) ||
  378. (ui32Peripheral == SYSCTL_PERIPH_I2C7) ||
  379. (ui32Peripheral == SYSCTL_PERIPH_I2C8) ||
  380. (ui32Peripheral == SYSCTL_PERIPH_I2C9) ||
  381. (ui32Peripheral == SYSCTL_PERIPH_LCD0) ||
  382. (ui32Peripheral == SYSCTL_PERIPH_PWM0) ||
  383. (ui32Peripheral == SYSCTL_PERIPH_PWM1) ||
  384. (ui32Peripheral == SYSCTL_PERIPH_QEI0) ||
  385. (ui32Peripheral == SYSCTL_PERIPH_QEI1) ||
  386. (ui32Peripheral == SYSCTL_PERIPH_SSI0) ||
  387. (ui32Peripheral == SYSCTL_PERIPH_SSI1) ||
  388. (ui32Peripheral == SYSCTL_PERIPH_SSI2) ||
  389. (ui32Peripheral == SYSCTL_PERIPH_SSI3) ||
  390. (ui32Peripheral == SYSCTL_PERIPH_TIMER0) ||
  391. (ui32Peripheral == SYSCTL_PERIPH_TIMER1) ||
  392. (ui32Peripheral == SYSCTL_PERIPH_TIMER2) ||
  393. (ui32Peripheral == SYSCTL_PERIPH_TIMER3) ||
  394. (ui32Peripheral == SYSCTL_PERIPH_TIMER4) ||
  395. (ui32Peripheral == SYSCTL_PERIPH_TIMER5) ||
  396. (ui32Peripheral == SYSCTL_PERIPH_UART0) ||
  397. (ui32Peripheral == SYSCTL_PERIPH_UART1) ||
  398. (ui32Peripheral == SYSCTL_PERIPH_UART2) ||
  399. (ui32Peripheral == SYSCTL_PERIPH_UART3) ||
  400. (ui32Peripheral == SYSCTL_PERIPH_UART4) ||
  401. (ui32Peripheral == SYSCTL_PERIPH_UART5) ||
  402. (ui32Peripheral == SYSCTL_PERIPH_UART6) ||
  403. (ui32Peripheral == SYSCTL_PERIPH_UART7) ||
  404. (ui32Peripheral == SYSCTL_PERIPH_UDMA) ||
  405. (ui32Peripheral == SYSCTL_PERIPH_USB0) ||
  406. (ui32Peripheral == SYSCTL_PERIPH_WDOG0) ||
  407. (ui32Peripheral == SYSCTL_PERIPH_WDOG1) ||
  408. (ui32Peripheral == SYSCTL_PERIPH_WTIMER0) ||
  409. (ui32Peripheral == SYSCTL_PERIPH_WTIMER1) ||
  410. (ui32Peripheral == SYSCTL_PERIPH_WTIMER2) ||
  411. (ui32Peripheral == SYSCTL_PERIPH_WTIMER3) ||
  412. (ui32Peripheral == SYSCTL_PERIPH_WTIMER4) ||
  413. (ui32Peripheral == SYSCTL_PERIPH_WTIMER5));
  414. }
  415. #endif
  416. //*****************************************************************************
  417. //
  418. //! Gets the size of the SRAM.
  419. //!
  420. //! This function determines the size of the SRAM on the Tiva device.
  421. //!
  422. //! \return The total number of bytes of SRAM.
  423. //
  424. //*****************************************************************************
  425. uint32_t
  426. SysCtlSRAMSizeGet(void)
  427. {
  428. return((HWREG(FLASH_SSIZE) + 1) * 256);
  429. }
  430. //*****************************************************************************
  431. //
  432. //! Gets the size of the flash.
  433. //!
  434. //! This function determines the size of the flash on the Tiva device.
  435. //!
  436. //! \return The total number of bytes of flash.
  437. //
  438. //*****************************************************************************
  439. uint32_t
  440. SysCtlFlashSizeGet(void)
  441. {
  442. //
  443. // TM4C123 devices report the flash size in DC0.
  444. //
  445. if(CLASS_IS_TM4C123)
  446. {
  447. //
  448. // Compute the size of the flash.
  449. //
  450. return(((HWREG(SYSCTL_DC0) & SYSCTL_DC0_FLASHSZ_M) << 11) + 0x800);
  451. }
  452. else
  453. {
  454. //
  455. // Get the flash size from the FLASH_PP register.
  456. //
  457. return(2048 * ((HWREG(FLASH_PP) & FLASH_PP_SIZE_M) + 1));
  458. }
  459. }
  460. //*****************************************************************************
  461. //
  462. //! Gets the size of a single eraseable sector of flash.
  463. //!
  464. //! This function determines the flash sector size on the Tiva device.
  465. //! This size determines the erase granularity of the device flash.
  466. //!
  467. //! \return The number of bytes in a single flash sector.
  468. //
  469. //*****************************************************************************
  470. uint32_t
  471. SysCtlFlashSectorSizeGet(void)
  472. {
  473. //
  474. // TM4C129 devices store the value in a different register.
  475. //
  476. if(CLASS_IS_TM4C129)
  477. {
  478. //
  479. // Get the flash sector size from the FLASH_PP register.
  480. //
  481. return(1 << (10 +
  482. ((HWREG(FLASH_PP) &
  483. FLASH_PP_MAINSS_M) >> FLASH_PP_MAINSS_S)));
  484. }
  485. else
  486. {
  487. //
  488. // The sector size is fixed at 1KB.
  489. //
  490. return(1024);
  491. }
  492. }
  493. //*****************************************************************************
  494. //
  495. //! Determines if a peripheral is present.
  496. //!
  497. //! \param ui32Peripheral is the peripheral in question.
  498. //!
  499. //! This function determines if a particular peripheral is present in the
  500. //! device. Each member of the Tiva family has a different peripheral
  501. //! set; this function determines which peripherals are present on this device.
  502. //!
  503. //! The \e ui32Peripheral parameter must be only one of the following values:
  504. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  505. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CCM0,\b SYSCTL_PERIPH_COMP0,
  506. //! \b SYSCTL_PERIPH_EEPROM0, \b SYSCTL_PERIPH_EMAC, \b SYSCTL_PERIPH_EPHY,
  507. //! \b SYSCTL_PERIPH_EPI0,
  508. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  509. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  510. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  511. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  512. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  513. //! \b SYSCTL_PERIPH_GPIOR, \b SYSCTL_PERIPH_GPIOS, \b SYSCTL_PERIPH_GPIOT,
  514. //! \b SYSCTL_PERIPH_HIBERNATE,
  515. //! \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_I2C2,
  516. //! \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4, \b SYSCTL_PERIPH_I2C5,
  517. //! \b SYSCTL_PERIPH_I2C6, \b SYSCTL_PERIPH_I2C7, \b SYSCTL_PERIPH_I2C8,
  518. //! \b SYSCTL_PERIPH_I2C9, \b SYSCTL_PERIPH_LCD0,
  519. //! \b SYSCTL_PERIPH_ONEWIRE0,
  520. //! \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1, \b SYSCTL_PERIPH_QEI0,
  521. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  522. //! \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3, \b SYSCTL_PERIPH_TIMER0,
  523. //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_TIMER3,
  524. //! \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5, \b SYSCTL_PERIPH_TIMER6,
  525. //! \b SYSCTL_PERIPH_TIMER7, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  526. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4,
  527. //! \b SYSCTL_PERIPH_UART5, \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7,
  528. //! \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0,
  529. //! \b SYSCTL_PERIPH_WDOG1, \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
  530. //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
  531. //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5
  532. //!
  533. //! \return Returns \b true if the specified peripheral is present and \b false
  534. //! if it is not.
  535. //
  536. //*****************************************************************************
  537. bool
  538. SysCtlPeripheralPresent(uint32_t ui32Peripheral)
  539. {
  540. //
  541. // Check the arguments.
  542. //
  543. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  544. //
  545. // See if this peripheral is present.
  546. //
  547. return(HWREGBITW(SYSCTL_PPBASE + ((ui32Peripheral & 0xff00) >> 8),
  548. ui32Peripheral & 0xff));
  549. }
  550. //*****************************************************************************
  551. //
  552. //! Determines if a peripheral is ready.
  553. //!
  554. //! \param ui32Peripheral is the peripheral in question.
  555. //!
  556. //! This function determines if a particular peripheral is ready to be
  557. //! accessed. The peripheral may be in a non-ready state if it is not enabled,
  558. //! is being held in reset, or is in the process of becoming ready after being
  559. //! enabled or taken out of reset.
  560. //!
  561. //! The \e ui32Peripheral parameter must be only one of the following values:
  562. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  563. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CCM0,\b SYSCTL_PERIPH_COMP0,
  564. //! \b SYSCTL_PERIPH_EEPROM0, \b SYSCTL_PERIPH_EMAC, \b SYSCTL_PERIPH_EPHY,
  565. //! \b SYSCTL_PERIPH_EPI0,
  566. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  567. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  568. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  569. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  570. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  571. //! \b SYSCTL_PERIPH_GPIOR, \b SYSCTL_PERIPH_GPIOS, \b SYSCTL_PERIPH_GPIOT,
  572. //! \b SYSCTL_PERIPH_HIBERNATE,
  573. //! \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_I2C2,
  574. //! \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4, \b SYSCTL_PERIPH_I2C5,
  575. //! \b SYSCTL_PERIPH_I2C6, \b SYSCTL_PERIPH_I2C7, \b SYSCTL_PERIPH_I2C8,
  576. //! \b SYSCTL_PERIPH_I2C9, \b SYSCTL_PERIPH_LCD0,
  577. //! \b SYSCTL_PERIPH_ONEWIRE0,
  578. //! \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1, \b SYSCTL_PERIPH_QEI0,
  579. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  580. //! \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3, \b SYSCTL_PERIPH_TIMER0,
  581. //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_TIMER3,
  582. //! \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5, \b SYSCTL_PERIPH_TIMER6,
  583. //! \b SYSCTL_PERIPH_TIMER7, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  584. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4,
  585. //! \b SYSCTL_PERIPH_UART5, \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7,
  586. //! \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0,
  587. //! \b SYSCTL_PERIPH_WDOG1, \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
  588. //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
  589. //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5
  590. //!
  591. //! \note The ability to check for a peripheral being ready varies based on the
  592. //! Tiva part in use. Please consult the data sheet for the part you are
  593. //! using to determine if this feature is available.
  594. //!
  595. //! \return Returns \b true if the specified peripheral is ready and \b false
  596. //! if it is not.
  597. //
  598. //*****************************************************************************
  599. bool
  600. SysCtlPeripheralReady(uint32_t ui32Peripheral)
  601. {
  602. //
  603. // Check the arguments.
  604. //
  605. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  606. //
  607. // See if this peripheral is ready.
  608. //
  609. return(HWREGBITW(SYSCTL_PRBASE + ((ui32Peripheral & 0xff00) >> 8),
  610. ui32Peripheral & 0xff));
  611. }
  612. //*****************************************************************************
  613. //
  614. //! Powers on a peripheral.
  615. //!
  616. //! \param ui32Peripheral is the peripheral to be powered on.
  617. //!
  618. //! This function turns on the power to a peripheral. The peripheral continues
  619. //! to receive power even when its clock is not enabled.
  620. //!
  621. //! The \e ui32Peripheral parameter must be only one of the following values:
  622. //! \b SYSCTL_PERIPH_CAN0,\b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_EMAC,
  623. //! \b SYSCTL_PERIPH_EPHY, \b SYSCTL_PERIPH_LCD0, \b SYSCTL_PERIPH_USB0
  624. //!
  625. //! \note The ability to power off a peripheral varies based on the Tiva
  626. //! part in use. Please consult the data sheet for the part you are using to
  627. //! determine if this feature is available.
  628. //!
  629. //! \return None.
  630. //
  631. //*****************************************************************************
  632. void
  633. SysCtlPeripheralPowerOn(uint32_t ui32Peripheral)
  634. {
  635. //
  636. // Check the arguments.
  637. //
  638. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  639. //
  640. // Power on this peripheral.
  641. //
  642. HWREGBITW(SYSCTL_PCBASE + ((ui32Peripheral & 0xff00) >> 8),
  643. ui32Peripheral & 0xff) = 1;
  644. }
  645. //*****************************************************************************
  646. //
  647. //! Powers off a peripheral.
  648. //!
  649. //! \param ui32Peripheral is the peripheral to be powered off.
  650. //!
  651. //! This function allows the power to a peripheral to be turned off. The
  652. //! peripheral continues to receive power when its clock is enabled, but
  653. //! the power is removed when its clock is disabled.
  654. //!
  655. //! The \e ui32Peripheral parameter must be only one of the following values:
  656. //! \b SYSCTL_PERIPH_CAN0,\b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_EMAC,
  657. //! \b SYSCTL_PERIPH_EPHY, \b SYSCTL_PERIPH_LCD0, \b SYSCTL_PERIPH_USB0
  658. //!
  659. //! \note The ability to power off a peripheral varies based on the Tiva
  660. //! part in use. Please consult the data sheet for the part you are using to
  661. //! determine if this feature is available.
  662. //!
  663. //! \return None.
  664. //
  665. //*****************************************************************************
  666. void
  667. SysCtlPeripheralPowerOff(uint32_t ui32Peripheral)
  668. {
  669. //
  670. // Check the arguments.
  671. //
  672. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  673. //
  674. // Power off this peripheral.
  675. //
  676. HWREGBITW(SYSCTL_PCBASE + ((ui32Peripheral & 0xff00) >> 8),
  677. ui32Peripheral & 0xff) = 0;
  678. }
  679. //*****************************************************************************
  680. //
  681. //! Performs a software reset of a peripheral.
  682. //!
  683. //! \param ui32Peripheral is the peripheral to reset.
  684. //!
  685. //! This function performs a software reset of the specified peripheral. An
  686. //! individual peripheral reset signal is asserted for a brief period and then
  687. //! de-asserted, returning the internal state of the peripheral to its reset
  688. //! condition.
  689. //!
  690. //! The \e ui32Peripheral parameter must be only one of the following values:
  691. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  692. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CCM0,\b SYSCTL_PERIPH_COMP0,
  693. //! \b SYSCTL_PERIPH_EEPROM0, \b SYSCTL_PERIPH_EMAC, \b SYSCTL_PERIPH_EPHY,
  694. //! \b SYSCTL_PERIPH_EPI0,
  695. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  696. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  697. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  698. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  699. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  700. //! \b SYSCTL_PERIPH_GPIOR, \b SYSCTL_PERIPH_GPIOS, \b SYSCTL_PERIPH_GPIOT,
  701. //! \b SYSCTL_PERIPH_HIBERNATE,
  702. //! \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_I2C2,
  703. //! \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4, \b SYSCTL_PERIPH_I2C5,
  704. //! \b SYSCTL_PERIPH_I2C6, \b SYSCTL_PERIPH_I2C7, \b SYSCTL_PERIPH_I2C8,
  705. //! \b SYSCTL_PERIPH_I2C9, \b SYSCTL_PERIPH_LCD0,
  706. //! \b SYSCTL_PERIPH_ONEWIRE0,
  707. //! \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1, \b SYSCTL_PERIPH_QEI0,
  708. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  709. //! \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3, \b SYSCTL_PERIPH_TIMER0,
  710. //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_TIMER3,
  711. //! \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5, \b SYSCTL_PERIPH_TIMER6,
  712. //! \b SYSCTL_PERIPH_TIMER7, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  713. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4,
  714. //! \b SYSCTL_PERIPH_UART5, \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7,
  715. //! \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0,
  716. //! \b SYSCTL_PERIPH_WDOG1, \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
  717. //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
  718. //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5
  719. //!
  720. //! \return None.
  721. //
  722. //*****************************************************************************
  723. void
  724. SysCtlPeripheralReset(uint32_t ui32Peripheral)
  725. {
  726. volatile uint_fast8_t ui8Delay;
  727. //
  728. // Check the arguments.
  729. //
  730. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  731. //
  732. // Put the peripheral into the reset state.
  733. //
  734. HWREGBITW(SYSCTL_SRBASE + ((ui32Peripheral & 0xff00) >> 8),
  735. ui32Peripheral & 0xff) = 1;
  736. //
  737. // Delay for a little bit.
  738. //
  739. for(ui8Delay = 0; ui8Delay < 16; ui8Delay++)
  740. {
  741. }
  742. //
  743. // Take the peripheral out of the reset state.
  744. //
  745. HWREGBITW(SYSCTL_SRBASE + ((ui32Peripheral & 0xff00) >> 8),
  746. ui32Peripheral & 0xff) = 0;
  747. }
  748. //*****************************************************************************
  749. //
  750. //! Enables a peripheral.
  751. //!
  752. //! \param ui32Peripheral is the peripheral to enable.
  753. //!
  754. //! This function enables a peripheral. At power-up, all peripherals are
  755. //! disabled; they must be enabled in order to operate or respond to register
  756. //! reads/writes.
  757. //!
  758. //! The \e ui32Peripheral parameter must be only one of the following values:
  759. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  760. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CCM0,\b SYSCTL_PERIPH_COMP0,
  761. //! \b SYSCTL_PERIPH_EEPROM0, \b SYSCTL_PERIPH_EMAC, \b SYSCTL_PERIPH_EPHY,
  762. //! \b SYSCTL_PERIPH_EPI0,
  763. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  764. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  765. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  766. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  767. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  768. //! \b SYSCTL_PERIPH_GPIOR, \b SYSCTL_PERIPH_GPIOS, \b SYSCTL_PERIPH_GPIOT,
  769. //! \b SYSCTL_PERIPH_HIBERNATE,
  770. //! \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_I2C2,
  771. //! \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4, \b SYSCTL_PERIPH_I2C5,
  772. //! \b SYSCTL_PERIPH_I2C6, \b SYSCTL_PERIPH_I2C7, \b SYSCTL_PERIPH_I2C8,
  773. //! \b SYSCTL_PERIPH_I2C9, \b SYSCTL_PERIPH_LCD0,
  774. //! \b SYSCTL_PERIPH_ONEWIRE0,
  775. //! \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1, \b SYSCTL_PERIPH_QEI0,
  776. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  777. //! \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3, \b SYSCTL_PERIPH_TIMER0,
  778. //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_TIMER3,
  779. //! \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5, \b SYSCTL_PERIPH_TIMER6,
  780. //! \b SYSCTL_PERIPH_TIMER7, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  781. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4,
  782. //! \b SYSCTL_PERIPH_UART5, \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7,
  783. //! \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0,
  784. //! \b SYSCTL_PERIPH_WDOG1, \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
  785. //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
  786. //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5
  787. //!
  788. //! \note It takes five clock cycles after the write to enable a peripheral
  789. //! before the the peripheral is actually enabled. During this time, attempts
  790. //! to access the peripheral result in a bus fault. Care should be taken
  791. //! to ensure that the peripheral is not accessed during this brief time
  792. //! period.
  793. //!
  794. //! \return None.
  795. //
  796. //*****************************************************************************
  797. void
  798. SysCtlPeripheralEnable(uint32_t ui32Peripheral)
  799. {
  800. //
  801. // Check the arguments.
  802. //
  803. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  804. //
  805. // Enable this peripheral.
  806. //
  807. HWREGBITW(SYSCTL_RCGCBASE + ((ui32Peripheral & 0xff00) >> 8),
  808. ui32Peripheral & 0xff) = 1;
  809. }
  810. //*****************************************************************************
  811. //
  812. //! Disables a peripheral.
  813. //!
  814. //! \param ui32Peripheral is the peripheral to disable.
  815. //!
  816. //! This function disables a peripheral. Once disabled, they do not operate or
  817. //! respond to register reads/writes.
  818. //!
  819. //! The \e ui32Peripheral parameter must be only one of the following values:
  820. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  821. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CCM0,\b SYSCTL_PERIPH_COMP0,
  822. //! \b SYSCTL_PERIPH_EEPROM0, \b SYSCTL_PERIPH_EMAC, \b SYSCTL_PERIPH_EPHY,
  823. //! \b SYSCTL_PERIPH_EPI0,
  824. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  825. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  826. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  827. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  828. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  829. //! \b SYSCTL_PERIPH_GPIOR, \b SYSCTL_PERIPH_GPIOS, \b SYSCTL_PERIPH_GPIOT,
  830. //! \b SYSCTL_PERIPH_HIBERNATE,
  831. //! \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_I2C2,
  832. //! \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4, \b SYSCTL_PERIPH_I2C5,
  833. //! \b SYSCTL_PERIPH_I2C6, \b SYSCTL_PERIPH_I2C7, \b SYSCTL_PERIPH_I2C8,
  834. //! \b SYSCTL_PERIPH_I2C9, \b SYSCTL_PERIPH_LCD0,
  835. //! \b SYSCTL_PERIPH_ONEWIRE0,
  836. //! \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1, \b SYSCTL_PERIPH_QEI0,
  837. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  838. //! \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3, \b SYSCTL_PERIPH_TIMER0,
  839. //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_TIMER3,
  840. //! \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5, \b SYSCTL_PERIPH_TIMER6,
  841. //! \b SYSCTL_PERIPH_TIMER7, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  842. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4,
  843. //! \b SYSCTL_PERIPH_UART5, \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7,
  844. //! \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0,
  845. //! \b SYSCTL_PERIPH_WDOG1, \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
  846. //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
  847. //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5
  848. //!
  849. //! \return None.
  850. //
  851. //*****************************************************************************
  852. void
  853. SysCtlPeripheralDisable(uint32_t ui32Peripheral)
  854. {
  855. //
  856. // Check the arguments.
  857. //
  858. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  859. //
  860. // Disable this peripheral.
  861. //
  862. HWREGBITW(SYSCTL_RCGCBASE + ((ui32Peripheral & 0xff00) >> 8),
  863. ui32Peripheral & 0xff) = 0;
  864. }
  865. //*****************************************************************************
  866. //
  867. //! Enables a peripheral in sleep mode.
  868. //!
  869. //! \param ui32Peripheral is the peripheral to enable in sleep mode.
  870. //!
  871. //! This function allows a peripheral to continue operating when the processor
  872. //! goes into sleep mode. Because the clocking configuration of the device
  873. //! does not change, any peripheral can safely continue operating while the
  874. //! processor is in sleep mode and can therefore wake the processor from sleep
  875. //! mode.
  876. //!
  877. //! Sleep mode clocking of peripherals must be enabled via
  878. //! SysCtlPeripheralClockGating(); if disabled, the peripheral sleep mode
  879. //! configuration is maintained but has no effect when sleep mode is entered.
  880. //!
  881. //! The \e ui32Peripheral parameter must be only one of the following values:
  882. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  883. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CCM0,\b SYSCTL_PERIPH_COMP0,
  884. //! \b SYSCTL_PERIPH_EEPROM0, \b SYSCTL_PERIPH_EMAC, \b SYSCTL_PERIPH_EPHY,
  885. //! \b SYSCTL_PERIPH_EPI0,
  886. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  887. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  888. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  889. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  890. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  891. //! \b SYSCTL_PERIPH_GPIOR, \b SYSCTL_PERIPH_GPIOS, \b SYSCTL_PERIPH_GPIOT,
  892. //! \b SYSCTL_PERIPH_HIBERNATE,
  893. //! \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_I2C2,
  894. //! \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4, \b SYSCTL_PERIPH_I2C5,
  895. //! \b SYSCTL_PERIPH_I2C6, \b SYSCTL_PERIPH_I2C7, \b SYSCTL_PERIPH_I2C8,
  896. //! \b SYSCTL_PERIPH_I2C9, \b SYSCTL_PERIPH_LCD0,
  897. //! \b SYSCTL_PERIPH_ONEWIRE0,
  898. //! \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1, \b SYSCTL_PERIPH_QEI0,
  899. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  900. //! \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3, \b SYSCTL_PERIPH_TIMER0,
  901. //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_TIMER3,
  902. //! \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5, \b SYSCTL_PERIPH_TIMER6,
  903. //! \b SYSCTL_PERIPH_TIMER7, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  904. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4,
  905. //! \b SYSCTL_PERIPH_UART5, \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7,
  906. //! \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0,
  907. //! \b SYSCTL_PERIPH_WDOG1, \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
  908. //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
  909. //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5
  910. //!
  911. //! \return None.
  912. //
  913. //*****************************************************************************
  914. void
  915. SysCtlPeripheralSleepEnable(uint32_t ui32Peripheral)
  916. {
  917. //
  918. // Check the arguments.
  919. //
  920. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  921. //
  922. // Enable this peripheral in sleep mode.
  923. //
  924. HWREGBITW(SYSCTL_SCGCBASE + ((ui32Peripheral & 0xff00) >> 8),
  925. ui32Peripheral & 0xff) = 1;
  926. }
  927. //*****************************************************************************
  928. //
  929. //! Disables a peripheral in sleep mode.
  930. //!
  931. //! \param ui32Peripheral is the peripheral to disable in sleep mode.
  932. //!
  933. //! This function causes a peripheral to stop operating when the processor goes
  934. //! into sleep mode. Disabling peripherals while in sleep mode helps to lower
  935. //! the current draw of the device. If enabled (via SysCtlPeripheralEnable()),
  936. //! the peripheral automatically resumes operation when the processor
  937. //! leaves sleep mode, maintaining its entire state from before sleep mode was
  938. //! entered.
  939. //!
  940. //! Sleep mode clocking of peripherals must be enabled via
  941. //! SysCtlPeripheralClockGating(); if disabled, the peripheral sleep mode
  942. //! configuration is maintained but has no effect when sleep mode is entered.
  943. //!
  944. //! The \e ui32Peripheral parameter must be only one of the following values:
  945. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  946. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CCM0,\b SYSCTL_PERIPH_COMP0,
  947. //! \b SYSCTL_PERIPH_EEPROM0, \b SYSCTL_PERIPH_EMAC, \b SYSCTL_PERIPH_EPHY,
  948. //! \b SYSCTL_PERIPH_EPI0,
  949. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  950. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  951. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  952. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  953. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  954. //! \b SYSCTL_PERIPH_GPIOR, \b SYSCTL_PERIPH_GPIOS, \b SYSCTL_PERIPH_GPIOT,
  955. //! \b SYSCTL_PERIPH_HIBERNATE,
  956. //! \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_I2C2,
  957. //! \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4, \b SYSCTL_PERIPH_I2C5,
  958. //! \b SYSCTL_PERIPH_I2C6, \b SYSCTL_PERIPH_I2C7, \b SYSCTL_PERIPH_I2C8,
  959. //! \b SYSCTL_PERIPH_I2C9, \b SYSCTL_PERIPH_LCD0,
  960. //! \b SYSCTL_PERIPH_ONEWIRE0,
  961. //! \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1, \b SYSCTL_PERIPH_QEI0,
  962. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  963. //! \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3, \b SYSCTL_PERIPH_TIMER0,
  964. //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_TIMER3,
  965. //! \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5, \b SYSCTL_PERIPH_TIMER6,
  966. //! \b SYSCTL_PERIPH_TIMER7, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  967. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4,
  968. //! \b SYSCTL_PERIPH_UART5, \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7,
  969. //! \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0,
  970. //! \b SYSCTL_PERIPH_WDOG1, \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
  971. //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
  972. //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5
  973. //!
  974. //! \return None.
  975. //
  976. //*****************************************************************************
  977. void
  978. SysCtlPeripheralSleepDisable(uint32_t ui32Peripheral)
  979. {
  980. //
  981. // Check the arguments.
  982. //
  983. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  984. //
  985. // Disable this peripheral in sleep mode.
  986. //
  987. HWREGBITW(SYSCTL_SCGCBASE + ((ui32Peripheral & 0xff00) >> 8),
  988. ui32Peripheral & 0xff) = 0;
  989. }
  990. //*****************************************************************************
  991. //
  992. //! Enables a peripheral in deep-sleep mode.
  993. //!
  994. //! \param ui32Peripheral is the peripheral to enable in deep-sleep mode.
  995. //!
  996. //! This function allows a peripheral to continue operating when the processor
  997. //! goes into deep-sleep mode. Because the clocking configuration of the
  998. //! device may change, not all peripherals can safely continue operating while
  999. //! the processor is in deep-sleep mode. Those that must run at a particular
  1000. //! frequency (such as a UART) do not work as expected if the clock changes.
  1001. //! It is the responsibility of the caller to make sensible choices.
  1002. //!
  1003. //! Deep-sleep mode clocking of peripherals must be enabled via
  1004. //! SysCtlPeripheralClockGating(); if disabled, the peripheral deep-sleep mode
  1005. //! configuration is maintained but has no effect when deep-sleep mode is
  1006. //! entered.
  1007. //!
  1008. //! The \e ui32Peripheral parameter must be only one of the following values:
  1009. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  1010. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CCM0,\b SYSCTL_PERIPH_COMP0,
  1011. //! \b SYSCTL_PERIPH_EEPROM0, \b SYSCTL_PERIPH_EMAC, \b SYSCTL_PERIPH_EPHY,
  1012. //! \b SYSCTL_PERIPH_EPI0,
  1013. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  1014. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  1015. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  1016. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  1017. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  1018. //! \b SYSCTL_PERIPH_GPIOR, \b SYSCTL_PERIPH_GPIOS, \b SYSCTL_PERIPH_GPIOT,
  1019. //! \b SYSCTL_PERIPH_HIBERNATE,
  1020. //! \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_I2C2,
  1021. //! \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4, \b SYSCTL_PERIPH_I2C5,
  1022. //! \b SYSCTL_PERIPH_I2C6, \b SYSCTL_PERIPH_I2C7, \b SYSCTL_PERIPH_I2C8,
  1023. //! \b SYSCTL_PERIPH_I2C9, \b SYSCTL_PERIPH_LCD0,
  1024. //! \b SYSCTL_PERIPH_ONEWIRE0,
  1025. //! \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1, \b SYSCTL_PERIPH_QEI0,
  1026. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  1027. //! \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3, \b SYSCTL_PERIPH_TIMER0,
  1028. //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_TIMER3,
  1029. //! \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5, \b SYSCTL_PERIPH_TIMER6,
  1030. //! \b SYSCTL_PERIPH_TIMER7, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  1031. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4,
  1032. //! \b SYSCTL_PERIPH_UART5, \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7,
  1033. //! \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0,
  1034. //! \b SYSCTL_PERIPH_WDOG1, \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
  1035. //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
  1036. //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5
  1037. //!
  1038. //! \return None.
  1039. //
  1040. //*****************************************************************************
  1041. void
  1042. SysCtlPeripheralDeepSleepEnable(uint32_t ui32Peripheral)
  1043. {
  1044. //
  1045. // Check the arguments.
  1046. //
  1047. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  1048. //
  1049. // Enable this peripheral in deep-sleep mode.
  1050. //
  1051. HWREGBITW(SYSCTL_DCGCBASE + ((ui32Peripheral & 0xff00) >> 8),
  1052. ui32Peripheral & 0xff) = 1;
  1053. }
  1054. //*****************************************************************************
  1055. //
  1056. //! Disables a peripheral in deep-sleep mode.
  1057. //!
  1058. //! \param ui32Peripheral is the peripheral to disable in deep-sleep mode.
  1059. //!
  1060. //! This function causes a peripheral to stop operating when the processor goes
  1061. //! into deep-sleep mode. Disabling peripherals while in deep-sleep mode helps
  1062. //! to lower the current draw of the device, and can keep peripherals that
  1063. //! require a particular clock frequency from operating when the clock changes
  1064. //! as a result of entering deep-sleep mode. If enabled (via
  1065. //! SysCtlPeripheralEnable()), the peripheral automatically resumes
  1066. //! operation when the processor leaves deep-sleep mode, maintaining its entire
  1067. //! state from before deep-sleep mode was entered.
  1068. //!
  1069. //! Deep-sleep mode clocking of peripherals must be enabled via
  1070. //! SysCtlPeripheralClockGating(); if disabled, the peripheral deep-sleep mode
  1071. //! configuration is maintained but has no effect when deep-sleep mode is
  1072. //! entered.
  1073. //!
  1074. //! The \e ui32Peripheral parameter must be only one of the following values:
  1075. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  1076. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CCM0,\b SYSCTL_PERIPH_COMP0,
  1077. //! \b SYSCTL_PERIPH_EEPROM0, \b SYSCTL_PERIPH_EMAC, \b SYSCTL_PERIPH_EPHY,
  1078. //! \b SYSCTL_PERIPH_EPI0,
  1079. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  1080. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  1081. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  1082. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  1083. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  1084. //! \b SYSCTL_PERIPH_GPIOR, \b SYSCTL_PERIPH_GPIOS, \b SYSCTL_PERIPH_GPIOT,
  1085. //! \b SYSCTL_PERIPH_HIBERNATE,
  1086. //! \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_I2C2,
  1087. //! \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4, \b SYSCTL_PERIPH_I2C5,
  1088. //! \b SYSCTL_PERIPH_I2C6, \b SYSCTL_PERIPH_I2C7, \b SYSCTL_PERIPH_I2C8,
  1089. //! \b SYSCTL_PERIPH_I2C9, \b SYSCTL_PERIPH_LCD0,
  1090. //! \b SYSCTL_PERIPH_ONEWIRE0,
  1091. //! \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1, \b SYSCTL_PERIPH_QEI0,
  1092. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  1093. //! \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3, \b SYSCTL_PERIPH_TIMER0,
  1094. //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_TIMER3,
  1095. //! \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5, \b SYSCTL_PERIPH_TIMER6,
  1096. //! \b SYSCTL_PERIPH_TIMER7, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  1097. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4,
  1098. //! \b SYSCTL_PERIPH_UART5, \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7,
  1099. //! \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0,
  1100. //! \b SYSCTL_PERIPH_WDOG1, \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
  1101. //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
  1102. //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5
  1103. //!
  1104. //! \return None.
  1105. //
  1106. //*****************************************************************************
  1107. void
  1108. SysCtlPeripheralDeepSleepDisable(uint32_t ui32Peripheral)
  1109. {
  1110. //
  1111. // Check the arguments.
  1112. //
  1113. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  1114. //
  1115. // Disable this peripheral in deep-sleep mode.
  1116. //
  1117. HWREGBITW(SYSCTL_DCGCBASE + ((ui32Peripheral & 0xff00) >> 8),
  1118. ui32Peripheral & 0xff) = 0;
  1119. }
  1120. //*****************************************************************************
  1121. //
  1122. //! Controls peripheral clock gating in sleep and deep-sleep mode.
  1123. //!
  1124. //! \param bEnable is a boolean that is \b true if the sleep and deep-sleep
  1125. //! peripheral configuration should be used and \b false if not.
  1126. //!
  1127. //! This function controls how peripherals are clocked when the processor goes
  1128. //! into sleep or deep-sleep mode. By default, the peripherals are clocked the
  1129. //! same as in run mode; if peripheral clock gating is enabled, they are
  1130. //! clocked according to the configuration set by
  1131. //! SysCtlPeripheralSleepEnable(), SysCtlPeripheralSleepDisable(),
  1132. //! SysCtlPeripheralDeepSleepEnable(), and SysCtlPeripheralDeepSleepDisable().
  1133. //!
  1134. //! \return None.
  1135. //
  1136. //*****************************************************************************
  1137. void
  1138. SysCtlPeripheralClockGating(bool bEnable)
  1139. {
  1140. if(CLASS_IS_TM4C123)
  1141. {
  1142. //
  1143. // Enable peripheral clock gating as requested.
  1144. //
  1145. if(bEnable)
  1146. {
  1147. HWREG(SYSCTL_RCC) |= SYSCTL_RCC_ACG;
  1148. }
  1149. else
  1150. {
  1151. HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_ACG);
  1152. }
  1153. }
  1154. else
  1155. {
  1156. //
  1157. // Enable peripheral clock gating as requested.
  1158. //
  1159. if(bEnable)
  1160. {
  1161. HWREG(SYSCTL_RSCLKCFG) |= SYSCTL_RSCLKCFG_ACG;
  1162. }
  1163. else
  1164. {
  1165. HWREG(SYSCTL_RSCLKCFG) &= ~SYSCTL_RSCLKCFG_ACG;
  1166. }
  1167. }
  1168. }
  1169. //*****************************************************************************
  1170. //
  1171. //! Registers an interrupt handler for the system control interrupt.
  1172. //!
  1173. //! \param pfnHandler is a pointer to the function to be called when the system
  1174. //! control interrupt occurs.
  1175. //!
  1176. //! This function registers the handler to be called when a system control
  1177. //! interrupt occurs. This function enables the global interrupt in the
  1178. //! interrupt controller; specific system control interrupts must be enabled
  1179. //! via SysCtlIntEnable(). It is the interrupt handler's responsibility to
  1180. //! clear the interrupt source via SysCtlIntClear().
  1181. //!
  1182. //! System control can generate interrupts when the PLL achieves lock, if the
  1183. //! internal LDO current limit is exceeded, if the internal oscillator fails,
  1184. //! if the main oscillator fails, if the internal LDO output voltage droops too
  1185. //! much, if the external voltage droops too much, or if the PLL fails.
  1186. //!
  1187. //! \sa IntRegister() for important information about registering interrupt
  1188. //! handlers.
  1189. //!
  1190. //! \note The events that cause system control interrupts vary based on the
  1191. //! Tiva part in use. Please consult the data sheet for the part you are
  1192. //! using to determine which interrupt sources are available.
  1193. //!
  1194. //! \return None.
  1195. //
  1196. //*****************************************************************************
  1197. void
  1198. SysCtlIntRegister(void (*pfnHandler)(void))
  1199. {
  1200. //
  1201. // Register the interrupt handler, returning an error if an error occurs.
  1202. //
  1203. IntRegister(INT_SYSCTL_TM4C123, pfnHandler);
  1204. //
  1205. // Enable the system control interrupt.
  1206. //
  1207. IntEnable(INT_SYSCTL_TM4C123);
  1208. }
  1209. //*****************************************************************************
  1210. //
  1211. //! Unregisters the interrupt handler for the system control interrupt.
  1212. //!
  1213. //! This function unregisters the handler to be called when a system control
  1214. //! interrupt occurs. This function also masks off the interrupt in the
  1215. //! interrupt controller so that the interrupt handler no longer is called.
  1216. //!
  1217. //! \sa IntRegister() for important information about registering interrupt
  1218. //! handlers.
  1219. //!
  1220. //! \return None.
  1221. //
  1222. //*****************************************************************************
  1223. void
  1224. SysCtlIntUnregister(void)
  1225. {
  1226. //
  1227. // Disable the interrupt.
  1228. //
  1229. IntDisable(INT_SYSCTL_TM4C123);
  1230. //
  1231. // Unregister the interrupt handler.
  1232. //
  1233. IntUnregister(INT_SYSCTL_TM4C123);
  1234. }
  1235. //*****************************************************************************
  1236. //
  1237. //! Enables individual system control interrupt sources.
  1238. //!
  1239. //! \param ui32Ints is a bit mask of the interrupt sources to be enabled. Must
  1240. //! be a logical OR of \b SYSCTL_INT_BOR0, \b SYSCTL_INT_VDDA_OK,
  1241. //! \b SYSCTL_INT_MOSC_PUP, \b SYSCTL_INT_USBPLL_LOCK,
  1242. //! \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_BOR, and/or
  1243. //! \b SYSCTL_INT_BOR1.
  1244. //!
  1245. //! This function enables the indicated system control interrupt sources. Only
  1246. //! the sources that are enabled can be reflected to the processor interrupt;
  1247. //! disabled sources have no effect on the processor.
  1248. //!
  1249. //! \note The interrupt sources vary based on the Tiva part in use.
  1250. //! Please consult the data sheet for the part you are using to determine
  1251. //! which interrupt sources are available.
  1252. //!
  1253. //! \return None.
  1254. //
  1255. //*****************************************************************************
  1256. void
  1257. SysCtlIntEnable(uint32_t ui32Ints)
  1258. {
  1259. //
  1260. // Enable the specified interrupts.
  1261. //
  1262. HWREG(SYSCTL_IMC) |= ui32Ints;
  1263. }
  1264. //*****************************************************************************
  1265. //
  1266. //! Disables individual system control interrupt sources.
  1267. //!
  1268. //! \param ui32Ints is a bit mask of the interrupt sources to be disabled.
  1269. //! Must be a logical OR of \b SYSCTL_INT_BOR0, \b SYSCTL_INT_VDDA_OK,
  1270. //! \b SYSCTL_INT_MOSC_PUP, \b SYSCTL_INT_USBPLL_LOCK,
  1271. //! \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_BOR, and/or
  1272. //! \b SYSCTL_INT_BOR1.
  1273. //!
  1274. //! This function disables the indicated system control interrupt sources.
  1275. //! Only the sources that are enabled can be reflected to the processor
  1276. //! interrupt; disabled sources have no effect on the processor.
  1277. //!
  1278. //! \note The interrupt sources vary based on the Tiva part in use.
  1279. //! Please consult the data sheet for the part you are using to determine
  1280. //! which interrupt sources are available.
  1281. //!
  1282. //! \return None.
  1283. //
  1284. //*****************************************************************************
  1285. void
  1286. SysCtlIntDisable(uint32_t ui32Ints)
  1287. {
  1288. //
  1289. // Disable the specified interrupts.
  1290. //
  1291. HWREG(SYSCTL_IMC) &= ~(ui32Ints);
  1292. }
  1293. //*****************************************************************************
  1294. //
  1295. //! Clears system control interrupt sources.
  1296. //!
  1297. //! \param ui32Ints is a bit mask of the interrupt sources to be cleared. Must
  1298. //! be a logical OR of \b SYSCTL_INT_BOR0, \b SYSCTL_INT_VDDA_OK,
  1299. //! \b SYSCTL_INT_MOSC_PUP, \b SYSCTL_INT_USBPLL_LOCK,
  1300. //! \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_BOR, and/or
  1301. //! \b SYSCTL_INT_BOR1.
  1302. //!
  1303. //! The specified system control interrupt sources are cleared, so that they no
  1304. //! longer assert. This function must be called in the interrupt handler to
  1305. //! keep it from being called again immediately on exit.
  1306. //!
  1307. //! \note Because there is a write buffer in the Cortex-M processor, it may
  1308. //! take several clock cycles before the interrupt source is actually cleared.
  1309. //! Therefore, it is recommended that the interrupt source be cleared early in
  1310. //! the interrupt handler (as opposed to the very last action) to avoid
  1311. //! returning from the interrupt handler before the interrupt source is
  1312. //! actually cleared. Failure to do so may result in the interrupt handler
  1313. //! being immediately reentered (because the interrupt controller still sees
  1314. //! the interrupt source asserted).
  1315. //!
  1316. //! \note The interrupt sources vary based on the Tiva part in use.
  1317. //! Please consult the data sheet for the part you are using to determine
  1318. //! which interrupt sources are available.
  1319. //!
  1320. //! \return None.
  1321. //
  1322. //*****************************************************************************
  1323. void
  1324. SysCtlIntClear(uint32_t ui32Ints)
  1325. {
  1326. //
  1327. // Clear the requested interrupt sources.
  1328. //
  1329. HWREG(SYSCTL_MISC) = ui32Ints;
  1330. }
  1331. //*****************************************************************************
  1332. //
  1333. //! Gets the current interrupt status.
  1334. //!
  1335. //! \param bMasked is false if the raw interrupt status is required and true if
  1336. //! the masked interrupt status is required.
  1337. //!
  1338. //! This function returns the interrupt status for the system controller.
  1339. //! Either the raw interrupt status or the status of interrupts that are
  1340. //! allowed to reflect to the processor can be returned.
  1341. //!
  1342. //! \note The interrupt sources vary based on the Tiva part in use.
  1343. //! Please consult the data sheet for the part you are using to determine
  1344. //! which interrupt sources are available.
  1345. //!
  1346. //! \return The current interrupt status, enumerated as a bit field of
  1347. //! \b SYSCTL_INT_BOR0, \b SYSCTL_INT_VDDA_OK,
  1348. //! \b SYSCTL_INT_MOSC_PUP, \b SYSCTL_INT_USBPLL_LOCK,
  1349. //! \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_BOR, and/or
  1350. //! \b SYSCTL_INT_BOR1.
  1351. //
  1352. //*****************************************************************************
  1353. uint32_t
  1354. SysCtlIntStatus(bool bMasked)
  1355. {
  1356. //
  1357. // Return either the interrupt status or the raw interrupt status as
  1358. // requested.
  1359. //
  1360. if(bMasked)
  1361. {
  1362. return(HWREG(SYSCTL_MISC));
  1363. }
  1364. else
  1365. {
  1366. return(HWREG(SYSCTL_RIS));
  1367. }
  1368. }
  1369. //*****************************************************************************
  1370. //
  1371. //! Sets the output voltage of the LDO when the device enters sleep mode.
  1372. //!
  1373. //! \param ui32Voltage is the required output voltage from the LDO while in
  1374. //! sleep mode.
  1375. //!
  1376. //! This function sets the output voltage of the LDO while in sleep mode.
  1377. //! The \e ui32Voltage parameter must be one of the following values:
  1378. //! \b SYSCTL_LDO_0_90V, \b SYSCTL_LDO_0_95V, \b SYSCTL_LDO_1_00V,
  1379. //! \b SYSCTL_LDO_1_05V, \b SYSCTL_LDO_1_10V, \b SYSCTL_LDO_1_15V, or
  1380. //! \b SYSCTL_LDO_1_20V.
  1381. //!
  1382. //! \note The availability of this feature, the default LDO voltage, and the
  1383. //! adjustment range varies with the Tiva part in use. Please consult the
  1384. //! data sheet for the part you are using to determine whether this support is
  1385. //! available.
  1386. //!
  1387. //! \return None.
  1388. //
  1389. //*****************************************************************************
  1390. void
  1391. SysCtlLDOSleepSet(uint32_t ui32Voltage)
  1392. {
  1393. //
  1394. // Check the arguments.
  1395. //
  1396. ASSERT((ui32Voltage == SYSCTL_LDO_0_90V) ||
  1397. (ui32Voltage == SYSCTL_LDO_0_95V) ||
  1398. (ui32Voltage == SYSCTL_LDO_1_00V) ||
  1399. (ui32Voltage == SYSCTL_LDO_1_05V) ||
  1400. (ui32Voltage == SYSCTL_LDO_1_10V) ||
  1401. (ui32Voltage == SYSCTL_LDO_1_15V) ||
  1402. (ui32Voltage == SYSCTL_LDO_1_20V));
  1403. //
  1404. // Set the sleep-mode LDO voltage to the requested value.
  1405. //
  1406. HWREG(SYSCTL_LDOSPCTL) = ui32Voltage;
  1407. }
  1408. //*****************************************************************************
  1409. //
  1410. //! Returns the output voltage of the LDO when the device enters sleep mode.
  1411. //!
  1412. //! This function determines the output voltage of the LDO while in sleep mode,
  1413. //! as specified by the control register.
  1414. //!
  1415. //! \note The availability of this feature, the default LDO voltage, and the
  1416. //! adjustment range varies with the Tiva part in use. Please consult the
  1417. //! data sheet for the part you are using to determine whether this support is
  1418. //! available.
  1419. //!
  1420. //! \return Returns the sleep-mode voltage of the LDO and is one of
  1421. //! \b SYSCTL_LDO_0_90V, \b SYSCTL_LDO_0_95V, \b SYSCTL_LDO_1_00V,
  1422. //! \b SYSCTL_LDO_1_05V, \b SYSCTL_LDO_1_10V, \b SYSCTL_LDO_1_15V, or
  1423. //! \b SYSCTL_LDO_1_20V.
  1424. //
  1425. //*****************************************************************************
  1426. uint32_t
  1427. SysCtlLDOSleepGet(void)
  1428. {
  1429. //
  1430. // Return the sleep-mode LDO voltage setting.
  1431. //
  1432. return(HWREG(SYSCTL_LDOSPCTL));
  1433. }
  1434. //*****************************************************************************
  1435. //
  1436. //! Sets the output voltage of the LDO when the device enters deep-sleep
  1437. //! mode.
  1438. //!
  1439. //! \param ui32Voltage is the required output voltage from the LDO while in
  1440. //! deep-sleep mode.
  1441. //!
  1442. //! This function sets the output voltage of the LDO while in deep-sleep mode.
  1443. //! The \e ui32Voltage parameter specifies the output voltage of the LDO and
  1444. //! must be one of the following values: \b SYSCTL_LDO_0_90V,
  1445. //! \b SYSCTL_LDO_0_95V, \b SYSCTL_LDO_1_00V, \b SYSCTL_LDO_1_05V,
  1446. //! \b SYSCTL_LDO_1_10V, \b SYSCTL_LDO_1_15V, or \b SYSCTL_LDO_1_20V.
  1447. //!
  1448. //! \note The availability of this feature, the default LDO voltage, and the
  1449. //! adjustment range varies with the Tiva part in use. Please consult the
  1450. //! data sheet for the part you are using to determine whether this support is
  1451. //! available.
  1452. //!
  1453. //! \return None.
  1454. //
  1455. //*****************************************************************************
  1456. void
  1457. SysCtlLDODeepSleepSet(uint32_t ui32Voltage)
  1458. {
  1459. //
  1460. // Check the arguments.
  1461. //
  1462. ASSERT((ui32Voltage == SYSCTL_LDO_0_90V) ||
  1463. (ui32Voltage == SYSCTL_LDO_0_95V) ||
  1464. (ui32Voltage == SYSCTL_LDO_1_00V) ||
  1465. (ui32Voltage == SYSCTL_LDO_1_05V) ||
  1466. (ui32Voltage == SYSCTL_LDO_1_10V) ||
  1467. (ui32Voltage == SYSCTL_LDO_1_15V) ||
  1468. (ui32Voltage == SYSCTL_LDO_1_20V));
  1469. //
  1470. // Set the deep-sleep LDO voltage to the requested value.
  1471. //
  1472. HWREG(SYSCTL_LDODPCTL) = ui32Voltage;
  1473. }
  1474. //*****************************************************************************
  1475. //
  1476. //! Returns the output voltage of the LDO when the device enters deep-sleep
  1477. //! mode.
  1478. //!
  1479. //! This function returns the output voltage of the LDO when the device is
  1480. //! in deep-sleep mode, as specified by the control register.
  1481. //!
  1482. //! \note The availability of this feature, the default LDO voltage, and the
  1483. //! adjustment range varies with the Tiva part in use. Please consult the
  1484. //! data sheet for the part you are using to determine whether this support is
  1485. //! available.
  1486. //!
  1487. //! \return Returns the deep-sleep-mode voltage of the LDO; is one of
  1488. //! \b SYSCTL_LDO_0_90V, \b SYSCTL_LDO_0_95V, \b SYSCTL_LDO_1_00V,
  1489. //! \b SYSCTL_LDO_1_05V, \b SYSCTL_LDO_1_10V, \b SYSCTL_LDO_1_15V, or
  1490. //! \b SYSCTL_LDO_1_20V.
  1491. //
  1492. //*****************************************************************************
  1493. uint32_t
  1494. SysCtlLDODeepSleepGet(void)
  1495. {
  1496. //
  1497. // Return the deep-sleep-mode LDO voltage setting.
  1498. //
  1499. return(HWREG(SYSCTL_LDODPCTL));
  1500. }
  1501. //*****************************************************************************
  1502. //
  1503. //! Configures the power to the flash and SRAM while in sleep mode.
  1504. //!
  1505. //! \param ui32Config is the required flash and SRAM power configuration.
  1506. //!
  1507. //! This function allows the power configuration of the flash and SRAM while in
  1508. //! sleep mode to be set. The \e ui32Config parameter is the logical OR of the
  1509. //! flash power configuration and the SRAM power configuration.
  1510. //!
  1511. //! The flash power configuration is specified as either:
  1512. //!
  1513. //! - \b SYSCTL_FLASH_NORMAL - The flash is left in fully powered mode,
  1514. //! providing fast wake-up time but higher power consumption.
  1515. //! - \b SYSCTL_FLASH_LOW_POWER - The flash is in low power mode, providing
  1516. //! reduced power consumption but longer wake-up time.
  1517. //!
  1518. //! The SRAM power configuration is specified as one of:
  1519. //!
  1520. //! - \b SYSCTL_SRAM_NORMAL - The SRAM is left in fully powered mode, providing
  1521. //! fast wake-up time but higher power consumption.
  1522. //! - \b SYSCTL_SRAM_STANDBY - The SRAM is placed into a lower power mode,
  1523. //! providing reduced power consumption but longer wake-up time.
  1524. //! - \b SYSCTL_SRAM_LOW_POWER - The SRAM is placed into lowest power mode,
  1525. //! providing further reduced power consumption but longer wake-up time.
  1526. //!
  1527. //! \note The availability of this feature varies with the Tiva part in
  1528. //! use. Please consult the data sheet for the part you are using to determine
  1529. //! whether this support is available.
  1530. //!
  1531. //! \return None.
  1532. //
  1533. //*****************************************************************************
  1534. void
  1535. SysCtlSleepPowerSet(uint32_t ui32Config)
  1536. {
  1537. //
  1538. // Set the sleep-mode flash and SRAM power configuration.
  1539. //
  1540. HWREG(SYSCTL_SLPPWRCFG) = ui32Config;
  1541. }
  1542. //*****************************************************************************
  1543. //
  1544. //! Configures the power to the flash and SRAM while in deep-sleep mode.
  1545. //!
  1546. //! \param ui32Config is the required flash and SRAM power configuration.
  1547. //!
  1548. //! This function allows the power configuration of the flash and SRAM while in
  1549. //! deep-sleep mode to be set. The \e ui32Config parameter is the logical OR
  1550. //! of the flash power configuration and the SRAM power configuration.
  1551. //!
  1552. //! The flash power configuration is specified as either:
  1553. //!
  1554. //! - \b SYSCTL_FLASH_NORMAL - The flash is left in fully powered mode,
  1555. //! providing fast wake-up time but higher power consumption.
  1556. //! - \b SYSCTL_FLASH_LOW_POWER - The flash is in low power mode, providing
  1557. //! reduced power consumption but longer wake-up time.
  1558. //!
  1559. //! The SRAM power configuration is specified as one of:
  1560. //!
  1561. //! - \b SYSCTL_LDO_SLEEP - The LDO is in sleep mode.
  1562. //! - \b SYSCTL_TEMP_LOW_POWER - The temperature sensor in low power mode.
  1563. //! - \b SYSCTL_SRAM_NORMAL - The SRAM is left in fully powered mode, providing
  1564. //! fast wake-up time but higher power consumption.
  1565. //! - \b SYSCTL_SRAM_STANDBY - The SRAM is placed into a lower power mode,
  1566. //! providing reduced power consumption but longer wake-up time.
  1567. //! - \b SYSCTL_SRAM_LOW_POWER - The SRAM is placed into lowest power mode,
  1568. //! providing further reduced power consumption but longer wake-up time.
  1569. //!
  1570. //! \note The availability of this feature varies with the Tiva part in
  1571. //! use. Please consult the data sheet for the part you are using to determine
  1572. //! whether this support is available.
  1573. //!
  1574. //! \return None.
  1575. //
  1576. //*****************************************************************************
  1577. void
  1578. SysCtlDeepSleepPowerSet(uint32_t ui32Config)
  1579. {
  1580. //
  1581. // Set the deep-sleep-mode flash and SRAM power configuration.
  1582. //
  1583. HWREG(SYSCTL_DSLPPWRCFG) = ui32Config;
  1584. }
  1585. //*****************************************************************************
  1586. //
  1587. //! Resets the device.
  1588. //!
  1589. //! This function performs a software reset of the entire device. The
  1590. //! processor and all peripherals are reset and all device registers are
  1591. //! returned to their default values (with the exception of the reset cause
  1592. //! register, which maintains its current value but has the software reset
  1593. //! bit set as well).
  1594. //!
  1595. //! \return This function does not return.
  1596. //
  1597. //*****************************************************************************
  1598. void
  1599. SysCtlReset(void)
  1600. {
  1601. //
  1602. // Perform a software reset request. This request causes the device to
  1603. // reset, no further code is executed.
  1604. //
  1605. HWREG(NVIC_APINT) = NVIC_APINT_VECTKEY | NVIC_APINT_SYSRESETREQ;
  1606. //
  1607. // The device should have reset, so this should never be reached. Just in
  1608. // case, loop forever.
  1609. //
  1610. while(1)
  1611. {
  1612. }
  1613. }
  1614. //*****************************************************************************
  1615. //
  1616. //! Puts the processor into sleep mode.
  1617. //!
  1618. //! This function places the processor into sleep mode; it does not return
  1619. //! until the processor returns to run mode. The peripherals that are enabled
  1620. //! via SysCtlPeripheralSleepEnable() continue to operate and can wake up the
  1621. //! processor (if automatic clock gating is enabled with
  1622. //! SysCtlPeripheralClockGating(), otherwise all peripherals continue to
  1623. //! operate).
  1624. //!
  1625. //! \return None.
  1626. //
  1627. //*****************************************************************************
  1628. void
  1629. SysCtlSleep(void)
  1630. {
  1631. //
  1632. // Wait for an interrupt.
  1633. //
  1634. CPUwfi();
  1635. }
  1636. //*****************************************************************************
  1637. //
  1638. //! Puts the processor into deep-sleep mode.
  1639. //!
  1640. //! This function places the processor into deep-sleep mode; it does not return
  1641. //! until the processor returns to run mode. The peripherals that are enabled
  1642. //! via SysCtlPeripheralDeepSleepEnable() continue to operate and can wake up
  1643. //! the processor (if automatic clock gating is enabled with
  1644. //! SysCtlPeripheralClockGating(), otherwise all peripherals continue to
  1645. //! operate).
  1646. //!
  1647. //! \return None.
  1648. //
  1649. //*****************************************************************************
  1650. void
  1651. SysCtlDeepSleep(void)
  1652. {
  1653. //
  1654. // Enable deep-sleep.
  1655. //
  1656. HWREG(NVIC_SYS_CTRL) |= NVIC_SYS_CTRL_SLEEPDEEP;
  1657. //
  1658. // Wait for an interrupt.
  1659. //
  1660. CPUwfi();
  1661. //
  1662. // Disable deep-sleep so that a future sleep works correctly.
  1663. //
  1664. HWREG(NVIC_SYS_CTRL) &= ~(NVIC_SYS_CTRL_SLEEPDEEP);
  1665. }
  1666. //*****************************************************************************
  1667. //
  1668. //! Gets the reason for a reset.
  1669. //!
  1670. //! This function returns the reason(s) for a reset. Because the reset
  1671. //! reasons are sticky until either cleared by software or a power-on reset,
  1672. //! multiple reset reasons may be returned if multiple resets have occurred.
  1673. //! The reset reason is a logical OR of \b SYSCTL_CAUSE_HSRVREQ,
  1674. //! \b SYSCTL_CAUSE_HIB, \b SYSCTL_CAUSE_WDOG1, \b SYSCTL_CAUSE_SW,
  1675. //! \b SYSCTL_CAUSE_WDOG0, \b SYSCTL_CAUSE_BOR, \b SYSCTL_CAUSE_POR,
  1676. //! and/or \b SYSCTL_CAUSE_EXT.
  1677. //!
  1678. //! \return Returns the reason(s) for a reset.
  1679. //
  1680. //*****************************************************************************
  1681. uint32_t
  1682. SysCtlResetCauseGet(void)
  1683. {
  1684. //
  1685. // Return the reset reasons.
  1686. //
  1687. return(HWREG(SYSCTL_RESC));
  1688. }
  1689. //*****************************************************************************
  1690. //
  1691. //! Clears reset reasons.
  1692. //!
  1693. //! \param ui32Causes are the reset causes to be cleared; must be a logical OR
  1694. //! of \b SYSCTL_CAUSE_HSRVREQ, \b SYSCTL_CAUSE_HIB, \b SYSCTL_CAUSE_WDOG1,
  1695. //! \b SYSCTL_CAUSE_SW, \b SYSCTL_CAUSE_WDOG0, \b SYSCTL_CAUSE_BOR,
  1696. //! \b SYSCTL_CAUSE_POR, and/or \b SYSCTL_CAUSE_EXT.
  1697. //!
  1698. //! This function clears the specified sticky reset reasons. Once cleared,
  1699. //! another reset for the same reason can be detected, and a reset for a
  1700. //! different reason can be distinguished (instead of having two reset causes
  1701. //! set). If the reset reason is used by an application, all reset causes
  1702. //! should be cleared after they are retrieved with SysCtlResetCauseGet().
  1703. //!
  1704. //! \return None.
  1705. //
  1706. //*****************************************************************************
  1707. void
  1708. SysCtlResetCauseClear(uint32_t ui32Causes)
  1709. {
  1710. //
  1711. // Clear the given reset reasons.
  1712. //
  1713. HWREG(SYSCTL_RESC) &= ~(ui32Causes);
  1714. }
  1715. //*****************************************************************************
  1716. //
  1717. //! Provides a small delay.
  1718. //!
  1719. //! \param ui32Count is the number of delay loop iterations to perform.
  1720. //!
  1721. //! This function provides a means of generating a delay by executing a simple
  1722. //! 3 instruction cycle loop a given number of times. It is written in
  1723. //! assembly to keep the loop instruction count consistent across tool chains.
  1724. //!
  1725. //! It is important to note that this function does NOT provide an accurate
  1726. //! timing mechanism. Although the delay loop is 3 instruction cycles long,
  1727. //! the execution time of the loop will vary dramatically depending upon the
  1728. //! application's interrupt environment (the loop will be interrupted unless
  1729. //! run with interrupts disabled and this is generally an unwise thing to do)
  1730. //! and also the current system clock rate and flash timings (wait states and
  1731. //! the operation of the prefetch buffer affect the timing).
  1732. //!
  1733. //! For better accuracy, the ROM version of this function may be used. This
  1734. //! version will not suffer from flash- and prefect buffer-related timing
  1735. //! variability but will still be delayed by interrupt service routines.
  1736. //!
  1737. //! For best accuracy, a system timer should be used with code either polling
  1738. //! for a particular timer value being exceeded or processing the timer
  1739. //! interrupt to determine when a particular time period has elapsed.
  1740. //!
  1741. //! \return None.
  1742. //
  1743. //*****************************************************************************
  1744. #if defined(ewarm) || defined(DOXYGEN)
  1745. void
  1746. SysCtlDelay(uint32_t ui32Count)
  1747. {
  1748. __asm(" subs r0, #1\n"
  1749. " bne.n SysCtlDelay\n"
  1750. " bx lr");
  1751. }
  1752. #endif
  1753. #if defined(codered) || defined(gcc) || defined(sourcerygxx)
  1754. void __attribute__((naked))
  1755. SysCtlDelay(uint32_t ui32Count)
  1756. {
  1757. __asm(" subs r0, #1\n"
  1758. " bne SysCtlDelay\n"
  1759. " bx lr");
  1760. }
  1761. #endif
  1762. #if defined(rvmdk) || defined(__ARMCC_VERSION)
  1763. __asm void
  1764. SysCtlDelay(uint32_t ui32Count)
  1765. {
  1766. subs r0, #1;
  1767. bne SysCtlDelay;
  1768. bx lr;
  1769. }
  1770. #endif
  1771. //
  1772. // For CCS implement this function in pure assembly. This prevents the TI
  1773. // compiler from doing funny things with the optimizer.
  1774. //
  1775. #if defined(ccs)
  1776. __asm(" .sect \".text:SysCtlDelay\"\n"
  1777. " .clink\n"
  1778. " .thumbfunc SysCtlDelay\n"
  1779. " .thumb\n"
  1780. " .global SysCtlDelay\n"
  1781. "SysCtlDelay:\n"
  1782. " subs r0, #1\n"
  1783. " bne.n SysCtlDelay\n"
  1784. " bx lr\n");
  1785. #endif
  1786. //*****************************************************************************
  1787. //
  1788. //! Sets the configuration of the main oscillator (MOSC) control.
  1789. //!
  1790. //! \param ui32Config is the required configuration of the MOSC control.
  1791. //!
  1792. //! This function configures the control of the main oscillator. The
  1793. //! \e ui32Config is specified as the logical OR of the following values:
  1794. //!
  1795. //! - \b SYSCTL_MOSC_VALIDATE enables the MOSC verification circuit that
  1796. //! detects a failure of the main oscillator (such as a loss of the clock).
  1797. //! - \b SYSCTL_MOSC_INTERRUPT indicates that a MOSC failure should generate an
  1798. //! interrupt instead of resetting the processor.
  1799. //! - \b SYSCTL_MOSC_NO_XTAL indicates that there is no crystal or oscillator
  1800. //! connected to the OSC0/OSC1 pins, allowing power consumption to be
  1801. //! reduced.
  1802. //! - \b SYSCTL_MOSC_PWR_DIS disable power to the main oscillator. If this
  1803. //! parameter is not specified, the MOSC input remains powered.
  1804. //! - \b SYSCTL_MOSC_LOWFREQ MOSC is less than 10 MHz.
  1805. //! - \b SYSCTL_MOSC_HIGHFREQ MOSC is greater than 10 MHz.
  1806. //! - \b SYSCTL_MOSC_SESRC specifies that the MOSC is a single-ended
  1807. //! oscillator connected to OSC0. If this parameter is not specified, the
  1808. //! input is assumed to be a crystal.
  1809. //!
  1810. //! \note The availability of MOSC control varies based on the Tiva part
  1811. //! in use. Please consult the data sheet for the part you are using to
  1812. //! determine whether this support is available. In addition, the capability
  1813. //! of MOSC control varies based on the Tiva part in use.
  1814. //!
  1815. //! \return None.
  1816. //
  1817. //*****************************************************************************
  1818. void
  1819. SysCtlMOSCConfigSet(uint32_t ui32Config)
  1820. {
  1821. //
  1822. // Configure the MOSC control.
  1823. //
  1824. HWREG(SYSCTL_MOSCCTL) = ui32Config;
  1825. }
  1826. //*****************************************************************************
  1827. //
  1828. //! Calibrates the precision internal oscillator.
  1829. //!
  1830. //! \param ui32Type is the type of calibration to perform.
  1831. //!
  1832. //! This function performs a calibration of the PIOSC. There are three types
  1833. //! of calibration available; the desired calibration type as specified in
  1834. //! \e ui32Type is one of:
  1835. //!
  1836. //! - \b SYSCTL_PIOSC_CAL_AUTO to perform automatic calibration using the
  1837. //! 32-kHz clock from the hibernate module as a reference. This type is
  1838. //! only possible on parts that have a hibernate module, and then only if
  1839. //! it is enabled, a 32.768-kHz clock source is attached to the XOSC0/1
  1840. //! pins and the hibernate module's RTC is also enabled.
  1841. //!
  1842. //! - \b SYSCTL_PIOSC_CAL_FACT to reset the PIOSC calibration to the factory
  1843. //! provided calibration.
  1844. //!
  1845. //! - \b SYSCTL_PIOSC_CAL_USER to set the PIOSC calibration to a user-supplied
  1846. //! value. The value to be used is ORed into the lower 7-bits of this value,
  1847. //! with 0x40 being the ``nominal'' value (in other words, if everything were
  1848. //! perfect, 0x40 provides exactly 16 MHz). Values larger than 0x40
  1849. //! slow down PIOSC, and values smaller than 0x40 speed up PIOSC.
  1850. //!
  1851. //! \return Returns 1 if the calibration was successful and 0 if it failed.
  1852. //
  1853. //*****************************************************************************
  1854. uint32_t
  1855. SysCtlPIOSCCalibrate(uint32_t ui32Type)
  1856. {
  1857. //
  1858. // Perform the requested calibration. If performing user calibration, the
  1859. // UTEN bit must be set with one write, then the UT field in a second
  1860. // write, and the UPDATE bit in a final write. For other calibration
  1861. // types, a single write to set UPDATE or CAL is all that is required.
  1862. //
  1863. if(ui32Type & (SYSCTL_PIOSCCAL_UTEN | SYSCTL_PIOSCCAL_UPDATE))
  1864. {
  1865. HWREG(SYSCTL_PIOSCCAL) = ui32Type & SYSCTL_PIOSCCAL_UTEN;
  1866. HWREG(SYSCTL_PIOSCCAL) =
  1867. ui32Type & (SYSCTL_PIOSCCAL_UTEN | SYSCTL_PIOSCCAL_UT_M);
  1868. }
  1869. HWREG(SYSCTL_PIOSCCAL) = ui32Type;
  1870. //
  1871. // See if an automatic calibration was requested.
  1872. //
  1873. if(ui32Type & SYSCTL_PIOSCCAL_CAL)
  1874. {
  1875. //
  1876. // Wait for the automatic calibration to complete.
  1877. //
  1878. while((HWREG(SYSCTL_PIOSCSTAT) & SYSCTL_PIOSCSTAT_CR_M) == 0)
  1879. {
  1880. }
  1881. //
  1882. // If the automatic calibration failed, return an error.
  1883. //
  1884. if((HWREG(SYSCTL_PIOSCSTAT) & SYSCTL_PIOSCSTAT_CR_M) !=
  1885. SYSCTL_PIOSCSTAT_CRPASS)
  1886. {
  1887. return(0);
  1888. }
  1889. }
  1890. //
  1891. // The calibration was successful.
  1892. //
  1893. return(1);
  1894. }
  1895. //*****************************************************************************
  1896. //
  1897. //! Sets the type of reset issued due to certain reset events.
  1898. //!
  1899. //! \param ui32Behavior specifies the types of resets for each of the
  1900. //! configurable reset events.
  1901. //!
  1902. //! This function sets the types of reset issued when a configurable reset
  1903. //! event occurs. The reset events that are configurable are: Watchdog 0 or 1,
  1904. //! a brown out and the external RSTn pin. The valid actions are either a
  1905. //! system reset or a full POR sequence. See the data sheet for more
  1906. //! information on the differences between a full POR and a system reset. All
  1907. //! reset behaviors can be configured with a single call using the logical OR
  1908. //! of the values defined below. Any reset option that is not specifically set
  1909. //! remains configured for its default behavior. Either POR or system reset
  1910. //! can be selected for each reset cause.
  1911. //!
  1912. //! Valid values are logical combinations of the following:
  1913. //!
  1914. //! - \b SYSCTL_ONRST_WDOG0_POR configures a Watchdog 0 reset to perform a full
  1915. //! POR.
  1916. //! - \b SYSCTL_ONRST_WDOG0_SYS configures a Watchdog 0 reset to perform a
  1917. //! system reset.
  1918. //! - \b SYSCTL_ONRST_WDOG1_POR configures a Watchdog 1 reset to perform a full
  1919. //! POR.
  1920. //! - \b SYSCTL_ONRST_WDOG1_SYS configures a Watchdog 1 reset to perform a
  1921. //! system reset.
  1922. //! - \b SYSCTL_ONRST_BOR_POR configures a brown-out reset to perform a full
  1923. //! POR.
  1924. //! - \b SYSCTL_ONRST_BOR_SYS configures a brown-out reset to perform a system
  1925. //! reset.
  1926. //! - \b SYSCTL_ONRST_EXT_POR configures an external pin reset to perform a
  1927. //! full POR.
  1928. //! - \b SYSCTL_ONRST_EXT_SYS configures an external pin reset to perform a
  1929. //! system reset.
  1930. //!
  1931. //! \b Example: Set Watchdog 0 reset to trigger a POR and a brown-out reset
  1932. //! to trigger a system reset while leaving the remaining resets with their
  1933. //! default behaviors.
  1934. //!
  1935. //! \verbatim
  1936. //! SysCtlResetBehaviorSet(SYSCTL_ONRST_WDOG0_POR | SYSCTL_ONRST_BOR_SYS);
  1937. //! \endverbatim
  1938. //!
  1939. //! \note This function cannot be used with TM4C123 devices.
  1940. //!
  1941. //! \return None.
  1942. //
  1943. //*****************************************************************************
  1944. void
  1945. SysCtlResetBehaviorSet(uint32_t ui32Behavior)
  1946. {
  1947. HWREG(SYSCTL_RESBEHAVCTL) = ui32Behavior;
  1948. }
  1949. //*****************************************************************************
  1950. //
  1951. //! Returns the current types of reset issued due to reset events.
  1952. //!
  1953. //! This function returns the types of resets issued when a configurable reset
  1954. //! occurs. The value returned is a logical OR combination of the valid values
  1955. //! that are described in the documentation for the \e ui32Behavior parameter
  1956. //! of the SysCtlResetBehaviorSet() function.
  1957. //!
  1958. //! \note This function should only be used with Flurry-class devices.
  1959. //!
  1960. //! \return The reset behaviors for all configurable resets.
  1961. //
  1962. //*****************************************************************************
  1963. uint32_t
  1964. SysCtlResetBehaviorGet(void)
  1965. {
  1966. return(HWREG(SYSCTL_RESBEHAVCTL));
  1967. }
  1968. //*****************************************************************************
  1969. //
  1970. //! Configures the system clock.
  1971. //!
  1972. //! \param ui32Config is the required configuration of the device clocking.
  1973. //! \param ui32SysClock is the requested processor frequency.
  1974. //!
  1975. //! This function configures the main system clocking for the device. The
  1976. //! input frequency, oscillator source, whether or not to enable the PLL, and
  1977. //! the system clock divider are all configured with this function. This
  1978. //! function configures the system frequency to the closest available divisor
  1979. //! of one of the fixed PLL VCO settings provided in the \e ui32Config
  1980. //! parameter. The caller sets the \e ui32SysClock parameter to request the
  1981. //! system clock frequency, and this function then attempts to match this using
  1982. //! the values provided in the \e ui32Config parameter. If this function
  1983. //! cannot exactly match the requested frequency, it picks the closest
  1984. //! frequency that is lower than the requested frequency. The \e ui32Config
  1985. //! parameter provides the remaining configuration options using a set of
  1986. //! defines that are a logical OR of several different values, many of which
  1987. //! are grouped into sets where only one of the set can be chosen. This
  1988. //! function returns the current system frequency which may not match the
  1989. //! requested frequency.
  1990. //!
  1991. //! The oscillator source is chosen with one of the following values:
  1992. //!
  1993. //! - \b SYSCTL_OSC_MAIN to use an external crystal or oscillator.
  1994. //! - \b SYSCTL_OSC_INT to use the 16-MHz precision internal oscillator.
  1995. //! - \b SYSCTL_OSC_INT30 to use the internal low frequency oscillator.
  1996. //! - \b SYSCTL_OSC_EXT32 to use the hibernate modules 32.786-kHz oscillator.
  1997. //! This option is only available on devices that include the hibernation
  1998. //! module.
  1999. //!
  2000. //! The system clock source is chosen with one of the following values:
  2001. //!
  2002. //! - \b SYSCTL_USE_PLL is used to select the PLL output as the system clock.
  2003. //! - \b SYSCTL_USE_OSC is used to choose one of the oscillators as the
  2004. //! system clock.
  2005. //!
  2006. //! The PLL VCO frequency is chosen with one of the the following values:
  2007. //!
  2008. //! - \b SYSCTL_CFG_VCO_480 to set the PLL VCO output to 480-MHz
  2009. //! - \b SYSCTL_CFG_VCO_320 to set the PLL VCO output to 320-MHz
  2010. //!
  2011. //! Example: Configure the system clocking to be 40 MHz with a 320-MHz PLL
  2012. //! setting using the 16-MHz internal oscillator.
  2013. //!
  2014. //! \verbatim
  2015. //! SysCtlClockFreqSet(SYSCTL_OSC_INT | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_320,
  2016. //! 40000000);
  2017. //! \endverbatim
  2018. //!
  2019. //! \note This function cannot be used with TM4C123 devices. For TM4C123
  2020. //! devices use the SysCtlClockSet() function.
  2021. //!
  2022. //! \return The actual configured system clock frequency in Hz or zero if the
  2023. //! value could not be changed due to a parameter error or PLL lock failure.
  2024. //
  2025. //*****************************************************************************
  2026. uint32_t
  2027. SysCtlClockFreqSet(uint32_t ui32Config, uint32_t ui32SysClock)
  2028. {
  2029. int32_t i32Timeout, i32VCOIdx, i32XtalIdx;
  2030. uint32_t ui32MOSCCTL;
  2031. uint32_t ui32SysDiv, ui32Osc, ui32OscSelect, ui32RSClkConfig;
  2032. bool bNewPLL;
  2033. //
  2034. // TM4C123 devices should not use this function.
  2035. //
  2036. if(CLASS_IS_TM4C123)
  2037. {
  2038. return(0);
  2039. }
  2040. //
  2041. // Get the index of the crystal from the ui32Config parameter.
  2042. //
  2043. i32XtalIdx = SysCtlXtalCfgToIndex(ui32Config);
  2044. //
  2045. // Determine which non-PLL source was selected.
  2046. //
  2047. if((ui32Config & 0x38) == SYSCTL_OSC_INT)
  2048. {
  2049. //
  2050. // Use the nominal frequency for the PIOSC oscillator and set the
  2051. // crystal select.
  2052. //
  2053. ui32Osc = 16000000;
  2054. ui32OscSelect = SYSCTL_RSCLKCFG_OSCSRC_PIOSC;
  2055. ui32OscSelect |= SYSCTL_RSCLKCFG_PLLSRC_PIOSC;
  2056. //
  2057. // Force the crystal index to the value for 16-MHz.
  2058. //
  2059. i32XtalIdx = SysCtlXtalCfgToIndex(SYSCTL_XTAL_16MHZ);
  2060. }
  2061. else if((ui32Config & 0x38) == SYSCTL_OSC_INT30)
  2062. {
  2063. //
  2064. // Use the nominal frequency for the low frequency oscillator.
  2065. //
  2066. ui32Osc = 30000;
  2067. ui32OscSelect = SYSCTL_RSCLKCFG_OSCSRC_LFIOSC;
  2068. }
  2069. else if((ui32Config & 0x38) == (SYSCTL_OSC_EXT32 & 0x38))
  2070. {
  2071. //
  2072. // Use the RTC frequency.
  2073. //
  2074. ui32Osc = 32768;
  2075. ui32OscSelect = SYSCTL_RSCLKCFG_OSCSRC_RTC;
  2076. }
  2077. else if((ui32Config & 0x38) == SYSCTL_OSC_MAIN)
  2078. {
  2079. //
  2080. // Bounds check the source frequency for the main oscillator. The is
  2081. // because the PLL tables in the g_pppui32XTALtoVCO structure range
  2082. // from 5MHz to 25MHz.
  2083. //
  2084. if((i32XtalIdx > (SysCtlXtalCfgToIndex(SYSCTL_XTAL_25MHZ))) ||
  2085. (i32XtalIdx < (SysCtlXtalCfgToIndex(SYSCTL_XTAL_5MHZ))))
  2086. {
  2087. return(0);
  2088. }
  2089. ui32Osc = g_pui32Xtals[i32XtalIdx];
  2090. //
  2091. // Set the PLL source select to MOSC.
  2092. //
  2093. ui32OscSelect = SYSCTL_RSCLKCFG_OSCSRC_MOSC;
  2094. ui32OscSelect |= SYSCTL_RSCLKCFG_PLLSRC_MOSC;
  2095. //
  2096. // Clear MOSC power down, high oscillator range setting, and no crystal
  2097. // present setting.
  2098. //
  2099. ui32MOSCCTL = HWREG(SYSCTL_MOSCCTL) &
  2100. ~(SYSCTL_MOSCCTL_OSCRNG | SYSCTL_MOSCCTL_PWRDN |
  2101. SYSCTL_MOSCCTL_NOXTAL);
  2102. //
  2103. // Increase the drive strength for MOSC of 10 MHz and above.
  2104. //
  2105. if(i32XtalIdx >= (SysCtlXtalCfgToIndex(SYSCTL_XTAL_10MHZ) -
  2106. (SysCtlXtalCfgToIndex(SYSCTL_XTAL_5MHZ))))
  2107. {
  2108. ui32MOSCCTL |= SYSCTL_MOSCCTL_OSCRNG;
  2109. }
  2110. HWREG(SYSCTL_MOSCCTL) = ui32MOSCCTL;
  2111. }
  2112. else
  2113. {
  2114. //
  2115. // This was an invalid request because no oscillator source was
  2116. // indicated.
  2117. //
  2118. ui32Osc = 0;
  2119. ui32OscSelect = SYSCTL_RSCLKCFG_OSCSRC_PIOSC;
  2120. }
  2121. //
  2122. // Check if the running with the PLL enabled was requested.
  2123. //
  2124. if((ui32Config & SYSCTL_USE_OSC) == SYSCTL_USE_PLL)
  2125. {
  2126. //
  2127. // ui32Config must be SYSCTL_OSC_MAIN or SYSCTL_OSC_INT.
  2128. //
  2129. if(((ui32Config & 0x38) != SYSCTL_OSC_MAIN) &&
  2130. ((ui32Config & 0x38) != SYSCTL_OSC_INT))
  2131. {
  2132. return(0);
  2133. }
  2134. //
  2135. // Get the VCO index out of the ui32Config parameter.
  2136. //
  2137. i32VCOIdx = (ui32Config >> 24) & 7;
  2138. //
  2139. // Check that the VCO index is not out of bounds.
  2140. //
  2141. ASSERT(i32VCOIdx < MAX_VCO_ENTRIES);
  2142. //
  2143. // Set the memory timings for the maximum external frequency since
  2144. // this could be a switch to PIOSC or possibly to MOSC which can be
  2145. // up to 25MHz.
  2146. //
  2147. HWREG(SYSCTL_MEMTIM0) = _SysCtlMemTimingGet(25000000);
  2148. //
  2149. // Clear the old PLL divider and source in case it was set.
  2150. //
  2151. ui32RSClkConfig = HWREG(SYSCTL_RSCLKCFG) &
  2152. ~(SYSCTL_RSCLKCFG_PSYSDIV_M |
  2153. SYSCTL_RSCLKCFG_OSCSRC_M |
  2154. SYSCTL_RSCLKCFG_PLLSRC_M | SYSCTL_RSCLKCFG_USEPLL);
  2155. //
  2156. // Update the memory timings to match running from PIOSC.
  2157. //
  2158. ui32RSClkConfig |= SYSCTL_RSCLKCFG_MEMTIMU;
  2159. //
  2160. // Update clock configuration to switch back to PIOSC.
  2161. //
  2162. HWREG(SYSCTL_RSCLKCFG) = ui32RSClkConfig;
  2163. //
  2164. // The table starts at 5 MHz so modify the index to match this.
  2165. //
  2166. i32XtalIdx -= SysCtlXtalCfgToIndex(SYSCTL_XTAL_5MHZ);
  2167. //
  2168. // If there were no changes to the PLL do not force the PLL to lock by
  2169. // writing the PLL settings.
  2170. //
  2171. if((HWREG(SYSCTL_PLLFREQ1) !=
  2172. g_pppui32XTALtoVCO[i32VCOIdx][i32XtalIdx][1]) ||
  2173. (HWREG(SYSCTL_PLLFREQ0) !=
  2174. (g_pppui32XTALtoVCO[i32VCOIdx][i32XtalIdx][0] |
  2175. SYSCTL_PLLFREQ0_PLLPWR)))
  2176. {
  2177. bNewPLL = true;
  2178. }
  2179. else
  2180. {
  2181. bNewPLL = false;
  2182. }
  2183. //
  2184. // If there are new PLL settings write them.
  2185. //
  2186. if(bNewPLL)
  2187. {
  2188. //
  2189. // Set the oscillator source.
  2190. //
  2191. HWREG(SYSCTL_RSCLKCFG) |= ui32OscSelect;
  2192. //
  2193. // Set the M, N and Q values provided from the table and preserve
  2194. // the power state of the main PLL.
  2195. //
  2196. HWREG(SYSCTL_PLLFREQ1) =
  2197. g_pppui32XTALtoVCO[i32VCOIdx][i32XtalIdx][1];
  2198. HWREG(SYSCTL_PLLFREQ0) =
  2199. (g_pppui32XTALtoVCO[i32VCOIdx][i32XtalIdx][0] |
  2200. (HWREG(SYSCTL_PLLFREQ0) & SYSCTL_PLLFREQ0_PLLPWR));
  2201. }
  2202. //
  2203. // Calculate the System divider such that we get a frequency that is
  2204. // the closest to the requested frequency without going over.
  2205. //
  2206. ui32SysDiv = (g_pui32VCOFrequencies[i32VCOIdx] + ui32SysClock - 1) /
  2207. ui32SysClock;
  2208. //
  2209. // Calculate the actual system clock.
  2210. //
  2211. ui32SysClock = _SysCtlFrequencyGet(ui32Osc) / ui32SysDiv;
  2212. //
  2213. // Set the Flash and EEPROM timing values.
  2214. //
  2215. HWREG(SYSCTL_MEMTIM0) = _SysCtlMemTimingGet(ui32SysClock);
  2216. //
  2217. // Check if the PLL is already powered up.
  2218. //
  2219. if(HWREG(SYSCTL_PLLFREQ0) & SYSCTL_PLLFREQ0_PLLPWR)
  2220. {
  2221. if(bNewPLL == true)
  2222. {
  2223. //
  2224. // Trigger the PLL to lock to the new frequency.
  2225. //
  2226. HWREG(SYSCTL_RSCLKCFG) |= SYSCTL_RSCLKCFG_NEWFREQ;
  2227. }
  2228. }
  2229. else
  2230. {
  2231. //
  2232. // Power up the PLL.
  2233. //
  2234. HWREG(SYSCTL_PLLFREQ0) |= SYSCTL_PLLFREQ0_PLLPWR;
  2235. }
  2236. //
  2237. // Wait until the PLL has locked.
  2238. //
  2239. for(i32Timeout = 32768; i32Timeout > 0; i32Timeout--)
  2240. {
  2241. if((HWREG(SYSCTL_PLLSTAT) & SYSCTL_PLLSTAT_LOCK))
  2242. {
  2243. break;
  2244. }
  2245. }
  2246. //
  2247. // If the loop above did not timeout then switch over to the PLL
  2248. //
  2249. if(i32Timeout)
  2250. {
  2251. ui32RSClkConfig = HWREG(SYSCTL_RSCLKCFG);
  2252. ui32RSClkConfig |= ((ui32SysDiv - 1) <<
  2253. SYSCTL_RSCLKCFG_PSYSDIV_S) | ui32OscSelect |
  2254. SYSCTL_RSCLKCFG_USEPLL;
  2255. ui32RSClkConfig |= SYSCTL_RSCLKCFG_MEMTIMU;
  2256. //
  2257. // Set the new clock configuration.
  2258. //
  2259. HWREG(SYSCTL_RSCLKCFG) = ui32RSClkConfig;
  2260. }
  2261. else
  2262. {
  2263. ui32SysClock = 0;
  2264. }
  2265. }
  2266. else
  2267. {
  2268. //
  2269. // Set the Flash and EEPROM timing values for PIOSC.
  2270. //
  2271. HWREG(SYSCTL_MEMTIM0) = _SysCtlMemTimingGet(16000000);
  2272. //
  2273. // Make sure that the PLL is powered down since it is not being used.
  2274. //
  2275. HWREG(SYSCTL_PLLFREQ0) &= ~SYSCTL_PLLFREQ0_PLLPWR;
  2276. //
  2277. // Clear the old PLL divider and source in case it was set.
  2278. //
  2279. ui32RSClkConfig = HWREG(SYSCTL_RSCLKCFG);
  2280. ui32RSClkConfig &= ~(SYSCTL_RSCLKCFG_OSYSDIV_M |
  2281. SYSCTL_RSCLKCFG_OSCSRC_M |
  2282. SYSCTL_RSCLKCFG_USEPLL);
  2283. //
  2284. // Update the memory timings.
  2285. //
  2286. ui32RSClkConfig |= SYSCTL_RSCLKCFG_MEMTIMU;
  2287. //
  2288. // Set the new clock configuration.
  2289. //
  2290. HWREG(SYSCTL_RSCLKCFG) = ui32RSClkConfig;
  2291. //
  2292. // If zero given as the system clock then default to divide by 1.
  2293. //
  2294. if(ui32SysClock == 0)
  2295. {
  2296. ui32SysDiv = 0;
  2297. }
  2298. else
  2299. {
  2300. //
  2301. // Calculate the System divider based on the requested
  2302. // frequency.
  2303. //
  2304. ui32SysDiv = ui32Osc / ui32SysClock;
  2305. //
  2306. // If the system divisor is not already zero, subtract one to
  2307. // set the value in the register which requires the value to
  2308. // be n-1.
  2309. //
  2310. if(ui32SysDiv != 0)
  2311. {
  2312. ui32SysDiv -= 1;
  2313. }
  2314. //
  2315. // Calculate the system clock.
  2316. //
  2317. ui32SysClock = ui32Osc / (ui32SysDiv + 1);
  2318. }
  2319. //
  2320. // Set the memory timing values for the new system clock.
  2321. //
  2322. HWREG(SYSCTL_MEMTIM0) = _SysCtlMemTimingGet(ui32SysClock);
  2323. //
  2324. // Set the new system clock values.
  2325. //
  2326. ui32RSClkConfig = HWREG(SYSCTL_RSCLKCFG);
  2327. ui32RSClkConfig |= (ui32SysDiv << SYSCTL_RSCLKCFG_OSYSDIV_S) |
  2328. ui32OscSelect;
  2329. //
  2330. // Update the memory timings.
  2331. //
  2332. ui32RSClkConfig |= SYSCTL_RSCLKCFG_MEMTIMU;
  2333. //
  2334. // Set the new clock configuration.
  2335. //
  2336. HWREG(SYSCTL_RSCLKCFG) = ui32RSClkConfig;
  2337. }
  2338. return(ui32SysClock);
  2339. }
  2340. //*****************************************************************************
  2341. //
  2342. //! Sets the clocking of the device.
  2343. //!
  2344. //! \param ui32Config is the required configuration of the device clocking.
  2345. //!
  2346. //! This function configures the clocking of the device. The input crystal
  2347. //! frequency, oscillator to be used, use of the PLL, and the system clock
  2348. //! divider are all configured with this function.
  2349. //!
  2350. //! The \e ui32Config parameter is the logical OR of several different values,
  2351. //! many of which are grouped into sets where only one can be chosen.
  2352. //!
  2353. //! The system clock divider is chosen with one of the following values:
  2354. //! \b SYSCTL_SYSDIV_1, \b SYSCTL_SYSDIV_2, \b SYSCTL_SYSDIV_3, ...
  2355. //! \b SYSCTL_SYSDIV_64.
  2356. //!
  2357. //! The use of the PLL is chosen with either \b SYSCTL_USE_PLL or
  2358. //! \b SYSCTL_USE_OSC.
  2359. //!
  2360. //! The external crystal frequency is chosen with one of the following values:
  2361. //! \b SYSCTL_XTAL_4MHZ, \b SYSCTL_XTAL_4_09MHZ, \b SYSCTL_XTAL_4_91MHZ,
  2362. //! \b SYSCTL_XTAL_5MHZ, \b SYSCTL_XTAL_5_12MHZ, \b SYSCTL_XTAL_6MHZ,
  2363. //! \b SYSCTL_XTAL_6_14MHZ, \b SYSCTL_XTAL_7_37MHZ, \b SYSCTL_XTAL_8MHZ,
  2364. //! \b SYSCTL_XTAL_8_19MHZ, \b SYSCTL_XTAL_10MHZ, \b SYSCTL_XTAL_12MHZ,
  2365. //! \b SYSCTL_XTAL_12_2MHZ, \b SYSCTL_XTAL_13_5MHZ, \b SYSCTL_XTAL_14_3MHZ,
  2366. //! \b SYSCTL_XTAL_16MHZ, \b SYSCTL_XTAL_16_3MHZ, \b SYSCTL_XTAL_18MHZ,
  2367. //! \b SYSCTL_XTAL_20MHZ, \b SYSCTL_XTAL_24MHZ, or \b SYSCTL_XTAL_25MHz.
  2368. //! Values below \b SYSCTL_XTAL_5MHZ are not valid when the PLL is in
  2369. //! operation.
  2370. //!
  2371. //! The oscillator source is chosen with one of the following values:
  2372. //! \b SYSCTL_OSC_MAIN, \b SYSCTL_OSC_INT, \b SYSCTL_OSC_INT4,
  2373. //! \b SYSCTL_OSC_INT30, or \b SYSCTL_OSC_EXT32. \b SYSCTL_OSC_EXT32 is only
  2374. //! available on devices with the hibernate module, and then only when the
  2375. //! hibernate module has been enabled.
  2376. //!
  2377. //! The internal and main oscillators are disabled with the
  2378. //! \b SYSCTL_INT_OSC_DIS and \b SYSCTL_MAIN_OSC_DIS flags, respectively.
  2379. //! The external oscillator must be enabled in order to use an external clock
  2380. //! source. Note that attempts to disable the oscillator used to clock the
  2381. //! device is prevented by the hardware.
  2382. //!
  2383. //! To clock the system from an external source (such as an external crystal
  2384. //! oscillator), use \b SYSCTL_USE_OSC \b | \b SYSCTL_OSC_MAIN. To clock the
  2385. //! system from the main oscillator, use \b SYSCTL_USE_OSC \b |
  2386. //! \b SYSCTL_OSC_MAIN. To clock the system from the PLL, use
  2387. //! \b SYSCTL_USE_PLL \b | \b SYSCTL_OSC_MAIN, and select the appropriate
  2388. //! crystal with one of the \b SYSCTL_XTAL_xxx values.
  2389. //!
  2390. //! \note This function should only be called on TM4C123 devices. For
  2391. //! all other devices use the SysCtlClockFreqSet() function.
  2392. //!
  2393. //! \note If selecting the PLL as the system clock source (that is, via
  2394. //! \b SYSCTL_USE_PLL), this function polls the PLL lock interrupt to
  2395. //! determine when the PLL has locked. If an interrupt handler for the
  2396. //! system control interrupt is in place, and it responds to and clears the
  2397. //! PLL lock interrupt, this function delays until its timeout has occurred
  2398. //! instead of completing as soon as PLL lock is achieved.
  2399. //!
  2400. //! \return None.
  2401. //
  2402. //*****************************************************************************
  2403. void
  2404. SysCtlClockSet(uint32_t ui32Config)
  2405. {
  2406. uint32_t ui32Delay, ui32RCC, ui32RCC2;
  2407. //
  2408. // Get the current value of the RCC and RCC2 registers.
  2409. //
  2410. ui32RCC = HWREG(SYSCTL_RCC);
  2411. ui32RCC2 = HWREG(SYSCTL_RCC2);
  2412. //
  2413. // Bypass the PLL and system clock dividers for now.
  2414. //
  2415. ui32RCC |= SYSCTL_RCC_BYPASS;
  2416. ui32RCC &= ~(SYSCTL_RCC_USESYSDIV);
  2417. ui32RCC2 |= SYSCTL_RCC2_BYPASS2;
  2418. //
  2419. // Write the new RCC value.
  2420. //
  2421. HWREG(SYSCTL_RCC) = ui32RCC;
  2422. HWREG(SYSCTL_RCC2) = ui32RCC2;
  2423. //
  2424. // See if the oscillator needs to be enabled.
  2425. //
  2426. if((ui32RCC & SYSCTL_RCC_MOSCDIS) && !(ui32Config & SYSCTL_MAIN_OSC_DIS))
  2427. {
  2428. //
  2429. // Make sure that the required oscillators are enabled. For now, the
  2430. // previously enabled oscillators must be enabled along with the newly
  2431. // requested oscillators.
  2432. //
  2433. ui32RCC &= (~SYSCTL_RCC_MOSCDIS | (ui32Config & SYSCTL_MAIN_OSC_DIS));
  2434. //
  2435. // Clear the MOSC power up raw interrupt status to be sure it is not
  2436. // set when waiting below.
  2437. //
  2438. HWREG(SYSCTL_MISC) = SYSCTL_MISC_MOSCPUPMIS;
  2439. //
  2440. // Write the new RCC value.
  2441. //
  2442. HWREG(SYSCTL_RCC) = ui32RCC;
  2443. //
  2444. // Timeout using the legacy delay value.
  2445. //
  2446. ui32Delay = 524288;
  2447. while((HWREG(SYSCTL_RIS) & SYSCTL_RIS_MOSCPUPRIS) == 0)
  2448. {
  2449. ui32Delay--;
  2450. if(ui32Delay == 0)
  2451. {
  2452. break;
  2453. }
  2454. }
  2455. //
  2456. // If the main oscillator failed to start up then do not switch to
  2457. // it and return.
  2458. //
  2459. if(ui32Delay == 0)
  2460. {
  2461. return;
  2462. }
  2463. }
  2464. //
  2465. // Set the new crystal value and oscillator source. Because the OSCSRC2
  2466. // field in RCC2 overlaps the XTAL field in RCC, the OSCSRC field has a
  2467. // special encoding within ui32Config to avoid the overlap.
  2468. //
  2469. ui32RCC &= ~(SYSCTL_RCC_XTAL_M | SYSCTL_RCC_OSCSRC_M);
  2470. ui32RCC |= ui32Config & (SYSCTL_RCC_XTAL_M | SYSCTL_RCC_OSCSRC_M);
  2471. ui32RCC2 &= ~(SYSCTL_RCC2_USERCC2 | SYSCTL_RCC2_OSCSRC2_M);
  2472. ui32RCC2 |= ui32Config & (SYSCTL_RCC2_USERCC2 | SYSCTL_RCC_OSCSRC_M);
  2473. ui32RCC2 |= (ui32Config & 0x00000008) << 3;
  2474. //
  2475. // Write the new RCC value.
  2476. //
  2477. HWREG(SYSCTL_RCC) = ui32RCC;
  2478. HWREG(SYSCTL_RCC2) = ui32RCC2;
  2479. //
  2480. // Set the PLL configuration.
  2481. //
  2482. ui32RCC &= ~SYSCTL_RCC_PWRDN;
  2483. ui32RCC |= ui32Config & SYSCTL_RCC_PWRDN;
  2484. ui32RCC2 &= ~SYSCTL_RCC2_PWRDN2;
  2485. ui32RCC2 |= ui32Config & SYSCTL_RCC2_PWRDN2;
  2486. //
  2487. // Clear the PLL lock interrupt.
  2488. //
  2489. HWREG(SYSCTL_MISC) = SYSCTL_MISC_PLLLMIS;
  2490. //
  2491. // Write the new RCC value.
  2492. //
  2493. if(ui32RCC2 & SYSCTL_RCC2_USERCC2)
  2494. {
  2495. HWREG(SYSCTL_RCC2) = ui32RCC2;
  2496. HWREG(SYSCTL_RCC) = ui32RCC;
  2497. }
  2498. else
  2499. {
  2500. HWREG(SYSCTL_RCC) = ui32RCC;
  2501. HWREG(SYSCTL_RCC2) = ui32RCC2;
  2502. }
  2503. //
  2504. // Set the requested system divider and disable the appropriate
  2505. // oscillators. This value is not written immediately.
  2506. //
  2507. ui32RCC &= ~(SYSCTL_RCC_SYSDIV_M | SYSCTL_RCC_USESYSDIV |
  2508. SYSCTL_RCC_MOSCDIS);
  2509. ui32RCC |= ui32Config & (SYSCTL_RCC_SYSDIV_M | SYSCTL_RCC_USESYSDIV |
  2510. SYSCTL_RCC_MOSCDIS);
  2511. ui32RCC2 &= ~(SYSCTL_RCC2_SYSDIV2_M);
  2512. ui32RCC2 |= ui32Config & SYSCTL_RCC2_SYSDIV2_M;
  2513. if(ui32Config & SYSCTL_RCC2_DIV400)
  2514. {
  2515. ui32RCC |= SYSCTL_RCC_USESYSDIV;
  2516. ui32RCC2 &= ~(SYSCTL_RCC_USESYSDIV);
  2517. ui32RCC2 |= ui32Config & (SYSCTL_RCC2_DIV400 | SYSCTL_RCC2_SYSDIV2LSB);
  2518. }
  2519. else
  2520. {
  2521. ui32RCC2 &= ~(SYSCTL_RCC2_DIV400);
  2522. }
  2523. //
  2524. // See if the PLL output is being used to clock the system.
  2525. //
  2526. if(!(ui32Config & SYSCTL_RCC_BYPASS))
  2527. {
  2528. //
  2529. // Wait until the PLL has locked.
  2530. //
  2531. for(ui32Delay = 32768; ui32Delay > 0; ui32Delay--)
  2532. {
  2533. if((HWREG(SYSCTL_PLLSTAT) & SYSCTL_PLLSTAT_LOCK))
  2534. {
  2535. break;
  2536. }
  2537. }
  2538. //
  2539. // Enable use of the PLL.
  2540. //
  2541. ui32RCC &= ~(SYSCTL_RCC_BYPASS);
  2542. ui32RCC2 &= ~(SYSCTL_RCC2_BYPASS2);
  2543. }
  2544. //
  2545. // Write the final RCC value.
  2546. //
  2547. HWREG(SYSCTL_RCC) = ui32RCC;
  2548. HWREG(SYSCTL_RCC2) = ui32RCC2;
  2549. //
  2550. // Delay for a little bit so that the system divider takes effect.
  2551. //
  2552. SysCtlDelay(16);
  2553. }
  2554. //*****************************************************************************
  2555. //
  2556. //! Gets the processor clock rate.
  2557. //!
  2558. //! This function determines the clock rate of the processor clock, which is
  2559. //! also the clock rate of the peripheral modules (with the exception of
  2560. //! PWM, which has its own clock divider; other peripherals may have different
  2561. //! clocking, see the device data sheet for details).
  2562. //!
  2563. //! \note This cannot return accurate results if SysCtlClockSet() has not
  2564. //! been called to configure the clocking of the device, or if the device is
  2565. //! directly clocked from a crystal (or a clock source) that is not one of the
  2566. //! supported crystal frequencies. In the latter case, this function should be
  2567. //! modified to directly return the correct system clock rate.
  2568. //!
  2569. //! \note This function can only be called on TM4C123 devices. For TM4C129
  2570. //! devices, the return value from SysCtlClockFreqSet() indicates the system
  2571. //! clock frequency.
  2572. //!
  2573. //! \return The processor clock rate for TM4C123 devices only.
  2574. //
  2575. //*****************************************************************************
  2576. uint32_t
  2577. SysCtlClockGet(void)
  2578. {
  2579. uint32_t ui32RCC, ui32RCC2, ui32PLL, ui32Clk, ui32Max;
  2580. uint32_t ui32PLL1;
  2581. //
  2582. // This function is only valid on TM4C123 devices.
  2583. //
  2584. ASSERT(CLASS_IS_TM4C123);
  2585. //
  2586. // Read RCC and RCC2.
  2587. //
  2588. ui32RCC = HWREG(SYSCTL_RCC);
  2589. ui32RCC2 = HWREG(SYSCTL_RCC2);
  2590. //
  2591. // Get the base clock rate.
  2592. //
  2593. switch((ui32RCC2 & SYSCTL_RCC2_USERCC2) ?
  2594. (ui32RCC2 & SYSCTL_RCC2_OSCSRC2_M) :
  2595. (ui32RCC & SYSCTL_RCC_OSCSRC_M))
  2596. {
  2597. //
  2598. // The main oscillator is the clock source. Determine its rate from
  2599. // the crystal setting field.
  2600. //
  2601. case SYSCTL_RCC_OSCSRC_MAIN:
  2602. {
  2603. ui32Clk = g_pui32Xtals[(ui32RCC & SYSCTL_RCC_XTAL_M) >>
  2604. SYSCTL_RCC_XTAL_S];
  2605. break;
  2606. }
  2607. //
  2608. // The internal oscillator is the source clock.
  2609. //
  2610. case SYSCTL_RCC_OSCSRC_INT:
  2611. {
  2612. //
  2613. // The internal oscillator on all devices is 16 MHz.
  2614. //
  2615. ui32Clk = 16000000;
  2616. break;
  2617. }
  2618. //
  2619. // The internal oscillator divided by four is the source clock.
  2620. //
  2621. case SYSCTL_RCC_OSCSRC_INT4:
  2622. {
  2623. //
  2624. // The internal oscillator on all devices is 16 MHz.
  2625. //
  2626. ui32Clk = 16000000 / 4;
  2627. break;
  2628. }
  2629. //
  2630. // The internal 30-KHz oscillator is the source clock.
  2631. //
  2632. case SYSCTL_RCC_OSCSRC_30:
  2633. {
  2634. //
  2635. // The internal 30-KHz oscillator has an accuracy of +/- 30%.
  2636. //
  2637. ui32Clk = 30000;
  2638. break;
  2639. }
  2640. //
  2641. // The 32.768-KHz clock from the hibernate module is the source clock.
  2642. //
  2643. case SYSCTL_RCC2_OSCSRC2_32:
  2644. {
  2645. ui32Clk = 32768;
  2646. break;
  2647. }
  2648. //
  2649. // An unknown setting, so return a zero clock (that is, an unknown
  2650. // clock rate).
  2651. //
  2652. default:
  2653. {
  2654. return(0);
  2655. }
  2656. }
  2657. //
  2658. // Default the maximum frequency to the maximum 32-bit unsigned value.
  2659. //
  2660. ui32Max = 0xffffffff;
  2661. //
  2662. // See if the PLL is being used.
  2663. //
  2664. if(((ui32RCC2 & SYSCTL_RCC2_USERCC2) &&
  2665. !(ui32RCC2 & SYSCTL_RCC2_BYPASS2)) ||
  2666. (!(ui32RCC2 & SYSCTL_RCC2_USERCC2) && !(ui32RCC & SYSCTL_RCC_BYPASS)))
  2667. {
  2668. //
  2669. // Read the two PLL frequency registers. The formula for a
  2670. // TM4C123 device is "(xtal * m) / ((q + 1) * (n + 1))".
  2671. //
  2672. ui32PLL = HWREG(SYSCTL_PLLFREQ0);
  2673. ui32PLL1 = HWREG(SYSCTL_PLLFREQ1);
  2674. //
  2675. // Divide the input clock by the dividers.
  2676. //
  2677. ui32Clk /= ((((ui32PLL1 & SYSCTL_PLLFREQ1_Q_M) >>
  2678. SYSCTL_PLLFREQ1_Q_S) + 1) *
  2679. (((ui32PLL1 & SYSCTL_PLLFREQ1_N_M) >>
  2680. SYSCTL_PLLFREQ1_N_S) + 1) * 2);
  2681. //
  2682. // Multiply the clock by the multiplier, which is split into an
  2683. // integer part and a fractional part.
  2684. //
  2685. ui32Clk = ((ui32Clk * ((ui32PLL & SYSCTL_PLLFREQ0_MINT_M) >>
  2686. SYSCTL_PLLFREQ0_MINT_S)) +
  2687. ((ui32Clk * ((ui32PLL & SYSCTL_PLLFREQ0_MFRAC_M) >>
  2688. SYSCTL_PLLFREQ0_MFRAC_S)) >> 10));
  2689. //
  2690. // Force the system divider to be enabled. It is always used when
  2691. // using the PLL, but in some cases it does not read as being enabled.
  2692. //
  2693. ui32RCC |= SYSCTL_RCC_USESYSDIV;
  2694. //
  2695. // Calculate the maximum system frequency.
  2696. //
  2697. switch(HWREG(SYSCTL_DC1) & SYSCTL_DC1_MINSYSDIV_M)
  2698. {
  2699. case SYSCTL_DC1_MINSYSDIV_80:
  2700. {
  2701. ui32Max = 80000000;
  2702. break;
  2703. }
  2704. case SYSCTL_DC1_MINSYSDIV_66:
  2705. {
  2706. ui32Max = 66666666;
  2707. break;
  2708. }
  2709. case SYSCTL_DC1_MINSYSDIV_50:
  2710. {
  2711. ui32Max = 50000000;
  2712. break;
  2713. }
  2714. case SYSCTL_DC1_MINSYSDIV_40:
  2715. {
  2716. ui32Max = 40000000;
  2717. break;
  2718. }
  2719. case SYSCTL_DC1_MINSYSDIV_25:
  2720. {
  2721. ui32Max = 25000000;
  2722. break;
  2723. }
  2724. case SYSCTL_DC1_MINSYSDIV_20:
  2725. {
  2726. ui32Max = 20000000;
  2727. break;
  2728. }
  2729. default:
  2730. {
  2731. break;
  2732. }
  2733. }
  2734. }
  2735. //
  2736. // See if the system divider is being used.
  2737. //
  2738. if(ui32RCC & SYSCTL_RCC_USESYSDIV)
  2739. {
  2740. //
  2741. // Adjust the clock rate by the system clock divider.
  2742. //
  2743. if(ui32RCC2 & SYSCTL_RCC2_USERCC2)
  2744. {
  2745. if((ui32RCC2 & SYSCTL_RCC2_DIV400) &&
  2746. (((ui32RCC2 & SYSCTL_RCC2_USERCC2) &&
  2747. !(ui32RCC2 & SYSCTL_RCC2_BYPASS2)) ||
  2748. (!(ui32RCC2 & SYSCTL_RCC2_USERCC2) &&
  2749. !(ui32RCC & SYSCTL_RCC_BYPASS))))
  2750. {
  2751. ui32Clk = ((ui32Clk * 2) / (((ui32RCC2 &
  2752. (SYSCTL_RCC2_SYSDIV2_M |
  2753. SYSCTL_RCC2_SYSDIV2LSB)) >>
  2754. (SYSCTL_RCC2_SYSDIV2_S - 1)) +
  2755. 1));
  2756. }
  2757. else
  2758. {
  2759. ui32Clk /= (((ui32RCC2 & SYSCTL_RCC2_SYSDIV2_M) >>
  2760. SYSCTL_RCC2_SYSDIV2_S) + 1);
  2761. }
  2762. }
  2763. else
  2764. {
  2765. ui32Clk /= (((ui32RCC & SYSCTL_RCC_SYSDIV_M) >>
  2766. SYSCTL_RCC_SYSDIV_S) + 1);
  2767. }
  2768. }
  2769. //
  2770. // Limit the maximum clock to the maximum clock frequency.
  2771. //
  2772. if(ui32Max < ui32Clk)
  2773. {
  2774. ui32Clk = ui32Max;
  2775. }
  2776. //
  2777. // Return the computed clock rate.
  2778. //
  2779. return(ui32Clk);
  2780. }
  2781. //*****************************************************************************
  2782. //
  2783. //! Sets the clocking of the device while in deep-sleep mode.
  2784. //!
  2785. //! \param ui32Config is the required configuration of the device clocking
  2786. //! while in deep-sleep mode.
  2787. //!
  2788. //! This function configures the clocking of the device while in deep-sleep
  2789. //! mode. The oscillator to be used and the system clock divider are
  2790. //! configured with this function.
  2791. //!
  2792. //! The \e ui32Config parameter is the logical OR of the following values:
  2793. //!
  2794. //! The system clock divider is chosen from one of the following values:
  2795. //! \b SYSCTL_DSLP_DIV_1, \b SYSCTL_DSLP_DIV_2, \b SYSCTL_DSLP_DIV_3, ...
  2796. //! \b SYSCTL_DSLP_DIV_64.
  2797. //!
  2798. //! The oscillator source is chosen from one of the following values:
  2799. //! \b SYSCTL_DSLP_OSC_MAIN, \b SYSCTL_DSLP_OSC_INT, \b SYSCTL_DSLP_OSC_INT30,
  2800. //! or \b SYSCTL_DSLP_OSC_EXT32. \b SYSCTL_OSC_EXT32 is only available on
  2801. //! devices with the hibernation module, and then only when the hibernation
  2802. //! module has been enabled.
  2803. //!
  2804. //! The precision internal oscillator can be powered down in deep-sleep mode by
  2805. //! specifying \b SYSCTL_DSLP_PIOSC_PD. The precision internal oscillator is
  2806. //! not powered down if it is required for operation while in deep-sleep
  2807. //! (based on other configuration settings.)
  2808. //!
  2809. //! \note This function should only be called on TM4C123 devices. For
  2810. //! other devices use the SysCtlDeepSleepClockConfigSet() function.
  2811. //!
  2812. //! \note The availability of deep-sleep clocking configuration varies with the
  2813. //! Tiva part in use. Please consult the data sheet for the part you are
  2814. //! using to determine whether this support is available.
  2815. //!
  2816. //! \return None.
  2817. //
  2818. //*****************************************************************************
  2819. void
  2820. SysCtlDeepSleepClockSet(uint32_t ui32Config)
  2821. {
  2822. //
  2823. // Set the deep-sleep clock configuration.
  2824. //
  2825. HWREG(SYSCTL_DSLPCLKCFG) = ui32Config;
  2826. }
  2827. //*****************************************************************************
  2828. //
  2829. //! Sets the clock configuration of the device while in deep-sleep mode.
  2830. //!
  2831. //! \param ui32Div is the clock divider when in deep-sleep mode.
  2832. //! \param ui32Config is the configuration of the device clocking while
  2833. //! in deep-sleep mode.
  2834. //!
  2835. //! This function configures the clocking of the device while in deep-sleep
  2836. //! mode. The \e ui32Config parameter selects the oscillator and the
  2837. //! \e ui32Div parameter sets the clock divider used in deep-sleep mode. The
  2838. //! valid values for the \e ui32Div parameter range from 1 to 1024, however not
  2839. //! all Tiva microcontrollers support this full range. This function
  2840. //! replaces the SysCtlDeepSleepClockSet() function and can be used on
  2841. //! Tiva devices that support deep-sleep mode.
  2842. //!
  2843. //! The oscillator source is chosen from one of the following values:
  2844. //! \b SYSCTL_DSLP_OSC_MAIN, \b SYSCTL_DSLP_OSC_INT, \b SYSCTL_DSLP_OSC_INT30,
  2845. //! or \b SYSCTL_DSLP_OSC_EXT32. The \b SYSCTL_DSLP_OSC_EXT32 option is only
  2846. //! available on devices with the hibernation module, and then only when the
  2847. //! hibernation module is enabled.
  2848. //!
  2849. //! The precision internal oscillator can be powered down in deep-sleep mode by
  2850. //! specifying \b SYSCTL_DSLP_PIOSC_PD. The precision internal oscillator is
  2851. //! not powered down if it is required for operation while in deep-sleep
  2852. //! (based on other configuration settings).
  2853. //!
  2854. //! The main oscillator can be powered down in deep-sleep mode by
  2855. //! specifying \b SYSCTL_DSLP_MOSC_PD. The main oscillator is
  2856. //! not powered down if it is required for operation while in deep-sleep
  2857. //! (based on other configuration settings).
  2858. //!
  2859. //! \note The availability of deep-sleep clocking configuration and the
  2860. //! configuration values vary with the Tiva device in use. Please consult
  2861. //! the data sheet for the device you are using to determine whether the
  2862. //! desired configuration options are available and to determine the valid
  2863. //! range for the clock divider.
  2864. //!
  2865. //! \return None.
  2866. //
  2867. //*****************************************************************************
  2868. void
  2869. SysCtlDeepSleepClockConfigSet(uint32_t ui32Div, uint32_t ui32Config)
  2870. {
  2871. uint32_t ui32Value;
  2872. ASSERT(ui32Div != 0);
  2873. if(CLASS_IS_TM4C123)
  2874. {
  2875. //
  2876. // Set the deep-sleep clock configuration.
  2877. //
  2878. HWREG(SYSCTL_DSLPCLKCFG) = (ui32Config & ~SYSCTL_DSLPCLKCFG_D_M) |
  2879. ((ui32Div - 1) << SYSCTL_DSLPCLKCFG_D_S);
  2880. }
  2881. else
  2882. {
  2883. //
  2884. // Initialize the value with the divider.
  2885. //
  2886. ui32Value = ui32Div - 1;
  2887. //
  2888. // Set the clock source selection based on the defines used for
  2889. // SysCtlDeepSleepClockSet() function so that there is some backwards
  2890. // compatibility.
  2891. //
  2892. switch(ui32Config & SYSCTL_DSLPCLKCFG_O_M)
  2893. {
  2894. //
  2895. // Choose the main external oscillator.
  2896. //
  2897. case SYSCTL_DSLP_OSC_MAIN:
  2898. {
  2899. ui32Value |= SYSCTL_DSCLKCFG_DSOSCSRC_MOSC;
  2900. break;
  2901. }
  2902. //
  2903. // Choose the low frequency oscillator.
  2904. //
  2905. case SYSCTL_DSLP_OSC_INT30:
  2906. {
  2907. ui32Value |= SYSCTL_DSCLKCFG_DSOSCSRC_LFIOSC;
  2908. break;
  2909. }
  2910. //
  2911. // Choose the low frequency oscillator.
  2912. //
  2913. case SYSCTL_DSLP_OSC_EXT32:
  2914. {
  2915. ui32Value |= SYSCTL_DSCLKCFG_DSOSCSRC_RTC;
  2916. break;
  2917. }
  2918. //
  2919. // The zero value uses the PIOSC as the clock source.
  2920. //
  2921. case SYSCTL_DSLP_OSC_INT:
  2922. default:
  2923. {
  2924. break;
  2925. }
  2926. }
  2927. //
  2928. // Set the PIOSC power down bit.
  2929. //
  2930. if(ui32Config & SYSCTL_DSLP_PIOSC_PD)
  2931. {
  2932. ui32Value |= SYSCTL_DSCLKCFG_PIOSCPD;
  2933. }
  2934. //
  2935. // Set the PIOSC power down bit.
  2936. //
  2937. if(ui32Config & SYSCTL_DSLP_MOSC_PD)
  2938. {
  2939. ui32Value |= SYSCTL_DSCLKCFG_MOSCDPD;
  2940. }
  2941. //
  2942. // Update the deep-sleep clock configuration.
  2943. //
  2944. HWREG(SYSCTL_DSCLKCFG) = ui32Value;
  2945. }
  2946. }
  2947. //*****************************************************************************
  2948. //
  2949. //! Sets the PWM clock configuration.
  2950. //!
  2951. //! \param ui32Config is the configuration for the PWM clock; it must be one of
  2952. //! \b SYSCTL_PWMDIV_1, \b SYSCTL_PWMDIV_2, \b SYSCTL_PWMDIV_4,
  2953. //! \b SYSCTL_PWMDIV_8, \b SYSCTL_PWMDIV_16, \b SYSCTL_PWMDIV_32, or
  2954. //! \b SYSCTL_PWMDIV_64.
  2955. //!
  2956. //! This function configures the rate of the clock provided to the PWM module
  2957. //! as a ratio of the processor clock. This clock is used by the PWM module to
  2958. //! generate PWM signals; its rate forms the basis for all PWM signals.
  2959. //!
  2960. //! \note This function should only be used with TM4C123 devices. For
  2961. //! other TM4C devices, the PWMClockSet() function should be used.
  2962. //!
  2963. //! \note The clocking of the PWM is dependent on the system clock rate as
  2964. //! configured by SysCtlClockSet().
  2965. //!
  2966. //! \return None.
  2967. //
  2968. //*****************************************************************************
  2969. void
  2970. SysCtlPWMClockSet(uint32_t ui32Config)
  2971. {
  2972. //
  2973. // Check the arguments.
  2974. //
  2975. ASSERT((ui32Config == SYSCTL_PWMDIV_1) ||
  2976. (ui32Config == SYSCTL_PWMDIV_2) ||
  2977. (ui32Config == SYSCTL_PWMDIV_4) ||
  2978. (ui32Config == SYSCTL_PWMDIV_8) ||
  2979. (ui32Config == SYSCTL_PWMDIV_16) ||
  2980. (ui32Config == SYSCTL_PWMDIV_32) ||
  2981. (ui32Config == SYSCTL_PWMDIV_64));
  2982. //
  2983. // Check that there is a PWM block on this part.
  2984. //
  2985. ASSERT(HWREG(SYSCTL_DC1) & (SYSCTL_DC1_PWM0 | SYSCTL_DC1_PWM1));
  2986. //
  2987. // Set the PWM clock configuration into the run-mode clock configuration
  2988. // register.
  2989. //
  2990. HWREG(SYSCTL_RCC) = ((HWREG(SYSCTL_RCC) &
  2991. ~(SYSCTL_RCC_USEPWMDIV | SYSCTL_RCC_PWMDIV_M)) |
  2992. ui32Config);
  2993. }
  2994. //*****************************************************************************
  2995. //
  2996. //! Gets the current PWM clock configuration.
  2997. //!
  2998. //! This function returns the current PWM clock configuration.
  2999. //!
  3000. //! \return Returns the current PWM clock configuration; is one of
  3001. //! \b SYSCTL_PWMDIV_1, \b SYSCTL_PWMDIV_2, \b SYSCTL_PWMDIV_4,
  3002. //! \b SYSCTL_PWMDIV_8, \b SYSCTL_PWMDIV_16, \b SYSCTL_PWMDIV_32, or
  3003. //! \b SYSCTL_PWMDIV_64.
  3004. //!
  3005. //! \note This function should only be used with TM4C123 devices. For
  3006. //! other TM4C devices, the PWMClockGet() function should be used.
  3007. //
  3008. //*****************************************************************************
  3009. uint32_t
  3010. SysCtlPWMClockGet(void)
  3011. {
  3012. //
  3013. // Check that there is a PWM block on this part.
  3014. //
  3015. ASSERT(HWREG(SYSCTL_DC1) & (SYSCTL_DC1_PWM0 | SYSCTL_DC1_PWM1));
  3016. //
  3017. // Return the current PWM clock configuration. Make sure that
  3018. // SYSCTL_PWMDIV_1 is returned in all cases where the divider is disabled.
  3019. //
  3020. if(!(HWREG(SYSCTL_RCC) & SYSCTL_RCC_USEPWMDIV))
  3021. {
  3022. //
  3023. // The divider is not active so reflect this in the value we return.
  3024. //
  3025. return(SYSCTL_PWMDIV_1);
  3026. }
  3027. else
  3028. {
  3029. //
  3030. // The divider is active so directly return the masked register value.
  3031. //
  3032. return(HWREG(SYSCTL_RCC) &
  3033. (SYSCTL_RCC_USEPWMDIV | SYSCTL_RCC_PWMDIV_M));
  3034. }
  3035. }
  3036. //*****************************************************************************
  3037. //
  3038. //! Enables access to a GPIO peripheral via the AHB.
  3039. //!
  3040. //! \param ui32GPIOPeripheral is the GPIO peripheral to enable.
  3041. //!
  3042. //! This function is used to enable the specified GPIO peripheral to be
  3043. //! accessed from the Advanced Host Bus (AHB) instead of the legacy Advanced
  3044. //! Peripheral Bus (APB). When a GPIO peripheral is enabled for AHB access,
  3045. //! the \b _AHB_BASE form of the base address should be used for GPIO
  3046. //! functions. For example, instead of using \b GPIO_PORTA_BASE as the base
  3047. //! address for GPIO functions, use \b GPIO_PORTA_AHB_BASE instead.
  3048. //!
  3049. //! The \e ui32GPIOPeripheral argument must be only one of the following
  3050. //! values:
  3051. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  3052. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  3053. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, or \b SYSCTL_PERIPH_GPIOJ.
  3054. //!
  3055. //! \note On some devices, all GPIO ports are only available on AHB.
  3056. //!
  3057. //! \return None.
  3058. //
  3059. //*****************************************************************************
  3060. void
  3061. SysCtlGPIOAHBEnable(uint32_t ui32GPIOPeripheral)
  3062. {
  3063. //
  3064. // Check the arguments.
  3065. //
  3066. ASSERT((ui32GPIOPeripheral == SYSCTL_PERIPH_GPIOA) ||
  3067. (ui32GPIOPeripheral == SYSCTL_PERIPH_GPIOB) ||
  3068. (ui32GPIOPeripheral == SYSCTL_PERIPH_GPIOC) ||
  3069. (ui32GPIOPeripheral == SYSCTL_PERIPH_GPIOD) ||
  3070. (ui32GPIOPeripheral == SYSCTL_PERIPH_GPIOE) ||
  3071. (ui32GPIOPeripheral == SYSCTL_PERIPH_GPIOF) ||
  3072. (ui32GPIOPeripheral == SYSCTL_PERIPH_GPIOG) ||
  3073. (ui32GPIOPeripheral == SYSCTL_PERIPH_GPIOH) ||
  3074. (ui32GPIOPeripheral == SYSCTL_PERIPH_GPIOJ));
  3075. //
  3076. // Enable this GPIO for AHB access.
  3077. //
  3078. HWREG(SYSCTL_GPIOHBCTL) |= (1 << (ui32GPIOPeripheral & 0xF));
  3079. }
  3080. //*****************************************************************************
  3081. //
  3082. //! Disables access to a GPIO peripheral via the AHB.
  3083. //!
  3084. //! \param ui32GPIOPeripheral is the GPIO peripheral to disable.
  3085. //!
  3086. //! This function disables the specified GPIO peripheral for access from the
  3087. //! Advanced Host Bus (AHB). Once disabled, the GPIO peripheral is accessed
  3088. //! from the legacy Advanced Peripheral Bus (APB).
  3089. //!
  3090. //! The \b ui32GPIOPeripheral argument must be only one of the following
  3091. //! values:
  3092. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  3093. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  3094. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, or \b SYSCTL_PERIPH_GPIOJ.
  3095. //!
  3096. //! \note Some devices allow disabling AHB access to GPIO ports that are only
  3097. //! present on the AHB. Disabling AHB access to these ports will disable
  3098. //! access to these GPIO ports. On some devices, all GPIO ports are only
  3099. //! available on AHB.
  3100. //!
  3101. //! \return None.
  3102. //
  3103. //*****************************************************************************
  3104. void
  3105. SysCtlGPIOAHBDisable(uint32_t ui32GPIOPeripheral)
  3106. {
  3107. //
  3108. // Check the arguments.
  3109. //
  3110. ASSERT((ui32GPIOPeripheral == SYSCTL_PERIPH_GPIOA) ||
  3111. (ui32GPIOPeripheral == SYSCTL_PERIPH_GPIOB) ||
  3112. (ui32GPIOPeripheral == SYSCTL_PERIPH_GPIOC) ||
  3113. (ui32GPIOPeripheral == SYSCTL_PERIPH_GPIOD) ||
  3114. (ui32GPIOPeripheral == SYSCTL_PERIPH_GPIOE) ||
  3115. (ui32GPIOPeripheral == SYSCTL_PERIPH_GPIOF) ||
  3116. (ui32GPIOPeripheral == SYSCTL_PERIPH_GPIOG) ||
  3117. (ui32GPIOPeripheral == SYSCTL_PERIPH_GPIOH) ||
  3118. (ui32GPIOPeripheral == SYSCTL_PERIPH_GPIOJ));
  3119. //
  3120. // Disable this GPIO for AHB access.
  3121. //
  3122. HWREG(SYSCTL_GPIOHBCTL) &= ~(1 << (ui32GPIOPeripheral & 0xF));
  3123. }
  3124. //*****************************************************************************
  3125. //
  3126. //! Powers up the USB PLL.
  3127. //!
  3128. //! This function enables the USB controller's PLL, which is used by its
  3129. //! physical layer. This call is necessary before connecting to any external
  3130. //! devices.
  3131. //!
  3132. //! \note This function should only be called on TM4C123 devices.
  3133. //!
  3134. //! \return None.
  3135. //
  3136. //*****************************************************************************
  3137. void
  3138. SysCtlUSBPLLEnable(void)
  3139. {
  3140. //
  3141. // Turn on the USB PLL.
  3142. //
  3143. HWREG(SYSCTL_RCC2) &= ~SYSCTL_RCC2_USBPWRDN;
  3144. }
  3145. //*****************************************************************************
  3146. //
  3147. //! Powers down the USB PLL.
  3148. //!
  3149. //! This function disables the USB controller's PLL, which is used by its
  3150. //! physical layer. The USB registers are still accessible, but the physical
  3151. //! layer no longer functions.
  3152. //!
  3153. //! \note This function should only be called on TM4C123 devices.
  3154. //!
  3155. //! \return None.
  3156. //
  3157. //*****************************************************************************
  3158. void
  3159. SysCtlUSBPLLDisable(void)
  3160. {
  3161. //
  3162. // Turn off the USB PLL.
  3163. //
  3164. HWREG(SYSCTL_RCC2) |= SYSCTL_RCC2_USBPWRDN;
  3165. }
  3166. //*****************************************************************************
  3167. //
  3168. //! Configures the response to system voltage events.
  3169. //!
  3170. //! \param ui32Config holds the configuration options for the voltage events.
  3171. //!
  3172. //! This function configures the response to voltage-related events.
  3173. //! These events are triggered when the voltage rails drop below certain
  3174. //! levels. The \e ui32Config parameter provides the configuration for the
  3175. //! voltage events and is a combination of the \b SYSCTL_VEVENT_* values.
  3176. //!
  3177. //! The response to a brown out on the VDDA rail is set by using one of the
  3178. //! following values:
  3179. //! - \b SYSCTL_VEVENT_VDDABO_NONE - There is no action taken on a VDDA
  3180. //! brown out.
  3181. //! - \b SYSCTL_VEVENT_VDDABO_INT - A system interrupt is generated when a
  3182. //! VDDA brown out occurs.
  3183. //! - \b SYSCTL_VEVENT_VDDABO_NMI - An NMI is generated when a VDDA brown out
  3184. //! occurs.
  3185. //! - \b SYSCTL_VEVENT_VDDABO_RST - A reset is generated when a VDDA brown out
  3186. //! occurs. The type of reset that is generated is controller by the
  3187. //! \b SYSCTL_ONRST_BOR_* setting passed into the SysCtlResetBehaviorSet()
  3188. //! function.
  3189. //!
  3190. //! The response to a brown out on the VDD rail is set by using one of the
  3191. //! following values:
  3192. //! - \b SYSCTL_VEVENT_VDDBO_NONE - There is no action taken on a VDD
  3193. //! brown out.
  3194. //! - \b SYSCTL_VEVENT_VDDBO_INT - A system interrupt is generated when a
  3195. //! VDD brown out occurs.
  3196. //! - \b SYSCTL_VEVENT_VDDBO_NMI - An NMI is generated when a VDD brown out
  3197. //! occurs.
  3198. //! - \b SYSCTL_VEVENT_VDDBO_RST - A reset is generated when a VDD brown out
  3199. //! occurs. The type of reset that is generated is controller by the
  3200. //! \b SYSCTL_ONRST_BOR_* setting passed into the SysCtlResetBehaviorSet()
  3201. //! function.
  3202. //!
  3203. //! \b Example: Configure the voltage events to trigger an interrupt on a VDDA
  3204. //! brown out, an NMI on a VDDC brown out and a reset on a VDD brown out.
  3205. //!
  3206. //! \verbatim
  3207. //!
  3208. //! //
  3209. //! // Configure the BOR rest to trigger a full POR. This is needed because
  3210. //! // the SysCtlVoltageEventConfig() call is triggering a reset so the type
  3211. //! // of reset is specified by this call.
  3212. //! //
  3213. //! SysCtlResetBehaviorSet(SYSCTL_ONRST_BOR_POR);
  3214. //!
  3215. //! //
  3216. //! // Trigger an interrupt on a VDDA brown out and a reset on a VDD brown out.
  3217. //! //
  3218. //! SysCtlVoltageEventConfig(SYSCTL_VEVENT_VDDABO_INT |
  3219. //! SYSCTL_VEVENT_VDDBO_RST);
  3220. //! \endverbatim
  3221. //!
  3222. //! \return None.
  3223. //
  3224. //*****************************************************************************
  3225. void
  3226. SysCtlVoltageEventConfig(uint32_t ui32Config)
  3227. {
  3228. //
  3229. // Set the requested events.
  3230. //
  3231. HWREG(SYSCTL_PTBOCTL) = ui32Config;
  3232. }
  3233. //*****************************************************************************
  3234. //
  3235. //! Returns the voltage event status.
  3236. //!
  3237. //! This function returns the voltage event status for the system controller.
  3238. //! The value returned is a logical OR of the following values:
  3239. //! - \b SYSCTL_VESTAT_VDDBOR a brown-out event occurred on the VDD rail.
  3240. //! - \b SYSCTL_VESTAT_VDDABOR a brown-out event occurred on the VDDA rail.
  3241. //!
  3242. //! The values returned from this function can be passed to the
  3243. //! SysCtlVoltageEventClear() to clear the current voltage event status.
  3244. //! Because voltage events are not cleared due to a reset, the voltage event
  3245. //! status must be cleared by calling SysCtlVoltageEventClear().
  3246. //!
  3247. //! \b Example: Clear the current voltage event status.
  3248. //!
  3249. //! \verbatim
  3250. //! uint32_t ui32VoltageEvents;
  3251. //!
  3252. //! //
  3253. //! // Read the current voltage event status.
  3254. //! //
  3255. //! ui32VoltageEvents = SysCtlVoltageEventStatus();
  3256. //!
  3257. //! //
  3258. //! // Clear all the current voltage events.
  3259. //! //
  3260. //! SysCtlVoltageEventClear(ui32VoltageEvents);
  3261. //! \endverbatim
  3262. //!
  3263. //! \return The current voltage event status.
  3264. //!
  3265. //! \note The availability of voltage events varies with the Tiva part
  3266. //! in use. Please consult the data sheet for the part you are using to
  3267. //! determine which interrupt sources are available.
  3268. //
  3269. //*****************************************************************************
  3270. uint32_t
  3271. SysCtlVoltageEventStatus(void)
  3272. {
  3273. //
  3274. // Return the current voltage event status.
  3275. //
  3276. return(HWREG(SYSCTL_PWRTC));
  3277. }
  3278. //*****************************************************************************
  3279. //
  3280. //! Clears the voltage event status.
  3281. //!
  3282. //! \param ui32Status is a bit mask of the voltage events to clear.
  3283. //!
  3284. //! This function clears the current voltage events status for the values
  3285. //! specified in the \e ui32Status parameter. The \e ui32Status value must be
  3286. //! a logical OR of the following values:
  3287. //! - \b SYSCTL_VESTAT_VDDBOR a brown-out event occurred on the VDD rail.
  3288. //! - \b SYSCTL_VESTAT_VDDABOR a brown-out event occurred on the VDDA rail.
  3289. //!
  3290. //! \b Example: Clear the current voltage event status.
  3291. //!
  3292. //! \verbatim
  3293. //! //
  3294. //! // Clear all the current voltage events.
  3295. //! //
  3296. //! SysCtlVoltageEventClear(SysCtlVoltageEventStatus());
  3297. //! \endverbatim
  3298. //!
  3299. //! \note The availability of voltage event status varies with the
  3300. //! Tiva part in use. Please consult the data sheet for the part you are
  3301. //! using to determine which interrupt sources are available.
  3302. //!
  3303. //! \return None.
  3304. //
  3305. //*****************************************************************************
  3306. void
  3307. SysCtlVoltageEventClear(uint32_t ui32Status)
  3308. {
  3309. //
  3310. // Clear the requested voltage events.
  3311. //
  3312. HWREG(SYSCTL_PWRTC) |= ui32Status;
  3313. }
  3314. //*****************************************************************************
  3315. //
  3316. //! Returns the current NMI status.
  3317. //!
  3318. //! This function returns the NMI status for the system controller. The valid
  3319. //! values for the \e ui32Ints parameter are a logical OR of the following
  3320. //! values:
  3321. //! - \b SYSCTL_NMI_MOSCFAIL the main oscillator is not present or did not
  3322. //! start.
  3323. //! - \b SYSCTL_NMI_TAMPER a tamper event has been detected.
  3324. //! - \b SYSCTL_NMI_WDT0 watchdog 0 generated a timeout.
  3325. //! - \b SYSCTL_NMI_WDT1 watchdog 1 generated a timeout.
  3326. //! - \b SYSCTL_NMI_POWER a power event occurred.
  3327. //! - \b SYSCTL_NMI_EXTERNAL an external NMI pin asserted.
  3328. //!
  3329. //! \b Example: Clear all current NMI status flags.
  3330. //!
  3331. //! \verbatim
  3332. //!
  3333. //! //
  3334. //! // Clear all the current NMI sources.
  3335. //! //
  3336. //! SysCtlNMIClear(SysCtlNMIStatus());
  3337. //! \endverbatim
  3338. //!
  3339. //! \note The availability of the NMI status varies with the Tiva part in
  3340. //! use. Please consult the data sheet for the part you are using to determine
  3341. //! which interrupt sources are available.
  3342. //!
  3343. //! \return The current NMI status.
  3344. //
  3345. //*****************************************************************************
  3346. uint32_t
  3347. SysCtlNMIStatus(void)
  3348. {
  3349. return(HWREG(SYSCTL_NMIC));
  3350. }
  3351. //*****************************************************************************
  3352. //
  3353. //! Clears NMI sources.
  3354. //!
  3355. //! \param ui32Ints is a bit mask of the non-maskable interrupt sources.
  3356. //!
  3357. //! This function clears the current NMI status specified in the \e ui32Ints
  3358. //! parameter. The valid values for the \e ui32Ints parameter are a logical OR
  3359. //! of the following values:
  3360. //! - \b SYSCTL_NMI_MOSCFAIL the main oscillator is not present or did not
  3361. //! start.
  3362. //! - \b SYSCTL_NMI_TAMPER a tamper event has been detected.
  3363. //! - \b SYSCTL_NMI_WDT0 watchdog 0 generated a timeout.
  3364. //! - \b SYSCTL_NMI_WDT1 watchdog 1 generated a timeout.
  3365. //! - \b SYSCTL_NMI_POWER a power event occurred.
  3366. //! - \b SYSCTL_NMI_EXTERNAL an external NMI pin asserted.
  3367. //!
  3368. //! \b Example: Clear all current NMI status flags.
  3369. //!
  3370. //! \verbatim
  3371. //!
  3372. //! //
  3373. //! // Clear all the current NMI sources.
  3374. //! //
  3375. //! SysCtlNMIClear(SysCtlNMIStatus());
  3376. //! \endverbatim
  3377. //!
  3378. //! \note The availability of the NMI status varies with the Tiva part in
  3379. //! use. Please consult the data sheet for the part you are using to determine
  3380. //! which interrupt sources are available.
  3381. //!
  3382. //! \return None.
  3383. //
  3384. //*****************************************************************************
  3385. void
  3386. SysCtlNMIClear(uint32_t ui32Ints)
  3387. {
  3388. //
  3389. // Clear the requested interrupt sources.
  3390. //
  3391. HWREG(SYSCTL_NMIC) &= ~ui32Ints;
  3392. }
  3393. //*****************************************************************************
  3394. //
  3395. //! Configures and enables or disables the clock output on the DIVSCLK pin.
  3396. //!
  3397. //! \param ui32Config holds the configuration options including enabling or
  3398. //! disabling the clock output on the DIVSCLK pin.
  3399. //! \param ui32Div is the divisor for the clock selected in the \e ui32Config
  3400. //! parameter.
  3401. //!
  3402. //! This function selects the source for the DIVSCLK, enables or disables
  3403. //! the clock output and provides an output divider value. The \e ui32Div
  3404. //! parameter specifies the divider for the selected clock source and has a
  3405. //! valid range of 1-256. The \e ui32Config parameter configures
  3406. //! the DIVSCLK output based on the following settings:
  3407. //!
  3408. //! The first setting allows the output to be enabled or disabled.
  3409. //! - \b SYSCTL_CLKOUT_EN - enable the DIVSCLK output.
  3410. //! - \b SYSCTL_CLKOUT_DIS - disable the DIVSCLK output (default).
  3411. //!
  3412. //! The next group of settings selects the source for the DIVSCLK.
  3413. //! - \b SYSCTL_CLKOUT_SYSCLK - use the current system clock as the
  3414. //! source (default).
  3415. //! - \b SYSCTL_CLKOUT_PIOSC - use the PIOSC as the source.
  3416. //! - \b SYSCTL_CLKOUT_MOSC - use the MOSC as the source.
  3417. //!
  3418. //! \b Example: Enable the PIOSC divided by 4 as the DIVSCLK output.
  3419. //!
  3420. //! \verbatim
  3421. //!
  3422. //! //
  3423. //! // Enable the PIOSC divided by 4 as the DIVSCLK output.
  3424. //! //
  3425. //! SysCtlClockOutConfig(SYSCTL_DIVSCLK_EN | SYSCTL_DIVSCLK_SRC_PIOSC, 4);
  3426. //! \endverbatim
  3427. //!
  3428. //! \note The availability of the DIVSCLK output varies with the Tiva part
  3429. //! in use. Please consult the data sheet for the part you are using to
  3430. //! determine which interrupt sources are available.
  3431. //!
  3432. //! \return None.
  3433. //
  3434. //*****************************************************************************
  3435. void
  3436. SysCtlClockOutConfig(uint32_t ui32Config, uint32_t ui32Div)
  3437. {
  3438. ASSERT(ui32Div != 0);
  3439. ASSERT((ui32Config & ~(SYSCTL_CLKOUT_EN | SYSCTL_CLKOUT_DIS |
  3440. SYSCTL_CLKOUT_SYSCLK | SYSCTL_CLKOUT_PIOSC |
  3441. SYSCTL_CLKOUT_MOSC)) == 0);
  3442. //
  3443. // Set the requested configuration and divisor.
  3444. //
  3445. HWREG(SYSCTL_DIVSCLK) = ui32Config | ((ui32Div - 1) &
  3446. SYSCTL_DIVSCLK_DIV_M);
  3447. }
  3448. //*****************************************************************************
  3449. //
  3450. //! Configures the alternate peripheral clock source.
  3451. //!
  3452. //! \param ui32Config holds the configuration options for the alternate
  3453. //! peripheral clock.
  3454. //!
  3455. //! This function configures the alternate peripheral clock. The alternate
  3456. //! peripheral clock is used to provide a known clock in all operating modes
  3457. //! to peripherals that support using the alternate peripheral clock as an
  3458. //! input clock. The \e ui32Config parameter value provides the clock input
  3459. //! source using one of the following values:
  3460. //! - \b SYSCTL_ALTCLK_PIOSC - use the PIOSC as the alternate clock
  3461. //! source (default).
  3462. //! - \b SYSCTL_ALTCLK_RTCOSC - use the Hibernate module RTC clock as the
  3463. //! alternate clock source.
  3464. //! - \b SYSCTL_ALTCLK_LFIOSC - use the low-frequency internal oscillator as
  3465. //! the alternate clock source.
  3466. //!
  3467. //! \b Example: Select the Hibernate module RTC clock as the alternate clock
  3468. //! source.
  3469. //!
  3470. //! \verbatim
  3471. //!
  3472. //! //
  3473. //! // Select the Hibernate module RTC clock as the alternate clock source.
  3474. //! //
  3475. //! SysCtlAltClkConfig(SYSCTL_ALTCLK_RTCOSC);
  3476. //! \endverbatim
  3477. //!
  3478. //! \note The availability of the alternate peripheral clock varies with the
  3479. //! Tiva part in use. Please consult the data sheet for the part you are
  3480. //! using to determine which interrupt sources are available.
  3481. //!
  3482. //! \return None.
  3483. //
  3484. //*****************************************************************************
  3485. void
  3486. SysCtlAltClkConfig(uint32_t ui32Config)
  3487. {
  3488. //
  3489. // Set the requested configuration and divisor.
  3490. //
  3491. HWREG(SYSCTL_ALTCLKCFG) = ui32Config;
  3492. }
  3493. //*****************************************************************************
  3494. //
  3495. // Close the Doxygen group.
  3496. //! @}
  3497. //
  3498. //*****************************************************************************