sysctl.c 114 KB

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