t

Fork of mbed-dev by mbed official

Committer:
amithy
Date:
Thu Nov 09 22:14:37 2017 +0000
Revision:
178:c26431f84b0d
Parent:
149:156823d33999
test export

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 107:414e9c822e99 1 /**
mbed_official 107:414e9c822e99 2 * \file
mbed_official 107:414e9c822e99 3 *
mbed_official 107:414e9c822e99 4 * \brief SAM Timer Counter (TC) driver.
mbed_official 107:414e9c822e99 5 *
mbed_official 107:414e9c822e99 6 * Copyright (c) 2011-2015 Atmel Corporation. All rights reserved.
mbed_official 107:414e9c822e99 7 *
mbed_official 107:414e9c822e99 8 * \asf_license_start
mbed_official 107:414e9c822e99 9 *
mbed_official 107:414e9c822e99 10 * \page License
mbed_official 107:414e9c822e99 11 *
mbed_official 107:414e9c822e99 12 * Redistribution and use in source and binary forms, with or without
mbed_official 107:414e9c822e99 13 * modification, are permitted provided that the following conditions are met:
mbed_official 107:414e9c822e99 14 *
mbed_official 107:414e9c822e99 15 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 107:414e9c822e99 16 * this list of conditions and the following disclaimer.
mbed_official 107:414e9c822e99 17 *
mbed_official 107:414e9c822e99 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 107:414e9c822e99 19 * this list of conditions and the following disclaimer in the documentation
mbed_official 107:414e9c822e99 20 * and/or other materials provided with the distribution.
mbed_official 107:414e9c822e99 21 *
mbed_official 107:414e9c822e99 22 * 3. The name of Atmel may not be used to endorse or promote products derived
mbed_official 107:414e9c822e99 23 * from this software without specific prior written permission.
mbed_official 107:414e9c822e99 24 *
mbed_official 107:414e9c822e99 25 * 4. This software may only be redistributed and used in connection with an
mbed_official 107:414e9c822e99 26 * Atmel microcontroller product.
mbed_official 107:414e9c822e99 27 *
mbed_official 107:414e9c822e99 28 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
mbed_official 107:414e9c822e99 29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mbed_official 107:414e9c822e99 30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
mbed_official 107:414e9c822e99 31 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
mbed_official 107:414e9c822e99 32 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 107:414e9c822e99 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
mbed_official 107:414e9c822e99 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
mbed_official 107:414e9c822e99 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
mbed_official 107:414e9c822e99 36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
mbed_official 107:414e9c822e99 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 107:414e9c822e99 38 * POSSIBILITY OF SUCH DAMAGE.
mbed_official 107:414e9c822e99 39 *
mbed_official 107:414e9c822e99 40 * \asf_license_stop
mbed_official 107:414e9c822e99 41 *
mbed_official 107:414e9c822e99 42 */
mbed_official 107:414e9c822e99 43 /*
mbed_official 107:414e9c822e99 44 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
mbed_official 107:414e9c822e99 45 */
mbed_official 107:414e9c822e99 46
mbed_official 107:414e9c822e99 47 #ifndef TC_H_INCLUDED
mbed_official 107:414e9c822e99 48 #define TC_H_INCLUDED
mbed_official 107:414e9c822e99 49
mbed_official 107:414e9c822e99 50 /**
mbed_official 107:414e9c822e99 51 * \defgroup asfdoc_sam_drivers_tc_group SAM3/4S/4L/4E/4N/4CM/4C/G Timer Counter (TC) Driver
mbed_official 107:414e9c822e99 52 *
mbed_official 107:414e9c822e99 53 * This driver for Atmel&reg; | SMART ARM&reg;-based microcontrollers
mbed_official 107:414e9c822e99 54 * provides an interface for the configuration and management of the
mbed_official 107:414e9c822e99 55 * device's Timer Counter functionality.
mbed_official 107:414e9c822e99 56 *
mbed_official 107:414e9c822e99 57 * The Timer Counter (TC) includes several identical 16-bit or 32-bit
mbed_official 107:414e9c822e99 58 * Timer Counter channels. Each channel can be independently programmed
mbed_official 107:414e9c822e99 59 * to perform a wide range of functions that includes frequency
mbed_official 107:414e9c822e99 60 * measurement, event counting, interval measurement, pulse generation,
mbed_official 107:414e9c822e99 61 * delay timing, and pulse width modulation.
mbed_official 107:414e9c822e99 62 *
mbed_official 107:414e9c822e99 63 * Devices from the following series can use this module:
mbed_official 107:414e9c822e99 64 * - Atmel | SMART SAM3
mbed_official 107:414e9c822e99 65 * - Atmel | SMART SAM4S
mbed_official 107:414e9c822e99 66 * - Atmel | SMART SAM4L
mbed_official 107:414e9c822e99 67 * - Atmel | SMART SAM4E
mbed_official 107:414e9c822e99 68 * - Atmel | SMART SAM4N
mbed_official 107:414e9c822e99 69 * - Atmel | SMART SAM4CM
mbed_official 107:414e9c822e99 70 * - Atmel | SMART SAM4C
mbed_official 107:414e9c822e99 71 * - Atmel | SMART SAMG
mbed_official 107:414e9c822e99 72 *
mbed_official 107:414e9c822e99 73 * The outline of this documentation is as follows:
mbed_official 107:414e9c822e99 74 * - \ref asfdoc_sam_drivers_tc_prerequisites
mbed_official 107:414e9c822e99 75 * - \ref asfdoc_sam_drivers_tc_module_overview
mbed_official 107:414e9c822e99 76 * - \ref asfdoc_sam_drivers_tc_special_considerations
mbed_official 107:414e9c822e99 77 * - \ref asfdoc_sam_drivers_tc_extra_info
mbed_official 107:414e9c822e99 78 * - \ref asfdoc_sam_drivers_tc_examples
mbed_official 107:414e9c822e99 79 * - \ref asfdoc_sam_drivers_tc_api_overview
mbed_official 107:414e9c822e99 80 *
mbed_official 107:414e9c822e99 81 *
mbed_official 107:414e9c822e99 82 * \section asfdoc_sam_drivers_tc_prerequisites Prerequisites
mbed_official 107:414e9c822e99 83 *
mbed_official 107:414e9c822e99 84 * There are no prerequisites for this module.
mbed_official 107:414e9c822e99 85 *
mbed_official 107:414e9c822e99 86 *
mbed_official 107:414e9c822e99 87 * \section asfdoc_sam_drivers_tc_module_overview Module Overview
mbed_official 107:414e9c822e99 88 * The Timer Counter (TC) includes several identical 16-bit or 32-bit Timer
mbed_official 107:414e9c822e99 89 * Counter channels. The number of TC channels is device specific, refer
mbed_official 107:414e9c822e99 90 * to the device-specific datasheet for more information.
mbed_official 107:414e9c822e99 91 *
mbed_official 107:414e9c822e99 92 * Each channel can be independently programmed to perform a wide range of
mbed_official 107:414e9c822e99 93 * functions that includes frequency measurement, event counting, interval measurement,
mbed_official 107:414e9c822e99 94 * pulse generation, delay timing, and pulse width modulation.
mbed_official 107:414e9c822e99 95 *
mbed_official 107:414e9c822e99 96 * Each channel has three external clock inputs, five internal clock inputs,
mbed_official 107:414e9c822e99 97 * and two multi-purpose input/output signals which can be configured by the user.
mbed_official 107:414e9c822e99 98 * Each channel drives an internal interrupt signal which can be programmed to
mbed_official 107:414e9c822e99 99 * generate processor interrupts.
mbed_official 107:414e9c822e99 100 *
mbed_official 107:414e9c822e99 101 * The Timer Counter (TC) embeds a quadrature decoder logic connected in front of
mbed_official 107:414e9c822e99 102 * the timers. When enabled, the quadrature decoder performs the input line
mbed_official 107:414e9c822e99 103 * filtering, decoding of quadrature signals and connects to the timers/counters
mbed_official 107:414e9c822e99 104 * in order to read the position and speed of the motor.
mbed_official 107:414e9c822e99 105 *
mbed_official 107:414e9c822e99 106 *
mbed_official 107:414e9c822e99 107 * \section asfdoc_sam_drivers_tc_special_considerations Special Considerations
mbed_official 107:414e9c822e99 108 * \subsection asfdoc_sam_drivers_tc_special_considerations_clock External Clock
mbed_official 107:414e9c822e99 109 * In all cases, if an external clock is used, the duration of each of its levels
mbed_official 107:414e9c822e99 110 * must be longer than the master clock (MCLK) period. The external clock frequency
mbed_official 107:414e9c822e99 111 * must be at least 2.5 times lower than the master clock.
mbed_official 107:414e9c822e99 112 *
mbed_official 107:414e9c822e99 113 * \subsection asfdoc_sam_drivers_tc_special_considerations_trigger External Trigger
mbed_official 107:414e9c822e99 114 * If an external trigger is used, the duration of its pulses must be longer than
mbed_official 107:414e9c822e99 115 * the master clock (MCLK) period in order to be detected.
mbed_official 107:414e9c822e99 116 *
mbed_official 107:414e9c822e99 117 *
mbed_official 107:414e9c822e99 118 * \section asfdoc_sam_drivers_tc_extra_info Extra Information
mbed_official 107:414e9c822e99 119 *
mbed_official 107:414e9c822e99 120 * For extra information, see \ref asfdoc_sam_drivers_tc_extra. This includes:
mbed_official 107:414e9c822e99 121 * - \ref asfdoc_sam_drivers_tc_extra_acronyms
mbed_official 107:414e9c822e99 122 * - \ref asfdoc_sam_drivers_tc_extra_dependencies
mbed_official 107:414e9c822e99 123 * - \ref asfdoc_sam_drivers_tc_extra_errata
mbed_official 107:414e9c822e99 124 * - \ref asfdoc_sam_drivers_tc_extra_history
mbed_official 107:414e9c822e99 125 *
mbed_official 107:414e9c822e99 126 * \section asfdoc_sam_drivers_tc_examples Examples
mbed_official 107:414e9c822e99 127 *
mbed_official 107:414e9c822e99 128 * For a list of examples related to this driver, see
mbed_official 107:414e9c822e99 129 * \ref asfdoc_sam_drivers_tc_exqsg.
mbed_official 107:414e9c822e99 130 *
mbed_official 107:414e9c822e99 131 *
mbed_official 107:414e9c822e99 132 * \section asfdoc_sam_drivers_tc_api_overview API Overview
mbed_official 107:414e9c822e99 133 * @{
mbed_official 107:414e9c822e99 134 */
mbed_official 107:414e9c822e99 135
mbed_official 107:414e9c822e99 136 #include <compiler.h>
mbed_official 107:414e9c822e99 137
mbed_official 107:414e9c822e99 138 /// @cond
mbed_official 107:414e9c822e99 139 /**INDENT-OFF**/
mbed_official 107:414e9c822e99 140 #ifdef __cplusplus
mbed_official 107:414e9c822e99 141 extern "C" {
mbed_official 107:414e9c822e99 142 #endif
mbed_official 107:414e9c822e99 143 /**INDENT-ON**/
mbed_official 107:414e9c822e99 144 /// @endcond
mbed_official 107:414e9c822e99 145
mbed_official 107:414e9c822e99 146 void tc_init(Tc *p_tc, uint32_t ul_Channel, uint32_t ul_Mode);
mbed_official 107:414e9c822e99 147 void tc_sync_trigger(Tc *p_tc);
mbed_official 107:414e9c822e99 148 void tc_set_block_mode(Tc *p_tc, uint32_t ul_blockmode);
mbed_official 107:414e9c822e99 149
mbed_official 107:414e9c822e99 150 #if (!SAM3U) || defined(__DOXYGEN__)
mbed_official 107:414e9c822e99 151 uint32_t tc_init_2bit_gray(Tc *p_tc, uint32_t ul_channel,
mbed_official 107:414e9c822e99 152 uint32_t ul_steppermode);
mbed_official 107:414e9c822e99 153 #endif /* (!SAM3U) || defined(__DOXYGEN__) */
mbed_official 107:414e9c822e99 154
mbed_official 107:414e9c822e99 155 void tc_start(Tc *p_tc, uint32_t ul_channel);
mbed_official 107:414e9c822e99 156 void tc_stop(Tc *p_tc, uint32_t ul_channel);
mbed_official 107:414e9c822e99 157
mbed_official 107:414e9c822e99 158 uint32_t tc_read_cv(Tc *p_tc, uint32_t ul_channel);
mbed_official 107:414e9c822e99 159 uint32_t tc_read_ra(Tc *p_tc, uint32_t ul_channel);
mbed_official 107:414e9c822e99 160 uint32_t tc_read_rb(Tc *p_tc, uint32_t ul_channel);
mbed_official 107:414e9c822e99 161 uint32_t tc_read_rc(Tc *p_tc, uint32_t ul_channel);
mbed_official 107:414e9c822e99 162
mbed_official 107:414e9c822e99 163 void tc_write_ra(Tc *p_tc, uint32_t ul_channel,
mbed_official 107:414e9c822e99 164 uint32_t ul_value);
mbed_official 107:414e9c822e99 165 void tc_write_rb(Tc *p_tc, uint32_t ul_channel,
mbed_official 107:414e9c822e99 166 uint32_t ul_value);
mbed_official 107:414e9c822e99 167 void tc_write_rc(Tc *p_tc, uint32_t ul_channel,
mbed_official 107:414e9c822e99 168 uint32_t ul_value);
mbed_official 107:414e9c822e99 169
mbed_official 107:414e9c822e99 170 uint32_t tc_find_mck_divisor(uint32_t ul_freq, uint32_t ul_mck,
mbed_official 107:414e9c822e99 171 uint32_t *p_uldiv, uint32_t *ul_tcclks, uint32_t ul_boardmck);
mbed_official 107:414e9c822e99 172 void tc_enable_interrupt(Tc *p_tc, uint32_t ul_channel,
mbed_official 107:414e9c822e99 173 uint32_t ul_sources);
mbed_official 107:414e9c822e99 174 void tc_disable_interrupt(Tc *p_tc, uint32_t ul_channel,
mbed_official 107:414e9c822e99 175 uint32_t ul_sources);
mbed_official 107:414e9c822e99 176 uint32_t tc_get_interrupt_mask(Tc *p_tc, uint32_t ul_channel);
mbed_official 107:414e9c822e99 177 uint32_t tc_get_status(Tc *p_tc, uint32_t ul_channel);
mbed_official 107:414e9c822e99 178 #if (!SAM4L && !SAMG) || defined(__DOXYGEN__)
mbed_official 107:414e9c822e99 179 void tc_enable_qdec_interrupt(Tc *p_tc, uint32_t ul_sources);
mbed_official 107:414e9c822e99 180 void tc_disable_qdec_interrupt(Tc *p_tc, uint32_t ul_sources);
mbed_official 107:414e9c822e99 181 uint32_t tc_get_qdec_interrupt_mask(Tc *p_tc);
mbed_official 107:414e9c822e99 182 uint32_t tc_get_qdec_interrupt_status(Tc *p_tc);
mbed_official 107:414e9c822e99 183 #endif /* (!SAM4L && !SAMG) || defined(__DOXYGEN__) */
mbed_official 107:414e9c822e99 184
mbed_official 107:414e9c822e99 185 #if (!SAM3U)
mbed_official 107:414e9c822e99 186 void tc_set_writeprotect(Tc *p_tc, uint32_t ul_enable);
mbed_official 107:414e9c822e99 187 #endif /* (!SAM3U) */
mbed_official 107:414e9c822e99 188
mbed_official 107:414e9c822e99 189 #if SAM4L || defined(__DOXYGEN__)
mbed_official 107:414e9c822e99 190 uint32_t tc_get_feature(Tc *p_tc);
mbed_official 107:414e9c822e99 191 uint32_t tc_get_version(Tc *p_tc);
mbed_official 107:414e9c822e99 192 #endif /* SAM4L || defined(__DOXYGEN__) */
mbed_official 107:414e9c822e99 193
mbed_official 107:414e9c822e99 194 /// @cond
mbed_official 107:414e9c822e99 195 /**INDENT-OFF**/
mbed_official 107:414e9c822e99 196 #ifdef __cplusplus
mbed_official 107:414e9c822e99 197 }
mbed_official 107:414e9c822e99 198 #endif
mbed_official 107:414e9c822e99 199 /**INDENT-ON**/
mbed_official 107:414e9c822e99 200 /// @endcond
mbed_official 107:414e9c822e99 201
mbed_official 107:414e9c822e99 202 /** @} */
mbed_official 107:414e9c822e99 203
mbed_official 107:414e9c822e99 204 /**
mbed_official 107:414e9c822e99 205 * \page asfdoc_sam_drivers_tc_extra Extra Information for Timer Counter Driver
mbed_official 107:414e9c822e99 206 *
mbed_official 107:414e9c822e99 207 * \section asfdoc_sam_drivers_tc_extra_acronyms Acronyms
mbed_official 107:414e9c822e99 208 * Below is a table listing the acronyms used in this module, along with their
mbed_official 107:414e9c822e99 209 * intended meanings.
mbed_official 107:414e9c822e99 210 *
mbed_official 107:414e9c822e99 211 * <table>
mbed_official 107:414e9c822e99 212 * <tr>
mbed_official 107:414e9c822e99 213 * <th>Acronym</th>
mbed_official 107:414e9c822e99 214 * <th>Definition</th>
mbed_official 107:414e9c822e99 215 * </tr>
mbed_official 107:414e9c822e99 216 * <tr>
mbed_official 107:414e9c822e99 217 * <td>MCK</td>
mbed_official 107:414e9c822e99 218 * <td>Master Clock</td>
mbed_official 107:414e9c822e99 219 * </tr>
mbed_official 107:414e9c822e99 220 * <tr>
mbed_official 107:414e9c822e99 221 * <td>PBA</td>
mbed_official 107:414e9c822e99 222 * <td>Peripheral Bus A clock</td>
mbed_official 107:414e9c822e99 223 * </tr>
mbed_official 107:414e9c822e99 224 * <tr>
mbed_official 107:414e9c822e99 225 * <td>PHA</td>
mbed_official 107:414e9c822e99 226 * <td>Quadrature Decoder input signal Phase A</td>
mbed_official 107:414e9c822e99 227 * </tr>
mbed_official 107:414e9c822e99 228 * <tr>
mbed_official 107:414e9c822e99 229 * <td>PHB</td>
mbed_official 107:414e9c822e99 230 * <td>Quadrature Decoder input signal Phase B</td>
mbed_official 107:414e9c822e99 231 * </tr>
mbed_official 107:414e9c822e99 232 * <tr>
mbed_official 107:414e9c822e99 233 * <td>QDEC</td>
mbed_official 107:414e9c822e99 234 * <td>Quadrature Decoder</td>
mbed_official 107:414e9c822e99 235 * </tr>
mbed_official 107:414e9c822e99 236 * <tr>
mbed_official 107:414e9c822e99 237 * <td>QSG</td>
mbed_official 107:414e9c822e99 238 * <td>Quick Start Guide</td>
mbed_official 107:414e9c822e99 239 * </tr>
mbed_official 107:414e9c822e99 240 * <tr>
mbed_official 107:414e9c822e99 241 * <td>RA</td>
mbed_official 107:414e9c822e99 242 * <td>Register A</td>
mbed_official 107:414e9c822e99 243 * </tr>
mbed_official 107:414e9c822e99 244 * <tr>
mbed_official 107:414e9c822e99 245 * <td>RB</td>
mbed_official 107:414e9c822e99 246 * <td>Register B</td>
mbed_official 107:414e9c822e99 247 * </tr>
mbed_official 107:414e9c822e99 248 * <tr>
mbed_official 107:414e9c822e99 249 * <td>RC</td>
mbed_official 107:414e9c822e99 250 * <td>Register C</td>
mbed_official 107:414e9c822e99 251 * </tr>
mbed_official 107:414e9c822e99 252 * <tr>
mbed_official 107:414e9c822e99 253 * <td>TIOB</td>
mbed_official 107:414e9c822e99 254 * <td>Timer Input Output B</td>
mbed_official 107:414e9c822e99 255 * </tr>
mbed_official 107:414e9c822e99 256 * </table>
mbed_official 107:414e9c822e99 257 *
mbed_official 107:414e9c822e99 258 *
mbed_official 107:414e9c822e99 259 * \section asfdoc_sam_drivers_tc_extra_dependencies Dependencies
mbed_official 107:414e9c822e99 260 * This driver has the following dependencies:
mbed_official 107:414e9c822e99 261 *
mbed_official 107:414e9c822e99 262 * - \ref clk_group "System Clock Management (sysclock)"
mbed_official 107:414e9c822e99 263 * - \ref asfdoc_sam_drivers_gpio_group "General Purpose I/O (GPIO) driver"
mbed_official 107:414e9c822e99 264 * - \ref asfdoc_sam_drivers_pmc_group "Power Manager Controller (PMC) driver"
mbed_official 107:414e9c822e99 265 *
mbed_official 107:414e9c822e99 266 *
mbed_official 107:414e9c822e99 267 * \section asfdoc_sam_drivers_tc_extra_errata Errata
mbed_official 107:414e9c822e99 268 * There are no errata related to this driver.
mbed_official 107:414e9c822e99 269 *
mbed_official 107:414e9c822e99 270 *
mbed_official 107:414e9c822e99 271 * \section asfdoc_sam_drivers_tc_extra_history Module History
mbed_official 107:414e9c822e99 272 * An overview of the module history is presented in the table below, with
mbed_official 107:414e9c822e99 273 * details on the enhancements and fixes made to the module since its first
mbed_official 107:414e9c822e99 274 * release. The current version of this corresponds to the newest version in
mbed_official 107:414e9c822e99 275 * the table.
mbed_official 107:414e9c822e99 276 *
mbed_official 107:414e9c822e99 277 * <table>
mbed_official 107:414e9c822e99 278 * <tr>
mbed_official 107:414e9c822e99 279 * <th>Changelog</th>
mbed_official 107:414e9c822e99 280 * </tr>
mbed_official 107:414e9c822e99 281 * <tr>
mbed_official 107:414e9c822e99 282 * <td>Initial document release</td>
mbed_official 107:414e9c822e99 283 * </tr>
mbed_official 107:414e9c822e99 284 * </table>
mbed_official 107:414e9c822e99 285 */
mbed_official 107:414e9c822e99 286
mbed_official 107:414e9c822e99 287 /**
mbed_official 107:414e9c822e99 288 * \page asfdoc_sam_drivers_tc_exqsg Examples for Timer Counter
mbed_official 107:414e9c822e99 289 *
mbed_official 107:414e9c822e99 290 * This is a list of the available Quick Start Guides (QSGs) and example
mbed_official 107:414e9c822e99 291 * applications for \ref asfdoc_sam_drivers_tc_group. QSGs are simple examples with
mbed_official 107:414e9c822e99 292 * step-by-step instructions to configure and use this driver in a selection of
mbed_official 107:414e9c822e99 293 * use cases. Note that a QSG can be compiled as a standalone application or be
mbed_official 107:414e9c822e99 294 * added to the user application.
mbed_official 107:414e9c822e99 295 *
mbed_official 107:414e9c822e99 296 * - \subpage asfdoc_sam_drivers_tc_qsg
mbed_official 107:414e9c822e99 297 * - \subpage asfdoc_sam_drivers_tc_example
mbed_official 107:414e9c822e99 298 *
mbed_official 107:414e9c822e99 299 * \page asfdoc_sam_drivers_tc_document_revision_history Document Revision History
mbed_official 107:414e9c822e99 300 *
mbed_official 107:414e9c822e99 301 * <table>
mbed_official 107:414e9c822e99 302 * <tr>
mbed_official 107:414e9c822e99 303 * <th>Doc. Rev.</td>
mbed_official 107:414e9c822e99 304 * <th>Date</td>
mbed_official 107:414e9c822e99 305 * <th>Comments</td>
mbed_official 107:414e9c822e99 306 * </tr>
mbed_official 107:414e9c822e99 307 * <tr>
mbed_official 107:414e9c822e99 308 * <td>42301B</td>
mbed_official 107:414e9c822e99 309 * <td>07/2015</td>
mbed_official 107:414e9c822e99 310 * <td>Updated title of application note and added list of supported devices</td>
mbed_official 107:414e9c822e99 311 * </tr>
mbed_official 107:414e9c822e99 312 * <tr>
mbed_official 107:414e9c822e99 313 * <td>42301A</td>
mbed_official 107:414e9c822e99 314 * <td>05/2014</td>
mbed_official 107:414e9c822e99 315 * <td>Initial document release</td>
mbed_official 107:414e9c822e99 316 * </tr>
mbed_official 107:414e9c822e99 317 * </table>
mbed_official 107:414e9c822e99 318 *
mbed_official 107:414e9c822e99 319 */
mbed_official 107:414e9c822e99 320
mbed_official 107:414e9c822e99 321 /**
mbed_official 107:414e9c822e99 322 * \page asfdoc_sam_drivers_tc_qsg Quick Start Guide for the TC driver
mbed_official 107:414e9c822e99 323 *
mbed_official 107:414e9c822e99 324 * This is the quick start guide for the \ref asfdoc_sam_drivers_tc_group, with
mbed_official 107:414e9c822e99 325 * step-by-step instructions on how to configure and use the driver for
mbed_official 107:414e9c822e99 326 * a specific use case. The code examples can be copied into the main
mbed_official 107:414e9c822e99 327 * application loop or any other function that will need to control the
mbed_official 107:414e9c822e99 328 * AST module.
mbed_official 107:414e9c822e99 329 *
mbed_official 107:414e9c822e99 330 * \section asfdoc_sam_drivers_tc_qsg_use_cases Use Cases
mbed_official 107:414e9c822e99 331 * - \ref asfdoc_sam_drivers_tc_qsg_basic_capture
mbed_official 107:414e9c822e99 332 * - \ref asfdoc_sam_drivers_tc_qsg_basic_waveform
mbed_official 107:414e9c822e99 333 *
mbed_official 107:414e9c822e99 334 * \section asfdoc_sam_drivers_tc_qsg_basic_capture TC Capture Mode Basic Usage
mbed_official 107:414e9c822e99 335 *
mbed_official 107:414e9c822e99 336 * This use case will demonstrate how to initialize the TC module to
mbed_official 107:414e9c822e99 337 * operate in capture mode using interrupts. Note, that the macros
mbed_official 107:414e9c822e99 338 * used to select the TC channel are device specific. Refer to the
mbed_official 107:414e9c822e99 339 * appropriate device-specific datasheet for more information.
mbed_official 107:414e9c822e99 340 *
mbed_official 107:414e9c822e99 341 *
mbed_official 107:414e9c822e99 342 * \section asfdoc_sam_drivers_tc_qsg_basic_capture_setup Setup Steps
mbed_official 107:414e9c822e99 343 *
mbed_official 107:414e9c822e99 344 * \subsection asfdoc_sam_tc_qsg_basic_capture_prereq Prerequisites
mbed_official 107:414e9c822e99 345 *
mbed_official 107:414e9c822e99 346 * This module requires the following services:
mbed_official 107:414e9c822e99 347 * - \ref clk_group "System Clock Management (sysclock)"
mbed_official 107:414e9c822e99 348 * - \ref asfdoc_sam_drivers_gpio_group "General Purpose I/O (GPIO) driver"
mbed_official 107:414e9c822e99 349 *
mbed_official 107:414e9c822e99 350 * \subsection asfdoc_sam_drivers_tc_qsg_basic_capture_setup_code Setup Code
mbed_official 107:414e9c822e99 351 *
mbed_official 107:414e9c822e99 352 * Add these macros to the top of your main application C-file:
mbed_official 107:414e9c822e99 353 * \snippet conf_board.h tc_define_peripheral
mbed_official 107:414e9c822e99 354 * \snippet conf_board.h tc_define_ch2
mbed_official 107:414e9c822e99 355 * \snippet conf_board.h tc_define_irq_handler
mbed_official 107:414e9c822e99 356 *
mbed_official 107:414e9c822e99 357 * Add this macro and functions to your main application C-file:
mbed_official 107:414e9c822e99 358 * \snippet tc_capture_waveform_example.c tc_capture_selection
mbed_official 107:414e9c822e99 359 * \snippet tc_capture_waveform_example.c tc_capture_init
mbed_official 107:414e9c822e99 360 * \snippet tc_capture_waveform_example.c tc_capture_irq_handler_start
mbed_official 107:414e9c822e99 361 * \snippet tc_capture_waveform_example.c tc_capture_irq_handler_end
mbed_official 107:414e9c822e99 362 *
mbed_official 107:414e9c822e99 363 * \subsection asfdoc_sam_drivers_tc_qsg_basic_capture_setup_workflow Workflow
mbed_official 107:414e9c822e99 364 *
mbed_official 107:414e9c822e99 365 * -# Enable the TC module's capture pin:
mbed_official 107:414e9c822e99 366 * \snippet tc_capture_waveform_example.c tc_capture_gpio
mbed_official 107:414e9c822e99 367 * -# Initialize the capture channel to the following:
mbed_official 107:414e9c822e99 368 * - Load RA on the rising edge of TIOA
mbed_official 107:414e9c822e99 369 * - Load RB on the falling edge of TIOA
mbed_official 107:414e9c822e99 370 * - Set the external trigger to TIOA
mbed_official 107:414e9c822e99 371 * - Set the external trigger to falling edge
mbed_official 107:414e9c822e99 372 * \snippet tc_capture_waveform_example.c tc_capture_init_call
mbed_official 107:414e9c822e99 373 * -# Enable the TC interrupt using NVIC:
mbed_official 107:414e9c822e99 374 * \snippet tc_capture_waveform_example.c tc_capture_init_irq
mbed_official 107:414e9c822e99 375 * -# Enable the capture channel interrupt:
mbed_official 107:414e9c822e99 376 * \snippet tc_capture_waveform_example.c tc_capture_init_module_irq
mbed_official 107:414e9c822e99 377 * -# In the \ref TC_Handler_null "TC_Handler()" function, the load.
mbed_official 107:414e9c822e99 378 * RB interrupt can be checked by:
mbed_official 107:414e9c822e99 379 * \snippet tc_capture_waveform_example.c tc_capture_irq_handler_status
mbed_official 107:414e9c822e99 380 * \code } \endcode
mbed_official 107:414e9c822e99 381 * -# In the \ref TC_Handler_null "TC_Handler()" function, the RA value.
mbed_official 107:414e9c822e99 382 * can be read by:
mbed_official 107:414e9c822e99 383 * \code uint32_t gs_ul_captured_ra; \endcode
mbed_official 107:414e9c822e99 384 * \snippet tc_capture_waveform_example.c tc_capture_irq_handler_read_ra
mbed_official 107:414e9c822e99 385 * -# In the \ref TC_Handler_null "TC_Handler()" function, the RB value.
mbed_official 107:414e9c822e99 386 * can be read by:
mbed_official 107:414e9c822e99 387 * \code uint32_t gs_ul_captured_rb; \endcode
mbed_official 107:414e9c822e99 388 * \snippet tc_capture_waveform_example.c tc_capture_irq_handler_read_rb
mbed_official 107:414e9c822e99 389 *
mbed_official 107:414e9c822e99 390 * \section asfdoc_sam_drivers_tc_qsg_basic_waveform TC Waveform Mode Basic Usage
mbed_official 107:414e9c822e99 391 *
mbed_official 107:414e9c822e99 392 * This use case will demonstrate how to initialize the TC module to
mbed_official 107:414e9c822e99 393 * operate in waveform mode. Note, that the macros used to select
mbed_official 107:414e9c822e99 394 * the TC channel are device specific. Refer to the appropriate
mbed_official 107:414e9c822e99 395 * device-specific datasheet for more information.
mbed_official 107:414e9c822e99 396 *
mbed_official 107:414e9c822e99 397 *
mbed_official 107:414e9c822e99 398 * \section asfdoc_sam_drivers_tc_qsg_basic_waveform_setup Setup Steps
mbed_official 107:414e9c822e99 399 *
mbed_official 107:414e9c822e99 400 * \subsection asfdoc_sam_tc_qsg_basic_waveform_prereq Prerequisites
mbed_official 107:414e9c822e99 401 *
mbed_official 107:414e9c822e99 402 * This module requires the following services:
mbed_official 107:414e9c822e99 403 * - \ref clk_group "System Clock Management (sysclock)"
mbed_official 107:414e9c822e99 404 * - \ref asfdoc_sam_drivers_gpio_group "General Purpose I/O (GPIO) driver"
mbed_official 107:414e9c822e99 405 *
mbed_official 107:414e9c822e99 406 * \subsection asfdoc_sam_drivers_tc_qsg_basic_waveform_setup_code Setup Code
mbed_official 107:414e9c822e99 407 *
mbed_official 107:414e9c822e99 408 * Add these macros to the top of your main application C-file:
mbed_official 107:414e9c822e99 409 * \snippet conf_board.h tc_define_peripheral
mbed_official 107:414e9c822e99 410 * \snippet conf_board.h tc_define_ch1
mbed_official 107:414e9c822e99 411 *
mbed_official 107:414e9c822e99 412 * Add these macros and function to your main application C-file:
mbed_official 107:414e9c822e99 413 * \code #define TC_WAVEFORM_TIMER_SELECTION TC_CMR_TCCLKS_TIMER_CLOCK4 \endcode
mbed_official 107:414e9c822e99 414 * \code #define TC_WAVEFORM_DIVISOR 128 \endcode
mbed_official 107:414e9c822e99 415 * \code #define TC_WAVEFORM_FREQUENCY 178 \endcode
mbed_official 107:414e9c822e99 416 * \code #define TC_WAVEFORM_DUTY_CYCLE 30 \endcode
mbed_official 107:414e9c822e99 417 * \code
mbed_official 107:414e9c822e99 418 * static void tc_waveform_initialize(void)
mbed_official 107:414e9c822e99 419 * {
mbed_official 107:414e9c822e99 420 * uint32_t ra, rc;
mbed_official 107:414e9c822e99 421 *
mbed_official 107:414e9c822e99 422 * // Configure the PMC to enable the TC module.
mbed_official 107:414e9c822e99 423 * sysclk_enable_peripheral_clock(ID_TC_WAVEFORM);
mbed_official 107:414e9c822e99 424 *
mbed_official 107:414e9c822e99 425 * // Init TC to waveform mode.
mbed_official 107:414e9c822e99 426 * tc_init(TC, TC_CHANNEL_WAVEFORM,
mbed_official 107:414e9c822e99 427 * TC_WAVEFORM_TIMER_SELECTION // Waveform Clock Selection
mbed_official 107:414e9c822e99 428 * | TC_CMR_WAVE // Waveform mode is enabled
mbed_official 107:414e9c822e99 429 * | TC_CMR_ACPA_SET // RA Compare Effect: set
mbed_official 107:414e9c822e99 430 * | TC_CMR_ACPC_CLEAR // RC Compare Effect: clear
mbed_official 107:414e9c822e99 431 * | TC_CMR_CPCTRG // UP mode with automatic trigger on RC Compare
mbed_official 107:414e9c822e99 432 * );
mbed_official 107:414e9c822e99 433 *
mbed_official 107:414e9c822e99 434 * // Configure waveform frequency and duty cycle.
mbed_official 107:414e9c822e99 435 * rc = (sysclk_get_peripheral_bus_hz(TC) /
mbed_official 107:414e9c822e99 436 * TC_WAVEFORM_DIVISOR /
mbed_official 107:414e9c822e99 437 * TC_WAVEFORM_FREQUENCY;
mbed_official 107:414e9c822e99 438 * tc_write_rc(TC, TC_CHANNEL_WAVEFORM, rc);
mbed_official 107:414e9c822e99 439 * ra = (100 - TC_WAVEFORM_FREQUENCY_DUTY_CYCLE * rc / 100;
mbed_official 107:414e9c822e99 440 * tc_write_ra(TC, TC_CHANNEL_WAVEFORM, ra);
mbed_official 107:414e9c822e99 441 *
mbed_official 107:414e9c822e99 442 * // Enable TC TC_CHANNEL_WAVEFORM.
mbed_official 107:414e9c822e99 443 * tc_start(TC, TC_CHANNEL_WAVEFORM);
mbed_official 107:414e9c822e99 444 * } \endcode
mbed_official 107:414e9c822e99 445 *
mbed_official 107:414e9c822e99 446 * \subsection asfdoc_sam_drivers_tc_qsg_basic_waveform_setup_workflow Workflow
mbed_official 107:414e9c822e99 447 *
mbed_official 107:414e9c822e99 448 * -# Enable the TC module's waveform pin:
mbed_official 107:414e9c822e99 449 * \snippet tc_capture_waveform_example.c tc_waveform_gpio
mbed_official 107:414e9c822e99 450 * -# Initialize the waveform channel to the following:
mbed_official 107:414e9c822e99 451 * - Output frequency of 178Hz, with a duty-cycle of 30%
mbed_official 107:414e9c822e99 452 * - Use TC_CMR_TCCLKS_TIMER_CLOCK4, with a divisor of 128
mbed_official 107:414e9c822e99 453 * \snippet tc_capture_waveform_example.c tc_waveform_init_call
mbed_official 107:414e9c822e99 454 */
mbed_official 107:414e9c822e99 455 #endif /* TC_H_INCLUDED */