1 /* ----------------------------------------------------------------------------
\r
2 * SAM Software Package License
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2013, Atmel Corporation
\r
6 * All rights reserved.
\r
8 * Redistribution and use in source and binary forms, with or without
\r
9 * modification, are permitted provided that the following conditions are met:
\r
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\r
14 * Atmel's name may not be used to endorse or promote products derived from
\r
15 * this software without specific prior written permission.
\r
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
\r
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
\r
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
27 * ----------------------------------------------------------------------------
\r
33 * Implementation of Watchdog Timer (WDT) controller.
\r
37 /** \addtogroup wdt_module Working with WDT
\r
38 * The WDT driver provides the interface to configure and use the WDT
\r
41 * The WDT can be used to prevent system lock-up if the software becomes
\r
42 * trapped in a deadlock. It can generate a general reset or a processor
\r
43 * reset only. It is clocked by slow clock divided by 128.
\r
45 * The WDT is running at reset with 16 seconds watchdog period (slow clock at 32.768 kHz)
\r
46 * and external reset generation enabled. The user must either disable it or
\r
47 * reprogram it to meet the application requires.
\r
49 * To use the WDT, the user could follow these few steps:
\r
51 * <li>Enable watchdog with given mode using \ref WDT_Enable().
\r
52 * <li>Restart the watchdog using \ref WDT_Restart() within the watchdog period.
\r
55 * For more accurate information, please look at the WDT section of the
\r
59 * The Watchdog Mode Register (WDT_MR) can be written only once.\n
\r
68 /*---------------------------------------------------------------------------
\r
70 *---------------------------------------------------------------------------*/
\r
76 /*----------------------------------------------------------------------------
\r
77 * Exported functions
\r
78 *----------------------------------------------------------------------------*/
\r
81 * \brief Enable watchdog with given mode.
\r
83 * \note The Watchdog Mode Register (WDT_MR) can be written only once.
\r
84 * Only a processor reset resets it.
\r
86 * \param dwMode WDT mode to be set
\r
88 extern void WDT_Enable( Wdt* pWDT, uint32_t dwMode )
\r
90 pWDT->WDT_MR = dwMode ;
\r
94 * \brief Disable watchdog.
\r
96 * \note The Watchdog Mode Register (WDT_MR) can be written only once.
\r
97 * Only a processor reset resets it.
\r
99 extern void WDT_Disable( Wdt* pWDT )
\r
101 pWDT->WDT_MR = WDT_MR_WDDIS;
\r
105 * \brief Watchdog restart.
\r
107 extern void WDT_Restart( Wdt* pWDT )
\r
109 pWDT->WDT_CR = 0xA5000001;
\r
113 * \brief Watchdog get status.
\r
115 extern uint32_t WDT_GetStatus( Wdt* pWDT )
\r
117 return (pWDT->WDT_SR & 0x3) ;
\r
121 * \brief Watchdog get status.
\r
123 extern uint32_t WDT_GetCounterValue( Wdt* pWDT )
\r
125 return (pWDT->WDT_MR & WDT_MR_WDV_Msk) ;
\r
129 * \brief Watchdog get period.
\r
131 * \param dwMs desired watchdog period in millisecond.
\r
133 extern uint32_t WDT_GetPeriod( uint32_t dwMs )
\r
135 if ( (dwMs < 4) || (dwMs > 16000) )
\r
139 return ((dwMs << 8) / 1000) ;
\r