tc.h 55 KB

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