• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

timer8_drv.h

Go to the documentation of this file.
00001 /*This file is prepared for Doxygen automatic documentation generation.*/
00013 
00014 /* Copyright (c) 2009 Atmel Corporation. All rights reserved.
00015  *
00016  * Redistribution and use in source and binary forms, with or without
00017  * modification, are permitted provided that the following conditions are met:
00018  *
00019  * 1. Redistributions of source code must retain the above copyright notice,
00020  * this list of conditions and the following disclaimer.
00021  *
00022  * 2. Redistributions in binary form must reproduce the above copyright notice,
00023  * this list of conditions and the following disclaimer in the documentation
00024  * and/or other materials provided with the distribution.
00025  *
00026  * 3. The name of Atmel may not be used to endorse or promote products derived
00027  * from this software without specific prior written permission.
00028  *
00029  * 4. This software may only be redistributed and used in connection with an Atmel
00030  * AVR product.
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, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 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 _TIMER8_DRV_H_
00046 #define _TIMER8_DRV_H_
00047 
00048 //_____ I N C L U D E S ________________________________________________________
00049 
00050 #include "config.h"
00051 
00052 //_____ G E N E R A L    D E F I N I T I O N S _________________________________
00053 
00054 #ifndef FOSC
00055 #  error  You must define FOSC in "config.h" file
00056 #endif
00057     // ----------
00058 #ifndef TIMER8_0             // 8-bit TIMER 0 Defintion
00059 #define TIMER8_0        0x00
00060 #endif
00061 #ifndef TIMER8_2             // 8-bit TIMER 2 Defintion
00062 #define TIMER8_2        0x02
00063 #endif
00064 #ifndef BOTH_TIMER8          // Both the 8-bit TIMERs Defintion
00065 #define BOTH_TIMER8     0xFF
00066 #endif
00067 
00068 //_____ M A C R O S ____________________________________________________________
00069 
00070     // ---------- Two ways to have a look on the things
00071 #define Timer8_set_pwm_a(value)    ( Timer8_set_compare_a(value) )
00072 #define Timer8_set_pwm(value)      ( Timer8_set_pwm_a(value) )
00073 #define Timer8_get_pwm_a()         ( Timer8_get_compare_a() )
00074 #define Timer8_get_pwm()           ( Timer8_get_pwm_a() )
00075     // ---------- If no clock, the timer is off !
00076 #define Timer8_off()                 Timer8_set_clock(TIMER8_NO_CLOCK)
00077 
00078     
00079 #ifndef USE_TIMER8
00080 #       error You must define USE_TIMER8 to TIMER8_0 in "config.h" file
00081 
00082 #   elif (USE_TIMER8 == TIMER8_0)        //!< 8-bit TIMER 0 used
00083 
00084 
00085 
00086 #       define Timer8_select(timer8_num)        // Empty !
00087     // ---------- Macros
00088 #       define Timer8_clear()                  { TCCR0A=0; TCNT0=0; OCR0A=0; }
00089         // ----------
00090 #       define Timer8_set_counter(value)       ( TCNT0 = value )
00091 #       define Timer8_get_counter()            ( TCNT0 )
00092         // ----------
00093 #       define Timer8_set_compare_a(value)     ( OCR0A = value )
00094 #       define Timer8_set_compare(value)       ( Timer8_set_compare_a(value) )          // No index specified
00095 #       define Timer8_get_compare_a()          ( OCR0A )
00096 #       define Timer8_get_compare()            ( Timer8_get_compare_a() )               // No index specified
00097         // ----------
00098 #       define Timer8_set_mode_output_a(conf)  ( TCCR0A = (TCCR0A & (~TIMER8_COMP_MODE_MASK_A)) | (conf << COM0A0) )
00099 #       define Timer8_set_mode_output(conf)    ( Timer8_set_mode_output_a(conf) )       // No index specified
00100 #       define Timer8_get_mode_output_a()      ((TCCR0A & TIMER8_COMP_MODE_MASK_A) >> COM0A0 )
00101 #       define Timer8_get_mode_output()        ( Timer8_get_mode_output_a() )           // No index specified
00102         // ----------
00103 #       define Timer8_set_waveform_mode(conf)  ( TCCR0A = (TCCR0A & (~TIMER8_WGM_RA_MASK)) |  \
00104                                                ( (((conf & 0x02) >> 1) << WGM01) | ((conf & 0x1) << WGM00) ) )
00105 #       define Timer8_get_waveform_mode()      ( ((TCCR0A & (1<<WGM00)) >> WGM00) |  \
00106                                                ( ((TCCR0A & (1<<WGM01)) >> WGM01) << 0x1) )
00107         // ----------
00108 #       define Timer8_set_clock(value)         ( TCCR0B = (TCCR0B & (~TIMER8_CLK_MASK)) | (value << CS00) )
00109 #       define Timer8_get_clock()              ((TCCR0B & TIMER8_CLK_MASK) >> CS00 )
00110         // ----------
00111 #       define Timer8_overflow_it_enable()    ( TIMSK0 |=  (1<<TOIE0)  )
00112 #       define Timer8_overflow_it_disable()   ( TIMSK0 &= ~(1<<TOIE0)  )
00113 #       define Timer8_compare_a_it_enable()   ( TIMSK0 |=  (1<<OCIE0A) )
00114 #       define Timer8_compare_a_it_disable()  ( TIMSK0 &= ~(1<<OCIE0A) )
00115 #       define Timer8_compare_it_enable()     ( Timer8_compare_a_it_enable()  )
00116 #       define Timer8_compare_it_disable()    ( Timer8_compare_a_it_disable() )
00117 
00118 #       define Timer8_get_overflow_it_mask()  ((TIMSK0  &  (1<<TOIE0) ) >> TOIE0  )
00119 #       define Timer8_get_compare_a_it_mask() ((TIMSK0  &  (1<<OCIE0A)) >> OCIE0A )
00120 #       define Timer8_get_compare_it_mask()   ( Timer8_get_compare_a_it_mask() )
00121         // ----------
00122 #       define Timer8_clear_overflow_it()     ( TIFR0 |=  (1<<TOV0)  )
00123 #       define Timer8_clear_compare_a_it()    ( TIFR0 |=  (1<<OCF0A) )
00124 #       define Timer8_clear_compare_it()      ( Timer8_clear_compare_a_it() )
00125 #       define Timer8_get_overflow_it()       ((TIFR0  &  (1<<TOV0) ) >> TOV0  )
00126 #       define Timer8_get_compare_a_it()      ((TIFR0  &  (1<<OCF0A)) >> OCF0A )
00127 #       define Timer8_get_compare_it()        ( Timer8_get_compare_a_it() )
00128 
00129     #else
00130         #error USE_TIMER8 definition is not referenced in "timer8_drv.h" file
00131 #endif
00132 
00133 
00137         // ---------- CLK SOURCE for TIMER 2 
00138 #       define Timer8_2_system_clk()          ( ASSR &= ~((1<<EXCLK)|(1<<AS2)) )
00139 #       define Timer8_2_external_osc()        ( ASSR  =  (ASSR & ~(1<<EXCLK)) | (1<<AS2) )
00140 #       define Timer8_2_external_clk()        ( ASSR |=  ((1<<EXCLK)|(1<<AS2)) )
00141         // ---------- UPDATE in ASYNCHRONOUS OPERATION 
00142 #       define Timer8_2_update_busy()         ( ASSR & ( (1<<TCN2UB) | (1<<OCR2UB) | (1<<TCR2UB) ) )
00143 
00144 
00145 //_____ T I M E R   D E F I N I T I O N S ______________________________________
00146 
00147     // ---------- Pre-definitions for "conf" field for Timer8_set(get)_mode_output_x(conf) macros
00148 #define TIMER8_COMP_MODE_NORMAL    (0)
00149 #define TIMER8_COMP_MODE_TOGGLE    (1)
00150 #define TIMER8_COMP_MODE_CLEAR_OC  (2)
00151 #define TIMER8_COMP_MODE_SET_OC    (3)
00152 #define TIMER8_COMP_MODE_MASK_A    (3<<COM0A0)
00153     // ---------- Pre-definitions for "conf" field for Timer8_set_waveform_mode(conf) macro
00154 #define TIMER8_WGM_NORMAL          (0)
00155 #define TIMER8_WGM_PWM_PC8         (1)
00156 #define TIMER8_WGM_CTC_OCR         (2)
00157 #define TIMER8_WGM_FAST_PWM8       (3)
00158 #define TIMER8_WGM_RA_MASK         ( (1<<WGM00) | (1<<WGM01) )
00159     // ---------- Pre-definitions for "value" field for Timer8_set_clock(value) macro
00160 #define TIMER8_NO_CLOCK                   (0)
00161 #define TIMER8_CLKIO_BY_1                 (1)
00162 #define TIMER8_CLK_MASK                   (7<<CS00)
00163         // ---------- and especally for TIMER 0
00164 #define TIMER8_0_NO_CLOCK                 (0)
00165 #define TIMER8_0_CLKIO_BY_1               (1)
00166 #define TIMER8_0_CLKIO_BY_8               (2)
00167 #define TIMER8_0_CLKIO_BY_64              (3)
00168 #define TIMER8_0_CLKIO_BY_256             (4)
00169 #define TIMER8_0_CLKIO_BY_1024            (5)
00170 #define TIMER8_0_EXT_CLOCK_FALLING_EDGE   (6)
00171 #define TIMER8_0_EXT_CLOCK_RISING_EDGE    (7)
00172         // ---------- and especally for TIMER 2
00173 #define TIMER8_2_NO_CLOCK                 (0)
00174 #define TIMER8_2_CLKIO_BY_1               (1)
00175 #define TIMER8_2_CLKIO_BY_8               (2)
00176 #define TIMER8_2_CLKIO_BY_32              (3)
00177 #define TIMER8_2_CLKIO_BY_64              (4)
00178 #define TIMER8_2_CLKIO_BY_128             (5)
00179 #define TIMER8_2_CLKIO_BY_256             (6)
00180 #define TIMER8_2_CLKIO_BY_1024            (7)
00181 
00182 
00183 //_____ D E C L A R A T I O N S ________________________________________________
00184 
00185 //------------------------------------------------------------------------------
00186 //  @fn timer8_get_counter
00196 extern  U8 timer8_get_counter(void);
00197 
00198 //______________________________________________________________________________
00199 
00200 #endif  // _TIMER8_DRV_H_
00201 
00202 
00203 
00204 
00205 
00206 
00207 
00208 
00209 
00210 
00211 
00212 
00213 
00214 
00215 
00216 
00217 
00218 
00219 
00220 
00221 
00222 
00223 
00224 
00225 
00226 
00227 
00228 
00229 
00230 

Generated on Tue Nov 8 2011 16:29:45 for ATMEL by  doxygen 1.7.2