| 1 |
/* Copyright (c) 2002, 2003, 2004 Marek Michalkiewicz |
/* Copyright (c) 2002, 2003, 2004,2005 Marek Michalkiewicz |
| 2 |
All rights reserved. |
All rights reserved. |
| 3 |
|
|
| 4 |
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
| 81 |
#define __ATTR_PURE__ __attribute__((__pure__)) |
#define __ATTR_PURE__ __attribute__((__pure__)) |
| 82 |
#endif |
#endif |
| 83 |
|
|
| 84 |
|
/** |
| 85 |
|
\ingroup avr_pgmspace |
| 86 |
|
\def PROGMEM |
| 87 |
|
|
| 88 |
|
Attribute to use in order to declare an object being located in |
| 89 |
|
flash ROM. |
| 90 |
|
*/ |
| 91 |
#define PROGMEM __ATTR_PROGMEM__ |
#define PROGMEM __ATTR_PROGMEM__ |
| 92 |
|
|
| 93 |
#ifdef __cplusplus |
#ifdef __cplusplus |
| 94 |
extern "C" { |
extern "C" { |
| 95 |
#endif |
#endif |
| 96 |
|
|
| 97 |
|
#if defined(DOXYGEN) |
| 98 |
|
/* |
| 99 |
|
* Doxygen doesn't grok the appended attribute syntax of |
| 100 |
|
* GCC, and confuses the typedefs with function decls, so |
| 101 |
|
* supply a doxygen-friendly view. |
| 102 |
|
*/ |
| 103 |
|
/** |
| 104 |
|
\ingroup avr_pgmspace |
| 105 |
|
\typedef prog_void |
| 106 |
|
|
| 107 |
|
Type of a "void" object located in flash ROM. Does not make much |
| 108 |
|
sense by itself, but can be used to declare a "void *" object in |
| 109 |
|
flash ROM. |
| 110 |
|
*/ |
| 111 |
|
typedef void PROGMEM prog_void; |
| 112 |
|
/** |
| 113 |
|
\ingroup avr_pgmspace |
| 114 |
|
\typedef prog_char |
| 115 |
|
|
| 116 |
|
Type of a "char" object located in flash ROM. |
| 117 |
|
*/ |
| 118 |
|
typedef char PROGMEM prog_char; |
| 119 |
|
|
| 120 |
|
/** |
| 121 |
|
\ingroup avr_pgmspace |
| 122 |
|
\typedef prog_uchar |
| 123 |
|
|
| 124 |
|
Type of an "unsigned char" object located in flash ROM. |
| 125 |
|
*/ |
| 126 |
|
typedef unsigned char PROGMEM prog_uchar; |
| 127 |
|
|
| 128 |
|
|
| 129 |
|
/** |
| 130 |
|
\ingroup avr_pgmspace |
| 131 |
|
\typedef prog_int8_t |
| 132 |
|
|
| 133 |
|
Type of an "int8_t" object located in flash ROM. |
| 134 |
|
*/ |
| 135 |
|
typedef int8_t PROGMEM prog_int8_t; |
| 136 |
|
|
| 137 |
|
/** |
| 138 |
|
\ingroup avr_pgmspace |
| 139 |
|
\typedef prog_uint8_t |
| 140 |
|
|
| 141 |
|
Type of an "uint8_t" object located in flash ROM. |
| 142 |
|
*/ |
| 143 |
|
typedef uint8_t PROGMEM prog_uint8_t; |
| 144 |
|
|
| 145 |
|
/** |
| 146 |
|
\ingroup avr_pgmspace |
| 147 |
|
\typedef prog_int16_t |
| 148 |
|
|
| 149 |
|
Type of an "int16_t" object located in flash ROM. |
| 150 |
|
*/ |
| 151 |
|
typedef int16_t PROGMEM prog_int16_t; |
| 152 |
|
|
| 153 |
|
/** |
| 154 |
|
\ingroup avr_pgmspace |
| 155 |
|
\typedef prog_uint16_t |
| 156 |
|
|
| 157 |
|
Type of an "uint16_t" object located in flash ROM. |
| 158 |
|
*/ |
| 159 |
|
typedef uint16_t PROGMEM prog_uint16_t; |
| 160 |
|
|
| 161 |
|
/** |
| 162 |
|
\ingroup avr_pgmspace |
| 163 |
|
\typedef prog_int32_t |
| 164 |
|
|
| 165 |
|
Type of an "int32_t" object located in flash ROM. |
| 166 |
|
*/ |
| 167 |
|
typedef int32_t PROGMEM prog_int32_t; |
| 168 |
|
|
| 169 |
|
/** |
| 170 |
|
\ingroup avr_pgmspace |
| 171 |
|
\typedef prog_uint32_t |
| 172 |
|
|
| 173 |
|
Type of an "uint32_t" object located in flash ROM. |
| 174 |
|
*/ |
| 175 |
|
typedef uint32_t PROGMEM prog_uint32_t; |
| 176 |
|
|
| 177 |
|
/** |
| 178 |
|
\ingroup avr_pgmspace |
| 179 |
|
\typedef prog_int64_t |
| 180 |
|
|
| 181 |
|
Type of an "int64_t" object located in flash ROM. |
| 182 |
|
*/ |
| 183 |
|
typedef int64_t PROGMEM prog_int64_t; |
| 184 |
|
|
| 185 |
|
/** |
| 186 |
|
\ingroup avr_pgmspace |
| 187 |
|
\typedef prog_uint64_t |
| 188 |
|
|
| 189 |
|
Type of an "uint64_t" object located in flash ROM. |
| 190 |
|
*/ |
| 191 |
|
typedef uint64_t PROGMEM prog_uint64_t; |
| 192 |
|
#else /* !DOXYGEN */ |
| 193 |
typedef void prog_void PROGMEM; |
typedef void prog_void PROGMEM; |
| 194 |
typedef char prog_char PROGMEM; |
typedef char prog_char PROGMEM; |
| 195 |
typedef unsigned char prog_uchar PROGMEM; |
typedef unsigned char prog_uchar PROGMEM; |
| 198 |
typedef uint8_t prog_uint8_t PROGMEM; |
typedef uint8_t prog_uint8_t PROGMEM; |
| 199 |
typedef int16_t prog_int16_t PROGMEM; |
typedef int16_t prog_int16_t PROGMEM; |
| 200 |
typedef uint16_t prog_uint16_t PROGMEM; |
typedef uint16_t prog_uint16_t PROGMEM; |
|
#if defined(__HAS_INT32_T__) |
|
| 201 |
typedef int32_t prog_int32_t PROGMEM; |
typedef int32_t prog_int32_t PROGMEM; |
| 202 |
typedef uint32_t prog_uint32_t PROGMEM; |
typedef uint32_t prog_uint32_t PROGMEM; |
|
#endif |
|
|
#if defined(__HAS_INT64_T__) |
|
| 203 |
typedef int64_t prog_int64_t PROGMEM; |
typedef int64_t prog_int64_t PROGMEM; |
| 204 |
typedef uint64_t prog_uint64_t PROGMEM; |
typedef uint64_t prog_uint64_t PROGMEM; |
| 205 |
#endif |
#endif /* defined(DOXYGEN) */ |
| 206 |
|
|
| 207 |
/* Although in C, we can get away with just using __c, it does not work in |
/* Although in C, we can get away with just using __c, it does not work in |
| 208 |
C++. We need to use &__c[0] to avoid the compiler puking. Dave Hylands |
C++. We need to use &__c[0] to avoid the compiler puking. Dave Hylands |
| 214 |
returned by &__c[0] is a prog_char *, which explains why it works |
returned by &__c[0] is a prog_char *, which explains why it works |
| 215 |
fine. */ |
fine. */ |
| 216 |
|
|
| 217 |
|
#if defined(DOXYGEN) |
| 218 |
|
/* |
| 219 |
|
* The #define below is just a dummy that serves documentation |
| 220 |
|
* purposes only. |
| 221 |
|
*/ |
| 222 |
/** \ingroup avr_pgmspace |
/** \ingroup avr_pgmspace |
| 223 |
\def PSTR(s) |
\def PSTR(s) |
| 224 |
|
|
| 225 |
Used to declare a static pointer to a string in program space. */ |
Used to declare a static pointer to a string in program space. */ |
| 226 |
|
# define PSTR(s) ((const PROGMEM char *)(s)) |
| 227 |
#define PSTR(s) ({static char __c[] PROGMEM = (s); &__c[0];}) |
#else /* !DOXYGEN */ |
| 228 |
|
/* The real thing. */ |
| 229 |
|
# define PSTR(s) (__extension__({static char __c[] PROGMEM = (s); &__c[0];})) |
| 230 |
|
#endif /* DOXYGEN */ |
| 231 |
|
|
| 232 |
#define __LPM_classic__(addr) \ |
#define __LPM_classic__(addr) \ |
| 233 |
({ \ |
(__extension__({ \ |
| 234 |
uint16_t __addr16 = (uint16_t)(addr); \ |
uint16_t __addr16 = (uint16_t)(addr); \ |
| 235 |
uint8_t __result; \ |
uint8_t __result; \ |
| 236 |
__asm__ \ |
__asm__ \ |
| 242 |
: "r0" \ |
: "r0" \ |
| 243 |
); \ |
); \ |
| 244 |
__result; \ |
__result; \ |
| 245 |
}) |
})) |
| 246 |
|
|
| 247 |
#define __LPM_enhanced__(addr) \ |
#define __LPM_enhanced__(addr) \ |
| 248 |
({ \ |
(__extension__({ \ |
| 249 |
uint16_t __addr16 = (uint16_t)(addr); \ |
uint16_t __addr16 = (uint16_t)(addr); \ |
| 250 |
uint8_t __result; \ |
uint8_t __result; \ |
| 251 |
__asm__ \ |
__asm__ \ |
| 255 |
: "z" (__addr16) \ |
: "z" (__addr16) \ |
| 256 |
); \ |
); \ |
| 257 |
__result; \ |
__result; \ |
| 258 |
}) |
})) |
| 259 |
|
|
| 260 |
#define __LPM_word_classic__(addr) \ |
#define __LPM_word_classic__(addr) \ |
| 261 |
({ \ |
(__extension__({ \ |
| 262 |
uint16_t __addr16 = (uint16_t)(addr); \ |
uint16_t __addr16 = (uint16_t)(addr); \ |
| 263 |
uint16_t __result; \ |
uint16_t __result; \ |
| 264 |
__asm__ \ |
__asm__ \ |
| 273 |
: "r0" \ |
: "r0" \ |
| 274 |
); \ |
); \ |
| 275 |
__result; \ |
__result; \ |
| 276 |
}) |
})) |
| 277 |
|
|
| 278 |
#define __LPM_word_enhanced__(addr) \ |
#define __LPM_word_enhanced__(addr) \ |
| 279 |
({ \ |
(__extension__({ \ |
| 280 |
uint16_t __addr16 = (uint16_t)(addr); \ |
uint16_t __addr16 = (uint16_t)(addr); \ |
| 281 |
uint16_t __result; \ |
uint16_t __result; \ |
| 282 |
__asm__ \ |
__asm__ \ |
| 287 |
: "1" (__addr16) \ |
: "1" (__addr16) \ |
| 288 |
); \ |
); \ |
| 289 |
__result; \ |
__result; \ |
| 290 |
}) |
})) |
| 291 |
|
|
| 292 |
#define __LPM_dword_classic__(addr) \ |
#define __LPM_dword_classic__(addr) \ |
| 293 |
({ \ |
(__extension__({ \ |
| 294 |
uint16_t __addr16 = (uint16_t)(addr); \ |
uint16_t __addr16 = (uint16_t)(addr); \ |
| 295 |
uint32_t __result; \ |
uint32_t __result; \ |
| 296 |
__asm__ \ |
__asm__ \ |
| 311 |
: "r0" \ |
: "r0" \ |
| 312 |
); \ |
); \ |
| 313 |
__result; \ |
__result; \ |
| 314 |
}) |
})) |
| 315 |
|
|
| 316 |
#define __LPM_dword_enhanced__(addr) \ |
#define __LPM_dword_enhanced__(addr) \ |
| 317 |
({ \ |
(__extension__({ \ |
| 318 |
uint16_t __addr16 = (uint16_t)(addr); \ |
uint16_t __addr16 = (uint16_t)(addr); \ |
| 319 |
uint32_t __result; \ |
uint32_t __result; \ |
| 320 |
__asm__ \ |
__asm__ \ |
| 327 |
: "1" (__addr16) \ |
: "1" (__addr16) \ |
| 328 |
); \ |
); \ |
| 329 |
__result; \ |
__result; \ |
| 330 |
}) |
})) |
| 331 |
|
|
| 332 |
#if defined (__AVR_ENHANCED__) |
#if defined (__AVR_ENHANCED__) |
| 333 |
#define __LPM(addr) __LPM_enhanced__(addr) |
#define __LPM(addr) __LPM_enhanced__(addr) |
| 375 |
/* The classic functions are needed for ATmega103. */ |
/* The classic functions are needed for ATmega103. */ |
| 376 |
|
|
| 377 |
#define __ELPM_classic__(addr) \ |
#define __ELPM_classic__(addr) \ |
| 378 |
({ \ |
(__extension__({ \ |
| 379 |
uint32_t __addr32 = (uint32_t)(addr); \ |
uint32_t __addr32 = (uint32_t)(addr); \ |
| 380 |
uint8_t __result; \ |
uint8_t __result; \ |
| 381 |
__asm__ \ |
__asm__ \ |
| 391 |
: "r0", "r30", "r31" \ |
: "r0", "r30", "r31" \ |
| 392 |
); \ |
); \ |
| 393 |
__result; \ |
__result; \ |
| 394 |
}) |
})) |
| 395 |
|
|
| 396 |
#define __ELPM_enhanced__(addr) \ |
#define __ELPM_enhanced__(addr) \ |
| 397 |
({ \ |
(__extension__({ \ |
| 398 |
uint32_t __addr32 = (uint32_t)(addr); \ |
uint32_t __addr32 = (uint32_t)(addr); \ |
| 399 |
uint8_t __result; \ |
uint8_t __result; \ |
| 400 |
__asm__ \ |
__asm__ \ |
| 408 |
: "r30", "r31" \ |
: "r30", "r31" \ |
| 409 |
); \ |
); \ |
| 410 |
__result; \ |
__result; \ |
| 411 |
}) |
})) |
| 412 |
|
|
| 413 |
#define __ELPM_word_classic__(addr) \ |
#define __ELPM_word_classic__(addr) \ |
| 414 |
({ \ |
(__extension__({ \ |
| 415 |
uint32_t __addr32 = (uint32_t)(addr); \ |
uint32_t __addr32 = (uint32_t)(addr); \ |
| 416 |
uint16_t __result; \ |
uint16_t __result; \ |
| 417 |
__asm__ \ |
__asm__ \ |
| 433 |
: "r0", "r30", "r31" \ |
: "r0", "r30", "r31" \ |
| 434 |
); \ |
); \ |
| 435 |
__result; \ |
__result; \ |
| 436 |
}) |
})) |
| 437 |
|
|
| 438 |
#define __ELPM_word_enhanced__(addr) \ |
#define __ELPM_word_enhanced__(addr) \ |
| 439 |
({ \ |
(__extension__({ \ |
| 440 |
uint32_t __addr32 = (uint32_t)(addr); \ |
uint32_t __addr32 = (uint32_t)(addr); \ |
| 441 |
uint16_t __result; \ |
uint16_t __result; \ |
| 442 |
__asm__ \ |
__asm__ \ |
| 451 |
: "r30", "r31" \ |
: "r30", "r31" \ |
| 452 |
); \ |
); \ |
| 453 |
__result; \ |
__result; \ |
| 454 |
}) |
})) |
| 455 |
|
|
| 456 |
#define __ELPM_dword_classic__(addr) \ |
#define __ELPM_dword_classic__(addr) \ |
| 457 |
({ \ |
(__extension__({ \ |
| 458 |
uint32_t __addr32 = (uint32_t)(addr); \ |
uint32_t __addr32 = (uint32_t)(addr); \ |
| 459 |
uint32_t __result; \ |
uint32_t __result; \ |
| 460 |
__asm__ \ |
__asm__ \ |
| 488 |
: "r0", "r30", "r31" \ |
: "r0", "r30", "r31" \ |
| 489 |
); \ |
); \ |
| 490 |
__result; \ |
__result; \ |
| 491 |
}) |
})) |
| 492 |
|
|
| 493 |
#define __ELPM_dword_enhanced__(addr) \ |
#define __ELPM_dword_enhanced__(addr) \ |
| 494 |
({ \ |
(__extension__({ \ |
| 495 |
uint32_t __addr32 = (uint32_t)(addr); \ |
uint32_t __addr32 = (uint32_t)(addr); \ |
| 496 |
uint32_t __result; \ |
uint32_t __result; \ |
| 497 |
__asm__ \ |
__asm__ \ |
| 508 |
: "r30", "r31" \ |
: "r30", "r31" \ |
| 509 |
); \ |
); \ |
| 510 |
__result; \ |
__result; \ |
| 511 |
}) |
})) |
| 512 |
|
|
| 513 |
#if defined (__AVR_ENHANCED__) |
#if defined (__AVR_ENHANCED__) |
| 514 |
#define __ELPM(addr) __ELPM_enhanced__(addr) |
#define __ELPM(addr) __ELPM_enhanced__(addr) |