Rev 1 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1 | Rev 196 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
1 | /******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** |
2 | * File Name : 91x_wdg.c |
2 | * File Name : 91x_wdg.c |
3 | * Author : MCD Application Team |
3 | * Author : MCD Application Team |
- | 4 | * Version : V2.1 |
|
4 | * Date First Issued : 05/18/2006 : Version 1.0 |
5 | * Date : 12/22/2008 |
5 | * Description : This file provides all the WDG software functions. |
6 | * Description : This file provides all the WDG firmware 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 | ******************************************************************************** |
7 | ******************************************************************************** |
12 | * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
8 | * 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. |
9 | * 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, |
10 | * 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 |
11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE |
Line 42... | Line 38... | ||
42 | /* Private variables ---------------------------------------------------------*/ |
38 | /* Private variables ---------------------------------------------------------*/ |
43 | /* Registers reset value */ |
39 | /* Registers reset value */ |
44 | /* Private function prototypes -----------------------------------------------*/ |
40 | /* Private function prototypes -----------------------------------------------*/ |
45 | /* Private functions ---------------------------------------------------------*/ |
41 | /* Private functions ---------------------------------------------------------*/ |
Line 46... | Line -... | ||
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 | 42 | ||
63 | /******************************************************************************* |
43 | /******************************************************************************* |
64 | * Function Name : WDG_StructInit |
44 | * Function Name : WDG_StructInit |
65 | * Description : Fills the WDG_InitTypeDef structure member with its reset |
45 | * Description : Fills the WDG_InitTypeDef structure member with its reset |
66 | * value. |
46 | * value. |
Line 69... | Line 49... | ||
69 | * Output : None |
49 | * Output : None |
70 | * Return : None |
50 | * Return : None |
71 | *******************************************************************************/ |
51 | *******************************************************************************/ |
72 | void WDG_StructInit(WDG_InitTypeDef *WDG_InitStruct) |
52 | void WDG_StructInit(WDG_InitTypeDef *WDG_InitStruct) |
73 | { |
53 | { |
74 | /* Select the Watchdog running mode*/ |
- | |
75 | WDG_InitStruct->WDG_Mode = WDG_Mode_Timer; |
- | |
Line 76... | Line 54... | ||
76 | 54 | ||
77 | /* Select the source clock */ |
55 | /* Select the source clock */ |
Line 78... | Line 56... | ||
78 | WDG_InitStruct-> WDG_ClockSource = WDG_ClockSource_Apb; |
56 | WDG_InitStruct-> WDG_ClockSource = WDG_ClockSource_Apb; |
Line 109... | Line 87... | ||
109 | { |
87 | { |
110 | /* Select the RTC clock as source */ |
88 | /* Select the RTC clock as source */ |
111 | WDG->CR |= WDG_ClockSource_Rtc ; |
89 | WDG->CR |= WDG_ClockSource_Rtc ; |
112 | } |
90 | } |
Line 113... | Line -... | ||
113 | - | ||
114 | 91 | ||
115 | /* Configure WDG Prescaler register value */ |
92 | /* Configure WDG Prescaler register value */ |
Line 116... | Line 93... | ||
116 | WDG->PR = WDG_InitStruct->WDG_Prescaler; |
93 | WDG->PR = WDG_InitStruct->WDG_Prescaler; |
117 | 94 | ||
Line 118... | Line -... | ||
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 | } |
95 | /* Configure WDG Pre-load register value */ |
Line 132... | Line 96... | ||
132 | 96 | WDG->VR = WDG_InitStruct->WDG_Preload ; |
|
133 | 97 | ||
134 | } |
98 | } |
135 | 99 | ||
136 | /******************************************************************************* |
100 | /******************************************************************************* |
137 | * Function Name : WDG_Cmd |
101 | * Function Name : WDG_TimerModeCmd |
138 | * Description : Enables or disables the WDG peripheral. |
102 | * Description : Enables or disables the WDG timer mode |
139 | * Input : NewState: new state of the WDG peripheral (Newstate can be |
103 | * Input : NewState: new state of the WDG peripheral (Newstate can be |
140 | * ENABLE or DISABLE) |
104 | * ENABLE or DISABLE) |
141 | * Output : None |
105 | * Output : None |
142 | * Return : None |
- | |
143 | *******************************************************************************/ |
- | |
144 | void WDG_Cmd(FunctionalState NewState ) |
- | |
145 | { |
106 | * Return : None |
146 | if((WDG->CR & WDG_Mode_Wdg) == 0) |
107 | *******************************************************************************/ |
147 | { |
108 | void WDG_TimerModeCmd(FunctionalState NewState) |
148 | /* Timer mode */ |
109 | { |
149 | if(NewState == ENABLE) |
110 | if(NewState == ENABLE) |
150 | { |
111 | { |
151 | /* Start timer by setting SC bit in Control register */ |
112 | /* Start timer by setting SC bit in Control register */ |
152 | WDG->CR |= WDG_Counter_Start; |
113 | WDG->CR |= WDG_Counter_Start; |
153 | } |
114 | } |
154 | else |
115 | else |
155 | { |
116 | { |
156 | /* Stop timer by clearning SC bit in Control register */ |
- | |
157 | WDG->CR &= WDG_Counter_Stop; |
117 | /* Stop timer by clearning SC bit in Control register */ |
- | 118 | WDG->CR &= WDG_Counter_Stop; |
|
- | 119 | } |
|
158 | } |
120 | } |
- | 121 | ||
- | 122 | /******************************************************************************* |
|
159 | } |
123 | * Function Name : WDG_StartWatchdogMode |
- | 124 | * Description : Starts the watchdog mode |
|
- | 125 | * Input : None |
|
160 | else |
126 | * Output : None |
- | 127 | * Return : None |
|
161 | { |
128 | *******************************************************************************/ |
162 | /* Watchdog mode */ |
129 | void WDG_StartWatchdogMode(void) |
163 | if(NewState == ENABLE) |
- | |
164 | { |
130 | { |
- | 131 | /*reload watchdog*/ |
|
- | 132 | WDG->KR = WDG_KeyValue1; |
|
165 | WDG->KR = WDG_KeyValue1; |
133 | WDG->KR = WDG_KeyValue2; |
Line 166... | Line 134... | ||
166 | WDG->KR = WDG_KeyValue2; |
134 | |
167 | } |
135 | /*start watchdog*/ |
168 | } |
136 | WDG->CR |= WDG_Mode_Wdg; |
Line 200... | Line 168... | ||
200 | u16 WDG_GetCounter(void) |
168 | u16 WDG_GetCounter(void) |
201 | { |
169 | { |
202 | return WDG->CNT; |
170 | return WDG->CNT; |
203 | } |
171 | } |
Line 204... | Line -... | ||
204 | - | ||
205 | - | ||
206 | - | ||
207 | 172 | ||
208 | /******************************************************************************* |
173 | /******************************************************************************* |
209 | * Function Name : WDG_GetITStatus |
174 | * Function Name : WDG_GetITStatus |
210 | * Description : Checks whether the WDG End of Count(EC) interrupt is occured or not. |
175 | * Description : Checks whether the WDG End of Count(EC) interrupt is occured or not. |
211 | * Input : None |
176 | * Input : None |
Line 248... | Line 213... | ||
248 | void WDG_ClearFlag(void) |
213 | void WDG_ClearFlag(void) |
249 | { |
214 | { |
250 | /* Clear the EC Flag */ |
215 | /* Clear the EC Flag */ |
Line 251... | Line 216... | ||
251 | 216 | ||
252 | WDG->SR &= ~WDG_FLAG_EC; |
- | |
253 | 217 | WDG->SR &= ~WDG_FLAG_EC; |
|
Line 254... | Line -... | ||
254 | } |
- | |
255 | 218 | } |
|
256 | 219 | ||
257 | /******************************************************************************* |
220 | /******************************************************************************* |
258 | * Function Name : WDG_GetFlagStatus |
221 | * Function Name : WDG_GetFlagStatus |
259 | * Description : Checks whether the WDG End of Count(EC) flag is set or not. |
222 | * Description : Checks whether the WDG End of Count(EC) flag is set or not. |
Line 271... | Line 234... | ||
271 | { |
234 | { |
272 | return RESET; |
235 | return RESET; |
273 | } |
236 | } |
274 | } |
237 | } |
Line -... | Line 238... | ||
- | 238 | ||
- | 239 | /******************************************************************************* |
|
- | 240 | * Function Name : WDG_Reload |
|
- | 241 | * Description : reloads the watchdog counter in watchdog mode |
|
- | 242 | * Input : None |
|
- | 243 | * Output : None |
|
- | 244 | * Return : none |
|
- | 245 | *******************************************************************************/ |
|
- | 246 | void WDG_Reload(void) |
|
- | 247 | { |
|
- | 248 | WDG->KR = WDG_KeyValue1; |
|
- | 249 | WDG->KR = WDG_KeyValue2; |
|
Line 275... | Line 250... | ||
275 | 250 | } |