00001
00054 #ifndef COMPILER_AVR_H
00055 #define COMPILER_AVR_H
00056
00057 #include <stdint.h>
00058 #include <stdbool.h>
00059 #include <stdlib.h>
00060
00062 #define ENTER_CRITICAL_REGION() uint8_t volatile saved_sreg = SREG; \
00063 cli();
00064
00067 #define LEAVE_CRITICAL_REGION() SREG = saved_sreg;
00068
00069 #if defined(__ICCAVR__)
00070
00071 #include <inavr.h>
00072 #include <ioavr.h>
00073 #include <intrinsics.h>
00074 #include <pgmspace.h>
00075
00076 #ifndef __HAS_ELPM__
00077 #define _MEMATTR __flash
00078 #else
00079 #define _MEMATTR __farflash
00080 #endif
00081
00082 #define cpu_sleep() __sleep()
00083
00084 #define delay_us( us ) __delay_cycles((F_CPU / 1000000UL) * (us))
00085
00098 #define PRAGMA(x) _Pragma(#x)
00099 #define ISR(vec) PRAGMA(vector=vec) __interrupt void handler_##vec(void)
00100 #define sei() (__enable_interrupt( ))
00101 #define cli() (__disable_interrupt( ))
00102
00103 #define nop() (__no_operation())
00104
00105 #define INLINE PRAGMA(inline=forced) static
00106
00107 #define PROGMEM_LOCATION(var, loc) const _MEMATTR var @ loc
00108 #define PROGMEM_DECLARE(x) _MEMATTR x
00109 #define PROGMEM_STRING(x) ((_MEMATTR const char *)(x))
00110 #define PROGMEM_STRING_T char const _MEMATTR *
00111 #define PROGMEM_T const _MEMATTR
00112 #define PROGMEM_PTR_T const _MEMATTR *
00113 #define PROGMEM_BYTE_ARRAY_T uint8_t const _MEMATTR *
00114 #define PROGMEM_WORD_ARRAY_T uint16_t const _MEMATTR *
00115 #define PROGMEM_READ_BYTE(x) *(x)
00116 #define PROGMEM_READ_WORD(x) *(x)
00117
00118 #define EEPROM_DECLARE(var) __eeprom var
00119 #define EEGET(var, adr) __EEGET(var, adr)
00120 #define EEPUT(adr, val) __EEPUT(adr, val)
00121
00122 #define watchdog_reset() __watchdog_reset()
00123
00124 #define SHORTENUM
00125
00126 #elif defined(__GNUC__)
00127
00128 #include <avr/sleep.h>
00129 #include <avr/io.h>
00130 #include <avr/interrupt.h>
00131 #include <avr/pgmspace.h>
00132
00133 #include <avr/wdt.h>
00134 #include <util/delay.h>
00135
00136 #define cpu_sleep() sleep_cpu()
00137
00138 #define delay_us(us) (_delay_us( us ))
00139
00140 #define INLINE static inline
00141
00142 #define nop() do {__asm__ __volatile__ ("nop");} while (0)
00143
00144 #define PROGMEM_LOCATION(var, loc) var __attribute__((section (#loc)))
00145 #define PROGMEM_DECLARE(x) x __attribute__((__progmem__))
00146 #define PROGMEM_STRING(x) PSTR(x)
00147 #define PROGMEM_STRING_T PGM_P
00148 #define PROGMEM_T
00149 #define PROGMEM_PTR_T *
00150 #define PROGMEM_BYTE_ARRAY_T uint8_t*
00151 #define PROGMEM_WORD_ARRAY_T uint16_t*
00152 #define PROGMEM_READ_BYTE(x) pgm_read_byte(x)
00153 #define PROGMEM_READ_WORD(x) pgm_read_word(x)
00154
00155 #define EEPROM_DECLARE(var) var EEMEM
00156 #define EEGET(var, addr) (var) = eeprom_read_byte ((uint8_t *)(addr))
00157 #define EEPUT(addr, var) eeprom_write_byte ((uint8_t *)(addr), var)
00158
00159 #define watchdog_reset() wdt_reset()
00160
00161 #define SHORTENUM __attribute__ ((packed))
00162 #else
00163 #error Compiler not supported.
00164 #endif
00165 #endif
00166
00167