TinyX61_macros.h

Go to the documentation of this file.
00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
00013 
00014 /* Copyright (c) 2007, 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  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
00030  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00031  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
00032  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00033  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00034  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00035  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00036  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00038  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039  */
00040  
00041 #ifndef __TINYX61_MACROS_H__
00042 #define __TINYX61_MACROS_H__
00043 
00044 //_____  I N C L U D E S ___________________________________________________
00045 
00048 #include "compiler.h"                    // Compiler definitions
00049 #ifdef __GNUC__
00050    #include <avr/io.h>                    // Use AVR-GCC library
00051    #include <avr/power.h>
00052 #elif __ICCAVR__
00053    #include <ioavr.h>                     // Use IAR-AVR library
00054 #else
00055    #error Current COMPILER not supported
00056 #endif
00058 
00059 //_____ M A C R O S ________________________________________________________
00060 
00061 #if defined(__ICCAVR__)
00063 #define SAVE_INTERRUPT()            __save_interrupt();
00064 
00066 #define RESTORE_INTERRUPT(state)    __restore_interrupt(state);
00067 
00069 #define DISABLE_INTERRUPT()         __disable_interrupt();
00070 
00071 #elif defined(__GNUC__)
00073 #define SAVE_INTERRUPT()            SREG
00074 
00076 #define RESTORE_INTERRUPT(state)    (SREG = (state))
00077 
00079 #define DISABLE_INTERRUPT()         cli()
00080 
00081 #else
00083 #define SAVE_INTERRUPT()            SREG
00084 
00086 #define RESTORE_INTERRUPT(state)    (SREG = (state))
00087 
00089 #define DISABLE_INTERRUPT()         (SREG &= (~GLOBAL_INTERRUPT_BIT_MASK))
00090 #endif
00091 
00092 
00099 #define TC0_WRITE_TCNT0(value) \
00100   { \
00101     TCNT0H = (U8)((value) >> 8); \
00102     TCNT0L = (U8)(value); \
00103   }
00104 
00105 
00112 #define TC0_READ_TCNT0(destinationVariable) \
00113   { \
00114     U8 tempL; \
00115     tempL = TCNT0L; \
00116     (destinationVariable) = ((TCNT0H << 8) | tempL); \
00117   }
00118 
00119 
00126 #define TC0_WRITE_TCNT0_INT_SAFE(value) \
00127   { \
00128     U8 iFlagTemp; \
00129     iFlagTemp = SAVE_INTERRUPT(); \
00130     DISABLE_INTERRUPT(); \
00131     TCNT0H = (U8)((value) >> 8); \
00132     TCNT0L = (U8)(value); \
00133     RESTORE_INTERRUPT(iFlagTemp); \
00134   }
00135 
00136 
00143 #define TC0_READ_TCNT0_INT_SAFE(destinationVariable) \
00144   { \
00145     U8 iFlagTemp; \
00146     U8 tempL; \
00147     iFlagTemp = SAVE_INTERRUPT(); \
00148     DISABLE_INTERRUPT(); \
00149     tempL = TCNT0L; \
00150     (destinationVariable) = ((TCNT0H << 8) | tempL); \
00151     RESTORE_INTERRUPT(iFlagTemp); \
00152   }
00153 
00154 
00161 #define TC0_WRITE_16_BIT_OCR0AB(value) \
00162   { \
00163     OCR0B = (U8)((value) >> 8); \
00164     OCR0A = (U8)(value);\
00165   }
00166 
00167 
00174 #define TC0_READ_16_BIT_OCR0AB(destinationVariable) \
00175   { \
00176     U8 tempL = OCR0A; \
00177     (destinationVariable) = ((U16)OCR0B << 8) | tempL; \
00178   }
00179 
00180 
00187 #define TC0_READ_16_BIT_OCR0AB_INT_SAFE(destinationVariable) \
00188   { \
00189     U8 iFlagTemp; \
00190     iFlagTemp = SAVE_INTERRUPT(); \
00191     DISABLE_INTERRUPT(); \
00192     U8 tempL = OCR0A; \
00193     (destinationVariable) = ((U16)OCR0B << 8) | tempL; \
00194     RESTORE_INTERRUPT(iFlagTemp); \
00195   }
00196 
00197 
00204 #define TC0_WRITE_16_BIT_OCR0AB_INT_SAFE(value) \
00205   { \
00206     U8 iFlagTemp; \
00207     iFlagTemp = SAVE_INTERRUPT(); \
00208     DISABLE_INTERRUPT(); \
00209     OCR0B = (U8)((value) >> 8); \
00210     OCR0A = (U8)(value);\
00211     RESTORE_INTERRUPT(iFlagTemp); \
00212   }
00213 
00214 
00222 #define TC1_WRITE_10_BIT_REGISTER(destinationRegister, value) \
00223   { \
00224     TC1H = ((value) >> 8); \
00225     (destinationRegister) = (U8)(value); \
00226   }
00227 
00228 
00236 #define TC1_READ_10_BIT_REGISTER(sourceRegister, destinationVariable) \
00237   { \
00238     U8 tempL; \
00239     tempL = (sourceRegister); \
00240     (destinationVariable) = ( ((U16)TC1H << 8) | tempL); \
00241   }
00242 
00243 
00252 #define TC1_WRITE_10_BIT_REGISTER_INT_SAFE(destinationRegister, value) \
00253   { \
00254   U8 iFlagTemp; \
00255   iFlagTemp = SAVE_INTERRUPT(); \
00256   DISABLE_INTERRUPT(); \
00257   TC1H = ((value) >> 8); \
00258   (destinationRegister) = (U8)(value); \
00259   RESTORE_INTERRUPT(iFlagTemp); \
00260   }
00261 
00262 
00271 #define TC1_READ_10_BIT_REGISTER_INT_SAFE(sourceRegister, destinationVariable) \
00272   { \
00273     U8 iFlagTemp; \
00274     U8 tempL; \
00275     iFlagTemp = SAVE_INTERRUPT(); \
00276     tempL = (sourceRegister); \
00277     (destinationVariable) = ( ((U16)TC1H << 8) | tempL); \
00278     RESTORE_INTERRUPT(iFlagTemp); \
00279   }
00280 
00281 
00290 #define TC1_SET_ALL_COMPARE_VALUES(compareValue) \
00291   { \
00292       U16 tempValue = compareValue; \
00293       TC1H = ((U8)((tempValue) >> 8)); \
00294       OCR1A = ((U8)tempValue); \
00295       OCR1B = ((U8)tempValue); \
00296       OCR1D = ((U8)tempValue); \
00297   }
00298 
00305 #ifdef  __GNUC__
00306    #define Clear_prescaler()                       (clock_prescale_set(0))
00307 #else
00308    #define Clear_prescaler()                       (Set_cpu_prescaler(0))
00309 #endif
00310 
00317 #ifdef  __GNUC__
00318    #define Set_cpu_prescaler(x)                        (clock_prescale_set(x))
00319 #else
00320    extern void Set_cpu_prescaler(U8 x);
00321 #endif
00322 
00323 //_____ D E F I N I T I O N S ______________________________________________
00324 
00326 #define GLOBAL_INTERRUPT_BIT_MASK     0x80
00327 
00329 #define CLEAR_ALL_TIMER1_INT_FLAGS    (TIFR = TIFR | 0xE4)
00330 
00332 #define DISABLE_ALL_TIMER1_INTS       (TIMSK &= 0x1B)
00333 
00335 #define SET_TIMER1_INT_ZC_DETECTION   (TIMSK = (1 << TOIE1))
00336 
00338 #define CLEAR_ALL_TIMER0_INT_FLAGS    (TIFR = TIFR | 0x1B)
00339 
00341 #define DISABLE_ALL_TIMER0_INTS       (TIMSK &= 0xE4)
00342 
00344 #define SET_TIMER0_COMPA_INT          (TIMSK = (1 << OCIE0A))
00345 
00347 #define ADC_RESOLUTION                1024
00348 
00350 #define ADC_PRESCALER_8               ((0 << ADPS2) | (1 << ADPS1) | (1 << ADPS0))
00351 
00353 #define ADC_PRESCALER_16              ((1 << ADPS2) | (0 << ADPS1) | (0 << ADPS0))
00354 
00356 #define ADC_TS_FREERUNNING            ((0 << ADTS2) | (0 << ADTS1) | (0 << ADTS0))
00357 
00358 #endif

Generated on Mon Dec 1 11:12:20 2008 for AVR498 : Atmel BLDC control on ATAVRMC301 with ATtiny861 by  doxygen 1.5.4