83 #define __PGMSPACE_H_ 1
90 #ifndef __ATTR_CONST__
91 #define __ATTR_CONST__ __attribute__((__const__))
94 #ifndef __ATTR_PROGMEM__
95 #define __ATTR_PROGMEM__ __attribute__((__progmem__))
99 #define __ATTR_PURE__ __attribute__((__pure__))
109 #define PROGMEM __ATTR_PROGMEM__
115 #if defined(__DOXYGEN__)
335 #define PGM_P const char *
344 #define PGM_VOID_P const void *
347 #elif defined(__PROG_TYPES_COMPAT__)
349 typedef void prog_void __attribute__((__progmem__,deprecated(
"prog_void type is deprecated.")));
350 typedef char prog_char __attribute__((__progmem__,deprecated(
"prog_char type is deprecated.")));
351 typedef unsigned char prog_uchar __attribute__((__progmem__,deprecated(
"prog_uchar type is deprecated.")));
352 typedef int8_t prog_int8_t __attribute__((__progmem__,deprecated(
"prog_int8_t type is deprecated.")));
353 typedef uint8_t prog_uint8_t __attribute__((__progmem__,deprecated(
"prog_uint8_t type is deprecated.")));
354 typedef int16_t prog_int16_t __attribute__((__progmem__,deprecated(
"prog_int16_t type is deprecated.")));
355 typedef uint16_t prog_uint16_t __attribute__((__progmem__,deprecated(
"prog_uint16_t type is deprecated.")));
356 typedef int32_t prog_int32_t __attribute__((__progmem__,deprecated(
"prog_int32_t type is deprecated.")));
357 typedef uint32_t prog_uint32_t __attribute__((__progmem__,deprecated(
"prog_uint32_t type is deprecated.")));
359 typedef int64_t prog_int64_t __attribute__((__progmem__,deprecated(
"prog_int64_t type is deprecated.")));
360 typedef uint64_t prog_uint64_t __attribute__((__progmem__,deprecated(
"prog_uint64_t type is deprecated.")));
364 #define PGM_P const prog_char *
368 #define PGM_VOID_P const prog_void *
374 #define PGM_P const char *
378 #define PGM_VOID_P const void *
392 #if defined(__DOXYGEN__)
401 # define PSTR(s) ((const PROGMEM char *)(s))
404 # define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];}))
407 #define __LPM_classic__(addr) \
409 uint16_t __addr16 = (uint16_t)(addr); \
411 __asm__ __volatile__ \
414 "mov %0, r0" "\n\t" \
422 #define __LPM_enhanced__(addr) \
424 uint16_t __addr16 = (uint16_t)(addr); \
426 __asm__ __volatile__ \
435 #define __LPM_word_classic__(addr) \
437 uint16_t __addr16 = (uint16_t)(addr); \
439 __asm__ __volatile__ \
442 "mov %A0, r0" "\n\t" \
443 "adiw r30, 1" "\n\t" \
445 "mov %B0, r0" "\n\t" \
446 : "=r" (__result), "=z" (__addr16) \
453 #define __LPM_word_enhanced__(addr) \
455 uint16_t __addr16 = (uint16_t)(addr); \
457 __asm__ __volatile__ \
459 "lpm %A0, Z+" "\n\t" \
460 "lpm %B0, Z" "\n\t" \
461 : "=r" (__result), "=z" (__addr16) \
467 #define __LPM_dword_classic__(addr) \
469 uint16_t __addr16 = (uint16_t)(addr); \
471 __asm__ __volatile__ \
474 "mov %A0, r0" "\n\t" \
475 "adiw r30, 1" "\n\t" \
477 "mov %B0, r0" "\n\t" \
478 "adiw r30, 1" "\n\t" \
480 "mov %C0, r0" "\n\t" \
481 "adiw r30, 1" "\n\t" \
483 "mov %D0, r0" "\n\t" \
484 : "=r" (__result), "=z" (__addr16) \
491 #define __LPM_dword_enhanced__(addr) \
493 uint16_t __addr16 = (uint16_t)(addr); \
495 __asm__ __volatile__ \
497 "lpm %A0, Z+" "\n\t" \
498 "lpm %B0, Z+" "\n\t" \
499 "lpm %C0, Z+" "\n\t" \
500 "lpm %D0, Z" "\n\t" \
501 : "=r" (__result), "=z" (__addr16) \
507 #define __LPM_float_classic__(addr) \
509 uint16_t __addr16 = (uint16_t)(addr); \
511 __asm__ __volatile__ \
514 "mov %A0, r0" "\n\t" \
515 "adiw r30, 1" "\n\t" \
517 "mov %B0, r0" "\n\t" \
518 "adiw r30, 1" "\n\t" \
520 "mov %C0, r0" "\n\t" \
521 "adiw r30, 1" "\n\t" \
523 "mov %D0, r0" "\n\t" \
524 : "=r" (__result), "=z" (__addr16) \
531 #define __LPM_float_enhanced__(addr) \
533 uint16_t __addr16 = (uint16_t)(addr); \
535 __asm__ __volatile__ \
537 "lpm %A0, Z+" "\n\t" \
538 "lpm %B0, Z+" "\n\t" \
539 "lpm %C0, Z+" "\n\t" \
540 "lpm %D0, Z" "\n\t" \
541 : "=r" (__result), "=z" (__addr16) \
547 #if defined (__AVR_HAVE_LPMX__)
548 #define __LPM(addr) __LPM_enhanced__(addr)
549 #define __LPM_word(addr) __LPM_word_enhanced__(addr)
550 #define __LPM_dword(addr) __LPM_dword_enhanced__(addr)
551 #define __LPM_float(addr) __LPM_float_enhanced__(addr)
553 #define __LPM(addr) __LPM_classic__(addr)
554 #define __LPM_word(addr) __LPM_word_classic__(addr)
555 #define __LPM_dword(addr) __LPM_dword_classic__(addr)
556 #define __LPM_float(addr) __LPM_float_classic__(addr)
565 #define pgm_read_byte_near(address_short) __LPM((uint16_t)(address_short))
573 #define pgm_read_word_near(address_short) __LPM_word((uint16_t)(address_short))
581 #define pgm_read_dword_near(address_short) \
582 __LPM_dword((uint16_t)(address_short))
590 #define pgm_read_float_near(address_short) \
591 __LPM_float((uint16_t)(address_short))
599 #define pgm_read_ptr_near(address_short) \
600 (void*)__LPM_word((uint16_t)(address_short))
602 #if defined(RAMPZ) || defined(__DOXYGEN__)
610 #define __ELPM_classic__(addr) \
612 uint32_t __addr32 = (uint32_t)(addr); \
614 __asm__ __volatile__ \
616 "out %2, %C1" "\n\t" \
617 "mov r31, %B1" "\n\t" \
618 "mov r30, %A1" "\n\t" \
620 "mov %0, r0" "\n\t" \
623 "I" (_SFR_IO_ADDR(RAMPZ)) \
624 : "r0", "r30", "r31" \
629 #define __ELPM_enhanced__(addr) \
631 uint32_t __addr32 = (uint32_t)(addr); \
633 __asm__ __volatile__ \
635 "out %2, %C1" "\n\t" \
636 "movw r30, %1" "\n\t" \
637 "elpm %0, Z+" "\n\t" \
640 "I" (_SFR_IO_ADDR(RAMPZ)) \
646 #define __ELPM_xmega__(addr) \
648 uint32_t __addr32 = (uint32_t)(addr); \
650 __asm__ __volatile__ \
652 "in __tmp_reg__, %2" "\n\t" \
653 "out %2, %C1" "\n\t" \
654 "movw r30, %1" "\n\t" \
655 "elpm %0, Z+" "\n\t" \
656 "out %2, __tmp_reg__" \
659 "I" (_SFR_IO_ADDR(RAMPZ)) \
665 #define __ELPM_word_classic__(addr) \
667 uint32_t __addr32 = (uint32_t)(addr); \
669 __asm__ __volatile__ \
671 "out %2, %C1" "\n\t" \
672 "mov r31, %B1" "\n\t" \
673 "mov r30, %A1" "\n\t" \
675 "mov %A0, r0" "\n\t" \
677 "adiw r30, 1" "\n\t" \
678 "adc r0, __zero_reg__" "\n\t" \
679 "out %2, r0" "\n\t" \
681 "mov %B0, r0" "\n\t" \
684 "I" (_SFR_IO_ADDR(RAMPZ)) \
685 : "r0", "r30", "r31" \
690 #define __ELPM_word_enhanced__(addr) \
692 uint32_t __addr32 = (uint32_t)(addr); \
694 __asm__ __volatile__ \
696 "out %2, %C1" "\n\t" \
697 "movw r30, %1" "\n\t" \
698 "elpm %A0, Z+" "\n\t" \
699 "elpm %B0, Z" "\n\t" \
702 "I" (_SFR_IO_ADDR(RAMPZ)) \
708 #define __ELPM_word_xmega__(addr) \
710 uint32_t __addr32 = (uint32_t)(addr); \
712 __asm__ __volatile__ \
714 "in __tmp_reg__, %2" "\n\t" \
715 "out %2, %C1" "\n\t" \
716 "movw r30, %1" "\n\t" \
717 "elpm %A0, Z+" "\n\t" \
718 "elpm %B0, Z" "\n\t" \
719 "out %2, __tmp_reg__" \
722 "I" (_SFR_IO_ADDR(RAMPZ)) \
728 #define __ELPM_dword_classic__(addr) \
730 uint32_t __addr32 = (uint32_t)(addr); \
732 __asm__ __volatile__ \
734 "out %2, %C1" "\n\t" \
735 "mov r31, %B1" "\n\t" \
736 "mov r30, %A1" "\n\t" \
738 "mov %A0, r0" "\n\t" \
740 "adiw r30, 1" "\n\t" \
741 "adc r0, __zero_reg__" "\n\t" \
742 "out %2, r0" "\n\t" \
744 "mov %B0, r0" "\n\t" \
746 "adiw r30, 1" "\n\t" \
747 "adc r0, __zero_reg__" "\n\t" \
748 "out %2, r0" "\n\t" \
750 "mov %C0, r0" "\n\t" \
752 "adiw r30, 1" "\n\t" \
753 "adc r0, __zero_reg__" "\n\t" \
754 "out %2, r0" "\n\t" \
756 "mov %D0, r0" "\n\t" \
759 "I" (_SFR_IO_ADDR(RAMPZ)) \
760 : "r0", "r30", "r31" \
765 #define __ELPM_dword_enhanced__(addr) \
767 uint32_t __addr32 = (uint32_t)(addr); \
769 __asm__ __volatile__ \
771 "out %2, %C1" "\n\t" \
772 "movw r30, %1" "\n\t" \
773 "elpm %A0, Z+" "\n\t" \
774 "elpm %B0, Z+" "\n\t" \
775 "elpm %C0, Z+" "\n\t" \
776 "elpm %D0, Z" "\n\t" \
779 "I" (_SFR_IO_ADDR(RAMPZ)) \
785 #define __ELPM_dword_xmega__(addr) \
787 uint32_t __addr32 = (uint32_t)(addr); \
789 __asm__ __volatile__ \
791 "in __tmp_reg__, %2" "\n\t" \
792 "out %2, %C1" "\n\t" \
793 "movw r30, %1" "\n\t" \
794 "elpm %A0, Z+" "\n\t" \
795 "elpm %B0, Z+" "\n\t" \
796 "elpm %C0, Z+" "\n\t" \
797 "elpm %D0, Z" "\n\t" \
798 "out %2, __tmp_reg__" \
801 "I" (_SFR_IO_ADDR(RAMPZ)) \
807 #define __ELPM_float_classic__(addr) \
809 uint32_t __addr32 = (uint32_t)(addr); \
811 __asm__ __volatile__ \
813 "out %2, %C1" "\n\t" \
814 "mov r31, %B1" "\n\t" \
815 "mov r30, %A1" "\n\t" \
817 "mov %A0, r0" "\n\t" \
819 "adiw r30, 1" "\n\t" \
820 "adc r0, __zero_reg__" "\n\t" \
821 "out %2, r0" "\n\t" \
823 "mov %B0, r0" "\n\t" \
825 "adiw r30, 1" "\n\t" \
826 "adc r0, __zero_reg__" "\n\t" \
827 "out %2, r0" "\n\t" \
829 "mov %C0, r0" "\n\t" \
831 "adiw r30, 1" "\n\t" \
832 "adc r0, __zero_reg__" "\n\t" \
833 "out %2, r0" "\n\t" \
835 "mov %D0, r0" "\n\t" \
838 "I" (_SFR_IO_ADDR(RAMPZ)) \
839 : "r0", "r30", "r31" \
844 #define __ELPM_float_enhanced__(addr) \
846 uint32_t __addr32 = (uint32_t)(addr); \
848 __asm__ __volatile__ \
850 "out %2, %C1" "\n\t" \
851 "movw r30, %1" "\n\t" \
852 "elpm %A0, Z+" "\n\t" \
853 "elpm %B0, Z+" "\n\t" \
854 "elpm %C0, Z+" "\n\t" \
855 "elpm %D0, Z" "\n\t" \
858 "I" (_SFR_IO_ADDR(RAMPZ)) \
864 #define __ELPM_float_xmega__(addr) \
866 uint32_t __addr32 = (uint32_t)(addr); \
868 __asm__ __volatile__ \
870 "in __tmp_reg__, %2" "\n\t" \
871 "out %2, %C1" "\n\t" \
872 "movw r30, %1" "\n\t" \
873 "elpm %A0, Z+" "\n\t" \
874 "elpm %B0, Z+" "\n\t" \
875 "elpm %C0, Z+" "\n\t" \
876 "elpm %D0, Z" "\n\t" \
877 "out %2, __tmp_reg__" \
880 "I" (_SFR_IO_ADDR(RAMPZ)) \
891 #if defined (__AVR_HAVE_RAMPD__)
893 #define __ELPM(addr) __ELPM_xmega__(addr)
894 #define __ELPM_word(addr) __ELPM_word_xmega__(addr)
895 #define __ELPM_dword(addr) __ELPM_dword_xmega__(addr)
896 #define __ELPM_float(addr) __ELPM_float_xmega__(addr)
900 #if defined (__AVR_HAVE_LPMX__)
902 #define __ELPM(addr) __ELPM_enhanced__(addr)
903 #define __ELPM_word(addr) __ELPM_word_enhanced__(addr)
904 #define __ELPM_dword(addr) __ELPM_dword_enhanced__(addr)
905 #define __ELPM_float(addr) __ELPM_float_enhanced__(addr)
909 #define __ELPM(addr) __ELPM_classic__(addr)
910 #define __ELPM_word(addr) __ELPM_word_classic__(addr)
911 #define __ELPM_dword(addr) __ELPM_dword_classic__(addr)
912 #define __ELPM_float(addr) __ELPM_float_classic__(addr)
926 #define pgm_read_byte_far(address_long) __ELPM((uint32_t)(address_long))
935 #define pgm_read_word_far(address_long) __ELPM_word((uint32_t)(address_long))
944 #define pgm_read_dword_far(address_long) __ELPM_dword((uint32_t)(address_long))
953 #define pgm_read_float_far(address_long) __ELPM_float((uint32_t)(address_long))
962 #define pgm_read_ptr_far(address_long) (void*)__ELPM_word((uint32_t)(address_long))
973 #define pgm_read_byte(address_short) pgm_read_byte_near(address_short)
982 #define pgm_read_word(address_short) pgm_read_word_near(address_short)
991 #define pgm_read_dword(address_short) pgm_read_dword_near(address_short)
1000 #define pgm_read_float(address_short) pgm_read_float_near(address_short)
1009 #define pgm_read_ptr(address_short) pgm_read_ptr_near(address_short)
1044 #define pgm_get_far_address(var) \
1046 uint_farptr_t tmp; \
1048 __asm__ __volatile__( \
1050 "ldi %A0, lo8(%1)" "\n\t" \
1051 "ldi %B0, hi8(%1)" "\n\t" \
1052 "ldi %C0, hh8(%1)" "\n\t" \
1064 extern const void * memchr_P(
const void *,
int __val,
size_t __len) __ATTR_CONST__;
1065 extern int memcmp_P(
const void *,
const void *,
size_t) __ATTR_PURE__;
1066 extern
void *memccpy_P(
void *, const
void *,
int __val,
size_t);
1067 extern
void *memcpy_P(
void *, const
void *,
size_t);
1068 extern
void *memmem_P(const
void *,
size_t, const
void *,
size_t) __ATTR_PURE__;
1069 extern const
void * memrchr_P(const
void *,
int __val,
size_t __len) __ATTR_CONST__;
1070 extern
char *strcat_P(
char *, const
char *);
1071 extern const
char * strchr_P(const
char *,
int __val) __ATTR_CONST__;
1072 extern const
char * strchrnul_P(const
char *,
int __val) __ATTR_CONST__;
1073 extern
int strcmp_P(const
char *, const
char *) __ATTR_PURE__;
1074 extern
char *strcpy_P(
char *, const
char *);
1075 extern
int strcasecmp_P(const
char *, const
char *) __ATTR_PURE__;
1076 extern
char *strcasestr_P(const
char *, const
char *) __ATTR_PURE__;
1077 extern
size_t strcspn_P(const
char *__s, const
char * __reject) __ATTR_PURE__;
1078 extern
size_t strlcat_P (
char *, const
char *,
size_t );
1079 extern
size_t strlcpy_P (
char *, const
char *,
size_t );
1080 extern
size_t __strlen_P(const
char *) __ATTR_CONST__;
1081 extern
size_t strnlen_P(const
char *,
size_t) __ATTR_CONST__;
1082 extern
int strncmp_P(const
char *, const
char *,
size_t) __ATTR_PURE__;
1083 extern
int strncasecmp_P(const
char *, const
char *,
size_t) __ATTR_PURE__;
1084 extern
char *strncat_P(
char *, const
char *,
size_t);
1085 extern
char *strncpy_P(
char *, const
char *,
size_t);
1086 extern
char *strpbrk_P(const
char *__s, const
char * __accept) __ATTR_PURE__;
1087 extern const
char * strrchr_P(const
char *,
int __val) __ATTR_CONST__;
1088 extern
char *strsep_P(
char **__sp, const
char * __delim);
1089 extern
size_t strspn_P(const
char *__s, const
char * __accept) __ATTR_PURE__;
1090 extern
char *strstr_P(const
char *, const
char *) __ATTR_PURE__;
1091 extern
char *
strtok_P(
char *__s, const
char * __delim);
1092 extern
char *strtok_rP(
char *__s, const
char * __delim,
char **__last);
1111 __attribute__((__always_inline__)) static __inline__
size_t strlen_P(const
char * s);
1112 static __inline__
size_t strlen_P(const
char *s) {
1113 return __builtin_constant_p(__builtin_strlen(s))
1114 ? __builtin_strlen(s) : __strlen_P(s);
uint32_t PROGMEM prog_uint32_t
Definition: pgmspace.h:284
signed long long int int64_t
Definition: stdint.h:107
char * strtok_P(char *s, PGM_P delim)
Parses the string into tokens.
Definition: strtok_P.c:60
int32_t PROGMEM prog_int32_t
Definition: pgmspace.h:266
uint64_t PROGMEM prog_uint64_t
Definition: pgmspace.h:326
unsigned char PROGMEM prog_uchar
Definition: pgmspace.h:176
void PROGMEM prog_void
Definition: pgmspace.h:140
int64_t PROGMEM prog_int64_t
Definition: pgmspace.h:305
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:85
signed char int8_t
Definition: stdint.h:75
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:109
size_t strlcat_PF(char *dst, uint_farptr_t src, size_t siz)
Concatenate two strings.
char * strncat_PF(char *dest, uint_farptr_t src, size_t len)
Concatenate two strings.
signed long int int32_t
Definition: stdint.h:95
char * strstr_PF(const char *s1, uint_farptr_t s2)
Locate a substring.
size_t strlcpy_PF(char *dst, uint_farptr_t src, size_t siz)
Copy a string from progmem to RAM.
int8_t PROGMEM prog_int8_t
Definition: pgmspace.h:194
int memcmp_PF(const void *, uint_farptr_t, size_t) __ATTR_PURE__
Compare memory areas.
int strcmp_PF(const char *s1, uint_farptr_t s2) __ATTR_PURE__
Compares two strings.
unsigned char uint8_t
Definition: stdint.h:80
uint32_t uint_farptr_t
Definition: inttypes.h:81
unsigned long int uint32_t
Definition: stdint.h:100
char * strncpy_PF(char *dest, uint_farptr_t src, size_t len)
Duplicate a string until a limited length.
char PROGMEM prog_char
Definition: pgmspace.h:158
uint16_t PROGMEM prog_uint16_t
Definition: pgmspace.h:248
unsigned long long int uint64_t
Definition: stdint.h:114
int strncmp_PF(const char *s1, uint_farptr_t s2, size_t n) __ATTR_PURE__
Compare two strings with limited length.
size_t strlen_PF(uint_farptr_t src)
Obtain the length of a string.
unsigned int uint16_t
Definition: stdint.h:90
uint8_t PROGMEM prog_uint8_t
Definition: pgmspace.h:212
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.
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:230