timer.h

Go to the documentation of this file.
00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
00023 /* ************************************************************************
00024 
00025 Copyright (c) 2006, Atmel Corporation All rights reserved. 
00026 
00027 Redistribution and use in source and binary forms, with or without
00028 modification, are permitted provided that the following conditions are met:
00029 
00030 1. Redistributions of source code must retain the above copyright notice,
00031 this list of conditions and the 
00032 following disclaimer. 
00033 
00034 2. Redistributions in binary form must reproduce the above copyright notice,
00035 this list of conditions and the following disclaimer in the documentation
00036 and/or other materials provided with the distribution.
00037 
00038 3. The name of ATMEL may not be used to endorse or promote products 
00039 derived from this software without specific prior written permission.  
00040 
00041 THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS 
00042 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00043 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
00044 PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY 
00045 DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00046 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
00047 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00048 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00049 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
00050 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
00051 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 
00052 WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00053 
00054 POSSIBILITY OF SUCH DAMAGE. 
00055 
00056 ************************************************************************ */
00057 
00058 #ifndef _TIMER_H_
00059 #define _TIMER_H_
00060 
00061 #ifdef __GNUC__
00062 #include <avr32/io.h>
00063 #elif __ICCAVR32__
00064 #include <avr32/ioap7000.h>
00065 #else
00066 #error No known compiler used
00067 #endif
00068 
00069 #define AVR32_TIMER_COUNT  2
00070 #define TIMER_NUMBER_OF_CHANNELS 3
00071 
00072 #define TIMER_INVALID_ARGUMENT          -1
00073 #define TIMER_NUMBER_OF_CHANNELS                3
00074 
00075 #define TIMER_COUNTING_MODE_RESTART     0
00076 #define TIMER_COUNTING_MODE_INVERT              1
00077 
00078 #define TIMER_CLOCK_SOURCE_TC1          0
00079 #define TIMER_CLOCK_SOURCE_TC2          1
00080 #define TIMER_CLOCK_SOURCE_TC3          2
00081 #define TIMER_CLOCK_SOURCE_TC4          3
00082 #define TIMER_CLOCK_SOURCE_TC5          4
00083 #define TIMER_CLOCK_SOURCE_XC0          5
00084 #define TIMER_CLOCK_SOURCE_XC1          6
00085 #define TIMER_CLOCK_SOURCE_XC2          7
00086 
00087 #define TIMER_CLOCK_RISING_EDGE         0
00088 #define TIMER_CLOCK_FALLING_EDGE                1
00089 
00090 #define TIMER_TRIGGER_SW                        11
00091 #define TIMER_TRIGGER_SYNC                      12
00092 #define TIMER_TRIGGER_COMPARE_RC                13
00093 
00094 #define TIMER_RB_LOAD_STOP                      1
00095 #define TIMER_RB_LOAD_DISABLE                   2
00096 
00097 #define TIMER_SEL_NO_EDGE                       0
00098 #define TIMER_SEL_RISING_EDGE                   1
00099 #define TIMER_SEL_FALLING_EDGE          2
00100 #define TIMER_SEL_EACH_EDGE                     3
00101 
00102 #define TIMER_EXT_TRIG_SEL_TIOA         1
00103 #define TIMER_EXT_TRIG_SEL_TIOB         0
00104 
00105 /* Operating modes */
00106 #define TIMER_CAPTURE_OPERATING_MODE    0
00107 
00108 #define TIMER_WAVEFORM_OPERATING_MODE           1
00109 
00110 #define TIMER_WAVEFORM_SEL_UP_MODE                              0
00111 #define TIMER_WAVEFORM_SEL_UP_MODE_RC_TRIGGER           2
00112 #define TIMER_WAVEFORM_SEL_UPDOWN_MODE_RC_TRIGGER       1
00113 #define TIMER_WAVEFORM_SEL_UPDOWN_MODE                  3
00114 
00115 #define TIMER_SUCCESS 0
00116 #define TIMER_INVALID_ARGUMENT -1
00117 
00121 struct timer_capture_opt_t{
00122 
00124   int channel;
00125   
00135   int tcclks:3;
00136 
00138   int clki:1;
00139   
00145   int burst:2;
00146 
00148   int ldbstop:1;
00149   
00151   int ldbdis:1;
00152   
00158   int etrgedg:2;
00159   
00161   int abetrg:1;
00162   
00164   int cpctrg:1;
00165   
00171   int ldra:2;
00172   
00178   int ldrb:2;
00179   
00180 };
00181 
00185 struct timer_waveform_opt_t{
00186 
00188   int channel;
00189 
00199   int tcclks:3;
00200   
00202   int clki:1;
00203   
00209   int burst:2;
00210   
00212   int cpcstop:1;
00213   
00215   int cpcdis:1;
00216   
00222   int eevtedg:1;
00223   
00229   int eevt:2;
00230   
00232   int enetrg:1;
00233 
00239   int wavsel:2;
00240 
00246   int acpa:2;
00247 
00253   int acpc:2;
00254 
00260   int aeevt:2;
00261 
00267   int aswtrg:2;
00268 
00274   int bcpb:2;
00275 
00281   int bcpc:2;
00282 
00288   int beevt:2;
00289 
00295   int bswtrg:2;
00296 };
00297 
00298 struct timer_interrupt_t{
00300         int covfs :1;
00301 
00303         int lovrs :1;
00304 
00306         int cpas :1;
00307 
00309         int cpbs :1;
00310 
00312         int cpcs :1;
00313 
00315         int ldras :1;
00316 
00318         int ldrbs :1;
00319 
00321         int etrgs :1;
00322 };
00323 
00324 /* ************************************************************************
00325 
00326 INIT FUNCTIONS
00327 
00328 ************************************************************************ */
00329 
00336 int timer_init_capture( unsigned int instance, volatile struct timer_capture_opt_t *opt );
00337 
00338 
00345 int timer_init_waveform( unsigned int instance, volatile struct timer_waveform_opt_t *opt );
00346 
00347 
00348 /* ************************************************************************
00349 
00350 START / STOP FUNCTIONS
00351 
00352 ************************************************************************ */
00353 
00360 int timer_start( unsigned int instance, unsigned int channel );
00361 
00362 
00369 int timer_stop( unsigned int instance, unsigned int channel );
00370 
00371 
00372 /* ************************************************************************
00373 
00374 TRIGGER AND CLOCK SELECTIONS
00375 
00376 ************************************************************************ */
00377 
00384 int timer_software_trigger( unsigned int instance, unsigned int channel);
00385 
00386 
00392 void timer_sync_trigger( unsigned int instance );
00393 
00394 
00402 int timer_external_clock_selection( unsigned int instance, unsigned int channel, unsigned int clock_signal );
00403 
00404 
00405 /* ************************************************************************
00406 
00407 READ / WRITE COMPARE REGISTERS AND COUNTER CLOCK
00408 
00409 ************************************************************************ */
00410 
00417 int timer_read_ra( unsigned int instance, unsigned int channel );
00418 
00419 
00426 int timer_read_rb( unsigned int instance, unsigned int channel );
00427 
00428 
00435 int timer_read_rc( unsigned int instance, unsigned int channel );
00436 
00437 
00444 int timer_read_tc( unsigned int instance, unsigned int channel );
00445 
00446 
00454 int timer_write_ra( unsigned int instance, unsigned int channel, unsigned short value );
00455 
00456 
00464 int timer_write_rb( unsigned int instance, unsigned int channel, unsigned short value );
00465 
00466 
00474 int timer_write_rc( unsigned int instance, unsigned int channel, unsigned short value );
00475 
00476 
00477 /* ************************************************************************
00478 
00479 INTERRUPT FUNCTIONS
00480 
00481 ************************************************************************ */
00482 
00490 int timer_configure_interrupts(unsigned int instance, unsigned int channel, volatile struct timer_interrupt_t *bitfield);
00491 
00492 
00499 char timer_interrupt_settings(unsigned int instance, unsigned int channel);
00500 
00501 
00502 /* ************************************************************************
00503 
00504 VARIOUS FUNCTIONS
00505 
00506 ************************************************************************ */
00507 
00513 volatile avr32_timer_t * timer_getHandle( unsigned int instance );
00514 
00515 
00522 unsigned long timer_read_sr( unsigned int instance, unsigned int channel );
00523 
00524 
00525 #endif

Generated on Fri Oct 13 09:41:12 2006 for AVR32110 Using the AVR32 Timer/Counter by  doxygen 1.4.7