t

Fork of mbed-dev by mbed official

Committer:
amithy
Date:
Thu Nov 09 22:14:37 2017 +0000
Revision:
178:c26431f84b0d
Parent:
149:156823d33999
test export

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 107:414e9c822e99 1 /**
mbed_official 107:414e9c822e99 2 * \file
mbed_official 107:414e9c822e99 3 *
mbed_official 107:414e9c822e99 4 * \brief Real-Time Clock (RTC) driver for SAM.
mbed_official 107:414e9c822e99 5 *
mbed_official 107:414e9c822e99 6 * Copyright (c) 2011-2015 Atmel Corporation. All rights reserved.
mbed_official 107:414e9c822e99 7 *
mbed_official 107:414e9c822e99 8 * \asf_license_start
mbed_official 107:414e9c822e99 9 *
mbed_official 107:414e9c822e99 10 * \page License
mbed_official 107:414e9c822e99 11 *
mbed_official 107:414e9c822e99 12 * Redistribution and use in source and binary forms, with or without
mbed_official 107:414e9c822e99 13 * modification, are permitted provided that the following conditions are met:
mbed_official 107:414e9c822e99 14 *
mbed_official 107:414e9c822e99 15 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 107:414e9c822e99 16 * this list of conditions and the following disclaimer.
mbed_official 107:414e9c822e99 17 *
mbed_official 107:414e9c822e99 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 107:414e9c822e99 19 * this list of conditions and the following disclaimer in the documentation
mbed_official 107:414e9c822e99 20 * and/or other materials provided with the distribution.
mbed_official 107:414e9c822e99 21 *
mbed_official 107:414e9c822e99 22 * 3. The name of Atmel may not be used to endorse or promote products derived
mbed_official 107:414e9c822e99 23 * from this software without specific prior written permission.
mbed_official 107:414e9c822e99 24 *
mbed_official 107:414e9c822e99 25 * 4. This software may only be redistributed and used in connection with an
mbed_official 107:414e9c822e99 26 * Atmel microcontroller product.
mbed_official 107:414e9c822e99 27 *
mbed_official 107:414e9c822e99 28 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
mbed_official 107:414e9c822e99 29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mbed_official 107:414e9c822e99 30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
mbed_official 107:414e9c822e99 31 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
mbed_official 107:414e9c822e99 32 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 107:414e9c822e99 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
mbed_official 107:414e9c822e99 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
mbed_official 107:414e9c822e99 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
mbed_official 107:414e9c822e99 36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
mbed_official 107:414e9c822e99 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 107:414e9c822e99 38 * POSSIBILITY OF SUCH DAMAGE.
mbed_official 107:414e9c822e99 39 *
mbed_official 107:414e9c822e99 40 * \asf_license_stop
mbed_official 107:414e9c822e99 41 *
mbed_official 107:414e9c822e99 42 */
mbed_official 107:414e9c822e99 43 /*
mbed_official 107:414e9c822e99 44 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
mbed_official 107:414e9c822e99 45 */
mbed_official 107:414e9c822e99 46
mbed_official 107:414e9c822e99 47 #ifndef RTC_H_INCLUDED
mbed_official 107:414e9c822e99 48 #define RTC_H_INCLUDED
mbed_official 107:414e9c822e99 49
mbed_official 107:414e9c822e99 50 #include "compiler.h"
mbed_official 107:414e9c822e99 51
mbed_official 107:414e9c822e99 52 /// @cond 0
mbed_official 107:414e9c822e99 53 /**INDENT-OFF**/
mbed_official 107:414e9c822e99 54 #ifdef __cplusplus
mbed_official 107:414e9c822e99 55 extern "C" {
mbed_official 107:414e9c822e99 56 #endif
mbed_official 107:414e9c822e99 57 /**INDENT-ON**/
mbed_official 107:414e9c822e99 58 /// @endcond
mbed_official 107:414e9c822e99 59
mbed_official 107:414e9c822e99 60 void rtc_set_hour_mode(Rtc *p_rtc, uint32_t ul_mode);
mbed_official 107:414e9c822e99 61 uint32_t rtc_get_hour_mode(Rtc *p_rtc);
mbed_official 107:414e9c822e99 62 void rtc_enable_interrupt(Rtc *p_rtc, uint32_t ul_sources);
mbed_official 107:414e9c822e99 63 void rtc_disable_interrupt(Rtc *p_rtc, uint32_t ul_sources);
mbed_official 107:414e9c822e99 64 uint32_t rtc_get_interrupt_mask(Rtc *p_rtc);
mbed_official 107:414e9c822e99 65 void rtc_get_time(Rtc *p_rtc, uint32_t *pul_hour, uint32_t *pul_minute,
mbed_official 107:414e9c822e99 66 uint32_t *pul_second);
mbed_official 107:414e9c822e99 67 uint32_t rtc_set_time(Rtc *p_rtc, uint32_t ul_hour, uint32_t ul_minute,
mbed_official 107:414e9c822e99 68 uint32_t ul_second);
mbed_official 107:414e9c822e99 69 uint32_t rtc_set_time_alarm(Rtc *p_rtc,
mbed_official 107:414e9c822e99 70 uint32_t ul_hour_flag, uint32_t ul_hour,
mbed_official 107:414e9c822e99 71 uint32_t ul_minute_flag, uint32_t ul_minute,
mbed_official 107:414e9c822e99 72 uint32_t ul_second_flag, uint32_t ul_second);
mbed_official 107:414e9c822e99 73 void rtc_get_date(Rtc *p_rtc, uint32_t *pul_year, uint32_t *pul_month,
mbed_official 107:414e9c822e99 74 uint32_t *pul_day, uint32_t *pul_week);
mbed_official 107:414e9c822e99 75 uint32_t rtc_set_date(Rtc *p_rtc, uint32_t ul_year, uint32_t ul_month,
mbed_official 107:414e9c822e99 76 uint32_t ul_day, uint32_t ul_week);
mbed_official 107:414e9c822e99 77 uint32_t rtc_set_date_alarm(Rtc *p_rtc,
mbed_official 107:414e9c822e99 78 uint32_t ul_month_flag, uint32_t ul_month,
mbed_official 107:414e9c822e99 79 uint32_t ul_day_flag, uint32_t ul_day);
mbed_official 107:414e9c822e99 80 void rtc_clear_time_alarm(Rtc *p_rtc);
mbed_official 107:414e9c822e99 81 void rtc_clear_date_alarm(Rtc *p_rtc);
mbed_official 107:414e9c822e99 82 uint32_t rtc_get_status(Rtc *p_rtc);
mbed_official 107:414e9c822e99 83 void rtc_clear_status(Rtc *p_rtc, uint32_t ul_clear);
mbed_official 107:414e9c822e99 84 uint32_t rtc_get_valid_entry(Rtc *p_rtc);
mbed_official 107:414e9c822e99 85 void rtc_set_time_event(Rtc *p_rtc, uint32_t ul_selection);
mbed_official 107:414e9c822e99 86 void rtc_set_calendar_event(Rtc *p_rtc, uint32_t ul_selection);
mbed_official 107:414e9c822e99 87
mbed_official 107:414e9c822e99 88 #if ((SAM3S8) || (SAM3SD8) || (SAM4S) || (SAM4N) || (SAM4C) || (SAMG) || (SAM4CP) || (SAM4CM))
mbed_official 107:414e9c822e99 89 void rtc_set_calendar_mode(Rtc *p_rtc, uint32_t ul_mode);
mbed_official 107:414e9c822e99 90 uint32_t rtc_get_calendar_mode(Rtc *p_rtc);
mbed_official 107:414e9c822e99 91 void rtc_set_calibration(Rtc *p_rtc, uint32_t ul_direction_ppm,
mbed_official 107:414e9c822e99 92 uint32_t ul_correction, uint32_t ul_range_ppm);
mbed_official 107:414e9c822e99 93 #endif
mbed_official 107:414e9c822e99 94
mbed_official 107:414e9c822e99 95 #if ((SAM3S8) || (SAM3SD8) || (SAM4S) || (SAM4C) || (SAMG) || (SAM4CP) || (SAM4CM) || SAMV71 || SAMV70 || SAME70 || SAMS70)
mbed_official 107:414e9c822e99 96 void rtc_set_waveform(Rtc *p_rtc, uint32_t ul_channel, uint32_t ul_value);
mbed_official 107:414e9c822e99 97 #if ((SAM3S8) || (SAM3SD8) || (SAM4S) || (SAM4C)|| (SAM4CP) || (SAM4CM) || SAMV71 || SAMV70 || SAME70 || SAMS70)
mbed_official 107:414e9c822e99 98 void rtc_set_pulse_parameter(Rtc *p_rtc, uint32_t ul_time_high,
mbed_official 107:414e9c822e99 99 uint32_t ul_period);
mbed_official 107:414e9c822e99 100 #endif
mbed_official 107:414e9c822e99 101 #endif
mbed_official 107:414e9c822e99 102
mbed_official 107:414e9c822e99 103 #if ((SAM3N) || (SAM3U) || (SAM3XA))
mbed_official 107:414e9c822e99 104 void rtc_set_writeprotect(Rtc *p_rtc, uint32_t ul_enable);
mbed_official 107:414e9c822e99 105 #endif /* ((SAM3N) || (SAM3U) || (SAM3XA)) */
mbed_official 107:414e9c822e99 106
mbed_official 107:414e9c822e99 107 #if ((SAM4C) || (SAM4CP) || (SAM4CM))
mbed_official 107:414e9c822e99 108 void rtc_get_tamper_time(Rtc *p_rtc, uint32_t *pul_hour, uint32_t *pul_minute,
mbed_official 107:414e9c822e99 109 uint32_t *pul_second, uint8_t reg_num);
mbed_official 107:414e9c822e99 110 void rtc_get_tamper_date(Rtc *p_rtc, uint32_t *pul_year, uint32_t *pul_month,
mbed_official 107:414e9c822e99 111 uint32_t *pul_day, uint32_t *pul_week, uint8_t reg_num);
mbed_official 107:414e9c822e99 112 uint32_t rtc_get_tamper_source(Rtc *p_rtc, uint8_t reg_num);
mbed_official 107:414e9c822e99 113 uint32_t rtc_get_tamper_event_counter(Rtc *p_rtc);
mbed_official 107:414e9c822e99 114 bool rtc_is_tamper_occur_in_backup_mode(Rtc *p_rtc, uint8_t reg_num);
mbed_official 107:414e9c822e99 115 #endif
mbed_official 107:414e9c822e99 116
mbed_official 107:414e9c822e99 117 #if (SAMG55)
mbed_official 107:414e9c822e99 118 uint32_t rtc_get_milliseconds(Rtc *p_rtc);
mbed_official 107:414e9c822e99 119 #endif
mbed_official 107:414e9c822e99 120
mbed_official 107:414e9c822e99 121 /**
mbed_official 107:414e9c822e99 122 * \page sam_rtc_quickstart Quickstart guide for SAM RTC driver
mbed_official 107:414e9c822e99 123 *
mbed_official 107:414e9c822e99 124 * This is the quickstart guide for the \ref rtc_group "SAM RTC driver",
mbed_official 107:414e9c822e99 125 * with step-by-step instructions on how to configure and use the driver in a
mbed_official 107:414e9c822e99 126 * selection of use cases.
mbed_official 107:414e9c822e99 127 *
mbed_official 107:414e9c822e99 128 * The use cases contain several code fragments. The code fragments in the
mbed_official 107:414e9c822e99 129 * steps for setup can be copied into a custom initialization function, while
mbed_official 107:414e9c822e99 130 * the steps for usage can be copied into, e.g., the main application function.
mbed_official 107:414e9c822e99 131 *
mbed_official 107:414e9c822e99 132 * \section rtc_basic_use_case Basic use case
mbed_official 107:414e9c822e99 133 * In this basic use case, the RTC module is using 32kHz external crystal and
mbed_official 107:414e9c822e99 134 * configured for 24-hour mode. It will read the current date and time.
mbed_official 107:414e9c822e99 135 *
mbed_official 107:414e9c822e99 136 * \subsection sam_rtc_quickstart_prereq Prerequisites
mbed_official 107:414e9c822e99 137 * -# \ref sysclk_group "System Clock Management (Sysclock)"
mbed_official 107:414e9c822e99 138 *
mbed_official 107:414e9c822e99 139 * \section rtc_basic_use_case_setup Setup steps
mbed_official 107:414e9c822e99 140 * \subsection rtc_basic_use_case_setup_code Example code
mbed_official 107:414e9c822e99 141 * Add to application C-file:
mbed_official 107:414e9c822e99 142 * \code
mbed_official 107:414e9c822e99 143 void rtc_setup(void)
mbed_official 107:414e9c822e99 144 {
mbed_official 107:414e9c822e99 145 pmc_switch_sclk_to_32kxtal(PMC_OSC_XTAL);
mbed_official 107:414e9c822e99 146
mbed_official 107:414e9c822e99 147 while (!pmc_osc_is_ready_32kxtal());
mbed_official 107:414e9c822e99 148
mbed_official 107:414e9c822e99 149 rtc_set_hour_mode(RTC, 0);
mbed_official 107:414e9c822e99 150 }
mbed_official 107:414e9c822e99 151 \endcode
mbed_official 107:414e9c822e99 152 *
mbed_official 107:414e9c822e99 153 * \subsection rtc_basic_use_case_setup_flow Workflow
mbed_official 107:414e9c822e99 154 * - \note Please make sure the external 32kHz crystal is available.
mbed_official 107:414e9c822e99 155 * -# Enable the External 32K crystal :
mbed_official 107:414e9c822e99 156 * - \code pmc_switch_sclk_to_32kxtal(PMC_OSC_XTAL); \endcode
mbed_official 107:414e9c822e99 157 * -# Wait for 32K crystal ready:
mbed_official 107:414e9c822e99 158 * - \code while (!pmc_osc_is_ready_32kxtal()); \endcode
mbed_official 107:414e9c822e99 159 * -# Set default RTC configuration, 24-hour mode .
mbed_official 107:414e9c822e99 160 * - \code rtc_set_hour_mode(RTC, 0); \endcode
mbed_official 107:414e9c822e99 161 *
mbed_official 107:414e9c822e99 162 * \section rtc_basic_use_case_usage Usage steps
mbed_official 107:414e9c822e99 163 * \subsection rtc_basic_use_case_usage_code Example code
mbed_official 107:414e9c822e99 164 * Add to, e.g., main loop in application C-file:
mbed_official 107:414e9c822e99 165 * \code
mbed_official 107:414e9c822e99 166 uint32_t hour, minute, second;
mbed_official 107:414e9c822e99 167 uint32_t year, month, day, week;
mbed_official 107:414e9c822e99 168
mbed_official 107:414e9c822e99 169 rtc_get_time(RTC, &hour, &minute, &second);
mbed_official 107:414e9c822e99 170 rtc_get_date(RTC, &year, &month, &day, &week);
mbed_official 107:414e9c822e99 171 \endcode
mbed_official 107:414e9c822e99 172 *
mbed_official 107:414e9c822e99 173 * \subsection rtc_basic_use_case_usage_flow Workflow
mbed_official 107:414e9c822e99 174 * -# Start Define the variables for the date and time:
mbed_official 107:414e9c822e99 175 * - \code uint32_t hour, minute, second; \endcode
mbed_official 107:414e9c822e99 176 * - \code uint32_t year, month, day, week; \endcode
mbed_official 107:414e9c822e99 177 * -# Read current time:
mbed_official 107:414e9c822e99 178 * - \code rtc_get_time(RTC, &hour, &minute, &second); \endcode
mbed_official 107:414e9c822e99 179 * -# Read current date:
mbed_official 107:414e9c822e99 180 * - \code rtc_get_date(RTC, &year, &month, &day, &week); \endcode
mbed_official 107:414e9c822e99 181 *
mbed_official 107:414e9c822e99 182 */
mbed_official 107:414e9c822e99 183
mbed_official 107:414e9c822e99 184 /// @cond 0
mbed_official 107:414e9c822e99 185 /**INDENT-OFF**/
mbed_official 107:414e9c822e99 186 #ifdef __cplusplus
mbed_official 107:414e9c822e99 187 }
mbed_official 107:414e9c822e99 188 #endif
mbed_official 107:414e9c822e99 189 /**INDENT-ON**/
mbed_official 107:414e9c822e99 190 /// @endcond
mbed_official 107:414e9c822e99 191
mbed_official 107:414e9c822e99 192 #endif /* RTC_H_INCLUDED */