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.
_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.NVM.CMD
or NVM_CMD
) is set to 0x00 (NOP) before using any of these functions. This macro facilitates the obtention of a 32 bit "far" pointer (only 24 bits used) to data even passed the 64KB limit for the 16 bit ordinary pointer. It is similar to the '&' operator, with some limitations.
Comments:
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 float from the program space with a 16-bit (near) address.
Read a float from the program space with a 32-bit (far) address.
Read a float from the program space with a 16-bit (near) address.
Read a pointer from the program space with a 16-bit (near) address.
Read a pointer from the program space with a 32-bit (far) address.
Read a pointer 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.
This typedef is now deprecated because the usage of the __progmem__ attribute on a type is not supported in GCC. However, the use of the __progmem__ attribute on a variable declaration is supported, and this is now the recommended usage.
The typedef is only visible if the macro __PROG_TYPES_COMPAT__ has been defined before including <avr/pgmspace.h> (either by a #define
directive, or by a -D compiler option.)
Type of a "char" object located in flash ROM.
This typedef is now deprecated because the usage of the __progmem__ attribute on a type is not supported in GCC. However, the use of the __progmem__ attribute on a variable declaration is supported, and this is now the recommended usage.
The typedef is only visible if the macro __PROG_TYPES_COMPAT__ has been defined before including <avr/pgmspace.h> (either by a #define
directive, or by a -D compiler option.)
Type of an "int16_t" object located in flash ROM.
This typedef is now deprecated because the usage of the __progmem__ attribute on a type is not supported in GCC. However, the use of the __progmem__ attribute on a variable declaration is supported, and this is now the recommended usage.
The typedef is only visible if the macro __PROG_TYPES_COMPAT__ has been defined before including <avr/pgmspace.h> (either by a #define
directive, or by a -D compiler option.)
Type of an "int32_t" object located in flash ROM.
This typedef is now deprecated because the usage of the __progmem__ attribute on a type is not supported in GCC. However, the use of the __progmem__ attribute on a variable declaration is supported, and this is now the recommended usage.
The typedef is only visible if the macro __PROG_TYPES_COMPAT__ has been defined before including <avr/pgmspace.h> (either by a #define
directive, or by a -D compiler option.)
Type of an "int64_t" object located in flash ROM.
This typedef is now deprecated because the usage of the __progmem__ attribute on a type is not supported in GCC. However, the use of the __progmem__ attribute on a variable declaration is supported, and this is now the recommended usage.
The typedef is only visible if the macro __PROG_TYPES_COMPAT__ has been defined before including <avr/pgmspace.h> (either by a #define
directive, or by a -D compiler option.)
Type of an "int8_t" object located in flash ROM.
This typedef is now deprecated because the usage of the __progmem__ attribute on a type is not supported in GCC. However, the use of the __progmem__ attribute on a variable declaration is supported, and this is now the recommended usage.
The typedef is only visible if the macro __PROG_TYPES_COMPAT__ has been defined before including <avr/pgmspace.h> (either by a #define
directive, or by a -D compiler option.)
Type of an "unsigned char" object located in flash ROM.
This typedef is now deprecated because the usage of the __progmem__ attribute on a type is not supported in GCC. However, the use of the __progmem__ attribute on a variable declaration is supported, and this is now the recommended usage.
The typedef is only visible if the macro __PROG_TYPES_COMPAT__ has been defined before including <avr/pgmspace.h> (either by a #define
directive, or by a -D compiler option.)
Type of an "uint16_t" object located in flash ROM.
This typedef is now deprecated because the usage of the __progmem__ attribute on a type is not supported in GCC. However, the use of the __progmem__ attribute on a variable declaration is supported, and this is now the recommended usage.
The typedef is only visible if the macro __PROG_TYPES_COMPAT__ has been defined before including <avr/pgmspace.h> (either by a #define
directive, or by a -D compiler option.)
Type of an "uint32_t" object located in flash ROM.
This typedef is now deprecated because the usage of the __progmem__ attribute on a type is not supported in GCC. However, the use of the __progmem__ attribute on a variable declaration is supported, and this is now the recommended usage.
The typedef is only visible if the macro __PROG_TYPES_COMPAT__ has been defined before including <avr/pgmspace.h> (either by a #define
directive, or by a -D compiler option.)
Type of an "uint64_t" object located in flash ROM.
This typedef is now deprecated because the usage of the __progmem__ attribute on a type is not supported in GCC. However, the use of the __progmem__ attribute on a variable declaration is supported, and this is now the recommended usage.
The typedef is only visible if the macro __PROG_TYPES_COMPAT__ has been defined before including <avr/pgmspace.h> (either by a #define
directive, or by a -D compiler option.)
Type of an "uint8_t" object located in flash ROM.
This typedef is now deprecated because the usage of the __progmem__ attribute on a type is not supported in GCC. However, the use of the __progmem__ attribute on a variable declaration is supported, and this is now the recommended usage.
The typedef is only visible if the macro __PROG_TYPES_COMPAT__ has been defined before including <avr/pgmspace.h> (either by a #define
directive, or by a -D compiler option.)
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.
This function is similar to memccpy() except that src
is pointer to a string in program space.
Scan flash memory for a character.
The memchr_P() function scans the first len
bytes of the flash memory area pointed to by s
for the character val
. The first byte to match val
(interpreted as an unsigned character) stops the operation.
NULL
if the character does not occur in the given memory area. Compare memory areas.
The memcmp_P() function compares the first len
bytes of the memory areas s1
and flash s2
. The comparision is performed using unsigned char operations.
len
bytes of s1
is found, respectively, to be less than, to match, or be greater than the first len
bytes of s2
. Compare memory areas.
The memcmp_PF() function compares the first len
bytes of the memory areas s1
and flash s2
. The comparision is performed using unsigned char operations. It is an equivalent of memcmp_P() function, except that it is capable working on all FLASH including the exteded area above 64kB.
len
bytes of s1
is found, respectively, to be less than, to match, or be greater than the first len
bytes of s2
. The memcpy_P() function is similar to memcpy(), except the src string resides in program space.
Copy a memory block from flash to SRAM.
The memcpy_PF() function is similar to memcpy(), except the data is copied from the program space and is addressed using a far pointer.
The memmem_P() function is similar to memmem() except that s2
is pointer to a string in program space.
The memrchr_P() function is like the memchr_P() function, except that it searches backwards from the end of the len
bytes pointed to by src
instead of forwards from the front. (Glibc, GNU extension.)
NULL
if the character does not occur in the given memory area. Compare two strings ignoring case.
The strcasecmp_P() function compares the two strings s1
and s2
, ignoring the case of the characters.
s1
is found, respectively, to be less than, to match, or be greater than s2
. A consequence of the ordering used by strcasecmp_P() is that if s1
is an initial substring of s2
, then s1
is considered to be "less than" s2
. Compare two strings ignoring case.
The strcasecmp_PF() function compares the two strings s1 and s2, ignoring the case of the characters.
This funtion is similar to strcasestr() except that s2
is pointer to a string in program space.
The strcat_P() function is similar to strcat() except that the src string must be located in program space (flash).
Concatenates two strings.
The strcat_PF() function is similar to strcat() except that the src string must be located in program space (flash) and is addressed using a far pointer
Locate character in program space string.
The strchr_P() function locates the first occurrence of val
(converted to a char) in the string pointed to by s
in program space. The terminating null character is considered to be part of the string.
The strchr_P() function is similar to strchr() except that s
is pointer to a string in program space.
NULL
if the character is not found. The strchrnul_P() function is like strchr_P() except that if c
is not found in s
, then it returns a pointer to the null byte at the end of s
, rather than NULL
. (Glibc, GNU extension.)
s
(i.e., s+strlen
(s)) if the character is not found. The strcmp_P() function is similar to strcmp() except that s2
is pointer to a string in program space.
s1
is found, respectively, to be less than, to match, or be greater than s2
. A consequence of the ordering used by strcmp_P() is that if s1
is an initial substring of s2
, then s1
is considered to be "less than" s2
. Compares two strings.
The strcmp_PF() function is similar to strcmp() except that s2 is a far 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.
Duplicate a string.
The strcpy_PF() function is similar to strcpy() except that src is a far pointer to a string in program space.
The strcspn_P() function calculates the length of the initial segment of s
which consists entirely of characters not in reject
. This function is similar to strcspn() except that reject
is a pointer to a string in program space.
s
which are not in the string reject
. The terminating zero is not considered as a part of string. 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)
).
Concatenate two strings.
The strlcat_PF() function is similar to strlcat(), except that the src string must be located in program space (flash) and is addressed using a far pointer.
Appends src to string dst of size n (unlike strncat(), n is the full size of dst, not space left). At most n-1 characters will be copied. Always NULL terminates (unless n <= 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 strlcpy_P() function is similar to strlcpy() except that the src
is pointer to a string in memory space.
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.
Obtain the length of a string.
The strlen_PF() function is similar to strlen(), except that s is a far 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
.
s1
(or the first n
bytes thereof) is found, respectively, to be less than, to match, or be greater than s2
. A consequence of the ordering used by strncasecmp_P() is that if s1
is an initial substring of s2
, then s1
is considered to be "less than" s2
. Compare two strings ignoring case.
The strncasecmp_PF() function is similar to strcasecmp_PF(), except it only compares the first n characters of s1 and the string in flash is addressed using a far pointer.
Concatenate two strings.
The strncat_P() function is similar to strncat(), except that the src string must be located in program space (flash).
Concatenate two strings.
The strncat_PF() function is similar to strncat(), except that the src string must be located in program space (flash) and is addressed using a far pointer.
The strncmp_P() function is similar to strcmp_P() except it only compares the first (at most) n characters of s1 and s2.
Compare two strings with limited length.
The strncmp_PF() function is similar to strcmp_PF() 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.
Duplicate a string until a limited length.
The strncpy_PF() function is similar to strcpy_PF() 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 dst will be padded with nulls.
Determine the length of a fixed-size string.
The strnlen_P() function is similar to strnlen(), except that src
is a pointer to a string in program space.
len
, or len
if there is no '0円' character among the first len
characters pointed to by src
. Determine the length of a fixed-size string.
The strnlen_PF() function is similar to strnlen(), except that s is a far pointer to a string in program space.
The strpbrk_P() function locates the first occurrence in the string s
of any of the characters in the flash string accept
. This function is similar to strpbrk() except that accept
is a pointer to a string in program space.
s
that matches one of the characters in accept
, or NULL
if no such character is found. The terminating zero is not considered as a part of string: if one or both args are empty, the result will NULL
. Locate character in string.
The strrchr_P() function returns a pointer to the last occurrence of the character val
in the flash string s
.
NULL
if the character is not found. Parse a string into tokens.
The strsep_P() function locates, in the string referenced by *sp
, the first occurrence of any character in the string delim
(or the terminating '0円' character) and replaces it with a '0円'. The location of the next character after the delimiter character (or NULL
, if the end of the string was reached) is stored in *sp
. An ``empty'' field, i.e. one caused by two adjacent delimiter characters, can be detected by comparing the location referenced by the pointer returned in *sp
to '0円'. This function is similar to strsep() except that delim
is a pointer to a string in program space.
*sp
. If *sp
is initially NULL
, strsep_P() returns NULL
. The strspn_P() function calculates the length of the initial segment of s
which consists entirely of characters in accept
. This function is similar to strspn() except that accept
is a pointer to a string in program space.
s
which consist only of characters from accept
. The terminating zero is not considered as a part of string. Locate a substring.
The strstr_P() function finds the first occurrence of the substring s2
in the string s1
. The terminating '0円' characters are not compared. The strstr_P() function is similar to strstr() except that s2
is pointer to a string in program space.
s2
points to a string of zero length, the function returns s1
. Locate a substring.
The strstr_PF() function finds the first occurrence of the substring s2
in the string s1
. The terminating '0円' characters are not compared. The strstr_PF() function is similar to strstr() except that s2
is a far pointer to a string in program space.
s2
points to a string of zero length, the function returns s1
. The contents of RAMPZ SFR are undefined when the function returns. Parses the string into tokens.
strtok_P() parses the string s
into tokens. The first call to strtok_P() should have s
as its first argument. Subsequent calls should have the first argument set to NULL. If a token ends with a delimiter, this delimiting character is overwritten with a '0円' and a pointer to the next character is saved for the next call to strtok_P(). The delimiter string delim
may be different for each call.
The strtok_P() function is similar to strtok() except that delim
is pointer to a string in program space.
Parses string into tokens.
The strtok_rP() function parses string
into tokens. The first call to strtok_rP() should have string as its first argument. Subsequent calls should have the first argument set to NULL. If a token ends with a delimiter, this delimiting character is overwritten with a '0円' and a pointer to the next character is saved for the next call to strtok_rP(). The delimiter string delim
may be different for each call. last
is a user allocated char* pointer. It must be the same while parsing the same string. strtok_rP() is a reentrant version of strtok_P().
The strtok_rP() function is similar to strtok_r() except that delim
is pointer to a string in program space.