]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_SAMV71_Xplained/libchip_samv7/source/wdt.c
Update version number ready for V8.2.1 release.
[freertos] / FreeRTOS / Demo / CORTEX_M7_SAMV71_Xplained / libchip_samv7 / source / wdt.c
1 /* ----------------------------------------------------------------------------\r
2  *         SAM Software Package License\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2012, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\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
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\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
16  *\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
28  */\r
29 \r
30 /**\r
31  * \file\r
32  *\r
33  * Implementation of Watchdog Timer (WDT) controller.\r
34  *\r
35  */\r
36 \r
37 /** \addtogroup wdt_module Working with WDT\r
38  *  \ingroup peripherals_module\r
39  * The WDT driver provides the interface to configure and use the WDT\r
40  * peripheral.\r
41  *\r
42  * The WDT can be used to prevent system lock-up if the software becomes\r
43  * trapped in a deadlock. It can generate a general reset or a processor\r
44  * reset only. It is clocked by slow clock divided by 128.\r
45  *\r
46  * The WDT is running at reset with 16 seconds watchdog period (slow clock at 32.768 kHz)\r
47  * and external reset generation enabled. The user must either disable it or\r
48  * reprogram it to meet the application requires.\r
49  *\r
50  * To use the WDT, the user could follow these few steps:\r
51  * <ul>\r
52  * <li>Enable watchdog with given mode using \ref WDT_Enable().\r
53  * <li>Restart the watchdog using \ref WDT_Restart() within the watchdog period.\r
54  * </ul>\r
55  *\r
56  * For more accurate information, please look at the WDT section of the\r
57  * Datasheet.\r
58  *\r
59  * \note\r
60  * The Watchdog Mode Register (WDT_MR) can be written only once.\n\r
61  *\r
62  * Related files :\n\r
63  * \ref wdt.c\n\r
64  * \ref wdt.h.\n\r
65  */\r
66 /*@{*/\r
67 /*@}*/\r
68 \r
69 /*---------------------------------------------------------------------------\r
70  *        Headers\r
71  *---------------------------------------------------------------------------*/\r
72 \r
73 #include "chip.h"\r
74 \r
75 #include <stdint.h>\r
76 \r
77 /*----------------------------------------------------------------------------\r
78  *        Exported functions\r
79  *----------------------------------------------------------------------------*/\r
80 \r
81 /**\r
82  * \brief Enable watchdog with given mode.\r
83  *\r
84  * \note The Watchdog Mode Register (WDT_MR) can be written only once.\r
85  * Only a processor reset resets it.\r
86  *\r
87  * \param dwMode   WDT mode to be set\r
88  */\r
89 extern void WDT_Enable( Wdt* pWDT, uint32_t dwMode )\r
90 {\r
91     pWDT->WDT_MR = dwMode ;\r
92 }\r
93 \r
94 /**\r
95  * \brief Disable watchdog.\r
96  *\r
97  * \note The Watchdog Mode Register (WDT_MR) can be written only once.\r
98  * Only a processor reset resets it.\r
99  */\r
100 extern void WDT_Disable( Wdt* pWDT )\r
101 {\r
102     pWDT->WDT_MR = WDT_MR_WDDIS;\r
103 }\r
104 \r
105 /**\r
106  * \brief Watchdog restart.\r
107  */\r
108 extern void WDT_Restart( Wdt* pWDT )\r
109 {\r
110     pWDT->WDT_CR = 0xA5000001;\r
111 }\r
112 \r
113 /**\r
114  * \brief Watchdog get status.\r
115  */\r
116 extern uint32_t WDT_GetStatus( Wdt* pWDT )\r
117 {\r
118     return (pWDT->WDT_SR & 0x3) ;\r
119 }\r
120 \r
121 /**\r
122  * \brief Watchdog get period.\r
123  *\r
124  * \param dwMs   desired watchdog period in millisecond.\r
125  */\r
126 extern uint32_t WDT_GetPeriod( uint32_t dwMs )\r
127 {\r
128     if ( (dwMs < 4) || (dwMs > 16000) )\r
129     {\r
130         return 0 ;\r
131     }\r
132     return ((dwMs << 8) / 1000) ;\r
133 }\r