#include <avr/io.h> #include <avr/pgmspace.h>
The functions in this module provide interfaces for a program to access data stored in program space (flash memory) of the device. In order to use these functions, the target device must support either the LPM
or ELPM
instructions.
If you are working with strings which are completely based in ram, use the standard string functions described in Strings.
If possible, put your constant tables in the lower 64K and use pgm_read_byte_near() or pgm_read_word_near() instead of pgm_read_byte_far() or pgm_read_word_far() since it is more efficient that way, and you can still use the upper 64K for executable code.
Backwards compatibility macros | |
#define | PRG_RDB(addr) pgm_read_byte(addr) |
Defines | |
#define | PSTR(s) ({static char __c[] PROGMEM = (s); &__c[0];}) |
#define | pgm_read_byte_near(address_short) __LPM((uint16_t)(address_short)) |
#define | pgm_read_word_near(address_short) __LPM_word((uint16_t)(address_short)) |
#define | pgm_read_dword_near(address_short) __LPM_dword((uint16_t)(address_short)) |
#define | pgm_read_byte_far(address_long) __ELPM((uint32_t)(address_long)) |
#define | pgm_read_word_far(address_long) __ELPM_word((uint32_t)(address_long)) |
#define | pgm_read_dword_far(address_long) __ELPM_dword((uint32_t)(address_long)) |
#define | pgm_read_byte(address_short) pgm_read_byte_near(address_short) |
#define | pgm_read_word(address_short) pgm_read_word_near(address_short) |
#define | pgm_read_dword(address_short) pgm_read_dword_near(address_short) |
#define | PGM_P const prog_char * |
#define | PGM_VOID_P const prog_void * |
Functions | |
void * | memcpy_P (void *, PGM_VOID_P, size_t) |
int | strcasecmp_P (const char *, PGM_P) __ATTR_PURE__ |
char * | strcat_P (char *, PGM_P) |
int | strcmp_P (const char *, PGM_P) __ATTR_PURE__ |
char * | strcpy_P (char *, PGM_P) |
size_t | strlcat_P (char *, PGM_P, size_t) |
size_t | strlcpy_P (char *, PGM_P, size_t) |
size_t | strlen_P (PGM_P) __ATTR_CONST__ |
int | strncasecmp_P (const char *, PGM_P, size_t) __ATTR_PURE__ |
char * | strncat_P (char *, PGM_P, size_t) |
int | strncmp_P (const char *, PGM_P, size_t) __ATTR_PURE__ |
char * | strncpy_P (char *, PGM_P, size_t) |
|
Used to declare a variable that is a pointer to a string in program space. |
|
Read a byte from the program space with a 16-bit (near) address.
|
|
Read a byte from the program space with a 32-bit (far) address.
|
|
Read a byte from the program space with a 16-bit (near) address.
|
|
Read a double word from the program space with a 16-bit (near) address.
|
|
Read a double word from the program space with a 32-bit (far) address.
|
|
Read a double word from the program space with a 16-bit (near) address.
|
|
Read a word from the program space with a 16-bit (near) address.
|
|
Read a word from the program space with a 32-bit (far) address.
|
|
Read a word from the program space with a 16-bit (near) address.
|
|
Used to declare a generic pointer to an object in program space. |
|
|
|
Used to declare a static pointer to a string in program space. |
|
The memcpy_P() function is similar to memcpy(), except the src string resides in program space.
|
|
Compare two strings ignoring case. The strcasecmp_P() function compares the two strings s1 and s2, ignoring the case of the characters.
|
|
The strcat_P() function is similar to strcat() except that the src string must be located in program space (flash).
|
|
The strcmp_P() function is similar to strcmp() except that s2 is pointer to a string in program space.
|
|
The strcpy_P() function is similar to strcpy() except that src is a pointer to a string in program space.
|
|
Concatenate two strings. The strlcat_P() function is similar to strlcat(), except that the src string must be located in program space (flash). Appends src to string dst of size siz (unlike strncat(), siz is the full size of dst, not space left). At most siz-1 characters will be copied. Always NULL terminates (unless siz <= strlen(dst)).
|
|
Copy a string from progmem to RAM. Copy src to string dst of size siz. At most siz-1 characters will be copied. Always NULL terminates (unless siz == 0).
|
|
The strlen_P() function is similar to strlen(), except that src is a pointer to a string in program space.
|
|
Compare two strings ignoring case. The strncasecmp_P() function is similar to strcasecmp_P(), except it only compares the first n characters of s1.
|
|
Concatenate two strings. The strncat_P() function is similar to strncat(), except that the src string must be located in program space (flash).
|
|
The strncmp_P() function is similar to strcmp_P() except it only compares the first (at most) n characters of s1 and s2.
|
|
The strncpy_P() function is similar to strcpy_P() except that not more than n bytes of src are copied. Thus, if there is no null byte among the first n bytes of src, the result will not be null-terminated. In the case where the length of src is less than that of n, the remainder of dest will be padded with nulls.
|