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

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
Parent:
TARGET_SAMR21G18A/TARGET_Atmel/TARGET_SAM_CortexM0P/drivers/tcc/tcc.h@111:4336505e4b1c
mbed library. Release version 164

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 111:4336505e4b1c 1 /**
Kojto 111:4336505e4b1c 2 * \file
Kojto 111:4336505e4b1c 3 *
Kojto 111:4336505e4b1c 4 * \brief SAM TCC - Timer Counter for Control Applications Driver
Kojto 111:4336505e4b1c 5 *
Kojto 111:4336505e4b1c 6 * Copyright (C) 2013-2015 Atmel Corporation. All rights reserved.
Kojto 111:4336505e4b1c 7 *
Kojto 111:4336505e4b1c 8 * \asf_license_start
Kojto 111:4336505e4b1c 9 *
Kojto 111:4336505e4b1c 10 * \page License
Kojto 111:4336505e4b1c 11 *
Kojto 111:4336505e4b1c 12 * Redistribution and use in source and binary forms, with or without
Kojto 111:4336505e4b1c 13 * modification, are permitted provided that the following conditions are met:
Kojto 111:4336505e4b1c 14 *
Kojto 111:4336505e4b1c 15 * 1. Redistributions of source code must retain the above copyright notice,
Kojto 111:4336505e4b1c 16 * this list of conditions and the following disclaimer.
Kojto 111:4336505e4b1c 17 *
Kojto 111:4336505e4b1c 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
Kojto 111:4336505e4b1c 19 * this list of conditions and the following disclaimer in the documentation
Kojto 111:4336505e4b1c 20 * and/or other materials provided with the distribution.
Kojto 111:4336505e4b1c 21 *
Kojto 111:4336505e4b1c 22 * 3. The name of Atmel may not be used to endorse or promote products derived
Kojto 111:4336505e4b1c 23 * from this software without specific prior written permission.
Kojto 111:4336505e4b1c 24 *
Kojto 111:4336505e4b1c 25 * 4. This software may only be redistributed and used in connection with an
Kojto 111:4336505e4b1c 26 * Atmel microcontroller product.
Kojto 111:4336505e4b1c 27 *
Kojto 111:4336505e4b1c 28 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
Kojto 111:4336505e4b1c 29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
Kojto 111:4336505e4b1c 30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
Kojto 111:4336505e4b1c 31 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
Kojto 111:4336505e4b1c 32 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Kojto 111:4336505e4b1c 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Kojto 111:4336505e4b1c 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Kojto 111:4336505e4b1c 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
Kojto 111:4336505e4b1c 36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
Kojto 111:4336505e4b1c 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Kojto 111:4336505e4b1c 38 * POSSIBILITY OF SUCH DAMAGE.
Kojto 111:4336505e4b1c 39 *
Kojto 111:4336505e4b1c 40 * \asf_license_stop
Kojto 111:4336505e4b1c 41 *
Kojto 111:4336505e4b1c 42 */
Kojto 111:4336505e4b1c 43 /*
Kojto 111:4336505e4b1c 44 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
Kojto 111:4336505e4b1c 45 */
Kojto 111:4336505e4b1c 46
Kojto 111:4336505e4b1c 47 #ifndef TCC_H_INCLUDED
Kojto 111:4336505e4b1c 48 #define TCC_H_INCLUDED
Kojto 111:4336505e4b1c 49
Kojto 111:4336505e4b1c 50 /**
Kojto 111:4336505e4b1c 51 * \defgroup asfdoc_sam0_tcc_group SAM Timer Counter for Control Applications Driver (TCC)
Kojto 111:4336505e4b1c 52 *
Kojto 111:4336505e4b1c 53 * This driver for Atmel&reg; | SMART SAM devices provides an interface for the configuration
Kojto 111:4336505e4b1c 54 * and management of the TCC module within the device, for waveform
Kojto 111:4336505e4b1c 55 * generation and timing operations. It also provides extended options for
Kojto 111:4336505e4b1c 56 * control applications.
Kojto 111:4336505e4b1c 57 *
Kojto 111:4336505e4b1c 58 * The following driver API modes are covered
Kojto 111:4336505e4b1c 59 * by this manual:
Kojto 111:4336505e4b1c 60 *
Kojto 111:4336505e4b1c 61 * - Polled APIs
Kojto 111:4336505e4b1c 62 * \if TCC_CALLBACK_MODE
Kojto 111:4336505e4b1c 63 * - Callback APIs
Kojto 111:4336505e4b1c 64 * \endif
Kojto 111:4336505e4b1c 65 *
Kojto 111:4336505e4b1c 66 * The following peripherals are used by this module:
Kojto 111:4336505e4b1c 67 * - TCC (Timer/Counter for Control Applications)
Kojto 111:4336505e4b1c 68 *
Kojto 111:4336505e4b1c 69 * The following devices can use this module:
Kojto 111:4336505e4b1c 70 * - Atmel | SMART SAM D21
Kojto 111:4336505e4b1c 71 * - Atmel | SMART SAM R21
Kojto 111:4336505e4b1c 72 * - Atmel | SMART SAM D10/D11
Kojto 111:4336505e4b1c 73 * - Atmel | SMART SAM L21
Kojto 111:4336505e4b1c 74 * - Atmel | SMART SAM DAx
Kojto 111:4336505e4b1c 75 * - Atmel | SMART SAM C20/C21
Kojto 111:4336505e4b1c 76 *
Kojto 111:4336505e4b1c 77 * The outline of this documentation is as follows:
Kojto 111:4336505e4b1c 78 * - \ref asfdoc_sam0_tcc_prerequisites
Kojto 111:4336505e4b1c 79 * - \ref asfdoc_sam0_tcc_module_overview
Kojto 111:4336505e4b1c 80 * - \ref asfdoc_sam0_tcc_special_considerations
Kojto 111:4336505e4b1c 81 * - \ref asfdoc_sam0_tcc_extra_info
Kojto 111:4336505e4b1c 82 * - \ref asfdoc_sam0_tcc_examples
Kojto 111:4336505e4b1c 83 * - \ref asfdoc_sam0_tcc_api_overview
Kojto 111:4336505e4b1c 84 *
Kojto 111:4336505e4b1c 85 * \section asfdoc_sam0_tcc_prerequisites Prerequisites
Kojto 111:4336505e4b1c 86 *
Kojto 111:4336505e4b1c 87 * There are no prerequisites for this module.
Kojto 111:4336505e4b1c 88 *
Kojto 111:4336505e4b1c 89 * \section asfdoc_sam0_tcc_module_overview Module Overview
Kojto 111:4336505e4b1c 90 *
Kojto 111:4336505e4b1c 91 * The Timer/Counter for Control Applications (TCC) module provides a set of
Kojto 111:4336505e4b1c 92 * timing and counting related functionality, such as the generation of periodic
Kojto 111:4336505e4b1c 93 * waveforms, the capturing of a periodic waveform's frequency/duty cycle,
Kojto 111:4336505e4b1c 94 * software timekeeping for periodic operations, waveform extension control,
Kojto 111:4336505e4b1c 95 * fault detection etc.
Kojto 111:4336505e4b1c 96 *
Kojto 111:4336505e4b1c 97 * The counter size of the TCC modules can be 16- or 24-bit depending on
Kojto 111:4336505e4b1c 98 * the TCC instance.
Kojto 111:4336505e4b1c 99 * Refer \ref asfdoc_sam0_tcc_special_considerations_tcc_d21 and
Kojto 111:4336505e4b1c 100 * \ref asfdoc_sam0_tcc_special_considerations_tcc_d11 for details on TCC instances.
Kojto 111:4336505e4b1c 101 *
Kojto 111:4336505e4b1c 102 * The TCC module for the SAM includes the following functions:
Kojto 111:4336505e4b1c 103 *
Kojto 111:4336505e4b1c 104 * - Generation of PWM signals
Kojto 111:4336505e4b1c 105 * - Generation of timestamps for events
Kojto 111:4336505e4b1c 106 * - General time counting
Kojto 111:4336505e4b1c 107 * - Waveform period capture
Kojto 111:4336505e4b1c 108 * - Waveform frequency capture
Kojto 111:4336505e4b1c 109 * - Additional control for generated waveform outputs
Kojto 111:4336505e4b1c 110 * - Fault protection for waveform generation
Kojto 111:4336505e4b1c 111 *
Kojto 111:4336505e4b1c 112 * \ref asfdoc_sam0_tcc_block_diagram "The diagram below" shows the overview
Kojto 111:4336505e4b1c 113 * of the TCC Module.
Kojto 111:4336505e4b1c 114 *
Kojto 111:4336505e4b1c 115 * \anchor asfdoc_sam0_tcc_block_diagram
Kojto 111:4336505e4b1c 116 * \image html overview.svg "Overview of the TCC Module"
Kojto 111:4336505e4b1c 117 *
Kojto 111:4336505e4b1c 118 * \subsection asfdoc_sam0_tcc_module_overview_parts Functional Description
Kojto 111:4336505e4b1c 119 * The TCC module consists of following sections:
Kojto 111:4336505e4b1c 120 * - Base Counter
Kojto 111:4336505e4b1c 121 * - Compare/Capture channels, with waveform generation
Kojto 111:4336505e4b1c 122 * - Waveform extension control and fault detection
Kojto 111:4336505e4b1c 123 * - Interface to the event system, DMAC, and the interrupt system
Kojto 111:4336505e4b1c 124 *
Kojto 111:4336505e4b1c 125 * The base counter can be configured to either count a prescaled generic
Kojto 111:4336505e4b1c 126 * clock or events from the event system.(TCEx, with event action configured
Kojto 111:4336505e4b1c 127 * to counting).
Kojto 111:4336505e4b1c 128 * The counter value can be used by compare/capture channels which can be
Kojto 111:4336505e4b1c 129 * set up either in compare mode or capture mode.
Kojto 111:4336505e4b1c 130 *
Kojto 111:4336505e4b1c 131 * In capture mode, the counter value is stored when a configurable event
Kojto 111:4336505e4b1c 132 * occurs. This mode can be used to generate timestamps used in event capture,
Kojto 111:4336505e4b1c 133 * or it can be used for the measurement of a periodic input signal's
Kojto 111:4336505e4b1c 134 * frequency/duty cycle.
Kojto 111:4336505e4b1c 135 *
Kojto 111:4336505e4b1c 136 * In compare mode, the counter value is compared against one or more of the
Kojto 111:4336505e4b1c 137 * configured channels' compare values. When the counter value coincides with a
Kojto 111:4336505e4b1c 138 * compare value an action can be taken automatically by the module, such as
Kojto 111:4336505e4b1c 139 * generating an output event or toggling a pin when used for frequency or PWM
Kojto 111:4336505e4b1c 140 * signal generation.
Kojto 111:4336505e4b1c 141 *
Kojto 111:4336505e4b1c 142 * \note The connection of events between modules requires the use of the
Kojto 111:4336505e4b1c 143 * \ref asfdoc_sam0_events_group "SAM Event System Driver (EVENTS)"
Kojto 111:4336505e4b1c 144 * to route output event of one module to the the input event of another.
Kojto 111:4336505e4b1c 145 * For more information on event routing, refer to the event driver
Kojto 111:4336505e4b1c 146 * documentation.
Kojto 111:4336505e4b1c 147 *
Kojto 111:4336505e4b1c 148 * In compare mode, when output signal is generated, extended waveform controls
Kojto 111:4336505e4b1c 149 * are available, to arrange the compare outputs into specific formats.
Kojto 111:4336505e4b1c 150 * The Output matrix can change the channel output routing. Pattern generation
Kojto 111:4336505e4b1c 151 * unit can overwrite the output signal line to specific state.
Kojto 111:4336505e4b1c 152 * The Fault protection feature of the TCC supports recoverable and
Kojto 111:4336505e4b1c 153 * non-recoverable faults.
Kojto 111:4336505e4b1c 154 *
Kojto 111:4336505e4b1c 155 * \subsection asfdoc_sam0_tcc_module_overview_tc Base Timer/Counter
Kojto 111:4336505e4b1c 156 *
Kojto 111:4336505e4b1c 157 * \subsubsection asfdoc_sam0_tcc_module_overview_tc_size Timer/Counter Size
Kojto 111:4336505e4b1c 158 * Each TCC has a counter size of either 16- or 24-bits. The size of the
Kojto 111:4336505e4b1c 159 * counter determines the maximum value it can count to before an overflow
Kojto 111:4336505e4b1c 160 * occurs.
Kojto 111:4336505e4b1c 161 * \ref asfdoc_sam0_tcc_count_size_vs_top "The table below" shows the
Kojto 111:4336505e4b1c 162 * maximum values for each of the possible counter sizes.
Kojto 111:4336505e4b1c 163 *
Kojto 111:4336505e4b1c 164 * \anchor asfdoc_sam0_tcc_count_size_vs_top
Kojto 111:4336505e4b1c 165 * <table>
Kojto 111:4336505e4b1c 166 * <caption>Timer Counter Sizes and Their Maximum Count Values</caption>
Kojto 111:4336505e4b1c 167 * <tr>
Kojto 111:4336505e4b1c 168 * <th>Counter size</th>
Kojto 111:4336505e4b1c 169 * <th>Max. (hexadecimal)</th>
Kojto 111:4336505e4b1c 170 * <th>Max. (decimal)</th>
Kojto 111:4336505e4b1c 171 * </tr>
Kojto 111:4336505e4b1c 172 * <tr>
Kojto 111:4336505e4b1c 173 * <td>16-bit</td>
Kojto 111:4336505e4b1c 174 * <td>0xFFFF</td>
Kojto 111:4336505e4b1c 175 * <td>65,535</td>
Kojto 111:4336505e4b1c 176 * </tr>
Kojto 111:4336505e4b1c 177 * <tr>
Kojto 111:4336505e4b1c 178 * <td>24-bit</td>
Kojto 111:4336505e4b1c 179 * <td>0xFFFFFF</td>
Kojto 111:4336505e4b1c 180 * <td>16,777,215</td>
Kojto 111:4336505e4b1c 181 * </tr>
Kojto 111:4336505e4b1c 182 * </table>
Kojto 111:4336505e4b1c 183 *
Kojto 111:4336505e4b1c 184 * The period/top value of the counter can be set, to define counting period.
Kojto 111:4336505e4b1c 185 * This will allow the counter to overflow when the counter value reaches the
Kojto 111:4336505e4b1c 186 * period/top value.
Kojto 111:4336505e4b1c 187 *
Kojto 111:4336505e4b1c 188 * \subsubsection asfdoc_sam0_tcc_module_overview_tc_clk Timer/Counter Clock and Prescaler
Kojto 111:4336505e4b1c 189 * TCC is clocked asynchronously to the system clock by a GCLK
Kojto 111:4336505e4b1c 190 * (Generic Clock) channel. The GCLK channel can be connected to any of the GCLK
Kojto 111:4336505e4b1c 191 * generators. The GCLK generators are configured to use one of the available
Kojto 111:4336505e4b1c 192 * clock sources in the system such as internal oscillator, external crystals,
Kojto 111:4336505e4b1c 193 * etc. - see the \ref asfdoc_sam0_system_clock_group "Generic Clock driver" for
Kojto 111:4336505e4b1c 194 * more information.
Kojto 111:4336505e4b1c 195 *
Kojto 111:4336505e4b1c 196 * Each TCC module in the SAM has its own individual clock prescaler, which
Kojto 111:4336505e4b1c 197 * can be used to divide the input clock frequency used by the counter. This
Kojto 111:4336505e4b1c 198 * prescaler only scales the clock used to provide clock pulses for the counter
Kojto 111:4336505e4b1c 199 * to count, and does not affect the digital register interface portion of
Kojto 111:4336505e4b1c 200 * the module, thus the timer registers will synchronized to the raw GCLK
Kojto 111:4336505e4b1c 201 * frequency input to the module.
Kojto 111:4336505e4b1c 202 *
Kojto 111:4336505e4b1c 203 * As a result of this, when selecting a GCLK frequency and timer prescaler
Kojto 111:4336505e4b1c 204 * value the user application should consider both the timer resolution
Kojto 111:4336505e4b1c 205 * required and the synchronization frequency, to avoid lengthy
Kojto 111:4336505e4b1c 206 * synchronization times of the module if a very slow GCLK frequency is fed
Kojto 111:4336505e4b1c 207 * into the TCC module. It is preferable to use a higher module GCLK frequency
Kojto 111:4336505e4b1c 208 * as the input to the timer and prescale this down as much as possible to
Kojto 111:4336505e4b1c 209 * obtain a suitable counter frequency in latency-sensitive applications.
Kojto 111:4336505e4b1c 210 *
Kojto 111:4336505e4b1c 211 * \subsubsection asfdoc_sam0_tcc_module_overview_tc_ctrl Timer/Counter Control Inputs (Events)
Kojto 111:4336505e4b1c 212 *
Kojto 111:4336505e4b1c 213 * The TCC can take several actions on the occurrence of an input event.
Kojto 111:4336505e4b1c 214 * The event actions are listed
Kojto 111:4336505e4b1c 215 * in \ref asfdoc_sam0_tcc_module_event_act "events action settings".
Kojto 111:4336505e4b1c 216 *
Kojto 111:4336505e4b1c 217 * \anchor asfdoc_sam0_tcc_module_event_act
Kojto 111:4336505e4b1c 218 * <table>
Kojto 111:4336505e4b1c 219 * <caption>TCC Module Event Actions</caption>
Kojto 111:4336505e4b1c 220 * <tr>
Kojto 111:4336505e4b1c 221 * <th>Event action</th>
Kojto 111:4336505e4b1c 222 * <th>Description</th>
Kojto 111:4336505e4b1c 223 * <th>Applied event</th>
Kojto 111:4336505e4b1c 224 * </tr>
Kojto 111:4336505e4b1c 225 * <tr>
Kojto 111:4336505e4b1c 226 * <td>TCC_EVENT_ACTION_OFF</td>
Kojto 111:4336505e4b1c 227 * <td>No action on the event input</td>
Kojto 111:4336505e4b1c 228 * <td>All</td>
Kojto 111:4336505e4b1c 229 * </tr>
Kojto 111:4336505e4b1c 230 * <tr>
Kojto 111:4336505e4b1c 231 * <td>TCC_EVENT_ACTION_RETRIGGER</td>
Kojto 111:4336505e4b1c 232 * <td>Re-trigger Counter on event</td>
Kojto 111:4336505e4b1c 233 * <td>All</td>
Kojto 111:4336505e4b1c 234 * </tr>
Kojto 111:4336505e4b1c 235 * <tr>
Kojto 111:4336505e4b1c 236 * <td>TCC_EVENT_ACTION_NON_RECOVERABLE_FAULT</td>
Kojto 111:4336505e4b1c 237 * <td>Generate Non-Recoverable Fault on event</td>
Kojto 111:4336505e4b1c 238 * <td>All</td>
Kojto 111:4336505e4b1c 239 * </tr>
Kojto 111:4336505e4b1c 240 * <tr>
Kojto 111:4336505e4b1c 241 * <td>TCC_EVENT_ACTION_START</td>
Kojto 111:4336505e4b1c 242 * <td>Counter start on event</td>
Kojto 111:4336505e4b1c 243 * <td>EV0</td>
Kojto 111:4336505e4b1c 244 * </tr>
Kojto 111:4336505e4b1c 245 * <tr>
Kojto 111:4336505e4b1c 246 * <td>TCC_EVENT_ACTION_DIR_CONTROL</td>
Kojto 111:4336505e4b1c 247 * <td>Counter direction control</td>
Kojto 111:4336505e4b1c 248 * <td>EV0</td>
Kojto 111:4336505e4b1c 249 * </tr>
Kojto 111:4336505e4b1c 250 * <tr>
Kojto 111:4336505e4b1c 251 * <td>TCC_EVENT_ACTION_DECREMENT</td>
Kojto 111:4336505e4b1c 252 * <td>Counter decrement on event</td>
Kojto 111:4336505e4b1c 253 * <td>EV0</td>
Kojto 111:4336505e4b1c 254 * </tr>
Kojto 111:4336505e4b1c 255 * <tr>
Kojto 111:4336505e4b1c 256 * <td>TCC_EVENT_ACTION_PERIOD_PULSE_WIDTH_CAPTURE</td>
Kojto 111:4336505e4b1c 257 * <td>Capture pulse period and pulse width</td>
Kojto 111:4336505e4b1c 258 * <td>EV0</td>
Kojto 111:4336505e4b1c 259 * </tr>
Kojto 111:4336505e4b1c 260 * <tr>
Kojto 111:4336505e4b1c 261 * <td>TCC_EVENT_ACTION_PULSE_WIDTH_PERIOD_CAPTURE</td>
Kojto 111:4336505e4b1c 262 * <td>Capture pulse width and pulse period</td>
Kojto 111:4336505e4b1c 263 * <td>EV0</td>
Kojto 111:4336505e4b1c 264 * </tr>
Kojto 111:4336505e4b1c 265 * <tr>
Kojto 111:4336505e4b1c 266 * <td>TCC_EVENT_ACTION_STOP</td>
Kojto 111:4336505e4b1c 267 * <td>Counter stop on event</td>
Kojto 111:4336505e4b1c 268 * <td>EV1</td>
Kojto 111:4336505e4b1c 269 * </tr>
Kojto 111:4336505e4b1c 270 * <tr>
Kojto 111:4336505e4b1c 271 * <td>TCC_EVENT_ACTION_COUNT_EVENT</td>
Kojto 111:4336505e4b1c 272 * <td>Counter count on event</td>
Kojto 111:4336505e4b1c 273 * <td>EV1</td>
Kojto 111:4336505e4b1c 274 * </tr>
Kojto 111:4336505e4b1c 275 * <tr>
Kojto 111:4336505e4b1c 276 * <td>TCC_EVENT_ACTION_INCREMENT</td>
Kojto 111:4336505e4b1c 277 * <td>Counter increment on event</td>
Kojto 111:4336505e4b1c 278 * <td>EV1</td>
Kojto 111:4336505e4b1c 279 * </tr>
Kojto 111:4336505e4b1c 280 * <tr>
Kojto 111:4336505e4b1c 281 * <td>TCC_EVENT_ACTION_COUNT_DURING_ACTIVE</td>
Kojto 111:4336505e4b1c 282 * <td>Counter count during active state of asynchronous event</td>
Kojto 111:4336505e4b1c 283 * <td>EV1</td>
Kojto 111:4336505e4b1c 284 * </tr>
Kojto 111:4336505e4b1c 285 * </table>
Kojto 111:4336505e4b1c 286 *
Kojto 111:4336505e4b1c 287 * \subsubsection asfdoc_sam0_tcc_module_overview_tc_reload Timer/Counter Reloading
Kojto 111:4336505e4b1c 288 *
Kojto 111:4336505e4b1c 289 * The TCC also has a configurable reload action, used when a
Kojto 111:4336505e4b1c 290 * re-trigger event occurs. Examples of a re-trigger event could be the counter
Kojto 111:4336505e4b1c 291 * reaching the maximum value when counting up, or when an event from the event
Kojto 111:4336505e4b1c 292 * system makes the counter to re-trigger. The reload action determines if the
Kojto 111:4336505e4b1c 293 * prescaler should be reset, and on which clock. The counter will
Kojto 111:4336505e4b1c 294 * always be reloaded with the value it is set to start counting. The user
Kojto 111:4336505e4b1c 295 * can choose between three different reload actions, described in
Kojto 111:4336505e4b1c 296 * \ref asfdoc_sam0_tcc_module_reload_act "the table below".
Kojto 111:4336505e4b1c 297 *
Kojto 111:4336505e4b1c 298 * \anchor asfdoc_sam0_tcc_module_reload_act
Kojto 111:4336505e4b1c 299 * <table>
Kojto 111:4336505e4b1c 300 * <caption>TCC Module Reload Actions</caption>
Kojto 111:4336505e4b1c 301 * <tr>
Kojto 111:4336505e4b1c 302 * <th>Reload action</th>
Kojto 111:4336505e4b1c 303 * <th>Description</th>
Kojto 111:4336505e4b1c 304 * </tr>
Kojto 111:4336505e4b1c 305 * <tr>
Kojto 111:4336505e4b1c 306 * <td>TCC_RELOAD_ACTION_GCLK</td>
Kojto 111:4336505e4b1c 307 * <td>Reload TCC counter value on next GCLK cycle. Leave prescaler
Kojto 111:4336505e4b1c 308 * as-is.</td>
Kojto 111:4336505e4b1c 309 * </tr>
Kojto 111:4336505e4b1c 310 * <tr>
Kojto 111:4336505e4b1c 311 * <td>TCC_RELOAD_ACTION_PRESC</td>
Kojto 111:4336505e4b1c 312 * <td>Reloads TCC counter value on next prescaler clock. Leave prescaler
Kojto 111:4336505e4b1c 313 * as-is.</td>
Kojto 111:4336505e4b1c 314 * </tr>
Kojto 111:4336505e4b1c 315 * <tr>
Kojto 111:4336505e4b1c 316 * <td>TCC_RELOAD_ACTION_RESYNC</td>
Kojto 111:4336505e4b1c 317 * <td>Reload TCC counter value on next GCLK cycle. Clear prescaler to
Kojto 111:4336505e4b1c 318 * zero.</td>
Kojto 111:4336505e4b1c 319 * </tr>
Kojto 111:4336505e4b1c 320 * </table>
Kojto 111:4336505e4b1c 321 *
Kojto 111:4336505e4b1c 322 * The reload action to use will depend on the specific application being
Kojto 111:4336505e4b1c 323 * implemented. One example is when an external trigger for a reload occurs; if
Kojto 111:4336505e4b1c 324 * the TCC uses the prescaler, the counter in the prescaler should not have a
Kojto 111:4336505e4b1c 325 * value between zero and the division factor. The counter in the TCC module
Kojto 111:4336505e4b1c 326 * and the counter in the prescaler should both start at zero.
Kojto 111:4336505e4b1c 327 * If the counter is set to re-trigger when it reaches the maximum value,
Kojto 111:4336505e4b1c 328 * this is not the right option to use. In such a case it would be better if
Kojto 111:4336505e4b1c 329 * the prescaler is left unaltered when the re-trigger happens, letting the
Kojto 111:4336505e4b1c 330 * counter reset on the next GCLK cycle.
Kojto 111:4336505e4b1c 331 *
Kojto 111:4336505e4b1c 332 * \subsubsection asfdoc_sam0_tcc_module_overview_tc_oneshot One-shot Mode
Kojto 111:4336505e4b1c 333 *
Kojto 111:4336505e4b1c 334 * The TCC module can be configured in one-shot mode. When configured in this
Kojto 111:4336505e4b1c 335 * manner, starting the timer will cause it to count until the next overflow
Kojto 111:4336505e4b1c 336 * or underflow condition before automatically halting, waiting to be manually
Kojto 111:4336505e4b1c 337 * triggered by the user application software or an event from the event
Kojto 111:4336505e4b1c 338 * system.
Kojto 111:4336505e4b1c 339 *
Kojto 111:4336505e4b1c 340 * \subsection asfdoc_sam0_tcc_module_overview_capt Capture Operations
Kojto 111:4336505e4b1c 341 *
Kojto 111:4336505e4b1c 342 * In capture operations, any event from the event system or a pin change can
Kojto 111:4336505e4b1c 343 * trigger a capture of the counter value. This captured counter value can be
Kojto 111:4336505e4b1c 344 * used as timestamps for the events, or it can be used in frequency and pulse
Kojto 111:4336505e4b1c 345 * width capture.
Kojto 111:4336505e4b1c 346 *
Kojto 111:4336505e4b1c 347 * \subsubsection asfdoc_sam0_tcc_module_overview_capt_ev Capture Operations - Event
Kojto 111:4336505e4b1c 348 *
Kojto 111:4336505e4b1c 349 * Event capture is a simple use of the capture functionality,
Kojto 111:4336505e4b1c 350 * designed to create timestamps for specific events. When the input event
Kojto 111:4336505e4b1c 351 * appears, the current counter value is copied into the corresponding
Kojto 111:4336505e4b1c 352 * compare/capture register, which can then be read by the user application.
Kojto 111:4336505e4b1c 353 *
Kojto 111:4336505e4b1c 354 * Note that when performing any capture operation, there is a risk that the
Kojto 111:4336505e4b1c 355 * counter reaches its top value (MAX) when counting up, or the bottom value
Kojto 111:4336505e4b1c 356 * (zero) when counting down, before the capture event occurs. This can distort
Kojto 111:4336505e4b1c 357 * the result, making event timestamps to appear shorter than they really are.
Kojto 111:4336505e4b1c 358 * In this case, the user application should check for timer overflow when
Kojto 111:4336505e4b1c 359 * reading a capture result in order to detect this situation and perform an
Kojto 111:4336505e4b1c 360 * appropriate adjustment.
Kojto 111:4336505e4b1c 361 *
Kojto 111:4336505e4b1c 362 * Before checking for a new capture, \ref TCC_STATUS_COUNT_OVERFLOW
Kojto 111:4336505e4b1c 363 * should be checked. The response to an overflow error is left to the user
Kojto 111:4336505e4b1c 364 * application, however it may be necessary to clear both the overflow
Kojto 111:4336505e4b1c 365 * flag and the capture flag upon each capture reading.
Kojto 111:4336505e4b1c 366 *
Kojto 111:4336505e4b1c 367 * \subsubsection asfdoc_sam0_tcc_module_overview_capt_pulse Capture Operations - Pulse Width
Kojto 111:4336505e4b1c 368 *
Kojto 111:4336505e4b1c 369 * Pulse Width Capture mode makes it possible to measure the pulse width and
Kojto 111:4336505e4b1c 370 * period of PWM signals. This mode uses two capture channels of the counter.
Kojto 111:4336505e4b1c 371 * There are two modes for pulse width capture;
Kojto 111:4336505e4b1c 372 * Pulse Width Period (PWP) and Period Pulse Width (PPW). In PWP mode, capture
Kojto 111:4336505e4b1c 373 * channel 0 is used for storing the pulse width and capture channel 1 stores
Kojto 111:4336505e4b1c 374 * the observed period. While in PPW mode, the roles of the two capture channels
Kojto 111:4336505e4b1c 375 * are reversed.
Kojto 111:4336505e4b1c 376 *
Kojto 111:4336505e4b1c 377 * As in the above example it is necessary to poll on interrupt flags to see
Kojto 111:4336505e4b1c 378 * if a new capture has happened and check that a capture overflow error has
Kojto 111:4336505e4b1c 379 * not occurred.
Kojto 111:4336505e4b1c 380 *
Kojto 111:4336505e4b1c 381 * Refer to \ref asfdoc_sam0_tcc_module_overview_tc_ctrl to set up the input
Kojto 111:4336505e4b1c 382 * event to perform pulse width capture.
Kojto 111:4336505e4b1c 383 *
Kojto 111:4336505e4b1c 384 * \subsection asfdoc_sam0_tcc_module_overview_mc Compare Match Operation
Kojto 111:4336505e4b1c 385 *
Kojto 111:4336505e4b1c 386 * In compare match operation, Compare/Capture registers are compared
Kojto 111:4336505e4b1c 387 * with the counter value. When the timer's count value matches the value of a
Kojto 111:4336505e4b1c 388 * compare channel, a user defined action can be taken.
Kojto 111:4336505e4b1c 389 *
Kojto 111:4336505e4b1c 390 * \subsubsection asfdoc_sam0_tcc_module_overview_mc_timer Basic Timer
Kojto 111:4336505e4b1c 391 *
Kojto 111:4336505e4b1c 392 * A Basic Timer is a simple application where compare match operation is used
Kojto 111:4336505e4b1c 393 * to determine when a specific period has elapsed. In Basic Timer operations,
Kojto 111:4336505e4b1c 394 * one or more values in the module's Compare/Capture registers are used to
Kojto 111:4336505e4b1c 395 * specify the time (in terms of the number of prescaled GCLK cycles, or
Kojto 111:4336505e4b1c 396 * input events) at which
Kojto 111:4336505e4b1c 397 * an action should be taken by the microcontroller. This can be an Interrupt
Kojto 111:4336505e4b1c 398 * Service Routine (ISR), event generation via the event system, or a software
Kojto 111:4336505e4b1c 399 * flag that is polled from the user application.
Kojto 111:4336505e4b1c 400 *
Kojto 111:4336505e4b1c 401 * \subsubsection asfdoc_sam0_tcc_module_overview_mc_wave Waveform Generation
Kojto 111:4336505e4b1c 402 *
Kojto 111:4336505e4b1c 403 * Waveform generation enables the TCC module to generate square waves, or if
Kojto 111:4336505e4b1c 404 * combined with an external passive low-pass filter, analog waveforms.
Kojto 111:4336505e4b1c 405 *
Kojto 111:4336505e4b1c 406 * \subsubsection asfdoc_sam0_tcc_module_overview_mc_wave_pwm Waveform Generation - PWM
Kojto 111:4336505e4b1c 407 *
Kojto 111:4336505e4b1c 408 * Pulse width modulation is a form of waveform generation and a signalling
Kojto 111:4336505e4b1c 409 * technique that can be useful in many applications. When PWM mode is used,
Kojto 111:4336505e4b1c 410 * a digital pulse train with a configurable frequency and duty cycle can be
Kojto 111:4336505e4b1c 411 * generated by the TCC module and output to a GPIO pin of the device.
Kojto 111:4336505e4b1c 412 *
Kojto 111:4336505e4b1c 413 * Often PWM is used to communicate a control or information parameter to an
Kojto 111:4336505e4b1c 414 * external circuit or component. Differing impedances of the source generator
Kojto 111:4336505e4b1c 415 * and sink receiver circuits is less of an issue when using PWM compared to
Kojto 111:4336505e4b1c 416 * using an analog voltage value, as noise will not generally affect the
Kojto 111:4336505e4b1c 417 * signal's integrity to a meaningful extent.
Kojto 111:4336505e4b1c 418 *
Kojto 111:4336505e4b1c 419 * \ref asfdoc_sam0_tcc_module_pwm_single_diag "The figure below" illustrates
Kojto 111:4336505e4b1c 420 * operations and different states of the counter and its output when using
Kojto 111:4336505e4b1c 421 * the timer in Normal PWM mode (Single Slope). As can be seen, the TOP/PERIOD
Kojto 111:4336505e4b1c 422 * value is
Kojto 111:4336505e4b1c 423 * unchanged and is set to MAX. The compare match value is changed at several
Kojto 111:4336505e4b1c 424 * points to illustrate the resulting waveform output changes. The PWM output is
Kojto 111:4336505e4b1c 425 * set to normal (i.e. non-inverted) output mode.
Kojto 111:4336505e4b1c 426 *
Kojto 111:4336505e4b1c 427 * \anchor asfdoc_sam0_tcc_module_pwm_single_diag
Kojto 111:4336505e4b1c 428 * \image html pwm_single_ex.svg "Example Of PWM In Single-Slope Mode, and Different Counter Operations"
Kojto 111:4336505e4b1c 429 *
Kojto 111:4336505e4b1c 430 * Several PWM modes are supported by the TCC module, refer to
Kojto 111:4336505e4b1c 431 * datasheet for the details on PWM waveform generation.
Kojto 111:4336505e4b1c 432 *
Kojto 111:4336505e4b1c 433 * \subsubsection asfdoc_sam0_tcc_module_overview_mc_wave_freq Waveform Generation - Frequency
Kojto 111:4336505e4b1c 434 *
Kojto 111:4336505e4b1c 435 * Normal Frequency Generation is in many ways identical to PWM generation.
Kojto 111:4336505e4b1c 436 * However, only in Frequency Generation, a toggle occurs on the output when a
Kojto 111:4336505e4b1c 437 * match on a compare channels occurs.
Kojto 111:4336505e4b1c 438 *
Kojto 111:4336505e4b1c 439 * When the Match Frequency Generation is used, the timer value is reset on
Kojto 111:4336505e4b1c 440 * match condition, resulting in a variable frequency square wave with a
Kojto 111:4336505e4b1c 441 * fixed 50% duty cycle.
Kojto 111:4336505e4b1c 442 *
Kojto 111:4336505e4b1c 443 * \subsection asfdoc_sam0_tcc_module_overview_ext Waveform Extended Controls
Kojto 111:4336505e4b1c 444 *
Kojto 111:4336505e4b1c 445 * \subsubsection asfdoc_sam0_tcc_module_overview_ext_pat Pattern Generation
Kojto 111:4336505e4b1c 446 *
Kojto 111:4336505e4b1c 447 * Pattern insertion allows the TCC module to change the actual pin output level
Kojto 111:4336505e4b1c 448 * without modifying the compare/match settings.
Kojto 111:4336505e4b1c 449 *
Kojto 111:4336505e4b1c 450 * \anchor asfdoc_sam0_tcc_module_pattern_gen
Kojto 111:4336505e4b1c 451 * <table>
Kojto 111:4336505e4b1c 452 * <caption>TCC Module Output Pattern Generation</caption>
Kojto 111:4336505e4b1c 453 * <tr>
Kojto 111:4336505e4b1c 454 * <th>Pattern</th>
Kojto 111:4336505e4b1c 455 * <th>Description</th>
Kojto 111:4336505e4b1c 456 * </tr>
Kojto 111:4336505e4b1c 457 * <tr>
Kojto 111:4336505e4b1c 458 * <td>TCC_OUTPUT_PATTERN_DISABLE</td>
Kojto 111:4336505e4b1c 459 * <td>Pattern disabled, generate output as is</td>
Kojto 111:4336505e4b1c 460 * </tr>
Kojto 111:4336505e4b1c 461 * <tr>
Kojto 111:4336505e4b1c 462 * <td>TCC_OUTPUT_PATTERN_0</td>
Kojto 111:4336505e4b1c 463 * <td>Generate pattern 0 on output (keep the output LOW)</td>
Kojto 111:4336505e4b1c 464 * </tr>
Kojto 111:4336505e4b1c 465 * <tr>
Kojto 111:4336505e4b1c 466 * <td>TCC_OUTPUT_PATTERN_1</td>
Kojto 111:4336505e4b1c 467 * <td>Generate pattern 1 on output (keep the output HIGH)</td>
Kojto 111:4336505e4b1c 468 * </tr>
Kojto 111:4336505e4b1c 469 * </table>
Kojto 111:4336505e4b1c 470 *
Kojto 111:4336505e4b1c 471 * \subsubsection asfdoc_sam0_tcc_module_overview_ext_r_fault Recoverable Faults
Kojto 111:4336505e4b1c 472 *
Kojto 111:4336505e4b1c 473 * The recoverable faults can trigger one or several of following fault actions:
Kojto 111:4336505e4b1c 474 * -# *Halt* action: The recoverable faults can halt the TCC timer/counter,
Kojto 111:4336505e4b1c 475 * so that the final output wave is kept at a defined state. When the fault
Kojto 111:4336505e4b1c 476 * state is removed it is possible to recover the counter and waveform
Kojto 111:4336505e4b1c 477 * generation. The halt action is defined as:
Kojto 111:4336505e4b1c 478 * \anchor asfdoc_sam0_tcc_module_fault_halt_action
Kojto 111:4336505e4b1c 479 * <table>
Kojto 111:4336505e4b1c 480 * <caption>TCC Module Recoverable Fault Halt Actions</caption>
Kojto 111:4336505e4b1c 481 * <tr>
Kojto 111:4336505e4b1c 482 * <th>Action</th>
Kojto 111:4336505e4b1c 483 * <th>Description</th>
Kojto 111:4336505e4b1c 484 * </tr>
Kojto 111:4336505e4b1c 485 * <tr>
Kojto 111:4336505e4b1c 486 * <td>TCC_FAULT_HALT_ACTION_DISABLE</td>
Kojto 111:4336505e4b1c 487 * <td>Halt action is disabled</td>
Kojto 111:4336505e4b1c 488 * </tr>
Kojto 111:4336505e4b1c 489 * <tr>
Kojto 111:4336505e4b1c 490 * <td>TCC_FAULT_HALT_ACTION_HW_HALT</td>
Kojto 111:4336505e4b1c 491 * <td>The timer/counter is halted as long as the corresponding fault is
Kojto 111:4336505e4b1c 492 * present</td>
Kojto 111:4336505e4b1c 493 * </tr>
Kojto 111:4336505e4b1c 494 * <tr>
Kojto 111:4336505e4b1c 495 * <td>TCC_FAULT_HALT_ACTION_SW_HALT</td>
Kojto 111:4336505e4b1c 496 * <td>The timer/counter is halted until the corresponding fault is removed
Kojto 111:4336505e4b1c 497 * and fault state cleared by software</td>
Kojto 111:4336505e4b1c 498 * </tr>
Kojto 111:4336505e4b1c 499 * <tr>
Kojto 111:4336505e4b1c 500 * <td>TCC_FAULT_HALT_ACTION_NON_RECOVERABLE</td>
Kojto 111:4336505e4b1c 501 * <td>Force all the TCC output pins to a pre-defined level, as what
Kojto 111:4336505e4b1c 502 * Non-Recoverable Fault do</td>
Kojto 111:4336505e4b1c 503 * </tr>
Kojto 111:4336505e4b1c 504 * </table>
Kojto 111:4336505e4b1c 505 * -# *Restart* action: When enabled, the recoverable faults can restart the TCC
Kojto 111:4336505e4b1c 506 * timer/counter.
Kojto 111:4336505e4b1c 507 * -# *Keep* action: When enabled, the recoverable faults can keep the
Kojto 111:4336505e4b1c 508 * corresponding channel output to zero when the fault condition is present.
Kojto 111:4336505e4b1c 509 * -# *Capture* action: When the recoverable fault occurs, the capture action can
Kojto 111:4336505e4b1c 510 * time stamps the corresponding fault. The following capture mode is
Kojto 111:4336505e4b1c 511 * supported:
Kojto 111:4336505e4b1c 512 * \anchor asfdoc_sam0_tcc_module_fault_capt_action
Kojto 111:4336505e4b1c 513 * <table>
Kojto 111:4336505e4b1c 514 * <caption>TCC Module Recoverable Fault Capture Actions</caption>
Kojto 111:4336505e4b1c 515 * <tr>
Kojto 111:4336505e4b1c 516 * <th>Action</th>
Kojto 111:4336505e4b1c 517 * <th>Description</th>
Kojto 111:4336505e4b1c 518 * </tr>
Kojto 111:4336505e4b1c 519 * <tr>
Kojto 111:4336505e4b1c 520 * <td>TCC_FAULT_CAPTURE_DISABLE</td>
Kojto 111:4336505e4b1c 521 * <td>Capture action is disabled</td>
Kojto 111:4336505e4b1c 522 * </tr>
Kojto 111:4336505e4b1c 523 * <tr>
Kojto 111:4336505e4b1c 524 * <td>TCC_FAULT_CAPTURE_EACH</td>
Kojto 111:4336505e4b1c 525 * <td>Equivalent to standard capture operation, on each fault occurrence
Kojto 111:4336505e4b1c 526 * the time stamp is captured</td>
Kojto 111:4336505e4b1c 527 * </tr>
Kojto 111:4336505e4b1c 528 * <tr>
Kojto 111:4336505e4b1c 529 * <td>TCC_FAULT_CAPTURE_MINIMUM</td>
Kojto 111:4336505e4b1c 530 * <td>Get the minimum time stamped value in all time stamps</td>
Kojto 111:4336505e4b1c 531 * </tr>
Kojto 111:4336505e4b1c 532 * <tr>
Kojto 111:4336505e4b1c 533 * <td>TCC_FAULT_CAPTURE_MAXIMUM</td>
Kojto 111:4336505e4b1c 534 * <td>Get the maximum time stamped value in all time stamps</td>
Kojto 111:4336505e4b1c 535 * </tr>
Kojto 111:4336505e4b1c 536 * <tr>
Kojto 111:4336505e4b1c 537 * <td>TCC_FAULT_CAPTURE_SMALLER</td>
Kojto 111:4336505e4b1c 538 * <td>Time stamp the fault input if the value is smaller than last one</td>
Kojto 111:4336505e4b1c 539 * </tr>
Kojto 111:4336505e4b1c 540 * <tr>
Kojto 111:4336505e4b1c 541 * <td>TCC_FAULT_CAPTURE_BIGGER</td>
Kojto 111:4336505e4b1c 542 * <td>Time stamp the fault input if the value is bigger than last one</td>
Kojto 111:4336505e4b1c 543 * </tr>
Kojto 111:4336505e4b1c 544 * <tr>
Kojto 111:4336505e4b1c 545 * <td>TCC_FAULT_CAPTURE_CHANGE</td>
Kojto 111:4336505e4b1c 546 * <td>Time stamp the fault input if the time stamps changes its increment
Kojto 111:4336505e4b1c 547 * direction</td>
Kojto 111:4336505e4b1c 548 * </tr>
Kojto 111:4336505e4b1c 549 * </table>
Kojto 111:4336505e4b1c 550 *
Kojto 111:4336505e4b1c 551 * In TCC module, only the first two compare channels (CC0 and CC1) can work
Kojto 111:4336505e4b1c 552 * with recoverable fault inputs. The corresponding event inputs (TCCx MC0
Kojto 111:4336505e4b1c 553 * and TCCx MC1) are then used as fault inputs respectively.
Kojto 111:4336505e4b1c 554 * The faults are called Fault A and Fault B.
Kojto 111:4336505e4b1c 555 *
Kojto 111:4336505e4b1c 556 * The recoverable fault can be filtered or effected by corresponding channel
Kojto 111:4336505e4b1c 557 * output. On fault condition there are many other settings that can be chosen.
Kojto 111:4336505e4b1c 558 * Refer to data sheet for more details about the recoverable fault
Kojto 111:4336505e4b1c 559 * operations.
Kojto 111:4336505e4b1c 560 *
Kojto 111:4336505e4b1c 561 * \subsubsection asfdoc_sam0_tcc_module_overview_ext_n_fault Non-Recoverable Faults
Kojto 111:4336505e4b1c 562 *
Kojto 111:4336505e4b1c 563 * The non-recoverable faults force all the TCC output pins to a pre-defined
Kojto 111:4336505e4b1c 564 * level (can be forced to 0 or 1). The input control signal of non-recoverable
Kojto 111:4336505e4b1c 565 * fault is from timer/counter event (TCCx EV0 and TCCx EV1).
Kojto 111:4336505e4b1c 566 * To enable non-recoverable fault,
Kojto 111:4336505e4b1c 567 * corresponding TCEx event action must be set to non-recoverable fault action
Kojto 111:4336505e4b1c 568 * (\ref TCC_EVENT_ACTION_NON_RECOVERABLE_FAULT).
Kojto 111:4336505e4b1c 569 * Refer to \ref asfdoc_sam0_tcc_module_overview_tc_ctrl to see the available
Kojto 111:4336505e4b1c 570 * event input action.
Kojto 111:4336505e4b1c 571 *
Kojto 111:4336505e4b1c 572 * \subsection asfdoc_sam0_tcc_module_overview_buffering Double and Circular Buffering
Kojto 111:4336505e4b1c 573 *
Kojto 111:4336505e4b1c 574 * The pattern, period and the compare channels registers are double buffered.
Kojto 111:4336505e4b1c 575 * For these options there are effective registers (PATT, PER, and CCx) and
Kojto 111:4336505e4b1c 576 * buffer registers (PATTB, PERB, and CCx). When writing to the buffer
Kojto 111:4336505e4b1c 577 * registers, the values are buffered and will be committed to effective
Kojto 111:4336505e4b1c 578 * registers on UPDATE condition.
Kojto 111:4336505e4b1c 579 *
Kojto 111:4336505e4b1c 580 * Usually the buffered value is cleared after it's committed, but there is also
Kojto 111:4336505e4b1c 581 * option to circular the register buffers. The period (PER) and four lowest
Kojto 111:4336505e4b1c 582 * compare channels register (CCx, x is 0 ~ 3) support this function. When
Kojto 111:4336505e4b1c 583 * circular buffer is used, on UPDATE the previous period or compare values are
Kojto 111:4336505e4b1c 584 * copied back into the corresponding period buffer and compare buffers.
Kojto 111:4336505e4b1c 585 * This way, the register value and its buffer register value is actually
Kojto 111:4336505e4b1c 586 * switched on UPDATE condition, and will be switched back on next UPDATE
Kojto 111:4336505e4b1c 587 * condition.
Kojto 111:4336505e4b1c 588 *
Kojto 111:4336505e4b1c 589 * For input capture, the buffer register (CCBx) and the corresponding capture
Kojto 111:4336505e4b1c 590 * channel register (CCx) act like a FIFO. When regular register (CCx) is empty
Kojto 111:4336505e4b1c 591 * or read, any content in the buffer register is passed to regular one.
Kojto 111:4336505e4b1c 592 *
Kojto 111:4336505e4b1c 593 * In TCC module driver, when the double buffering write is enabled, any
Kojto 111:4336505e4b1c 594 * write through \ref tcc_set_top_value(), \ref tcc_set_compare_value(), and
Kojto 111:4336505e4b1c 595 * \ref tcc_set_pattern() will be done to the corresponding buffer register.
Kojto 111:4336505e4b1c 596 * Then the value in the buffer register will be transferred to the regular
Kojto 111:4336505e4b1c 597 * register on the next UPDATE condition or by a force UPDATE using
Kojto 111:4336505e4b1c 598 * \ref tcc_force_double_buffer_update().
Kojto 111:4336505e4b1c 599 *
Kojto 111:4336505e4b1c 600 * \subsection asfdoc_sam0_tcc_module_overview_sleep Sleep Mode
Kojto 111:4336505e4b1c 601 *
Kojto 111:4336505e4b1c 602 * TCC modules can be configured to operate in any sleep mode, with its "run
Kojto 111:4336505e4b1c 603 * in standby" function enabled. It can wake up the device using interrupts or
Kojto 111:4336505e4b1c 604 * perform internal actions with the help of the Event System.
Kojto 111:4336505e4b1c 605 *
Kojto 111:4336505e4b1c 606 * \section asfdoc_sam0_tcc_special_considerations Special Considerations
Kojto 111:4336505e4b1c 607 *
Kojto 111:4336505e4b1c 608 * \subsection asfdoc_sam0_tcc_special_considerations_specific_features Driver Feature Macro Definition
Kojto 111:4336505e4b1c 609 * \ref asfdoc_sam0_tcc_feature_table "The table below" shows some specific features
Kojto 111:4336505e4b1c 610 * of the TCC Module.
Kojto 111:4336505e4b1c 611 *
Kojto 111:4336505e4b1c 612 * \anchor asfdoc_sam0_tcc_feature_table
Kojto 111:4336505e4b1c 613 * <table>
Kojto 111:4336505e4b1c 614 * <caption>TCC Module Specific Features</caption>
Kojto 111:4336505e4b1c 615 * <tr>
Kojto 111:4336505e4b1c 616 * <th>Driver Feature Macro</th>
Kojto 111:4336505e4b1c 617 * <th>Supported devices</th>
Kojto 111:4336505e4b1c 618 * </tr>
Kojto 111:4336505e4b1c 619 * <tr>
Kojto 111:4336505e4b1c 620 * <td>FEATURE_TCC_GENERATE_DMA_TRIGGER</td>
Kojto 111:4336505e4b1c 621 * <td>SAML21</td>
Kojto 111:4336505e4b1c 622 * </tr>
Kojto 111:4336505e4b1c 623 * </table>
Kojto 111:4336505e4b1c 624 *
Kojto 111:4336505e4b1c 625 * \note The specific features are only available in the driver when the
Kojto 111:4336505e4b1c 626 * selected device supports those features.
Kojto 111:4336505e4b1c 627 *
Kojto 111:4336505e4b1c 628 * \subsection asfdoc_sam0_tcc_special_considerations_tcc_feature Module Features
Kojto 111:4336505e4b1c 629 *
Kojto 111:4336505e4b1c 630 * The features of TCC, such as timer/counter size, number of compare capture
Kojto 111:4336505e4b1c 631 * channels, and number of outputs, are dependent on the TCC module instance being
Kojto 111:4336505e4b1c 632 * used.
Kojto 111:4336505e4b1c 633 *
Kojto 111:4336505e4b1c 634 * \subsubsection asfdoc_sam0_tcc_special_considerations_tcc_d21 SAM TCC Feature List
Kojto 111:4336505e4b1c 635 * For SAM D21/R21/L21/DAx/C21, the TCC features are:
Kojto 111:4336505e4b1c 636 * \anchor asfdoc_sam0_tcc_features_d21
Kojto 111:4336505e4b1c 637 * <table>
Kojto 111:4336505e4b1c 638 * <caption>TCC module features for SAM D21/R21/L21/DAx/C21</caption>
Kojto 111:4336505e4b1c 639 * <tr>
Kojto 111:4336505e4b1c 640 * <th>TCC#</th>
Kojto 111:4336505e4b1c 641 * <th>Match/Capture channels</th>
Kojto 111:4336505e4b1c 642 * <th>Wave outputs</th>
Kojto 111:4336505e4b1c 643 * <th>Counter size [bits]</th>
Kojto 111:4336505e4b1c 644 * <th>Fault</th>
Kojto 111:4336505e4b1c 645 * <th>Dithering</th>
Kojto 111:4336505e4b1c 646 * <th>Output matrix</th>
Kojto 111:4336505e4b1c 647 * <th>Dead-Time insertion</th>
Kojto 111:4336505e4b1c 648 * <th>SWAP</th>
Kojto 111:4336505e4b1c 649 * <th>Pattern</th>
Kojto 111:4336505e4b1c 650 * </tr>
Kojto 111:4336505e4b1c 651 * <tr>
Kojto 111:4336505e4b1c 652 * <td>0</td>
Kojto 111:4336505e4b1c 653 * <td>4</td>
Kojto 111:4336505e4b1c 654 * <td>8</td>
Kojto 111:4336505e4b1c 655 * <td>24</td>
Kojto 111:4336505e4b1c 656 * <td>Y</td>
Kojto 111:4336505e4b1c 657 * <td>Y</td>
Kojto 111:4336505e4b1c 658 * <td>Y</td>
Kojto 111:4336505e4b1c 659 * <td>Y</td>
Kojto 111:4336505e4b1c 660 * <td>Y</td>
Kojto 111:4336505e4b1c 661 * <td>Y</td>
Kojto 111:4336505e4b1c 662 * </tr>
Kojto 111:4336505e4b1c 663 * <tr>
Kojto 111:4336505e4b1c 664 * <td>1</td>
Kojto 111:4336505e4b1c 665 * <td>2</td>
Kojto 111:4336505e4b1c 666 * <td>4</td>
Kojto 111:4336505e4b1c 667 * <td>24</td>
Kojto 111:4336505e4b1c 668 * <td>Y</td>
Kojto 111:4336505e4b1c 669 * <td>Y</td>
Kojto 111:4336505e4b1c 670 * <td></td>
Kojto 111:4336505e4b1c 671 * <td></td>
Kojto 111:4336505e4b1c 672 * <td></td>
Kojto 111:4336505e4b1c 673 * <td>Y</td>
Kojto 111:4336505e4b1c 674 * </tr>
Kojto 111:4336505e4b1c 675 * <tr>
Kojto 111:4336505e4b1c 676 * <td>2</td>
Kojto 111:4336505e4b1c 677 * <td>2</td>
Kojto 111:4336505e4b1c 678 * <td>2</td>
Kojto 111:4336505e4b1c 679 * <td>16</td>
Kojto 111:4336505e4b1c 680 * <td>Y</td>
Kojto 111:4336505e4b1c 681 * <td></td>
Kojto 111:4336505e4b1c 682 * <td></td>
Kojto 111:4336505e4b1c 683 * <td></td>
Kojto 111:4336505e4b1c 684 * <td></td>
Kojto 111:4336505e4b1c 685 * <td></td>
Kojto 111:4336505e4b1c 686 * </tr>
Kojto 111:4336505e4b1c 687 * </table>
Kojto 111:4336505e4b1c 688 *
Kojto 111:4336505e4b1c 689 * \subsubsection asfdoc_sam0_tcc_special_considerations_tcc_d11 SAM D10/D11 TCC Feature List
Kojto 111:4336505e4b1c 690 * For SAM D10/D11, the TCC features are:
Kojto 111:4336505e4b1c 691 * \anchor asfdoc_sam0_tcc_features_d11
Kojto 111:4336505e4b1c 692 * <table>
Kojto 111:4336505e4b1c 693 * <caption>TCC Module Features For SAM D10/D11</caption>
Kojto 111:4336505e4b1c 694 * <tr>
Kojto 111:4336505e4b1c 695 * <th>TCC#</th>
Kojto 111:4336505e4b1c 696 * <th>Match/Capture channels</th>
Kojto 111:4336505e4b1c 697 * <th>Wave outputs</th>
Kojto 111:4336505e4b1c 698 * <th>Counter size [bits]</th>
Kojto 111:4336505e4b1c 699 * <th>Fault</th>
Kojto 111:4336505e4b1c 700 * <th>Dithering</th>
Kojto 111:4336505e4b1c 701 * <th>Output matrix</th>
Kojto 111:4336505e4b1c 702 * <th>Dead-Time insertion</th>
Kojto 111:4336505e4b1c 703 * <th>SWAP</th>
Kojto 111:4336505e4b1c 704 * <th>Pattern</th>
Kojto 111:4336505e4b1c 705 * </tr>
Kojto 111:4336505e4b1c 706 * <tr>
Kojto 111:4336505e4b1c 707 * <td>0</td>
Kojto 111:4336505e4b1c 708 * <td>4</td>
Kojto 111:4336505e4b1c 709 * <td>8</td>
Kojto 111:4336505e4b1c 710 * <td>24</td>
Kojto 111:4336505e4b1c 711 * <td>Y</td>
Kojto 111:4336505e4b1c 712 * <td>Y</td>
Kojto 111:4336505e4b1c 713 * <td>Y</td>
Kojto 111:4336505e4b1c 714 * <td>Y</td>
Kojto 111:4336505e4b1c 715 * <td>Y</td>
Kojto 111:4336505e4b1c 716 * <td>Y</td>
Kojto 111:4336505e4b1c 717 * </tr>
Kojto 111:4336505e4b1c 718 * </table>
Kojto 111:4336505e4b1c 719 *
Kojto 111:4336505e4b1c 720 * \subsection asfdoc_sam0_tcc_special_considerations_tcc_pin Channels vs. Pin outs
Kojto 111:4336505e4b1c 721 *
Kojto 111:4336505e4b1c 722 * As the TCC module may have more waveform output pins than the number of
Kojto 111:4336505e4b1c 723 * compare/capture channels, the free pins (with number higher than number of
Kojto 111:4336505e4b1c 724 * channels) will reuse the waveform generated by channels subsequently. E.g.,
Kojto 111:4336505e4b1c 725 * if the number of channels is four and the number of wave output pins is eight, channel
Kojto 111:4336505e4b1c 726 * 0 output will be available on out pin 0 and 4, channel 1 output
Kojto 111:4336505e4b1c 727 * on wave out pin 1 and 5, and so on.
Kojto 111:4336505e4b1c 728 *
Kojto 111:4336505e4b1c 729 * \section asfdoc_sam0_tcc_extra_info Extra Information
Kojto 111:4336505e4b1c 730 *
Kojto 111:4336505e4b1c 731 * For extra information, see \ref asfdoc_sam0_tcc_extra. This includes:
Kojto 111:4336505e4b1c 732 * - \ref asfdoc_sam0_tcc_extra_acronyms
Kojto 111:4336505e4b1c 733 * - \ref asfdoc_sam0_tcc_extra_dependencies
Kojto 111:4336505e4b1c 734 * - \ref asfdoc_sam0_tcc_extra_errata
Kojto 111:4336505e4b1c 735 * - \ref asfdoc_sam0_tcc_extra_history
Kojto 111:4336505e4b1c 736 *
Kojto 111:4336505e4b1c 737 *
Kojto 111:4336505e4b1c 738 * \section asfdoc_sam0_tcc_examples Examples
Kojto 111:4336505e4b1c 739 *
Kojto 111:4336505e4b1c 740 * For a list of examples related to this driver, see
Kojto 111:4336505e4b1c 741 * \ref asfdoc_sam0_tcc_exqsg.
Kojto 111:4336505e4b1c 742 *
Kojto 111:4336505e4b1c 743 * \section asfdoc_sam0_tcc_api_overview API Overview
Kojto 111:4336505e4b1c 744 * @{
Kojto 111:4336505e4b1c 745 */
Kojto 111:4336505e4b1c 746
Kojto 111:4336505e4b1c 747 #include <compiler.h>
Kojto 111:4336505e4b1c 748 #include <clock.h>
Kojto 111:4336505e4b1c 749 #include <gclk.h>
Kojto 111:4336505e4b1c 750 #include <pinmux.h>
Kojto 111:4336505e4b1c 751
Kojto 111:4336505e4b1c 752 /** Maximum number of channels supported by the driver
Kojto 111:4336505e4b1c 753 * (Channel index from 0 to \c TCC_NUM_CHANNELS - 1).
Kojto 111:4336505e4b1c 754 */
Kojto 111:4336505e4b1c 755 #define TCC_NUM_CHANNELS 4
Kojto 111:4336505e4b1c 756
Kojto 111:4336505e4b1c 757 /** Maximum number of wave outputs lines supported by the driver
Kojto 111:4336505e4b1c 758 * (Output line index from 0 to \c TCC_NUM_WAVE_OUTPUTS - 1).
Kojto 111:4336505e4b1c 759 */
Kojto 111:4336505e4b1c 760 #define TCC_NUM_WAVE_OUTPUTS 8
Kojto 111:4336505e4b1c 761
Kojto 111:4336505e4b1c 762 /** Maximum number of (recoverable) faults supported by the driver. */
Kojto 111:4336505e4b1c 763 #define TCC_NUM_FAULTS 2
Kojto 111:4336505e4b1c 764
Kojto 111:4336505e4b1c 765 #if TCC_ASYNC == true
Kojto 111:4336505e4b1c 766 # include <system_interrupt.h>
Kojto 111:4336505e4b1c 767 #endif
Kojto 111:4336505e4b1c 768
Kojto 111:4336505e4b1c 769 /**
Kojto 111:4336505e4b1c 770 * Define port features set according to different device family.
Kojto 111:4336505e4b1c 771 * @{
Kojto 111:4336505e4b1c 772 */
Kojto 111:4336505e4b1c 773 #if (SAML21) || defined(__DOXYGEN__)
Kojto 111:4336505e4b1c 774 /** Generate DMA triggers. */
Kojto 111:4336505e4b1c 775 # define FEATURE_TCC_GENERATE_DMA_TRIGGER
Kojto 111:4336505e4b1c 776 #endif
Kojto 111:4336505e4b1c 777 /*@}*/
Kojto 111:4336505e4b1c 778
Kojto 111:4336505e4b1c 779 #ifdef __cplusplus
Kojto 111:4336505e4b1c 780 extern "C" {
Kojto 111:4336505e4b1c 781 #endif
Kojto 111:4336505e4b1c 782
Kojto 111:4336505e4b1c 783 /* Generates a table enum list entry for a given type
Kojto 111:4336505e4b1c 784 and index (e.g. "TCC_CALLBACK_MC_CHANNEL_0,"). */
Kojto 111:4336505e4b1c 785 #define _TCC_ENUM(n, type) TCC_##type##_##n,
Kojto 111:4336505e4b1c 786
Kojto 111:4336505e4b1c 787 /* Generates table enum list entries for all channels of a
Kojto 111:4336505e4b1c 788 given type and channel number on TCC module. */
Kojto 111:4336505e4b1c 789 #define _TCC_CHANNEL_ENUM_LIST(type) \
Kojto 111:4336505e4b1c 790 MREPEAT(TCC_NUM_CHANNELS, _TCC_ENUM, type##_CHANNEL)
Kojto 111:4336505e4b1c 791 /* Generates table enum list entries for all output of a
Kojto 111:4336505e4b1c 792 given type and waveform output number on TCC module. */
Kojto 111:4336505e4b1c 793 #define _TCC_WO_ENUM_LIST(type) \
Kojto 111:4336505e4b1c 794 MREPEAT(TCC_NUM_WAVE_OUTPUTS, _TCC_ENUM, type)
Kojto 111:4336505e4b1c 795
Kojto 111:4336505e4b1c 796
Kojto 111:4336505e4b1c 797 #if TCC_ASYNC == true
Kojto 111:4336505e4b1c 798 /** Enum for the possible callback types for the TCC module. */
Kojto 111:4336505e4b1c 799 enum tcc_callback {
Kojto 111:4336505e4b1c 800 /** Callback for TCC overflow. */
Kojto 111:4336505e4b1c 801 TCC_CALLBACK_OVERFLOW,
Kojto 111:4336505e4b1c 802 /** Callback for TCC Retrigger. */
Kojto 111:4336505e4b1c 803 TCC_CALLBACK_RETRIGGER,
Kojto 111:4336505e4b1c 804 /** Callback for TCC counter event. */
Kojto 111:4336505e4b1c 805 TCC_CALLBACK_COUNTER_EVENT,
Kojto 111:4336505e4b1c 806 /** Callback for capture overflow error. */
Kojto 111:4336505e4b1c 807 TCC_CALLBACK_ERROR,
Kojto 111:4336505e4b1c 808 /** Callback for Recoverable Fault A. */
Kojto 111:4336505e4b1c 809 TCC_CALLBACK_FAULTA,
Kojto 111:4336505e4b1c 810 /** Callback for Recoverable Fault B. */
Kojto 111:4336505e4b1c 811 TCC_CALLBACK_FAULTB,
Kojto 111:4336505e4b1c 812 /** Callback for Non-Recoverable Fault 0. */
Kojto 111:4336505e4b1c 813 TCC_CALLBACK_FAULT0,
Kojto 111:4336505e4b1c 814 /** Callback for Non-Recoverable Fault 1. */
Kojto 111:4336505e4b1c 815 TCC_CALLBACK_FAULT1,
Kojto 111:4336505e4b1c 816
Kojto 111:4336505e4b1c 817 # if defined(__DOXYGEN__)
Kojto 111:4336505e4b1c 818 /** Channel callback type table for TCC
Kojto 111:4336505e4b1c 819 *
Kojto 111:4336505e4b1c 820 * Each TCC module may contain several callback types for channels; each
Kojto 111:4336505e4b1c 821 * channel will have its own callback type in the table, with the channel
Kojto 111:4336505e4b1c 822 * index number substituted for "n" in the channel callback type
Kojto 111:4336505e4b1c 823 * (e.g. \c TCC_MATCH_CAPTURE_CHANNEL_0).
Kojto 111:4336505e4b1c 824 */
Kojto 111:4336505e4b1c 825 TCC_CALLBACK_CHANNEL_n = n,
Kojto 111:4336505e4b1c 826 # else
Kojto 111:4336505e4b1c 827 /** Callbacks for Match/Capture channels, e.g., TCC_CALLBACK_CHANNEL_0. */
Kojto 111:4336505e4b1c 828 _TCC_CHANNEL_ENUM_LIST(CALLBACK)
Kojto 111:4336505e4b1c 829 # endif
Kojto 111:4336505e4b1c 830
Kojto 111:4336505e4b1c 831 # if !defined(__DOXYGEN__)
Kojto 111:4336505e4b1c 832 /** Number of available callbacks. */
Kojto 111:4336505e4b1c 833 TCC_CALLBACK_N
Kojto 111:4336505e4b1c 834 # endif
Kojto 111:4336505e4b1c 835 };
Kojto 111:4336505e4b1c 836 #endif /* #if TCC_ASYNC == true */
Kojto 111:4336505e4b1c 837
Kojto 111:4336505e4b1c 838 /**
Kojto 111:4336505e4b1c 839 * \name Module Status Flags
Kojto 111:4336505e4b1c 840 *
Kojto 111:4336505e4b1c 841 * TCC status flags, returned by \ref tcc_get_status() and cleared by
Kojto 111:4336505e4b1c 842 * \ref tcc_clear_status().
Kojto 111:4336505e4b1c 843 *
Kojto 111:4336505e4b1c 844 * @{
Kojto 111:4336505e4b1c 845 */
Kojto 111:4336505e4b1c 846
Kojto 111:4336505e4b1c 847 /** Timer channel \c ch (0 ~ 3) has matched against its compare value,
Kojto 111:4336505e4b1c 848 * or has captured a new value.
Kojto 111:4336505e4b1c 849 */
Kojto 111:4336505e4b1c 850 #define TCC_STATUS_CHANNEL_MATCH_CAPTURE(ch) (1UL << (ch))
Kojto 111:4336505e4b1c 851 /** Timer channel \c ch (0 ~ 3) match/compare output state. */
Kojto 111:4336505e4b1c 852 #define TCC_STATUS_CHANNEL_OUTPUT(ch) (1UL << ((ch)+8))
Kojto 111:4336505e4b1c 853 /** A Non-Recoverable Fault \c x (0 ~ 1) has occurred. */
Kojto 111:4336505e4b1c 854 #define TCC_STATUS_NON_RECOVERABLE_FAULT_OCCUR(x) (1UL << ((x)+16))
Kojto 111:4336505e4b1c 855 /** A Recoverable Fault \c n (0 ~ 1 representing A ~ B) has occured. */
Kojto 111:4336505e4b1c 856 #define TCC_STATUS_RECOVERABLE_FAULT_OCCUR(n) (1UL << ((n)+18))
Kojto 111:4336505e4b1c 857 /** The Non-Recoverable Fault \c x (0 ~ 1) input is present. */
Kojto 111:4336505e4b1c 858 #define TCC_STATUS_NON_RECOVERABLE_FAULT_PRESENT(x) (1UL << ((x)+20))
Kojto 111:4336505e4b1c 859 /** A Recoverable Fault \c n (0 ~ 1 representing A ~ B) is present. */
Kojto 111:4336505e4b1c 860 #define TCC_STATUS_RECOVERABLE_FAULT_PRESENT(n) (1UL << ((n)+22))
Kojto 111:4336505e4b1c 861 /** Timer registers synchronization has completed, and the synchronized count
Kojto 111:4336505e4b1c 862 * value may be read.
Kojto 111:4336505e4b1c 863 */
Kojto 111:4336505e4b1c 864 #define TCC_STATUS_SYNC_READY (1UL << 23)
Kojto 111:4336505e4b1c 865 /** A new value was captured before the previous value was read, resulting in
Kojto 111:4336505e4b1c 866 * lost data.
Kojto 111:4336505e4b1c 867 */
Kojto 111:4336505e4b1c 868 #define TCC_STATUS_CAPTURE_OVERFLOW (1UL << 24)
Kojto 111:4336505e4b1c 869 /** A counter event occurred. */
Kojto 111:4336505e4b1c 870 #define TCC_STATUS_COUNTER_EVENT (1UL << 25)
Kojto 111:4336505e4b1c 871 /** A counter retrigger occurred. */
Kojto 111:4336505e4b1c 872 #define TCC_STATUS_COUNTER_RETRIGGERED (1UL << 26)
Kojto 111:4336505e4b1c 873 /** The timer count value has overflowed from its maximum value to its minimum
Kojto 111:4336505e4b1c 874 * when counting upward, or from its minimum value to its maximum when
Kojto 111:4336505e4b1c 875 * counting downward.
Kojto 111:4336505e4b1c 876 */
Kojto 111:4336505e4b1c 877 #define TCC_STATUS_COUNT_OVERFLOW (1UL << 27)
Kojto 111:4336505e4b1c 878 /** Ramp period cycle index.
Kojto 111:4336505e4b1c 879 * In ramp operation, each two period cycles are marked as cycle A and B,
Kojto 111:4336505e4b1c 880 * the index 0 represents cycle A and 1 represents cycle B. */
Kojto 111:4336505e4b1c 881 #define TCC_STATUS_RAMP_CYCLE_INDEX (1UL << 28)
Kojto 111:4336505e4b1c 882 /** The counter has been stopped (due to disable, stop command or one-shot). */
Kojto 111:4336505e4b1c 883 #define TCC_STATUS_STOPPED (1UL << 29)
Kojto 111:4336505e4b1c 884
Kojto 111:4336505e4b1c 885 /** @} */
Kojto 111:4336505e4b1c 886
Kojto 111:4336505e4b1c 887 /**
Kojto 111:4336505e4b1c 888 * \brief Index of the match capture channels
Kojto 111:4336505e4b1c 889 *
Kojto 111:4336505e4b1c 890 * This enum is used to specify which capture/match channel to do
Kojto 111:4336505e4b1c 891 * operations on.
Kojto 111:4336505e4b1c 892 */
Kojto 111:4336505e4b1c 893 enum tcc_match_capture_channel {
Kojto 111:4336505e4b1c 894 # if defined(__DOXYGEN__)
Kojto 111:4336505e4b1c 895 /** Match capture channel index table for TCC
Kojto 111:4336505e4b1c 896 *
Kojto 111:4336505e4b1c 897 * Each TCC module may contain several match capture channels; each channel
Kojto 111:4336505e4b1c 898 * will have its own index in the table, with the index number substituted
Kojto 111:4336505e4b1c 899 * for "n" in the index name (e.g. \c TCC_MATCH_CAPTURE_CHANNEL_0).
Kojto 111:4336505e4b1c 900 */
Kojto 111:4336505e4b1c 901 TCC_MATCH_CAPTURE_CHANNEL_n = n,
Kojto 111:4336505e4b1c 902 # else
Kojto 111:4336505e4b1c 903 /** Indexes of match capture channels, e.g., TCC_MATCH_CAPTURE_CHANNEL_0. */
Kojto 111:4336505e4b1c 904 _TCC_CHANNEL_ENUM_LIST(MATCH_CAPTURE)
Kojto 111:4336505e4b1c 905 # endif
Kojto 111:4336505e4b1c 906 # if !defined(__DOXYGEN__)
Kojto 111:4336505e4b1c 907 /** Number of supported channels. */
Kojto 111:4336505e4b1c 908 TCC_MATCH_CAPTURE_CHANNEL_N
Kojto 111:4336505e4b1c 909 # endif
Kojto 111:4336505e4b1c 910 };
Kojto 111:4336505e4b1c 911
Kojto 111:4336505e4b1c 912 /**
Kojto 111:4336505e4b1c 913 * \brief Index of the wave outputs
Kojto 111:4336505e4b1c 914 *
Kojto 111:4336505e4b1c 915 * This enum is used to specify which wave output to do
Kojto 111:4336505e4b1c 916 * operations on.
Kojto 111:4336505e4b1c 917 */
Kojto 111:4336505e4b1c 918 enum tcc_wave_output {
Kojto 111:4336505e4b1c 919 # if defined(__DOXYGEN__)
Kojto 111:4336505e4b1c 920 /** Waveform output index table for TCC
Kojto 111:4336505e4b1c 921 *
Kojto 111:4336505e4b1c 922 * Each TCC module may contain several wave outputs; each output
Kojto 111:4336505e4b1c 923 * will have its own index in the table, with the index number substituted
Kojto 111:4336505e4b1c 924 * for "n" in the index name (e.g. \c TCC_WAVE_OUTPUT_0).
Kojto 111:4336505e4b1c 925 */
Kojto 111:4336505e4b1c 926 TCC_WAVE_OUTPUT_n = n,
Kojto 111:4336505e4b1c 927 # else
Kojto 111:4336505e4b1c 928 /** Indexes of match capture channels, e.g., TCC_WAVEFORM_OUTPUT_0. */
Kojto 111:4336505e4b1c 929 _TCC_WO_ENUM_LIST(WAVE_OUTPUT)
Kojto 111:4336505e4b1c 930 # endif
Kojto 111:4336505e4b1c 931 # if !defined(__DOXYGEN__)
Kojto 111:4336505e4b1c 932 /** Number of supported channels. */
Kojto 111:4336505e4b1c 933 TCC_WAVE_OUTPUT_N
Kojto 111:4336505e4b1c 934 # endif
Kojto 111:4336505e4b1c 935 };
Kojto 111:4336505e4b1c 936
Kojto 111:4336505e4b1c 937 /**
Kojto 111:4336505e4b1c 938 * \brief TCC wave generation mode enum
Kojto 111:4336505e4b1c 939 *
Kojto 111:4336505e4b1c 940 * This enum is used to specify the waveform generation mode.
Kojto 111:4336505e4b1c 941 *
Kojto 111:4336505e4b1c 942 */
Kojto 111:4336505e4b1c 943 enum tcc_wave_generation {
Kojto 111:4336505e4b1c 944 /** Normal Frequency: Top is the PER register, output toggled on each
Kojto 111:4336505e4b1c 945 * compare match. */
Kojto 111:4336505e4b1c 946 TCC_WAVE_GENERATION_NORMAL_FREQ = 0,
Kojto 111:4336505e4b1c 947 /** Match Frequency: Top is CC0 register, output toggles on each update
Kojto 111:4336505e4b1c 948 * condition. */
Kojto 111:4336505e4b1c 949 TCC_WAVE_GENERATION_MATCH_FREQ = 1,
Kojto 111:4336505e4b1c 950 /** Single-Slope PWM: Top is the PER register, CCx controls duty cycle (
Kojto 111:4336505e4b1c 951 * output active when count is greater than CCx). */
Kojto 111:4336505e4b1c 952 TCC_WAVE_GENERATION_SINGLE_SLOPE_PWM = 2,
Kojto 111:4336505e4b1c 953
Kojto 111:4336505e4b1c 954 /** Double-slope (count up and down), non centre-aligned: Top is the PER
Kojto 111:4336505e4b1c 955 * register, CC[x] controls duty cycle while counting up and CC[x+N/2]
Kojto 111:4336505e4b1c 956 * controls it while counting down. */
Kojto 111:4336505e4b1c 957 TCC_WAVE_GENERATION_DOUBLE_SLOPE_CRITICAL = 4,
Kojto 111:4336505e4b1c 958 /** Double-slope (count up and down), interrupt/event at Bottom (Top is the
Kojto 111:4336505e4b1c 959 * PER register, output active when count is greater than CCx). */
Kojto 111:4336505e4b1c 960 TCC_WAVE_GENERATION_DOUBLE_SLOPE_BOTTOM = 5,
Kojto 111:4336505e4b1c 961 /** Double-slope (count up and down), interrupt/event at Bottom and Top: (Top is the
Kojto 111:4336505e4b1c 962 * PER register, output active when count is lower than CCx). */
Kojto 111:4336505e4b1c 963 TCC_WAVE_GENERATION_DOUBLE_SLOPE_BOTH = 6,
Kojto 111:4336505e4b1c 964 /** Double-slope (count up and down), interrupt/event at Top (Top is the
Kojto 111:4336505e4b1c 965 * PER register, output active when count is greater than CCx). */
Kojto 111:4336505e4b1c 966 TCC_WAVE_GENERATION_DOUBLE_SLOPE_TOP = 7,
Kojto 111:4336505e4b1c 967 };
Kojto 111:4336505e4b1c 968
Kojto 111:4336505e4b1c 969 /**
Kojto 111:4336505e4b1c 970 * \brief Polarity of TCC wave generation on channels
Kojto 111:4336505e4b1c 971 *
Kojto 111:4336505e4b1c 972 * Specifies whether the wave output needs to be inverted or not.
Kojto 111:4336505e4b1c 973 */
Kojto 111:4336505e4b1c 974 enum tcc_wave_polarity {
Kojto 111:4336505e4b1c 975 /** Wave output is not inverted. */
Kojto 111:4336505e4b1c 976 TCC_WAVE_POLARITY_0,
Kojto 111:4336505e4b1c 977 /** Wave output is inverted. */
Kojto 111:4336505e4b1c 978 TCC_WAVE_POLARITY_1
Kojto 111:4336505e4b1c 979 };
Kojto 111:4336505e4b1c 980
Kojto 111:4336505e4b1c 981 /**
Kojto 111:4336505e4b1c 982 * \brief TCC pattern generator for outputs
Kojto 111:4336505e4b1c 983 *
Kojto 111:4336505e4b1c 984 * Used when disabling output pattern or when selecting a specific pattern.
Kojto 111:4336505e4b1c 985 */
Kojto 111:4336505e4b1c 986 enum tcc_output_pattern {
Kojto 111:4336505e4b1c 987 /** SWAP output pattern is not used. */
Kojto 111:4336505e4b1c 988 TCC_OUTPUT_PATTERN_DISABLE,
Kojto 111:4336505e4b1c 989 /** Pattern 0 is applied to SWAP output. */
Kojto 111:4336505e4b1c 990 TCC_OUTPUT_PATTERN_0,
Kojto 111:4336505e4b1c 991 /** Pattern 1 is applied to SWAP output. */
Kojto 111:4336505e4b1c 992 TCC_OUTPUT_PATTERN_1
Kojto 111:4336505e4b1c 993 };
Kojto 111:4336505e4b1c 994
Kojto 111:4336505e4b1c 995 /**
Kojto 111:4336505e4b1c 996 * \brief Ramp Operations which are supported in single-slope PWM generation
Kojto 111:4336505e4b1c 997 *
Kojto 111:4336505e4b1c 998 * Ramp operations which are supported in single-slope PWM generation.
Kojto 111:4336505e4b1c 999 */
Kojto 111:4336505e4b1c 1000 enum tcc_ramp {
Kojto 111:4336505e4b1c 1001 /** Default timer/counter PWM operation. */
Kojto 111:4336505e4b1c 1002 TCC_RAMP_RAMP1 = 0,
Kojto 111:4336505e4b1c 1003
Kojto 111:4336505e4b1c 1004 /** Uses a single channel (CC0) to control both CC0/CC1 compare outputs.
Kojto 111:4336505e4b1c 1005 * In cycle A, the channel 0 output is disabled, and
Kojto 111:4336505e4b1c 1006 * in cycle B, the channel 1 output is disabled. */
Kojto 111:4336505e4b1c 1007 TCC_RAMP_RAMP2A,
Kojto 111:4336505e4b1c 1008
Kojto 111:4336505e4b1c 1009 /** Uses channels CC0 and CC1 to control compare outputs.
Kojto 111:4336505e4b1c 1010 * In cycle A, the channel 0 output is disabled, and
Kojto 111:4336505e4b1c 1011 * in cycle B, the channel 1 output is disabled.*/
Kojto 111:4336505e4b1c 1012 TCC_RAMP_RAMP2
Kojto 111:4336505e4b1c 1013 };
Kojto 111:4336505e4b1c 1014
Kojto 111:4336505e4b1c 1015 /**
Kojto 111:4336505e4b1c 1016 * \brief Ramp Index for TCC wave generation
Kojto 111:4336505e4b1c 1017 *
Kojto 111:4336505e4b1c 1018 * In ramp operation, each two period cycles are marked as cycle A and B,
Kojto 111:4336505e4b1c 1019 * the index 0 represents cycle A and 1 represents cycle B.
Kojto 111:4336505e4b1c 1020 */
Kojto 111:4336505e4b1c 1021 enum tcc_ramp_index {
Kojto 111:4336505e4b1c 1022 /** Default, cycle index toggles. */
Kojto 111:4336505e4b1c 1023 TCC_RAMP_INDEX_DEFAULT,
Kojto 111:4336505e4b1c 1024 /** Force next cycle to be cycle B (set to 1). */
Kojto 111:4336505e4b1c 1025 TCC_RAMP_INDEX_FORCE_B,
Kojto 111:4336505e4b1c 1026 /** Force next cycle to be cycle A (clear to 0). */
Kojto 111:4336505e4b1c 1027 TCC_RAMP_INDEX_FORCE_A,
Kojto 111:4336505e4b1c 1028 /** Force next cycle keeping the same as current. */
Kojto 111:4336505e4b1c 1029 TCC_RAMP_INDEX_FORCE_KEEP
Kojto 111:4336505e4b1c 1030 };
Kojto 111:4336505e4b1c 1031
Kojto 111:4336505e4b1c 1032 /**
Kojto 111:4336505e4b1c 1033 * \brief TCC output inversion
Kojto 111:4336505e4b1c 1034 *
Kojto 111:4336505e4b1c 1035 * Used when enabling or disabling output inversion.
Kojto 111:4336505e4b1c 1036 */
Kojto 111:4336505e4b1c 1037 enum tcc_output_invertion {
Kojto 111:4336505e4b1c 1038 /** Output inversion not to be enabled. */
Kojto 111:4336505e4b1c 1039 TCC_OUTPUT_INVERTION_DISABLE,
Kojto 111:4336505e4b1c 1040 /** Invert the output from WO[x]. */
Kojto 111:4336505e4b1c 1041 TCC_OUTPUT_INVERTION_ENABLE
Kojto 111:4336505e4b1c 1042 };
Kojto 111:4336505e4b1c 1043
Kojto 111:4336505e4b1c 1044 /**
Kojto 111:4336505e4b1c 1045 * \brief TCC Counter reload action enum
Kojto 111:4336505e4b1c 1046 *
Kojto 111:4336505e4b1c 1047 * This enum specify how the counter is reloaded and whether the prescaler
Kojto 111:4336505e4b1c 1048 * should be restarted.
Kojto 111:4336505e4b1c 1049 */
Kojto 111:4336505e4b1c 1050 enum tcc_reload_action {
Kojto 111:4336505e4b1c 1051 /** The counter is reloaded/reset on the next GCLK and starts
Kojto 111:4336505e4b1c 1052 * counting on the prescaler clock.
Kojto 111:4336505e4b1c 1053 */
Kojto 111:4336505e4b1c 1054 TCC_RELOAD_ACTION_GCLK,
Kojto 111:4336505e4b1c 1055 /** The counter is reloaded/reset on the next prescaler clock.
Kojto 111:4336505e4b1c 1056 */
Kojto 111:4336505e4b1c 1057 TCC_RELOAD_ACTION_PRESC,
Kojto 111:4336505e4b1c 1058 /** The counter is reloaded/reset on the next GCLK, and the
Kojto 111:4336505e4b1c 1059 * prescaler is restarted as well.
Kojto 111:4336505e4b1c 1060 */
Kojto 111:4336505e4b1c 1061 TCC_RELOAD_ACTION_RESYNC
Kojto 111:4336505e4b1c 1062 };
Kojto 111:4336505e4b1c 1063
Kojto 111:4336505e4b1c 1064
Kojto 111:4336505e4b1c 1065 /**
Kojto 111:4336505e4b1c 1066 * \brief TCC clock prescaler values
Kojto 111:4336505e4b1c 1067 *
Kojto 111:4336505e4b1c 1068 * This enum is used to choose the clock prescaler
Kojto 111:4336505e4b1c 1069 * configuration. The prescaler divides the clock frequency of the TCC
Kojto 111:4336505e4b1c 1070 * module to operate TCC at a slower clock rate.
Kojto 111:4336505e4b1c 1071 */
Kojto 111:4336505e4b1c 1072 enum tcc_clock_prescaler {
Kojto 111:4336505e4b1c 1073 /** Divide clock by 1. */
Kojto 111:4336505e4b1c 1074 TCC_CLOCK_PRESCALER_DIV1,
Kojto 111:4336505e4b1c 1075 /** Divide clock by 2. */
Kojto 111:4336505e4b1c 1076 TCC_CLOCK_PRESCALER_DIV2,
Kojto 111:4336505e4b1c 1077 /** Divide clock by 4. */
Kojto 111:4336505e4b1c 1078 TCC_CLOCK_PRESCALER_DIV4,
Kojto 111:4336505e4b1c 1079 /** Divide clock by 8. */
Kojto 111:4336505e4b1c 1080 TCC_CLOCK_PRESCALER_DIV8,
Kojto 111:4336505e4b1c 1081 /** Divide clock by 16. */
Kojto 111:4336505e4b1c 1082 TCC_CLOCK_PRESCALER_DIV16,
Kojto 111:4336505e4b1c 1083 /** Divide clock by 64. */
Kojto 111:4336505e4b1c 1084 TCC_CLOCK_PRESCALER_DIV64,
Kojto 111:4336505e4b1c 1085 /** Divide clock by 256. */
Kojto 111:4336505e4b1c 1086 TCC_CLOCK_PRESCALER_DIV256,
Kojto 111:4336505e4b1c 1087 /** Divide clock by 1024. */
Kojto 111:4336505e4b1c 1088 TCC_CLOCK_PRESCALER_DIV1024
Kojto 111:4336505e4b1c 1089 };
Kojto 111:4336505e4b1c 1090
Kojto 111:4336505e4b1c 1091 /**
Kojto 111:4336505e4b1c 1092 * \brief TCC module count direction
Kojto 111:4336505e4b1c 1093 *
Kojto 111:4336505e4b1c 1094 * Used when selecting the Timer/Counter count direction.
Kojto 111:4336505e4b1c 1095 */
Kojto 111:4336505e4b1c 1096 enum tcc_count_direction {
Kojto 111:4336505e4b1c 1097 /** Timer should count upward. */
Kojto 111:4336505e4b1c 1098 TCC_COUNT_DIRECTION_UP,
Kojto 111:4336505e4b1c 1099 /** Timer should count downward. */
Kojto 111:4336505e4b1c 1100 TCC_COUNT_DIRECTION_DOWN,
Kojto 111:4336505e4b1c 1101 };
Kojto 111:4336505e4b1c 1102
Kojto 111:4336505e4b1c 1103 /**
Kojto 111:4336505e4b1c 1104 * \brief Action to perform when the TCC module is triggered by events
Kojto 111:4336505e4b1c 1105 *
Kojto 111:4336505e4b1c 1106 * Event action to perform when the module is triggered by events.
Kojto 111:4336505e4b1c 1107 */
Kojto 111:4336505e4b1c 1108 enum tcc_event_action {
Kojto 111:4336505e4b1c 1109 /** No event action. */
Kojto 111:4336505e4b1c 1110 TCC_EVENT_ACTION_OFF,
Kojto 111:4336505e4b1c 1111 /** Stop counting, the counter will maintain its current value, waveforms
Kojto 111:4336505e4b1c 1112 * are set to a defined Non-Recoverable State output
Kojto 111:4336505e4b1c 1113 * (\ref tcc_non_recoverable_state_output). */
Kojto 111:4336505e4b1c 1114 TCC_EVENT_ACTION_STOP,
Kojto 111:4336505e4b1c 1115 /** Re-trigger counter on event, may generate an event if the re-trigger
Kojto 111:4336505e4b1c 1116 * event output is enabled.
Kojto 111:4336505e4b1c 1117 * \note When re-trigger event action is enabled, enabling the counter
Kojto 111:4336505e4b1c 1118 * will not start until the next incoming event appears. */
Kojto 111:4336505e4b1c 1119 TCC_EVENT_ACTION_RETRIGGER,
Kojto 111:4336505e4b1c 1120
Kojto 111:4336505e4b1c 1121 /** Start counter when previously stopped.
Kojto 111:4336505e4b1c 1122 * Start counting on the event rising edge. Further events will not
Kojto 111:4336505e4b1c 1123 * restart the counter;
Kojto 111:4336505e4b1c 1124 * the counter keeps on counting using prescaled GCLK_TCCx, until it
Kojto 111:4336505e4b1c 1125 * reaches TOP or Zero
Kojto 111:4336505e4b1c 1126 * depending on the direction. */
Kojto 111:4336505e4b1c 1127 TCC_EVENT_ACTION_START,
Kojto 111:4336505e4b1c 1128 /** Count events; i.e. Increment or decrement depending on count
Kojto 111:4336505e4b1c 1129 * direction. */
Kojto 111:4336505e4b1c 1130 TCC_EVENT_ACTION_COUNT_EVENT,
Kojto 111:4336505e4b1c 1131 /** The event source must be an asynchronous event, input value will
Kojto 111:4336505e4b1c 1132 * overrides the direction settings (input low: counting up, input high
Kojto 111:4336505e4b1c 1133 * counting down). */
Kojto 111:4336505e4b1c 1134 TCC_EVENT_ACTION_DIR_CONTROL,
Kojto 111:4336505e4b1c 1135 /** Increment the counter on event, irrespective of count direction. */
Kojto 111:4336505e4b1c 1136 TCC_EVENT_ACTION_INCREMENT,
Kojto 111:4336505e4b1c 1137 /** Decrement the counter on event, irrespective of count direction. */
Kojto 111:4336505e4b1c 1138 TCC_EVENT_ACTION_DECREMENT,
Kojto 111:4336505e4b1c 1139 /** Count during active state of asynchronous event. In this case,
Kojto 111:4336505e4b1c 1140 * depending on the count direction, the count will be incremented
Kojto 111:4336505e4b1c 1141 * or decremented on each prescaled GCLK_TCCx, as long as the input
Kojto 111:4336505e4b1c 1142 * event remains active. */
Kojto 111:4336505e4b1c 1143 TCC_EVENT_ACTION_COUNT_DURING_ACTIVE,
Kojto 111:4336505e4b1c 1144
Kojto 111:4336505e4b1c 1145 /** Store period in capture register 0, pulse width in capture
Kojto 111:4336505e4b1c 1146 * register 1.
Kojto 111:4336505e4b1c 1147 */
Kojto 111:4336505e4b1c 1148 TCC_EVENT_ACTION_PERIOD_PULSE_WIDTH_CAPTURE,
Kojto 111:4336505e4b1c 1149 /** Store pulse width in capture register 0, period in capture
Kojto 111:4336505e4b1c 1150 * register 1.
Kojto 111:4336505e4b1c 1151 */
Kojto 111:4336505e4b1c 1152 TCC_EVENT_ACTION_PULSE_WIDTH_PERIOD_CAPTURE,
Kojto 111:4336505e4b1c 1153
Kojto 111:4336505e4b1c 1154 /** Generate Non-Recoverable Fault on event. */
Kojto 111:4336505e4b1c 1155 TCC_EVENT_ACTION_NON_RECOVERABLE_FAULT,
Kojto 111:4336505e4b1c 1156 };
Kojto 111:4336505e4b1c 1157
Kojto 111:4336505e4b1c 1158
Kojto 111:4336505e4b1c 1159 /**
Kojto 111:4336505e4b1c 1160 * \brief Action to be performed when the TCC module is triggered by event0
Kojto 111:4336505e4b1c 1161 *
Kojto 111:4336505e4b1c 1162 * Event action to perform when the module is triggered by event0.
Kojto 111:4336505e4b1c 1163 */
Kojto 111:4336505e4b1c 1164 enum tcc_event0_action {
Kojto 111:4336505e4b1c 1165 /** No event action. */
Kojto 111:4336505e4b1c 1166 TCC_EVENT0_ACTION_OFF = TCC_EVENT_ACTION_OFF,
Kojto 111:4336505e4b1c 1167 /** Re-trigger Counter on event. */
Kojto 111:4336505e4b1c 1168 TCC_EVENT0_ACTION_RETRIGGER = TCC_EVENT_ACTION_RETRIGGER,
Kojto 111:4336505e4b1c 1169 /** Count events (increment or decrement, depending on count direction).
Kojto 111:4336505e4b1c 1170 */
Kojto 111:4336505e4b1c 1171 TCC_EVENT0_ACTION_COUNT_EVENT = TCC_EVENT_ACTION_COUNT_EVENT,
Kojto 111:4336505e4b1c 1172 /** Start counter on event. */
Kojto 111:4336505e4b1c 1173 TCC_EVENT0_ACTION_START = TCC_EVENT_ACTION_START,
Kojto 111:4336505e4b1c 1174 /** Increment counter on event. */
Kojto 111:4336505e4b1c 1175 TCC_EVENT0_ACTION_INCREMENT = TCC_EVENT_ACTION_INCREMENT,
Kojto 111:4336505e4b1c 1176 /** Count during active state of asynchronous event. */
Kojto 111:4336505e4b1c 1177 TCC_EVENT0_ACTION_COUNT_DURING_ACTIVE = TCC_EVENT_ACTION_COUNT_DURING_ACTIVE,
Kojto 111:4336505e4b1c 1178
Kojto 111:4336505e4b1c 1179 /** Generate Non-Recoverable Fault on event. */
Kojto 111:4336505e4b1c 1180 TCC_EVENT0_ACTION_NON_RECOVERABLE_FAULT = TCC_EVENT_ACTION_NON_RECOVERABLE_FAULT
Kojto 111:4336505e4b1c 1181 };
Kojto 111:4336505e4b1c 1182
Kojto 111:4336505e4b1c 1183 /**
Kojto 111:4336505e4b1c 1184 * \brief Action to perform when the TCC module is triggered by event1
Kojto 111:4336505e4b1c 1185 *
Kojto 111:4336505e4b1c 1186 * Event action to perform when the module is triggered by event1.
Kojto 111:4336505e4b1c 1187 */
Kojto 111:4336505e4b1c 1188 enum tcc_event1_action {
Kojto 111:4336505e4b1c 1189 /** No event action. */
Kojto 111:4336505e4b1c 1190 TCC_EVENT1_ACTION_OFF = TCC_EVENT_ACTION_OFF,
Kojto 111:4336505e4b1c 1191 /** Re-trigger Counter on event. */
Kojto 111:4336505e4b1c 1192 TCC_EVENT1_ACTION_RETRIGGER = TCC_EVENT_ACTION_RETRIGGER,
Kojto 111:4336505e4b1c 1193 /** The event source must be an asynchronous event, input value will
Kojto 111:4336505e4b1c 1194 * override the direction settings.
Kojto 111:4336505e4b1c 1195 * If TCEINVx is 0 and input event is LOW: counter will count up.
Kojto 111:4336505e4b1c 1196 * If TCEINVx is 0 and input event is HIGH: counter will count down.
Kojto 111:4336505e4b1c 1197 */
Kojto 111:4336505e4b1c 1198 TCC_EVENT1_ACTION_DIR_CONTROL = TCC_EVENT_ACTION_DIR_CONTROL,
Kojto 111:4336505e4b1c 1199 /** Stop counter on event. */
Kojto 111:4336505e4b1c 1200 TCC_EVENT1_ACTION_STOP = TCC_EVENT_ACTION_STOP,
Kojto 111:4336505e4b1c 1201 /** Decrement on event. */
Kojto 111:4336505e4b1c 1202 TCC_EVENT1_ACTION_DECREMENT = TCC_EVENT_ACTION_DECREMENT,
Kojto 111:4336505e4b1c 1203
Kojto 111:4336505e4b1c 1204 /** Store period in capture register 0, pulse width in capture
Kojto 111:4336505e4b1c 1205 * register 1.
Kojto 111:4336505e4b1c 1206 */
Kojto 111:4336505e4b1c 1207 TCC_EVENT1_ACTION_PERIOD_PULSE_WIDTH_CAPTURE = TCC_EVENT_ACTION_PERIOD_PULSE_WIDTH_CAPTURE,
Kojto 111:4336505e4b1c 1208 /** Store pulse width in capture register 0, period in capture
Kojto 111:4336505e4b1c 1209 * register 1.
Kojto 111:4336505e4b1c 1210 */
Kojto 111:4336505e4b1c 1211 TCC_EVENT1_ACTION_PULSE_WIDTH_PERIOD_CAPTURE = TCC_EVENT_ACTION_PULSE_WIDTH_PERIOD_CAPTURE,
Kojto 111:4336505e4b1c 1212
Kojto 111:4336505e4b1c 1213 /** Generate Non-Recoverable Fault on event. */
Kojto 111:4336505e4b1c 1214 TCC_EVENT1_ACTION_NON_RECOVERABLE_FAULT = TCC_EVENT_ACTION_NON_RECOVERABLE_FAULT
Kojto 111:4336505e4b1c 1215 };
Kojto 111:4336505e4b1c 1216
Kojto 111:4336505e4b1c 1217 /**
Kojto 111:4336505e4b1c 1218 * \brief On which part of the counter cycle the counter event output is generated
Kojto 111:4336505e4b1c 1219 *
Kojto 111:4336505e4b1c 1220 * This enum is used to define the point at which the counter event is generated.
Kojto 111:4336505e4b1c 1221 */
Kojto 111:4336505e4b1c 1222 enum tcc_event_generation_selection {
Kojto 111:4336505e4b1c 1223 /** Counter Event is generated when a new counter cycle starts. */
Kojto 111:4336505e4b1c 1224 TCC_EVENT_GENERATION_SELECTION_START,
Kojto 111:4336505e4b1c 1225 /** Counter Event is generated when a counter cycle ends. */
Kojto 111:4336505e4b1c 1226 TCC_EVENT_GENERATION_SELECTION_END,
Kojto 111:4336505e4b1c 1227 /** Counter Event is generated when a counter cycle ends, except for the
Kojto 111:4336505e4b1c 1228 * first and last cycles. */
Kojto 111:4336505e4b1c 1229 TCC_EVENT_GENERATION_SELECTION_BETWEEN,
Kojto 111:4336505e4b1c 1230 /** Counter Event is generated when a new counter cycle starts or ends. */
Kojto 111:4336505e4b1c 1231 TCC_EVENT_GENERATION_SELECTION_BOUNDARY
Kojto 111:4336505e4b1c 1232 };
Kojto 111:4336505e4b1c 1233
Kojto 111:4336505e4b1c 1234 /**
Kojto 111:4336505e4b1c 1235 * \brief TCC channel operation modes
Kojto 111:4336505e4b1c 1236 *
Kojto 111:4336505e4b1c 1237 * To set a timer channel either in compare or in capture mode.
Kojto 111:4336505e4b1c 1238 */
Kojto 111:4336505e4b1c 1239 enum tcc_channel_function {
Kojto 111:4336505e4b1c 1240 /** TCC channel performs compare operation. */
Kojto 111:4336505e4b1c 1241 TCC_CHANNEL_FUNCTION_COMPARE,
Kojto 111:4336505e4b1c 1242 /** TCC channel performs capture operation. */
Kojto 111:4336505e4b1c 1243 TCC_CHANNEL_FUNCTION_CAPTURE
Kojto 111:4336505e4b1c 1244 };
Kojto 111:4336505e4b1c 1245
Kojto 111:4336505e4b1c 1246 /**
Kojto 111:4336505e4b1c 1247 * \brief TCC (recoverable) fault Halt action
Kojto 111:4336505e4b1c 1248 */
Kojto 111:4336505e4b1c 1249 enum tcc_fault_halt_action {
Kojto 111:4336505e4b1c 1250 /** Halt action disabled. */
Kojto 111:4336505e4b1c 1251 TCC_FAULT_HALT_ACTION_DISABLE,
Kojto 111:4336505e4b1c 1252 /** Hardware halt action, counter is halted until restart. */
Kojto 111:4336505e4b1c 1253 TCC_FAULT_HALT_ACTION_HW_HALT,
Kojto 111:4336505e4b1c 1254 /** Software halt action, counter is halted until fault bit cleared. */
Kojto 111:4336505e4b1c 1255 TCC_FAULT_HALT_ACTION_SW_HALT,
Kojto 111:4336505e4b1c 1256 /** Non-Recoverable fault, force output to pre-defined level. */
Kojto 111:4336505e4b1c 1257 TCC_FAULT_HALT_ACTION_NON_RECOVERABLE
Kojto 111:4336505e4b1c 1258 };
Kojto 111:4336505e4b1c 1259
Kojto 111:4336505e4b1c 1260 /**
Kojto 111:4336505e4b1c 1261 * \brief TCC (recoverable) fault Capture action
Kojto 111:4336505e4b1c 1262 */
Kojto 111:4336505e4b1c 1263 enum tcc_fault_capture_action {
Kojto 111:4336505e4b1c 1264 /** Capture disabled. */
Kojto 111:4336505e4b1c 1265 TCC_FAULT_CAPTURE_DISABLE,
Kojto 111:4336505e4b1c 1266 /** Capture on Fault, each value is captured. */
Kojto 111:4336505e4b1c 1267 TCC_FAULT_CAPTURE_EACH,
Kojto 111:4336505e4b1c 1268 /** Capture the minimum detection, but notify on smaller ones. */
Kojto 111:4336505e4b1c 1269 TCC_FAULT_CAPTURE_MINIMUM,
Kojto 111:4336505e4b1c 1270 /** Capture the maximum detection, but notify on bigger ones. */
Kojto 111:4336505e4b1c 1271 TCC_FAULT_CAPTURE_MAXIMUM,
Kojto 111:4336505e4b1c 1272 /** Capture if the value is smaller than last, notify event or interrupt
Kojto 111:4336505e4b1c 1273 * if previous stamp is confirmed to be "local minimum" (not bigger than
Kojto 111:4336505e4b1c 1274 * current stamp). */
Kojto 111:4336505e4b1c 1275 TCC_FAULT_CAPTURE_SMALLER,
Kojto 111:4336505e4b1c 1276 /** Capture if the value is bigger than last, notify event or interrupt
Kojto 111:4336505e4b1c 1277 * if previous stamp is confirmed to be "local maximum" (not smaller than
Kojto 111:4336505e4b1c 1278 * current stamp). */
Kojto 111:4336505e4b1c 1279 TCC_FAULT_CAPTURE_BIGGER,
Kojto 111:4336505e4b1c 1280 /** Capture if the time stamps changes its increment direction. */
Kojto 111:4336505e4b1c 1281 TCC_FAULT_CAPTURE_CHANGE
Kojto 111:4336505e4b1c 1282 };
Kojto 111:4336505e4b1c 1283
Kojto 111:4336505e4b1c 1284 /**
Kojto 111:4336505e4b1c 1285 * \brief Capture Channel triggered by TCC (recoverable) fault
Kojto 111:4336505e4b1c 1286 */
Kojto 111:4336505e4b1c 1287 enum tcc_fault_capture_channel {
Kojto 111:4336505e4b1c 1288 /** Recoverable fault triggers channel 0 capture operation. */
Kojto 111:4336505e4b1c 1289 TCC_FAULT_CAPTURE_CHANNEL_0,
Kojto 111:4336505e4b1c 1290 /** Recoverable fault triggers channel 1 capture operation. */
Kojto 111:4336505e4b1c 1291 TCC_FAULT_CAPTURE_CHANNEL_1,
Kojto 111:4336505e4b1c 1292 /** Recoverable fault triggers channel 2 capture operation. */
Kojto 111:4336505e4b1c 1293 TCC_FAULT_CAPTURE_CHANNEL_2,
Kojto 111:4336505e4b1c 1294 /** Recoverable fault triggers channel 3 capture operation. */
Kojto 111:4336505e4b1c 1295 TCC_FAULT_CAPTURE_CHANNEL_3
Kojto 111:4336505e4b1c 1296 };
Kojto 111:4336505e4b1c 1297
Kojto 111:4336505e4b1c 1298 /**
Kojto 111:4336505e4b1c 1299 * \brief TCC (recoverable) fault Input Source
Kojto 111:4336505e4b1c 1300 */
Kojto 111:4336505e4b1c 1301 enum tcc_fault_source {
Kojto 111:4336505e4b1c 1302 /** Fault input is disabled. */
Kojto 111:4336505e4b1c 1303 TCC_FAULT_SOURCE_DISABLE,
Kojto 111:4336505e4b1c 1304 /** Match Capture Event x (x=0,1) input. */
Kojto 111:4336505e4b1c 1305 TCC_FAULT_SOURCE_ENABLE,
Kojto 111:4336505e4b1c 1306 /** Inverted MCEx (x=0,1) event input. */
Kojto 111:4336505e4b1c 1307 TCC_FAULT_SOURCE_INVERT,
Kojto 111:4336505e4b1c 1308 /** Alternate fault (A or B) state at the end of the previous period. */
Kojto 111:4336505e4b1c 1309 TCC_FAULT_SOURCE_ALTFAULT
Kojto 111:4336505e4b1c 1310 };
Kojto 111:4336505e4b1c 1311
Kojto 111:4336505e4b1c 1312 /**
Kojto 111:4336505e4b1c 1313 * \brief TCC (recoverable) fault Input Blanking Start Point
Kojto 111:4336505e4b1c 1314 */
Kojto 111:4336505e4b1c 1315 enum tcc_fault_blanking {
Kojto 111:4336505e4b1c 1316 /** No blanking. */
Kojto 111:4336505e4b1c 1317 TCC_FAULT_BLANKING_DISABLE,
Kojto 111:4336505e4b1c 1318 /** Blanking applied from rising edge of the output waveform. */
Kojto 111:4336505e4b1c 1319 TCC_FAULT_BLANKING_RISING_EDGE,
Kojto 111:4336505e4b1c 1320 /** Blanking applied from falling edge of the output waveform. */
Kojto 111:4336505e4b1c 1321 TCC_FAULT_BLANKING_FALLING_EDGE,
Kojto 111:4336505e4b1c 1322 /** Blanking applied from each toggle of the output waveform. */
Kojto 111:4336505e4b1c 1323 TCC_FAULT_BLANKING_BOTH_EDGE
Kojto 111:4336505e4b1c 1324 };
Kojto 111:4336505e4b1c 1325
Kojto 111:4336505e4b1c 1326 /**
Kojto 111:4336505e4b1c 1327 * \brief TCC (recoverable) fault Input Qualification Action
Kojto 111:4336505e4b1c 1328 */
Kojto 111:4336505e4b1c 1329 enum tcc_fault_qualification {
Kojto 111:4336505e4b1c 1330 /** The input is not disabled on compare condition. */
Kojto 111:4336505e4b1c 1331 TCC_FAULT_QUALIFICATION_DISABLE,
Kojto 111:4336505e4b1c 1332 /** The input is disabled when match output signal is at inactive level. */
Kojto 111:4336505e4b1c 1333 TCC_FAULT_QUALIFICATION_BY_OUTPUT
Kojto 111:4336505e4b1c 1334 };
Kojto 111:4336505e4b1c 1335
Kojto 111:4336505e4b1c 1336 /**
Kojto 111:4336505e4b1c 1337 * \brief TCC (recoverable) fault Output Keep Action
Kojto 111:4336505e4b1c 1338 */
Kojto 111:4336505e4b1c 1339 enum tcc_fault_keep {
Kojto 111:4336505e4b1c 1340 /** Disable keeping, wave output released as soon as fault is released. */
Kojto 111:4336505e4b1c 1341 TCC_FAULT_KEEP_DISABLE,
Kojto 111:4336505e4b1c 1342 /** Keep wave output until end of TCC cycle. */
Kojto 111:4336505e4b1c 1343 TCC_FAULT_KEEP_TILL_END
Kojto 111:4336505e4b1c 1344 };
Kojto 111:4336505e4b1c 1345
Kojto 111:4336505e4b1c 1346 /**
Kojto 111:4336505e4b1c 1347 * \brief TCC Non-recoverable State Outupt
Kojto 111:4336505e4b1c 1348 */
Kojto 111:4336505e4b1c 1349 enum tcc_fault_state_output {
Kojto 111:4336505e4b1c 1350 /** Non-recoverable fault output is tri-stated. */
Kojto 111:4336505e4b1c 1351 TCC_FAULT_STATE_OUTPUT_OFF,
Kojto 111:4336505e4b1c 1352 /** Non-recoverable fault force output 0. */
Kojto 111:4336505e4b1c 1353 TCC_FAULT_STATE_OUTPUT_0,
Kojto 111:4336505e4b1c 1354 /** Non-recoverable fault force output 1. */
Kojto 111:4336505e4b1c 1355 TCC_FAULT_STATE_OUTPUT_1
Kojto 111:4336505e4b1c 1356 };
Kojto 111:4336505e4b1c 1357
Kojto 111:4336505e4b1c 1358 /**
Kojto 111:4336505e4b1c 1359 * \brief TCC (recoverable) fault Restart Action
Kojto 111:4336505e4b1c 1360 */
Kojto 111:4336505e4b1c 1361 enum tcc_fault_restart {
Kojto 111:4336505e4b1c 1362 /** Restart Action disabled. */
Kojto 111:4336505e4b1c 1363 TCC_FAULT_RESTART_DISABLE,
Kojto 111:4336505e4b1c 1364 /** Restart Action enabled. */
Kojto 111:4336505e4b1c 1365 TCC_FAULT_RESTART_ENABLE
Kojto 111:4336505e4b1c 1366 };
Kojto 111:4336505e4b1c 1367
Kojto 111:4336505e4b1c 1368 /**
Kojto 111:4336505e4b1c 1369 * \brief Configuration struct for TCC module recoverable fault
Kojto 111:4336505e4b1c 1370 */
Kojto 111:4336505e4b1c 1371 struct tcc_recoverable_fault_config {
Kojto 111:4336505e4b1c 1372 /** Fault filter value applied on MCEx event input line (0x0 ~ 0xF).
Kojto 111:4336505e4b1c 1373 * Must be 0 when MCEx event is used as synchronous event.
Kojto 111:4336505e4b1c 1374 * Apply to both recoverable and non-recoverable fault. */
Kojto 111:4336505e4b1c 1375 uint8_t filter_value;
Kojto 111:4336505e4b1c 1376 /** Fault blanking value (0 ~ 255), disable input source for several TCC
Kojto 111:4336505e4b1c 1377 * clocks after the detection of the waveform edge. */
Kojto 111:4336505e4b1c 1378 uint8_t blanking_cycles;
Kojto 111:4336505e4b1c 1379
Kojto 111:4336505e4b1c 1380 /** Set to \c true to enable restart action. */
Kojto 111:4336505e4b1c 1381 bool restart;
Kojto 111:4336505e4b1c 1382 /** Set to \c true to enable keep action (keep until end of TCC cycle). */
Kojto 111:4336505e4b1c 1383 bool keep;
Kojto 111:4336505e4b1c 1384
Kojto 111:4336505e4b1c 1385 /** Set to \c true to enable input qualification
Kojto 111:4336505e4b1c 1386 * (disable input when output is inactive). */
Kojto 111:4336505e4b1c 1387 bool qualification;
Kojto 111:4336505e4b1c 1388
Kojto 111:4336505e4b1c 1389 /** Specifies if the event input generates recoverable Fault.
Kojto 111:4336505e4b1c 1390 * The event system channel connected to MCEx event input must be
Kojto 111:4336505e4b1c 1391 * configured as asynchronous.
Kojto 111:4336505e4b1c 1392 */
Kojto 111:4336505e4b1c 1393 enum tcc_fault_source source;
Kojto 111:4336505e4b1c 1394 /** Fault Blanking Start Point for recoverable Fault. */
Kojto 111:4336505e4b1c 1395 enum tcc_fault_blanking blanking;
Kojto 111:4336505e4b1c 1396
Kojto 111:4336505e4b1c 1397 /** Halt action for recoverable Fault. */
Kojto 111:4336505e4b1c 1398 enum tcc_fault_halt_action halt_action;
Kojto 111:4336505e4b1c 1399 /** Capture action for recoverable Fault. */
Kojto 111:4336505e4b1c 1400 enum tcc_fault_capture_action capture_action;
Kojto 111:4336505e4b1c 1401 /** Channel triggered by recoverable Fault. */
Kojto 111:4336505e4b1c 1402 enum tcc_fault_capture_channel capture_channel;
Kojto 111:4336505e4b1c 1403 };
Kojto 111:4336505e4b1c 1404
Kojto 111:4336505e4b1c 1405 /**
Kojto 111:4336505e4b1c 1406 * \brief Configuration struct for TCC module non-recoverable fault
Kojto 111:4336505e4b1c 1407 */
Kojto 111:4336505e4b1c 1408 struct tcc_non_recoverable_fault_config {
Kojto 111:4336505e4b1c 1409 /** Fault filter value applied on TCEx event input line (0x0 ~ 0xF).
Kojto 111:4336505e4b1c 1410 * Must be 0 when TCEx event is used as synchronous event. */
Kojto 111:4336505e4b1c 1411 uint8_t filter_value;
Kojto 111:4336505e4b1c 1412 /** Output. */
Kojto 111:4336505e4b1c 1413 enum tcc_fault_state_output output;
Kojto 111:4336505e4b1c 1414 };
Kojto 111:4336505e4b1c 1415
Kojto 111:4336505e4b1c 1416 /**
Kojto 111:4336505e4b1c 1417 * \brief TCC input event enable/disable/configure structure
Kojto 111:4336505e4b1c 1418 *
Kojto 111:4336505e4b1c 1419 * For configuring an input event.
Kojto 111:4336505e4b1c 1420 */
Kojto 111:4336505e4b1c 1421 struct tcc_input_event_config {
Kojto 111:4336505e4b1c 1422 /** Event action on incoming event. */
Kojto 111:4336505e4b1c 1423 enum tcc_event_action action;
Kojto 111:4336505e4b1c 1424 /** Modify event action. */
Kojto 111:4336505e4b1c 1425 bool modify_action;
Kojto 111:4336505e4b1c 1426 /** Invert incoming event input line. */
Kojto 111:4336505e4b1c 1427 bool invert;
Kojto 111:4336505e4b1c 1428 };
Kojto 111:4336505e4b1c 1429
Kojto 111:4336505e4b1c 1430 /**
Kojto 111:4336505e4b1c 1431 * \brief TCC output event enable/disable/configure structure
Kojto 111:4336505e4b1c 1432 *
Kojto 111:4336505e4b1c 1433 * Structure used for configuring an output event.
Kojto 111:4336505e4b1c 1434 */
Kojto 111:4336505e4b1c 1435 struct tcc_output_event_config {
Kojto 111:4336505e4b1c 1436 /** It decides which part of the counter cycle the counter event output
Kojto 111:4336505e4b1c 1437 * is generated. */
Kojto 111:4336505e4b1c 1438 enum tcc_event_generation_selection generation_selection;
Kojto 111:4336505e4b1c 1439 /** A switch to allow enable/disable of events, without modifying the
Kojto 111:4336505e4b1c 1440 * event output configuration.
Kojto 111:4336505e4b1c 1441 */
Kojto 111:4336505e4b1c 1442 bool modify_generation_selection;
Kojto 111:4336505e4b1c 1443 };
Kojto 111:4336505e4b1c 1444
Kojto 111:4336505e4b1c 1445 /**
Kojto 111:4336505e4b1c 1446 * \brief TCC event enable/disable structure
Kojto 111:4336505e4b1c 1447 *
Kojto 111:4336505e4b1c 1448 * Event flags for the \ref tcc_enable_events() and \ref tcc_disable_events().
Kojto 111:4336505e4b1c 1449 */
Kojto 111:4336505e4b1c 1450 struct tcc_events {
Kojto 111:4336505e4b1c 1451 /** Input events configuration. */
Kojto 111:4336505e4b1c 1452 struct tcc_input_event_config input_config[2];
Kojto 111:4336505e4b1c 1453 /** Output event configuration. */
Kojto 111:4336505e4b1c 1454 struct tcc_output_event_config output_config;
Kojto 111:4336505e4b1c 1455
Kojto 111:4336505e4b1c 1456 /** Perform the configured event action when an incoming event is
Kojto 111:4336505e4b1c 1457 * signalled. */
Kojto 111:4336505e4b1c 1458 bool on_input_event_perform_action[2];
Kojto 111:4336505e4b1c 1459
Kojto 111:4336505e4b1c 1460 /** Perform the configured event action when an incoming channel event is
Kojto 111:4336505e4b1c 1461 * signalled. */
Kojto 111:4336505e4b1c 1462 bool on_event_perform_channel_action[TCC_NUM_CHANNELS];
Kojto 111:4336505e4b1c 1463 /** Generate an output event on a channel capture/match.
Kojto 111:4336505e4b1c 1464 * Specify which channels will generate events. */
Kojto 111:4336505e4b1c 1465 bool generate_event_on_channel[TCC_NUM_CHANNELS];
Kojto 111:4336505e4b1c 1466
Kojto 111:4336505e4b1c 1467 /** Generate an output event on counter overflow/underflow. */
Kojto 111:4336505e4b1c 1468 bool generate_event_on_counter_overflow;
Kojto 111:4336505e4b1c 1469 /** Generate an output event on counter retrigger. */
Kojto 111:4336505e4b1c 1470 bool generate_event_on_counter_retrigger;
Kojto 111:4336505e4b1c 1471 /** Generate an output event on counter boundary.
Kojto 111:4336505e4b1c 1472 * See \ref tcc_event_output_action. */
Kojto 111:4336505e4b1c 1473 bool generate_event_on_counter_event;
Kojto 111:4336505e4b1c 1474 };
Kojto 111:4336505e4b1c 1475
Kojto 111:4336505e4b1c 1476 /**
Kojto 111:4336505e4b1c 1477 * \brief Configuration struct for the TCC module base counter
Kojto 111:4336505e4b1c 1478 *
Kojto 111:4336505e4b1c 1479 * Structure for configuring a TCC as a counter.
Kojto 111:4336505e4b1c 1480 */
Kojto 111:4336505e4b1c 1481 struct tcc_counter_config {
Kojto 111:4336505e4b1c 1482 /** Value to initialize the count register. */
Kojto 111:4336505e4b1c 1483 uint32_t count;
Kojto 111:4336505e4b1c 1484 /** Period/top and period/top buffer values for counter. */
Kojto 111:4336505e4b1c 1485 uint32_t period;
Kojto 111:4336505e4b1c 1486
Kojto 111:4336505e4b1c 1487 /** When \c true, counter will be stopped on the next hardware or
Kojto 111:4336505e4b1c 1488 * software re-trigger event or overflow/underflow.
Kojto 111:4336505e4b1c 1489 */
Kojto 111:4336505e4b1c 1490 bool oneshot;
Kojto 111:4336505e4b1c 1491
Kojto 111:4336505e4b1c 1492 /** Specifies the direction for the TCC to count. */
Kojto 111:4336505e4b1c 1493 enum tcc_count_direction direction;
Kojto 111:4336505e4b1c 1494
Kojto 111:4336505e4b1c 1495 /** GCLK generator used to clock the peripheral. */
Kojto 111:4336505e4b1c 1496 enum gclk_generator clock_source;
Kojto 111:4336505e4b1c 1497 /** Specifies the prescaler value for GCLK_TCC. */
Kojto 111:4336505e4b1c 1498 enum tcc_clock_prescaler clock_prescaler;
Kojto 111:4336505e4b1c 1499 /** Specifies the reload or reset time of the counter and prescaler
Kojto 111:4336505e4b1c 1500 * resynchronization on a re-trigger event for the TCC.
Kojto 111:4336505e4b1c 1501 */
Kojto 111:4336505e4b1c 1502 enum tcc_reload_action reload_action;
Kojto 111:4336505e4b1c 1503 };
Kojto 111:4336505e4b1c 1504
Kojto 111:4336505e4b1c 1505 /**
Kojto 111:4336505e4b1c 1506 * \brief Configuration struct for the TCC module capture
Kojto 111:4336505e4b1c 1507 *
Kojto 111:4336505e4b1c 1508 * Structure used when configuring TCC channels in capture mode.
Kojto 111:4336505e4b1c 1509 */
Kojto 111:4336505e4b1c 1510 struct tcc_capture_config {
Kojto 111:4336505e4b1c 1511 /** Channel functions selection (capture/match). */
Kojto 111:4336505e4b1c 1512 enum tcc_channel_function channel_function[TCC_NUM_CHANNELS];
Kojto 111:4336505e4b1c 1513 };
Kojto 111:4336505e4b1c 1514
Kojto 111:4336505e4b1c 1515 /**
Kojto 111:4336505e4b1c 1516 * \brief Configuration struct for the TCC module match/wave generation
Kojto 111:4336505e4b1c 1517 *
Kojto 111:4336505e4b1c 1518 * The structure, which helps to configure a TCC channel for compare
Kojto 111:4336505e4b1c 1519 * operation and wave generation.
Kojto 111:4336505e4b1c 1520 */
Kojto 111:4336505e4b1c 1521 struct tcc_match_wave_config {
Kojto 111:4336505e4b1c 1522 /** Channel functions selection (capture/match). */
Kojto 111:4336505e4b1c 1523 enum tcc_channel_function channel_function[TCC_NUM_CHANNELS];
Kojto 111:4336505e4b1c 1524
Kojto 111:4336505e4b1c 1525 /** Specifies polarity for match output waveform generation. */
Kojto 111:4336505e4b1c 1526 enum tcc_wave_polarity wave_polarity[TCC_NUM_CHANNELS];
Kojto 111:4336505e4b1c 1527 /** Specifies which waveform generation mode to use. */
Kojto 111:4336505e4b1c 1528 enum tcc_wave_generation wave_generation;
Kojto 111:4336505e4b1c 1529 /** Specifies Ramp mode for waveform generation. */
Kojto 111:4336505e4b1c 1530 enum tcc_ramp wave_ramp;
Kojto 111:4336505e4b1c 1531
Kojto 111:4336505e4b1c 1532 /** Value to be used for compare match on each channel. */
Kojto 111:4336505e4b1c 1533 uint32_t match[TCC_NUM_CHANNELS];
Kojto 111:4336505e4b1c 1534 };
Kojto 111:4336505e4b1c 1535
Kojto 111:4336505e4b1c 1536 /**
Kojto 111:4336505e4b1c 1537 * \brief Configuration struct for the TCC module waveform extension
Kojto 111:4336505e4b1c 1538 *
Kojto 111:4336505e4b1c 1539 * This structure is used to specify the waveform extension features for TCC.
Kojto 111:4336505e4b1c 1540 */
Kojto 111:4336505e4b1c 1541 struct tcc_wave_extension_config {
Kojto 111:4336505e4b1c 1542 /** Configuration for recoverable faults. */
Kojto 111:4336505e4b1c 1543 struct tcc_recoverable_fault_config
Kojto 111:4336505e4b1c 1544 recoverable_fault[TCC_NUM_FAULTS];
Kojto 111:4336505e4b1c 1545 /** Configuration for non-recoverable faults. */
Kojto 111:4336505e4b1c 1546 struct tcc_non_recoverable_fault_config
Kojto 111:4336505e4b1c 1547 non_recoverable_fault[TCC_NUM_WAVE_OUTPUTS];
Kojto 111:4336505e4b1c 1548
Kojto 111:4336505e4b1c 1549 /** Invert waveform final outputs lines. */
Kojto 111:4336505e4b1c 1550 bool invert[TCC_NUM_WAVE_OUTPUTS];
Kojto 111:4336505e4b1c 1551 };
Kojto 111:4336505e4b1c 1552
Kojto 111:4336505e4b1c 1553 /**
Kojto 111:4336505e4b1c 1554 * \brief Configuration struct for the TCC module output pins
Kojto 111:4336505e4b1c 1555 *
Kojto 111:4336505e4b1c 1556 * Structure which is used when taking wave output from TCC.
Kojto 111:4336505e4b1c 1557 */
Kojto 111:4336505e4b1c 1558 struct tcc_pins_config {
Kojto 111:4336505e4b1c 1559 /** Specifies pin output for each channel. */
Kojto 111:4336505e4b1c 1560 uint32_t wave_out_pin[TCC_NUM_WAVE_OUTPUTS];
Kojto 111:4336505e4b1c 1561 /** Specifies MUX setting for each output channel pin. */
Kojto 111:4336505e4b1c 1562 uint32_t wave_out_pin_mux[TCC_NUM_WAVE_OUTPUTS];
Kojto 111:4336505e4b1c 1563 /** When \c true, PWM output pin for the given channel is enabled. */
Kojto 111:4336505e4b1c 1564 bool enable_wave_out_pin[TCC_NUM_WAVE_OUTPUTS];
Kojto 111:4336505e4b1c 1565 };
Kojto 111:4336505e4b1c 1566
Kojto 111:4336505e4b1c 1567 /**
Kojto 111:4336505e4b1c 1568 * \brief TCC configuration structure
Kojto 111:4336505e4b1c 1569 *
Kojto 111:4336505e4b1c 1570 * Configuration struct for a TCC instance. This structure should be
Kojto 111:4336505e4b1c 1571 * initialized by the \ref tcc_get_config_defaults function before being
Kojto 111:4336505e4b1c 1572 * modified by the user application.
Kojto 111:4336505e4b1c 1573 */
Kojto 111:4336505e4b1c 1574 struct tcc_config {
Kojto 111:4336505e4b1c 1575 /** Structure for configuring TCC base timer/counter. */
Kojto 111:4336505e4b1c 1576 struct tcc_counter_config counter;
Kojto 111:4336505e4b1c 1577 /** TCC match/capture configurations. */
Kojto 111:4336505e4b1c 1578 union {
Kojto 111:4336505e4b1c 1579 /** Helps to configure a TCC channel in capture mode. */
Kojto 111:4336505e4b1c 1580 struct tcc_capture_config capture;
Kojto 111:4336505e4b1c 1581 /** For configuring a TCC channel in compare mode. */
Kojto 111:4336505e4b1c 1582 struct tcc_match_wave_config compare;
Kojto 111:4336505e4b1c 1583 /** Serves the same purpose as compare. Used as an alias for
Kojto 111:4336505e4b1c 1584 * compare,
Kojto 111:4336505e4b1c 1585 * when a TCC channel is configured for wave generation. */
Kojto 111:4336505e4b1c 1586 struct tcc_match_wave_config wave;
Kojto 111:4336505e4b1c 1587 };
Kojto 111:4336505e4b1c 1588
Kojto 111:4336505e4b1c 1589 /** Structure for configuring TCC waveform extension. */
Kojto 111:4336505e4b1c 1590 struct tcc_wave_extension_config wave_ext;
Kojto 111:4336505e4b1c 1591
Kojto 111:4336505e4b1c 1592 /** Structure for configuring TCC output pins. */
Kojto 111:4336505e4b1c 1593 struct tcc_pins_config pins;
Kojto 111:4336505e4b1c 1594
Kojto 111:4336505e4b1c 1595 /** Set to \c true to enable double buffering write. When enabled any write
Kojto 111:4336505e4b1c 1596 * through \ref tcc_set_top_value(), \ref tcc_set_compare_value() and
Kojto 111:4336505e4b1c 1597 * \ref tcc_set_pattern() will direct to the buffer register as buffered
Kojto 111:4336505e4b1c 1598 * value, and the buffered value will be committed to effective register
Kojto 111:4336505e4b1c 1599 * on UPDATE condition, if update is not locked.
Kojto 111:4336505e4b1c 1600 *
Kojto 111:4336505e4b1c 1601 * \note The init values in \ref tcc_config for \ref tcc_init are always
Kojto 111:4336505e4b1c 1602 * filled to effective registers, no matter double buffering
Kojto 111:4336505e4b1c 1603 * enabled or not.
Kojto 111:4336505e4b1c 1604 */
Kojto 111:4336505e4b1c 1605 bool double_buffering_enabled;
Kojto 111:4336505e4b1c 1606
Kojto 111:4336505e4b1c 1607 /** When \c true the module is enabled during standby. */
Kojto 111:4336505e4b1c 1608 bool run_in_standby;
Kojto 111:4336505e4b1c 1609 };
Kojto 111:4336505e4b1c 1610
Kojto 111:4336505e4b1c 1611 #if TCC_ASYNC == true
Kojto 111:4336505e4b1c 1612 /* Forward Declaration for the device instance. */
Kojto 111:4336505e4b1c 1613 struct tcc_module;
Kojto 111:4336505e4b1c 1614
Kojto 111:4336505e4b1c 1615 /** Type definition for the TCC callback function. */
Kojto 111:4336505e4b1c 1616 typedef void (*tcc_callback_t)(struct tcc_module *const module);
Kojto 111:4336505e4b1c 1617 #endif
Kojto 111:4336505e4b1c 1618
Kojto 111:4336505e4b1c 1619 /**
Kojto 111:4336505e4b1c 1620 * \brief TCC software device instance structure
Kojto 111:4336505e4b1c 1621 *
Kojto 111:4336505e4b1c 1622 * TCC software instance structure, used to retain software state information
Kojto 111:4336505e4b1c 1623 * of an associated hardware module instance.
Kojto 111:4336505e4b1c 1624 *
Kojto 111:4336505e4b1c 1625 * \note The fields of this structure should not be altered by the user
Kojto 111:4336505e4b1c 1626 * application; they are reserved only for module-internal use.
Kojto 111:4336505e4b1c 1627 */
Kojto 111:4336505e4b1c 1628 struct tcc_module {
Kojto 111:4336505e4b1c 1629 /** Hardware module pointer of the associated Timer/Counter peripheral. */
Kojto 111:4336505e4b1c 1630 Tcc *hw;
Kojto 111:4336505e4b1c 1631
Kojto 111:4336505e4b1c 1632 # if TCC_ASYNC == true
Kojto 111:4336505e4b1c 1633 /** Array of callbacks. */
Kojto 111:4336505e4b1c 1634 tcc_callback_t callback[TCC_CALLBACK_N];
Kojto 111:4336505e4b1c 1635 /** Bit mask for callbacks registered. */
Kojto 111:4336505e4b1c 1636 uint32_t register_callback_mask;
Kojto 111:4336505e4b1c 1637 /** Bit mask for callbacks enabled. */
Kojto 111:4336505e4b1c 1638 uint32_t enable_callback_mask;
Kojto 111:4336505e4b1c 1639 # endif
Kojto 111:4336505e4b1c 1640
Kojto 111:4336505e4b1c 1641 /** Set to \c true to write to buffered registers. */
Kojto 111:4336505e4b1c 1642 bool double_buffering_enabled;
Kojto 111:4336505e4b1c 1643 };
Kojto 111:4336505e4b1c 1644
Kojto 111:4336505e4b1c 1645 #if !defined(__DOXYGEN__)
Kojto 111:4336505e4b1c 1646 uint8_t _tcc_get_inst_index(
Kojto 111:4336505e4b1c 1647 Tcc *const hw);
Kojto 111:4336505e4b1c 1648 #endif
Kojto 111:4336505e4b1c 1649
Kojto 111:4336505e4b1c 1650 /**
Kojto 111:4336505e4b1c 1651 * \name Driver Initialization and Configuration
Kojto 111:4336505e4b1c 1652 * @{
Kojto 111:4336505e4b1c 1653 */
Kojto 111:4336505e4b1c 1654
Kojto 111:4336505e4b1c 1655 /**
Kojto 111:4336505e4b1c 1656 * \brief Determines if the hardware module is currently synchronizing to the bus
Kojto 111:4336505e4b1c 1657 *
Kojto 111:4336505e4b1c 1658 * Checks to see if the underlying hardware peripheral module is currently
Kojto 111:4336505e4b1c 1659 * synchronizing across multiple clock domains to the hardware bus. This
Kojto 111:4336505e4b1c 1660 * function can be used to delay further operations on a module until such time
Kojto 111:4336505e4b1c 1661 * that it is ready, to prevent blocking delays for synchronization in the
Kojto 111:4336505e4b1c 1662 * user application.
Kojto 111:4336505e4b1c 1663 *
Kojto 111:4336505e4b1c 1664 * \param[in] module_inst Pointer to the software module instance struct
Kojto 111:4336505e4b1c 1665 *
Kojto 111:4336505e4b1c 1666 * \return Synchronization status of the underlying hardware module.
Kojto 111:4336505e4b1c 1667 *
Kojto 111:4336505e4b1c 1668 * \retval false If the module has completed synchronization
Kojto 111:4336505e4b1c 1669 * \retval true If the module synchronization is ongoing
Kojto 111:4336505e4b1c 1670 */
Kojto 111:4336505e4b1c 1671 static inline bool tcc_is_syncing(
Kojto 111:4336505e4b1c 1672 const struct tcc_module *const module_inst)
Kojto 111:4336505e4b1c 1673 {
Kojto 111:4336505e4b1c 1674 /* Sanity check arguments */
Kojto 111:4336505e4b1c 1675 Assert(module_inst);
Kojto 111:4336505e4b1c 1676 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 1677
Kojto 111:4336505e4b1c 1678 return (module_inst->hw->SYNCBUSY.reg > 0);
Kojto 111:4336505e4b1c 1679 }
Kojto 111:4336505e4b1c 1680
Kojto 111:4336505e4b1c 1681
Kojto 111:4336505e4b1c 1682 void tcc_get_config_defaults(
Kojto 111:4336505e4b1c 1683 struct tcc_config *const config,
Kojto 111:4336505e4b1c 1684 Tcc *const hw);
Kojto 111:4336505e4b1c 1685
Kojto 111:4336505e4b1c 1686 enum status_code tcc_init(
Kojto 111:4336505e4b1c 1687 struct tcc_module *const module_inst,
Kojto 111:4336505e4b1c 1688 Tcc *const hw,
Kojto 111:4336505e4b1c 1689 const struct tcc_config *const config);
Kojto 111:4336505e4b1c 1690
Kojto 111:4336505e4b1c 1691 /** @} */
Kojto 111:4336505e4b1c 1692
Kojto 111:4336505e4b1c 1693 /**
Kojto 111:4336505e4b1c 1694 * \name Event Management
Kojto 111:4336505e4b1c 1695 * @{
Kojto 111:4336505e4b1c 1696 */
Kojto 111:4336505e4b1c 1697
Kojto 111:4336505e4b1c 1698 enum status_code tcc_enable_events(
Kojto 111:4336505e4b1c 1699 struct tcc_module *const module_inst,
Kojto 111:4336505e4b1c 1700 struct tcc_events *const events);
Kojto 111:4336505e4b1c 1701
Kojto 111:4336505e4b1c 1702 void tcc_disable_events(
Kojto 111:4336505e4b1c 1703 struct tcc_module *const module_inst,
Kojto 111:4336505e4b1c 1704 struct tcc_events *const events);
Kojto 111:4336505e4b1c 1705
Kojto 111:4336505e4b1c 1706 /** @} */
Kojto 111:4336505e4b1c 1707
Kojto 111:4336505e4b1c 1708 /**
Kojto 111:4336505e4b1c 1709 * \name Enable/Disable/Reset
Kojto 111:4336505e4b1c 1710 * @{
Kojto 111:4336505e4b1c 1711 */
Kojto 111:4336505e4b1c 1712
Kojto 111:4336505e4b1c 1713 /**
Kojto 111:4336505e4b1c 1714 * \brief Enable the TCC module
Kojto 111:4336505e4b1c 1715 *
Kojto 111:4336505e4b1c 1716 * Enables a TCC module that has been previously initialized. The counter will
Kojto 111:4336505e4b1c 1717 * start when the counter is enabled.
Kojto 111:4336505e4b1c 1718 *
Kojto 111:4336505e4b1c 1719 * \note When the counter is configured to re-trigger on an event, the counter
Kojto 111:4336505e4b1c 1720 * will not start until the next incoming event appears. Then it
Kojto 111:4336505e4b1c 1721 * restarts on any following event.
Kojto 111:4336505e4b1c 1722 *
Kojto 111:4336505e4b1c 1723 * \param[in] module_inst Pointer to the software module instance struct
Kojto 111:4336505e4b1c 1724 */
Kojto 111:4336505e4b1c 1725 static inline void tcc_enable(
Kojto 111:4336505e4b1c 1726 const struct tcc_module *const module_inst)
Kojto 111:4336505e4b1c 1727 {
Kojto 111:4336505e4b1c 1728 /* Sanity check arguments */
Kojto 111:4336505e4b1c 1729 Assert(module_inst);
Kojto 111:4336505e4b1c 1730 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 1731
Kojto 111:4336505e4b1c 1732 /* Get a pointer to the module's hardware instance */
Kojto 111:4336505e4b1c 1733 Tcc *const tcc_module = module_inst->hw;
Kojto 111:4336505e4b1c 1734
Kojto 111:4336505e4b1c 1735 while (tcc_module->SYNCBUSY.reg & TCC_SYNCBUSY_ENABLE) {
Kojto 111:4336505e4b1c 1736 /* Wait for sync */
Kojto 111:4336505e4b1c 1737 }
Kojto 111:4336505e4b1c 1738
Kojto 111:4336505e4b1c 1739 /* Enable the TCC module */
Kojto 111:4336505e4b1c 1740 tcc_module->CTRLA.reg |= TCC_CTRLA_ENABLE;
Kojto 111:4336505e4b1c 1741 }
Kojto 111:4336505e4b1c 1742
Kojto 111:4336505e4b1c 1743 /**
Kojto 111:4336505e4b1c 1744 * \brief Disables the TCC module
Kojto 111:4336505e4b1c 1745 *
Kojto 111:4336505e4b1c 1746 * Disables a TCC module and stops the counter.
Kojto 111:4336505e4b1c 1747 *
Kojto 111:4336505e4b1c 1748 * \param[in] module_inst Pointer to the software module instance struct
Kojto 111:4336505e4b1c 1749 */
Kojto 111:4336505e4b1c 1750 static inline void tcc_disable(
Kojto 111:4336505e4b1c 1751 const struct tcc_module *const module_inst)
Kojto 111:4336505e4b1c 1752 {
Kojto 111:4336505e4b1c 1753 /* Sanity check arguments */
Kojto 111:4336505e4b1c 1754 Assert(module_inst);
Kojto 111:4336505e4b1c 1755 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 1756
Kojto 111:4336505e4b1c 1757 /* Get a pointer to the module's hardware instance */
Kojto 111:4336505e4b1c 1758 Tcc *const tcc_module = module_inst->hw;
Kojto 111:4336505e4b1c 1759
Kojto 111:4336505e4b1c 1760 while (tcc_module->SYNCBUSY.reg & TCC_SYNCBUSY_ENABLE) {
Kojto 111:4336505e4b1c 1761 /* Wait for sync */
Kojto 111:4336505e4b1c 1762 }
Kojto 111:4336505e4b1c 1763
Kojto 111:4336505e4b1c 1764 /* Disable the TCC module */
Kojto 111:4336505e4b1c 1765 tcc_module->CTRLA.reg &= ~TC_CTRLA_ENABLE;
Kojto 111:4336505e4b1c 1766 }
Kojto 111:4336505e4b1c 1767
Kojto 111:4336505e4b1c 1768 /**
Kojto 111:4336505e4b1c 1769 * \brief Resets the TCC module
Kojto 111:4336505e4b1c 1770 *
Kojto 111:4336505e4b1c 1771 * Resets the TCC module, restoring all hardware module registers to their
Kojto 111:4336505e4b1c 1772 * default values and disabling the module. The TCC module will not be
Kojto 111:4336505e4b1c 1773 * accessible while the reset is being performed.
Kojto 111:4336505e4b1c 1774 *
Kojto 111:4336505e4b1c 1775 * \note When resetting a 32-bit counter only the master TCC module's instance
Kojto 111:4336505e4b1c 1776 * structure should be passed to the function.
Kojto 111:4336505e4b1c 1777 *
Kojto 111:4336505e4b1c 1778 * \param[in] module_inst Pointer to the software module instance struct
Kojto 111:4336505e4b1c 1779 *
Kojto 111:4336505e4b1c 1780 */
Kojto 111:4336505e4b1c 1781 static inline void tcc_reset(
Kojto 111:4336505e4b1c 1782 const struct tcc_module *const module_inst)
Kojto 111:4336505e4b1c 1783 {
Kojto 111:4336505e4b1c 1784 /* Sanity check arguments */
Kojto 111:4336505e4b1c 1785 Assert(module_inst);
Kojto 111:4336505e4b1c 1786 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 1787
Kojto 111:4336505e4b1c 1788 /* Get a pointer to the module hardware instance */
Kojto 111:4336505e4b1c 1789 Tcc *const tcc_module = module_inst->hw;
Kojto 111:4336505e4b1c 1790
Kojto 111:4336505e4b1c 1791 /* Disable this module if it is running */
Kojto 111:4336505e4b1c 1792 if (tcc_module->CTRLA.reg & TCC_CTRLA_ENABLE) {
Kojto 111:4336505e4b1c 1793 tcc_disable(module_inst);
Kojto 111:4336505e4b1c 1794 while (tcc_is_syncing(module_inst)) {
Kojto 111:4336505e4b1c 1795 /* wait while module is disabling */
Kojto 111:4336505e4b1c 1796 }
Kojto 111:4336505e4b1c 1797 }
Kojto 111:4336505e4b1c 1798
Kojto 111:4336505e4b1c 1799 /* Reset this TC module */
Kojto 111:4336505e4b1c 1800 tcc_module->CTRLA.reg |= TCC_CTRLA_SWRST;
Kojto 111:4336505e4b1c 1801 }
Kojto 111:4336505e4b1c 1802
Kojto 111:4336505e4b1c 1803 /** @} */
Kojto 111:4336505e4b1c 1804
Kojto 111:4336505e4b1c 1805
Kojto 111:4336505e4b1c 1806 /**
Kojto 111:4336505e4b1c 1807 * \name Set/Toggle Count Direction
Kojto 111:4336505e4b1c 1808 * @{
Kojto 111:4336505e4b1c 1809 */
Kojto 111:4336505e4b1c 1810
Kojto 111:4336505e4b1c 1811 /**
Kojto 111:4336505e4b1c 1812 * \brief Sets the TCC module count direction
Kojto 111:4336505e4b1c 1813 *
Kojto 111:4336505e4b1c 1814 * Sets the count direction of an initialized TCC module. The
Kojto 111:4336505e4b1c 1815 * specified TCC module can remain running or stopped.
Kojto 111:4336505e4b1c 1816 *
Kojto 111:4336505e4b1c 1817 * \param[in] module_inst Pointer to the software module instance struct
Kojto 111:4336505e4b1c 1818 * \param[in] dir New timer count direction to set
Kojto 111:4336505e4b1c 1819 */
Kojto 111:4336505e4b1c 1820 static inline void tcc_set_count_direction(
Kojto 111:4336505e4b1c 1821 const struct tcc_module *const module_inst,
Kojto 111:4336505e4b1c 1822 enum tcc_count_direction dir)
Kojto 111:4336505e4b1c 1823 {
Kojto 111:4336505e4b1c 1824 /* Sanity check arguments */
Kojto 111:4336505e4b1c 1825 Assert(module_inst);
Kojto 111:4336505e4b1c 1826 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 1827
Kojto 111:4336505e4b1c 1828 /* Get a pointer to the module's hardware instance */
Kojto 111:4336505e4b1c 1829 Tcc *const tcc_module = module_inst->hw;
Kojto 111:4336505e4b1c 1830
Kojto 111:4336505e4b1c 1831 while (tcc_module->SYNCBUSY.bit.CTRLB) {
Kojto 111:4336505e4b1c 1832 /* Wait for sync */
Kojto 111:4336505e4b1c 1833 }
Kojto 111:4336505e4b1c 1834
Kojto 111:4336505e4b1c 1835 /* Set count direction */
Kojto 111:4336505e4b1c 1836 if (TCC_COUNT_DIRECTION_DOWN == dir) {
Kojto 111:4336505e4b1c 1837 tcc_module->CTRLBSET.reg = TCC_CTRLBSET_DIR;
Kojto 111:4336505e4b1c 1838 return;
Kojto 111:4336505e4b1c 1839 }
Kojto 111:4336505e4b1c 1840 tcc_module->CTRLBCLR.reg = TCC_CTRLBCLR_DIR;
Kojto 111:4336505e4b1c 1841 }
Kojto 111:4336505e4b1c 1842
Kojto 111:4336505e4b1c 1843 /**
Kojto 111:4336505e4b1c 1844 * \brief Toggles the TCC module count direction
Kojto 111:4336505e4b1c 1845 *
Kojto 111:4336505e4b1c 1846 * Toggles the count direction of an initialized TCC module. The
Kojto 111:4336505e4b1c 1847 * specified TCC module can remain running or stopped.
Kojto 111:4336505e4b1c 1848 *
Kojto 111:4336505e4b1c 1849 * \param[in] module_inst Pointer to the software module instance struct
Kojto 111:4336505e4b1c 1850 */
Kojto 111:4336505e4b1c 1851 static inline void tcc_toggle_count_direction(
Kojto 111:4336505e4b1c 1852 const struct tcc_module *const module_inst)
Kojto 111:4336505e4b1c 1853 {
Kojto 111:4336505e4b1c 1854 /* Sanity check arguments */
Kojto 111:4336505e4b1c 1855 Assert(module_inst);
Kojto 111:4336505e4b1c 1856 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 1857
Kojto 111:4336505e4b1c 1858 /* Get a pointer to the module's hardware instance */
Kojto 111:4336505e4b1c 1859 Tcc *const tcc_module = module_inst->hw;
Kojto 111:4336505e4b1c 1860
Kojto 111:4336505e4b1c 1861 while (tcc_module->SYNCBUSY.bit.CTRLB) {
Kojto 111:4336505e4b1c 1862 /* Wait for sync */
Kojto 111:4336505e4b1c 1863 }
Kojto 111:4336505e4b1c 1864 bool dir_value_1 = tcc_module->CTRLBSET.bit.DIR;
Kojto 111:4336505e4b1c 1865 if (dir_value_1) {
Kojto 111:4336505e4b1c 1866 tcc_module->CTRLBCLR.reg = TCC_CTRLBCLR_DIR;
Kojto 111:4336505e4b1c 1867 } else {
Kojto 111:4336505e4b1c 1868 tcc_module->CTRLBSET.reg = TCC_CTRLBSET_DIR;
Kojto 111:4336505e4b1c 1869 }
Kojto 111:4336505e4b1c 1870 }
Kojto 111:4336505e4b1c 1871
Kojto 111:4336505e4b1c 1872 /** @} */
Kojto 111:4336505e4b1c 1873
Kojto 111:4336505e4b1c 1874 /**
Kojto 111:4336505e4b1c 1875 * \name Get/Set Count Value
Kojto 111:4336505e4b1c 1876 * @{
Kojto 111:4336505e4b1c 1877 */
Kojto 111:4336505e4b1c 1878
Kojto 111:4336505e4b1c 1879 uint32_t tcc_get_count_value(
Kojto 111:4336505e4b1c 1880 const struct tcc_module *const module_inst);
Kojto 111:4336505e4b1c 1881
Kojto 111:4336505e4b1c 1882 enum status_code tcc_set_count_value(
Kojto 111:4336505e4b1c 1883 const struct tcc_module *const module_inst,
Kojto 111:4336505e4b1c 1884 const uint32_t count);
Kojto 111:4336505e4b1c 1885
Kojto 111:4336505e4b1c 1886 /** @} */
Kojto 111:4336505e4b1c 1887
Kojto 111:4336505e4b1c 1888 /**
Kojto 111:4336505e4b1c 1889 * \name Stop/Restart Counter
Kojto 111:4336505e4b1c 1890 * @{
Kojto 111:4336505e4b1c 1891 */
Kojto 111:4336505e4b1c 1892
Kojto 111:4336505e4b1c 1893 /**
Kojto 111:4336505e4b1c 1894 * \brief Stops the counter
Kojto 111:4336505e4b1c 1895 *
Kojto 111:4336505e4b1c 1896 * This function will stop the counter. When the counter is stopped
Kojto 111:4336505e4b1c 1897 * the value in the count register is set to 0 if the counter was
Kojto 111:4336505e4b1c 1898 * counting up, or maximum or the top value if the counter was counting
Kojto 111:4336505e4b1c 1899 * down.
Kojto 111:4336505e4b1c 1900 *
Kojto 111:4336505e4b1c 1901 * \param[in] module_inst Pointer to the software module instance struct
Kojto 111:4336505e4b1c 1902 */
Kojto 111:4336505e4b1c 1903 static inline void tcc_stop_counter(
Kojto 111:4336505e4b1c 1904 const struct tcc_module *const module_inst)
Kojto 111:4336505e4b1c 1905 {
Kojto 111:4336505e4b1c 1906 /* Sanity check arguments */
Kojto 111:4336505e4b1c 1907 Assert(module_inst);
Kojto 111:4336505e4b1c 1908 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 1909
Kojto 111:4336505e4b1c 1910 /* Get a pointer to the module's hardware instance */
Kojto 111:4336505e4b1c 1911 Tcc *const tcc_module = module_inst->hw;
Kojto 111:4336505e4b1c 1912 uint32_t last_cmd;
Kojto 111:4336505e4b1c 1913
Kojto 111:4336505e4b1c 1914 /* Wait until last command is done */
Kojto 111:4336505e4b1c 1915 do {
Kojto 111:4336505e4b1c 1916 while (tcc_module->SYNCBUSY.bit.CTRLB) {
Kojto 111:4336505e4b1c 1917 /* Wait for sync */
Kojto 111:4336505e4b1c 1918 }
Kojto 111:4336505e4b1c 1919 last_cmd = tcc_module->CTRLBSET.reg & TCC_CTRLBSET_CMD_Msk;
Kojto 111:4336505e4b1c 1920 if (last_cmd == TCC_CTRLBSET_CMD_NONE) {
Kojto 111:4336505e4b1c 1921 break;
Kojto 111:4336505e4b1c 1922 } else if (last_cmd == TCC_CTRLBSET_CMD_STOP) {
Kojto 111:4336505e4b1c 1923 /* Command have been issued */
Kojto 111:4336505e4b1c 1924 return;
Kojto 111:4336505e4b1c 1925 } else if (last_cmd == TCC_CTRLBSET_CMD_RETRIGGER) {
Kojto 111:4336505e4b1c 1926 /* Cancel RETRIGGER command and issue STOP */
Kojto 111:4336505e4b1c 1927 tcc_module->CTRLBCLR.reg = TCC_CTRLBCLR_CMD_Msk;
Kojto 111:4336505e4b1c 1928 }
Kojto 111:4336505e4b1c 1929 } while (1);
Kojto 111:4336505e4b1c 1930
Kojto 111:4336505e4b1c 1931 /* Write command to execute */
Kojto 111:4336505e4b1c 1932 tcc_module->CTRLBSET.reg = TCC_CTRLBSET_CMD_STOP;
Kojto 111:4336505e4b1c 1933 }
Kojto 111:4336505e4b1c 1934
Kojto 111:4336505e4b1c 1935 /**
Kojto 111:4336505e4b1c 1936 * \brief Starts the counter from beginning
Kojto 111:4336505e4b1c 1937 *
Kojto 111:4336505e4b1c 1938 * Restarts an initialized TCC module's counter.
Kojto 111:4336505e4b1c 1939 *
Kojto 111:4336505e4b1c 1940 * \param[in] module_inst Pointer to the software module instance struct
Kojto 111:4336505e4b1c 1941 */
Kojto 111:4336505e4b1c 1942 static inline void tcc_restart_counter(
Kojto 111:4336505e4b1c 1943 const struct tcc_module *const module_inst)
Kojto 111:4336505e4b1c 1944 {
Kojto 111:4336505e4b1c 1945 /* Sanity check arguments */
Kojto 111:4336505e4b1c 1946 Assert(module_inst);
Kojto 111:4336505e4b1c 1947 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 1948
Kojto 111:4336505e4b1c 1949 /* Get a pointer to the module's hardware instance */
Kojto 111:4336505e4b1c 1950 Tcc *const tcc_module = module_inst->hw;
Kojto 111:4336505e4b1c 1951 uint32_t last_cmd;
Kojto 111:4336505e4b1c 1952
Kojto 111:4336505e4b1c 1953 /* Wait until last command is done */
Kojto 111:4336505e4b1c 1954 do {
Kojto 111:4336505e4b1c 1955 while (tcc_module->SYNCBUSY.bit.CTRLB) {
Kojto 111:4336505e4b1c 1956 /* Wait for sync */
Kojto 111:4336505e4b1c 1957 }
Kojto 111:4336505e4b1c 1958 last_cmd = tcc_module->CTRLBSET.reg & TCC_CTRLBSET_CMD_Msk;
Kojto 111:4336505e4b1c 1959 if (last_cmd == TCC_CTRLBSET_CMD_NONE) {
Kojto 111:4336505e4b1c 1960 break;
Kojto 111:4336505e4b1c 1961 } else if (last_cmd == TCC_CTRLBSET_CMD_RETRIGGER) {
Kojto 111:4336505e4b1c 1962 /* Command have been issued */
Kojto 111:4336505e4b1c 1963 return;
Kojto 111:4336505e4b1c 1964 } else if (last_cmd == TCC_CTRLBSET_CMD_STOP) {
Kojto 111:4336505e4b1c 1965 /* Cancel STOP command and issue RETRIGGER */
Kojto 111:4336505e4b1c 1966 tcc_module->CTRLBCLR.reg = TCC_CTRLBCLR_CMD_Msk;
Kojto 111:4336505e4b1c 1967 }
Kojto 111:4336505e4b1c 1968 } while (1);
Kojto 111:4336505e4b1c 1969
Kojto 111:4336505e4b1c 1970 /* Write command to execute */
Kojto 111:4336505e4b1c 1971 tcc_module->CTRLBSET.reg = TCC_CTRLBSET_CMD_RETRIGGER;
Kojto 111:4336505e4b1c 1972 }
Kojto 111:4336505e4b1c 1973
Kojto 111:4336505e4b1c 1974 /** @} */
Kojto 111:4336505e4b1c 1975
Kojto 111:4336505e4b1c 1976 #ifdef FEATURE_TCC_GENERATE_DMA_TRIGGER
Kojto 111:4336505e4b1c 1977 /**
Kojto 111:4336505e4b1c 1978 * \name Generate TCC DMA Triggers command
Kojto 111:4336505e4b1c 1979 * @{
Kojto 111:4336505e4b1c 1980 */
Kojto 111:4336505e4b1c 1981
Kojto 111:4336505e4b1c 1982 /**
Kojto 111:4336505e4b1c 1983 * \brief TCC DMA Trigger.
Kojto 111:4336505e4b1c 1984 *
Kojto 111:4336505e4b1c 1985 * TCC DMA trigger command.
Kojto 111:4336505e4b1c 1986 *
Kojto 111:4336505e4b1c 1987 * \param[in] module_inst Pointer to the software module instance struct
Kojto 111:4336505e4b1c 1988 */
Kojto 111:4336505e4b1c 1989 static inline void tcc_dma_trigger_command(
Kojto 111:4336505e4b1c 1990 const struct tcc_module *const module_inst)
Kojto 111:4336505e4b1c 1991 {
Kojto 111:4336505e4b1c 1992 /* Sanity check arguments */
Kojto 111:4336505e4b1c 1993 Assert(module_inst);
Kojto 111:4336505e4b1c 1994 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 1995
Kojto 111:4336505e4b1c 1996 /* Get a pointer to the module's hardware instance */
Kojto 111:4336505e4b1c 1997 Tcc *const tcc_module = module_inst->hw;
Kojto 111:4336505e4b1c 1998
Kojto 111:4336505e4b1c 1999 while (tcc_module->SYNCBUSY.bit.CTRLB) {
Kojto 111:4336505e4b1c 2000 /* Wait for sync */
Kojto 111:4336505e4b1c 2001 }
Kojto 111:4336505e4b1c 2002
Kojto 111:4336505e4b1c 2003 /* Make certain that there are no conflicting commands in the register */
Kojto 111:4336505e4b1c 2004 tcc_module->CTRLBCLR.reg = TCC_CTRLBCLR_CMD_NONE;
Kojto 111:4336505e4b1c 2005
Kojto 111:4336505e4b1c 2006 while (tcc_module->SYNCBUSY.bit.CTRLB) {
Kojto 111:4336505e4b1c 2007 /* Wait for sync */
Kojto 111:4336505e4b1c 2008 }
Kojto 111:4336505e4b1c 2009
Kojto 111:4336505e4b1c 2010 /* Write command to execute */
Kojto 111:4336505e4b1c 2011 tcc_module->CTRLBSET.reg = TCC_CTRLBSET_CMD_DMATRG;
Kojto 111:4336505e4b1c 2012 }
Kojto 111:4336505e4b1c 2013 /** @} */
Kojto 111:4336505e4b1c 2014 #endif
Kojto 111:4336505e4b1c 2015
Kojto 111:4336505e4b1c 2016 /**
Kojto 111:4336505e4b1c 2017 * \name Get/Set Compare/Capture Register
Kojto 111:4336505e4b1c 2018 * @{
Kojto 111:4336505e4b1c 2019 */
Kojto 111:4336505e4b1c 2020
Kojto 111:4336505e4b1c 2021 uint32_t tcc_get_capture_value(
Kojto 111:4336505e4b1c 2022 const struct tcc_module *const module_inst,
Kojto 111:4336505e4b1c 2023 const enum tcc_match_capture_channel channel_index);
Kojto 111:4336505e4b1c 2024
Kojto 111:4336505e4b1c 2025 enum status_code tcc_set_compare_value(
Kojto 111:4336505e4b1c 2026 const struct tcc_module *const module_inst,
Kojto 111:4336505e4b1c 2027 const enum tcc_match_capture_channel channel_index,
Kojto 111:4336505e4b1c 2028 const uint32_t compare);
Kojto 111:4336505e4b1c 2029
Kojto 111:4336505e4b1c 2030 /** @} */
Kojto 111:4336505e4b1c 2031
Kojto 111:4336505e4b1c 2032 /**
Kojto 111:4336505e4b1c 2033 * \name Set Top Value
Kojto 111:4336505e4b1c 2034 * @{
Kojto 111:4336505e4b1c 2035 */
Kojto 111:4336505e4b1c 2036
Kojto 111:4336505e4b1c 2037 enum status_code tcc_set_top_value(
Kojto 111:4336505e4b1c 2038 const struct tcc_module *const module_inst,
Kojto 111:4336505e4b1c 2039 const uint32_t top_value);
Kojto 111:4336505e4b1c 2040
Kojto 111:4336505e4b1c 2041 /** @} */
Kojto 111:4336505e4b1c 2042
Kojto 111:4336505e4b1c 2043
Kojto 111:4336505e4b1c 2044 /**
Kojto 111:4336505e4b1c 2045 * \name Set Output Pattern
Kojto 111:4336505e4b1c 2046 * @{
Kojto 111:4336505e4b1c 2047 */
Kojto 111:4336505e4b1c 2048
Kojto 111:4336505e4b1c 2049 enum status_code tcc_set_pattern(
Kojto 111:4336505e4b1c 2050 const struct tcc_module *const module_inst,
Kojto 111:4336505e4b1c 2051 const uint32_t line_index,
Kojto 111:4336505e4b1c 2052 const enum tcc_output_pattern pattern);
Kojto 111:4336505e4b1c 2053
Kojto 111:4336505e4b1c 2054 /** @} */
Kojto 111:4336505e4b1c 2055
Kojto 111:4336505e4b1c 2056
Kojto 111:4336505e4b1c 2057 /**
Kojto 111:4336505e4b1c 2058 * \name Set Ramp Index
Kojto 111:4336505e4b1c 2059 * @{
Kojto 111:4336505e4b1c 2060 */
Kojto 111:4336505e4b1c 2061
Kojto 111:4336505e4b1c 2062 /**
Kojto 111:4336505e4b1c 2063 * \brief Sets the TCC module ramp index on next cycle
Kojto 111:4336505e4b1c 2064 *
Kojto 111:4336505e4b1c 2065 * In RAMP2 and RAMP2A operation, we can force either cycle A or cycle B at
Kojto 111:4336505e4b1c 2066 * the output, on the next clock cycle.
Kojto 111:4336505e4b1c 2067 * When ramp index command is disabled, cycle A and cycle B will appear at
Kojto 111:4336505e4b1c 2068 * the output, on alternate clock cycles.
Kojto 111:4336505e4b1c 2069 * See \ref tcc_ramp.
Kojto 111:4336505e4b1c 2070 *
Kojto 111:4336505e4b1c 2071 * \param[in] module_inst Pointer to the software module instance struct
Kojto 111:4336505e4b1c 2072 * \param[in] ramp_index Ramp index (\ref tcc_ramp_index) of the next cycle
Kojto 111:4336505e4b1c 2073 */
Kojto 111:4336505e4b1c 2074 static inline void tcc_set_ramp_index(
Kojto 111:4336505e4b1c 2075 const struct tcc_module *const module_inst,
Kojto 111:4336505e4b1c 2076 const enum tcc_ramp_index ramp_index)
Kojto 111:4336505e4b1c 2077 {
Kojto 111:4336505e4b1c 2078 /* Sanity check arguments */
Kojto 111:4336505e4b1c 2079 Assert(module_inst);
Kojto 111:4336505e4b1c 2080 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 2081
Kojto 111:4336505e4b1c 2082 /* Get a pointer to the module's hardware instance */
Kojto 111:4336505e4b1c 2083 Tcc *const tcc_module = module_inst->hw;
Kojto 111:4336505e4b1c 2084 uint32_t last_cmd;
Kojto 111:4336505e4b1c 2085
Kojto 111:4336505e4b1c 2086 /* Wait until last command is done */
Kojto 111:4336505e4b1c 2087 do {
Kojto 111:4336505e4b1c 2088 while (tcc_module->SYNCBUSY.bit.CTRLB) {
Kojto 111:4336505e4b1c 2089 /* Wait for sync */
Kojto 111:4336505e4b1c 2090 }
Kojto 111:4336505e4b1c 2091 if (TCC_RAMP_INDEX_DEFAULT == ramp_index) {
Kojto 111:4336505e4b1c 2092 /* Cancel pending command */
Kojto 111:4336505e4b1c 2093 tcc_module->CTRLBCLR.reg = TCC_CTRLBSET_IDXCMD_DISABLE;
Kojto 111:4336505e4b1c 2094 return;
Kojto 111:4336505e4b1c 2095 }
Kojto 111:4336505e4b1c 2096 last_cmd = tcc_module->CTRLBSET.reg & TCC_CTRLBSET_IDXCMD_Msk;
Kojto 111:4336505e4b1c 2097 if (last_cmd == TCC_CTRLBSET_IDXCMD_DISABLE) {
Kojto 111:4336505e4b1c 2098 break;
Kojto 111:4336505e4b1c 2099 } else if (last_cmd == TCC_CTRLBSET_CMD(ramp_index)) {
Kojto 111:4336505e4b1c 2100 /* Command have been issued */
Kojto 111:4336505e4b1c 2101 return;
Kojto 111:4336505e4b1c 2102 }
Kojto 111:4336505e4b1c 2103 } while (1);
Kojto 111:4336505e4b1c 2104
Kojto 111:4336505e4b1c 2105 /* Write command to execute */
Kojto 111:4336505e4b1c 2106 tcc_module->CTRLBSET.reg = TCC_CTRLBSET_CMD(ramp_index);
Kojto 111:4336505e4b1c 2107 }
Kojto 111:4336505e4b1c 2108
Kojto 111:4336505e4b1c 2109 /** @} */
Kojto 111:4336505e4b1c 2110
Kojto 111:4336505e4b1c 2111 /**
Kojto 111:4336505e4b1c 2112 * \name Status Management
Kojto 111:4336505e4b1c 2113 * @{
Kojto 111:4336505e4b1c 2114 */
Kojto 111:4336505e4b1c 2115
Kojto 111:4336505e4b1c 2116 /**
Kojto 111:4336505e4b1c 2117 * \brief Checks if the timer/counter is running
Kojto 111:4336505e4b1c 2118 *
Kojto 111:4336505e4b1c 2119 * \param[in] module_inst Pointer to the TCC software instance struct
Kojto 111:4336505e4b1c 2120 *
Kojto 111:4336505e4b1c 2121 * \return Status which indicates whether the module is running.
Kojto 111:4336505e4b1c 2122 *
Kojto 111:4336505e4b1c 2123 * \retval true The timer/counter is running
Kojto 111:4336505e4b1c 2124 * \retval false The timer/counter is stopped
Kojto 111:4336505e4b1c 2125 */
Kojto 111:4336505e4b1c 2126 static inline bool tcc_is_running(
Kojto 111:4336505e4b1c 2127 struct tcc_module *const module_inst)
Kojto 111:4336505e4b1c 2128 {
Kojto 111:4336505e4b1c 2129 /* Sanity check arguments */
Kojto 111:4336505e4b1c 2130 Assert(module_inst);
Kojto 111:4336505e4b1c 2131 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 2132
Kojto 111:4336505e4b1c 2133 return !module_inst->hw->STATUS.bit.STOP;
Kojto 111:4336505e4b1c 2134 }
Kojto 111:4336505e4b1c 2135
Kojto 111:4336505e4b1c 2136 uint32_t tcc_get_status(
Kojto 111:4336505e4b1c 2137 struct tcc_module *const module_inst);
Kojto 111:4336505e4b1c 2138
Kojto 111:4336505e4b1c 2139 void tcc_clear_status(
Kojto 111:4336505e4b1c 2140 struct tcc_module *const module_inst,
Kojto 111:4336505e4b1c 2141 const uint32_t status_flags);
Kojto 111:4336505e4b1c 2142
Kojto 111:4336505e4b1c 2143 /** @} */
Kojto 111:4336505e4b1c 2144
Kojto 111:4336505e4b1c 2145 /**
Kojto 111:4336505e4b1c 2146 * \name Double Buffering Management
Kojto 111:4336505e4b1c 2147 * @{
Kojto 111:4336505e4b1c 2148 */
Kojto 111:4336505e4b1c 2149
Kojto 111:4336505e4b1c 2150 /**
Kojto 111:4336505e4b1c 2151 * \brief Enable TCC double buffering write
Kojto 111:4336505e4b1c 2152 *
Kojto 111:4336505e4b1c 2153 * When double buffering write is enabled, following function will write values
Kojto 111:4336505e4b1c 2154 * to buffered registers instead of effective ones (buffered):
Kojto 111:4336505e4b1c 2155 * - PERB: through \ref tcc_set_top_value()
Kojto 111:4336505e4b1c 2156 * - CCBx(x is 0~3): through \ref tcc_set_compare_value()
Kojto 111:4336505e4b1c 2157 * - PATTB: through \ref tcc_set_pattern()
Kojto 111:4336505e4b1c 2158 *
Kojto 111:4336505e4b1c 2159 * Then on UPDATE condition the buffered registers are committed to regular ones
Kojto 111:4336505e4b1c 2160 * to take effect.
Kojto 111:4336505e4b1c 2161 *
Kojto 111:4336505e4b1c 2162 * \param[in] module_inst Pointer to the TCC software instance struct
Kojto 111:4336505e4b1c 2163 */
Kojto 111:4336505e4b1c 2164 static inline void tcc_enable_double_buffering(
Kojto 111:4336505e4b1c 2165 struct tcc_module *const module_inst)
Kojto 111:4336505e4b1c 2166 {
Kojto 111:4336505e4b1c 2167 /* Sanity check arguments */
Kojto 111:4336505e4b1c 2168 Assert(module_inst);
Kojto 111:4336505e4b1c 2169
Kojto 111:4336505e4b1c 2170 module_inst->double_buffering_enabled = true;
Kojto 111:4336505e4b1c 2171 }
Kojto 111:4336505e4b1c 2172
Kojto 111:4336505e4b1c 2173 /**
Kojto 111:4336505e4b1c 2174 * \brief Disable TCC double buffering Write
Kojto 111:4336505e4b1c 2175 *
Kojto 111:4336505e4b1c 2176 * When double buffering write is disabled, following function will write values
Kojto 111:4336505e4b1c 2177 * to effective registers (not buffered):
Kojto 111:4336505e4b1c 2178 * - PER: through \ref tcc_set_top_value()
Kojto 111:4336505e4b1c 2179 * - CCx(x is 0~3): through \ref tcc_set_compare_value()
Kojto 111:4336505e4b1c 2180 * - PATT: through \ref tcc_set_pattern()
Kojto 111:4336505e4b1c 2181 *
Kojto 111:4336505e4b1c 2182 * \note This function does not lock double buffer update, which means on next
Kojto 111:4336505e4b1c 2183 * UPDATE condition the last written buffered values will be committed to
Kojto 111:4336505e4b1c 2184 * take effect. Invoke \ref tcc_lock_double_buffer_update() before this
Kojto 111:4336505e4b1c 2185 * function to disable double buffering update, if this change is not
Kojto 111:4336505e4b1c 2186 * expected.
Kojto 111:4336505e4b1c 2187 *
Kojto 111:4336505e4b1c 2188 * \param[in] module_inst Pointer to the TCC software instance struct
Kojto 111:4336505e4b1c 2189 */
Kojto 111:4336505e4b1c 2190 static inline void tcc_disable_double_buffering(
Kojto 111:4336505e4b1c 2191 struct tcc_module *const module_inst)
Kojto 111:4336505e4b1c 2192 {
Kojto 111:4336505e4b1c 2193 /* Sanity check arguments */
Kojto 111:4336505e4b1c 2194 Assert(module_inst);
Kojto 111:4336505e4b1c 2195 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 2196
Kojto 111:4336505e4b1c 2197 module_inst->double_buffering_enabled = false;
Kojto 111:4336505e4b1c 2198 }
Kojto 111:4336505e4b1c 2199
Kojto 111:4336505e4b1c 2200 /**
Kojto 111:4336505e4b1c 2201 * \brief Lock the TCC double buffered registers updates
Kojto 111:4336505e4b1c 2202 *
Kojto 111:4336505e4b1c 2203 * Locks the double buffered registers so they will not be updated through
Kojto 111:4336505e4b1c 2204 * their buffered values on UPDATE conditions.
Kojto 111:4336505e4b1c 2205 *
Kojto 111:4336505e4b1c 2206 * \param[in] module_inst Pointer to the TCC software instance struct
Kojto 111:4336505e4b1c 2207 *
Kojto 111:4336505e4b1c 2208 */
Kojto 111:4336505e4b1c 2209 static inline void tcc_lock_double_buffer_update(
Kojto 111:4336505e4b1c 2210 struct tcc_module *const module_inst)
Kojto 111:4336505e4b1c 2211 {
Kojto 111:4336505e4b1c 2212 /* Sanity check arguments */
Kojto 111:4336505e4b1c 2213 Assert(module_inst);
Kojto 111:4336505e4b1c 2214 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 2215
Kojto 111:4336505e4b1c 2216 while (module_inst->hw->SYNCBUSY.bit.CTRLB) {
Kojto 111:4336505e4b1c 2217 /* Wait for sync */
Kojto 111:4336505e4b1c 2218 }
Kojto 111:4336505e4b1c 2219 module_inst->hw->CTRLBSET.reg = TCC_CTRLBSET_LUPD;
Kojto 111:4336505e4b1c 2220 }
Kojto 111:4336505e4b1c 2221
Kojto 111:4336505e4b1c 2222 /**
Kojto 111:4336505e4b1c 2223 * \brief Unlock the TCC double buffered registers updates
Kojto 111:4336505e4b1c 2224 *
Kojto 111:4336505e4b1c 2225 * Unlock the double buffered registers so they will be updated through
Kojto 111:4336505e4b1c 2226 * their buffered values on UPDATE conditions.
Kojto 111:4336505e4b1c 2227 *
Kojto 111:4336505e4b1c 2228 * \param[in] module_inst Pointer to the TCC software instance struct
Kojto 111:4336505e4b1c 2229 *
Kojto 111:4336505e4b1c 2230 */
Kojto 111:4336505e4b1c 2231 static inline void tcc_unlock_double_buffer_update(
Kojto 111:4336505e4b1c 2232 struct tcc_module *const module_inst)
Kojto 111:4336505e4b1c 2233 {
Kojto 111:4336505e4b1c 2234 /* Sanity check arguments */
Kojto 111:4336505e4b1c 2235 Assert(module_inst);
Kojto 111:4336505e4b1c 2236 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 2237
Kojto 111:4336505e4b1c 2238 while (module_inst->hw->SYNCBUSY.bit.CTRLB) {
Kojto 111:4336505e4b1c 2239 /* Wait for sync */
Kojto 111:4336505e4b1c 2240 }
Kojto 111:4336505e4b1c 2241 module_inst->hw->CTRLBCLR.reg = TCC_CTRLBCLR_LUPD;
Kojto 111:4336505e4b1c 2242 }
Kojto 111:4336505e4b1c 2243
Kojto 111:4336505e4b1c 2244 /**
Kojto 111:4336505e4b1c 2245 * \brief Force the TCC double buffered registers to update once
Kojto 111:4336505e4b1c 2246 *
Kojto 111:4336505e4b1c 2247 * \param[in] module_inst Pointer to the TCC software instance struct
Kojto 111:4336505e4b1c 2248 *
Kojto 111:4336505e4b1c 2249 */
Kojto 111:4336505e4b1c 2250 static inline void tcc_force_double_buffer_update(
Kojto 111:4336505e4b1c 2251 struct tcc_module *const module_inst)
Kojto 111:4336505e4b1c 2252 {
Kojto 111:4336505e4b1c 2253 /* Sanity check arguments */
Kojto 111:4336505e4b1c 2254 Assert(module_inst);
Kojto 111:4336505e4b1c 2255 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 2256
Kojto 111:4336505e4b1c 2257 /* Get a pointer to the module's hardware instance */
Kojto 111:4336505e4b1c 2258 Tcc *const tcc_module = module_inst->hw;
Kojto 111:4336505e4b1c 2259 uint32_t last_cmd;
Kojto 111:4336505e4b1c 2260
Kojto 111:4336505e4b1c 2261 /* Wait until last command is done */
Kojto 111:4336505e4b1c 2262 do {
Kojto 111:4336505e4b1c 2263 while (tcc_module->SYNCBUSY.bit.CTRLB) {
Kojto 111:4336505e4b1c 2264 /* Wait for sync */
Kojto 111:4336505e4b1c 2265 }
Kojto 111:4336505e4b1c 2266 last_cmd = tcc_module->CTRLBSET.reg & TCC_CTRLBSET_CMD_Msk;
Kojto 111:4336505e4b1c 2267 if (last_cmd == TCC_CTRLBSET_CMD_NONE) {
Kojto 111:4336505e4b1c 2268 break;
Kojto 111:4336505e4b1c 2269 } else if (last_cmd == TCC_CTRLBSET_CMD_UPDATE) {
Kojto 111:4336505e4b1c 2270 /* Command have been issued */
Kojto 111:4336505e4b1c 2271 return;
Kojto 111:4336505e4b1c 2272 }
Kojto 111:4336505e4b1c 2273 } while (1);
Kojto 111:4336505e4b1c 2274
Kojto 111:4336505e4b1c 2275 /* Write command to execute */
Kojto 111:4336505e4b1c 2276 tcc_module->CTRLBSET.reg = TCC_CTRLBSET_CMD_UPDATE;
Kojto 111:4336505e4b1c 2277 }
Kojto 111:4336505e4b1c 2278
Kojto 111:4336505e4b1c 2279 /**
Kojto 111:4336505e4b1c 2280 * \brief Enable Circular option for double buffered Top/Period Values
Kojto 111:4336505e4b1c 2281 *
Kojto 111:4336505e4b1c 2282 * Enable circular option for the double buffered top/period values.
Kojto 111:4336505e4b1c 2283 * On each UPDATE condition, the contents of PERB and PER are switched, meaning
Kojto 111:4336505e4b1c 2284 * that the contents of PERB are transferred to PER and the contents of PER are
Kojto 111:4336505e4b1c 2285 * transferred to PERB.
Kojto 111:4336505e4b1c 2286 *
Kojto 111:4336505e4b1c 2287 * \param[in] module_inst Pointer to the TCC software instance struct
Kojto 111:4336505e4b1c 2288 */
Kojto 111:4336505e4b1c 2289 static inline void tcc_enable_circular_buffer_top(
Kojto 111:4336505e4b1c 2290 struct tcc_module *const module_inst)
Kojto 111:4336505e4b1c 2291 {
Kojto 111:4336505e4b1c 2292 /* Sanity check arguments */
Kojto 111:4336505e4b1c 2293 Assert(module_inst);
Kojto 111:4336505e4b1c 2294 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 2295
Kojto 111:4336505e4b1c 2296 module_inst->hw->WAVE.reg |= TCC_WAVE_CIPEREN;
Kojto 111:4336505e4b1c 2297 }
Kojto 111:4336505e4b1c 2298
Kojto 111:4336505e4b1c 2299 /**
Kojto 111:4336505e4b1c 2300 * \brief Disable Circular option for double buffered Top/Period Values
Kojto 111:4336505e4b1c 2301 *
Kojto 111:4336505e4b1c 2302 * Stop circularing the double buffered top/period values.
Kojto 111:4336505e4b1c 2303 *
Kojto 111:4336505e4b1c 2304 * \param[in] module_inst Pointer to the TCC software instance struct
Kojto 111:4336505e4b1c 2305 */
Kojto 111:4336505e4b1c 2306 static inline void tcc_disable_circular_buffer_top(
Kojto 111:4336505e4b1c 2307 struct tcc_module *const module_inst)
Kojto 111:4336505e4b1c 2308 {
Kojto 111:4336505e4b1c 2309 /* Sanity check arguments */
Kojto 111:4336505e4b1c 2310 Assert(module_inst);
Kojto 111:4336505e4b1c 2311 Assert(module_inst->hw);
Kojto 111:4336505e4b1c 2312
Kojto 111:4336505e4b1c 2313 module_inst->hw->WAVE.reg &= ~TCC_WAVE_CIPEREN;
Kojto 111:4336505e4b1c 2314 }
Kojto 111:4336505e4b1c 2315
Kojto 111:4336505e4b1c 2316 enum status_code tcc_set_double_buffer_top_values(
Kojto 111:4336505e4b1c 2317 const struct tcc_module *const module_inst,
Kojto 111:4336505e4b1c 2318 const uint32_t top_value, const uint32_t top_buffer_value);
Kojto 111:4336505e4b1c 2319
Kojto 111:4336505e4b1c 2320
Kojto 111:4336505e4b1c 2321 enum status_code tcc_enable_circular_buffer_compare(
Kojto 111:4336505e4b1c 2322 struct tcc_module *const module_inst,
Kojto 111:4336505e4b1c 2323 enum tcc_match_capture_channel channel_index);
Kojto 111:4336505e4b1c 2324 enum status_code tcc_disable_circular_buffer_compare(
Kojto 111:4336505e4b1c 2325 struct tcc_module *const module_inst,
Kojto 111:4336505e4b1c 2326 enum tcc_match_capture_channel channel_index);
Kojto 111:4336505e4b1c 2327 enum status_code tcc_set_double_buffer_compare_values(
Kojto 111:4336505e4b1c 2328 struct tcc_module *const module_inst,
Kojto 111:4336505e4b1c 2329 enum tcc_match_capture_channel channel_index,
Kojto 111:4336505e4b1c 2330 const uint32_t compare,
Kojto 111:4336505e4b1c 2331 const uint32_t compare_buffer);
Kojto 111:4336505e4b1c 2332
Kojto 111:4336505e4b1c 2333
Kojto 111:4336505e4b1c 2334 /** @} */
Kojto 111:4336505e4b1c 2335
Kojto 111:4336505e4b1c 2336 /** @} */
Kojto 111:4336505e4b1c 2337
Kojto 111:4336505e4b1c 2338 #ifdef __cplusplus
Kojto 111:4336505e4b1c 2339 }
Kojto 111:4336505e4b1c 2340 #endif
Kojto 111:4336505e4b1c 2341
Kojto 111:4336505e4b1c 2342 /**
Kojto 111:4336505e4b1c 2343 * \page asfdoc_sam0_tcc_extra Extra Information for TCC Driver
Kojto 111:4336505e4b1c 2344 *
Kojto 111:4336505e4b1c 2345 * \section asfdoc_sam0_tcc_extra_acronyms Acronyms
Kojto 111:4336505e4b1c 2346 * The table below presents the acronyms used in this module:
Kojto 111:4336505e4b1c 2347 *
Kojto 111:4336505e4b1c 2348 * <table>
Kojto 111:4336505e4b1c 2349 * <tr>
Kojto 111:4336505e4b1c 2350 * <th>Acronym</th>
Kojto 111:4336505e4b1c 2351 * <th>Description</th>
Kojto 111:4336505e4b1c 2352 * </tr>
Kojto 111:4336505e4b1c 2353 * <tr>
Kojto 111:4336505e4b1c 2354 * <td>DMA</td>
Kojto 111:4336505e4b1c 2355 * <td>Direct Memory Access</td>
Kojto 111:4336505e4b1c 2356 * </tr>
Kojto 111:4336505e4b1c 2357 * <tr>
Kojto 111:4336505e4b1c 2358 * <td>TCC</td>
Kojto 111:4336505e4b1c 2359 * <td>Timer Counter for Control Applications</td>
Kojto 111:4336505e4b1c 2360 * </tr>
Kojto 111:4336505e4b1c 2361 * <tr>
Kojto 111:4336505e4b1c 2362 * <td>PWM</td>
Kojto 111:4336505e4b1c 2363 * <td>Pulse Width Modulation</td>
Kojto 111:4336505e4b1c 2364 * </tr>
Kojto 111:4336505e4b1c 2365 * <tr>
Kojto 111:4336505e4b1c 2366 * <td>PWP</td>
Kojto 111:4336505e4b1c 2367 * <td>Pulse Width Period</td>
Kojto 111:4336505e4b1c 2368 * </tr>
Kojto 111:4336505e4b1c 2369 * <tr>
Kojto 111:4336505e4b1c 2370 * <td>PPW</td>
Kojto 111:4336505e4b1c 2371 * <td>Period Pulse Width</td>
Kojto 111:4336505e4b1c 2372 * </tr>
Kojto 111:4336505e4b1c 2373 * </table>
Kojto 111:4336505e4b1c 2374 *
Kojto 111:4336505e4b1c 2375 *
Kojto 111:4336505e4b1c 2376 * \section asfdoc_sam0_tcc_extra_dependencies Dependencies
Kojto 111:4336505e4b1c 2377 * This driver has the following dependencies:
Kojto 111:4336505e4b1c 2378 *
Kojto 111:4336505e4b1c 2379 * - \ref asfdoc_sam0_system_pinmux_group "System Pin Multiplexer Driver"
Kojto 111:4336505e4b1c 2380 *
Kojto 111:4336505e4b1c 2381 *
Kojto 111:4336505e4b1c 2382 * \section asfdoc_sam0_tcc_extra_errata Errata
Kojto 111:4336505e4b1c 2383 * There are no errata related to this driver.
Kojto 111:4336505e4b1c 2384 *
Kojto 111:4336505e4b1c 2385 *
Kojto 111:4336505e4b1c 2386 * \section asfdoc_sam0_tcc_extra_history Module History
Kojto 111:4336505e4b1c 2387 * An overview of the module history is presented in the table below, with
Kojto 111:4336505e4b1c 2388 * details on the enhancements and fixes made to the module since its first
Kojto 111:4336505e4b1c 2389 * release. The current version of this corresponds to the newest version in
Kojto 111:4336505e4b1c 2390 * the table.
Kojto 111:4336505e4b1c 2391 *
Kojto 111:4336505e4b1c 2392 * <table>
Kojto 111:4336505e4b1c 2393 * <tr>
Kojto 111:4336505e4b1c 2394 * <th>Changelog</th>
Kojto 111:4336505e4b1c 2395 * </tr>
Kojto 111:4336505e4b1c 2396 * <tr>
Kojto 111:4336505e4b1c 2397 * <td>Add double buffering functionality</td>
Kojto 111:4336505e4b1c 2398 * </tr>
Kojto 111:4336505e4b1c 2399 * <tr>
Kojto 111:4336505e4b1c 2400 * <td>Add fault handling functionality</td>
Kojto 111:4336505e4b1c 2401 * </tr>
Kojto 111:4336505e4b1c 2402 * <tr>
Kojto 111:4336505e4b1c 2403 * <td>Initial Release</td>
Kojto 111:4336505e4b1c 2404 * </tr>
Kojto 111:4336505e4b1c 2405 * </table>
Kojto 111:4336505e4b1c 2406 */
Kojto 111:4336505e4b1c 2407
Kojto 111:4336505e4b1c 2408 /**
Kojto 111:4336505e4b1c 2409 * \page asfdoc_sam0_tcc_exqsg Examples for TCC Driver
Kojto 111:4336505e4b1c 2410 *
Kojto 111:4336505e4b1c 2411 * This is a list of the available Quick Start guides (QSGs) and example
Kojto 111:4336505e4b1c 2412 * applications for \ref asfdoc_sam0_tcc_group. QSGs are simple examples with
Kojto 111:4336505e4b1c 2413 * step-by-step instructions to configure and use this driver in a selection of
Kojto 111:4336505e4b1c 2414 * use cases. Note that QSGs can be compiled as a standalone application or be
Kojto 111:4336505e4b1c 2415 * added to the user application.
Kojto 111:4336505e4b1c 2416 *
Kojto 111:4336505e4b1c 2417 * - \subpage asfdoc_sam0_tcc_basic_use_case
Kojto 111:4336505e4b1c 2418 * - \subpage asfdoc_sam0_tcc_buffering_use_case
Kojto 111:4336505e4b1c 2419 * \if TCC_CALLBACK_MODE
Kojto 111:4336505e4b1c 2420 * - \subpage asfdoc_sam0_tcc_timer_use_case
Kojto 111:4336505e4b1c 2421 * - \subpage asfdoc_sam0_tcc_callback_use_case
Kojto 111:4336505e4b1c 2422 * - \subpage asfdoc_sam0_tcc_faultx_use_case
Kojto 111:4336505e4b1c 2423 * - \subpage asfdoc_sam0_tcc_faultn_use_case
Kojto 111:4336505e4b1c 2424 * \endif
Kojto 111:4336505e4b1c 2425 * - \subpage asfdoc_sam0_tcc_dma_use_case
Kojto 111:4336505e4b1c 2426 *
Kojto 111:4336505e4b1c 2427 * \page asfdoc_sam0_tcc_document_revision_history Document Revision History
Kojto 111:4336505e4b1c 2428 *
Kojto 111:4336505e4b1c 2429 * <table>
Kojto 111:4336505e4b1c 2430 * <tr>
Kojto 111:4336505e4b1c 2431 * <th>Doc. Rev.</td>
Kojto 111:4336505e4b1c 2432 * <th>Date</td>
Kojto 111:4336505e4b1c 2433 * <th>Comments</td>
Kojto 111:4336505e4b1c 2434 * </tr>
Kojto 111:4336505e4b1c 2435 * <tr>
Kojto 111:4336505e4b1c 2436 * <td>C</td>
Kojto 111:4336505e4b1c 2437 * <td>04/2015</td>
Kojto 111:4336505e4b1c 2438 * <td>Added support for SAML21 and SAMDAx</td>
Kojto 111:4336505e4b1c 2439 * </tr>
Kojto 111:4336505e4b1c 2440 * <tr>
Kojto 111:4336505e4b1c 2441 * <td>B</td>
Kojto 111:4336505e4b1c 2442 * <td>12/2014</td>
Kojto 111:4336505e4b1c 2443 * <td>Added fault handling functionality;
Kojto 111:4336505e4b1c 2444 * Added double buffering functionality with use case;
Kojto 111:4336505e4b1c 2445 * Added timer use case;
Kojto 111:4336505e4b1c 2446 * Added SAM R21/D10/D11 support</td>
Kojto 111:4336505e4b1c 2447 * </tr>
Kojto 111:4336505e4b1c 2448 * <tr>
Kojto 111:4336505e4b1c 2449 * <td>A</td>
Kojto 111:4336505e4b1c 2450 * <td>01/2014</td>
Kojto 111:4336505e4b1c 2451 * <td>Initial release</td>
Kojto 111:4336505e4b1c 2452 * </tr>
Kojto 111:4336505e4b1c 2453 * </table>
Kojto 111:4336505e4b1c 2454 */
Kojto 111:4336505e4b1c 2455
Kojto 111:4336505e4b1c 2456 #endif /* TCC_H_INCLUDED */