- Main Page
- Related Pages
- Data Structures
- Files

# tc.h

Go to the documentation of this file.

    00001 /*This file is prepared for Doxygen automatic documentation generation.*/
    00017 /* Copyright (C) 2006-2008, Atmel Corporation All rights reserved.
    00018  *
    00019  * Redistribution and use in source and binary forms, with or without
    00020  * modification, are permitted provided that the following conditions are met:
    00021  *
    00022  * 1. Redistributions of source code must retain the above copyright notice,
    00023  * this list of conditions and the following disclaimer.
    00024  *
    00025  * 2. Redistributions in binary form must reproduce the above copyright notice,
    00026  * this list of conditions and the following disclaimer in the documentation
    00027  * and/or other materials provided with the distribution.
    00028  *
    00029  * 3. The name of ATMEL may not be used to endorse or promote products derived
    00030  * from this software without specific prior written permission.
    00031  *
    00032  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
    00033  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00034  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
    00035  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
    00036  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    00037  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    00038  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    00039  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00040  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    00041  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00042  */
    00043
    00044
    00045 #ifndef _TC_H_
    00046 #define _TC_H_
    00047
    00048 #include <avr32/io.h>
    00049
    00050
    00052 #define TC_INVALID_ARGUMENT                     (-1)
    00053
    00055 #define TC_NUMBER_OF_CHANNELS                   (sizeof(((avr32_tc_t *)0)->channel) / sizeof(avr32_tc_channel_t))
    00056
    00059
    00060 #define TC_CH0_EXT_CLK0_SRC_TCLK0               AVR32_TC_TC0XC0S_TCLK0
    00061 #define TC_CH0_EXT_CLK0_SRC_NO_CLK              AVR32_TC_TC0XC0S_NO_CLK
    00062 #define TC_CH0_EXT_CLK0_SRC_TIOA1               AVR32_TC_TC0XC0S_TIOA1
    00063 #define TC_CH0_EXT_CLK0_SRC_TIOA2               AVR32_TC_TC0XC0S_TIOA2
    00065
    00066
    00068
    00069 #define TC_CH1_EXT_CLK1_SRC_TCLK1               AVR32_TC_TC1XC1S_TCLK1
    00070 #define TC_CH1_EXT_CLK1_SRC_NO_CLK              AVR32_TC_TC1XC1S_NO_CLK
    00071 #define TC_CH1_EXT_CLK1_SRC_TIOA0               AVR32_TC_TC1XC1S_TIOA0
    00072 #define TC_CH1_EXT_CLK1_SRC_TIOA2               AVR32_TC_TC1XC1S_TIOA2
    00074
    00075
    00077
    00078 #define TC_CH2_EXT_CLK2_SRC_TCLK2               AVR32_TC_TC2XC2S_TCLK2
    00079 #define TC_CH2_EXT_CLK2_SRC_NO_CLK              AVR32_TC_TC2XC2S_NO_CLK
    00080 #define TC_CH2_EXT_CLK2_SRC_TIOA0               AVR32_TC_TC2XC2S_TIOA0
    00081 #define TC_CH2_EXT_CLK2_SRC_TIOA1               AVR32_TC_TC2XC2S_TIOA1
    00083
    00084
    00086
    00087 #define TC_EVT_EFFECT_NOOP                      AVR32_TC_NONE
    00088 #define TC_EVT_EFFECT_SET                       AVR32_TC_SET
    00089 #define TC_EVT_EFFECT_CLEAR                     AVR32_TC_CLEAR
    00090 #define TC_EVT_EFFECT_TOGGLE                    AVR32_TC_TOGGLE
    00092
    00093
    00095
    00096 #define TC_NO_TRIGGER_COMPARE_RC                0
    00097 #define TC_TRIGGER_COMPARE_RC                   1
    00099
    00100
    00102
    00103 #define TC_WAVEFORM_SEL_UP_MODE                 AVR32_TC_WAVSEL_UP_NO_AUTO
    00104 #define TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER      AVR32_TC_WAVSEL_UP_AUTO
    00105 #define TC_WAVEFORM_SEL_UPDOWN_MODE             AVR32_TC_WAVSEL_UPDOWN_NO_AUTO
    00106 #define TC_WAVEFORM_SEL_UPDOWN_MODE_RC_TRIGGER  AVR32_TC_WAVSEL_UPDOWN_AUTO
    00108
    00109
    00111
    00112 #define TC_EXT_TRIG_SEL_TIOA                    1
    00113 #define TC_EXT_TRIG_SEL_TIOB                    0
    00115
    00116
    00118
    00119 #define TC_EXT_EVENT_SEL_TIOB_INPUT             AVR32_TC_EEVT_TIOB_INPUT
    00120 #define TC_EXT_EVENT_SEL_XC0_OUTPUT             AVR32_TC_EEVT_XC0_OUTPUT
    00121 #define TC_EXT_EVENT_SEL_XC1_OUTPUT             AVR32_TC_EEVT_XC1_OUTPUT
    00122 #define TC_EXT_EVENT_SEL_XC2_OUTPUT             AVR32_TC_EEVT_XC2_OUTPUT
    00124
    00125
    00127
    00128 #define TC_SEL_NO_EDGE                          AVR32_TC_EEVTEDG_NO_EDGE
    00129 #define TC_SEL_RISING_EDGE                      AVR32_TC_EEVTEDG_POS_EDGE
    00130 #define TC_SEL_FALLING_EDGE                     AVR32_TC_EEVTEDG_NEG_EDGE
    00131 #define TC_SEL_EACH_EDGE                        AVR32_TC_EEVTEDG_BOTH_EDGES
    00133
    00134
    00136
    00137 #define TC_BURST_NOT_GATED                      AVR32_TC_BURST_NOT_GATED
    00138 #define TC_BURST_CLK_AND_XC0                    AVR32_TC_BURST_CLK_AND_XC0
    00139 #define TC_BURST_CLK_AND_XC1                    AVR32_TC_BURST_CLK_AND_XC1
    00140 #define TC_BURST_CLK_AND_XC2                    AVR32_TC_BURST_CLK_AND_XC2
    00142
    00143
    00145
    00146 #define TC_CLOCK_RISING_EDGE                    0
    00147 #define TC_CLOCK_FALLING_EDGE                   1
    00149
    00150
    00152
    00153 #define TC_CLOCK_SOURCE_TC1                     AVR32_TC_TCCLKS_TIMER_CLOCK1
    00154 #define TC_CLOCK_SOURCE_TC2                     AVR32_TC_TCCLKS_TIMER_CLOCK2
    00155 #define TC_CLOCK_SOURCE_TC3                     AVR32_TC_TCCLKS_TIMER_CLOCK3
    00156 #define TC_CLOCK_SOURCE_TC4                     AVR32_TC_TCCLKS_TIMER_CLOCK4
    00157 #define TC_CLOCK_SOURCE_TC5                     AVR32_TC_TCCLKS_TIMER_CLOCK5
    00158 #define TC_CLOCK_SOURCE_XC0                     AVR32_TC_TCCLKS_XC0
    00159 #define TC_CLOCK_SOURCE_XC1                     AVR32_TC_TCCLKS_XC1
    00160 #define TC_CLOCK_SOURCE_XC2                     AVR32_TC_TCCLKS_XC2
    00162
    00163
    00165 typedef struct
    00166 {
    00167   unsigned int                 :24;
    00168
    00170   unsigned int etrgs           : 1;
    00171
    00173   unsigned int ldrbs           : 1;
    00174
    00176   unsigned int ldras           : 1;
    00177
    00179   unsigned int cpcs            : 1;
    00180
    00182   unsigned int cpbs            : 1;
    00183
    00185   unsigned int cpas            : 1;
    00186
    00188   unsigned int lovrs           : 1;
    00189
    00191   unsigned int covfs           : 1;
    00192 } tc_interrupt_t;
    00193
    00195 typedef struct
    00196 {
    00198   unsigned int channel            ;
    00199
    00200   unsigned int                 :12;
    00201
    00207   unsigned int ldrb            : 2;
    00208
    00214   unsigned int ldra            : 2;
    00215
    00216   unsigned int                 : 1;
    00217
    00221   unsigned int cpctrg          : 1;
    00222
    00223   unsigned int                 : 3;
    00224
    00228   unsigned int abetrg          : 1;
    00229
    00235   unsigned int etrgedg         : 2;
    00236
    00240   unsigned int ldbdis          : 1;
    00241
    00245   unsigned int ldbstop         : 1;
    00246
    00252   unsigned int burst           : 2;
    00253
    00257   unsigned int clki            : 1;
    00258
    00268   unsigned int tcclks          : 3;
    00269 } tc_capture_opt_t;
    00270
    00272 typedef struct
    00273 {
    00275   unsigned int channel            ;
    00276
    00282   unsigned int bswtrg          : 2;
    00283
    00289   unsigned int beevt           : 2;
    00290
    00296   unsigned int bcpc            : 2;
    00297
    00303   unsigned int bcpb            : 2;
    00304
    00310   unsigned int aswtrg          : 2;
    00311
    00317   unsigned int aeevt           : 2;
    00318
    00324   unsigned int acpc            : 2;
    00325
    00331   unsigned int acpa            : 2;
    00332
    00333   unsigned int                 : 1;
    00334
    00340   unsigned int wavsel          : 2;
    00341
    00345   unsigned int enetrg          : 1;
    00346
    00352   unsigned int eevt            : 2;
    00353
    00359   unsigned int eevtedg         : 2;
    00360
    00364   unsigned int cpcdis          : 1;
    00365
    00369   unsigned int cpcstop         : 1;
    00370
    00376   unsigned int burst           : 2;
    00377
    00381   unsigned int clki            : 1;
    00382
    00392   unsigned int tcclks          : 3;
    00393 } tc_waveform_opt_t;
    00394
    00395
    00404 extern int tc_get_interrupt_settings(volatile avr32_tc_t *tc, unsigned int channel);
    00405
    00415 extern int tc_configure_interrupts(volatile avr32_tc_t *tc, unsigned int channel, const tc_interrupt_t *bitfield);
    00416
    00438 extern int tc_select_external_clock(volatile avr32_tc_t *tc, unsigned int channel, unsigned int ext_clk_sig_src);
    00439
    00448 extern int tc_init_capture(volatile avr32_tc_t *tc, const tc_capture_opt_t *opt);
    00449
    00458 extern int tc_init_waveform(volatile avr32_tc_t *tc, const tc_waveform_opt_t *opt);
    00459
    00468 extern int tc_start(volatile avr32_tc_t *tc, unsigned int channel);
    00469
    00478 extern int tc_stop(volatile avr32_tc_t *tc, unsigned int channel);
    00479
    00488 extern int tc_software_trigger(volatile avr32_tc_t *tc, unsigned int channel);
    00489
    00494 extern void tc_sync_trigger(volatile avr32_tc_t *tc);
    00495
    00500 extern void tc_sync_start(volatile avr32_tc_t *tc);
    00501
    00510 extern int tc_read_sr(volatile avr32_tc_t *tc, unsigned int channel);
    00511
    00520 extern int tc_read_tc(volatile avr32_tc_t *tc, unsigned int channel);
    00521
    00530 extern int tc_read_ra(volatile avr32_tc_t *tc, unsigned int channel);
    00531
    00540 extern int tc_read_rb(volatile avr32_tc_t *tc, unsigned int channel);
    00541
    00550 extern int tc_read_rc(volatile avr32_tc_t *tc, unsigned int channel);
    00551
    00561 extern int tc_write_ra(volatile avr32_tc_t *tc, unsigned int channel, unsigned short value);
    00562
    00572 extern int tc_write_rb(volatile avr32_tc_t *tc, unsigned int channel, unsigned short value);
    00573
    00583 extern int tc_write_rc(volatile avr32_tc_t *tc, unsigned int channel, unsigned short value);
    00584
    00585
    00586 #endif  // _TC_H_