Rev 1 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1 | Rev 196 | ||
---|---|---|---|
1 | /******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
1 | /******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** |
2 | * File Name : 91x_rtc.c |
2 | * File Name : 91x_rtc.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 the RTC library software functions |
6 | * Description : This file provides the RTC library 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 WITH |
8 | * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH |
13 | * CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS |
9 | * CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS |
14 | * A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT |
10 | * A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT |
15 | * OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT |
11 | * OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT |
16 | * OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION |
12 | * OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION |
17 | * CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
13 | * CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
18 | *******************************************************************************/ |
14 | *******************************************************************************/ |
19 | 15 | ||
20 | /* Includes ------------------------------------------------------------------*/ |
16 | /* Includes ------------------------------------------------------------------*/ |
21 | #include "91x_rtc.h" |
17 | #include "91x_rtc.h" |
22 | #include "91x_scu.h" |
18 | #include "91x_scu.h" |
23 | 19 | ||
24 | /* Include of other module interface headers ---------------------------------*/ |
20 | /* Include of other module interface headers ---------------------------------*/ |
25 | /* Local includes ------------------------------------------------------------*/ |
21 | /* Local includes ------------------------------------------------------------*/ |
26 | /* Private typedef -----------------------------------------------------------*/ |
22 | /* Private typedef -----------------------------------------------------------*/ |
27 | /* Private define ------------------------------------------------------------*/ |
23 | /* Private define ------------------------------------------------------------*/ |
28 | /* Private macro -------------------------------------------------------------*/ |
24 | /* Private macro -------------------------------------------------------------*/ |
29 | /* Private variables ---------------------------------------------------------*/ |
25 | /* Private variables ---------------------------------------------------------*/ |
30 | /* Private function prototypes -----------------------------------------------*/ |
26 | /* Private function prototypes -----------------------------------------------*/ |
31 | u8 BYTEToBCD2(u8 value); |
27 | u8 BYTEToBCD2(u8 value); |
32 | u16 WORDToBCD3(u16 value); |
28 | u16 WORDToBCD3(u16 value); |
33 | u8 BCD2ToBYTE(u8 value); |
29 | u8 BCD2ToBYTE(u8 value); |
34 | u16 BCD3ToBYTE(u16 value); |
30 | u16 BCD3ToBYTE(u16 value); |
35 | /* Interface functions -------------------------------------------------------*/ |
31 | /* Interface functions -------------------------------------------------------*/ |
36 | /* Private functions ---------------------------------------------------------*/ |
32 | /* Private functions ---------------------------------------------------------*/ |
37 | 33 | ||
38 | /******************************************************************************* |
34 | /******************************************************************************* |
39 | * Function Name : BYTEToBCD2 |
35 | * Function Name : BYTEToBCD2 |
40 | * Description : Converts a 2 digit decimal to BCD format |
36 | * Description : Converts a 2 digit decimal to BCD format |
41 | * Input : None |
37 | * Input : None |
42 | * Output : None |
38 | * Output : None |
43 | * Return : Converted byte |
39 | * Return : Converted byte |
44 | *******************************************************************************/ |
40 | *******************************************************************************/ |
45 | u8 BYTEToBCD2(u8 value) |
41 | u8 BYTEToBCD2(u8 value) |
46 | { |
42 | { |
47 | u8 bcdhigh = 0; |
43 | u8 bcdhigh = 0; |
48 | while (value >= 10) |
44 | while (value >= 10) |
49 | { |
45 | { |
50 | bcdhigh++; |
46 | bcdhigh++; |
51 | value -= 10; |
47 | value -= 10; |
52 | } |
48 | } |
53 | return (bcdhigh << 4) | value; |
49 | return (bcdhigh << 4) | value; |
54 | } |
50 | } |
55 | /******************************************************************************* |
51 | /******************************************************************************* |
56 | * Function Name : WORDToBCD3 |
52 | * Function Name : WORDToBCD3 |
57 | * Description : Converts a 3 digit decimal to BCD format |
53 | * Description : Converts a 3 digit decimal to BCD format |
58 | * Input : None |
54 | * Input : None |
59 | * Output : None |
55 | * Output : None |
60 | * Return : Converted word |
56 | * Return : Converted word |
61 | *******************************************************************************/ |
57 | *******************************************************************************/ |
62 | u16 WORDToBCD3(u16 value) |
58 | u16 WORDToBCD3(u16 value) |
63 | { |
59 | { |
64 | u16 bcdhigh = 0; |
60 | u16 bcdhigh = 0; |
65 | while (value >= 100) |
61 | while (value >= 100) |
66 | { |
62 | { |
67 | bcdhigh++; |
63 | bcdhigh++; |
68 | value -= 100; |
64 | value -= 100; |
69 | } |
65 | } |
70 | bcdhigh <<= 4; |
66 | bcdhigh <<= 4; |
71 | while (value >= 10) |
67 | while (value >= 10) |
72 | { |
68 | { |
73 | bcdhigh++; |
69 | bcdhigh++; |
74 | value -= 10; |
70 | value -= 10; |
75 | } |
71 | } |
76 | return (bcdhigh << 4) | value; |
72 | return (bcdhigh << 4) | value; |
77 | } |
73 | } |
78 | 74 | ||
79 | /******************************************************************************* |
75 | /******************************************************************************* |
80 | * Function Name : BCD3ToWORD |
76 | * Function Name : BCD3ToWORD |
81 | * Description : convert from 3 digit BCD to Binary |
77 | * Description : convert from 3 digit BCD to Binary |
82 | * Input : None |
78 | * Input : None |
83 | * Output : None |
79 | * Output : None |
84 | * Return : Converted word |
80 | * Return : Converted word |
85 | *******************************************************************************/ |
81 | *******************************************************************************/ |
86 | u16 BCD3ToWORD(u16 value) |
82 | u16 BCD3ToWORD(u16 value) |
87 | { |
83 | { |
88 | return (u16)((((value&0xF00)>>8)*100) + (((value&0x0F0)>>4)*10) + (value&0x0F)); |
84 | return (u16)((((value&0xF00)>>8)*100) + (((value&0x0F0)>>4)*10) + (value&0x0F)); |
89 | } |
85 | } |
90 | 86 | ||
91 | /******************************************************************************* |
87 | /******************************************************************************* |
92 | * Function Name : BCD2ToBYTE |
88 | * Function Name : BCD2ToBYTE |
93 | * Description : convert from 2 digit BCD to Binary |
89 | * Description : convert from 2 digit BCD to Binary |
94 | * Input : None |
90 | * Input : None |
95 | * Output : None |
91 | * Output : None |
96 | * Return : Converted word |
92 | * Return : Converted word |
97 | *******************************************************************************/ |
93 | *******************************************************************************/ |
98 | u8 BCD2ToBYTE(u8 value) |
94 | u8 BCD2ToBYTE(u8 value) |
99 | { |
95 | { |
100 | u32 tmp; |
96 | u32 tmp; |
101 | tmp= ((value&0xF0)>>4)*10; |
97 | tmp= ((value&0xF0)>>4)*10; |
102 | return (u8)(tmp+ (value&0x0F)); |
98 | return (u8)(tmp+ (value&0x0F)); |
103 | } |
99 | } |
104 | 100 | ||
105 | /******************************************************************************* |
101 | /******************************************************************************* |
106 | * Function Name : RTC_DeInit |
102 | * Function Name : RTC_DeInit |
107 | * Description : Resets the RTC peripheral registers |
103 | * Description : Resets the RTC peripheral registers |
108 | * Input : None |
104 | * Input : None |
109 | * Output : None |
105 | * Output : None |
110 | * Return : None |
106 | * Return : None |
111 | *******************************************************************************/ |
107 | *******************************************************************************/ |
112 | void RTC_DeInit(void) |
108 | void RTC_DeInit(void) |
113 | { |
109 | { |
114 | SCU_APBPeriphReset(__RTC,ENABLE); |
110 | SCU_APBPeriphReset(__RTC,ENABLE); |
115 | SCU_APBPeriphReset(__RTC,DISABLE); |
111 | SCU_APBPeriphReset(__RTC,DISABLE); |
116 | } |
112 | } |
117 | 113 | ||
118 | /******************************************************************************* |
114 | /******************************************************************************* |
119 | * Function Name : RTC_SetDate |
115 | * Function Name : RTC_SetDate |
120 | * Description : Sets the Date register |
116 | * Description : Sets the Date register |
121 | * Input : struct of type RTC_DATE |
117 | * Input : struct of type RTC_DATE |
122 | * Output : None |
118 | * Output : None |
123 | * Return : None |
119 | * Return : None |
124 | *******************************************************************************/ |
120 | *******************************************************************************/ |
125 | void RTC_SetDate(RTC_DATE Date) |
121 | void RTC_SetDate(RTC_DATE Date) |
126 | { |
122 | { |
127 | u32 tmp = 0; |
123 | u32 tmp = 0; |
128 | 124 | ||
129 | RTC->CR |=0x80; /*Enable write operation in DTR register*/ |
125 | RTC->CR |=0x80; /*Enable write operation in DTR register*/ |
130 | RTC->DTR = 0; |
126 | RTC->DTR = 0; |
131 | tmp = BYTEToBCD2(Date.century); |
127 | tmp = BYTEToBCD2(Date.century); |
132 | RTC->DTR|=tmp<<24; |
128 | RTC->DTR|=tmp<<24; |
133 | tmp = BYTEToBCD2(Date.year); |
129 | tmp = BYTEToBCD2(Date.year); |
134 | RTC->DTR|=tmp<<16; |
130 | RTC->DTR|=tmp<<16; |
135 | tmp = BYTEToBCD2(Date.month); |
131 | tmp = BYTEToBCD2(Date.month); |
136 | RTC->DTR|=tmp<<8; |
132 | RTC->DTR|=tmp<<8; |
137 | tmp = BYTEToBCD2(Date.weekday); |
133 | tmp = BYTEToBCD2(Date.weekday); |
138 | RTC->DTR|=tmp; |
134 | RTC->DTR|=tmp; |
139 | RTC->TR &=0xFFFFFF; |
135 | RTC->TR &=0xFFFFFF; |
140 | tmp = BYTEToBCD2(Date.day); |
136 | tmp = BYTEToBCD2(Date.day); |
141 | RTC->TR|=tmp<<24; |
137 | RTC->TR|=tmp<<24; |
142 | RTC->CR &=~0x80; /*Disable write operation in DTR register*/ |
138 | RTC->CR &=~0x80; /*Disable write operation in DTR register*/ |
143 | } |
139 | } |
144 | /******************************************************************************* |
140 | /******************************************************************************* |
145 | * Function Name : RTC_SetTime |
141 | * Function Name : RTC_SetTime |
146 | * Description : Sets the Time register |
142 | * Description : Sets the Time register |
147 | * Input : struct of type RTC_TIME |
143 | * Input : struct of type RTC_TIME |
148 | * Output : None |
144 | * Output : None |
149 | * Return : None |
145 | * Return : None |
150 | *******************************************************************************/ |
146 | *******************************************************************************/ |
151 | void RTC_SetTime(RTC_TIME Time) |
147 | void RTC_SetTime(RTC_TIME Time) |
152 | { |
148 | { |
153 | u32 tmp = 0; |
149 | u32 tmp = 0; |
154 | 150 | ||
155 | RTC->CR |=0x80; /*Enable write operation in TR register*/ |
151 | RTC->CR |=0x80; /*Enable write operation in TR register*/ |
156 | RTC->TR &= 0xFF000000; |
152 | RTC->TR &= 0xFF000000; |
157 | tmp = BYTEToBCD2(Time.hours); |
153 | tmp = BYTEToBCD2(Time.hours); |
158 | RTC->TR|=tmp<<16; |
154 | RTC->TR|=tmp<<16; |
159 | tmp = BYTEToBCD2(Time.minutes); |
155 | tmp = BYTEToBCD2(Time.minutes); |
160 | RTC->TR|=tmp<<8; |
156 | RTC->TR|=tmp<<8; |
161 | tmp = BYTEToBCD2(Time.seconds); |
157 | tmp = BYTEToBCD2(Time.seconds); |
162 | RTC->TR|=tmp; |
158 | RTC->TR|=tmp; |
163 | RTC->MILR = 0; |
159 | RTC->MILR = 0; |
164 | RTC->MILR |= WORDToBCD3(Time.milliseconds); |
160 | RTC->MILR |= WORDToBCD3(Time.milliseconds); |
165 | RTC->CR &=~0x80; /*Disable write operation in TR register*/ |
161 | RTC->CR &=~0x80; /*Disable write operation in TR register*/ |
166 | } |
162 | } |
167 | /******************************************************************************* |
163 | /******************************************************************************* |
168 | * Function Name : RTC_SetAlarm |
164 | * Function Name : RTC_SetAlarm |
169 | * Description : Sets the Alarm register |
165 | * Description : Sets the Alarm register |
170 | * Input : Struct of type RTC_ALARM |
166 | * Input : Struct of type RTC_ALARM |
171 | * Output : Date |
167 | * Output : Date |
172 | * Return : None |
168 | * Return : None |
173 | *******************************************************************************/ |
169 | *******************************************************************************/ |
174 | void RTC_SetAlarm(RTC_ALARM Alarm) |
170 | void RTC_SetAlarm(RTC_ALARM Alarm) |
175 | { |
171 | { |
176 | u32 tmp = 0; |
172 | u32 tmp = 0; |
177 | 173 | ||
178 | RTC->CR |=0x80; /*Enable write operation in ATR register*/ |
174 | RTC->CR |=0x80; /*Enable write operation in ATR register*/ |
179 | RTC->ATR = 0; |
175 | RTC->ATR = 0; |
180 | tmp = BYTEToBCD2(Alarm.day); |
176 | tmp = BYTEToBCD2(Alarm.day); |
181 | RTC->ATR|=tmp<<24; |
177 | RTC->ATR|=tmp<<24; |
182 | tmp = BYTEToBCD2(Alarm.hours); |
178 | tmp = BYTEToBCD2(Alarm.hours); |
183 | RTC->ATR|=tmp<<16; |
179 | RTC->ATR|=tmp<<16; |
184 | tmp = BYTEToBCD2(Alarm.minutes); |
180 | tmp = BYTEToBCD2(Alarm.minutes); |
185 | RTC->ATR|=tmp<<8; |
181 | RTC->ATR|=tmp<<8; |
186 | tmp = BYTEToBCD2(Alarm.seconds); |
182 | tmp = BYTEToBCD2(Alarm.seconds); |
187 | RTC->ATR|=tmp; |
183 | RTC->ATR|=tmp; |
188 | RTC->CR &=~0x80; /*Disable write operation in ATR register*/ |
184 | RTC->CR &=~0x80; /*Disable write operation in ATR register*/ |
189 | } |
185 | } |
190 | 186 | ||
191 | /******************************************************************************* |
187 | /******************************************************************************* |
192 | * Function Name : RTC_GetDate |
188 | * Function Name : RTC_GetDate |
193 | * Description : Gets RTC date in BCD coded or BINARY code |
189 | * Description : Gets RTC date in BCD coded or BINARY code |
194 | * Input : -Format: BCD or BINARY |
190 | * Input : -Format: BCD or BINARY |
195 | * -Date: pointer to structure of type RTC_DATE to be filled by function |
191 | * -Date: pointer to structure of type RTC_DATE to be filled by function |
196 | * Output : None |
192 | * Output : None |
197 | * Return : None |
193 | * Return : None |
198 | *******************************************************************************/ |
194 | *******************************************************************************/ |
199 | void RTC_GetDate(u8 Format, RTC_DATE * Date) |
195 | void RTC_GetDate(u8 Format, RTC_DATE * Date) |
200 | { |
196 | { |
201 | Date->century = (u8)((RTC->DTR&0xFF000000)>>24); |
197 | Date->century = (u8)((RTC->DTR&0xFF000000)>>24); |
202 | Date->year = (u8)((RTC->DTR&0x00FF0000)>>16); |
198 | Date->year = (u8)((RTC->DTR&0x00FF0000)>>16); |
203 | Date->month = (u8)((RTC->DTR&0x00001F00)>>8); |
199 | Date->month = (u8)((RTC->DTR&0x00001F00)>>8); |
204 | Date->day = (u8)((RTC->TR&0x3F000000)>>24); |
200 | Date->day = (u8)((RTC->TR&0x3F000000)>>24); |
205 | Date->weekday = (u8)(RTC->DTR&0xF); |
201 | Date->weekday = (u8)(RTC->DTR&0xF); |
206 | if (Format == BINARY) |
202 | if (Format == BINARY) |
207 | { |
203 | { |
208 | Date->century = BCD2ToBYTE(Date->century); |
204 | Date->century = BCD2ToBYTE(Date->century); |
209 | Date->year = BCD2ToBYTE(Date->year); |
205 | Date->year = BCD2ToBYTE(Date->year); |
210 | Date->month = BCD2ToBYTE(Date->month); |
206 | Date->month = BCD2ToBYTE(Date->month); |
211 | Date->day = BCD2ToBYTE(Date->day); |
207 | Date->day = BCD2ToBYTE(Date->day); |
212 | Date->weekday = BCD2ToBYTE(Date->weekday); |
208 | Date->weekday = BCD2ToBYTE(Date->weekday); |
213 | } |
209 | } |
214 | } |
210 | } |
215 | 211 | ||
216 | /******************************************************************************* |
212 | /******************************************************************************* |
217 | * Function Name : RTC_GetTime |
213 | * Function Name : RTC_GetTime |
218 | * Description : Gets TIME in BCD coded or BINARY code |
214 | * Description : Gets TIME in BCD coded or BINARY code |
219 | * Input : -Format: BCD or BINARY |
215 | * Input : -Format: BCD or BINARY |
220 | * -Time : pointer to structure of type RTC_TIME to be filled by function |
216 | * -Time : pointer to structure of type RTC_TIME to be filled by function |
221 | * Output : Time |
217 | * Output : Time |
222 | * Return : None |
218 | * Return : None |
223 | *******************************************************************************/ |
219 | *******************************************************************************/ |
224 | void RTC_GetTime(u8 Format, RTC_TIME * Time) |
220 | void RTC_GetTime(u8 Format, RTC_TIME * Time) |
225 | { |
221 | { |
226 | 222 | ||
227 | Time->hours = (u8)((RTC->TR&0x003F0000)>>16); |
223 | Time->hours = (u8)((RTC->TR&0x003F0000)>>16); |
228 | Time->minutes = (u8)((RTC->TR&0x00007F00)>>8); |
224 | Time->minutes = (u8)((RTC->TR&0x00007F00)>>8); |
229 | Time->seconds = (u8)(RTC->TR&0x7F); |
225 | Time->seconds = (u8)(RTC->TR&0x7F); |
230 | Time->milliseconds =(u16)(RTC->MILR&0xFFF); |
226 | Time->milliseconds =(u16)(RTC->MILR&0xFFF); |
231 | if (Format == BINARY) |
227 | if (Format == BINARY) |
232 | { |
228 | { |
233 | Time->hours = BCD2ToBYTE(Time->hours); |
229 | Time->hours = BCD2ToBYTE(Time->hours); |
234 | Time->minutes = BCD2ToBYTE(Time->minutes); |
230 | Time->minutes = BCD2ToBYTE(Time->minutes); |
235 | Time->seconds = BCD2ToBYTE(Time->seconds); |
231 | Time->seconds = BCD2ToBYTE(Time->seconds); |
236 | Time->milliseconds = BCD3ToWORD(Time->milliseconds); |
232 | Time->milliseconds = BCD3ToWORD(Time->milliseconds); |
237 | } |
233 | } |
238 | } |
234 | } |
239 | 235 | ||
240 | 236 | ||
241 | /******************************************************************************* |
237 | /******************************************************************************* |
242 | * Function Name : RTC_GetAlarm |
238 | * Function Name : RTC_GetAlarm |
243 | * Description : Gets the RTC Alarm in BCD or BINARY code |
239 | * Description : Gets the RTC Alarm in BCD or BINARY code |
244 | * Input : -Format: BCD or BINARY |
240 | * Input : -Format: BCD or BINARY |
245 | * -Alarm : pointer to structure of type RTC_ALARM to be filled by function |
241 | * -Alarm : pointer to structure of type RTC_ALARM to be filled by function |
246 | * Output : Alarm |
242 | * Output : Alarm |
247 | * Return : None |
243 | * Return : None |
248 | *******************************************************************************/ |
244 | *******************************************************************************/ |
249 | void RTC_GetAlarm(u8 Format,RTC_ALARM * Alarm) |
245 | void RTC_GetAlarm(u8 Format,RTC_ALARM * Alarm) |
250 | { |
246 | { |
251 | Alarm->day = (u8)((RTC->ATR&0x3F000000)>>24); |
247 | Alarm->day = (u8)((RTC->ATR&0x3F000000)>>24); |
252 | Alarm->hours = (u8)((RTC->ATR&0x003F0000)>>16); |
248 | Alarm->hours = (u8)((RTC->ATR&0x003F0000)>>16); |
253 | Alarm->minutes = (u8)((RTC->ATR&0x00007F00)>>8); |
249 | Alarm->minutes = (u8)((RTC->ATR&0x00007F00)>>8); |
254 | Alarm->seconds = (u8)((RTC->ATR)&0x7F); |
250 | Alarm->seconds = (u8)((RTC->ATR)&0x7F); |
255 | if (Format == BINARY) |
251 | if (Format == BINARY) |
256 | { |
252 | { |
257 | Alarm->day = BCD2ToBYTE(Alarm->day); |
253 | Alarm->day = BCD2ToBYTE(Alarm->day); |
258 | Alarm->hours = BCD2ToBYTE(Alarm->hours); |
254 | Alarm->hours = BCD2ToBYTE(Alarm->hours); |
259 | Alarm->minutes = BCD2ToBYTE(Alarm->minutes); |
255 | Alarm->minutes = BCD2ToBYTE(Alarm->minutes); |
260 | Alarm->seconds = BCD2ToBYTE(Alarm->seconds); |
256 | Alarm->seconds = BCD2ToBYTE(Alarm->seconds); |
261 | } |
257 | } |
262 | } |
258 | } |
263 | 259 | ||
264 | /******************************************************************************* |
260 | /******************************************************************************* |
265 | * Function Name : RTC_TamperConfig |
261 | * Function Name : RTC_TamperConfig |
266 | * Description : configures the Tamper mode and tamper polarity |
262 | * Description : configures the Tamper mode and tamper polarity |
267 | * Input : -TamperMode: RTC_TamperMode_Edge or RTC_TamperMode_Level |
263 | * Input : -TamperMode: RTC_TamperMode_Edge or RTC_TamperMode_Level |
268 | * -TamperPol : RTC_TamperPol_Low or RTC_TamperMode_High |
264 | * -TamperPol : RTC_TamperPol_Low or RTC_TamperMode_High |
269 | * Output : None |
265 | * Output : None |
270 | * Return : None |
266 | * Return : None |
271 | *******************************************************************************/ |
267 | *******************************************************************************/ |
272 | void RTC_TamperConfig(u32 TamperMode, u32 TamperPol) |
268 | void RTC_TamperConfig(u32 TamperMode, u32 TamperPol) |
273 | { |
269 | { |
274 | RTC->CR&=RTC_TamperMode_Edge; |
270 | RTC->CR&=RTC_TamperMode_Edge; |
275 | if (TamperMode!=RTC_TamperMode_Edge) |
271 | if (TamperMode!=RTC_TamperMode_Edge) |
276 | RTC->CR|=RTC_TamperMode_Level; |
272 | RTC->CR|=RTC_TamperMode_Level; |
277 | 273 | ||
278 | RTC->CR&=RTC_TamperPol_Low; |
274 | RTC->CR&=RTC_TamperPol_Low; |
279 | if (TamperPol!=RTC_TamperPol_Low) |
275 | if (TamperPol!=RTC_TamperPol_Low) |
280 | RTC->CR|=RTC_TamperPol_High; |
276 | RTC->CR|=RTC_TamperPol_High; |
281 | } |
277 | } |
282 | 278 | ||
283 | /******************************************************************************* |
279 | /******************************************************************************* |
284 | * Function Name : RTC_TamperCmd |
280 | * Function Name : RTC_TamperCmd |
285 | * Description : Enable or Disable Tamper |
281 | * Description : Enable or Disable Tamper |
286 | * Input : NewState: ENABLE or DISABLE |
282 | * Input : NewState: ENABLE or DISABLE |
287 | * Output : None |
283 | * Output : None |
288 | * Return : None |
284 | * Return : None |
289 | *******************************************************************************/ |
285 | *******************************************************************************/ |
290 | void RTC_TamperCmd(FunctionalState NewState) |
286 | void RTC_TamperCmd(FunctionalState NewState) |
291 | { |
287 | { |
292 | RTC->CR&=0xFFFFFFFE; |
288 | RTC->CR&=0xFFFFFFFE; |
293 | if (NewState==ENABLE) |
289 | if (NewState==ENABLE) |
294 | RTC->CR|=0x1; |
290 | RTC->CR|=0x1; |
295 | } |
291 | } |
296 | 292 | ||
297 | /******************************************************************************* |
293 | /******************************************************************************* |
298 | * Function Name : RTC_AlarmCmd |
294 | * Function Name : RTC_AlarmCmd |
299 | * Description : Enable or Disable Alarm |
295 | * Description : Enable or Disable Alarm |
300 | * Input : NewState: ENABLE or DISABLE |
296 | * Input : NewState: ENABLE or DISABLE |
301 | * Output : None |
297 | * Output : None |
302 | * Return : None |
298 | * Return : None |
303 | *******************************************************************************/ |
299 | *******************************************************************************/ |
304 | void RTC_AlarmCmd(FunctionalState NewState) |
300 | void RTC_AlarmCmd(FunctionalState NewState) |
305 | { |
301 | { |
306 | RTC->CR&=~0x100000; |
302 | RTC->CR&=~0x100000; |
307 | if (NewState==ENABLE) |
303 | if (NewState==ENABLE) |
308 | RTC->CR|=0x100000; |
304 | RTC->CR|=0x100000; |
309 | } |
305 | } |
310 | 306 | ||
311 | /******************************************************************************* |
307 | /******************************************************************************* |
312 | * Function Name : RTC_CalibClockCmd |
308 | * Function Name : RTC_CalibClockCmd |
313 | * Description : Enable or Disable RTC Calibration Clock Output |
309 | * Description : Enable or Disable RTC Calibration Clock Output |
314 | * Input : NewState: ENABLE or DISABLE |
310 | * Input : NewState: ENABLE or DISABLE |
315 | * Output : None |
311 | * Output : None |
316 | * Return : None |
312 | * Return : None |
317 | *******************************************************************************/ |
313 | *******************************************************************************/ |
318 | void RTC_CalibClockCmd(FunctionalState NewState) |
314 | void RTC_CalibClockCmd(FunctionalState NewState) |
319 | { |
315 | { |
320 | RTC->CR&=~0x40; |
316 | RTC->CR&=~0x40; |
321 | if (NewState ==ENABLE) |
317 | if (NewState ==ENABLE) |
322 | RTC->CR|=0x40; |
318 | RTC->CR|=0x40; |
323 | } |
319 | } |
324 | 320 | ||
325 | /******************************************************************************* |
321 | /******************************************************************************* |
326 | * Function Name : SRAMBattPowerCmd |
322 | * Function Name : SRAMBattPowerCmd |
327 | * Description : Enable or Disable SRAM backup Power by VBATT |
323 | * Description : Enable or Disable SRAM backup Power by VBATT |
328 | * Input : NewState : ENABLE or DISABLE |
324 | * Input : NewState : ENABLE or DISABLE |
329 | * Output : None |
325 | * Output : None |
330 | * Return : None |
326 | * Return : None |
331 | *******************************************************************************/ |
327 | *******************************************************************************/ |
332 | void RTC_SRAMBattPowerCmd(FunctionalState NewState) |
328 | void RTC_SRAMBattPowerCmd(FunctionalState NewState) |
333 | { |
329 | { |
334 | RTC->CR&=~0x8; |
330 | RTC->CR&=~0x8; |
335 | if (NewState ==ENABLE) |
331 | if (NewState ==ENABLE) |
336 | RTC->CR|=0x8; |
332 | RTC->CR|=0x8; |
337 | } |
333 | } |
338 | 334 | ||
339 | /******************************************************************************* |
335 | /******************************************************************************* |
340 | * Function Name : RTC_PeridicIntConfig |
336 | * Function Name : RTC_PeridicIntConfig |
341 | * Description : Select a Periodic CLock |
337 | * Description : Select a Periodic CLock |
342 | * Input : PeriodicClock |
338 | * Input : PeriodicClock |
343 | * Output : None |
339 | * Output : None |
344 | * Return : None |
340 | * Return : None |
345 | * Note : When PeriodicClock = RTC_Per_DISABLE the Periodic clock generation |
341 | * Note : When PeriodicClock = RTC_Per_DISABLE the Periodic clock generation |
346 | * will be disabled. |
342 | * will be disabled. |
347 | *******************************************************************************/ |
343 | *******************************************************************************/ |
348 | void RTC_PeriodicIntConfig(u32 PeriodicClock) |
344 | void RTC_PeriodicIntConfig(u32 PeriodicClock) |
349 | { |
345 | { |
350 | RTC->CR &=~0xF0000; |
346 | RTC->CR &=~0xF0000; |
351 | RTC->CR|=PeriodicClock; |
347 | RTC->CR|=PeriodicClock; |
352 | } |
348 | } |
353 | 349 | ||
354 | /******************************************************************************* |
350 | /******************************************************************************* |
355 | * Function Name : RTC_ITConfig |
351 | * Function Name : RTC_ITConfig |
356 | * Description : Enable or Disable an interrupt |
352 | * Description : Enable or Disable an interrupt |
357 | * Input : -RTC_IT : RTC interrupt |
353 | * Input : -RTC_IT : RTC interrupt |
358 | * -Newstate: Enable or Disable |
354 | * -Newstate: Enable or Disable |
359 | * Output : None |
355 | * Output : None |
360 | * Return : None |
356 | * Return : None |
361 | *******************************************************************************/ |
357 | *******************************************************************************/ |
362 | void RTC_ITConfig(u32 RTC_IT, FunctionalState NewState) |
358 | void RTC_ITConfig(u32 RTC_IT, FunctionalState NewState) |
363 | { |
359 | { |
364 | RTC->CR&=~RTC_IT; |
360 | RTC->CR&=~RTC_IT; |
365 | if (NewState==ENABLE) |
361 | if (NewState==ENABLE) |
366 | RTC->CR|=RTC_IT; |
362 | RTC->CR|=RTC_IT; |
367 | } |
363 | } |
368 | 364 | ||
369 | /******************************************************************************* |
365 | /******************************************************************************* |
370 | * Function Name : RTC_GetFlagStatus |
366 | * Function Name : RTC_GetFlagStatus |
371 | * Description : Gets a RTC flag status |
367 | * Description : Gets a RTC flag status |
372 | * Input : RTC_FLAG |
368 | * Input : RTC_FLAG |
373 | * Output : None |
369 | * Output : None |
374 | * Return : FlagStatus :SET or RESET |
370 | * Return : FlagStatus :SET or RESET |
375 | *******************************************************************************/ |
371 | *******************************************************************************/ |
376 | FlagStatus RTC_GetFlagStatus(u32 RTC_FLAG) |
372 | FlagStatus RTC_GetFlagStatus(u32 RTC_FLAG) |
377 | { |
373 | { |
378 | if (RTC->SR&RTC_FLAG) return SET; |
374 | if (RTC->SR&RTC_FLAG) return SET; |
379 | else return RESET; |
375 | else return RESET; |
380 | } |
376 | } |
381 | 377 | ||
382 | /******************************************************************************* |
378 | /******************************************************************************* |
383 | * Function Name : RTC_ClearFlag |
379 | * Function Name : RTC_ClearFlag |
384 | * Description : Clears a RTC flag |
380 | * Description : Clears a RTC flag |
385 | * Input : RTC_FLAG |
381 | * Input : RTC_FLAG |
386 | * Output : None |
382 | * Output : None |
387 | * Return : None |
383 | * Return : None |
388 | * Note : Before clearing the RTC Periodic Flag you need to disable the |
384 | * Note : Before clearing the RTC Periodic Flag you need to disable the |
389 | * Periodic interrupt generation, to do this use function |
385 | * Periodic interrupt generation, to do this use function |
390 | * RTC_PeriodicIntConfig(RTC_Per_DISABLE) |
386 | * RTC_PeriodicIntConfig(RTC_Per_DISABLE) |
391 | *******************************************************************************/ |
387 | *******************************************************************************/ |
392 | void RTC_ClearFlag(u32 RTC_FLAG) |
388 | void RTC_ClearFlag(u32 RTC_FLAG) |
393 | { |
389 | { |
394 | vu32 tmp=0; |
390 | vu32 tmp=0; |
395 | if (RTC_FLAG == RTC_FLAG_Per) tmp=RTC->SR; |
391 | if (RTC_FLAG == RTC_FLAG_Per) tmp=RTC->SR; |
396 | else if (RTC_FLAG == RTC_FLAG_Alarm) RTC->CR&=~0x100000; |
392 | else if (RTC_FLAG == RTC_FLAG_Alarm) RTC->CR&=~0x100000; |
397 | else if (RTC_FLAG == RTC_FLAG_Tamper) RTC->CR&=~0x1; |
393 | else if (RTC_FLAG == RTC_FLAG_Tamper) RTC->CR&=~0x1; |
398 | } |
394 | } |
399 | 395 | ||
400 | 396 | ||
401 | /******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ |
397 | /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/ |
402 | 398 |