AVR Libc Home Page | AVR Libc Development Pages | |||
Main Page | FAQ | Library Reference | Additional Documentation | Example Projects |
#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 <string.h>: Strings.
If possible, put your constant tables in the lower 64 KB 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. All functions that are suffixed with a _P
require their arguments to be in the lower 64 KB of the flash ROM, as they do not use ELPM instructions. This is normally not a big concern as the linker setup arranges any program space constants declared using the macros from this header file so they are placed right after the interrupt vectors, and in front of any executable code. However, it can become a problem if there are too many of these constants, or for bootloaders on devices with more than 64 KB of ROM. All these functions will not work in that situation.
Defines | |
#define | PROGMEM __ATTR_PROGMEM__ |
#define | PSTR(s) ((const PROGMEM char *)(s)) |
#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 * |
Typedefs | |
typedef void PROGMEM | prog_void |
typedef char PROGMEM | prog_char |
typedef unsigned char PROGMEM | prog_uchar |
typedef int8_t PROGMEM | prog_int8_t |
typedef uint8_t PROGMEM | prog_uint8_t |
typedef int16_t PROGMEM | prog_int16_t |
typedef uint16_t PROGMEM | prog_uint16_t |
typedef int32_t PROGMEM | prog_int32_t |
typedef uint32_t PROGMEM | prog_uint32_t |
typedef int64_t PROGMEM | prog_int64_t |
typedef uint64_t PROGMEM | prog_uint64_t |
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) |
size_t | strnlen_P (PGM_P, size_t) __ATTR_CONST__ |
char * | strstr_P (const char *, PGM_P) __ATTR_PURE__ |
|
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. |
|
Attribute to use in order to declare an object being located in flash ROM. |
|
Used to declare a static pointer to a string in program space. |
|
Type of a "char" object located in flash ROM. |
|
Type of an "int16_t" object located in flash ROM. |
|
Type of an "int32_t" object located in flash ROM. |
|
Type of an "int64_t" object located in flash ROM. |
|
Type of an "int8_t" object located in flash ROM. |
|
Type of an "unsigned char" object located in flash ROM. |
|
Type of an "uint16_t" object located in flash ROM. |
|
Type of an "uint32_t" object located in flash ROM. |
|
Type of an "uint64_t" object located in flash ROM. |
|
Type of an "uint8_t" object located in flash ROM. |
|
Type of a "void" object located in flash ROM. Does not make much sense by itself, but can be used to declare a "void *" object in flash ROM. |
|
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.
|
|
Determine the length of a fixed-size string.
The strnlen_P() function is similar to strnlen(), except that
|
|
Locate a substring.
The strstr_P() function finds the first occurrence of the substring
|