mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Committer:
mbed_official
Date:
Wed Nov 04 16:30:11 2015 +0000
Revision:
15:a81a8d6c1dfe
Synchronized with git revision 46af745ef4405614c3fa49abbd9a706a362ea514

Full URL: https://github.com/mbedmicro/mbed/commit/46af745ef4405614c3fa49abbd9a706a362ea514/

Renamed TARGET_SAM_CortexM0+ to TARGET_SAM_CortexM0P for compatiblity with online compiler

Who changed what in which revision?

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