sysctl.c 83 KB

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