00001 #ifndef _ARCH_AVR_ICC_H_
00002 #define _ARCH_AVR_ICC_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 #include <stddef.h>
00072 #include <macros.h>
00073 #include <eeprom.h>
00074
00075
00076 #if defined(_MCU_Enhanced) && !defined(_MCU_enhanced)
00077 #define _MCU_enhanced
00078 #endif
00079
00080 #if defined(_MCU_Extended) && !defined(_MCU_extended)
00081 #define _MCU_extended
00082 #endif
00083
00091 #if defined(_MCU_enhanced) || defined(_MCU_extended)
00092 #undef __AVR_ENHANCED__
00093 #define __AVR_ENHANCED__
00094 #endif
00095
00103 #ifndef CONST
00104 #define CONST
00105 #endif
00106
00113 #ifndef INLINE
00114 #define INLINE
00115 #endif
00116
00126 #define printf printf_M
00127 #define puts puts_M
00128 #define sprintf sprintf_M
00129 #define vprintf vprintf_M
00130 #define scanf scanf_M
00131 #define gets gets_M
00132 #define malloc malloc_M
00133 #define realloc realloc_M
00134 #define free free_M
00135
00142 #define cprintf printf_P
00143 #define csprintf sprintf_P
00144 #define cscanf scanf_P
00145 #define csscanf sscanf_P
00146
00147 #define memcpy_P(dst, src_P, n) cmemcpy(dst, src_P, n)
00148 #define strcat_P(s1, s2_P) cstrcat(s1, s2_P)
00149 #define strcmp_P(s1_P, s2) cstrcmp(s2, s1_P)
00150 #define strlen_P(s_P) cstrlen(s_P)
00151 #define strncat_P(s1, s2_P, n) cstrncat(s1, s2_P, n)
00152 #define strncmp_P(s1_P, s2, n) cstrncmp(s1_P, s2, n)
00153 #define strcpy_P(dst, src_P) cstrcpy(dst, src_P)
00154 #define strncpy_P(x,y,z) cstrncpy(x,y,z)
00155
00164 #define strcasecmp(s1, s2) strcmp(s1, s2)
00165 #define strncasecmp(s1, s2, n) strncmp(s1, s2, n)
00166
00167
00171 #define __heap_start _bss_end
00172
00178 #define __attribute__(x)
00179
00185 #define PSTR(p) (p)
00186
00190 #define PRG_RDB(p) (*((const char *)(p)))
00191
00195 #define prog_char const char
00196
00200 #define prog_int const int
00201
00205 #define PGM_P prog_char *
00206
00207
00208
00209
00210
00211
00212 #define wdt_enable(tmo) \
00213 { \
00214 register u_char s = _BV(WDCE) | _BV(WDE); \
00215 register u_char r = tmo | _BV(WDE); \
00216 asm("in R0, 0x3F\n" \
00217 "cli\n" \
00218 "wdr\n" \
00219 "out 0x21, %s\n" \
00220 "out 0x21, %r\n" \
00221 "out 0x3F, R0\n"); \
00222 }
00223
00224 #define wdt_disable() \
00225 { \
00226 register u_char s = _BV(WDCE) | _BV(WDE); \
00227 register u_char r = 0; \
00228 asm("in R0, $3F\n" \
00229 "cli\n" \
00230 "out 0x21, %s\n" \
00231 "out 0x21, %r\n" \
00232 "out 0x3F, R0\n"); \
00233 }
00234
00235 #define wdt_reset() \
00236 { \
00237 _WDR(); \
00238 }
00239
00240
00241 #define __SFR_OFFSET 0
00242 #define SFR_IO_ADDR(sfr) ((sfr) - __SFR_OFFSET)
00243 #define SFR_MEM_ADDR(sfr) (sfr)
00244 #define SFR_IO_REG_P(sfr) ((sfr) < 0x40 + __SFR_OFFSET)
00245
00246 #define _SFR_MEM8(addr) (addr)
00247 #define _SFR_MEM16(addr) (addr)
00248
00249 #define BV(x) BIT(x)
00250 #define _BV(x) BIT(x)
00251
00252 #define cli() CLI()
00253 #define sei() SEI()
00254 #define cbi(reg, bit) (reg &= ~BIT(bit))
00255 #define sbi(reg, bit) (reg |= BIT(bit))
00256
00257
00258 #define loop_until_bit_is_set(reg, bit) while((reg & BIT(bit)) == 0)
00259
00260 #define bit_is_clear(reg, bit) ((reg & BIT(bit)) == 0)
00261 #define bit_is_set(reg, bit) ((reg & BIT(bit)) != 0)
00262
00263
00264 #define parity_even_bit(x) (0)
00265
00266
00267 #define SIGNAL(x) void x(void)
00268
00269 #define outp(val, reg) (reg = val)
00270 #define outb(reg, val) (reg = val)
00271
00272 #define inp(reg) (reg)
00273 #define inb(reg) (reg)
00274
00275 #include <eeprom.h>
00276
00277 #if defined(_MCU_enhanced) || defined(_MCU_extended)
00278
00279 #ifdef ATMega2560
00280 #include <iom2560v.h>
00281 #define __AVR_ATmega2560__
00282 #ifndef _EE_EXTIO
00283 #error "Looks like wrong platform. Select avrext-icc, not avr-icc."
00284 #endif
00285 #elif defined(ATMega2561)
00286 #include <iom2561v.h>
00287 #define __AVR_ATmega2561__
00288 #ifndef _EE_EXTIO
00289 #error "Looks like wrong platform. Select avrext-icc, not avr-icc."
00290 #endif
00291 #else
00292 #include <iom128v.h>
00293 #define __AVR_ATmega128__
00294 #endif
00295
00296 #ifndef RAMEND
00297 #if defined(ATMega2560) || defined(ATMega2561)
00298 #define RAMEND 0x21FF
00299 #else
00300 #define RAMEND 0x10FF
00301 #endif
00302 #endif
00303
00304 #ifndef SRW
00305 #define SRW 6
00306 #endif
00307
00308
00309 #ifndef TXC
00310 #define TXC TXC0
00311 #endif
00312 #ifndef ADCSR
00313 #define ADCSR ADCSRA
00314 #endif
00315
00316
00317 #define TW_START 0x08
00318 #define TW_REP_START 0x10
00319
00320 #define TW_MT_SLA_ACK 0x18
00321 #define TW_MT_SLA_NACK 0x20
00322 #define TW_MT_DATA_ACK 0x28
00323 #define TW_MT_DATA_NACK 0x30
00324 #define TW_MT_ARB_LOST 0x38
00325
00326 #define TW_MR_ARB_LOST 0x38
00327 #define TW_MR_SLA_ACK 0x40
00328 #define TW_MR_SLA_NACK 0x48
00329 #define TW_MR_DATA_ACK 0x50
00330 #define TW_MR_DATA_NACK 0x58
00331
00332 #define TW_ST_SLA_ACK 0xA8
00333 #define TW_ST_ARB_LOST_SLA_ACK 0xB0
00334 #define TW_ST_DATA_ACK 0xB8
00335 #define TW_ST_DATA_NACK 0xC0
00336 #define TW_ST_LAST_DATA 0xC8
00337
00338 #define TW_SR_SLA_ACK 0x60
00339 #define TW_SR_ARB_LOST_SLA_ACK 0x68
00340 #define TW_SR_GCALL_ACK 0x70
00341 #define TW_SR_ARB_LOST_GCALL_ACK 0x78
00342 #define TW_SR_DATA_ACK 0x80
00343 #define TW_SR_DATA_NACK 0x88
00344 #define TW_SR_GCALL_DATA_ACK 0x90
00345 #define TW_SR_GCALL_DATA_NACK 0x98
00346 #define TW_SR_STOP 0xA0
00347
00348 #define TW_NO_INFO 0xF8
00349 #define TW_BUS_ERROR 0x00
00350
00351
00352 #else
00353
00354 #include <iom103v.h>
00355 #define __AVR_ATmega103__
00356
00357 #ifndef DOR
00358 #define DOR OVR
00359 #endif
00360
00361 #ifndef RAMEND
00362 #define RAMEND 0x0FFF
00363 #endif
00364
00365 #ifndef WDCE
00366 #define WDCE WDTOE
00367 #endif
00368
00369 #endif
00370
00371 #define eeprom_read_block(dst, addr, size) EEPROMReadBytes((int)addr, dst, size)
00372 #define eeprom_write_byte(addr, src) EEPROMwrite((int)addr, src)
00373 #define eeprom_read_byte(addr) EEPROMread((int)addr)
00374
00375
00376 #endif
00377
00378