]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC/ThirdParty/CMSISv2p10_LPC18xx_DriverLib/src/lpc18xx_wwdt.c
Update copyright date ready for tagging V10.1.0.
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC / ThirdParty / CMSISv2p10_LPC18xx_DriverLib / src / lpc18xx_wwdt.c
1 /**********************************************************************\r
2 * $Id$          lpc18xx_wwdt.c          2011-06-02\r
3 *//**\r
4 * @file         lpc18xx_wwdt.c\r
5 * @brief        Contains all functions support for WDT firmware library\r
6 *                       on LPC18xx\r
7 * @version      1.0\r
8 * @date         02. June. 2011\r
9 * @author       NXP MCU SW Application Team\r
10 *\r
11 * Copyright(C) 2011, NXP Semiconductor\r
12 * All rights reserved.\r
13 *\r
14 ***********************************************************************\r
15 * Software that is described herein is for illustrative purposes only\r
16 * which provides customers with programming information regarding the\r
17 * products. This software is supplied "AS IS" without any warranties.\r
18 * NXP Semiconductors assumes no responsibility or liability for the\r
19 * use of the software, conveys no license or title under any patent,\r
20 * copyright, or mask work right to the product. NXP Semiconductors\r
21 * reserves the right to make changes in the software without\r
22 * notification. NXP Semiconductors also make no representation or\r
23 * warranty that such application will be suitable for the specified\r
24 * use without further testing or modification.\r
25 **********************************************************************/\r
26 \r
27 /* Peripheral group ----------------------------------------------------------- */\r
28 /** @addtogroup WWDT\r
29  * @{\r
30  */\r
31 \r
32 /* Includes ------------------------------------------------------------------- */\r
33 #include "lpc18xx_wwdt.h"\r
34 \r
35 /* If this source file built with example, the LPC18xx FW library configuration\r
36  * file in each example directory ("lpc18xx_libcfg.h") must be included,\r
37  * otherwise the default FW library configuration file must be included instead\r
38  */\r
39 #ifdef __BUILD_WITH_EXAMPLE__\r
40 #include "lpc18xx_libcfg.h"\r
41 #else\r
42 #include "lpc18xx_libcfg_default.h"\r
43 #endif /* __BUILD_WITH_EXAMPLE__ */\r
44 \r
45 \r
46 #ifdef _WWDT\r
47 \r
48 void WWDT_SetTimeOut(uint32_t timeout);\r
49 \r
50 /*********************************************************************//**\r
51  * @brief               Update WDT timeout value and feed\r
52  * @param[in]   timeout WDT timeout (us)\r
53  * @return              none\r
54  **********************************************************************/\r
55 void WWDT_SetTimeOut(uint32_t timeout)\r
56 {\r
57         uint32_t timeoutVal;\r
58 \r
59         timeoutVal = WDT_GET_FROM_USEC(timeout);\r
60 \r
61         if(timeoutVal < WWDT_TIMEOUT_MIN)\r
62         {\r
63                 timeoutVal = WWDT_TIMEOUT_MIN;\r
64         }\r
65         else if (timeoutVal > WWDT_TIMEOUT_MAX)\r
66         {\r
67                 timeoutVal = WWDT_TIMEOUT_MAX;\r
68         }\r
69 \r
70         LPC_WWDT->TC = timeoutVal;\r
71 }\r
72 /* Public Functions ----------------------------------------------------------- */\r
73 /** @addtogroup WDT_Public_Functions\r
74  * @{\r
75  */\r
76 \r
77 /*********************************************************************//**\r
78 * @brief                Initial for Watchdog function\r
79 * @param[in]    none\r
80 * @return               None\r
81  **********************************************************************/\r
82 void WWDT_Init(void)\r
83 {\r
84         LPC_WWDT->MOD   = 0;                                    // Clear time out and interrupt flags\r
85         LPC_WWDT->TC    = WWDT_TIMEOUT_MIN;     // Reset time out\r
86         LPC_WWDT->WARNINT= 0;                                   // Reset warning value\r
87         LPC_WWDT->WINDOW = WWDT_WINDOW_MAX;             // Reset window value\r
88 }\r
89 \r
90 /********************************************************************//**\r
91  * @brief               Update WDT timeout value and feed\r
92  * @param[in]   TimeOut TimeOut value to be updated, should be in range:\r
93  *                              2048 .. 134217728\r
94  * @return              None\r
95  *********************************************************************/\r
96 void WDT_UpdateTimeOut(uint32_t TimeOut)\r
97 {\r
98         /* check WDPROTECT,\r
99          * if it is enable, wait until the counter is below the value of\r
100          * WDWARNINT and WDWINDOW\r
101          */\r
102         if(LPC_WWDT->MOD & (1<<4))\r
103         {\r
104                 while((LPC_WWDT->TV <(LPC_WWDT->WARNINT & WWDT_WDWARNINT_MASK))\\r
105                                                 &&(LPC_WWDT->TV <(LPC_WWDT->WINDOW & WWDT_WDTC_MASK)));\r
106         }\r
107 \r
108         WWDT_SetTimeOut(TimeOut);\r
109 }\r
110 /********************************************************************//**\r
111  * @brief               After set WDTEN, call this function to start Watchdog\r
112  *                              or reload the Watchdog timer\r
113  * @param[in]   None\r
114  * @return              None\r
115  *********************************************************************/\r
116 void WWDT_Feed (void)\r
117 {\r
118         LPC_WWDT->FEED = 0xAA;\r
119 \r
120         LPC_WWDT->FEED = 0x55;\r
121 }\r
122 \r
123 /********************************************************************//**\r
124  * @brief               Update WDT timeout value and feed\r
125  * @param[in]   WarnTime        time to generate watchdog warning interrupt(us)\r
126  *                              should be in range: 2048 .. 8192\r
127  * @return              None\r
128  *********************************************************************/\r
129 void WWDT_SetWarning(uint32_t WarnTime)\r
130 {\r
131         uint32_t warnVal;\r
132 \r
133         warnVal = WDT_GET_FROM_USEC(WarnTime);\r
134 \r
135         if(warnVal <= WWDT_WARNINT_MIN)\r
136         {\r
137                 warnVal = WWDT_WARNINT_MIN;\r
138         }\r
139         else if (warnVal >= WWDT_WARNINT_MAX)\r
140         {\r
141                 warnVal = WWDT_WARNINT_MAX;\r
142         }\r
143 \r
144         LPC_WWDT->WARNINT = warnVal;\r
145 }\r
146 \r
147 /********************************************************************//**\r
148  * @brief               Update WDT timeout value and feed\r
149  * @param[in]   WindowedTime    expected time to set watchdog window event(us)\r
150  * @return              none\r
151  *********************************************************************/\r
152 void WWDT_SetWindow(uint32_t WindowedTime)\r
153 {\r
154         uint32_t wndVal;\r
155 \r
156         wndVal = WDT_GET_FROM_USEC(WindowedTime);\r
157 \r
158         if(wndVal <= WWDT_WINDOW_MIN)\r
159         {\r
160                 wndVal = WWDT_WINDOW_MIN;\r
161         }\r
162         else if (wndVal >= WWDT_WINDOW_MAX)\r
163         {\r
164                 wndVal = WWDT_WINDOW_MAX;\r
165         }\r
166 \r
167         LPC_WWDT->WINDOW = wndVal;\r
168 }\r
169 /*********************************************************************//**\r
170 * @brief                Enable/Disable WWDT activity\r
171 * @param[in]    None\r
172 * @return               None\r
173  **********************************************************************/\r
174 void WWDT_Configure(st_Wdt_Config wdtCfg)\r
175 {\r
176         WWDT_SetTimeOut(wdtCfg.wdtTmrConst);\r
177 \r
178         if(wdtCfg.wdtReset)\r
179         {\r
180                 LPC_WWDT->MOD |= WWDT_WDMOD_WDRESET;\r
181         }\r
182         else\r
183         {\r
184                 LPC_WWDT->MOD &= ~WWDT_WDMOD_WDRESET;\r
185         }\r
186 \r
187         if(wdtCfg.wdtProtect)\r
188         {\r
189                 LPC_WWDT->MOD |= WWDT_WDMOD_WDPROTECT;\r
190         }\r
191         else\r
192         {\r
193                 LPC_WWDT->MOD &= ~WWDT_WDMOD_WDPROTECT;\r
194         }\r
195 }\r
196 \r
197 /*********************************************************************//**\r
198 * @brief                Enable WWDT activity\r
199 * @param[in]    None\r
200 * @return               None\r
201  **********************************************************************/\r
202 void WWDT_Start(void)\r
203 {\r
204         LPC_WWDT->MOD |= WWDT_WDMOD_WDEN;\r
205         WWDT_Feed();\r
206 }\r
207 \r
208 /********************************************************************//**\r
209  * @brief               Read WWDT status flag\r
210  * @param[in]   Status kind of status flag that you want to get, should be:\r
211  *                              - WWDT_WARNINT_FLAG: watchdog interrupt flag\r
212  *                              - WWDT_TIMEOUT_FLAG: watchdog time-out flag\r
213  * @return              Time out flag status of WDT\r
214  *********************************************************************/\r
215 FlagStatus WWDT_GetStatus (uint8_t Status)\r
216 {\r
217         if(Status == WWDT_WARNINT_FLAG)\r
218         {\r
219                 return ((FlagStatus)(LPC_WWDT->MOD & (1<<3)));\r
220         }\r
221         else if (Status == WWDT_TIMEOUT_FLAG)\r
222         {\r
223                 return ((FlagStatus)(LPC_WWDT->MOD & (1<<2)));\r
224         }\r
225         return (FlagStatus)RESET;\r
226 }\r
227 \r
228 /********************************************************************//**\r
229  * @brief               Read WWDT status flag\r
230  * @param[in]   Status kind of status flag that you want to get, should be:\r
231  *                              - WWDT_WARNINT_FLAG: watchdog interrupt flag\r
232  *                              - WWDT_TIMEOUT_FLAG: watchdog time-out flag\r
233  * @return              Time out flag status of WDT\r
234  *********************************************************************/\r
235 void WWDT_ClearStatusFlag (uint8_t flag)\r
236 {\r
237         if(flag == WWDT_WARNINT_FLAG)\r
238         {\r
239                 // Write 1 to this bit to clear itself\r
240                 LPC_WWDT->MOD |= WWDT_WDMOD_WDINT;\r
241         }\r
242         else if(flag == WWDT_TIMEOUT_FLAG)\r
243         {\r
244                 // Write 0 to this bit to clear itself\r
245                 LPC_WWDT->MOD &= ~ WWDT_WDMOD_WDTOF;\r
246         }\r
247 }\r
248 \r
249 /********************************************************************//**\r
250  * @brief               Get the current value of WDT\r
251  * @param[in]   None\r
252  * @return              current value of WDT\r
253  *********************************************************************/\r
254 uint32_t WWDT_GetCurrentCount(void)\r
255 {\r
256         return LPC_WWDT->TV;\r
257 }\r
258 \r
259 /**\r
260  * @}\r
261  */\r
262 \r
263 #endif /* _WWDT */\r
264 /**\r
265  * @}\r
266  */\r
267 \r
268 /* --------------------------------- End Of File ------------------------------ */\r