sysctl.c 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319
  1. //*****************************************************************************
  2. //
  3. // sysctl.c - Driver for the system controller.
  4. //
  5. // Copyright (c) 2005-2009 Luminary Micro, Inc. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Luminary Micro, Inc. (LMI) is supplying this software for use solely and
  9. // exclusively on LMI's microcontroller products.
  10. //
  11. // The software is owned by LMI and/or its suppliers, and is protected under
  12. // applicable copyright laws. All rights are reserved. You may not combine
  13. // this software with "viral" open-source software in order to form a larger
  14. // program. Any use in violation of the foregoing restrictions may subject
  15. // the user to criminal sanctions under applicable laws, as well as to civil
  16. // liability for the breach of the terms and conditions of this license.
  17. //
  18. // THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
  19. // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
  20. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
  21. // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
  22. // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
  23. //
  24. // This is part of revision 4694 of the Stellaris Peripheral Driver Library.
  25. //
  26. //*****************************************************************************
  27. //*****************************************************************************
  28. //
  29. //! \addtogroup sysctl_api
  30. //! @{
  31. //
  32. //*****************************************************************************
  33. #include "inc/hw_ints.h"
  34. #include "inc/hw_nvic.h"
  35. #include "inc/hw_sysctl.h"
  36. #include "inc/hw_types.h"
  37. #include "driverlib/cpu.h"
  38. #include "driverlib/debug.h"
  39. #include "driverlib/interrupt.h"
  40. #include "driverlib/sysctl.h"
  41. //*****************************************************************************
  42. //
  43. // This macro extracts the array index out of the peripheral number.
  44. //
  45. //*****************************************************************************
  46. #define SYSCTL_PERIPH_INDEX(a) (((a) >> 28) & 0xf)
  47. //*****************************************************************************
  48. //
  49. // This macro constructs the peripheral bit mask from the peripheral number.
  50. //
  51. //*****************************************************************************
  52. #define SYSCTL_PERIPH_MASK(a) (((a) & 0xffff) << (((a) & 0x001f0000) >> 16))
  53. //*****************************************************************************
  54. //
  55. // An array that maps the "peripheral set" number (which is stored in the upper
  56. // nibble of the SYSCTL_PERIPH_* defines) to the SYSCTL DC? register that
  57. // contains the peripheral present bit for that peripheral.
  58. //
  59. //*****************************************************************************
  60. static const unsigned long g_pulDCRegs[] =
  61. {
  62. SYSCTL_DC1,
  63. SYSCTL_DC2,
  64. SYSCTL_DC4,
  65. SYSCTL_DC1
  66. };
  67. //*****************************************************************************
  68. //
  69. // An array that maps the "peripheral set" number (which is stored in the upper
  70. // nibble of the SYSCTL_PERIPH_* defines) to the SYSCTL_SRCR? register that
  71. // controls the software reset for that peripheral.
  72. //
  73. //*****************************************************************************
  74. static const unsigned long g_pulSRCRRegs[] =
  75. {
  76. SYSCTL_SRCR0,
  77. SYSCTL_SRCR1,
  78. SYSCTL_SRCR2
  79. };
  80. //*****************************************************************************
  81. //
  82. // An array that maps the "peripheral set" number (which is stored in the upper
  83. // nibble of the SYSCTL_PERIPH_* defines) to the SYSCTL_RCGC? register that
  84. // controls the run-mode enable for that peripheral.
  85. //
  86. //*****************************************************************************
  87. static const unsigned long g_pulRCGCRegs[] =
  88. {
  89. SYSCTL_RCGC0,
  90. SYSCTL_RCGC1,
  91. SYSCTL_RCGC2
  92. };
  93. //*****************************************************************************
  94. //
  95. // An array that maps the "peripheral set" number (which is stored in the upper
  96. // nibble of the SYSCTL_PERIPH_* defines) to the SYSCTL_SCGC? register that
  97. // controls the sleep-mode enable for that peripheral.
  98. //
  99. //*****************************************************************************
  100. static const unsigned long g_pulSCGCRegs[] =
  101. {
  102. SYSCTL_SCGC0,
  103. SYSCTL_SCGC1,
  104. SYSCTL_SCGC2
  105. };
  106. //*****************************************************************************
  107. //
  108. // An array that maps the "peripheral set" number (which is stored in the upper
  109. // nibble of the SYSCTL_PERIPH_* defines) to the SYSCTL_DCGC? register that
  110. // controls the deep-sleep-mode enable for that peripheral.
  111. //
  112. //*****************************************************************************
  113. static const unsigned long g_pulDCGCRegs[] =
  114. {
  115. SYSCTL_DCGC0,
  116. SYSCTL_DCGC1,
  117. SYSCTL_DCGC2
  118. };
  119. //*****************************************************************************
  120. //
  121. // An array that maps the crystal number in RCC to a frequency.
  122. //
  123. //*****************************************************************************
  124. static const unsigned long g_pulXtals[] =
  125. {
  126. 1000000,
  127. 1843200,
  128. 2000000,
  129. 2457600,
  130. 3579545,
  131. 3686400,
  132. 4000000,
  133. 4096000,
  134. 4915200,
  135. 5000000,
  136. 5120000,
  137. 6000000,
  138. 6144000,
  139. 7372800,
  140. 8000000,
  141. 8192000,
  142. 10000000,
  143. 12000000,
  144. 12288000,
  145. 13560000,
  146. 14318180,
  147. 16000000,
  148. 16384000
  149. };
  150. //*****************************************************************************
  151. //
  152. //! \internal
  153. //! Checks a peripheral identifier.
  154. //!
  155. //! \param ulPeripheral is the peripheral identifier.
  156. //!
  157. //! This function determines if a peripheral identifier is valid.
  158. //!
  159. //! \return Returns \b true if the peripheral identifier is valid and \b false
  160. //! otherwise.
  161. //
  162. //*****************************************************************************
  163. #ifdef DEBUG
  164. static tBoolean
  165. SysCtlPeripheralValid(unsigned long ulPeripheral)
  166. {
  167. return((ulPeripheral == SYSCTL_PERIPH_ADC0) ||
  168. (ulPeripheral == SYSCTL_PERIPH_ADC1) ||
  169. (ulPeripheral == SYSCTL_PERIPH_CAN0) ||
  170. (ulPeripheral == SYSCTL_PERIPH_CAN1) ||
  171. (ulPeripheral == SYSCTL_PERIPH_CAN2) ||
  172. (ulPeripheral == SYSCTL_PERIPH_COMP0) ||
  173. (ulPeripheral == SYSCTL_PERIPH_COMP1) ||
  174. (ulPeripheral == SYSCTL_PERIPH_COMP2) ||
  175. (ulPeripheral == SYSCTL_PERIPH_EPI0) ||
  176. (ulPeripheral == SYSCTL_PERIPH_ETH) ||
  177. (ulPeripheral == SYSCTL_PERIPH_GPIOA) ||
  178. (ulPeripheral == SYSCTL_PERIPH_GPIOB) ||
  179. (ulPeripheral == SYSCTL_PERIPH_GPIOC) ||
  180. (ulPeripheral == SYSCTL_PERIPH_GPIOD) ||
  181. (ulPeripheral == SYSCTL_PERIPH_GPIOE) ||
  182. (ulPeripheral == SYSCTL_PERIPH_GPIOF) ||
  183. (ulPeripheral == SYSCTL_PERIPH_GPIOG) ||
  184. (ulPeripheral == SYSCTL_PERIPH_GPIOH) ||
  185. (ulPeripheral == SYSCTL_PERIPH_GPIOJ) ||
  186. (ulPeripheral == SYSCTL_PERIPH_HIBERNATE) ||
  187. (ulPeripheral == SYSCTL_PERIPH_I2C0) ||
  188. (ulPeripheral == SYSCTL_PERIPH_I2C1) ||
  189. (ulPeripheral == SYSCTL_PERIPH_I2S0) ||
  190. (ulPeripheral == SYSCTL_PERIPH_IEEE1588) ||
  191. (ulPeripheral == SYSCTL_PERIPH_MPU) ||
  192. (ulPeripheral == SYSCTL_PERIPH_PLL) ||
  193. (ulPeripheral == SYSCTL_PERIPH_PWM) ||
  194. (ulPeripheral == SYSCTL_PERIPH_QEI0) ||
  195. (ulPeripheral == SYSCTL_PERIPH_QEI1) ||
  196. (ulPeripheral == SYSCTL_PERIPH_SSI0) ||
  197. (ulPeripheral == SYSCTL_PERIPH_SSI1) ||
  198. (ulPeripheral == SYSCTL_PERIPH_TEMP) ||
  199. (ulPeripheral == SYSCTL_PERIPH_TIMER0) ||
  200. (ulPeripheral == SYSCTL_PERIPH_TIMER1) ||
  201. (ulPeripheral == SYSCTL_PERIPH_TIMER2) ||
  202. (ulPeripheral == SYSCTL_PERIPH_TIMER3) ||
  203. (ulPeripheral == SYSCTL_PERIPH_UART0) ||
  204. (ulPeripheral == SYSCTL_PERIPH_UART1) ||
  205. (ulPeripheral == SYSCTL_PERIPH_UART2) ||
  206. (ulPeripheral == SYSCTL_PERIPH_UDMA) ||
  207. (ulPeripheral == SYSCTL_PERIPH_USB0) ||
  208. (ulPeripheral == SYSCTL_PERIPH_WDOG0) ||
  209. (ulPeripheral == SYSCTL_PERIPH_WDOG1));
  210. }
  211. #endif
  212. //*****************************************************************************
  213. //
  214. //! Gets the size of the SRAM.
  215. //!
  216. //! This function determines the size of the SRAM on the Stellaris device.
  217. //!
  218. //! \return The total number of bytes of SRAM.
  219. //
  220. //*****************************************************************************
  221. unsigned long
  222. SysCtlSRAMSizeGet(void)
  223. {
  224. //
  225. // Compute the size of the SRAM.
  226. //
  227. return(((HWREG(SYSCTL_DC0) & SYSCTL_DC0_SRAMSZ_M) >> 8) + 0x100);
  228. }
  229. //*****************************************************************************
  230. //
  231. //! Gets the size of the flash.
  232. //!
  233. //! This function determines the size of the flash on the Stellaris device.
  234. //!
  235. //! \return The total number of bytes of flash.
  236. //
  237. //*****************************************************************************
  238. unsigned long
  239. SysCtlFlashSizeGet(void)
  240. {
  241. //
  242. // Compute the size of the flash.
  243. //
  244. return(((HWREG(SYSCTL_DC0) & SYSCTL_DC0_FLASHSZ_M) << 11) + 0x800);
  245. }
  246. //*****************************************************************************
  247. //
  248. //! Determines if a pin is present.
  249. //!
  250. //! \param ulPin is the pin in question.
  251. //!
  252. //! Determines if a particular pin is present in the device. The PWM, analog
  253. //! comparators, ADC, and timers have a varying number of pins across members
  254. //! of the Stellaris family; this will determine which are present on this
  255. //! device.
  256. //!
  257. //! The \e ulPin argument must be only one of the following values:
  258. //! \b SYSCTL_PIN_PWM0, \b SYSCTL_PIN_PWM1, \b SYSCTL_PIN_PWM2,
  259. //! \b SYSCTL_PIN_PWM3, \b SYSCTL_PIN_PWM4, \b SYSCTL_PIN_PWM5,
  260. //! \b SYSCTL_PIN_C0MINUS, \b SYSCTL_PIN_C0PLUS, \b SYSCTL_PIN_C0O,
  261. //! \b SYSCTL_PIN_C1MINUS, \b SYSCTL_PIN_C1PLUS, \b SYSCTL_PIN_C1O,
  262. //! \b SYSCTL_PIN_C2MINUS, \b SYSCTL_PIN_C2PLUS, \b SYSCTL_PIN_C2O,
  263. //! \b SYSCTL_PIN_ADC0, \b SYSCTL_PIN_ADC1, \b SYSCTL_PIN_ADC2,
  264. //! \b SYSCTL_PIN_ADC3, \b SYSCTL_PIN_ADC4, \b SYSCTL_PIN_ADC5,
  265. //! \b SYSCTL_PIN_ADC6, \b SYSCTL_PIN_ADC7, \b SYSCTL_PIN_CCP0,
  266. //! \b SYSCTL_PIN_CCP1, \b SYSCTL_PIN_CCP2, \b SYSCTL_PIN_CCP3,
  267. //! \b SYSCTL_PIN_CCP4, \b SYSCTL_PIN_CCP5, \b SYSCTL_PIN_CCP6,
  268. //! \b SYSCTL_PIN_CCP7, \b SYSCTL_PIN_32KHZ, or \b SYSCTL_PIN_MC_FAULT0.
  269. //!
  270. //! \return Returns \b true if the specified pin is present and \b false if it
  271. //! is not.
  272. //
  273. //*****************************************************************************
  274. tBoolean
  275. SysCtlPinPresent(unsigned long ulPin)
  276. {
  277. //
  278. // Check the arguments.
  279. //
  280. ASSERT((ulPin == SYSCTL_PIN_PWM0) ||
  281. (ulPin == SYSCTL_PIN_PWM1) ||
  282. (ulPin == SYSCTL_PIN_PWM2) ||
  283. (ulPin == SYSCTL_PIN_PWM3) ||
  284. (ulPin == SYSCTL_PIN_PWM4) ||
  285. (ulPin == SYSCTL_PIN_PWM5) ||
  286. (ulPin == SYSCTL_PIN_C0MINUS) ||
  287. (ulPin == SYSCTL_PIN_C0PLUS) ||
  288. (ulPin == SYSCTL_PIN_C0O) ||
  289. (ulPin == SYSCTL_PIN_C1MINUS) ||
  290. (ulPin == SYSCTL_PIN_C1PLUS) ||
  291. (ulPin == SYSCTL_PIN_C1O) ||
  292. (ulPin == SYSCTL_PIN_C2MINUS) ||
  293. (ulPin == SYSCTL_PIN_C2PLUS) ||
  294. (ulPin == SYSCTL_PIN_C2O) ||
  295. (ulPin == SYSCTL_PIN_MC_FAULT0) ||
  296. (ulPin == SYSCTL_PIN_ADC0) ||
  297. (ulPin == SYSCTL_PIN_ADC1) ||
  298. (ulPin == SYSCTL_PIN_ADC2) ||
  299. (ulPin == SYSCTL_PIN_ADC3) ||
  300. (ulPin == SYSCTL_PIN_ADC4) ||
  301. (ulPin == SYSCTL_PIN_ADC5) ||
  302. (ulPin == SYSCTL_PIN_ADC6) ||
  303. (ulPin == SYSCTL_PIN_ADC7) ||
  304. (ulPin == SYSCTL_PIN_CCP0) ||
  305. (ulPin == SYSCTL_PIN_CCP1) ||
  306. (ulPin == SYSCTL_PIN_CCP2) ||
  307. (ulPin == SYSCTL_PIN_CCP3) ||
  308. (ulPin == SYSCTL_PIN_CCP4) ||
  309. (ulPin == SYSCTL_PIN_CCP5) ||
  310. (ulPin == SYSCTL_PIN_32KHZ));
  311. //
  312. // Determine if this pin is present.
  313. //
  314. if(HWREG(SYSCTL_DC3) & ulPin)
  315. {
  316. return(true);
  317. }
  318. else
  319. {
  320. return(false);
  321. }
  322. }
  323. //*****************************************************************************
  324. //
  325. //! Determines if a peripheral is present.
  326. //!
  327. //! \param ulPeripheral is the peripheral in question.
  328. //!
  329. //! Determines if a particular peripheral is present in the device. Each
  330. //! member of the Stellaris family has a different peripheral set; this will
  331. //! determine which are present on this device.
  332. //!
  333. //! The \e ulPeripheral parameter must be only one of the following values:
  334. //! \b SYSCTL_PERIPH_ADC, \b SYSCTL_PERIPH_CAN0, \b SYSCTL_PERIPH_CAN1,
  335. //! \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0, \b SYSCTL_PERIPH_COMP1,
  336. //! \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_GPIOA,
  337. //! \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC, \b SYSCTL_PERIPH_GPIOD,
  338. //! \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF, \b SYSCTL_PERIPH_GPIOG,
  339. //! \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0,
  340. //! \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_IEEE1588, \b SYSCTL_PERIPH_MPU,
  341. //! \b SYSCTL_PERIPH_PLL, \b SYSCTL_PERIPH_PWM, \b SYSCTL_PERIPH_QEI0,
  342. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  343. //! \b SYSCTL_PERIPH_TEMP, \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1,
  344. //! \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_UART0,
  345. //! \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UDMA,
  346. //! \b SYSCTL_PERIPH_USB0, or \b SYSCTL_PERIPH_WDOG.
  347. //!
  348. //! \return Returns \b true if the specified peripheral is present and \b false
  349. //! if it is not.
  350. //
  351. //*****************************************************************************
  352. tBoolean
  353. SysCtlPeripheralPresent(unsigned long ulPeripheral)
  354. {
  355. //
  356. // Check the arguments.
  357. //
  358. ASSERT(SysCtlPeripheralValid(ulPeripheral));
  359. //
  360. // Read the correct DC register and determine if this peripheral exists.
  361. //
  362. if(HWREG(g_pulDCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) &
  363. SYSCTL_PERIPH_MASK(ulPeripheral))
  364. {
  365. return(true);
  366. }
  367. else
  368. {
  369. return(false);
  370. }
  371. }
  372. //*****************************************************************************
  373. //
  374. //! Performs a software reset of a peripheral.
  375. //!
  376. //! \param ulPeripheral is the peripheral to reset.
  377. //!
  378. //! This function performs a software reset of the specified peripheral. An
  379. //! individual peripheral reset signal is asserted for a brief period and then
  380. //! deasserted, leaving the peripheral in a operating state but in its reset
  381. //! condition.
  382. //!
  383. //! The \e ulPeripheral parameter must be only one of the following values:
  384. //! \b SYSCTL_PERIPH_ADC, \b SYSCTL_PERIPH_CAN0, \b SYSCTL_PERIPH_CAN1,
  385. //! \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0, \b SYSCTL_PERIPH_COMP1,
  386. //! \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_GPIOA,
  387. //! \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC, \b SYSCTL_PERIPH_GPIOD,
  388. //! \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF, \b SYSCTL_PERIPH_GPIOG,
  389. //! \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0,
  390. //! \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_PWM, \b SYSCTL_PERIPH_QEI0,
  391. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  392. //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
  393. //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  394. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, or
  395. //! \b SYSCTL_PERIPH_WDOG.
  396. //!
  397. //! \return None.
  398. //
  399. //*****************************************************************************
  400. void
  401. SysCtlPeripheralReset(unsigned long ulPeripheral)
  402. {
  403. volatile unsigned long ulDelay;
  404. //
  405. // Check the arguments.
  406. //
  407. ASSERT(SysCtlPeripheralValid(ulPeripheral));
  408. //
  409. // Put the peripheral into the reset state.
  410. //
  411. HWREG(g_pulSRCRRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) |=
  412. SYSCTL_PERIPH_MASK(ulPeripheral);
  413. //
  414. // Delay for a little bit.
  415. //
  416. for(ulDelay = 0; ulDelay < 16; ulDelay++)
  417. {
  418. }
  419. //
  420. // Take the peripheral out of the reset state.
  421. //
  422. HWREG(g_pulSRCRRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) &=
  423. ~SYSCTL_PERIPH_MASK(ulPeripheral);
  424. }
  425. //*****************************************************************************
  426. //
  427. //! Enables a peripheral.
  428. //!
  429. //! \param ulPeripheral is the peripheral to enable.
  430. //!
  431. //! Peripherals are enabled with this function. At power-up, all peripherals
  432. //! are disabled; they must be enabled in order to operate or respond to
  433. //! register reads/writes.
  434. //!
  435. //! The \e ulPeripheral parameter must be only one of the following values:
  436. //! \b SYSCTL_PERIPH_ADC, \b SYSCTL_PERIPH_CAN0, \b SYSCTL_PERIPH_CAN1,
  437. //! \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0, \b SYSCTL_PERIPH_COMP1,
  438. //! \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_GPIOA,
  439. //! \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC, \b SYSCTL_PERIPH_GPIOD,
  440. //! \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF, \b SYSCTL_PERIPH_GPIOG,
  441. //! \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0,
  442. //! \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_PWM, \b SYSCTL_PERIPH_QEI0,
  443. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  444. //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
  445. //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  446. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, or
  447. //! \b SYSCTL_PERIPH_WDOG.
  448. //!
  449. //! \note It takes five clock cycles after the write to enable a peripheral
  450. //! before the the peripheral is actually enabled. During this time, attempts
  451. //! to access the peripheral will result in a bus fault. Care should be taken
  452. //! to ensure that the peripheral is not accessed during this brief time
  453. //! period.
  454. //!
  455. //! \return None.
  456. //
  457. //*****************************************************************************
  458. void
  459. SysCtlPeripheralEnable(unsigned long ulPeripheral)
  460. {
  461. //
  462. // Check the arguments.
  463. //
  464. ASSERT(SysCtlPeripheralValid(ulPeripheral));
  465. //
  466. // Enable this peripheral.
  467. //
  468. HWREG(g_pulRCGCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) |=
  469. SYSCTL_PERIPH_MASK(ulPeripheral);
  470. }
  471. //*****************************************************************************
  472. //
  473. //! Disables a peripheral.
  474. //!
  475. //! \param ulPeripheral is the peripheral to disable.
  476. //!
  477. //! Peripherals are disabled with this function. Once disabled, they will not
  478. //! operate or respond to register reads/writes.
  479. //!
  480. //! The \e ulPeripheral parameter must be only one of the following values:
  481. //! \b SYSCTL_PERIPH_ADC, \b SYSCTL_PERIPH_CAN0, \b SYSCTL_PERIPH_CAN1,
  482. //! \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0, \b SYSCTL_PERIPH_COMP1,
  483. //! \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_GPIOA,
  484. //! \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC, \b SYSCTL_PERIPH_GPIOD,
  485. //! \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF, \b SYSCTL_PERIPH_GPIOG,
  486. //! \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0,
  487. //! \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_PWM, \b SYSCTL_PERIPH_QEI0,
  488. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  489. //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
  490. //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  491. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, or
  492. //! \b SYSCTL_PERIPH_WDOG.
  493. //!
  494. //! \return None.
  495. //
  496. //*****************************************************************************
  497. void
  498. SysCtlPeripheralDisable(unsigned long ulPeripheral)
  499. {
  500. //
  501. // Check the arguments.
  502. //
  503. ASSERT(SysCtlPeripheralValid(ulPeripheral));
  504. //
  505. // Disable this peripheral.
  506. //
  507. HWREG(g_pulRCGCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) &=
  508. ~SYSCTL_PERIPH_MASK(ulPeripheral);
  509. }
  510. //*****************************************************************************
  511. //
  512. //! Enables a peripheral in sleep mode.
  513. //!
  514. //! \param ulPeripheral is the peripheral to enable in sleep mode.
  515. //!
  516. //! This function allows a peripheral to continue operating when the processor
  517. //! goes into sleep mode. Since the clocking configuration of the device does
  518. //! not change, any peripheral can safely continue operating while the
  519. //! processor is in sleep mode, and can therefore wake the processor from sleep
  520. //! mode.
  521. //!
  522. //! Sleep mode clocking of peripherals must be enabled via
  523. //! SysCtlPeripheralClockGating(); if disabled, the peripheral sleep mode
  524. //! configuration is maintained but has no effect when sleep mode is entered.
  525. //!
  526. //! The \e ulPeripheral parameter must be only one of the following values:
  527. //! \b SYSCTL_PERIPH_ADC, \b SYSCTL_PERIPH_CAN0, \b SYSCTL_PERIPH_CAN1,
  528. //! \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0, \b SYSCTL_PERIPH_COMP1,
  529. //! \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_GPIOA,
  530. //! \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC, \b SYSCTL_PERIPH_GPIOD,
  531. //! \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF, \b SYSCTL_PERIPH_GPIOG,
  532. //! \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0,
  533. //! \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_PWM, \b SYSCTL_PERIPH_QEI0,
  534. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  535. //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
  536. //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  537. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, or
  538. //! \b SYSCTL_PERIPH_WDOG.
  539. //!
  540. //! \return None.
  541. //
  542. //*****************************************************************************
  543. void
  544. SysCtlPeripheralSleepEnable(unsigned long ulPeripheral)
  545. {
  546. //
  547. // Check the arguments.
  548. //
  549. ASSERT(SysCtlPeripheralValid(ulPeripheral));
  550. //
  551. // Enable this peripheral in sleep mode.
  552. //
  553. HWREG(g_pulSCGCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) |=
  554. SYSCTL_PERIPH_MASK(ulPeripheral);
  555. }
  556. //*****************************************************************************
  557. //
  558. //! Disables a peripheral in sleep mode.
  559. //!
  560. //! \param ulPeripheral is the peripheral to disable in sleep mode.
  561. //!
  562. //! This function causes a peripheral to stop operating when the processor goes
  563. //! into sleep mode. Disabling peripherals while in sleep mode helps to lower
  564. //! the current draw of the device. If enabled (via SysCtlPeripheralEnable()),
  565. //! the peripheral will automatically resume operation when the processor
  566. //! leaves sleep mode, maintaining its entire state from before sleep mode was
  567. //! entered.
  568. //!
  569. //! Sleep mode clocking of peripherals must be enabled via
  570. //! SysCtlPeripheralClockGating(); if disabled, the peripheral sleep mode
  571. //! configuration is maintained but has no effect when sleep mode is entered.
  572. //!
  573. //! The \e ulPeripheral parameter must be only one of the following values:
  574. //! \b SYSCTL_PERIPH_ADC, \b SYSCTL_PERIPH_CAN0, \b SYSCTL_PERIPH_CAN1,
  575. //! \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0, \b SYSCTL_PERIPH_COMP1,
  576. //! \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_GPIOA,
  577. //! \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC, \b SYSCTL_PERIPH_GPIOD,
  578. //! \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF, \b SYSCTL_PERIPH_GPIOG,
  579. //! \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0,
  580. //! \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_PWM, \b SYSCTL_PERIPH_QEI0,
  581. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  582. //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
  583. //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  584. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, or
  585. //! \b SYSCTL_PERIPH_WDOG.
  586. //!
  587. //! \return None.
  588. //
  589. //*****************************************************************************
  590. void
  591. SysCtlPeripheralSleepDisable(unsigned long ulPeripheral)
  592. {
  593. //
  594. // Check the arguments.
  595. //
  596. ASSERT(SysCtlPeripheralValid(ulPeripheral));
  597. //
  598. // Disable this peripheral in sleep mode.
  599. //
  600. HWREG(g_pulSCGCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) &=
  601. ~SYSCTL_PERIPH_MASK(ulPeripheral);
  602. }
  603. //*****************************************************************************
  604. //
  605. //! Enables a peripheral in deep-sleep mode.
  606. //!
  607. //! \param ulPeripheral is the peripheral to enable in deep-sleep mode.
  608. //!
  609. //! This function allows a peripheral to continue operating when the processor
  610. //! goes into deep-sleep mode. Since the clocking configuration of the device
  611. //! may change, not all peripherals can safely continue operating while the
  612. //! processor is in sleep mode. Those that must run at a particular frequency
  613. //! (such as a UART) will not work as expected if the clock changes. It is the
  614. //! responsibility of the caller to make sensible choices.
  615. //!
  616. //! Deep-sleep mode clocking of peripherals must be enabled via
  617. //! SysCtlPeripheralClockGating(); if disabled, the peripheral deep-sleep mode
  618. //! configuration is maintained but has no effect when deep-sleep mode is
  619. //! entered.
  620. //!
  621. //! The \e ulPeripheral parameter must be one of the following values:
  622. //! \b SYSCTL_PERIPH_ADC, \b SYSCTL_PERIPH_CAN0, \b SYSCTL_PERIPH_CAN1,
  623. //! \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0, \b SYSCTL_PERIPH_COMP1,
  624. //! \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_GPIOA,
  625. //! \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC, \b SYSCTL_PERIPH_GPIOD,
  626. //! \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF, \b SYSCTL_PERIPH_GPIOG,
  627. //! \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0,
  628. //! \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_PWM, \b SYSCTL_PERIPH_QEI0,
  629. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  630. //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
  631. //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  632. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, or
  633. //! \b SYSCTL_PERIPH_WDOG.
  634. //!
  635. //! \return None.
  636. //
  637. //*****************************************************************************
  638. void
  639. SysCtlPeripheralDeepSleepEnable(unsigned long ulPeripheral)
  640. {
  641. //
  642. // Check the arguments.
  643. //
  644. ASSERT(SysCtlPeripheralValid(ulPeripheral));
  645. //
  646. // Enable this peripheral in deep-sleep mode.
  647. //
  648. HWREG(g_pulDCGCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) |=
  649. SYSCTL_PERIPH_MASK(ulPeripheral);
  650. }
  651. //*****************************************************************************
  652. //
  653. //! Disables a peripheral in deep-sleep mode.
  654. //!
  655. //! \param ulPeripheral is the peripheral to disable in deep-sleep mode.
  656. //!
  657. //! This function causes a peripheral to stop operating when the processor goes
  658. //! into deep-sleep mode. Disabling peripherals while in deep-sleep mode helps
  659. //! to lower the current draw of the device, and can keep peripherals that
  660. //! require a particular clock frequency from operating when the clock changes
  661. //! as a result of entering deep-sleep mode. If enabled (via
  662. //! SysCtlPeripheralEnable()), the peripheral will automatically resume
  663. //! operation when the processor leaves deep-sleep mode, maintaining its entire
  664. //! state from before deep-sleep mode was entered.
  665. //!
  666. //! Deep-sleep mode clocking of peripherals must be enabled via
  667. //! SysCtlPeripheralClockGating(); if disabled, the peripheral deep-sleep mode
  668. //! configuration is maintained but has no effect when deep-sleep mode is
  669. //! entered.
  670. //!
  671. //! The \e ulPeripheral parameter must be one of the following values:
  672. //! \b SYSCTL_PERIPH_ADC, \b SYSCTL_PERIPH_CAN0, \b SYSCTL_PERIPH_CAN1,
  673. //! \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0, \b SYSCTL_PERIPH_COMP1,
  674. //! \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_GPIOA,
  675. //! \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC, \b SYSCTL_PERIPH_GPIOD,
  676. //! \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF, \b SYSCTL_PERIPH_GPIOG,
  677. //! \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0,
  678. //! \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_PWM, \b SYSCTL_PERIPH_QEI0,
  679. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  680. //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
  681. //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  682. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, or
  683. //! \b SYSCTL_PERIPH_WDOG.
  684. //!
  685. //! \return None.
  686. //
  687. //*****************************************************************************
  688. void
  689. SysCtlPeripheralDeepSleepDisable(unsigned long ulPeripheral)
  690. {
  691. //
  692. // Check the arguments.
  693. //
  694. ASSERT(SysCtlPeripheralValid(ulPeripheral));
  695. //
  696. // Disable this peripheral in deep-sleep mode.
  697. //
  698. HWREG(g_pulDCGCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) &=
  699. ~SYSCTL_PERIPH_MASK(ulPeripheral);
  700. }
  701. //*****************************************************************************
  702. //
  703. //! Controls peripheral clock gating in sleep and deep-sleep mode.
  704. //!
  705. //! \param bEnable is a boolean that is \b true if the sleep and deep-sleep
  706. //! peripheral configuration should be used and \b false if not.
  707. //!
  708. //! This function controls how peripherals are clocked when the processor goes
  709. //! into sleep or deep-sleep mode. By default, the peripherals are clocked the
  710. //! same as in run mode; if peripheral clock gating is enabled they are clocked
  711. //! according to the configuration set by SysCtlPeripheralSleepEnable(),
  712. //! SysCtlPeripheralSleepDisable(), SysCtlPeripheralDeepSleepEnable(), and
  713. //! SysCtlPeripheralDeepSleepDisable().
  714. //!
  715. //! \return None.
  716. //
  717. //*****************************************************************************
  718. void
  719. SysCtlPeripheralClockGating(tBoolean bEnable)
  720. {
  721. //
  722. // Enable peripheral clock gating as requested.
  723. //
  724. if(bEnable)
  725. {
  726. HWREG(SYSCTL_RCC) |= SYSCTL_RCC_ACG;
  727. }
  728. else
  729. {
  730. HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_ACG);
  731. }
  732. }
  733. //*****************************************************************************
  734. //
  735. //! Registers an interrupt handler for the system control interrupt.
  736. //!
  737. //! \param pfnHandler is a pointer to the function to be called when the system
  738. //! control interrupt occurs.
  739. //!
  740. //! This sets the handler to be called when a system control interrupt occurs.
  741. //! This will enable the global interrupt in the interrupt controller; specific
  742. //! system control interrupts must be enabled via SysCtlIntEnable(). It is the
  743. //! interrupt handler's responsibility to clear the interrupt source via
  744. //! SysCtlIntClear().
  745. //!
  746. //! System control can generate interrupts when the PLL achieves lock, if the
  747. //! internal LDO current limit is exceeded, if the internal oscillator fails,
  748. //! if the main oscillator fails, if the internal LDO output voltage droops too
  749. //! much, if the external voltage droops too much, or if the PLL fails.
  750. //!
  751. //! \sa IntRegister() for important information about registering interrupt
  752. //! handlers.
  753. //!
  754. //! \return None.
  755. //
  756. //*****************************************************************************
  757. void
  758. SysCtlIntRegister(void (*pfnHandler)(void))
  759. {
  760. //
  761. // Register the interrupt handler, returning an error if an error occurs.
  762. //
  763. IntRegister(INT_SYSCTL, pfnHandler);
  764. //
  765. // Enable the system control interrupt.
  766. //
  767. IntEnable(INT_SYSCTL);
  768. }
  769. //*****************************************************************************
  770. //
  771. //! Unregisters the interrupt handler for the system control interrupt.
  772. //!
  773. //! This function will clear the handler to be called when a system control
  774. //! interrupt occurs. This will also mask off the interrupt in the interrupt
  775. //! controller so that the interrupt handler no longer is called.
  776. //!
  777. //! \sa IntRegister() for important information about registering interrupt
  778. //! handlers.
  779. //!
  780. //! \return None.
  781. //
  782. //*****************************************************************************
  783. void
  784. SysCtlIntUnregister(void)
  785. {
  786. //
  787. // Disable the interrupt.
  788. //
  789. IntDisable(INT_SYSCTL);
  790. //
  791. // Unregister the interrupt handler.
  792. //
  793. IntUnregister(INT_SYSCTL);
  794. }
  795. //*****************************************************************************
  796. //
  797. //! Enables individual system control interrupt sources.
  798. //!
  799. //! \param ulInts is a bit mask of the interrupt sources to be enabled. Must
  800. //! be a logical OR of \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_CUR_LIMIT,
  801. //! \b SYSCTL_INT_IOSC_FAIL, \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_POR,
  802. //! \b SYSCTL_INT_BOR, and/or \b SYSCTL_INT_PLL_FAIL.
  803. //!
  804. //! Enables the indicated system control interrupt sources. Only the sources
  805. //! that are enabled can be reflected to the processor interrupt; disabled
  806. //! sources have no effect on the processor.
  807. //!
  808. //! \return None.
  809. //
  810. //*****************************************************************************
  811. void
  812. SysCtlIntEnable(unsigned long ulInts)
  813. {
  814. //
  815. // Enable the specified interrupts.
  816. //
  817. HWREG(SYSCTL_IMC) |= ulInts;
  818. }
  819. //*****************************************************************************
  820. //
  821. //! Disables individual system control interrupt sources.
  822. //!
  823. //! \param ulInts is a bit mask of the interrupt sources to be disabled. Must
  824. //! be a logical OR of \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_CUR_LIMIT,
  825. //! \b SYSCTL_INT_IOSC_FAIL, \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_POR,
  826. //! \b SYSCTL_INT_BOR, and/or \b SYSCTL_INT_PLL_FAIL.
  827. //!
  828. //! Disables the indicated system control interrupt sources. Only the sources
  829. //! that are enabled can be reflected to the processor interrupt; disabled
  830. //! sources have no effect on the processor.
  831. //!
  832. //! \return None.
  833. //
  834. //*****************************************************************************
  835. void
  836. SysCtlIntDisable(unsigned long ulInts)
  837. {
  838. //
  839. // Disable the specified interrupts.
  840. //
  841. HWREG(SYSCTL_IMC) &= ~(ulInts);
  842. }
  843. //*****************************************************************************
  844. //
  845. //! Clears system control interrupt sources.
  846. //!
  847. //! \param ulInts is a bit mask of the interrupt sources to be cleared. Must
  848. //! be a logical OR of \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_CUR_LIMIT,
  849. //! \b SYSCTL_INT_IOSC_FAIL, \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_POR,
  850. //! \b SYSCTL_INT_BOR, and/or \b SYSCTL_INT_PLL_FAIL.
  851. //!
  852. //! The specified system control interrupt sources are cleared, so that they no
  853. //! longer assert. This must be done in the interrupt handler to keep it from
  854. //! being called again immediately upon exit.
  855. //!
  856. //! \note Since there is a write buffer in the Cortex-M3 processor, it may take
  857. //! several clock cycles before the interrupt source is actually cleared.
  858. //! Therefore, it is recommended that the interrupt source be cleared early in
  859. //! the interrupt handler (as opposed to the very last action) to avoid
  860. //! returning from the interrupt handler before the interrupt source is
  861. //! actually cleared. Failure to do so may result in the interrupt handler
  862. //! being immediately reentered (since NVIC still sees the interrupt source
  863. //! asserted).
  864. //!
  865. //! \return None.
  866. //
  867. //*****************************************************************************
  868. void
  869. SysCtlIntClear(unsigned long ulInts)
  870. {
  871. //
  872. // Clear the requested interrupt sources.
  873. //
  874. HWREG(SYSCTL_MISC) = ulInts;
  875. }
  876. //*****************************************************************************
  877. //
  878. //! Gets the current interrupt status.
  879. //!
  880. //! \param bMasked is false if the raw interrupt status is required and true if
  881. //! the masked interrupt status is required.
  882. //!
  883. //! This returns the interrupt status for the system controller. Either the
  884. //! raw interrupt status or the status of interrupts that are allowed to
  885. //! reflect to the processor can be returned.
  886. //!
  887. //! \return The current interrupt status, enumerated as a bit field of
  888. //! \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_CUR_LIMIT, \b SYSCTL_INT_IOSC_FAIL,
  889. //! \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_POR, \b SYSCTL_INT_BOR, and
  890. //! \b SYSCTL_INT_PLL_FAIL.
  891. //
  892. //*****************************************************************************
  893. unsigned long
  894. SysCtlIntStatus(tBoolean bMasked)
  895. {
  896. //
  897. // Return either the interrupt status or the raw interrupt status as
  898. // requested.
  899. //
  900. if(bMasked)
  901. {
  902. return(HWREG(SYSCTL_MISC));
  903. }
  904. else
  905. {
  906. return(HWREG(SYSCTL_RIS));
  907. }
  908. }
  909. //*****************************************************************************
  910. //
  911. //! Sets the output voltage of the LDO.
  912. //!
  913. //! \param ulVoltage is the required output voltage from the LDO. Must be one
  914. //! of \b SYSCTL_LDO_2_25V, \b SYSCTL_LDO_2_30V, \b SYSCTL_LDO_2_35V,
  915. //! \b SYSCTL_LDO_2_40V, \b SYSCTL_LDO_2_45V, \b SYSCTL_LDO_2_50V,
  916. //! \b SYSCTL_LDO_2_55V, \b SYSCTL_LDO_2_60V, \b SYSCTL_LDO_2_65V,
  917. //! \b SYSCTL_LDO_2_70V, or \b SYSCTL_LDO_2_75V.
  918. //!
  919. //! This function sets the output voltage of the LDO. The default voltage is
  920. //! 2.5 V; it can be adjusted +/- 10%.
  921. //!
  922. //! \return None.
  923. //
  924. //*****************************************************************************
  925. void
  926. SysCtlLDOSet(unsigned long ulVoltage)
  927. {
  928. //
  929. // Check the arguments.
  930. //
  931. ASSERT((ulVoltage == SYSCTL_LDO_2_25V) ||
  932. (ulVoltage == SYSCTL_LDO_2_30V) ||
  933. (ulVoltage == SYSCTL_LDO_2_35V) ||
  934. (ulVoltage == SYSCTL_LDO_2_40V) ||
  935. (ulVoltage == SYSCTL_LDO_2_45V) ||
  936. (ulVoltage == SYSCTL_LDO_2_50V) ||
  937. (ulVoltage == SYSCTL_LDO_2_55V) ||
  938. (ulVoltage == SYSCTL_LDO_2_60V) ||
  939. (ulVoltage == SYSCTL_LDO_2_65V) ||
  940. (ulVoltage == SYSCTL_LDO_2_70V) ||
  941. (ulVoltage == SYSCTL_LDO_2_75V));
  942. //
  943. // Set the LDO voltage to the requested value.
  944. //
  945. HWREG(SYSCTL_LDOPCTL) = ulVoltage;
  946. }
  947. //*****************************************************************************
  948. //
  949. //! Gets the output voltage of the LDO.
  950. //!
  951. //! This function determines the output voltage of the LDO, as specified by the
  952. //! control register.
  953. //!
  954. //! \return Returns the current voltage of the LDO; will be one of
  955. //! \b SYSCTL_LDO_2_25V, \b SYSCTL_LDO_2_30V, \b SYSCTL_LDO_2_35V,
  956. //! \b SYSCTL_LDO_2_40V, \b SYSCTL_LDO_2_45V, \b SYSCTL_LDO_2_50V,
  957. //! \b SYSCTL_LDO_2_55V, \b SYSCTL_LDO_2_60V, \b SYSCTL_LDO_2_65V,
  958. //! \b SYSCTL_LDO_2_70V, or \b SYSCTL_LDO_2_75V.
  959. //
  960. //*****************************************************************************
  961. unsigned long
  962. SysCtlLDOGet(void)
  963. {
  964. //
  965. // Return the LDO voltage setting.
  966. //
  967. return(HWREG(SYSCTL_LDOPCTL));
  968. }
  969. //*****************************************************************************
  970. //
  971. //! Configures the LDO failure control.
  972. //!
  973. //! \param ulConfig is the required LDO failure control setting; can be either
  974. //! \b SYSCTL_LDOCFG_ARST or \b SYSCTL_LDOCFG_NORST.
  975. //!
  976. //! This function allows the LDO to be configured to cause a processor reset
  977. //! when the output voltage becomes unregulated.
  978. //!
  979. //! The LDO failure control is only available on Sandstorm-class devices.
  980. //!
  981. //! \return None.
  982. //
  983. //*****************************************************************************
  984. void
  985. SysCtlLDOConfigSet(unsigned long ulConfig)
  986. {
  987. //
  988. // Check the arguments.
  989. //
  990. ASSERT((ulConfig == SYSCTL_LDOCFG_ARST) ||
  991. (ulConfig == SYSCTL_LDOCFG_NORST));
  992. //
  993. // Set the reset control as requested.
  994. //
  995. HWREG(SYSCTL_LDOARST) = ulConfig;
  996. }
  997. //*****************************************************************************
  998. //
  999. //! Resets the device.
  1000. //!
  1001. //! This function will perform a software reset of the entire device. The
  1002. //! processor and all peripherals will be reset and all device registers will
  1003. //! return to their default values (with the exception of the reset cause
  1004. //! register, which will maintain its current value but have the software reset
  1005. //! bit set as well).
  1006. //!
  1007. //! \return This function does not return.
  1008. //
  1009. //*****************************************************************************
  1010. void
  1011. SysCtlReset(void)
  1012. {
  1013. //
  1014. // Perform a software reset request. This will cause the device to reset,
  1015. // no further code will be executed.
  1016. //
  1017. HWREG(NVIC_APINT) = NVIC_APINT_VECTKEY | NVIC_APINT_SYSRESETREQ;
  1018. //
  1019. // The device should have reset, so this should never be reached. Just in
  1020. // case, loop forever.
  1021. //
  1022. while(1)
  1023. {
  1024. }
  1025. }
  1026. //*****************************************************************************
  1027. //
  1028. //! Puts the processor into sleep mode.
  1029. //!
  1030. //! This function places the processor into sleep mode; it will not return
  1031. //! until the processor returns to run mode. The peripherals that are enabled
  1032. //! via SysCtlPeripheralSleepEnable() continue to operate and can wake up the
  1033. //! processor (if automatic clock gating is enabled with
  1034. //! SysCtlPeripheralClockGating(), otherwise all peripherals continue to
  1035. //! operate).
  1036. //!
  1037. //! \return None.
  1038. //
  1039. //*****************************************************************************
  1040. void
  1041. SysCtlSleep(void)
  1042. {
  1043. //
  1044. // Wait for an interrupt.
  1045. //
  1046. CPUwfi();
  1047. }
  1048. //*****************************************************************************
  1049. //
  1050. //! Puts the processor into deep-sleep mode.
  1051. //!
  1052. //! This function places the processor into deep-sleep mode; it will not return
  1053. //! until the processor returns to run mode. The peripherals that are enabled
  1054. //! via SysCtlPeripheralDeepSleepEnable() continue to operate and can wake up
  1055. //! the processor (if automatic clock gating is enabled with
  1056. //! SysCtlPeripheralClockGating(), otherwise all peripherals continue to
  1057. //! operate).
  1058. //!
  1059. //! \return None.
  1060. //
  1061. //*****************************************************************************
  1062. void
  1063. SysCtlDeepSleep(void)
  1064. {
  1065. //
  1066. // Enable deep-sleep.
  1067. //
  1068. HWREG(NVIC_SYS_CTRL) |= NVIC_SYS_CTRL_SLEEPDEEP;
  1069. //
  1070. // Wait for an interrupt.
  1071. //
  1072. CPUwfi();
  1073. //
  1074. // Disable deep-sleep so that a future sleep will work correctly.
  1075. //
  1076. HWREG(NVIC_SYS_CTRL) &= ~(NVIC_SYS_CTRL_SLEEPDEEP);
  1077. }
  1078. //*****************************************************************************
  1079. //
  1080. //! Gets the reason for a reset.
  1081. //!
  1082. //! This function will return the reason(s) for a reset. Since the reset
  1083. //! reasons are sticky until either cleared by software or an external reset,
  1084. //! multiple reset reasons may be returned if multiple resets have occurred.
  1085. //! The reset reason will be a logical OR of \b SYSCTL_CAUSE_LDO,
  1086. //! \b SYSCTL_CAUSE_SW, \b SYSCTL_CAUSE_WDOG, \b SYSCTL_CAUSE_BOR,
  1087. //! \b SYSCTL_CAUSE_POR, and/or \b SYSCTL_CAUSE_EXT.
  1088. //!
  1089. //! \return Returns the reason(s) for a reset.
  1090. //
  1091. //*****************************************************************************
  1092. unsigned long
  1093. SysCtlResetCauseGet(void)
  1094. {
  1095. //
  1096. // Return the reset reasons.
  1097. //
  1098. return(HWREG(SYSCTL_RESC));
  1099. }
  1100. //*****************************************************************************
  1101. //
  1102. //! Clears reset reasons.
  1103. //!
  1104. //! \param ulCauses are the reset causes to be cleared; must be a logical OR of
  1105. //! \b SYSCTL_CAUSE_LDO, \b SYSCTL_CAUSE_SW, \b SYSCTL_CAUSE_WDOG,
  1106. //! \b SYSCTL_CAUSE_BOR, \b SYSCTL_CAUSE_POR, and/or \b SYSCTL_CAUSE_EXT.
  1107. //!
  1108. //! This function clears the specified sticky reset reasons. Once cleared,
  1109. //! another reset for the same reason can be detected, and a reset for a
  1110. //! different reason can be distinguished (instead of having two reset causes
  1111. //! set). If the reset reason is used by an application, all reset causes
  1112. //! should be cleared after they are retrieved with SysCtlResetCauseGet().
  1113. //!
  1114. //! \return None.
  1115. //
  1116. //*****************************************************************************
  1117. void
  1118. SysCtlResetCauseClear(unsigned long ulCauses)
  1119. {
  1120. //
  1121. // Clear the given reset reasons.
  1122. //
  1123. HWREG(SYSCTL_RESC) &= ~(ulCauses);
  1124. }
  1125. //*****************************************************************************
  1126. //
  1127. //! Configures the brown-out control.
  1128. //!
  1129. //! \param ulConfig is the desired configuration of the brown-out control.
  1130. //! Must be the logical OR of \b SYSCTL_BOR_RESET and/or
  1131. //! \b SYSCTL_BOR_RESAMPLE.
  1132. //! \param ulDelay is the number of internal oscillator cycles to wait before
  1133. //! resampling an asserted brown-out signal. This value only has meaning when
  1134. //! \b SYSCTL_BOR_RESAMPLE is set and must be less than 8192.
  1135. //!
  1136. //! This function configures how the brown-out control operates. It can detect
  1137. //! a brown-out by looking at only the brown-out output, or it can wait for it
  1138. //! to be active for two consecutive samples separated by a configurable time.
  1139. //! When it detects a brown-out condition, it can either reset the device or
  1140. //! generate a processor interrupt.
  1141. //!
  1142. //! \return None.
  1143. //
  1144. //*****************************************************************************
  1145. void
  1146. SysCtlBrownOutConfigSet(unsigned long ulConfig, unsigned long ulDelay)
  1147. {
  1148. //
  1149. // Check the arguments.
  1150. //
  1151. ASSERT(!(ulConfig & ~(SYSCTL_BOR_RESET | SYSCTL_BOR_RESAMPLE)));
  1152. ASSERT(ulDelay < 8192);
  1153. //
  1154. // Configure the brown-out reset control.
  1155. //
  1156. HWREG(SYSCTL_PBORCTL) = (ulDelay << SYSCTL_PBORCTL_BORTIM_S) | ulConfig;
  1157. }
  1158. //*****************************************************************************
  1159. //
  1160. //! Provides a small delay.
  1161. //!
  1162. //! \param ulCount is the number of delay loop iterations to perform.
  1163. //!
  1164. //! This function provides a means of generating a constant length delay. It
  1165. //! is written in assembly to keep the delay consistent across tool chains,
  1166. //! avoiding the need to tune the delay based on the tool chain in use.
  1167. //!
  1168. //! The loop takes 3 cycles/loop.
  1169. //!
  1170. //! \return None.
  1171. //
  1172. //*****************************************************************************
  1173. #if defined(ewarm) || defined(DOXYGEN)
  1174. void
  1175. SysCtlDelay(unsigned long ulCount)
  1176. {
  1177. __asm(" subs r0, #1\n"
  1178. " bne.n SysCtlDelay\n"
  1179. " bx lr");
  1180. }
  1181. #endif
  1182. #if defined(codered) || defined(gcc) || defined(sourcerygxx)
  1183. void __attribute__((naked))
  1184. SysCtlDelay(unsigned long ulCount)
  1185. {
  1186. __asm(" subs r0, #1\n"
  1187. " bne SysCtlDelay\n"
  1188. " bx lr");
  1189. }
  1190. #endif
  1191. #if defined(rvmdk) || defined(__ARMCC_VERSION)
  1192. __asm void
  1193. SysCtlDelay(unsigned long ulCount)
  1194. {
  1195. subs r0, #1;
  1196. bne SysCtlDelay;
  1197. bx lr;
  1198. }
  1199. #endif
  1200. //*****************************************************************************
  1201. //
  1202. //! Sets the clocking of the device.
  1203. //!
  1204. //! \param ulConfig is the required configuration of the device clocking.
  1205. //!
  1206. //! This function configures the clocking of the device. The input crystal
  1207. //! frequency, oscillator to be used, use of the PLL, and the system clock
  1208. //! divider are all configured with this function.
  1209. //!
  1210. //! The \e ulConfig parameter is the logical OR of several different values,
  1211. //! many of which are grouped into sets where only one can be chosen.
  1212. //!
  1213. //! The system clock divider is chosen with one of the following values:
  1214. //! \b SYSCTL_SYSDIV_1, \b SYSCTL_SYSDIV_2, \b SYSCTL_SYSDIV_3, ...
  1215. //! \b SYSCTL_SYSDIV_64. Only \b SYSCTL_SYSDIV_1 through \b SYSCTL_SYSDIV_16
  1216. //! are valid on Sandstorm-class devices.
  1217. //!
  1218. //! The use of the PLL is chosen with either \b SYSCTL_USE_PLL or
  1219. //! \b SYSCTL_USE_OSC.
  1220. //!
  1221. //! The external crystal frequency is chosen with one of the following values:
  1222. //! \b SYSCTL_XTAL_1MHZ, \b SYSCTL_XTAL_1_84MHZ, \b SYSCTL_XTAL_2MHZ,
  1223. //! \b SYSCTL_XTAL_2_45MHZ, \b SYSCTL_XTAL_3_57MHZ, \b SYSCTL_XTAL_3_68MHZ,
  1224. //! \b SYSCTL_XTAL_4MHZ, \b SYSCTL_XTAL_4_09MHZ, \b SYSCTL_XTAL_4_91MHZ,
  1225. //! \b SYSCTL_XTAL_5MHZ, \b SYSCTL_XTAL_5_12MHZ, \b SYSCTL_XTAL_6MHZ,
  1226. //! \b SYSCTL_XTAL_6_14MHZ, \b SYSCTL_XTAL_7_37MHZ, \b SYSCTL_XTAL_8MHZ,
  1227. //! \b SYSCTL_XTAL_8_19MHZ, \b SYSCTL_XTAL_10MHZ, \b SYSCTL_XTAL_12MHZ,
  1228. //! \b SYSCTL_XTAL_12_2MHZ, \b SYSCTL_XTAL_13_5MHZ, \b SYSCTL_XTAL_14_3MHZ,
  1229. //! \b SYSCTL_XTAL_16MHZ, or \b SYSCTL_XTAL_16_3MHZ. Values below
  1230. //! \b SYSCTL_XTAL_3_57MHZ are not valid when the PLL is in operation. On
  1231. //! Sandstorm- and Fury-class devices, values above \b SYSCTL_XTAL_8_19MHZ are
  1232. //! not valid.
  1233. //!
  1234. //! The oscillator source is chosen with one of the following values:
  1235. //! \b SYSCTL_OSC_MAIN, \b SYSCTL_OSC_INT, \b SYSCTL_OSC_INT4,
  1236. //! \b SYSCTL_OSC_INT30, or \b SYSCTL_OSC_EXT32. On Sandstorm-class devices,
  1237. //! \b SYSCTL_OSC_INT30 and \b SYSCTL_OSC_EXT32 are not valid.
  1238. //! \b SYSCTL_OSC_EXT32 is only available on devices with the hibernate module,
  1239. //! and then only when the hibernate module has been enabled.
  1240. //!
  1241. //! The internal and main oscillators are disabled with the
  1242. //! \b SYSCTL_INT_OSC_DIS and \b SYSCTL_MAIN_OSC_DIS flags, respectively.
  1243. //! The external oscillator must be enabled in order to use an external clock
  1244. //! source. Note that attempts to disable the oscillator used to clock the
  1245. //! device will be prevented by the hardware.
  1246. //!
  1247. //! To clock the system from an external source (such as an external crystal
  1248. //! oscillator), use \b SYSCTL_USE_OSC \b | \b SYSCTL_OSC_MAIN. To clock the
  1249. //! system from the main oscillator, use \b SYSCTL_USE_OSC \b |
  1250. //! \b SYSCTL_OSC_MAIN. To clock the system from the PLL, use
  1251. //! \b SYSCTL_USE_PLL \b | \b SYSCTL_OSC_MAIN, and select the appropriate
  1252. //! crystal with one of the \b SYSCTL_XTAL_xxx values.
  1253. //!
  1254. //! \note If selecting the PLL as the system clock source (that is, via
  1255. //! \b SYSCTL_USE_PLL), this function will poll the PLL lock interrupt to
  1256. //! determine when the PLL has locked. If an interrupt handler for the
  1257. //! system control interrupt is in place, and it responds to and clears the
  1258. //! PLL lock interrupt, this function will delay until its timeout has occurred
  1259. //! instead of completing as soon as PLL lock is achieved.
  1260. //!
  1261. //! \return None.
  1262. //
  1263. //*****************************************************************************
  1264. void
  1265. SysCtlClockSet(unsigned long ulConfig)
  1266. {
  1267. unsigned long ulDelay, ulRCC, ulRCC2;
  1268. //
  1269. // See if this is a Sandstorm-class device and clocking features from newer
  1270. // devices were requested.
  1271. //
  1272. if(CLASS_IS_SANDSTORM && (ulConfig & SYSCTL_RCC2_USERCC2))
  1273. {
  1274. //
  1275. // Return without changing the clocking since the requested
  1276. // configuration can not be achieved.
  1277. //
  1278. return;
  1279. }
  1280. //
  1281. // Get the current value of the RCC and RCC2 registers. If using a
  1282. // Sandstorm-class device, the RCC2 register will read back as zero and the
  1283. // writes to it from within this function will be ignored.
  1284. //
  1285. ulRCC = HWREG(SYSCTL_RCC);
  1286. ulRCC2 = HWREG(SYSCTL_RCC2);
  1287. //
  1288. // Bypass the PLL and system clock dividers for now.
  1289. //
  1290. ulRCC |= SYSCTL_RCC_BYPASS;
  1291. ulRCC &= ~(SYSCTL_RCC_USESYSDIV);
  1292. ulRCC2 |= SYSCTL_RCC2_BYPASS2;
  1293. //
  1294. // Write the new RCC value.
  1295. //
  1296. HWREG(SYSCTL_RCC) = ulRCC;
  1297. HWREG(SYSCTL_RCC2) = ulRCC2;
  1298. //
  1299. // See if either oscillator needs to be enabled.
  1300. //
  1301. if(((ulRCC & SYSCTL_RCC_IOSCDIS) && !(ulConfig & SYSCTL_RCC_IOSCDIS)) ||
  1302. ((ulRCC & SYSCTL_RCC_MOSCDIS) && !(ulConfig & SYSCTL_RCC_MOSCDIS)))
  1303. {
  1304. //
  1305. // Make sure that the required oscillators are enabled. For now, the
  1306. // previously enabled oscillators must be enabled along with the newly
  1307. // requested oscillators.
  1308. //
  1309. ulRCC &= (~(SYSCTL_RCC_IOSCDIS | SYSCTL_RCC_MOSCDIS) |
  1310. (ulConfig & (SYSCTL_RCC_IOSCDIS | SYSCTL_RCC_MOSCDIS)));
  1311. //
  1312. // Write the new RCC value.
  1313. //
  1314. HWREG(SYSCTL_RCC) = ulRCC;
  1315. //
  1316. // Wait for a bit, giving the oscillator time to stabilize. The number
  1317. // of iterations is adjusted based on the current clock source; a
  1318. // smaller number of iterations is required for slower clock rates.
  1319. //
  1320. if(((ulRCC2 & SYSCTL_RCC2_USERCC2) &&
  1321. (((ulRCC2 & SYSCTL_RCC2_OSCSRC2_M) == SYSCTL_RCC2_OSCSRC2_30) ||
  1322. ((ulRCC2 & SYSCTL_RCC2_OSCSRC2_M) == SYSCTL_RCC2_OSCSRC2_32))) ||
  1323. (!(ulRCC2 & SYSCTL_RCC2_USERCC2) &&
  1324. ((ulRCC & SYSCTL_RCC_OSCSRC_M) == SYSCTL_RCC_OSCSRC_30)))
  1325. {
  1326. //
  1327. // Delay for 4096 iterations.
  1328. //
  1329. SysCtlDelay(4096);
  1330. }
  1331. else
  1332. {
  1333. //
  1334. // Delay for 524,288 iterations.
  1335. //
  1336. SysCtlDelay(524288);
  1337. }
  1338. }
  1339. //
  1340. // Set the new crystal value, oscillator source, and PLL configuration.
  1341. // Since the OSCSRC2 field in RCC2 overlaps the XTAL field in RCC, the
  1342. // OSCSRC field has a special encoding within ulConfig to avoid the
  1343. // overlap.
  1344. //
  1345. ulRCC &= ~(SYSCTL_RCC_XTAL_M | SYSCTL_RCC_OSCSRC_M |
  1346. SYSCTL_RCC_PWRDN | SYSCTL_RCC_OEN);
  1347. ulRCC |= ulConfig & (SYSCTL_RCC_XTAL_M | SYSCTL_RCC_OSCSRC_M |
  1348. SYSCTL_RCC_PWRDN | SYSCTL_RCC_OEN);
  1349. ulRCC2 &= ~(SYSCTL_RCC2_USERCC2 | SYSCTL_RCC2_OSCSRC2_M |
  1350. SYSCTL_RCC2_PWRDN2);
  1351. ulRCC2 |= ulConfig & (SYSCTL_RCC2_USERCC2 | SYSCTL_RCC_OSCSRC_M |
  1352. SYSCTL_RCC2_PWRDN2);
  1353. ulRCC2 |= (ulConfig & 0x00000008) << 3;
  1354. //
  1355. // Clear the PLL lock interrupt.
  1356. //
  1357. HWREG(SYSCTL_MISC) = SYSCTL_INT_PLL_LOCK;
  1358. //
  1359. // Write the new RCC value.
  1360. //
  1361. if(ulRCC2 & SYSCTL_RCC2_USERCC2)
  1362. {
  1363. HWREG(SYSCTL_RCC2) = ulRCC2;
  1364. HWREG(SYSCTL_RCC) = ulRCC;
  1365. }
  1366. else
  1367. {
  1368. HWREG(SYSCTL_RCC) = ulRCC;
  1369. HWREG(SYSCTL_RCC2) = ulRCC2;
  1370. }
  1371. //
  1372. // Wait for a bit so that new crystal value and oscillator source can take
  1373. // effect.
  1374. //
  1375. SysCtlDelay(16);
  1376. //
  1377. // Set the requested system divider and disable the appropriate
  1378. // oscillators. This will not get written immediately.
  1379. //
  1380. ulRCC &= ~(SYSCTL_RCC_SYSDIV_M | SYSCTL_RCC_USESYSDIV |
  1381. SYSCTL_RCC_IOSCDIS | SYSCTL_RCC_MOSCDIS);
  1382. ulRCC |= ulConfig & (SYSCTL_RCC_SYSDIV_M | SYSCTL_RCC_USESYSDIV |
  1383. SYSCTL_RCC_IOSCDIS | SYSCTL_RCC_MOSCDIS);
  1384. ulRCC2 &= ~(SYSCTL_RCC2_SYSDIV2_M);
  1385. ulRCC2 |= ulConfig & SYSCTL_RCC2_SYSDIV2_M;
  1386. if(ulConfig & SYSCTL_RCC2_USEFRACT)
  1387. {
  1388. ulRCC |= SYSCTL_RCC_USESYSDIV;
  1389. ulRCC2 &= ~(SYSCTL_RCC_USESYSDIV);
  1390. ulRCC2 |= ulConfig & (SYSCTL_RCC2_USEFRACT | SYSCTL_RCC2_FRACT);
  1391. }
  1392. else
  1393. {
  1394. ulRCC2 &= ~(SYSCTL_RCC2_USEFRACT);
  1395. }
  1396. //
  1397. // See if the PLL output is being used to clock the system.
  1398. //
  1399. if(!(ulConfig & SYSCTL_RCC_BYPASS))
  1400. {
  1401. //
  1402. // Wait until the PLL has locked.
  1403. //
  1404. for(ulDelay = 32768; ulDelay > 0; ulDelay--)
  1405. {
  1406. if(HWREG(SYSCTL_RIS) & SYSCTL_INT_PLL_LOCK)
  1407. {
  1408. break;
  1409. }
  1410. }
  1411. //
  1412. // Enable use of the PLL.
  1413. //
  1414. ulRCC &= ~(SYSCTL_RCC_BYPASS);
  1415. ulRCC2 &= ~(SYSCTL_RCC2_BYPASS2);
  1416. }
  1417. //
  1418. // Write the final RCC value.
  1419. //
  1420. HWREG(SYSCTL_RCC) = ulRCC;
  1421. HWREG(SYSCTL_RCC2) = ulRCC2;
  1422. //
  1423. // Delay for a little bit so that the system divider takes effect.
  1424. //
  1425. SysCtlDelay(16);
  1426. }
  1427. //*****************************************************************************
  1428. //
  1429. //! Gets the processor clock rate.
  1430. //!
  1431. //! This function determines the clock rate of the processor clock. This is
  1432. //! also the clock rate of all the peripheral modules (with the exception of
  1433. //! PWM, which has its own clock divider).
  1434. //!
  1435. //! \note This will not return accurate results if SysCtlClockSet() has not
  1436. //! been called to configure the clocking of the device, or if the device is
  1437. //! directly clocked from a crystal (or a clock source) that is not one of the
  1438. //! supported crystal frequencies. In the later case, this function should be
  1439. //! modified to directly return the correct system clock rate.
  1440. //!
  1441. //! \return The processor clock rate.
  1442. //
  1443. //*****************************************************************************
  1444. unsigned long
  1445. SysCtlClockGet(void)
  1446. {
  1447. unsigned long ulRCC, ulRCC2, ulPLL, ulClk;
  1448. //
  1449. // Read RCC and RCC2. For Sandstorm-class devices (which do not have
  1450. // RCC2), the RCC2 read will return 0, which indicates that RCC2 is
  1451. // disabled (since the SYSCTL_RCC2_USERCC2 bit is clear).
  1452. //
  1453. ulRCC = HWREG(SYSCTL_RCC);
  1454. ulRCC2 = HWREG(SYSCTL_RCC2);
  1455. //
  1456. // Get the base clock rate.
  1457. //
  1458. switch((ulRCC2 & SYSCTL_RCC2_USERCC2) ?
  1459. (ulRCC2 & SYSCTL_RCC2_OSCSRC2_M) :
  1460. (ulRCC & SYSCTL_RCC_OSCSRC_M))
  1461. {
  1462. //
  1463. // The main oscillator is the clock source. Determine its rate from
  1464. // the crystal setting field.
  1465. //
  1466. case SYSCTL_RCC_OSCSRC_MAIN:
  1467. {
  1468. ulClk = g_pulXtals[(ulRCC & SYSCTL_RCC_XTAL_M) >>
  1469. SYSCTL_RCC_XTAL_S];
  1470. break;
  1471. }
  1472. //
  1473. // The internal oscillator is the source clock.
  1474. //
  1475. case SYSCTL_RCC_OSCSRC_INT:
  1476. {
  1477. //
  1478. // See if this is a Sandstorm-class or Fury-class device.
  1479. //
  1480. if(CLASS_IS_SANDSTORM)
  1481. {
  1482. //
  1483. // The internal oscillator on a Sandstorm-class device is
  1484. // 15 MHz +/- 50%.
  1485. //
  1486. ulClk = 15000000;
  1487. }
  1488. else if((CLASS_IS_FURY && REVISION_IS_A2) ||
  1489. (CLASS_IS_DUSTDEVIL && REVISION_IS_A0))
  1490. {
  1491. //
  1492. // The internal oscillator on a rev A2 Fury-class device and a
  1493. // rev A0 Dustdevil-class device is 12 MHz +/- 30%.
  1494. //
  1495. ulClk = 12000000;
  1496. }
  1497. else
  1498. {
  1499. //
  1500. // The internal oscillator on all other devices is 16 MHz.
  1501. //
  1502. ulClk = 16000000;
  1503. }
  1504. break;
  1505. }
  1506. //
  1507. // The internal oscillator divided by four is the source clock.
  1508. //
  1509. case SYSCTL_RCC_OSCSRC_INT4:
  1510. {
  1511. //
  1512. // See if this is a Sandstorm-class or Fury-class device.
  1513. //
  1514. if(CLASS_IS_SANDSTORM)
  1515. {
  1516. //
  1517. // The internal oscillator on a Sandstorm-class device is
  1518. // 15 MHz +/- 50%.
  1519. //
  1520. ulClk = 15000000 / 4;
  1521. }
  1522. else if((CLASS_IS_FURY && REVISION_IS_A2) ||
  1523. (CLASS_IS_DUSTDEVIL && REVISION_IS_A0))
  1524. {
  1525. //
  1526. // The internal oscillator on a rev A2 Fury-class device and a
  1527. // rev A0 Dustdevil-class device is 12 MHz +/- 30%.
  1528. //
  1529. ulClk = 12000000 / 4;
  1530. }
  1531. else
  1532. {
  1533. //
  1534. // The internal oscillator on a Tempest-class device is 16 MHz.
  1535. //
  1536. ulClk = 16000000 / 4;
  1537. }
  1538. break;
  1539. }
  1540. //
  1541. // The internal 30 KHz oscillator is the source clock.
  1542. //
  1543. case SYSCTL_RCC_OSCSRC_30:
  1544. {
  1545. //
  1546. // The internal 30 KHz oscillator has an accuracy of +/- 30%.
  1547. //
  1548. ulClk = 30000;
  1549. break;
  1550. }
  1551. //
  1552. // The 4.19 MHz clock from the hibernate module is the clock source.
  1553. //
  1554. case SYSCTL_RCC2_OSCSRC2_419:
  1555. {
  1556. ulClk = 4194304;
  1557. break;
  1558. }
  1559. //
  1560. // The 32 KHz clock from the hibernate module is the source clock.
  1561. //
  1562. case SYSCTL_RCC2_OSCSRC2_32:
  1563. {
  1564. ulClk = 32768;
  1565. break;
  1566. }
  1567. //
  1568. // An unknown setting, so return a zero clock (that is, an unknown
  1569. // clock rate).
  1570. //
  1571. default:
  1572. {
  1573. return(0);
  1574. }
  1575. }
  1576. //
  1577. // See if the PLL is being used.
  1578. //
  1579. if(((ulRCC2 & SYSCTL_RCC2_USERCC2) && !(ulRCC2 & SYSCTL_RCC2_BYPASS2)) ||
  1580. (!(ulRCC2 & SYSCTL_RCC2_USERCC2) && !(ulRCC & SYSCTL_RCC_BYPASS)))
  1581. {
  1582. //
  1583. // Get the PLL configuration.
  1584. //
  1585. ulPLL = HWREG(SYSCTL_PLLCFG);
  1586. //
  1587. // See if this is a Sandstorm-class or Fury-class device.
  1588. //
  1589. if(CLASS_IS_SANDSTORM)
  1590. {
  1591. //
  1592. // Compute the PLL output frequency based on its input frequency.
  1593. // The formula for a Sandstorm-class devices is
  1594. // "(xtal * (f + 2)) / (r + 2)".
  1595. //
  1596. ulClk = ((ulClk * (((ulPLL & SYSCTL_PLLCFG_F_M) >>
  1597. SYSCTL_PLLCFG_F_S) + 2)) /
  1598. (((ulPLL & SYSCTL_PLLCFG_R_M) >>
  1599. SYSCTL_PLLCFG_R_S) + 2));
  1600. }
  1601. else
  1602. {
  1603. //
  1604. // Compute the PLL output frequency based on its input frequency.
  1605. // The formula for a Fury-class device is
  1606. // "(xtal * f) / ((r + 1) * 2)".
  1607. //
  1608. ulClk = ((ulClk * ((ulPLL & SYSCTL_PLLCFG_F_M) >>
  1609. SYSCTL_PLLCFG_F_S)) /
  1610. ((((ulPLL & SYSCTL_PLLCFG_R_M) >>
  1611. SYSCTL_PLLCFG_R_S) + 1) * 2));
  1612. }
  1613. //
  1614. // See if the optional output divide by 2 is being used.
  1615. //
  1616. if(ulPLL & SYSCTL_PLLCFG_OD_2)
  1617. {
  1618. ulClk /= 2;
  1619. }
  1620. //
  1621. // See if the optional output divide by 4 is being used.
  1622. //
  1623. if(ulPLL & SYSCTL_PLLCFG_OD_4)
  1624. {
  1625. ulClk /= 4;
  1626. }
  1627. }
  1628. //
  1629. // See if the system divider is being used.
  1630. //
  1631. if(ulRCC & SYSCTL_RCC_USESYSDIV)
  1632. {
  1633. //
  1634. // Adjust the clock rate by the system clock divider.
  1635. //
  1636. if(ulRCC2 & SYSCTL_RCC2_USERCC2)
  1637. {
  1638. if((ulRCC2 & SYSCTL_RCC2_USEFRACT) &&
  1639. (((ulRCC2 & SYSCTL_RCC2_USERCC2) &&
  1640. !(ulRCC2 & SYSCTL_RCC2_BYPASS2)) ||
  1641. (!(ulRCC2 & SYSCTL_RCC2_USERCC2) &&
  1642. !(ulRCC & SYSCTL_RCC_BYPASS))))
  1643. {
  1644. ulClk = ((ulClk * 2) / (((ulRCC2 & (SYSCTL_RCC2_SYSDIV2_M |
  1645. SYSCTL_RCC2_FRACT)) >>
  1646. (SYSCTL_RCC2_SYSDIV2_S - 1)) + 1));
  1647. }
  1648. else
  1649. {
  1650. ulClk /= (((ulRCC2 & SYSCTL_RCC2_SYSDIV2_M) >>
  1651. SYSCTL_RCC2_SYSDIV2_S) + 1);
  1652. }
  1653. }
  1654. else
  1655. {
  1656. ulClk /= (((ulRCC & SYSCTL_RCC_SYSDIV_M) >> SYSCTL_RCC_SYSDIV_S) +
  1657. 1);
  1658. }
  1659. }
  1660. //
  1661. // Return the computed clock rate.
  1662. //
  1663. return(ulClk);
  1664. }
  1665. //*****************************************************************************
  1666. //
  1667. //! Sets the PWM clock configuration.
  1668. //!
  1669. //! \param ulConfig is the configuration for the PWM clock; it must be one of
  1670. //! \b SYSCTL_PWMDIV_1, \b SYSCTL_PWMDIV_2, \b SYSCTL_PWMDIV_4,
  1671. //! \b SYSCTL_PWMDIV_8, \b SYSCTL_PWMDIV_16, \b SYSCTL_PWMDIV_32, or
  1672. //! \b SYSCTL_PWMDIV_64.
  1673. //!
  1674. //! This function sets the rate of the clock provided to the PWM module as a
  1675. //! ratio of the processor clock. This clock is used by the PWM module to
  1676. //! generate PWM signals; its rate forms the basis for all PWM signals.
  1677. //!
  1678. //! \note The clocking of the PWM is dependent upon the system clock rate as
  1679. //! configured by SysCtlClockSet().
  1680. //!
  1681. //! \return None.
  1682. //
  1683. //*****************************************************************************
  1684. void
  1685. SysCtlPWMClockSet(unsigned long ulConfig)
  1686. {
  1687. //
  1688. // Check the arguments.
  1689. //
  1690. ASSERT((ulConfig == SYSCTL_PWMDIV_1) ||
  1691. (ulConfig == SYSCTL_PWMDIV_2) ||
  1692. (ulConfig == SYSCTL_PWMDIV_4) ||
  1693. (ulConfig == SYSCTL_PWMDIV_8) ||
  1694. (ulConfig == SYSCTL_PWMDIV_16) ||
  1695. (ulConfig == SYSCTL_PWMDIV_32) ||
  1696. (ulConfig == SYSCTL_PWMDIV_64));
  1697. //
  1698. // Check that there is a PWM block on this part.
  1699. //
  1700. ASSERT(HWREG(SYSCTL_DC1) & SYSCTL_DC1_PWM);
  1701. //
  1702. // Set the PWM clock configuration into the run-mode clock configuration
  1703. // register.
  1704. //
  1705. HWREG(SYSCTL_RCC) = ((HWREG(SYSCTL_RCC) &
  1706. ~(SYSCTL_RCC_USEPWMDIV | SYSCTL_RCC_PWMDIV_M)) |
  1707. ulConfig);
  1708. }
  1709. //*****************************************************************************
  1710. //
  1711. //! Gets the current PWM clock configuration.
  1712. //!
  1713. //! This function returns the current PWM clock configuration.
  1714. //!
  1715. //! \return Returns the current PWM clock configuration; will be one of
  1716. //! \b SYSCTL_PWMDIV_1, \b SYSCTL_PWMDIV_2, \b SYSCTL_PWMDIV_4,
  1717. //! \b SYSCTL_PWMDIV_8, \b SYSCTL_PWMDIV_16, \b SYSCTL_PWMDIV_32, or
  1718. //! \b SYSCTL_PWMDIV_64.
  1719. //
  1720. //*****************************************************************************
  1721. unsigned long
  1722. SysCtlPWMClockGet(void)
  1723. {
  1724. //
  1725. // Check that there is a PWM block on this part.
  1726. //
  1727. ASSERT(HWREG(SYSCTL_DC1) & SYSCTL_DC1_PWM);
  1728. //
  1729. // Return the current PWM clock configuration. Make sure that
  1730. // SYSCTL_PWMDIV_1 is returned in all cases where the divider is disabled.
  1731. //
  1732. if(!(HWREG(SYSCTL_RCC) & SYSCTL_RCC_USEPWMDIV))
  1733. {
  1734. //
  1735. // The divider is not active so reflect this in the value we return.
  1736. //
  1737. return(SYSCTL_PWMDIV_1);
  1738. }
  1739. else
  1740. {
  1741. //
  1742. // The divider is active so directly return the masked register value.
  1743. //
  1744. return(HWREG(SYSCTL_RCC) &
  1745. (SYSCTL_RCC_USEPWMDIV | SYSCTL_RCC_PWMDIV_M));
  1746. }
  1747. }
  1748. //*****************************************************************************
  1749. //
  1750. //! Sets the sample rate of the ADC.
  1751. //!
  1752. //! \param ulSpeed is the desired sample rate of the ADC; must be one of
  1753. //! \b SYSCTL_ADCSPEED_1MSPS, \b SYSCTL_ADCSPEED_500KSPS,
  1754. //! \b SYSCTL_ADCSPEED_250KSPS, or \b SYSCTL_ADCSPEED_125KSPS.
  1755. //!
  1756. //! This function sets the rate at which the ADC samples are captured by the
  1757. //! ADC block. The sampling speed may be limited by the hardware, so the
  1758. //! sample rate may end up being slower than requested. SysCtlADCSpeedGet()
  1759. //! will return the actual speed in use.
  1760. //!
  1761. //! \return None.
  1762. //
  1763. //*****************************************************************************
  1764. void
  1765. SysCtlADCSpeedSet(unsigned long ulSpeed)
  1766. {
  1767. //
  1768. // Check the arguments.
  1769. //
  1770. ASSERT((ulSpeed == SYSCTL_ADCSPEED_1MSPS) ||
  1771. (ulSpeed == SYSCTL_ADCSPEED_500KSPS) ||
  1772. (ulSpeed == SYSCTL_ADCSPEED_250KSPS) ||
  1773. (ulSpeed == SYSCTL_ADCSPEED_125KSPS));
  1774. //
  1775. // Check that there is an ADC block on this part.
  1776. //
  1777. ASSERT(HWREG(SYSCTL_DC1) & SYSCTL_DC1_ADC0);
  1778. //
  1779. // Set the ADC speed in run, sleep, and deep-sleep mode.
  1780. //
  1781. HWREG(SYSCTL_RCGC0) = ((HWREG(SYSCTL_RCGC0) & ~(SYSCTL_RCGC0_ADCSPD_M)) |
  1782. ulSpeed);
  1783. HWREG(SYSCTL_SCGC0) = ((HWREG(SYSCTL_SCGC0) & ~(SYSCTL_SCGC0_ADCSPD_M)) |
  1784. ulSpeed);
  1785. HWREG(SYSCTL_DCGC0) = ((HWREG(SYSCTL_DCGC0) & ~(SYSCTL_DCGC0_ADCSPD_M)) |
  1786. ulSpeed);
  1787. }
  1788. //*****************************************************************************
  1789. //
  1790. //! Gets the sample rate of the ADC.
  1791. //!
  1792. //! This function gets the current sample rate of the ADC.
  1793. //!
  1794. //! \return Returns the current ADC sample rate; will be one of
  1795. //! \b SYSCTL_ADCSPEED_1MSPS, \b SYSCTL_ADCSPEED_500KSPS,
  1796. //! \b SYSCTL_ADCSPEED_250KSPS, or \b SYSCTL_ADCSPEED_125KSPS.
  1797. //
  1798. //*****************************************************************************
  1799. unsigned long
  1800. SysCtlADCSpeedGet(void)
  1801. {
  1802. //
  1803. // Check that there is an ADC block on this part.
  1804. //
  1805. ASSERT(HWREG(SYSCTL_DC1) & SYSCTL_DC1_ADC0);
  1806. //
  1807. // Return the current ADC speed.
  1808. //
  1809. return(HWREG(SYSCTL_RCGC0) & SYSCTL_RCGC0_ADCSPD_M);
  1810. }
  1811. //*****************************************************************************
  1812. //
  1813. //! Configures the internal oscillator verification timer.
  1814. //!
  1815. //! \param bEnable is a boolean that is \b true if the internal oscillator
  1816. //! verification timer should be enabled.
  1817. //!
  1818. //! This function allows the internal oscillator verification timer to be
  1819. //! enabled or disabled. When enabled, an interrupt will be generated if the
  1820. //! internal oscillator ceases to operate.
  1821. //!
  1822. //! The internal oscillator verification timer is only available on
  1823. //! Sandstorm-class devices.
  1824. //!
  1825. //! \note Both oscillators (main and internal) must be enabled for this
  1826. //! verification timer to operate as the main oscillator will verify the
  1827. //! internal oscillator.
  1828. //!
  1829. //! \return None.
  1830. //
  1831. //*****************************************************************************
  1832. void
  1833. SysCtlIOSCVerificationSet(tBoolean bEnable)
  1834. {
  1835. //
  1836. // Enable or disable the internal oscillator verification timer as
  1837. // requested.
  1838. //
  1839. if(bEnable)
  1840. {
  1841. HWREG(SYSCTL_RCC) |= SYSCTL_RCC_IOSCVER;
  1842. }
  1843. else
  1844. {
  1845. HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_IOSCVER);
  1846. }
  1847. }
  1848. //*****************************************************************************
  1849. //
  1850. //! Configures the main oscillator verification timer.
  1851. //!
  1852. //! \param bEnable is a boolean that is \b true if the main oscillator
  1853. //! verification timer should be enabled.
  1854. //!
  1855. //! This function allows the main oscillator verification timer to be enabled
  1856. //! or disabled. When enabled, an interrupt will be generated if the main
  1857. //! oscillator ceases to operate.
  1858. //!
  1859. //! The main oscillator verification timer is only available on
  1860. //! Sandstorm-class devices.
  1861. //!
  1862. //! \note Both oscillators (main and internal) must be enabled for this
  1863. //! verification timer to operate as the internal oscillator will verify the
  1864. //! main oscillator.
  1865. //!
  1866. //! \return None.
  1867. //
  1868. //*****************************************************************************
  1869. void
  1870. SysCtlMOSCVerificationSet(tBoolean bEnable)
  1871. {
  1872. //
  1873. // Enable or disable the main oscillator verification timer as requested.
  1874. //
  1875. if(bEnable)
  1876. {
  1877. HWREG(SYSCTL_RCC) |= SYSCTL_RCC_MOSCVER;
  1878. }
  1879. else
  1880. {
  1881. HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_MOSCVER);
  1882. }
  1883. }
  1884. //*****************************************************************************
  1885. //
  1886. //! Configures the PLL verification timer.
  1887. //!
  1888. //! \param bEnable is a boolean that is \b true if the PLL verification timer
  1889. //! should be enabled.
  1890. //!
  1891. //! This function allows the PLL verification timer to be enabled or disabled.
  1892. //! When enabled, an interrupt will be generated if the PLL ceases to operate.
  1893. //!
  1894. //! The PLL verification timer is only available on Sandstorm-class devices.
  1895. //!
  1896. //! \note The main oscillator must be enabled for this verification timer to
  1897. //! operate as it is used to check the PLL. Also, the verification timer
  1898. //! should be disabled while the PLL is being reconfigured via
  1899. //! SysCtlClockSet().
  1900. //!
  1901. //! \return None.
  1902. //
  1903. //*****************************************************************************
  1904. void
  1905. SysCtlPLLVerificationSet(tBoolean bEnable)
  1906. {
  1907. //
  1908. // Enable or disable the PLL verification timer as requested.
  1909. //
  1910. if(bEnable)
  1911. {
  1912. HWREG(SYSCTL_RCC) |= SYSCTL_RCC_PLLVER;
  1913. }
  1914. else
  1915. {
  1916. HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_PLLVER);
  1917. }
  1918. }
  1919. //*****************************************************************************
  1920. //
  1921. //! Clears the clock verification status.
  1922. //!
  1923. //! This function clears the status of the clock verification timers, allowing
  1924. //! them to assert another failure if detected.
  1925. //!
  1926. //! The clock verification timers are only available on Sandstorm-class
  1927. //! devices.
  1928. //!
  1929. //! \return None.
  1930. //
  1931. //*****************************************************************************
  1932. void
  1933. SysCtlClkVerificationClear(void)
  1934. {
  1935. //
  1936. // Clear the clock verification.
  1937. //
  1938. HWREG(SYSCTL_CLKVCLR) = SYSCTL_CLKVCLR_VERCLR;
  1939. //
  1940. // The bit does not self-reset, so clear it.
  1941. //
  1942. HWREG(SYSCTL_CLKVCLR) = 0;
  1943. }
  1944. //*****************************************************************************
  1945. //
  1946. //! Enables a GPIO peripheral for access from the AHB.
  1947. //!
  1948. //! \param ulGPIOPeripheral is the GPIO peripheral to enable.
  1949. //!
  1950. //! This function is used to enable the specified GPIO peripheral to be
  1951. //! accessed from the Advanced Host Bus (AHB) instead of the legacy Advanced
  1952. //! Peripheral Bus (APB). When a GPIO peripheral is enabled for AHB access,
  1953. //! the \b _AHB_BASE form of the base address should be used for GPIO
  1954. //! functions. For example, instead of using \b GPIO_PORTA_BASE as the base
  1955. //! address for GPIO functions, use \b GPIO_PORTA_AHB_BASE instead.
  1956. //!
  1957. //! The \e ulGPIOPeripheral argument must be only one of the following values:
  1958. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  1959. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  1960. //! \b SYSCTL_PERIPH_GPIOG, or \b SYSCTL_PERIPH_GPIOH.
  1961. //!
  1962. //! \return None.
  1963. //
  1964. //*****************************************************************************
  1965. void
  1966. SysCtlGPIOAHBEnable(unsigned long ulGPIOPeripheral)
  1967. {
  1968. //
  1969. // Check the arguments.
  1970. //
  1971. ASSERT((ulGPIOPeripheral == SYSCTL_PERIPH_GPIOA) ||
  1972. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOB) ||
  1973. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOC) ||
  1974. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOD) ||
  1975. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOE) ||
  1976. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOF) ||
  1977. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOG) ||
  1978. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOH) ||
  1979. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOJ));
  1980. //
  1981. // Enable this GPIO for AHB access.
  1982. //
  1983. HWREG(SYSCTL_GPIOHSCTL) |= ulGPIOPeripheral & 0xFFFF;
  1984. }
  1985. //*****************************************************************************
  1986. //
  1987. //! Disables a GPIO peripheral for access from the AHB.
  1988. //!
  1989. //! \param ulGPIOPeripheral is the GPIO peripheral to disable.
  1990. //!
  1991. //! This function disables the specified GPIO peripheral for access from the
  1992. //! Advanced Host Bus (AHB). Once disabled, the GPIO peripheral is accessed
  1993. //! from the legacy Advanced Peripheral Bus (AHB).
  1994. //!
  1995. //! The \b ulGPIOPeripheral argument must be only one of the following values:
  1996. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  1997. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  1998. //! \b SYSCTL_PERIPH_GPIOG, or \b SYSCTL_PERIPH_GPIOH.
  1999. //!
  2000. //! \return None.
  2001. //
  2002. //*****************************************************************************
  2003. void
  2004. SysCtlGPIOAHBDisable(unsigned long ulGPIOPeripheral)
  2005. {
  2006. //
  2007. // Check the arguments.
  2008. //
  2009. ASSERT((ulGPIOPeripheral == SYSCTL_PERIPH_GPIOA) ||
  2010. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOB) ||
  2011. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOC) ||
  2012. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOD) ||
  2013. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOE) ||
  2014. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOF) ||
  2015. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOG) ||
  2016. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOH) ||
  2017. (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOJ));
  2018. //
  2019. // Disable this GPIO for AHB access.
  2020. //
  2021. HWREG(SYSCTL_GPIOHSCTL) &= ~(ulGPIOPeripheral & 0xFFFF);
  2022. }
  2023. //*****************************************************************************
  2024. //
  2025. //! Powers up the USB PLL.
  2026. //!
  2027. //! This function will enable the USB controller's PLL which is used by it's
  2028. //! physical layer. This call is necessary before connecting to any external
  2029. //! devices.
  2030. //!
  2031. //! \return None.
  2032. //
  2033. //*****************************************************************************
  2034. void
  2035. SysCtlUSBPLLEnable(void)
  2036. {
  2037. //
  2038. // Turn on the USB PLL.
  2039. //
  2040. HWREG(SYSCTL_RCC2) &= ~SYSCTL_RCC2_USBPWRDN;
  2041. }
  2042. //*****************************************************************************
  2043. //
  2044. //! Powers down the USB PLL.
  2045. //!
  2046. //! This function will disable the USB controller's PLL which is used by it's
  2047. //! physical layer. The USB registers are still accessible, but the physical
  2048. //! layer will no longer function.
  2049. //!
  2050. //! \return None.
  2051. //
  2052. //*****************************************************************************
  2053. void
  2054. SysCtlUSBPLLDisable(void)
  2055. {
  2056. //
  2057. // Turn of USB PLL.
  2058. //
  2059. HWREG(SYSCTL_RCC2) |= SYSCTL_RCC2_USBPWRDN;
  2060. }
  2061. //*****************************************************************************
  2062. //
  2063. //! Sets the MCLK frequency provided to the I2S module.
  2064. //!
  2065. //! \param ulInputClock is the input clock to the MCLK divider. If this is
  2066. //! zero, the value is computed from the current PLL configuration.
  2067. //! \param ulMClk is the desired MCLK frequency. If this is zero, MCLK output
  2068. //! is disabled.
  2069. //!
  2070. //! This function sets the dividers to provide MCLK to the I2S module. A MCLK
  2071. //! divider will be chosen that produces the MCLK frequency that is the closest
  2072. //! possible to the requested frequency, which may be above or below the
  2073. //! requested frequency.
  2074. //!
  2075. //! The actual MCLK frequency will be returned. It is the responsibility of
  2076. //! the application to determine if the selected MCLK is acceptable; in general
  2077. //! the human ear can not discern the frequency difference if it is within 0.3%
  2078. //! of the desired frequency (though there is a very small percentage of the
  2079. //! population that can discern lower frequency deviations).
  2080. //!
  2081. //! \return Returns the actual MCLK frequency.
  2082. //
  2083. //*****************************************************************************
  2084. unsigned long
  2085. SysCtlI2SMClkSet(unsigned long ulInputClock, unsigned long ulMClk)
  2086. {
  2087. unsigned long ulDivInt, ulDivFrac, ulPLL;
  2088. //
  2089. // See if the I2S MCLK should be disabled.
  2090. //
  2091. if(ulMClk == 0)
  2092. {
  2093. //
  2094. // Disable the I2S MCLK and return.
  2095. //
  2096. HWREG(SYSCTL_I2SMCLKCFG) = 0;
  2097. return(0);
  2098. }
  2099. //
  2100. // See if the input clock was specified.
  2101. //
  2102. if(ulInputClock == 0)
  2103. {
  2104. //
  2105. // The input clock was not specified, so compute the output frequency
  2106. // of the PLL. Get the current PLL configuration.
  2107. //
  2108. ulPLL = HWREG(SYSCTL_PLLCFG);
  2109. //
  2110. // Get the frequency of the crystal in use.
  2111. //
  2112. ulInputClock = g_pulXtals[(HWREG(SYSCTL_RCC) & SYSCTL_RCC_XTAL_M) >>
  2113. SYSCTL_RCC_XTAL_S];
  2114. //
  2115. // Calculate the PLL output frequency.
  2116. //
  2117. ulInputClock = ((ulInputClock * ((ulPLL & SYSCTL_PLLCFG_F_M) >>
  2118. SYSCTL_PLLCFG_F_S)) /
  2119. ((((ulPLL & SYSCTL_PLLCFG_R_M) >>
  2120. SYSCTL_PLLCFG_R_S) + 1)));
  2121. //
  2122. // See if the optional output divide by 2 is being used.
  2123. //
  2124. if(ulPLL & SYSCTL_PLLCFG_OD_2)
  2125. {
  2126. ulInputClock /= 2;
  2127. }
  2128. //
  2129. // See if the optional output divide by 4 is being used.
  2130. //
  2131. if(ulPLL & SYSCTL_PLLCFG_OD_4)
  2132. {
  2133. ulInputClock /= 4;
  2134. }
  2135. }
  2136. //
  2137. // Verify that the requested MCLK frequency is attainable.
  2138. //
  2139. ASSERT(ulMClk < ulInputClock);
  2140. //
  2141. // Add a rounding factor to the input clock, so that the MCLK frequency
  2142. // that is closest to the desire value is selected.
  2143. //
  2144. ulInputClock += (ulMClk / 32) - 1;
  2145. //
  2146. // Compute the integer portion of the MCLK divider.
  2147. //
  2148. ulDivInt = ulInputClock / ulMClk;
  2149. //
  2150. // If the divisor is too large, then simply use the maximum divisor.
  2151. //
  2152. if(CLASS_IS_TEMPEST && REVISION_IS_B1 && (ulDivInt > 255))
  2153. {
  2154. ulDivInt = 255;
  2155. ulDivFrac = 15;
  2156. }
  2157. else if(ulDivInt > 1023)
  2158. {
  2159. ulDivInt = 1023;
  2160. ulDivFrac = 15;
  2161. }
  2162. else
  2163. {
  2164. //
  2165. // Compute the fractional portion of the MCLK divider.
  2166. //
  2167. ulDivFrac = ((ulInputClock - (ulDivInt * ulMClk)) * 16) / ulMClk;
  2168. }
  2169. //
  2170. // Set the divisor for the Tx and Rx MCLK generators and enable the clocks.
  2171. //
  2172. HWREG(SYSCTL_I2SMCLKCFG) = (SYSCTL_I2SMCLKCFG_RXEN |
  2173. (ulDivInt << SYSCTL_I2SMCLKCFG_RXI_S) |
  2174. (ulDivFrac << SYSCTL_I2SMCLKCFG_RXF_S) |
  2175. SYSCTL_I2SMCLKCFG_TXEN |
  2176. (ulDivInt << SYSCTL_I2SMCLKCFG_TXI_S) |
  2177. (ulDivFrac << SYSCTL_I2SMCLKCFG_TXF_S));
  2178. //
  2179. // Return the actual MCLK frequency.
  2180. //
  2181. ulInputClock -= (ulMClk / 32) - 1;
  2182. ulDivInt = (ulDivInt * 16) + ulDivFrac;
  2183. ulMClk = (ulInputClock / ulDivInt) * 16;
  2184. ulMClk += ((ulInputClock - ((ulMClk / 16) * ulDivInt)) * 16) / ulDivInt;
  2185. return(ulMClk);
  2186. }
  2187. //*****************************************************************************
  2188. //
  2189. // Close the Doxygen group.
  2190. //! @}
  2191. //
  2192. //*****************************************************************************