1 |
577 |
jeremybenn |
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
|
2 |
|
|
* File Name : 91x_wdg.c
|
3 |
|
|
* Author : MCD Application Team
|
4 |
|
|
* Date First Issued : 05/18/2006 : Version 1.0
|
5 |
|
|
* Description : This file provides all the WDG software functions.
|
6 |
|
|
********************************************************************************
|
7 |
|
|
* History:
|
8 |
|
|
* 05/24/2006 : Version 1.1
|
9 |
|
|
* 05/18/2006 : Version 1.0
|
10 |
|
|
********************************************************************************
|
11 |
|
|
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
12 |
|
|
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
|
13 |
|
|
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
|
14 |
|
|
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
|
15 |
|
|
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
16 |
|
|
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
17 |
|
|
*******************************************************************************/
|
18 |
|
|
|
19 |
|
|
/* Includes ------------------------------------------------------------------*/
|
20 |
|
|
#include "91x_wdg.h"
|
21 |
|
|
#include "91x_scu.h"
|
22 |
|
|
/* Private typedef -----------------------------------------------------------*/
|
23 |
|
|
/* Private define ------------------------------------------------------------*/
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
/* WDG End of Count interrupt Flag */
|
27 |
|
|
#define WDG_FLAG_EC 0x0001
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
/* WDG End of Count interrupt request */
|
31 |
|
|
#define WDG_IT_EC 0x0001
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
/* WDG Start/Stop counter */
|
36 |
|
|
#define WDG_Counter_Start 0x0002
|
37 |
|
|
#define WDG_Counter_Stop 0xFFFD
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
/* Private macro -------------------------------------------------------------*/
|
41 |
|
|
/* Private variables ---------------------------------------------------------*/
|
42 |
|
|
/* Registers reset value */
|
43 |
|
|
/* Private function prototypes -----------------------------------------------*/
|
44 |
|
|
/* Private functions ---------------------------------------------------------*/
|
45 |
|
|
|
46 |
|
|
/******************************************************************************
|
47 |
|
|
* Function Name : WDG_DeInit
|
48 |
|
|
* Description : Deinitializes the WDG peripheral registers to their default
|
49 |
|
|
* reset values.
|
50 |
|
|
* Input : None
|
51 |
|
|
* Output : None
|
52 |
|
|
* Return : None
|
53 |
|
|
*******************************************************************************/
|
54 |
|
|
void WDG_DeInit(void)
|
55 |
|
|
{
|
56 |
|
|
|
57 |
|
|
SCU_APBPeriphReset(__WDG, ENABLE); /*WDG peripheral under Reset */
|
58 |
|
|
SCU_APBPeriphReset(__WDG, DISABLE); /*WDG peripheral Reset off*/
|
59 |
|
|
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
/*******************************************************************************
|
63 |
|
|
* Function Name : WDG_StructInit
|
64 |
|
|
* Description : Fills the WDG_InitTypeDef structure member with its reset
|
65 |
|
|
* value.
|
66 |
|
|
* Input : WDG_InitStruct : pointer to a WDG_InitTypeDef structure
|
67 |
|
|
* which will be initialized.
|
68 |
|
|
* Output : None
|
69 |
|
|
* Return : None
|
70 |
|
|
*******************************************************************************/
|
71 |
|
|
void WDG_StructInit(WDG_InitTypeDef *WDG_InitStruct)
|
72 |
|
|
{
|
73 |
|
|
/* Select the Watchdog running mode*/
|
74 |
|
|
WDG_InitStruct->WDG_Mode = WDG_Mode_Timer;
|
75 |
|
|
|
76 |
|
|
/* Select the source clock */
|
77 |
|
|
WDG_InitStruct-> WDG_ClockSource = WDG_ClockSource_Apb;
|
78 |
|
|
|
79 |
|
|
/* Initialize Prescaler */
|
80 |
|
|
WDG_InitStruct->WDG_Prescaler =0xFF;
|
81 |
|
|
|
82 |
|
|
/* Initialize Preload */
|
83 |
|
|
WDG_InitStruct->WDG_Preload =0xFFFF;
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
/*******************************************************************************
|
89 |
|
|
* Function Name : WDG_Init
|
90 |
|
|
* Description : Initializes WDG peripheral according to the specified
|
91 |
|
|
* parameters in the WDG_InitStruct.
|
92 |
|
|
* Input : WDG_InitStruct: pointer to a WDG_InitTypeDef structure that
|
93 |
|
|
* contains the configuration information for the WDG peripheral.
|
94 |
|
|
* Output : None
|
95 |
|
|
* Return : None
|
96 |
|
|
*******************************************************************************/
|
97 |
|
|
void WDG_Init(WDG_InitTypeDef* WDG_InitStruct)
|
98 |
|
|
{
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
if(WDG_InitStruct->WDG_ClockSource == WDG_ClockSource_Apb)
|
102 |
|
|
{
|
103 |
|
|
/* Select The APB clock as clock source */
|
104 |
|
|
WDG->CR &= WDG_ClockSource_Apb;
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
else
|
108 |
|
|
{
|
109 |
|
|
/* Select the RTC clock as source */
|
110 |
|
|
WDG->CR |= WDG_ClockSource_Rtc ;
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
/* Configure WDG Prescaler register value */
|
115 |
|
|
WDG->PR = WDG_InitStruct->WDG_Prescaler;
|
116 |
|
|
|
117 |
|
|
/* Configure WDG Pre-load register value */
|
118 |
|
|
WDG->VR = WDG_InitStruct->WDG_Preload ;
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
if(WDG_InitStruct->WDG_Mode == WDG_Mode_Timer)
|
122 |
|
|
{
|
123 |
|
|
/* Select Timer mode */
|
124 |
|
|
WDG->CR &= WDG_Mode_Timer;
|
125 |
|
|
}
|
126 |
|
|
else
|
127 |
|
|
{
|
128 |
|
|
/* Select WDG mode */
|
129 |
|
|
WDG->CR |= WDG_Mode_Wdg ;
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
/*******************************************************************************
|
136 |
|
|
* Function Name : WDG_Cmd
|
137 |
|
|
* Description : Enables or disables the WDG peripheral.
|
138 |
|
|
* Input : NewState: new state of the WDG peripheral (Newstate can be
|
139 |
|
|
* ENABLE or DISABLE)
|
140 |
|
|
* Output : None
|
141 |
|
|
* Return : None
|
142 |
|
|
*******************************************************************************/
|
143 |
|
|
void WDG_Cmd(FunctionalState NewState )
|
144 |
|
|
{
|
145 |
|
|
if((WDG->CR & WDG_Mode_Wdg) == 0)
|
146 |
|
|
{
|
147 |
|
|
/* Timer mode */
|
148 |
|
|
if(NewState == ENABLE)
|
149 |
|
|
{
|
150 |
|
|
/* Start timer by setting SC bit in Control register */
|
151 |
|
|
WDG->CR |= WDG_Counter_Start;
|
152 |
|
|
}
|
153 |
|
|
else
|
154 |
|
|
{
|
155 |
|
|
/* Stop timer by clearning SC bit in Control register */
|
156 |
|
|
WDG->CR &= WDG_Counter_Stop;
|
157 |
|
|
}
|
158 |
|
|
}
|
159 |
|
|
else
|
160 |
|
|
{
|
161 |
|
|
/* Watchdog mode */
|
162 |
|
|
if(NewState == ENABLE)
|
163 |
|
|
{
|
164 |
|
|
WDG->KR = WDG_KeyValue1;
|
165 |
|
|
WDG->KR = WDG_KeyValue2;
|
166 |
|
|
}
|
167 |
|
|
}
|
168 |
|
|
}
|
169 |
|
|
|
170 |
|
|
/*******************************************************************************
|
171 |
|
|
* Function Name : WDG_ITConfig
|
172 |
|
|
* Description : Enables or disables the WDG End of Count(EC) interrupt.
|
173 |
|
|
* Input : Newstate: new state of the End of Count(EC) WDG interrupt.
|
174 |
|
|
* This parameter can be: ENABLE or DISABLE.
|
175 |
|
|
* Output : None
|
176 |
|
|
* Return : None
|
177 |
|
|
*******************************************************************************/
|
178 |
|
|
void WDG_ITConfig(FunctionalState NewState)
|
179 |
|
|
{
|
180 |
|
|
if(NewState == ENABLE)
|
181 |
|
|
{
|
182 |
|
|
/* Enable the End of Count interrupt */
|
183 |
|
|
WDG->MR |= WDG_IT_EC;
|
184 |
|
|
}
|
185 |
|
|
else
|
186 |
|
|
{
|
187 |
|
|
/* Disable the End of Count interrupt */
|
188 |
|
|
WDG->MR &= ~WDG_IT_EC;
|
189 |
|
|
}
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
/*******************************************************************************
|
193 |
|
|
* Function Name : WDG_GetCounter
|
194 |
|
|
* Description : Gets the WDG’s current counter value.
|
195 |
|
|
* Input : None
|
196 |
|
|
* Output : None
|
197 |
|
|
* Return : The WDG current counter value
|
198 |
|
|
*******************************************************************************/
|
199 |
|
|
u16 WDG_GetCounter(void)
|
200 |
|
|
{
|
201 |
|
|
return WDG->CNT;
|
202 |
|
|
}
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
|
206 |
|
|
|
207 |
|
|
/*******************************************************************************
|
208 |
|
|
* Function Name : WDG_GetITStatus
|
209 |
|
|
* Description : Checks whether the WDG End of Count(EC) interrupt is occured or not.
|
210 |
|
|
* Input : None
|
211 |
|
|
* Output : None
|
212 |
|
|
* Return : The new state of WDG_IT (SET or RESET).
|
213 |
|
|
*******************************************************************************/
|
214 |
|
|
ITStatus WDG_GetITStatus(void)
|
215 |
|
|
{
|
216 |
|
|
if(((WDG->SR & WDG_IT_EC) != RESET )&&((WDG->MR & WDG_IT_EC) != RESET ))
|
217 |
|
|
{
|
218 |
|
|
return SET;
|
219 |
|
|
}
|
220 |
|
|
else
|
221 |
|
|
{
|
222 |
|
|
return RESET;
|
223 |
|
|
}
|
224 |
|
|
}
|
225 |
|
|
|
226 |
|
|
/*******************************************************************************
|
227 |
|
|
* Function Name : WDG_ClearITPendingBit
|
228 |
|
|
* Description : Clears the WDG's End of Count(EC) interrupt pending bit.
|
229 |
|
|
* Input : None
|
230 |
|
|
* Output : None
|
231 |
|
|
* Return : None
|
232 |
|
|
*******************************************************************************/
|
233 |
|
|
void WDG_ClearITPendingBit(void)
|
234 |
|
|
{
|
235 |
|
|
/* Clear the EC pending bit */
|
236 |
|
|
WDG->SR &= ~WDG_IT_EC;
|
237 |
|
|
|
238 |
|
|
}
|
239 |
|
|
|
240 |
|
|
/*******************************************************************************
|
241 |
|
|
* Function Name : WDG_ClearFlag
|
242 |
|
|
* Description : Clears the WDG's End of Count(EC) Flag.
|
243 |
|
|
* Input : None
|
244 |
|
|
* Output : None
|
245 |
|
|
* Return : None
|
246 |
|
|
*******************************************************************************/
|
247 |
|
|
void WDG_ClearFlag(void)
|
248 |
|
|
{
|
249 |
|
|
/* Clear the EC Flag */
|
250 |
|
|
|
251 |
|
|
WDG->SR &= ~WDG_FLAG_EC;
|
252 |
|
|
|
253 |
|
|
}
|
254 |
|
|
|
255 |
|
|
|
256 |
|
|
/*******************************************************************************
|
257 |
|
|
* Function Name : WDG_GetFlagStatus
|
258 |
|
|
* Description : Checks whether the WDG End of Count(EC) flag is set or not.
|
259 |
|
|
* Input : None
|
260 |
|
|
* Output : None
|
261 |
|
|
* Return : The new state of the WDG_FLAG (SET or RESET).
|
262 |
|
|
*******************************************************************************/
|
263 |
|
|
FlagStatus WDG_GetFlagStatus(void)
|
264 |
|
|
{
|
265 |
|
|
if((WDG->SR & WDG_FLAG_EC) != RESET )
|
266 |
|
|
{
|
267 |
|
|
return SET;
|
268 |
|
|
}
|
269 |
|
|
else
|
270 |
|
|
{
|
271 |
|
|
return RESET;
|
272 |
|
|
}
|
273 |
|
|
}
|
274 |
|
|
|
275 |
|
|
|
276 |
|
|
|
277 |
|
|
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
|