- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

# timer16_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 _TIMER16_DRV_H_
    00046 #define _TIMER16_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 TIMER16_1            // 16-bit TIMER 1 Defintion
    00059 #define TIMER16_1       0x01
    00060 #endif
    00061 #ifndef TIMER16_3            // 16-bit TIMER 3 Defintion
    00062 #define TIMER16_3       0x03
    00063 #endif
    00064 #ifndef BOTH_TIMER16         // Both the 16-bit TIMERs Defintion
    00065 #define BOTH_TIMER16    0xFF
    00066 #endif
    00067
    00068 //_____ M A C R O S ____________________________________________________________
    00069
    00070     // ---------- To order the loading (reading) of 16-bit registers
    00071 #define Timer16_get_counter()       ( timer16_get_counter() )        // c.f. "timer16_drv.c" file
    00072 #define Timer16_get_capture()       ( timer16_get_capture() )        // c.f. "timer16_drv.c" file
    00073     // ---------- Two ways to have a look on the things
    00074 #define Timer16_set_pwm_a(value)    ( Timer16_set_compare_a(value) ) // c.f. above !
    00075 #define Timer16_set_pwm_b(value)    ( Timer16_set_compare_b(value) ) // c.f. above !
    00076 #define Timer16_set_pwm_c(value)    ( Timer16_set_compare_c(value) ) // c.f. above !
    00077 #define Timer16_get_pwm_a()         ( Timer16_get_compare_a() )      // c.f. above !
    00078 #define Timer16_get_pwm_b()         ( Timer16_get_compare_b() )      // c.f. above !
    00079 #define Timer16_get_pwm_c()         ( Timer16_get_compare_c() )      // c.f. above !
    00080     // ---------- If no clock, the timer is off !
    00081 #define Timer16_off()                 Timer16_set_clock(TIMER16_NO_CLOCK)
    00082
    00083 //_____ D E F .  &   M A C R O S   for   H W   C O N F . _______________________
    00084
    00085     //----- CARE WITH THE ORDER WHEN 16-BIT REGISTERS ARE READ
    00086     //      ==================================================
    00087     //----- For sensitive 16-bit registers (c.f. temporary reg), the macros are:
    00088     //-----     *  Timer16_get_nnn_low()
    00089     //-----     *  Timer16_get_nnn_high()
    00090     //----- For instance, in your main, do not write:
    00091     //-----     short_temp = ((Timer16_get_nnn_high())<<8) | (Timer16_get_nnn_low());
    00092     //-----   or
    00093     //-----     short_temp = (Timer16_get_nnn_low()) | ((Timer16_get_nnn_high())<<8);
    00094     //-----   because IAR and ImageCraft doesn't evaluate the operandes in the same order!
    00095     //-----
    00096     //----- The good way to write a READ (load) sequence is in 2 times:
    00097     //-----     short_temp  =  Timer16_get_nnn_low();
    00098     //-----     short_temp |= (Timer16_get_nnn_high() << 8 );
    00099     //-----
    00100     //----- Otherwise a macro "Timer16_get_nnn()" exits and call "timer16_get_counter()" function
    00101
    00102 #ifndef USE_TIMER16
    00103 #       error You must define USE_TIMER16 to TIMER16_1 or TIMER16_3 or BOTH_TIMER16 in "config.h" file
    00104 #   elif (USE_TIMER16 == TIMER16_1)        //!< 16-bit TIMER 1 used
    00105
    00106
    00107
    00108 #       define Timer16_select(timer16_num)     // Empty !
    00109     // ---------- Macros
    00110 #       define Timer16_clear()  ( TCCR1B=0, TCCR1A=0, TCCR1C=0, TCNT1H=0, TCNT1L= 0, OCR1AH=0, OCR1AL=0, \
    00111                                   OCR1BH=0, OCR1BL=0, OCR1CH=0, OCR1CL=0, ICR1H=0, ICR1L=0              )
    00112         // ----------
    00113 #       define Timer16_set_counter(value)       ( TCNT1H = ((U8)(value>>8)), TCNT1L = ((U8)(value)))
    00114 #       define Timer16_get_counter_low()        ((U16)(TCNT1L))
    00115 #       define Timer16_get_counter_high()       ((U16)(TCNT1H))
    00116         // ----------
    00117 #       define Timer16_set_compare_a(value)     ( OCR1AH = ((U8)(value>>8)), OCR1AL = ((U8)(value)))
    00118 #       define Timer16_set_compare_b(value)     ( OCR1BH = ((U8)(value>>8)), OCR1BL = ((U8)(value)))
    00119 #       define Timer16_set_compare_c(value)     ( OCR1CH = ((U8)(value>>8)), OCR1CL = ((U8)(value)))
    00120 #       define Timer16_get_compare_a()          ( OCR1A )      // The temporary register is not used
    00121 #       define Timer16_get_compare_b()          ( OCR1B )      // The temporary register is not used
    00122 #       define Timer16_get_compare_c()          ( OCR1C )      // The temporary register is not used
    00123         // ----------
    00124 #       define Timer16_set_capture(value)       { ICR1H = ((U8)(value>>8)); ICR1L = ((U8)(value)); }
    00125 #       define Timer16_get_capture_low()        ((U16)(ICR1L))
    00126 #       define Timer16_get_capture_high()       ((U16)(ICR1H))
    00127         // ----------
    00128 #       define Timer16_set_mode_output_a(conf)  ( TCCR1A = (TCCR1A & (~TIMER16_COMP_MODE_MASK_A)) | (conf << COM1A0) )
    00129 #       define Timer16_set_mode_output_b(conf)  ( TCCR1A = (TCCR1A & (~TIMER16_COMP_MODE_MASK_B)) | (conf << COM1B0) )
    00130 #       define Timer16_set_mode_output_c(conf)  ( TCCR1A = (TCCR1A & (~TIMER16_COMP_MODE_MASK_C)) | (conf << COM1C0) )
    00131 #       define Timer16_get_mode_output_a()      ((TCCR1A & TIMER16_COMP_MODE_MASK_A) >> COM1A0 )
    00132 #       define Timer16_get_mode_output_b()      ((TCCR1A & TIMER16_COMP_MODE_MASK_B) >> COM1B0 )
    00133 #       define Timer16_get_mode_output_c()      ((TCCR1A & TIMER16_COMP_MODE_MASK_C) >> COM1C0 )
    00134         // ----------
    00135 #       define Timer16_set_waveform_mode(conf)  ( TCCR1A = (TCCR1A & (~TIMER16_WGM_RA_MASK)) | ((conf &  0x3) << WGM10), \
    00136                                                   TCCR1B = (TCCR1B & (~TIMER16_WGM_RB_MASK)) | ((conf >> 0x2) << WGM12)  )
    00137 #       define Timer16_get_waveform_mode()     (((TCCR1A & TIMER16_WGM_RA_MASK) >> WGM10) |         \
    00138                                                (((TCCR1B & TIMER16_WGM_RB_MASK) >> WGM12) << 0x2)   )
    00139         // ----------
    00140 #       define Timer16_set_clock(value)        ( TCCR1B = (TCCR1B & (~TIMER16_CLK_MASK)) | (value << CS10) )
    00141 #       define Timer16_get_clock()            (((TCCR1B & TIMER16_CLK_MASK) >> CS10) )
    00142         // ----------
    00143 #       define Timer16_set_input_filter()      ( TCCR1B |=  (1<<ICNC1) )
    00144 #       define Timer16_clear_input_filter()    ( TCCR1B &= ~(1<<ICNC1) )
    00145 #       define Timer16_get_input_filter()      ((TCCR1B  &  (1<<ICNC1)) >> ICNC1 )
    00146     // ----------
    00147 #       define Timer16_set_input_rising_edge() ( TCCR1B |=  (1<<ICES1) )
    00148 #       define Timer16_set_input_falling_edge()( TCCR1B &= ~(1<<ICES1) )
    00149 #       define Timer16_get_input_capture_edge()((TCCR1B &   (1<<ICES1)) >> ICES1 )
    00150     // ----------
    00151 #       define Timer16_set_compare_force_a()   ( TCCR1C |=  (1<<FOC1A) )
    00152 #       define Timer16_set_compare_force_b()   ( TCCR1C |=  (1<<FOC1B) )
    00153 #       define Timer16_set_compare_force_c()   ( TCCR1C |=  (1<<FOC1C) )
    00154 #       define Timer16_clear_compare_force_a() ( TCCR1C &= ~(1<<FOC1A) )
    00155 #       define Timer16_clear_compare_force_b() ( TCCR1C &= ~(1<<FOC1B) )
    00156 #       define Timer16_clear_compare_force_c() ( TCCR1C &= ~(1<<FOC1C) )
    00157 #       define Timer16_get_compare_force_a()   ((TCCR1C  &  (1<<FOC1A)) >> FOC1A )
    00158 #       define Timer16_get_compare_force_b()   ((TCCR1C  &  (1<<FOC1B)) >> FOC1B )
    00159 #       define Timer16_get_compare_force_c()   ((TCCR1C  &  (1<<FOC1C)) >> FOC1C )
    00160     // ----------
    00161 #       define Timer16_overflow_it_enable()    ( TIMSK1 |=  (1<<TOIE1)  )
    00162 #       define Timer16_overflow_it_disable()   ( TIMSK1 &= ~(1<<TOIE1)  )
    00163 #       define Timer16_compare_a_it_enable()   ( TIMSK1 |=  (1<<OCIE1A) )
    00164 #       define Timer16_compare_a_it_disable()  ( TIMSK1 &= ~(1<<OCIE1A) )
    00165 #       define Timer16_compare_b_it_enable()   ( TIMSK1 |=  (1<<OCIE1B) )
    00166 #       define Timer16_compare_b_it_disable()  ( TIMSK1 &= ~(1<<OCIE1B) )
    00167 #       define Timer16_compare_c_it_enable()   ( TIMSK1 |=  (1<<OCIE1C) )
    00168 #       define Timer16_compare_c_it_disable()  ( TIMSK1 &= ~(1<<OCIE1C) )
    00169 #       define Timer16_capture_it_enable()     ( TIMSK1 |=  (1<<ICIE1)  )
    00170 #       define Timer16_capture_it_disable()    ( TIMSK1 &= ~(1<<ICIE1)  )
    00171 #       define Timer16_get_overflow_it_mask()  ((TIMSK1  &  (1<<TOIE1) ) >> TOIE1  )
    00172 #       define Timer16_get_compare_a_it_mask() ((TIMSK1  &  (1<<OCIE1A)) >> OCIE1A )
    00173 #       define Timer16_get_compare_b_it_mask() ((TIMSK1  &  (1<<OCIE1B)) >> OCIE1B )
    00174 #       define Timer16_get_compare_c_it_mask() ((TIMSK1  &  (1<<OCIE1C)) >> OCIE1C )
    00175 #       define Timer16_get_capture_it_mask()   ((TIMSK1  &  (1<<ICIE1) ) >> ICIE1  )
    00176     // ----------
    00177 #       define Timer16_clear_overflow_it()     ( TIFR1 |=  (1<<TOV1)  )
    00178 #       define Timer16_clear_compare_a_it()    ( TIFR1 |=  (1<<OCF1A) )
    00179 #       define Timer16_clear_compare_b_it()    ( TIFR1 |=  (1<<OCF1B) )
    00180 #       define Timer16_clear_compare_c_it()    ( TIFR1 |=  (1<<OCF1C) )
    00181 #       define Timer16_clear_capture_it()      ( TIFR1 |=  (1<<ICF1)  )
    00182 #       define Timer16_get_overflow_it()       ((TIFR1  &  (1<<TOV1) ) >> TOV1  )
    00183 #       define Timer16_get_compare_a_it()      ((TIFR1  &  (1<<OCF1A)) >> OCF1A )
    00184 #       define Timer16_get_compare_b_it()      ((TIFR1  &  (1<<OCF1B)) >> OCF1B )
    00185 #       define Timer16_get_compare_c_it()      ((TIFR1  &  (1<<OCF1C)) >> OCF1C )
    00186 #       define Timer16_get_capture_it()        ((TIFR1  &  (1<<ICF1) ) >> ICF1  )
    00187
    00188 #   elif USE_TIMER16 == TIMER16_3          //!< 16-bit TIMER 3 used
    00189
    00190
    00191
    00192 #       define Timer16_select(timer16_num)     // Empty !
    00193     // ---------- Macros
    00194 #       define Timer16_clear()  { TCCR3B=0; TCCR3A=0; TCCR3C=0; TCNT3H=0; TCNT3L= 0; OCR3AH=0; OCR3AL=0; \
    00195                                   OCR3BH=0; OCR3BL=0; OCR3CH=0; OCR3CL=0; ICR3H=0, ICR3L=0;              }
    00196         // ----------
    00197 #       define Timer16_set_counter(value)       ( TCNT3H = ((U8)(value>>8)), TCNT3L = ((U8)(value)))
    00198 #       define Timer16_get_counter_low()        ((U16)(TCNT3L))
    00199 #       define Timer16_get_counter_high()       ((U16)(TCNT3H))
    00200         // ----------
    00201 #       define Timer16_set_compare_a(value)     { OCR3AH = ((U8)(value>>8)); OCR3AL = ((U8)(value)); }
    00202 #       define Timer16_set_compare_b(value)     { OCR3BH = ((U8)(value>>8)); OCR3BL = ((U8)(value)); }
    00203 #       define Timer16_set_compare_c(value)     { OCR3CH = ((U8)(value>>8)); OCR3CL = ((U8)(value)); }
    00204 #       define Timer16_get_compare_a()          ( OCR3A )      // The temporary register is not used
    00205 #       define Timer16_get_compare_b()          ( OCR3B )      // The temporary register is not used
    00206 #       define Timer16_get_compare_c()          ( OCR3C )      // The temporary register is not used
    00207         // ----------
    00208 #       define Timer16_set_capture(value)       { ICR3H = ((U8)(value>>8)); ICR3L = ((U8)(value)); }
    00209 #       define Timer16_get_capture_low()        ((U16)(ICR3L))
    00210 #       define Timer16_get_capture_high()       ((U16)(ICR3H))
    00211         // ----------
    00212 #       define Timer16_set_mode_output_a(conf)  ( TCCR3A = (TCCR3A & (~TIMER16_COMP_MODE_MASK_A)) | (conf << COM3A0) )
    00213 #       define Timer16_set_mode_output_b(conf)  ( TCCR3A = (TCCR3A & (~TIMER16_COMP_MODE_MASK_B)) | (conf << COM3B0) )
    00214 #       define Timer16_set_mode_output_c(conf)  ( TCCR3A = (TCCR3A & (~TIMER16_COMP_MODE_MASK_C)) | (conf << COM3C0) )
    00215 #       define Timer16_get_mode_output_a()      ((TCCR3A & TIMER16_COMP_MODE_MASK_A) >> COM3A0 )
    00216 #       define Timer16_get_mode_output_b()      ((TCCR3A & TIMER16_COMP_MODE_MASK_B) >> COM3B0 )
    00217 #       define Timer16_get_mode_output_c()      ((TCCR3A & TIMER16_COMP_MODE_MASK_C) >> COM3C0 )
    00218         // ----------
    00219 #       define Timer16_set_waveform_mode(conf)  ( TCCR3A = (TCCR3A & (~TIMER16_WGM_RA_MASK)) | ((conf &  0x3) << WGM30), \
    00220                                                   TCCR3B = (TCCR3B & (~TIMER16_WGM_RB_MASK)) | ((conf >> 0x2) << WGM32)  )
    00221 #       define Timer16_get_waveform_mode()     (((TCCR3A & TIMER16_WGM_RA_MASK) >> WGM30) |         \
    00222                                                (((TCCR3B & TIMER16_WGM_RB_MASK) >> WGM32) << 0x2)   )
    00223         // ----------
    00224 #       define Timer16_set_clock(value)        ( TCCR3B = (TCCR3B & (~TIMER16_CLK_MASK)) | (value << CS30) )
    00225 #       define Timer16_get_clock()            (((TCCR3B & TIMER16_CLK_MASK) >> CS30) )
    00226         // ----------
    00227 #       define Timer16_set_input_filter()      ( TCCR3B |=  (1<<ICNC3) )
    00228 #       define Timer16_clear_input_filter()    ( TCCR3B &= ~(1<<ICNC3) )
    00229 #       define Timer16_get_input_filter()      ((TCCR3B  &  (1<<ICNC3)) >> ICNC3 )
    00230     // ----------
    00231 #       define Timer16_set_input_rising_edge() ( TCCR3B |=  (1<<ICES3) )
    00232 #       define Timer16_set_input_falling_edge()( TCCR3B &= ~(1<<ICES3) )
    00233 #       define Timer16_get_input_capture_edge()((TCCR3B &   (1<<ICES3)) >> ICES3 )
    00234     // ----------
    00235 #       define Timer16_set_compare_force_a()   ( TCCR3C |=  (1<<FOC3A) )
    00236 #       define Timer16_set_compare_force_b()   ( TCCR3C |=  (1<<FOC3B) )
    00237 #       define Timer16_set_compare_force_c()   ( TCCR3C |=  (1<<FOC3C) )
    00238 #       define Timer16_clear_compare_force_a() ( TCCR3C &= ~(1<<FOC3A) )
    00239 #       define Timer16_clear_compare_force_b() ( TCCR3C &= ~(1<<FOC3B) )
    00240 #       define Timer16_clear_compare_force_c() ( TCCR3C &= ~(1<<FOC3C) )
    00241 #       define Timer16_get_compare_force_a()   ((TCCR3C  &  (1<<FOC3A)) >> FOC3A )
    00242 #       define Timer16_get_compare_force_b()   ((TCCR3C  &  (1<<FOC3B)) >> FOC3B )
    00243 #       define Timer16_get_compare_force_c()   ((TCCR3C  &  (1<<FOC3C)) >> FOC3C )
    00244     // ----------
    00245 #       define Timer16_overflow_it_enable()    ( TIMSK3 |=  (1<<TOIE3)  )
    00246 #       define Timer16_overflow_it_disable()   ( TIMSK3 &= ~(1<<TOIE3)  )
    00247 #       define Timer16_compare_a_it_enable()   ( TIMSK3 |=  (1<<OCIE3A) )
    00248 #       define Timer16_compare_a_it_disable()  ( TIMSK3 &= ~(1<<OCIE3A) )
    00249 #       define Timer16_compare_b_it_enable()   ( TIMSK3 |=  (1<<OCIE3B) )
    00250 #       define Timer16_compare_b_it_disable()  ( TIMSK3 &= ~(1<<OCIE3B) )
    00251 #       define Timer16_compare_c_it_enable()   ( TIMSK3 |=  (1<<OCIE3C) )
    00252 #       define Timer16_compare_c_it_disable()  ( TIMSK3 &= ~(1<<OCIE3C) )
    00253 #       define Timer16_capture_it_enable()     ( TIMSK3 |=  (1<<ICIE3)  )
    00254 #       define Timer16_capture_it_disable()    ( TIMSK3 &= ~(1<<ICIE3)  )
    00255 #       define Timer16_get_overflow_it_mask()  ((TIMSK3  &  (1<<TOIE3) ) >> TOIE3  )
    00256 #       define Timer16_get_compare_a_it_mask() ((TIMSK3  &  (1<<OCIE3A)) >> OCIE3A )
    00257 #       define Timer16_get_compare_b_it_mask() ((TIMSK3  &  (1<<OCIE3B)) >> OCIE3B )
    00258 #       define Timer16_get_compare_c_it_mask() ((TIMSK3  &  (1<<OCIE3C)) >> OCIE3C )
    00259 #       define Timer16_get_capture_it_mask()   ((TIMSK3  &  (1<<ICIE3) ) >> ICIE3  )
    00260     // ----------
    00261 #       define Timer16_clear_overflow_it()     ( TIFR3 |=  (1<<TOV3)  )
    00262 #       define Timer16_clear_compare_a_it()    ( TIFR3 |=  (1<<OCF3A) )
    00263 #       define Timer16_clear_compare_b_it()    ( TIFR3 |=  (1<<OCF3B) )
    00264 #       define Timer16_clear_compare_c_it()    ( TIFR3 |=  (1<<OCF3C) )
    00265 #       define Timer16_clear_capture_it()      ( TIFR3 |=  (1<<ICF3)  )
    00266 #       define Timer16_get_overflow_it()       ((TIFR3  &  (1<<TOV3) ) >> TOV3  )
    00267 #       define Timer16_get_compare_a_it()      ((TIFR3  &  (1<<OCF3A)) >> OCF3A )
    00268 #       define Timer16_get_compare_b_it()      ((TIFR3  &  (1<<OCF3B)) >> OCF3B )
    00269 #       define Timer16_get_compare_c_it()      ((TIFR3  &  (1<<OCF3C)) >> OCF3C )
    00270 #       define Timer16_get_capture_it()        ((TIFR3  &  (1<<ICF3) ) >> ICF3  )
    00271
    00272 #   elif USE_TIMER16 == BOTH_TIMER16   //!< Both the 16-bit TIMERs
    00273
    00274
    00275
    00276         extern U8 timer16_selected;         // $$$-- EXTERNAL DECLARATION --$$$
    00277 #       define Timer16_select(timer16_num)     (timer16_selected=timer16_num)
    00278     // ---------- Macros
    00279 #       define Timer16_clear()              ((timer16_selected==TIMER16_1)? \
    00280                                                 (TCCR1B=0, TCCR1A=0, TCCR1C=0, TCNT1H=0, TCNT1L= 0, OCR1AH=0, OCR1AL=0, \
    00281                                                  OCR1BH=0, OCR1BL=0, OCR1CH=0, OCR1CL=0, ICR1H=0, ICR1L=0 )             \
    00282                                                 : \
    00283                                                 (TCCR3B=0, TCCR3A=0, TCCR3C=0, TCNT3H=0, TCNT3L= 0, OCR3AH=0, OCR3AL=0, \
    00284                                                  OCR3BH=0, OCR3BL=0, OCR3CH=0, OCR3CL=0, ICR3H=0, ICR3L=0 )             )
    00285         // ----------
    00286 #       define Timer16_set_counter(value)   ((timer16_selected==TIMER16_1)? \
    00287                                                 (TCNT1H = ((U8)(value>>8)), TCNT1L = ((U8)(value)) ) \
    00288                                                 : \
    00289                                                 (TCNT3H = ((U8)(value>>8)), TCNT3L = ((U8)(value)) ) )
    00290 #       define Timer16_get_counter_low()    ((timer16_selected==TIMER16_1)? ((U16)(TCNT1L)) : ((U16)(TCNT3L)) )
    00291 #       define Timer16_get_counter_high()   ((timer16_selected==TIMER16_1)? ((U16)(TCNT1H)) : ((U16)(TCNT3H)) )
    00292         // ----------
    00293 #       define Timer16_set_compare_a(value) ((timer16_selected==TIMER16_1)? \
    00294                                                 (OCR1AH = ((U8)(value>>8)), OCR1AL = ((U8)(value)) ) \
    00295                                                 : \
    00296                                                 (OCR3AH = ((U8)(value>>8)), OCR3AL = ((U8)(value)) ) )
    00297 #       define Timer16_set_compare_b(value) ((timer16_selected==TIMER16_1)? \
    00298                                                 (OCR1BH = ((U8)(value>>8)), OCR1BL = ((U8)(value)) ) \
    00299                                                 : \
    00300                                                 (OCR3BH = ((U8)(value>>8)), OCR3BL = ((U8)(value)) ) )
    00301 #       define Timer16_set_compare_c(value) ((timer16_selected==TIMER16_1)? \
    00302                                                 (OCR3CH = ((U8)(value>>8)), OCR3CL = ((U8)(value)) ) \
    00303                                                 : \
    00304                                                 (OCR1CH = ((U8)(value>>8)), OCR1CL = ((U8)(value)) ) )
    00305 #       define Timer16_get_compare_a()      ((timer16_selected==TIMER16_1)? (OCR1A) : (OCR3A) )   // The temporary register is not used
    00306 #       define Timer16_get_compare_b()      ((timer16_selected==TIMER16_1)? (OCR1B) : (OCR3B) )   // The temporary register is not used
    00307 #       define Timer16_get_compare_c()      ((timer16_selected==TIMER16_1)? (OCR1C) : (OCR3C) )   // The temporary register is not used
    00308         // ----------
    00309 #       define Timer16_set_capture(value)   ((timer16_selected==TIMER16_1)? \
    00310                                                 (ICR1H = ((U8)(value>>8)), ICR1L = ((U8)(value))) \
    00311                                                 : \
    00312                                                 (ICR3H = ((U8)(value>>8)), ICR3L = ((U8)(value))) )
    00313 #       define Timer16_get_capture_low()    ((timer16_selected==TIMER16_1)? ((U16)(ICR1L)) : ((U16)(ICR3L)) )
    00314 #       define Timer16_get_capture_high()   ((timer16_selected==TIMER16_1)? ((U16)(ICR1H)) : ((U16)(ICR3H)) )
    00315         // ----------
    00316 #       define Timer16_set_mode_output_a(conf)  ((timer16_selected==TIMER16_1)? \
    00317                                                     (TCCR1A = (TCCR1A & (~TIMER16_COMP_MODE_MASK_A)) | (conf << COM1A0)) \
    00318                                                     : \
    00319                                                     (TCCR3A = (TCCR3A & (~TIMER16_COMP_MODE_MASK_A)) | (conf << COM3A0)) )
    00320 #       define Timer16_set_mode_output_b(conf)  ((timer16_selected==TIMER16_1)? \
    00321                                                     (TCCR1A = (TCCR1A & (~TIMER16_COMP_MODE_MASK_B)) | (conf << COM1B0)) \
    00322                                                     : \
    00323                                                     (TCCR3A = (TCCR3A & (~TIMER16_COMP_MODE_MASK_B)) | (conf << COM3B0)) )
    00324 #       define Timer16_set_mode_output_c(conf)  ((timer16_selected==TIMER16_1)? \
    00325                                                     (TCCR1A = (TCCR1A & (~TIMER16_COMP_MODE_MASK_C)) | (conf << COM1C0)) \
    00326                                                     : \
    00327                                                     (TCCR3A = (TCCR3A & (~TIMER16_COMP_MODE_MASK_C)) | (conf << COM3C0)) )
    00328 #       define Timer16_get_mode_output_a()   ((timer16_selected==TIMER16_1)? \
    00329                                                 ((TCCR1A & TIMER16_COMP_MODE_MASK_A) >> COM1A0) : ((TCCR3A & TIMER16_COMP_MODE_MASK_A) >> COM3A0 ) )
    00330 #       define Timer16_get_mode_output_b()   ((timer16_selected==TIMER16_1)? \
    00331                                                 ((TCCR1A & TIMER16_COMP_MODE_MASK_B) >> COM1B0) : ((TCCR3A & TIMER16_COMP_MODE_MASK_B) >> COM3B0) )
    00332 #       define Timer16_get_mode_output_c()   ((timer16_selected==TIMER16_1)? \
    00333                                                 ((TCCR1A & TIMER16_COMP_MODE_MASK_C) >> COM1C0) : ((TCCR3A & TIMER16_COMP_MODE_MASK_C) >> COM3C0) )
    00334         // ----------
    00335 #       define Timer16_set_waveform_mode(conf)  ((timer16_selected==TIMER16_1)? \
    00336                                                     (TCCR1A = (TCCR1A & (~TIMER16_WGM_RA_MASK)) | ((conf &  0x3) << WGM10) , \
    00337                                                      TCCR1B = (TCCR1B & (~TIMER16_WGM_RB_MASK)) | ((conf >> 0x2) << WGM12) ) \
    00338                                                      : \
    00339                                                     (TCCR3A = (TCCR3A & (~TIMER16_WGM_RA_MASK)) | ((conf &  0x3) << WGM30) , \
    00340                                                      TCCR3B = (TCCR3B & (~TIMER16_WGM_RB_MASK)) | ((conf >> 0x2) << WGM32) ) )
    00341 #       define Timer16_get_waveform_mode()   ((timer16_selected==TIMER16_1)? \
    00342                                                 (((TCCR1A & TIMER16_WGM_RA_MASK) >> WGM10) | (((TCCR1B & TIMER16_WGM_RB_MASK) >> WGM12) << 0x2)) \
    00343                                                 : \
    00344                                                 (((TCCR3A & TIMER16_WGM_RA_MASK) >> WGM30) | (((TCCR3B & TIMER16_WGM_RB_MASK) >> WGM32) << 0x2)) )
    00345         // ----------
    00346 #       define Timer16_set_clock(value)      ((timer16_selected==TIMER16_1)? \
    00347                                                 (TCCR1B = (TCCR1B & (~TIMER16_CLK_MASK)) | (value << CS10)) \
    00348                                                 : \
    00349                                                 (TCCR3B = (TCCR3B & (~TIMER16_CLK_MASK)) | (value << CS30)) )
    00350
    00351 #       define Timer16_get_clock()           ((timer16_selected==TIMER16_1)? \
    00352                                                 (((TCCR1B & TIMER16_CLK_MASK) >> CS10)) : (((TCCR3B & TIMER16_CLK_MASK) >> CS30)) )
    00353         // ----------
    00354 #       define Timer16_set_input_filter()    ((timer16_selected==TIMER16_1)? \
    00355                                                 (TCCR1B |= (1<<ICNC1)) : ( TCCR3B |= (1<<ICNC3)) )
    00356 #       define Timer16_clear_input_filter()  ((timer16_selected==TIMER16_1)? \
    00357                                                 (TCCR1B &= ~(1<<ICNC1)) :  ( TCCR3B &= ~(1<<ICNC3)) )
    00358 #       define Timer16_get_input_filter()    ((timer16_selected==TIMER16_1)? \
    00359                                                 ((TCCR1B & (1<<ICNC1)) >> ICNC1) : ((TCCR3B & (1<<ICNC3)) >> ICNC3) )
    00360     // ----------
    00361 #       define Timer16_set_input_rising_edge()  ((timer16_selected==TIMER16_1)? \
    00362                                                     (TCCR1B |= (1<<ICES1)) : (TCCR3B |= (1<<ICES3)) )
    00363 #       define Timer16_set_input_falling_edge() ((timer16_selected==TIMER16_1)? \
    00364                                                     (TCCR1B &= ~(1<<ICES1)) : ( TCCR3B &= ~(1<<ICES3)) )
    00365 #       define Timer16_get_input_capture_edge() ((timer16_selected==TIMER16_1)? \
    00366                                                     ((TCCR1B & (1<<ICES1)) >> ICES1) : ((TCCR3B & (1<<ICES3)) >> ICES3) )
    00367     // ----------
    00368 #       define Timer16_set_compare_force_a()    ((timer16_selected==TIMER16_1)? \
    00369                                                     (TCCR1C |= (1<<FOC1A)) : (TCCR3C |= (1<<FOC3A)) )
    00370 #       define Timer16_set_compare_force_b()    ((timer16_selected==TIMER16_1)? \
    00371                                                     (TCCR1C |= (1<<FOC1B)) : (TCCR3C |= (1<<FOC3B)) )
    00372 #       define Timer16_set_compare_force_c()    ((timer16_selected==TIMER16_1)? \
    00373                                                     (TCCR1C |= (1<<FOC1C)) : (TCCR3C |= (1<<FOC3C)) )
    00374 #       define Timer16_clear_compare_force_a()  ((timer16_selected==TIMER16_1)? \
    00375                                                     (TCCR1C &= ~(1<<FOC1A ) : (TCCR3C &= ~(1<<FOC3A)) )
    00376 #       define Timer16_clear_compare_force_b()  ((timer16_selected==TIMER16_1)? \
    00377                                                     (TCCR1C &= ~(1<<FOC1B)) : (TCCR3C &= ~(1<<FOC3B)) )
    00378 #       define Timer16_clear_compare_force_c()  ((timer16_selected==TIMER16_1)? \
    00379                                                     (TCCR1C &= ~(1<<FOC1C)) : (TCCR3C &= ~(1<<FOC3C)) )
    00380 #       define Timer16_get_compare_force_a()    ((timer16_selected==TIMER16_1)? \
    00381                                                     ((TCCR1C & (1<<FOC1A)) >> FOC1A) : ((TCCR3C & (1<<FOC3A)) >> FOC3A) )
    00382 #       define Timer16_get_compare_force_b()    ((timer16_selected==TIMER16_1)? \
    00383                                                     ((TCCR1C & (1<<FOC1B)) >> FOC1B) : ((TCCR3C & (1<<FOC3B)) >> FOC3B) )
    00384 #       define Timer16_get_compare_force_c()    ((timer16_selected==TIMER16_1)? \
    00385                                                     ((TCCR1C & (1<<FOC1C)) >> FOC1C) : ((TCCR3C & (1<<FOC3C)) >> FOC3C) )
    00386     // ----------
    00387 #       define Timer16_overflow_it_enable()     ((timer16_selected==TIMER16_1)? \
    00388                                                     (TIMSK1 |= (1<<TOIE1)) : (TIMSK3 |= (1<<TOIE3)) )
    00389 #       define Timer16_overflow_it_disable()    ((timer16_selected==TIMER16_1)? \
    00390                                                     (TIMSK1 &= ~(1<<TOIE1)) : (TIMSK3 &= ~(1<<TOIE3)) )
    00391 #       define Timer16_compare_a_it_enable()    ((timer16_selected==TIMER16_1)? \
    00392                                                     (TIMSK1 |= (1<<OCIE1A)) : (TIMSK3 |= (1<<OCIE3A)) )
    00393 #       define Timer16_compare_a_it_disable()   ((timer16_selected==TIMER16_1)? \
    00394                                                     (TIMSK1 &= ~(1<<OCIE1A)) : (TIMSK3 &= ~(1<<OCIE3A)) )
    00395 #       define Timer16_compare_b_it_enable()    ((timer16_selected==TIMER16_1)? \
    00396                                                     (TIMSK1 |= (1<<OCIE1B)) : (TIMSK3 |= (1<<OCIE3B)) )
    00397 #       define Timer16_compare_b_it_disable()   ((timer16_selected==TIMER16_1)? \
    00398                                                     (TIMSK1 &= ~(1<<OCIE1B)) : (TIMSK3 &= ~(1<<OCIE3B)) )
    00399 #       define Timer16_compare_c_it_enable()    ((timer16_selected==TIMER16_1)? \
    00400                                                     (TIMSK1 |= (1<<OCIE1C)) : (TIMSK3 |= (1<<OCIE3C)) )
    00401 #       define Timer16_compare_c_it_disable()   ((timer16_selected==TIMER16_1)? \
    00402                                                     (TIMSK1 &= ~(1<<OCIE1C)) : (TIMSK3 &= ~(1<<OCIE3C)) )
    00403 #       define Timer16_capture_it_enable()      ((timer16_selected==TIMER16_1)? \
    00404                                                     (TIMSK1 |= (1<<ICIE1)) : (TIMSK3 |= (1<<ICIE3)) )
    00405 #       define Timer16_capture_it_disable()     ((timer16_selected==TIMER16_1)? \
    00406                                                     (TIMSK1 &= ~(1<<ICIE1)) : (TIMSK3 &= ~(1<<ICIE3)) )
    00407 #       define Timer16_get_overflow_it_mask()   ((timer16_selected==TIMER16_1)? \
    00408                                                     ((TIMSK1 & (1<<TOIE1)) >> TOIE1) : ((TIMSK3 & (1<<TOIE3)) >> TOIE3) )
    00409 #       define Timer16_get_compare_a_it_mask()  ((timer16_selected==TIMER16_1)? \
    00410                                                     ((TIMSK1 & (1<<OCIE1A)) >> OCIE1A) : ((TIMSK3 & (1<<OCIE3A)) >> OCIE3A) )
    00411 #       define Timer16_get_compare_b_it_mask()  ((timer16_selected==TIMER16_1)? \
    00412                                                     ((TIMSK1 & (1<<OCIE1B)) >> OCIE1B) : ((TIMSK3 & (1<<OCIE3B)) >> OCIE3B) )
    00413 #       define Timer16_get_compare_c_it_mask()  ((timer16_selected==TIMER16_1)? \
    00414                                                     ((TIMSK1 & (1<<OCIE1C)) >> OCIE1C) : ((TIMSK3 & (1<<OCIE3C)) >> OCIE3C) )
    00415 #       define Timer16_get_capture_it_mask()    ((timer16_selected==TIMER16_1)? \
    00416                                                     ((TIMSK1 & (1<<ICIE1)) >> ICIE1) : ((TIMSK3 & (1<<ICIE3)) >> ICIE3) )
    00417     // ----------
    00418 #       define Timer16_clear_overflow_it()      ((timer16_selected==TIMER16_1)? \
    00419                                                     (TIFR1 |= (1<<TOV1)) : (TIFR3 |= (1<<TOV3)) )
    00420 #       define Timer16_clear_compare_a_it()     ((timer16_selected==TIMER16_1)? \
    00421                                                     (TIFR1 |= (1<<OCF1A)) : (TIFR3 |= (1<<OCF3A)) )
    00422 #       define Timer16_clear_compare_b_it()     ((timer16_selected==TIMER16_1)? \
    00423                                                     (TIFR1 |= (1<<OCF1B)) : (TIFR3 |= (1<<OCF3B)) )
    00424 #       define Timer16_clear_compare_c_it()     ((timer16_selected==TIMER16_1)? \
    00425                                                     (TIFR1 |= (1<<OCF1C)) : (TIFR3 |= (1<<OCF3C)) )
    00426 #       define Timer16_clear_capture_it()       ((timer16_selected==TIMER16_1)? \
    00427                                                     (TIFR1 |= (1<<ICF1)) : (TIFR3 |= (1<<ICF3)) )
    00428 #       define Timer16_get_overflow_it()        ((timer16_selected==TIMER16_1)? \
    00429                                                     ((TIFR1 & (1<<TOV1)) >> TOV1) : ((TIFR3 & (1<<TOV3)) >> TOV3) )
    00430 #       define Timer16_get_compare_a_it()       ((timer16_selected==TIMER16_1)? \
    00431                                                     ((TIFR1 & (1<<OCF1A)) >> OCF1A) : ((TIFR3 & (1<<OCF3A)) >> OCF3A) )
    00432 #       define Timer16_get_compare_b_it()       ((timer16_selected==TIMER16_1)? \
    00433                                                     ((TIFR1 & (1<<OCF1B)) >> OCF1B) : ((TIFR3 & (1<<OCF3B)) >> OCF3B) )
    00434 #       define Timer16_get_compare_c_it()       ((timer16_selected==TIMER16_1)? \
    00435                                                     ((TIFR1 & (1<<OCF1C)) >> OCF1C) : ((TIFR3 & (1<<OCF3C)) >> OCF3C) )
    00436 #       define Timer16_get_capture_it()         ((timer16_selected==TIMER16_1)? \
    00437                                                     ((TIFR1 & (1<<ICF1)) >> ICF1) : ((TIFR3 & (1<<ICF3)) >> ICF3) )
    00438
    00439     #else
    00440         #error USE_TIMER16 definition is not referenced in "timer16_drv.h" file
    00441 #endif
    00442
    00443 //_____ T I M E R   D E F I N I T I O N S ______________________________________
    00444
    00445     // ---------- Pre-definitions for "conf" field for Timer16_set(get)_mode_output_x(conf) macros
    00446 #define TIMER16_COMP_MODE_NORMAL    (0)
    00447 #define TIMER16_COMP_MODE_TOGGLE    (1)
    00448 #define TIMER16_COMP_MODE_CLEAR_OC  (2)
    00449 #define TIMER16_COMP_MODE_SET_OC    (3)
    00450 #define TIMER16_COMP_MODE_MASK_A    (3<<COM1A0)
    00451 #define TIMER16_COMP_MODE_MASK_B    (3<<COM1B0)
    00452 #define TIMER16_COMP_MODE_MASK_C    (3<<COM1C0)
    00453     // ---------- Pre-definitions for "conf" field for Timer16_set_waveform_mode(conf) macro
    00454 #define TIMER16_WGM_NORMAL          (0)
    00455 #define TIMER16_WGM_CTC_OCR         (4)
    00456 #define TIMER16_WGM_CTC_ICR         (12)
    00457 #define TIMER16_WGM_PWM_PC8         (1)
    00458 #define TIMER16_WGM_PWM_PC9         (2)
    00459 #define TIMER16_WGM_PWM_PC10        (3)
    00460 #define TIMER16_WGM_PWM_PC_ICR      (10)
    00461 #define TIMER16_WGM_PWM_PC_OCR      (11)
    00462 #define TIMER16_WGM_PWM_PFC_ICR     (8)
    00463 #define TIMER16_WGM_PWM_PFC_OCR     (9)
    00464 #define TIMER16_WGM_FAST_PWM8       (5)
    00465 #define TIMER16_WGM_FAST_PWM9       (6)
    00466 #define TIMER16_WGM_FAST_PWM10      (7)
    00467 #define TIMER16_WGM_FAST_PWM_ICR    (14)
    00468 #define TIMER16_WGM_FAST_PWM_OCR    (15)
    00469 #define TIMER16_WGM_RA_MASK         (3<<WGM10)
    00470 #define TIMER16_WGM_RB_MASK         (3<<WGM12)
    00471     // ---------- Pre-definitions for "value" field for Timer16_set_clock(value) macro
    00472 #define TIMER16_NO_CLOCK                 (0)
    00473 #define TIMER16_CLKIO_BY_1               (1)
    00474 #define TIMER16_CLKIO_BY_8               (2)
    00475 #define TIMER16_CLKIO_BY_64              (3)
    00476 #define TIMER16_CLKIO_BY_256             (4)
    00477 #define TIMER16_CLKIO_BY_1024            (5)
    00478 #define TIMER16_EXT_CLOCK_FALLING_EDGE   (6)
    00479 #define TIMER16_EXT_CLOCK_RISING_EDGE    (7)
    00480 #define TIMER16_CLK_MASK                 (7<<CS10)
    00481
    00482
    00483 //_____ D E C L A R A T I O N S ________________________________________________
    00484
    00485 //------------------------------------------------------------------------------
    00486 //  @fn timer16_get_counter
    00496 extern  U16 timer16_get_counter(void);
    00497
    00498 //------------------------------------------------------------------------------
    00499 //  @fn timer16_get_capture
    00509 extern  U16 timer16_get_capture(void);
    00510
    00511 //______________________________________________________________________________
    00512
    00513 #endif  // _TIMER16_DRV_H_
    00514
    00515
    00516
    00517
    00518
    00519
    00520
    00521
    00522
    00523
    00524
    00525
    00526
    00527
    00528
    00529
    00530
    00531
    00532
    00533
    00534
    00535
    00536
    00537
    00538
    00539
    00540
    00541
    00542
    00543