00001
00025 #ifndef __TINYX61_MACROS_H__
00026 #define __TINYX61_MACROS_H__
00027
00029 #define GLOBAL_INTERRUPT_BIT_MASK 0x80
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "config.h"
00044
00045 #if defined(__ICCAVR__)
00047 #define SAVE_INTERRUPT() __save_interrupt();
00048
00050 #define RESTORE_INTERRUPT(state) __restore_interrupt(state);
00051
00053 #define DISABLE_INTERRUPT() __disable_interrupt();
00054
00055 #elif defined(__GNUC__)
00057 #define SAVE_INTERRUPT() SREG
00058
00060 #define RESTORE_INTERRUPT(state) (SREG = (state))
00061
00063 #define DISABLE_INTERRUPT() cli()
00064
00065 #else
00067 #define SAVE_INTERRUPT() SREG
00068
00070 #define RESTORE_INTERRUPT(state) (SREG = (state))
00071
00073 #define DISABLE_INTERRUPT() (SREG &= (~GLOBAL_INTERRUPT_BIT_MASK))
00074 #endif
00075
00076
00083 #define TC0_WRITE_TCNT0(value) \
00084 { \
00085 TCNT0H = (uint8_t)((value) >> 8); \
00086 TCNT0L = (uint8_t)(value); \
00087 }
00088
00089
00096 #define TC0_READ_TCNT0(destinationVariable) \
00097 { \
00098 uint8_t tempL; \
00099 tempL = TCNT0L; \
00100 (destinationVariable) = ((TCNT0H << 8) | tempL); \
00101 }
00102
00103
00110 #define TC0_WRITE_TCNT0_INT_SAFE(value) \
00111 { \
00112 uint8_t iFlagTemp; \
00113 iFlagTemp = SAVE_INTERRUPT(); \
00114 DISABLE_INTERRUPT(); \
00115 TCNT0H = (uint8_t)((value) >> 8); \
00116 TCNT0L = (uint8_t)(value); \
00117 RESTORE_INTERRUPT(iFlagTemp); \
00118 }
00119
00120
00127 #define TC0_READ_TCNT0_INT_SAFE(destinationVariable) \
00128 { \
00129 uint8_t iFlagTemp; \
00130 uint8_t tempL; \
00131 iFlagTemp = SAVE_INTERRUPT(); \
00132 DISABLE_INTERRUPT(); \
00133 tempL = TCNT0L; \
00134 (destinationVariable) = ((TCNT0H << 8) | tempL); \
00135 RESTORE_INTERRUPT(iFlagTemp); \
00136 }
00137
00138
00145 #define TC0_WRITE_16_BIT_OCR0AB(value) \
00146 { \
00147 OCR0B = (uint8_t)((value) >> 8); \
00148 OCR0A = (uint8_t)(value);\
00149 }
00150
00151
00158 #define TC0_READ_16_BIT_OCR0AB(destinationVariable) \
00159 { \
00160 uint8_t tempL = OCR0A; \
00161 (destinationVariable) = ((uint16_t)OCR0B << 8) | tempL; \
00162 }
00163
00164
00171 #define TC0_READ_16_BIT_OCR0AB_INT_SAFE(destinationVariable) \
00172 { \
00173 uint8_t iFlagTemp; \
00174 iFlagTemp = SAVE_INTERRUPT(); \
00175 DISABLE_INTERRUPT(); \
00176 uint8_t tempL = OCR0A; \
00177 (destinationVariable) = ((uint16_t)OCR0B << 8) | tempL; \
00178 RESTORE_INTERRUPT(iFlagTemp); \
00179 }
00180
00181
00188 #define TC0_WRITE_16_BIT_OCR0AB_INT_SAFE(value) \
00189 { \
00190 uint8_t iFlagTemp; \
00191 iFlagTemp = SAVE_INTERRUPT(); \
00192 DISABLE_INTERRUPT(); \
00193 OCR0B = (uint8_t)((value) >> 8); \
00194 OCR0A = (uint8_t)(value);\
00195 RESTORE_INTERRUPT(iFlagTemp); \
00196 }
00197
00198
00206 #define TC1_WRITE_10_BIT_REGISTER(destinationRegister, value) \
00207 { \
00208 TC1H = ((value) >> 8); \
00209 (destinationRegister) = (uint8_t)(value); \
00210 }
00211
00212
00220 #define TC1_READ_10_BIT_REGISTER(sourceRegister, destinationVariable) \
00221 { \
00222 uint8_t tempL; \
00223 tempL = (sourceRegister); \
00224 (destinationVariable) = ( ((uint16_t)TC1H << 8) | tempL); \
00225 }
00226
00227
00236 #define TC1_WRITE_10_BIT_REGISTER_INT_SAFE(destinationRegister, value) \
00237 { \
00238 uint8_t iFlagTemp; \
00239 iFlagTemp = SAVE_INTERRUPT(); \
00240 DISABLE_INTERRUPT(); \
00241 TC1H = ((value) >> 8); \
00242 (destinationRegister) = (uint8_t)(value); \
00243 RESTORE_INTERRUPT(iFlagTemp); \
00244 }
00245
00246
00255 #define TC1_READ_10_BIT_REGISTER_INT_SAFE(sourceRegister, destinationVariable) \
00256 { \
00257 uint8_t iFlagTemp; \
00258 uint8_t tempL; \
00259 iFlagTemp = SAVE_INTERRUPT(); \
00260 tempL = (sourceRegister); \
00261 (destinationVariable) = ( ((uint16_t)TC1H << 8) | tempL); \
00262 RESTORE_INTERRUPT(iFlagTemp); \
00263 }
00264
00265
00274 #define TC1_SET_ALL_COMPARE_VALUES(compareValue) \
00275 { \
00276 uint16_t tempValue = compareValue; \
00277 TC1H = ((uint8_t)((tempValue) >> 8)); \
00278 OCR1A = ((uint8_t)tempValue); \
00279 OCR1B = ((uint8_t)tempValue); \
00280 OCR1D = ((uint8_t)tempValue); \
00281 }
00282
00283
00284 #endif