1
0

hibernate.c 82 KB

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