hibernate.c 81 KB

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