timer16_drv.h

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

Generated on Mon Feb 19 09:31:47 2007 for Atmel by  doxygen 1.5.1-p1