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