sysctl.c 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750
  1. //*****************************************************************************
  2. //
  3. // sysctl.c - Driver for the system controller.
  4. //
  5. // Copyright (c) 2005-2017 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions
  10. // are met:
  11. //
  12. // Redistributions of source code must retain the above copyright
  13. // notice, this list of conditions and the following disclaimer.
  14. //
  15. // Redistributions in binary form must reproduce the above copyright
  16. // notice, this list of conditions and the following disclaimer in the
  17. // documentation and/or other materials provided with the
  18. // distribution.
  19. //
  20. // Neither the name of Texas Instruments Incorporated nor the names of
  21. // its contributors may be used to endorse or promote products derived
  22. // from this software without specific prior written permission.
  23. //
  24. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. //*****************************************************************************
  37. //*****************************************************************************
  38. //
  39. //! \addtogroup sysctl_api
  40. //! @{
  41. //
  42. //*****************************************************************************
  43. #include "types.h"
  44. #include <stdbool.h>
  45. #include <stdint.h>
  46. #include "inc/hw_nvic.h"
  47. #include "inc/hw_sysctl.h"
  48. #include "inc/hw_flash.h"
  49. #include "cpu.h"
  50. #include "debug.h"
  51. #include "interrupt.h"
  52. #include "sysctl.h"
  53. //*****************************************************************************
  54. //
  55. // The flash shift used in the math to calculate the flash sector size.
  56. //
  57. //*****************************************************************************
  58. #ifndef FLASH_PP_MAINSS_S
  59. #define FLASH_PP_MAINSS_S 16
  60. #endif
  61. //*****************************************************************************
  62. //
  63. // This macro converts the XTAL value provided in the ui32Config parameter to
  64. // an index to the g_pui32Xtals array.
  65. //
  66. //*****************************************************************************
  67. #define SysCtlXtalCfgToIndex(a) ((a & 0x7c0) >> 6)
  68. //*****************************************************************************
  69. //
  70. // An array that maps the crystal number in RCC to a frequency.
  71. //
  72. //*****************************************************************************
  73. static const uint32_t g_pui32Xtals[] =
  74. {
  75. 5000000,
  76. 6000000,
  77. 8000000,
  78. 10000000,
  79. 12000000,
  80. 16000000,
  81. 18000000,
  82. 20000000,
  83. 24000000,
  84. 25000000
  85. };
  86. //*****************************************************************************
  87. //
  88. // Maximum number of VCO entries in the g_pui32XTALtoVCO and
  89. // g_pui32VCOFrequencies structures for a device.
  90. //
  91. //*****************************************************************************
  92. #define MAX_VCO_ENTRIES 2
  93. #define MAX_XTAL_ENTRIES 18
  94. //*****************************************************************************
  95. //
  96. // These macros are used in the g_pui32XTALtoVCO table to make it more
  97. // readable.
  98. //
  99. //*****************************************************************************
  100. #define PLL_M_TO_REG(mi, mf) \
  101. ((uint32_t)mi | (uint32_t)(mf << SYSCTL_PLLFREQ0_MFRAC_S))
  102. #define PLL_N_TO_REG(n) \
  103. ((uint32_t)(n - 1) << SYSCTL_PLLFREQ1_N_S)
  104. #define PLL_Q_TO_REG(q) \
  105. ((uint32_t)(q - 1) << SYSCTL_PLLFREQ1_Q_S)
  106. //*****************************************************************************
  107. //
  108. // Look up of the values that go into the PLLFREQ0 and PLLFREQ1 registers.
  109. //
  110. //*****************************************************************************
  111. static const uint32_t g_pppui32XTALtoVCO[MAX_VCO_ENTRIES][MAX_XTAL_ENTRIES][3] =
  112. {
  113. {
  114. //
  115. // VCO 320 MHz
  116. //
  117. { PLL_M_TO_REG(64, 0), PLL_N_TO_REG(1), PLL_Q_TO_REG(2) }, // 5 MHz
  118. { PLL_M_TO_REG(160, 0), PLL_N_TO_REG(3), PLL_Q_TO_REG(2) }, // 6 MHz
  119. { PLL_M_TO_REG(40, 0), PLL_N_TO_REG(1), PLL_Q_TO_REG(2) }, // 8 MHz
  120. { PLL_M_TO_REG(32, 0), PLL_N_TO_REG(1), PLL_Q_TO_REG(2) }, // 10 MHz
  121. { PLL_M_TO_REG(80, 0), PLL_N_TO_REG(3), PLL_Q_TO_REG(2) }, // 12 MHz
  122. { PLL_M_TO_REG(20, 0), PLL_N_TO_REG(1), PLL_Q_TO_REG(2) }, // 16 MHz
  123. { PLL_M_TO_REG(160, 0), PLL_N_TO_REG(9), PLL_Q_TO_REG(2) }, // 18 MHz
  124. { PLL_M_TO_REG(16, 0), PLL_N_TO_REG(1), PLL_Q_TO_REG(2) }, // 20 MHz
  125. { PLL_M_TO_REG(40, 0), PLL_N_TO_REG(3), PLL_Q_TO_REG(2) }, // 24 MHz
  126. { PLL_M_TO_REG(64, 0), PLL_N_TO_REG(5), PLL_Q_TO_REG(2) }, // 25 MHz
  127. },
  128. {
  129. //
  130. // VCO 480 MHz
  131. //
  132. { PLL_M_TO_REG(96, 0), PLL_N_TO_REG(1), PLL_Q_TO_REG(2) }, // 5 MHz
  133. { PLL_M_TO_REG(80, 0), PLL_N_TO_REG(1), PLL_Q_TO_REG(2) }, // 6 MHz
  134. { PLL_M_TO_REG(60, 0), PLL_N_TO_REG(1), PLL_Q_TO_REG(2) }, // 8 MHz
  135. { PLL_M_TO_REG(48, 0), PLL_N_TO_REG(1), PLL_Q_TO_REG(2) }, // 10 MHz
  136. { PLL_M_TO_REG(40, 0), PLL_N_TO_REG(1), PLL_Q_TO_REG(2) }, // 12 MHz
  137. { PLL_M_TO_REG(30, 0), PLL_N_TO_REG(1), PLL_Q_TO_REG(2) }, // 16 MHz
  138. { PLL_M_TO_REG(80, 0), PLL_N_TO_REG(3), PLL_Q_TO_REG(2) }, // 18 MHz
  139. { PLL_M_TO_REG(24, 0), PLL_N_TO_REG(1), PLL_Q_TO_REG(2) }, // 20 MHz
  140. { PLL_M_TO_REG(20, 0), PLL_N_TO_REG(1), PLL_Q_TO_REG(2) }, // 24 MHz
  141. { PLL_M_TO_REG(96, 0), PLL_N_TO_REG(5), PLL_Q_TO_REG(2) }, // 25 MHz
  142. },
  143. };
  144. //*****************************************************************************
  145. //
  146. // The mapping of system clock frequency to flash memory timing parameters.
  147. //
  148. //*****************************************************************************
  149. static const struct
  150. {
  151. uint32_t ui32Frequency;
  152. uint32_t ui32MemTiming;
  153. }
  154. g_sXTALtoMEMTIM[] =
  155. {
  156. {
  157. 16000000, (SYSCTL_MEMTIM0_FBCHT_0_5 | SYSCTL_MEMTIM0_FBCE |
  158. (0 << SYSCTL_MEMTIM0_FWS_S) |
  159. SYSCTL_MEMTIM0_EBCHT_0_5 | SYSCTL_MEMTIM0_EBCE |
  160. (0 << SYSCTL_MEMTIM0_EWS_S) |
  161. SYSCTL_MEMTIM0_MB1)
  162. },
  163. {
  164. 40000000, (SYSCTL_MEMTIM0_FBCHT_1_5 | (1 << SYSCTL_MEMTIM0_FWS_S) |
  165. SYSCTL_MEMTIM0_EBCHT_1_5 | (1 << SYSCTL_MEMTIM0_EWS_S) |
  166. SYSCTL_MEMTIM0_MB1)
  167. },
  168. {
  169. 60000000, (SYSCTL_MEMTIM0_FBCHT_2 | (2 << SYSCTL_MEMTIM0_FWS_S) |
  170. SYSCTL_MEMTIM0_EBCHT_2 | (2 << SYSCTL_MEMTIM0_EWS_S) |
  171. SYSCTL_MEMTIM0_MB1)
  172. },
  173. {
  174. 80000000, (SYSCTL_MEMTIM0_FBCHT_2_5 | (3 << SYSCTL_MEMTIM0_FWS_S) |
  175. SYSCTL_MEMTIM0_EBCHT_2_5 | (3 << SYSCTL_MEMTIM0_EWS_S) |
  176. SYSCTL_MEMTIM0_MB1)
  177. },
  178. {
  179. 100000000, (SYSCTL_MEMTIM0_FBCHT_3 | (4 << SYSCTL_MEMTIM0_FWS_S) |
  180. SYSCTL_MEMTIM0_EBCHT_3 | (4 << SYSCTL_MEMTIM0_EWS_S) |
  181. SYSCTL_MEMTIM0_MB1)
  182. },
  183. {
  184. 120000000, (SYSCTL_MEMTIM0_FBCHT_3_5 | (5 << SYSCTL_MEMTIM0_FWS_S) |
  185. SYSCTL_MEMTIM0_EBCHT_3_5 | (5 << SYSCTL_MEMTIM0_EWS_S) |
  186. SYSCTL_MEMTIM0_MB1)
  187. },
  188. };
  189. //*****************************************************************************
  190. //
  191. // Get the correct memory timings for a given system clock value.
  192. //
  193. //*****************************************************************************
  194. static uint32_t
  195. _SysCtlMemTimingGet(uint32_t ui32SysClock)
  196. {
  197. uint_fast8_t ui8Idx;
  198. //
  199. // Loop through the flash memory timings.
  200. //
  201. for (ui8Idx = 0;
  202. ui8Idx < (sizeof(g_sXTALtoMEMTIM) / sizeof(g_sXTALtoMEMTIM[0]));
  203. ui8Idx++)
  204. {
  205. //
  206. // See if the system clock frequency is less than the maximum frequency
  207. // for this flash memory timing.
  208. //
  209. if (ui32SysClock <= g_sXTALtoMEMTIM[ui8Idx].ui32Frequency)
  210. {
  211. //
  212. // This flash memory timing is the best choice for the system clock
  213. // frequency, so return it now.
  214. //
  215. return (g_sXTALtoMEMTIM[ui8Idx].ui32MemTiming);
  216. }
  217. }
  218. //
  219. // An appropriate flash memory timing could not be found, so the device is
  220. // being clocked too fast. Return the default flash memory timing.
  221. //
  222. return (0);
  223. }
  224. //*****************************************************************************
  225. //
  226. // Calculate the system frequency from the register settings base on the
  227. // oscillator input.
  228. //
  229. //*****************************************************************************
  230. static uint32_t
  231. _SysCtlFrequencyGet(uint32_t ui32Xtal)
  232. {
  233. uint32_t ui32Result;
  234. uint_fast16_t ui16F1, ui16F2;
  235. uint_fast16_t ui16PInt, ui16PFract;
  236. uint_fast8_t ui8Q, ui8N;
  237. //
  238. // Extract all of the values from the hardware registers.
  239. //
  240. ui16PFract = ((HWREG(SYSCTL_PLLFREQ0) & SYSCTL_PLLFREQ0_MFRAC_M) >>
  241. SYSCTL_PLLFREQ0_MFRAC_S);
  242. ui16PInt = HWREG(SYSCTL_PLLFREQ0) & SYSCTL_PLLFREQ0_MINT_M;
  243. ui8Q = (((HWREG(SYSCTL_PLLFREQ1) & SYSCTL_PLLFREQ1_Q_M) >>
  244. SYSCTL_PLLFREQ1_Q_S) + 1);
  245. ui8N = (((HWREG(SYSCTL_PLLFREQ1) & SYSCTL_PLLFREQ1_N_M) >>
  246. SYSCTL_PLLFREQ1_N_S) + 1);
  247. //
  248. // Divide the crystal value by N.
  249. //
  250. ui32Xtal /= (uint32_t)ui8N;
  251. //
  252. // Calculate the multiplier for bits 9:5.
  253. //
  254. ui16F1 = ui16PFract / 32;
  255. //
  256. // Calculate the multiplier for bits 4:0.
  257. //
  258. ui16F2 = ui16PFract - (ui16F1 * 32);
  259. //
  260. // Get the integer portion.
  261. //
  262. ui32Result = ui32Xtal * (uint32_t)ui16PInt;
  263. //
  264. // Add first fractional bits portion(9:0).
  265. //
  266. ui32Result += (ui32Xtal * (uint32_t)ui16F1) / 32;
  267. //
  268. // Add the second fractional bits portion(4:0).
  269. //
  270. ui32Result += (ui32Xtal * (uint32_t)ui16F2) / 1024;
  271. //
  272. // Divide the result by Q.
  273. //
  274. ui32Result = ui32Result / (uint32_t)ui8Q;
  275. //
  276. // Return the resulting PLL frequency.
  277. //
  278. return (ui32Result);
  279. }
  280. //*****************************************************************************
  281. //
  282. // Look up of the possible VCO frequencies.
  283. //
  284. //*****************************************************************************
  285. static const uint32_t g_pui32VCOFrequencies[MAX_VCO_ENTRIES] =
  286. {
  287. 160000000, // VCO 320
  288. 240000000, // VCO 480
  289. };
  290. //*****************************************************************************
  291. //
  292. // The base addresses of the various peripheral control registers.
  293. //
  294. //*****************************************************************************
  295. #define SYSCTL_PPBASE 0x400fe300
  296. #define SYSCTL_SRBASE 0x400fe500
  297. #define SYSCTL_RCGCBASE 0x400fe600
  298. #define SYSCTL_SCGCBASE 0x400fe700
  299. #define SYSCTL_DCGCBASE 0x400fe800
  300. #define SYSCTL_PCBASE 0x400fe900
  301. #define SYSCTL_PRBASE 0x400fea00
  302. //*****************************************************************************
  303. //
  304. //! \internal
  305. //! Checks a peripheral identifier.
  306. //!
  307. //! \param ui32Peripheral is the peripheral identifier.
  308. //!
  309. //! This function determines if a peripheral identifier is valid.
  310. //!
  311. //! \return Returns \b true if the peripheral identifier is valid and \b false
  312. //! otherwise.
  313. //
  314. //*****************************************************************************
  315. #ifdef DEBUG
  316. static bool
  317. _SysCtlPeripheralValid(uint32_t ui32Peripheral)
  318. {
  319. return ((ui32Peripheral == SYSCTL_PERIPH_ADC0) ||
  320. (ui32Peripheral == SYSCTL_PERIPH_ADC1) ||
  321. (ui32Peripheral == SYSCTL_PERIPH_CAN0) ||
  322. (ui32Peripheral == SYSCTL_PERIPH_CAN1) ||
  323. (ui32Peripheral == SYSCTL_PERIPH_COMP0) ||
  324. (ui32Peripheral == SYSCTL_PERIPH_CCM0) ||
  325. (ui32Peripheral == SYSCTL_PERIPH_EEPROM0) ||
  326. (ui32Peripheral == SYSCTL_PERIPH_EPHY0) ||
  327. (ui32Peripheral == SYSCTL_PERIPH_EMAC0) ||
  328. (ui32Peripheral == SYSCTL_PERIPH_EPI0) ||
  329. (ui32Peripheral == SYSCTL_PERIPH_GPIOA) ||
  330. (ui32Peripheral == SYSCTL_PERIPH_GPIOB) ||
  331. (ui32Peripheral == SYSCTL_PERIPH_GPIOC) ||
  332. (ui32Peripheral == SYSCTL_PERIPH_GPIOD) ||
  333. (ui32Peripheral == SYSCTL_PERIPH_GPIOE) ||
  334. (ui32Peripheral == SYSCTL_PERIPH_GPIOF) ||
  335. (ui32Peripheral == SYSCTL_PERIPH_GPIOG) ||
  336. (ui32Peripheral == SYSCTL_PERIPH_GPIOH) ||
  337. (ui32Peripheral == SYSCTL_PERIPH_GPIOJ) ||
  338. (ui32Peripheral == SYSCTL_PERIPH_GPIOK) ||
  339. (ui32Peripheral == SYSCTL_PERIPH_GPIOL) ||
  340. (ui32Peripheral == SYSCTL_PERIPH_GPIOM) ||
  341. (ui32Peripheral == SYSCTL_PERIPH_GPION) ||
  342. (ui32Peripheral == SYSCTL_PERIPH_GPIOP) ||
  343. (ui32Peripheral == SYSCTL_PERIPH_GPIOQ) ||
  344. (ui32Peripheral == SYSCTL_PERIPH_GPIOR) ||
  345. (ui32Peripheral == SYSCTL_PERIPH_GPIOS) ||
  346. (ui32Peripheral == SYSCTL_PERIPH_GPIOT) ||
  347. (ui32Peripheral == SYSCTL_PERIPH_HIBERNATE) ||
  348. (ui32Peripheral == SYSCTL_PERIPH_I2C0) ||
  349. (ui32Peripheral == SYSCTL_PERIPH_I2C1) ||
  350. (ui32Peripheral == SYSCTL_PERIPH_I2C2) ||
  351. (ui32Peripheral == SYSCTL_PERIPH_I2C3) ||
  352. (ui32Peripheral == SYSCTL_PERIPH_I2C4) ||
  353. (ui32Peripheral == SYSCTL_PERIPH_I2C5) ||
  354. (ui32Peripheral == SYSCTL_PERIPH_I2C6) ||
  355. (ui32Peripheral == SYSCTL_PERIPH_I2C7) ||
  356. (ui32Peripheral == SYSCTL_PERIPH_I2C8) ||
  357. (ui32Peripheral == SYSCTL_PERIPH_I2C9) ||
  358. (ui32Peripheral == SYSCTL_PERIPH_LCD0) ||
  359. (ui32Peripheral == SYSCTL_PERIPH_PWM0) ||
  360. (ui32Peripheral == SYSCTL_PERIPH_PWM1) ||
  361. (ui32Peripheral == SYSCTL_PERIPH_QEI0) ||
  362. (ui32Peripheral == SYSCTL_PERIPH_QEI1) ||
  363. (ui32Peripheral == SYSCTL_PERIPH_SSI0) ||
  364. (ui32Peripheral == SYSCTL_PERIPH_SSI1) ||
  365. (ui32Peripheral == SYSCTL_PERIPH_SSI2) ||
  366. (ui32Peripheral == SYSCTL_PERIPH_SSI3) ||
  367. (ui32Peripheral == SYSCTL_PERIPH_TIMER0) ||
  368. (ui32Peripheral == SYSCTL_PERIPH_TIMER1) ||
  369. (ui32Peripheral == SYSCTL_PERIPH_TIMER2) ||
  370. (ui32Peripheral == SYSCTL_PERIPH_TIMER3) ||
  371. (ui32Peripheral == SYSCTL_PERIPH_TIMER4) ||
  372. (ui32Peripheral == SYSCTL_PERIPH_TIMER5) ||
  373. (ui32Peripheral == SYSCTL_PERIPH_TIMER6) ||
  374. (ui32Peripheral == SYSCTL_PERIPH_TIMER7) ||
  375. (ui32Peripheral == SYSCTL_PERIPH_UART0) ||
  376. (ui32Peripheral == SYSCTL_PERIPH_UART1) ||
  377. (ui32Peripheral == SYSCTL_PERIPH_UART2) ||
  378. (ui32Peripheral == SYSCTL_PERIPH_UART3) ||
  379. (ui32Peripheral == SYSCTL_PERIPH_UART4) ||
  380. (ui32Peripheral == SYSCTL_PERIPH_UART5) ||
  381. (ui32Peripheral == SYSCTL_PERIPH_UART6) ||
  382. (ui32Peripheral == SYSCTL_PERIPH_UART7) ||
  383. (ui32Peripheral == SYSCTL_PERIPH_UDMA) ||
  384. (ui32Peripheral == SYSCTL_PERIPH_USB0) ||
  385. (ui32Peripheral == SYSCTL_PERIPH_WDOG0) ||
  386. (ui32Peripheral == SYSCTL_PERIPH_WDOG1));
  387. }
  388. #endif
  389. //*****************************************************************************
  390. //
  391. //! Gets the size of the SRAM.
  392. //!
  393. //! This function determines the size of the SRAM on the device.
  394. //!
  395. //! \return The total number of bytes of SRAM.
  396. //
  397. //*****************************************************************************
  398. uint32_t
  399. SysCtlSRAMSizeGet(void)
  400. {
  401. return ((HWREG(FLASH_SSIZE) + 1) * 256);
  402. }
  403. //*****************************************************************************
  404. //
  405. //! Gets the size of the flash.
  406. //!
  407. //! This function determines the size of the flash on the device.
  408. //!
  409. //! \return The total number of bytes of flash.
  410. //
  411. //*****************************************************************************
  412. uint32_t
  413. SysCtlFlashSizeGet(void)
  414. {
  415. //
  416. // Get the flash size from the FLASH_PP register.
  417. //
  418. return (2048 * ((HWREG(FLASH_PP) & FLASH_PP_SIZE_M) + 1));
  419. }
  420. //*****************************************************************************
  421. //
  422. //! Gets the size of a single eraseable sector of flash.
  423. //!
  424. //! This function determines the flash sector size on the device.
  425. //! This size determines the erase granularity of the device flash.
  426. //!
  427. //! \return The number of bytes in a single flash sector.
  428. //
  429. //*****************************************************************************
  430. uint32_t
  431. SysCtlFlashSectorSizeGet(void)
  432. {
  433. //
  434. // Get the flash sector size from the FLASH_PP register.
  435. //
  436. return (1 << (10 +
  437. ((HWREG(FLASH_PP) &
  438. FLASH_PP_MAINSS_M) >> FLASH_PP_MAINSS_S)));
  439. }
  440. //*****************************************************************************
  441. //
  442. //! Determines if a peripheral is present.
  443. //!
  444. //! \param ui32Peripheral is the peripheral in question.
  445. //!
  446. //! This function determines if a particular peripheral is present in the
  447. //! device.
  448. //!
  449. //! The \e ui32Peripheral parameter must be only one of the following values:
  450. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  451. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CCM0,\b SYSCTL_PERIPH_COMP0,
  452. //! \b SYSCTL_PERIPH_EEPROM0, \b SYSCTL_PERIPH_EMAC, \b SYSCTL_PERIPH_EPHY,
  453. //! \b SYSCTL_PERIPH_EPI0,
  454. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  455. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  456. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  457. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  458. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  459. //! \b SYSCTL_PERIPH_GPIOR, \b SYSCTL_PERIPH_GPIOS, \b SYSCTL_PERIPH_GPIOT,
  460. //! \b SYSCTL_PERIPH_HIBERNATE,
  461. //! \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_I2C2,
  462. //! \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4, \b SYSCTL_PERIPH_I2C5,
  463. //! \b SYSCTL_PERIPH_I2C6, \b SYSCTL_PERIPH_I2C7, \b SYSCTL_PERIPH_I2C8,
  464. //! \b SYSCTL_PERIPH_I2C9, \b SYSCTL_PERIPH_LCD0,
  465. //! \b SYSCTL_PERIPH_ONEWIRE0,
  466. //! \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1, \b SYSCTL_PERIPH_QEI0,
  467. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  468. //! \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3, \b SYSCTL_PERIPH_TIMER0,
  469. //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_TIMER3,
  470. //! \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5, \b SYSCTL_PERIPH_TIMER6,
  471. //! \b SYSCTL_PERIPH_TIMER7, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  472. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4,
  473. //! \b SYSCTL_PERIPH_UART5, \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7,
  474. //! \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0,
  475. //! or \b SYSCTL_PERIPH_WDOG1
  476. //!
  477. //! \return Returns \b true if the specified peripheral is present and \b false
  478. //! if it is not.
  479. //
  480. //*****************************************************************************
  481. bool
  482. SysCtlPeripheralPresent(uint32_t ui32Peripheral)
  483. {
  484. //
  485. // Check the arguments.
  486. //
  487. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  488. //
  489. // See if this peripheral is present.
  490. //
  491. return (HWREGBITW(SYSCTL_PPBASE + ((ui32Peripheral & 0xff00) >> 8),
  492. ui32Peripheral & 0xff));
  493. }
  494. //*****************************************************************************
  495. //
  496. //! Determines if a peripheral is ready.
  497. //!
  498. //! \param ui32Peripheral is the peripheral in question.
  499. //!
  500. //! This function determines if a particular peripheral is ready to be
  501. //! accessed. The peripheral may be in a non-ready state if it is not enabled,
  502. //! is being held in reset, or is in the process of becoming ready after being
  503. //! enabled or taken out of reset.
  504. //!
  505. //! The \e ui32Peripheral parameter must be only one of the following values:
  506. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  507. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CCM0,\b SYSCTL_PERIPH_COMP0,
  508. //! \b SYSCTL_PERIPH_EEPROM0, \b SYSCTL_PERIPH_EMAC, \b SYSCTL_PERIPH_EPHY,
  509. //! \b SYSCTL_PERIPH_EPI0,
  510. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  511. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  512. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  513. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  514. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  515. //! \b SYSCTL_PERIPH_GPIOR, \b SYSCTL_PERIPH_GPIOS, \b SYSCTL_PERIPH_GPIOT,
  516. //! \b SYSCTL_PERIPH_HIBERNATE,
  517. //! \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_I2C2,
  518. //! \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4, \b SYSCTL_PERIPH_I2C5,
  519. //! \b SYSCTL_PERIPH_I2C6, \b SYSCTL_PERIPH_I2C7, \b SYSCTL_PERIPH_I2C8,
  520. //! \b SYSCTL_PERIPH_I2C9, \b SYSCTL_PERIPH_LCD0,
  521. //! \b SYSCTL_PERIPH_ONEWIRE0,
  522. //! \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1, \b SYSCTL_PERIPH_QEI0,
  523. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  524. //! \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3, \b SYSCTL_PERIPH_TIMER0,
  525. //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_TIMER3,
  526. //! \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5, \b SYSCTL_PERIPH_TIMER6,
  527. //! \b SYSCTL_PERIPH_TIMER7, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  528. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4,
  529. //! \b SYSCTL_PERIPH_UART5, \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7,
  530. //! \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0,
  531. //! or \b SYSCTL_PERIPH_WDOG1
  532. //!
  533. //! \return Returns \b true if the specified peripheral is ready and \b false
  534. //! if it is not.
  535. //
  536. //*****************************************************************************
  537. bool
  538. SysCtlPeripheralReady(uint32_t ui32Peripheral)
  539. {
  540. //
  541. // Check the arguments.
  542. //
  543. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  544. //
  545. // See if this peripheral is ready.
  546. //
  547. return (HWREGBITW(SYSCTL_PRBASE + ((ui32Peripheral & 0xff00) >> 8),
  548. ui32Peripheral & 0xff));
  549. }
  550. //*****************************************************************************
  551. //
  552. //! Powers on a peripheral.
  553. //!
  554. //! \param ui32Peripheral is the peripheral to be powered on.
  555. //!
  556. //! This function turns on the power to a peripheral. The peripheral continues
  557. //! to receive power even when its clock is not enabled.
  558. //!
  559. //! The \e ui32Peripheral parameter must be only one of the following values:
  560. //! \b SYSCTL_PERIPH_CAN0,\b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_EMAC,
  561. //! \b SYSCTL_PERIPH_EPHY, \b SYSCTL_PERIPH_LCD0, \b SYSCTL_PERIPH_USB0
  562. //!
  563. //! \return None.
  564. //
  565. //*****************************************************************************
  566. void
  567. SysCtlPeripheralPowerOn(uint32_t ui32Peripheral)
  568. {
  569. //
  570. // Check the arguments.
  571. //
  572. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  573. //
  574. // Power on this peripheral.
  575. //
  576. HWREGBITW(SYSCTL_PCBASE + ((ui32Peripheral & 0xff00) >> 8),
  577. ui32Peripheral & 0xff) = 1;
  578. }
  579. //*****************************************************************************
  580. //
  581. //! Powers off a peripheral.
  582. //!
  583. //! \param ui32Peripheral is the peripheral to be powered off.
  584. //!
  585. //! This function allows the power to a peripheral to be turned off. The
  586. //! peripheral continues to receive power when its clock is enabled, but
  587. //! the power is removed when its clock is disabled.
  588. //!
  589. //! The \e ui32Peripheral parameter must be only one of the following values:
  590. //! \b SYSCTL_PERIPH_CAN0,\b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_EMAC,
  591. //! \b SYSCTL_PERIPH_EPHY, \b SYSCTL_PERIPH_LCD0, \b SYSCTL_PERIPH_USB0
  592. //!
  593. //! \return None.
  594. //
  595. //*****************************************************************************
  596. void
  597. SysCtlPeripheralPowerOff(uint32_t ui32Peripheral)
  598. {
  599. //
  600. // Check the arguments.
  601. //
  602. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  603. //
  604. // Power off this peripheral.
  605. //
  606. HWREGBITW(SYSCTL_PCBASE + ((ui32Peripheral & 0xff00) >> 8),
  607. ui32Peripheral & 0xff) = 0;
  608. }
  609. //*****************************************************************************
  610. //
  611. //! Performs a software reset of a peripheral.
  612. //!
  613. //! \param ui32Peripheral is the peripheral to reset.
  614. //!
  615. //! This function performs a software reset of the specified peripheral. An
  616. //! individual peripheral reset signal is asserted for a brief period and then
  617. //! de-asserted, returning the internal state of the peripheral to its reset
  618. //! condition.
  619. //!
  620. //! The \e ui32Peripheral parameter must be only one of the following values:
  621. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  622. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CCM0,\b SYSCTL_PERIPH_COMP0,
  623. //! \b SYSCTL_PERIPH_EEPROM0, \b SYSCTL_PERIPH_EMAC, \b SYSCTL_PERIPH_EPHY,
  624. //! \b SYSCTL_PERIPH_EPI0,
  625. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  626. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  627. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  628. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  629. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  630. //! \b SYSCTL_PERIPH_GPIOR, \b SYSCTL_PERIPH_GPIOS, \b SYSCTL_PERIPH_GPIOT,
  631. //! \b SYSCTL_PERIPH_HIBERNATE,
  632. //! \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_I2C2,
  633. //! \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4, \b SYSCTL_PERIPH_I2C5,
  634. //! \b SYSCTL_PERIPH_I2C6, \b SYSCTL_PERIPH_I2C7, \b SYSCTL_PERIPH_I2C8,
  635. //! \b SYSCTL_PERIPH_I2C9, \b SYSCTL_PERIPH_LCD0,
  636. //! \b SYSCTL_PERIPH_ONEWIRE0,
  637. //! \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1, \b SYSCTL_PERIPH_QEI0,
  638. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  639. //! \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3, \b SYSCTL_PERIPH_TIMER0,
  640. //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_TIMER3,
  641. //! \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5, \b SYSCTL_PERIPH_TIMER6,
  642. //! \b SYSCTL_PERIPH_TIMER7, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  643. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4,
  644. //! \b SYSCTL_PERIPH_UART5, \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7,
  645. //! \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0,
  646. //! or \b SYSCTL_PERIPH_WDOG1
  647. //!
  648. //! \return None.
  649. //
  650. //*****************************************************************************
  651. void
  652. SysCtlPeripheralReset(uint32_t ui32Peripheral)
  653. {
  654. volatile uint_fast8_t ui8Delay;
  655. //
  656. // Check the arguments.
  657. //
  658. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  659. //
  660. // Put the peripheral into the reset state.
  661. //
  662. HWREGBITW(SYSCTL_SRBASE + ((ui32Peripheral & 0xff00) >> 8),
  663. ui32Peripheral & 0xff) = 1;
  664. //
  665. // Delay for a little bit.
  666. //
  667. for (ui8Delay = 0; ui8Delay < 16; ui8Delay++)
  668. {
  669. }
  670. //
  671. // Take the peripheral out of the reset state.
  672. //
  673. HWREGBITW(SYSCTL_SRBASE + ((ui32Peripheral & 0xff00) >> 8),
  674. ui32Peripheral & 0xff) = 0;
  675. }
  676. //*****************************************************************************
  677. //
  678. //! Enables a peripheral.
  679. //!
  680. //! \param ui32Peripheral is the peripheral to enable.
  681. //!
  682. //! This function enables a peripheral. At power-up, all peripherals are
  683. //! disabled; they must be enabled in order to operate or respond to register
  684. //! reads/writes.
  685. //!
  686. //! The \e ui32Peripheral parameter must be only one of the following values:
  687. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  688. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CCM0,\b SYSCTL_PERIPH_COMP0,
  689. //! \b SYSCTL_PERIPH_EEPROM0, \b SYSCTL_PERIPH_EMAC, \b SYSCTL_PERIPH_EPHY,
  690. //! \b SYSCTL_PERIPH_EPI0,
  691. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  692. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  693. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  694. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  695. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  696. //! \b SYSCTL_PERIPH_GPIOR, \b SYSCTL_PERIPH_GPIOS, \b SYSCTL_PERIPH_GPIOT,
  697. //! \b SYSCTL_PERIPH_HIBERNATE,
  698. //! \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_I2C2,
  699. //! \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4, \b SYSCTL_PERIPH_I2C5,
  700. //! \b SYSCTL_PERIPH_I2C6, \b SYSCTL_PERIPH_I2C7, \b SYSCTL_PERIPH_I2C8,
  701. //! \b SYSCTL_PERIPH_I2C9, \b SYSCTL_PERIPH_LCD0,
  702. //! \b SYSCTL_PERIPH_ONEWIRE0,
  703. //! \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1, \b SYSCTL_PERIPH_QEI0,
  704. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  705. //! \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3, \b SYSCTL_PERIPH_TIMER0,
  706. //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_TIMER3,
  707. //! \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5, \b SYSCTL_PERIPH_TIMER6,
  708. //! \b SYSCTL_PERIPH_TIMER7, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  709. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4,
  710. //! \b SYSCTL_PERIPH_UART5, \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7,
  711. //! \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0,
  712. //! or \b SYSCTL_PERIPH_WDOG1
  713. //!
  714. //! \note It takes five clock cycles after the write to enable a peripheral
  715. //! before the the peripheral is actually enabled. During this time, attempts
  716. //! to access the peripheral result in a bus fault. Care should be taken
  717. //! to ensure that the peripheral is not accessed during this brief time
  718. //! period.
  719. //!
  720. //! \return None.
  721. //
  722. //*****************************************************************************
  723. void
  724. SysCtlPeripheralEnable(uint32_t ui32Peripheral)
  725. {
  726. //
  727. // Check the arguments.
  728. //
  729. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  730. //
  731. // Enable this peripheral.
  732. //
  733. HWREGBITW(SYSCTL_RCGCBASE + ((ui32Peripheral & 0xff00) >> 8),
  734. ui32Peripheral & 0xff) = 1;
  735. }
  736. //*****************************************************************************
  737. //
  738. //! Disables a peripheral.
  739. //!
  740. //! \param ui32Peripheral is the peripheral to disable.
  741. //!
  742. //! This function disables a peripheral. Once disabled, they do not operate or
  743. //! respond to register reads/writes.
  744. //!
  745. //! The \e ui32Peripheral parameter must be only one of the following values:
  746. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  747. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CCM0,\b SYSCTL_PERIPH_COMP0,
  748. //! \b SYSCTL_PERIPH_EEPROM0, \b SYSCTL_PERIPH_EMAC, \b SYSCTL_PERIPH_EPHY,
  749. //! \b SYSCTL_PERIPH_EPI0,
  750. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  751. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  752. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  753. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  754. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  755. //! \b SYSCTL_PERIPH_GPIOR, \b SYSCTL_PERIPH_GPIOS, \b SYSCTL_PERIPH_GPIOT,
  756. //! \b SYSCTL_PERIPH_HIBERNATE,
  757. //! \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_I2C2,
  758. //! \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4, \b SYSCTL_PERIPH_I2C5,
  759. //! \b SYSCTL_PERIPH_I2C6, \b SYSCTL_PERIPH_I2C7, \b SYSCTL_PERIPH_I2C8,
  760. //! \b SYSCTL_PERIPH_I2C9, \b SYSCTL_PERIPH_LCD0,
  761. //! \b SYSCTL_PERIPH_ONEWIRE0,
  762. //! \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1, \b SYSCTL_PERIPH_QEI0,
  763. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  764. //! \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3, \b SYSCTL_PERIPH_TIMER0,
  765. //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_TIMER3,
  766. //! \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5, \b SYSCTL_PERIPH_TIMER6,
  767. //! \b SYSCTL_PERIPH_TIMER7, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  768. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4,
  769. //! \b SYSCTL_PERIPH_UART5, \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7,
  770. //! \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0,
  771. //! or \b SYSCTL_PERIPH_WDOG1
  772. //!
  773. //! \return None.
  774. //
  775. //*****************************************************************************
  776. void
  777. SysCtlPeripheralDisable(uint32_t ui32Peripheral)
  778. {
  779. //
  780. // Check the arguments.
  781. //
  782. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  783. //
  784. // Disable this peripheral.
  785. //
  786. HWREGBITW(SYSCTL_RCGCBASE + ((ui32Peripheral & 0xff00) >> 8),
  787. ui32Peripheral & 0xff) = 0;
  788. }
  789. //*****************************************************************************
  790. //
  791. //! Enables a peripheral in sleep mode.
  792. //!
  793. //! \param ui32Peripheral is the peripheral to enable in sleep mode.
  794. //!
  795. //! This function allows a peripheral to continue operating when the processor
  796. //! goes into sleep mode. Because the clocking configuration of the device
  797. //! does not change, any peripheral can safely continue operating while the
  798. //! processor is in sleep mode and can therefore wake the processor from sleep
  799. //! mode.
  800. //!
  801. //! Sleep mode clocking of peripherals must be enabled via
  802. //! SysCtlPeripheralClockGating(); if disabled, the peripheral sleep mode
  803. //! configuration is maintained but has no effect when sleep mode is entered.
  804. //!
  805. //! The \e ui32Peripheral parameter must be only one of the following values:
  806. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  807. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CCM0,\b SYSCTL_PERIPH_COMP0,
  808. //! \b SYSCTL_PERIPH_EEPROM0, \b SYSCTL_PERIPH_EMAC, \b SYSCTL_PERIPH_EPHY,
  809. //! \b SYSCTL_PERIPH_EPI0,
  810. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  811. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  812. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  813. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  814. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  815. //! \b SYSCTL_PERIPH_GPIOR, \b SYSCTL_PERIPH_GPIOS, \b SYSCTL_PERIPH_GPIOT,
  816. //! \b SYSCTL_PERIPH_HIBERNATE,
  817. //! \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_I2C2,
  818. //! \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4, \b SYSCTL_PERIPH_I2C5,
  819. //! \b SYSCTL_PERIPH_I2C6, \b SYSCTL_PERIPH_I2C7, \b SYSCTL_PERIPH_I2C8,
  820. //! \b SYSCTL_PERIPH_I2C9, \b SYSCTL_PERIPH_LCD0,
  821. //! \b SYSCTL_PERIPH_ONEWIRE0,
  822. //! \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1, \b SYSCTL_PERIPH_QEI0,
  823. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  824. //! \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3, \b SYSCTL_PERIPH_TIMER0,
  825. //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_TIMER3,
  826. //! \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5, \b SYSCTL_PERIPH_TIMER6,
  827. //! \b SYSCTL_PERIPH_TIMER7, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  828. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4,
  829. //! \b SYSCTL_PERIPH_UART5, \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7,
  830. //! \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0,
  831. //! or \b SYSCTL_PERIPH_WDOG1
  832. //!
  833. //! \return None.
  834. //
  835. //*****************************************************************************
  836. void
  837. SysCtlPeripheralSleepEnable(uint32_t ui32Peripheral)
  838. {
  839. //
  840. // Check the arguments.
  841. //
  842. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  843. //
  844. // Enable this peripheral in sleep mode.
  845. //
  846. HWREGBITW(SYSCTL_SCGCBASE + ((ui32Peripheral & 0xff00) >> 8),
  847. ui32Peripheral & 0xff) = 1;
  848. }
  849. //*****************************************************************************
  850. //
  851. //! Disables a peripheral in sleep mode.
  852. //!
  853. //! \param ui32Peripheral is the peripheral to disable in sleep mode.
  854. //!
  855. //! This function causes a peripheral to stop operating when the processor goes
  856. //! into sleep mode. Disabling peripherals while in sleep mode helps to lower
  857. //! the current draw of the device. If enabled (via SysCtlPeripheralEnable()),
  858. //! the peripheral automatically resumes operation when the processor
  859. //! leaves sleep mode, maintaining its entire state from before sleep mode was
  860. //! entered.
  861. //!
  862. //! Sleep mode clocking of peripherals must be enabled via
  863. //! SysCtlPeripheralClockGating(); if disabled, the peripheral sleep mode
  864. //! configuration is maintained but has no effect when sleep mode is entered.
  865. //!
  866. //! The \e ui32Peripheral parameter must be only one of the following values:
  867. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  868. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CCM0,\b SYSCTL_PERIPH_COMP0,
  869. //! \b SYSCTL_PERIPH_EEPROM0, \b SYSCTL_PERIPH_EMAC, \b SYSCTL_PERIPH_EPHY,
  870. //! \b SYSCTL_PERIPH_EPI0,
  871. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  872. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  873. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  874. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  875. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  876. //! \b SYSCTL_PERIPH_GPIOR, \b SYSCTL_PERIPH_GPIOS, \b SYSCTL_PERIPH_GPIOT,
  877. //! \b SYSCTL_PERIPH_HIBERNATE,
  878. //! \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_I2C2,
  879. //! \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4, \b SYSCTL_PERIPH_I2C5,
  880. //! \b SYSCTL_PERIPH_I2C6, \b SYSCTL_PERIPH_I2C7, \b SYSCTL_PERIPH_I2C8,
  881. //! \b SYSCTL_PERIPH_I2C9, \b SYSCTL_PERIPH_LCD0,
  882. //! \b SYSCTL_PERIPH_ONEWIRE0,
  883. //! \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1, \b SYSCTL_PERIPH_QEI0,
  884. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  885. //! \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3, \b SYSCTL_PERIPH_TIMER0,
  886. //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_TIMER3,
  887. //! \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5, \b SYSCTL_PERIPH_TIMER6,
  888. //! \b SYSCTL_PERIPH_TIMER7, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  889. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4,
  890. //! \b SYSCTL_PERIPH_UART5, \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7,
  891. //! \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0,
  892. //! or \b SYSCTL_PERIPH_WDOG1
  893. //!
  894. //! \return None.
  895. //
  896. //*****************************************************************************
  897. void
  898. SysCtlPeripheralSleepDisable(uint32_t ui32Peripheral)
  899. {
  900. //
  901. // Check the arguments.
  902. //
  903. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  904. //
  905. // Disable this peripheral in sleep mode.
  906. //
  907. HWREGBITW(SYSCTL_SCGCBASE + ((ui32Peripheral & 0xff00) >> 8),
  908. ui32Peripheral & 0xff) = 0;
  909. }
  910. //*****************************************************************************
  911. //
  912. //! Enables a peripheral in deep-sleep mode.
  913. //!
  914. //! \param ui32Peripheral is the peripheral to enable in deep-sleep mode.
  915. //!
  916. //! This function allows a peripheral to continue operating when the processor
  917. //! goes into deep-sleep mode. Because the clocking configuration of the
  918. //! device may change, not all peripherals can safely continue operating while
  919. //! the processor is in deep-sleep mode. Those that must run at a particular
  920. //! frequency (such as a UART) do not work as expected if the clock changes.
  921. //! It is the responsibility of the caller to make sensible choices.
  922. //!
  923. //! Deep-sleep mode clocking of peripherals must be enabled via
  924. //! SysCtlPeripheralClockGating(); if disabled, the peripheral deep-sleep mode
  925. //! configuration is maintained but has no effect when deep-sleep mode is
  926. //! entered.
  927. //!
  928. //! The \e ui32Peripheral parameter must be only one of the following values:
  929. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  930. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CCM0,\b SYSCTL_PERIPH_COMP0,
  931. //! \b SYSCTL_PERIPH_EEPROM0, \b SYSCTL_PERIPH_EMAC, \b SYSCTL_PERIPH_EPHY,
  932. //! \b SYSCTL_PERIPH_EPI0,
  933. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  934. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  935. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  936. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  937. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  938. //! \b SYSCTL_PERIPH_GPIOR, \b SYSCTL_PERIPH_GPIOS, \b SYSCTL_PERIPH_GPIOT,
  939. //! \b SYSCTL_PERIPH_HIBERNATE,
  940. //! \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_I2C2,
  941. //! \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4, \b SYSCTL_PERIPH_I2C5,
  942. //! \b SYSCTL_PERIPH_I2C6, \b SYSCTL_PERIPH_I2C7, \b SYSCTL_PERIPH_I2C8,
  943. //! \b SYSCTL_PERIPH_I2C9, \b SYSCTL_PERIPH_LCD0,
  944. //! \b SYSCTL_PERIPH_ONEWIRE0,
  945. //! \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1, \b SYSCTL_PERIPH_QEI0,
  946. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  947. //! \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3, \b SYSCTL_PERIPH_TIMER0,
  948. //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_TIMER3,
  949. //! \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5, \b SYSCTL_PERIPH_TIMER6,
  950. //! \b SYSCTL_PERIPH_TIMER7, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  951. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4,
  952. //! \b SYSCTL_PERIPH_UART5, \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7,
  953. //! \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0,
  954. //! or \b SYSCTL_PERIPH_WDOG1
  955. //!
  956. //! \return None.
  957. //
  958. //*****************************************************************************
  959. void
  960. SysCtlPeripheralDeepSleepEnable(uint32_t ui32Peripheral)
  961. {
  962. //
  963. // Check the arguments.
  964. //
  965. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  966. //
  967. // Enable this peripheral in deep-sleep mode.
  968. //
  969. HWREGBITW(SYSCTL_DCGCBASE + ((ui32Peripheral & 0xff00) >> 8),
  970. ui32Peripheral & 0xff) = 1;
  971. }
  972. //*****************************************************************************
  973. //
  974. //! Disables a peripheral in deep-sleep mode.
  975. //!
  976. //! \param ui32Peripheral is the peripheral to disable in deep-sleep mode.
  977. //!
  978. //! This function causes a peripheral to stop operating when the processor goes
  979. //! into deep-sleep mode. Disabling peripherals while in deep-sleep mode helps
  980. //! to lower the current draw of the device, and can keep peripherals that
  981. //! require a particular clock frequency from operating when the clock changes
  982. //! as a result of entering deep-sleep mode. If enabled (via
  983. //! SysCtlPeripheralEnable()), the peripheral automatically resumes
  984. //! operation when the processor leaves deep-sleep mode, maintaining its entire
  985. //! state from before deep-sleep mode was entered.
  986. //!
  987. //! Deep-sleep mode clocking of peripherals must be enabled via
  988. //! SysCtlPeripheralClockGating(); if disabled, the peripheral deep-sleep mode
  989. //! configuration is maintained but has no effect when deep-sleep mode is
  990. //! entered.
  991. //!
  992. //! The \e ui32Peripheral parameter must be only one of the following values:
  993. //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
  994. //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CCM0,\b SYSCTL_PERIPH_COMP0,
  995. //! \b SYSCTL_PERIPH_EEPROM0, \b SYSCTL_PERIPH_EMAC, \b SYSCTL_PERIPH_EPHY,
  996. //! \b SYSCTL_PERIPH_EPI0,
  997. //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
  998. //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
  999. //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
  1000. //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
  1001. //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
  1002. //! \b SYSCTL_PERIPH_GPIOR, \b SYSCTL_PERIPH_GPIOS, \b SYSCTL_PERIPH_GPIOT,
  1003. //! \b SYSCTL_PERIPH_HIBERNATE,
  1004. //! \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_I2C2,
  1005. //! \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4, \b SYSCTL_PERIPH_I2C5,
  1006. //! \b SYSCTL_PERIPH_I2C6, \b SYSCTL_PERIPH_I2C7, \b SYSCTL_PERIPH_I2C8,
  1007. //! \b SYSCTL_PERIPH_I2C9, \b SYSCTL_PERIPH_LCD0,
  1008. //! \b SYSCTL_PERIPH_ONEWIRE0,
  1009. //! \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1, \b SYSCTL_PERIPH_QEI0,
  1010. //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
  1011. //! \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3, \b SYSCTL_PERIPH_TIMER0,
  1012. //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_TIMER3,
  1013. //! \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5, \b SYSCTL_PERIPH_TIMER6,
  1014. //! \b SYSCTL_PERIPH_TIMER7, \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1,
  1015. //! \b SYSCTL_PERIPH_UART2, \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4,
  1016. //! \b SYSCTL_PERIPH_UART5, \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7,
  1017. //! \b SYSCTL_PERIPH_UDMA, \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0,
  1018. //! or \b SYSCTL_PERIPH_WDOG1
  1019. //!
  1020. //! \return None.
  1021. //
  1022. //*****************************************************************************
  1023. void
  1024. SysCtlPeripheralDeepSleepDisable(uint32_t ui32Peripheral)
  1025. {
  1026. //
  1027. // Check the arguments.
  1028. //
  1029. ASSERT(_SysCtlPeripheralValid(ui32Peripheral));
  1030. //
  1031. // Disable this peripheral in deep-sleep mode.
  1032. //
  1033. HWREGBITW(SYSCTL_DCGCBASE + ((ui32Peripheral & 0xff00) >> 8),
  1034. ui32Peripheral & 0xff) = 0;
  1035. }
  1036. //*****************************************************************************
  1037. //
  1038. //! Controls peripheral clock gating in sleep and deep-sleep mode.
  1039. //!
  1040. //! \param bEnable is a boolean that is \b true if the sleep and deep-sleep
  1041. //! peripheral configuration should be used and \b false if not.
  1042. //!
  1043. //! This function controls how peripherals are clocked when the processor goes
  1044. //! into sleep or deep-sleep mode. By default, the peripherals are clocked the
  1045. //! same as in run mode; if peripheral clock gating is enabled, they are
  1046. //! clocked according to the configuration set by
  1047. //! SysCtlPeripheralSleepEnable(), SysCtlPeripheralSleepDisable(),
  1048. //! SysCtlPeripheralDeepSleepEnable(), and SysCtlPeripheralDeepSleepDisable().
  1049. //!
  1050. //! \return None.
  1051. //
  1052. //*****************************************************************************
  1053. void
  1054. SysCtlPeripheralClockGating(bool bEnable)
  1055. {
  1056. //
  1057. // Enable peripheral clock gating as requested.
  1058. //
  1059. if (bEnable)
  1060. {
  1061. HWREG(SYSCTL_RSCLKCFG) |= SYSCTL_RSCLKCFG_ACG;
  1062. }
  1063. else
  1064. {
  1065. HWREG(SYSCTL_RSCLKCFG) &= ~SYSCTL_RSCLKCFG_ACG;
  1066. }
  1067. }
  1068. //*****************************************************************************
  1069. //
  1070. //! Registers an interrupt handler for the system control interrupt.
  1071. //!
  1072. //! \param pfnHandler is a pointer to the function to be called when the system
  1073. //! control interrupt occurs.
  1074. //!
  1075. //! This function registers the handler to be called when a system control
  1076. //! interrupt occurs. This function enables the global interrupt in the
  1077. //! interrupt controller; specific system control interrupts must be enabled
  1078. //! via SysCtlIntEnable(). It is the interrupt handler's responsibility to
  1079. //! clear the interrupt source via SysCtlIntClear().
  1080. //!
  1081. //! System control can generate interrupts when the PLL achieves lock, if the
  1082. //! internal LDO current limit is exceeded, if the internal oscillator fails,
  1083. //! if the main oscillator fails, if the internal LDO output voltage droops too
  1084. //! much, if the external voltage droops too much, or if the PLL fails.
  1085. //!
  1086. //! \sa IntRegister() for important information about registering interrupt
  1087. //! handlers.
  1088. //!
  1089. //! \return None.
  1090. //
  1091. //*****************************************************************************
  1092. void
  1093. SysCtlIntRegister(void (*pfnHandler)(void))
  1094. {
  1095. //
  1096. // Register the interrupt handler, returning an error if an error occurs.
  1097. //
  1098. IntRegister(INT_SYSCTL, pfnHandler);
  1099. //
  1100. // Enable the system control interrupt.
  1101. //
  1102. IntEnable(INT_SYSCTL);
  1103. }
  1104. //*****************************************************************************
  1105. //
  1106. //! Unregisters the interrupt handler for the system control interrupt.
  1107. //!
  1108. //! This function unregisters the handler to be called when a system control
  1109. //! interrupt occurs. This function also masks off the interrupt in the
  1110. //! interrupt controller so that the interrupt handler no longer is called.
  1111. //!
  1112. //! \sa IntRegister() for important information about registering interrupt
  1113. //! handlers.
  1114. //!
  1115. //! \return None.
  1116. //
  1117. //*****************************************************************************
  1118. void
  1119. SysCtlIntUnregister(void)
  1120. {
  1121. //
  1122. // Disable the interrupt.
  1123. //
  1124. IntDisable(INT_SYSCTL);
  1125. //
  1126. // Unregister the interrupt handler.
  1127. //
  1128. IntUnregister(INT_SYSCTL);
  1129. }
  1130. //*****************************************************************************
  1131. //
  1132. //! Enables individual system control interrupt sources.
  1133. //!
  1134. //! \param ui32Ints is a bit mask of the interrupt sources to be enabled. Must
  1135. //! be a logical OR of \b SYSCTL_INT_BOR0, \b SYSCTL_INT_VDDA_OK,
  1136. //! \b SYSCTL_INT_MOSC_PUP, \b SYSCTL_INT_USBPLL_LOCK,
  1137. //! \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_BOR, and/or
  1138. //! \b SYSCTL_INT_BOR1.
  1139. //!
  1140. //! This function enables the indicated system control interrupt sources. Only
  1141. //! the sources that are enabled can be reflected to the processor interrupt;
  1142. //! disabled sources have no effect on the processor.
  1143. //!
  1144. //! \return None.
  1145. //
  1146. //*****************************************************************************
  1147. void
  1148. SysCtlIntEnable(uint32_t ui32Ints)
  1149. {
  1150. //
  1151. // Enable the specified interrupts.
  1152. //
  1153. HWREG(SYSCTL_IMC) |= ui32Ints;
  1154. }
  1155. //*****************************************************************************
  1156. //
  1157. //! Disables individual system control interrupt sources.
  1158. //!
  1159. //! \param ui32Ints is a bit mask of the interrupt sources to be disabled.
  1160. //! Must be a logical OR of \b SYSCTL_INT_BOR0, \b SYSCTL_INT_VDDA_OK,
  1161. //! \b SYSCTL_INT_MOSC_PUP, \b SYSCTL_INT_USBPLL_LOCK,
  1162. //! \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_BOR, and/or
  1163. //! \b SYSCTL_INT_BOR1.
  1164. //!
  1165. //! This function disables the indicated system control interrupt sources.
  1166. //! Only the sources that are enabled can be reflected to the processor
  1167. //! interrupt; disabled sources have no effect on the processor.
  1168. //!
  1169. //! \return None.
  1170. //
  1171. //*****************************************************************************
  1172. void
  1173. SysCtlIntDisable(uint32_t ui32Ints)
  1174. {
  1175. //
  1176. // Disable the specified interrupts.
  1177. //
  1178. HWREG(SYSCTL_IMC) &= ~(ui32Ints);
  1179. }
  1180. //*****************************************************************************
  1181. //
  1182. //! Clears system control interrupt sources.
  1183. //!
  1184. //! \param ui32Ints is a bit mask of the interrupt sources to be cleared. Must
  1185. //! be a logical OR of \b SYSCTL_INT_BOR0, \b SYSCTL_INT_VDDA_OK,
  1186. //! \b SYSCTL_INT_MOSC_PUP, \b SYSCTL_INT_USBPLL_LOCK,
  1187. //! \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_BOR, and/or
  1188. //! \b SYSCTL_INT_BOR1.
  1189. //!
  1190. //! The specified system control interrupt sources are cleared, so that they no
  1191. //! longer assert. This function must be called in the interrupt handler to
  1192. //! keep it from being called again immediately on exit.
  1193. //!
  1194. //! \note Because there is a write buffer in the Cortex-M processor, it may
  1195. //! take several clock cycles before the interrupt source is actually cleared.
  1196. //! Therefore, it is recommended that the interrupt source be cleared early in
  1197. //! the interrupt handler (as opposed to the very last action) to avoid
  1198. //! returning from the interrupt handler before the interrupt source is
  1199. //! actually cleared. Failure to do so may result in the interrupt handler
  1200. //! being immediately reentered (because the interrupt controller still sees
  1201. //! the interrupt source asserted).
  1202. //!
  1203. //! \return None.
  1204. //
  1205. //*****************************************************************************
  1206. void
  1207. SysCtlIntClear(uint32_t ui32Ints)
  1208. {
  1209. //
  1210. // Clear the requested interrupt sources.
  1211. //
  1212. HWREG(SYSCTL_MISC) = ui32Ints;
  1213. }
  1214. //*****************************************************************************
  1215. //
  1216. //! Gets the current interrupt status.
  1217. //!
  1218. //! \param bMasked is false if the raw interrupt status is required and true if
  1219. //! the masked interrupt status is required.
  1220. //!
  1221. //! This function returns the interrupt status for the system controller.
  1222. //! Either the raw interrupt status or the status of interrupts that are
  1223. //! allowed to reflect to the processor can be returned.
  1224. //!
  1225. //! \return The current interrupt status, enumerated as a bit field of
  1226. //! \b SYSCTL_INT_BOR0, \b SYSCTL_INT_VDDA_OK,
  1227. //! \b SYSCTL_INT_MOSC_PUP, \b SYSCTL_INT_USBPLL_LOCK,
  1228. //! \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_BOR, and/or
  1229. //! \b SYSCTL_INT_BOR1.
  1230. //
  1231. //*****************************************************************************
  1232. uint32_t
  1233. SysCtlIntStatus(bool bMasked)
  1234. {
  1235. //
  1236. // Return either the interrupt status or the raw interrupt status as
  1237. // requested.
  1238. //
  1239. if (bMasked)
  1240. {
  1241. return (HWREG(SYSCTL_MISC));
  1242. }
  1243. else
  1244. {
  1245. return (HWREG(SYSCTL_RIS));
  1246. }
  1247. }
  1248. //*****************************************************************************
  1249. //
  1250. //! Sets the output voltage of the LDO when the device enters deep-sleep
  1251. //! mode.
  1252. //!
  1253. //! \param ui32Voltage is the required output voltage from the LDO while in
  1254. //! deep-sleep mode.
  1255. //!
  1256. //! This function sets the output voltage of the LDO while in deep-sleep mode.
  1257. //! The \e ui32Voltage parameter specifies the output voltage of the LDO and
  1258. //! must be one of the following values: \b SYSCTL_LDO_0_90V,
  1259. //! \b SYSCTL_LDO_0_95V, \b SYSCTL_LDO_1_00V, \b SYSCTL_LDO_1_05V,
  1260. //! \b SYSCTL_LDO_1_10V, \b SYSCTL_LDO_1_15V, or \b SYSCTL_LDO_1_20V.
  1261. //!
  1262. //! \return None.
  1263. //
  1264. //*****************************************************************************
  1265. void
  1266. SysCtlLDODeepSleepSet(uint32_t ui32Voltage)
  1267. {
  1268. //
  1269. // Check the arguments.
  1270. //
  1271. ASSERT((ui32Voltage == SYSCTL_LDO_0_90V) ||
  1272. (ui32Voltage == SYSCTL_LDO_0_95V) ||
  1273. (ui32Voltage == SYSCTL_LDO_1_00V) ||
  1274. (ui32Voltage == SYSCTL_LDO_1_05V) ||
  1275. (ui32Voltage == SYSCTL_LDO_1_10V) ||
  1276. (ui32Voltage == SYSCTL_LDO_1_15V) ||
  1277. (ui32Voltage == SYSCTL_LDO_1_20V));
  1278. //
  1279. // Set the deep-sleep LDO voltage to the requested value.
  1280. //
  1281. HWREG(SYSCTL_LDODPCTL) = ui32Voltage;
  1282. }
  1283. //*****************************************************************************
  1284. //
  1285. //! Returns the output voltage of the LDO when the device enters deep-sleep
  1286. //! mode.
  1287. //!
  1288. //! This function returns the output voltage of the LDO when the device is
  1289. //! in deep-sleep mode, as specified by the control register.
  1290. //!
  1291. //! \return Returns the deep-sleep-mode voltage of the LDO; is one of
  1292. //! \b SYSCTL_LDO_0_90V, \b SYSCTL_LDO_0_95V, \b SYSCTL_LDO_1_00V,
  1293. //! \b SYSCTL_LDO_1_05V, \b SYSCTL_LDO_1_10V, \b SYSCTL_LDO_1_15V, or
  1294. //! \b SYSCTL_LDO_1_20V.
  1295. //
  1296. //*****************************************************************************
  1297. uint32_t
  1298. SysCtlLDODeepSleepGet(void)
  1299. {
  1300. //
  1301. // Return the deep-sleep-mode LDO voltage setting.
  1302. //
  1303. return (HWREG(SYSCTL_LDODPCTL));
  1304. }
  1305. //*****************************************************************************
  1306. //
  1307. //! Configures the power to the flash and SRAM while in sleep mode.
  1308. //!
  1309. //! \param ui32Config is the required flash and SRAM power configuration.
  1310. //!
  1311. //! This function allows the power configuration of the flash and SRAM while in
  1312. //! sleep mode to be set. The \e ui32Config parameter is the logical OR of the
  1313. //! flash power configuration and the SRAM power configuration.
  1314. //!
  1315. //! The flash power configuration is specified as either:
  1316. //!
  1317. //! - \b SYSCTL_FLASH_NORMAL - The flash is left in fully powered mode,
  1318. //! providing fast wake-up time but higher power consumption.
  1319. //! - \b SYSCTL_FLASH_LOW_POWER - The flash is in low power mode, providing
  1320. //! reduced power consumption but longer wake-up time.
  1321. //!
  1322. //! The SRAM power configuration is specified as one of:
  1323. //!
  1324. //! - \b SYSCTL_SRAM_NORMAL - The SRAM is left in fully powered mode, providing
  1325. //! fast wake-up time but higher power consumption.
  1326. //! - \b SYSCTL_SRAM_STANDBY - The SRAM is placed into a lower power mode,
  1327. //! providing reduced power consumption but longer wake-up time.
  1328. //! - \b SYSCTL_SRAM_LOW_POWER - The SRAM is placed into lowest power mode,
  1329. //! providing further reduced power consumption but longer wake-up time.
  1330. //!
  1331. //! \return None.
  1332. //
  1333. //*****************************************************************************
  1334. void
  1335. SysCtlSleepPowerSet(uint32_t ui32Config)
  1336. {
  1337. //
  1338. // Set the sleep-mode flash and SRAM power configuration.
  1339. //
  1340. HWREG(SYSCTL_SLPPWRCFG) = ui32Config;
  1341. }
  1342. //*****************************************************************************
  1343. //
  1344. //! Configures the power to the flash and SRAM while in deep-sleep mode.
  1345. //!
  1346. //! \param ui32Config is the required flash and SRAM power configuration.
  1347. //!
  1348. //! This function allows the power configuration of the flash and SRAM while in
  1349. //! deep-sleep mode to be set. The \e ui32Config parameter is the logical OR
  1350. //! of the flash power configuration and the SRAM power configuration.
  1351. //!
  1352. //! The flash power configuration is specified as either:
  1353. //!
  1354. //! - \b SYSCTL_FLASH_NORMAL - The flash is left in fully powered mode,
  1355. //! providing fast wake-up time but higher power consumption.
  1356. //! - \b SYSCTL_FLASH_LOW_POWER - The flash is in low power mode, providing
  1357. //! reduced power consumption but longer wake-up time.
  1358. //!
  1359. //! The SRAM power configuration is specified as one of:
  1360. //!
  1361. //! - \b SYSCTL_LDO_SLEEP - The LDO is in sleep mode.
  1362. //! - \b SYSCTL_TEMP_LOW_POWER - The temperature sensor in low power mode.
  1363. //! - \b SYSCTL_SRAM_NORMAL - The SRAM is left in fully powered mode, providing
  1364. //! fast wake-up time but higher power consumption.
  1365. //! - \b SYSCTL_SRAM_STANDBY - The SRAM is placed into a lower power mode,
  1366. //! providing reduced power consumption but longer wake-up time.
  1367. //! - \b SYSCTL_SRAM_LOW_POWER - The SRAM is placed into lowest power mode,
  1368. //! providing further reduced power consumption but longer wake-up time.
  1369. //!
  1370. //! \return None.
  1371. //
  1372. //*****************************************************************************
  1373. void
  1374. SysCtlDeepSleepPowerSet(uint32_t ui32Config)
  1375. {
  1376. //
  1377. // Set the deep-sleep-mode flash and SRAM power configuration.
  1378. //
  1379. HWREG(SYSCTL_DSLPPWRCFG) = ui32Config;
  1380. }
  1381. //*****************************************************************************
  1382. //
  1383. //! Resets the device.
  1384. //!
  1385. //! This function performs a software reset of the entire device. The
  1386. //! processor and all peripherals are reset and all device registers are
  1387. //! returned to their default values (with the exception of the reset cause
  1388. //! register, which maintains its current value but has the software reset
  1389. //! bit set as well).
  1390. //!
  1391. //! \return This function does not return.
  1392. //
  1393. //*****************************************************************************
  1394. void
  1395. SysCtlReset(void)
  1396. {
  1397. //
  1398. // Perform a software reset request. This request causes the device to
  1399. // reset, no further code is executed.
  1400. //
  1401. HWREG(NVIC_APINT) = NVIC_APINT_VECTKEY | NVIC_APINT_SYSRESETREQ;
  1402. //
  1403. // The device should have reset, so this should never be reached. Just in
  1404. // case, loop forever.
  1405. //
  1406. while (1)
  1407. {
  1408. }
  1409. }
  1410. //*****************************************************************************
  1411. //
  1412. //! Puts the processor into sleep mode.
  1413. //!
  1414. //! This function places the processor into sleep mode; it does not return
  1415. //! until the processor returns to run mode. The peripherals that are enabled
  1416. //! via SysCtlPeripheralSleepEnable() continue to operate and can wake up the
  1417. //! processor (if automatic clock gating is enabled with
  1418. //! SysCtlPeripheralClockGating(), otherwise all peripherals continue to
  1419. //! operate).
  1420. //!
  1421. //! \return None.
  1422. //
  1423. //*****************************************************************************
  1424. void
  1425. SysCtlSleep(void)
  1426. {
  1427. //
  1428. // Wait for an interrupt.
  1429. //
  1430. CPUwfi();
  1431. }
  1432. //*****************************************************************************
  1433. //
  1434. //! Puts the processor into deep-sleep mode.
  1435. //!
  1436. //! This function places the processor into deep-sleep mode; it does not return
  1437. //! until the processor returns to run mode. The peripherals that are enabled
  1438. //! via SysCtlPeripheralDeepSleepEnable() continue to operate and can wake up
  1439. //! the processor (if automatic clock gating is enabled with
  1440. //! SysCtlPeripheralClockGating(), otherwise all peripherals continue to
  1441. //! operate).
  1442. //!
  1443. //! \return None.
  1444. //
  1445. //*****************************************************************************
  1446. void
  1447. SysCtlDeepSleep(void)
  1448. {
  1449. //
  1450. // Enable deep-sleep.
  1451. //
  1452. HWREG(NVIC_SYS_CTRL) |= NVIC_SYS_CTRL_SLEEPDEEP;
  1453. //
  1454. // Wait for an interrupt.
  1455. //
  1456. CPUwfi();
  1457. //
  1458. // Disable deep-sleep so that a future sleep works correctly.
  1459. //
  1460. HWREG(NVIC_SYS_CTRL) &= ~(NVIC_SYS_CTRL_SLEEPDEEP);
  1461. }
  1462. //*****************************************************************************
  1463. //
  1464. //! Gets the reason for a reset.
  1465. //!
  1466. //! This function returns the reason(s) for a reset. Because the reset
  1467. //! reasons are sticky until either cleared by software or a power-on reset,
  1468. //! multiple reset reasons may be returned if multiple resets have occurred.
  1469. //! The reset reason is a logical OR of \b SYSCTL_CAUSE_HSRVREQ,
  1470. //! \b SYSCTL_CAUSE_HIB, \b SYSCTL_CAUSE_WDOG1, \b SYSCTL_CAUSE_SW,
  1471. //! \b SYSCTL_CAUSE_WDOG0, \b SYSCTL_CAUSE_BOR, \b SYSCTL_CAUSE_POR,
  1472. //! and/or \b SYSCTL_CAUSE_EXT.
  1473. //!
  1474. //! \return Returns the reason(s) for a reset.
  1475. //
  1476. //*****************************************************************************
  1477. uint32_t
  1478. SysCtlResetCauseGet(void)
  1479. {
  1480. //
  1481. // Return the reset reasons.
  1482. //
  1483. return (HWREG(SYSCTL_RESC));
  1484. }
  1485. //*****************************************************************************
  1486. //
  1487. //! Clears reset reasons.
  1488. //!
  1489. //! \param ui32Causes are the reset causes to be cleared; must be a logical OR
  1490. //! of \b SYSCTL_CAUSE_HSRVREQ, \b SYSCTL_CAUSE_HIB, \b SYSCTL_CAUSE_WDOG1,
  1491. //! \b SYSCTL_CAUSE_SW, \b SYSCTL_CAUSE_WDOG0, \b SYSCTL_CAUSE_BOR,
  1492. //! \b SYSCTL_CAUSE_POR, and/or \b SYSCTL_CAUSE_EXT.
  1493. //!
  1494. //! This function clears the specified sticky reset reasons. Once cleared,
  1495. //! another reset for the same reason can be detected, and a reset for a
  1496. //! different reason can be distinguished (instead of having two reset causes
  1497. //! set). If the reset reason is used by an application, all reset causes
  1498. //! should be cleared after they are retrieved with SysCtlResetCauseGet().
  1499. //!
  1500. //! \return None.
  1501. //
  1502. //*****************************************************************************
  1503. void
  1504. SysCtlResetCauseClear(uint32_t ui32Causes)
  1505. {
  1506. //
  1507. // Clear the given reset reasons.
  1508. //
  1509. HWREG(SYSCTL_RESC) &= ~(ui32Causes);
  1510. }
  1511. //*****************************************************************************
  1512. //
  1513. //! Provides a small delay.
  1514. //!
  1515. //! \param ui32Count is the number of delay loop iterations to perform.
  1516. //!
  1517. //! This function provides a means of generating a delay by executing a simple
  1518. //! 3 instruction cycle loop a given number of times. It is written in
  1519. //! assembly to keep the loop instruction count consistent across tool chains.
  1520. //!
  1521. //! It is important to note that this function does NOT provide an accurate
  1522. //! timing mechanism. Although the delay loop is 3 instruction cycles long,
  1523. //! the execution time of the loop will vary dramatically depending upon the
  1524. //! application's interrupt environment (the loop will be interrupted unless
  1525. //! run with interrupts disabled and this is generally an unwise thing to do)
  1526. //! and also the current system clock rate and flash timings (wait states and
  1527. //! the operation of the prefetch buffer affect the timing).
  1528. //!
  1529. //! For better accuracy, the ROM version of this function may be used. This
  1530. //! version will not suffer from flash- and prefect buffer-related timing
  1531. //! variability but will still be delayed by interrupt service routines.
  1532. //!
  1533. //! For best accuracy, a system timer should be used with code either polling
  1534. //! for a particular timer value being exceeded or processing the timer
  1535. //! interrupt to determine when a particular time period has elapsed.
  1536. //!
  1537. //! \return None.
  1538. //
  1539. //*****************************************************************************
  1540. #if defined(__ICCARM__) || defined(DOXYGEN)
  1541. void
  1542. SysCtlDelay(uint32_t ui32Count)
  1543. {
  1544. __asm(" subs r0, #1\n"
  1545. " bne.n SysCtlDelay\n"
  1546. " bx lr");
  1547. }
  1548. #endif
  1549. #if defined(codered) || defined(__GNUC__) || defined(sourcerygxx)
  1550. void __attribute__((naked))
  1551. SysCtlDelay(uint32_t ui32Count)
  1552. {
  1553. __asm(" subs r0, #1\n"
  1554. " bne SysCtlDelay\n"
  1555. " bx lr");
  1556. }
  1557. #endif
  1558. #if defined(rvmdk) || defined(__ARMCC_VERSION)
  1559. __asm void
  1560. SysCtlDelay(uint32_t ui32Count)
  1561. {
  1562. subs r0, #1;
  1563. bne SysCtlDelay;
  1564. bx lr;
  1565. }
  1566. #endif
  1567. //
  1568. // For CCS implement this function in pure assembly. This prevents the TI
  1569. // compiler from doing funny things with the optimizer.
  1570. //
  1571. #if defined(__TI_ARM__)
  1572. __asm(" .sect \".text:SysCtlDelay\"\n"
  1573. " .clink\n"
  1574. " .thumbfunc SysCtlDelay\n"
  1575. " .thumb\n"
  1576. " .global SysCtlDelay\n"
  1577. "SysCtlDelay:\n"
  1578. " subs r0, #1\n"
  1579. " bne.n SysCtlDelay\n"
  1580. " bx lr\n");
  1581. #endif
  1582. //*****************************************************************************
  1583. //
  1584. //! Sets the configuration of the main oscillator (MOSC) control.
  1585. //!
  1586. //! \param ui32Config is the required configuration of the MOSC control.
  1587. //!
  1588. //! This function configures the control of the main oscillator. The
  1589. //! \e ui32Config is specified as the logical OR of the following values:
  1590. //!
  1591. //! - \b SYSCTL_MOSC_VALIDATE enables the MOSC verification circuit that
  1592. //! detects a failure of the main oscillator (such as a loss of the clock).
  1593. //! - \b SYSCTL_MOSC_INTERRUPT indicates that a MOSC failure should generate an
  1594. //! interrupt instead of resetting the processor.
  1595. //! - \b SYSCTL_MOSC_NO_XTAL indicates that there is no crystal or oscillator
  1596. //! connected to the OSC0/OSC1 pins, allowing power consumption to be
  1597. //! reduced.
  1598. //! - \b SYSCTL_MOSC_PWR_DIS disable power to the main oscillator. If this
  1599. //! parameter is not specified, the MOSC input remains powered.
  1600. //! - \b SYSCTL_MOSC_LOWFREQ MOSC is less than 10 MHz.
  1601. //! - \b SYSCTL_MOSC_HIGHFREQ MOSC is greater than 10 MHz.
  1602. //! - \b SYSCTL_MOSC_SESRC specifies that the MOSC is a single-ended
  1603. //! oscillator connected to OSC0. If this parameter is not specified, the
  1604. //! input is assumed to be a crystal.
  1605. //!
  1606. //! \return None.
  1607. //
  1608. //*****************************************************************************
  1609. void
  1610. SysCtlMOSCConfigSet(uint32_t ui32Config)
  1611. {
  1612. //
  1613. // Configure the MOSC control.
  1614. //
  1615. HWREG(SYSCTL_MOSCCTL) = ui32Config;
  1616. }
  1617. //*****************************************************************************
  1618. //
  1619. //! Calibrates the precision internal oscillator.
  1620. //!
  1621. //! \param ui32Type is the type of calibration to perform.
  1622. //!
  1623. //! This function performs a calibration of the PIOSC. There are three types
  1624. //! of calibration available; the desired calibration type as specified in
  1625. //! \e ui32Type is one of:
  1626. //!
  1627. //! - \b SYSCTL_PIOSC_CAL_AUTO to perform automatic calibration using the
  1628. //! 32-kHz clock from the hibernate module as a reference. This type is
  1629. //! only possible if the hibernate module is enabled, a 32.768-kHz
  1630. //! clock source is attached to the XOSC0/1 pins and the hibernate module's
  1631. //! RTC is also enabled.
  1632. //!
  1633. //! - \b SYSCTL_PIOSC_CAL_FACT to reset the PIOSC calibration to the factory
  1634. //! provided calibration.
  1635. //!
  1636. //! - \b SYSCTL_PIOSC_CAL_USER to set the PIOSC calibration to a user-supplied
  1637. //! value. The value to be used is ORed into the lower 7-bits of this value,
  1638. //! with 0x40 being the ``nominal'' value (in other words, if everything were
  1639. //! perfect, 0x40 provides exactly 16 MHz). Values larger than 0x40
  1640. //! slow down PIOSC, and values smaller than 0x40 speed up PIOSC.
  1641. //!
  1642. //! \return Returns 1 if the calibration was successful and 0 if it failed.
  1643. //
  1644. //*****************************************************************************
  1645. uint32_t
  1646. SysCtlPIOSCCalibrate(uint32_t ui32Type)
  1647. {
  1648. //
  1649. // Perform the requested calibration. If performing user calibration, the
  1650. // UTEN bit must be set with one write, then the UT field in a second
  1651. // write, and the UPDATE bit in a final write. For other calibration
  1652. // types, a single write to set UPDATE or CAL is all that is required.
  1653. //
  1654. if (ui32Type & (SYSCTL_PIOSCCAL_UTEN | SYSCTL_PIOSCCAL_UPDATE))
  1655. {
  1656. HWREG(SYSCTL_PIOSCCAL) = ui32Type & SYSCTL_PIOSCCAL_UTEN;
  1657. HWREG(SYSCTL_PIOSCCAL) =
  1658. ui32Type & (SYSCTL_PIOSCCAL_UTEN | SYSCTL_PIOSCCAL_UT_M);
  1659. }
  1660. HWREG(SYSCTL_PIOSCCAL) = ui32Type;
  1661. //
  1662. // See if an automatic calibration was requested.
  1663. //
  1664. if (ui32Type & SYSCTL_PIOSCCAL_CAL)
  1665. {
  1666. //
  1667. // Wait for the automatic calibration to complete.
  1668. //
  1669. while ((HWREG(SYSCTL_PIOSCSTAT) & SYSCTL_PIOSCSTAT_CR_M) == 0)
  1670. {
  1671. }
  1672. //
  1673. // If the automatic calibration failed, return an error.
  1674. //
  1675. if ((HWREG(SYSCTL_PIOSCSTAT) & SYSCTL_PIOSCSTAT_CR_M) !=
  1676. SYSCTL_PIOSCSTAT_CRPASS)
  1677. {
  1678. return (0);
  1679. }
  1680. }
  1681. //
  1682. // The calibration was successful.
  1683. //
  1684. return (1);
  1685. }
  1686. //*****************************************************************************
  1687. //
  1688. //! Sets the type of reset issued due to certain reset events.
  1689. //!
  1690. //! \param ui32Behavior specifies the types of resets for each of the
  1691. //! configurable reset events.
  1692. //!
  1693. //! This function sets the types of reset issued when a configurable reset
  1694. //! event occurs. The reset events that are configurable are: Watchdog 0 or 1,
  1695. //! a brown out and the external RSTn pin. The valid actions are either a
  1696. //! system reset or a full POR sequence. See the technical reference manual for
  1697. //! more information on the differences between a full POR and a system reset.
  1698. //! All reset behaviors can be configured with a single call using the logical OR
  1699. //! of the values defined below. Any reset option that is not specifically set
  1700. //! remains configured for its default behavior. Either POR or system reset can
  1701. //! be selected for each reset cause.
  1702. //!
  1703. //! Valid values are logical combinations of the following:
  1704. //!
  1705. //! - \b SYSCTL_ONRST_WDOG0_POR configures a Watchdog 0 reset to perform a full
  1706. //! POR.
  1707. //! - \b SYSCTL_ONRST_WDOG0_SYS configures a Watchdog 0 reset to perform a
  1708. //! system reset.
  1709. //! - \b SYSCTL_ONRST_WDOG1_POR configures a Watchdog 1 reset to perform a full
  1710. //! POR.
  1711. //! - \b SYSCTL_ONRST_WDOG1_SYS configures a Watchdog 1 reset to perform a
  1712. //! system reset.
  1713. //! - \b SYSCTL_ONRST_BOR_POR configures a brown-out reset to perform a full
  1714. //! POR.
  1715. //! - \b SYSCTL_ONRST_BOR_SYS configures a brown-out reset to perform a system
  1716. //! reset.
  1717. //! - \b SYSCTL_ONRST_EXT_POR configures an external pin reset to perform a
  1718. //! full POR.
  1719. //! - \b SYSCTL_ONRST_EXT_SYS configures an external pin reset to perform a
  1720. //! system reset.
  1721. //!
  1722. //! \b Example: Set Watchdog 0 reset to trigger a POR and a brown-out reset
  1723. //! to trigger a system reset while leaving the remaining resets with their
  1724. //! default behaviors.
  1725. //!
  1726. //! \verbatim
  1727. //! SysCtlResetBehaviorSet(SYSCTL_ONRST_WDOG0_POR | SYSCTL_ONRST_BOR_SYS);
  1728. //! \endverbatim
  1729. //!
  1730. //! \return None.
  1731. //
  1732. //*****************************************************************************
  1733. void
  1734. SysCtlResetBehaviorSet(uint32_t ui32Behavior)
  1735. {
  1736. HWREG(SYSCTL_RESBEHAVCTL) = ui32Behavior;
  1737. }
  1738. //*****************************************************************************
  1739. //
  1740. //! Returns the current types of reset issued due to reset events.
  1741. //!
  1742. //! This function returns the types of resets issued when a configurable reset
  1743. //! occurs. The value returned is a logical OR combination of the valid values
  1744. //! that are described in the documentation for the \e ui32Behavior parameter
  1745. //! of the SysCtlResetBehaviorSet() function.
  1746. //!
  1747. //! \return The reset behaviors for all configurable resets.
  1748. //
  1749. //*****************************************************************************
  1750. uint32_t
  1751. SysCtlResetBehaviorGet(void)
  1752. {
  1753. return (HWREG(SYSCTL_RESBEHAVCTL));
  1754. }
  1755. //*****************************************************************************
  1756. //
  1757. //! Configures the system clock.
  1758. //!
  1759. //! \param ui32Config is the required configuration of the device clocking.
  1760. //! \param ui32SysClock is the requested processor frequency.
  1761. //!
  1762. //! This function configures the main system clocking for the device. The
  1763. //! input frequency, oscillator source, whether or not to enable the PLL, and
  1764. //! the system clock divider are all configured with this function. This
  1765. //! function configures the system frequency to the closest available divisor
  1766. //! of one of the fixed PLL VCO settings provided in the \e ui32Config
  1767. //! parameter. The caller sets the \e ui32SysClock parameter to request the
  1768. //! system clock frequency, and this function then attempts to match this using
  1769. //! the values provided in the \e ui32Config parameter. If this function
  1770. //! cannot exactly match the requested frequency, it picks the closest
  1771. //! frequency that is lower than the requested frequency. The \e ui32Config
  1772. //! parameter provides the remaining configuration options using a set of
  1773. //! defines that are a logical OR of several different values, many of which
  1774. //! are grouped into sets where only one of the set can be chosen. This
  1775. //! function returns the current system frequency which may not match the
  1776. //! requested frequency.
  1777. //!
  1778. //! If the application is using an external crystal then the frequency is
  1779. //! set by using one of the following values:
  1780. //! \b SYSCTL_XTAL_5MHZ, \b SYSCTL_XTAL_6MHZ, \b SYSCTL_XTAL_8MHZ,
  1781. //! \b SYSCTL_XTAL_10MHZ, \b SYSCTL_XTAL_12MHZ, \b SYSCTL_XTAL_16MHZ,
  1782. //! \b SYSCTL_XTAL_18MHZ, \b SYSCTL_XTAL_20MHZ, \b SYSCTL_XTAL_24MHZ, or
  1783. //! \b SYSCTL_XTAL_25MHz.
  1784. //!
  1785. //! The oscillator source is chosen with one of the following values:
  1786. //!
  1787. //! - \b SYSCTL_OSC_MAIN to use an external crystal or oscillator.
  1788. //! - \b SYSCTL_OSC_INT to use the 16-MHz precision internal oscillator.
  1789. //! - \b SYSCTL_OSC_INT30 to use the internal low frequency oscillator.
  1790. //! - \b SYSCTL_OSC_EXT32 to use the hibernate modules 32.786-kHz oscillator.
  1791. //!
  1792. //! The system clock source is chosen with one of the following values:
  1793. //!
  1794. //! - \b SYSCTL_USE_PLL is used to select the PLL output as the system clock.
  1795. //! - \b SYSCTL_USE_OSC is used to choose one of the oscillators as the
  1796. //! system clock.
  1797. //!
  1798. //! The PLL VCO frequency is chosen with one of the the following values:
  1799. //!
  1800. //! - \b SYSCTL_CFG_VCO_480 to set the PLL VCO output to 480-MHz
  1801. //! - \b SYSCTL_CFG_VCO_320 to set the PLL VCO output to 320-MHz
  1802. //!
  1803. //! Example: Configure the system clocking to be 40 MHz with a 320-MHz PLL
  1804. //! setting using the 16-MHz internal oscillator.
  1805. //!
  1806. //! \verbatim
  1807. //! SysCtlClockFreqSet(SYSCTL_OSC_INT | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_320,
  1808. //! 40000000);
  1809. //! \endverbatim
  1810. //!
  1811. //! \return The actual configured system clock frequency in Hz or zero if the
  1812. //! value could not be changed due to a parameter error or PLL lock failure.
  1813. //
  1814. //*****************************************************************************
  1815. uint32_t
  1816. SysCtlClockFreqSet(uint32_t ui32Config, uint32_t ui32SysClock)
  1817. {
  1818. int32_t i32Timeout, i32VCOIdx, i32XtalIdx;
  1819. uint32_t ui32MOSCCTL;
  1820. uint32_t ui32Delay;
  1821. uint32_t ui32SysDiv, ui32Osc, ui32OscSelect, ui32RSClkConfig;
  1822. //
  1823. // Get the index of the crystal from the ui32Config parameter.
  1824. //
  1825. i32XtalIdx = SysCtlXtalCfgToIndex(ui32Config);
  1826. //
  1827. // Determine which non-PLL source was selected.
  1828. //
  1829. if ((ui32Config & 0x38) == SYSCTL_OSC_INT)
  1830. {
  1831. //
  1832. // Use the nominal frequency for the PIOSC oscillator and set the
  1833. // crystal select.
  1834. //
  1835. ui32Osc = 16000000;
  1836. ui32OscSelect = SYSCTL_RSCLKCFG_OSCSRC_PIOSC;
  1837. ui32OscSelect |= SYSCTL_RSCLKCFG_PLLSRC_PIOSC;
  1838. //
  1839. // Force the crystal index to the value for 16-MHz.
  1840. //
  1841. i32XtalIdx = SysCtlXtalCfgToIndex(SYSCTL_XTAL_16MHZ);
  1842. }
  1843. else if ((ui32Config & 0x38) == SYSCTL_OSC_INT30)
  1844. {
  1845. //
  1846. // Use the nominal frequency for the low frequency oscillator.
  1847. //
  1848. ui32Osc = 30000;
  1849. ui32OscSelect = SYSCTL_RSCLKCFG_OSCSRC_LFIOSC;
  1850. }
  1851. else if ((ui32Config & 0x38) == (SYSCTL_OSC_EXT32 & 0x38))
  1852. {
  1853. //
  1854. // Use the RTC frequency.
  1855. //
  1856. ui32Osc = 32768;
  1857. ui32OscSelect = SYSCTL_RSCLKCFG_OSCSRC_RTC;
  1858. }
  1859. else if ((ui32Config & 0x38) == SYSCTL_OSC_MAIN)
  1860. {
  1861. //
  1862. // Bounds check the source frequency for the main oscillator. The is
  1863. // because the PLL tables in the g_pppui32XTALtoVCO structure range
  1864. // from 5MHz to 25MHz.
  1865. //
  1866. if ((i32XtalIdx > (SysCtlXtalCfgToIndex(SYSCTL_XTAL_25MHZ))) ||
  1867. (i32XtalIdx < (SysCtlXtalCfgToIndex(SYSCTL_XTAL_5MHZ))))
  1868. {
  1869. return (0);
  1870. }
  1871. ui32Osc = g_pui32Xtals[i32XtalIdx];
  1872. //
  1873. // Set the PLL source select to MOSC.
  1874. //
  1875. ui32OscSelect = SYSCTL_RSCLKCFG_OSCSRC_MOSC;
  1876. ui32OscSelect |= SYSCTL_RSCLKCFG_PLLSRC_MOSC;
  1877. //
  1878. // Clear MOSC power down, high oscillator range setting, and no crystal
  1879. // present setting.
  1880. //
  1881. ui32MOSCCTL = HWREG(SYSCTL_MOSCCTL) &
  1882. ~(SYSCTL_MOSCCTL_OSCRNG | SYSCTL_MOSCCTL_PWRDN |
  1883. SYSCTL_MOSCCTL_NOXTAL);
  1884. //
  1885. // Increase the drive strength for MOSC of 10 MHz and above.
  1886. //
  1887. if (i32XtalIdx >= (SysCtlXtalCfgToIndex(SYSCTL_XTAL_10MHZ) -
  1888. (SysCtlXtalCfgToIndex(SYSCTL_XTAL_5MHZ))))
  1889. {
  1890. ui32MOSCCTL |= SYSCTL_MOSCCTL_OSCRNG;
  1891. }
  1892. HWREG(SYSCTL_MOSCCTL) = ui32MOSCCTL;
  1893. //
  1894. // Timeout using the legacy delay value.
  1895. //
  1896. ui32Delay = 524288;
  1897. while ((HWREG(SYSCTL_RIS) & SYSCTL_RIS_MOSCPUPRIS) == 0)
  1898. {
  1899. ui32Delay--;
  1900. if (ui32Delay == 0)
  1901. {
  1902. break;
  1903. }
  1904. }
  1905. //
  1906. // If the main oscillator failed to start up then do not switch to
  1907. // it and return.
  1908. //
  1909. if (ui32Delay == 0)
  1910. {
  1911. return (0);
  1912. }
  1913. }
  1914. else
  1915. {
  1916. //
  1917. // This was an invalid request because no oscillator source was
  1918. // indicated.
  1919. //
  1920. ui32Osc = 0;
  1921. ui32OscSelect = SYSCTL_RSCLKCFG_OSCSRC_PIOSC;
  1922. }
  1923. //
  1924. // Check if the running with the PLL enabled was requested.
  1925. //
  1926. if ((ui32Config & SYSCTL_USE_OSC) == SYSCTL_USE_PLL)
  1927. {
  1928. //
  1929. // ui32Config must be SYSCTL_OSC_MAIN or SYSCTL_OSC_INT.
  1930. //
  1931. if (((ui32Config & 0x38) != SYSCTL_OSC_MAIN) &&
  1932. ((ui32Config & 0x38) != SYSCTL_OSC_INT))
  1933. {
  1934. return (0);
  1935. }
  1936. //
  1937. // Get the VCO index out of the ui32Config parameter.
  1938. //
  1939. i32VCOIdx = (ui32Config >> 24) & 7;
  1940. //
  1941. // Check that the VCO index is not out of bounds.
  1942. //
  1943. ASSERT(i32VCOIdx < MAX_VCO_ENTRIES);
  1944. //
  1945. // Set the memory timings for the maximum external frequency since
  1946. // this could be a switch to PIOSC or possibly to MOSC which can be
  1947. // up to 25MHz.
  1948. //
  1949. HWREG(SYSCTL_MEMTIM0) = _SysCtlMemTimingGet(25000000);
  1950. //
  1951. // Clear the old PLL divider and source in case it was set.
  1952. //
  1953. ui32RSClkConfig = HWREG(SYSCTL_RSCLKCFG) &
  1954. ~(SYSCTL_RSCLKCFG_PSYSDIV_M |
  1955. SYSCTL_RSCLKCFG_OSCSRC_M |
  1956. SYSCTL_RSCLKCFG_PLLSRC_M | SYSCTL_RSCLKCFG_USEPLL);
  1957. //
  1958. // Update the memory timings to match running from PIOSC.
  1959. //
  1960. ui32RSClkConfig |= SYSCTL_RSCLKCFG_MEMTIMU;
  1961. //
  1962. // Update clock configuration to switch back to PIOSC.
  1963. //
  1964. HWREG(SYSCTL_RSCLKCFG) = ui32RSClkConfig;
  1965. //
  1966. // The table starts at 5 MHz so modify the index to match this.
  1967. //
  1968. i32XtalIdx -= SysCtlXtalCfgToIndex(SYSCTL_XTAL_5MHZ);
  1969. //
  1970. // Calculate the System divider such that we get a frequency that is
  1971. // the closest to the requested frequency without going over.
  1972. //
  1973. ui32SysDiv = (g_pui32VCOFrequencies[i32VCOIdx] + ui32SysClock - 1) /
  1974. ui32SysClock;
  1975. //
  1976. // Set the oscillator source.
  1977. //
  1978. HWREG(SYSCTL_RSCLKCFG) |= ui32OscSelect;
  1979. //
  1980. // Set the M, N and Q values provided from the table and preserve
  1981. // the power state of the main PLL.
  1982. //
  1983. HWREG(SYSCTL_PLLFREQ1) =
  1984. g_pppui32XTALtoVCO[i32VCOIdx][i32XtalIdx][1];
  1985. HWREG(SYSCTL_PLLFREQ1) |= PLL_Q_TO_REG(ui32SysDiv);
  1986. HWREG(SYSCTL_PLLFREQ0) =
  1987. (g_pppui32XTALtoVCO[i32VCOIdx][i32XtalIdx][0] |
  1988. (HWREG(SYSCTL_PLLFREQ0) & SYSCTL_PLLFREQ0_PLLPWR));
  1989. //
  1990. // Calculate the actual system clock as PSYSDIV is always div-by 2.
  1991. //
  1992. ui32SysClock = _SysCtlFrequencyGet(ui32Osc) / 2;
  1993. //
  1994. // Set the Flash and EEPROM timing values.
  1995. //
  1996. HWREG(SYSCTL_MEMTIM0) = _SysCtlMemTimingGet(ui32SysClock);
  1997. //
  1998. // Check if the PLL is already powered up.
  1999. //
  2000. if (HWREG(SYSCTL_PLLFREQ0) & SYSCTL_PLLFREQ0_PLLPWR)
  2001. {
  2002. //
  2003. // Trigger the PLL to lock to the new frequency.
  2004. //
  2005. HWREG(SYSCTL_RSCLKCFG) |= SYSCTL_RSCLKCFG_NEWFREQ;
  2006. }
  2007. else
  2008. {
  2009. //
  2010. // Power up the PLL.
  2011. //
  2012. HWREG(SYSCTL_PLLFREQ0) |= SYSCTL_PLLFREQ0_PLLPWR;
  2013. }
  2014. //
  2015. // Wait until the PLL has locked.
  2016. //
  2017. for (i32Timeout = 32768; i32Timeout > 0; i32Timeout--)
  2018. {
  2019. if ((HWREG(SYSCTL_PLLSTAT) & SYSCTL_PLLSTAT_LOCK))
  2020. {
  2021. break;
  2022. }
  2023. }
  2024. //
  2025. // If the loop above did not timeout then switch over to the PLL
  2026. //
  2027. if (i32Timeout)
  2028. {
  2029. ui32RSClkConfig = HWREG(SYSCTL_RSCLKCFG);
  2030. ui32RSClkConfig |= (1 << SYSCTL_RSCLKCFG_PSYSDIV_S) |
  2031. ui32OscSelect | SYSCTL_RSCLKCFG_USEPLL;
  2032. ui32RSClkConfig |= SYSCTL_RSCLKCFG_MEMTIMU;
  2033. //
  2034. // Set the new clock configuration.
  2035. //
  2036. HWREG(SYSCTL_RSCLKCFG) = ui32RSClkConfig;
  2037. }
  2038. else
  2039. {
  2040. ui32SysClock = 0;
  2041. }
  2042. }
  2043. else
  2044. {
  2045. //
  2046. // Set the Flash and EEPROM timing values for PIOSC.
  2047. //
  2048. HWREG(SYSCTL_MEMTIM0) = _SysCtlMemTimingGet(16000000);
  2049. //
  2050. // Make sure that the PLL is powered down since it is not being used.
  2051. //
  2052. HWREG(SYSCTL_PLLFREQ0) &= ~SYSCTL_PLLFREQ0_PLLPWR;
  2053. //
  2054. // Clear the old PLL divider and source in case it was set.
  2055. //
  2056. ui32RSClkConfig = HWREG(SYSCTL_RSCLKCFG);
  2057. ui32RSClkConfig &= ~(SYSCTL_RSCLKCFG_OSYSDIV_M |
  2058. SYSCTL_RSCLKCFG_OSCSRC_M |
  2059. SYSCTL_RSCLKCFG_USEPLL);
  2060. //
  2061. // Update the memory timings.
  2062. //
  2063. ui32RSClkConfig |= SYSCTL_RSCLKCFG_MEMTIMU;
  2064. //
  2065. // Set the new clock configuration.
  2066. //
  2067. HWREG(SYSCTL_RSCLKCFG) = ui32RSClkConfig;
  2068. //
  2069. // If zero given as the system clock then default to divide by 1.
  2070. //
  2071. if (ui32SysClock == 0)
  2072. {
  2073. ui32SysDiv = 0;
  2074. }
  2075. else
  2076. {
  2077. //
  2078. // Calculate the System divider based on the requested
  2079. // frequency.
  2080. //
  2081. ui32SysDiv = ui32Osc / ui32SysClock;
  2082. //
  2083. // If the system divisor is not already zero, subtract one to
  2084. // set the value in the register which requires the value to
  2085. // be n-1.
  2086. //
  2087. if (ui32SysDiv != 0)
  2088. {
  2089. ui32SysDiv -= 1;
  2090. }
  2091. //
  2092. // Calculate the system clock.
  2093. //
  2094. ui32SysClock = ui32Osc / (ui32SysDiv + 1);
  2095. }
  2096. //
  2097. // Set the memory timing values for the new system clock.
  2098. //
  2099. HWREG(SYSCTL_MEMTIM0) = _SysCtlMemTimingGet(ui32SysClock);
  2100. //
  2101. // Set the new system clock values.
  2102. //
  2103. ui32RSClkConfig = HWREG(SYSCTL_RSCLKCFG);
  2104. ui32RSClkConfig |= (ui32SysDiv << SYSCTL_RSCLKCFG_OSYSDIV_S) |
  2105. ui32OscSelect;
  2106. //
  2107. // Update the memory timings.
  2108. //
  2109. ui32RSClkConfig |= SYSCTL_RSCLKCFG_MEMTIMU;
  2110. //
  2111. // Set the new clock configuration.
  2112. //
  2113. HWREG(SYSCTL_RSCLKCFG) = ui32RSClkConfig;
  2114. }
  2115. //
  2116. // Finally change the OSCSRC back to PIOSC
  2117. //
  2118. HWREG(SYSCTL_RSCLKCFG) &= ~(SYSCTL_RSCLKCFG_OSCSRC_M);
  2119. return (ui32SysClock);
  2120. }
  2121. //*****************************************************************************
  2122. //
  2123. //! Sets the clock configuration of the device while in deep-sleep mode.
  2124. //!
  2125. //! \param ui32Div is the clock divider when in deep-sleep mode.
  2126. //! \param ui32Config is the configuration of the device clocking while
  2127. //! in deep-sleep mode.
  2128. //!
  2129. //! This function configures the clocking of the device while in deep-sleep
  2130. //! mode. The \e ui32Config parameter selects the oscillator and the
  2131. //! \e ui32Div parameter sets the clock divider used in deep-sleep mode. The
  2132. //! valid values for the \e ui32Div parameter range from 1 to 1024.
  2133. //!
  2134. //! The oscillator source is chosen from one of the following values:
  2135. //! \b SYSCTL_DSLP_OSC_MAIN, \b SYSCTL_DSLP_OSC_INT, \b SYSCTL_DSLP_OSC_INT30,
  2136. //! or \b SYSCTL_DSLP_OSC_EXT32. The \b SYSCTL_DSLP_OSC_EXT32 option is only
  2137. //! available when the hibernation module is enabled.
  2138. //!
  2139. //! The precision internal oscillator can be powered down in deep-sleep mode by
  2140. //! specifying \b SYSCTL_DSLP_PIOSC_PD. The precision internal oscillator is
  2141. //! not powered down if it is required for operation while in deep-sleep
  2142. //! (based on other configuration settings).
  2143. //!
  2144. //! The main oscillator can be powered down in deep-sleep mode by
  2145. //! specifying \b SYSCTL_DSLP_MOSC_PD. The main oscillator is
  2146. //! not powered down if it is required for operation while in deep-sleep
  2147. //! (based on other configuration settings).
  2148. //!
  2149. //! \return None.
  2150. //
  2151. //*****************************************************************************
  2152. void
  2153. SysCtlDeepSleepClockConfigSet(uint32_t ui32Div, uint32_t ui32Config)
  2154. {
  2155. uint32_t ui32Value;
  2156. ASSERT(ui32Div != 0);
  2157. //
  2158. // Initialize the value with the divider.
  2159. //
  2160. ui32Value = ui32Div - 1;
  2161. //
  2162. // Set the clock source selection
  2163. //
  2164. switch (ui32Config & SYSCTL_DSCLKCFG_DSOSCSRC_M)
  2165. {
  2166. //
  2167. // Choose the main external oscillator.
  2168. //
  2169. case SYSCTL_DSLP_OSC_MAIN:
  2170. {
  2171. ui32Value |= SYSCTL_DSCLKCFG_DSOSCSRC_MOSC;
  2172. break;
  2173. }
  2174. //
  2175. // Choose the low frequency oscillator.
  2176. //
  2177. case SYSCTL_DSLP_OSC_INT30:
  2178. {
  2179. ui32Value |= SYSCTL_DSCLKCFG_DSOSCSRC_LFIOSC;
  2180. break;
  2181. }
  2182. //
  2183. // Choose the low frequency oscillator.
  2184. //
  2185. case SYSCTL_DSLP_OSC_EXT32:
  2186. {
  2187. ui32Value |= SYSCTL_DSCLKCFG_DSOSCSRC_RTC;
  2188. break;
  2189. }
  2190. //
  2191. // The zero value uses the PIOSC as the clock source.
  2192. //
  2193. case SYSCTL_DSLP_OSC_INT:
  2194. default:
  2195. {
  2196. break;
  2197. }
  2198. }
  2199. //
  2200. // Set the PIOSC power down bit.
  2201. //
  2202. if (ui32Config & SYSCTL_DSLP_PIOSC_PD)
  2203. {
  2204. ui32Value |= SYSCTL_DSCLKCFG_PIOSCPD;
  2205. }
  2206. //
  2207. // Set the MOSC power down disable bit.
  2208. //
  2209. if (ui32Config & SYSCTL_DSLP_MOSC_DPD)
  2210. {
  2211. ui32Value |= SYSCTL_DSCLKCFG_MOSCDPD;
  2212. }
  2213. //
  2214. // Update the deep-sleep clock configuration.
  2215. //
  2216. HWREG(SYSCTL_DSCLKCFG) = ui32Value;
  2217. }
  2218. //*****************************************************************************
  2219. //
  2220. //! Configures the response to system voltage events.
  2221. //!
  2222. //! \param ui32Config holds the configuration options for the voltage events.
  2223. //!
  2224. //! This function configures the response to voltage-related events.
  2225. //! These events are triggered when the voltage rails drop below certain
  2226. //! levels. The \e ui32Config parameter provides the configuration for the
  2227. //! voltage events and is a combination of the \b SYSCTL_VEVENT_* values.
  2228. //!
  2229. //! The response to a brown out on the VDDA rail is set by using one of the
  2230. //! following values:
  2231. //! - \b SYSCTL_VEVENT_VDDABO_NONE - There is no action taken on a VDDA
  2232. //! brown out.
  2233. //! - \b SYSCTL_VEVENT_VDDABO_INT - A system interrupt is generated when a
  2234. //! VDDA brown out occurs.
  2235. //! - \b SYSCTL_VEVENT_VDDABO_NMI - An NMI is generated when a VDDA brown out
  2236. //! occurs.
  2237. //! - \b SYSCTL_VEVENT_VDDABO_RST - A reset is generated when a VDDA brown out
  2238. //! occurs. The type of reset that is generated is controller by the
  2239. //! \b SYSCTL_ONRST_BOR_* setting passed into the SysCtlResetBehaviorSet()
  2240. //! function.
  2241. //!
  2242. //! The response to a brown out on the VDD rail is set by using one of the
  2243. //! following values:
  2244. //! - \b SYSCTL_VEVENT_VDDBO_NONE - There is no action taken on a VDD
  2245. //! brown out.
  2246. //! - \b SYSCTL_VEVENT_VDDBO_INT - A system interrupt is generated when a
  2247. //! VDD brown out occurs.
  2248. //! - \b SYSCTL_VEVENT_VDDBO_NMI - An NMI is generated when a VDD brown out
  2249. //! occurs.
  2250. //! - \b SYSCTL_VEVENT_VDDBO_RST - A reset is generated when a VDD brown out
  2251. //! occurs. The type of reset that is generated is controller by the
  2252. //! \b SYSCTL_ONRST_BOR_* setting passed into the SysCtlResetBehaviorSet()
  2253. //! function.
  2254. //!
  2255. //! \b Example: Configure the voltage events to trigger an interrupt on a VDDA
  2256. //! brown out, an NMI on a VDDC brown out and a reset on a VDD brown out.
  2257. //!
  2258. //! \verbatim
  2259. //!
  2260. //! //
  2261. //! // Configure the BOR rest to trigger a full POR. This is needed because
  2262. //! // the SysCtlVoltageEventConfig() call is triggering a reset so the type
  2263. //! // of reset is specified by this call.
  2264. //! //
  2265. //! SysCtlResetBehaviorSet(SYSCTL_ONRST_BOR_POR);
  2266. //!
  2267. //! //
  2268. //! // Trigger an interrupt on a VDDA brown out and a reset on a VDD brown out.
  2269. //! //
  2270. //! SysCtlVoltageEventConfig(SYSCTL_VEVENT_VDDABO_INT |
  2271. //! SYSCTL_VEVENT_VDDBO_RST);
  2272. //! \endverbatim
  2273. //!
  2274. //! \return None.
  2275. //
  2276. //*****************************************************************************
  2277. void
  2278. SysCtlVoltageEventConfig(uint32_t ui32Config)
  2279. {
  2280. //
  2281. // Set the requested events.
  2282. //
  2283. HWREG(SYSCTL_PTBOCTL) = ui32Config;
  2284. }
  2285. //*****************************************************************************
  2286. //
  2287. //! Returns the voltage event status.
  2288. //!
  2289. //! This function returns the voltage event status for the system controller.
  2290. //! The value returned is a logical OR of the following values:
  2291. //! - \b SYSCTL_VESTAT_VDDBOR a brown-out event occurred on the VDD rail.
  2292. //! - \b SYSCTL_VESTAT_VDDABOR a brown-out event occurred on the VDDA rail.
  2293. //!
  2294. //! The values returned from this function can be passed to the
  2295. //! SysCtlVoltageEventClear() to clear the current voltage event status.
  2296. //! Because voltage events are not cleared due to a reset, the voltage event
  2297. //! status must be cleared by calling SysCtlVoltageEventClear().
  2298. //!
  2299. //! \b Example: Clear the current voltage event status.
  2300. //!
  2301. //! \verbatim
  2302. //! uint32_t ui32VoltageEvents;
  2303. //!
  2304. //! //
  2305. //! // Read the current voltage event status.
  2306. //! //
  2307. //! ui32VoltageEvents = SysCtlVoltageEventStatus();
  2308. //!
  2309. //! //
  2310. //! // Clear all the current voltage events.
  2311. //! //
  2312. //! SysCtlVoltageEventClear(ui32VoltageEvents);
  2313. //! \endverbatim
  2314. //!
  2315. //! \return The current voltage event status.
  2316. //!
  2317. //
  2318. //*****************************************************************************
  2319. uint32_t
  2320. SysCtlVoltageEventStatus(void)
  2321. {
  2322. //
  2323. // Return the current voltage event status.
  2324. //
  2325. return (HWREG(SYSCTL_PWRTC));
  2326. }
  2327. //*****************************************************************************
  2328. //
  2329. //! Clears the voltage event status.
  2330. //!
  2331. //! \param ui32Status is a bit mask of the voltage events to clear.
  2332. //!
  2333. //! This function clears the current voltage events status for the values
  2334. //! specified in the \e ui32Status parameter. The \e ui32Status value must be
  2335. //! a logical OR of the following values:
  2336. //! - \b SYSCTL_VESTAT_VDDBOR a brown-out event occurred on the VDD rail.
  2337. //! - \b SYSCTL_VESTAT_VDDABOR a brown-out event occurred on the VDDA rail.
  2338. //!
  2339. //! \b Example: Clear the current voltage event status.
  2340. //!
  2341. //! \verbatim
  2342. //! //
  2343. //! // Clear all the current voltage events.
  2344. //! //
  2345. //! SysCtlVoltageEventClear(SysCtlVoltageEventStatus());
  2346. //! \endverbatim
  2347. //!
  2348. //! \return None.
  2349. //
  2350. //*****************************************************************************
  2351. void
  2352. SysCtlVoltageEventClear(uint32_t ui32Status)
  2353. {
  2354. //
  2355. // Clear the requested voltage events.
  2356. //
  2357. HWREG(SYSCTL_PWRTC) |= ui32Status;
  2358. }
  2359. //*****************************************************************************
  2360. //
  2361. //! Gets the effective VCO frequency.
  2362. //!
  2363. //! \param ui32Crystal holds the crystal value used for the PLL.
  2364. //! \param pui32VCOFrequency is a pointer to the storage location which holds
  2365. //! value of the VCO computed.
  2366. //!
  2367. //! This function calculates the VCO of the PLL before the system divider is
  2368. //! applied
  2369. //!
  2370. //! \return \b true if the PLL is configured correctly and a VCO is valid or
  2371. //! \b false if the PLL is not used
  2372. //
  2373. //*****************************************************************************
  2374. bool
  2375. SysCtlVCOGet(uint32_t ui32Crystal, uint32_t *pui32VCOFrequency)
  2376. {
  2377. int32_t i32XtalIdx;
  2378. uint32_t ui32RSClkConfig, ui32PLLFreq0, ui32PLLFreq1, ui32Osc;
  2379. uint32_t ui32MInt, ui32MFrac, ui32NDiv, ui32QDiv, ui32TempVCO;
  2380. //
  2381. // Read the RSCLKCFG register to determine if PLL is being used.
  2382. //
  2383. ui32RSClkConfig = HWREG(SYSCTL_RSCLKCFG);
  2384. //
  2385. // Check if PLL is used.
  2386. //
  2387. if ((ui32RSClkConfig & SYSCTL_RSCLKCFG_USEPLL) != SYSCTL_RSCLKCFG_USEPLL)
  2388. {
  2389. //
  2390. // Return error if PLL is not used.
  2391. //
  2392. *pui32VCOFrequency = 0;
  2393. return (false);
  2394. }
  2395. //
  2396. // Get the index of the crystal from the ui32Config parameter.
  2397. //
  2398. i32XtalIdx = SysCtlXtalCfgToIndex(ui32Crystal);
  2399. //
  2400. // Get the value of the crystal frequency based on the index
  2401. //
  2402. ui32Osc = g_pui32Xtals[i32XtalIdx];
  2403. //
  2404. // Read the PLLFREQ0 and PLLFREQ1 registers to get information on the
  2405. // MINT, MFRAC, N and Q values of the PLL
  2406. //
  2407. ui32PLLFreq0 = HWREG(SYSCTL_PLLFREQ0);
  2408. ui32PLLFreq1 = HWREG(SYSCTL_PLLFREQ1);
  2409. ui32MInt = (ui32PLLFreq0 & SYSCTL_PLLFREQ0_MINT_M) >>
  2410. SYSCTL_PLLFREQ0_MINT_S;
  2411. ui32MFrac = (ui32PLLFreq0 & SYSCTL_PLLFREQ0_MFRAC_M) >>
  2412. SYSCTL_PLLFREQ0_MFRAC_S;
  2413. ui32NDiv = (ui32PLLFreq1 & SYSCTL_PLLFREQ1_N_M) >>
  2414. SYSCTL_PLLFREQ1_N_S;
  2415. ui32QDiv = (ui32PLLFreq1 & SYSCTL_PLLFREQ1_Q_M) >>
  2416. SYSCTL_PLLFREQ1_Q_S;
  2417. //
  2418. // Calculate the VCO at the output of the PLL
  2419. //
  2420. ui32TempVCO = (ui32Osc * ui32MInt) + ((ui32Osc * ui32MFrac) / 1024);
  2421. ui32TempVCO /= ((ui32NDiv + 1) * (ui32QDiv + 1));
  2422. *pui32VCOFrequency = ui32TempVCO;
  2423. return (true);
  2424. }
  2425. //*****************************************************************************
  2426. //
  2427. //! Returns the current NMI status.
  2428. //!
  2429. //! This function returns the NMI status for the system controller. The valid
  2430. //! values for the \e ui32Ints parameter are a logical OR of the following
  2431. //! values:
  2432. //! - \b SYSCTL_NMI_MOSCFAIL the main oscillator is not present or did not
  2433. //! start.
  2434. //! - \b SYSCTL_NMI_TAMPER a tamper event has been detected.
  2435. //! - \b SYSCTL_NMI_WDT0 watchdog 0 generated a timeout.
  2436. //! - \b SYSCTL_NMI_WDT1 watchdog 1 generated a timeout.
  2437. //! - \b SYSCTL_NMI_POWER a power event occurred.
  2438. //! - \b SYSCTL_NMI_EXTERNAL an external NMI pin asserted.
  2439. //!
  2440. //! \b Example: Clear all current NMI status flags.
  2441. //!
  2442. //! \verbatim
  2443. //!
  2444. //! //
  2445. //! // Clear all the current NMI sources.
  2446. //! //
  2447. //! SysCtlNMIClear(SysCtlNMIStatus());
  2448. //! \endverbatim
  2449. //!
  2450. //! \return The current NMI status.
  2451. //
  2452. //*****************************************************************************
  2453. uint32_t
  2454. SysCtlNMIStatus(void)
  2455. {
  2456. return (HWREG(SYSCTL_NMIC));
  2457. }
  2458. //*****************************************************************************
  2459. //
  2460. //! Clears NMI sources.
  2461. //!
  2462. //! \param ui32Ints is a bit mask of the non-maskable interrupt sources.
  2463. //!
  2464. //! This function clears the current NMI status specified in the \e ui32Ints
  2465. //! parameter. The valid values for the \e ui32Ints parameter are a logical OR
  2466. //! of the following values:
  2467. //! - \b SYSCTL_NMI_MOSCFAIL the main oscillator is not present or did not
  2468. //! start.
  2469. //! - \b SYSCTL_NMI_TAMPER a tamper event has been detected.
  2470. //! - \b SYSCTL_NMI_WDT0 watchdog 0 generated a timeout.
  2471. //! - \b SYSCTL_NMI_WDT1 watchdog 1 generated a timeout.
  2472. //! - \b SYSCTL_NMI_POWER a power event occurred.
  2473. //! - \b SYSCTL_NMI_EXTERNAL an external NMI pin asserted.
  2474. //!
  2475. //! \b Example: Clear all current NMI status flags.
  2476. //!
  2477. //! \verbatim
  2478. //!
  2479. //! //
  2480. //! // Clear all the current NMI sources.
  2481. //! //
  2482. //! SysCtlNMIClear(SysCtlNMIStatus());
  2483. //! \endverbatim
  2484. //!
  2485. //! \return None.
  2486. //
  2487. //*****************************************************************************
  2488. void
  2489. SysCtlNMIClear(uint32_t ui32Ints)
  2490. {
  2491. //
  2492. // Clear the requested interrupt sources.
  2493. //
  2494. HWREG(SYSCTL_NMIC) &= ~ui32Ints;
  2495. }
  2496. //*****************************************************************************
  2497. //
  2498. //! Configures and enables or disables the clock output on the DIVSCLK pin.
  2499. //!
  2500. //! \param ui32Config holds the configuration options including enabling or
  2501. //! disabling the clock output on the DIVSCLK pin.
  2502. //! \param ui32Div is the divisor for the clock selected in the \e ui32Config
  2503. //! parameter.
  2504. //!
  2505. //! This function selects the source for the DIVSCLK, enables or disables
  2506. //! the clock output and provides an output divider value. The \e ui32Div
  2507. //! parameter specifies the divider for the selected clock source and has a
  2508. //! valid range of 1-256. The \e ui32Config parameter configures
  2509. //! the DIVSCLK output based on the following settings:
  2510. //!
  2511. //! The first setting allows the output to be enabled or disabled.
  2512. //! - \b SYSCTL_CLKOUT_EN - enable the DIVSCLK output.
  2513. //! - \b SYSCTL_CLKOUT_DIS - disable the DIVSCLK output (default).
  2514. //!
  2515. //! The next group of settings selects the source for the DIVSCLK.
  2516. //! - \b SYSCTL_CLKOUT_SYSCLK - use the current system clock as the
  2517. //! source (default).
  2518. //! - \b SYSCTL_CLKOUT_PIOSC - use the PIOSC as the source.
  2519. //! - \b SYSCTL_CLKOUT_MOSC - use the MOSC as the source.
  2520. //!
  2521. //! \b Example: Enable the PIOSC divided by 4 as the DIVSCLK output.
  2522. //!
  2523. //! \verbatim
  2524. //!
  2525. //! //
  2526. //! // Enable the PIOSC divided by 4 as the DIVSCLK output.
  2527. //! //
  2528. //! SysCtlClockOutConfig(SYSCTL_DIVSCLK_EN | SYSCTL_DIVSCLK_SRC_PIOSC, 4);
  2529. //! \endverbatim
  2530. //!
  2531. //! \return None.
  2532. //
  2533. //*****************************************************************************
  2534. void
  2535. SysCtlClockOutConfig(uint32_t ui32Config, uint32_t ui32Div)
  2536. {
  2537. ASSERT(ui32Div != 0);
  2538. ASSERT((ui32Config & ~(SYSCTL_CLKOUT_EN | SYSCTL_CLKOUT_DIS |
  2539. SYSCTL_CLKOUT_SYSCLK | SYSCTL_CLKOUT_PIOSC |
  2540. SYSCTL_CLKOUT_MOSC)) == 0);
  2541. //
  2542. // Set the requested configuration and divisor.
  2543. //
  2544. HWREG(SYSCTL_DIVSCLK) = ui32Config | ((ui32Div - 1) &
  2545. SYSCTL_DIVSCLK_DIV_M);
  2546. }
  2547. //*****************************************************************************
  2548. //
  2549. //! Configures the alternate peripheral clock source.
  2550. //!
  2551. //! \param ui32Config holds the configuration options for the alternate
  2552. //! peripheral clock.
  2553. //!
  2554. //! This function configures the alternate peripheral clock. The alternate
  2555. //! peripheral clock is used to provide a known clock in all operating modes
  2556. //! to peripherals that support using the alternate peripheral clock as an
  2557. //! input clock. The \e ui32Config parameter value provides the clock input
  2558. //! source using one of the following values:
  2559. //! - \b SYSCTL_ALTCLK_PIOSC - use the PIOSC as the alternate clock
  2560. //! source (default).
  2561. //! - \b SYSCTL_ALTCLK_RTCOSC - use the Hibernate module RTC clock as the
  2562. //! alternate clock source.
  2563. //! - \b SYSCTL_ALTCLK_LFIOSC - use the low-frequency internal oscillator as
  2564. //! the alternate clock source.
  2565. //!
  2566. //! \b Example: Select the Hibernate module RTC clock as the alternate clock
  2567. //! source.
  2568. //!
  2569. //! \verbatim
  2570. //!
  2571. //! //
  2572. //! // Select the Hibernate module RTC clock as the alternate clock source.
  2573. //! //
  2574. //! SysCtlAltClkConfig(SYSCTL_ALTCLK_RTCOSC);
  2575. //! \endverbatim
  2576. //!
  2577. //! \return None.
  2578. //
  2579. //*****************************************************************************
  2580. void
  2581. SysCtlAltClkConfig(uint32_t ui32Config)
  2582. {
  2583. //
  2584. // Set the requested configuration and divisor.
  2585. //
  2586. HWREG(SYSCTL_ALTCLKCFG) = ui32Config;
  2587. }
  2588. //*****************************************************************************
  2589. //
  2590. // Close the Doxygen group.
  2591. //! @}
  2592. //
  2593. //*****************************************************************************