83 #define __PGMSPACE_H_ 1
93 #ifndef __ATTR_CONST__
94 #define __ATTR_CONST__ __attribute__((__const__))
97 #ifndef __ATTR_PROGMEM__
98 #define __ATTR_PROGMEM__ __attribute__((__progmem__))
101 #ifndef __ATTR_PURE__
102 #define __ATTR_PURE__ __attribute__((__pure__))
113 #define PROGMEM __ATTR_PROGMEM__
119 #if defined(__DOXYGEN__)
339 #define PGM_P const char *
348 #define PGM_VOID_P const void *
351 #elif defined(__PROG_TYPES_COMPAT__)
353 typedef void prog_void
__attribute__((__progmem__,deprecated(
"prog_void type is deprecated.")));
354 typedef char prog_char
__attribute__((__progmem__,deprecated(
"prog_char type is deprecated.")));
355 typedef unsigned char prog_uchar
__attribute__((__progmem__,deprecated(
"prog_uchar type is deprecated.")));
356 typedef int8_t prog_int8_t
__attribute__((__progmem__,deprecated(
"prog_int8_t type is deprecated.")));
357 typedef uint8_t prog_uint8_t
__attribute__((__progmem__,deprecated(
"prog_uint8_t type is deprecated.")));
358 typedef int16_t prog_int16_t
__attribute__((__progmem__,deprecated(
"prog_int16_t type is deprecated.")));
359 typedef uint16_t prog_uint16_t
__attribute__((__progmem__,deprecated(
"prog_uint16_t type is deprecated.")));
360 typedef int32_t prog_int32_t
__attribute__((__progmem__,deprecated(
"prog_int32_t type is deprecated.")));
361 typedef uint32_t prog_uint32_t
__attribute__((__progmem__,deprecated(
"prog_uint32_t type is deprecated.")));
363 typedef int64_t prog_int64_t
__attribute__((__progmem__,deprecated(
"prog_int64_t type is deprecated.")));
364 typedef uint64_t prog_uint64_t
__attribute__((__progmem__,deprecated(
"prog_uint64_t type is deprecated.")));
368 #define PGM_P const prog_char *
372 #define PGM_VOID_P const prog_void *
378 #define PGM_P const char *
382 #define PGM_VOID_P const void *
396 #if defined(__DOXYGEN__)
405 # define PSTR(s) ((const PROGMEM char *)(s))
408 # define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];}))
412 #define __LPM_classic__(addr) \
414 uint16_t __addr16 = (uint16_t)(addr); \
416 __asm__ __volatile__ \
419 "mov %0, r0" "\n\t" \
427 #define __LPM_enhanced__(addr) \
429 uint16_t __addr16 = (uint16_t)(addr); \
431 __asm__ __volatile__ \
440 #define __LPM_word_classic__(addr) \
442 uint16_t __addr16 = (uint16_t)(addr); \
444 __asm__ __volatile__ \
447 "mov %A0, r0" "\n\t" \
448 "adiw r30, 1" "\n\t" \
450 "mov %B0, r0" "\n\t" \
451 : "=r" (__result), "=z" (__addr16) \
458 #define __LPM_word_enhanced__(addr) \
460 uint16_t __addr16 = (uint16_t)(addr); \
462 __asm__ __volatile__ \
464 "lpm %A0, Z+" "\n\t" \
465 "lpm %B0, Z" "\n\t" \
466 : "=r" (__result), "=z" (__addr16) \
472 #define __LPM_dword_classic__(addr) \
474 uint16_t __addr16 = (uint16_t)(addr); \
476 __asm__ __volatile__ \
479 "mov %A0, r0" "\n\t" \
480 "adiw r30, 1" "\n\t" \
482 "mov %B0, r0" "\n\t" \
483 "adiw r30, 1" "\n\t" \
485 "mov %C0, r0" "\n\t" \
486 "adiw r30, 1" "\n\t" \
488 "mov %D0, r0" "\n\t" \
489 : "=r" (__result), "=z" (__addr16) \
496 #define __LPM_dword_enhanced__(addr) \
498 uint16_t __addr16 = (uint16_t)(addr); \
500 __asm__ __volatile__ \
502 "lpm %A0, Z+" "\n\t" \
503 "lpm %B0, Z+" "\n\t" \
504 "lpm %C0, Z+" "\n\t" \
505 "lpm %D0, Z" "\n\t" \
506 : "=r" (__result), "=z" (__addr16) \
512 #define __LPM_float_classic__(addr) \
514 uint16_t __addr16 = (uint16_t)(addr); \
516 __asm__ __volatile__ \
519 "mov %A0, r0" "\n\t" \
520 "adiw r30, 1" "\n\t" \
522 "mov %B0, r0" "\n\t" \
523 "adiw r30, 1" "\n\t" \
525 "mov %C0, r0" "\n\t" \
526 "adiw r30, 1" "\n\t" \
528 "mov %D0, r0" "\n\t" \
529 : "=r" (__result), "=z" (__addr16) \
536 #define __LPM_float_enhanced__(addr) \
538 uint16_t __addr16 = (uint16_t)(addr); \
540 __asm__ __volatile__ \
542 "lpm %A0, Z+" "\n\t" \
543 "lpm %B0, Z+" "\n\t" \
544 "lpm %C0, Z+" "\n\t" \
545 "lpm %D0, Z" "\n\t" \
546 : "=r" (__result), "=z" (__addr16) \
552 #if defined (__AVR_HAVE_LPMX__)
553 #define __LPM(addr) __LPM_enhanced__(addr)
554 #define __LPM_word(addr) __LPM_word_enhanced__(addr)
555 #define __LPM_dword(addr) __LPM_dword_enhanced__(addr)
556 #define __LPM_float(addr) __LPM_float_enhanced__(addr)
558 #define __LPM(addr) __LPM_classic__(addr)
559 #define __LPM_word(addr) __LPM_word_classic__(addr)
560 #define __LPM_dword(addr) __LPM_dword_classic__(addr)
561 #define __LPM_float(addr) __LPM_float_classic__(addr)
572 #define pgm_read_byte_near(address_short) __LPM((uint16_t)(address_short))
580 #define pgm_read_word_near(address_short) __LPM_word((uint16_t)(address_short))
588 #define pgm_read_dword_near(address_short) \
589 __LPM_dword((uint16_t)(address_short))
597 #define pgm_read_float_near(address_short) \
598 __LPM_float((uint16_t)(address_short))
606 #define pgm_read_ptr_near(address_short) \
607 (void*)__LPM_word((uint16_t)(address_short))
609 #if defined(RAMPZ) || defined(__DOXYGEN__)
618 #define __ELPM_classic__(addr) \
620 uint32_t __addr32 = (uint32_t)(addr); \
622 __asm__ __volatile__ \
624 "out %2, %C1" "\n\t" \
625 "mov r31, %B1" "\n\t" \
626 "mov r30, %A1" "\n\t" \
628 "mov %0, r0" "\n\t" \
631 "I" (_SFR_IO_ADDR(RAMPZ)) \
632 : "r0", "r30", "r31" \
637 #define __ELPM_enhanced__(addr) \
639 uint32_t __addr32 = (uint32_t)(addr); \
641 __asm__ __volatile__ \
643 "out %2, %C1" "\n\t" \
644 "movw r30, %1" "\n\t" \
645 "elpm %0, Z+" "\n\t" \
648 "I" (_SFR_IO_ADDR(RAMPZ)) \
654 #define __ELPM_xmega__(addr) \
656 uint32_t __addr32 = (uint32_t)(addr); \
658 __asm__ __volatile__ \
660 "in __tmp_reg__, %2" "\n\t" \
661 "out %2, %C1" "\n\t" \
662 "movw r30, %1" "\n\t" \
663 "elpm %0, Z+" "\n\t" \
664 "out %2, __tmp_reg__" \
667 "I" (_SFR_IO_ADDR(RAMPZ)) \
673 #define __ELPM_word_classic__(addr) \
675 uint32_t __addr32 = (uint32_t)(addr); \
677 __asm__ __volatile__ \
679 "out %2, %C1" "\n\t" \
680 "mov r31, %B1" "\n\t" \
681 "mov r30, %A1" "\n\t" \
683 "mov %A0, r0" "\n\t" \
685 "adiw r30, 1" "\n\t" \
686 "adc r0, __zero_reg__" "\n\t" \
687 "out %2, r0" "\n\t" \
689 "mov %B0, r0" "\n\t" \
692 "I" (_SFR_IO_ADDR(RAMPZ)) \
693 : "r0", "r30", "r31" \
698 #define __ELPM_word_enhanced__(addr) \
700 uint32_t __addr32 = (uint32_t)(addr); \
702 __asm__ __volatile__ \
704 "out %2, %C1" "\n\t" \
705 "movw r30, %1" "\n\t" \
706 "elpm %A0, Z+" "\n\t" \
707 "elpm %B0, Z" "\n\t" \
710 "I" (_SFR_IO_ADDR(RAMPZ)) \
716 #define __ELPM_word_xmega__(addr) \
718 uint32_t __addr32 = (uint32_t)(addr); \
720 __asm__ __volatile__ \
722 "in __tmp_reg__, %2" "\n\t" \
723 "out %2, %C1" "\n\t" \
724 "movw r30, %1" "\n\t" \
725 "elpm %A0, Z+" "\n\t" \
726 "elpm %B0, Z" "\n\t" \
727 "out %2, __tmp_reg__" \
730 "I" (_SFR_IO_ADDR(RAMPZ)) \
736 #define __ELPM_dword_classic__(addr) \
738 uint32_t __addr32 = (uint32_t)(addr); \
740 __asm__ __volatile__ \
742 "out %2, %C1" "\n\t" \
743 "mov r31, %B1" "\n\t" \
744 "mov r30, %A1" "\n\t" \
746 "mov %A0, r0" "\n\t" \
748 "adiw r30, 1" "\n\t" \
749 "adc r0, __zero_reg__" "\n\t" \
750 "out %2, r0" "\n\t" \
752 "mov %B0, r0" "\n\t" \
754 "adiw r30, 1" "\n\t" \
755 "adc r0, __zero_reg__" "\n\t" \
756 "out %2, r0" "\n\t" \
758 "mov %C0, r0" "\n\t" \
760 "adiw r30, 1" "\n\t" \
761 "adc r0, __zero_reg__" "\n\t" \
762 "out %2, r0" "\n\t" \
764 "mov %D0, r0" "\n\t" \
767 "I" (_SFR_IO_ADDR(RAMPZ)) \
768 : "r0", "r30", "r31" \
773 #define __ELPM_dword_enhanced__(addr) \
775 uint32_t __addr32 = (uint32_t)(addr); \
777 __asm__ __volatile__ \
779 "out %2, %C1" "\n\t" \
780 "movw r30, %1" "\n\t" \
781 "elpm %A0, Z+" "\n\t" \
782 "elpm %B0, Z+" "\n\t" \
783 "elpm %C0, Z+" "\n\t" \
784 "elpm %D0, Z" "\n\t" \
787 "I" (_SFR_IO_ADDR(RAMPZ)) \
793 #define __ELPM_dword_xmega__(addr) \
795 uint32_t __addr32 = (uint32_t)(addr); \
797 __asm__ __volatile__ \
799 "in __tmp_reg__, %2" "\n\t" \
800 "out %2, %C1" "\n\t" \
801 "movw r30, %1" "\n\t" \
802 "elpm %A0, Z+" "\n\t" \
803 "elpm %B0, Z+" "\n\t" \
804 "elpm %C0, Z+" "\n\t" \
805 "elpm %D0, Z" "\n\t" \
806 "out %2, __tmp_reg__" \
809 "I" (_SFR_IO_ADDR(RAMPZ)) \
815 #define __ELPM_float_classic__(addr) \
817 uint32_t __addr32 = (uint32_t)(addr); \
819 __asm__ __volatile__ \
821 "out %2, %C1" "\n\t" \
822 "mov r31, %B1" "\n\t" \
823 "mov r30, %A1" "\n\t" \
825 "mov %A0, r0" "\n\t" \
827 "adiw r30, 1" "\n\t" \
828 "adc r0, __zero_reg__" "\n\t" \
829 "out %2, r0" "\n\t" \
831 "mov %B0, r0" "\n\t" \
833 "adiw r30, 1" "\n\t" \
834 "adc r0, __zero_reg__" "\n\t" \
835 "out %2, r0" "\n\t" \
837 "mov %C0, r0" "\n\t" \
839 "adiw r30, 1" "\n\t" \
840 "adc r0, __zero_reg__" "\n\t" \
841 "out %2, r0" "\n\t" \
843 "mov %D0, r0" "\n\t" \
846 "I" (_SFR_IO_ADDR(RAMPZ)) \
847 : "r0", "r30", "r31" \
852 #define __ELPM_float_enhanced__(addr) \
854 uint32_t __addr32 = (uint32_t)(addr); \
856 __asm__ __volatile__ \
858 "out %2, %C1" "\n\t" \
859 "movw r30, %1" "\n\t" \
860 "elpm %A0, Z+" "\n\t" \
861 "elpm %B0, Z+" "\n\t" \
862 "elpm %C0, Z+" "\n\t" \
863 "elpm %D0, Z" "\n\t" \
866 "I" (_SFR_IO_ADDR(RAMPZ)) \
872 #define __ELPM_float_xmega__(addr) \
874 uint32_t __addr32 = (uint32_t)(addr); \
876 __asm__ __volatile__ \
878 "in __tmp_reg__, %2" "\n\t" \
879 "out %2, %C1" "\n\t" \
880 "movw r30, %1" "\n\t" \
881 "elpm %A0, Z+" "\n\t" \
882 "elpm %B0, Z+" "\n\t" \
883 "elpm %C0, Z+" "\n\t" \
884 "elpm %D0, Z" "\n\t" \
885 "out %2, __tmp_reg__" \
888 "I" (_SFR_IO_ADDR(RAMPZ)) \
899 #if defined (__AVR_HAVE_RAMPD__)
901 #define __ELPM(addr) __ELPM_xmega__(addr)
902 #define __ELPM_word(addr) __ELPM_word_xmega__(addr)
903 #define __ELPM_dword(addr) __ELPM_dword_xmega__(addr)
904 #define __ELPM_float(addr) __ELPM_float_xmega__(addr)
908 #if defined (__AVR_HAVE_LPMX__)
910 #define __ELPM(addr) __ELPM_enhanced__(addr)
911 #define __ELPM_word(addr) __ELPM_word_enhanced__(addr)
912 #define __ELPM_dword(addr) __ELPM_dword_enhanced__(addr)
913 #define __ELPM_float(addr) __ELPM_float_enhanced__(addr)
917 #define __ELPM(addr) __ELPM_classic__(addr)
918 #define __ELPM_word(addr) __ELPM_word_classic__(addr)
919 #define __ELPM_dword(addr) __ELPM_dword_classic__(addr)
920 #define __ELPM_float(addr) __ELPM_float_classic__(addr)
935 #define pgm_read_byte_far(address_long) __ELPM((uint32_t)(address_long))
944 #define pgm_read_word_far(address_long) __ELPM_word((uint32_t)(address_long))
953 #define pgm_read_dword_far(address_long) __ELPM_dword((uint32_t)(address_long))
962 #define pgm_read_float_far(address_long) __ELPM_float((uint32_t)(address_long))
971 #define pgm_read_ptr_far(address_long) (void*)__ELPM_word((uint32_t)(address_long))
982 #define pgm_read_byte(address_short) pgm_read_byte_near(address_short)
991 #define pgm_read_word(address_short) pgm_read_word_near(address_short)
1000 #define pgm_read_dword(address_short) pgm_read_dword_near(address_short)
1009 #define pgm_read_float(address_short) pgm_read_float_near(address_short)
1018 #define pgm_read_ptr(address_short) pgm_read_ptr_near(address_short)
1053 #define pgm_get_far_address(var) \
1055 uint_farptr_t tmp; \
1057 __asm__ __volatile__( \
1059 "ldi %A0, lo8(%1)" "\n\t" \
1060 "ldi %B0, hi8(%1)" "\n\t" \
1061 "ldi %C0, hh8(%1)" "\n\t" \
1085 extern const void *
memchr_P(
const void *,
int __val,
size_t __len) __ATTR_CONST__;
1099 extern int memcmp_P(
const void *,
const void *,
size_t) __ATTR_PURE__;
1106 extern
void *
memccpy_P(
void *, const
void *,
int __val,
size_t);
1115 extern
void *
memcpy_P(
void *, const
void *,
size_t);
1122 extern
void *
memmem_P(const
void *,
size_t, const
void *,
size_t) __ATTR_PURE__;
1134 extern const
void *
memrchr_P(const
void *,
int __val,
size_t __len) __ATTR_CONST__;
1144 extern
char *
strcat_P(
char *, const
char *);
1160 extern const
char *
strchr_P(const
char *,
int __val) __ATTR_CONST__;
1172 extern const
char *
strchrnul_P(const
char *,
int __val) __ATTR_CONST__;
1185 extern
int strcmp_P(const
char *, const
char *) __ATTR_PURE__;
1195 extern
char *
strcpy_P(
char *, const
char *);
1212 extern
int strcasecmp_P(const
char *, const
char *) __ATTR_PURE__;
1219 extern
char *
strcasestr_P(const
char *, const
char *) __ATTR_PURE__;
1232 extern
size_t strcspn_P(const
char *__s, const
char * __reject) __ATTR_PURE__;
1248 extern
size_t strlcat_P (
char *, const
char *,
size_t );
1261 extern
size_t strlcpy_P (
char *, const
char *,
size_t );
1273 extern
size_t strnlen_P(const
char *,
size_t) __ATTR_CONST__;
1284 extern
int strncmp_P(const
char *, const
char *,
size_t) __ATTR_PURE__;
1303 extern
int strncasecmp_P(const
char *, const
char *,
size_t) __ATTR_PURE__;
1314 extern
char *
strncat_P(
char *, const
char *,
size_t);
1328 extern
char *
strncpy_P(
char *, const
char *,
size_t);
1343 extern
char *
strpbrk_P(const
char *__s, const
char * __accept) __ATTR_PURE__;
1354 extern const
char *
strrchr_P(const
char *,
int __val) __ATTR_CONST__;
1374 extern
char *
strsep_P(
char **__sp, const
char * __delim);
1387 extern
size_t strspn_P(const
char *__s, const
char * __accept) __ATTR_PURE__;
1401 extern
char *
strstr_P(const
char *, const
char *) __ATTR_PURE__;
1423 extern
char *
strtok_P(
char *__s, const
char * __delim);
1443 extern
char *
strtok_rP(
char *__s, const
char * __delim,
char **__last);
1704 static inline size_t strlen_P(
const char * s);
1706 extern size_t __strlen_P(
const char *) __ATTR_CONST__;
1708 static __inline__
size_t strlen_P(const
char *s) {
1709 return __builtin_constant_p(__builtin_strlen(s))
1710 ? __builtin_strlen(s) : __strlen_P(s);
int memcmp_P(const void *, const void *, size_t) __ATTR_PURE__
Compare memory areas.
uint32_t PROGMEM prog_uint32_t
Definition: pgmspace.h:288
char * strtok_P(char *__s, const char *__delim)
Parses the string into tokens.
signed long long int int64_t
Definition: stdint.h:110
void * memmem_P(const void *, size_t, const void *, size_t) __ATTR_PURE__
char * strstr_P(const char *, const char *) __ATTR_PURE__
Locate a substring.
int32_t PROGMEM prog_int32_t
Definition: pgmspace.h:270
uint64_t PROGMEM prog_uint64_t
Definition: pgmspace.h:330
char * strncpy_P(char *, const char *, size_t)
unsigned char PROGMEM prog_uchar
Definition: pgmspace.h:180
void PROGMEM prog_void
Definition: pgmspace.h:144
const char * strchr_P(const char *, int __val)
Locate character in program space string.
size_t strlcpy_P(char *, const char *, size_t)
Copy a string from progmem to RAM.
int64_t PROGMEM prog_int64_t
Definition: pgmspace.h:309
void * memcpy_PF(void *dest, uint_farptr_t src, size_t len)
Copy a memory block from flash to SRAM.
signed int int16_t
Definition: stdint.h:88
signed char int8_t
Definition: stdint.h:78
int strcasecmp_P(const char *, const char *) __ATTR_PURE__
Compare two strings ignoring case.
size_t strcspn_P(const char *__s, const char *__reject) __ATTR_PURE__
char * strcpy_PF(char *dest, uint_farptr_t src)
Duplicate a string.
char * strcat_PF(char *dest, uint_farptr_t src)
Concatenates two strings.
#define PROGMEM
Definition: pgmspace.h:113
size_t strlcat_PF(char *dst, uint_farptr_t src, size_t siz)
Concatenate two strings.
static __inline void __attribute__((__always_inline__)) __power_all_enable()
Definition: power.h:1148
char * strncat_PF(char *dest, uint_farptr_t src, size_t len)
Concatenate two strings.
char * strncat_P(char *, const char *, size_t)
Concatenate two strings.
signed long int int32_t
Definition: stdint.h:98
void * memcpy_P(void *, const void *, size_t)
char * strstr_PF(const char *s1, uint_farptr_t s2)
Locate a substring.
int strcmp_P(const char *, const char *) __ATTR_PURE__
size_t strlcpy_PF(char *dst, uint_farptr_t src, size_t siz)
Copy a string from progmem to RAM.
static size_t strlen_P(const char *s)
char * strtok_rP(char *__s, const char *__delim, char **__last)
Parses string into tokens.
int8_t PROGMEM prog_int8_t
Definition: pgmspace.h:198
int memcmp_PF(const void *, uint_farptr_t, size_t) __ATTR_PURE__
Compare memory areas.
const char * strrchr_P(const char *, int __val)
Locate character in string.
int strcmp_PF(const char *s1, uint_farptr_t s2) __ATTR_PURE__
Compares two strings.
unsigned char uint8_t
Definition: stdint.h:83
const void * memrchr_P(const void *, int __val, size_t __len)
char * strpbrk_P(const char *__s, const char *__accept) __ATTR_PURE__
uint32_t uint_farptr_t
Definition: inttypes.h:81
char * strcpy_P(char *, const char *)
unsigned long int uint32_t
Definition: stdint.h:103
char * strncpy_PF(char *dest, uint_farptr_t src, size_t len)
Duplicate a string until a limited length.
int strncasecmp_P(const char *, const char *, size_t) __ATTR_PURE__
Compare two strings ignoring case.
char PROGMEM prog_char
Definition: pgmspace.h:162
size_t strspn_P(const char *__s, const char *__accept) __ATTR_PURE__
void * memccpy_P(void *, const void *, int __val, size_t)
uint16_t PROGMEM prog_uint16_t
Definition: pgmspace.h:252
const char * strchrnul_P(const char *, int __val)
size_t strnlen_P(const char *, size_t)
Determine the length of a fixed-size string.
int strncmp_P(const char *, const char *, size_t) __ATTR_PURE__
char * strcasestr_P(const char *, const char *) __ATTR_PURE__
char * strcat_P(char *, const char *)
unsigned long long int uint64_t
Definition: stdint.h:117
const void * memchr_P(const void *, int __val, size_t __len)
Scan flash memory for a character.
int strncmp_PF(const char *s1, uint_farptr_t s2, size_t n) __ATTR_PURE__
Compare two strings with limited length.
char * strsep_P(char **__sp, const char *__delim)
Parse a string into tokens.
size_t strlen_PF(uint_farptr_t src)
Obtain the length of a string.
unsigned int uint16_t
Definition: stdint.h:93
uint8_t PROGMEM prog_uint8_t
Definition: pgmspace.h:216
size_t strnlen_PF(uint_farptr_t src, size_t len)
Determine the length of a fixed-size string.
int strcasecmp_PF(const char *s1, uint_farptr_t s2) __ATTR_PURE__
Compare two strings ignoring case.
size_t strlcat_P(char *, const char *, size_t)
Concatenate two strings.
int strncasecmp_PF(const char *s1, uint_farptr_t s2, size_t n) __ATTR_PURE__
Compare two strings ignoring case.
int16_t PROGMEM prog_int16_t
Definition: pgmspace.h:234