123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553 |
- //*****************************************************************************
- //
- // hibernate.c - Driver for the Hibernation module
- //
- // Copyright (c) 2007-2017 Texas Instruments Incorporated. All rights reserved.
- // Software License Agreement
- //
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions
- // are met:
- //
- // Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- //
- // Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the
- // distribution.
- //
- // Neither the name of Texas Instruments Incorporated nor the names of
- // its contributors may be used to endorse or promote products derived
- // from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- // This is part of revision 2.1.4.178 of the Tiva Peripheral Driver Library.
- //
- //*****************************************************************************
- //*****************************************************************************
- //
- //! \addtogroup hibernate_api
- //! @{
- //
- //*****************************************************************************
- #include <stdbool.h>
- #include <stdint.h>
- #include <time.h>
- #include "inc/hw_hibernate.h"
- #include "inc/hw_ints.h"
- #include "inc/hw_sysctl.h"
- #include "inc/hw_types.h"
- #include "driverlib/debug.h"
- #include "driverlib/hibernate.h"
- #include "driverlib/interrupt.h"
- #include "driverlib/sysctl.h"
- //*****************************************************************************
- //
- // The delay in microseconds for writing to the Hibernation module registers.
- //
- //*****************************************************************************
- #define DELAY_USECS 95
- //*****************************************************************************
- //
- // The number of processor cycles to execute one pass of the delay loop.
- //
- //*****************************************************************************
- #define LOOP_CYCLES 3
- //*****************************************************************************
- //
- // A macro used to determine whether the target part supports Wake from IO
- // pins.
- //
- //*****************************************************************************
- #define HIBERNATE_WAKE_IO CLASS_IS_TM4C129
- //*****************************************************************************
- //
- // A macro used to determine whether the target part supports Wake from IO
- // pins.
- //
- //*****************************************************************************
- #define HIBERNATE_CLOCK_OUTPUT CLASS_IS_TM4C129
- //*****************************************************************************
- //
- //! \internal
- //!
- //! Polls until the write complete (WRC) bit in the hibernate control register
- //! is set.
- //!
- //! \param None.
- //!
- //! The Hibernation module provides an indication when any write is completed.
- //! This mechanism is used to pace writes to the module. This function merely
- //! polls this bit and returns as soon as it is set. At this point, it is safe
- //! to perform another write to the module.
- //!
- //! \return None.
- //
- //*****************************************************************************
- static void
- _HibernateWriteComplete(void)
- {
- //
- // Spin until the write complete bit is set.
- //
- while(!(HWREG(HIB_CTL) & HIB_CTL_WRC))
- {
- }
- }
- //*****************************************************************************
- //
- //! Enables the Hibernation module for operation.
- //!
- //! \param ui32HibClk is the rate of the clock supplied to the Hibernation
- //! module.
- //!
- //! This function enables the Hibernation module for operation. This function
- //! should be called before any of the Hibernation module features are used.
- //!
- //! The peripheral clock is the same as the processor clock. The frequency of
- //! the system clock is the value returned by SysCtlClockGet() for TM4C123x
- //! devices or the value returned by SysCtlClockFreqSet() for TM4C129x devices,
- //! or it can be explicitly hard coded if it is constant and known (to save the
- //! code/execution overhead of a call to SysCtlClockGet() or fetch of the
- //! variable call holding the return value of SysCtlClockFreqSet()).
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateEnableExpClk(uint32_t ui32HibClk)
- {
- //
- // Turn on the clock enable bit.
- //
- HWREG(HIB_CTL) |= HIB_CTL_CLK32EN;
- //
- // Wait for write complete following register load (above).
- //
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Disables the Hibernation module for operation.
- //!
- //! This function disables the Hibernation module. After this function is
- //! called, none of the Hibernation module features are available.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateDisable(void)
- {
- //
- // Turn off the clock enable bit.
- //
- HWREG(HIB_CTL) &= ~HIB_CTL_CLK32EN;
- //
- // Wait for write completion
- //
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Configures the clock input for the Hibernation module.
- //!
- //! \param ui32Config is one of the possible configuration options for the
- //! clock input listed below.
- //!
- //! This function is used to configure the clock input for the Hibernation
- //! module. The \e ui32Config parameter can be one of the following values:
- //!
- //! - \b HIBERNATE_OSC_DISABLE specifies that the internal oscillator
- //! is powered off. This option is used when an externally supplied oscillator
- //! is connected to the XOSC0 pin or to save power when the LFIOSC is used in
- //! devices that have an LFIOSC in the Hibernation module.
- //! - \b HIBERNATE_OSC_HIGHDRIVE specifies a higher drive strength when a 24-pF
- //! filter capacitor is used with a crystal.
- //! - \b HIBERNATE_OSC_LOWDRIVE specifies a lower drive strength when a 12-pF
- //! filter capacitor is used with a crystal.
- //!
- //! On some devices, there is an option to use an internal low frequency
- //! oscillator (LFIOSC) as the clock source for the Hibernation module.
- //! Because of the low accuracy of this oscillator, this option should not be
- //! used when the system requires a real time counter. Adding the
- //! \b HIBERNATE_OSC_LFIOSC value enables the LFIOSC as the clock source to
- //! the Hibernation module.
- //!
- //! - \b HIBERNATE_OSC_LFIOSC enables the Hibernation module's internal low
- //! frequency oscillator as the clock to the Hibernation module.
- //!
- //! This \e ui32Config also configures how the clock output from the
- //! hibernation is used to clock other peripherals in the system. The ALT
- //! clock settings allow clocking a subset of the peripherals. See the
- //! hibernate section in the datasheet to determine which peripherals can be
- //! clocked by the ALT clock outputs from the Hibernation module.
- //! The \e ui32Config parameter can have any combination of the following
- //! values:
- //!
- //! - \b HIBERNATE_OUT_SYSCLK enables the hibernate clock output to the system
- //! clock.
- //!
- //! The \b HIBERNATE_OSC_DISABLE option is used to disable and power down the
- //! internal oscillator if an external clock source or no clock source is used
- //! instead of a 32.768-kHz crystal. In the case where an external crystal is
- //! used, either the \b HIBERNATE_OSC_HIGHDRIVE or \b HIBERNATE_OSC_LOWDRIVE is
- //! used. These settings optimizes the oscillator drive strength to match the
- //! size of the filter capacitor that is used with the external crystal
- //! circuit.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateClockConfig(uint32_t ui32Config)
- {
- uint32_t ui32HIBCtl;
- ASSERT((ui32Config & ~(HIBERNATE_OSC_HIGHDRIVE | HIBERNATE_OSC_LOWDRIVE |
- HIBERNATE_OSC_DISABLE)) == 0);
- ui32HIBCtl = HWREG(HIB_CTL);
- //
- // Clear the current configuration bits.
- //
- ui32HIBCtl &= ~(HIBERNATE_OSC_HIGHDRIVE | HIBERNATE_OSC_LOWDRIVE |
- HIBERNATE_OSC_LFIOSC | HIBERNATE_OSC_DISABLE);
- //
- // Set the new configuration bits.
- //
- ui32HIBCtl |= ui32Config & (HIBERNATE_OSC_HIGHDRIVE |
- HIBERNATE_OSC_LOWDRIVE |
- HIBERNATE_OSC_LFIOSC |
- HIBERNATE_OSC_DISABLE);
- //
- // Must be sure that the 32KHz clock is enabled if the hibernate is about
- // to switch to it.
- //
- if(ui32Config & HIBERNATE_OSC_LFIOSC)
- {
- ui32HIBCtl |= HIB_CTL_CLK32EN;
- }
- //
- // Set the hibernation clocking configuration.
- //
- HWREG(HIB_CTL) = ui32HIBCtl;
- //
- // Wait for write completion
- //
- _HibernateWriteComplete();
- //
- // Write the output clock configuration for devices that support
- // controlling the output clocks from the hibernate module.
- //
- if(HIBERNATE_CLOCK_OUTPUT)
- {
- HWREG(HIB_CC) = ui32Config & (HIBERNATE_OUT_SYSCLK |
- HIBERNATE_OUT_ALT1CLK);
- }
- }
- //*****************************************************************************
- //
- //! Enables the RTC feature of the Hibernation module.
- //!
- //! This function enables the RTC in the Hibernation module. The RTC can be
- //! used to wake the processor from hibernation at a certain time, or to
- //! generate interrupts at certain times. This function must be called before
- //! using any of the RTC features of the Hibernation module.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateRTCEnable(void)
- {
- //
- // Turn on the RTC enable bit.
- //
- HWREG(HIB_CTL) |= HIB_CTL_RTCEN;
- //
- // Wait for write completion
- //
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Disables the RTC feature of the Hibernation module.
- //!
- //! This function disables the RTC in the Hibernation module. After calling
- //! this function, the RTC features of the Hibernation module are not
- //! available.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateRTCDisable(void)
- {
- //
- // Turn off the RTC enable bit.
- //
- HWREG(HIB_CTL) &= ~HIB_CTL_RTCEN;
- //
- // Wait for write completion
- //
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Forces the Hibernation module to initiate a check of the battery voltage.
- //!
- //! This function forces the Hibernation module to initiate a check of the
- //! battery voltage immediately rather than waiting for the next check interval
- //! to pass. After calling this function, the application should call the
- //! HibernateBatCheckDone() function and wait for the function to return a zero
- //! value before calling the HibernateIntStatus() to check if the return code
- //! has the \b HIBERNATE_INT_LOW_BAT set. If \b HIBERNATE_INT_LOW_BAT is set,
- //! the battery level is low. The application can also enable the
- //! \b HIBERNATE_INT_LOW_BAT interrupt and wait for an interrupt to indicate
- //! that the battery level is low.
- //!
- //! \note A hibernation request is held off if a battery check is in progress.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateBatCheckStart(void)
- {
- //
- // Initiated a forced battery check.
- //
- HWREG(HIB_CTL) |= HIB_CTL_BATCHK;
- //
- // Wait for write completion
- //
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Determines whether or not a forced battery check has completed.
- //!
- //! This function determines whether the forced battery check initiated by a
- //! call to the HibernateBatCheckStart() function has completed. This function
- //! returns a non-zero value until the battery level check has completed. Once
- //! this function returns a value of zero, the Hibernation module has completed
- //! the battery check and the HibernateIntStatus() function can be used to
- //! check if the battery was low by checking if the value returned has the
- //! \b HIBERNATE_INT_LOW_BAT set.
- //!
- //! \return The value is zero when the battery level check has completed or
- //! non-zero if the check is still in process.
- //
- //*****************************************************************************
- uint32_t
- HibernateBatCheckDone(void)
- {
- //
- // Read the current state of the battery check.
- //
- return(HWREG(HIB_CTL) & HIB_CTL_BATCHK);
- }
- //*****************************************************************************
- //
- //! Configures the wake conditions for the Hibernation module.
- //!
- //! \param ui32WakeFlags specifies which conditions should be used for waking.
- //!
- //! This function enables the conditions under which the Hibernation module
- //! wakes. The \e ui32WakeFlags parameter is the logical OR of any combination
- //! of the following:
- //!
- //! - \b HIBERNATE_WAKE_PIN - wake when the external wake pin is asserted.
- //! - \b HIBERNATE_WAKE_RTC - wake when the RTC match occurs.
- //! - \b HIBERNATE_WAKE_LOW_BAT - wake from hibernate due to a low-battery
- //! level being detected.
- //! - \b HIBERNATE_WAKE_GPIO - wake when a GPIO pin is asserted.
- //! - \b HIBERNATE_WAKE_RESET - wake when a reset pin is asserted.
- //!
- //! If the \b HIBERNATE_WAKE_GPIO flag is set, then one of the GPIO
- //! configuration functions GPIOPinTypeWakeHigh() or GPIOPinTypeWakeLow() must
- //! be called to properly configure and enable a GPIO as a wake source for
- //! hibernation.
- //!
- //! \note The \b HIBERNATE_WAKE_GPIO and \b HIBERNATE_WAKE_RESET parameters are
- //! only available on some Tiva devices.
- //!
- //! \note On some Tiva devices a tamper event acts as a wake source for the
- //! Hibernation module. Refer the function \b HibernateTamperEventsConfig() to
- //! wake from hibernation on a tamper event.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateWakeSet(uint32_t ui32WakeFlags)
- {
- //
- // Check the arguments.
- //
- ASSERT(!(ui32WakeFlags & ~(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC |
- HIBERNATE_WAKE_GPIO | HIBERNATE_WAKE_RESET |
- HIBERNATE_WAKE_LOW_BAT)));
- //
- // Set the specified wake flags in the control register.
- //
- HWREG(HIB_CTL) = (ui32WakeFlags | (HWREG(HIB_CTL) &
- ~(HIBERNATE_WAKE_PIN |
- HIBERNATE_WAKE_RTC |
- HIBERNATE_WAKE_LOW_BAT)));
- //
- // Wait for write completion
- //
- _HibernateWriteComplete();
- //
- // Write the hibernate IO register if requested.
- //
- if(HIBERNATE_WAKE_IO)
- {
- //
- // If the reset or GPIOs are begin used as a wake source then the
- // the VDD3ON needs to be set to allow the pads to remained
- // powered.
- //
- if((ui32WakeFlags & (HIBERNATE_WAKE_RESET | HIBERNATE_WAKE_GPIO)) &&
- ((HWREG(HIB_CTL) & HIB_CTL_VDD3ON) == 0))
- {
- //
- // Make sure that VDD3ON mode is enabled so that the pads can
- // retain their state.
- //
- HWREG(HIB_CTL) |= HIB_CTL_VDD3ON;
- //
- // Wait for write completion
- //
- _HibernateWriteComplete();
- }
- //
- // Set the requested flags.
- //
- HWREG(HIB_IO) = (ui32WakeFlags >> 16) | HIB_IO_WUUNLK;
- //
- // Spin until the write complete bit is set.
- //
- while((HWREG(HIB_IO) & HIB_IO_IOWRC) == 0)
- {
- }
- //
- // Clear the write unlock bit.
- //
- HWREG(HIB_IO) &= ~HIB_IO_WUUNLK;
- }
- }
- //*****************************************************************************
- //
- //! Gets the currently configured wake conditions for the Hibernation module.
- //!
- //! This function returns the flags representing the wake configuration for the
- //! Hibernation module. The return value is a combination of the following
- //! flags:
- //!
- //! - \b HIBERNATE_WAKE_PIN - wake when the external wake pin is asserted
- //! - \b HIBERNATE_WAKE_RTC - wake when the RTC matches occurs
- //! - \b HIBERNATE_WAKE_LOW_BAT - wake from hibernation due to a low-battery
- //! level being detected
- //! - \b HIBERNATE_WAKE_GPIO - wake when a GPIO pin is asserted
- //! - \b HIBERNATE_WAKE_RESET - wake when a reset pin is asserted
- //!
- //! \note The \b HIBERNATE_WAKE_LOW_BAT, \b HIBERNATE_WAKE_GPIO, and
- //! \b HIBERNATE_WAKE_RESET parameters are only available on some Tiva devices.
- //!
- //! \note On some Tiva devices a tamper event acts as a wake source for the
- //! Hibernation module. Refer the function \b HibernateTamperEventsConfig() to
- //! wake from hibernation on a tamper event.
- //!
- //! \return Returns flags indicating the configured wake conditions.
- //
- //*****************************************************************************
- uint32_t
- HibernateWakeGet(void)
- {
- uint32_t ui32Ctrl;
- //
- // Read the wake bits from the control register and return those bits to
- // the caller.
- //
- if(HIBERNATE_WAKE_IO)
- {
- ui32Ctrl = HWREG(HIB_CTL);
- return((ui32Ctrl & (HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC |
- HIBERNATE_WAKE_LOW_BAT)) |
- ((HWREG(HIB_IO) << 16) & (HIBERNATE_WAKE_RESET |
- HIBERNATE_WAKE_GPIO)));
- }
- else
- {
- return(HWREG(HIB_CTL) & (HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC |
- HIBERNATE_WAKE_LOW_BAT));
- }
- }
- //*****************************************************************************
- //
- //! Configures the low-battery detection.
- //!
- //! \param ui32LowBatFlags specifies behavior of low-battery detection.
- //!
- //! This function enables the low-battery detection and whether hibernation is
- //! allowed if a low battery is detected. If low-battery detection is enabled,
- //! then a low-battery condition is indicated in the raw interrupt status
- //! register, which can be enabled to trigger an interrupt. Optionally,
- //! hibernation can be aborted if a low battery condition is detected.
- //!
- //! The \e ui32LowBatFlags parameter is one of the following values:
- //!
- //! - \b HIBERNATE_LOW_BAT_DETECT - detect a low-battery condition
- //! - \b HIBERNATE_LOW_BAT_ABORT - detect a low-battery condition and abort
- //! hibernation if low-battery is detected
- //!
- //! The other setting in the \e ui32LowBatFlags allows the caller to set one of
- //! the following voltage level trigger values :
- //!
- //! - \b HIBERNATE_LOW_BAT_1_9V - voltage low level is 1.9 V
- //! - \b HIBERNATE_LOW_BAT_2_1V - voltage low level is 2.1 V
- //! - \b HIBERNATE_LOW_BAT_2_3V - voltage low level is 2.3 V
- //! - \b HIBERNATE_LOW_BAT_2_5V - voltage low level is 2.5 V
- //!
- //! \b Example: Abort hibernate if the voltage level is below 2.1 V.
- //!
- //! \verbatim
- //! HibernateLowBatSet(HIBERNATE_LOW_BAT_ABORT | HIBERNATE_LOW_BAT_2_1V);
- //! \endverbatim
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateLowBatSet(uint32_t ui32LowBatFlags)
- {
- //
- // Check the arguments.
- //
- ASSERT(!(ui32LowBatFlags &
- ~(HIB_CTL_VBATSEL_M | HIBERNATE_LOW_BAT_ABORT)));
- //
- // Set the low-battery detect and abort bits in the control register,
- // according to the parameter.
- //
- HWREG(HIB_CTL) = (ui32LowBatFlags |
- (HWREG(HIB_CTL) & ~(HIB_CTL_VBATSEL_M |
- HIBERNATE_LOW_BAT_ABORT)));
- //
- // Wait for write completion
- //
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Gets the currently configured low-battery detection behavior.
- //!
- //! This function returns a value representing the currently configured low
- //! battery detection behavior.
- //!
- //! The return value is a combination of the values described in the
- //! HibernateLowBatSet() function.
- //!
- //! \return Returns a value indicating the configured low-battery detection.
- //
- //*****************************************************************************
- uint32_t
- HibernateLowBatGet(void)
- {
- //
- // Read the supported low bat bits from the control register and return
- // those bits to the caller.
- //
- return(HWREG(HIB_CTL) & (HIB_CTL_VBATSEL_M | HIBERNATE_LOW_BAT_ABORT));
- }
- //*****************************************************************************
- //
- //! Sets the value of the real time clock (RTC) counter.
- //!
- //! \param ui32RTCValue is the new value for the RTC.
- //!
- //! This function sets the value of the RTC. The RTC counter contains the
- //! count in seconds when a 32.768kHz clock source is in use. The RTC must be
- //! enabled by calling HibernateRTCEnable() before calling this function.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateRTCSet(uint32_t ui32RTCValue)
- {
- //
- // Load register requires unlock.
- //
- HWREG(HIB_LOCK) = HIB_LOCK_HIBLOCK_KEY;
- _HibernateWriteComplete();
- //
- // Write the new RTC value to the RTC load register.
- //
- HWREG(HIB_RTCLD) = ui32RTCValue;
- //
- // Wait for write completion
- //
- _HibernateWriteComplete();
- //
- // Unlock.
- //
- HWREG(HIB_LOCK) = 0;
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Gets the value of the real time clock (RTC) counter.
- //!
- //! This function gets the value of the RTC and returns it to the caller.
- //!
- //! \return Returns the value of the RTC counter in seconds.
- //
- //*****************************************************************************
- uint32_t
- HibernateRTCGet(void)
- {
- //
- // Return the value of the RTC counter register to the caller.
- //
- return(HWREG(HIB_RTCC));
- }
- //*****************************************************************************
- //
- //! Sets the value of the RTC match register.
- //!
- //! \param ui32Match is the index of the match register.
- //! \param ui32Value is the value for the match register.
- //!
- //! This function sets a match register for the RTC. The Hibernation
- //! module can be configured to wake from hibernation, and/or generate an
- //! interrupt when the value of the RTC counter is the same as the match
- //! register.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateRTCMatchSet(uint32_t ui32Match, uint32_t ui32Value)
- {
- ASSERT(ui32Match == 0);
- //
- // Write the new match value to the match register.
- //
- HWREG(HIB_RTCM0) = ui32Value;
- //
- // Wait for write completion
- //
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Gets the value of the requested RTC match register.
- //!
- //! \param ui32Match is the index of the match register.
- //!
- //! This function gets the value of the match register for the RTC. The only
- //! value that can be used with the \e ui32Match parameter is zero, other
- //! values are reserved for future use.
- //!
- //! \return Returns the value of the requested match register.
- //
- //*****************************************************************************
- uint32_t
- HibernateRTCMatchGet(uint32_t ui32Match)
- {
- ASSERT(ui32Match == 0);
- //
- // Return the value of the match register to the caller.
- //
- return(HWREG(HIB_RTCM0));
- }
- //*****************************************************************************
- //
- //! Sets the value of the RTC sub second match register.
- //!
- //! \param ui32Match is the index of the match register.
- //! \param ui32Value is the value for the sub second match register.
- //!
- //! This function sets the sub second match register for the RTC in 1/32768
- //! of a second increments. The Hibernation module can be configured to wake
- //! from hibernation, and/or generate an interrupt when the value of the RTC
- //! counter is the same as the match combined with the sub second match
- //! register. The only value that can be used with the \e ui32Match
- //! parameter is zero, other values are reserved for future use.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateRTCSSMatchSet(uint32_t ui32Match, uint32_t ui32Value)
- {
- ASSERT(ui32Match == 0);
- //
- // Write the new sub second match value to the sub second match register.
- //
- HWREG(HIB_RTCSS) = ui32Value << HIB_RTCSS_RTCSSM_S;
- //
- // Wait for write complete to be signaled on later devices.
- //
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Returns the value of the requested RTC sub second match register.
- //!
- //! \param ui32Match is the index of the match register.
- //!
- //! This function returns the current value of the sub second match register
- //! for the RTC. The value returned is in 1/32768 second increments. The only
- //! value that can be used with the \e ui32Match parameter is zero, other
- //! values are reserved for future use.
- //!
- //! \return Returns the value of the requested sub section match register.
- //
- //*****************************************************************************
- uint32_t
- HibernateRTCSSMatchGet(uint32_t ui32Match)
- {
- ASSERT(ui32Match == 0);
- //
- // Read the current second RTC count.
- //
- return(HWREG(HIB_RTCSS) >> HIB_RTCSS_RTCSSM_S);
- }
- //*****************************************************************************
- //
- //! Returns the current value of the RTC sub second count.
- //!
- //! This function returns the current value of the sub second count for the RTC
- //! in 1/32768 of a second increments. The only value that can be used with
- //! the \e ui32Match parameter is zero, other values are reserved for future
- //! use.
- //!
- //! \return The current RTC sub second count in 1/32768 seconds.
- //
- //*****************************************************************************
- uint32_t
- HibernateRTCSSGet(void)
- {
- //
- // Read the current second RTC count.
- //
- return(HWREG(HIB_RTCSS) & HIB_RTCSS_RTCSSC_M);
- }
- //*****************************************************************************
- //
- //! Sets the value of the RTC pre-divider trim register.
- //!
- //! \param ui32Trim is the new value for the pre-divider trim register.
- //!
- //! This function sets the value of the pre-divider trim register. The input
- //! time source is divided by the pre-divider to achieve a one-second clock
- //! rate. Once every 64 seconds, the value of the pre-divider trim register is
- //! applied to the pre-divider to allow fine-tuning of the RTC rate, in order
- //! to make corrections to the rate. The software application can make
- //! adjustments to the pre-divider trim register to account for variations in
- //! the accuracy of the input time source. The nominal value is 0x7FFF, and it
- //! can be adjusted up or down in order to fine-tune the RTC rate.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateRTCTrimSet(uint32_t ui32Trim)
- {
- //
- // Check the arguments.
- //
- ASSERT(ui32Trim < 0x10000);
- //
- // Write the new trim value to the trim register.
- //
- HWREG(HIB_RTCT) = ui32Trim;
- //
- // Wait for write completion
- //
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Gets the value of the RTC pre-divider trim register.
- //!
- //! This function gets the value of the pre-divider trim register. This
- //! function can be used to get the current value of the trim register prior
- //! to making an adjustment by using the HibernateRTCTrimSet() function.
- //!
- //! \return None.
- //
- //*****************************************************************************
- uint32_t
- HibernateRTCTrimGet(void)
- {
- //
- // Return the value of the trim register to the caller.
- //
- return(HWREG(HIB_RTCT));
- }
- //*****************************************************************************
- //
- //! Stores data in the battery-backed memory of the Hibernation module.
- //!
- //! \param pui32Data points to the data that the caller wants to store in the
- //! memory of the Hibernation module.
- //! \param ui32Count is the count of 32-bit words to store.
- //!
- //! Stores a set of data in the Hibernation module battery-backed memory.
- //! This memory is preserved when the power to the processor is turned off
- //! and can be used to store application state information that is needed when
- //! the processor wakes. Up to 16 32-bit words can be stored in the
- //! battery-backed memory. The data can be restored by calling the
- //! HibernateDataGet() function.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateDataSet(uint32_t *pui32Data, uint32_t ui32Count)
- {
- uint32_t ui32Idx;
- //
- // Check the arguments.
- //
- ASSERT(ui32Count <= 64);
- ASSERT(pui32Data != 0);
- //
- // Loop through all the words to be stored, storing one at a time.
- //
- for(ui32Idx = 0; ui32Idx < ui32Count; ui32Idx++)
- {
- //
- // Write a word to the battery-backed storage area.
- //
- HWREG(HIB_DATA + (ui32Idx * 4)) = pui32Data[ui32Idx];
- //
- // Wait for write completion
- //
- _HibernateWriteComplete();
- }
- }
- //*****************************************************************************
- //
- //! Reads a set of data from the battery-backed memory of the Hibernation
- //! module.
- //!
- //! \param pui32Data points to a location where the data that is read from the
- //! Hibernation module is stored.
- //! \param ui32Count is the count of 32-bit words to read.
- //!
- //! This function retrieves a set of data from the Hibernation module
- //! battery-backed memory that was previously stored with the
- //! HibernateDataSet() function. The caller must ensure that \e pui32Data
- //! points to a large enough memory block to hold all the data that is read
- //! from the battery-backed memory.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateDataGet(uint32_t *pui32Data, uint32_t ui32Count)
- {
- uint32_t ui32Idx;
- //
- // Check the arguments.
- //
- ASSERT(ui32Count <= 64);
- ASSERT(pui32Data != 0);
- //
- // Loop through all the words to be restored, reading one at a time.
- //
- for(ui32Idx = 0; ui32Idx < ui32Count; ui32Idx++)
- {
- //
- // Read a word from the battery-backed storage area. No delay is
- // required between reads.
- //
- pui32Data[ui32Idx] = HWREG(HIB_DATA + (ui32Idx * 4));
- }
- }
- //*****************************************************************************
- //
- //! Requests hibernation mode.
- //!
- //! This function requests the Hibernation module to disable the external
- //! regulator, thus removing power from the processor and all peripherals. The
- //! Hibernation module remains powered from the battery or auxiliary power
- //! supply.
- //!
- //! The Hibernation module re-enables the external regulator when one of
- //! the configured wake conditions occurs (such as RTC match or external
- //! \b WAKE pin). When the power is restored, the processor goes through a
- //! power-on reset although the Hibernation module is not reset. The processor
- //! can retrieve saved state information with the HibernateDataGet() function.
- //! Prior to calling the function to request hibernation mode, the conditions
- //! for waking must have already been set by using the HibernateWakeSet()
- //! function.
- //!
- //! Note that this function may return because some time may elapse before the
- //! power is actually removed, or it may not be removed at all. For this
- //! reason, the processor continues to execute instructions for some time,
- //! and the caller should be prepared for this function to return. There are
- //! various reasons why the power may not be removed. For example, if the
- //! HibernateLowBatSet() function was used to configure an abort if low
- //! battery is detected, then the power is not removed if the battery
- //! voltage is too low. There may be other reasons related to the external
- //! circuit design, that a request for hibernation may not actually occur.
- //!
- //! For all these reasons, the caller must be prepared for this function to
- //! return. The simplest way to handle it is to just enter an infinite loop
- //! and wait for the power to be removed.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateRequest(void)
- {
- //
- // Set the bit in the control register to cut main power to the processor.
- //
- HWREG(HIB_CTL) |= HIB_CTL_HIBREQ;
- //
- // Wait for write completion
- //
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Enables interrupts for the Hibernation module.
- //!
- //! \param ui32IntFlags is the bit mask of the interrupts to be enabled.
- //!
- //! This function enables the specified interrupt sources from the Hibernation
- //! module.
- //!
- //! The \e ui32IntFlags parameter must be the logical OR of any combination of
- //! the following:
- //!
- //! - \b HIBERNATE_INT_WR_COMPLETE - write complete interrupt
- //! - \b HIBERNATE_INT_PIN_WAKE - wake from pin interrupt
- //! - \b HIBERNATE_INT_LOW_BAT - low-battery interrupt
- //! - \b HIBERNATE_INT_RTC_MATCH_0 - RTC match 0 interrupt
- //! - \b HIBERNATE_INT_VDDFAIL - supply failure interrupt.
- //! - \b HIBERNATE_INT_RESET_WAKE - wake from reset pin interrupt
- //! - \b HIBERNATE_INT_GPIO_WAKE - wake from GPIO pin or reset pin interrupt.
- //!
- //! \note The \b HIBERNATE_INT_RESET_WAKE, \b HIBERNATE_INT_GPIO_WAKE, and
- //! \b HIBERNATE_INT_VDDFAIL settings are not available on all Tiva devices.
- //! Please consult the data sheet for the Tiva device that you are using to
- //! determine if these interrupt sources are available.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateIntEnable(uint32_t ui32IntFlags)
- {
- //
- // Check the arguments.
- //
- ASSERT(!(ui32IntFlags & ~(HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_LOW_BAT |
- HIBERNATE_INT_VDDFAIL |
- HIBERNATE_INT_RESET_WAKE |
- HIBERNATE_INT_GPIO_WAKE |
- HIBERNATE_INT_RTC_MATCH_0 |
- HIBERNATE_INT_WR_COMPLETE)));
- //
- // Set the specified interrupt mask bits.
- //
- HWREG(HIB_IM) |= ui32IntFlags;
- //
- // Wait for write completion
- //
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Disables interrupts for the Hibernation module.
- //!
- //! \param ui32IntFlags is the bit mask of the interrupts to be disabled.
- //!
- //! This function disables the specified interrupt sources from the
- //! Hibernation module.
- //!
- //! The \e ui32IntFlags parameter has the same definition as the
- //! \e ui32IntFlags parameter to the HibernateIntEnable() function.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateIntDisable(uint32_t ui32IntFlags)
- {
- //
- // Check the arguments.
- //
- ASSERT(!(ui32IntFlags & ~(HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_LOW_BAT |
- HIBERNATE_INT_VDDFAIL |
- HIBERNATE_INT_RESET_WAKE |
- HIBERNATE_INT_GPIO_WAKE |
- HIBERNATE_INT_RTC_MATCH_0 |
- HIBERNATE_INT_WR_COMPLETE)));
- //
- // Clear the specified interrupt mask bits.
- //
- HWREG(HIB_IM) &= ~ui32IntFlags;
- //
- // Wait for write completion
- //
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Returns the hibernate module interrupt number.
- //!
- //! This function returns the interrupt number for the hibernate module.
- //!
- //! \return Returns a hibernate interrupt number or 0 if the interrupt does not
- //! exist.
- //
- //*****************************************************************************
- static uint32_t
- _HibernateIntNumberGet(void)
- {
- uint32_t ui32Int;
- //
- // Find the valid interrupt number for the hibernate module.
- //
- if(CLASS_IS_TM4C129)
- {
- ui32Int = INT_HIBERNATE_TM4C129;
- }
- else
- {
- ui32Int = INT_HIBERNATE_TM4C123;
- }
- return(ui32Int);
- }
- //*****************************************************************************
- //
- //! Registers an interrupt handler for the Hibernation module interrupt.
- //!
- //! \param pfnHandler points to the function to be called when a hibernation
- //! interrupt occurs.
- //!
- //! This function registers the interrupt handler in the system interrupt
- //! controller. The interrupt is enabled at the global level, but individual
- //! interrupt sources must still be enabled with a call to
- //! HibernateIntEnable().
- //!
- //! \sa IntRegister() for important information about registering interrupt
- //! handlers.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateIntRegister(void (*pfnHandler)(void))
- {
- uint32_t ui32Int;
- //
- // Get the interrupt number for the Hibernate module.
- //
- ui32Int = _HibernateIntNumberGet();
- ASSERT(ui32Int != 0);
- //
- // Register the interrupt handler.
- //
- IntRegister(ui32Int, pfnHandler);
- //
- // Enable the hibernate module interrupt.
- //
- IntEnable(ui32Int);
- }
- //*****************************************************************************
- //
- //! Unregisters an interrupt handler for the Hibernation module interrupt.
- //!
- //! This function unregisters the interrupt handler in the system interrupt
- //! controller. The interrupt is disabled at the global level, and the
- //! interrupt handler is no longer called.
- //!
- //! \sa IntRegister() for important information about registering interrupt
- //! handlers.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateIntUnregister(void)
- {
- uint32_t ui32Int;
- //
- // Get the interrupt number for the Hibernate module.
- //
- ui32Int = _HibernateIntNumberGet();
- ASSERT(ui32Int != 0);
- //
- // Disable the hibernate interrupt.
- //
- IntDisable(ui32Int);
- //
- // Unregister the interrupt handler.
- //
- IntUnregister(ui32Int);
- }
- //*****************************************************************************
- //
- //! Gets the current interrupt status of the Hibernation module.
- //!
- //! \param bMasked is false to retrieve the raw interrupt status, and true to
- //! retrieve the masked interrupt status.
- //!
- //! This function returns the interrupt status of the Hibernation module. The
- //! caller can use this function to determine the cause of a hibernation
- //! interrupt. Either the masked or raw interrupt status can be returned.
- //!
- //! \note A wake from reset pin also signals a wake from GPIO pin with the
- //! value returned being HIBERNATE_INT_GPIO_WAKE | HIBERNATE_INT_RESET_WAKE.
- //! Hence a wake from reset pin should take priority over wake from GPIO pin.
- //!
- //! \return Returns the interrupt status as a bit field with the values as
- //! described in the HibernateIntEnable() function.
- //
- //*****************************************************************************
- uint32_t
- HibernateIntStatus(bool bMasked)
- {
- //
- // Read and return the Hibernation module raw or masked interrupt status.
- //
- if(bMasked == true)
- {
- return(HWREG(HIB_MIS));
- }
- else
- {
- return(HWREG(HIB_RIS));
- }
- }
- //*****************************************************************************
- //
- //! Clears pending interrupts from the Hibernation module.
- //!
- //! \param ui32IntFlags is the bit mask of the interrupts to be cleared.
- //!
- //! This function clears the specified interrupt sources. This function must
- //! be called within the interrupt handler or else the handler is called again
- //! upon exit.
- //!
- //! The \e ui32IntFlags parameter has the same definition as the
- //! \e ui32IntFlags parameter to the HibernateIntEnable() function.
- //!
- //! \note Because there is a write buffer in the Cortex-M processor, it may
- //! take several clock cycles before the interrupt source is actually cleared.
- //! Therefore, it is recommended that the interrupt source be cleared early in
- //! the interrupt handler (as opposed to the very last action) to avoid
- //! returning from the interrupt handler before the interrupt source is
- //! actually cleared. Failure to do so may result in the interrupt handler
- //! being immediately reentered (because the interrupt controller still sees
- //! the interrupt source asserted).
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateIntClear(uint32_t ui32IntFlags)
- {
- //
- // Check the arguments.
- //
- ASSERT(!(ui32IntFlags & ~(HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_LOW_BAT |
- HIBERNATE_INT_VDDFAIL |
- HIBERNATE_INT_RESET_WAKE |
- HIBERNATE_INT_GPIO_WAKE |
- HIBERNATE_INT_RTC_MATCH_0 |
- HIBERNATE_INT_WR_COMPLETE)));
- //
- // Write the specified interrupt bits into the interrupt clear register.
- //
- HWREG(HIB_IC) |= ui32IntFlags;
- //
- // Wait for write completion
- //
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Checks to see if the Hibernation module is already powered up.
- //!
- //! This function queries the control register to determine if the module is
- //! already active. This function can be called at a power-on reset to help
- //! determine if the reset is due to a wake from hibernation or a cold start.
- //! If the Hibernation module is already active, then it does not need to be
- //! re-enabled, and its status can be queried immediately.
- //!
- //! The software application should also use the HibernateIntStatus() function
- //! to read the raw interrupt status to determine the cause of the wake. The
- //! HibernateDataGet() function can be used to restore state. These
- //! combinations of functions can be used by the software to determine if the
- //! processor is waking from hibernation and the appropriate action to take as
- //! a result.
- //!
- //! \return Returns \b true if the module is already active, and \b false if
- //! not.
- //
- //*****************************************************************************
- uint32_t
- HibernateIsActive(void)
- {
- //
- // Read the control register, and return true if the module is enabled.
- //
- return(HWREG(HIB_CTL) & HIB_CTL_CLK32EN ? 1 : 0);
- }
- //*****************************************************************************
- //
- //! Enables GPIO retention after wake from hibernation.
- //!
- //! This function enables the GPIO pin state to be maintained during
- //! hibernation and remain active even when waking from hibernation. The GPIO
- //! module itself is reset upon entering hibernation and no longer controls the
- //! output pins. To maintain the current output level after waking from
- //! hibernation, the GPIO module must be reconfigured and then the
- //! HibernateGPIORetentionDisable() function must be called to return control
- //! of the GPIO pin to the GPIO module.
- //!
- //! \note The hibernation GPIO retention setting is not available on all
- //! Tiva devices. Please consult the data sheet to determine if the
- //! device you are using supports this feature in the Hibernation module.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateGPIORetentionEnable(void)
- {
- //
- // Enable power to the pads and enable GPIO retention during hibernate.
- //
- HWREG(HIB_CTL) |= HIB_CTL_VDD3ON | HIB_CTL_RETCLR;
- //
- // Wait for write completion
- //
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Disables GPIO retention after wake from hibernation.
- //!
- //! This function disables the retention of the GPIO pin state during
- //! hibernation and allows the GPIO pins to be controlled by the system. If
- //! the HibernateGPIORetentionEnable() function is called before entering
- //! hibernation, this function must be called after returning from hibernation
- //! to allow the GPIO pins to be controlled by GPIO module.
- //!
- //! \note The hibernate GPIO retention setting is not available on all
- //! Tiva devices. Please consult the data sheet to determine if the
- //! device you are using supports this feature in the Hibernation module.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateGPIORetentionDisable(void)
- {
- //
- // Reset the GPIO configuration after waking from hibernate and disable
- // the hibernate power to the pads.
- //
- HWREG(HIB_CTL) &= ~(HIB_CTL_RETCLR | HIB_CTL_VDD3ON);
- //
- // Wait for write completion
- //
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Returns the current setting for GPIO retention.
- //!
- //! This function returns the current setting for GPIO retention in the
- //! hibernate module.
- //!
- //! \note The hibernation GPIO retention setting is not available on all
- //! Tiva devices. Please consult the data sheet to determine if the
- //! device you are using supports this feature in the Hibernation module.
- //!
- //! \return Returns true if GPIO retention is enabled and false if GPIO
- //! retention is disabled.
- //
- //*****************************************************************************
- bool
- HibernateGPIORetentionGet(void)
- {
- //
- // Read the current GPIO retention configuration.
- //
- if((HWREG(HIB_CTL) & (HIB_CTL_RETCLR | HIB_CTL_VDD3ON)) ==
- (HIB_CTL_RETCLR | HIB_CTL_VDD3ON))
- {
- return(true);
- }
- return(false);
- }
- //*****************************************************************************
- //
- //! Configures the Hibernation module's internal counter mode.
- //!
- //! \param ui32Config is the configuration to use for the Hibernation module's
- //! counter.
- //!
- //! This function configures the Hibernate module's counter mode to operate
- //! as a standard RTC counter or to operate in a calendar mode. The
- //! \e ui32Config parameter is used to provide the configuration for
- //! the counter and must include only one of the following values:
- //!
- //! - \b HIBERNATE_COUNTER_24HR specifies 24-hour calendar mode.
- //! - \b HIBERNATE_COUNTER_12HR specifies 12-hour AM/PM calendar mode.
- //! - \b HIBERNATE_COUNTER_RTC specifies RTC counter mode.
- //!
- //! The HibernateCalendar functions can only be called when either
- //! \b HIBERNATE_COUNTER_24HR or \b HIBERNATE_COUNTER_12HR is specified.
- //!
- //! \b Example: Configure hibernate counter to 24-hour calendar mode.
- //!
- //! \verbatim
- //!
- //! //
- //! // Configure the hibernate module counter to 24-hour calendar mode.
- //! //
- //! HibernateCounterMode(HIBERNATE_COUNTER_24HR);
- //!
- //! \endverbatim
- //!
- //! \note The hibernate calendar mode is not available on all Tiva
- //! devices. Please consult the data sheet to determine if the device you are
- //! using supports this feature in the Hibernation module.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateCounterMode(uint32_t ui32Config)
- {
- //
- // Set the requested configuration.
- //
- HWREG(HIB_CALCTL) = ui32Config;
- //
- // Wait for write completion
- //
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- // Internal function to parse the time structure to set the calendar fields.
- //
- //*****************************************************************************
- static void
- _HibernateCalendarSet(uint32_t ui32Reg, struct tm *psTime)
- {
- uint32_t ui32Time, ui32Date;
- ASSERT(HWREG(HIB_CALCTL) & HIB_CALCTL_CALEN);
- //
- // Minutes and seconds are consistent in all modes.
- //
- ui32Time = (((psTime->tm_min << HIB_CALLD0_MIN_S) & HIB_CALLD0_MIN_M) |
- ((psTime->tm_sec << HIB_CALLD0_SEC_S) & HIB_CALLD0_SEC_M));
- //
- // 24 Hour time is used directly for Calendar set.
- //
- if(HWREG(HIB_CALCTL) & HIB_CALCTL_CAL24)
- {
- ui32Time |= (psTime->tm_hour << HIB_CALLD0_HR_S);
- //
- // for Calendar match, if it is every hour, AMPM bit should be clear
- //
- if((ui32Reg == HIB_CALM0) && (psTime->tm_hour == 0xFF) )
- {
- //
- // clear AMPM bit
- //
- ui32Time &= ~HIB_CAL0_AMPM;
- }
- }
- else
- {
- //
- // In AM/PM time hours have to be capped at 12.
- // If the hours are all 1s, it means the match for the hour is
- // always true. We need to set 1F in the hw field.
- //
- if(psTime->tm_hour == 0xFF)
- {
- //
- // Match every hour.
- //
- ui32Time |= HIB_CALLD0_HR_M;
- }
- else if(psTime->tm_hour >= 12)
- {
- //
- // Need to set the PM bit if it is noon or later.
- //
- ui32Time |= (((psTime->tm_hour - 12) << HIB_CALLD0_HR_S) |
- HIB_CAL0_AMPM);
- }
- else
- {
- //
- // All other times are normal and AM.
- //
- ui32Time |= (psTime->tm_hour << HIB_CALLD0_HR_S);
- }
- }
- //
- // Create the date in the correct register format.
- //
- if(ui32Reg == HIB_CAL0)
- {
- //
- // We must add 1 to the month, since the time structure lists
- // the month from 0 to 11 and the HIB lists it from 1 to 12.
- //
- ui32Date = ((psTime->tm_mday << HIB_CAL1_DOM_S) |
- ((psTime->tm_mon + 1) << HIB_CAL1_MON_S) |
- (psTime->tm_wday << HIB_CAL1_DOW_S) |
- ((psTime->tm_year - 100) << HIB_CAL1_YEAR_S));
- }
- else
- {
- //
- // Wday, month and year are not included in the match
- // Functionality.
- //
- if(psTime->tm_mday == 0xFF)
- {
- //
- // program 0 to match every day
- //
- ui32Date = 0 << HIB_CAL1_DOM_M;
- }
- else
- {
- ui32Date = (psTime->tm_mday << HIB_CAL1_DOM_S);
- }
- }
- //
- // Load register requires unlock.
- //
- if(ui32Reg == HIB_CAL0)
- {
- //
- // Unlock the hibernate counter load registers.
- //
- HWREG(HIB_LOCK) = HIB_LOCK_HIBLOCK_KEY;
- _HibernateWriteComplete();
- }
- //
- // Set the requested time and date.
- //
- if(ui32Reg == HIB_CAL0)
- {
- HWREG(HIB_CALLD0) = ui32Time;
- _HibernateWriteComplete();
- HWREG(HIB_CALLD1) = ui32Date;
- _HibernateWriteComplete();
- }
- else
- {
- HWREG(HIB_CALM0) = ui32Time;
- _HibernateWriteComplete();
- HWREG(HIB_CALM1) = ui32Date;
- _HibernateWriteComplete();
- }
- //
- // Load register requires unlock.
- //
- if(ui32Reg == HIB_CAL0)
- {
- //
- // Lock the hibernate counter load registers.
- //
- HWREG(HIB_LOCK) = 0;
- _HibernateWriteComplete();
- }
- }
- //*****************************************************************************
- //
- //! Sets the Hibernation module's date and time in calendar mode.
- //!
- //! \param psTime is the structure that holds the information for the current
- //! date and time.
- //!
- //! This function uses the \e psTime parameter to set the current date and
- //! time when the Hibernation module is in calendar mode. Regardless of
- //! whether 24-hour or 12-hour mode is in use, the \e psTime structure uses a
- //! 24-hour representation of the time. This function can only be called when
- //! the hibernate counter is configured in calendar mode using the
- //! HibernateCounterMode() function with one of the calendar modes.
- //!
- //! \note The hibernate calendar mode is not available on all Tiva
- //! devices. Please consult the data sheet to determine if the device you are
- //! using supports this feature in the Hibernation module.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateCalendarSet(struct tm *psTime)
- {
- //
- // Load a new date/time.
- //
- _HibernateCalendarSet(HIB_CAL0, psTime);
- }
- //*****************************************************************************
- //
- //! Returns the Hibernation module's date and time in calendar mode.
- //!
- //! \param psTime is the structure that is filled with the current date and
- //! time.
- //!
- //! This function returns the current date and time in the structure provided
- //! by the \e psTime parameter. Regardless of the calendar mode, the
- //! \e psTime parameter uses a 24-hour representation of the time. This
- //! function can only be called when the Hibernation module is configured in
- //! calendar mode using the HibernateCounterMode() function with one of the
- //! calendar modes.
- //!
- //! The only case where this function fails and returns a non-zero value is
- //! when the function detects that the counter is passing from the last second
- //! of the day to the first second of the next day. This exception must be
- //! handled in the application by waiting at least one second before calling
- //! again to get the updated calendar information.
- //!
- //! \note The hibernate calendar mode is not available on all Tiva
- //! devices. Please consult the data sheet to determine if the device you are
- //! using supports this feature in the Hibernation module.
- //!
- //! \return Returns zero if the time and date were read successfully and
- //! returns a non-zero value if the \e psTime structure was not updated.
- //
- //*****************************************************************************
- int
- HibernateCalendarGet(struct tm *psTime)
- {
- uint32_t ui32Date, ui32Time;
- ASSERT(HWREG(HIB_CALCTL) & HIB_CALCTL_CALEN);
- //
- // Wait for the value to be valid, this should never be more than a few
- // loops and should never hang.
- //
- do
- {
- ui32Date = HWREG(HIB_CAL1);
- }
- while((ui32Date & HIB_CAL1_VALID) == 0);
- //
- // Wait for the value to be valid, this should never be more than a few
- // loops and should never hang.
- //
- do
- {
- ui32Time = HWREG(HIB_CAL0);
- }
- while((ui32Time & HIB_CAL0_VALID) == 0);
- //
- // The date changed after reading the time so fail this call and let the
- // application call again since it knows how int32_t to wait until another
- // second passes.
- //
- if(ui32Date != HWREG(HIB_CAL1))
- {
- return(-1);
- }
- //
- // Populate the date and time fields in the psTime structure.
- // We must subtract 1 from the month, since the time structure lists
- // the month from 0 to 11 and the HIB lists it from 1 to 12.
- //
- psTime->tm_min = (ui32Time & HIB_CAL0_MIN_M) >> HIB_CAL0_MIN_S;
- psTime->tm_sec = (ui32Time & HIB_CAL0_SEC_M) >> HIB_CAL0_SEC_S;
- psTime->tm_mon = (((ui32Date & HIB_CAL1_MON_M) >> HIB_CAL1_MON_S) - 1);
- psTime->tm_mday = (ui32Date & HIB_CAL1_DOM_M) >> HIB_CAL1_DOM_S;
- psTime->tm_wday = (ui32Date & HIB_CAL1_DOW_M) >> HIB_CAL1_DOW_S;
- psTime->tm_year = ((ui32Date & HIB_CAL1_YEAR_M) >> HIB_CAL1_YEAR_S) + 100;
- psTime->tm_hour = (ui32Time & HIB_CAL0_HR_M) >> HIB_CAL0_HR_S;
- //
- // Fix up the hour in the non-24-hour mode and the time is in PM.
- //
- if(((HWREG(HIB_CALCTL) & HIB_CALCTL_CAL24) == 0) &&
- (ui32Time & HIB_CAL0_AMPM))
- {
- psTime->tm_hour += 12;
- }
- return(0);
- }
- //*****************************************************************************
- //
- //! Sets the Hibernation module's date and time match value in calendar mode.
- //!
- //! \param ui32Index indicates which match register to access.
- //! \param psTime is the structure that holds all of the information to set
- //! the current date and time match values.
- //!
- //! This function uses the \e psTime parameter to set the current date and time
- //! match value in the Hibernation module's calendar. Regardless of the mode,
- //! the \e psTime parameter uses a 24-hour clock representation of time.
- //! This function can only be called when the Hibernation module is
- //! configured in calendar mode using the HibernateCounterMode()
- //! function. The \e ui32Index value is reserved for future use and should
- //! always be zero.
- //! Calendar match can be enabled for every day, every hour, every minute or
- //! every second, setting any of these fields to 0xFF causes a match for
- //! that field. For example, setting the day of month field to 0xFF
- //! results in a calendar match daily at the same time.
- //!
- //! \note The hibernate calendar mode is not available on all Tiva
- //! devices. Please consult the data sheet to determine if the device you are
- //! using supports this feature in the Hibernation module.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateCalendarMatchSet(uint32_t ui32Index, struct tm *psTime)
- {
- //
- // Set the Match value.
- //
- _HibernateCalendarSet(HIB_CALM0, psTime);
- }
- //*****************************************************************************
- //
- //! Returns the Hibernation module's date and time match value in calendar
- //! mode.
- //!
- //! \param ui32Index indicates which match register to access.
- //! \param psTime is the structure to fill with the current date and time
- //! match value.
- //!
- //! This function returns the current date and time match value in the
- //! structure provided by the \e psTime parameter. Regardless of the mode, the
- //! \e psTime parameter uses a 24-hour clock representation of time.
- //! This function can only be called when the Hibernation module is configured
- //! in calendar mode using the HibernateCounterMode() function.
- //! The \e ui32Index value is reserved for future use and should always be
- //! zero.
- //!
- //! \note The hibernate calendar mode is not available on all Tiva
- //! devices. Please consult the data sheet to determine if the device you are
- //! using supports this feature in the Hibernation module.
- //!
- //! \return Returns zero if the time and date match value were read
- //! successfully and returns a non-zero value if the psTime structure was not
- //! updated.
- //
- //*****************************************************************************
- void
- HibernateCalendarMatchGet(uint32_t ui32Index, struct tm *psTime)
- {
- uint32_t ui32Date, ui32Time;
- ASSERT(HWREG(HIB_CALCTL) & HIB_CALCTL_CALEN);
- //
- // Get the date field.
- //
- ui32Date = HWREG(HIB_CALM1);
- //
- // Get the time field.
- //
- ui32Time = HWREG(HIB_CALM0);
- //
- // Populate the date and time fields in the psTime structure.
- //
- if((ui32Time & HIB_CAL0_MIN_M) == HIB_CAL0_MIN_M)
- {
- //
- // Match every minute
- //
- psTime->tm_min = 0xFF;
- }
- else
- {
- psTime->tm_min = (ui32Time & HIB_CAL0_MIN_M) >> HIB_CAL0_MIN_S;
- }
- if((ui32Time & HIB_CAL0_SEC_M) == HIB_CAL0_SEC_M)
- {
- //
- // Match every second
- //
- psTime->tm_sec = 0xFF;
- }
- else
- {
- psTime->tm_sec = (ui32Time & HIB_CAL0_SEC_M) >> HIB_CAL0_SEC_S;
- }
- if((ui32Time & HIB_CAL0_HR_M) == HIB_CAL0_HR_M)
- {
- //
- // Match every hour
- //
- psTime->tm_hour = 0xFF;
- }
- else
- {
- psTime->tm_hour = (ui32Time & HIB_CAL0_HR_M) >> HIB_CAL0_HR_S;
- }
- if((ui32Date & HIB_CAL1_DOM_M) == 0)
- {
- //
- // Match every day
- //
- psTime->tm_mday = 0xFF;
- }
- else
- {
- psTime->tm_mday = (ui32Date & HIB_CAL1_DOM_M) >> HIB_CAL1_DOM_S;
- }
- //
- // Fix up the hour in the non-24-hour mode and the time is in PM.
- //
- if(((HWREG(HIB_CALCTL) & HIB_CALCTL_CAL24) == 0) &&
- (ui32Time & HIB_CAL0_AMPM))
- {
- psTime->tm_hour += 12;
- }
- }
- //*****************************************************************************
- //
- //! Configures the tamper feature event response.
- //!
- //! \param ui32Config specifies the configuration options for tamper events.
- //!
- //! This function is used to configure the event response options for the
- //! tamper feature. The \e ui32Config parameter provides a combination of the
- //! \b HIBERNATE_TAMPER_EVENTS_* features to set these options. The
- //! application should choose from the following set of defines to determine
- //! what happens to the system when a tamper event occurs:
- //!
- //! - \b HIBERNATE_TAMPER_EVENTS_ERASE_ALL_HIB_MEM all of the Hibernation
- //! module's battery-backed RAM is cleared due to a tamper event
- //! - \b HIBERNATE_TAMPER_EVENTS_ERASE_HIGH_HIB_MEM the upper half of the
- //! Hibernation module's battery-backed RAM is cleared due to a tamper event
- //! - \b HIBERNATE_TAMPER_EVENTS_ERASE_LOW_HIB_MEM the lower half of the
- //! Hibernation module's battery-backed RAM is cleared due to a tamper event
- //! - \b HIBERNATE_TAMPER_EVENTS_ERASE_NO_HIB_MEM the Hibernation module's
- //! battery-backed RAM is not changed due to a tamper event
- //! - \b HIBERNATE_TAMPER_EVENTS_HIB_WAKE a tamper event wakes the MCU from
- //! hibernation
- //! - \b HIBERNATE_TAMPER_EVENTS_NO_HIB_WAKE a tamper event does not wake the
- //! MCU from hibernation
- //!
- //! \note The hibernate tamper feature is not available on all Tiva
- //! devices. Please consult the data sheet for the Tiva device that you
- //! are using to determine if this feature is available.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateTamperEventsConfig(uint32_t ui32Config)
- {
- uint32_t ui32Temp;
- //
- // Mask out the on-event configuration options.
- //
- ui32Temp = (HWREG(HIB_TPCTL) & ~HIB_TPCTL_MEMCLR_M);
- //
- // Unlock the tamper registers.
- //
- HWREG(HIB_LOCK) = HIB_LOCK_HIBLOCK_KEY;
- _HibernateWriteComplete();
- //
- // Set the on-event configuration.
- //
- HWREG(HIB_TPCTL) = (ui32Temp | ui32Config);
- //
- // Wait for write completion.
- //
- _HibernateWriteComplete();
- //
- // Lock the tamper registers.
- //
- HWREG(HIB_LOCK) = 0;
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Enables the tamper feature.
- //!
- //! This function is used to enable the tamper feature functionality. This
- //! function should only be called after the global configuration is set with
- //! a call to HibernateTamperEventsConfig() and the tamper inputs have been
- //! configured with a call to HibernateTamperIOEnable().
- //!
- //! \note The hibernate tamper feature is not available on all Tiva
- //! devices. Please consult the data sheet for the Tiva device that you
- //! are using to determine if this feature is available.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateTamperEnable(void)
- {
- //
- // Unlock the tamper registers.
- //
- HWREG(HIB_LOCK) = HIB_LOCK_HIBLOCK_KEY;
- _HibernateWriteComplete();
- //
- // Set the tamper enable bit.
- //
- HWREG(HIB_TPCTL) |= HIB_TPCTL_TPEN;
- //
- // Wait for write completion.
- //
- _HibernateWriteComplete();
- //
- // Lock the tamper registers.
- //
- HWREG(HIB_LOCK) = 0;
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Disables the tamper feature.
- //!
- //! This function is used to disable the tamper feature functionality. All
- //! other configuration settings are left unmodified, allowing a call to
- //! HibernateTamperEnable() to quickly enable the tamper feature with its
- //! previous configuration.
- //!
- //! \note The hibernate tamper feature is not available on all Tiva
- //! devices. Please consult the data sheet for the Tiva device that you
- //! are using to determine if this feature is available.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateTamperDisable(void)
- {
- //
- // Unlock the tamper registers.
- //
- HWREG(HIB_LOCK) = HIB_LOCK_HIBLOCK_KEY;
- _HibernateWriteComplete();
- //
- // Clear the tamper enable bit.
- //
- HWREG(HIB_TPCTL) &= ~HIB_TPCTL_TPEN;
- //
- // Wait for write completion.
- //
- _HibernateWriteComplete();
- //
- // Lock the tamper registers.
- //
- HWREG(HIB_LOCK) = 0;
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Configures an input to the tamper feature.
- //!
- //! \param ui32Input is the tamper input to configure.
- //! \param ui32Config holds the configuration options for a given input to the
- //! tamper feature.
- //!
- //! This function is used to configure an input to the tamper feature. The
- //! \e ui32Input parameter specifies the tamper signal to configure and has a
- //! valid range of 0-3. The \e ui32Config parameter provides the set of tamper
- //! features in the \b HIBERNATE_TAMPER_IO_* values. The values that are valid
- //! in the \e ui32Config parameter are:
- //!
- //! - \b HIBERNATE_TAMPER_IO_MATCH_SHORT configures the trigger to match after
- //! 2 hibernation clocks
- //! - \b HIBERNATE_TAMPER_IO_MATCH_LONG configures the trigger to match after
- //! 3071 hibernation clocks
- //! - \b HIBERNATE_TAMPER_IO_WPU_ENABLED turns on an internal weak pull up
- //! - \b HIBERNATE_TAMPER_IO_WPU_DISABLED turns off an internal weak pull up
- //! - \b HIBERNATE_TAMPER_IO_TRIGGER_HIGH sets the tamper event to active high
- //! - \b HIBERNATE_TAMPER_IO_TRIGGER_LOW sets the tamper event to active low
- //!
- //! \note None of the GPIO API functions are needed to configure the tamper
- //! pins. The tamper pins configured by using this function overrides any
- //! configuration by GPIO APIs.
- //!
- //! \note The hibernate tamper feature is not available on all Tiva
- //! devices. Please consult the data sheet for the Tiva device that you
- //! are using to determine if this feature is available.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateTamperIOEnable(uint32_t ui32Input, uint32_t ui32Config)
- {
- uint32_t ui32Temp, ui32Mask;
- //
- // Verify parameters.
- //
- ASSERT(ui32Input < 4);
- //
- // Read the current tamper I/O configuration.
- //
- ui32Temp = HWREG(HIB_TPIO);
- //
- // Mask out configuration options for the requested input.
- //
- ui32Mask = (ui32Temp & (~((HIB_TPIO_GFLTR0 | HIB_TPIO_PUEN0 |
- HIB_TPIO_LEV0 | HIB_TPIO_EN0) <<
- (ui32Input << 3))));
- //
- // Set tamper I/O configuration for the requested input.
- //
- ui32Temp = (ui32Mask | ((ui32Config | HIB_TPIO_EN0) << (ui32Input << 3)));
- //
- // Unlock the tamper registers.
- //
- HWREG(HIB_LOCK) = HIB_LOCK_HIBLOCK_KEY;
- _HibernateWriteComplete();
- //
- // Write to the register.
- //
- HWREG(HIB_TPIO) = ui32Temp;
- //
- // Wait for write completion.
- //
- _HibernateWriteComplete();
- //
- // Lock the tamper registers.
- //
- HWREG(HIB_LOCK) = 0;
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Disables an input to the tamper feature.
- //!
- //! \param ui32Input is the tamper input to disable.
- //!
- //! This function is used to disable an input to the tamper feature. The
- //! \e ui32Input parameter specifies the tamper signal to disable and has a
- //! valid range of 0-3.
- //!
- //! \note None of the GPIO API functions are needed to configure the tamper
- //! pins. The tamper pins configured by using this function overrides any
- //! configuration by GPIO APIs.
- //!
- //! \note The hibernate tamper feature is not available on all Tiva
- //! devices. Please consult the data sheet for the Tiva device that you
- //! are using to determine if this feature is available.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateTamperIODisable(uint32_t ui32Input)
- {
- //
- // Verify parameters.
- //
- ASSERT(ui32Input < 4);
- //
- // Unlock the tamper registers.
- //
- HWREG(HIB_LOCK) = HIB_LOCK_HIBLOCK_KEY;
- _HibernateWriteComplete();
- //
- // Clear the I/O enable bit.
- //
- HWREG(HIB_TPIO) &= ((~HIB_TPIO_EN0) << (ui32Input << 3));
- //
- // Wait for write completion.
- //
- _HibernateWriteComplete();
- //
- // Lock the tamper registers.
- //
- HWREG(HIB_LOCK) = 0;
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Clears the tamper feature events.
- //!
- //! This function is used to clear all tamper events. This function always
- //! clears the tamper feature event state indicator along with all tamper log
- //! entries. Logged event data should be retrieved with
- //! HibernateTamperEventsGet() prior to requesting a event clear.
- //!
- //! HibernateTamperEventsClear() should be called prior to clearing the system
- //! control NMI that resulted from the tamper event.
- //!
- //! \note The hibernate tamper feature is not available on all Tiva
- //! devices. Please consult the data sheet for the Tiva device that you
- //! are using to determine if this feature is available.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateTamperEventsClear(void)
- {
- //
- // Unlock the tamper registers.
- //
- HWREG(HIB_LOCK) = HIB_LOCK_HIBLOCK_KEY;
- _HibernateWriteComplete();
- //
- // Set the tamper event clear bit.
- //
- HWREG(HIB_TPCTL) |= HIB_TPCTL_TPCLR;
- //
- // Wait for write completion.
- //
- _HibernateWriteComplete();
- //
- // Lock the tamper registers.
- //
- HWREG(HIB_LOCK) = 0;
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Clears the tamper feature events without Unlock and Lock.
- //!
- //! This function is used to clear all tamper events without unlock/locking
- //! the tamper control registers, so API HibernateTamperUnLock() should be
- //! called before this function, and API HibernateTamperLock() should be
- //! called after to ensure that tamper control registers are locked.
- //!
- //! This function doesn't block until the write is complete.
- //! Therefore, care must be taken to ensure the next immediate write will
- //! occure only after the write complete bit is set.
- //!
- //! This function is used to implement a software workaround in NMI interrupt
- //! handler to fix an issue when a new tamper event could be missed during
- //! the clear of current tamper event.
- //!
- //! \note The hibernate tamper feature is not available on all Tiva
- //! devices. Please consult the data sheet for the Tiva device that you
- //! are using to determine if this feature is available.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateTamperEventsClearNoLock(void)
- {
- //
- // Wait for write completion.
- //
- _HibernateWriteComplete();
- //
- // Set the tamper event clear bit.
- //
- HWREG(HIB_TPCTL) |= HIB_TPCTL_TPCLR;
- }
- //*****************************************************************************
- //
- //! Unlock temper registers.
- //!
- //! This function is used to unlock the temper control registers. This
- //! function should be only used before calling API
- //! HibernateTamperEventsClearNoLock().
- //!
- //! \note The hibernate tamper feature is not available on all Tiva
- //! devices. Please consult the data sheet for the Tiva device that you
- //! are using to determine if this feature is available.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateTamperUnLock(void)
- {
- //
- // Unlock the tamper registers.
- //
- HWREG(HIB_LOCK) = HIB_LOCK_HIBLOCK_KEY;
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Lock temper registers.
- //!
- //! This function is used to lock the temper control registers. This
- //! function should be used after calling API
- //! HibernateTamperEventsClearNoLock().
- //!
- //! \note The hibernate tamper feature is not available on all Tiva
- //! devices. Please consult the data sheet for the Tiva device that you
- //! are using to determine if this feature is available.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateTamperLock(void)
- {
- //
- // Wait for write completion.
- //
- _HibernateWriteComplete();
- //
- // Lock the tamper registers.
- //
- HWREG(HIB_LOCK) = 0;
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Returns the current tamper feature status.
- //!
- //! This function is used to return the tamper feature status. This function
- //! returns one of the values from this group of options:
- //!
- //! - \b HIBERNATE_TAMPER_STATUS_INACTIVE indicates tamper detection is
- //! disabled
- //! - \b HIBERNATE_TAMPER_STATUS_ACTIVE indicates tamper detection is enabled
- //! and ready
- //! - \b HIBERNATE_TAMPER_STATUS_EVENT indicates tamper event was detected
- //!
- //! In addition, one of the values is included from this group:
- //!
- //! - \b HIBERNATE_TAMPER_STATUS_EXT_OSC_INACTIVE indicates the external
- //! oscillator is not active
- //! - \b HIBERNATE_TAMPER_STATUS_EXT_OSC_ACTIVE indicates the external
- //! oscillator is active
- //!
- //! And one of the values is included from this group:
- //!
- //! - \b HIBERNATE_TAMPER_STATUS_EXT_OSC_FAILED indicates the external
- //! oscillator signal has transitioned from valid to invalid
- //! - \b HIBERNATE_TAMPER_STATUS_EXT_OSC_VALID indicates the external
- //! oscillator is providing a valid signal
- //!
- //! \note The hibernate tamper feature is not available on all Tiva
- //! devices. Please consult the data sheet for the Tiva device that you
- //! are using to determine if this feature is available.
- //!
- //! \return Returns a combination of the \b HIBERNATE_TAMPER_STATUS_* values.
- //
- //*****************************************************************************
- uint32_t
- HibernateTamperStatusGet(void)
- {
- uint32_t ui32Status, ui32Reg;
- //
- // Retrieve the raw register value.
- //
- ui32Reg = HWREG(HIB_TPSTAT);
- //
- // Setup the oscillator status indicators.
- //
- ui32Status = (ui32Reg & (HIB_TPSTAT_XOSCST | HIB_TPSTAT_XOSCFAIL));
- ui32Status |= ((ui32Reg & HIB_TPSTAT_XOSCST) ? 0 :
- HIBERNATE_TAMPER_STATUS_EXT_OSC_ACTIVE);
- ui32Status |= ((ui32Reg & HIB_TPSTAT_XOSCFAIL) ? 0 :
- HIBERNATE_TAMPER_STATUS_EXT_OSC_VALID);
- //
- // Retrieve the tamper status indicators.
- //
- ui32Status |= ((ui32Reg & HIB_TPSTAT_STATE_M) << 3);
- //
- // The HW shows "disabled" with a zero value, use bit[0] as a flag
- // for this purpose.
- //
- if((ui32Reg & HIB_TPSTAT_STATE_M) == 0)
- {
- ui32Status |= HIBERNATE_TAMPER_STATUS_INACTIVE;
- }
- //
- // Return the API status flags.
- //
- return(ui32Status);
- }
- //*****************************************************************************
- //
- //! Returns a tamper log entry.
- //!
- //! \param ui32Index is the index of the log entry to return.
- //! \param pui32RTC is a pointer to the memory to store the logged RTC data.
- //! \param pui32Event is a pointer to the memory to store the logged tamper
- //! event.
- //!
- //! This function is used to return a tamper log entry from the hibernate
- //! feature. The \e ui32Index specifies the zero-based index of the log entry
- //! to query and has a valid range of 0-3.
- //!
- //! When this function returns, the \e pui32RTC value contains the time value
- //! and \e pui32Event parameter contains the tamper I/O event that triggered
- //! this log.
- //!
- //! The format of the returned \e pui32RTC data is dependent on the
- //! configuration of the RTC within the Hibernation module. If the RTC is
- //! configured for counter mode, the returned data contains counted seconds
- //! from the RTC enable. If the RTC is configured for calendar mode, the data
- //! returned is formatted as follows:
- //!
- //! \verbatim
- //! +----------------------------------------------------------------------+
- //! | 31:26 | 25:22 | 21:17 | 16:12 | 11:6 | 5:0 |
- //! +----------------------------------------------------------------------+
- //! | year | month | day of month | hours | minutes | seconds |
- //! +----------------------------------------------------------------------+
- //! \endverbatim
- //!
- //! The data returned in the \e pui32Events parameter could include any of the
- //! following flags:
- //!
- //! - \b HIBERNATE_TAMPER_EVENT_0 indicates a tamper event was triggered on I/O
- //! signal 0
- //! - \b HIBERNATE_TAMPER_EVENT_1 indicates a tamper event was triggered on I/O
- //! signal 1
- //! - \b HIBERNATE_TAMPER_EVENT_2 indicates a tamper event was triggered on I/O
- //! signal 2
- //! - \b HIBERNATE_TAMPER_EVENT_3 indicates a tamper event was triggered on I/O
- //! signal 3
- //! - \b HIBERNATE_TAMPER_EVENT_XOSC indicates an external oscillator failure
- //! triggered the tamper event
- //!
- //! \note Tamper event logs are not consumed when read and remain available
- //! until cleared. Events are only logged if unused log space is available.
- //!
- //! \note The hibernate tamper feature is not available on all Tiva
- //! devices. Please consult the data sheet for the Tiva device that you
- //! are using to determine if this feature is available.
- //!
- //! \return Returns \b true if the \e pui32RTC and \e pui32Events were updated
- //! successfully and returns \b false if the values were not updated.
- //
- //*****************************************************************************
- bool
- HibernateTamperEventsGet(uint32_t ui32Index, uint32_t *pui32RTC,
- uint32_t *pui32Event)
- {
- uint32_t ui32Reg;
- //
- // Verify parameters.
- //
- ASSERT(pui32RTC);
- ASSERT(pui32Event);
- ASSERT(ui32Index < 4);
- //
- // Retrieve the event log data for the requested index if available.
- //
- ui32Reg = HWREG(HIB_TPLOG0 + ((ui32Index << 3) + 4));
- if(ui32Reg == 0)
- {
- //
- // No event data is available for this index.
- //
- return(false);
- }
- //
- // Store the event data in the provided location.
- //
- *pui32Event = ui32Reg;
- //
- // Retrieve the calendar information.
- //
- *pui32RTC = HWREG(HIB_TPLOG0 + (ui32Index << 3));
- //
- // Convert the hour to 24hr mode if the Calendar is enabled
- // and in 24hr mode.
- //
- if((HWREG(HIB_CALCTL) & (HIB_CALCTL_CALEN | HIB_CALCTL_CAL24)) ==
- (HIB_CALCTL_CALEN | HIB_CALCTL_CAL24))
- {
- if(HWREG(HIB_CAL0) & HIB_CAL0_AMPM)
- {
- //
- // Add 12 hour since it is PM
- //
- ui32Reg = ((*pui32RTC & 0X0001f000) + (12<<12)) & 0X0001f000;
- *pui32RTC &= ~0X0001f000;
- *pui32RTC |= ui32Reg;
- }
- }
- //
- // Return success.
- //
- return(true);
- }
- //*****************************************************************************
- //
- //! Attempts to recover the external oscillator.
- //!
- //! This function is used to attempt to recover the external oscillator after a
- //! \b HIBERNATE_TAMPER_STATUS_EXT_OSC_FAILED status is reported. This
- //! function must not be called if the external oscillator is not used as
- //! the hibernation clock input. HibernateTamperExtOscValid() should be called
- //! before calling this function.
- //!
- //! \note The hibernate tamper feature is not available on all Tiva
- //! devices. Please consult the data sheet for the Tiva device that you
- //! are using to determine if this feature is available.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- HibernateTamperExtOscRecover(void)
- {
- //
- // Unlock the tamper registers.
- //
- HWREG(HIB_LOCK) = HIB_LOCK_HIBLOCK_KEY;
- _HibernateWriteComplete();
- //
- // Set the XOSCFAIL clear bit.
- //
- HWREG(HIB_TPSTAT) |= HIB_TPSTAT_XOSCFAIL;
- //
- // Wait for write completion.
- //
- _HibernateWriteComplete();
- //
- // Lock the tamper registers.
- //
- HWREG(HIB_LOCK) = 0;
- _HibernateWriteComplete();
- }
- //*****************************************************************************
- //
- //! Reports if the external oscillator signal is active and stable.
- //!
- //! This function should be used to verify the external oscillator is active
- //! and valid before attempting to recover from a
- //! \b HIBERNATE_TAMPER_STATUS_EXT_OSC_FAILED status by calling
- //! HibernateTamperExtOscRecover().
- //!
- //! \note The hibernate tamper feature is not available on all Tiva
- //! devices. Please consult the data sheet for the Tiva device that you
- //! are using to determine if this feature is available.
- //!
- //! \return Returns \b true if the external oscillator is both active and
- //! stable, otherwise a \b false indicator is returned.
- //
- //*****************************************************************************
- bool
- HibernateTamperExtOscValid(void)
- {
- if(HibernateTamperStatusGet() & (HIBERNATE_TAMPER_STATUS_EXT_OSC_ACTIVE |
- HIBERNATE_TAMPER_STATUS_EXT_OSC_VALID))
- {
- return(true);
- }
- return(false);
- }
- //*****************************************************************************
- //
- // Close the Doxygen group.
- //! @}
- //
- //*****************************************************************************
|