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