mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Committer:
screamer
Date:
Tue Aug 02 14:07:36 2016 +0000
Revision:
144:423e1876dc07
Parent:
15:a81a8d6c1dfe
Added targets.json file for the supported targets in the release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 15:a81a8d6c1dfe 1 /**
mbed_official 15:a81a8d6c1dfe 2 * \file
mbed_official 15:a81a8d6c1dfe 3 *
mbed_official 15:a81a8d6c1dfe 4 * \brief SAM TC - Timer Counter Driver
mbed_official 15:a81a8d6c1dfe 5 *
mbed_official 15:a81a8d6c1dfe 6 * Copyright (C) 2013-2015 Atmel Corporation. All rights reserved.
mbed_official 15:a81a8d6c1dfe 7 *
mbed_official 15:a81a8d6c1dfe 8 * \asf_license_start
mbed_official 15:a81a8d6c1dfe 9 *
mbed_official 15:a81a8d6c1dfe 10 * \page License
mbed_official 15:a81a8d6c1dfe 11 *
mbed_official 15:a81a8d6c1dfe 12 * Redistribution and use in source and binary forms, with or without
mbed_official 15:a81a8d6c1dfe 13 * modification, are permitted provided that the following conditions are met:
mbed_official 15:a81a8d6c1dfe 14 *
mbed_official 15:a81a8d6c1dfe 15 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 15:a81a8d6c1dfe 16 * this list of conditions and the following disclaimer.
mbed_official 15:a81a8d6c1dfe 17 *
mbed_official 15:a81a8d6c1dfe 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 15:a81a8d6c1dfe 19 * this list of conditions and the following disclaimer in the documentation
mbed_official 15:a81a8d6c1dfe 20 * and/or other materials provided with the distribution.
mbed_official 15:a81a8d6c1dfe 21 *
mbed_official 15:a81a8d6c1dfe 22 * 3. The name of Atmel may not be used to endorse or promote products derived
mbed_official 15:a81a8d6c1dfe 23 * from this software without specific prior written permission.
mbed_official 15:a81a8d6c1dfe 24 *
mbed_official 15:a81a8d6c1dfe 25 * 4. This software may only be redistributed and used in connection with an
mbed_official 15:a81a8d6c1dfe 26 * Atmel microcontroller product.
mbed_official 15:a81a8d6c1dfe 27 *
mbed_official 15:a81a8d6c1dfe 28 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
mbed_official 15:a81a8d6c1dfe 29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mbed_official 15:a81a8d6c1dfe 30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
mbed_official 15:a81a8d6c1dfe 31 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
mbed_official 15:a81a8d6c1dfe 32 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 15:a81a8d6c1dfe 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
mbed_official 15:a81a8d6c1dfe 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
mbed_official 15:a81a8d6c1dfe 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
mbed_official 15:a81a8d6c1dfe 36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
mbed_official 15:a81a8d6c1dfe 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 15:a81a8d6c1dfe 38 * POSSIBILITY OF SUCH DAMAGE.
mbed_official 15:a81a8d6c1dfe 39 *
mbed_official 15:a81a8d6c1dfe 40 * \asf_license_stop
mbed_official 15:a81a8d6c1dfe 41 *
mbed_official 15:a81a8d6c1dfe 42 */
mbed_official 15:a81a8d6c1dfe 43 /*
mbed_official 15:a81a8d6c1dfe 44 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
mbed_official 15:a81a8d6c1dfe 45 */
mbed_official 15:a81a8d6c1dfe 46
mbed_official 15:a81a8d6c1dfe 47 #ifndef TC_H_INCLUDED
mbed_official 15:a81a8d6c1dfe 48 #define TC_H_INCLUDED
mbed_official 15:a81a8d6c1dfe 49
mbed_official 15:a81a8d6c1dfe 50 /**
mbed_official 15:a81a8d6c1dfe 51 * \defgroup asfdoc_sam0_tc_group SAM Timer/Counter Driver (TC)
mbed_official 15:a81a8d6c1dfe 52 *
mbed_official 15:a81a8d6c1dfe 53 * This driver for Atmel&reg; | SMART SAM devices provides an interface for the configuration
mbed_official 15:a81a8d6c1dfe 54 * and management of the timer modules within the device, for waveform
mbed_official 15:a81a8d6c1dfe 55 * generation and timing operations. The following driver API modes are covered
mbed_official 15:a81a8d6c1dfe 56 * by this manual:
mbed_official 15:a81a8d6c1dfe 57 *
mbed_official 15:a81a8d6c1dfe 58 * - Polled APIs
mbed_official 15:a81a8d6c1dfe 59 * \if TC_CALLBACK_MODE
mbed_official 15:a81a8d6c1dfe 60 * - Callback APIs
mbed_official 15:a81a8d6c1dfe 61 * \endif
mbed_official 15:a81a8d6c1dfe 62 *
mbed_official 15:a81a8d6c1dfe 63 *
mbed_official 15:a81a8d6c1dfe 64 * The following peripherals are used by this module:
mbed_official 15:a81a8d6c1dfe 65 * - TC (Timer/Counter)
mbed_official 15:a81a8d6c1dfe 66 *
mbed_official 15:a81a8d6c1dfe 67 * The following devices can use this module:
mbed_official 15:a81a8d6c1dfe 68 * - Atmel | SMART SAM D20/D21
mbed_official 15:a81a8d6c1dfe 69 * - Atmel | SMART SAM R21
mbed_official 15:a81a8d6c1dfe 70 * - Atmel | SMART SAM D10/D11
mbed_official 15:a81a8d6c1dfe 71 * - Atmel | SMART SAM L21
mbed_official 15:a81a8d6c1dfe 72 * - Atmel | SMART SAM DAx
mbed_official 15:a81a8d6c1dfe 73 * - Atmel | SMART SAM C20/C21
mbed_official 15:a81a8d6c1dfe 74 *
mbed_official 15:a81a8d6c1dfe 75 * The outline of this documentation is as follows:
mbed_official 15:a81a8d6c1dfe 76 * - \ref asfdoc_sam0_tc_prerequisites
mbed_official 15:a81a8d6c1dfe 77 * - \ref asfdoc_sam0_tc_module_overview
mbed_official 15:a81a8d6c1dfe 78 * - \ref asfdoc_sam0_tc_special_considerations
mbed_official 15:a81a8d6c1dfe 79 * - \ref asfdoc_sam0_tc_extra_info
mbed_official 15:a81a8d6c1dfe 80 * - \ref asfdoc_sam0_tc_examples
mbed_official 15:a81a8d6c1dfe 81 * - \ref asfdoc_sam0_tc_api_overview
mbed_official 15:a81a8d6c1dfe 82 *
mbed_official 15:a81a8d6c1dfe 83 *
mbed_official 15:a81a8d6c1dfe 84 * \section asfdoc_sam0_tc_prerequisites Prerequisites
mbed_official 15:a81a8d6c1dfe 85 *
mbed_official 15:a81a8d6c1dfe 86 * There are no prerequisites for this module.
mbed_official 15:a81a8d6c1dfe 87 *
mbed_official 15:a81a8d6c1dfe 88 *
mbed_official 15:a81a8d6c1dfe 89 * \section asfdoc_sam0_tc_module_overview Module Overview
mbed_official 15:a81a8d6c1dfe 90 *
mbed_official 15:a81a8d6c1dfe 91 * The Timer/Counter (TC) module provides a set of timing and counting related
mbed_official 15:a81a8d6c1dfe 92 * functionality, such as the generation of periodic waveforms, the capturing
mbed_official 15:a81a8d6c1dfe 93 * of a periodic waveform's frequency/duty cycle, and software timekeeping for
mbed_official 15:a81a8d6c1dfe 94 * periodic operations. TC modules can be configured to use an 8-, 16-, or
mbed_official 15:a81a8d6c1dfe 95 * 32-bit counter size.
mbed_official 15:a81a8d6c1dfe 96 *
mbed_official 15:a81a8d6c1dfe 97 * This TC module for the SAM is capable of the following functions:
mbed_official 15:a81a8d6c1dfe 98 *
mbed_official 15:a81a8d6c1dfe 99 * - Generation of PWM signals
mbed_official 15:a81a8d6c1dfe 100 * - Generation of timestamps for events
mbed_official 15:a81a8d6c1dfe 101 * - General time counting
mbed_official 15:a81a8d6c1dfe 102 * - Waveform period capture
mbed_official 15:a81a8d6c1dfe 103 * - Waveform frequency capture
mbed_official 15:a81a8d6c1dfe 104 *
mbed_official 15:a81a8d6c1dfe 105 * \ref asfdoc_sam0_tc_block_diagram "The diagram below" shows the overview
mbed_official 15:a81a8d6c1dfe 106 * of the TC module design.
mbed_official 15:a81a8d6c1dfe 107 *
mbed_official 15:a81a8d6c1dfe 108 * \anchor asfdoc_sam0_tc_block_diagram
mbed_official 15:a81a8d6c1dfe 109 * \image html overview.svg "Basic Overview of the TC Module"
mbed_official 15:a81a8d6c1dfe 110 *
mbed_official 15:a81a8d6c1dfe 111 *
mbed_official 15:a81a8d6c1dfe 112 * \subsection asfdoc_sam0_tc_features Driver Feature Macro Definition
mbed_official 15:a81a8d6c1dfe 113 * <table>
mbed_official 15:a81a8d6c1dfe 114 * <tr>
mbed_official 15:a81a8d6c1dfe 115 * <th>Driver Feature Macro</th>
mbed_official 15:a81a8d6c1dfe 116 * <th>Supported devices</th>
mbed_official 15:a81a8d6c1dfe 117 * </tr>
mbed_official 15:a81a8d6c1dfe 118 * <tr>
mbed_official 15:a81a8d6c1dfe 119 * <td>FEATURE_TC_DOUBLE_BUFFERED</td>
mbed_official 15:a81a8d6c1dfe 120 * <td>SAML21/C20/C21</td>
mbed_official 15:a81a8d6c1dfe 121 * </tr>
mbed_official 15:a81a8d6c1dfe 122 * <tr>
mbed_official 15:a81a8d6c1dfe 123 * <td>FEATURE_TC_SYNCBUSY_SCHEME_VERSION_2</td>
mbed_official 15:a81a8d6c1dfe 124 * <td>SAML21/C20/C21</td>
mbed_official 15:a81a8d6c1dfe 125 * </tr>
mbed_official 15:a81a8d6c1dfe 126 * <tr>
mbed_official 15:a81a8d6c1dfe 127 * <td>FEATURE_TC_STAMP_PW_CAPTURE</td>
mbed_official 15:a81a8d6c1dfe 128 * <td>SAML21/C20/C21</td>
mbed_official 15:a81a8d6c1dfe 129 * </tr>
mbed_official 15:a81a8d6c1dfe 130 * <tr>
mbed_official 15:a81a8d6c1dfe 131 * <td>FEATURE_TC_READ_SYNC</td>
mbed_official 15:a81a8d6c1dfe 132 * <td>SAML21/C20/C21</td>
mbed_official 15:a81a8d6c1dfe 133 * </tr>
mbed_official 15:a81a8d6c1dfe 134 * <tr>
mbed_official 15:a81a8d6c1dfe 135 * <td>FEATURE_TC_IO_CAPTURE</td>
mbed_official 15:a81a8d6c1dfe 136 * <td>SAML21/C20/C21</td>
mbed_official 15:a81a8d6c1dfe 137 * </tr>
mbed_official 15:a81a8d6c1dfe 138 * <tr>
mbed_official 15:a81a8d6c1dfe 139 * <td>FEATURE_TC_GENERATE_DMA_TRIGGER</td>
mbed_official 15:a81a8d6c1dfe 140 * <td>SAML21</td>
mbed_official 15:a81a8d6c1dfe 141 * </tr>
mbed_official 15:a81a8d6c1dfe 142 * </table>
mbed_official 15:a81a8d6c1dfe 143 * \note The specific features are only available in the driver when the
mbed_official 15:a81a8d6c1dfe 144 * selected device supports those features.
mbed_official 15:a81a8d6c1dfe 145 *
mbed_official 15:a81a8d6c1dfe 146 * \subsection asfdoc_sam0_tc_module_overview_func_desc Functional Description
mbed_official 15:a81a8d6c1dfe 147 * Independent of the configured counter size, each TC module can be set up
mbed_official 15:a81a8d6c1dfe 148 * in one of two different modes; capture and compare.
mbed_official 15:a81a8d6c1dfe 149 *
mbed_official 15:a81a8d6c1dfe 150 * In capture mode, the counter value is stored when a configurable event
mbed_official 15:a81a8d6c1dfe 151 * occurs. This mode can be used to generate timestamps used in event capture,
mbed_official 15:a81a8d6c1dfe 152 * or it can be used for the measurement of a periodic input signal's
mbed_official 15:a81a8d6c1dfe 153 * frequency/duty cycle.
mbed_official 15:a81a8d6c1dfe 154 *
mbed_official 15:a81a8d6c1dfe 155 * In compare mode, the counter value is compared against one or more of the
mbed_official 15:a81a8d6c1dfe 156 * configured channel compare values. When the counter value coincides with a
mbed_official 15:a81a8d6c1dfe 157 * compare value an action can be taken automatically by the module, such as
mbed_official 15:a81a8d6c1dfe 158 * generating an output event or toggling a pin when used for frequency or PWM
mbed_official 15:a81a8d6c1dfe 159 * signal generation.
mbed_official 15:a81a8d6c1dfe 160 *
mbed_official 15:a81a8d6c1dfe 161 * \note The connection of events between modules requires the use of the
mbed_official 15:a81a8d6c1dfe 162 * \ref asfdoc_sam0_events_group "SAM Event System Driver (EVENTS)"
mbed_official 15:a81a8d6c1dfe 163 * to route output event of one module to the input event of another.
mbed_official 15:a81a8d6c1dfe 164 * For more information on event routing, refer to the event driver
mbed_official 15:a81a8d6c1dfe 165 * documentation.
mbed_official 15:a81a8d6c1dfe 166 *
mbed_official 15:a81a8d6c1dfe 167 * \subsection asfdoc_sam0_tc_module_overview_tc_size Timer/Counter Size
mbed_official 15:a81a8d6c1dfe 168 * Each timer module can be configured in one of three different counter
mbed_official 15:a81a8d6c1dfe 169 * sizes; 8-, 16-, and 32-bit. The size of the counter determines the maximum
mbed_official 15:a81a8d6c1dfe 170 * value it can count to before an overflow occurs and the count is reset back
mbed_official 15:a81a8d6c1dfe 171 * to zero. \ref asfdoc_sam0_tc_count_size_vs_top "The table below" shows the
mbed_official 15:a81a8d6c1dfe 172 * maximum values for each of the possible counter sizes.
mbed_official 15:a81a8d6c1dfe 173 *
mbed_official 15:a81a8d6c1dfe 174 * \anchor asfdoc_sam0_tc_count_size_vs_top
mbed_official 15:a81a8d6c1dfe 175 * <table>
mbed_official 15:a81a8d6c1dfe 176 * <caption>Timer Counter Sizes and Their Maximum Count Values</caption>
mbed_official 15:a81a8d6c1dfe 177 * <tr>
mbed_official 15:a81a8d6c1dfe 178 * <th>Counter size</th>
mbed_official 15:a81a8d6c1dfe 179 * <th>Max. (hexadecimal)</th>
mbed_official 15:a81a8d6c1dfe 180 * <th>Max. (decimal)</th>
mbed_official 15:a81a8d6c1dfe 181 * </tr>
mbed_official 15:a81a8d6c1dfe 182 * <tr>
mbed_official 15:a81a8d6c1dfe 183 * <td>8-bit</td>
mbed_official 15:a81a8d6c1dfe 184 * <td>0xFF</td>
mbed_official 15:a81a8d6c1dfe 185 * <td>255</td>
mbed_official 15:a81a8d6c1dfe 186 * </tr>
mbed_official 15:a81a8d6c1dfe 187 * <tr>
mbed_official 15:a81a8d6c1dfe 188 * <td>16-bit</td>
mbed_official 15:a81a8d6c1dfe 189 * <td>0xFFFF</td>
mbed_official 15:a81a8d6c1dfe 190 * <td>65,535</td>
mbed_official 15:a81a8d6c1dfe 191 * </tr>
mbed_official 15:a81a8d6c1dfe 192 * <tr>
mbed_official 15:a81a8d6c1dfe 193 * <td>32-bit</td>
mbed_official 15:a81a8d6c1dfe 194 * <td>0xFFFFFFFF</td>
mbed_official 15:a81a8d6c1dfe 195 * <td>4,294,967,295</td>
mbed_official 15:a81a8d6c1dfe 196 * </tr>
mbed_official 15:a81a8d6c1dfe 197 * </table>
mbed_official 15:a81a8d6c1dfe 198 *
mbed_official 15:a81a8d6c1dfe 199 * When using the counter in 16- or 32-bit count mode, Compare Capture
mbed_official 15:a81a8d6c1dfe 200 * register 0 (CC0) is used to store the period value when running in PWM
mbed_official 15:a81a8d6c1dfe 201 * generation match mode.
mbed_official 15:a81a8d6c1dfe 202 *
mbed_official 15:a81a8d6c1dfe 203 * When using 32-bit counter size, two 16-bit counters are chained together
mbed_official 15:a81a8d6c1dfe 204 * in a cascade formation. Except in SAM D10/D11, Even numbered TC modules
mbed_official 15:a81a8d6c1dfe 205 * (e.g. TC0, TC2) can be configured as 32-bit counters. The odd numbered
mbed_official 15:a81a8d6c1dfe 206 * counters will act as slaves to the even numbered masters, and will not
mbed_official 15:a81a8d6c1dfe 207 * be reconfigurable until the master timer is disabled. The pairing of timer
mbed_official 15:a81a8d6c1dfe 208 * modules for 32-bit mode is shown in \ref asfdoc_sam0_tc_module_ms_pairs
mbed_official 15:a81a8d6c1dfe 209 * "the table below".
mbed_official 15:a81a8d6c1dfe 210 *
mbed_official 15:a81a8d6c1dfe 211 * \anchor asfdoc_sam0_tc_module_ms_pairs
mbed_official 15:a81a8d6c1dfe 212 * <table>
mbed_official 15:a81a8d6c1dfe 213 * <caption>TC Master and Slave Module Pairings</caption>
mbed_official 15:a81a8d6c1dfe 214 * <tr>
mbed_official 15:a81a8d6c1dfe 215 * <th>Master TC Module</th>
mbed_official 15:a81a8d6c1dfe 216 * <th>Slave TC Module</th>
mbed_official 15:a81a8d6c1dfe 217 * </tr>
mbed_official 15:a81a8d6c1dfe 218 * <tr>
mbed_official 15:a81a8d6c1dfe 219 * <td>TC0</td>
mbed_official 15:a81a8d6c1dfe 220 * <td>TC1</td>
mbed_official 15:a81a8d6c1dfe 221 * </tr>
mbed_official 15:a81a8d6c1dfe 222 * <tr>
mbed_official 15:a81a8d6c1dfe 223 * <td>TC2</td>
mbed_official 15:a81a8d6c1dfe 224 * <td>TC3</td>
mbed_official 15:a81a8d6c1dfe 225 * </tr>
mbed_official 15:a81a8d6c1dfe 226 * <tr>
mbed_official 15:a81a8d6c1dfe 227 * <td>...</td>
mbed_official 15:a81a8d6c1dfe 228 * <td>...</td>
mbed_official 15:a81a8d6c1dfe 229 * </tr>
mbed_official 15:a81a8d6c1dfe 230 * <tr>
mbed_official 15:a81a8d6c1dfe 231 * <td>TCn-1</td>
mbed_official 15:a81a8d6c1dfe 232 * <td>TCn</td>
mbed_official 15:a81a8d6c1dfe 233 * </tr>
mbed_official 15:a81a8d6c1dfe 234 * </table>
mbed_official 15:a81a8d6c1dfe 235 *
mbed_official 15:a81a8d6c1dfe 236 * In SAMD10/D11, odd numbered TC modules (e.g. TC1) can be configured as 32-bit
mbed_official 15:a81a8d6c1dfe 237 * counters. The even numbered(e.g. TC2) counters will act as slaves to the odd
mbed_official 15:a81a8d6c1dfe 238 * numbered masters.
mbed_official 15:a81a8d6c1dfe 239 *
mbed_official 15:a81a8d6c1dfe 240 * \subsection asfdoc_sam0_tc_module_overview_clock Clock Settings
mbed_official 15:a81a8d6c1dfe 241 *
mbed_official 15:a81a8d6c1dfe 242 * \subsubsection asfdoc_sam0_tc_module_overview_clock_selection Clock Selection
mbed_official 15:a81a8d6c1dfe 243 * Each TC peripheral is clocked asynchronously to the system clock by a GCLK
mbed_official 15:a81a8d6c1dfe 244 * (Generic Clock) channel. The GCLK channel connects to any of the GCLK
mbed_official 15:a81a8d6c1dfe 245 * generators. The GCLK generators are configured to use one of the available
mbed_official 15:a81a8d6c1dfe 246 * clock sources on the system such as internal oscillator, external crystals,
mbed_official 15:a81a8d6c1dfe 247 * etc. see the \ref asfdoc_sam0_system_clock_group "Generic Clock driver"
mbed_official 15:a81a8d6c1dfe 248 *for
mbed_official 15:a81a8d6c1dfe 249 * more information.
mbed_official 15:a81a8d6c1dfe 250 *
mbed_official 15:a81a8d6c1dfe 251 * \subsubsection asfdoc_sam0_tc_module_overview_clock_prescaler Prescaler
mbed_official 15:a81a8d6c1dfe 252 * Each TC module in the SAM has its own individual clock prescaler, which
mbed_official 15:a81a8d6c1dfe 253 * can be used to divide the input clock frequency used in the counter. This
mbed_official 15:a81a8d6c1dfe 254 * prescaler only scales the clock used to provide clock pulses for the counter
mbed_official 15:a81a8d6c1dfe 255 * to count, and does not affect the digital register interface portion of
mbed_official 15:a81a8d6c1dfe 256 * the module, thus the timer registers will synchronize to the raw GCLK
mbed_official 15:a81a8d6c1dfe 257 * frequency input to the module.
mbed_official 15:a81a8d6c1dfe 258 *
mbed_official 15:a81a8d6c1dfe 259 * As a result of this, when selecting a GCLK frequency and timer prescaler
mbed_official 15:a81a8d6c1dfe 260 * value the user application should consider both the timer resolution
mbed_official 15:a81a8d6c1dfe 261 * required and the synchronization frequency, to avoid lengthy
mbed_official 15:a81a8d6c1dfe 262 * synchronization times of the module if a very slow GCLK frequency is fed
mbed_official 15:a81a8d6c1dfe 263 * into the TC module. It is preferable to use a higher module GCLK frequency
mbed_official 15:a81a8d6c1dfe 264 * as the input to the timer, and prescale this down as much as possible to
mbed_official 15:a81a8d6c1dfe 265 * obtain a suitable counter frequency in latency-sensitive applications.
mbed_official 15:a81a8d6c1dfe 266 *
mbed_official 15:a81a8d6c1dfe 267 * \subsubsection asfdoc_sam0_tc_module_overview_clock_reloading Reloading
mbed_official 15:a81a8d6c1dfe 268 * Timer modules also contain a configurable reload action, used when a
mbed_official 15:a81a8d6c1dfe 269 * re-trigger event occurs. Examples of a re-trigger event are the counter
mbed_official 15:a81a8d6c1dfe 270 * reaching the maximum value when counting up, or when an event from the event
mbed_official 15:a81a8d6c1dfe 271 * system tells the counter to re-trigger. The reload action determines if the
mbed_official 15:a81a8d6c1dfe 272 * prescaler should be reset, and when this should happen. The counter will
mbed_official 15:a81a8d6c1dfe 273 * always be reloaded with the value it is set to start counting from. The user
mbed_official 15:a81a8d6c1dfe 274 * can choose between three different reload actions, described in
mbed_official 15:a81a8d6c1dfe 275 * \ref asfdoc_sam0_tc_module_reload_act "the table below".
mbed_official 15:a81a8d6c1dfe 276 *
mbed_official 15:a81a8d6c1dfe 277 * \anchor asfdoc_sam0_tc_module_reload_act
mbed_official 15:a81a8d6c1dfe 278 * <table>
mbed_official 15:a81a8d6c1dfe 279 * <caption>TC Module Reload Actions</caption>
mbed_official 15:a81a8d6c1dfe 280 * <tr>
mbed_official 15:a81a8d6c1dfe 281 * <th>Reload action</th>
mbed_official 15:a81a8d6c1dfe 282 * <th>Description</th>
mbed_official 15:a81a8d6c1dfe 283 * </tr>
mbed_official 15:a81a8d6c1dfe 284 * <tr>
mbed_official 15:a81a8d6c1dfe 285 * <td>\ref TC_RELOAD_ACTION_GCLK </td>
mbed_official 15:a81a8d6c1dfe 286 * <td>Reload TC counter value on next GCLK cycle. Leave prescaler
mbed_official 15:a81a8d6c1dfe 287 * as-is.</td>
mbed_official 15:a81a8d6c1dfe 288 * </tr>
mbed_official 15:a81a8d6c1dfe 289 * <tr>
mbed_official 15:a81a8d6c1dfe 290 * <td>\ref TC_RELOAD_ACTION_PRESC </td>
mbed_official 15:a81a8d6c1dfe 291 * <td>Reloads TC counter value on next prescaler clock. Leave prescaler
mbed_official 15:a81a8d6c1dfe 292 * as-is.</td>
mbed_official 15:a81a8d6c1dfe 293 * </tr>
mbed_official 15:a81a8d6c1dfe 294 * <tr>
mbed_official 15:a81a8d6c1dfe 295 * <td> \ref TC_RELOAD_ACTION_RESYNC </td>
mbed_official 15:a81a8d6c1dfe 296 * <td>Reload TC counter value on next GCLK cycle. Clear prescaler to
mbed_official 15:a81a8d6c1dfe 297 * zero.</td>
mbed_official 15:a81a8d6c1dfe 298 * </tr>
mbed_official 15:a81a8d6c1dfe 299 * </table>
mbed_official 15:a81a8d6c1dfe 300 *
mbed_official 15:a81a8d6c1dfe 301 * The reload action to use will depend on the specific application being
mbed_official 15:a81a8d6c1dfe 302 * implemented. One example is when an external trigger for a reload occurs; if
mbed_official 15:a81a8d6c1dfe 303 * the TC uses the prescaler, the counter in the prescaler should not have a
mbed_official 15:a81a8d6c1dfe 304 * value between zero and the division factor. The TC counter and the counter
mbed_official 15:a81a8d6c1dfe 305 * in the prescaler should both start at zero. When the counter is set to
mbed_official 15:a81a8d6c1dfe 306 * re-trigger when it reaches the maximum value on the other hand, this is not the
mbed_official 15:a81a8d6c1dfe 307 * right option to use. In such a case it would be better if the prescaler is
mbed_official 15:a81a8d6c1dfe 308 * left unaltered when the re-trigger happens, letting the counter reset on the
mbed_official 15:a81a8d6c1dfe 309 * next GCLK cycle.
mbed_official 15:a81a8d6c1dfe 310 *
mbed_official 15:a81a8d6c1dfe 311 * \subsection asfdoc_sam0_tc_module_overview_compare_match Compare Match Operations
mbed_official 15:a81a8d6c1dfe 312 * In compare match operation, Compare/Capture registers are used in comparison
mbed_official 15:a81a8d6c1dfe 313 * with the counter value. When the timer's count value matches the value of a
mbed_official 15:a81a8d6c1dfe 314 * compare channel, a user defined action can be taken.
mbed_official 15:a81a8d6c1dfe 315 *
mbed_official 15:a81a8d6c1dfe 316 * \subsubsection asfdoc_sam0_tc_module_overview_compare_match_timer Basic Timer
mbed_official 15:a81a8d6c1dfe 317 *
mbed_official 15:a81a8d6c1dfe 318 * A Basic Timer is a simple application where compare match operations is used
mbed_official 15:a81a8d6c1dfe 319 * to determine when a specific period has elapsed. In Basic Timer operations,
mbed_official 15:a81a8d6c1dfe 320 * one or more values in the module's Compare/Capture registers are used to
mbed_official 15:a81a8d6c1dfe 321 * specify the time (as a number of prescaled GCLK cycles) when an action should
mbed_official 15:a81a8d6c1dfe 322 * be taken by the microcontroller. This can be an Interrupt Service Routine
mbed_official 15:a81a8d6c1dfe 323 * (ISR), event generator via the event system, or a software flag that is
mbed_official 15:a81a8d6c1dfe 324 * polled via the user application.
mbed_official 15:a81a8d6c1dfe 325 *
mbed_official 15:a81a8d6c1dfe 326 * \subsubsection asfdoc_sam0_tc_module_overview_compare_match_wg Waveform Generation
mbed_official 15:a81a8d6c1dfe 327 *
mbed_official 15:a81a8d6c1dfe 328 * Waveform generation enables the TC module to generate square waves, or if
mbed_official 15:a81a8d6c1dfe 329 * combined with an external passive low-pass filter; analog waveforms.
mbed_official 15:a81a8d6c1dfe 330 *
mbed_official 15:a81a8d6c1dfe 331 * \subsubsection asfdoc_sam0_tc_module_overview_compare_match_wg_pwm Waveform Generation - PWM
mbed_official 15:a81a8d6c1dfe 332 *
mbed_official 15:a81a8d6c1dfe 333 * Pulse width modulation is a form of waveform generation and a signalling
mbed_official 15:a81a8d6c1dfe 334 * technique that can be useful in many situations. When PWM mode is used,
mbed_official 15:a81a8d6c1dfe 335 * a digital pulse train with a configurable frequency and duty cycle can be
mbed_official 15:a81a8d6c1dfe 336 * generated by the TC module and output to a GPIO pin of the device.
mbed_official 15:a81a8d6c1dfe 337 *
mbed_official 15:a81a8d6c1dfe 338 * Often PWM is used to communicate a control or information parameter to an
mbed_official 15:a81a8d6c1dfe 339 * external circuit or component. Differing impedances of the source generator
mbed_official 15:a81a8d6c1dfe 340 * and sink receiver circuits is less of an issue when using PWM compared to
mbed_official 15:a81a8d6c1dfe 341 * using an analog voltage value, as noise will not generally affect the
mbed_official 15:a81a8d6c1dfe 342 * signal's integrity to a meaningful extent.
mbed_official 15:a81a8d6c1dfe 343 *
mbed_official 15:a81a8d6c1dfe 344 * \ref asfdoc_sam0_tc_module_pwm_normal_diag "The figure below" illustrates
mbed_official 15:a81a8d6c1dfe 345 * operations and different states of the counter and its output when running
mbed_official 15:a81a8d6c1dfe 346 * the counter in PWM normal mode. As can be seen, the TOP value is unchanged
mbed_official 15:a81a8d6c1dfe 347 * and is set to MAX. The compare match value is changed at several points to
mbed_official 15:a81a8d6c1dfe 348 * illustrate the resulting waveform output changes. The PWM output is set to
mbed_official 15:a81a8d6c1dfe 349 * normal (i.e. non-inverted) output mode.
mbed_official 15:a81a8d6c1dfe 350 *
mbed_official 15:a81a8d6c1dfe 351 * \anchor asfdoc_sam0_tc_module_pwm_normal_diag
mbed_official 15:a81a8d6c1dfe 352 * \image html pwm_normal_ex.svg "Example of PWM in Normal Mode, and Different Counter Operations"
mbed_official 15:a81a8d6c1dfe 353 *
mbed_official 15:a81a8d6c1dfe 354 *
mbed_official 15:a81a8d6c1dfe 355 * In \ref asfdoc_sam0_tc_module_pwm_match_diag "the figure below", the
mbed_official 15:a81a8d6c1dfe 356 * counter is set to generate PWM in Match mode. The PWM output is inverted via
mbed_official 15:a81a8d6c1dfe 357 * the appropriate configuration option in the TC driver configuration
mbed_official 15:a81a8d6c1dfe 358 * structure. In this example, the counter value is changed once, but the
mbed_official 15:a81a8d6c1dfe 359 * compare match value is kept unchanged. As can be seen, it is possible to
mbed_official 15:a81a8d6c1dfe 360 * change the TOP value when running in PWM match mode.
mbed_official 15:a81a8d6c1dfe 361 *
mbed_official 15:a81a8d6c1dfe 362 * \anchor asfdoc_sam0_tc_module_pwm_match_diag
mbed_official 15:a81a8d6c1dfe 363 * \image html pwm_match_ex.svg "Example of PWM in Match Mode, and Different Counter Operations"
mbed_official 15:a81a8d6c1dfe 364 *
mbed_official 15:a81a8d6c1dfe 365 * \subsubsection asfdoc_sam0_tc_module_overview_compare_match_wg_freq Waveform Generation - Frequency
mbed_official 15:a81a8d6c1dfe 366 *
mbed_official 15:a81a8d6c1dfe 367 * Frequency Generation mode is in many ways identical to PWM
mbed_official 15:a81a8d6c1dfe 368 * generation. However, in Frequency Generation a toggle only occurs
mbed_official 15:a81a8d6c1dfe 369 * on the output when a match on a capture channels occurs. When the
mbed_official 15:a81a8d6c1dfe 370 * match is made, the timer value is reset, resulting in a variable
mbed_official 15:a81a8d6c1dfe 371 * frequency square wave with a fixed 50% duty cycle.
mbed_official 15:a81a8d6c1dfe 372 *
mbed_official 15:a81a8d6c1dfe 373 * \subsubsection asfdoc_sam0_tc_module_overview_compare_match_capt Capture Operations
mbed_official 15:a81a8d6c1dfe 374 *
mbed_official 15:a81a8d6c1dfe 375 * In capture operations, any event from the event system or a pin change can
mbed_official 15:a81a8d6c1dfe 376 * trigger a capture of the counter value. This captured counter value can be
mbed_official 15:a81a8d6c1dfe 377 * used as a timestamp for the event, or it can be used in frequency and pulse
mbed_official 15:a81a8d6c1dfe 378 * width capture.
mbed_official 15:a81a8d6c1dfe 379 *
mbed_official 15:a81a8d6c1dfe 380 * \subsubsection asfdoc_sam0_tc_module_overview_compare_match_capt_event_capture Capture Operations - Event
mbed_official 15:a81a8d6c1dfe 381 *
mbed_official 15:a81a8d6c1dfe 382 * Event capture is a simple use of the capture functionality,
mbed_official 15:a81a8d6c1dfe 383 * designed to create timestamps for specific events. When the TC
mbed_official 15:a81a8d6c1dfe 384 * module's input capture pin is externally toggled, the current timer
mbed_official 15:a81a8d6c1dfe 385 * count value is copied into a buffered register which can then be
mbed_official 15:a81a8d6c1dfe 386 * read out by the user application.
mbed_official 15:a81a8d6c1dfe 387 *
mbed_official 15:a81a8d6c1dfe 388 * Note that when performing any capture operation, there is a risk that the
mbed_official 15:a81a8d6c1dfe 389 * counter reaches its top value (MAX) when counting up, or the bottom value
mbed_official 15:a81a8d6c1dfe 390 * (zero) when counting down, before the capture event occurs. This can distort
mbed_official 15:a81a8d6c1dfe 391 * the result, making event timestamps to appear shorter than reality; the
mbed_official 15:a81a8d6c1dfe 392 * user application should check for timer overflow when reading a capture
mbed_official 15:a81a8d6c1dfe 393 * result in order to detect this situation and perform an appropriate
mbed_official 15:a81a8d6c1dfe 394 * adjustment.
mbed_official 15:a81a8d6c1dfe 395 *
mbed_official 15:a81a8d6c1dfe 396 * Before checking for a new capture, \ref TC_STATUS_COUNT_OVERFLOW
mbed_official 15:a81a8d6c1dfe 397 * should be checked. The response to an overflow error is left to the user
mbed_official 15:a81a8d6c1dfe 398 * application, however it may be necessary to clear both the capture overflow
mbed_official 15:a81a8d6c1dfe 399 * flag and the capture flag upon each capture reading.
mbed_official 15:a81a8d6c1dfe 400 *
mbed_official 15:a81a8d6c1dfe 401 * \subsubsection asfdoc_sam0_tc_module_overview_compare_match_capt_pwc Capture Operations - Pulse Width
mbed_official 15:a81a8d6c1dfe 402 *
mbed_official 15:a81a8d6c1dfe 403 * Pulse Width Capture mode makes it possible to measure the pulse width and
mbed_official 15:a81a8d6c1dfe 404 * period of PWM signals. This mode uses two capture channels of the counter.
mbed_official 15:a81a8d6c1dfe 405 * This means that the counter module used for Pulse Width Capture can not be
mbed_official 15:a81a8d6c1dfe 406 * used for any other purpose. There are two modes for pulse width capture;
mbed_official 15:a81a8d6c1dfe 407 * Pulse Width Period (PWP) and Period Pulse Width (PPW). In PWP mode, capture
mbed_official 15:a81a8d6c1dfe 408 * channel 0 is used for storing the pulse width and capture channel 1 stores
mbed_official 15:a81a8d6c1dfe 409 * the observed period. While in PPW mode, the roles of the two capture channels
mbed_official 15:a81a8d6c1dfe 410 * is reversed.
mbed_official 15:a81a8d6c1dfe 411 *
mbed_official 15:a81a8d6c1dfe 412 * As in the above example it is necessary to poll on interrupt flags to see
mbed_official 15:a81a8d6c1dfe 413 * if a new capture has happened and check that a capture overflow error has
mbed_official 15:a81a8d6c1dfe 414 * not occurred.
mbed_official 15:a81a8d6c1dfe 415 *
mbed_official 15:a81a8d6c1dfe 416 * \subsection asfdoc_sam0_tc_module_overview_oneshot One-shot Mode
mbed_official 15:a81a8d6c1dfe 417 *
mbed_official 15:a81a8d6c1dfe 418 * TC modules can be configured into a one-shot mode. When configured in this
mbed_official 15:a81a8d6c1dfe 419 * manner, starting the timer will cause it to count until the next overflow
mbed_official 15:a81a8d6c1dfe 420 * or underflow condition before automatically halting, waiting to be manually
mbed_official 15:a81a8d6c1dfe 421 * triggered by the user application software or an event signal from the event
mbed_official 15:a81a8d6c1dfe 422 * system.
mbed_official 15:a81a8d6c1dfe 423 *
mbed_official 15:a81a8d6c1dfe 424 * \subsubsection asfdoc_sam0_tc_module_overview_inversion Wave Generation Output Inversion
mbed_official 15:a81a8d6c1dfe 425 *
mbed_official 15:a81a8d6c1dfe 426 * The output of the wave generation can be inverted by hardware if desired,
mbed_official 15:a81a8d6c1dfe 427 * resulting in the logically inverted value being output to the configured
mbed_official 15:a81a8d6c1dfe 428 * device GPIO pin.
mbed_official 15:a81a8d6c1dfe 429 *
mbed_official 15:a81a8d6c1dfe 430 *
mbed_official 15:a81a8d6c1dfe 431 * \section asfdoc_sam0_tc_special_considerations Special Considerations
mbed_official 15:a81a8d6c1dfe 432 *
mbed_official 15:a81a8d6c1dfe 433 * The number of capture compare registers in each TC module is dependent on
mbed_official 15:a81a8d6c1dfe 434 * the specific SAM device being used, and in some cases the counter size.
mbed_official 15:a81a8d6c1dfe 435 *
mbed_official 15:a81a8d6c1dfe 436 * The maximum amount of capture compare registers available in any SAM
mbed_official 15:a81a8d6c1dfe 437 * device is two when running in 32-bit mode and four in 8- and 16-bit modes.
mbed_official 15:a81a8d6c1dfe 438 *
mbed_official 15:a81a8d6c1dfe 439 *
mbed_official 15:a81a8d6c1dfe 440 * \section asfdoc_sam0_tc_extra_info Extra Information
mbed_official 15:a81a8d6c1dfe 441 *
mbed_official 15:a81a8d6c1dfe 442 * For extra information, see \ref asfdoc_sam0_tc_extra. This includes:
mbed_official 15:a81a8d6c1dfe 443 * - \ref asfdoc_sam0_tc_extra_acronyms
mbed_official 15:a81a8d6c1dfe 444 * - \ref asfdoc_sam0_tc_extra_dependencies
mbed_official 15:a81a8d6c1dfe 445 * - \ref asfdoc_sam0_tc_extra_errata
mbed_official 15:a81a8d6c1dfe 446 * - \ref asfdoc_sam0_tc_extra_history
mbed_official 15:a81a8d6c1dfe 447 *
mbed_official 15:a81a8d6c1dfe 448 *
mbed_official 15:a81a8d6c1dfe 449 * \section asfdoc_sam0_tc_examples Examples
mbed_official 15:a81a8d6c1dfe 450 *
mbed_official 15:a81a8d6c1dfe 451 * For a list of examples related to this driver, see
mbed_official 15:a81a8d6c1dfe 452 * \ref asfdoc_sam0_tc_exqsg.
mbed_official 15:a81a8d6c1dfe 453 *
mbed_official 15:a81a8d6c1dfe 454 * \section asfdoc_sam0_tc_api_overview API Overview
mbed_official 15:a81a8d6c1dfe 455 * @{
mbed_official 15:a81a8d6c1dfe 456 */
mbed_official 15:a81a8d6c1dfe 457
mbed_official 15:a81a8d6c1dfe 458 #include <compiler.h>
mbed_official 15:a81a8d6c1dfe 459 #include <clock.h>
mbed_official 15:a81a8d6c1dfe 460 #include <gclk.h>
mbed_official 15:a81a8d6c1dfe 461 #include <pinmux.h>
mbed_official 15:a81a8d6c1dfe 462
mbed_official 15:a81a8d6c1dfe 463 /**
mbed_official 15:a81a8d6c1dfe 464 * Define port features set according to different device family
mbed_official 15:a81a8d6c1dfe 465 * @{
mbed_official 15:a81a8d6c1dfe 466 */
mbed_official 15:a81a8d6c1dfe 467 #if (SAML21) || (SAMC20) || (SAMC21) || defined(__DOXYGEN__)
mbed_official 15:a81a8d6c1dfe 468 /** TC double buffered. */
mbed_official 15:a81a8d6c1dfe 469 # define FEATURE_TC_DOUBLE_BUFFERED
mbed_official 15:a81a8d6c1dfe 470 /** SYNCBUSY scheme version 2. */
mbed_official 15:a81a8d6c1dfe 471 # define FEATURE_TC_SYNCBUSY_SCHEME_VERSION_2
mbed_official 15:a81a8d6c1dfe 472 /** TC time stamp capture and pulse width capture. */
mbed_official 15:a81a8d6c1dfe 473 # define FEATURE_TC_STAMP_PW_CAPTURE
mbed_official 15:a81a8d6c1dfe 474 /** Read synchronization of COUNT. */
mbed_official 15:a81a8d6c1dfe 475 # define FEATURE_TC_READ_SYNC
mbed_official 15:a81a8d6c1dfe 476 /** IO pin edge capture. */
mbed_official 15:a81a8d6c1dfe 477 # define FEATURE_TC_IO_CAPTURE
mbed_official 15:a81a8d6c1dfe 478 /** Generate DMA triggers. */
mbed_official 15:a81a8d6c1dfe 479 # define FEATURE_TC_GENERATE_DMA_TRIGGER
mbed_official 15:a81a8d6c1dfe 480 #endif
mbed_official 15:a81a8d6c1dfe 481 /*@}*/
mbed_official 15:a81a8d6c1dfe 482
mbed_official 15:a81a8d6c1dfe 483 #if !defined(__DOXYGEN__)
mbed_official 15:a81a8d6c1dfe 484 #if SAMD20 || SAML21 || SAMC20 || SAMC21
mbed_official 15:a81a8d6c1dfe 485 # define TC_INSTANCE_OFFSET 0
mbed_official 15:a81a8d6c1dfe 486 #endif
mbed_official 15:a81a8d6c1dfe 487 #if SAMD21 || SAMR21 || SAMDA1
mbed_official 15:a81a8d6c1dfe 488 # define TC_INSTANCE_OFFSET 3
mbed_official 15:a81a8d6c1dfe 489 #endif
mbed_official 15:a81a8d6c1dfe 490 #if SAMD10 || SAMD11
mbed_official 15:a81a8d6c1dfe 491 # define TC_INSTANCE_OFFSET 1
mbed_official 15:a81a8d6c1dfe 492 #endif
mbed_official 15:a81a8d6c1dfe 493
mbed_official 15:a81a8d6c1dfe 494 #if SAMD20
mbed_official 15:a81a8d6c1dfe 495 # define NUMBER_OF_COMPARE_CAPTURE_CHANNELS TC0_CC8_NUM
mbed_official 15:a81a8d6c1dfe 496 #elif SAML21 || SAMC20 || SAMC21
mbed_official 15:a81a8d6c1dfe 497 # define NUMBER_OF_COMPARE_CAPTURE_CHANNELS TC0_CC_NUM
mbed_official 15:a81a8d6c1dfe 498 #elif SAMD10 || SAMD11
mbed_official 15:a81a8d6c1dfe 499 # define NUMBER_OF_COMPARE_CAPTURE_CHANNELS TC1_CC8_NUM
mbed_official 15:a81a8d6c1dfe 500 #else
mbed_official 15:a81a8d6c1dfe 501 # define NUMBER_OF_COMPARE_CAPTURE_CHANNELS TC3_CC8_NUM
mbed_official 15:a81a8d6c1dfe 502 /* Same number for 8-, 16- and 32-bit TC and all TC instances */
mbed_official 15:a81a8d6c1dfe 503 #endif
mbed_official 15:a81a8d6c1dfe 504
mbed_official 15:a81a8d6c1dfe 505 /** TC Instance MAX ID Number. */
mbed_official 15:a81a8d6c1dfe 506 #if SAMD20E || SAMD21G || SAMD21E || SAMR21
mbed_official 15:a81a8d6c1dfe 507 #define TC_INST_MAX_ID 5
mbed_official 15:a81a8d6c1dfe 508 #elif SAML21 || SAMC20 || SAMC21
mbed_official 15:a81a8d6c1dfe 509 #define TC_INST_MAX_ID 4
mbed_official 15:a81a8d6c1dfe 510 #elif SAMD10 || SAMD11
mbed_official 15:a81a8d6c1dfe 511 #define TC_INST_MAX_ID 2
mbed_official 15:a81a8d6c1dfe 512 #else
mbed_official 15:a81a8d6c1dfe 513 #define TC_INST_MAX_ID 7
mbed_official 15:a81a8d6c1dfe 514 #endif
mbed_official 15:a81a8d6c1dfe 515
mbed_official 15:a81a8d6c1dfe 516 #endif
mbed_official 15:a81a8d6c1dfe 517
mbed_official 15:a81a8d6c1dfe 518 #if TC_ASYNC == true
mbed_official 15:a81a8d6c1dfe 519 # include <system_interrupt.h>
mbed_official 15:a81a8d6c1dfe 520 #endif
mbed_official 15:a81a8d6c1dfe 521
mbed_official 15:a81a8d6c1dfe 522 #ifdef __cplusplus
mbed_official 15:a81a8d6c1dfe 523 extern "C" {
mbed_official 15:a81a8d6c1dfe 524 #endif
mbed_official 15:a81a8d6c1dfe 525
mbed_official 15:a81a8d6c1dfe 526 #if TC_ASYNC == true
mbed_official 15:a81a8d6c1dfe 527 /** Enum for the possible callback types for the TC module. */
mbed_official 15:a81a8d6c1dfe 528 enum tc_callback {
mbed_official 15:a81a8d6c1dfe 529 /** Callback for TC overflow. */
mbed_official 15:a81a8d6c1dfe 530 TC_CALLBACK_OVERFLOW,
mbed_official 15:a81a8d6c1dfe 531 /** Callback for capture overflow error. */
mbed_official 15:a81a8d6c1dfe 532 TC_CALLBACK_ERROR,
mbed_official 15:a81a8d6c1dfe 533 /** Callback for capture compare channel 0. */
mbed_official 15:a81a8d6c1dfe 534 TC_CALLBACK_CC_CHANNEL0,
mbed_official 15:a81a8d6c1dfe 535 /** Callback for capture compare channel 1. */
mbed_official 15:a81a8d6c1dfe 536 TC_CALLBACK_CC_CHANNEL1,
mbed_official 15:a81a8d6c1dfe 537 # if !defined(__DOXYGEN__)
mbed_official 15:a81a8d6c1dfe 538 /** Number of available callbacks. */
mbed_official 15:a81a8d6c1dfe 539 TC_CALLBACK_N,
mbed_official 15:a81a8d6c1dfe 540 # endif
mbed_official 15:a81a8d6c1dfe 541 };
mbed_official 15:a81a8d6c1dfe 542 #endif
mbed_official 15:a81a8d6c1dfe 543
mbed_official 15:a81a8d6c1dfe 544 /**
mbed_official 15:a81a8d6c1dfe 545 * \name Module Status Flags
mbed_official 15:a81a8d6c1dfe 546 *
mbed_official 15:a81a8d6c1dfe 547 * TC status flags, returned by \ref tc_get_status() and cleared by
mbed_official 15:a81a8d6c1dfe 548 * \ref tc_clear_status().
mbed_official 15:a81a8d6c1dfe 549 *
mbed_official 15:a81a8d6c1dfe 550 * @{
mbed_official 15:a81a8d6c1dfe 551 */
mbed_official 15:a81a8d6c1dfe 552
mbed_official 15:a81a8d6c1dfe 553 /** Timer channel 0 has matched against its compare value, or has captured a
mbed_official 15:a81a8d6c1dfe 554 * new value.
mbed_official 15:a81a8d6c1dfe 555 */
mbed_official 15:a81a8d6c1dfe 556 #define TC_STATUS_CHANNEL_0_MATCH (1UL << 0)
mbed_official 15:a81a8d6c1dfe 557
mbed_official 15:a81a8d6c1dfe 558 /** Timer channel 1 has matched against its compare value, or has captured a
mbed_official 15:a81a8d6c1dfe 559 * new value.
mbed_official 15:a81a8d6c1dfe 560 */
mbed_official 15:a81a8d6c1dfe 561 #define TC_STATUS_CHANNEL_1_MATCH (1UL << 1)
mbed_official 15:a81a8d6c1dfe 562
mbed_official 15:a81a8d6c1dfe 563 /** Timer register synchronization has completed, and the synchronized count
mbed_official 15:a81a8d6c1dfe 564 * value may be read.
mbed_official 15:a81a8d6c1dfe 565 */
mbed_official 15:a81a8d6c1dfe 566 #define TC_STATUS_SYNC_READY (1UL << 2)
mbed_official 15:a81a8d6c1dfe 567
mbed_official 15:a81a8d6c1dfe 568 /** A new value was captured before the previous value was read, resulting in
mbed_official 15:a81a8d6c1dfe 569 * lost data.
mbed_official 15:a81a8d6c1dfe 570 */
mbed_official 15:a81a8d6c1dfe 571 #define TC_STATUS_CAPTURE_OVERFLOW (1UL << 3)
mbed_official 15:a81a8d6c1dfe 572
mbed_official 15:a81a8d6c1dfe 573 /** The timer count value has overflowed from its maximum value to its minimum
mbed_official 15:a81a8d6c1dfe 574 * when counting upward, or from its minimum value to its maximum when
mbed_official 15:a81a8d6c1dfe 575 * counting downward.
mbed_official 15:a81a8d6c1dfe 576 */
mbed_official 15:a81a8d6c1dfe 577 #define TC_STATUS_COUNT_OVERFLOW (1UL << 4)
mbed_official 15:a81a8d6c1dfe 578
mbed_official 15:a81a8d6c1dfe 579 #ifdef FEATURE_TC_DOUBLE_BUFFERED
mbed_official 15:a81a8d6c1dfe 580 /** Channel 0 compare or capture buffer valid. */
mbed_official 15:a81a8d6c1dfe 581 #define TC_STATUS_CHN0_BUFFER_VALID (1UL << 5)
mbed_official 15:a81a8d6c1dfe 582 /** Channel 1 compare or capture buffer valid. */
mbed_official 15:a81a8d6c1dfe 583 #define TC_STATUS_CHN1_BUFFER_VALID (1UL << 6)
mbed_official 15:a81a8d6c1dfe 584 /** Period buffer valid. */
mbed_official 15:a81a8d6c1dfe 585 #define TC_STATUS_PERIOD_BUFFER_VALID (1UL << 7)
mbed_official 15:a81a8d6c1dfe 586 #endif
mbed_official 15:a81a8d6c1dfe 587 /** @} */
mbed_official 15:a81a8d6c1dfe 588
mbed_official 15:a81a8d6c1dfe 589 /**
mbed_official 15:a81a8d6c1dfe 590 * \brief Index of the compare capture channels.
mbed_official 15:a81a8d6c1dfe 591 *
mbed_official 15:a81a8d6c1dfe 592 * This enum is used to specify which capture/compare channel to do
mbed_official 15:a81a8d6c1dfe 593 * operations on.
mbed_official 15:a81a8d6c1dfe 594 */
mbed_official 15:a81a8d6c1dfe 595 enum tc_compare_capture_channel {
mbed_official 15:a81a8d6c1dfe 596 /** Index of compare capture channel 0. */
mbed_official 15:a81a8d6c1dfe 597 TC_COMPARE_CAPTURE_CHANNEL_0,
mbed_official 15:a81a8d6c1dfe 598 /** Index of compare capture channel 1. */
mbed_official 15:a81a8d6c1dfe 599 TC_COMPARE_CAPTURE_CHANNEL_1,
mbed_official 15:a81a8d6c1dfe 600 };
mbed_official 15:a81a8d6c1dfe 601
mbed_official 15:a81a8d6c1dfe 602 /** TC wave generation mode. */
mbed_official 15:a81a8d6c1dfe 603 #if SAML21 || SAMC20 || SAMC21
mbed_official 15:a81a8d6c1dfe 604 #define TC_WAVE_GENERATION_NORMAL_FREQ_MODE TC_WAVE_WAVEGEN_NFRQ
mbed_official 15:a81a8d6c1dfe 605 #define TC_WAVE_GENERATION_MATCH_FREQ_MODE TC_WAVE_WAVEGEN_MFRQ
mbed_official 15:a81a8d6c1dfe 606 #define TC_WAVE_GENERATION_NORMAL_PWM_MODE TC_WAVE_WAVEGEN_NPWM
mbed_official 15:a81a8d6c1dfe 607 #define TC_WAVE_GENERATION_MATCH_PWM_MODE TC_WAVE_WAVEGEN_MPWM
mbed_official 15:a81a8d6c1dfe 608 #else
mbed_official 15:a81a8d6c1dfe 609 #define TC_WAVE_GENERATION_NORMAL_FREQ_MODE TC_CTRLA_WAVEGEN_NFRQ
mbed_official 15:a81a8d6c1dfe 610 #define TC_WAVE_GENERATION_MATCH_FREQ_MODE TC_CTRLA_WAVEGEN_MFRQ
mbed_official 15:a81a8d6c1dfe 611 #define TC_WAVE_GENERATION_NORMAL_PWM_MODE TC_CTRLA_WAVEGEN_NPWM
mbed_official 15:a81a8d6c1dfe 612 #define TC_WAVE_GENERATION_MATCH_PWM_MODE TC_CTRLA_WAVEGEN_MPWM
mbed_official 15:a81a8d6c1dfe 613 #endif
mbed_official 15:a81a8d6c1dfe 614
mbed_official 15:a81a8d6c1dfe 615 /**
mbed_official 15:a81a8d6c1dfe 616 * \brief TC wave generation mode enum.
mbed_official 15:a81a8d6c1dfe 617 *
mbed_official 15:a81a8d6c1dfe 618 * This enum is used to select which mode to run the wave
mbed_official 15:a81a8d6c1dfe 619 * generation in.
mbed_official 15:a81a8d6c1dfe 620 *
mbed_official 15:a81a8d6c1dfe 621 */
mbed_official 15:a81a8d6c1dfe 622 enum tc_wave_generation {
mbed_official 15:a81a8d6c1dfe 623 /** Top is maximum, except in 8-bit counter size where it is the PER
mbed_official 15:a81a8d6c1dfe 624 * register.
mbed_official 15:a81a8d6c1dfe 625 */
mbed_official 15:a81a8d6c1dfe 626 TC_WAVE_GENERATION_NORMAL_FREQ = TC_WAVE_GENERATION_NORMAL_FREQ_MODE,
mbed_official 15:a81a8d6c1dfe 627
mbed_official 15:a81a8d6c1dfe 628 /** Top is CC0, except in 8-bit counter size where it is the PER
mbed_official 15:a81a8d6c1dfe 629 * register.
mbed_official 15:a81a8d6c1dfe 630 */
mbed_official 15:a81a8d6c1dfe 631 TC_WAVE_GENERATION_MATCH_FREQ = TC_WAVE_GENERATION_MATCH_FREQ_MODE,
mbed_official 15:a81a8d6c1dfe 632
mbed_official 15:a81a8d6c1dfe 633 /** Top is maximum, except in 8-bit counter size where it is the PER
mbed_official 15:a81a8d6c1dfe 634 * register.
mbed_official 15:a81a8d6c1dfe 635 */
mbed_official 15:a81a8d6c1dfe 636 TC_WAVE_GENERATION_NORMAL_PWM = TC_WAVE_GENERATION_NORMAL_PWM_MODE,
mbed_official 15:a81a8d6c1dfe 637
mbed_official 15:a81a8d6c1dfe 638 /** Top is CC0, except in 8-bit counter size where it is the PER
mbed_official 15:a81a8d6c1dfe 639 * register.
mbed_official 15:a81a8d6c1dfe 640 */
mbed_official 15:a81a8d6c1dfe 641 TC_WAVE_GENERATION_MATCH_PWM = TC_WAVE_GENERATION_MATCH_PWM_MODE,
mbed_official 15:a81a8d6c1dfe 642 };
mbed_official 15:a81a8d6c1dfe 643
mbed_official 15:a81a8d6c1dfe 644 /**
mbed_official 15:a81a8d6c1dfe 645 * \brief Specifies if the counter is 8-, 16-, or 32-bit.
mbed_official 15:a81a8d6c1dfe 646 *
mbed_official 15:a81a8d6c1dfe 647 * This enum specifies the maximum value it is possible to count to.
mbed_official 15:a81a8d6c1dfe 648 */
mbed_official 15:a81a8d6c1dfe 649 enum tc_counter_size {
mbed_official 15:a81a8d6c1dfe 650 /** The counter's maximum value is 0xFF, the period register is
mbed_official 15:a81a8d6c1dfe 651 * available to be used as top value.
mbed_official 15:a81a8d6c1dfe 652 */
mbed_official 15:a81a8d6c1dfe 653 TC_COUNTER_SIZE_8BIT = TC_CTRLA_MODE_COUNT8,
mbed_official 15:a81a8d6c1dfe 654
mbed_official 15:a81a8d6c1dfe 655 /** The counter's maximum value is 0xFFFF. There is no separate
mbed_official 15:a81a8d6c1dfe 656 * period register, to modify top one of the capture compare
mbed_official 15:a81a8d6c1dfe 657 * registers has to be used. This limits the amount of
mbed_official 15:a81a8d6c1dfe 658 * available channels.
mbed_official 15:a81a8d6c1dfe 659 */
mbed_official 15:a81a8d6c1dfe 660 TC_COUNTER_SIZE_16BIT = TC_CTRLA_MODE_COUNT16,
mbed_official 15:a81a8d6c1dfe 661
mbed_official 15:a81a8d6c1dfe 662 /** The counter's maximum value is 0xFFFFFFFF. There is no separate
mbed_official 15:a81a8d6c1dfe 663 * period register, to modify top one of the capture compare
mbed_official 15:a81a8d6c1dfe 664 * registers has to be used. This limits the amount of
mbed_official 15:a81a8d6c1dfe 665 * available channels.
mbed_official 15:a81a8d6c1dfe 666 */
mbed_official 15:a81a8d6c1dfe 667 TC_COUNTER_SIZE_32BIT = TC_CTRLA_MODE_COUNT32,
mbed_official 15:a81a8d6c1dfe 668 };
mbed_official 15:a81a8d6c1dfe 669
mbed_official 15:a81a8d6c1dfe 670 /**
mbed_official 15:a81a8d6c1dfe 671 * \brief TC Counter reload action enum.
mbed_official 15:a81a8d6c1dfe 672 *
mbed_official 15:a81a8d6c1dfe 673 * This enum specify how the counter and prescaler should reload.
mbed_official 15:a81a8d6c1dfe 674 */
mbed_official 15:a81a8d6c1dfe 675 enum tc_reload_action {
mbed_official 15:a81a8d6c1dfe 676 /** The counter is reloaded/reset on the next GCLK and starts
mbed_official 15:a81a8d6c1dfe 677 * counting on the prescaler clock.
mbed_official 15:a81a8d6c1dfe 678 */
mbed_official 15:a81a8d6c1dfe 679 TC_RELOAD_ACTION_GCLK = TC_CTRLA_PRESCSYNC_GCLK,
mbed_official 15:a81a8d6c1dfe 680
mbed_official 15:a81a8d6c1dfe 681 /** The counter is reloaded/reset on the next prescaler clock.
mbed_official 15:a81a8d6c1dfe 682 */
mbed_official 15:a81a8d6c1dfe 683 TC_RELOAD_ACTION_PRESC = TC_CTRLA_PRESCSYNC_PRESC,
mbed_official 15:a81a8d6c1dfe 684
mbed_official 15:a81a8d6c1dfe 685 /** The counter is reloaded/reset on the next GCLK, and the
mbed_official 15:a81a8d6c1dfe 686 * prescaler is restarted as well.
mbed_official 15:a81a8d6c1dfe 687 */
mbed_official 15:a81a8d6c1dfe 688 TC_RELOAD_ACTION_RESYNC = TC_CTRLA_PRESCSYNC_RESYNC,
mbed_official 15:a81a8d6c1dfe 689 };
mbed_official 15:a81a8d6c1dfe 690
mbed_official 15:a81a8d6c1dfe 691 /**
mbed_official 15:a81a8d6c1dfe 692 * \brief TC clock prescaler values.
mbed_official 15:a81a8d6c1dfe 693 *
mbed_official 15:a81a8d6c1dfe 694 * This enum is used to choose the clock prescaler
mbed_official 15:a81a8d6c1dfe 695 * configuration. The prescaler divides the clock frequency of the TC
mbed_official 15:a81a8d6c1dfe 696 * module to make the counter count slower.
mbed_official 15:a81a8d6c1dfe 697 */
mbed_official 15:a81a8d6c1dfe 698 enum tc_clock_prescaler {
mbed_official 15:a81a8d6c1dfe 699 /** Divide clock by 1. */
mbed_official 15:a81a8d6c1dfe 700 TC_CLOCK_PRESCALER_DIV1 = TC_CTRLA_PRESCALER(0),
mbed_official 15:a81a8d6c1dfe 701 /** Divide clock by 2. */
mbed_official 15:a81a8d6c1dfe 702 TC_CLOCK_PRESCALER_DIV2 = TC_CTRLA_PRESCALER(1),
mbed_official 15:a81a8d6c1dfe 703 /** Divide clock by 4. */
mbed_official 15:a81a8d6c1dfe 704 TC_CLOCK_PRESCALER_DIV4 = TC_CTRLA_PRESCALER(2),
mbed_official 15:a81a8d6c1dfe 705 /** Divide clock by 8. */
mbed_official 15:a81a8d6c1dfe 706 TC_CLOCK_PRESCALER_DIV8 = TC_CTRLA_PRESCALER(3),
mbed_official 15:a81a8d6c1dfe 707 /** Divide clock by 16. */
mbed_official 15:a81a8d6c1dfe 708 TC_CLOCK_PRESCALER_DIV16 = TC_CTRLA_PRESCALER(4),
mbed_official 15:a81a8d6c1dfe 709 /** Divide clock by 64. */
mbed_official 15:a81a8d6c1dfe 710 TC_CLOCK_PRESCALER_DIV64 = TC_CTRLA_PRESCALER(5),
mbed_official 15:a81a8d6c1dfe 711 /** Divide clock by 256. */
mbed_official 15:a81a8d6c1dfe 712 TC_CLOCK_PRESCALER_DIV256 = TC_CTRLA_PRESCALER(6),
mbed_official 15:a81a8d6c1dfe 713 /** Divide clock by 1024. */
mbed_official 15:a81a8d6c1dfe 714 TC_CLOCK_PRESCALER_DIV1024 = TC_CTRLA_PRESCALER(7),
mbed_official 15:a81a8d6c1dfe 715 };
mbed_official 15:a81a8d6c1dfe 716
mbed_official 15:a81a8d6c1dfe 717 /**
mbed_official 15:a81a8d6c1dfe 718 * \brief TC module count direction.
mbed_official 15:a81a8d6c1dfe 719 *
mbed_official 15:a81a8d6c1dfe 720 * Timer/Counter count direction.
mbed_official 15:a81a8d6c1dfe 721 */
mbed_official 15:a81a8d6c1dfe 722 enum tc_count_direction {
mbed_official 15:a81a8d6c1dfe 723 /** Timer should count upward from zero to MAX. */
mbed_official 15:a81a8d6c1dfe 724 TC_COUNT_DIRECTION_UP,
mbed_official 15:a81a8d6c1dfe 725
mbed_official 15:a81a8d6c1dfe 726 /** Timer should count downward to zero from MAX. */
mbed_official 15:a81a8d6c1dfe 727 TC_COUNT_DIRECTION_DOWN,
mbed_official 15:a81a8d6c1dfe 728 };
mbed_official 15:a81a8d6c1dfe 729
mbed_official 15:a81a8d6c1dfe 730 /** Waveform inversion mode. */
mbed_official 15:a81a8d6c1dfe 731 #if SAML21 || SAMC20 || SAMC21
mbed_official 15:a81a8d6c1dfe 732 #define TC_WAVEFORM_INVERT_CC0_MODE TC_DRVCTRL_INVEN(1)
mbed_official 15:a81a8d6c1dfe 733 #define TC_WAVEFORM_INVERT_CC1_MODE TC_DRVCTRL_INVEN(2)
mbed_official 15:a81a8d6c1dfe 734 #else
mbed_official 15:a81a8d6c1dfe 735 #define TC_WAVEFORM_INVERT_CC0_MODE TC_CTRLC_INVEN(1)
mbed_official 15:a81a8d6c1dfe 736 #define TC_WAVEFORM_INVERT_CC1_MODE TC_CTRLC_INVEN(2)
mbed_official 15:a81a8d6c1dfe 737 #endif
mbed_official 15:a81a8d6c1dfe 738
mbed_official 15:a81a8d6c1dfe 739 /**
mbed_official 15:a81a8d6c1dfe 740 * \brief Waveform inversion mode.
mbed_official 15:a81a8d6c1dfe 741 *
mbed_official 15:a81a8d6c1dfe 742 * Output waveform inversion mode.
mbed_official 15:a81a8d6c1dfe 743 */
mbed_official 15:a81a8d6c1dfe 744 enum tc_waveform_invert_output {
mbed_official 15:a81a8d6c1dfe 745 /** No inversion of the waveform output. */
mbed_official 15:a81a8d6c1dfe 746 TC_WAVEFORM_INVERT_OUTPUT_NONE = 0,
mbed_official 15:a81a8d6c1dfe 747 /** Invert output from compare channel 0. */
mbed_official 15:a81a8d6c1dfe 748 TC_WAVEFORM_INVERT_OUTPUT_CHANNEL_0 = TC_WAVEFORM_INVERT_CC0_MODE,
mbed_official 15:a81a8d6c1dfe 749 /** Invert output from compare channel 1. */
mbed_official 15:a81a8d6c1dfe 750 TC_WAVEFORM_INVERT_OUTPUT_CHANNEL_1 = TC_WAVEFORM_INVERT_CC1_MODE,
mbed_official 15:a81a8d6c1dfe 751 };
mbed_official 15:a81a8d6c1dfe 752
mbed_official 15:a81a8d6c1dfe 753 /**
mbed_official 15:a81a8d6c1dfe 754 * \brief Action to perform when the TC module is triggered by an event.
mbed_official 15:a81a8d6c1dfe 755 *
mbed_official 15:a81a8d6c1dfe 756 * Event action to perform when the module is triggered by an event.
mbed_official 15:a81a8d6c1dfe 757 */
mbed_official 15:a81a8d6c1dfe 758 enum tc_event_action {
mbed_official 15:a81a8d6c1dfe 759 /** No event action. */
mbed_official 15:a81a8d6c1dfe 760 TC_EVENT_ACTION_OFF = TC_EVCTRL_EVACT_OFF,
mbed_official 15:a81a8d6c1dfe 761 /** Re-trigger on event. */
mbed_official 15:a81a8d6c1dfe 762 TC_EVENT_ACTION_RETRIGGER = TC_EVCTRL_EVACT_RETRIGGER,
mbed_official 15:a81a8d6c1dfe 763 /** Increment counter on event. */
mbed_official 15:a81a8d6c1dfe 764 TC_EVENT_ACTION_INCREMENT_COUNTER = TC_EVCTRL_EVACT_COUNT,
mbed_official 15:a81a8d6c1dfe 765 /** Start counter on event. */
mbed_official 15:a81a8d6c1dfe 766 TC_EVENT_ACTION_START = TC_EVCTRL_EVACT_START,
mbed_official 15:a81a8d6c1dfe 767
mbed_official 15:a81a8d6c1dfe 768 /** Store period in capture register 0, pulse width in capture
mbed_official 15:a81a8d6c1dfe 769 * register 1.
mbed_official 15:a81a8d6c1dfe 770 */
mbed_official 15:a81a8d6c1dfe 771 TC_EVENT_ACTION_PPW = TC_EVCTRL_EVACT_PPW,
mbed_official 15:a81a8d6c1dfe 772
mbed_official 15:a81a8d6c1dfe 773 /** Store pulse width in capture register 0, period in capture
mbed_official 15:a81a8d6c1dfe 774 * register 1.
mbed_official 15:a81a8d6c1dfe 775 */
mbed_official 15:a81a8d6c1dfe 776 TC_EVENT_ACTION_PWP = TC_EVCTRL_EVACT_PWP,
mbed_official 15:a81a8d6c1dfe 777 #ifdef FEATURE_TC_STAMP_PW_CAPTURE
mbed_official 15:a81a8d6c1dfe 778 /** Time stamp capture. */
mbed_official 15:a81a8d6c1dfe 779 TC_EVENT_ACTION_STAMP = TC_EVCTRL_EVACT_STAMP,
mbed_official 15:a81a8d6c1dfe 780 /** Pulse width capture. */
mbed_official 15:a81a8d6c1dfe 781 TC_EVENT_ACTION_PW = TC_EVCTRL_EVACT_PW,
mbed_official 15:a81a8d6c1dfe 782 #endif
mbed_official 15:a81a8d6c1dfe 783 };
mbed_official 15:a81a8d6c1dfe 784
mbed_official 15:a81a8d6c1dfe 785 /**
mbed_official 15:a81a8d6c1dfe 786 * \brief TC event enable/disable structure.
mbed_official 15:a81a8d6c1dfe 787 *
mbed_official 15:a81a8d6c1dfe 788 * Event flags for the \ref tc_enable_events() and \ref tc_disable_events().
mbed_official 15:a81a8d6c1dfe 789 */
mbed_official 15:a81a8d6c1dfe 790 struct tc_events {
mbed_official 15:a81a8d6c1dfe 791 /** Generate an output event on a compare channel match. */
mbed_official 15:a81a8d6c1dfe 792 bool generate_event_on_compare_channel
mbed_official 15:a81a8d6c1dfe 793 [NUMBER_OF_COMPARE_CAPTURE_CHANNELS];
mbed_official 15:a81a8d6c1dfe 794 /** Generate an output event on counter overflow. */
mbed_official 15:a81a8d6c1dfe 795 bool generate_event_on_overflow;
mbed_official 15:a81a8d6c1dfe 796 /** Perform the configured event action when an incoming event is signalled. */
mbed_official 15:a81a8d6c1dfe 797 bool on_event_perform_action;
mbed_official 15:a81a8d6c1dfe 798 /** Specifies if the input event source is inverted, when used in PWP or
mbed_official 15:a81a8d6c1dfe 799 * PPW event action modes.
mbed_official 15:a81a8d6c1dfe 800 */
mbed_official 15:a81a8d6c1dfe 801 bool invert_event_input;
mbed_official 15:a81a8d6c1dfe 802 /** Specifies which event to trigger if an event is triggered. */
mbed_official 15:a81a8d6c1dfe 803 enum tc_event_action event_action;
mbed_official 15:a81a8d6c1dfe 804 };
mbed_official 15:a81a8d6c1dfe 805
mbed_official 15:a81a8d6c1dfe 806 /**
mbed_official 15:a81a8d6c1dfe 807 * \brief Configuration struct for TC module in 8-bit size counter mode.
mbed_official 15:a81a8d6c1dfe 808 */
mbed_official 15:a81a8d6c1dfe 809 struct tc_8bit_config {
mbed_official 15:a81a8d6c1dfe 810 /** Initial timer count value. */
mbed_official 15:a81a8d6c1dfe 811 uint8_t value;
mbed_official 15:a81a8d6c1dfe 812 /** Where to count to or from depending on the direction on the counter. */
mbed_official 15:a81a8d6c1dfe 813 uint8_t period;
mbed_official 15:a81a8d6c1dfe 814 /** Value to be used for compare match on each channel. */
mbed_official 15:a81a8d6c1dfe 815 uint8_t compare_capture_channel[NUMBER_OF_COMPARE_CAPTURE_CHANNELS];
mbed_official 15:a81a8d6c1dfe 816 };
mbed_official 15:a81a8d6c1dfe 817
mbed_official 15:a81a8d6c1dfe 818 /**
mbed_official 15:a81a8d6c1dfe 819 * \brief Configuration struct for TC module in 16-bit size counter mode.
mbed_official 15:a81a8d6c1dfe 820 */
mbed_official 15:a81a8d6c1dfe 821 struct tc_16bit_config {
mbed_official 15:a81a8d6c1dfe 822 /** Initial timer count value. */
mbed_official 15:a81a8d6c1dfe 823 uint16_t value;
mbed_official 15:a81a8d6c1dfe 824 /** Value to be used for compare match on each channel. */
mbed_official 15:a81a8d6c1dfe 825 uint16_t compare_capture_channel[NUMBER_OF_COMPARE_CAPTURE_CHANNELS];
mbed_official 15:a81a8d6c1dfe 826 };
mbed_official 15:a81a8d6c1dfe 827
mbed_official 15:a81a8d6c1dfe 828 /**
mbed_official 15:a81a8d6c1dfe 829 * \brief Configuration struct for TC module in 32-bit size counter mode.
mbed_official 15:a81a8d6c1dfe 830 */
mbed_official 15:a81a8d6c1dfe 831 struct tc_32bit_config {
mbed_official 15:a81a8d6c1dfe 832 /** Initial timer count value. */
mbed_official 15:a81a8d6c1dfe 833 uint32_t value;
mbed_official 15:a81a8d6c1dfe 834 /** Value to be used for compare match on each channel. */
mbed_official 15:a81a8d6c1dfe 835 uint32_t compare_capture_channel[NUMBER_OF_COMPARE_CAPTURE_CHANNELS];
mbed_official 15:a81a8d6c1dfe 836 };
mbed_official 15:a81a8d6c1dfe 837
mbed_official 15:a81a8d6c1dfe 838 /**
mbed_official 15:a81a8d6c1dfe 839 * \brief Configuration struct for TC module in 32-bit size counter mode.
mbed_official 15:a81a8d6c1dfe 840 */
mbed_official 15:a81a8d6c1dfe 841 struct tc_pwm_channel {
mbed_official 15:a81a8d6c1dfe 842 /** When \c true, PWM output for the given channel is enabled. */
mbed_official 15:a81a8d6c1dfe 843 bool enabled;
mbed_official 15:a81a8d6c1dfe 844 /** Specifies pin output for each channel. */
mbed_official 15:a81a8d6c1dfe 845 uint32_t pin_out;
mbed_official 15:a81a8d6c1dfe 846 /** Specifies MUX setting for each output channel pin. */
mbed_official 15:a81a8d6c1dfe 847 uint32_t pin_mux;
mbed_official 15:a81a8d6c1dfe 848 };
mbed_official 15:a81a8d6c1dfe 849
mbed_official 15:a81a8d6c1dfe 850 /**
mbed_official 15:a81a8d6c1dfe 851 * \brief TC configuration structure.
mbed_official 15:a81a8d6c1dfe 852 *
mbed_official 15:a81a8d6c1dfe 853 * Configuration struct for a TC instance. This structure should be
mbed_official 15:a81a8d6c1dfe 854 * initialized by the \ref tc_get_config_defaults function before being
mbed_official 15:a81a8d6c1dfe 855 * modified by the user application.
mbed_official 15:a81a8d6c1dfe 856 */
mbed_official 15:a81a8d6c1dfe 857 struct tc_config {
mbed_official 15:a81a8d6c1dfe 858 /** GCLK generator used to clock the peripheral. */
mbed_official 15:a81a8d6c1dfe 859 enum gclk_generator clock_source;
mbed_official 15:a81a8d6c1dfe 860
mbed_official 15:a81a8d6c1dfe 861 /** When \c true the module is enabled during standby. */
mbed_official 15:a81a8d6c1dfe 862 bool run_in_standby;
mbed_official 15:a81a8d6c1dfe 863 #if (SAML21) || (SAMC20) || (SAMC21)
mbed_official 15:a81a8d6c1dfe 864 /** Run on demand. */
mbed_official 15:a81a8d6c1dfe 865 bool on_demand;
mbed_official 15:a81a8d6c1dfe 866 #endif
mbed_official 15:a81a8d6c1dfe 867 /** Specifies either 8-, 16-, or 32-bit counter size. */
mbed_official 15:a81a8d6c1dfe 868 enum tc_counter_size counter_size;
mbed_official 15:a81a8d6c1dfe 869 /** Specifies the prescaler value for GCLK_TC. */
mbed_official 15:a81a8d6c1dfe 870 enum tc_clock_prescaler clock_prescaler;
mbed_official 15:a81a8d6c1dfe 871 /** Specifies which waveform generation mode to use. */
mbed_official 15:a81a8d6c1dfe 872 enum tc_wave_generation wave_generation;
mbed_official 15:a81a8d6c1dfe 873
mbed_official 15:a81a8d6c1dfe 874 /** Specifies the reload or reset time of the counter and prescaler
mbed_official 15:a81a8d6c1dfe 875 * resynchronization on a re-trigger event for the TC.
mbed_official 15:a81a8d6c1dfe 876 */
mbed_official 15:a81a8d6c1dfe 877 enum tc_reload_action reload_action;
mbed_official 15:a81a8d6c1dfe 878
mbed_official 15:a81a8d6c1dfe 879 /** Specifies which channel(s) to invert the waveform on.
mbed_official 15:a81a8d6c1dfe 880 For SAML21/C20/C21, it's also used to invert IO input pin. */
mbed_official 15:a81a8d6c1dfe 881 uint8_t waveform_invert_output;
mbed_official 15:a81a8d6c1dfe 882
mbed_official 15:a81a8d6c1dfe 883 /** Specifies which channel(s) to enable channel capture
mbed_official 15:a81a8d6c1dfe 884 * operation on.
mbed_official 15:a81a8d6c1dfe 885 */
mbed_official 15:a81a8d6c1dfe 886 bool enable_capture_on_channel[NUMBER_OF_COMPARE_CAPTURE_CHANNELS];
mbed_official 15:a81a8d6c1dfe 887 #ifdef FEATURE_TC_IO_CAPTURE
mbed_official 15:a81a8d6c1dfe 888 /** Specifies which channel(s) to enable I/O capture
mbed_official 15:a81a8d6c1dfe 889 * operation on.
mbed_official 15:a81a8d6c1dfe 890 */
mbed_official 15:a81a8d6c1dfe 891 bool enable_capture_on_IO[NUMBER_OF_COMPARE_CAPTURE_CHANNELS];
mbed_official 15:a81a8d6c1dfe 892 #endif
mbed_official 15:a81a8d6c1dfe 893
mbed_official 15:a81a8d6c1dfe 894 /** When \c true, one-shot will stop the TC on next hardware or software
mbed_official 15:a81a8d6c1dfe 895 * re-trigger event or overflow/underflow.
mbed_official 15:a81a8d6c1dfe 896 */
mbed_official 15:a81a8d6c1dfe 897 bool oneshot;
mbed_official 15:a81a8d6c1dfe 898
mbed_official 15:a81a8d6c1dfe 899 /** Specifies the direction for the TC to count. */
mbed_official 15:a81a8d6c1dfe 900 enum tc_count_direction count_direction;
mbed_official 15:a81a8d6c1dfe 901
mbed_official 15:a81a8d6c1dfe 902 /** Specifies the PWM channel for TC. */
mbed_official 15:a81a8d6c1dfe 903 struct tc_pwm_channel pwm_channel[NUMBER_OF_COMPARE_CAPTURE_CHANNELS];
mbed_official 15:a81a8d6c1dfe 904
mbed_official 15:a81a8d6c1dfe 905 /** Access the different counter size settings though this configuration member. */
mbed_official 15:a81a8d6c1dfe 906 union {
mbed_official 15:a81a8d6c1dfe 907 /** Struct for 8-bit specific timer configuration. */
mbed_official 15:a81a8d6c1dfe 908 struct tc_8bit_config counter_8_bit;
mbed_official 15:a81a8d6c1dfe 909 /** Struct for 16-bit specific timer configuration. */
mbed_official 15:a81a8d6c1dfe 910 struct tc_16bit_config counter_16_bit;
mbed_official 15:a81a8d6c1dfe 911 /** Struct for 32-bit specific timer configuration. */
mbed_official 15:a81a8d6c1dfe 912 struct tc_32bit_config counter_32_bit;
mbed_official 15:a81a8d6c1dfe 913 };
mbed_official 15:a81a8d6c1dfe 914
mbed_official 15:a81a8d6c1dfe 915 #ifdef FEATURE_TC_DOUBLE_BUFFERED
mbed_official 15:a81a8d6c1dfe 916 /** Set to \c true to enable double buffering write. When enabled any write
mbed_official 15:a81a8d6c1dfe 917 * through \ref tc_set_top_value(), \ref tc_set_compare_value() and
mbed_official 15:a81a8d6c1dfe 918 * will direct to the buffer register as buffered
mbed_official 15:a81a8d6c1dfe 919 * value, and the buffered value will be committed to effective register
mbed_official 15:a81a8d6c1dfe 920 * on UPDATE condition, if update is not locked.
mbed_official 15:a81a8d6c1dfe 921 */
mbed_official 15:a81a8d6c1dfe 922 bool double_buffering_enabled;
mbed_official 15:a81a8d6c1dfe 923 #endif
mbed_official 15:a81a8d6c1dfe 924 };
mbed_official 15:a81a8d6c1dfe 925
mbed_official 15:a81a8d6c1dfe 926 #if TC_ASYNC == true
mbed_official 15:a81a8d6c1dfe 927 /* Forward Declaration for the device instance. */
mbed_official 15:a81a8d6c1dfe 928 struct tc_module;
mbed_official 15:a81a8d6c1dfe 929
mbed_official 15:a81a8d6c1dfe 930 /* Type of the callback functions. */
mbed_official 15:a81a8d6c1dfe 931 typedef void (*tc_callback_t)(struct tc_module *const module);
mbed_official 15:a81a8d6c1dfe 932 #endif
mbed_official 15:a81a8d6c1dfe 933
mbed_official 15:a81a8d6c1dfe 934 /**
mbed_official 15:a81a8d6c1dfe 935 * \brief TC software device instance structure.
mbed_official 15:a81a8d6c1dfe 936 *
mbed_official 15:a81a8d6c1dfe 937 * TC software instance structure, used to retain software state information
mbed_official 15:a81a8d6c1dfe 938 * of an associated hardware module instance.
mbed_official 15:a81a8d6c1dfe 939 *
mbed_official 15:a81a8d6c1dfe 940 * \note The fields of this structure should not be altered by the user
mbed_official 15:a81a8d6c1dfe 941 * application; they are reserved for module-internal use only.
mbed_official 15:a81a8d6c1dfe 942 */
mbed_official 15:a81a8d6c1dfe 943 struct tc_module {
mbed_official 15:a81a8d6c1dfe 944 #if !defined(__DOXYGEN__)
mbed_official 15:a81a8d6c1dfe 945 /** Hardware module pointer of the associated Timer/Counter peripheral. */
mbed_official 15:a81a8d6c1dfe 946 Tc *hw;
mbed_official 15:a81a8d6c1dfe 947
mbed_official 15:a81a8d6c1dfe 948 /** Size of the initialized Timer/Counter module configuration. */
mbed_official 15:a81a8d6c1dfe 949 enum tc_counter_size counter_size;
mbed_official 15:a81a8d6c1dfe 950 # if TC_ASYNC == true
mbed_official 15:a81a8d6c1dfe 951 /** Array of callbacks. */
mbed_official 15:a81a8d6c1dfe 952 tc_callback_t callback[TC_CALLBACK_N];
mbed_official 15:a81a8d6c1dfe 953 /** Bit mask for callbacks registered. */
mbed_official 15:a81a8d6c1dfe 954 uint8_t register_callback_mask;
mbed_official 15:a81a8d6c1dfe 955 /** Bit mask for callbacks enabled. */
mbed_official 15:a81a8d6c1dfe 956 uint8_t enable_callback_mask;
mbed_official 15:a81a8d6c1dfe 957 # endif
mbed_official 15:a81a8d6c1dfe 958 #ifdef FEATURE_TC_DOUBLE_BUFFERED
mbed_official 15:a81a8d6c1dfe 959 /** Set to \c true to enable double buffering write. */
mbed_official 15:a81a8d6c1dfe 960 bool double_buffering_enabled;
mbed_official 15:a81a8d6c1dfe 961 #endif
mbed_official 15:a81a8d6c1dfe 962 #endif
mbed_official 15:a81a8d6c1dfe 963 };
mbed_official 15:a81a8d6c1dfe 964
mbed_official 15:a81a8d6c1dfe 965 #if !defined(__DOXYGEN__)
mbed_official 15:a81a8d6c1dfe 966 uint8_t _tc_get_inst_index(
mbed_official 15:a81a8d6c1dfe 967 Tc *const hw);
mbed_official 15:a81a8d6c1dfe 968 #endif
mbed_official 15:a81a8d6c1dfe 969
mbed_official 15:a81a8d6c1dfe 970 /**
mbed_official 15:a81a8d6c1dfe 971 * \name Driver Initialization and Configuration
mbed_official 15:a81a8d6c1dfe 972 * @{
mbed_official 15:a81a8d6c1dfe 973 */
mbed_official 15:a81a8d6c1dfe 974
mbed_official 15:a81a8d6c1dfe 975 /**
mbed_official 15:a81a8d6c1dfe 976 * \brief Determines if the hardware module(s) are currently synchronizing to
mbed_official 15:a81a8d6c1dfe 977 *the bus.
mbed_official 15:a81a8d6c1dfe 978 *
mbed_official 15:a81a8d6c1dfe 979 * Checks to see if the underlying hardware peripheral module(s) are currently
mbed_official 15:a81a8d6c1dfe 980 * synchronizing across multiple clock domains to the hardware bus. This
mbed_official 15:a81a8d6c1dfe 981 * function can be used to delay further operations on a module until such time
mbed_official 15:a81a8d6c1dfe 982 * that it is ready, to prevent blocking delays for synchronization in the
mbed_official 15:a81a8d6c1dfe 983 * user application.
mbed_official 15:a81a8d6c1dfe 984 *
mbed_official 15:a81a8d6c1dfe 985 * \param[in] module_inst Pointer to the software module instance struct
mbed_official 15:a81a8d6c1dfe 986 *
mbed_official 15:a81a8d6c1dfe 987 * \return Synchronization status of the underlying hardware module(s).
mbed_official 15:a81a8d6c1dfe 988 *
mbed_official 15:a81a8d6c1dfe 989 * \retval false If the module has completed synchronization
mbed_official 15:a81a8d6c1dfe 990 * \retval true If the module synchronization is ongoing
mbed_official 15:a81a8d6c1dfe 991 */
mbed_official 15:a81a8d6c1dfe 992 static inline bool tc_is_syncing(
mbed_official 15:a81a8d6c1dfe 993 const struct tc_module *const module_inst)
mbed_official 15:a81a8d6c1dfe 994 {
mbed_official 15:a81a8d6c1dfe 995 /* Sanity check arguments */
mbed_official 15:a81a8d6c1dfe 996 Assert(module_inst);
mbed_official 15:a81a8d6c1dfe 997 Assert(module_inst->hw);
mbed_official 15:a81a8d6c1dfe 998
mbed_official 15:a81a8d6c1dfe 999 /* Get a pointer to the module's hardware instance */
mbed_official 15:a81a8d6c1dfe 1000 TcCount8 *const tc_module = &(module_inst->hw->COUNT8);
mbed_official 15:a81a8d6c1dfe 1001
mbed_official 15:a81a8d6c1dfe 1002 #if (SAML21) || (SAMC20) || (SAMC21)
mbed_official 15:a81a8d6c1dfe 1003 return (tc_module->SYNCBUSY.reg);
mbed_official 15:a81a8d6c1dfe 1004 #else
mbed_official 15:a81a8d6c1dfe 1005 return (tc_module->STATUS.reg & TC_STATUS_SYNCBUSY);
mbed_official 15:a81a8d6c1dfe 1006 #endif
mbed_official 15:a81a8d6c1dfe 1007 }
mbed_official 15:a81a8d6c1dfe 1008
mbed_official 15:a81a8d6c1dfe 1009 /**
mbed_official 15:a81a8d6c1dfe 1010 * \brief Initializes config with predefined default values.
mbed_official 15:a81a8d6c1dfe 1011 *
mbed_official 15:a81a8d6c1dfe 1012 * This function will initialize a given TC configuration structure to
mbed_official 15:a81a8d6c1dfe 1013 * a set of known default values. This function should be called on
mbed_official 15:a81a8d6c1dfe 1014 * any new instance of the configuration structures before being
mbed_official 15:a81a8d6c1dfe 1015 * modified by the user application.
mbed_official 15:a81a8d6c1dfe 1016 *
mbed_official 15:a81a8d6c1dfe 1017 * The default configuration is as follows:
mbed_official 15:a81a8d6c1dfe 1018 * \li GCLK generator 0 (GCLK main) clock source
mbed_official 15:a81a8d6c1dfe 1019 * \li 16-bit counter size on the counter
mbed_official 15:a81a8d6c1dfe 1020 * \li No prescaler
mbed_official 15:a81a8d6c1dfe 1021 * \li Normal frequency wave generation
mbed_official 15:a81a8d6c1dfe 1022 * \li GCLK reload action
mbed_official 15:a81a8d6c1dfe 1023 * \li Don't run in standby
mbed_official 15:a81a8d6c1dfe 1024 * \li Don't run on demand for SAML21/C20/C21
mbed_official 15:a81a8d6c1dfe 1025 * \li No inversion of waveform output
mbed_official 15:a81a8d6c1dfe 1026 * \li No capture enabled
mbed_official 15:a81a8d6c1dfe 1027 * \li No I/O capture enabled for SAML21/C20/C21
mbed_official 15:a81a8d6c1dfe 1028 * \li No event input enabled
mbed_official 15:a81a8d6c1dfe 1029 * \li Count upward
mbed_official 15:a81a8d6c1dfe 1030 * \li Don't perform one-shot operations
mbed_official 15:a81a8d6c1dfe 1031 * \li No event action
mbed_official 15:a81a8d6c1dfe 1032 * \li No channel 0 PWM output
mbed_official 15:a81a8d6c1dfe 1033 * \li No channel 1 PWM output
mbed_official 15:a81a8d6c1dfe 1034 * \li Counter starts on 0
mbed_official 15:a81a8d6c1dfe 1035 * \li Capture compare channel 0 set to 0
mbed_official 15:a81a8d6c1dfe 1036 * \li Capture compare channel 1 set to 0
mbed_official 15:a81a8d6c1dfe 1037 * \li No PWM pin output enabled
mbed_official 15:a81a8d6c1dfe 1038 * \li Pin and MUX configuration not set
mbed_official 15:a81a8d6c1dfe 1039 * \li Double buffer disabled (if have this feature)
mbed_official 15:a81a8d6c1dfe 1040 *
mbed_official 15:a81a8d6c1dfe 1041 * \param[out] config Pointer to a TC module configuration structure to set
mbed_official 15:a81a8d6c1dfe 1042 */
mbed_official 15:a81a8d6c1dfe 1043 static inline void tc_get_config_defaults(
mbed_official 15:a81a8d6c1dfe 1044 struct tc_config *const config)
mbed_official 15:a81a8d6c1dfe 1045 {
mbed_official 15:a81a8d6c1dfe 1046 /* Sanity check arguments */
mbed_official 15:a81a8d6c1dfe 1047 Assert(config);
mbed_official 15:a81a8d6c1dfe 1048
mbed_official 15:a81a8d6c1dfe 1049 /* Write default config to config struct */
mbed_official 15:a81a8d6c1dfe 1050 config->clock_source = GCLK_GENERATOR_0;
mbed_official 15:a81a8d6c1dfe 1051 config->counter_size = TC_COUNTER_SIZE_16BIT;
mbed_official 15:a81a8d6c1dfe 1052 config->clock_prescaler = TC_CLOCK_PRESCALER_DIV1;
mbed_official 15:a81a8d6c1dfe 1053 config->wave_generation = TC_WAVE_GENERATION_NORMAL_FREQ;
mbed_official 15:a81a8d6c1dfe 1054 config->reload_action = TC_RELOAD_ACTION_GCLK;
mbed_official 15:a81a8d6c1dfe 1055 config->run_in_standby = false;
mbed_official 15:a81a8d6c1dfe 1056 #if (SAML21) || (SAMC20) || (SAMC21)
mbed_official 15:a81a8d6c1dfe 1057 config->on_demand = false;
mbed_official 15:a81a8d6c1dfe 1058 #endif
mbed_official 15:a81a8d6c1dfe 1059 config->waveform_invert_output = TC_WAVEFORM_INVERT_OUTPUT_NONE;
mbed_official 15:a81a8d6c1dfe 1060 config->enable_capture_on_channel[TC_COMPARE_CAPTURE_CHANNEL_0] = false;
mbed_official 15:a81a8d6c1dfe 1061 config->enable_capture_on_channel[TC_COMPARE_CAPTURE_CHANNEL_1] = false;
mbed_official 15:a81a8d6c1dfe 1062 #ifdef FEATURE_TC_IO_CAPTURE
mbed_official 15:a81a8d6c1dfe 1063 config->enable_capture_on_IO[TC_COMPARE_CAPTURE_CHANNEL_0] = false;
mbed_official 15:a81a8d6c1dfe 1064 config->enable_capture_on_IO[TC_COMPARE_CAPTURE_CHANNEL_1] = false;
mbed_official 15:a81a8d6c1dfe 1065 #endif
mbed_official 15:a81a8d6c1dfe 1066
mbed_official 15:a81a8d6c1dfe 1067 config->count_direction = TC_COUNT_DIRECTION_UP;
mbed_official 15:a81a8d6c1dfe 1068 config->oneshot = false;
mbed_official 15:a81a8d6c1dfe 1069
mbed_official 15:a81a8d6c1dfe 1070 config->pwm_channel[TC_COMPARE_CAPTURE_CHANNEL_0].enabled = false;
mbed_official 15:a81a8d6c1dfe 1071 config->pwm_channel[TC_COMPARE_CAPTURE_CHANNEL_0].pin_out = 0;
mbed_official 15:a81a8d6c1dfe 1072 config->pwm_channel[TC_COMPARE_CAPTURE_CHANNEL_0].pin_mux = 0;
mbed_official 15:a81a8d6c1dfe 1073
mbed_official 15:a81a8d6c1dfe 1074 config->pwm_channel[TC_COMPARE_CAPTURE_CHANNEL_1].enabled = false;
mbed_official 15:a81a8d6c1dfe 1075 config->pwm_channel[TC_COMPARE_CAPTURE_CHANNEL_1].pin_out = 0;
mbed_official 15:a81a8d6c1dfe 1076 config->pwm_channel[TC_COMPARE_CAPTURE_CHANNEL_1].pin_mux = 0;
mbed_official 15:a81a8d6c1dfe 1077
mbed_official 15:a81a8d6c1dfe 1078 config->counter_16_bit.value = 0x0000;
mbed_official 15:a81a8d6c1dfe 1079 config->counter_16_bit.compare_capture_channel\
mbed_official 15:a81a8d6c1dfe 1080 [TC_COMPARE_CAPTURE_CHANNEL_0] = 0x0000;
mbed_official 15:a81a8d6c1dfe 1081 config->counter_16_bit.compare_capture_channel\
mbed_official 15:a81a8d6c1dfe 1082 [TC_COMPARE_CAPTURE_CHANNEL_1] = 0x0000;
mbed_official 15:a81a8d6c1dfe 1083 #ifdef FEATURE_TC_DOUBLE_BUFFERED
mbed_official 15:a81a8d6c1dfe 1084 config->double_buffering_enabled = false;
mbed_official 15:a81a8d6c1dfe 1085 #endif
mbed_official 15:a81a8d6c1dfe 1086
mbed_official 15:a81a8d6c1dfe 1087 }
mbed_official 15:a81a8d6c1dfe 1088
mbed_official 15:a81a8d6c1dfe 1089 enum status_code tc_init(
mbed_official 15:a81a8d6c1dfe 1090 struct tc_module *const module_inst,
mbed_official 15:a81a8d6c1dfe 1091 Tc *const hw,
mbed_official 15:a81a8d6c1dfe 1092 const struct tc_config *const config);
mbed_official 15:a81a8d6c1dfe 1093
mbed_official 15:a81a8d6c1dfe 1094 /** @} */
mbed_official 15:a81a8d6c1dfe 1095
mbed_official 15:a81a8d6c1dfe 1096 /**
mbed_official 15:a81a8d6c1dfe 1097 * \name Event Management
mbed_official 15:a81a8d6c1dfe 1098 * @{
mbed_official 15:a81a8d6c1dfe 1099 */
mbed_official 15:a81a8d6c1dfe 1100
mbed_official 15:a81a8d6c1dfe 1101 /**
mbed_official 15:a81a8d6c1dfe 1102 * \brief Enables a TC module event input or output.
mbed_official 15:a81a8d6c1dfe 1103 *
mbed_official 15:a81a8d6c1dfe 1104 * Enables one or more input or output events to or from the TC module.
mbed_official 15:a81a8d6c1dfe 1105 * See \ref tc_events for a list of events this module supports.
mbed_official 15:a81a8d6c1dfe 1106 *
mbed_official 15:a81a8d6c1dfe 1107 * \note Events cannot be altered while the module is enabled.
mbed_official 15:a81a8d6c1dfe 1108 *
mbed_official 15:a81a8d6c1dfe 1109 * \param[in] module_inst Pointer to the software module instance struct
mbed_official 15:a81a8d6c1dfe 1110 * \param[in] events Struct containing flags of events to enable
mbed_official 15:a81a8d6c1dfe 1111 */
mbed_official 15:a81a8d6c1dfe 1112 static inline void tc_enable_events(
mbed_official 15:a81a8d6c1dfe 1113 struct tc_module *const module_inst,
mbed_official 15:a81a8d6c1dfe 1114 struct tc_events *const events)
mbed_official 15:a81a8d6c1dfe 1115 {
mbed_official 15:a81a8d6c1dfe 1116 /* Sanity check arguments */
mbed_official 15:a81a8d6c1dfe 1117 Assert(module_inst);
mbed_official 15:a81a8d6c1dfe 1118 Assert(module_inst->hw);
mbed_official 15:a81a8d6c1dfe 1119 Assert(events);
mbed_official 15:a81a8d6c1dfe 1120
mbed_official 15:a81a8d6c1dfe 1121 Tc *const tc_module = module_inst->hw;
mbed_official 15:a81a8d6c1dfe 1122
mbed_official 15:a81a8d6c1dfe 1123 uint32_t event_mask = 0;
mbed_official 15:a81a8d6c1dfe 1124
mbed_official 15:a81a8d6c1dfe 1125 if (events->invert_event_input == true) {
mbed_official 15:a81a8d6c1dfe 1126 event_mask |= TC_EVCTRL_TCINV;
mbed_official 15:a81a8d6c1dfe 1127 }
mbed_official 15:a81a8d6c1dfe 1128
mbed_official 15:a81a8d6c1dfe 1129 if (events->on_event_perform_action == true) {
mbed_official 15:a81a8d6c1dfe 1130 event_mask |= TC_EVCTRL_TCEI;
mbed_official 15:a81a8d6c1dfe 1131 }
mbed_official 15:a81a8d6c1dfe 1132
mbed_official 15:a81a8d6c1dfe 1133 if (events->generate_event_on_overflow == true) {
mbed_official 15:a81a8d6c1dfe 1134 event_mask |= TC_EVCTRL_OVFEO;
mbed_official 15:a81a8d6c1dfe 1135 }
mbed_official 15:a81a8d6c1dfe 1136
mbed_official 15:a81a8d6c1dfe 1137 for (uint8_t i = 0; i < NUMBER_OF_COMPARE_CAPTURE_CHANNELS; i++) {
mbed_official 15:a81a8d6c1dfe 1138 if (events->generate_event_on_compare_channel[i] == true) {
mbed_official 15:a81a8d6c1dfe 1139 event_mask |= (TC_EVCTRL_MCEO(1) << i);
mbed_official 15:a81a8d6c1dfe 1140 }
mbed_official 15:a81a8d6c1dfe 1141 }
mbed_official 15:a81a8d6c1dfe 1142
mbed_official 15:a81a8d6c1dfe 1143 tc_module->COUNT8.EVCTRL.reg |= event_mask | events->event_action;
mbed_official 15:a81a8d6c1dfe 1144 }
mbed_official 15:a81a8d6c1dfe 1145
mbed_official 15:a81a8d6c1dfe 1146 /**
mbed_official 15:a81a8d6c1dfe 1147 * \brief Disables a TC module event input or output.
mbed_official 15:a81a8d6c1dfe 1148 *
mbed_official 15:a81a8d6c1dfe 1149 * Disables one or more input or output events to or from the TC module.
mbed_official 15:a81a8d6c1dfe 1150 * See \ref tc_events for a list of events this module supports.
mbed_official 15:a81a8d6c1dfe 1151 *
mbed_official 15:a81a8d6c1dfe 1152 * \note Events cannot be altered while the module is enabled.
mbed_official 15:a81a8d6c1dfe 1153 *
mbed_official 15:a81a8d6c1dfe 1154 * \param[in] module_inst Pointer to the software module instance struct
mbed_official 15:a81a8d6c1dfe 1155 * \param[in] events Struct containing flags of events to disable
mbed_official 15:a81a8d6c1dfe 1156 */
mbed_official 15:a81a8d6c1dfe 1157 static inline void tc_disable_events(
mbed_official 15:a81a8d6c1dfe 1158 struct tc_module *const module_inst,
mbed_official 15:a81a8d6c1dfe 1159 struct tc_events *const events)
mbed_official 15:a81a8d6c1dfe 1160 {
mbed_official 15:a81a8d6c1dfe 1161 /* Sanity check arguments */
mbed_official 15:a81a8d6c1dfe 1162 Assert(module_inst);
mbed_official 15:a81a8d6c1dfe 1163 Assert(module_inst->hw);
mbed_official 15:a81a8d6c1dfe 1164 Assert(events);
mbed_official 15:a81a8d6c1dfe 1165
mbed_official 15:a81a8d6c1dfe 1166 Tc *const tc_module = module_inst->hw;
mbed_official 15:a81a8d6c1dfe 1167
mbed_official 15:a81a8d6c1dfe 1168 uint32_t event_mask = 0;
mbed_official 15:a81a8d6c1dfe 1169
mbed_official 15:a81a8d6c1dfe 1170 if (events->invert_event_input == true) {
mbed_official 15:a81a8d6c1dfe 1171 event_mask |= TC_EVCTRL_TCINV;
mbed_official 15:a81a8d6c1dfe 1172 }
mbed_official 15:a81a8d6c1dfe 1173
mbed_official 15:a81a8d6c1dfe 1174 if (events->on_event_perform_action == true) {
mbed_official 15:a81a8d6c1dfe 1175 event_mask |= TC_EVCTRL_TCEI;
mbed_official 15:a81a8d6c1dfe 1176 }
mbed_official 15:a81a8d6c1dfe 1177
mbed_official 15:a81a8d6c1dfe 1178 if (events->generate_event_on_overflow == true) {
mbed_official 15:a81a8d6c1dfe 1179 event_mask |= TC_EVCTRL_OVFEO;
mbed_official 15:a81a8d6c1dfe 1180 }
mbed_official 15:a81a8d6c1dfe 1181
mbed_official 15:a81a8d6c1dfe 1182 for (uint8_t i = 0; i < NUMBER_OF_COMPARE_CAPTURE_CHANNELS; i++) {
mbed_official 15:a81a8d6c1dfe 1183 if (events->generate_event_on_compare_channel[i] == true) {
mbed_official 15:a81a8d6c1dfe 1184 event_mask |= (TC_EVCTRL_MCEO(1) << i);
mbed_official 15:a81a8d6c1dfe 1185 }
mbed_official 15:a81a8d6c1dfe 1186 }
mbed_official 15:a81a8d6c1dfe 1187
mbed_official 15:a81a8d6c1dfe 1188 tc_module->COUNT8.EVCTRL.reg &= ~event_mask;
mbed_official 15:a81a8d6c1dfe 1189 }
mbed_official 15:a81a8d6c1dfe 1190
mbed_official 15:a81a8d6c1dfe 1191 /** @} */
mbed_official 15:a81a8d6c1dfe 1192
mbed_official 15:a81a8d6c1dfe 1193 /**
mbed_official 15:a81a8d6c1dfe 1194 * \name Enable/Disable/Reset
mbed_official 15:a81a8d6c1dfe 1195 * @{
mbed_official 15:a81a8d6c1dfe 1196 */
mbed_official 15:a81a8d6c1dfe 1197
mbed_official 15:a81a8d6c1dfe 1198 enum status_code tc_reset(
mbed_official 15:a81a8d6c1dfe 1199 const struct tc_module *const module_inst);
mbed_official 15:a81a8d6c1dfe 1200
mbed_official 15:a81a8d6c1dfe 1201 /**
mbed_official 15:a81a8d6c1dfe 1202 * \brief Enable the TC module.
mbed_official 15:a81a8d6c1dfe 1203 *
mbed_official 15:a81a8d6c1dfe 1204 * Enables a TC module that has been previously initialized. The counter will
mbed_official 15:a81a8d6c1dfe 1205 * start when the counter is enabled.
mbed_official 15:a81a8d6c1dfe 1206 *
mbed_official 15:a81a8d6c1dfe 1207 * \note When the counter is configured to re-trigger on an event, the counter
mbed_official 15:a81a8d6c1dfe 1208 * will not start until the start function is used.
mbed_official 15:a81a8d6c1dfe 1209 *
mbed_official 15:a81a8d6c1dfe 1210 * \param[in] module_inst Pointer to the software module instance struct
mbed_official 15:a81a8d6c1dfe 1211 */
mbed_official 15:a81a8d6c1dfe 1212 static inline void tc_enable(
mbed_official 15:a81a8d6c1dfe 1213 const struct tc_module *const module_inst)
mbed_official 15:a81a8d6c1dfe 1214 {
mbed_official 15:a81a8d6c1dfe 1215 /* Sanity check arguments */
mbed_official 15:a81a8d6c1dfe 1216 Assert(module_inst);
mbed_official 15:a81a8d6c1dfe 1217 Assert(module_inst->hw);
mbed_official 15:a81a8d6c1dfe 1218
mbed_official 15:a81a8d6c1dfe 1219 /* Get a pointer to the module's hardware instance */
mbed_official 15:a81a8d6c1dfe 1220 TcCount8 *const tc_module = &(module_inst->hw->COUNT8);
mbed_official 15:a81a8d6c1dfe 1221
mbed_official 15:a81a8d6c1dfe 1222 while (tc_is_syncing(module_inst)) {
mbed_official 15:a81a8d6c1dfe 1223 /* Wait for sync */
mbed_official 15:a81a8d6c1dfe 1224 }
mbed_official 15:a81a8d6c1dfe 1225
mbed_official 15:a81a8d6c1dfe 1226 /* Enable TC module */
mbed_official 15:a81a8d6c1dfe 1227 tc_module->CTRLA.reg |= TC_CTRLA_ENABLE;
mbed_official 15:a81a8d6c1dfe 1228 }
mbed_official 15:a81a8d6c1dfe 1229
mbed_official 15:a81a8d6c1dfe 1230 /**
mbed_official 15:a81a8d6c1dfe 1231 * \brief Disables the TC module.
mbed_official 15:a81a8d6c1dfe 1232 *
mbed_official 15:a81a8d6c1dfe 1233 * Disables a TC module and stops the counter.
mbed_official 15:a81a8d6c1dfe 1234 *
mbed_official 15:a81a8d6c1dfe 1235 * \param[in] module_inst Pointer to the software module instance struct
mbed_official 15:a81a8d6c1dfe 1236 */
mbed_official 15:a81a8d6c1dfe 1237 static inline void tc_disable(
mbed_official 15:a81a8d6c1dfe 1238 const struct tc_module *const module_inst)
mbed_official 15:a81a8d6c1dfe 1239 {
mbed_official 15:a81a8d6c1dfe 1240 /* Sanity check arguments */
mbed_official 15:a81a8d6c1dfe 1241 Assert(module_inst);
mbed_official 15:a81a8d6c1dfe 1242 Assert(module_inst->hw);
mbed_official 15:a81a8d6c1dfe 1243
mbed_official 15:a81a8d6c1dfe 1244 /* Get a pointer to the module's hardware instance */
mbed_official 15:a81a8d6c1dfe 1245 TcCount8 *const tc_module = &(module_inst->hw->COUNT8);
mbed_official 15:a81a8d6c1dfe 1246
mbed_official 15:a81a8d6c1dfe 1247 while (tc_is_syncing(module_inst)) {
mbed_official 15:a81a8d6c1dfe 1248 /* Wait for sync */
mbed_official 15:a81a8d6c1dfe 1249 }
mbed_official 15:a81a8d6c1dfe 1250
mbed_official 15:a81a8d6c1dfe 1251 /* Disable TC module */
mbed_official 15:a81a8d6c1dfe 1252 tc_module->CTRLA.reg &= ~TC_CTRLA_ENABLE;
mbed_official 15:a81a8d6c1dfe 1253 }
mbed_official 15:a81a8d6c1dfe 1254
mbed_official 15:a81a8d6c1dfe 1255 /** @} */
mbed_official 15:a81a8d6c1dfe 1256
mbed_official 15:a81a8d6c1dfe 1257 /**
mbed_official 15:a81a8d6c1dfe 1258 * \name Get/Set Count Value
mbed_official 15:a81a8d6c1dfe 1259 * @{
mbed_official 15:a81a8d6c1dfe 1260 */
mbed_official 15:a81a8d6c1dfe 1261
mbed_official 15:a81a8d6c1dfe 1262 uint32_t tc_get_count_value(
mbed_official 15:a81a8d6c1dfe 1263 const struct tc_module *const module_inst);
mbed_official 15:a81a8d6c1dfe 1264
mbed_official 15:a81a8d6c1dfe 1265 enum status_code tc_set_count_value(
mbed_official 15:a81a8d6c1dfe 1266 const struct tc_module *const module_inst,
mbed_official 15:a81a8d6c1dfe 1267 const uint32_t count);
mbed_official 15:a81a8d6c1dfe 1268
mbed_official 15:a81a8d6c1dfe 1269 /** @} */
mbed_official 15:a81a8d6c1dfe 1270
mbed_official 15:a81a8d6c1dfe 1271 /**
mbed_official 15:a81a8d6c1dfe 1272 * \name Start/Stop Counter
mbed_official 15:a81a8d6c1dfe 1273 * @{
mbed_official 15:a81a8d6c1dfe 1274 */
mbed_official 15:a81a8d6c1dfe 1275
mbed_official 15:a81a8d6c1dfe 1276 /**
mbed_official 15:a81a8d6c1dfe 1277 * \brief Stops the counter.
mbed_official 15:a81a8d6c1dfe 1278 *
mbed_official 15:a81a8d6c1dfe 1279 * This function will stop the counter. When the counter is stopped
mbed_official 15:a81a8d6c1dfe 1280 * the value in the count value is set to 0 if the counter was
mbed_official 15:a81a8d6c1dfe 1281 * counting up, or maximum if the counter was counting
mbed_official 15:a81a8d6c1dfe 1282 * down when stopped.
mbed_official 15:a81a8d6c1dfe 1283 *
mbed_official 15:a81a8d6c1dfe 1284 * \param[in] module_inst Pointer to the software module instance struct
mbed_official 15:a81a8d6c1dfe 1285 */
mbed_official 15:a81a8d6c1dfe 1286 static inline void tc_stop_counter(
mbed_official 15:a81a8d6c1dfe 1287 const struct tc_module *const module_inst)
mbed_official 15:a81a8d6c1dfe 1288 {
mbed_official 15:a81a8d6c1dfe 1289 /* Sanity check arguments */
mbed_official 15:a81a8d6c1dfe 1290 Assert(module_inst);
mbed_official 15:a81a8d6c1dfe 1291 Assert(module_inst->hw);
mbed_official 15:a81a8d6c1dfe 1292
mbed_official 15:a81a8d6c1dfe 1293 /* Get a pointer to the module's hardware instance */
mbed_official 15:a81a8d6c1dfe 1294 TcCount8 *const tc_module = &(module_inst->hw->COUNT8);
mbed_official 15:a81a8d6c1dfe 1295
mbed_official 15:a81a8d6c1dfe 1296 while (tc_is_syncing(module_inst)) {
mbed_official 15:a81a8d6c1dfe 1297 /* Wait for sync */
mbed_official 15:a81a8d6c1dfe 1298 }
mbed_official 15:a81a8d6c1dfe 1299
mbed_official 15:a81a8d6c1dfe 1300 /* Write command to execute */
mbed_official 15:a81a8d6c1dfe 1301 tc_module->CTRLBSET.reg = TC_CTRLBSET_CMD(TC_CTRLBSET_CMD_STOP_Val);
mbed_official 15:a81a8d6c1dfe 1302 }
mbed_official 15:a81a8d6c1dfe 1303
mbed_official 15:a81a8d6c1dfe 1304 /**
mbed_official 15:a81a8d6c1dfe 1305 * \brief Starts the counter.
mbed_official 15:a81a8d6c1dfe 1306 *
mbed_official 15:a81a8d6c1dfe 1307 * Starts or restarts an initialized TC module's counter.
mbed_official 15:a81a8d6c1dfe 1308 *
mbed_official 15:a81a8d6c1dfe 1309 * \param[in] module_inst Pointer to the software module instance struct
mbed_official 15:a81a8d6c1dfe 1310 */
mbed_official 15:a81a8d6c1dfe 1311 static inline void tc_start_counter(
mbed_official 15:a81a8d6c1dfe 1312 const struct tc_module *const module_inst)
mbed_official 15:a81a8d6c1dfe 1313 {
mbed_official 15:a81a8d6c1dfe 1314 /* Sanity check arguments */
mbed_official 15:a81a8d6c1dfe 1315 Assert(module_inst);
mbed_official 15:a81a8d6c1dfe 1316 Assert(module_inst->hw);
mbed_official 15:a81a8d6c1dfe 1317
mbed_official 15:a81a8d6c1dfe 1318 /* Get a pointer to the module's hardware instance */
mbed_official 15:a81a8d6c1dfe 1319 TcCount8 *const tc_module = &(module_inst->hw->COUNT8);
mbed_official 15:a81a8d6c1dfe 1320
mbed_official 15:a81a8d6c1dfe 1321 while (tc_is_syncing(module_inst)) {
mbed_official 15:a81a8d6c1dfe 1322 /* Wait for sync */
mbed_official 15:a81a8d6c1dfe 1323 }
mbed_official 15:a81a8d6c1dfe 1324
mbed_official 15:a81a8d6c1dfe 1325 /* Make certain that there are no conflicting commands in the register */
mbed_official 15:a81a8d6c1dfe 1326 tc_module->CTRLBCLR.reg = TC_CTRLBCLR_CMD_NONE;
mbed_official 15:a81a8d6c1dfe 1327
mbed_official 15:a81a8d6c1dfe 1328 while (tc_is_syncing(module_inst)) {
mbed_official 15:a81a8d6c1dfe 1329 /* Wait for sync */
mbed_official 15:a81a8d6c1dfe 1330 }
mbed_official 15:a81a8d6c1dfe 1331
mbed_official 15:a81a8d6c1dfe 1332 /* Write command to execute */
mbed_official 15:a81a8d6c1dfe 1333 tc_module->CTRLBSET.reg = TC_CTRLBSET_CMD(TC_CTRLBSET_CMD_RETRIGGER_Val);
mbed_official 15:a81a8d6c1dfe 1334 }
mbed_official 15:a81a8d6c1dfe 1335
mbed_official 15:a81a8d6c1dfe 1336 /** @} */
mbed_official 15:a81a8d6c1dfe 1337
mbed_official 15:a81a8d6c1dfe 1338 #ifdef FEATURE_TC_DOUBLE_BUFFERED
mbed_official 15:a81a8d6c1dfe 1339 /**
mbed_official 15:a81a8d6c1dfe 1340 * \name Double Buffering
mbed_official 15:a81a8d6c1dfe 1341 * @{
mbed_official 15:a81a8d6c1dfe 1342 */
mbed_official 15:a81a8d6c1dfe 1343
mbed_official 15:a81a8d6c1dfe 1344 /**
mbed_official 15:a81a8d6c1dfe 1345 * \brief Update double buffer.
mbed_official 15:a81a8d6c1dfe 1346 *
mbed_official 15:a81a8d6c1dfe 1347 * Update double buffer.
mbed_official 15:a81a8d6c1dfe 1348 *
mbed_official 15:a81a8d6c1dfe 1349 * \param[in] module_inst Pointer to the software module instance struct
mbed_official 15:a81a8d6c1dfe 1350 */
mbed_official 15:a81a8d6c1dfe 1351 static inline void tc_update_double_buffer(
mbed_official 15:a81a8d6c1dfe 1352 const struct tc_module *const module_inst)
mbed_official 15:a81a8d6c1dfe 1353 {
mbed_official 15:a81a8d6c1dfe 1354 /* Sanity check arguments */
mbed_official 15:a81a8d6c1dfe 1355 Assert(module_inst);
mbed_official 15:a81a8d6c1dfe 1356 Assert(module_inst->hw);
mbed_official 15:a81a8d6c1dfe 1357
mbed_official 15:a81a8d6c1dfe 1358 /* Get a pointer to the module's hardware instance */
mbed_official 15:a81a8d6c1dfe 1359 TcCount8 *const tc_module = &(module_inst->hw->COUNT8);
mbed_official 15:a81a8d6c1dfe 1360
mbed_official 15:a81a8d6c1dfe 1361 while (tc_is_syncing(module_inst)) {
mbed_official 15:a81a8d6c1dfe 1362 /* Wait for sync */
mbed_official 15:a81a8d6c1dfe 1363 }
mbed_official 15:a81a8d6c1dfe 1364
mbed_official 15:a81a8d6c1dfe 1365 /* Make certain that there are no conflicting commands in the register */
mbed_official 15:a81a8d6c1dfe 1366 tc_module->CTRLBCLR.reg = TC_CTRLBCLR_CMD_NONE;
mbed_official 15:a81a8d6c1dfe 1367
mbed_official 15:a81a8d6c1dfe 1368 while (tc_is_syncing(module_inst)) {
mbed_official 15:a81a8d6c1dfe 1369 /* Wait for sync */
mbed_official 15:a81a8d6c1dfe 1370 }
mbed_official 15:a81a8d6c1dfe 1371
mbed_official 15:a81a8d6c1dfe 1372 /* Write command to execute */
mbed_official 15:a81a8d6c1dfe 1373 tc_module->CTRLBSET.reg = TC_CTRLBSET_CMD(TC_CTRLBSET_CMD_UPDATE_Val);
mbed_official 15:a81a8d6c1dfe 1374 }
mbed_official 15:a81a8d6c1dfe 1375 /** @} */
mbed_official 15:a81a8d6c1dfe 1376 #endif
mbed_official 15:a81a8d6c1dfe 1377
mbed_official 15:a81a8d6c1dfe 1378 #ifdef FEATURE_TC_READ_SYNC
mbed_official 15:a81a8d6c1dfe 1379 /**
mbed_official 15:a81a8d6c1dfe 1380 * \name Count Read Synchronization
mbed_official 15:a81a8d6c1dfe 1381 * @{
mbed_official 15:a81a8d6c1dfe 1382 */
mbed_official 15:a81a8d6c1dfe 1383
mbed_official 15:a81a8d6c1dfe 1384 /**
mbed_official 15:a81a8d6c1dfe 1385 * \brief Read synchronization of COUNT.
mbed_official 15:a81a8d6c1dfe 1386 *
mbed_official 15:a81a8d6c1dfe 1387 * Read synchronization of COUNT.
mbed_official 15:a81a8d6c1dfe 1388 *
mbed_official 15:a81a8d6c1dfe 1389 * \param[in] module_inst Pointer to the software module instance struct
mbed_official 15:a81a8d6c1dfe 1390 */
mbed_official 15:a81a8d6c1dfe 1391 static inline void tc_sync_read_count(
mbed_official 15:a81a8d6c1dfe 1392 const struct tc_module *const module_inst)
mbed_official 15:a81a8d6c1dfe 1393 {
mbed_official 15:a81a8d6c1dfe 1394 /* Sanity check arguments */
mbed_official 15:a81a8d6c1dfe 1395 Assert(module_inst);
mbed_official 15:a81a8d6c1dfe 1396 Assert(module_inst->hw);
mbed_official 15:a81a8d6c1dfe 1397
mbed_official 15:a81a8d6c1dfe 1398 /* Get a pointer to the module's hardware instance */
mbed_official 15:a81a8d6c1dfe 1399 TcCount8 *const tc_module = &(module_inst->hw->COUNT8);
mbed_official 15:a81a8d6c1dfe 1400
mbed_official 15:a81a8d6c1dfe 1401 while (tc_is_syncing(module_inst)) {
mbed_official 15:a81a8d6c1dfe 1402 /* Wait for sync */
mbed_official 15:a81a8d6c1dfe 1403 }
mbed_official 15:a81a8d6c1dfe 1404
mbed_official 15:a81a8d6c1dfe 1405 /* Make certain that there are no conflicting commands in the register */
mbed_official 15:a81a8d6c1dfe 1406 tc_module->CTRLBCLR.reg = TC_CTRLBCLR_CMD_NONE;
mbed_official 15:a81a8d6c1dfe 1407
mbed_official 15:a81a8d6c1dfe 1408 while (tc_is_syncing(module_inst)) {
mbed_official 15:a81a8d6c1dfe 1409 /* Wait for sync */
mbed_official 15:a81a8d6c1dfe 1410 }
mbed_official 15:a81a8d6c1dfe 1411
mbed_official 15:a81a8d6c1dfe 1412 /* Write command to execute */
mbed_official 15:a81a8d6c1dfe 1413 tc_module->CTRLBSET.reg = TC_CTRLBSET_CMD(TC_CTRLBSET_CMD_READSYNC_Val);
mbed_official 15:a81a8d6c1dfe 1414 }
mbed_official 15:a81a8d6c1dfe 1415 /** @} */
mbed_official 15:a81a8d6c1dfe 1416 #endif
mbed_official 15:a81a8d6c1dfe 1417
mbed_official 15:a81a8d6c1dfe 1418 #ifdef FEATURE_TC_GENERATE_DMA_TRIGGER
mbed_official 15:a81a8d6c1dfe 1419 /**
mbed_official 15:a81a8d6c1dfe 1420 * \name Generate TC DMA Triggers command
mbed_official 15:a81a8d6c1dfe 1421 * @{
mbed_official 15:a81a8d6c1dfe 1422 */
mbed_official 15:a81a8d6c1dfe 1423
mbed_official 15:a81a8d6c1dfe 1424 /**
mbed_official 15:a81a8d6c1dfe 1425 * \brief TC DMA Trigger.
mbed_official 15:a81a8d6c1dfe 1426 *
mbed_official 15:a81a8d6c1dfe 1427 * TC DMA trigger command.
mbed_official 15:a81a8d6c1dfe 1428 *
mbed_official 15:a81a8d6c1dfe 1429 * \param[in] module_inst Pointer to the software module instance struct
mbed_official 15:a81a8d6c1dfe 1430 */
mbed_official 15:a81a8d6c1dfe 1431 static inline void tc_dma_trigger_command(
mbed_official 15:a81a8d6c1dfe 1432 const struct tc_module *const module_inst)
mbed_official 15:a81a8d6c1dfe 1433 {
mbed_official 15:a81a8d6c1dfe 1434 /* Sanity check arguments */
mbed_official 15:a81a8d6c1dfe 1435 Assert(module_inst);
mbed_official 15:a81a8d6c1dfe 1436 Assert(module_inst->hw);
mbed_official 15:a81a8d6c1dfe 1437
mbed_official 15:a81a8d6c1dfe 1438 /* Get a pointer to the module's hardware instance */
mbed_official 15:a81a8d6c1dfe 1439 TcCount8 *const tc_module = &(module_inst->hw->COUNT8);
mbed_official 15:a81a8d6c1dfe 1440
mbed_official 15:a81a8d6c1dfe 1441 while (tc_is_syncing(module_inst)) {
mbed_official 15:a81a8d6c1dfe 1442 /* Wait for sync */
mbed_official 15:a81a8d6c1dfe 1443 }
mbed_official 15:a81a8d6c1dfe 1444
mbed_official 15:a81a8d6c1dfe 1445 /* Make certain that there are no conflicting commands in the register */
mbed_official 15:a81a8d6c1dfe 1446 tc_module->CTRLBCLR.reg = TC_CTRLBCLR_CMD_NONE;
mbed_official 15:a81a8d6c1dfe 1447
mbed_official 15:a81a8d6c1dfe 1448 while (tc_is_syncing(module_inst)) {
mbed_official 15:a81a8d6c1dfe 1449 /* Wait for sync */
mbed_official 15:a81a8d6c1dfe 1450 }
mbed_official 15:a81a8d6c1dfe 1451
mbed_official 15:a81a8d6c1dfe 1452 #if SAML21
mbed_official 15:a81a8d6c1dfe 1453 /* Write command to execute */
mbed_official 15:a81a8d6c1dfe 1454 tc_module->CTRLBSET.reg = TC_CTRLBSET_CMD(TC_CTRLBSET_CMD_DMATRG_Val);
mbed_official 15:a81a8d6c1dfe 1455 #endif
mbed_official 15:a81a8d6c1dfe 1456 #if (SAMC20) || (SAMC21)
mbed_official 15:a81a8d6c1dfe 1457 /* Write command to execute */
mbed_official 15:a81a8d6c1dfe 1458 tc_module->CTRLBSET.reg = TC_CTRLBSET_CMD(TC_CTRLBSET_CMD_DMAOS_Val);
mbed_official 15:a81a8d6c1dfe 1459 #endif
mbed_official 15:a81a8d6c1dfe 1460 }
mbed_official 15:a81a8d6c1dfe 1461 /** @} */
mbed_official 15:a81a8d6c1dfe 1462 #endif
mbed_official 15:a81a8d6c1dfe 1463
mbed_official 15:a81a8d6c1dfe 1464 /**
mbed_official 15:a81a8d6c1dfe 1465 * \name Get Capture Set Compare
mbed_official 15:a81a8d6c1dfe 1466 * @{
mbed_official 15:a81a8d6c1dfe 1467 */
mbed_official 15:a81a8d6c1dfe 1468
mbed_official 15:a81a8d6c1dfe 1469 uint32_t tc_get_capture_value(
mbed_official 15:a81a8d6c1dfe 1470 const struct tc_module *const module_inst,
mbed_official 15:a81a8d6c1dfe 1471 const enum tc_compare_capture_channel channel_index);
mbed_official 15:a81a8d6c1dfe 1472
mbed_official 15:a81a8d6c1dfe 1473 enum status_code tc_set_compare_value(
mbed_official 15:a81a8d6c1dfe 1474 const struct tc_module *const module_inst,
mbed_official 15:a81a8d6c1dfe 1475 const enum tc_compare_capture_channel channel_index,
mbed_official 15:a81a8d6c1dfe 1476 const uint32_t compare_value);
mbed_official 15:a81a8d6c1dfe 1477
mbed_official 15:a81a8d6c1dfe 1478 /** @} */
mbed_official 15:a81a8d6c1dfe 1479
mbed_official 15:a81a8d6c1dfe 1480 /**
mbed_official 15:a81a8d6c1dfe 1481 * \name Set Top Value
mbed_official 15:a81a8d6c1dfe 1482 * @{
mbed_official 15:a81a8d6c1dfe 1483 */
mbed_official 15:a81a8d6c1dfe 1484
mbed_official 15:a81a8d6c1dfe 1485 enum status_code tc_set_top_value(
mbed_official 15:a81a8d6c1dfe 1486 const struct tc_module *const module_inst,
mbed_official 15:a81a8d6c1dfe 1487 const uint32_t top_value);
mbed_official 15:a81a8d6c1dfe 1488
mbed_official 15:a81a8d6c1dfe 1489 /** @} */
mbed_official 15:a81a8d6c1dfe 1490
mbed_official 15:a81a8d6c1dfe 1491 /**
mbed_official 15:a81a8d6c1dfe 1492 * \name Status Management
mbed_official 15:a81a8d6c1dfe 1493 * @{
mbed_official 15:a81a8d6c1dfe 1494 */
mbed_official 15:a81a8d6c1dfe 1495
mbed_official 15:a81a8d6c1dfe 1496 /**
mbed_official 15:a81a8d6c1dfe 1497 * \brief Retrieves the current module status.
mbed_official 15:a81a8d6c1dfe 1498 *
mbed_official 15:a81a8d6c1dfe 1499 * Retrieves the status of the module, giving overall state information.
mbed_official 15:a81a8d6c1dfe 1500 *
mbed_official 15:a81a8d6c1dfe 1501 * \param[in] module_inst Pointer to the TC software instance struct
mbed_official 15:a81a8d6c1dfe 1502 *
mbed_official 15:a81a8d6c1dfe 1503 * \return Bitmask of \c TC_STATUS_* flags.
mbed_official 15:a81a8d6c1dfe 1504 *
mbed_official 15:a81a8d6c1dfe 1505 * \retval TC_STATUS_CHANNEL_0_MATCH Timer channel 0 compare/capture match
mbed_official 15:a81a8d6c1dfe 1506 * \retval TC_STATUS_CHANNEL_1_MATCH Timer channel 1 compare/capture match
mbed_official 15:a81a8d6c1dfe 1507 * \retval TC_STATUS_SYNC_READY Timer read synchronization has completed
mbed_official 15:a81a8d6c1dfe 1508 * \retval TC_STATUS_CAPTURE_OVERFLOW Timer capture data has overflowed
mbed_official 15:a81a8d6c1dfe 1509 * \retval TC_STATUS_COUNT_OVERFLOW Timer count value has overflowed
mbed_official 15:a81a8d6c1dfe 1510 * \retval TC_STATUS_CHN0_BUFFER_VALID Timer count channel 0 compare/capture buffer valid
mbed_official 15:a81a8d6c1dfe 1511 * \retval TC_STATUS_CHN1_BUFFER_VALID Timer count channel 1 compare/capture buffer valid
mbed_official 15:a81a8d6c1dfe 1512 * \retval TC_STATUS_PERIOD_BUFFER_VALID Timer count period buffer valid
mbed_official 15:a81a8d6c1dfe 1513 */
mbed_official 15:a81a8d6c1dfe 1514 static inline uint32_t tc_get_status(
mbed_official 15:a81a8d6c1dfe 1515 struct tc_module *const module_inst)
mbed_official 15:a81a8d6c1dfe 1516 {
mbed_official 15:a81a8d6c1dfe 1517 /* Sanity check arguments */
mbed_official 15:a81a8d6c1dfe 1518 Assert(module_inst);
mbed_official 15:a81a8d6c1dfe 1519 Assert(module_inst->hw);
mbed_official 15:a81a8d6c1dfe 1520
mbed_official 15:a81a8d6c1dfe 1521 /* Get a pointer to the module's hardware instance */
mbed_official 15:a81a8d6c1dfe 1522 TcCount8 *const tc_module = &(module_inst->hw->COUNT8);
mbed_official 15:a81a8d6c1dfe 1523
mbed_official 15:a81a8d6c1dfe 1524 uint32_t int_flags = tc_module->INTFLAG.reg;
mbed_official 15:a81a8d6c1dfe 1525
mbed_official 15:a81a8d6c1dfe 1526 uint32_t status_flags = 0;
mbed_official 15:a81a8d6c1dfe 1527
mbed_official 15:a81a8d6c1dfe 1528 /* Check for TC channel 0 match */
mbed_official 15:a81a8d6c1dfe 1529 if (int_flags & TC_INTFLAG_MC(1)) {
mbed_official 15:a81a8d6c1dfe 1530 status_flags |= TC_STATUS_CHANNEL_0_MATCH;
mbed_official 15:a81a8d6c1dfe 1531 }
mbed_official 15:a81a8d6c1dfe 1532
mbed_official 15:a81a8d6c1dfe 1533 /* Check for TC channel 1 match */
mbed_official 15:a81a8d6c1dfe 1534 if (int_flags & TC_INTFLAG_MC(2)) {
mbed_official 15:a81a8d6c1dfe 1535 status_flags |= TC_STATUS_CHANNEL_1_MATCH;
mbed_official 15:a81a8d6c1dfe 1536 }
mbed_official 15:a81a8d6c1dfe 1537
mbed_official 15:a81a8d6c1dfe 1538 #if !defined(FEATURE_TC_SYNCBUSY_SCHEME_VERSION_2)
mbed_official 15:a81a8d6c1dfe 1539 /* Check for TC read synchronization ready */
mbed_official 15:a81a8d6c1dfe 1540 if (int_flags & TC_INTFLAG_SYNCRDY) {
mbed_official 15:a81a8d6c1dfe 1541 status_flags |= TC_STATUS_SYNC_READY;
mbed_official 15:a81a8d6c1dfe 1542 }
mbed_official 15:a81a8d6c1dfe 1543 #endif
mbed_official 15:a81a8d6c1dfe 1544
mbed_official 15:a81a8d6c1dfe 1545 /* Check for TC capture overflow */
mbed_official 15:a81a8d6c1dfe 1546 if (int_flags & TC_INTFLAG_ERR) {
mbed_official 15:a81a8d6c1dfe 1547 status_flags |= TC_STATUS_CAPTURE_OVERFLOW;
mbed_official 15:a81a8d6c1dfe 1548 }
mbed_official 15:a81a8d6c1dfe 1549
mbed_official 15:a81a8d6c1dfe 1550 /* Check for TC count overflow */
mbed_official 15:a81a8d6c1dfe 1551 if (int_flags & TC_INTFLAG_OVF) {
mbed_official 15:a81a8d6c1dfe 1552 status_flags |= TC_STATUS_COUNT_OVERFLOW;
mbed_official 15:a81a8d6c1dfe 1553 }
mbed_official 15:a81a8d6c1dfe 1554 #ifdef FEATURE_TC_DOUBLE_BUFFERED
mbed_official 15:a81a8d6c1dfe 1555 uint8_t double_buffer_valid_status = tc_module->STATUS.reg;
mbed_official 15:a81a8d6c1dfe 1556
mbed_official 15:a81a8d6c1dfe 1557 /* Check channel 0 compare or capture buffer valid */
mbed_official 15:a81a8d6c1dfe 1558 if (double_buffer_valid_status & TC_STATUS_CCBUFV0) {
mbed_official 15:a81a8d6c1dfe 1559 status_flags |= TC_STATUS_CHN0_BUFFER_VALID;
mbed_official 15:a81a8d6c1dfe 1560 }
mbed_official 15:a81a8d6c1dfe 1561 /* Check channel 0 compare or capture buffer valid */
mbed_official 15:a81a8d6c1dfe 1562 if (double_buffer_valid_status & TC_STATUS_CCBUFV1) {
mbed_official 15:a81a8d6c1dfe 1563 status_flags |= TC_STATUS_CHN1_BUFFER_VALID;
mbed_official 15:a81a8d6c1dfe 1564 }
mbed_official 15:a81a8d6c1dfe 1565 /* Check period buffer valid */
mbed_official 15:a81a8d6c1dfe 1566 if (double_buffer_valid_status & TC_STATUS_PERBUFV) {
mbed_official 15:a81a8d6c1dfe 1567 status_flags |= TC_STATUS_PERIOD_BUFFER_VALID;
mbed_official 15:a81a8d6c1dfe 1568 }
mbed_official 15:a81a8d6c1dfe 1569 #endif
mbed_official 15:a81a8d6c1dfe 1570
mbed_official 15:a81a8d6c1dfe 1571 return status_flags;
mbed_official 15:a81a8d6c1dfe 1572 }
mbed_official 15:a81a8d6c1dfe 1573
mbed_official 15:a81a8d6c1dfe 1574 /**
mbed_official 15:a81a8d6c1dfe 1575 * \brief Clears a module status flag.
mbed_official 15:a81a8d6c1dfe 1576 *
mbed_official 15:a81a8d6c1dfe 1577 * Clears the given status flag of the module.
mbed_official 15:a81a8d6c1dfe 1578 *
mbed_official 15:a81a8d6c1dfe 1579 * \param[in] module_inst Pointer to the TC software instance struct
mbed_official 15:a81a8d6c1dfe 1580 * \param[in] status_flags Bitmask of \c TC_STATUS_* flags to clear
mbed_official 15:a81a8d6c1dfe 1581 */
mbed_official 15:a81a8d6c1dfe 1582 static inline void tc_clear_status(
mbed_official 15:a81a8d6c1dfe 1583 struct tc_module *const module_inst,
mbed_official 15:a81a8d6c1dfe 1584 const uint32_t status_flags)
mbed_official 15:a81a8d6c1dfe 1585 {
mbed_official 15:a81a8d6c1dfe 1586 /* Sanity check arguments */
mbed_official 15:a81a8d6c1dfe 1587 Assert(module_inst);
mbed_official 15:a81a8d6c1dfe 1588 Assert(module_inst->hw);
mbed_official 15:a81a8d6c1dfe 1589
mbed_official 15:a81a8d6c1dfe 1590 /* Get a pointer to the module's hardware instance */
mbed_official 15:a81a8d6c1dfe 1591 TcCount8 *const tc_module = &(module_inst->hw->COUNT8);
mbed_official 15:a81a8d6c1dfe 1592
mbed_official 15:a81a8d6c1dfe 1593 uint32_t int_flags = 0;
mbed_official 15:a81a8d6c1dfe 1594
mbed_official 15:a81a8d6c1dfe 1595 /* Check for TC channel 0 match */
mbed_official 15:a81a8d6c1dfe 1596 if (status_flags & TC_STATUS_CHANNEL_0_MATCH) {
mbed_official 15:a81a8d6c1dfe 1597 int_flags |= TC_INTFLAG_MC(1);
mbed_official 15:a81a8d6c1dfe 1598 }
mbed_official 15:a81a8d6c1dfe 1599
mbed_official 15:a81a8d6c1dfe 1600 /* Check for TC channel 1 match */
mbed_official 15:a81a8d6c1dfe 1601 if (status_flags & TC_STATUS_CHANNEL_1_MATCH) {
mbed_official 15:a81a8d6c1dfe 1602 int_flags |= TC_INTFLAG_MC(2);
mbed_official 15:a81a8d6c1dfe 1603 }
mbed_official 15:a81a8d6c1dfe 1604
mbed_official 15:a81a8d6c1dfe 1605 #if !defined(FEATURE_TC_SYNCBUSY_SCHEME_VERSION_2)
mbed_official 15:a81a8d6c1dfe 1606 /* Check for TC read synchronization ready */
mbed_official 15:a81a8d6c1dfe 1607 if (status_flags & TC_STATUS_SYNC_READY) {
mbed_official 15:a81a8d6c1dfe 1608 int_flags |= TC_INTFLAG_SYNCRDY;
mbed_official 15:a81a8d6c1dfe 1609 }
mbed_official 15:a81a8d6c1dfe 1610 #endif
mbed_official 15:a81a8d6c1dfe 1611
mbed_official 15:a81a8d6c1dfe 1612 /* Check for TC capture overflow */
mbed_official 15:a81a8d6c1dfe 1613 if (status_flags & TC_STATUS_CAPTURE_OVERFLOW) {
mbed_official 15:a81a8d6c1dfe 1614 int_flags |= TC_INTFLAG_ERR;
mbed_official 15:a81a8d6c1dfe 1615 }
mbed_official 15:a81a8d6c1dfe 1616
mbed_official 15:a81a8d6c1dfe 1617 /* Check for TC count overflow */
mbed_official 15:a81a8d6c1dfe 1618 if (status_flags & TC_STATUS_COUNT_OVERFLOW) {
mbed_official 15:a81a8d6c1dfe 1619 int_flags |= TC_INTFLAG_OVF;
mbed_official 15:a81a8d6c1dfe 1620 }
mbed_official 15:a81a8d6c1dfe 1621
mbed_official 15:a81a8d6c1dfe 1622 /* Clear interrupt flag */
mbed_official 15:a81a8d6c1dfe 1623 tc_module->INTFLAG.reg = int_flags;
mbed_official 15:a81a8d6c1dfe 1624 }
mbed_official 15:a81a8d6c1dfe 1625
mbed_official 15:a81a8d6c1dfe 1626 /** @} */
mbed_official 15:a81a8d6c1dfe 1627
mbed_official 15:a81a8d6c1dfe 1628 /** @} */
mbed_official 15:a81a8d6c1dfe 1629
mbed_official 15:a81a8d6c1dfe 1630 #ifdef __cplusplus
mbed_official 15:a81a8d6c1dfe 1631 }
mbed_official 15:a81a8d6c1dfe 1632 #endif
mbed_official 15:a81a8d6c1dfe 1633
mbed_official 15:a81a8d6c1dfe 1634 /**
mbed_official 15:a81a8d6c1dfe 1635 * \page asfdoc_sam0_tc_extra Extra Information for TC Driver
mbed_official 15:a81a8d6c1dfe 1636 *
mbed_official 15:a81a8d6c1dfe 1637 * \section asfdoc_sam0_tc_extra_acronyms Acronyms
mbed_official 15:a81a8d6c1dfe 1638 * The table below presents the acronyms used in this module:
mbed_official 15:a81a8d6c1dfe 1639 *
mbed_official 15:a81a8d6c1dfe 1640 * <table>
mbed_official 15:a81a8d6c1dfe 1641 * <tr>
mbed_official 15:a81a8d6c1dfe 1642 * <th>Acronym</th>
mbed_official 15:a81a8d6c1dfe 1643 * <th>Description</th>
mbed_official 15:a81a8d6c1dfe 1644 * </tr>
mbed_official 15:a81a8d6c1dfe 1645 * <tr>
mbed_official 15:a81a8d6c1dfe 1646 * <td>DMA</td>
mbed_official 15:a81a8d6c1dfe 1647 * <td>Direct Memory Access</td>
mbed_official 15:a81a8d6c1dfe 1648 * </tr>
mbed_official 15:a81a8d6c1dfe 1649 * <tr>
mbed_official 15:a81a8d6c1dfe 1650 * <td>TC</td>
mbed_official 15:a81a8d6c1dfe 1651 * <td>Timer Counter</td>
mbed_official 15:a81a8d6c1dfe 1652 * </tr>
mbed_official 15:a81a8d6c1dfe 1653 * <tr>
mbed_official 15:a81a8d6c1dfe 1654 * <td>PWM</td>
mbed_official 15:a81a8d6c1dfe 1655 * <td>Pulse Width Modulation</td>
mbed_official 15:a81a8d6c1dfe 1656 * </tr>
mbed_official 15:a81a8d6c1dfe 1657 * <tr>
mbed_official 15:a81a8d6c1dfe 1658 * <td>PWP</td>
mbed_official 15:a81a8d6c1dfe 1659 * <td>Pulse Width Period</td>
mbed_official 15:a81a8d6c1dfe 1660 * </tr>
mbed_official 15:a81a8d6c1dfe 1661 * <tr>
mbed_official 15:a81a8d6c1dfe 1662 * <td>PPW</td>
mbed_official 15:a81a8d6c1dfe 1663 * <td>Period Pulse Width</td>
mbed_official 15:a81a8d6c1dfe 1664 * </tr>
mbed_official 15:a81a8d6c1dfe 1665 * </table>
mbed_official 15:a81a8d6c1dfe 1666 *
mbed_official 15:a81a8d6c1dfe 1667 *
mbed_official 15:a81a8d6c1dfe 1668 * \section asfdoc_sam0_tc_extra_dependencies Dependencies
mbed_official 15:a81a8d6c1dfe 1669 * This driver has the following dependencies:
mbed_official 15:a81a8d6c1dfe 1670 *
mbed_official 15:a81a8d6c1dfe 1671 * - \ref asfdoc_sam0_system_pinmux_group "System Pin Multiplexer Driver"
mbed_official 15:a81a8d6c1dfe 1672 *
mbed_official 15:a81a8d6c1dfe 1673 *
mbed_official 15:a81a8d6c1dfe 1674 * \section asfdoc_sam0_tc_extra_errata Errata
mbed_official 15:a81a8d6c1dfe 1675 * There are no errata related to this driver.
mbed_official 15:a81a8d6c1dfe 1676 *
mbed_official 15:a81a8d6c1dfe 1677 *
mbed_official 15:a81a8d6c1dfe 1678 * \section asfdoc_sam0_tc_extra_history Module History
mbed_official 15:a81a8d6c1dfe 1679 * An overview of the module history is presented in the table below, with
mbed_official 15:a81a8d6c1dfe 1680 * details on the enhancements and fixes made to the module since its first
mbed_official 15:a81a8d6c1dfe 1681 * release. The current version of this corresponds to the newest version in
mbed_official 15:a81a8d6c1dfe 1682 * the table.
mbed_official 15:a81a8d6c1dfe 1683 *
mbed_official 15:a81a8d6c1dfe 1684 * <table>
mbed_official 15:a81a8d6c1dfe 1685 * <tr>
mbed_official 15:a81a8d6c1dfe 1686 * <th>Changelog</th>
mbed_official 15:a81a8d6c1dfe 1687 * </tr>
mbed_official 15:a81a8d6c1dfe 1688 * <tr>
mbed_official 15:a81a8d6c1dfe 1689 * <td>Added support for SAMD21 and do some modifications as below:
mbed_official 15:a81a8d6c1dfe 1690 * \li Clean up in the configuration structure, the counter size
mbed_official 15:a81a8d6c1dfe 1691 * setting specific registers is accessed through the counter_8_bit,
mbed_official 15:a81a8d6c1dfe 1692 * counter_16_bit and counter_32_bit structures
mbed_official 15:a81a8d6c1dfe 1693 * \li All event related settings moved into the tc_event structure </td>
mbed_official 15:a81a8d6c1dfe 1694 * </tr>
mbed_official 15:a81a8d6c1dfe 1695 * <tr>
mbed_official 15:a81a8d6c1dfe 1696 * <td>Added automatic digital clock interface enable for the slave TC
mbed_official 15:a81a8d6c1dfe 1697 * module when a timer is initialized in 32-bit mode</td>
mbed_official 15:a81a8d6c1dfe 1698 * </tr>
mbed_official 15:a81a8d6c1dfe 1699 * <tr>
mbed_official 15:a81a8d6c1dfe 1700 * <td>Initial Release</td>
mbed_official 15:a81a8d6c1dfe 1701 * </tr>
mbed_official 15:a81a8d6c1dfe 1702 * </table>
mbed_official 15:a81a8d6c1dfe 1703 */
mbed_official 15:a81a8d6c1dfe 1704
mbed_official 15:a81a8d6c1dfe 1705 /**
mbed_official 15:a81a8d6c1dfe 1706 * \page asfdoc_sam0_tc_exqsg Examples for TC Driver
mbed_official 15:a81a8d6c1dfe 1707 *
mbed_official 15:a81a8d6c1dfe 1708 * This is a list of the available Quick Start guides (QSGs) and example
mbed_official 15:a81a8d6c1dfe 1709 * applications for \ref asfdoc_sam0_tc_group. QSGs are simple examples with
mbed_official 15:a81a8d6c1dfe 1710 * step-by-step instructions to configure and use this driver in a selection of
mbed_official 15:a81a8d6c1dfe 1711 * use cases. Note that QSGs can be compiled as a standalone application or be
mbed_official 15:a81a8d6c1dfe 1712 * added to the user application.
mbed_official 15:a81a8d6c1dfe 1713 *
mbed_official 15:a81a8d6c1dfe 1714 * - \subpage asfdoc_sam0_tc_basic_use_case
mbed_official 15:a81a8d6c1dfe 1715 * - \subpage asfdoc_sam0_tc_macth_freq_use_case
mbed_official 15:a81a8d6c1dfe 1716 * \if TC_CALLBACK_MODE
mbed_official 15:a81a8d6c1dfe 1717 * - \subpage asfdoc_sam0_tc_timer_use_case
mbed_official 15:a81a8d6c1dfe 1718 * - \subpage asfdoc_sam0_tc_callback_use_case
mbed_official 15:a81a8d6c1dfe 1719 * \endif
mbed_official 15:a81a8d6c1dfe 1720 * - \subpage asfdoc_sam0_tc_dma_use_case
mbed_official 15:a81a8d6c1dfe 1721 *
mbed_official 15:a81a8d6c1dfe 1722 * \page asfdoc_sam0_tc_document_revision_history Document Revision History
mbed_official 15:a81a8d6c1dfe 1723 *
mbed_official 15:a81a8d6c1dfe 1724 * <table>
mbed_official 15:a81a8d6c1dfe 1725 * <tr>
mbed_official 15:a81a8d6c1dfe 1726 * <th>Doc. Rev.</td>
mbed_official 15:a81a8d6c1dfe 1727 * <th>Date</td>
mbed_official 15:a81a8d6c1dfe 1728 * <th>Comments</td>
mbed_official 15:a81a8d6c1dfe 1729 * </tr>
mbed_official 15:a81a8d6c1dfe 1730 * <tr>
mbed_official 15:a81a8d6c1dfe 1731 * <td>F</td>
mbed_official 15:a81a8d6c1dfe 1732 * <td>12/2014</td>
mbed_official 15:a81a8d6c1dfe 1733 * <td>Added support for SAMC21.</td>
mbed_official 15:a81a8d6c1dfe 1734 * </tr>
mbed_official 15:a81a8d6c1dfe 1735 * <tr>
mbed_official 15:a81a8d6c1dfe 1736 * <td>E</td>
mbed_official 15:a81a8d6c1dfe 1737 * <td>04/2015</td>
mbed_official 15:a81a8d6c1dfe 1738 * <td>Added support for SAML21 and SAMDAx.</td>
mbed_official 15:a81a8d6c1dfe 1739 * </tr>
mbed_official 15:a81a8d6c1dfe 1740 * <tr>
mbed_official 15:a81a8d6c1dfe 1741 * <td>D</td>
mbed_official 15:a81a8d6c1dfe 1742 * <td>12/2014</td>
mbed_official 15:a81a8d6c1dfe 1743 * <td>Added timer use case.
mbed_official 15:a81a8d6c1dfe 1744 * Added support for SAMR21 and SAMD10/D11.</td>
mbed_official 15:a81a8d6c1dfe 1745 * </tr>
mbed_official 15:a81a8d6c1dfe 1746 * <tr>
mbed_official 15:a81a8d6c1dfe 1747 * <td>C</td>
mbed_official 15:a81a8d6c1dfe 1748 * <td>01/2014</td>
mbed_official 15:a81a8d6c1dfe 1749 * <td>Added support for SAMD21.</td>
mbed_official 15:a81a8d6c1dfe 1750 * </tr>
mbed_official 15:a81a8d6c1dfe 1751 * <tr>
mbed_official 15:a81a8d6c1dfe 1752 * <td>B</td>
mbed_official 15:a81a8d6c1dfe 1753 * <td>06/2013</td>
mbed_official 15:a81a8d6c1dfe 1754 * <td>Corrected documentation typos.</td>
mbed_official 15:a81a8d6c1dfe 1755 * </tr>
mbed_official 15:a81a8d6c1dfe 1756 * <tr>
mbed_official 15:a81a8d6c1dfe 1757 * <td>A</td>
mbed_official 15:a81a8d6c1dfe 1758 * <td>06/2013</td>
mbed_official 15:a81a8d6c1dfe 1759 * <td>Initial release</td>
mbed_official 15:a81a8d6c1dfe 1760 * </tr>
mbed_official 15:a81a8d6c1dfe 1761 * </table>
mbed_official 15:a81a8d6c1dfe 1762 */
mbed_official 15:a81a8d6c1dfe 1763
mbed_official 15:a81a8d6c1dfe 1764 #endif /* TC_H_INCLUDED */