1
0

hibernate.c 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558
  1. //*****************************************************************************
  2. //
  3. // hibernate.c - Driver for the Hibernation module
  4. //
  5. // Copyright (c) 2007-2020 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. // This is part of revision 2.2.0.295 of the Tiva Peripheral Driver Library.
  37. //
  38. //*****************************************************************************
  39. //*****************************************************************************
  40. //
  41. //! \addtogroup hibernate_api
  42. //! @{
  43. //
  44. //*****************************************************************************
  45. #include <stdbool.h>
  46. #include <stdint.h>
  47. #include <time.h>
  48. #include "inc/hw_hibernate.h"
  49. #include "inc/hw_ints.h"
  50. #include "inc/hw_sysctl.h"
  51. #include "inc/hw_types.h"
  52. #include "driverlib/debug.h"
  53. #include "driverlib/hibernate.h"
  54. #include "driverlib/interrupt.h"
  55. #include "driverlib/sysctl.h"
  56. //*****************************************************************************
  57. //
  58. // The delay in microseconds for writing to the Hibernation module registers.
  59. //
  60. //*****************************************************************************
  61. #define DELAY_USECS 95
  62. //*****************************************************************************
  63. //
  64. // The number of processor cycles to execute one pass of the delay loop.
  65. //
  66. //*****************************************************************************
  67. #define LOOP_CYCLES 3
  68. //*****************************************************************************
  69. //
  70. // A macro used to determine whether the target part supports Wake from IO
  71. // pins.
  72. //
  73. //*****************************************************************************
  74. #define HIBERNATE_WAKE_IO CLASS_IS_TM4C129
  75. //*****************************************************************************
  76. //
  77. // A macro used to determine whether the target part supports Wake from IO
  78. // pins.
  79. //
  80. //*****************************************************************************
  81. #define HIBERNATE_CLOCK_OUTPUT CLASS_IS_TM4C129
  82. //*****************************************************************************
  83. //
  84. //! \internal
  85. //!
  86. //! Polls until the write complete (WRC) bit in the hibernate control register
  87. //! is set.
  88. //!
  89. //! \param None.
  90. //!
  91. //! The Hibernation module provides an indication when any write is completed.
  92. //! This mechanism is used to pace writes to the module. This function merely
  93. //! polls this bit and returns as soon as it is set. At this point, it is safe
  94. //! to perform another write to the module.
  95. //!
  96. //! \return None.
  97. //
  98. //*****************************************************************************
  99. static void
  100. _HibernateWriteComplete(void)
  101. {
  102. //
  103. // Spin until the write complete bit is set.
  104. //
  105. while(!(HWREG(HIB_CTL) & HIB_CTL_WRC))
  106. {
  107. }
  108. }
  109. //*****************************************************************************
  110. //
  111. //! Enables the Hibernation module for operation.
  112. //!
  113. //! \param ui32HibClk is the rate of the clock supplied to the Hibernation
  114. //! module.
  115. //!
  116. //! This function enables the Hibernation module for operation. This function
  117. //! should be called before any of the Hibernation module features are used.
  118. //!
  119. //! The peripheral clock is the same as the processor clock. The frequency of
  120. //! the system clock is the value returned by SysCtlClockGet() for TM4C123x
  121. //! devices or the value returned by SysCtlClockFreqSet() for TM4C129x devices,
  122. //! or it can be explicitly hard coded if it is constant and known (to save the
  123. //! code/execution overhead of a call to SysCtlClockGet() or fetch of the
  124. //! variable call holding the return value of SysCtlClockFreqSet()).
  125. //!
  126. //! \return None.
  127. //
  128. //*****************************************************************************
  129. void
  130. HibernateEnableExpClk(uint32_t ui32HibClk)
  131. {
  132. //
  133. // Turn on the clock enable bit.
  134. //
  135. HWREG(HIB_CTL) |= HIB_CTL_CLK32EN;
  136. //
  137. // Wait for write complete following register load (above).
  138. //
  139. _HibernateWriteComplete();
  140. }
  141. //*****************************************************************************
  142. //
  143. //! Disables the Hibernation module for operation.
  144. //!
  145. //! This function disables the Hibernation module. After this function is
  146. //! called, none of the Hibernation module features are available.
  147. //!
  148. //! \return None.
  149. //
  150. //*****************************************************************************
  151. void
  152. HibernateDisable(void)
  153. {
  154. //
  155. // Turn off the clock enable bit.
  156. //
  157. HWREG(HIB_CTL) &= ~HIB_CTL_CLK32EN;
  158. //
  159. // Wait for write completion
  160. //
  161. _HibernateWriteComplete();
  162. }
  163. //*****************************************************************************
  164. //
  165. //! Configures the clock input for the Hibernation module.
  166. //!
  167. //! \param ui32Config is one of the possible configuration options for the
  168. //! clock input listed below.
  169. //!
  170. //! This function is used to configure the clock input for the Hibernation
  171. //! module. The \e ui32Config parameter can be one of the following values:
  172. //!
  173. //! - \b HIBERNATE_OSC_DISABLE specifies that the internal oscillator
  174. //! is powered off. This option is used when an externally supplied oscillator
  175. //! is connected to the XOSC0 pin or to save power when the LFIOSC is used in
  176. //! devices that have an LFIOSC in the Hibernation module.
  177. //! - \b HIBERNATE_OSC_HIGHDRIVE specifies a higher drive strength when a 24-pF
  178. //! filter capacitor is used with a crystal.
  179. //! - \b HIBERNATE_OSC_LOWDRIVE specifies a lower drive strength when a 12-pF
  180. //! filter capacitor is used with a crystal.
  181. //!
  182. //! On some devices, there is an option to use an internal low frequency
  183. //! oscillator (LFIOSC) as the clock source for the Hibernation module.
  184. //! Because of the low accuracy of this oscillator, this option should not be
  185. //! used when the system requires a real time counter. Adding the
  186. //! \b HIBERNATE_OSC_LFIOSC value enables the LFIOSC as the clock source to
  187. //! the Hibernation module.
  188. //!
  189. //! - \b HIBERNATE_OSC_LFIOSC enables the Hibernation module's internal low
  190. //! frequency oscillator as the clock to the Hibernation module.
  191. //!
  192. //! This \e ui32Config also configures how the clock output from the
  193. //! hibernation is used to clock other peripherals in the system. The ALT
  194. //! clock settings allow clocking a subset of the peripherals. See the
  195. //! hibernate section in the datasheet to determine which peripherals can be
  196. //! clocked by the ALT clock outputs from the Hibernation module.
  197. //! The \e ui32Config parameter can have any combination of the following
  198. //! values:
  199. //!
  200. //! - \b HIBERNATE_OUT_SYSCLK enables the hibernate clock output to the system
  201. //! clock.
  202. //!
  203. //! The \b HIBERNATE_OSC_DISABLE option is used to disable and power down the
  204. //! internal oscillator if an external clock source or no clock source is used
  205. //! instead of a 32.768-kHz crystal. In the case where an external crystal is
  206. //! used, either the \b HIBERNATE_OSC_HIGHDRIVE or \b HIBERNATE_OSC_LOWDRIVE is
  207. //! used. These settings optimizes the oscillator drive strength to match the
  208. //! size of the filter capacitor that is used with the external crystal
  209. //! circuit.
  210. //!
  211. //! \return None.
  212. //
  213. //*****************************************************************************
  214. void
  215. HibernateClockConfig(uint32_t ui32Config)
  216. {
  217. uint32_t ui32HIBCtl;
  218. ASSERT((ui32Config & ~(HIBERNATE_OSC_HIGHDRIVE | HIBERNATE_OSC_LOWDRIVE |
  219. HIBERNATE_OSC_DISABLE)) == 0);
  220. ui32HIBCtl = HWREG(HIB_CTL);
  221. //
  222. // Clear the current configuration bits.
  223. //
  224. ui32HIBCtl &= ~(HIBERNATE_OSC_HIGHDRIVE | HIBERNATE_OSC_LOWDRIVE |
  225. HIBERNATE_OSC_LFIOSC | HIBERNATE_OSC_DISABLE);
  226. //
  227. // Set the new configuration bits.
  228. //
  229. ui32HIBCtl |= ui32Config & (HIBERNATE_OSC_HIGHDRIVE |
  230. HIBERNATE_OSC_LOWDRIVE |
  231. HIBERNATE_OSC_LFIOSC |
  232. HIBERNATE_OSC_DISABLE);
  233. //
  234. // Must be sure that the 32KHz clock is enabled if the hibernate is about
  235. // to switch to it.
  236. //
  237. if(ui32Config & HIBERNATE_OSC_LFIOSC)
  238. {
  239. ui32HIBCtl |= HIB_CTL_CLK32EN;
  240. }
  241. //
  242. // Set the hibernation clocking configuration.
  243. //
  244. HWREG(HIB_CTL) = ui32HIBCtl;
  245. //
  246. // Wait for write completion
  247. //
  248. _HibernateWriteComplete();
  249. //
  250. // Write the output clock configuration for devices that support
  251. // controlling the output clocks from the hibernate module.
  252. //
  253. if(HIBERNATE_CLOCK_OUTPUT)
  254. {
  255. HWREG(HIB_CC) = ui32Config & (HIBERNATE_OUT_SYSCLK);
  256. }
  257. }
  258. //*****************************************************************************
  259. //
  260. //! Enables the RTC feature of the Hibernation module.
  261. //!
  262. //! This function enables the RTC in the Hibernation module. The RTC can be
  263. //! used to wake the processor from hibernation at a certain time, or to
  264. //! generate interrupts at certain times. This function must be called before
  265. //! using any of the RTC features of the Hibernation module.
  266. //!
  267. //! \return None.
  268. //
  269. //*****************************************************************************
  270. void
  271. HibernateRTCEnable(void)
  272. {
  273. //
  274. // Turn on the RTC enable bit.
  275. //
  276. HWREG(HIB_CTL) |= HIB_CTL_RTCEN;
  277. //
  278. // Wait for write completion
  279. //
  280. _HibernateWriteComplete();
  281. }
  282. //*****************************************************************************
  283. //
  284. //! Disables the RTC feature of the Hibernation module.
  285. //!
  286. //! This function disables the RTC in the Hibernation module. After calling
  287. //! this function, the RTC features of the Hibernation module are not
  288. //! available.
  289. //!
  290. //! \return None.
  291. //
  292. //*****************************************************************************
  293. void
  294. HibernateRTCDisable(void)
  295. {
  296. //
  297. // Turn off the RTC enable bit.
  298. //
  299. HWREG(HIB_CTL) &= ~HIB_CTL_RTCEN;
  300. //
  301. // Wait for write completion
  302. //
  303. _HibernateWriteComplete();
  304. }
  305. //*****************************************************************************
  306. //
  307. //! Forces the Hibernation module to initiate a check of the battery voltage.
  308. //!
  309. //! This function forces the Hibernation module to initiate a check of the
  310. //! battery voltage immediately rather than waiting for the next check interval
  311. //! to pass. After calling this function, the application should call the
  312. //! HibernateBatCheckDone() function and wait for the function to return a zero
  313. //! value before calling the HibernateIntStatus() to check if the return code
  314. //! has the \b HIBERNATE_INT_LOW_BAT set. If \b HIBERNATE_INT_LOW_BAT is set,
  315. //! the battery level is low. The application can also enable the
  316. //! \b HIBERNATE_INT_LOW_BAT interrupt and wait for an interrupt to indicate
  317. //! that the battery level is low.
  318. //!
  319. //! \note A hibernation request is held off if a battery check is in progress.
  320. //!
  321. //! \return None.
  322. //
  323. //*****************************************************************************
  324. void
  325. HibernateBatCheckStart(void)
  326. {
  327. //
  328. // Initiated a forced battery check.
  329. //
  330. HWREG(HIB_CTL) |= HIB_CTL_BATCHK;
  331. //
  332. // Wait for write completion
  333. //
  334. _HibernateWriteComplete();
  335. }
  336. //*****************************************************************************
  337. //
  338. //! Determines whether or not a forced battery check has completed.
  339. //!
  340. //! This function determines whether the forced battery check initiated by a
  341. //! call to the HibernateBatCheckStart() function has completed. This function
  342. //! returns a non-zero value until the battery level check has completed. Once
  343. //! this function returns a value of zero, the Hibernation module has completed
  344. //! the battery check and the HibernateIntStatus() function can be used to
  345. //! check if the battery was low by checking if the value returned has the
  346. //! \b HIBERNATE_INT_LOW_BAT set.
  347. //!
  348. //! \return The value is zero when the battery level check has completed or
  349. //! non-zero if the check is still in process.
  350. //
  351. //*****************************************************************************
  352. uint32_t
  353. HibernateBatCheckDone(void)
  354. {
  355. //
  356. // Read the current state of the battery check.
  357. //
  358. return(HWREG(HIB_CTL) & HIB_CTL_BATCHK);
  359. }
  360. //*****************************************************************************
  361. //
  362. //! Configures the wake conditions for the Hibernation module.
  363. //!
  364. //! \param ui32WakeFlags specifies which conditions should be used for waking.
  365. //!
  366. //! This function enables the conditions under which the Hibernation module
  367. //! wakes. The \e ui32WakeFlags parameter is the logical OR of any combination
  368. //! of the following:
  369. //!
  370. //! - \b HIBERNATE_WAKE_PIN - wake when the external wake pin is asserted.
  371. //! - \b HIBERNATE_WAKE_RTC - wake when the RTC match occurs.
  372. //! - \b HIBERNATE_WAKE_LOW_BAT - wake from hibernate due to a low-battery
  373. //! level being detected.
  374. //! - \b HIBERNATE_WAKE_GPIO - wake when a GPIO pin is asserted.
  375. //! - \b HIBERNATE_WAKE_RESET - wake when a reset pin is asserted.
  376. //!
  377. //! If the \b HIBERNATE_WAKE_GPIO flag is set, then one of the GPIO
  378. //! configuration functions GPIOPinTypeWakeHigh() or GPIOPinTypeWakeLow() must
  379. //! be called to properly configure and enable a GPIO as a wake source for
  380. //! hibernation.
  381. //!
  382. //! \note The \b HIBERNATE_WAKE_GPIO and \b HIBERNATE_WAKE_RESET parameters are
  383. //! only available on some Tiva devices.
  384. //!
  385. //! \note On some Tiva devices a tamper event acts as a wake source for the
  386. //! Hibernation module. Refer the function \b HibernateTamperEventsConfig() to
  387. //! wake from hibernation on a tamper event.
  388. //!
  389. //! \return None.
  390. //
  391. //*****************************************************************************
  392. void
  393. HibernateWakeSet(uint32_t ui32WakeFlags)
  394. {
  395. //
  396. // Check the arguments.
  397. //
  398. ASSERT(!(ui32WakeFlags & ~(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC |
  399. HIBERNATE_WAKE_GPIO | HIBERNATE_WAKE_RESET |
  400. HIBERNATE_WAKE_LOW_BAT)));
  401. //
  402. // Set the specified wake flags in the control register.
  403. //
  404. HWREG(HIB_CTL) = (ui32WakeFlags | (HWREG(HIB_CTL) &
  405. ~(HIBERNATE_WAKE_PIN |
  406. HIBERNATE_WAKE_RTC |
  407. HIBERNATE_WAKE_LOW_BAT)));
  408. //
  409. // Wait for write completion
  410. //
  411. _HibernateWriteComplete();
  412. //
  413. // Write the hibernate IO register if requested.
  414. //
  415. if(HIBERNATE_WAKE_IO)
  416. {
  417. //
  418. // If the reset or GPIOs are begin used as a wake source then the
  419. // the VDD3ON needs to be set to allow the pads to remained
  420. // powered.
  421. //
  422. if((ui32WakeFlags & (HIBERNATE_WAKE_RESET | HIBERNATE_WAKE_GPIO)) &&
  423. ((HWREG(HIB_CTL) & HIB_CTL_VDD3ON) == 0))
  424. {
  425. //
  426. // Make sure that VDD3ON mode is enabled so that the pads can
  427. // retain their state.
  428. //
  429. HWREG(HIB_CTL) |= HIB_CTL_VDD3ON;
  430. //
  431. // Wait for write completion
  432. //
  433. _HibernateWriteComplete();
  434. }
  435. //
  436. // Set the requested flags.
  437. //
  438. HWREG(HIB_IO) = (ui32WakeFlags >> 16) | HIB_IO_WUUNLK;
  439. //
  440. // Spin until the write complete bit is set.
  441. //
  442. while((HWREG(HIB_IO) & HIB_IO_IOWRC) == 0)
  443. {
  444. }
  445. //
  446. // Clear the write unlock bit.
  447. //
  448. HWREG(HIB_IO) &= ~HIB_IO_WUUNLK;
  449. }
  450. }
  451. //*****************************************************************************
  452. //
  453. //! Gets the currently configured wake conditions for the Hibernation module.
  454. //!
  455. //! This function returns the flags representing the wake configuration for the
  456. //! Hibernation module. The return value is a combination of the following
  457. //! flags:
  458. //!
  459. //! - \b HIBERNATE_WAKE_PIN - wake when the external wake pin is asserted
  460. //! - \b HIBERNATE_WAKE_RTC - wake when the RTC matches occurs
  461. //! - \b HIBERNATE_WAKE_LOW_BAT - wake from hibernation due to a low-battery
  462. //! level being detected
  463. //! - \b HIBERNATE_WAKE_GPIO - wake when a GPIO pin is asserted
  464. //! - \b HIBERNATE_WAKE_RESET - wake when a reset pin is asserted
  465. //!
  466. //! \note The \b HIBERNATE_WAKE_LOW_BAT, \b HIBERNATE_WAKE_GPIO, and
  467. //! \b HIBERNATE_WAKE_RESET parameters are only available on some Tiva devices.
  468. //!
  469. //! \note On some Tiva devices a tamper event acts as a wake source for the
  470. //! Hibernation module. Refer the function \b HibernateTamperEventsConfig() to
  471. //! wake from hibernation on a tamper event.
  472. //!
  473. //! \return Returns flags indicating the configured wake conditions.
  474. //
  475. //*****************************************************************************
  476. uint32_t
  477. HibernateWakeGet(void)
  478. {
  479. uint32_t ui32Ctrl;
  480. //
  481. // Read the wake bits from the control register and return those bits to
  482. // the caller.
  483. //
  484. if(HIBERNATE_WAKE_IO)
  485. {
  486. ui32Ctrl = HWREG(HIB_CTL);
  487. return((ui32Ctrl & (HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC |
  488. HIBERNATE_WAKE_LOW_BAT)) |
  489. ((HWREG(HIB_IO) << 16) & (HIBERNATE_WAKE_RESET |
  490. HIBERNATE_WAKE_GPIO)));
  491. }
  492. else
  493. {
  494. return(HWREG(HIB_CTL) & (HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC |
  495. HIBERNATE_WAKE_LOW_BAT));
  496. }
  497. }
  498. //*****************************************************************************
  499. //
  500. //! Configures the low-battery detection.
  501. //!
  502. //! \param ui32LowBatFlags specifies behavior of low-battery detection.
  503. //!
  504. //! This function enables the low-battery detection and whether hibernation is
  505. //! allowed if a low battery is detected. If low-battery detection is enabled,
  506. //! then a low-battery condition is indicated in the raw interrupt status
  507. //! register, which can be enabled to trigger an interrupt. Optionally,
  508. //! hibernation can be aborted if a low battery condition is detected.
  509. //!
  510. //! The \e ui32LowBatFlags parameter is one of the following values:
  511. //!
  512. //! - \b HIBERNATE_LOW_BAT_DETECT - detect a low-battery condition
  513. //! - \b HIBERNATE_LOW_BAT_ABORT - detect a low-battery condition and abort
  514. //! hibernation if low-battery is detected
  515. //!
  516. //! The other setting in the \e ui32LowBatFlags allows the caller to set one of
  517. //! the following voltage level trigger values :
  518. //!
  519. //! - \b HIBERNATE_LOW_BAT_1_9V - voltage low level is 1.9 V
  520. //! - \b HIBERNATE_LOW_BAT_2_1V - voltage low level is 2.1 V
  521. //! - \b HIBERNATE_LOW_BAT_2_3V - voltage low level is 2.3 V
  522. //! - \b HIBERNATE_LOW_BAT_2_5V - voltage low level is 2.5 V
  523. //!
  524. //! \b Example: Abort hibernate if the voltage level is below 2.1 V.
  525. //!
  526. //! \verbatim
  527. //! HibernateLowBatSet(HIBERNATE_LOW_BAT_ABORT | HIBERNATE_LOW_BAT_2_1V);
  528. //! \endverbatim
  529. //!
  530. //! \return None.
  531. //
  532. //*****************************************************************************
  533. void
  534. HibernateLowBatSet(uint32_t ui32LowBatFlags)
  535. {
  536. //
  537. // Check the arguments.
  538. //
  539. ASSERT(!(ui32LowBatFlags &
  540. ~(HIB_CTL_VBATSEL_M | HIBERNATE_LOW_BAT_ABORT)));
  541. //
  542. // Set the low-battery detect and abort bits in the control register,
  543. // according to the parameter.
  544. //
  545. HWREG(HIB_CTL) = (ui32LowBatFlags |
  546. (HWREG(HIB_CTL) & ~(HIB_CTL_VBATSEL_M |
  547. HIBERNATE_LOW_BAT_ABORT)));
  548. //
  549. // Wait for write completion
  550. //
  551. _HibernateWriteComplete();
  552. }
  553. //*****************************************************************************
  554. //
  555. //! Gets the currently configured low-battery detection behavior.
  556. //!
  557. //! This function returns a value representing the currently configured low
  558. //! battery detection behavior.
  559. //!
  560. //! The return value is a combination of the values described in the
  561. //! HibernateLowBatSet() function.
  562. //!
  563. //! \return Returns a value indicating the configured low-battery detection.
  564. //
  565. //*****************************************************************************
  566. uint32_t
  567. HibernateLowBatGet(void)
  568. {
  569. //
  570. // Read the supported low bat bits from the control register and return
  571. // those bits to the caller.
  572. //
  573. return(HWREG(HIB_CTL) & (HIB_CTL_VBATSEL_M | HIBERNATE_LOW_BAT_ABORT));
  574. }
  575. //*****************************************************************************
  576. //
  577. //! Sets the value of the real time clock (RTC) counter.
  578. //!
  579. //! \param ui32RTCValue is the new value for the RTC.
  580. //!
  581. //! This function sets the value of the RTC. The RTC counter contains the
  582. //! count in seconds when a 32.768kHz clock source is in use. The RTC must be
  583. //! enabled by calling HibernateRTCEnable() before calling this function.
  584. //!
  585. //! \return None.
  586. //
  587. //*****************************************************************************
  588. void
  589. HibernateRTCSet(uint32_t ui32RTCValue)
  590. {
  591. //
  592. // Load register requires unlock.
  593. //
  594. HWREG(HIB_LOCK) = HIB_LOCK_HIBLOCK_KEY;
  595. _HibernateWriteComplete();
  596. //
  597. // Write the new RTC value to the RTC load register.
  598. //
  599. HWREG(HIB_RTCLD) = ui32RTCValue;
  600. //
  601. // Wait for write completion
  602. //
  603. _HibernateWriteComplete();
  604. //
  605. // Unlock.
  606. //
  607. HWREG(HIB_LOCK) = 0;
  608. _HibernateWriteComplete();
  609. }
  610. //*****************************************************************************
  611. //
  612. //! Gets the value of the real time clock (RTC) counter.
  613. //!
  614. //! This function gets the value of the RTC and returns it to the caller.
  615. //!
  616. //! \return Returns the value of the RTC counter in seconds.
  617. //
  618. //*****************************************************************************
  619. uint32_t
  620. HibernateRTCGet(void)
  621. {
  622. //
  623. // Return the value of the RTC counter register to the caller.
  624. //
  625. return(HWREG(HIB_RTCC));
  626. }
  627. //*****************************************************************************
  628. //
  629. //! Sets the value of the RTC match register.
  630. //!
  631. //! \param ui32Match is the index of the match register.
  632. //! \param ui32Value is the value for the match register.
  633. //!
  634. //! This function sets a match register for the RTC. The Hibernation
  635. //! module can be configured to wake from hibernation, and/or generate an
  636. //! interrupt when the value of the RTC counter is the same as the match
  637. //! register.
  638. //!
  639. //! \return None.
  640. //
  641. //*****************************************************************************
  642. void
  643. HibernateRTCMatchSet(uint32_t ui32Match, uint32_t ui32Value)
  644. {
  645. ASSERT(ui32Match == 0);
  646. //
  647. // Write the new match value to the match register.
  648. //
  649. HWREG(HIB_RTCM0) = ui32Value;
  650. //
  651. // Wait for write completion
  652. //
  653. _HibernateWriteComplete();
  654. }
  655. //*****************************************************************************
  656. //
  657. //! Gets the value of the requested RTC match register.
  658. //!
  659. //! \param ui32Match is the index of the match register.
  660. //!
  661. //! This function gets the value of the match register for the RTC. The only
  662. //! value that can be used with the \e ui32Match parameter is zero, other
  663. //! values are reserved for future use.
  664. //!
  665. //! \return Returns the value of the requested match register.
  666. //
  667. //*****************************************************************************
  668. uint32_t
  669. HibernateRTCMatchGet(uint32_t ui32Match)
  670. {
  671. ASSERT(ui32Match == 0);
  672. //
  673. // Return the value of the match register to the caller.
  674. //
  675. return(HWREG(HIB_RTCM0));
  676. }
  677. //*****************************************************************************
  678. //
  679. //! Sets the value of the RTC sub second match register.
  680. //!
  681. //! \param ui32Match is the index of the match register.
  682. //! \param ui32Value is the value for the sub second match register.
  683. //!
  684. //! This function sets the sub second match register for the RTC in 1/32768
  685. //! of a second increments. The Hibernation module can be configured to wake
  686. //! from hibernation, and/or generate an interrupt when the value of the RTC
  687. //! counter is the same as the match combined with the sub second match
  688. //! register. The only value that can be used with the \e ui32Match
  689. //! parameter is zero, other values are reserved for future use.
  690. //!
  691. //! \return None.
  692. //
  693. //*****************************************************************************
  694. void
  695. HibernateRTCSSMatchSet(uint32_t ui32Match, uint32_t ui32Value)
  696. {
  697. ASSERT(ui32Match == 0);
  698. //
  699. // Write the new sub second match value to the sub second match register.
  700. //
  701. HWREG(HIB_RTCSS) = ui32Value << HIB_RTCSS_RTCSSM_S;
  702. //
  703. // Wait for write complete to be signaled on later devices.
  704. //
  705. _HibernateWriteComplete();
  706. }
  707. //*****************************************************************************
  708. //
  709. //! Returns the value of the requested RTC sub second match register.
  710. //!
  711. //! \param ui32Match is the index of the match register.
  712. //!
  713. //! This function returns the current value of the sub second match register
  714. //! for the RTC. The value returned is in 1/32768 second increments. The only
  715. //! value that can be used with the \e ui32Match parameter is zero, other
  716. //! values are reserved for future use.
  717. //!
  718. //! \return Returns the value of the requested sub section match register.
  719. //
  720. //*****************************************************************************
  721. uint32_t
  722. HibernateRTCSSMatchGet(uint32_t ui32Match)
  723. {
  724. ASSERT(ui32Match == 0);
  725. //
  726. // Read the current second RTC count.
  727. //
  728. return(HWREG(HIB_RTCSS) >> HIB_RTCSS_RTCSSM_S);
  729. }
  730. //*****************************************************************************
  731. //
  732. //! Returns the current value of the RTC sub second count.
  733. //!
  734. //! This function returns the current value of the sub second count for the RTC
  735. //! in 1/32768 of a second increments. The only value that can be used with
  736. //! the \e ui32Match parameter is zero, other values are reserved for future
  737. //! use.
  738. //!
  739. //! \return The current RTC sub second count in 1/32768 seconds.
  740. //
  741. //*****************************************************************************
  742. uint32_t
  743. HibernateRTCSSGet(void)
  744. {
  745. //
  746. // Read the current second RTC count.
  747. //
  748. return(HWREG(HIB_RTCSS) & HIB_RTCSS_RTCSSC_M);
  749. }
  750. //*****************************************************************************
  751. //
  752. //! Sets the value of the RTC pre-divider trim register.
  753. //!
  754. //! \param ui32Trim is the new value for the pre-divider trim register.
  755. //!
  756. //! This function sets the value of the pre-divider trim register. The input
  757. //! time source is divided by the pre-divider to achieve a one-second clock
  758. //! rate. Once every 64 seconds, the value of the pre-divider trim register is
  759. //! applied to the pre-divider to allow fine-tuning of the RTC rate, in order
  760. //! to make corrections to the rate. The software application can make
  761. //! adjustments to the pre-divider trim register to account for variations in
  762. //! the accuracy of the input time source. The nominal value is 0x7FFF, and it
  763. //! can be adjusted up or down in order to fine-tune the RTC rate.
  764. //!
  765. //! \return None.
  766. //
  767. //*****************************************************************************
  768. void
  769. HibernateRTCTrimSet(uint32_t ui32Trim)
  770. {
  771. //
  772. // Check the arguments.
  773. //
  774. ASSERT(ui32Trim < 0x10000);
  775. //
  776. // Write the new trim value to the trim register.
  777. //
  778. HWREG(HIB_RTCT) = ui32Trim;
  779. //
  780. // Wait for write completion
  781. //
  782. _HibernateWriteComplete();
  783. }
  784. //*****************************************************************************
  785. //
  786. //! Gets the value of the RTC pre-divider trim register.
  787. //!
  788. //! This function gets the value of the pre-divider trim register. This
  789. //! function can be used to get the current value of the trim register prior
  790. //! to making an adjustment by using the HibernateRTCTrimSet() function.
  791. //!
  792. //! \return None.
  793. //
  794. //*****************************************************************************
  795. uint32_t
  796. HibernateRTCTrimGet(void)
  797. {
  798. //
  799. // Return the value of the trim register to the caller.
  800. //
  801. return(HWREG(HIB_RTCT));
  802. }
  803. //*****************************************************************************
  804. //
  805. //! Stores data in the battery-backed memory of the Hibernation module.
  806. //!
  807. //! \param pui32Data points to the data that the caller wants to store in the
  808. //! memory of the Hibernation module.
  809. //! \param ui32Count is the count of 32-bit words to store.
  810. //!
  811. //! Stores a set of data in the Hibernation module battery-backed memory.
  812. //! This memory is preserved when the power to the processor is turned off
  813. //! and can be used to store application state information that is needed when
  814. //! the processor wakes. Up to 16 32-bit words can be stored in the
  815. //! battery-backed memory. The data can be restored by calling the
  816. //! HibernateDataGet() function.
  817. //!
  818. //! \return None.
  819. //
  820. //*****************************************************************************
  821. void
  822. HibernateDataSet(uint32_t *pui32Data, uint32_t ui32Count)
  823. {
  824. uint32_t ui32Idx;
  825. //
  826. // Check the arguments.
  827. //
  828. ASSERT(ui32Count <= 64);
  829. ASSERT(pui32Data != 0);
  830. //
  831. // Loop through all the words to be stored, storing one at a time.
  832. //
  833. for(ui32Idx = 0; ui32Idx < ui32Count; ui32Idx++)
  834. {
  835. //
  836. // Write a word to the battery-backed storage area.
  837. //
  838. HWREG(HIB_DATA + (ui32Idx * 4)) = pui32Data[ui32Idx];
  839. //
  840. // Wait for write completion
  841. //
  842. _HibernateWriteComplete();
  843. }
  844. }
  845. //*****************************************************************************
  846. //
  847. //! Reads a set of data from the battery-backed memory of the Hibernation
  848. //! module.
  849. //!
  850. //! \param pui32Data points to a location where the data that is read from the
  851. //! Hibernation module is stored.
  852. //! \param ui32Count is the count of 32-bit words to read.
  853. //!
  854. //! This function retrieves a set of data from the Hibernation module
  855. //! battery-backed memory that was previously stored with the
  856. //! HibernateDataSet() function. The caller must ensure that \e pui32Data
  857. //! points to a large enough memory block to hold all the data that is read
  858. //! from the battery-backed memory.
  859. //!
  860. //! \return None.
  861. //
  862. //*****************************************************************************
  863. void
  864. HibernateDataGet(uint32_t *pui32Data, uint32_t ui32Count)
  865. {
  866. uint32_t ui32Idx;
  867. //
  868. // Check the arguments.
  869. //
  870. ASSERT(ui32Count <= 64);
  871. ASSERT(pui32Data != 0);
  872. //
  873. // Loop through all the words to be restored, reading one at a time.
  874. //
  875. for(ui32Idx = 0; ui32Idx < ui32Count; ui32Idx++)
  876. {
  877. //
  878. // Read a word from the battery-backed storage area. No delay is
  879. // required between reads.
  880. //
  881. pui32Data[ui32Idx] = HWREG(HIB_DATA + (ui32Idx * 4));
  882. }
  883. }
  884. //*****************************************************************************
  885. //
  886. //! Requests hibernation mode.
  887. //!
  888. //! This function requests the Hibernation module to disable the external
  889. //! regulator, thus removing power from the processor and all peripherals. The
  890. //! Hibernation module remains powered from the battery or auxiliary power
  891. //! supply.
  892. //!
  893. //! The Hibernation module re-enables the external regulator when one of
  894. //! the configured wake conditions occurs (such as RTC match or external
  895. //! \b WAKE pin). When the power is restored, the processor goes through a
  896. //! power-on reset although the Hibernation module is not reset. The processor
  897. //! can retrieve saved state information with the HibernateDataGet() function.
  898. //! Prior to calling the function to request hibernation mode, the conditions
  899. //! for waking must have already been set by using the HibernateWakeSet()
  900. //! function.
  901. //!
  902. //! Note that this function may return because some time may elapse before the
  903. //! power is actually removed, or it may not be removed at all. For this
  904. //! reason, the processor continues to execute instructions for some time,
  905. //! and the caller should be prepared for this function to return. There are
  906. //! various reasons why the power may not be removed. For example, if the
  907. //! HibernateLowBatSet() function was used to configure an abort if low
  908. //! battery is detected, then the power is not removed if the battery
  909. //! voltage is too low. There may be other reasons related to the external
  910. //! circuit design, that a request for hibernation may not actually occur.
  911. //!
  912. //! For all these reasons, the caller must be prepared for this function to
  913. //! return. The simplest way to handle it is to just enter an infinite loop
  914. //! and wait for the power to be removed.
  915. //!
  916. //! \return None.
  917. //
  918. //*****************************************************************************
  919. void
  920. HibernateRequest(void)
  921. {
  922. //
  923. // Set the bit in the control register to cut main power to the processor.
  924. //
  925. HWREG(HIB_CTL) |= HIB_CTL_HIBREQ;
  926. //
  927. // Wait for write completion
  928. //
  929. _HibernateWriteComplete();
  930. }
  931. //*****************************************************************************
  932. //
  933. //! Enables interrupts for the Hibernation module.
  934. //!
  935. //! \param ui32IntFlags is the bit mask of the interrupts to be enabled.
  936. //!
  937. //! This function enables the specified interrupt sources from the Hibernation
  938. //! module.
  939. //!
  940. //! The \e ui32IntFlags parameter must be the logical OR of any combination of
  941. //! the following:
  942. //!
  943. //! - \b HIBERNATE_INT_WR_COMPLETE - write complete interrupt
  944. //! - \b HIBERNATE_INT_PIN_WAKE - wake from pin interrupt
  945. //! - \b HIBERNATE_INT_LOW_BAT - low-battery interrupt
  946. //! - \b HIBERNATE_INT_RTC_MATCH_0 - RTC match 0 interrupt
  947. //! - \b HIBERNATE_INT_VDDFAIL - supply failure interrupt.
  948. //! - \b HIBERNATE_INT_RESET_WAKE - wake from reset pin interrupt
  949. //! - \b HIBERNATE_INT_GPIO_WAKE - wake from GPIO pin or reset pin interrupt.
  950. //!
  951. //! \note The \b HIBERNATE_INT_RESET_WAKE, \b HIBERNATE_INT_GPIO_WAKE, and
  952. //! \b HIBERNATE_INT_VDDFAIL settings are not available on all Tiva devices.
  953. //! Please consult the data sheet for the Tiva device that you are using to
  954. //! determine if these interrupt sources are available.
  955. //!
  956. //! \return None.
  957. //
  958. //*****************************************************************************
  959. void
  960. HibernateIntEnable(uint32_t ui32IntFlags)
  961. {
  962. //
  963. // Check the arguments.
  964. //
  965. ASSERT(!(ui32IntFlags & ~(HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_LOW_BAT |
  966. HIBERNATE_INT_VDDFAIL |
  967. HIBERNATE_INT_RESET_WAKE |
  968. HIBERNATE_INT_GPIO_WAKE |
  969. HIBERNATE_INT_RTC_MATCH_0 |
  970. HIBERNATE_INT_WR_COMPLETE)));
  971. //
  972. // Set the specified interrupt mask bits.
  973. //
  974. HWREG(HIB_IM) |= ui32IntFlags;
  975. //
  976. // Wait for write completion
  977. //
  978. _HibernateWriteComplete();
  979. }
  980. //*****************************************************************************
  981. //
  982. //! Disables interrupts for the Hibernation module.
  983. //!
  984. //! \param ui32IntFlags is the bit mask of the interrupts to be disabled.
  985. //!
  986. //! This function disables the specified interrupt sources from the
  987. //! Hibernation module.
  988. //!
  989. //! The \e ui32IntFlags parameter has the same definition as the
  990. //! \e ui32IntFlags parameter to the HibernateIntEnable() function.
  991. //!
  992. //! \return None.
  993. //
  994. //*****************************************************************************
  995. void
  996. HibernateIntDisable(uint32_t ui32IntFlags)
  997. {
  998. //
  999. // Check the arguments.
  1000. //
  1001. ASSERT(!(ui32IntFlags & ~(HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_LOW_BAT |
  1002. HIBERNATE_INT_VDDFAIL |
  1003. HIBERNATE_INT_RESET_WAKE |
  1004. HIBERNATE_INT_GPIO_WAKE |
  1005. HIBERNATE_INT_RTC_MATCH_0 |
  1006. HIBERNATE_INT_WR_COMPLETE)));
  1007. //
  1008. // Clear the specified interrupt mask bits.
  1009. //
  1010. HWREG(HIB_IM) &= ~ui32IntFlags;
  1011. //
  1012. // Wait for write completion
  1013. //
  1014. _HibernateWriteComplete();
  1015. }
  1016. //*****************************************************************************
  1017. //
  1018. //! Returns the hibernate module interrupt number.
  1019. //!
  1020. //! This function returns the interrupt number for the hibernate module.
  1021. //!
  1022. //! \return Returns a hibernate interrupt number or 0 if the interrupt does not
  1023. //! exist.
  1024. //
  1025. //*****************************************************************************
  1026. static uint32_t
  1027. _HibernateIntNumberGet(void)
  1028. {
  1029. uint32_t ui32Int;
  1030. //
  1031. // Find the valid interrupt number for the hibernate module.
  1032. //
  1033. if(CLASS_IS_TM4C129)
  1034. {
  1035. ui32Int = INT_HIBERNATE_TM4C129;
  1036. }
  1037. else
  1038. {
  1039. ui32Int = INT_HIBERNATE_TM4C123;
  1040. }
  1041. return(ui32Int);
  1042. }
  1043. //*****************************************************************************
  1044. //
  1045. //! Registers an interrupt handler for the Hibernation module interrupt.
  1046. //!
  1047. //! \param pfnHandler points to the function to be called when a hibernation
  1048. //! interrupt occurs.
  1049. //!
  1050. //! This function registers the interrupt handler in the system interrupt
  1051. //! controller. The interrupt is enabled at the global level, but individual
  1052. //! interrupt sources must still be enabled with a call to
  1053. //! HibernateIntEnable().
  1054. //!
  1055. //! \sa IntRegister() for important information about registering interrupt
  1056. //! handlers.
  1057. //!
  1058. //! \return None.
  1059. //
  1060. //*****************************************************************************
  1061. void
  1062. HibernateIntRegister(void (*pfnHandler)(void))
  1063. {
  1064. uint32_t ui32Int;
  1065. //
  1066. // Get the interrupt number for the Hibernate module.
  1067. //
  1068. ui32Int = _HibernateIntNumberGet();
  1069. ASSERT(ui32Int != 0);
  1070. //
  1071. // Register the interrupt handler.
  1072. //
  1073. IntRegister(ui32Int, pfnHandler);
  1074. //
  1075. // Enable the hibernate module interrupt.
  1076. //
  1077. IntEnable(ui32Int);
  1078. }
  1079. //*****************************************************************************
  1080. //
  1081. //! Unregisters an interrupt handler for the Hibernation module interrupt.
  1082. //!
  1083. //! This function unregisters the interrupt handler in the system interrupt
  1084. //! controller. The interrupt is disabled at the global level, and the
  1085. //! interrupt handler is no longer called.
  1086. //!
  1087. //! \sa IntRegister() for important information about registering interrupt
  1088. //! handlers.
  1089. //!
  1090. //! \return None.
  1091. //
  1092. //*****************************************************************************
  1093. void
  1094. HibernateIntUnregister(void)
  1095. {
  1096. uint32_t ui32Int;
  1097. //
  1098. // Get the interrupt number for the Hibernate module.
  1099. //
  1100. ui32Int = _HibernateIntNumberGet();
  1101. ASSERT(ui32Int != 0);
  1102. //
  1103. // Disable the hibernate interrupt.
  1104. //
  1105. IntDisable(ui32Int);
  1106. //
  1107. // Unregister the interrupt handler.
  1108. //
  1109. IntUnregister(ui32Int);
  1110. }
  1111. //*****************************************************************************
  1112. //
  1113. //! Gets the current interrupt status of the Hibernation module.
  1114. //!
  1115. //! \param bMasked is false to retrieve the raw interrupt status, and true to
  1116. //! retrieve the masked interrupt status.
  1117. //!
  1118. //! This function returns the interrupt status of the Hibernation module. The
  1119. //! caller can use this function to determine the cause of a hibernation
  1120. //! interrupt. Either the masked or raw interrupt status can be returned.
  1121. //!
  1122. //! \note A wake from reset pin also signals a wake from GPIO pin with the
  1123. //! value returned being HIBERNATE_INT_GPIO_WAKE | HIBERNATE_INT_RESET_WAKE.
  1124. //! Hence a wake from reset pin should take priority over wake from GPIO pin.
  1125. //!
  1126. //! \return Returns the interrupt status as a bit field with the values as
  1127. //! described in the HibernateIntEnable() function.
  1128. //
  1129. //*****************************************************************************
  1130. uint32_t
  1131. HibernateIntStatus(bool bMasked)
  1132. {
  1133. //
  1134. // Read and return the Hibernation module raw or masked interrupt status.
  1135. //
  1136. if(bMasked == true)
  1137. {
  1138. return(HWREG(HIB_MIS));
  1139. }
  1140. else
  1141. {
  1142. return(HWREG(HIB_RIS));
  1143. }
  1144. }
  1145. //*****************************************************************************
  1146. //
  1147. //! Clears pending interrupts from the Hibernation module.
  1148. //!
  1149. //! \param ui32IntFlags is the bit mask of the interrupts to be cleared.
  1150. //!
  1151. //! This function clears the specified interrupt sources. This function must
  1152. //! be called within the interrupt handler or else the handler is called again
  1153. //! upon exit.
  1154. //!
  1155. //! The \e ui32IntFlags parameter has the same definition as the
  1156. //! \e ui32IntFlags parameter to the HibernateIntEnable() function.
  1157. //!
  1158. //! \note Because there is a write buffer in the Cortex-M processor, it may
  1159. //! take several clock cycles before the interrupt source is actually cleared.
  1160. //! Therefore, it is recommended that the interrupt source be cleared early in
  1161. //! the interrupt handler (as opposed to the very last action) to avoid
  1162. //! returning from the interrupt handler before the interrupt source is
  1163. //! actually cleared. Failure to do so may result in the interrupt handler
  1164. //! being immediately reentered (because the interrupt controller still sees
  1165. //! the interrupt source asserted).
  1166. //!
  1167. //! \return None.
  1168. //
  1169. //*****************************************************************************
  1170. void
  1171. HibernateIntClear(uint32_t ui32IntFlags)
  1172. {
  1173. //
  1174. // Check the arguments.
  1175. //
  1176. ASSERT(!(ui32IntFlags & ~(HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_LOW_BAT |
  1177. HIBERNATE_INT_VDDFAIL |
  1178. HIBERNATE_INT_RESET_WAKE |
  1179. HIBERNATE_INT_GPIO_WAKE |
  1180. HIBERNATE_INT_RTC_MATCH_0 |
  1181. HIBERNATE_INT_WR_COMPLETE)));
  1182. //
  1183. // Write the specified interrupt bits into the interrupt clear register.
  1184. //
  1185. HWREG(HIB_IC) |= ui32IntFlags;
  1186. //
  1187. // Wait for write completion
  1188. //
  1189. _HibernateWriteComplete();
  1190. }
  1191. //*****************************************************************************
  1192. //
  1193. //! Checks to see if the Hibernation module is already powered up.
  1194. //!
  1195. //! This function queries the control register to determine if the module is
  1196. //! already active. This function can be called at a power-on reset to help
  1197. //! determine if the reset is due to a wake from hibernation or a cold start.
  1198. //! If the Hibernation module is already active, then it does not need to be
  1199. //! re-enabled, and its status can be queried immediately.
  1200. //!
  1201. //! The software application should also use the HibernateIntStatus() function
  1202. //! to read the raw interrupt status to determine the cause of the wake. The
  1203. //! HibernateDataGet() function can be used to restore state. These
  1204. //! combinations of functions can be used by the software to determine if the
  1205. //! processor is waking from hibernation and the appropriate action to take as
  1206. //! a result.
  1207. //!
  1208. //! \return Returns \b true if the module is already active, and \b false if
  1209. //! not.
  1210. //
  1211. //*****************************************************************************
  1212. uint32_t
  1213. HibernateIsActive(void)
  1214. {
  1215. //
  1216. // Read the control register, and return true if the module is enabled.
  1217. //
  1218. return(HWREG(HIB_CTL) & HIB_CTL_CLK32EN ? 1 : 0);
  1219. }
  1220. //*****************************************************************************
  1221. //
  1222. //! Enables GPIO retention after wake from hibernation.
  1223. //!
  1224. //! This function enables the GPIO pin state to be maintained during
  1225. //! hibernation and remain active even when waking from hibernation. The GPIO
  1226. //! module itself is reset upon entering hibernation and no longer controls the
  1227. //! output pins. To maintain the current output level after waking from
  1228. //! hibernation, the GPIO module must be reconfigured and then the
  1229. //! HibernateGPIORetentionDisable() function must be called to return control
  1230. //! of the GPIO pin to the GPIO module.
  1231. //!
  1232. //! \note The hibernation GPIO retention setting is not available on all
  1233. //! Tiva devices. Please consult the data sheet to determine if the
  1234. //! device you are using supports this feature in the Hibernation module.
  1235. //!
  1236. //! \return None.
  1237. //
  1238. //*****************************************************************************
  1239. void
  1240. HibernateGPIORetentionEnable(void)
  1241. {
  1242. //
  1243. // Enable power to the pads and enable GPIO retention during hibernate.
  1244. //
  1245. HWREG(HIB_CTL) |= HIB_CTL_VDD3ON | HIB_CTL_RETCLR;
  1246. //
  1247. // Wait for write completion
  1248. //
  1249. _HibernateWriteComplete();
  1250. }
  1251. //*****************************************************************************
  1252. //
  1253. //! Disables GPIO retention after wake from hibernation.
  1254. //!
  1255. //! This function disables the retention of the GPIO pin state during
  1256. //! hibernation and allows the GPIO pins to be controlled by the system. If
  1257. //! the HibernateGPIORetentionEnable() function is called before entering
  1258. //! hibernation, this function must be called after returning from hibernation
  1259. //! to allow the GPIO pins to be controlled by GPIO module.
  1260. //!
  1261. //! \note The hibernate GPIO retention setting is not available on all
  1262. //! Tiva devices. Please consult the data sheet to determine if the
  1263. //! device you are using supports this feature in the Hibernation module.
  1264. //!
  1265. //! \return None.
  1266. //
  1267. //*****************************************************************************
  1268. void
  1269. HibernateGPIORetentionDisable(void)
  1270. {
  1271. //
  1272. // Reset the GPIO configuration after waking from hibernate and disable
  1273. // the hibernate power to the pads.
  1274. //
  1275. HWREG(HIB_CTL) &= ~(HIB_CTL_RETCLR | HIB_CTL_VDD3ON);
  1276. //
  1277. // Wait for write completion
  1278. //
  1279. _HibernateWriteComplete();
  1280. }
  1281. //*****************************************************************************
  1282. //
  1283. //! Returns the current setting for GPIO retention.
  1284. //!
  1285. //! This function returns the current setting for GPIO retention in the
  1286. //! hibernate module.
  1287. //!
  1288. //! \note The hibernation GPIO retention setting is not available on all
  1289. //! Tiva devices. Please consult the data sheet to determine if the
  1290. //! device you are using supports this feature in the Hibernation module.
  1291. //!
  1292. //! \return Returns true if GPIO retention is enabled and false if GPIO
  1293. //! retention is disabled.
  1294. //
  1295. //*****************************************************************************
  1296. bool
  1297. HibernateGPIORetentionGet(void)
  1298. {
  1299. //
  1300. // Read the current GPIO retention configuration.
  1301. //
  1302. if((HWREG(HIB_CTL) & (HIB_CTL_RETCLR | HIB_CTL_VDD3ON)) ==
  1303. (HIB_CTL_RETCLR | HIB_CTL_VDD3ON))
  1304. {
  1305. return(true);
  1306. }
  1307. return(false);
  1308. }
  1309. //*****************************************************************************
  1310. //
  1311. //! Configures the Hibernation module's internal counter mode.
  1312. //!
  1313. //! \param ui32Config is the configuration to use for the Hibernation module's
  1314. //! counter.
  1315. //!
  1316. //! This function configures the Hibernate module's counter mode to operate
  1317. //! as a standard RTC counter or to operate in a calendar mode. The
  1318. //! \e ui32Config parameter is used to provide the configuration for
  1319. //! the counter and must include only one of the following values:
  1320. //!
  1321. //! - \b HIBERNATE_COUNTER_24HR specifies 24-hour calendar mode.
  1322. //! - \b HIBERNATE_COUNTER_12HR specifies 12-hour AM/PM calendar mode.
  1323. //! - \b HIBERNATE_COUNTER_RTC specifies RTC counter mode.
  1324. //!
  1325. //! The HibernateCalendar functions can only be called when either
  1326. //! \b HIBERNATE_COUNTER_24HR or \b HIBERNATE_COUNTER_12HR is specified.
  1327. //!
  1328. //! \b Example: Configure hibernate counter to 24-hour calendar mode.
  1329. //!
  1330. //! \verbatim
  1331. //!
  1332. //! //
  1333. //! // Configure the hibernate module counter to 24-hour calendar mode.
  1334. //! //
  1335. //! HibernateCounterMode(HIBERNATE_COUNTER_24HR);
  1336. //!
  1337. //! \endverbatim
  1338. //!
  1339. //! \note The hibernate calendar mode is not available on all Tiva
  1340. //! devices. Please consult the data sheet to determine if the device you are
  1341. //! using supports this feature in the Hibernation module.
  1342. //!
  1343. //! \return None.
  1344. //
  1345. //*****************************************************************************
  1346. void
  1347. HibernateCounterMode(uint32_t ui32Config)
  1348. {
  1349. //
  1350. // Set the requested configuration.
  1351. //
  1352. HWREG(HIB_CALCTL) = ui32Config;
  1353. //
  1354. // Wait for write completion
  1355. //
  1356. _HibernateWriteComplete();
  1357. }
  1358. //*****************************************************************************
  1359. //
  1360. // Internal function to parse the time structure to set the calendar fields.
  1361. //
  1362. //*****************************************************************************
  1363. static void
  1364. _HibernateCalendarSet(uint32_t ui32Reg, struct tm *psTime)
  1365. {
  1366. uint32_t ui32Time, ui32Date;
  1367. ASSERT(HWREG(HIB_CALCTL) & HIB_CALCTL_CALEN);
  1368. //
  1369. // Minutes and seconds are consistent in all modes.
  1370. //
  1371. ui32Time = (((psTime->tm_min << HIB_CALLD0_MIN_S) & HIB_CALLD0_MIN_M) |
  1372. ((psTime->tm_sec << HIB_CALLD0_SEC_S) & HIB_CALLD0_SEC_M));
  1373. //
  1374. // 24 Hour time is used directly for Calendar set.
  1375. //
  1376. if(HWREG(HIB_CALCTL) & HIB_CALCTL_CAL24)
  1377. {
  1378. ui32Time |= (psTime->tm_hour << HIB_CALLD0_HR_S);
  1379. //
  1380. // for Calendar match, if it is every hour, AMPM bit should be clear
  1381. //
  1382. if((ui32Reg == HIB_CALM0) && (psTime->tm_hour == 0xFF) )
  1383. {
  1384. //
  1385. // clear AMPM bit
  1386. //
  1387. ui32Time &= ~HIB_CAL0_AMPM;
  1388. }
  1389. }
  1390. else
  1391. {
  1392. //
  1393. // In AM/PM time hours have to be capped at 12.
  1394. // If the hours are all 1s, it means the match for the hour is
  1395. // always true. We need to set 1F in the hw field.
  1396. //
  1397. if(psTime->tm_hour == 0xFF)
  1398. {
  1399. //
  1400. // Match every hour.
  1401. //
  1402. ui32Time |= HIB_CALLD0_HR_M;
  1403. }
  1404. else if(psTime->tm_hour >= 12)
  1405. {
  1406. //
  1407. // Need to set the PM bit if it is noon or later.
  1408. //
  1409. ui32Time |= (((psTime->tm_hour - 12) << HIB_CALLD0_HR_S) |
  1410. HIB_CAL0_AMPM);
  1411. }
  1412. else
  1413. {
  1414. //
  1415. // All other times are normal and AM.
  1416. //
  1417. ui32Time |= (psTime->tm_hour << HIB_CALLD0_HR_S);
  1418. }
  1419. }
  1420. //
  1421. // Create the date in the correct register format.
  1422. //
  1423. if(ui32Reg == HIB_CAL0)
  1424. {
  1425. //
  1426. // We must add 1 to the month, since the time structure lists
  1427. // the month from 0 to 11 and the HIB lists it from 1 to 12.
  1428. //
  1429. ui32Date = ((psTime->tm_mday << HIB_CAL1_DOM_S) |
  1430. ((psTime->tm_mon + 1) << HIB_CAL1_MON_S) |
  1431. (psTime->tm_wday << HIB_CAL1_DOW_S) |
  1432. ((psTime->tm_year - 100) << HIB_CAL1_YEAR_S));
  1433. }
  1434. else
  1435. {
  1436. //
  1437. // Wday, month and year are not included in the match
  1438. // Functionality.
  1439. //
  1440. if(psTime->tm_mday == 0xFF)
  1441. {
  1442. //
  1443. // program 0 to match every day
  1444. //
  1445. ui32Date = 0 << HIB_CAL1_DOM_M;
  1446. }
  1447. else
  1448. {
  1449. ui32Date = (psTime->tm_mday << HIB_CAL1_DOM_S);
  1450. }
  1451. }
  1452. //
  1453. // Load register requires unlock.
  1454. //
  1455. if(ui32Reg == HIB_CAL0)
  1456. {
  1457. //
  1458. // Unlock the hibernate counter load registers.
  1459. //
  1460. HWREG(HIB_LOCK) = HIB_LOCK_HIBLOCK_KEY;
  1461. _HibernateWriteComplete();
  1462. }
  1463. //
  1464. // Set the requested time and date.
  1465. //
  1466. if(ui32Reg == HIB_CAL0)
  1467. {
  1468. HWREG(HIB_CALLD0) = ui32Time;
  1469. _HibernateWriteComplete();
  1470. HWREG(HIB_CALLD1) = ui32Date;
  1471. _HibernateWriteComplete();
  1472. }
  1473. else
  1474. {
  1475. HWREG(HIB_CALM0) = ui32Time;
  1476. _HibernateWriteComplete();
  1477. HWREG(HIB_CALM1) = ui32Date;
  1478. _HibernateWriteComplete();
  1479. }
  1480. //
  1481. // Load register requires unlock.
  1482. //
  1483. if(ui32Reg == HIB_CAL0)
  1484. {
  1485. //
  1486. // Lock the hibernate counter load registers.
  1487. //
  1488. HWREG(HIB_LOCK) = 0;
  1489. _HibernateWriteComplete();
  1490. }
  1491. }
  1492. //*****************************************************************************
  1493. //
  1494. //! Sets the Hibernation module's date and time in calendar mode.
  1495. //!
  1496. //! \param psTime is the structure that holds the information for the current
  1497. //! date and time.
  1498. //!
  1499. //! This function uses the \e psTime parameter to set the current date and
  1500. //! time when the Hibernation module is in calendar mode. Regardless of
  1501. //! whether 24-hour or 12-hour mode is in use, the \e psTime structure uses a
  1502. //! 24-hour representation of the time. This function can only be called when
  1503. //! the hibernate counter is configured in calendar mode using the
  1504. //! HibernateCounterMode() function with one of the calendar modes.
  1505. //!
  1506. //! The hibernate module contains a 7-bit register field to store the year with
  1507. //! valid values ranges from 0 to 99. In order to maximize the calendar
  1508. //! year up to 2099, the HibernateCalendarSet() will accept calendar year
  1509. //! after the year 2000 only. Calendar years before 2000 (i.e. 1987) will
  1510. //! produce unexpected results.
  1511. //!
  1512. //! \note The hibernate calendar mode is not available on all Tiva
  1513. //! devices. Please consult the data sheet to determine if the device you are
  1514. //! using supports this feature in the Hibernation module.
  1515. //!
  1516. //! \return None.
  1517. //
  1518. //*****************************************************************************
  1519. void
  1520. HibernateCalendarSet(struct tm *psTime)
  1521. {
  1522. //
  1523. // Load a new date/time.
  1524. //
  1525. _HibernateCalendarSet(HIB_CAL0, psTime);
  1526. }
  1527. //*****************************************************************************
  1528. //
  1529. //! Returns the Hibernation module's date and time in calendar mode.
  1530. //!
  1531. //! \param psTime is the structure that is filled with the current date and
  1532. //! time.
  1533. //!
  1534. //! This function returns the current date and time in the structure provided
  1535. //! by the \e psTime parameter. Regardless of the calendar mode, the
  1536. //! \e psTime parameter uses a 24-hour representation of the time. This
  1537. //! function can only be called when the Hibernation module is configured in
  1538. //! calendar mode using the HibernateCounterMode() function with one of the
  1539. //! calendar modes.
  1540. //!
  1541. //! The only case where this function fails and returns a non-zero value is
  1542. //! when the function detects that the counter is passing from the last second
  1543. //! of the day to the first second of the next day. This exception must be
  1544. //! handled in the application by waiting at least one second before calling
  1545. //! again to get the updated calendar information.
  1546. //!
  1547. //! \note The hibernate calendar mode is not available on all Tiva
  1548. //! devices. Please consult the data sheet to determine if the device you are
  1549. //! using supports this feature in the Hibernation module.
  1550. //!
  1551. //! \return Returns zero if the time and date were read successfully and
  1552. //! returns a non-zero value if the \e psTime structure was not updated.
  1553. //
  1554. //*****************************************************************************
  1555. int
  1556. HibernateCalendarGet(struct tm *psTime)
  1557. {
  1558. uint32_t ui32Date, ui32Time;
  1559. ASSERT(HWREG(HIB_CALCTL) & HIB_CALCTL_CALEN);
  1560. //
  1561. // Wait for the value to be valid, this should never be more than a few
  1562. // loops and should never hang.
  1563. //
  1564. do
  1565. {
  1566. ui32Date = HWREG(HIB_CAL1);
  1567. }
  1568. while((ui32Date & HIB_CAL1_VALID) == 0);
  1569. //
  1570. // Wait for the value to be valid, this should never be more than a few
  1571. // loops and should never hang.
  1572. //
  1573. do
  1574. {
  1575. ui32Time = HWREG(HIB_CAL0);
  1576. }
  1577. while((ui32Time & HIB_CAL0_VALID) == 0);
  1578. //
  1579. // The date changed after reading the time so fail this call and let the
  1580. // application call again since it knows how int32_t to wait until another
  1581. // second passes.
  1582. //
  1583. if(ui32Date != HWREG(HIB_CAL1))
  1584. {
  1585. return(-1);
  1586. }
  1587. //
  1588. // Populate the date and time fields in the psTime structure.
  1589. // We must subtract 1 from the month, since the time structure lists
  1590. // the month from 0 to 11 and the HIB lists it from 1 to 12.
  1591. //
  1592. psTime->tm_min = (ui32Time & HIB_CAL0_MIN_M) >> HIB_CAL0_MIN_S;
  1593. psTime->tm_sec = (ui32Time & HIB_CAL0_SEC_M) >> HIB_CAL0_SEC_S;
  1594. psTime->tm_mon = (((ui32Date & HIB_CAL1_MON_M) >> HIB_CAL1_MON_S) - 1);
  1595. psTime->tm_mday = (ui32Date & HIB_CAL1_DOM_M) >> HIB_CAL1_DOM_S;
  1596. psTime->tm_wday = (ui32Date & HIB_CAL1_DOW_M) >> HIB_CAL1_DOW_S;
  1597. psTime->tm_year = ((ui32Date & HIB_CAL1_YEAR_M) >> HIB_CAL1_YEAR_S) + 100;
  1598. psTime->tm_hour = (ui32Time & HIB_CAL0_HR_M) >> HIB_CAL0_HR_S;
  1599. //
  1600. // Fix up the hour in the non-24-hour mode and the time is in PM.
  1601. //
  1602. if(((HWREG(HIB_CALCTL) & HIB_CALCTL_CAL24) == 0) &&
  1603. (ui32Time & HIB_CAL0_AMPM))
  1604. {
  1605. psTime->tm_hour += 12;
  1606. }
  1607. return(0);
  1608. }
  1609. //*****************************************************************************
  1610. //
  1611. //! Sets the Hibernation module's date and time match value in calendar mode.
  1612. //!
  1613. //! \param ui32Index indicates which match register to access.
  1614. //! \param psTime is the structure that holds all of the information to set
  1615. //! the current date and time match values.
  1616. //!
  1617. //! This function uses the \e psTime parameter to set the current date and time
  1618. //! match value in the Hibernation module's calendar. Regardless of the mode,
  1619. //! the \e psTime parameter uses a 24-hour clock representation of time.
  1620. //! This function can only be called when the Hibernation module is
  1621. //! configured in calendar mode using the HibernateCounterMode()
  1622. //! function. The \e ui32Index value is reserved for future use and should
  1623. //! always be zero.
  1624. //! Calendar match can be enabled for every day, every hour, every minute or
  1625. //! every second, setting any of these fields to 0xFF causes a match for
  1626. //! that field. For example, setting the day of month field to 0xFF
  1627. //! results in a calendar match daily at the same time.
  1628. //!
  1629. //! \note The hibernate calendar mode is not available on all Tiva
  1630. //! devices. Please consult the data sheet to determine if the device you are
  1631. //! using supports this feature in the Hibernation module.
  1632. //!
  1633. //! \return None.
  1634. //
  1635. //*****************************************************************************
  1636. void
  1637. HibernateCalendarMatchSet(uint32_t ui32Index, struct tm *psTime)
  1638. {
  1639. //
  1640. // Set the Match value.
  1641. //
  1642. _HibernateCalendarSet(HIB_CALM0, psTime);
  1643. }
  1644. //*****************************************************************************
  1645. //
  1646. //! Returns the Hibernation module's date and time match value in calendar
  1647. //! mode.
  1648. //!
  1649. //! \param ui32Index indicates which match register to access.
  1650. //! \param psTime is the structure to fill with the current date and time
  1651. //! match value.
  1652. //!
  1653. //! This function returns the current date and time match value in the
  1654. //! structure provided by the \e psTime parameter. Regardless of the mode, the
  1655. //! \e psTime parameter uses a 24-hour clock representation of time.
  1656. //! This function can only be called when the Hibernation module is configured
  1657. //! in calendar mode using the HibernateCounterMode() function.
  1658. //! The \e ui32Index value is reserved for future use and should always be
  1659. //! zero.
  1660. //!
  1661. //! \note The hibernate calendar mode is not available on all Tiva
  1662. //! devices. Please consult the data sheet to determine if the device you are
  1663. //! using supports this feature in the Hibernation module.
  1664. //!
  1665. //! \return Returns zero if the time and date match value were read
  1666. //! successfully and returns a non-zero value if the psTime structure was not
  1667. //! updated.
  1668. //
  1669. //*****************************************************************************
  1670. void
  1671. HibernateCalendarMatchGet(uint32_t ui32Index, struct tm *psTime)
  1672. {
  1673. uint32_t ui32Date, ui32Time;
  1674. ASSERT(HWREG(HIB_CALCTL) & HIB_CALCTL_CALEN);
  1675. //
  1676. // Get the date field.
  1677. //
  1678. ui32Date = HWREG(HIB_CALM1);
  1679. //
  1680. // Get the time field.
  1681. //
  1682. ui32Time = HWREG(HIB_CALM0);
  1683. //
  1684. // Populate the date and time fields in the psTime structure.
  1685. //
  1686. if((ui32Time & HIB_CAL0_MIN_M) == HIB_CAL0_MIN_M)
  1687. {
  1688. //
  1689. // Match every minute
  1690. //
  1691. psTime->tm_min = 0xFF;
  1692. }
  1693. else
  1694. {
  1695. psTime->tm_min = (ui32Time & HIB_CAL0_MIN_M) >> HIB_CAL0_MIN_S;
  1696. }
  1697. if((ui32Time & HIB_CAL0_SEC_M) == HIB_CAL0_SEC_M)
  1698. {
  1699. //
  1700. // Match every second
  1701. //
  1702. psTime->tm_sec = 0xFF;
  1703. }
  1704. else
  1705. {
  1706. psTime->tm_sec = (ui32Time & HIB_CAL0_SEC_M) >> HIB_CAL0_SEC_S;
  1707. }
  1708. if((ui32Time & HIB_CAL0_HR_M) == HIB_CAL0_HR_M)
  1709. {
  1710. //
  1711. // Match every hour
  1712. //
  1713. psTime->tm_hour = 0xFF;
  1714. }
  1715. else
  1716. {
  1717. psTime->tm_hour = (ui32Time & HIB_CAL0_HR_M) >> HIB_CAL0_HR_S;
  1718. }
  1719. if((ui32Date & HIB_CAL1_DOM_M) == 0)
  1720. {
  1721. //
  1722. // Match every day
  1723. //
  1724. psTime->tm_mday = 0xFF;
  1725. }
  1726. else
  1727. {
  1728. psTime->tm_mday = (ui32Date & HIB_CAL1_DOM_M) >> HIB_CAL1_DOM_S;
  1729. }
  1730. //
  1731. // Fix up the hour in the non-24-hour mode and the time is in PM.
  1732. //
  1733. if(((HWREG(HIB_CALCTL) & HIB_CALCTL_CAL24) == 0) &&
  1734. (ui32Time & HIB_CAL0_AMPM))
  1735. {
  1736. psTime->tm_hour += 12;
  1737. }
  1738. }
  1739. //*****************************************************************************
  1740. //
  1741. //! Configures the tamper feature event response.
  1742. //!
  1743. //! \param ui32Config specifies the configuration options for tamper events.
  1744. //!
  1745. //! This function is used to configure the event response options for the
  1746. //! tamper feature. The \e ui32Config parameter provides a combination of the
  1747. //! \b HIBERNATE_TAMPER_EVENTS_* features to set these options. The
  1748. //! application should choose from the following set of defines to determine
  1749. //! what happens to the system when a tamper event occurs:
  1750. //!
  1751. //! - \b HIBERNATE_TAMPER_EVENTS_ERASE_ALL_HIB_MEM all of the Hibernation
  1752. //! module's battery-backed RAM is cleared due to a tamper event
  1753. //! - \b HIBERNATE_TAMPER_EVENTS_ERASE_HIGH_HIB_MEM the upper half of the
  1754. //! Hibernation module's battery-backed RAM is cleared due to a tamper event
  1755. //! - \b HIBERNATE_TAMPER_EVENTS_ERASE_LOW_HIB_MEM the lower half of the
  1756. //! Hibernation module's battery-backed RAM is cleared due to a tamper event
  1757. //! - \b HIBERNATE_TAMPER_EVENTS_ERASE_NO_HIB_MEM the Hibernation module's
  1758. //! battery-backed RAM is not changed due to a tamper event
  1759. //! - \b HIBERNATE_TAMPER_EVENTS_HIB_WAKE a tamper event wakes the MCU from
  1760. //! hibernation
  1761. //! - \b HIBERNATE_TAMPER_EVENTS_NO_HIB_WAKE a tamper event does not wake the
  1762. //! MCU from hibernation
  1763. //!
  1764. //! \note The hibernate tamper feature is not available on all Tiva
  1765. //! devices. Please consult the data sheet for the Tiva device that you
  1766. //! are using to determine if this feature is available.
  1767. //!
  1768. //! \return None.
  1769. //
  1770. //*****************************************************************************
  1771. void
  1772. HibernateTamperEventsConfig(uint32_t ui32Config)
  1773. {
  1774. uint32_t ui32Temp;
  1775. //
  1776. // Mask out the on-event configuration options.
  1777. //
  1778. ui32Temp = (HWREG(HIB_TPCTL) & ~HIB_TPCTL_MEMCLR_M);
  1779. //
  1780. // Unlock the tamper registers.
  1781. //
  1782. HWREG(HIB_LOCK) = HIB_LOCK_HIBLOCK_KEY;
  1783. _HibernateWriteComplete();
  1784. //
  1785. // Set the on-event configuration.
  1786. //
  1787. HWREG(HIB_TPCTL) = (ui32Temp | ui32Config);
  1788. //
  1789. // Wait for write completion.
  1790. //
  1791. _HibernateWriteComplete();
  1792. //
  1793. // Lock the tamper registers.
  1794. //
  1795. HWREG(HIB_LOCK) = 0;
  1796. _HibernateWriteComplete();
  1797. }
  1798. //*****************************************************************************
  1799. //
  1800. //! Enables the tamper feature.
  1801. //!
  1802. //! This function is used to enable the tamper feature functionality. This
  1803. //! function should only be called after the global configuration is set with
  1804. //! a call to HibernateTamperEventsConfig() and the tamper inputs have been
  1805. //! configured with a call to HibernateTamperIOEnable().
  1806. //!
  1807. //! \note The hibernate tamper feature is not available on all Tiva
  1808. //! devices. Please consult the data sheet for the Tiva device that you
  1809. //! are using to determine if this feature is available.
  1810. //!
  1811. //! \return None.
  1812. //
  1813. //*****************************************************************************
  1814. void
  1815. HibernateTamperEnable(void)
  1816. {
  1817. //
  1818. // Unlock the tamper registers.
  1819. //
  1820. HWREG(HIB_LOCK) = HIB_LOCK_HIBLOCK_KEY;
  1821. _HibernateWriteComplete();
  1822. //
  1823. // Set the tamper enable bit.
  1824. //
  1825. HWREG(HIB_TPCTL) |= HIB_TPCTL_TPEN;
  1826. //
  1827. // Wait for write completion.
  1828. //
  1829. _HibernateWriteComplete();
  1830. //
  1831. // Lock the tamper registers.
  1832. //
  1833. HWREG(HIB_LOCK) = 0;
  1834. _HibernateWriteComplete();
  1835. }
  1836. //*****************************************************************************
  1837. //
  1838. //! Disables the tamper feature.
  1839. //!
  1840. //! This function is used to disable the tamper feature functionality. All
  1841. //! other configuration settings are left unmodified, allowing a call to
  1842. //! HibernateTamperEnable() to quickly enable the tamper feature with its
  1843. //! previous configuration.
  1844. //!
  1845. //! \note The hibernate tamper feature is not available on all Tiva
  1846. //! devices. Please consult the data sheet for the Tiva device that you
  1847. //! are using to determine if this feature is available.
  1848. //!
  1849. //! \return None.
  1850. //
  1851. //*****************************************************************************
  1852. void
  1853. HibernateTamperDisable(void)
  1854. {
  1855. //
  1856. // Unlock the tamper registers.
  1857. //
  1858. HWREG(HIB_LOCK) = HIB_LOCK_HIBLOCK_KEY;
  1859. _HibernateWriteComplete();
  1860. //
  1861. // Clear the tamper enable bit.
  1862. //
  1863. HWREG(HIB_TPCTL) &= ~HIB_TPCTL_TPEN;
  1864. //
  1865. // Wait for write completion.
  1866. //
  1867. _HibernateWriteComplete();
  1868. //
  1869. // Lock the tamper registers.
  1870. //
  1871. HWREG(HIB_LOCK) = 0;
  1872. _HibernateWriteComplete();
  1873. }
  1874. //*****************************************************************************
  1875. //
  1876. //! Configures an input to the tamper feature.
  1877. //!
  1878. //! \param ui32Input is the tamper input to configure.
  1879. //! \param ui32Config holds the configuration options for a given input to the
  1880. //! tamper feature.
  1881. //!
  1882. //! This function is used to configure an input to the tamper feature. The
  1883. //! \e ui32Input parameter specifies the tamper signal to configure and has a
  1884. //! valid range of 0-3. The \e ui32Config parameter provides the set of tamper
  1885. //! features in the \b HIBERNATE_TAMPER_IO_* values. The values that are valid
  1886. //! in the \e ui32Config parameter are:
  1887. //!
  1888. //! - \b HIBERNATE_TAMPER_IO_MATCH_SHORT configures the trigger to match after
  1889. //! 2 hibernation clocks
  1890. //! - \b HIBERNATE_TAMPER_IO_MATCH_LONG configures the trigger to match after
  1891. //! 3071 hibernation clocks
  1892. //! - \b HIBERNATE_TAMPER_IO_WPU_ENABLED turns on an internal weak pull up
  1893. //! - \b HIBERNATE_TAMPER_IO_WPU_DISABLED turns off an internal weak pull up
  1894. //! - \b HIBERNATE_TAMPER_IO_TRIGGER_HIGH sets the tamper event to active high
  1895. //! - \b HIBERNATE_TAMPER_IO_TRIGGER_LOW sets the tamper event to active low
  1896. //!
  1897. //! \note None of the GPIO API functions are needed to configure the tamper
  1898. //! pins. The tamper pins configured by using this function overrides any
  1899. //! configuration by GPIO APIs.
  1900. //!
  1901. //! \note The hibernate tamper feature is not available on all Tiva
  1902. //! devices. Please consult the data sheet for the Tiva device that you
  1903. //! are using to determine if this feature is available.
  1904. //!
  1905. //! \return None.
  1906. //
  1907. //*****************************************************************************
  1908. void
  1909. HibernateTamperIOEnable(uint32_t ui32Input, uint32_t ui32Config)
  1910. {
  1911. uint32_t ui32Temp, ui32Mask;
  1912. //
  1913. // Verify parameters.
  1914. //
  1915. ASSERT(ui32Input < 4);
  1916. //
  1917. // Read the current tamper I/O configuration.
  1918. //
  1919. ui32Temp = HWREG(HIB_TPIO);
  1920. //
  1921. // Mask out configuration options for the requested input.
  1922. //
  1923. ui32Mask = (ui32Temp & (~((HIB_TPIO_GFLTR0 | HIB_TPIO_PUEN0 |
  1924. HIB_TPIO_LEV0 | HIB_TPIO_EN0) <<
  1925. (ui32Input << 3))));
  1926. //
  1927. // Set tamper I/O configuration for the requested input.
  1928. //
  1929. ui32Temp = (ui32Mask | ((ui32Config | HIB_TPIO_EN0) << (ui32Input << 3)));
  1930. //
  1931. // Unlock the tamper registers.
  1932. //
  1933. HWREG(HIB_LOCK) = HIB_LOCK_HIBLOCK_KEY;
  1934. _HibernateWriteComplete();
  1935. //
  1936. // Write to the register.
  1937. //
  1938. HWREG(HIB_TPIO) = ui32Temp;
  1939. //
  1940. // Wait for write completion.
  1941. //
  1942. _HibernateWriteComplete();
  1943. //
  1944. // Lock the tamper registers.
  1945. //
  1946. HWREG(HIB_LOCK) = 0;
  1947. _HibernateWriteComplete();
  1948. }
  1949. //*****************************************************************************
  1950. //
  1951. //! Disables an input to the tamper feature.
  1952. //!
  1953. //! \param ui32Input is the tamper input to disable.
  1954. //!
  1955. //! This function is used to disable an input to the tamper feature. The
  1956. //! \e ui32Input parameter specifies the tamper signal to disable and has a
  1957. //! valid range of 0-3.
  1958. //!
  1959. //! \note None of the GPIO API functions are needed to configure the tamper
  1960. //! pins. The tamper pins configured by using this function overrides any
  1961. //! configuration by GPIO APIs.
  1962. //!
  1963. //! \note The hibernate tamper feature is not available on all Tiva
  1964. //! devices. Please consult the data sheet for the Tiva device that you
  1965. //! are using to determine if this feature is available.
  1966. //!
  1967. //! \return None.
  1968. //
  1969. //*****************************************************************************
  1970. void
  1971. HibernateTamperIODisable(uint32_t ui32Input)
  1972. {
  1973. //
  1974. // Verify parameters.
  1975. //
  1976. ASSERT(ui32Input < 4);
  1977. //
  1978. // Unlock the tamper registers.
  1979. //
  1980. HWREG(HIB_LOCK) = HIB_LOCK_HIBLOCK_KEY;
  1981. _HibernateWriteComplete();
  1982. //
  1983. // Clear the I/O enable bit.
  1984. //
  1985. HWREG(HIB_TPIO) &= ((~HIB_TPIO_EN0) << (ui32Input << 3));
  1986. //
  1987. // Wait for write completion.
  1988. //
  1989. _HibernateWriteComplete();
  1990. //
  1991. // Lock the tamper registers.
  1992. //
  1993. HWREG(HIB_LOCK) = 0;
  1994. _HibernateWriteComplete();
  1995. }
  1996. //*****************************************************************************
  1997. //
  1998. //! Clears the tamper feature events.
  1999. //!
  2000. //! This function is used to clear all tamper events. This function always
  2001. //! clears the tamper feature event state indicator along with all tamper log
  2002. //! entries. Logged event data should be retrieved with
  2003. //! HibernateTamperEventsGet() prior to requesting a event clear.
  2004. //!
  2005. //! HibernateTamperEventsClear() should be called prior to clearing the system
  2006. //! control NMI that resulted from the tamper event.
  2007. //!
  2008. //! \note The hibernate tamper feature is not available on all Tiva
  2009. //! devices. Please consult the data sheet for the Tiva device that you
  2010. //! are using to determine if this feature is available.
  2011. //!
  2012. //! \return None.
  2013. //
  2014. //*****************************************************************************
  2015. void
  2016. HibernateTamperEventsClear(void)
  2017. {
  2018. //
  2019. // Unlock the tamper registers.
  2020. //
  2021. HWREG(HIB_LOCK) = HIB_LOCK_HIBLOCK_KEY;
  2022. _HibernateWriteComplete();
  2023. //
  2024. // Set the tamper event clear bit.
  2025. //
  2026. HWREG(HIB_TPCTL) |= HIB_TPCTL_TPCLR;
  2027. //
  2028. // Wait for write completion.
  2029. //
  2030. _HibernateWriteComplete();
  2031. //
  2032. // Lock the tamper registers.
  2033. //
  2034. HWREG(HIB_LOCK) = 0;
  2035. _HibernateWriteComplete();
  2036. }
  2037. //*****************************************************************************
  2038. //
  2039. //! Clears the tamper feature events without Unlock and Lock.
  2040. //!
  2041. //! This function is used to clear all tamper events without unlock/locking
  2042. //! the tamper control registers, so API HibernateTamperUnLock() should be
  2043. //! called before this function, and API HibernateTamperLock() should be
  2044. //! called after to ensure that tamper control registers are locked.
  2045. //!
  2046. //! This function doesn't block until the write is complete.
  2047. //! Therefore, care must be taken to ensure the next immediate write will
  2048. //! occure only after the write complete bit is set.
  2049. //!
  2050. //! This function is used to implement a software workaround in NMI interrupt
  2051. //! handler to fix an issue when a new tamper event could be missed during
  2052. //! the clear of current tamper event.
  2053. //!
  2054. //! \note The hibernate tamper feature is not available on all Tiva
  2055. //! devices. Please consult the data sheet for the Tiva device that you
  2056. //! are using to determine if this feature is available.
  2057. //!
  2058. //! \return None.
  2059. //
  2060. //*****************************************************************************
  2061. void
  2062. HibernateTamperEventsClearNoLock(void)
  2063. {
  2064. //
  2065. // Wait for write completion.
  2066. //
  2067. _HibernateWriteComplete();
  2068. //
  2069. // Set the tamper event clear bit.
  2070. //
  2071. HWREG(HIB_TPCTL) |= HIB_TPCTL_TPCLR;
  2072. }
  2073. //*****************************************************************************
  2074. //
  2075. //! Unlock temper registers.
  2076. //!
  2077. //! This function is used to unlock the temper control registers. This
  2078. //! function should be only used before calling API
  2079. //! HibernateTamperEventsClearNoLock().
  2080. //!
  2081. //! \note The hibernate tamper feature is not available on all Tiva
  2082. //! devices. Please consult the data sheet for the Tiva device that you
  2083. //! are using to determine if this feature is available.
  2084. //!
  2085. //! \return None.
  2086. //
  2087. //*****************************************************************************
  2088. void
  2089. HibernateTamperUnLock(void)
  2090. {
  2091. //
  2092. // Unlock the tamper registers.
  2093. //
  2094. HWREG(HIB_LOCK) = HIB_LOCK_HIBLOCK_KEY;
  2095. _HibernateWriteComplete();
  2096. }
  2097. //*****************************************************************************
  2098. //
  2099. //! Lock temper registers.
  2100. //!
  2101. //! This function is used to lock the temper control registers. This
  2102. //! function should be used after calling API
  2103. //! HibernateTamperEventsClearNoLock().
  2104. //!
  2105. //! \note The hibernate tamper feature is not available on all Tiva
  2106. //! devices. Please consult the data sheet for the Tiva device that you
  2107. //! are using to determine if this feature is available.
  2108. //!
  2109. //! \return None.
  2110. //
  2111. //*****************************************************************************
  2112. void
  2113. HibernateTamperLock(void)
  2114. {
  2115. //
  2116. // Wait for write completion.
  2117. //
  2118. _HibernateWriteComplete();
  2119. //
  2120. // Lock the tamper registers.
  2121. //
  2122. HWREG(HIB_LOCK) = 0;
  2123. _HibernateWriteComplete();
  2124. }
  2125. //*****************************************************************************
  2126. //
  2127. //! Returns the current tamper feature status.
  2128. //!
  2129. //! This function is used to return the tamper feature status. This function
  2130. //! returns one of the values from this group of options:
  2131. //!
  2132. //! - \b HIBERNATE_TAMPER_STATUS_INACTIVE indicates tamper detection is
  2133. //! disabled
  2134. //! - \b HIBERNATE_TAMPER_STATUS_ACTIVE indicates tamper detection is enabled
  2135. //! and ready
  2136. //! - \b HIBERNATE_TAMPER_STATUS_EVENT indicates tamper event was detected
  2137. //!
  2138. //! In addition, one of the values is included from this group:
  2139. //!
  2140. //! - \b HIBERNATE_TAMPER_STATUS_EXT_OSC_INACTIVE indicates the external
  2141. //! oscillator is not active
  2142. //! - \b HIBERNATE_TAMPER_STATUS_EXT_OSC_ACTIVE indicates the external
  2143. //! oscillator is active
  2144. //!
  2145. //! And one of the values is included from this group:
  2146. //!
  2147. //! - \b HIBERNATE_TAMPER_STATUS_EXT_OSC_FAILED indicates the external
  2148. //! oscillator signal has transitioned from valid to invalid
  2149. //! - \b HIBERNATE_TAMPER_STATUS_EXT_OSC_VALID indicates the external
  2150. //! oscillator is providing a valid signal
  2151. //!
  2152. //! \note The hibernate tamper feature is not available on all Tiva
  2153. //! devices. Please consult the data sheet for the Tiva device that you
  2154. //! are using to determine if this feature is available.
  2155. //!
  2156. //! \return Returns a combination of the \b HIBERNATE_TAMPER_STATUS_* values.
  2157. //
  2158. //*****************************************************************************
  2159. uint32_t
  2160. HibernateTamperStatusGet(void)
  2161. {
  2162. uint32_t ui32Status, ui32Reg;
  2163. //
  2164. // Retrieve the raw register value.
  2165. //
  2166. ui32Reg = HWREG(HIB_TPSTAT);
  2167. //
  2168. // Setup the oscillator status indicators.
  2169. //
  2170. ui32Status = (ui32Reg & (HIB_TPSTAT_XOSCST | HIB_TPSTAT_XOSCFAIL));
  2171. ui32Status |= ((ui32Reg & HIB_TPSTAT_XOSCST) ? 0 :
  2172. HIBERNATE_TAMPER_STATUS_EXT_OSC_ACTIVE);
  2173. ui32Status |= ((ui32Reg & HIB_TPSTAT_XOSCFAIL) ? 0 :
  2174. HIBERNATE_TAMPER_STATUS_EXT_OSC_VALID);
  2175. //
  2176. // Retrieve the tamper status indicators.
  2177. //
  2178. ui32Status |= ((ui32Reg & HIB_TPSTAT_STATE_M) << 3);
  2179. //
  2180. // The HW shows "disabled" with a zero value, use bit[0] as a flag
  2181. // for this purpose.
  2182. //
  2183. if((ui32Reg & HIB_TPSTAT_STATE_M) == 0)
  2184. {
  2185. ui32Status |= HIBERNATE_TAMPER_STATUS_INACTIVE;
  2186. }
  2187. //
  2188. // Return the API status flags.
  2189. //
  2190. return(ui32Status);
  2191. }
  2192. //*****************************************************************************
  2193. //
  2194. //! Returns a tamper log entry.
  2195. //!
  2196. //! \param ui32Index is the index of the log entry to return.
  2197. //! \param pui32RTC is a pointer to the memory to store the logged RTC data.
  2198. //! \param pui32Event is a pointer to the memory to store the logged tamper
  2199. //! event.
  2200. //!
  2201. //! This function is used to return a tamper log entry from the hibernate
  2202. //! feature. The \e ui32Index specifies the zero-based index of the log entry
  2203. //! to query and has a valid range of 0-3.
  2204. //!
  2205. //! When this function returns, the \e pui32RTC value contains the time value
  2206. //! and \e pui32Event parameter contains the tamper I/O event that triggered
  2207. //! this log.
  2208. //!
  2209. //! The format of the returned \e pui32RTC data is dependent on the
  2210. //! configuration of the RTC within the Hibernation module. If the RTC is
  2211. //! configured for counter mode, the returned data contains counted seconds
  2212. //! from the RTC enable. If the RTC is configured for calendar mode, the data
  2213. //! returned is formatted as follows:
  2214. //!
  2215. //! \verbatim
  2216. //! +----------------------------------------------------------------------+
  2217. //! | 31:26 | 25:22 | 21:17 | 16:12 | 11:6 | 5:0 |
  2218. //! +----------------------------------------------------------------------+
  2219. //! | year | month | day of month | hours | minutes | seconds |
  2220. //! +----------------------------------------------------------------------+
  2221. //! \endverbatim
  2222. //!
  2223. //! The data returned in the \e pui32Events parameter could include any of the
  2224. //! following flags:
  2225. //!
  2226. //! - \b HIBERNATE_TAMPER_EVENT_0 indicates a tamper event was triggered on I/O
  2227. //! signal 0
  2228. //! - \b HIBERNATE_TAMPER_EVENT_1 indicates a tamper event was triggered on I/O
  2229. //! signal 1
  2230. //! - \b HIBERNATE_TAMPER_EVENT_2 indicates a tamper event was triggered on I/O
  2231. //! signal 2
  2232. //! - \b HIBERNATE_TAMPER_EVENT_3 indicates a tamper event was triggered on I/O
  2233. //! signal 3
  2234. //! - \b HIBERNATE_TAMPER_EVENT_XOSC indicates an external oscillator failure
  2235. //! triggered the tamper event
  2236. //!
  2237. //! \note Tamper event logs are not consumed when read and remain available
  2238. //! until cleared. Events are only logged if unused log space is available.
  2239. //!
  2240. //! \note The hibernate tamper feature is not available on all Tiva
  2241. //! devices. Please consult the data sheet for the Tiva device that you
  2242. //! are using to determine if this feature is available.
  2243. //!
  2244. //! \return Returns \b true if the \e pui32RTC and \e pui32Events were updated
  2245. //! successfully and returns \b false if the values were not updated.
  2246. //
  2247. //*****************************************************************************
  2248. bool
  2249. HibernateTamperEventsGet(uint32_t ui32Index, uint32_t *pui32RTC,
  2250. uint32_t *pui32Event)
  2251. {
  2252. uint32_t ui32Reg;
  2253. //
  2254. // Verify parameters.
  2255. //
  2256. ASSERT(pui32RTC);
  2257. ASSERT(pui32Event);
  2258. ASSERT(ui32Index < 4);
  2259. //
  2260. // Retrieve the event log data for the requested index if available.
  2261. //
  2262. ui32Reg = HWREG(HIB_TPLOG0 + ((ui32Index << 3) + 4));
  2263. if(ui32Reg == 0)
  2264. {
  2265. //
  2266. // No event data is available for this index.
  2267. //
  2268. return(false);
  2269. }
  2270. //
  2271. // Store the event data in the provided location.
  2272. //
  2273. *pui32Event = ui32Reg;
  2274. //
  2275. // Retrieve the calendar information.
  2276. //
  2277. *pui32RTC = HWREG(HIB_TPLOG0 + (ui32Index << 3));
  2278. //
  2279. // Convert the hour to 24hr mode if the Calendar is enabled
  2280. // and in 24hr mode.
  2281. //
  2282. if((HWREG(HIB_CALCTL) & (HIB_CALCTL_CALEN | HIB_CALCTL_CAL24)) ==
  2283. (HIB_CALCTL_CALEN | HIB_CALCTL_CAL24))
  2284. {
  2285. if(HWREG(HIB_CAL0) & HIB_CAL0_AMPM)
  2286. {
  2287. //
  2288. // Add 12 hour since it is PM
  2289. //
  2290. ui32Reg = ((*pui32RTC & 0X0001f000) + (12<<12)) & 0X0001f000;
  2291. *pui32RTC &= ~0X0001f000;
  2292. *pui32RTC |= ui32Reg;
  2293. }
  2294. }
  2295. //
  2296. // Return success.
  2297. //
  2298. return(true);
  2299. }
  2300. //*****************************************************************************
  2301. //
  2302. //! Attempts to recover the external oscillator.
  2303. //!
  2304. //! This function is used to attempt to recover the external oscillator after a
  2305. //! \b HIBERNATE_TAMPER_STATUS_EXT_OSC_FAILED status is reported. This
  2306. //! function must not be called if the external oscillator is not used as
  2307. //! the hibernation clock input. HibernateTamperExtOscValid() should be called
  2308. //! before calling this function.
  2309. //!
  2310. //! \note The hibernate tamper feature is not available on all Tiva
  2311. //! devices. Please consult the data sheet for the Tiva device that you
  2312. //! are using to determine if this feature is available.
  2313. //!
  2314. //! \return None.
  2315. //
  2316. //*****************************************************************************
  2317. void
  2318. HibernateTamperExtOscRecover(void)
  2319. {
  2320. //
  2321. // Unlock the tamper registers.
  2322. //
  2323. HWREG(HIB_LOCK) = HIB_LOCK_HIBLOCK_KEY;
  2324. _HibernateWriteComplete();
  2325. //
  2326. // Set the XOSCFAIL clear bit.
  2327. //
  2328. HWREG(HIB_TPSTAT) |= HIB_TPSTAT_XOSCFAIL;
  2329. //
  2330. // Wait for write completion.
  2331. //
  2332. _HibernateWriteComplete();
  2333. //
  2334. // Lock the tamper registers.
  2335. //
  2336. HWREG(HIB_LOCK) = 0;
  2337. _HibernateWriteComplete();
  2338. }
  2339. //*****************************************************************************
  2340. //
  2341. //! Reports if the external oscillator signal is active and stable.
  2342. //!
  2343. //! This function should be used to verify the external oscillator is active
  2344. //! and valid before attempting to recover from a
  2345. //! \b HIBERNATE_TAMPER_STATUS_EXT_OSC_FAILED status by calling
  2346. //! HibernateTamperExtOscRecover().
  2347. //!
  2348. //! \note The hibernate tamper feature is not available on all Tiva
  2349. //! devices. Please consult the data sheet for the Tiva device that you
  2350. //! are using to determine if this feature is available.
  2351. //!
  2352. //! \return Returns \b true if the external oscillator is both active and
  2353. //! stable, otherwise a \b false indicator is returned.
  2354. //
  2355. //*****************************************************************************
  2356. bool
  2357. HibernateTamperExtOscValid(void)
  2358. {
  2359. if(HibernateTamperStatusGet() & (HIBERNATE_TAMPER_STATUS_EXT_OSC_ACTIVE |
  2360. HIBERNATE_TAMPER_STATUS_EXT_OSC_VALID))
  2361. {
  2362. return(true);
  2363. }
  2364. return(false);
  2365. }
  2366. //*****************************************************************************
  2367. //
  2368. // Close the Doxygen group.
  2369. //! @}
  2370. //
  2371. //*****************************************************************************