sysctl.c 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126
  1. //*****************************************************************************
  2. //
  3. // sysctl.c - Driver for the system controller.
  4. //
  5. // Copyright (c) 2005-2011 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Texas Instruments (TI) is supplying this software for use solely and
  9. // exclusively on TI's microcontroller products. The software is owned by
  10. // TI and/or its suppliers, and is protected under applicable copyright
  11. // laws. You may not combine this software with "viral" open-source
  12. // software in order to form a larger program.
  13. //
  14. // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
  15. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
  16. // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
  18. // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
  19. // DAMAGES, FOR ANY REASON WHATSOEVER.
  20. //
  21. // This is part of revision 8264 of the Stellaris Peripheral Driver Library.
  22. //
  23. //*****************************************************************************
  24. //*****************************************************************************
  25. //
  26. //! \addtogroup sysctl_api
  27. //! @{
  28. //
  29. //*****************************************************************************
  30. #include "inc/hw_ints.h"
  31. #include "inc/hw_nvic.h"
  32. #include "inc/hw_sysctl.h"
  33. #include "inc/hw_types.h"
  34. #include "driverlib/cpu.h"
  35. #include "driverlib/debug.h"
  36. #include "driverlib/interrupt.h"
  37. #include "driverlib/sysctl.h"
  38. //*****************************************************************************
  39. //
  40. // This macro extracts the array index out of the peripheral number.
  41. //
  42. //*****************************************************************************
  43. #define SYSCTL_PERIPH_INDEX(a) (((a) >> 28) & 0xf)
  44. //*****************************************************************************
  45. //
  46. // This macro constructs the peripheral bit mask from the peripheral number.
  47. //
  48. //*****************************************************************************
  49. #define SYSCTL_PERIPH_MASK(a) (((a) & 0xffff) << (((a) & 0x001f0000) >> 16))
  50. //*****************************************************************************
  51. //
  52. // An array that maps the "peripheral set" number (which is stored in the upper
  53. // nibble of the SYSCTL_PERIPH_* defines) to the SYSCTL DC? register that
  54. // contains the peripheral present bit for that peripheral.
  55. //
  56. //*****************************************************************************
  57. static const unsigned long g_pulDCRegs[] =
  58. {
  59. SYSCTL_DC1,
  60. SYSCTL_DC2,
  61. SYSCTL_DC4,
  62. SYSCTL_DC1
  63. };
  64. //*****************************************************************************
  65. //
  66. // An array that maps the "peripheral set" number (which is stored in the upper
  67. // nibble of the SYSCTL_PERIPH_* defines) to the SYSCTL_SRCR? register that
  68. // controls the software reset for that peripheral.
  69. //
  70. //*****************************************************************************
  71. static const unsigned long g_pulSRCRRegs[] =
  72. {
  73. SYSCTL_SRCR0,
  74. SYSCTL_SRCR1,
  75. SYSCTL_SRCR2
  76. };
  77. //*****************************************************************************
  78. //
  79. // An array that maps the "peripheral set" number (which is stored in the upper
  80. // nibble of the SYSCTL_PERIPH_* defines) to the SYSCTL_RCGC? register that
  81. // controls the run-mode enable for that peripheral.
  82. //
  83. //*****************************************************************************
  84. static const unsigned long g_pulRCGCRegs[] =
  85. {
  86. SYSCTL_RCGC0,
  87. SYSCTL_RCGC1,
  88. SYSCTL_RCGC2
  89. };
  90. //*****************************************************************************
  91. //
  92. // An array that maps the "peripheral set" number (which is stored in the upper
  93. // nibble of the SYSCTL_PERIPH_* defines) to the SYSCTL_SCGC? register that
  94. // controls the sleep-mode enable for that peripheral.
  95. //
  96. //*****************************************************************************
  97. static const unsigned long g_pulSCGCRegs[] =
  98. {
  99. SYSCTL_SCGC0,
  100. SYSCTL_SCGC1,
  101. SYSCTL_SCGC2
  102. };
  103. //*****************************************************************************
  104. //
  105. // An array that maps the "peripheral set" number (which is stored in the upper
  106. // nibble of the SYSCTL_PERIPH_* defines) to the SYSCTL_DCGC? register that
  107. // controls the deep-sleep-mode enable for that peripheral.
  108. //
  109. //*****************************************************************************
  110. static const unsigned long g_pulDCGCRegs[] =
  111. {
  112. SYSCTL_DCGC0,
  113. SYSCTL_DCGC1,
  114. SYSCTL_DCGC2
  115. };
  116. //*****************************************************************************
  117. //
  118. // An array that maps the crystal number in RCC to a frequency.
  119. //
  120. //*****************************************************************************
  121. static const unsigned long g_pulXtals[] =
  122. {
  123. 1000000,
  124. 1843200,
  125. 2000000,
  126. 2457600,
  127. 3579545,
  128. 3686400,
  129. 4000000,
  130. 4096000,
  131. 4915200,
  132. 5000000,
  133. 5120000,
  134. 6000000,
  135. 6144000,
  136. 7372800,
  137. 8000000,
  138. 8192000,
  139. 10000000,
  140. 12000000,
  141. 12288000,
  142. 13560000,
  143. 14318180,
  144. 16000000,
  145. 16384000,
  146. 18000000,
  147. 20000000,
  148. 24000000,
  149. 25000000
  150. };
  151. //*****************************************************************************
  152. //
  153. // The base addresses of the various peripheral control registers.
  154. //
  155. //*****************************************************************************
  156. #define SYSCTL_PPBASE 0x400fe300
  157. #define SYSCTL_SRBASE 0x400fe500
  158. #define SYSCTL_RCGCBASE 0x400fe600
  159. #define SYSCTL_SCGCBASE 0x400fe700
  160. #define SYSCTL_DCGCBASE 0x400fe800
  161. #define SYSCTL_PCBASE 0x400fe900
  162. #define SYSCTL_PRBASE 0x400fea00
  163. //*****************************************************************************
  164. //
  165. //! \internal
  166. //! Checks a peripheral identifier.
  167. //!
  168. //! \param ulPeripheral is the peripheral identifier.
  169. //!
  170. //! This function determines if a peripheral identifier is valid.
  171. //!
  172. //! \return Returns \b true if the peripheral identifier is valid and \b false
  173. //! otherwise.
  174. //
  175. //*****************************************************************************
  176. #ifdef DEBUG
  177. static tBoolean
  178. SysCtlPeripheralValid(unsigned long ulPeripheral)
  179. {
  180. return((ulPeripheral == SYSCTL_PERIPH_ADC0) ||
  181. (ulPeripheral == SYSCTL_PERIPH_ADC1) ||
  182. (ulPeripheral == SYSCTL_PERIPH_CAN0) ||
  183. (ulPeripheral == SYSCTL_PERIPH_CAN1) ||
  184. (ulPeripheral == SYSCTL_PERIPH_CAN2) ||
  185. (ulPeripheral == SYSCTL_PERIPH_COMP0) ||
  186. (ulPeripheral == SYSCTL_PERIPH_COMP1) ||
  187. (ulPeripheral == SYSCTL_PERIPH_COMP2) ||
  188. (ulPeripheral == SYSCTL_PERIPH_EEPROM0) ||
  189. (ulPeripheral == SYSCTL_PERIPH_EPI0) ||
  190. (ulPeripheral == SYSCTL_PERIPH_ETH) ||
  191. (ulPeripheral == SYSCTL_PERIPH_FAN0) ||
  192. (ulPeripheral == SYSCTL_PERIPH_GPIOA) ||
  193. (ulPeripheral == SYSCTL_PERIPH_GPIOB) ||
  194. (ulPeripheral == SYSCTL_PERIPH_GPIOC) ||
  195. (ulPeripheral == SYSCTL_PERIPH_GPIOD) ||
  196. (ulPeripheral == SYSCTL_PERIPH_GPIOE) ||
  197. (ulPeripheral == SYSCTL_PERIPH_GPIOF) ||
  198. (ulPeripheral == SYSCTL_PERIPH_GPIOG) ||
  199. (ulPeripheral == SYSCTL_PERIPH_GPIOH) ||
  200. (ulPeripheral == SYSCTL_PERIPH_GPIOJ) ||
  201. (ulPeripheral == SYSCTL_PERIPH_GPIOK) ||
  202. (ulPeripheral == SYSCTL_PERIPH_GPIOL) ||
  203. (ulPeripheral == SYSCTL_PERIPH_GPIOM) ||
  204. (ulPeripheral == SYSCTL_PERIPH_GPION) ||
  205. (ulPeripheral == SYSCTL_PERIPH_GPIOP) ||
  206. (ulPeripheral == SYSCTL_PERIPH_GPIOQ) ||
  207. (ulPeripheral == SYSCTL_PERIPH_HIBERNATE) ||
  208. (ulPeripheral == SYSCTL_PERIPH_I2C0) ||
  209. (ulPeripheral == SYSCTL_PERIPH_I2C1) ||
  210. (ulPeripheral == SYSCTL_PERIPH_I2C2) ||
  211. (ulPeripheral == SYSCTL_PERIPH_I2C3) ||
  212. (ulPeripheral == SYSCTL_PERIPH_I2C4) ||
  213. (ulPeripheral == SYSCTL_PERIPH_I2C5) ||
  214. (ulPeripheral == SYSCTL_PERIPH_I2S0) ||
  215. (ulPeripheral == SYSCTL_PERIPH_IEEE1588) ||
  216. (ulPeripheral == SYSCTL_PERIPH_LPC0) ||
  217. (ulPeripheral == SYSCTL_PERIPH_MPU) ||
  218. (ulPeripheral == SYSCTL_PERIPH_PECI0) ||
  219. (ulPeripheral == SYSCTL_PERIPH_PLL) ||
  220. (ulPeripheral == SYSCTL_PERIPH_PWM0) ||
  221. (ulPeripheral == SYSCTL_PERIPH_PWM1) ||
  222. (ulPeripheral == SYSCTL_PERIPH_QEI0) ||
  223. (ulPeripheral == SYSCTL_PERIPH_QEI1) ||
  224. (ulPeripheral == SYSCTL_PERIPH_SSI0) ||
  225. (ulPeripheral == SYSCTL_PERIPH_SSI1) ||
  226. (ulPeripheral == SYSCTL_PERIPH_SSI2) ||
  227. (ulPeripheral == SYSCTL_PERIPH_SSI3) ||
  228. (ulPeripheral == SYSCTL_PERIPH_TEMP) ||
  229. (ulPeripheral == SYSCTL_PERIPH_TIMER0) ||
  230. (ulPeripheral == SYSCTL_PERIPH_TIMER1) ||
  231. (ulPeripheral == SYSCTL_PERIPH_TIMER2) ||
  232. (ulPeripheral == SYSCTL_PERIPH_TIMER3) ||
  233. (ulPeripheral == SYSCTL_PERIPH_TIMER4) ||
  234. (ulPeripheral == SYSCTL_PERIPH_TIMER5) ||
  235. (ulPeripheral == SYSCTL_PERIPH_UART0) ||
  236. (ulPeripheral == SYSCTL_PERIPH_UART1) ||
  237. (ulPeripheral == SYSCTL_PERIPH_UART2) ||
  238. (ulPeripheral == SYSCTL_PERIPH_UART3) ||
  239. (ulPeripheral == SYSCTL_PERIPH_UART4) ||
  240. (ulPeripheral == SYSCTL_PERIPH_UART5) ||
  241. (ulPeripheral == SYSCTL_PERIPH_UART6) ||
  242. (ulPeripheral == SYSCTL_PERIPH_UART7) ||
  243. (ulPeripheral == SYSCTL_PERIPH_UDMA) ||
  244. (ulPeripheral == SYSCTL_PERIPH_USB0) ||
  245. (ulPeripheral == SYSCTL_PERIPH_WDOG0) ||
  246. (ulPeripheral == SYSCTL_PERIPH_WDOG1) ||
  247. (ulPeripheral == SYSCTL_PERIPH_WTIMER0) ||
  248. (ulPeripheral == SYSCTL_PERIPH_WTIMER1) ||
  249. (ulPeripheral == SYSCTL_PERIPH_WTIMER2) ||
  250. (ulPeripheral == SYSCTL_PERIPH_WTIMER3) ||
  251. (ulPeripheral == SYSCTL_PERIPH_WTIMER4) ||
  252. (ulPeripheral == SYSCTL_PERIPH_WTIMER5));
  253. }
  254. #endif
  255. //*****************************************************************************
  256. //
  257. // A map of old peripheral defines to new peripheral defines. Note that the
  258. // new peripheral defines will not work on parts that precede Blizzard class.
  259. //
  260. //*****************************************************************************
  261. static const unsigned long g_ppulPeripheralMap[][2] =
  262. {
  263. { SYSCTL_PERIPH_ADC0, SYSCTL_PERIPH2_ADC0 },
  264. { SYSCTL_PERIPH_ADC1, SYSCTL_PERIPH2_ADC1 },
  265. { SYSCTL_PERIPH_CAN0, SYSCTL_PERIPH2_CAN0 },
  266. { SYSCTL_PERIPH_CAN1, SYSCTL_PERIPH2_CAN1 },
  267. { SYSCTL_PERIPH_CAN2, SYSCTL_PERIPH2_CAN2 },
  268. { SYSCTL_PERIPH_COMP0, SYSCTL_PERIPH2_COMP0 },
  269. { SYSCTL_PERIPH_COMP1, SYSCTL_PERIPH2_COMP0 },
  270. { SYSCTL_PERIPH_COMP2, SYSCTL_PERIPH2_COMP0 },
  271. { SYSCTL_PERIPH_GPIOA, SYSCTL_PERIPH2_GPIOA },
  272. { SYSCTL_PERIPH_GPIOB, SYSCTL_PERIPH2_GPIOB },
  273. { SYSCTL_PERIPH_GPIOC, SYSCTL_PERIPH2_GPIOC },
  274. { SYSCTL_PERIPH_GPIOD, SYSCTL_PERIPH2_GPIOD },
  275. { SYSCTL_PERIPH_GPIOE, SYSCTL_PERIPH2_GPIOE },
  276. { SYSCTL_PERIPH_GPIOF, SYSCTL_PERIPH2_GPIOF },
  277. { SYSCTL_PERIPH_GPIOG, SYSCTL_PERIPH2_GPIOG },
  278. { SYSCTL_PERIPH_GPIOH, SYSCTL_PERIPH2_GPIOH },
  279. { SYSCTL_PERIPH_GPIOJ, SYSCTL_PERIPH2_GPIOJ },
  280. { SYSCTL_PERIPH_I2C0, SYSCTL_PERIPH2_I2C0 },
  281. { SYSCTL_PERIPH_I2C1, SYSCTL_PERIPH2_I2C1 },
  282. { SYSCTL_PERIPH_PWM0, SYSCTL_PERIPH2_PWM0 },
  283. { SYSCTL_PERIPH_QEI0, SYSCTL_PERIPH2_QEI0 },
  284. { SYSCTL_PERIPH_QEI1, SYSCTL_PERIPH2_QEI1 },
  285. { SYSCTL_PERIPH_SSI0, SYSCTL_PERIPH2_SSI0 },
  286. { SYSCTL_PERIPH_SSI1, SYSCTL_PERIPH2_SSI1 },
  287. { SYSCTL_PERIPH_TIMER0, SYSCTL_PERIPH2_TIMER0 },
  288. { SYSCTL_PERIPH_TIMER1, SYSCTL_PERIPH2_TIMER1 },
  289. { SYSCTL_PERIPH_TIMER2, SYSCTL_PERIPH2_TIMER2 },
  290. { SYSCTL_PERIPH_TIMER3, SYSCTL_PERIPH2_TIMER3 },
  291. { SYSCTL_PERIPH_UART0, SYSCTL_PERIPH2_UART0 },
  292. { SYSCTL_PERIPH_UART1, SYSCTL_PERIPH2_UART1 },
  293. { SYSCTL_PERIPH_UART2, SYSCTL_PERIPH2_UART2 },
  294. { SYSCTL_PERIPH_UDMA, SYSCTL_PERIPH2_UDMA },
  295. { SYSCTL_PERIPH_USB0, SYSCTL_PERIPH2_USB0 },
  296. { SYSCTL_PERIPH_WDOG0, SYSCTL_PERIPH2_WDOG0 },
  297. { SYSCTL_PERIPH_WDOG1, SYSCTL_PERIPH2_WDOG1 },
  298. };
  299. //*****************************************************************************
  300. //
  301. // Maps a SYSCTL_PERIPH_foo identifier into its new-style SYSCTL_PERIPH2_foo
  302. // identifier.
  303. //
  304. //*****************************************************************************
  305. static unsigned long
  306. SysCtlPeripheralMapToNew(unsigned long ulPeripheral)
  307. {
  308. unsigned long ulIndex;
  309. //
  310. // Loop throug the table of old-style identifiers.
  311. //
  312. for(ulIndex = 0; ulIndex < (sizeof(g_ppulPeripheralMap) /
  313. sizeof(g_ppulPeripheralMap[0])); ulIndex++)
  314. {
  315. //
  316. // See if this peripheral matches the old-style identifer.
  317. //
  318. if(g_ppulPeripheralMap[ulIndex][0] == ulPeripheral)
  319. {
  320. //
  321. // Return the new-style identifier that corresponds to this
  322. // peripheral.
  323. //
  324. return(g_ppulPeripheralMap[ulIndex][1]);
  325. }
  326. }
  327. //
  328. // No old-style identifier was found, so return the identifier unchanged
  329. // (on the assumption that it is already a new-style identifier).
  330. //
  331. return(ulPeripheral);
  332. }
  333. //*****************************************************************************
  334. //
  335. //! Gets the size of the SRAM.
  336. //!
  337. //! This function determines the size of the SRAM on the Stellaris device.
  338. //!
  339. //! \return The total number of bytes of SRAM.
  340. //
  341. //*****************************************************************************
  342. unsigned long
  343. SysCtlSRAMSizeGet(void)
  344. {
  345. //
  346. // Compute the size of the SRAM.
  347. //
  348. return(((HWREG(SYSCTL_DC0) & SYSCTL_DC0_SRAMSZ_M) >> 8) + 0x100);
  349. }
  350. //*****************************************************************************
  351. //
  352. //! Gets the size of the flash.
  353. //!
  354. //! This function determines the size of the flash on the Stellaris device.
  355. //!
  356. //! \return The total number of bytes of flash.
  357. //
  358. //*****************************************************************************
  359. unsigned long
  360. SysCtlFlashSizeGet(void)
  361. {
  362. //
  363. // Compute the size of the flash.
  364. //
  365. return(((HWREG(SYSCTL_DC0) & SYSCTL_DC0_FLASHSZ_M) << 11) + 0x800);
  366. }
  367. //*****************************************************************************
  368. //
  369. //! Determines if a pin is present.
  370. //!
  371. //! \param ulPin is the pin in question.
  372. //!
  373. //! This function determines if a particular pin is present in the device. The
  374. //! PWM, analog comparators, ADC, and timers have a varying number of pins
  375. //! across members of the Stellaris family; this function determines which pins
  376. //! are present on this device.
  377. //!
  378. //! The \e ulPin argument must be only one of the following values:
  379. //! \b SYSCTL_PIN_PWM0, \b SYSCTL_PIN_PWM1, \b SYSCTL_PIN_PWM2,
  380. //! \b SYSCTL_PIN_PWM3, \b SYSCTL_PIN_PWM4, \b SYSCTL_PIN_PWM5,
  381. //! \b SYSCTL_PIN_C0MINUS, \b SYSCTL_PIN_C0PLUS, \b SYSCTL_PIN_C0O,
  382. //! \b SYSCTL_PIN_C1MINUS, \b SYSCTL_PIN_C1PLUS, \b SYSCTL_PIN_C1O,
  383. //! \b SYSCTL_PIN_C2MINUS, \b SYSCTL_PIN_C2PLUS, \b SYSCTL_PIN_C2O,
  384. //! \b SYSCTL_PIN_ADC0, \b SYSCTL_PIN_ADC1, \b SYSCTL_PIN_ADC2,
  385. //! \b SYSCTL_PIN_ADC3, \b SYSCTL_PIN_ADC4, \b SYSCTL_PIN_ADC5,
  386. //! \b SYSCTL_PIN_ADC6, \b SYSCTL_PIN_ADC7, \b SYSCTL_PIN_CCP0,
  387. //! \b SYSCTL_PIN_CCP1, \b SYSCTL_PIN_CCP2, \b SYSCTL_PIN_CCP3,
  388. //! \b SYSCTL_PIN_CCP4, \b SYSCTL_PIN_CCP5, \b SYSCTL_PIN_CCP6,
  389. //! \b SYSCTL_PIN_CCP7, \b SYSCTL_PIN_32KHZ, or \b SYSCTL_PIN_MC_FAULT0.
  390. //!
  391. //! \return Returns \b true if the specified pin is present and \b false if it
  392. //! is not.
  393. //
  394. //*****************************************************************************
  395. tBoolean
  396. SysCtlPinPresent(unsigned long ulPin)
  397. {
  398. //
  399. // Check the arguments.
  400. //
  401. ASSERT((ulPin == SYSCTL_PIN_PWM0) ||
  402. (ulPin == SYSCTL_PIN_PWM1) ||
  403. (ulPin == SYSCTL_PIN_PWM2) ||
  404. (ulPin == SYSCTL_PIN_PWM3) ||
  405. (ulPin == SYSCTL_PIN_PWM4) ||
  406. (ulPin == SYSCTL_PIN_PWM5) ||
  407. (ulPin == SYSCTL_PIN_C0MINUS) ||
  408. (ulPin == SYSCTL_PIN_C0PLUS) ||
  409. (ulPin == SYSCTL_PIN_C0O) ||
  410. (ulPin == SYSCTL_PIN_C1MINUS) ||
  411. (ulPin == SYSCTL_PIN_C1PLUS) ||
  412. (ulPin == SYSCTL_PIN_C1O) ||
  413. (ulPin == SYSCTL_PIN_C2MINUS) ||
  414. (ulPin == SYSCTL_PIN_C2PLUS) ||
  415. (ulPin == SYSCTL_PIN_C2O) ||
  416. (ulPin == SYSCTL_PIN_MC_FAULT0) ||
  417. (ulPin == SYSCTL_PIN_ADC0) ||
  418. (ulPin == SYSCTL_PIN_ADC1) ||
  419. (ulPin == SYSCTL_PIN_ADC2) ||
  420. (ulPin == SYSCTL_PIN_ADC3) ||
  421. (ulPin == SYSCTL_PIN_ADC4) ||
  422. (ulPin == SYSCTL_PIN_ADC5) ||
  423. (ulPin == SYSCTL_PIN_ADC6) ||
  424. (ulPin == SYSCTL_PIN_ADC7) ||
  425. (ulPin == SYSCTL_PIN_CCP0) ||
  426. (ulPin == SYSCTL_PIN_CCP1) ||
  427. (ulPin == SYSCTL_PIN_CCP2) ||
  428. (ulPin == SYSCTL_PIN_CCP3) ||
  429. (ulPin == SYSCTL_PIN_CCP4) ||
  430. (ulPin == SYSCTL_PIN_CCP5) ||
  431. (ulPin == SYSCTL_PIN_32KHZ));
  432. //
  433. // Determine if this pin is present.
  434. //
  435. if(HWREG(SYSCTL_DC3) & ulPin)
  436. {
  437. return(true);
  438. }
  439. else
  440. {
  441. return(false);
  442. }
  443. }
  444. //*****************************************************************************
  445. //
  446. //! Determines if a peripheral is present.
  447. //!
  448. //! \param ulPeripheral is the peripheral in question.
  449. //!
  450. //! This function determines if a particular peripheral is present in the
  451. //! device. Each member of the Stellaris family has a different peripheral
  452. //! set; this function determines which peripherals are present on this device.
  453. //!
  454. //! The \e ulPeripheral parameter must be only one of the following values:
  455. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  456. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
  457. //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EPI0,
  458. //! \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0, \b SYSCTL_PERIPH_GPIOA,
  459. //! \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC, \b SYSCTL_PERIPH_GPIOD,
  460. //! \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF, \b SYSCTL_PERIPH_GPIOG,
  461. //! \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ, \b SYSCTL_PERIPH_GPIOK,
  462. //! \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM, \b SYSCTL_PERIPH_GPION,
  463. //! \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ, \b SYSCTL_PERIPH_HIBERNATE,
  464. //! \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_I2C2,
  465. //! \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4, \b SYSCTL_PERIPH_I2C5,
  466. //! \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_IEEE1588, \b SYSCTL_PERIPH_LPC0,
  467. //! \b SYSCTL_PERIPH_MPU, \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PLL,
  468. //! \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1, \b SYSCTL_PERIPH_QEI0,
  469. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  470. //! \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3, \b SYSCTL_PERIPH_TEMP,
  471. //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
  472. //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
  473. //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
  474. //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
  475. //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
  476. //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
  477. //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
  478. //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
  479. //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5,
  480. //!
  481. //! \return Returns \b true if the specified peripheral is present and \b false
  482. //! if it is not.
  483. //
  484. //*****************************************************************************
  485. tBoolean
  486. SysCtlPeripheralPresent(unsigned long ulPeripheral)
  487. {
  488. //
  489. // Check the arguments.
  490. //
  491. ASSERT(SysCtlPeripheralValid(ulPeripheral));
  492. //
  493. // See if the peripheral index is 15, indicating a peripheral that is
  494. // accessed via the SYSCTL_PPperiph registers.
  495. //
  496. if((ulPeripheral & 0xf0000000) == 0xf0000000)
  497. {
  498. //
  499. // See if this peripheral is present.
  500. //
  501. return(HWREGBITW(SYSCTL_PPBASE + ((ulPeripheral & 0xff00) >> 8),
  502. ulPeripheral & 0xff));
  503. }
  504. else if(ulPeripheral == SYSCTL_PERIPH_USB0)
  505. {
  506. //
  507. // USB is a special case because the DC bit is missing for USB0.
  508. //
  509. if(HWREG(SYSCTL_DC6) & SYSCTL_DC6_USB0_M)
  510. {
  511. return(true);
  512. }
  513. else
  514. {
  515. return(false);
  516. }
  517. }
  518. else if(HWREG(g_pulDCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) &
  519. SYSCTL_PERIPH_MASK(ulPeripheral))
  520. {
  521. return(true);
  522. }
  523. else
  524. {
  525. return(false);
  526. }
  527. }
  528. //*****************************************************************************
  529. //
  530. //! Determines if a peripheral is ready.
  531. //!
  532. //! \param ulPeripheral is the peripheral in question.
  533. //!
  534. //! This function determines if a particular peripheral is ready to be
  535. //! accessed. The peripheral may be in a non-ready state if it is not enabled,
  536. //! is being held in reset, or is in the process of becoming ready after being
  537. //! enabled or taken out of reset.
  538. //!
  539. //! The \e ulPeripheral paramter must be only one of the following values:
  540. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  541. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
  542. //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EEPROM0,
  543. //! \b SYSCTL_PERIPH_EPI0, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0,
  544. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  545. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  546. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  547. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  548. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  549. //! \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1,
  550. //! \b SYSCTL_PERIPH_I2C2, \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4,
  551. //! \b SYSCTL_PERIPH_I2C5, \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_LPC0,
  552. //! \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1,
  553. //! \b SYSCTL_PERIPH_QEI0, \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0,
  554. //! \b SYSCTL_PERIPH_SSI1, \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3,
  555. //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
  556. //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
  557. //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
  558. //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
  559. //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
  560. //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
  561. //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
  562. //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
  563. //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5.
  564. //!
  565. //! \note The ability to check for a peripheral being ready varies based on the
  566. //! Stellaris part in use. Please consult the data sheet for the part you are
  567. //! using to determine if this feature is available.
  568. //!
  569. //! \return Returns \b true if the specified peripheral is ready and \b false
  570. //! if it is not.
  571. //
  572. //*****************************************************************************
  573. tBoolean
  574. SysCtlPeripheralReady(unsigned long ulPeripheral)
  575. {
  576. //
  577. // Check the arguments.
  578. //
  579. ASSERT(SysCtlPeripheralValid(ulPeripheral));
  580. //
  581. // Map the peripheral identifier to the new style identifiers. If it is
  582. // already a new style identifier, this is a NOP.
  583. //
  584. ulPeripheral = SysCtlPeripheralMapToNew(ulPeripheral);
  585. //
  586. // See if this peripheral is ready.
  587. //
  588. return(HWREGBITW(SYSCTL_PRBASE + ((ulPeripheral & 0xff00) >> 8),
  589. ulPeripheral & 0xff));
  590. }
  591. //*****************************************************************************
  592. //
  593. //! Powers on a peripheral.
  594. //!
  595. //! \param ulPeripheral is the peripheral to be powered on.
  596. //!
  597. //! This function turns on the power to a peripheral. The peripheral continues
  598. //! to receive power even when its clock is not enabled.
  599. //!
  600. //! The \e ulPeripheral paramter must be only one of the following values:
  601. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  602. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
  603. //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EEPROM0,
  604. //! \b SYSCTL_PERIPH_EPI0, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0,
  605. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  606. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  607. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  608. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  609. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  610. //! \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1,
  611. //! \b SYSCTL_PERIPH_I2C2, \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4,
  612. //! \b SYSCTL_PERIPH_I2C5, \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_LPC0,
  613. //! \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1,
  614. //! \b SYSCTL_PERIPH_QEI0, \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0,
  615. //! \b SYSCTL_PERIPH_SSI1, \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3,
  616. //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
  617. //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
  618. //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
  619. //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
  620. //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
  621. //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
  622. //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
  623. //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
  624. //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5.
  625. //!
  626. //! \note The ability to power off a peripheral varies based on the Stellaris
  627. //! part in use. Please consult the data sheet for the part you are using to
  628. //! determine if this feature is available.
  629. //!
  630. //! \return None.
  631. //
  632. //*****************************************************************************
  633. void
  634. SysCtlPeripheralPowerOn(unsigned long ulPeripheral)
  635. {
  636. //
  637. // Check the arguments.
  638. //
  639. ASSERT(SysCtlPeripheralValid(ulPeripheral));
  640. //
  641. // Map the peripheral identifier to the new style identifiers. If it is
  642. // already a new style identifier, this is a NOP.
  643. //
  644. ulPeripheral = SysCtlPeripheralMapToNew(ulPeripheral);
  645. //
  646. // Power on this peripheral.
  647. //
  648. HWREGBITW(SYSCTL_PCBASE + ((ulPeripheral & 0xff00) >> 8),
  649. ulPeripheral & 0xff) = 1;
  650. }
  651. //*****************************************************************************
  652. //
  653. //! Powers off a peripheral.
  654. //!
  655. //! \param ulPeripheral is the peripheral to be powered off.
  656. //!
  657. //! This function allows the power to a peripheral to be turned off. The
  658. //! peripheral continues to receive power when its clock is enabled, but
  659. //! the power is removed when its clock is disabled.
  660. //!
  661. //! The \e ulPeripheral paramter must be only one of the following values:
  662. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  663. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
  664. //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EEPROM0,
  665. //! \b SYSCTL_PERIPH_EPI0, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0,
  666. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  667. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  668. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  669. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  670. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  671. //! \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1,
  672. //! \b SYSCTL_PERIPH_I2C2, \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4,
  673. //! \b SYSCTL_PERIPH_I2C5, \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_LPC0,
  674. //! \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1,
  675. //! \b SYSCTL_PERIPH_QEI0, \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0,
  676. //! \b SYSCTL_PERIPH_SSI1, \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3,
  677. //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
  678. //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
  679. //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
  680. //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
  681. //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
  682. //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
  683. //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
  684. //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
  685. //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5.
  686. //!
  687. //! \note The ability to power off a peripheral varies based on the Stellaris
  688. //! part in use. Please consult the data sheet for the part you are using to
  689. //! determine if this feature is available.
  690. //!
  691. //! \return None.
  692. //
  693. //*****************************************************************************
  694. void
  695. SysCtlPeripheralPowerOff(unsigned long ulPeripheral)
  696. {
  697. //
  698. // Check the arguments.
  699. //
  700. ASSERT(SysCtlPeripheralValid(ulPeripheral));
  701. //
  702. // Map the peripheral identifier to the new style identifiers. If it is
  703. // already a new style identifier, this is a NOP.
  704. //
  705. ulPeripheral = SysCtlPeripheralMapToNew(ulPeripheral);
  706. //
  707. // Power off this peripheral.
  708. //
  709. HWREGBITW(SYSCTL_PCBASE + ((ulPeripheral & 0xff00) >> 8),
  710. ulPeripheral & 0xff) = 0;
  711. }
  712. //*****************************************************************************
  713. //
  714. //! Performs a software reset of a peripheral.
  715. //!
  716. //! \param ulPeripheral is the peripheral to reset.
  717. //!
  718. //! This function performs a software reset of the specified peripheral. An
  719. //! individual peripheral reset signal is asserted for a brief period and then
  720. //! deasserted, returning the internal state of the peripheral to its reset
  721. //! condition.
  722. //!
  723. //! The \e ulPeripheral parameter must be only one of the following values:
  724. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  725. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
  726. //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EEPROM0,
  727. //! \b SYSCTL_PERIPH_EPI0, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0,
  728. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  729. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  730. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  731. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  732. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  733. //! \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1,
  734. //! \b SYSCTL_PERIPH_I2C2, \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4,
  735. //! \b SYSCTL_PERIPH_I2C5, \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_LPC0,
  736. //! \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1,
  737. //! \b SYSCTL_PERIPH_QEI0, \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0,
  738. //! \b SYSCTL_PERIPH_SSI1, \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3,
  739. //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
  740. //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
  741. //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
  742. //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
  743. //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
  744. //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
  745. //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
  746. //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
  747. //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5.
  748. //!
  749. //! \return None.
  750. //
  751. //*****************************************************************************
  752. void
  753. SysCtlPeripheralReset(unsigned long ulPeripheral)
  754. {
  755. volatile unsigned long ulDelay;
  756. //
  757. // Check the arguments.
  758. //
  759. ASSERT(SysCtlPeripheralValid(ulPeripheral));
  760. //
  761. // See if the peripheral index is 15, indicating a peripheral that is
  762. // accessed via the SYSCTL_SRperiph registers.
  763. //
  764. if((ulPeripheral & 0xf0000000) == 0xf0000000)
  765. {
  766. //
  767. // Put the peripheral into the reset state.
  768. //
  769. HWREGBITW(SYSCTL_SRBASE + ((ulPeripheral & 0xff00) >> 8),
  770. ulPeripheral & 0xff) = 1;
  771. //
  772. // Delay for a little bit.
  773. //
  774. for(ulDelay = 0; ulDelay < 16; ulDelay++)
  775. {
  776. }
  777. //
  778. // Take the peripheral out of the reset state.
  779. //
  780. HWREGBITW(SYSCTL_SRBASE + ((ulPeripheral & 0xff00) >> 8),
  781. ulPeripheral & 0xff) = 0;
  782. }
  783. else
  784. {
  785. //
  786. // Put the peripheral into the reset state.
  787. //
  788. HWREG(g_pulSRCRRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) |=
  789. SYSCTL_PERIPH_MASK(ulPeripheral);
  790. //
  791. // Delay for a little bit.
  792. //
  793. for(ulDelay = 0; ulDelay < 16; ulDelay++)
  794. {
  795. }
  796. //
  797. // Take the peripheral out of the reset state.
  798. //
  799. HWREG(g_pulSRCRRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) &=
  800. ~SYSCTL_PERIPH_MASK(ulPeripheral);
  801. }
  802. }
  803. //*****************************************************************************
  804. //
  805. //! Enables a peripheral.
  806. //!
  807. //! \param ulPeripheral is the peripheral to enable.
  808. //!
  809. //! This function enables peripherals. At power-up, all peripherals
  810. //! are disabled; they must be enabled in order to operate or respond to
  811. //! register reads/writes.
  812. //!
  813. //! The \e ulPeripheral parameter must be only one of the following values:
  814. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  815. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
  816. //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EEPROM0,
  817. //! \b SYSCTL_PERIPH_EPI0, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0,
  818. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  819. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  820. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  821. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  822. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  823. //! \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1,
  824. //! \b SYSCTL_PERIPH_I2C2, \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4,
  825. //! \b SYSCTL_PERIPH_I2C5, \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_LPC0,
  826. //! \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1,
  827. //! \b SYSCTL_PERIPH_QEI0, \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0,
  828. //! \b SYSCTL_PERIPH_SSI1, \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3,
  829. //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
  830. //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
  831. //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
  832. //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
  833. //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
  834. //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
  835. //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
  836. //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
  837. //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5.
  838. //!
  839. //! \note It takes five clock cycles after the write to enable a peripheral
  840. //! before the the peripheral is actually enabled. During this time, attempts
  841. //! to access the peripheral result in a bus fault. Care should be taken
  842. //! to ensure that the peripheral is not accessed during this brief time
  843. //! period.
  844. //!
  845. //! \return None.
  846. //
  847. //*****************************************************************************
  848. void
  849. SysCtlPeripheralEnable(unsigned long ulPeripheral)
  850. {
  851. //
  852. // Check the arguments.
  853. //
  854. ASSERT(SysCtlPeripheralValid(ulPeripheral));
  855. //
  856. // See if the peripheral index is 15, indicating a peripheral that is
  857. // accessed via the SYSCTL_RCGCperiph registers.
  858. //
  859. if((ulPeripheral & 0xf0000000) == 0xf0000000)
  860. {
  861. //
  862. // Enable this peripheral.
  863. //
  864. HWREGBITW(SYSCTL_RCGCBASE + ((ulPeripheral & 0xff00) >> 8),
  865. ulPeripheral & 0xff) = 1;
  866. }
  867. else
  868. {
  869. //
  870. // Enable this peripheral.
  871. //
  872. HWREG(g_pulRCGCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) |=
  873. SYSCTL_PERIPH_MASK(ulPeripheral);
  874. }
  875. }
  876. //*****************************************************************************
  877. //
  878. //! Disables a peripheral.
  879. //!
  880. //! \param ulPeripheral is the peripheral to disable.
  881. //!
  882. //! This function disables peripherals are disabled with this function. Once
  883. //! disabled, they do not operate or respond to register reads/writes.
  884. //!
  885. //! The \e ulPeripheral parameter must be only one of the following values:
  886. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  887. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
  888. //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EEPROM0,
  889. //! \b SYSCTL_PERIPH_EPI0, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0,
  890. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  891. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  892. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  893. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  894. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  895. //! \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1,
  896. //! \b SYSCTL_PERIPH_I2C2, \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4,
  897. //! \b SYSCTL_PERIPH_I2C5, \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_LPC0,
  898. //! \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1,
  899. //! \b SYSCTL_PERIPH_QEI0, \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0,
  900. //! \b SYSCTL_PERIPH_SSI1, \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3,
  901. //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
  902. //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
  903. //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
  904. //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
  905. //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
  906. //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
  907. //! \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. SysCtlPeripheralDisable(unsigned long ulPeripheral)
  916. {
  917. //
  918. // Check the arguments.
  919. //
  920. ASSERT(SysCtlPeripheralValid(ulPeripheral));
  921. //
  922. // See if the peripheral index is 15, indicating a peripheral that is
  923. // accessed via the SYSCTL_RCGCperiph registers.
  924. //
  925. if((ulPeripheral & 0xf0000000) == 0xf0000000)
  926. {
  927. //
  928. // Disable this peripheral.
  929. //
  930. HWREGBITW(SYSCTL_RCGCBASE + ((ulPeripheral & 0xff00) >> 8),
  931. ulPeripheral & 0xff) = 0;
  932. }
  933. else
  934. {
  935. //
  936. // Disable this peripheral.
  937. //
  938. HWREG(g_pulRCGCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) &=
  939. ~SYSCTL_PERIPH_MASK(ulPeripheral);
  940. }
  941. }
  942. //*****************************************************************************
  943. //
  944. //! Enables a peripheral in sleep mode.
  945. //!
  946. //! \param ulPeripheral is the peripheral to enable in sleep mode.
  947. //!
  948. //! This function allows a peripheral to continue operating when the processor
  949. //! goes into sleep mode. Because the clocking configuration of the device
  950. //! does not change, any peripheral can safely continue operating while the
  951. //! processor is in sleep mode and can therefore wake the processor from sleep
  952. //! mode.
  953. //!
  954. //! Sleep mode clocking of peripherals must be enabled via
  955. //! SysCtlPeripheralClockGating(); if disabled, the peripheral sleep mode
  956. //! configuration is maintained but has no effect when sleep mode is entered.
  957. //!
  958. //! The \e ulPeripheral parameter must be only one of the following values:
  959. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  960. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
  961. //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EEPROM0,
  962. //! \b SYSCTL_PERIPH_EPI0, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0,
  963. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  964. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  965. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  966. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  967. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  968. //! \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1,
  969. //! \b SYSCTL_PERIPH_I2C2, \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4,
  970. //! \b SYSCTL_PERIPH_I2C5, \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_LPC0,
  971. //! \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1,
  972. //! \b SYSCTL_PERIPH_QEI0, \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0,
  973. //! \b SYSCTL_PERIPH_SSI1, \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3,
  974. //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
  975. //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
  976. //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
  977. //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
  978. //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
  979. //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
  980. //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
  981. //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
  982. //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5.
  983. //!
  984. //! \return None.
  985. //
  986. //*****************************************************************************
  987. void
  988. SysCtlPeripheralSleepEnable(unsigned long ulPeripheral)
  989. {
  990. //
  991. // Check the arguments.
  992. //
  993. ASSERT(SysCtlPeripheralValid(ulPeripheral));
  994. //
  995. // See if the peripheral index is 15, indicating a peripheral that is
  996. // accessed via the SYSCTL_SCGCperiph registers.
  997. //
  998. if((ulPeripheral & 0xf0000000) == 0xf0000000)
  999. {
  1000. //
  1001. // Enable this peripheral in sleep mode.
  1002. //
  1003. HWREGBITW(SYSCTL_SCGCBASE + ((ulPeripheral & 0xff00) >> 8),
  1004. ulPeripheral & 0xff) = 1;
  1005. }
  1006. else
  1007. {
  1008. //
  1009. // Enable this peripheral in sleep mode.
  1010. //
  1011. HWREG(g_pulSCGCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) |=
  1012. SYSCTL_PERIPH_MASK(ulPeripheral);
  1013. }
  1014. }
  1015. //*****************************************************************************
  1016. //
  1017. //! Disables a peripheral in sleep mode.
  1018. //!
  1019. //! \param ulPeripheral is the peripheral to disable in sleep mode.
  1020. //!
  1021. //! This function causes a peripheral to stop operating when the processor goes
  1022. //! into sleep mode. Disabling peripherals while in sleep mode helps to lower
  1023. //! the current draw of the device. If enabled (via SysCtlPeripheralEnable()),
  1024. //! the peripheral automatically resumes operation when the processor
  1025. //! leaves sleep mode, maintaining its entire state from before sleep mode was
  1026. //! entered.
  1027. //!
  1028. //! Sleep mode clocking of peripherals must be enabled via
  1029. //! SysCtlPeripheralClockGating(); if disabled, the peripheral sleep mode
  1030. //! configuration is maintained but has no effect when sleep mode is entered.
  1031. //!
  1032. //! The \e ulPeripheral parameter must be only one of the following values:
  1033. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  1034. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
  1035. //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EEPROM0,
  1036. //! \b SYSCTL_PERIPH_EPI0, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0,
  1037. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  1038. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  1039. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  1040. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  1041. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  1042. //! \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1,
  1043. //! \b SYSCTL_PERIPH_I2C2, \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4,
  1044. //! \b SYSCTL_PERIPH_I2C5, \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_LPC0,
  1045. //! \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1,
  1046. //! \b SYSCTL_PERIPH_QEI0, \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0,
  1047. //! \b SYSCTL_PERIPH_SSI1, \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3,
  1048. //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
  1049. //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
  1050. //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
  1051. //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
  1052. //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
  1053. //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
  1054. //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
  1055. //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
  1056. //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5.
  1057. //!
  1058. //! \return None.
  1059. //
  1060. //*****************************************************************************
  1061. void
  1062. SysCtlPeripheralSleepDisable(unsigned long ulPeripheral)
  1063. {
  1064. //
  1065. // Check the arguments.
  1066. //
  1067. ASSERT(SysCtlPeripheralValid(ulPeripheral));
  1068. //
  1069. // See if the peripheral index is 15, indicating a peripheral that is
  1070. // accessed via the SYSCTL_SCGCperiph registers.
  1071. //
  1072. if((ulPeripheral & 0xf0000000) == 0xf0000000)
  1073. {
  1074. //
  1075. // Disable this peripheral in sleep mode.
  1076. //
  1077. HWREGBITW(SYSCTL_SCGCBASE + ((ulPeripheral & 0xff00) >> 8),
  1078. ulPeripheral & 0xff) = 0;
  1079. }
  1080. else
  1081. {
  1082. //
  1083. // Disable this peripheral in sleep mode.
  1084. //
  1085. HWREG(g_pulSCGCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) &=
  1086. ~SYSCTL_PERIPH_MASK(ulPeripheral);
  1087. }
  1088. }
  1089. //*****************************************************************************
  1090. //
  1091. //! Enables a peripheral in deep-sleep mode.
  1092. //!
  1093. //! \param ulPeripheral is the peripheral to enable in deep-sleep mode.
  1094. //!
  1095. //! This function allows a peripheral to continue operating when the processor
  1096. //! goes into deep-sleep mode. Because the clocking configuration of the
  1097. //! device may change, not all peripherals can safely continue operating while
  1098. //! the processor is in sleep mode. Those that must run at a particular
  1099. //! frequency (such as a UART) do not work as expected if the clock changes.
  1100. //! It is the responsibility of the caller to make sensible choices.
  1101. //!
  1102. //! Deep-sleep mode clocking of peripherals must be enabled via
  1103. //! SysCtlPeripheralClockGating(); if disabled, the peripheral deep-sleep mode
  1104. //! configuration is maintained but has no effect when deep-sleep mode is
  1105. //! entered.
  1106. //!
  1107. //! The \e ulPeripheral parameter must be only one of the following values:
  1108. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  1109. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
  1110. //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EEPROM0,
  1111. //! \b SYSCTL_PERIPH_EPI0, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0,
  1112. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  1113. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  1114. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  1115. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  1116. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  1117. //! \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1,
  1118. //! \b SYSCTL_PERIPH_I2C2, \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4,
  1119. //! \b SYSCTL_PERIPH_I2C5, \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_LPC0,
  1120. //! \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1,
  1121. //! \b SYSCTL_PERIPH_QEI0, \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0,
  1122. //! \b SYSCTL_PERIPH_SSI1, \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3,
  1123. //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
  1124. //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
  1125. //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
  1126. //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
  1127. //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
  1128. //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
  1129. //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
  1130. //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
  1131. //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5.
  1132. //!
  1133. //! \return None.
  1134. //
  1135. //*****************************************************************************
  1136. void
  1137. SysCtlPeripheralDeepSleepEnable(unsigned long ulPeripheral)
  1138. {
  1139. //
  1140. // Check the arguments.
  1141. //
  1142. ASSERT(SysCtlPeripheralValid(ulPeripheral));
  1143. //
  1144. // See if the peripheral index is 15, indicating a peripheral that is
  1145. // accessed via the SYSCTL_DCGCperiph registers.
  1146. //
  1147. if((ulPeripheral & 0xf0000000) == 0xf0000000)
  1148. {
  1149. //
  1150. // Enable this peripheral in deep-sleep mode.
  1151. //
  1152. HWREGBITW(SYSCTL_DCGCBASE + ((ulPeripheral & 0xff00) >> 8),
  1153. ulPeripheral & 0xff) = 1;
  1154. }
  1155. else
  1156. {
  1157. //
  1158. // Enable this peripheral in deep-sleep mode.
  1159. //
  1160. HWREG(g_pulDCGCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) |=
  1161. SYSCTL_PERIPH_MASK(ulPeripheral);
  1162. }
  1163. }
  1164. //*****************************************************************************
  1165. //
  1166. //! Disables a peripheral in deep-sleep mode.
  1167. //!
  1168. //! \param ulPeripheral is the peripheral to disable in deep-sleep mode.
  1169. //!
  1170. //! This function causes a peripheral to stop operating when the processor goes
  1171. //! into deep-sleep mode. Disabling peripherals while in deep-sleep mode helps
  1172. //! to lower the current draw of the device, and can keep peripherals that
  1173. //! require a particular clock frequency from operating when the clock changes
  1174. //! as a result of entering deep-sleep mode. If enabled (via
  1175. //! SysCtlPeripheralEnable()), the peripheral automatically resumes
  1176. //! operation when the processor leaves deep-sleep mode, maintaining its entire
  1177. //! state from before deep-sleep mode was entered.
  1178. //!
  1179. //! Deep-sleep mode clocking of peripherals must be enabled via
  1180. //! SysCtlPeripheralClockGating(); if disabled, the peripheral deep-sleep mode
  1181. //! configuration is maintained but has no effect when deep-sleep mode is
  1182. //! entered.
  1183. //!
  1184. //! The \e ulPeripheral parameter must be only one of the following values:
  1185. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  1186. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
  1187. //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EEPROM0,
  1188. //! \b SYSCTL_PERIPH_EPI0, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0,
  1189. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  1190. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  1191. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  1192. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  1193. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  1194. //! \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1,
  1195. //! \b SYSCTL_PERIPH_I2C2, \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4,
  1196. //! \b SYSCTL_PERIPH_I2C5, \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_LPC0,
  1197. //! \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1,
  1198. //! \b SYSCTL_PERIPH_QEI0, \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0,
  1199. //! \b SYSCTL_PERIPH_SSI1, \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3,
  1200. //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
  1201. //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
  1202. //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
  1203. //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
  1204. //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
  1205. //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
  1206. //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
  1207. //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
  1208. //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5.
  1209. //!
  1210. //! \return None.
  1211. //
  1212. //*****************************************************************************
  1213. void
  1214. SysCtlPeripheralDeepSleepDisable(unsigned long ulPeripheral)
  1215. {
  1216. //
  1217. // Check the arguments.
  1218. //
  1219. ASSERT(SysCtlPeripheralValid(ulPeripheral));
  1220. //
  1221. // See if the peripheral index is 15, indicating a peripheral that is
  1222. // accessed via the SYSCTL_DCGCperiph registers.
  1223. //
  1224. if((ulPeripheral & 0xf0000000) == 0xf0000000)
  1225. {
  1226. //
  1227. // Disable this peripheral in deep-sleep mode.
  1228. //
  1229. HWREGBITW(SYSCTL_DCGCBASE + ((ulPeripheral & 0xff00) >> 8),
  1230. ulPeripheral & 0xff) = 0;
  1231. }
  1232. else
  1233. {
  1234. //
  1235. // Disable this peripheral in deep-sleep mode.
  1236. //
  1237. HWREG(g_pulDCGCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) &=
  1238. ~SYSCTL_PERIPH_MASK(ulPeripheral);
  1239. }
  1240. }
  1241. //*****************************************************************************
  1242. //
  1243. //! Controls peripheral clock gating in sleep and deep-sleep mode.
  1244. //!
  1245. //! \param bEnable is a boolean that is \b true if the sleep and deep-sleep
  1246. //! peripheral configuration should be used and \b false if not.
  1247. //!
  1248. //! This function controls how peripherals are clocked when the processor goes
  1249. //! into sleep or deep-sleep mode. By default, the peripherals are clocked the
  1250. //! same as in run mode; if peripheral clock gating is enabled, they are
  1251. //! clocked according to the configuration set by
  1252. //! SysCtlPeripheralSleepEnable(), SysCtlPeripheralSleepDisable(),
  1253. //! SysCtlPeripheralDeepSleepEnable(), and SysCtlPeripheralDeepSleepDisable().
  1254. //!
  1255. //! \return None.
  1256. //
  1257. //*****************************************************************************
  1258. void
  1259. SysCtlPeripheralClockGating(tBoolean bEnable)
  1260. {
  1261. //
  1262. // Enable peripheral clock gating as requested.
  1263. //
  1264. if(bEnable)
  1265. {
  1266. HWREG(SYSCTL_RCC) |= SYSCTL_RCC_ACG;
  1267. }
  1268. else
  1269. {
  1270. HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_ACG);
  1271. }
  1272. }
  1273. //*****************************************************************************
  1274. //
  1275. //! Registers an interrupt handler for the system control interrupt.
  1276. //!
  1277. //! \param pfnHandler is a pointer to the function to be called when the system
  1278. //! control interrupt occurs.
  1279. //!
  1280. //! This function registers the handler to be called when a system control
  1281. //! interrupt occurs. This function enables the global interrupt in the
  1282. //! interrupt controller; specific system control interrupts must be enabled
  1283. //! via SysCtlIntEnable(). It is the interrupt handler's responsibility to
  1284. //! clear the interrupt source via SysCtlIntClear().
  1285. //!
  1286. //! System control can generate interrupts when the PLL achieves lock, if the
  1287. //! internal LDO current limit is exceeded, if the internal oscillator fails,
  1288. //! if the main oscillator fails, if the internal LDO output voltage droops too
  1289. //! much, if the external voltage droops too much, or if the PLL fails.
  1290. //!
  1291. //! \sa IntRegister() for important information about registering interrupt
  1292. //! handlers.
  1293. //!
  1294. //! \note The events that cause system control interrupts vary based on the
  1295. //! Stellaris part in use. Please consult the data sheet for the part you are
  1296. //! using to determine which interrupt sources are available.
  1297. //!
  1298. //! \return None.
  1299. //
  1300. //*****************************************************************************
  1301. void
  1302. SysCtlIntRegister(void (*pfnHandler)(void))
  1303. {
  1304. //
  1305. // Register the interrupt handler, returning an error if an error occurs.
  1306. //
  1307. IntRegister(INT_SYSCTL, pfnHandler);
  1308. //
  1309. // Enable the system control interrupt.
  1310. //
  1311. IntEnable(INT_SYSCTL);
  1312. }
  1313. //*****************************************************************************
  1314. //
  1315. //! Unregisters the interrupt handler for the system control interrupt.
  1316. //!
  1317. //! This function unregisters the handler to be called when a system control
  1318. //! interrupt occurs. This function also masks off the interrupt in the
  1319. //! interrupt controller so that the interrupt handler no longer is called.
  1320. //!
  1321. //! \sa IntRegister() for important information about registering interrupt
  1322. //! handlers.
  1323. //!
  1324. //! \return None.
  1325. //
  1326. //*****************************************************************************
  1327. void
  1328. SysCtlIntUnregister(void)
  1329. {
  1330. //
  1331. // Disable the interrupt.
  1332. //
  1333. IntDisable(INT_SYSCTL);
  1334. //
  1335. // Unregister the interrupt handler.
  1336. //
  1337. IntUnregister(INT_SYSCTL);
  1338. }
  1339. //*****************************************************************************
  1340. //
  1341. //! Enables individual system control interrupt sources.
  1342. //!
  1343. //! \param ulInts is a bit mask of the interrupt sources to be enabled. Must
  1344. //! be a logical OR of \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_CUR_LIMIT,
  1345. //! \b SYSCTL_INT_IOSC_FAIL, \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_POR,
  1346. //! \b SYSCTL_INT_BOR, and/or \b SYSCTL_INT_PLL_FAIL.
  1347. //!
  1348. //! This function enables the indicated system control interrupt sources. Only
  1349. //! the sources that are enabled can be reflected to the processor interrupt;
  1350. //! disabled sources have no effect on the processor.
  1351. //!
  1352. //! \note The interrupt sources vary based on the Stellaris part in use.
  1353. //! Please consult the data sheet for the part you are using to determine
  1354. //! which interrupt sources are available.
  1355. //!
  1356. //! \return None.
  1357. //
  1358. //*****************************************************************************
  1359. void
  1360. SysCtlIntEnable(unsigned long ulInts)
  1361. {
  1362. //
  1363. // Enable the specified interrupts.
  1364. //
  1365. HWREG(SYSCTL_IMC) |= ulInts;
  1366. }
  1367. //*****************************************************************************
  1368. //
  1369. //! Disables individual system control interrupt sources.
  1370. //!
  1371. //! \param ulInts is a bit mask of the interrupt sources to be disabled. Must
  1372. //! be a logical OR of \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_CUR_LIMIT,
  1373. //! \b SYSCTL_INT_IOSC_FAIL, \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_POR,
  1374. //! \b SYSCTL_INT_BOR, and/or \b SYSCTL_INT_PLL_FAIL.
  1375. //!
  1376. //! This function disables the indicated system control interrupt sources.
  1377. //! Only the sources that are enabled can be reflected to the processor
  1378. //! interrupt; disabled sources have no effect on the processor.
  1379. //!
  1380. //! \note The interrupt sources vary based on the Stellaris part in use.
  1381. //! Please consult the data sheet for the part you are using to determine
  1382. //! which interrupt sources are available.
  1383. //!
  1384. //! \return None.
  1385. //
  1386. //*****************************************************************************
  1387. void
  1388. SysCtlIntDisable(unsigned long ulInts)
  1389. {
  1390. //
  1391. // Disable the specified interrupts.
  1392. //
  1393. HWREG(SYSCTL_IMC) &= ~(ulInts);
  1394. }
  1395. //*****************************************************************************
  1396. //
  1397. //! Clears system control interrupt sources.
  1398. //!
  1399. //! \param ulInts is a bit mask of the interrupt sources to be cleared. Must
  1400. //! be a logical OR of \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_CUR_LIMIT,
  1401. //! \b SYSCTL_INT_IOSC_FAIL, \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_POR,
  1402. //! \b SYSCTL_INT_BOR, and/or \b SYSCTL_INT_PLL_FAIL.
  1403. //!
  1404. //! The specified system control interrupt sources are cleared, so that they no
  1405. //! longer assert. This function must be called in the interrupt handler to
  1406. //! keep it from being called again immediately upon exit.
  1407. //!
  1408. //! \note Because there is a write buffer in the Cortex-M processor, it may
  1409. //! take several clock cycles before the interrupt source is actually cleared.
  1410. //! Therefore, it is recommended that the interrupt source be cleared early in
  1411. //! the interrupt handler (as opposed to the very last action) to avoid
  1412. //! returning from the interrupt handler before the interrupt source is
  1413. //! actually cleared. Failure to do so may result in the interrupt handler
  1414. //! being immediately reentered (because the interrupt controller still sees
  1415. //! the interrupt source asserted).
  1416. //!
  1417. //! \note The interrupt sources vary based on the Stellaris part in use.
  1418. //! Please consult the data sheet for the part you are using to determine
  1419. //! which interrupt sources are available.
  1420. //!
  1421. //! \return None.
  1422. //
  1423. //*****************************************************************************
  1424. void
  1425. SysCtlIntClear(unsigned long ulInts)
  1426. {
  1427. //
  1428. // Clear the requested interrupt sources.
  1429. //
  1430. HWREG(SYSCTL_MISC) = ulInts;
  1431. }
  1432. //*****************************************************************************
  1433. //
  1434. //! Gets the current interrupt status.
  1435. //!
  1436. //! \param bMasked is false if the raw interrupt status is required and true if
  1437. //! the masked interrupt status is required.
  1438. //!
  1439. //! This function returns the interrupt status for the system controller.
  1440. //! Either the raw interrupt status or the status of interrupts that are
  1441. //! allowed to reflect to the processor can be returned.
  1442. //!
  1443. //! \return The current interrupt status, enumerated as a bit field of
  1444. //! \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_CUR_LIMIT, \b SYSCTL_INT_IOSC_FAIL,
  1445. //! \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_POR, \b SYSCTL_INT_BOR, and
  1446. //! \b SYSCTL_INT_PLL_FAIL.
  1447. //!
  1448. //! \note The interrupt sources vary based on the Stellaris part in use.
  1449. //! Please consult the data sheet for the part you are using to determine
  1450. //! which interrupt sources are available.
  1451. //
  1452. //*****************************************************************************
  1453. unsigned long
  1454. SysCtlIntStatus(tBoolean bMasked)
  1455. {
  1456. //
  1457. // Return either the interrupt status or the raw interrupt status as
  1458. // requested.
  1459. //
  1460. if(bMasked)
  1461. {
  1462. return(HWREG(SYSCTL_MISC));
  1463. }
  1464. else
  1465. {
  1466. return(HWREG(SYSCTL_RIS));
  1467. }
  1468. }
  1469. //*****************************************************************************
  1470. //
  1471. //! Sets the output voltage of the LDO.
  1472. //!
  1473. //! \param ulVoltage is the required output voltage from the LDO. Must be one
  1474. //! of \b SYSCTL_LDO_2_25V, \b SYSCTL_LDO_2_30V, \b SYSCTL_LDO_2_35V,
  1475. //! \b SYSCTL_LDO_2_40V, \b SYSCTL_LDO_2_45V, \b SYSCTL_LDO_2_50V,
  1476. //! \b SYSCTL_LDO_2_55V, \b SYSCTL_LDO_2_60V, \b SYSCTL_LDO_2_65V,
  1477. //! \b SYSCTL_LDO_2_70V, or \b SYSCTL_LDO_2_75V.
  1478. //!
  1479. //! This function sets the output voltage of the LDO.
  1480. //!
  1481. //! \note The default LDO voltage and the adjustment range varies with the
  1482. //! Stellaris part in use. Please consult the datasheet for the part you are
  1483. //! using to determine the default voltage and range available.
  1484. //!
  1485. //! \return None.
  1486. //
  1487. //*****************************************************************************
  1488. void
  1489. SysCtlLDOSet(unsigned long ulVoltage)
  1490. {
  1491. //
  1492. // Check the arguments.
  1493. //
  1494. ASSERT((ulVoltage == SYSCTL_LDO_2_25V) ||
  1495. (ulVoltage == SYSCTL_LDO_2_30V) ||
  1496. (ulVoltage == SYSCTL_LDO_2_35V) ||
  1497. (ulVoltage == SYSCTL_LDO_2_40V) ||
  1498. (ulVoltage == SYSCTL_LDO_2_45V) ||
  1499. (ulVoltage == SYSCTL_LDO_2_50V) ||
  1500. (ulVoltage == SYSCTL_LDO_2_55V) ||
  1501. (ulVoltage == SYSCTL_LDO_2_60V) ||
  1502. (ulVoltage == SYSCTL_LDO_2_65V) ||
  1503. (ulVoltage == SYSCTL_LDO_2_70V) ||
  1504. (ulVoltage == SYSCTL_LDO_2_75V));
  1505. //
  1506. // Set the LDO voltage to the requested value.
  1507. //
  1508. HWREG(SYSCTL_LDOPCTL) = ulVoltage;
  1509. }
  1510. //*****************************************************************************
  1511. //
  1512. //! Gets the output voltage of the LDO.
  1513. //!
  1514. //! This function determines the output voltage of the LDO, as specified by the
  1515. //! control register.
  1516. //!
  1517. //! \return Returns the current voltage of the LDO; is one of
  1518. //! \b SYSCTL_LDO_2_25V, \b SYSCTL_LDO_2_30V, \b SYSCTL_LDO_2_35V,
  1519. //! \b SYSCTL_LDO_2_40V, \b SYSCTL_LDO_2_45V, \b SYSCTL_LDO_2_50V,
  1520. //! \b SYSCTL_LDO_2_55V, \b SYSCTL_LDO_2_60V, \b SYSCTL_LDO_2_65V,
  1521. //! \b SYSCTL_LDO_2_70V, or \b SYSCTL_LDO_2_75V.
  1522. //
  1523. //*****************************************************************************
  1524. unsigned long
  1525. SysCtlLDOGet(void)
  1526. {
  1527. //
  1528. // Return the LDO voltage setting.
  1529. //
  1530. return(HWREG(SYSCTL_LDOPCTL));
  1531. }
  1532. //*****************************************************************************
  1533. //
  1534. //! Configures the LDO failure control.
  1535. //!
  1536. //! \param ulConfig is the required LDO failure control setting; can be either
  1537. //! \b SYSCTL_LDOCFG_ARST or \b SYSCTL_LDOCFG_NORST.
  1538. //!
  1539. //! This function allows the LDO to be configured to cause a processor reset
  1540. //! when the output voltage becomes unregulated.
  1541. //!
  1542. //! The LDO failure control is only available on Sandstorm-class devices.
  1543. //!
  1544. //! \return None.
  1545. //
  1546. //*****************************************************************************
  1547. void
  1548. SysCtlLDOConfigSet(unsigned long ulConfig)
  1549. {
  1550. //
  1551. // Check the arguments.
  1552. //
  1553. ASSERT((ulConfig == SYSCTL_LDOCFG_ARST) ||
  1554. (ulConfig == SYSCTL_LDOCFG_NORST));
  1555. //
  1556. // Set the reset control as requested.
  1557. //
  1558. HWREG(SYSCTL_LDOARST) = ulConfig;
  1559. }
  1560. //*****************************************************************************
  1561. //
  1562. //! Resets the device.
  1563. //!
  1564. //! This function performs a software reset of the entire device. The
  1565. //! processor and all peripherals are reset and all device registers are
  1566. //! returned to their default values (with the exception of the reset cause
  1567. //! register, which maintains its current value but has the software reset
  1568. //! bit set as well).
  1569. //!
  1570. //! \return This function does not return.
  1571. //
  1572. //*****************************************************************************
  1573. void
  1574. SysCtlReset(void)
  1575. {
  1576. //
  1577. // Perform a software reset request. This request causes the device to
  1578. // reset, no further code is executed.
  1579. //
  1580. HWREG(NVIC_APINT) = NVIC_APINT_VECTKEY | NVIC_APINT_SYSRESETREQ;
  1581. //
  1582. // The device should have reset, so this should never be reached. Just in
  1583. // case, loop forever.
  1584. //
  1585. while(1)
  1586. {
  1587. }
  1588. }
  1589. //*****************************************************************************
  1590. //
  1591. //! Puts the processor into sleep mode.
  1592. //!
  1593. //! This function places the processor into sleep mode; it does not return
  1594. //! until the processor returns to run mode. The peripherals that are enabled
  1595. //! via SysCtlPeripheralSleepEnable() continue to operate and can wake up the
  1596. //! processor (if automatic clock gating is enabled with
  1597. //! SysCtlPeripheralClockGating(), otherwise all peripherals continue to
  1598. //! operate).
  1599. //!
  1600. //! \return None.
  1601. //
  1602. //*****************************************************************************
  1603. void
  1604. SysCtlSleep(void)
  1605. {
  1606. //
  1607. // Wait for an interrupt.
  1608. //
  1609. CPUwfi();
  1610. }
  1611. //*****************************************************************************
  1612. //
  1613. //! Puts the processor into deep-sleep mode.
  1614. //!
  1615. //! This function places the processor into deep-sleep mode; it does not return
  1616. //! until the processor returns to run mode. The peripherals that are enabled
  1617. //! via SysCtlPeripheralDeepSleepEnable() continue to operate and can wake up
  1618. //! the processor (if automatic clock gating is enabled with
  1619. //! SysCtlPeripheralClockGating(), otherwise all peripherals continue to
  1620. //! operate).
  1621. //!
  1622. //! \return None.
  1623. //
  1624. //*****************************************************************************
  1625. void
  1626. SysCtlDeepSleep(void)
  1627. {
  1628. //
  1629. // Enable deep-sleep.
  1630. //
  1631. HWREG(NVIC_SYS_CTRL) |= NVIC_SYS_CTRL_SLEEPDEEP;
  1632. //
  1633. // Wait for an interrupt.
  1634. //
  1635. CPUwfi();
  1636. //
  1637. // Disable deep-sleep so that a future sleep will work correctly.
  1638. //
  1639. HWREG(NVIC_SYS_CTRL) &= ~(NVIC_SYS_CTRL_SLEEPDEEP);
  1640. }
  1641. //*****************************************************************************
  1642. //
  1643. //! Gets the reason for a reset.
  1644. //!
  1645. //! This function returns the reason(s) for a reset. Because the reset
  1646. //! reasons are sticky until either cleared by software or an external reset
  1647. //! (for Sandstorm-class devices) or a power-on reset (for all other classes),
  1648. //! multiple reset reasons may be returned if multiple resets have occurred.
  1649. //! The reset reason is a logical OR of \b SYSCTL_CAUSE_LDO,
  1650. //! \b SYSCTL_CAUSE_SW, \b SYSCTL_CAUSE_WDOG, \b SYSCTL_CAUSE_BOR,
  1651. //! \b SYSCTL_CAUSE_POR, and/or \b SYSCTL_CAUSE_EXT.
  1652. //!
  1653. //! \return Returns the reason(s) for a reset.
  1654. //
  1655. //*****************************************************************************
  1656. unsigned long
  1657. SysCtlResetCauseGet(void)
  1658. {
  1659. //
  1660. // Return the reset reasons.
  1661. //
  1662. return(HWREG(SYSCTL_RESC));
  1663. }
  1664. //*****************************************************************************
  1665. //
  1666. //! Clears reset reasons.
  1667. //!
  1668. //! \param ulCauses are the reset causes to be cleared; must be a logical OR of
  1669. //! \b SYSCTL_CAUSE_LDO, \b SYSCTL_CAUSE_SW, \b SYSCTL_CAUSE_WDOG,
  1670. //! \b SYSCTL_CAUSE_BOR, \b SYSCTL_CAUSE_POR, and/or \b SYSCTL_CAUSE_EXT.
  1671. //!
  1672. //! This function clears the specified sticky reset reasons. Once cleared,
  1673. //! another reset for the same reason can be detected, and a reset for a
  1674. //! different reason can be distinguished (instead of having two reset causes
  1675. //! set). If the reset reason is used by an application, all reset causes
  1676. //! should be cleared after they are retrieved with SysCtlResetCauseGet().
  1677. //!
  1678. //! \return None.
  1679. //
  1680. //*****************************************************************************
  1681. void
  1682. SysCtlResetCauseClear(unsigned long ulCauses)
  1683. {
  1684. //
  1685. // Clear the given reset reasons.
  1686. //
  1687. HWREG(SYSCTL_RESC) &= ~(ulCauses);
  1688. }
  1689. //*****************************************************************************
  1690. //
  1691. //! Configures the brown-out control.
  1692. //!
  1693. //! \param ulConfig is the desired configuration of the brown-out control.
  1694. //! Must be the logical OR of \b SYSCTL_BOR_RESET and/or
  1695. //! \b SYSCTL_BOR_RESAMPLE.
  1696. //! \param ulDelay is the number of internal oscillator cycles to wait before
  1697. //! resampling an asserted brown-out signal. This value only has meaning when
  1698. //! \b SYSCTL_BOR_RESAMPLE is set and must be less than 8192.
  1699. //!
  1700. //! This function configures how the brown-out control operates. It can detect
  1701. //! a brown-out by looking at only the brown-out output, or it can wait for it
  1702. //! to be active for two consecutive samples separated by a configurable time.
  1703. //! When it detects a brown-out condition, it can either reset the device or
  1704. //! generate a processor interrupt.
  1705. //!
  1706. //! \note The availability of the resample feature is only available on
  1707. //! Sandstorm-class devices. Please consult the datasheet for the part you
  1708. //! are using to determine whether this feature is available.
  1709. //!
  1710. //! \return None.
  1711. //
  1712. //*****************************************************************************
  1713. void
  1714. SysCtlBrownOutConfigSet(unsigned long ulConfig, unsigned long ulDelay)
  1715. {
  1716. //
  1717. // Check the arguments.
  1718. //
  1719. ASSERT(!(ulConfig & ~(SYSCTL_BOR_RESET | SYSCTL_BOR_RESAMPLE)));
  1720. ASSERT(ulDelay < 8192);
  1721. //
  1722. // Configure the brown-out reset control.
  1723. //
  1724. HWREG(SYSCTL_PBORCTL) = (ulDelay << SYSCTL_PBORCTL_BORTIM_S) | ulConfig;
  1725. }
  1726. //*****************************************************************************
  1727. //
  1728. //! Provides a small delay.
  1729. //!
  1730. //! \param ulCount is the number of delay loop iterations to perform.
  1731. //!
  1732. //! This function provides a means of generating a constant length delay. It
  1733. //! is written in assembly to keep the delay consistent across tool chains,
  1734. //! avoiding the need to tune the delay based on the tool chain in use.
  1735. //!
  1736. //! The loop takes 3 cycles/loop.
  1737. //!
  1738. //! \return None.
  1739. //
  1740. //*****************************************************************************
  1741. #if defined(ewarm) || defined(DOXYGEN)
  1742. void
  1743. SysCtlDelay(unsigned long ulCount)
  1744. {
  1745. __asm(" subs r0, #1\n"
  1746. " bne.n SysCtlDelay\n"
  1747. " bx lr");
  1748. }
  1749. #endif
  1750. #if defined(codered) || defined(gcc) || defined(sourcerygxx)
  1751. void __attribute__((naked))
  1752. SysCtlDelay(unsigned long ulCount)
  1753. {
  1754. __asm(" subs r0, #1\n"
  1755. " bne SysCtlDelay\n"
  1756. " bx lr");
  1757. }
  1758. #endif
  1759. #if defined(rvmdk) || defined(__ARMCC_VERSION)
  1760. __asm void
  1761. SysCtlDelay(unsigned long ulCount)
  1762. {
  1763. subs r0, #1;
  1764. bne SysCtlDelay;
  1765. bx lr;
  1766. }
  1767. #endif
  1768. //
  1769. // For CCS implement this function in pure assembly. This prevents the TI
  1770. // compiler from doing funny things with the optimizer.
  1771. //
  1772. #if defined(ccs)
  1773. __asm(" .sect \".text:SysCtlDelay\"\n"
  1774. " .clink\n"
  1775. " .thumbfunc SysCtlDelay\n"
  1776. " .thumb\n"
  1777. " .global SysCtlDelay\n"
  1778. "SysCtlDelay:\n"
  1779. " subs r0, #1\n"
  1780. " bne.n SysCtlDelay\n"
  1781. " bx lr\n");
  1782. #endif
  1783. //*****************************************************************************
  1784. //
  1785. //! Sets the configuration of the main oscillator (MOSC) control.
  1786. //!
  1787. //! \param ulConfig is the required configuration of the MOSC control.
  1788. //!
  1789. //! This function configures the control of the main oscillator. The
  1790. //! \e ulConfig is specified as follows:
  1791. //!
  1792. //! - \b SYSCTL_MOSC_VALIDATE enables the MOSC verification circuit that
  1793. //! detects a failure of the main oscillator (such as a loss of the clock).
  1794. //! - \b SYSCTL_MOSC_INTERRUPT indicates that a MOSC failure should generate an
  1795. //! interrupt instead of resetting the processor.
  1796. //! - \b SYSCTL_MOSC_NO_XTAL indicates that there is no crystal connected to
  1797. //! the OSC0/OSC1 pins, allowing power consumption to be reduced.
  1798. //!
  1799. //! \note The availability of MOSC control varies based on the Stellaris part
  1800. //! in use. Please consult the data sheet for the part you are using to
  1801. //! determine whether this support is available. In addition, the capability
  1802. //! of MOSC control varies based on the Stellaris part in use.
  1803. //!
  1804. //! \return None.
  1805. //
  1806. //*****************************************************************************
  1807. void
  1808. SysCtlMOSCConfigSet(unsigned long ulConfig)
  1809. {
  1810. //
  1811. // Configure the MOSC control.
  1812. //
  1813. HWREG(SYSCTL_MOSCCTL) = ulConfig;
  1814. }
  1815. //*****************************************************************************
  1816. //
  1817. //! Calibrates the precision internal oscillator.
  1818. //!
  1819. //! \param ulType is the type of calibration to perform.
  1820. //!
  1821. //! This function performs a calibration of the PIOSC. There are three types
  1822. //! of calibration available; the desired calibration type as specified in
  1823. //! \e ulType is one of:
  1824. //!
  1825. //! - \b SYSCTL_PIOSC_CAL_AUTO to perform automatic calibration using the
  1826. //! 32-kHz clock from the hibernate module as a reference. This type is
  1827. //! only possible on parts that have a hibernate module, and then only if
  1828. //! it is enabled and the hibernate module's RTC is also enabled.
  1829. //!
  1830. //! - \b SYSCTL_PIOSC_CAL_FACT to reset the PIOSC calibration to the factory
  1831. //! provided calibration.
  1832. //!
  1833. //! - \b SYSCTL_PIOSC_CAL_USER to set the PIOSC calibration to a user-supplied
  1834. //! value. The value to be used is ORed into the lower 7-bits of this value,
  1835. //! with 0x40 being the ``nominal'' value (in other words, if everything were
  1836. //! perfect, 0x40 provides exactly 16 MHz). Values larger than 0x40
  1837. //! slow down PIOSC, and values smaller than 0x40 speed up PIOSC.
  1838. //!
  1839. //! \return None.
  1840. //
  1841. //*****************************************************************************
  1842. unsigned long
  1843. SysCtlPIOSCCalibrate(unsigned long ulType)
  1844. {
  1845. //
  1846. // Perform the requested calibration. If performing user calibration, the
  1847. // UTEN bit must be set with one write, then the UT field in a second
  1848. // write, and the UPDATE bit in a final write. For other calibration
  1849. // types, a single write to set UPDATE or CAL is all that is required.
  1850. //
  1851. if(ulType & (SYSCTL_PIOSCCAL_UTEN | SYSCTL_PIOSCCAL_UPDATE))
  1852. {
  1853. HWREG(SYSCTL_PIOSCCAL) = ulType & SYSCTL_PIOSCCAL_UTEN;
  1854. HWREG(SYSCTL_PIOSCCAL) =
  1855. ulType & (SYSCTL_PIOSCCAL_UTEN | SYSCTL_PIOSCCAL_UT_M);
  1856. }
  1857. HWREG(SYSCTL_PIOSCCAL) = ulType;
  1858. //
  1859. // See if an automatic calibration was requested.
  1860. //
  1861. if(ulType & SYSCTL_PIOSCCAL_CAL)
  1862. {
  1863. //
  1864. // Wait for the automatic calibration to complete.
  1865. //
  1866. while((HWREG(SYSCTL_PIOSCSTAT) & SYSCTL_PIOSCSTAT_CR_M) == 0)
  1867. {
  1868. }
  1869. //
  1870. // If the automatic calibration failed, return an error.
  1871. //
  1872. if((HWREG(SYSCTL_PIOSCSTAT) & SYSCTL_PIOSCSTAT_CR_M) !=
  1873. SYSCTL_PIOSCSTAT_CRPASS)
  1874. {
  1875. return(0);
  1876. }
  1877. }
  1878. //
  1879. // The calibration was successful.
  1880. //
  1881. return(1);
  1882. }
  1883. //*****************************************************************************
  1884. //
  1885. //! Sets the clocking of the device.
  1886. //!
  1887. //! \param ulConfig is the required configuration of the device clocking.
  1888. //!
  1889. //! This function configures the clocking of the device. The input crystal
  1890. //! frequency, oscillator to be used, use of the PLL, and the system clock
  1891. //! divider are all configured with this function.
  1892. //!
  1893. //! The \e ulConfig parameter is the logical OR of several different values,
  1894. //! many of which are grouped into sets where only one can be chosen.
  1895. //!
  1896. //! The system clock divider is chosen with one of the following values:
  1897. //! \b SYSCTL_SYSDIV_1, \b SYSCTL_SYSDIV_2, \b SYSCTL_SYSDIV_3, ...
  1898. //! \b SYSCTL_SYSDIV_64. Only \b SYSCTL_SYSDIV_1 through \b SYSCTL_SYSDIV_16
  1899. //! are valid on Sandstorm-class devices. Half-dividers, such as
  1900. //! \b SYSCTL_SYSDIV_2_5 and \b SYSCTL_SYSDIV_3_5. are available on Tempest-,
  1901. //! Firestorm-, and Blizzard-class devices.
  1902. //!
  1903. //! The use of the PLL is chosen with either \b SYSCTL_USE_PLL or
  1904. //! \b SYSCTL_USE_OSC.
  1905. //!
  1906. //! The external crystal frequency is chosen with one of the following values:
  1907. //! \b SYSCTL_XTAL_1MHZ, \b SYSCTL_XTAL_1_84MHZ, \b SYSCTL_XTAL_2MHZ,
  1908. //! \b SYSCTL_XTAL_2_45MHZ, \b SYSCTL_XTAL_3_57MHZ, \b SYSCTL_XTAL_3_68MHZ,
  1909. //! \b SYSCTL_XTAL_4MHZ, \b SYSCTL_XTAL_4_09MHZ, \b SYSCTL_XTAL_4_91MHZ,
  1910. //! \b SYSCTL_XTAL_5MHZ, \b SYSCTL_XTAL_5_12MHZ, \b SYSCTL_XTAL_6MHZ,
  1911. //! \b SYSCTL_XTAL_6_14MHZ, \b SYSCTL_XTAL_7_37MHZ, \b SYSCTL_XTAL_8MHZ,
  1912. //! \b SYSCTL_XTAL_8_19MHZ, \b SYSCTL_XTAL_10MHZ, \b SYSCTL_XTAL_12MHZ,
  1913. //! \b SYSCTL_XTAL_12_2MHZ, \b SYSCTL_XTAL_13_5MHZ, \b SYSCTL_XTAL_14_3MHZ,
  1914. //! \b SYSCTL_XTAL_16MHZ, \b SYSCTL_XTAL_16_3MHZ, \b SYSCTL_XTAL_18MHZ,
  1915. //! \b SYSCTL_XTAL_20MHZ, \b SYSCTL_XTAL_24MHZ, or \b SYSCTL_XTAL_25MHz.
  1916. //! Values below \b SYSCTL_XTAL_3_57MHZ are not valid when the PLL is in
  1917. //! operation on Sandstorm-, Fury-, Dustdevil-, Tempest-, and Firestorm-class.
  1918. //! devices. Values below \b SYSCTL_XTAL_5MHZ are not valid when the PLL is in
  1919. //! operation on Blizzard-class devices. Values below \b SYSCTL_XTAL_4MHZ
  1920. //! are never valid on Blizzard-class devices. On Sandstorm- and Fury-class
  1921. //! devices, values above \b SYSCTL_XTAL_8_19MHZ are not valid. On Dustdevil-,
  1922. //! Tempest-, and Firestorm-class devices, values above \b SYSCTL_XTAL_16_3MHZ
  1923. //! are not valid.
  1924. //!
  1925. //! The oscillator source is chosen with one of the following values:
  1926. //! \b SYSCTL_OSC_MAIN, \b SYSCTL_OSC_INT, \b SYSCTL_OSC_INT4,
  1927. //! \b SYSCTL_OSC_INT30, or \b SYSCTL_OSC_EXT32. On Sandstorm-class devices,
  1928. //! \b SYSCTL_OSC_INT30 and \b SYSCTL_OSC_EXT32 are not valid.
  1929. //! \b SYSCTL_OSC_EXT32 is only available on devices with the hibernate module,
  1930. //! and then only when the hibernate module has been enabled.
  1931. //!
  1932. //! The internal and main oscillators are disabled with the
  1933. //! \b SYSCTL_INT_OSC_DIS and \b SYSCTL_MAIN_OSC_DIS flags, respectively.
  1934. //! The external oscillator must be enabled in order to use an external clock
  1935. //! source. Note that attempts to disable the oscillator used to clock the
  1936. //! device is prevented by the hardware.
  1937. //!
  1938. //! To clock the system from an external source (such as an external crystal
  1939. //! oscillator), use \b SYSCTL_USE_OSC \b | \b SYSCTL_OSC_MAIN. To clock the
  1940. //! system from the main oscillator, use \b SYSCTL_USE_OSC \b |
  1941. //! \b SYSCTL_OSC_MAIN. To clock the system from the PLL, use
  1942. //! \b SYSCTL_USE_PLL \b | \b SYSCTL_OSC_MAIN, and select the appropriate
  1943. //! crystal with one of the \b SYSCTL_XTAL_xxx values.
  1944. //!
  1945. //! \note If selecting the PLL as the system clock source (that is, via
  1946. //! \b SYSCTL_USE_PLL), this function polls the PLL lock interrupt to
  1947. //! determine when the PLL has locked. If an interrupt handler for the
  1948. //! system control interrupt is in place, and it responds to and clears the
  1949. //! PLL lock interrupt, this function delays until its timeout has occurred
  1950. //! instead of completing as soon as PLL lock is achieved.
  1951. //!
  1952. //! \return None.
  1953. //
  1954. //*****************************************************************************
  1955. void
  1956. SysCtlClockSet(unsigned long ulConfig)
  1957. {
  1958. unsigned long ulDelay, ulRCC, ulRCC2;
  1959. //
  1960. // See if this is a Sandstorm-class device and clocking features from newer
  1961. // devices were requested.
  1962. //
  1963. if(CLASS_IS_SANDSTORM && (ulConfig & SYSCTL_RCC2_USERCC2))
  1964. {
  1965. //
  1966. // Return without changing the clocking because the requested
  1967. // configuration can not be achieved.
  1968. //
  1969. return;
  1970. }
  1971. //
  1972. // Get the current value of the RCC and RCC2 registers. If using a
  1973. // Sandstorm-class device, the RCC2 register reads back as zero and the
  1974. // writes to it from within this function are ignored.
  1975. //
  1976. ulRCC = HWREG(SYSCTL_RCC);
  1977. ulRCC2 = HWREG(SYSCTL_RCC2);
  1978. //
  1979. // Bypass the PLL and system clock dividers for now.
  1980. //
  1981. ulRCC |= SYSCTL_RCC_BYPASS;
  1982. ulRCC &= ~(SYSCTL_RCC_USESYSDIV);
  1983. ulRCC2 |= SYSCTL_RCC2_BYPASS2;
  1984. //
  1985. // Write the new RCC value.
  1986. //
  1987. HWREG(SYSCTL_RCC) = ulRCC;
  1988. HWREG(SYSCTL_RCC2) = ulRCC2;
  1989. //
  1990. // See if either oscillator needs to be enabled.
  1991. //
  1992. if(((ulRCC & SYSCTL_RCC_IOSCDIS) && !(ulConfig & SYSCTL_RCC_IOSCDIS)) ||
  1993. ((ulRCC & SYSCTL_RCC_MOSCDIS) && !(ulConfig & SYSCTL_RCC_MOSCDIS)))
  1994. {
  1995. //
  1996. // Make sure that the required oscillators are enabled. For now, the
  1997. // previously enabled oscillators must be enabled along with the newly
  1998. // requested oscillators.
  1999. //
  2000. ulRCC &= (~(SYSCTL_RCC_IOSCDIS | SYSCTL_RCC_MOSCDIS) |
  2001. (ulConfig & (SYSCTL_RCC_IOSCDIS | SYSCTL_RCC_MOSCDIS)));
  2002. //
  2003. // Write the new RCC value.
  2004. //
  2005. HWREG(SYSCTL_RCC) = ulRCC;
  2006. //
  2007. // Wait for a bit, giving the oscillator time to stabilize. The number
  2008. // of iterations is adjusted based on the current clock source; a
  2009. // smaller number of iterations is required for slower clock rates.
  2010. //
  2011. if(((ulRCC2 & SYSCTL_RCC2_USERCC2) &&
  2012. (((ulRCC2 & SYSCTL_RCC2_OSCSRC2_M) == SYSCTL_RCC2_OSCSRC2_30) ||
  2013. ((ulRCC2 & SYSCTL_RCC2_OSCSRC2_M) == SYSCTL_RCC2_OSCSRC2_32))) ||
  2014. (!(ulRCC2 & SYSCTL_RCC2_USERCC2) &&
  2015. ((ulRCC & SYSCTL_RCC_OSCSRC_M) == SYSCTL_RCC_OSCSRC_30)))
  2016. {
  2017. //
  2018. // Delay for 4096 iterations.
  2019. //
  2020. SysCtlDelay(4096);
  2021. }
  2022. else
  2023. {
  2024. //
  2025. // Delay for 524,288 iterations.
  2026. //
  2027. SysCtlDelay(524288);
  2028. }
  2029. }
  2030. //
  2031. // Set the new crystal value and oscillator source. Because the OSCSRC2
  2032. // field in RCC2 overlaps the XTAL field in RCC, the OSCSRC field has a
  2033. // special encoding within ulConfig to avoid the overlap.
  2034. //
  2035. ulRCC &= ~(SYSCTL_RCC_XTAL_M | SYSCTL_RCC_OSCSRC_M);
  2036. ulRCC |= ulConfig & (SYSCTL_RCC_XTAL_M | SYSCTL_RCC_OSCSRC_M);
  2037. ulRCC2 &= ~(SYSCTL_RCC2_USERCC2 | SYSCTL_RCC2_OSCSRC2_M);
  2038. ulRCC2 |= ulConfig & (SYSCTL_RCC2_USERCC2 | SYSCTL_RCC_OSCSRC_M);
  2039. ulRCC2 |= (ulConfig & 0x00000008) << 3;
  2040. //
  2041. // Write the new RCC value.
  2042. //
  2043. HWREG(SYSCTL_RCC) = ulRCC;
  2044. HWREG(SYSCTL_RCC2) = ulRCC2;
  2045. //
  2046. // Wait for a bit so that new crystal value and oscillator source can take
  2047. // effect.
  2048. //
  2049. SysCtlDelay(16);
  2050. //
  2051. // Set the PLL configuration.
  2052. //
  2053. ulRCC &= ~(SYSCTL_RCC_PWRDN | SYSCTL_RCC_OEN);
  2054. ulRCC |= ulConfig & (SYSCTL_RCC_PWRDN | SYSCTL_RCC_OEN);
  2055. ulRCC2 &= ~(SYSCTL_RCC2_PWRDN2);
  2056. ulRCC2 |= ulConfig & SYSCTL_RCC2_PWRDN2;
  2057. //
  2058. // Clear the PLL lock interrupt.
  2059. //
  2060. HWREG(SYSCTL_MISC) = SYSCTL_INT_PLL_LOCK;
  2061. //
  2062. // Write the new RCC value.
  2063. //
  2064. if(ulRCC2 & SYSCTL_RCC2_USERCC2)
  2065. {
  2066. HWREG(SYSCTL_RCC2) = ulRCC2;
  2067. HWREG(SYSCTL_RCC) = ulRCC;
  2068. }
  2069. else
  2070. {
  2071. HWREG(SYSCTL_RCC) = ulRCC;
  2072. HWREG(SYSCTL_RCC2) = ulRCC2;
  2073. }
  2074. //
  2075. // Set the requested system divider and disable the appropriate
  2076. // oscillators. This value is not written immediately.
  2077. //
  2078. ulRCC &= ~(SYSCTL_RCC_SYSDIV_M | SYSCTL_RCC_USESYSDIV |
  2079. SYSCTL_RCC_IOSCDIS | SYSCTL_RCC_MOSCDIS);
  2080. ulRCC |= ulConfig & (SYSCTL_RCC_SYSDIV_M | SYSCTL_RCC_USESYSDIV |
  2081. SYSCTL_RCC_IOSCDIS | SYSCTL_RCC_MOSCDIS);
  2082. ulRCC2 &= ~(SYSCTL_RCC2_SYSDIV2_M);
  2083. ulRCC2 |= ulConfig & SYSCTL_RCC2_SYSDIV2_M;
  2084. if(ulConfig & SYSCTL_RCC2_DIV400)
  2085. {
  2086. ulRCC |= SYSCTL_RCC_USESYSDIV;
  2087. ulRCC2 &= ~(SYSCTL_RCC_USESYSDIV);
  2088. ulRCC2 |= ulConfig & (SYSCTL_RCC2_DIV400 | SYSCTL_RCC2_SYSDIV2LSB);
  2089. }
  2090. else
  2091. {
  2092. ulRCC2 &= ~(SYSCTL_RCC2_DIV400);
  2093. }
  2094. //
  2095. // See if the PLL output is being used to clock the system.
  2096. //
  2097. if(!(ulConfig & SYSCTL_RCC_BYPASS))
  2098. {
  2099. //
  2100. // Wait until the PLL has locked.
  2101. //
  2102. for(ulDelay = 32768; ulDelay > 0; ulDelay--)
  2103. {
  2104. if(HWREG(SYSCTL_RIS) & SYSCTL_INT_PLL_LOCK)
  2105. {
  2106. break;
  2107. }
  2108. }
  2109. //
  2110. // Enable use of the PLL.
  2111. //
  2112. ulRCC &= ~(SYSCTL_RCC_BYPASS);
  2113. ulRCC2 &= ~(SYSCTL_RCC2_BYPASS2);
  2114. }
  2115. //
  2116. // Write the final RCC value.
  2117. //
  2118. HWREG(SYSCTL_RCC) = ulRCC;
  2119. HWREG(SYSCTL_RCC2) = ulRCC2;
  2120. //
  2121. // Delay for a little bit so that the system divider takes effect.
  2122. //
  2123. SysCtlDelay(16);
  2124. }
  2125. //*****************************************************************************
  2126. //
  2127. //! Gets the processor clock rate.
  2128. //!
  2129. //! This function determines the clock rate of the processor clock, which is
  2130. //! also the clock rate of the peripheral modules (with the exception of
  2131. //! PWM, which has its own clock divider; other peripherals may have different
  2132. //! clocking, see the device data sheet for details).
  2133. //!
  2134. //! \note This cannot return accurate results if SysCtlClockSet() has not
  2135. //! been called to configure the clocking of the device, or if the device is
  2136. //! directly clocked from a crystal (or a clock source) that is not one of the
  2137. //! supported crystal frequencies. In the latter case, this function should be
  2138. //! modified to directly return the correct system clock rate.
  2139. //!
  2140. //! \return The processor clock rate.
  2141. //
  2142. //*****************************************************************************
  2143. unsigned long
  2144. SysCtlClockGet(void)
  2145. {
  2146. unsigned long ulRCC, ulRCC2, ulPLL, ulClk;
  2147. unsigned long ulPLL1;
  2148. //
  2149. // Read RCC and RCC2. For Sandstorm-class devices (which do not have
  2150. // RCC2), the RCC2 read returns 0, indicating that RCC2 is
  2151. // disabled (because the SYSCTL_RCC2_USERCC2 bit is clear).
  2152. //
  2153. ulRCC = HWREG(SYSCTL_RCC);
  2154. ulRCC2 = HWREG(SYSCTL_RCC2);
  2155. //
  2156. // Get the base clock rate.
  2157. //
  2158. switch((ulRCC2 & SYSCTL_RCC2_USERCC2) ?
  2159. (ulRCC2 & SYSCTL_RCC2_OSCSRC2_M) :
  2160. (ulRCC & SYSCTL_RCC_OSCSRC_M))
  2161. {
  2162. //
  2163. // The main oscillator is the clock source. Determine its rate from
  2164. // the crystal setting field.
  2165. //
  2166. case SYSCTL_RCC_OSCSRC_MAIN:
  2167. {
  2168. ulClk = g_pulXtals[(ulRCC & SYSCTL_RCC_XTAL_M) >>
  2169. SYSCTL_RCC_XTAL_S];
  2170. break;
  2171. }
  2172. //
  2173. // The internal oscillator is the source clock.
  2174. //
  2175. case SYSCTL_RCC_OSCSRC_INT:
  2176. {
  2177. //
  2178. // See if this is a Sandstorm-class or Fury-class device.
  2179. //
  2180. if(CLASS_IS_SANDSTORM)
  2181. {
  2182. //
  2183. // The internal oscillator on a Sandstorm-class device is
  2184. // 15 MHz +/- 50%.
  2185. //
  2186. ulClk = 15000000;
  2187. }
  2188. else if((CLASS_IS_FURY && REVISION_IS_A2) ||
  2189. (CLASS_IS_DUSTDEVIL && REVISION_IS_A0))
  2190. {
  2191. //
  2192. // The internal oscillator on a rev A2 Fury-class device and a
  2193. // Dustdevil-class device is 12 MHz +/- 30%.
  2194. //
  2195. ulClk = 12000000;
  2196. }
  2197. else
  2198. {
  2199. //
  2200. // The internal oscillator on all other devices is 16 MHz.
  2201. //
  2202. ulClk = 16000000;
  2203. }
  2204. break;
  2205. }
  2206. //
  2207. // The internal oscillator divided by four is the source clock.
  2208. //
  2209. case SYSCTL_RCC_OSCSRC_INT4:
  2210. {
  2211. //
  2212. // See if this is a Sandstorm-class or Fury-class device.
  2213. //
  2214. if(CLASS_IS_SANDSTORM)
  2215. {
  2216. //
  2217. // The internal oscillator on a Sandstorm-class device is
  2218. // 15 MHz +/- 50%.
  2219. //
  2220. ulClk = 15000000 / 4;
  2221. }
  2222. else if((CLASS_IS_FURY && REVISION_IS_A2) ||
  2223. (CLASS_IS_DUSTDEVIL && REVISION_IS_A0))
  2224. {
  2225. //
  2226. // The internal oscillator on a rev A2 Fury-class device and a
  2227. // Dustdevil-class device is 12 MHz +/- 30%.
  2228. //
  2229. ulClk = 12000000 / 4;
  2230. }
  2231. else
  2232. {
  2233. //
  2234. // The internal oscillator on a Tempest-class device is 16 MHz.
  2235. //
  2236. ulClk = 16000000 / 4;
  2237. }
  2238. break;
  2239. }
  2240. //
  2241. // The internal 30-KHz oscillator is the source clock.
  2242. //
  2243. case SYSCTL_RCC_OSCSRC_30:
  2244. {
  2245. //
  2246. // The internal 30-KHz oscillator has an accuracy of +/- 30%.
  2247. //
  2248. ulClk = 30000;
  2249. break;
  2250. }
  2251. //
  2252. // The 4.194304-MHz clock from the hibernate module is the clock source.
  2253. //
  2254. case SYSCTL_RCC2_OSCSRC2_419:
  2255. {
  2256. ulClk = 4194304;
  2257. break;
  2258. }
  2259. //
  2260. // The 32.768-KHz clock from the hibernate module is the source clock.
  2261. //
  2262. case SYSCTL_RCC2_OSCSRC2_32:
  2263. {
  2264. ulClk = 32768;
  2265. break;
  2266. }
  2267. //
  2268. // An unknown setting, so return a zero clock (that is, an unknown
  2269. // clock rate).
  2270. //
  2271. default:
  2272. {
  2273. return(0);
  2274. }
  2275. }
  2276. //
  2277. // See if the PLL is being used.
  2278. //
  2279. if(((ulRCC2 & SYSCTL_RCC2_USERCC2) && !(ulRCC2 & SYSCTL_RCC2_BYPASS2)) ||
  2280. (!(ulRCC2 & SYSCTL_RCC2_USERCC2) && !(ulRCC & SYSCTL_RCC_BYPASS)))
  2281. {
  2282. //
  2283. // See if this is a Blizzard-class device.
  2284. //
  2285. if(CLASS_IS_BLIZZARD)
  2286. {
  2287. //
  2288. // Read the two PLL frequency registers. The formula for a
  2289. // Blizzard-class device is "(xtal * m) / ((q + 1) * (n + 1))".
  2290. //
  2291. ulPLL = HWREG(SYSCTL_PLLFREQ0);
  2292. ulPLL1 = HWREG(SYSCTL_PLLFREQ1);
  2293. //
  2294. // Divide the input clock by the dividers.
  2295. //
  2296. ulClk /= ((((ulPLL1 & SYSCTL_PLLFREQ1_Q_M) >>
  2297. SYSCTL_PLLFREQ1_Q_S) + 1) *
  2298. (((ulPLL1 & SYSCTL_PLLFREQ1_N_M) >>
  2299. SYSCTL_PLLFREQ1_N_S) + 1) * 2);
  2300. //
  2301. // Multiply the clock by the multiplier, which is split into an
  2302. // integer part and a fractional part.
  2303. //
  2304. ulClk = ((ulClk * ((ulPLL & SYSCTL_PLLFREQ0_MINT_M) >>
  2305. SYSCTL_PLLFREQ0_MINT_S)) +
  2306. ((ulClk * ((ulPLL & SYSCTL_PLLFREQ0_MFRAC_M) >>
  2307. SYSCTL_PLLFREQ0_MFRAC_S)) >> 10));
  2308. }
  2309. //
  2310. // Older device classes used a different PLL.
  2311. //
  2312. else
  2313. {
  2314. //
  2315. // Get the PLL configuration.
  2316. //
  2317. ulPLL = HWREG(SYSCTL_PLLCFG);
  2318. //
  2319. // See if this is a Sandstorm-class or Fury-class device.
  2320. //
  2321. if(CLASS_IS_SANDSTORM)
  2322. {
  2323. //
  2324. // Compute the PLL output frequency based on its input
  2325. // frequency. The formula for a Sandstorm-class devices is
  2326. // "(xtal * (f + 2)) / (r + 2)".
  2327. //
  2328. ulClk = ((ulClk * (((ulPLL & SYSCTL_PLLCFG_F_M) >>
  2329. SYSCTL_PLLCFG_F_S) + 2)) /
  2330. (((ulPLL & SYSCTL_PLLCFG_R_M) >>
  2331. SYSCTL_PLLCFG_R_S) + 2));
  2332. }
  2333. else
  2334. {
  2335. //
  2336. // Compute the PLL output frequency based on its input
  2337. // frequency. The formula for a Fury-class device is
  2338. // "(xtal * f) / ((r + 1) * 2)".
  2339. //
  2340. ulClk = ((ulClk * ((ulPLL & SYSCTL_PLLCFG_F_M) >>
  2341. SYSCTL_PLLCFG_F_S)) /
  2342. ((((ulPLL & SYSCTL_PLLCFG_R_M) >>
  2343. SYSCTL_PLLCFG_R_S) + 1) * 2));
  2344. }
  2345. //
  2346. // See if the optional output divide by 2 is being used.
  2347. //
  2348. if(ulPLL & SYSCTL_PLLCFG_OD_2)
  2349. {
  2350. ulClk /= 2;
  2351. }
  2352. //
  2353. // See if the optional output divide by 4 is being used.
  2354. //
  2355. if(ulPLL & SYSCTL_PLLCFG_OD_4)
  2356. {
  2357. ulClk /= 4;
  2358. }
  2359. }
  2360. //
  2361. // Force the system divider to be enabled. It is always used when
  2362. // using the PLL, but in some cases it does not read as being enabled.
  2363. //
  2364. ulRCC |= SYSCTL_RCC_USESYSDIV;
  2365. }
  2366. //
  2367. // See if the system divider is being used.
  2368. //
  2369. if(ulRCC & SYSCTL_RCC_USESYSDIV)
  2370. {
  2371. //
  2372. // Adjust the clock rate by the system clock divider.
  2373. //
  2374. if(ulRCC2 & SYSCTL_RCC2_USERCC2)
  2375. {
  2376. if((ulRCC2 & SYSCTL_RCC2_DIV400) &&
  2377. (((ulRCC2 & SYSCTL_RCC2_USERCC2) &&
  2378. !(ulRCC2 & SYSCTL_RCC2_BYPASS2)) ||
  2379. (!(ulRCC2 & SYSCTL_RCC2_USERCC2) &&
  2380. !(ulRCC & SYSCTL_RCC_BYPASS))))
  2381. {
  2382. ulClk = ((ulClk * 2) / (((ulRCC2 & (SYSCTL_RCC2_SYSDIV2_M |
  2383. SYSCTL_RCC2_SYSDIV2LSB)) >>
  2384. (SYSCTL_RCC2_SYSDIV2_S - 1)) + 1));
  2385. }
  2386. else
  2387. {
  2388. ulClk /= (((ulRCC2 & SYSCTL_RCC2_SYSDIV2_M) >>
  2389. SYSCTL_RCC2_SYSDIV2_S) + 1);
  2390. }
  2391. }
  2392. else
  2393. {
  2394. ulClk /= (((ulRCC & SYSCTL_RCC_SYSDIV_M) >> SYSCTL_RCC_SYSDIV_S) +
  2395. 1);
  2396. }
  2397. }
  2398. //
  2399. // Return the computed clock rate.
  2400. //
  2401. return(ulClk);
  2402. }
  2403. //*****************************************************************************
  2404. //
  2405. //! Sets the clocking of the device while in deep-sleep mode.
  2406. //!
  2407. //! \param ulConfig is the required configuration of the device clocking while
  2408. //! in deep-sleep mode.
  2409. //!
  2410. //! This function configures the clocking of the device while in deep-sleep
  2411. //! mode. The oscillator to be used and the system clock divider are
  2412. //! configured with this function.
  2413. //!
  2414. //! The \e ulConfig parameter is the logical OR of the following values:
  2415. //!
  2416. //! The system clock divider is chosen with one of the following values:
  2417. //! \b SYSCTL_DSLP_DIV_1, \b SYSCTL_DSLP_DIV_2, \b SYSCTL_DSLP_DIV_3, ...
  2418. //! \b SYSCTL_DSLP_DIV_64.
  2419. //!
  2420. //! The oscillator source is chosen with one of the following values:
  2421. //! \b SYSCTL_DSLP_OSC_MAIN, \b SYSCTL_DSLP_OSC_INT, \b SYSCTL_DSLP_OSC_INT30,
  2422. //! or \b SYSCTL_DSLP_OSC_EXT32. \b SYSCTL_OSC_EXT32 is only available on
  2423. //! devices with the hibernate module, and then only when the hibernate module
  2424. //! has been enabled.
  2425. //!
  2426. //! The precision internal oscillator can be powered down in deep-sleep mode by
  2427. //! specifying \b SYSCTL_DSLP_PIOSC_PD. If it is required for operation while
  2428. //! in deep-sleep (based on other configuration settings), it will not be
  2429. //! powered down.
  2430. //!
  2431. //! \note The availability of deep-sleep clocking configuration varies with the
  2432. //! Stellaris part in use. Please consult the datasheet for the part you are
  2433. //! using to determine whether this support is available.
  2434. //!
  2435. //! \return None.
  2436. //
  2437. //*****************************************************************************
  2438. void
  2439. SysCtlDeepSleepClockSet(unsigned long ulConfig)
  2440. {
  2441. //
  2442. // Set the deep-sleep clock configuration.
  2443. //
  2444. HWREG(SYSCTL_DSLPCLKCFG) = ulConfig;
  2445. }
  2446. //*****************************************************************************
  2447. //
  2448. //! Sets the PWM clock configuration.
  2449. //!
  2450. //! \param ulConfig is the configuration for the PWM clock; it must be one of
  2451. //! \b SYSCTL_PWMDIV_1, \b SYSCTL_PWMDIV_2, \b SYSCTL_PWMDIV_4,
  2452. //! \b SYSCTL_PWMDIV_8, \b SYSCTL_PWMDIV_16, \b SYSCTL_PWMDIV_32, or
  2453. //! \b SYSCTL_PWMDIV_64.
  2454. //!
  2455. //! This function configures the rate of the clock provided to the PWM module
  2456. //! as a ratio of the processor clock. This clock is used by the PWM module to
  2457. //! generate PWM signals; its rate forms the basis for all PWM signals.
  2458. //!
  2459. //! \note The clocking of the PWM is dependent upon the system clock rate as
  2460. //! configured by SysCtlClockSet().
  2461. //!
  2462. //! \return None.
  2463. //
  2464. //*****************************************************************************
  2465. void
  2466. SysCtlPWMClockSet(unsigned long ulConfig)
  2467. {
  2468. //
  2469. // Check the arguments.
  2470. //
  2471. ASSERT((ulConfig == SYSCTL_PWMDIV_1) ||
  2472. (ulConfig == SYSCTL_PWMDIV_2) ||
  2473. (ulConfig == SYSCTL_PWMDIV_4) ||
  2474. (ulConfig == SYSCTL_PWMDIV_8) ||
  2475. (ulConfig == SYSCTL_PWMDIV_16) ||
  2476. (ulConfig == SYSCTL_PWMDIV_32) ||
  2477. (ulConfig == SYSCTL_PWMDIV_64));
  2478. //
  2479. // Check that there is a PWM block on this part.
  2480. //
  2481. ASSERT(HWREG(SYSCTL_DC1) & SYSCTL_DC1_PWM0);
  2482. //
  2483. // Set the PWM clock configuration into the run-mode clock configuration
  2484. // register.
  2485. //
  2486. HWREG(SYSCTL_RCC) = ((HWREG(SYSCTL_RCC) &
  2487. ~(SYSCTL_RCC_USEPWMDIV | SYSCTL_RCC_PWMDIV_M)) |
  2488. ulConfig);
  2489. }
  2490. //*****************************************************************************
  2491. //
  2492. //! Gets the current PWM clock configuration.
  2493. //!
  2494. //! This function returns the current PWM clock configuration.
  2495. //!
  2496. //! \return Returns the current PWM clock configuration; is one of
  2497. //! \b SYSCTL_PWMDIV_1, \b SYSCTL_PWMDIV_2, \b SYSCTL_PWMDIV_4,
  2498. //! \b SYSCTL_PWMDIV_8, \b SYSCTL_PWMDIV_16, \b SYSCTL_PWMDIV_32, or
  2499. //! \b SYSCTL_PWMDIV_64.
  2500. //
  2501. //*****************************************************************************
  2502. unsigned long
  2503. SysCtlPWMClockGet(void)
  2504. {
  2505. //
  2506. // Check that there is a PWM block on this part.
  2507. //
  2508. ASSERT(HWREG(SYSCTL_DC1) & SYSCTL_DC1_PWM0);
  2509. //
  2510. // Return the current PWM clock configuration. Make sure that
  2511. // SYSCTL_PWMDIV_1 is returned in all cases where the divider is disabled.
  2512. //
  2513. if(!(HWREG(SYSCTL_RCC) & SYSCTL_RCC_USEPWMDIV))
  2514. {
  2515. //
  2516. // The divider is not active so reflect this in the value we return.
  2517. //
  2518. return(SYSCTL_PWMDIV_1);
  2519. }
  2520. else
  2521. {
  2522. //
  2523. // The divider is active so directly return the masked register value.
  2524. //
  2525. return(HWREG(SYSCTL_RCC) &
  2526. (SYSCTL_RCC_USEPWMDIV | SYSCTL_RCC_PWMDIV_M));
  2527. }
  2528. }
  2529. //*****************************************************************************
  2530. //
  2531. //! Sets the sample rate of the ADC.
  2532. //!
  2533. //! \param ulSpeed is the desired sample rate of the ADC; must be one of
  2534. //! \b SYSCTL_ADCSPEED_1MSPS, \b SYSCTL_ADCSPEED_500KSPS,
  2535. //! \b SYSCTL_ADCSPEED_250KSPS, or \b SYSCTL_ADCSPEED_125KSPS.
  2536. //!
  2537. //! This function configures the rate at which the ADC samples are captured by
  2538. //! the ADC block. The sampling speed may be limited by the hardware, so the
  2539. //! sample rate may end up being slower than requested. SysCtlADCSpeedGet()
  2540. //! returns the actual speed in use.
  2541. //!
  2542. //! \return None.
  2543. //
  2544. //*****************************************************************************
  2545. void
  2546. SysCtlADCSpeedSet(unsigned long ulSpeed)
  2547. {
  2548. //
  2549. // Check the arguments.
  2550. //
  2551. ASSERT((ulSpeed == SYSCTL_ADCSPEED_1MSPS) ||
  2552. (ulSpeed == SYSCTL_ADCSPEED_500KSPS) ||
  2553. (ulSpeed == SYSCTL_ADCSPEED_250KSPS) ||
  2554. (ulSpeed == SYSCTL_ADCSPEED_125KSPS));
  2555. //
  2556. // Check that there is an ADC block on this part.
  2557. //
  2558. ASSERT(HWREG(SYSCTL_DC1) & SYSCTL_DC1_ADC0);
  2559. //
  2560. // Set the ADC speed in run and sleep mode.
  2561. //
  2562. HWREG(SYSCTL_RCGC0) = ((HWREG(SYSCTL_RCGC0) & ~(SYSCTL_RCGC0_ADCSPD_M)) |
  2563. ulSpeed);
  2564. HWREG(SYSCTL_SCGC0) = ((HWREG(SYSCTL_SCGC0) & ~(SYSCTL_SCGC0_ADCSPD_M)) |
  2565. ulSpeed);
  2566. }
  2567. //*****************************************************************************
  2568. //
  2569. //! Gets the sample rate of the ADC.
  2570. //!
  2571. //! This function gets the current sample rate of the ADC.
  2572. //!
  2573. //! \return Returns the current ADC sample rate; is one of
  2574. //! \b SYSCTL_ADCSPEED_1MSPS, \b SYSCTL_ADCSPEED_500KSPS,
  2575. //! \b SYSCTL_ADCSPEED_250KSPS, or \b SYSCTL_ADCSPEED_125KSPS.
  2576. //
  2577. //*****************************************************************************
  2578. unsigned long
  2579. SysCtlADCSpeedGet(void)
  2580. {
  2581. //
  2582. // Check that there is an ADC block on this part.
  2583. //
  2584. ASSERT(HWREG(SYSCTL_DC1) & SYSCTL_DC1_ADC0);
  2585. //
  2586. // Return the current ADC speed.
  2587. //
  2588. return(HWREG(SYSCTL_RCGC0) & SYSCTL_RCGC0_ADCSPD_M);
  2589. }
  2590. //*****************************************************************************
  2591. //
  2592. //! Configures the internal oscillator verification timer.
  2593. //!
  2594. //! \param bEnable is a boolean that is \b true if the internal oscillator
  2595. //! verification timer should be enabled.
  2596. //!
  2597. //! This function allows the internal oscillator verification timer to be
  2598. //! enabled or disabled. When enabled, an interrupt is generated if the
  2599. //! internal oscillator ceases to operate.
  2600. //!
  2601. //! The internal oscillator verification timer is only available on
  2602. //! Sandstorm-class devices.
  2603. //!
  2604. //! \note Both oscillators (main and internal) must be enabled for this
  2605. //! verification timer to operate as the main oscillator verifies the
  2606. //! internal oscillator.
  2607. //!
  2608. //! \return None.
  2609. //
  2610. //*****************************************************************************
  2611. void
  2612. SysCtlIOSCVerificationSet(tBoolean bEnable)
  2613. {
  2614. //
  2615. // Enable or disable the internal oscillator verification timer as
  2616. // requested.
  2617. //
  2618. if(bEnable)
  2619. {
  2620. HWREG(SYSCTL_RCC) |= SYSCTL_RCC_IOSCVER;
  2621. }
  2622. else
  2623. {
  2624. HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_IOSCVER);
  2625. }
  2626. }
  2627. //*****************************************************************************
  2628. //
  2629. //! Configures the main oscillator verification timer.
  2630. //!
  2631. //! \param bEnable is a boolean that is \b true if the main oscillator
  2632. //! verification timer should be enabled.
  2633. //!
  2634. //! This function allows the main oscillator verification timer to be enabled
  2635. //! or disabled. When enabled, an interrupt is generated if the main
  2636. //! oscillator ceases to operate.
  2637. //!
  2638. //! The main oscillator verification timer is only available on
  2639. //! Sandstorm-class devices.
  2640. //!
  2641. //! \note Both oscillators (main and internal) must be enabled for this
  2642. //! verification timer to operate as the internal oscillator verifies the
  2643. //! main oscillator.
  2644. //!
  2645. //! \return None.
  2646. //
  2647. //*****************************************************************************
  2648. void
  2649. SysCtlMOSCVerificationSet(tBoolean bEnable)
  2650. {
  2651. //
  2652. // Enable or disable the main oscillator verification timer as requested.
  2653. //
  2654. if(bEnable)
  2655. {
  2656. HWREG(SYSCTL_RCC) |= SYSCTL_RCC_MOSCVER;
  2657. }
  2658. else
  2659. {
  2660. HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_MOSCVER);
  2661. }
  2662. }
  2663. //*****************************************************************************
  2664. //
  2665. //! Configures the PLL verification timer.
  2666. //!
  2667. //! \param bEnable is a boolean that is \b true if the PLL verification timer
  2668. //! should be enabled.
  2669. //!
  2670. //! This function allows the PLL verification timer to be enabled or disabled.
  2671. //! When enabled, an interrupt is generated if the PLL ceases to operate.
  2672. //!
  2673. //! The PLL verification timer is only available on Sandstorm-class devices.
  2674. //!
  2675. //! \note The main oscillator must be enabled for this verification timer to
  2676. //! operate as it is used to check the PLL. Also, the verification timer
  2677. //! should be disabled while the PLL is being reconfigured via
  2678. //! SysCtlClockSet().
  2679. //!
  2680. //! \return None.
  2681. //
  2682. //*****************************************************************************
  2683. void
  2684. SysCtlPLLVerificationSet(tBoolean bEnable)
  2685. {
  2686. //
  2687. // Enable or disable the PLL verification timer as requested.
  2688. //
  2689. if(bEnable)
  2690. {
  2691. HWREG(SYSCTL_RCC) |= SYSCTL_RCC_PLLVER;
  2692. }
  2693. else
  2694. {
  2695. HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_PLLVER);
  2696. }
  2697. }
  2698. //*****************************************************************************
  2699. //
  2700. //! Clears the clock verification status.
  2701. //!
  2702. //! This function clears the status of the clock verification timers, allowing
  2703. //! them to assert another failure if detected.
  2704. //!
  2705. //! The clock verification timers are only available on Sandstorm-class
  2706. //! devices.
  2707. //!
  2708. //! \return None.
  2709. //
  2710. //*****************************************************************************
  2711. void
  2712. SysCtlClkVerificationClear(void)
  2713. {
  2714. //
  2715. // Clear the clock verification.
  2716. //
  2717. HWREG(SYSCTL_CLKVCLR) = SYSCTL_CLKVCLR_VERCLR;
  2718. //
  2719. // The bit does not self-reset, so clear it.
  2720. //
  2721. HWREG(SYSCTL_CLKVCLR) = 0;
  2722. }
  2723. //*****************************************************************************
  2724. //
  2725. //! Enables a GPIO peripheral for access from the AHB.
  2726. //!
  2727. //! \param ulGPIOPeripheral is the GPIO peripheral to enable.
  2728. //!
  2729. //! This function is used to enable the specified GPIO peripheral to be
  2730. //! accessed from the Advanced Host Bus (AHB) instead of the legacy Advanced
  2731. //! Peripheral Bus (APB). When a GPIO peripheral is enabled for AHB access,
  2732. //! the \b _AHB_BASE form of the base address should be used for GPIO
  2733. //! functions. For example, instead of using \b GPIO_PORTA_BASE as the base
  2734. //! address for GPIO functions, use \b GPIO_PORTA_AHB_BASE instead.
  2735. //!
  2736. //! The \e ulGPIOPeripheral argument must be only one of the following values:
  2737. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  2738. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  2739. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, or \b SYSCTL_PERIPH_GPIOJ.
  2740. //!
  2741. //! \return None.
  2742. //
  2743. //*****************************************************************************
  2744. void
  2745. SysCtlGPIOAHBEnable(unsigned long ulGPIOPeripheral)
  2746. {
  2747. //
  2748. // Check the arguments.
  2749. //
  2750. ASSERT((ulGPIOPeripheral == SYSCTL_PERIPH_GPIOA) ||
  2751. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOB) ||
  2752. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOC) ||
  2753. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOD) ||
  2754. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOE) ||
  2755. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOF) ||
  2756. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOG) ||
  2757. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOH) ||
  2758. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOJ));
  2759. //
  2760. // Enable this GPIO for AHB access.
  2761. //
  2762. HWREG(SYSCTL_GPIOHBCTL) |= ulGPIOPeripheral & 0xFFFF;
  2763. }
  2764. //*****************************************************************************
  2765. //
  2766. //! Disables a GPIO peripheral for access from the AHB.
  2767. //!
  2768. //! \param ulGPIOPeripheral is the GPIO peripheral to disable.
  2769. //!
  2770. //! This function disables the specified GPIO peripheral for access from the
  2771. //! Advanced Host Bus (AHB). Once disabled, the GPIO peripheral is accessed
  2772. //! from the legacy Advanced Peripheral Bus (APB).
  2773. //!
  2774. //! The \b ulGPIOPeripheral argument must be only one of the following values:
  2775. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  2776. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  2777. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, or \b SYSCTL_PERIPH_GPIOJ.
  2778. //!
  2779. //! \return None.
  2780. //
  2781. //*****************************************************************************
  2782. void
  2783. SysCtlGPIOAHBDisable(unsigned long ulGPIOPeripheral)
  2784. {
  2785. //
  2786. // Check the arguments.
  2787. //
  2788. ASSERT((ulGPIOPeripheral == SYSCTL_PERIPH_GPIOA) ||
  2789. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOB) ||
  2790. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOC) ||
  2791. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOD) ||
  2792. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOE) ||
  2793. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOF) ||
  2794. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOG) ||
  2795. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOH) ||
  2796. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOJ));
  2797. //
  2798. // Disable this GPIO for AHB access.
  2799. //
  2800. HWREG(SYSCTL_GPIOHBCTL) &= ~(ulGPIOPeripheral & 0xFFFF);
  2801. }
  2802. //*****************************************************************************
  2803. //
  2804. //! Powers up the USB PLL.
  2805. //!
  2806. //! This function enables the USB controller's PLL, which is used by it's
  2807. //! physical layer. This call is necessary before connecting to any external
  2808. //! devices.
  2809. //!
  2810. //! \return None.
  2811. //
  2812. //*****************************************************************************
  2813. void
  2814. SysCtlUSBPLLEnable(void)
  2815. {
  2816. //
  2817. // Turn on the USB PLL.
  2818. //
  2819. HWREG(SYSCTL_RCC2) &= ~SYSCTL_RCC2_USBPWRDN;
  2820. }
  2821. //*****************************************************************************
  2822. //
  2823. //! Powers down the USB PLL.
  2824. //!
  2825. //! This function disables the USB controller's PLL, which is used by it's
  2826. //! physical layer. The USB registers are still accessible, but the physical
  2827. //! layer no longer functions.
  2828. //!
  2829. //! \return None.
  2830. //
  2831. //*****************************************************************************
  2832. void
  2833. SysCtlUSBPLLDisable(void)
  2834. {
  2835. //
  2836. // Turn off the USB PLL.
  2837. //
  2838. HWREG(SYSCTL_RCC2) |= SYSCTL_RCC2_USBPWRDN;
  2839. }
  2840. //*****************************************************************************
  2841. //
  2842. //! Sets the MCLK frequency provided to the I2S module.
  2843. //!
  2844. //! \param ulInputClock is the input clock to the MCLK divider. If this value
  2845. //! is zero, the value is computed from the current PLL configuration.
  2846. //! \param ulMClk is the desired MCLK frequency. If this value is zero, MCLK
  2847. //! output is disabled.
  2848. //!
  2849. //! This function confgiures the dividers to provide MCLK to the I2S module. A
  2850. //! MCLK divider is chosen that produces the MCLK frequency that is the closest
  2851. //! possible to the requested frequency, which may be above or below the
  2852. //! requested frequency.
  2853. //!
  2854. //! The actual MCLK frequency is returned. It is the responsibility of the
  2855. //! application to determine if the selected MCLK is acceptable; in general the
  2856. //! human ear can not discern the frequency difference if it is within 0.3% of
  2857. //! the desired frequency (although there is a very small percentage of the
  2858. //! population that can discern lower frequency deviations).
  2859. //!
  2860. //! \return Returns the actual MCLK frequency.
  2861. //
  2862. //*****************************************************************************
  2863. unsigned long
  2864. SysCtlI2SMClkSet(unsigned long ulInputClock, unsigned long ulMClk)
  2865. {
  2866. unsigned long ulDivInt, ulDivFrac, ulPLL;
  2867. //
  2868. // See if the I2S MCLK should be disabled.
  2869. //
  2870. if(ulMClk == 0)
  2871. {
  2872. //
  2873. // Disable the I2S MCLK and return.
  2874. //
  2875. HWREG(SYSCTL_I2SMCLKCFG) = 0;
  2876. return(0);
  2877. }
  2878. //
  2879. // See if the input clock was specified.
  2880. //
  2881. if(ulInputClock == 0)
  2882. {
  2883. //
  2884. // The input clock was not specified, so compute the output frequency
  2885. // of the PLL. Get the current PLL configuration.
  2886. //
  2887. ulPLL = HWREG(SYSCTL_PLLCFG);
  2888. //
  2889. // Get the frequency of the crystal in use.
  2890. //
  2891. ulInputClock = g_pulXtals[(HWREG(SYSCTL_RCC) & SYSCTL_RCC_XTAL_M) >>
  2892. SYSCTL_RCC_XTAL_S];
  2893. //
  2894. // Calculate the PLL output frequency.
  2895. //
  2896. ulInputClock = ((ulInputClock * ((ulPLL & SYSCTL_PLLCFG_F_M) >>
  2897. SYSCTL_PLLCFG_F_S)) /
  2898. ((((ulPLL & SYSCTL_PLLCFG_R_M) >>
  2899. SYSCTL_PLLCFG_R_S) + 1)));
  2900. //
  2901. // See if the optional output divide by 2 is being used.
  2902. //
  2903. if(ulPLL & SYSCTL_PLLCFG_OD_2)
  2904. {
  2905. ulInputClock /= 2;
  2906. }
  2907. //
  2908. // See if the optional output divide by 4 is being used.
  2909. //
  2910. if(ulPLL & SYSCTL_PLLCFG_OD_4)
  2911. {
  2912. ulInputClock /= 4;
  2913. }
  2914. }
  2915. //
  2916. // Verify that the requested MCLK frequency is attainable.
  2917. //
  2918. ASSERT(ulMClk < ulInputClock);
  2919. //
  2920. // Add a rounding factor to the input clock, so that the MCLK frequency
  2921. // that is closest to the desire value is selected.
  2922. //
  2923. ulInputClock += (ulMClk / 32) - 1;
  2924. //
  2925. // Compute the integer portion of the MCLK divider.
  2926. //
  2927. ulDivInt = ulInputClock / ulMClk;
  2928. //
  2929. // If the divisor is too large, then simply use the maximum divisor.
  2930. //
  2931. if(CLASS_IS_TEMPEST && REVISION_IS_B1 && (ulDivInt > 255))
  2932. {
  2933. ulDivInt = 255;
  2934. ulDivFrac = 15;
  2935. }
  2936. else if(ulDivInt > 1023)
  2937. {
  2938. ulDivInt = 1023;
  2939. ulDivFrac = 15;
  2940. }
  2941. else
  2942. {
  2943. //
  2944. // Compute the fractional portion of the MCLK divider.
  2945. //
  2946. ulDivFrac = ((ulInputClock - (ulDivInt * ulMClk)) * 16) / ulMClk;
  2947. }
  2948. //
  2949. // Set the divisor for the Tx and Rx MCLK generators and enable the clocks.
  2950. //
  2951. HWREG(SYSCTL_I2SMCLKCFG) = (SYSCTL_I2SMCLKCFG_RXEN |
  2952. (ulDivInt << SYSCTL_I2SMCLKCFG_RXI_S) |
  2953. (ulDivFrac << SYSCTL_I2SMCLKCFG_RXF_S) |
  2954. SYSCTL_I2SMCLKCFG_TXEN |
  2955. (ulDivInt << SYSCTL_I2SMCLKCFG_TXI_S) |
  2956. (ulDivFrac << SYSCTL_I2SMCLKCFG_TXF_S));
  2957. //
  2958. // Return the actual MCLK frequency.
  2959. //
  2960. ulInputClock -= (ulMClk / 32) - 1;
  2961. ulDivInt = (ulDivInt * 16) + ulDivFrac;
  2962. ulMClk = (ulInputClock / ulDivInt) * 16;
  2963. ulMClk += ((ulInputClock - ((ulMClk / 16) * ulDivInt)) * 16) / ulDivInt;
  2964. return(ulMClk);
  2965. }
  2966. //*****************************************************************************
  2967. //
  2968. // Close the Doxygen group.
  2969. //! @}
  2970. //
  2971. //*****************************************************************************