mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Fri Jul 17 09:15:10 2015 +0100
Revision:
592:a274ee790e56
Synchronized with git revision e7144f83a8d75df80c4877936b6ffe552b0be9e6

Full URL: https://github.com/mbedmicro/mbed/commit/e7144f83a8d75df80c4877936b6ffe552b0be9e6/

More API implementation for SAMR21

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 592:a274ee790e56 1 #ifndef RTC_COUNT_H_INCLUDED
mbed_official 592:a274ee790e56 2 #define RTC_COUNT_H_INCLUDED
mbed_official 592:a274ee790e56 3
mbed_official 592:a274ee790e56 4 /**
mbed_official 592:a274ee790e56 5 * \defgroup asfdoc_sam0_rtc_count_group SAM RTC Count Driver (RTC COUNT)
mbed_official 592:a274ee790e56 6 *
mbed_official 592:a274ee790e56 7 * This driver for Atmel庐 | SMART SAM devices provides an interface for the configuration
mbed_official 592:a274ee790e56 8 * and management of the device's Real Time Clock functionality in Count
mbed_official 592:a274ee790e56 9 * operating mode, for the configuration and retrieval of the current RTC
mbed_official 592:a274ee790e56 10 * counter value. The following driver API modes are covered by this
mbed_official 592:a274ee790e56 11 * manual:
mbed_official 592:a274ee790e56 12 *
mbed_official 592:a274ee790e56 13 * - Polled APIs
mbed_official 592:a274ee790e56 14 * \if RTC_COUNT_CALLBACK_MODE
mbed_official 592:a274ee790e56 15 * - Callback APIs
mbed_official 592:a274ee790e56 16 * \endif
mbed_official 592:a274ee790e56 17 *
mbed_official 592:a274ee790e56 18 * The following peripherals are used by this module:
mbed_official 592:a274ee790e56 19 * - RTC (Real Time Clock)
mbed_official 592:a274ee790e56 20 *
mbed_official 592:a274ee790e56 21 * The following devices can use this module:
mbed_official 592:a274ee790e56 22 * - Atmel | SMART SAM D20/D21
mbed_official 592:a274ee790e56 23 * - Atmel | SMART SAM R21
mbed_official 592:a274ee790e56 24 * - Atmel | SMART SAM D10/D11
mbed_official 592:a274ee790e56 25 * - Atmel | SMART SAM L21
mbed_official 592:a274ee790e56 26 *
mbed_official 592:a274ee790e56 27 * The outline of this documentation is as follows:
mbed_official 592:a274ee790e56 28 * - \ref asfdoc_sam0_rtc_count_prerequisites
mbed_official 592:a274ee790e56 29 * - \ref asfdoc_sam0_rtc_count_module_overview
mbed_official 592:a274ee790e56 30 * - \ref asfdoc_sam0_rtc_count_special_considerations
mbed_official 592:a274ee790e56 31 * - \ref asfdoc_sam0_rtc_count_extra_info
mbed_official 592:a274ee790e56 32 * - \ref asfdoc_sam0_rtc_count_examples
mbed_official 592:a274ee790e56 33 * - \ref asfdoc_sam0_rtc_count_api_overview
mbed_official 592:a274ee790e56 34 *
mbed_official 592:a274ee790e56 35 *
mbed_official 592:a274ee790e56 36 * \section asfdoc_sam0_rtc_count_prerequisites Prerequisites
mbed_official 592:a274ee790e56 37 *
mbed_official 592:a274ee790e56 38 * There are no prerequisites for this module.
mbed_official 592:a274ee790e56 39 *
mbed_official 592:a274ee790e56 40 *
mbed_official 592:a274ee790e56 41 * \section asfdoc_sam0_rtc_count_module_overview Module Overview
mbed_official 592:a274ee790e56 42 *
mbed_official 592:a274ee790e56 43 * The RTC module in the SAM devices is a 32-bit counter, with a 10-bit
mbed_official 592:a274ee790e56 44 * programmable prescaler. Typically, the RTC clock is run continuously,
mbed_official 592:a274ee790e56 45 * including in the device's low-power sleep modes, to track the current time
mbed_official 592:a274ee790e56 46 * and date information. The RTC can be used as a source to wake up the system
mbed_official 592:a274ee790e56 47 * at a scheduled time or periodically using the alarm functions.
mbed_official 592:a274ee790e56 48 *
mbed_official 592:a274ee790e56 49 * In this driver, the RTC is operated in Count mode. This allows for an
mbed_official 592:a274ee790e56 50 * easy integration of an asynchronous counter into a user application, which is
mbed_official 592:a274ee790e56 51 * capable of operating while the device is in sleep mode.
mbed_official 592:a274ee790e56 52 *
mbed_official 592:a274ee790e56 53 * Whilst operating in Count mode, the RTC features:
mbed_official 592:a274ee790e56 54 * - 16-bit counter mode
mbed_official 592:a274ee790e56 55 * - Selectable counter period
mbed_official 592:a274ee790e56 56 * - Up to six configurable compare values
mbed_official 592:a274ee790e56 57 * - 32-bit counter mode
mbed_official 592:a274ee790e56 58 * - Clear counter value on match
mbed_official 592:a274ee790e56 59 * - Up to four configurable compare values
mbed_official 592:a274ee790e56 60 *
mbed_official 592:a274ee790e56 61 * \subsection asfdoc_sam0_rtc_count_features Driver Feature Macro Definition
mbed_official 592:a274ee790e56 62 * <table>
mbed_official 592:a274ee790e56 63 * <tr>
mbed_official 592:a274ee790e56 64 * <th>Driver Feature Macro</th>
mbed_official 592:a274ee790e56 65 * <th>Supported devices</th>
mbed_official 592:a274ee790e56 66 * </tr>
mbed_official 592:a274ee790e56 67 * <tr>
mbed_official 592:a274ee790e56 68 * <td>FEATURE_RTC_PERIODIC_INT</td>
mbed_official 592:a274ee790e56 69 * <td>SAML21</td>
mbed_official 592:a274ee790e56 70 * </tr>
mbed_official 592:a274ee790e56 71 * <tr>
mbed_official 592:a274ee790e56 72 * <td>FEATURE_RTC_PRESCALER_OFF</td>
mbed_official 592:a274ee790e56 73 * <td>SAML21</td>
mbed_official 592:a274ee790e56 74 * </tr>
mbed_official 592:a274ee790e56 75 * <tr>
mbed_official 592:a274ee790e56 76 * <td>FEATURE_RTC_CLOCK_SELECTION</td>
mbed_official 592:a274ee790e56 77 * <td>SAML21</td>
mbed_official 592:a274ee790e56 78 * </tr>
mbed_official 592:a274ee790e56 79 * <tr>
mbed_official 592:a274ee790e56 80 * <td>FEATURE_RTC_GENERAL_PURPOSE_REG</td>
mbed_official 592:a274ee790e56 81 * <td>SAML21</td>
mbed_official 592:a274ee790e56 82 * </tr>
mbed_official 592:a274ee790e56 83 * <tr>
mbed_official 592:a274ee790e56 84 * <td>FEATURE_RTC_CONTINUOUSLY_UPDATED</td>
mbed_official 592:a274ee790e56 85 * <td>SAMD20,SAMD21,SAMR21,SAMD10,SAMD11</td>
mbed_official 592:a274ee790e56 86 * </tr>
mbed_official 592:a274ee790e56 87 * </table>
mbed_official 592:a274ee790e56 88 * \note The specific features are only available in the driver when the
mbed_official 592:a274ee790e56 89 * selected device supports those features.
mbed_official 592:a274ee790e56 90 *
mbed_official 592:a274ee790e56 91 * \section asfdoc_sam0_rtc_count_module_overview_compares Compare and Overflow
mbed_official 592:a274ee790e56 92 * The RTC can be used with up to 4/6 compare values (depending on selected
mbed_official 592:a274ee790e56 93 * operation mode). These compare values will trigger on match with the current
mbed_official 592:a274ee790e56 94 * RTC counter value, and can be set up to trigger an interrupt, event, or both.
mbed_official 592:a274ee790e56 95 * The RTC can also be configured to clear the counter value on compare match
mbed_official 592:a274ee790e56 96 * in 32-bit mode, resetting the count value back to zero.
mbed_official 592:a274ee790e56 97 *
mbed_official 592:a274ee790e56 98 * If the RTC is operated without the Clear on Match option enabled, or in
mbed_official 592:a274ee790e56 99 * 16-bit mode, the RTC counter value will instead be cleared on overflow once
mbed_official 592:a274ee790e56 100 * the maximum count value has been reached:
mbed_official 592:a274ee790e56 101 *
mbed_official 592:a274ee790e56 102 * \f[ COUNT_{MAX} = 2^{32}-1 \f] for 32-bit counter mode, and
mbed_official 592:a274ee790e56 103 * \f[ COUNT_{MAX} = 2^{16}-1 \f] for 16-bit counter mode.
mbed_official 592:a274ee790e56 104 *
mbed_official 592:a274ee790e56 105 * When running in 16-bit mode, the overflow value is selectable with a period
mbed_official 592:a274ee790e56 106 * value. The counter overflow will then occur when the counter value reaches
mbed_official 592:a274ee790e56 107 * the specified period value.
mbed_official 592:a274ee790e56 108 *
mbed_official 592:a274ee790e56 109 * \subsection asfdoc_sam0_rtc_count_module_overview_periodic Periodic Events
mbed_official 592:a274ee790e56 110 * The RTC can generate events at periodic intervals, allowing for direct
mbed_official 592:a274ee790e56 111 * peripheral actions without CPU intervention. The periodic events can be
mbed_official 592:a274ee790e56 112 * generated on the upper eight bits of the RTC prescaler, and will be generated on
mbed_official 592:a274ee790e56 113 * the rising edge transition of the specified bit. The resulting periodic
mbed_official 592:a274ee790e56 114 * frequency can be calculated by the following formula:
mbed_official 592:a274ee790e56 115 *
mbed_official 592:a274ee790e56 116 * \f[ f_{PERIODIC}=\frac{f_{ASY}}{2^{n+3}} \f]
mbed_official 592:a274ee790e56 117 *
mbed_official 592:a274ee790e56 118 * Where \f$f_{ASY}\f$ refers to the \e asynchronous clock set up in the RTC
mbed_official 592:a274ee790e56 119 * module configuration. The \b n parameter is the event source generator index
mbed_official 592:a274ee790e56 120 * of the RTC module. If the asynchronous clock is operated at the recommended
mbed_official 592:a274ee790e56 121 * frequency of 1KHz, the formula results in the values shown in
mbed_official 592:a274ee790e56 122 * \ref asfdoc_sam0_rtc_count_module_rtc_hz "the table below".
mbed_official 592:a274ee790e56 123 *
mbed_official 592:a274ee790e56 124 * \anchor asfdoc_sam0_rtc_count_module_rtc_hz
mbed_official 592:a274ee790e56 125 * <table>
mbed_official 592:a274ee790e56 126 * <caption>RTC Event Frequencies for Each Prescaler Bit Using a 1KHz Clock</caption>
mbed_official 592:a274ee790e56 127 * <tr>
mbed_official 592:a274ee790e56 128 * <th>n</th> <th>Periodic event</th>
mbed_official 592:a274ee790e56 129 * </tr>
mbed_official 592:a274ee790e56 130 * <tr>
mbed_official 592:a274ee790e56 131 * <td>7</td> <td>1Hz</td>
mbed_official 592:a274ee790e56 132 * </tr>
mbed_official 592:a274ee790e56 133 * <tr>
mbed_official 592:a274ee790e56 134 * <td>6</td> <td>2Hz</td>
mbed_official 592:a274ee790e56 135 * </tr>
mbed_official 592:a274ee790e56 136 * <tr>
mbed_official 592:a274ee790e56 137 * <td>5</td> <td>4Hz</td>
mbed_official 592:a274ee790e56 138 * </tr>
mbed_official 592:a274ee790e56 139 * <tr>
mbed_official 592:a274ee790e56 140 * <td>4</td> <td>8Hz</td>
mbed_official 592:a274ee790e56 141 * </tr>
mbed_official 592:a274ee790e56 142 * <tr>
mbed_official 592:a274ee790e56 143 * <td>3</td> <td>16Hz</td>
mbed_official 592:a274ee790e56 144 * </tr>
mbed_official 592:a274ee790e56 145 * <tr>
mbed_official 592:a274ee790e56 146 * <td>2</td> <td>32Hz</td>
mbed_official 592:a274ee790e56 147 * </tr>
mbed_official 592:a274ee790e56 148 * <tr>
mbed_official 592:a274ee790e56 149 * <td>1</td> <td>64Hz</td>
mbed_official 592:a274ee790e56 150 * </tr>
mbed_official 592:a274ee790e56 151 * <tr>
mbed_official 592:a274ee790e56 152 * <td>0</td> <td>128Hz</td>
mbed_official 592:a274ee790e56 153 * </tr>
mbed_official 592:a274ee790e56 154 * </table>
mbed_official 592:a274ee790e56 155 *
mbed_official 592:a274ee790e56 156 * \note The connection of events between modules requires the use of the
mbed_official 592:a274ee790e56 157 * \ref asfdoc_sam0_events_group "SAM Event System Driver (EVENTS)"
mbed_official 592:a274ee790e56 158 * to route output event of one module to the the input event of another.
mbed_official 592:a274ee790e56 159 * For more information on event routing, refer to the event driver
mbed_official 592:a274ee790e56 160 * documentation.
mbed_official 592:a274ee790e56 161 *
mbed_official 592:a274ee790e56 162 * \subsection asfdoc_sam0_rtc_count_module_overview_correction Digital Frequency Correction
mbed_official 592:a274ee790e56 163 * The RTC module contains Digital Frequency Correction logic to compensate for
mbed_official 592:a274ee790e56 164 * inaccurate source clock frequencies which would otherwise result in skewed
mbed_official 592:a274ee790e56 165 * time measurements. The correction scheme requires that at least two bits
mbed_official 592:a274ee790e56 166 * in the RTC module prescaler are reserved by the correction logic. As a
mbed_official 592:a274ee790e56 167 * result of this implementation, frequency correction is only available when
mbed_official 592:a274ee790e56 168 * the RTC is running from a 1Hz reference clock.
mbed_official 592:a274ee790e56 169 *
mbed_official 592:a274ee790e56 170 * The correction procedure is implemented by subtracting or adding a single
mbed_official 592:a274ee790e56 171 * cycle from the RTC prescaler every 1024 RTC GCLK cycles. The adjustment is
mbed_official 592:a274ee790e56 172 * applied the specified number of time (maximum 127) over 976 of these periods. The
mbed_official 592:a274ee790e56 173 * corresponding correction in PPM will be given by:
mbed_official 592:a274ee790e56 174 *
mbed_official 592:a274ee790e56 175 * \f[ Correction(PPM) = \frac{VALUE}{999424}10^6 \f]
mbed_official 592:a274ee790e56 176 *
mbed_official 592:a274ee790e56 177 * The RTC clock will tick faster if provided with a positive correction value,
mbed_official 592:a274ee790e56 178 * and slower when given a negative correction value.
mbed_official 592:a274ee790e56 179 *
mbed_official 592:a274ee790e56 180 *
mbed_official 592:a274ee790e56 181 * \section asfdoc_sam0_rtc_count_special_considerations Special Considerations
mbed_official 592:a274ee790e56 182 *
mbed_official 592:a274ee790e56 183 * \subsection asfdoc_sam0_rtc_count_special_considerations_clock Clock Setup
mbed_official 592:a274ee790e56 184 * \subsubsection asfdoc_sam0_rtc_count_clock_samd_r SAM D20/D21/R21/D10/D11 Clock Setup
mbed_official 592:a274ee790e56 185 * The RTC is typically clocked by a specialized GCLK generator that has a
mbed_official 592:a274ee790e56 186 * smaller prescaler than the others. By default the RTC clock is on, selected
mbed_official 592:a274ee790e56 187 * to use the internal 32KHz RC-oscillator with a prescaler of 32, giving a
mbed_official 592:a274ee790e56 188 * resulting clock frequency of 1KHz to the RTC. When the internal RTC
mbed_official 592:a274ee790e56 189 * prescaler is set to 1024, this yields an end-frequency of 1Hz.
mbed_official 592:a274ee790e56 190 *
mbed_official 592:a274ee790e56 191 * The implementer also has the option to set other end-frequencies.
mbed_official 592:a274ee790e56 192 * \ref asfdoc_sam0_rtc_count_rtc_out_freq "The table below" lists the
mbed_official 592:a274ee790e56 193 * available RTC frequencies for each possible GCLK and RTC input prescaler
mbed_official 592:a274ee790e56 194 * options.
mbed_official 592:a274ee790e56 195 *
mbed_official 592:a274ee790e56 196 * \anchor asfdoc_sam0_rtc_count_rtc_out_freq
mbed_official 592:a274ee790e56 197 * <table>
mbed_official 592:a274ee790e56 198 * <caption>RTC Output Frequencies from Allowable Input Clocks</caption>
mbed_official 592:a274ee790e56 199 * <tr>
mbed_official 592:a274ee790e56 200 * <th>End-frequency</th>
mbed_official 592:a274ee790e56 201 * <th>GCLK prescaler</th>
mbed_official 592:a274ee790e56 202 * <th>RTC prescaler</th>
mbed_official 592:a274ee790e56 203 * </tr>
mbed_official 592:a274ee790e56 204 * <tr>
mbed_official 592:a274ee790e56 205 * <td>32KHz</td>
mbed_official 592:a274ee790e56 206 * <td>1</td>
mbed_official 592:a274ee790e56 207 * <td>1</td>
mbed_official 592:a274ee790e56 208 * </tr>
mbed_official 592:a274ee790e56 209 * <tr>
mbed_official 592:a274ee790e56 210 * <td>1KHz</td>
mbed_official 592:a274ee790e56 211 * <td>32</td>
mbed_official 592:a274ee790e56 212 * <td>1</td>
mbed_official 592:a274ee790e56 213 * </tr>
mbed_official 592:a274ee790e56 214 * <tr>
mbed_official 592:a274ee790e56 215 * <td>1Hz</td>
mbed_official 592:a274ee790e56 216 * <td>32</td>
mbed_official 592:a274ee790e56 217 * <td>1024</td>
mbed_official 592:a274ee790e56 218 * </tr>
mbed_official 592:a274ee790e56 219 * </table>
mbed_official 592:a274ee790e56 220 *
mbed_official 592:a274ee790e56 221 * The overall RTC module clocking scheme is shown in
mbed_official 592:a274ee790e56 222 * \ref asfdoc_sam0_rtc_count_rtc_clock_fig "the figure below".
mbed_official 592:a274ee790e56 223 *
mbed_official 592:a274ee790e56 224 * \anchor asfdoc_sam0_rtc_count_rtc_clock_fig
mbed_official 592:a274ee790e56 225 * \dot
mbed_official 592:a274ee790e56 226 * digraph clocking_scheme {
mbed_official 592:a274ee790e56 227 * rankdir=LR;
mbed_official 592:a274ee790e56 228 * GCLK [shape="record", label="<f0> GCLK | <f1> RTC_GCLK",
mbed_official 592:a274ee790e56 229 * bgcolor="lightgray", style="filled"];
mbed_official 592:a274ee790e56 230 * RTCPRE [shape="record" label="<f0> RTC | <f1> RTC PRESCALER"];
mbed_official 592:a274ee790e56 231 * RTC [shape="record", label="<f0> RTC | <f1> RTC CLOCK"];
mbed_official 592:a274ee790e56 232 *
mbed_official 592:a274ee790e56 233 * GCLK:f1 -> RTCPRE:f1;
mbed_official 592:a274ee790e56 234 * RTCPRE:f1 -> RTC:f1;
mbed_official 592:a274ee790e56 235 * }
mbed_official 592:a274ee790e56 236 * \enddot
mbed_official 592:a274ee790e56 237 *
mbed_official 592:a274ee790e56 238 * \subsubsection asfdoc_sam0_rtc_count_clock_saml SAM L21 Clock Setup
mbed_official 592:a274ee790e56 239 * The RTC clock can be selected from OSC32K,XOSC32K or OSCULP32K , and a 32KHz
mbed_official 592:a274ee790e56 240 * or 1KHz oscillator clock frequency is required. This clock must be
mbed_official 592:a274ee790e56 241 * configured and enabled in the 32KHz oscillator controller before using the RTC.
mbed_official 592:a274ee790e56 242 *
mbed_official 592:a274ee790e56 243 * The table below lists the available RTC clock \ref asfdoc_sam0_rtc_count_rtc_clk
mbed_official 592:a274ee790e56 244 *
mbed_official 592:a274ee790e56 245 * \anchor asfdoc_sam0_rtc_count_rtc_clk
mbed_official 592:a274ee790e56 246 * <table>
mbed_official 592:a274ee790e56 247 * <caption>RTC clocks source</caption>
mbed_official 592:a274ee790e56 248 * <tr>
mbed_official 592:a274ee790e56 249 * <th>RTC clock frequency</th>
mbed_official 592:a274ee790e56 250 * <th>Clock source</th>
mbed_official 592:a274ee790e56 251 * <th>Description</th>
mbed_official 592:a274ee790e56 252 * </tr>
mbed_official 592:a274ee790e56 253 * <tr>
mbed_official 592:a274ee790e56 254 * <td>1.024KHz</td>
mbed_official 592:a274ee790e56 255 * <td>ULP1K</td>
mbed_official 592:a274ee790e56 256 * <td>1.024KHz from 32KHz internal ULP oscillator</td>
mbed_official 592:a274ee790e56 257 * </tr>
mbed_official 592:a274ee790e56 258 * <tr>
mbed_official 592:a274ee790e56 259 * <td>32.768KHz</td>
mbed_official 592:a274ee790e56 260 * <td>ULP32K</td>
mbed_official 592:a274ee790e56 261 * <td>32.768KHz from 32KHz internal ULP oscillator</td>
mbed_official 592:a274ee790e56 262 * </tr>
mbed_official 592:a274ee790e56 263 * <tr>
mbed_official 592:a274ee790e56 264 * <td>1.024KHz</td>
mbed_official 592:a274ee790e56 265 * <td>OSC1K</td>
mbed_official 592:a274ee790e56 266 * <td>1.024KHz from 32KHz internal oscillator</td>
mbed_official 592:a274ee790e56 267 * </tr>
mbed_official 592:a274ee790e56 268 * <tr>
mbed_official 592:a274ee790e56 269 * <td>32.768KHz</td>
mbed_official 592:a274ee790e56 270 * <td>OSC32K</td>
mbed_official 592:a274ee790e56 271 * <td>32.768KHz from 32KHz internal oscillator</td>
mbed_official 592:a274ee790e56 272 * </tr>
mbed_official 592:a274ee790e56 273 * <tr>
mbed_official 592:a274ee790e56 274 * <td>1.024KHz</td>
mbed_official 592:a274ee790e56 275 * <td>XOSC1K</td>
mbed_official 592:a274ee790e56 276 * <td>1.024KHz from 32KHz internal oscillator</td>
mbed_official 592:a274ee790e56 277 * </tr>
mbed_official 592:a274ee790e56 278 * <tr>
mbed_official 592:a274ee790e56 279 * <td>32.768KHz</td>
mbed_official 592:a274ee790e56 280 * <td>XOSC32K</td>
mbed_official 592:a274ee790e56 281 * <td>32.768KHz from 32KHz external crystal oscillator</td>
mbed_official 592:a274ee790e56 282 * </tr>
mbed_official 592:a274ee790e56 283 * </table>
mbed_official 592:a274ee790e56 284 *
mbed_official 592:a274ee790e56 285 * \section asfdoc_sam0_rtc_count_extra_info Extra Information
mbed_official 592:a274ee790e56 286 *
mbed_official 592:a274ee790e56 287 * For extra information, see \ref asfdoc_sam0_rtc_count_extra. This includes:
mbed_official 592:a274ee790e56 288 * - \ref asfdoc_sam0_rtc_count_extra_acronyms
mbed_official 592:a274ee790e56 289 * - \ref asfdoc_sam0_rtc_count_extra_dependencies
mbed_official 592:a274ee790e56 290 * - \ref asfdoc_sam0_rtc_count_extra_errata
mbed_official 592:a274ee790e56 291 * - \ref asfdoc_sam0_rtc_count_extra_history
mbed_official 592:a274ee790e56 292 *
mbed_official 592:a274ee790e56 293 *
mbed_official 592:a274ee790e56 294 * \section asfdoc_sam0_rtc_count_examples Examples
mbed_official 592:a274ee790e56 295 *
mbed_official 592:a274ee790e56 296 * For a list of examples related to this driver, see
mbed_official 592:a274ee790e56 297 * \ref asfdoc_sam0_rtc_count_exqsg.
mbed_official 592:a274ee790e56 298 *
mbed_official 592:a274ee790e56 299 *
mbed_official 592:a274ee790e56 300 * \section asfdoc_sam0_rtc_count_api_overview API Overview
mbed_official 592:a274ee790e56 301 * @{
mbed_official 592:a274ee790e56 302 */
mbed_official 592:a274ee790e56 303
mbed_official 592:a274ee790e56 304 #include <compiler.h>
mbed_official 592:a274ee790e56 305 #include <conf_clocks.h>
mbed_official 592:a274ee790e56 306
mbed_official 592:a274ee790e56 307 #if RTC_COUNT_ASYNC == true
mbed_official 592:a274ee790e56 308 # include <system_interrupt.h>
mbed_official 592:a274ee790e56 309 #endif
mbed_official 592:a274ee790e56 310
mbed_official 592:a274ee790e56 311 #ifdef __cplusplus
mbed_official 592:a274ee790e56 312 extern "C" {
mbed_official 592:a274ee790e56 313 #endif
mbed_official 592:a274ee790e56 314
mbed_official 592:a274ee790e56 315 /**
mbed_official 592:a274ee790e56 316 * Define port features set according to different device family
mbed_official 592:a274ee790e56 317 * @{
mbed_official 592:a274ee790e56 318 */
mbed_official 592:a274ee790e56 319 #if (SAML21) || defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 320 /** RTC periodic interval interrupt. */
mbed_official 592:a274ee790e56 321 # define FEATURE_RTC_PERIODIC_INT
mbed_official 592:a274ee790e56 322 /** RTC prescaler is off. */
mbed_official 592:a274ee790e56 323 # define FEATURE_RTC_PRESCALER_OFF
mbed_official 592:a274ee790e56 324 /** RTC clock selection. */
mbed_official 592:a274ee790e56 325 # define FEATURE_RTC_CLOCK_SELECTION
mbed_official 592:a274ee790e56 326 /** General purpose registers. */
mbed_official 592:a274ee790e56 327 # define FEATURE_RTC_GENERAL_PURPOSE_REG
mbed_official 592:a274ee790e56 328 #else
mbed_official 592:a274ee790e56 329 /** RTC continuously updated. */
mbed_official 592:a274ee790e56 330 # define FEATURE_RTC_CONTINUOUSLY_UPDATED
mbed_official 592:a274ee790e56 331 #endif
mbed_official 592:a274ee790e56 332 /*@}*/
mbed_official 592:a274ee790e56 333
mbed_official 592:a274ee790e56 334 #ifdef FEATURE_RTC_CLOCK_SELECTION
mbed_official 592:a274ee790e56 335 /**
mbed_official 592:a274ee790e56 336 * \brief Available clock source for RTC.
mbed_official 592:a274ee790e56 337 * RTC clock source.
mbed_official 592:a274ee790e56 338 */
mbed_official 592:a274ee790e56 339 enum rtc_clock_sel {
mbed_official 592:a274ee790e56 340 /** 1.024KHz from 32KHz internal ULP oscillator. */
mbed_official 592:a274ee790e56 341 RTC_CLOCK_SELECTION_ULP1K = OSC32KCTRL_RTCCTRL_RTCSEL_ULP1K_Val,
mbed_official 592:a274ee790e56 342 /** 32.768KHz from 32KHz internal ULP oscillator. */
mbed_official 592:a274ee790e56 343 RTC_CLOCK_SELECTION_ULP32K = OSC32KCTRL_RTCCTRL_RTCSEL_ULP32K_Val,
mbed_official 592:a274ee790e56 344 /** 1.024KHz from 32KHz internal oscillator. */
mbed_official 592:a274ee790e56 345 RTC_CLOCK_SELECTION_OSC1K = OSC32KCTRL_RTCCTRL_RTCSEL_OSC1K_Val,
mbed_official 592:a274ee790e56 346 /** 32.768KHz from 32KHz internal oscillator. */
mbed_official 592:a274ee790e56 347 RTC_CLOCK_SELECTION_OSC32K = OSC32KCTRL_RTCCTRL_RTCSEL_OSC32K_Val,
mbed_official 592:a274ee790e56 348 /** 1.024KHz from 32KHz internal oscillator. */
mbed_official 592:a274ee790e56 349 RTC_CLOCK_SELECTION_XOSC1K = OSC32KCTRL_RTCCTRL_RTCSEL_XOSC1K_Val,
mbed_official 592:a274ee790e56 350 /** 32.768KHz from 32.768KHz external crystal oscillator. */
mbed_official 592:a274ee790e56 351 RTC_CLOCK_SELECTION_XOSC32K = OSC32KCTRL_RTCCTRL_RTCSEL_XOSC32K_Val,
mbed_official 592:a274ee790e56 352 };
mbed_official 592:a274ee790e56 353 #endif
mbed_official 592:a274ee790e56 354
mbed_official 592:a274ee790e56 355 /**
mbed_official 592:a274ee790e56 356 * \brief Available operation modes for the RTC.
mbed_official 592:a274ee790e56 357 *
mbed_official 592:a274ee790e56 358 * RTC Count operating modes, to select the counting width and associated module
mbed_official 592:a274ee790e56 359 * operation.
mbed_official 592:a274ee790e56 360 */
mbed_official 592:a274ee790e56 361 enum rtc_count_mode {
mbed_official 592:a274ee790e56 362 /** RTC Count module operates in 16-bit mode. */
mbed_official 592:a274ee790e56 363 RTC_COUNT_MODE_16BIT = 0,
mbed_official 592:a274ee790e56 364 /** RTC Count module operates in 32-bit mode. */
mbed_official 592:a274ee790e56 365 RTC_COUNT_MODE_32BIT = 1,
mbed_official 592:a274ee790e56 366 };
mbed_official 592:a274ee790e56 367
mbed_official 592:a274ee790e56 368 #if !defined (RTC_NUM_OF_COMP16) && defined(RTC_COMP16_NUM)
mbed_official 592:a274ee790e56 369 #define RTC_NUM_OF_COMP16 RTC_COMP16_NUM
mbed_official 592:a274ee790e56 370 #endif
mbed_official 592:a274ee790e56 371
mbed_official 592:a274ee790e56 372 /**
mbed_official 592:a274ee790e56 373 * \brief Available compare channels.
mbed_official 592:a274ee790e56 374 *
mbed_official 592:a274ee790e56 375 * \note Not all compare channels are available in all devices and modes.
mbed_official 592:a274ee790e56 376 */
mbed_official 592:a274ee790e56 377 enum rtc_count_compare {
mbed_official 592:a274ee790e56 378 /** Compare channel 0. */
mbed_official 592:a274ee790e56 379 RTC_COUNT_COMPARE_0 = 0,
mbed_official 592:a274ee790e56 380 #if (RTC_NUM_OF_COMP16 > 1) || defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 381 /** Compare channel 1. */
mbed_official 592:a274ee790e56 382 RTC_COUNT_COMPARE_1 = 1,
mbed_official 592:a274ee790e56 383 #endif
mbed_official 592:a274ee790e56 384 #if (RTC_NUM_OF_COMP16 > 2) || defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 385 /** Compare channel 2. */
mbed_official 592:a274ee790e56 386 RTC_COUNT_COMPARE_2 = 2,
mbed_official 592:a274ee790e56 387 #endif
mbed_official 592:a274ee790e56 388 #if (RTC_NUM_OF_COMP16 > 3) || defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 389 /** Compare channel 3. */
mbed_official 592:a274ee790e56 390 RTC_COUNT_COMPARE_3 = 3,
mbed_official 592:a274ee790e56 391 #endif
mbed_official 592:a274ee790e56 392 #if (RTC_NUM_OF_COMP16 > 4) || defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 393 /** Compare channel 4. */
mbed_official 592:a274ee790e56 394 RTC_COUNT_COMPARE_4 = 4,
mbed_official 592:a274ee790e56 395 #endif
mbed_official 592:a274ee790e56 396 #if (RTC_NUM_OF_COMP16 > 5) || defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 397 /** Compare channel 5. */
mbed_official 592:a274ee790e56 398 RTC_COUNT_COMPARE_5 = 5,
mbed_official 592:a274ee790e56 399 #endif
mbed_official 592:a274ee790e56 400 };
mbed_official 592:a274ee790e56 401
mbed_official 592:a274ee790e56 402 #ifdef FEATURE_RTC_PERIODIC_INT
mbed_official 592:a274ee790e56 403 /**
mbed_official 592:a274ee790e56 404 * \brief Available periodic interval source.
mbed_official 592:a274ee790e56 405 */
mbed_official 592:a274ee790e56 406 enum rtc_count_periodic_interval {
mbed_official 592:a274ee790e56 407 /** Periodic interval 0 */
mbed_official 592:a274ee790e56 408 RTC_COUNT_PERIODIC_INTERVAL_0 = 0,
mbed_official 592:a274ee790e56 409 /** Periodic interval 1 */
mbed_official 592:a274ee790e56 410 RTC_COUNT_PERIODIC_INTERVAL_1 = 1,
mbed_official 592:a274ee790e56 411 /** Periodic interval 2 */
mbed_official 592:a274ee790e56 412 RTC_COUNT_PERIODIC_INTERVAL_2 = 2,
mbed_official 592:a274ee790e56 413 /** Periodic interval 3 */
mbed_official 592:a274ee790e56 414 RTC_COUNT_PERIODIC_INTERVAL_3 = 3,
mbed_official 592:a274ee790e56 415 /** Periodic interval 4 */
mbed_official 592:a274ee790e56 416 RTC_COUNT_PERIODIC_INTERVAL_4 = 4,
mbed_official 592:a274ee790e56 417 /** Periodic interval 5 */
mbed_official 592:a274ee790e56 418 RTC_COUNT_PERIODIC_INTERVAL_5 = 5,
mbed_official 592:a274ee790e56 419 /** Periodic interval 6 */
mbed_official 592:a274ee790e56 420 RTC_COUNT_PERIODIC_INTERVAL_6 = 6,
mbed_official 592:a274ee790e56 421 /** Periodic interval 7 */
mbed_official 592:a274ee790e56 422 RTC_COUNT_PERIODIC_INTERVAL_7 = 7,
mbed_official 592:a274ee790e56 423 };
mbed_official 592:a274ee790e56 424 #endif
mbed_official 592:a274ee790e56 425
mbed_official 592:a274ee790e56 426 #if RTC_COUNT_ASYNC == true
mbed_official 592:a274ee790e56 427 #ifdef FEATURE_RTC_PERIODIC_INT
mbed_official 592:a274ee790e56 428 /**
mbed_official 592:a274ee790e56 429 * \brief Callback types.
mbed_official 592:a274ee790e56 430 *
mbed_official 592:a274ee790e56 431 * The available callback types for the RTC count module.
mbed_official 592:a274ee790e56 432 */
mbed_official 592:a274ee790e56 433 enum rtc_count_callback {
mbed_official 592:a274ee790e56 434 /** Callback for Periodic Interval 0 Interrupt. */
mbed_official 592:a274ee790e56 435 RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_0 = 0,
mbed_official 592:a274ee790e56 436 /** Callback for Periodic Interval 1 Interrupt. */
mbed_official 592:a274ee790e56 437 RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_1,
mbed_official 592:a274ee790e56 438 /** Callback for Periodic Interval 2 Interrupt. */
mbed_official 592:a274ee790e56 439 RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_2,
mbed_official 592:a274ee790e56 440 /** Callback for Periodic Interval 3 Interrupt. */
mbed_official 592:a274ee790e56 441 RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_3,
mbed_official 592:a274ee790e56 442 /** Callback for Periodic Interval 4 Interrupt. */
mbed_official 592:a274ee790e56 443 RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_4,
mbed_official 592:a274ee790e56 444 /** Callback for Periodic Interval 5 Interrupt. */
mbed_official 592:a274ee790e56 445 RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_5,
mbed_official 592:a274ee790e56 446 /** Callback for Periodic Interval 6 Interrupt. */
mbed_official 592:a274ee790e56 447 RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_6,
mbed_official 592:a274ee790e56 448 /** Callback for Periodic Interval 7 Interrupt. */
mbed_official 592:a274ee790e56 449 RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_7,
mbed_official 592:a274ee790e56 450 /** Callback for compare channel 0. */
mbed_official 592:a274ee790e56 451 RTC_COUNT_CALLBACK_COMPARE_0,
mbed_official 592:a274ee790e56 452 # if (RTC_NUM_OF_COMP16 > 1) || defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 453 /** Callback for compare channel 1. */
mbed_official 592:a274ee790e56 454 RTC_COUNT_CALLBACK_COMPARE_1,
mbed_official 592:a274ee790e56 455 # endif
mbed_official 592:a274ee790e56 456 # if (RTC_NUM_OF_COMP16 > 2) || defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 457 /** Callback for compare channel 2. */
mbed_official 592:a274ee790e56 458 RTC_COUNT_CALLBACK_COMPARE_2,
mbed_official 592:a274ee790e56 459 # endif
mbed_official 592:a274ee790e56 460 # if (RTC_NUM_OF_COMP16 > 3) || defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 461 /** Callback for compare channel 3. */
mbed_official 592:a274ee790e56 462 RTC_COUNT_CALLBACK_COMPARE_3,
mbed_official 592:a274ee790e56 463 # endif
mbed_official 592:a274ee790e56 464 # if (RTC_NUM_OF_COMP16 > 4) || defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 465 /** Callback for compare channel 4. */
mbed_official 592:a274ee790e56 466 RTC_COUNT_CALLBACK_COMPARE_4,
mbed_official 592:a274ee790e56 467 # endif
mbed_official 592:a274ee790e56 468 # if (RTC_NUM_OF_COMP16 > 5) || defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 469 /** Callback for compare channel 5. */
mbed_official 592:a274ee790e56 470 RTC_COUNT_CALLBACK_COMPARE_5,
mbed_official 592:a274ee790e56 471 # endif
mbed_official 592:a274ee790e56 472
mbed_official 592:a274ee790e56 473 /** Callback for overflow. */
mbed_official 592:a274ee790e56 474 RTC_COUNT_CALLBACK_OVERFLOW,
mbed_official 592:a274ee790e56 475 # if !defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 476 /** Total number of callbacks. */
mbed_official 592:a274ee790e56 477 _RTC_COUNT_CALLBACK_N
mbed_official 592:a274ee790e56 478 # endif
mbed_official 592:a274ee790e56 479 };
mbed_official 592:a274ee790e56 480 #else
mbed_official 592:a274ee790e56 481 /**
mbed_official 592:a274ee790e56 482 * \brief Callback types.
mbed_official 592:a274ee790e56 483 *
mbed_official 592:a274ee790e56 484 * The available callback types for the RTC count module.
mbed_official 592:a274ee790e56 485 */
mbed_official 592:a274ee790e56 486 enum rtc_count_callback {
mbed_official 592:a274ee790e56 487 /** Callback for compare channel 0. */
mbed_official 592:a274ee790e56 488 RTC_COUNT_CALLBACK_COMPARE_0 = 0,
mbed_official 592:a274ee790e56 489 # if (RTC_NUM_OF_COMP16 > 1) || defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 490 /** Callback for compare channel 1. */
mbed_official 592:a274ee790e56 491 RTC_COUNT_CALLBACK_COMPARE_1,
mbed_official 592:a274ee790e56 492 # endif
mbed_official 592:a274ee790e56 493 # if (RTC_NUM_OF_COMP16 > 2) || defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 494 /** Callback for compare channel 2. */
mbed_official 592:a274ee790e56 495 RTC_COUNT_CALLBACK_COMPARE_2,
mbed_official 592:a274ee790e56 496 # endif
mbed_official 592:a274ee790e56 497 # if (RTC_NUM_OF_COMP16 > 3) || defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 498 /** Callback for compare channel 3. */
mbed_official 592:a274ee790e56 499 RTC_COUNT_CALLBACK_COMPARE_3,
mbed_official 592:a274ee790e56 500 # endif
mbed_official 592:a274ee790e56 501 # if (RTC_NUM_OF_COMP16 > 4) || defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 502 /** Callback for compare channel 4. */
mbed_official 592:a274ee790e56 503 RTC_COUNT_CALLBACK_COMPARE_4,
mbed_official 592:a274ee790e56 504 # endif
mbed_official 592:a274ee790e56 505 # if (RTC_NUM_OF_COMP16 > 5) || defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 506 /** Callback for compare channel 5. */
mbed_official 592:a274ee790e56 507 RTC_COUNT_CALLBACK_COMPARE_5,
mbed_official 592:a274ee790e56 508 # endif
mbed_official 592:a274ee790e56 509 /** Callback for overflow. */
mbed_official 592:a274ee790e56 510 RTC_COUNT_CALLBACK_OVERFLOW,
mbed_official 592:a274ee790e56 511 # if !defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 512 /** Total number of callbacks. */
mbed_official 592:a274ee790e56 513 _RTC_COUNT_CALLBACK_N
mbed_official 592:a274ee790e56 514 # endif
mbed_official 592:a274ee790e56 515 };
mbed_official 592:a274ee790e56 516 #endif
mbed_official 592:a274ee790e56 517
mbed_official 592:a274ee790e56 518 # if !defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 519 typedef void (*rtc_count_callback_t)(void);
mbed_official 592:a274ee790e56 520 # endif
mbed_official 592:a274ee790e56 521 #endif
mbed_official 592:a274ee790e56 522
mbed_official 592:a274ee790e56 523 #ifdef FEATURE_RTC_PRESCALER_OFF
mbed_official 592:a274ee790e56 524 /**
mbed_official 592:a274ee790e56 525 * \brief RTC input clock prescaler settings.
mbed_official 592:a274ee790e56 526 *
mbed_official 592:a274ee790e56 527 * The available input clock prescaler values for the RTC count module.
mbed_official 592:a274ee790e56 528 */
mbed_official 592:a274ee790e56 529 enum rtc_count_prescaler {
mbed_official 592:a274ee790e56 530 /** RTC prescaler is off, and the input clock frequency is
mbed_official 592:a274ee790e56 531 prescaled by a factor of 1. */
mbed_official 592:a274ee790e56 532 RTC_COUNT_PRESCALER_OFF = RTC_MODE0_CTRLA_PRESCALER_OFF,
mbed_official 592:a274ee790e56 533 /** RTC input clock frequency is prescaled by a factor of 1. */
mbed_official 592:a274ee790e56 534 RTC_COUNT_PRESCALER_DIV_1 = RTC_MODE0_CTRLA_PRESCALER_DIV1,
mbed_official 592:a274ee790e56 535 /** RTC input clock frequency is prescaled by a factor of 2. */
mbed_official 592:a274ee790e56 536 RTC_COUNT_PRESCALER_DIV_2 = RTC_MODE0_CTRLA_PRESCALER_DIV2,
mbed_official 592:a274ee790e56 537 /** RTC input clock frequency is prescaled by a factor of 4. */
mbed_official 592:a274ee790e56 538 RTC_COUNT_PRESCALER_DIV_4 = RTC_MODE0_CTRLA_PRESCALER_DIV4,
mbed_official 592:a274ee790e56 539 /** RTC input clock frequency is prescaled by a factor of 8. */
mbed_official 592:a274ee790e56 540 RTC_COUNT_PRESCALER_DIV_8 = RTC_MODE0_CTRLA_PRESCALER_DIV8,
mbed_official 592:a274ee790e56 541 /** RTC input clock frequency is prescaled by a factor of 16. */
mbed_official 592:a274ee790e56 542 RTC_COUNT_PRESCALER_DIV_16 = RTC_MODE0_CTRLA_PRESCALER_DIV16,
mbed_official 592:a274ee790e56 543 /** RTC input clock frequency is prescaled by a factor of 32. */
mbed_official 592:a274ee790e56 544 RTC_COUNT_PRESCALER_DIV_32 = RTC_MODE0_CTRLA_PRESCALER_DIV32,
mbed_official 592:a274ee790e56 545 /** RTC input clock frequency is prescaled by a factor of 64. */
mbed_official 592:a274ee790e56 546 RTC_COUNT_PRESCALER_DIV_64 = RTC_MODE0_CTRLA_PRESCALER_DIV64,
mbed_official 592:a274ee790e56 547 /** RTC input clock frequency is prescaled by a factor of 128. */
mbed_official 592:a274ee790e56 548 RTC_COUNT_PRESCALER_DIV_128 = RTC_MODE0_CTRLA_PRESCALER_DIV128,
mbed_official 592:a274ee790e56 549 /** RTC input clock frequency is prescaled by a factor of 256. */
mbed_official 592:a274ee790e56 550 RTC_COUNT_PRESCALER_DIV_256 = RTC_MODE0_CTRLA_PRESCALER_DIV256,
mbed_official 592:a274ee790e56 551 /** RTC input clock frequency is prescaled by a factor of 512. */
mbed_official 592:a274ee790e56 552 RTC_COUNT_PRESCALER_DIV_512 = RTC_MODE0_CTRLA_PRESCALER_DIV512,
mbed_official 592:a274ee790e56 553 /** RTC input clock frequency is prescaled by a factor of 1024. */
mbed_official 592:a274ee790e56 554 RTC_COUNT_PRESCALER_DIV_1024 = RTC_MODE0_CTRLA_PRESCALER_DIV1024,
mbed_official 592:a274ee790e56 555 };
mbed_official 592:a274ee790e56 556 #else
mbed_official 592:a274ee790e56 557 /**
mbed_official 592:a274ee790e56 558 * \brief RTC input clock prescaler settings.
mbed_official 592:a274ee790e56 559 *
mbed_official 592:a274ee790e56 560 * The available input clock prescaler values for the RTC count module.
mbed_official 592:a274ee790e56 561 */
mbed_official 592:a274ee790e56 562 enum rtc_count_prescaler {
mbed_official 592:a274ee790e56 563 /** RTC input clock frequency is prescaled by a factor of 1. */
mbed_official 592:a274ee790e56 564 RTC_COUNT_PRESCALER_DIV_1 = RTC_MODE0_CTRL_PRESCALER_DIV1,
mbed_official 592:a274ee790e56 565 /** RTC input clock frequency is prescaled by a factor of 2. */
mbed_official 592:a274ee790e56 566 RTC_COUNT_PRESCALER_DIV_2 = RTC_MODE0_CTRL_PRESCALER_DIV2,
mbed_official 592:a274ee790e56 567 /** RTC input clock frequency is prescaled by a factor of 4. */
mbed_official 592:a274ee790e56 568 RTC_COUNT_PRESCALER_DIV_4 = RTC_MODE0_CTRL_PRESCALER_DIV4,
mbed_official 592:a274ee790e56 569 /** RTC input clock frequency is prescaled by a factor of 8. */
mbed_official 592:a274ee790e56 570 RTC_COUNT_PRESCALER_DIV_8 = RTC_MODE0_CTRL_PRESCALER_DIV8,
mbed_official 592:a274ee790e56 571 /** RTC input clock frequency is prescaled by a factor of 16. */
mbed_official 592:a274ee790e56 572 RTC_COUNT_PRESCALER_DIV_16 = RTC_MODE0_CTRL_PRESCALER_DIV16,
mbed_official 592:a274ee790e56 573 /** RTC input clock frequency is prescaled by a factor of 32. */
mbed_official 592:a274ee790e56 574 RTC_COUNT_PRESCALER_DIV_32 = RTC_MODE0_CTRL_PRESCALER_DIV32,
mbed_official 592:a274ee790e56 575 /** RTC input clock frequency is prescaled by a factor of 64. */
mbed_official 592:a274ee790e56 576 RTC_COUNT_PRESCALER_DIV_64 = RTC_MODE0_CTRL_PRESCALER_DIV64,
mbed_official 592:a274ee790e56 577 /** RTC input clock frequency is prescaled by a factor of 128. */
mbed_official 592:a274ee790e56 578 RTC_COUNT_PRESCALER_DIV_128 = RTC_MODE0_CTRL_PRESCALER_DIV128,
mbed_official 592:a274ee790e56 579 /** RTC input clock frequency is prescaled by a factor of 256. */
mbed_official 592:a274ee790e56 580 RTC_COUNT_PRESCALER_DIV_256 = RTC_MODE0_CTRL_PRESCALER_DIV256,
mbed_official 592:a274ee790e56 581 /** RTC input clock frequency is prescaled by a factor of 512. */
mbed_official 592:a274ee790e56 582 RTC_COUNT_PRESCALER_DIV_512 = RTC_MODE0_CTRL_PRESCALER_DIV512,
mbed_official 592:a274ee790e56 583 /** RTC input clock frequency is prescaled by a factor of 1024. */
mbed_official 592:a274ee790e56 584 RTC_COUNT_PRESCALER_DIV_1024 = RTC_MODE0_CTRL_PRESCALER_DIV1024,
mbed_official 592:a274ee790e56 585 };
mbed_official 592:a274ee790e56 586 #endif
mbed_official 592:a274ee790e56 587
mbed_official 592:a274ee790e56 588 /**
mbed_official 592:a274ee790e56 589 * \brief RTC Count event enable/disable structure.
mbed_official 592:a274ee790e56 590 *
mbed_official 592:a274ee790e56 591 * Event flags for the \ref rtc_count_enable_events() and
mbed_official 592:a274ee790e56 592 * \ref rtc_count_disable_events().
mbed_official 592:a274ee790e56 593 */
mbed_official 592:a274ee790e56 594 struct rtc_count_events {
mbed_official 592:a274ee790e56 595 /** Generate an output event on each overflow of the RTC count. */
mbed_official 592:a274ee790e56 596 bool generate_event_on_overflow;
mbed_official 592:a274ee790e56 597 /** Generate an output event on a compare channel match against the RTC
mbed_official 592:a274ee790e56 598 * count. */
mbed_official 592:a274ee790e56 599 bool generate_event_on_compare[RTC_NUM_OF_COMP16];
mbed_official 592:a274ee790e56 600 /** Generate an output event periodically at a binary division of the RTC
mbed_official 592:a274ee790e56 601 * counter frequency. */
mbed_official 592:a274ee790e56 602 bool generate_event_on_periodic[8];
mbed_official 592:a274ee790e56 603 };
mbed_official 592:a274ee790e56 604
mbed_official 592:a274ee790e56 605 #if !defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 606 /**
mbed_official 592:a274ee790e56 607 * \brief Device structure.
mbed_official 592:a274ee790e56 608 */
mbed_official 592:a274ee790e56 609 struct rtc_module {
mbed_official 592:a274ee790e56 610 /** RTC hardware module. */
mbed_official 592:a274ee790e56 611 Rtc *hw;
mbed_official 592:a274ee790e56 612 /** Operation mode of count. */
mbed_official 592:a274ee790e56 613 enum rtc_count_mode mode;
mbed_official 592:a274ee790e56 614 #ifdef FEATURE_RTC_CONTINUOUSLY_UPDATED
mbed_official 592:a274ee790e56 615 /** Set if counter value should be continuously updated. */
mbed_official 592:a274ee790e56 616 bool continuously_update;
mbed_official 592:a274ee790e56 617 #endif
mbed_official 592:a274ee790e56 618 # if RTC_COUNT_ASYNC == true
mbed_official 592:a274ee790e56 619 /** Pointers to callback functions. */
mbed_official 592:a274ee790e56 620 volatile rtc_count_callback_t callbacks[_RTC_COUNT_CALLBACK_N];
mbed_official 592:a274ee790e56 621 /** Mask for registered callbacks. */
mbed_official 592:a274ee790e56 622 volatile uint16_t registered_callback;
mbed_official 592:a274ee790e56 623 /** Mask for enabled callbacks. */
mbed_official 592:a274ee790e56 624 volatile uint16_t enabled_callback;
mbed_official 592:a274ee790e56 625 # endif
mbed_official 592:a274ee790e56 626 };
mbed_official 592:a274ee790e56 627 #endif
mbed_official 592:a274ee790e56 628
mbed_official 592:a274ee790e56 629 /**
mbed_official 592:a274ee790e56 630 * \brief RTC Count configuration structure.
mbed_official 592:a274ee790e56 631 *
mbed_official 592:a274ee790e56 632 * Configuration structure for the RTC instance. This structure should
mbed_official 592:a274ee790e56 633 * be initialized using the \ref rtc_count_get_config_defaults() before any
mbed_official 592:a274ee790e56 634 * user configurations are set.
mbed_official 592:a274ee790e56 635 */
mbed_official 592:a274ee790e56 636 struct rtc_count_config {
mbed_official 592:a274ee790e56 637 /** Input clock prescaler for the RTC module. */
mbed_official 592:a274ee790e56 638 enum rtc_count_prescaler prescaler;
mbed_official 592:a274ee790e56 639 /** Select the operation mode of the RTC.*/
mbed_official 592:a274ee790e56 640 enum rtc_count_mode mode;
mbed_official 592:a274ee790e56 641 /** If true, clears the counter value on compare match. Only available
mbed_official 592:a274ee790e56 642 * whilst running in 32-bit mode. */
mbed_official 592:a274ee790e56 643 bool clear_on_match;
mbed_official 592:a274ee790e56 644 #ifdef FEATURE_RTC_CONTINUOUSLY_UPDATED
mbed_official 592:a274ee790e56 645 /** Continuously update the counter value so no synchronization is
mbed_official 592:a274ee790e56 646 * needed for reading. */
mbed_official 592:a274ee790e56 647 bool continuously_update;
mbed_official 592:a274ee790e56 648 #endif
mbed_official 592:a274ee790e56 649 /** Array of Compare values. Not all Compare values are available in 32-bit
mbed_official 592:a274ee790e56 650 * mode. */
mbed_official 592:a274ee790e56 651 uint32_t compare_values[RTC_NUM_OF_COMP16];
mbed_official 592:a274ee790e56 652 };
mbed_official 592:a274ee790e56 653
mbed_official 592:a274ee790e56 654
mbed_official 592:a274ee790e56 655 /**
mbed_official 592:a274ee790e56 656 * \name Configuration and Initialization
mbed_official 592:a274ee790e56 657 * @{
mbed_official 592:a274ee790e56 658 */
mbed_official 592:a274ee790e56 659
mbed_official 592:a274ee790e56 660 /**
mbed_official 592:a274ee790e56 661 * \brief Gets the RTC default configurations.
mbed_official 592:a274ee790e56 662 *
mbed_official 592:a274ee790e56 663 * Initializes the configuration structure to default values. This
mbed_official 592:a274ee790e56 664 * function should be called at the start of any RTC initialization.
mbed_official 592:a274ee790e56 665 *
mbed_official 592:a274ee790e56 666 * The default configuration is as follows:
mbed_official 592:a274ee790e56 667 * - Input clock divided by a factor of 1024
mbed_official 592:a274ee790e56 668 * - RTC in 32-bit mode
mbed_official 592:a274ee790e56 669 * - Clear on compare match off
mbed_official 592:a274ee790e56 670 * - Continuously sync count register off
mbed_official 592:a274ee790e56 671 * - No event source on
mbed_official 592:a274ee790e56 672 * - All compare values equal 0
mbed_official 592:a274ee790e56 673 *
mbed_official 592:a274ee790e56 674 * \param[out] config Configuration structure to be initialized to default
mbed_official 592:a274ee790e56 675 * values.
mbed_official 592:a274ee790e56 676 */
mbed_official 592:a274ee790e56 677 static inline void rtc_count_get_config_defaults(
mbed_official 592:a274ee790e56 678 struct rtc_count_config *const config)
mbed_official 592:a274ee790e56 679 {
mbed_official 592:a274ee790e56 680 /* Sanity check argument */
mbed_official 592:a274ee790e56 681 Assert(config);
mbed_official 592:a274ee790e56 682
mbed_official 592:a274ee790e56 683 /* Set default into configuration structure */
mbed_official 592:a274ee790e56 684 config->prescaler = RTC_COUNT_PRESCALER_DIV_1024;
mbed_official 592:a274ee790e56 685 config->mode = RTC_COUNT_MODE_32BIT;
mbed_official 592:a274ee790e56 686 config->clear_on_match = false;
mbed_official 592:a274ee790e56 687
mbed_official 592:a274ee790e56 688 #ifdef FEATURE_RTC_CONTINUOUSLY_UPDATED
mbed_official 592:a274ee790e56 689 config->continuously_update = false;
mbed_official 592:a274ee790e56 690 #endif
mbed_official 592:a274ee790e56 691
mbed_official 592:a274ee790e56 692 for (uint8_t i = 0; i < RTC_NUM_OF_COMP16; i++) {
mbed_official 592:a274ee790e56 693 config->compare_values[i] = 0;
mbed_official 592:a274ee790e56 694 }
mbed_official 592:a274ee790e56 695 }
mbed_official 592:a274ee790e56 696
mbed_official 592:a274ee790e56 697 void rtc_count_reset(struct rtc_module *const module);
mbed_official 592:a274ee790e56 698 void rtc_count_enable(struct rtc_module *const module);
mbed_official 592:a274ee790e56 699 void rtc_count_disable(struct rtc_module *const module);
mbed_official 592:a274ee790e56 700
mbed_official 592:a274ee790e56 701 #if (RTC_INST_NUM > 1) && !defined(__DOXYGEN__)
mbed_official 592:a274ee790e56 702 /**
mbed_official 592:a274ee790e56 703 * \internal Find the index of given RTC module instance.
mbed_official 592:a274ee790e56 704 *
mbed_official 592:a274ee790e56 705 * \param[in] RTC module instance pointer
mbed_official 592:a274ee790e56 706 *
mbed_official 592:a274ee790e56 707 * \return Index of the given AC module instance.
mbed_official 592:a274ee790e56 708 */
mbed_official 592:a274ee790e56 709 uint8_t _rtc_get_inst_index(
mbed_official 592:a274ee790e56 710 Rtc *const hw)
mbed_official 592:a274ee790e56 711 {
mbed_official 592:a274ee790e56 712 /* List of available RTC modules. */
mbed_official 592:a274ee790e56 713 static Rtc *const rtc_modules[RTC_INST_NUM] = RTC_INSTS;
mbed_official 592:a274ee790e56 714
mbed_official 592:a274ee790e56 715 /* Find index for RTC instance. */
mbed_official 592:a274ee790e56 716 for (uint32_t i = 0; i < RTC_INST_NUM; i++) {
mbed_official 592:a274ee790e56 717 if (hw == rtc_modules[i]) {
mbed_official 592:a274ee790e56 718 return i;
mbed_official 592:a274ee790e56 719 }
mbed_official 592:a274ee790e56 720 }
mbed_official 592:a274ee790e56 721
mbed_official 592:a274ee790e56 722 /* Invalid data given. */
mbed_official 592:a274ee790e56 723 Assert(false);
mbed_official 592:a274ee790e56 724 return 0;
mbed_official 592:a274ee790e56 725 }
mbed_official 592:a274ee790e56 726 #endif /* (RTC_INST_NUM > 1) && !defined(__DOXYGEN__) */
mbed_official 592:a274ee790e56 727
mbed_official 592:a274ee790e56 728 enum status_code rtc_count_init(
mbed_official 592:a274ee790e56 729 struct rtc_module *const module,
mbed_official 592:a274ee790e56 730 Rtc *const hw,
mbed_official 592:a274ee790e56 731 const struct rtc_count_config *const config);
mbed_official 592:a274ee790e56 732
mbed_official 592:a274ee790e56 733 enum status_code rtc_count_frequency_correction(
mbed_official 592:a274ee790e56 734 struct rtc_module *const module,
mbed_official 592:a274ee790e56 735 const int8_t value);
mbed_official 592:a274ee790e56 736
mbed_official 592:a274ee790e56 737 /** @} */
mbed_official 592:a274ee790e56 738
mbed_official 592:a274ee790e56 739 /** \name Count and Compare Value Management
mbed_official 592:a274ee790e56 740 * @{
mbed_official 592:a274ee790e56 741 */
mbed_official 592:a274ee790e56 742 enum status_code rtc_count_set_count(
mbed_official 592:a274ee790e56 743 struct rtc_module *const module,
mbed_official 592:a274ee790e56 744 const uint32_t count_value);
mbed_official 592:a274ee790e56 745
mbed_official 592:a274ee790e56 746 uint32_t rtc_count_get_count(struct rtc_module *const module);
mbed_official 592:a274ee790e56 747
mbed_official 592:a274ee790e56 748 enum status_code rtc_count_set_compare(
mbed_official 592:a274ee790e56 749 struct rtc_module *const module,
mbed_official 592:a274ee790e56 750 const uint32_t comp_value,
mbed_official 592:a274ee790e56 751 const enum rtc_count_compare comp_index);
mbed_official 592:a274ee790e56 752
mbed_official 592:a274ee790e56 753 enum status_code rtc_count_get_compare(
mbed_official 592:a274ee790e56 754 struct rtc_module *const module,
mbed_official 592:a274ee790e56 755 uint32_t *const comp_value,
mbed_official 592:a274ee790e56 756 const enum rtc_count_compare comp_index);
mbed_official 592:a274ee790e56 757
mbed_official 592:a274ee790e56 758 enum status_code rtc_count_set_period(
mbed_official 592:a274ee790e56 759 struct rtc_module *const module,
mbed_official 592:a274ee790e56 760 uint16_t period_value);
mbed_official 592:a274ee790e56 761
mbed_official 592:a274ee790e56 762 enum status_code rtc_count_get_period(
mbed_official 592:a274ee790e56 763 struct rtc_module *const module,
mbed_official 592:a274ee790e56 764 uint16_t *const period_value);
mbed_official 592:a274ee790e56 765
mbed_official 592:a274ee790e56 766 /** @} */
mbed_official 592:a274ee790e56 767
mbed_official 592:a274ee790e56 768
mbed_official 592:a274ee790e56 769 /** \name Status Management
mbed_official 592:a274ee790e56 770 * @{
mbed_official 592:a274ee790e56 771 */
mbed_official 592:a274ee790e56 772
mbed_official 592:a274ee790e56 773 /**
mbed_official 592:a274ee790e56 774 * \brief Check if an RTC overflow has occurred.
mbed_official 592:a274ee790e56 775 *
mbed_official 592:a274ee790e56 776 * Checks the overflow flag in the RTC. The flag is set when there
mbed_official 592:a274ee790e56 777 * is an overflow in the clock.
mbed_official 592:a274ee790e56 778 *
mbed_official 592:a274ee790e56 779 * \param[in,out] module RTC hardware module
mbed_official 592:a274ee790e56 780 *
mbed_official 592:a274ee790e56 781 * \return Overflow state of the RTC module.
mbed_official 592:a274ee790e56 782 *
mbed_official 592:a274ee790e56 783 * \retval true If the RTC count value has overflowed
mbed_official 592:a274ee790e56 784 * \retval false If the RTC count value has not overflowed
mbed_official 592:a274ee790e56 785 */
mbed_official 592:a274ee790e56 786
mbed_official 592:a274ee790e56 787 static inline bool rtc_count_is_overflow(struct rtc_module *const module)
mbed_official 592:a274ee790e56 788 {
mbed_official 592:a274ee790e56 789 /* Sanity check arguments */
mbed_official 592:a274ee790e56 790 Assert(module);
mbed_official 592:a274ee790e56 791 Assert(module->hw);
mbed_official 592:a274ee790e56 792
mbed_official 592:a274ee790e56 793 Rtc *const rtc_module = module->hw;
mbed_official 592:a274ee790e56 794
mbed_official 592:a274ee790e56 795 /* Return status of flag */
mbed_official 592:a274ee790e56 796 return (rtc_module->MODE0.INTFLAG.reg & RTC_MODE0_INTFLAG_OVF);
mbed_official 592:a274ee790e56 797 }
mbed_official 592:a274ee790e56 798
mbed_official 592:a274ee790e56 799 /**
mbed_official 592:a274ee790e56 800 * \brief Clears the RTC overflow flag.
mbed_official 592:a274ee790e56 801 *
mbed_official 592:a274ee790e56 802 * Clears the RTC module counter overflow flag, so that new overflow conditions
mbed_official 592:a274ee790e56 803 * can be detected.
mbed_official 592:a274ee790e56 804 *
mbed_official 592:a274ee790e56 805 * \param[in,out] module RTC hardware module
mbed_official 592:a274ee790e56 806 */
mbed_official 592:a274ee790e56 807 static inline void rtc_count_clear_overflow(struct rtc_module *const module)
mbed_official 592:a274ee790e56 808 {
mbed_official 592:a274ee790e56 809 /* Sanity check arguments */
mbed_official 592:a274ee790e56 810 Assert(module);
mbed_official 592:a274ee790e56 811 Assert(module->hw);
mbed_official 592:a274ee790e56 812
mbed_official 592:a274ee790e56 813 Rtc *const rtc_module = module->hw;
mbed_official 592:a274ee790e56 814
mbed_official 592:a274ee790e56 815 /* Clear OVF flag */
mbed_official 592:a274ee790e56 816 rtc_module->MODE0.INTFLAG.reg = RTC_MODE0_INTFLAG_OVF;
mbed_official 592:a274ee790e56 817 }
mbed_official 592:a274ee790e56 818
mbed_official 592:a274ee790e56 819 #ifdef FEATURE_RTC_PERIODIC_INT
mbed_official 592:a274ee790e56 820 /**
mbed_official 592:a274ee790e56 821 * \brief Check if an RTC periodic interval interrupt has occurred.
mbed_official 592:a274ee790e56 822 *
mbed_official 592:a274ee790e56 823 * Checks the periodic interval flag in the RTC.
mbed_official 592:a274ee790e56 824 *
mbed_official 592:a274ee790e56 825 * \param[in,out] module RTC hardware module
mbed_official 592:a274ee790e56 826 * \param[in] n RTC periodic interval interrupt
mbed_official 592:a274ee790e56 827 *
mbed_official 592:a274ee790e56 828 * \return periodic interval interrupt state of the RTC module.
mbed_official 592:a274ee790e56 829 *
mbed_official 592:a274ee790e56 830 * \retval true RTC periodic interval interrupt occurs
mbed_official 592:a274ee790e56 831 * \retval false RTC periodic interval interrupt dosen't occurs
mbed_official 592:a274ee790e56 832 */
mbed_official 592:a274ee790e56 833 static inline bool rtc_count_is_periodic_interval(struct rtc_module *const module,
mbed_official 592:a274ee790e56 834 enum rtc_count_periodic_interval n)
mbed_official 592:a274ee790e56 835 {
mbed_official 592:a274ee790e56 836 /* Sanity check arguments */
mbed_official 592:a274ee790e56 837 Assert(module);
mbed_official 592:a274ee790e56 838 Assert(module->hw);
mbed_official 592:a274ee790e56 839
mbed_official 592:a274ee790e56 840 Rtc *const rtc_module = module->hw;
mbed_official 592:a274ee790e56 841
mbed_official 592:a274ee790e56 842 /* Return status of flag */
mbed_official 592:a274ee790e56 843 return (rtc_module->MODE0.INTFLAG.reg & RTC_MODE0_INTFLAG_PER(1 << n));
mbed_official 592:a274ee790e56 844 }
mbed_official 592:a274ee790e56 845
mbed_official 592:a274ee790e56 846 /**
mbed_official 592:a274ee790e56 847 * \brief Clears the RTC periodic interval flag.
mbed_official 592:a274ee790e56 848 *
mbed_official 592:a274ee790e56 849 * Clears the RTC module counter periodic interval flag, so that new periodic
mbed_official 592:a274ee790e56 850 * interval conditions can be detected.
mbed_official 592:a274ee790e56 851 *
mbed_official 592:a274ee790e56 852 * \param[in,out] module RTC hardware module
mbed_official 592:a274ee790e56 853 * \param[in] n RTC periodic interval interrupt
mbed_official 592:a274ee790e56 854 */
mbed_official 592:a274ee790e56 855 static inline void rtc_count_clear_periodic_interval(struct rtc_module *const module,
mbed_official 592:a274ee790e56 856 enum rtc_count_periodic_interval n)
mbed_official 592:a274ee790e56 857 {
mbed_official 592:a274ee790e56 858 /* Sanity check arguments */
mbed_official 592:a274ee790e56 859 Assert(module);
mbed_official 592:a274ee790e56 860 Assert(module->hw);
mbed_official 592:a274ee790e56 861
mbed_official 592:a274ee790e56 862 Rtc *const rtc_module = module->hw;
mbed_official 592:a274ee790e56 863
mbed_official 592:a274ee790e56 864 /* Clear periodic interval flag */
mbed_official 592:a274ee790e56 865 rtc_module->MODE0.INTFLAG.reg = RTC_MODE0_INTFLAG_PER(1 << n);
mbed_official 592:a274ee790e56 866 }
mbed_official 592:a274ee790e56 867 #endif
mbed_official 592:a274ee790e56 868 bool rtc_count_is_compare_match(
mbed_official 592:a274ee790e56 869 struct rtc_module *const module,
mbed_official 592:a274ee790e56 870 const enum rtc_count_compare comp_index);
mbed_official 592:a274ee790e56 871
mbed_official 592:a274ee790e56 872 enum status_code rtc_count_clear_compare_match(
mbed_official 592:a274ee790e56 873 struct rtc_module *const module,
mbed_official 592:a274ee790e56 874 const enum rtc_count_compare comp_index);
mbed_official 592:a274ee790e56 875
mbed_official 592:a274ee790e56 876 /** @} */
mbed_official 592:a274ee790e56 877
mbed_official 592:a274ee790e56 878
mbed_official 592:a274ee790e56 879 /**
mbed_official 592:a274ee790e56 880 * \name Event Management
mbed_official 592:a274ee790e56 881 * @{
mbed_official 592:a274ee790e56 882 */
mbed_official 592:a274ee790e56 883
mbed_official 592:a274ee790e56 884 /**
mbed_official 592:a274ee790e56 885 * \brief Enables a RTC event output.
mbed_official 592:a274ee790e56 886 *
mbed_official 592:a274ee790e56 887 * Enables one or more output events from the RTC module. See
mbed_official 592:a274ee790e56 888 * \ref rtc_count_events for a list of events this module supports.
mbed_official 592:a274ee790e56 889 *
mbed_official 592:a274ee790e56 890 * \note Events cannot be altered while the module is enabled.
mbed_official 592:a274ee790e56 891 *
mbed_official 592:a274ee790e56 892 * \param[in,out] module RTC hardware module
mbed_official 592:a274ee790e56 893 * \param[in] events Struct containing flags of events to enable
mbed_official 592:a274ee790e56 894 */
mbed_official 592:a274ee790e56 895 static inline void rtc_count_enable_events(
mbed_official 592:a274ee790e56 896 struct rtc_module *const module,
mbed_official 592:a274ee790e56 897 struct rtc_count_events *const events)
mbed_official 592:a274ee790e56 898 {
mbed_official 592:a274ee790e56 899 /* Sanity check arguments */
mbed_official 592:a274ee790e56 900 Assert(module);
mbed_official 592:a274ee790e56 901 Assert(module->hw);
mbed_official 592:a274ee790e56 902
mbed_official 592:a274ee790e56 903 Rtc *const rtc_module = module->hw;
mbed_official 592:a274ee790e56 904
mbed_official 592:a274ee790e56 905 uint32_t event_mask = 0;
mbed_official 592:a274ee790e56 906
mbed_official 592:a274ee790e56 907 /* Check if the user has requested an overflow event. */
mbed_official 592:a274ee790e56 908 if (events->generate_event_on_overflow) {
mbed_official 592:a274ee790e56 909 event_mask |= RTC_MODE0_EVCTRL_OVFEO;
mbed_official 592:a274ee790e56 910 }
mbed_official 592:a274ee790e56 911
mbed_official 592:a274ee790e56 912 /* Check if the user has requested any compare events. */
mbed_official 592:a274ee790e56 913 for (uint8_t i = 0; i < RTC_NUM_OF_COMP16; i++) {
mbed_official 592:a274ee790e56 914 if (events->generate_event_on_compare[i]) {
mbed_official 592:a274ee790e56 915 event_mask |= RTC_MODE0_EVCTRL_CMPEO(1 << i);
mbed_official 592:a274ee790e56 916 }
mbed_official 592:a274ee790e56 917 }
mbed_official 592:a274ee790e56 918
mbed_official 592:a274ee790e56 919 /* Check if the user has requested any periodic events. */
mbed_official 592:a274ee790e56 920 for (uint8_t i = 0; i < 8; i++) {
mbed_official 592:a274ee790e56 921 if (events->generate_event_on_periodic[i]) {
mbed_official 592:a274ee790e56 922 event_mask |= RTC_MODE0_EVCTRL_PEREO(1 << i);
mbed_official 592:a274ee790e56 923 }
mbed_official 592:a274ee790e56 924 }
mbed_official 592:a274ee790e56 925
mbed_official 592:a274ee790e56 926 /* Enable given event(s). */
mbed_official 592:a274ee790e56 927 rtc_module->MODE0.EVCTRL.reg |= event_mask;
mbed_official 592:a274ee790e56 928 }
mbed_official 592:a274ee790e56 929
mbed_official 592:a274ee790e56 930 /**
mbed_official 592:a274ee790e56 931 * \brief Disables a RTC event output.
mbed_official 592:a274ee790e56 932 *
mbed_official 592:a274ee790e56 933 * Disabled one or more output events from the RTC module. See
mbed_official 592:a274ee790e56 934 * \ref rtc_count_events for a list of events this module supports.
mbed_official 592:a274ee790e56 935 *
mbed_official 592:a274ee790e56 936 * \note Events cannot be altered while the module is enabled.
mbed_official 592:a274ee790e56 937 *
mbed_official 592:a274ee790e56 938 * \param[in,out] module RTC hardware module
mbed_official 592:a274ee790e56 939 * \param[in] events Struct containing flags of events to disable
mbed_official 592:a274ee790e56 940 */
mbed_official 592:a274ee790e56 941 static inline void rtc_count_disable_events(
mbed_official 592:a274ee790e56 942 struct rtc_module *const module,
mbed_official 592:a274ee790e56 943 struct rtc_count_events *const events)
mbed_official 592:a274ee790e56 944 {
mbed_official 592:a274ee790e56 945 /* Sanity check arguments */
mbed_official 592:a274ee790e56 946 Assert(module);
mbed_official 592:a274ee790e56 947 Assert(module->hw);
mbed_official 592:a274ee790e56 948
mbed_official 592:a274ee790e56 949 Rtc *const rtc_module = module->hw;
mbed_official 592:a274ee790e56 950
mbed_official 592:a274ee790e56 951 uint32_t event_mask = 0;
mbed_official 592:a274ee790e56 952
mbed_official 592:a274ee790e56 953 /* Check if the user has requested an overflow event. */
mbed_official 592:a274ee790e56 954 if (events->generate_event_on_overflow) {
mbed_official 592:a274ee790e56 955 event_mask |= RTC_MODE0_EVCTRL_OVFEO;
mbed_official 592:a274ee790e56 956 }
mbed_official 592:a274ee790e56 957
mbed_official 592:a274ee790e56 958 /* Check if the user has requested any compare events. */
mbed_official 592:a274ee790e56 959 for (uint8_t i = 0; i < RTC_NUM_OF_COMP16; i++) {
mbed_official 592:a274ee790e56 960 if (events->generate_event_on_compare[i]) {
mbed_official 592:a274ee790e56 961 event_mask |= RTC_MODE0_EVCTRL_CMPEO(1 << i);
mbed_official 592:a274ee790e56 962 }
mbed_official 592:a274ee790e56 963 }
mbed_official 592:a274ee790e56 964
mbed_official 592:a274ee790e56 965 /* Check if the user has requested any periodic events. */
mbed_official 592:a274ee790e56 966 for (uint8_t i = 0; i < 8; i++) {
mbed_official 592:a274ee790e56 967 if (events->generate_event_on_periodic[i]) {
mbed_official 592:a274ee790e56 968 event_mask |= RTC_MODE0_EVCTRL_PEREO(1 << i);
mbed_official 592:a274ee790e56 969 }
mbed_official 592:a274ee790e56 970 }
mbed_official 592:a274ee790e56 971
mbed_official 592:a274ee790e56 972 /* Disable given event(s). */
mbed_official 592:a274ee790e56 973 rtc_module->MODE0.EVCTRL.reg &= ~event_mask;
mbed_official 592:a274ee790e56 974 }
mbed_official 592:a274ee790e56 975
mbed_official 592:a274ee790e56 976 /** @} */
mbed_official 592:a274ee790e56 977
mbed_official 592:a274ee790e56 978 #ifdef FEATURE_RTC_GENERAL_PURPOSE_REG
mbed_official 592:a274ee790e56 979 /**
mbed_official 592:a274ee790e56 980 * \name RTC General Purpose Registers
mbed_official 592:a274ee790e56 981 * @{
mbed_official 592:a274ee790e56 982 */
mbed_official 592:a274ee790e56 983
mbed_official 592:a274ee790e56 984 /**
mbed_official 592:a274ee790e56 985 * \brief Write a value into general purpose register.
mbed_official 592:a274ee790e56 986 *
mbed_official 592:a274ee790e56 987 * \param[in] module Pointer to the software instance struct
mbed_official 592:a274ee790e56 988 * \param[in] n General purpose type
mbed_official 592:a274ee790e56 989 * \param[in] index General purpose register index (0..3)
mbed_official 592:a274ee790e56 990 *
mbed_official 592:a274ee790e56 991 */
mbed_official 592:a274ee790e56 992 static inline void rtc_write_general_purpose_reg(
mbed_official 592:a274ee790e56 993 struct rtc_module *const module,
mbed_official 592:a274ee790e56 994 const uint8_t index,
mbed_official 592:a274ee790e56 995 uint32_t value)
mbed_official 592:a274ee790e56 996 {
mbed_official 592:a274ee790e56 997 /* Sanity check arguments */
mbed_official 592:a274ee790e56 998 Assert(module);
mbed_official 592:a274ee790e56 999 Assert(module->hw);
mbed_official 592:a274ee790e56 1000 Assert(index <= 3);
mbed_official 592:a274ee790e56 1001
mbed_official 592:a274ee790e56 1002 Rtc *const rtc_module = module->hw;
mbed_official 592:a274ee790e56 1003
mbed_official 592:a274ee790e56 1004 rtc_module->MODE0.GP[index].reg = value;
mbed_official 592:a274ee790e56 1005 }
mbed_official 592:a274ee790e56 1006
mbed_official 592:a274ee790e56 1007 /**
mbed_official 592:a274ee790e56 1008 * \brief Read the value from general purpose register.
mbed_official 592:a274ee790e56 1009 *
mbed_official 592:a274ee790e56 1010 * \param[in] module Pointer to the software instance struct
mbed_official 592:a274ee790e56 1011 * \param[in] index General purpose register index (0..3)
mbed_official 592:a274ee790e56 1012 *
mbed_official 592:a274ee790e56 1013 * \retval Value of general purpose register
mbed_official 592:a274ee790e56 1014 */
mbed_official 592:a274ee790e56 1015 static inline uint32_t rtc_read_general_purpose_reg(
mbed_official 592:a274ee790e56 1016 struct rtc_module *const module,
mbed_official 592:a274ee790e56 1017 const uint8_t index)
mbed_official 592:a274ee790e56 1018 {
mbed_official 592:a274ee790e56 1019 /* Sanity check arguments */
mbed_official 592:a274ee790e56 1020 Assert(module);
mbed_official 592:a274ee790e56 1021 Assert(module->hw);
mbed_official 592:a274ee790e56 1022 Assert(index <= 3);
mbed_official 592:a274ee790e56 1023
mbed_official 592:a274ee790e56 1024 Rtc *const rtc_module = module->hw;
mbed_official 592:a274ee790e56 1025
mbed_official 592:a274ee790e56 1026 return rtc_module->MODE0.GP[index].reg;
mbed_official 592:a274ee790e56 1027 }
mbed_official 592:a274ee790e56 1028
mbed_official 592:a274ee790e56 1029 /** @} */
mbed_official 592:a274ee790e56 1030 #endif
mbed_official 592:a274ee790e56 1031
mbed_official 592:a274ee790e56 1032 /** @} */
mbed_official 592:a274ee790e56 1033
mbed_official 592:a274ee790e56 1034 #ifdef __cplusplus
mbed_official 592:a274ee790e56 1035 }
mbed_official 592:a274ee790e56 1036 #endif
mbed_official 592:a274ee790e56 1037
mbed_official 592:a274ee790e56 1038 /**
mbed_official 592:a274ee790e56 1039 * \page asfdoc_sam0_rtc_count_extra Extra Information for RTC COUNT Driver
mbed_official 592:a274ee790e56 1040 *
mbed_official 592:a274ee790e56 1041 * \section asfdoc_sam0_rtc_count_extra_acronyms Acronyms
mbed_official 592:a274ee790e56 1042 * Below is a table listing the acronyms used in this module, along with their
mbed_official 592:a274ee790e56 1043 * intended meanings.
mbed_official 592:a274ee790e56 1044 *
mbed_official 592:a274ee790e56 1045 * <table>
mbed_official 592:a274ee790e56 1046 * <tr>
mbed_official 592:a274ee790e56 1047 * <th>Acronym</td>
mbed_official 592:a274ee790e56 1048 * <th>Description</td>
mbed_official 592:a274ee790e56 1049 * </tr>
mbed_official 592:a274ee790e56 1050 * <tr>
mbed_official 592:a274ee790e56 1051 * <td>RTC</td>
mbed_official 592:a274ee790e56 1052 * <td>Real Time Counter</td>
mbed_official 592:a274ee790e56 1053 * </tr>
mbed_official 592:a274ee790e56 1054 * <tr>
mbed_official 592:a274ee790e56 1055 * <td>PPM</td>
mbed_official 592:a274ee790e56 1056 * <td>Part Per Million</td>
mbed_official 592:a274ee790e56 1057 * </tr>
mbed_official 592:a274ee790e56 1058 * <tr>
mbed_official 592:a274ee790e56 1059 * <td>RC</td>
mbed_official 592:a274ee790e56 1060 * <td>Resistor/Capacitor</td>
mbed_official 592:a274ee790e56 1061 * </tr>
mbed_official 592:a274ee790e56 1062 * </table>
mbed_official 592:a274ee790e56 1063 *
mbed_official 592:a274ee790e56 1064 *
mbed_official 592:a274ee790e56 1065 * \section asfdoc_sam0_rtc_count_extra_dependencies Dependencies
mbed_official 592:a274ee790e56 1066 * This driver has the following dependencies:
mbed_official 592:a274ee790e56 1067 *
mbed_official 592:a274ee790e56 1068 * - None
mbed_official 592:a274ee790e56 1069 *
mbed_official 592:a274ee790e56 1070 *
mbed_official 592:a274ee790e56 1071 * \section asfdoc_sam0_rtc_count_extra_errata Errata
mbed_official 592:a274ee790e56 1072 * There are no errata related to this driver.
mbed_official 592:a274ee790e56 1073 *
mbed_official 592:a274ee790e56 1074 *
mbed_official 592:a274ee790e56 1075 * \section asfdoc_sam0_rtc_count_extra_history Module History
mbed_official 592:a274ee790e56 1076 * An overview of the module history is presented in the table below, with
mbed_official 592:a274ee790e56 1077 * details on the enhancements and fixes made to the module since its first
mbed_official 592:a274ee790e56 1078 * release. The current version of this corresponds to the newest version in
mbed_official 592:a274ee790e56 1079 * the table.
mbed_official 592:a274ee790e56 1080 *
mbed_official 592:a274ee790e56 1081 * <table>
mbed_official 592:a274ee790e56 1082 * <tr>
mbed_official 592:a274ee790e56 1083 * <th>Changelog</th>
mbed_official 592:a274ee790e56 1084 * </tr>
mbed_official 592:a274ee790e56 1085 * <tr>
mbed_official 592:a274ee790e56 1086 * <td>Added support for SAML21</td>
mbed_official 592:a274ee790e56 1087 * </tr>
mbed_official 592:a274ee790e56 1088 * <tr>
mbed_official 592:a274ee790e56 1089 * <td>
mbed_official 592:a274ee790e56 1090 * Added support for SAMD21 and added driver instance parameter to all
mbed_official 592:a274ee790e56 1091 * API function calls, except get_config_defaults
mbed_official 592:a274ee790e56 1092 * </td>
mbed_official 592:a274ee790e56 1093 * </tr>
mbed_official 592:a274ee790e56 1094 * <tr>
mbed_official 592:a274ee790e56 1095 * <td>Updated initialization function to also enable the digital interface
mbed_official 592:a274ee790e56 1096 * clock to the module if it is disabled</td>
mbed_official 592:a274ee790e56 1097 * </tr>
mbed_official 592:a274ee790e56 1098 * <tr>
mbed_official 592:a274ee790e56 1099 * <td>Initial Release</td>
mbed_official 592:a274ee790e56 1100 * </tr>
mbed_official 592:a274ee790e56 1101 * </table>
mbed_official 592:a274ee790e56 1102 */
mbed_official 592:a274ee790e56 1103
mbed_official 592:a274ee790e56 1104 /**
mbed_official 592:a274ee790e56 1105 * \page asfdoc_sam0_rtc_count_exqsg Examples for RTC (COUNT) Driver
mbed_official 592:a274ee790e56 1106 *
mbed_official 592:a274ee790e56 1107 * This is a list of the available Quick Start guides (QSGs) and example
mbed_official 592:a274ee790e56 1108 * applications for \ref asfdoc_sam0_rtc_count_group. QSGs are simple
mbed_official 592:a274ee790e56 1109 * examples with step-by-step instructions to configure and use this driver in a
mbed_official 592:a274ee790e56 1110 * selection of use cases. Note that QSGs can be compiled as a standalone
mbed_official 592:a274ee790e56 1111 * application or be added to the user application.
mbed_official 592:a274ee790e56 1112 *
mbed_official 592:a274ee790e56 1113 * - \subpage asfdoc_sam0_rtc_count_basic_use_case
mbed_official 592:a274ee790e56 1114 * \if RTC_COUNT_CALLBACK_MODE
mbed_official 592:a274ee790e56 1115 * - \subpage asfdoc_sam0_rtc_count_callback_use_case
mbed_official 592:a274ee790e56 1116 * \endif
mbed_official 592:a274ee790e56 1117 *
mbed_official 592:a274ee790e56 1118 * \page asfdoc_sam0_rtc_count_document_revision_history Document Revision History
mbed_official 592:a274ee790e56 1119 *
mbed_official 592:a274ee790e56 1120 * <table>
mbed_official 592:a274ee790e56 1121 * <tr>
mbed_official 592:a274ee790e56 1122 * <th>Doc. Rev.</td>
mbed_official 592:a274ee790e56 1123 * <th>Date</td>
mbed_official 592:a274ee790e56 1124 * <th>Comments</td>
mbed_official 592:a274ee790e56 1125 * </tr>
mbed_official 592:a274ee790e56 1126 * <tr>
mbed_official 592:a274ee790e56 1127 * <td>E</td>
mbed_official 592:a274ee790e56 1128 * <td>11/2014</td>
mbed_official 592:a274ee790e56 1129 * <td>Added support for SAML21.</td>
mbed_official 592:a274ee790e56 1130 * </tr>
mbed_official 592:a274ee790e56 1131 * <tr>
mbed_official 592:a274ee790e56 1132 * <td>D</td>
mbed_official 592:a274ee790e56 1133 * <td>12/2014</td>
mbed_official 592:a274ee790e56 1134 * <td>Added support for SAMR21 and SAMD10/D11.</td>
mbed_official 592:a274ee790e56 1135 * </tr>
mbed_official 592:a274ee790e56 1136 * <tr>
mbed_official 592:a274ee790e56 1137 * <td>C</td>
mbed_official 592:a274ee790e56 1138 * <td>01/2014</td>
mbed_official 592:a274ee790e56 1139 * <td>Added support for SAMD21.</td>
mbed_official 592:a274ee790e56 1140 * </tr>
mbed_official 592:a274ee790e56 1141 * <tr>
mbed_official 592:a274ee790e56 1142 * <td>B</td>
mbed_official 592:a274ee790e56 1143 * <td>06/2013</td>
mbed_official 592:a274ee790e56 1144 * <td>Added additional documentation on the event system. Corrected
mbed_official 592:a274ee790e56 1145 * documentation typos.</td>
mbed_official 592:a274ee790e56 1146 * </tr>
mbed_official 592:a274ee790e56 1147 * <tr>
mbed_official 592:a274ee790e56 1148 * <td>A</td>
mbed_official 592:a274ee790e56 1149 * <td>06/2013</td>
mbed_official 592:a274ee790e56 1150 * <td>Initial release</td>
mbed_official 592:a274ee790e56 1151 * </tr>
mbed_official 592:a274ee790e56 1152 * </table>
mbed_official 592:a274ee790e56 1153 */
mbed_official 592:a274ee790e56 1154
mbed_official 592:a274ee790e56 1155 #endif /* RTC_COUNT_H_INCLUDED */