]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A5_SAMA5D2x_Xplained_IAR/AtmelFiles/drivers/peripherals/rtc.h
Add SAMA5D2 Xplained IAR demo.
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D2x_Xplained_IAR / AtmelFiles / drivers / peripherals / rtc.h
1 /* ----------------------------------------------------------------------------\r
2  *         SAM Software Package License\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2011, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\r
8  * Redistribution and use in source and binary forms, with or without\r
9  * modification, are permitted provided that the following conditions are met:\r
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\r
14  * Atmel's name may not be used to endorse or promote products derived from\r
15  * this software without specific prior written permission.\r
16  *\r
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR\r
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,\r
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
27  * ----------------------------------------------------------------------------\r
28  */\r
29 \r
30 /**\r
31  * \file\r
32  *\r
33  * Interface for Real Time Clock (RTC) controller.\r
34  *\r
35  */\r
36 \r
37 #ifndef _RTC_H_\r
38 #define _RTC_H_\r
39 \r
40 /*----------------------------------------------------------------------------\r
41  *        Headers\r
42  *----------------------------------------------------------------------------*/\r
43 \r
44 #include "chip.h"\r
45 #include <stdint.h>\r
46 \r
47 /*----------------------------------------------------------------------------\r
48  *        Definitions\r
49  *----------------------------------------------------------------------------*/\r
50 \r
51 #define RTC_HOUR_BIT_LEN_MASK   0x3F\r
52 #define RTC_MIN_BIT_LEN_MASK    0x7F\r
53 #define RTC_SEC_BIT_LEN_MASK    0x7F\r
54 #define RTC_CENT_BIT_LEN_MASK   0x7F\r
55 #define RTC_YEAR_BIT_LEN_MASK   0xFF\r
56 #define RTC_MONTH_BIT_LEN_MASK  0x1F\r
57 #define RTC_DATE_BIT_LEN_MASK   0x3F\r
58 #define RTC_WEEK_BIT_LEN_MASK   0x07\r
59 \r
60 struct _time\r
61 {\r
62   uint8_t hour;\r
63   uint8_t min;\r
64   uint8_t sec;\r
65 } ;\r
66 \r
67 struct _date\r
68 {\r
69   uint16_t year;\r
70   uint8_t  month;\r
71   uint8_t  day;\r
72   uint8_t  week;\r
73 } ;\r
74 \r
75 #ifdef CONFIG_SOC_SAMA5D2\r
76         /* -------- RTC_TSTR : (RTC Offset: N/A) TimeStamp Time Register 0 -------- */\r
77         #define RTC_TSTR_SEC_Pos 0\r
78         #define RTC_TSTR_SEC_Msk (0x7fu << RTC_TSTR_SEC_Pos) /**< \brief (RTC_TSTR) SEConds of the tamper */\r
79         #define RTC_TSTR_MIN_Pos 8\r
80         #define RTC_TSTR_MIN_Msk (0x7fu << RTC_TSTR_MIN_Pos) /**< \brief (RTC_TSTR) MINutes of the tamper */\r
81         #define RTC_TSTR_HOUR_Pos 16\r
82         #define RTC_TSTR_HOUR_Msk (0x3fu << RTC_TSTR_HOUR_Pos) /**< \brief (RTC_TSTR) HOURs of the tamper */\r
83         #define RTC_TSTR_AMPM (0x1u << 22) /**< \brief (RTC_TSTR) AMPM indicator of the tamper */\r
84         #define RTC_TSTR_TEVCNT_Pos 24\r
85         #define RTC_TSTR_TEVCNT_Msk (0xfu << RTC_TSTR_TEVCNT_Pos) /**< \brief (RTC_TSTR) Tamper events counter */\r
86         #define RTC_TSTR_BACKUP (0x1u << 31) /**< \brief (RTC_TSTR) system mode of the tamper */\r
87         /* -------- RTC_TSDR : (RTC Offset: N/A) TimeStamp Date Register 0 -------- */\r
88         #define RTC_TSDR_CENT_Pos 0\r
89         #define RTC_TSDR_CENT_Msk (0x7fu << RTC_TSDR_CENT_Pos) /**< \brief (RTC_TSDR) Century of the tamper */\r
90         #define RTC_TSDR_YEAR_Pos 8\r
91         #define RTC_TSDR_YEAR_Msk (0xffu << RTC_TSDR_YEAR_Pos) /**< \brief (RTC_TSDR) Year of the tamper */\r
92         #define RTC_TSDR_MONTH_Pos 16\r
93         #define RTC_TSDR_MONTH_Msk (0x1fu << RTC_TSDR_MONTH_Pos) /**< \brief (RTC_TSDR) Month of the tamper */\r
94         #define RTC_TSDR_DAY_Pos 21\r
95         #define RTC_TSDR_DAY_Msk (0x7u << RTC_TSDR_DAY_Pos) /**< \brief (RTC_TSDR) Day of the tamper */\r
96         #define RTC_TSDR_DATE_Pos 24\r
97         #define RTC_TSDR_DATE_Msk (0x3fu << RTC_TSDR_DATE_Pos) /**< \brief (RTC_TSDR) Date of the tamper */\r
98 #endif\r
99 \r
100 /*----------------------------------------------------------------------------\r
101  *        Exported functions\r
102  *----------------------------------------------------------------------------*/\r
103 \r
104 #ifdef __cplusplus\r
105 extern "C" {\r
106 #endif\r
107 \r
108 /**\r
109  * \brief Sets the RTC in either 12 or 24 hour mode.\r
110  *\r
111  * \param mode  Hour mode.\r
112  */\r
113 extern void rtc_set_hour_mode(uint32_t mode);\r
114 \r
115 /**\r
116  * \brief Gets the RTC mode.\r
117  *\r
118  * \return Hour mode.\r
119  */\r
120 extern uint32_t rtc_get_hour_mode(void);\r
121 \r
122 /**\r
123  * \brief Enables the selected interrupt sources of the RTC.\r
124  *\r
125  * \param sources  Interrupt sources to enable.\r
126  */\r
127 extern void rtc_enable_it(uint32_t sources);\r
128 \r
129 /**\r
130 * \brief Disables the selected interrupt sources of the RTC.\r
131 *\r
132 * \param sources  Interrupt sources to disable.\r
133 */\r
134 extern void rtc_disable_it(uint32_t sources);\r
135 \r
136 /**\r
137  * \brief Sets the current time in the RTC.\r
138  *\r
139  * \note In successive update operations, the user must wait at least one second\r
140  * after resetting the UPDTIM/UPDCAL bit in the RTC_CR before setting these\r
141  * bits again. Please look at the RTC section of the datasheet for detail.\r
142  *\r
143  * \param time Pointer to structure time\r
144  *\r
145  * \return 0 sucess, 1 fail to set\r
146  */\r
147 extern uint32_t rtc_set_time(struct _time *time);\r
148 \r
149 /**\r
150  * \brief Retrieves the current time as stored in the RTC in several variables.\r
151  *\r
152  * \param time Pointer to structure time\r
153  */\r
154 extern void rtc_get_time(struct _time *time);\r
155 \r
156 /**\r
157  * \brief Sets a time alarm on the RTC.\r
158  * The match is performed only on the provided variables;\r
159  * Setting all pointers to 0 disables the time alarm.\r
160  *\r
161  * \note In AM/PM mode, the hour value must have bit #7 set for PM, cleared for\r
162  * AM (as expected in the time registers).\r
163  *\r
164  * \param time Pointer to structure time.\r
165  *\r
166  * \return 0 success, 1 fail to set\r
167  */\r
168 extern uint32_t rtc_set_time_alarm(struct _time *time);\r
169 \r
170 /**\r
171  * \brief Retrieves the current year, month and day from the RTC.\r
172  * Month, day and week values are numbered starting at 1.\r
173  *\r
174  * \param date  Pointer to structure Date.\r
175  */\r
176 extern void rtc_get_date(struct _date *date);\r
177 \r
178 /**\r
179  * \brief Sets the current year, month and day in the RTC.\r
180  * Month, day and week values must be numbered starting from 1.\r
181  *\r
182  * \note In successive update operations, the user must wait at least one second\r
183  * after resetting the UPDTIM/UPDCAL bit in the RTC_CR before setting these\r
184  * bits again. Please look at the RTC section of the datasheet for detail.\r
185  *\r
186  * \param date  Pointer to structure Date\r
187  *\r
188  * \return 0 success, 1 fail to set\r
189  */\r
190 extern uint32_t rtc_set_date(struct _date *date);\r
191 \r
192 /**\r
193  * \brief Sets a date alarm in the RTC.\r
194  * The alarm will match only the provided values;\r
195  * Passing a null-pointer disables the corresponding field match.\r
196  *\r
197  * \param pucMonth If not null, the RTC alarm will month-match this value.\r
198  * \param pucDay   If not null, the RTC alarm will day-match this value.\r
199  *\r
200  * \return 0 success, 1 fail to set\r
201  */\r
202 extern uint32_t rtc_set_date_alarm(struct _date *date);\r
203 \r
204 /**\r
205  * \brief Clear flag bits of status clear command register in the RTC.\r
206  *\r
207  * \param mask Bits mask of cleared events\r
208  */\r
209 extern void rtc_clear_sccr(uint32_t mask);\r
210 \r
211 /**\r
212  * \brief Get flag bits of status register in the RTC.\r
213  *\r
214  * \param mask Bits mask of Status Register\r
215  *\r
216  * \return Status register & mask\r
217  */\r
218 extern uint32_t rtc_get_sr(uint32_t mask);\r
219 \r
220 /**\r
221  * \brief Get the RTC tamper time value.\r
222  *\r
223  * \note This function should be called before rtc_get_tamper_source()\r
224  *       function call, Otherwise the tamper time will be cleared.\r
225  *\r
226  * \param time Pointer to structure Time.\r
227  * \param reg_num    Tamper register set number.\r
228  */\r
229 extern void rtc_get_tamper_time(struct _time *time, uint8_t reg_num);\r
230 \r
231 /**\r
232  * \brief Get the RTC tamper date.\r
233  *\r
234  * \note This function should be called before rtc_get_tamper_source()\r
235  *       function call, Otherwise the tamper date will be cleared.\r
236  *\r
237  * \param date     Pointer to structure Date\r
238  * \param reg_num   Tamper register set number.\r
239  */\r
240 extern void rtc_get_tamper_date(struct _date *date, uint8_t reg_num);\r
241 \r
242 /**\r
243  * \brief Get the RTC tamper source.\r
244  *\r
245  * \param reg_num  Current tamper register set number.\r
246  *\r
247  * \return Tamper source.\r
248  */\r
249 extern uint32_t rtc_get_tamper_source(uint8_t reg_num);\r
250 \r
251 /**\r
252  * \brief Get the RTC tamper event counter.\r
253  *\r
254  * \note This function should be called before rtc_get_tamper_source()\r
255  *       function call, Otherwise the tamper event counter will be cleared.\r
256  *\r
257  * \return Tamper event counter\r
258  */\r
259 extern uint32_t rtc_get_tamper_event_counter(void);\r
260 \r
261 /**\r
262  * \brief Check the system is in backup mode when RTC tamper event happen.\r
263  *\r
264  * \note This function should be called before rtc_get_tamper_source()\r
265  *       function call, Otherwise the flag indicates tamper occur in backup\r
266  *       mode will be cleared.\r
267  *\r
268  * \param reg_num  Current tamper register set number.\r
269  *\r
270  * \return 1 - The system is in backup mode when the tamper event occurs.\r
271  *         0 - The system is different from backup mode.\r
272  */\r
273 extern uint8_t rtc_is_tamper_occur_in_backup_mode(uint8_t reg_num);\r
274 \r
275 /**\r
276  * \brief Convert number of second (count) to HMS format.\r
277  *\r
278  */\r
279 extern void rtc_convert_time_to_hms (struct _time *time, uint32_t count);\r
280 \r
281 /**\r
282  * \brief RTC calibration for Temperature or PPM drift\r
283  */\r
284 extern void rtc_calibration(int32_t current_tempr);\r
285 \r
286 /**\r
287  * \brief Set calendar event selection.\r
288  *\r
289  * \param mask Bits CALEVSEL of Control Register\r
290  * \return Status register & mask\r
291  */\r
292 extern uint32_t rtc_set_calendar_event (uint32_t mask);\r
293 \r
294 /**\r
295  * \brief Set time event selection.\r
296  *\r
297  * \param mask Bits TIMEVSEL of Control Register\r
298  * \return Status register & mask\r
299  */\r
300 extern uint32_t rtc_set_time_event (uint32_t maskask);\r
301 \r
302 #ifdef __cplusplus\r
303 }\r
304 #endif\r
305 #endif /* _RTC_H_ */\r