1 /* ----------------------------------------------------------------------------
\r
2 * SAM Software Package License
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2011, Atmel Corporation
\r
6 * All rights reserved.
\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
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\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
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
33 * Interface for Real Time Clock (RTC) controller.
\r
40 /*----------------------------------------------------------------------------
\r
42 *----------------------------------------------------------------------------*/
\r
47 /*----------------------------------------------------------------------------
\r
49 *----------------------------------------------------------------------------*/
\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
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
100 /*----------------------------------------------------------------------------
\r
101 * Exported functions
\r
102 *----------------------------------------------------------------------------*/
\r
109 * \brief Sets the RTC in either 12 or 24 hour mode.
\r
111 * \param mode Hour mode.
\r
113 extern void rtc_set_hour_mode(uint32_t mode);
\r
116 * \brief Gets the RTC mode.
\r
118 * \return Hour mode.
\r
120 extern uint32_t rtc_get_hour_mode(void);
\r
123 * \brief Enables the selected interrupt sources of the RTC.
\r
125 * \param sources Interrupt sources to enable.
\r
127 extern void rtc_enable_it(uint32_t sources);
\r
130 * \brief Disables the selected interrupt sources of the RTC.
\r
132 * \param sources Interrupt sources to disable.
\r
134 extern void rtc_disable_it(uint32_t sources);
\r
137 * \brief Sets the current time in the RTC.
\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
143 * \param time Pointer to structure time
\r
145 * \return 0 sucess, 1 fail to set
\r
147 extern uint32_t rtc_set_time(struct _time *time);
\r
150 * \brief Retrieves the current time as stored in the RTC in several variables.
\r
152 * \param time Pointer to structure time
\r
154 extern void rtc_get_time(struct _time *time);
\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
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
164 * \param time Pointer to structure time.
\r
166 * \return 0 success, 1 fail to set
\r
168 extern uint32_t rtc_set_time_alarm(struct _time *time);
\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
174 * \param date Pointer to structure Date.
\r
176 extern void rtc_get_date(struct _date *date);
\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
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
186 * \param date Pointer to structure Date
\r
188 * \return 0 success, 1 fail to set
\r
190 extern uint32_t rtc_set_date(struct _date *date);
\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
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
200 * \return 0 success, 1 fail to set
\r
202 extern uint32_t rtc_set_date_alarm(struct _date *date);
\r
205 * \brief Clear flag bits of status clear command register in the RTC.
\r
207 * \param mask Bits mask of cleared events
\r
209 extern void rtc_clear_sccr(uint32_t mask);
\r
212 * \brief Get flag bits of status register in the RTC.
\r
214 * \param mask Bits mask of Status Register
\r
216 * \return Status register & mask
\r
218 extern uint32_t rtc_get_sr(uint32_t mask);
\r
221 * \brief Get the RTC tamper time value.
\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
226 * \param time Pointer to structure Time.
\r
227 * \param reg_num Tamper register set number.
\r
229 extern void rtc_get_tamper_time(struct _time *time, uint8_t reg_num);
\r
232 * \brief Get the RTC tamper date.
\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
237 * \param date Pointer to structure Date
\r
238 * \param reg_num Tamper register set number.
\r
240 extern void rtc_get_tamper_date(struct _date *date, uint8_t reg_num);
\r
243 * \brief Get the RTC tamper source.
\r
245 * \param reg_num Current tamper register set number.
\r
247 * \return Tamper source.
\r
249 extern uint32_t rtc_get_tamper_source(uint8_t reg_num);
\r
252 * \brief Get the RTC tamper event counter.
\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
257 * \return Tamper event counter
\r
259 extern uint32_t rtc_get_tamper_event_counter(void);
\r
262 * \brief Check the system is in backup mode when RTC tamper event happen.
\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
268 * \param reg_num Current tamper register set number.
\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
273 extern uint8_t rtc_is_tamper_occur_in_backup_mode(uint8_t reg_num);
\r
276 * \brief Convert number of second (count) to HMS format.
\r
279 extern void rtc_convert_time_to_hms (struct _time *time, uint32_t count);
\r
282 * \brief RTC calibration for Temperature or PPM drift
\r
284 extern void rtc_calibration(int32_t current_tempr);
\r
287 * \brief Set calendar event selection.
\r
289 * \param mask Bits CALEVSEL of Control Register
\r
290 * \return Status register & mask
\r
292 extern uint32_t rtc_set_calendar_event (uint32_t mask);
\r
295 * \brief Set time event selection.
\r
297 * \param mask Bits TIMEVSEL of Control Register
\r
298 * \return Status register & mask
\r
300 extern uint32_t rtc_set_time_event (uint32_t maskask);
\r
305 #endif /* _RTC_H_ */
\r