00001
00062 #ifndef LOWPOWER_MACROS_H
00063 #define LOWPOWER_MACROS_H
00064
00065
00066
00068 #define DISABLE_JTAG( ) { \
00069 ENTER_CRITICAL_REGION(); \
00070 CCP = 0xD8; \
00071 MCU_MCUCR = MCU_JTAGD_bm; \
00072 LEAVE_CRITICAL_REGION(); \
00073 }
00074
00076 #define __PORT_PULLUP(port, mask) { \
00077 PORTCFG.MPCMASK = mask ; \
00078 port.PIN0CTRL = PORT_OPC_PULLUP_gc; \
00079 }
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 #if defined(__ATxmega64A1__) || defined(__ATxmega128A1__) || defined(__ATxmega192A1__) || defined(__ATxmega256A1__) || \
00091 defined(__AVR_ATxmega64A1__) || defined(__AVR_ATxmega128A1__) || defined(__AVR_ATxmega192A1__) || defined(__AVR_ATxmega256A1__)
00092
00094 #define DISABLE_GEN( ) { \
00095 PR.PRGEN |= PR_AES_bm | PR_DMA_bm | PR_EBI_bm | PR_EVSYS_bm | PR_RTC_bm; \
00096 }
00097
00101 #define DISABLE_TC( ) { \
00102 PR.PRPC |= PR_HIRES_bm | PR_TC0_bm | PR_TC1_bm; \
00103 PR.PRPD |= PR_HIRES_bm | PR_TC0_bm | PR_TC1_bm; \
00104 PR.PRPE |= PR_HIRES_bm | PR_TC0_bm | PR_TC1_bm; \
00105 PR.PRPF |= PR_HIRES_bm | PR_TC0_bm | PR_TC1_bm; \
00106 }
00107
00109 #define DISABLE_COM( ) { \
00110 PR.PRPC |= PR_SPI_bm | PR_TWI_bm | PR_USART0_bm | PR_USART1_bm; \
00111 PR.PRPD |= PR_SPI_bm | PR_TWI_bm | PR_USART0_bm | PR_USART1_bm; \
00112 PR.PRPE |= PR_SPI_bm | PR_TWI_bm | PR_USART0_bm | PR_USART1_bm; \
00113 PR.PRPF |= PR_SPI_bm | PR_TWI_bm | PR_USART0_bm | PR_USART1_bm; \
00114 }
00115
00117 #define DISABLE_ANLG( ) { \
00118 PR.PRPA |= PR_AC_bm | PR_ADC_bm | PR_DAC_bm; \
00119 PR.PRPB |= PR_AC_bm | PR_ADC_bm | PR_DAC_bm; \
00120 }
00121
00123 #define ENABLE_PULLUP( ) { \
00124 __PORT_PULLUP(PORTA, 0xFF); \
00125 __PORT_PULLUP(PORTB, 0xFF); \
00126 __PORT_PULLUP(PORTC, 0xFF); \
00127 __PORT_PULLUP(PORTD, 0xFF); \
00128 __PORT_PULLUP(PORTE, 0xFF); \
00129 __PORT_PULLUP(PORTF, 0xFF); \
00130 __PORT_PULLUP(PORTH, 0xFF); \
00131 __PORT_PULLUP(PORTJ, 0xFF); \
00132 __PORT_PULLUP(PORTK, 0xFF); \
00133 __PORT_PULLUP(PORTQ, 0x0F); \
00134 __PORT_PULLUP(PORTR, 0x03); \
00135 }
00136
00137
00138
00139 #elif defined(__ATxmega64A3__) || defined(__ATxmega128A3__) || defined(__ATxmega192A3__) || defined(__ATxmega256A3__) || \
00140 defined(___AVR_ATxmega64A3__) || defined(__AVR_ATxmega128A3__) || defined(__AVR_ATxmega192A3__) || defined(__AVR_ATxmega256A3__)
00141
00142 #define DISABLE_GEN( ) { \
00143 PR.PRGEN |= PR_AES_bm | PR_DMA_bm | PR_EVSYS_bm | PR_RTC_bm; \
00144 }
00145
00146 #define DISABLE_TC( ) { \
00147 PR.PRPC |= PR_HIRES_bm | PR_TC0_bm | PR_TC1_bm; \
00148 PR.PRPD |= PR_HIRES_bm | PR_TC0_bm | PR_TC1_bm; \
00149 PR.PRPE |= PR_HIRES_bm | PR_TC0_bm | PR_TC1_bm; \
00150 PR.PRPF |= PR_HIRES_bm | PR_TC0_bm; \
00151 }
00152
00153 #define DISABLE_COM( ) { \
00154 PR.PRPC |= PR_SPI_bm | PR_TWI_bm | PR_USART0_bm | PR_USART1_bm; \
00155 PR.PRPD |= PR_SPI_bm | PR_USART0_bm | PR_USART1_bm; \
00156 PR.PRPE |= PR_SPI_bm | PR_TWI_bm | PR_USART0_bm | PR_USART1_bm; \
00157 PR.PRPF |= PR_USART0_bm; \
00158 }
00159
00160 #define DISABLE_ANLG( ) { \
00161 PR.PRPA |= PR_AC_bm | PR_ADC_bm; \
00162 PR.PRPB |= PR_AC_bm | PR_ADC_bm | PR_DAC_bm; \
00163 }
00164
00165 #define ENABLE_PULLUP( ) { \
00166 __PORT_PULLUP(PORTA, 0xFF); \
00167 __PORT_PULLUP(PORTB, 0xFF); \
00168 __PORT_PULLUP(PORTC, 0xFF); \
00169 __PORT_PULLUP(PORTD, 0xFF); \
00170 __PORT_PULLUP(PORTE, 0xFF); \
00171 __PORT_PULLUP(PORTF, 0xFF); \
00172 __PORT_PULLUP(PORTR, 0x03); \
00173 }
00174
00175
00176
00177 #elif defined(__ATxmega256A3B__) || defined(__AVR_ATxmega256A3B__)
00178
00179 #define DISABLE_GEN( ) { \
00180 PR.PRGEN |= PR_AES_bm | PR_DMA_bm | PR_EVSYS_bm | PR_RTC_bm; \
00181 }
00182
00183 #define DISABLE_TC( ) { \
00184 PR.PRPC |= PR_HIRES_bm | PR_TC0_bm | PR_TC1_bm; \
00185 PR.PRPD |= PR_HIRES_bm | PR_TC0_bm | PR_TC1_bm; \
00186 PR.PRPE |= PR_HIRES_bm | PR_TC0_bm | PR_TC1_bm; \
00187 PR.PRPF |= PR_HIRES_bm | PR_TC0_bm; \
00188 }
00189
00190 #define DISABLE_COM( ) { \
00191 PR.PRPC |= PR_SPI_bm | PR_TWI_bm | PR_USART0_bm | PR_USART1_bm; \
00192 PR.PRPD |= PR_SPI_bm | PR_USART0_bm | PR_USART1_bm; \
00193 PR.PRPE |= PR_TWI_bm | PR_USART0_bm; \
00194 PR.PRPF |= PR_USART0_bm; \
00195 }
00196
00197 #define DISABLE_ANLG( ) { \
00198 PR.PRPA |= PR_AC_bm | PR_ADC_bm; \
00199 PR.PRPB |= PR_AC_bm | PR_ADC_bm | PR_DAC_bm; \
00200 }
00201
00202 #define ENABLE_PULLUP( ) { \
00203 __PORT_PULLUP(PORTA, 0xFF); \
00204 __PORT_PULLUP(PORTB, 0xFF); \
00205 __PORT_PULLUP(PORTC, 0xFF); \
00206 __PORT_PULLUP(PORTD, 0xFF); \
00207 __PORT_PULLUP(PORTE, 0xFF); \
00208 __PORT_PULLUP(PORTF, 0xDF); \
00209 __PORT_PULLUP(PORTR, 0x03); \
00210 }
00211
00212
00213
00214 #elif defined(__ATxmega16A4__) || defined(__ATxmega32A4__) || defined(__ATxmega64A4__) || defined(__ATxmega128A4__) || \
00215 defined(__AVR_ATxmega16A4__) || defined(__AVR_ATxmega32A4__) || defined(__AVR_ATxmega64A4__) || defined(__AVR_ATxmega128A4__)
00216
00217 #define DISABLE_GEN( ) { \
00218 PR.PRGEN |= PR_AES_bm | PR_DMA_bm | PR_EVSYS_bm | PR_RTC_bm; \
00219 }
00220
00221 #define DISABLE_TC( ) { \
00222 PR.PRPC |= PR_HIRES_bm | PR_TC0_bm | PR_TC1_bm; \
00223 PR.PRPD |= PR_HIRES_bm | PR_TC0_bm | PR_TC1_bm; \
00224 PR.PRPE |= PR_HIRES_bm | PR_TC0_bm; \
00225 }
00226
00227 #define DISABLE_COM( ) { \
00228 PR.PRPC |= PR_SPI_bm | PR_TWI_bm | PR_USART0_bm | PR_USART1_bm; \
00229 PR.PRPD |= PR_SPI_bm | PR_USART0_bm | PR_USART1_bm; \
00230 PR.PRPE |= PR_TWI_bm | PR_USART0_bm; \
00231 }
00232
00233 #define DISABLE_ANLG( ) { \
00234 PR.PRPA |= PR_AC_bm | PR_ADC_bm; \
00235 PR.PRPB |= PR_DAC_bm; \
00236 }
00237
00238 #define ENABLE_PULLUP( ) { \
00239 __PORT_PULLUP(PORTA, 0xFF); \
00240 __PORT_PULLUP(PORTB, 0x0F); \
00241 __PORT_PULLUP(PORTC, 0xFF); \
00242 __PORT_PULLUP(PORTD, 0xFF); \
00243 __PORT_PULLUP(PORTE, 0x0F); \
00244 __PORT_PULLUP(PORTR, 0x03); \
00245 }
00246
00247
00248
00249 #elif defined(__ATxmega64D3__) || defined(__ATxmega128D3__) || defined(__ATxmega192D3__) || defined(__ATxmega256D3__) || \
00250 defined(__AVR_ATxmega64D3__) || defined(__AVR_ATxmega128D3__) || defined(__AVR_ATxmega192D3__) || defined(__AVR_ATxmega256D3__)
00251 #warning Macros for D3 may be outdated!
00252
00253 #define DISABLE_GEN( ) { \
00254 PR.PRGEN |= PR_EVSYS_bm | PR_RTC_bm; \
00255 }
00256
00257 #define DISABLE_TC( ) { \
00258 PR.PRPC |= PR_HIRES_bm | PR_TC0_bm | PR_TC1_bm; \
00259 PR.PRPD |= PR_HIRES_bm | PR_TC0_bm; \
00260 PR.PRPE |= PR_HIRES_bm | PR_TC0_bm; \
00261 PR.PRPF |= PR_HIRES_bm | PR_TC0_bm; \
00262 }
00263
00264 #define DISABLE_COM( ) { \
00265 PR.PRPC |= PR_SPI_bm | PR_TWI_bm | PR_USART0_bm; \
00266 PR.PRPD |= PR_SPI_bm | PR_USART0_bm; \
00267 PR.PRPE |= PR_USART0_bm; \
00268 }
00269
00270 #define DISABLE_ANLG( ) { \
00271 PR.PRPA |= PR_AC_bm | PR_ADC_bm; \
00272 }
00273
00274 #define ENABLE_PULLUP( ) { \
00275 __PORT_PULLUP(PORTA, 0xFF); \
00276 __PORT_PULLUP(PORTB, 0xFF); \
00277 __PORT_PULLUP(PORTC, 0xFF); \
00278 __PORT_PULLUP(PORTD, 0xFF); \
00279 __PORT_PULLUP(PORTE, 0xFF); \
00280 __PORT_PULLUP(PORTF, 0xFF); \
00281 __PORT_PULLUP(PORTR, 0x03); \
00282 }
00283
00284
00285
00286 #elif defined(__ATxmega16D4__) || defined(__ATxmega32D4__) || defined(__ATxmega64D4__) || \
00287 defined(__AVR_ATxmega16D4__) || defined(__AVR_ATxmega32D4__) || defined(__AVR_ATxmega64D4__)
00288 #warning Macros for D4 may be outdated!
00289
00290 #define DISABLE_GEN( ) { \
00291 PR.PRGEN |= PR_EVSYS_bm | PR_RTC_bm; \
00292 }
00293
00294 #define DISABLE_TC( ) { \
00295 PR.PRPC |= PR_HIRES_bm | PR_TC0_bm | PR_TC1_bm; \
00296 PR.PRPD |= PR_TC0_bm; \
00297 PR.PRPE |= PR_TC0_bm; \
00298 }
00299
00300 #define DISABLE_COM( ) { \
00301 PR.PRPC |= PR_SPI_bm | PR_TWI_bm | PR_USART0_bm; \
00302 PR.PRPD |= PR_SPI_bm | PR_USART0_bm; \
00303 }
00304
00305 #define DISABLE_ANLG( ) { \
00306 PR.PRPA |= PR_AC_bm | PR_ADC_bm; \
00307 }
00308
00309 #define ENABLE_PULLUP( ) { \
00310 __PORT_PULLUP(PORTA, 0xFF); \
00311 __PORT_PULLUP(PORTB, 0x0F); \
00312 __PORT_PULLUP(PORTC, 0xFF); \
00313 __PORT_PULLUP(PORTD, 0xFF); \
00314 __PORT_PULLUP(PORTE, 0x0F); \
00315 __PORT_PULLUP(PORTR, 0x03); \
00316 }
00317
00318
00319
00320 #else
00321 #error Device not supported by lowpower module!
00322 #endif // Device selection.
00323
00324
00325 #endif // LOWPOWER_MACROS_H