Detailed Description

#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.

Note:

These functions are an attempt to provide some compatibility with header files that come with IAR C, to make porting applications between different compilers easier. This is not 100% compatibility though (GCC does not have full support for multiple address spaces yet).

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.

For Xmega devices, make sure the NVM controller command register (NVM.CMD or NVM_CMD) is set to 0x00 (NOP) before using any of these functions.

Macro Definition Documentation

#define PGM_P const char *

Used to declare a variable that is a pointer to a string in program space.

#define pgm_read_byte(address_short) \fBpgm_read_byte_near\fP(address_short)

Read a byte from the program space with a 16-bit (near) address.

Note:

The address is a byte address. The address is in the program space.

#define pgm_read_byte_far(address_long) __ELPM((\fBuint32_t\fP)(address_long))

Read a byte from the program space with a 32-bit (far) address.

Note:

The address is a byte address. The address is in the program space.

#define pgm_read_byte_near(address_short) __LPM((\fBuint16_t\fP)(address_short))

Read a byte from the program space with a 16-bit (near) address.

Note:

The address is a byte address. The address is in the program space.

#define pgm_read_dword(address_short) \fBpgm_read_dword_near\fP(address_short)

Read a double word from the program space with a 16-bit (near) address.

Note:

The address is a byte address. The address is in the program space.

#define pgm_read_dword_far(address_long) __ELPM_dword((\fBuint32_t\fP)(address_long))

Read a double word from the program space with a 32-bit (far) address.

Note:

The address is a byte address. The address is in the program space.

#define pgm_read_dword_near(address_short) __LPM_dword((\fBuint16_t\fP)(address_short))

Read a double word from the program space with a 16-bit (near) address.

Note:

The address is a byte address. The address is in the program space.

#define pgm_read_float(address_short) \fBpgm_read_float_near\fP(address_short)

Read a float from the program space with a 16-bit (near) address.

Note:

The address is a byte address. The address is in the program space.

#define pgm_read_float_far(address_long) __ELPM_float((\fBuint32_t\fP)(address_long))

Read a float from the program space with a 32-bit (far) address.

Note:

The address is a byte address. The address is in the program space.

#define pgm_read_float_near(address_short) __LPM_float((\fBuint16_t\fP)(address_short))

Read a float from the program space with a 16-bit (near) address.

Note:

The address is a byte address. The address is in the program space.

#define pgm_read_ptr(address_short) \fBpgm_read_ptr_near\fP(address_short)

Read a pointer from the program space with a 16-bit (near) address.

Note:

The address is a byte address. The address is in the program space.

#define pgm_read_ptr_far(address_long) (void*)__ELPM_word((\fBuint32_t\fP)(address_long))

Read a pointer from the program space with a 32-bit (far) address.

Note:

The address is a byte address. The address is in the program space.

#define pgm_read_ptr_near(address_short) (void*)__LPM_word((\fBuint16_t\fP)(address_short))

Read a pointer from the program space with a 16-bit (near) address.

Note:

The address is a byte address. The address is in the program space.

#define pgm_read_word(address_short) \fBpgm_read_word_near\fP(address_short)

Read a word from the program space with a 16-bit (near) address.

Note:

The address is a byte address. The address is in the program space.

#define pgm_read_word_far(address_long) __ELPM_word((\fBuint32_t\fP)(address_long))

Read a word from the program space with a 32-bit (far) address.

Note:

The address is a byte address. The address is in the program space.

#define pgm_read_word_near(address_short) __LPM_word((\fBuint16_t\fP)(address_short))

Read a word from the program space with a 16-bit (near) address.

Note:

The address is a byte address. The address is in the program space.

#define PGM_VOID_P const void *

Used to declare a generic pointer to an object in program space.

#define PROGMEM __ATTR_PROGMEM__

Attribute to use in order to declare an object being located in flash ROM.

#define PSTR(s) ((const \fBPROGMEM\fP char *)(s))

Used to declare a static pointer to a string in program space.

Typedef Documentation

\fBprog_char\fP

Note:

DEPRECATED

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.

\fBprog_int16_t\fP

Note:

DEPRECATED

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.

\fBprog_int32_t\fP

Note:

DEPRECATED

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.

\fBprog_int64_t\fP

Note:

DEPRECATED

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.

Note:

This type is not available when the compiler option -mint8 is in effect.

\fBprog_int8_t\fP

Note:

DEPRECATED

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.

\fBprog_uchar\fP

Note:

DEPRECATED

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.

\fBprog_uint16_t\fP

Note:

DEPRECATED

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.

\fBprog_uint32_t\fP

Note:

DEPRECATED

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.

\fBprog_uint64_t\fP

Note:

DEPRECATED

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.

Note:

This type is not available when the compiler option -mint8 is in effect.

\fBprog_uint8_t\fP

Note:

DEPRECATED

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.

\fBprog_void\fP

Note:

DEPRECATED

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.

Function Documentation

int memcmp_PF (const void *s1, \fBuint_farptr_t\fPs2, size_tlen)

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.

Returns:

The memcmp_PF() function returns an integer less than, equal to, or greater than zero if the first len bytes of s1 is found, respectively, to be less than, to match, or be greater than the first len bytes of s2.

void * memcpy_PF (void *dest, \fBuint_farptr_t\fPsrc, size_tn)

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

\param dst A pointer to the destination buffer
\param src A far pointer to the origin of data in flash memory
\param n The number of bytes to be copied

Returns:

The memcpy_PF() function returns a pointer to dst. The contents of RAMPZ SFR are undefined when the function returns

int strcasecmp_PF (const char *s1, \fBuint_farptr_t\fPs2)

Compare two strings ignoring case. The strcasecmp_PF() function compares the two strings s1 and s2, ignoring the case of the characters

Parameters:

s1 A pointer to the first string in SRAM

s2 A far pointer to the second string in Flash

Returns:

The strcasecmp_PF() function returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2. The contents of RAMPZ SFR are undefined when the function returns

char * strcat_PF (char *dst, \fBuint_farptr_t\fPsrc)

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

Parameters:

dst A pointer to the destination string in SRAM

src A far pointer to the string to be appended in Flash

Returns:

The strcat_PF() function returns a pointer to the resulting string dst. The contents of RAMPZ SFR are undefined when the function returns

int strcmp_PF (const char *s1, \fBuint_farptr_t\fPs2)

Compares two strings. The strcmp_PF() function is similar to strcmp() except that s2 is a far pointer to a string in program space

Parameters:

s1 A pointer to the first string in SRAM

s2 A far pointer to the second string in Flash

Returns:

The strcmp_PF() function returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2. The contents of RAMPZ SFR are undefined when the function returns

char * strcpy_PF (char *dst, \fBuint_farptr_t\fPsrc)

Duplicate a string. The strcpy_PF() function is similar to strcpy() except that src is a far pointer to a string in program space

Parameters:

dst A pointer to the destination string in SRAM

src A far pointer to the source string in Flash

Returns:

The strcpy_PF() function returns a pointer to the destination string dst. The contents of RAMPZ SFR are undefined when the funcion returns

size_t strlcat_PF (char *dst, \fBuint_farptr_t\fPsrc, size_tn)

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))

Parameters:

dst A pointer to the destination string in SRAM

src A far pointer to the source string in Flash

n The total number of bytes allocated to the destination string

Returns:

The strlcat_PF() function returns strlen(src) + MIN(n, strlen(initial dst)). If retval >= n, truncation occurred. The contents of RAMPZ SFR are undefined when the funcion returns

size_t strlcpy_PF (char *dst, \fBuint_farptr_t\fPsrc, size_tsiz)

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).

Returns:

The strlcpy_PF() function returns strlen(src). If retval >= siz, truncation occurred. The contents of RAMPZ SFR are undefined when the function returns

size_t strlen_PF (\fBuint_farptr_t\fPs)

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

Parameters:

s A far pointer to the string in flash

Returns:

The strlen_PF() function returns the number of characters in s. The contents of RAMPZ SFR are undefined when the function returns

int strncasecmp_PF (const char *s1, \fBuint_farptr_t\fPs2, size_tn)

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

Parameters:

s1 A pointer to a string in SRAM

s2 A far pointer to a string in Flash

n The maximum number of bytes to compare

Returns:

The strncasecmp_PF() function returns an integer less than, equal to, or greater than zero if s1 (or the first n bytes thereof) is found, respectively, to be less than, to match, or be greater than s2. The contents of RAMPZ SFR are undefined when the function returns

char * strncat_PF (char *dst, \fBuint_farptr_t\fPsrc, size_tn)

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

Parameters:

dst A pointer to the destination string in SRAM

src A far pointer to the source string in Flash

n The maximum number of bytes to append

Returns:

The strncat_PF() function returns a pointer to the resulting string dst. The contents of RAMPZ SFR are undefined when the function returns

int strncmp_PF (const char *s1, \fBuint_farptr_t\fPs2, size_tn)

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

Parameters:

s1 A pointer to the first string in SRAM

s2 A far pointer to the second string in Flash

n The maximum number of bytes to compare

Returns:

The strncmp_PF() function returns an integer less than, equal to, or greater than zero if s1 (or the first n bytes thereof) is found, respectively, to be less than, to match, or be greater than s2. The contents of RAMPZ SFR are undefined when the function returns

char * strncpy_PF (char *dst, \fBuint_farptr_t\fPsrc, size_tn)

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

Parameters:

dst A pointer to the destination string in SRAM

src A far pointer to the source string in Flash

n The maximum number of bytes to copy

Returns:

The strncpy_PF() function returns a pointer to the destination string dst. The contents of RAMPZ SFR are undefined when the function returns

size_t strnlen_PF (\fBuint_farptr_t\fPs, size_tlen)

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

Parameters:

s A far pointer to the string in Flash

len The maximum number of length to return

Returns:

The strnlen_PF function returns strlen_P(s), if that is less than len, or len if there is no '\0' character among the first len characters pointed to by s. The contents of RAMPZ SFR are undefined when the function returns

char * strstr_PF (const char *s1, \fBuint_farptr_t\fPs2)

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.

Returns:

The strstr_PF() function returns a pointer to the beginning of the substring, or NULL if the substring is not found. If s2 points to a string of zero length, the function returns s1. The contents of RAMPZ SFR are undefined when the function returns

char* strtok_P (char *s, \fBPGM_P\fPdelim)

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.

Returns:

The strtok_P() function returns a pointer to the next token or NULL when no more tokens are found.

Note:

strtok_P() is NOT reentrant. For a reentrant version of this function see strtok_rP().

Author

Generated automatically by Doxygen for avr-libc from the source code.