Program Space String Utilities


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


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)
size_t strnlen_P (PGM_P, size_t) __ATTR_CONST__


Define Documentation

#define PGM_P   const prog_char *
 

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

#define pgm_read_byte address_short   )     pgm_read_byte_near(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((uint32_t)(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((uint16_t)(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   )     pgm_read_dword_near(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((uint32_t)(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((uint16_t)(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_word address_short   )     pgm_read_word_near(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((uint32_t)(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((uint16_t)(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 prog_void *
 

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

#define PSTR  )     ({static char __c[] PROGMEM = (s); &__c[0];})
 

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


Function Documentation

void * memcpy_P void *  dest,
PGM_VOID_P  src,
size_t  n
 

The memcpy_P() function is similar to memcpy(), except the src string resides in program space.

Returns:
The memcpy_P() function returns a pointer to dest.

int strcasecmp_P const char *  s1,
PGM_P  s2
 

Compare two strings ignoring case.

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

Parameters:
s1 A pointer to a string in the devices SRAM.
s2 A pointer to a string in the devices Flash.
Returns:
The strcasecmp_P() 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.

char * strcat_P char *  dest,
PGM_P  src
 

The strcat_P() function is similar to strcat() except that the src string must be located in program space (flash).

Returns:
The strcat() function returns a pointer to the resulting string dest.

int strcmp_P const char *  s1,
PGM_P  s2
 

The strcmp_P() function is similar to strcmp() except that s2 is pointer to a string in program space.

Returns:
The strcmp_P() 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.

char * strcpy_P char *  dest,
PGM_P  src
 

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

Returns:
The strcpy_P() function returns a pointer to the destination string dest.

size_t strlcat_P char *  dst,
PGM_P  ,
size_t  siz
 

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

Returns:
The strlcat_P() function returns strlen(src) + MIN(siz, strlen(initial dst)). If retval >= siz, truncation occurred.

size_t strlcpy_P char *  dst,
PGM_P  ,
size_t  siz
 

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_P() function returns strlen(src). If retval >= siz, truncation occurred.

size_t strlen_P PGM_P  src  ) 
 

The strlen_P() function is similar to strlen(), except that src is a pointer to a string in program space.

Returns:
The strlen() function returns the number of characters in src.

int strncasecmp_P const char *  s1,
PGM_P  s2,
size_t  n
 

Compare two strings ignoring case.

The strncasecmp_P() function is similar to strcasecmp_P(), except it only compares the first n characters of s1.

Parameters:
s1 A pointer to a string in the devices SRAM.
s2 A pointer to a string in the devices Flash.
n The maximum number of bytes to compare.
Returns:
The strcasecmp_P() 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.

char * strncat_P char *  dest,
PGM_P  src,
size_t  len
 

Concatenate two strings.

The strncat_P() function is similar to strncat(), except that the src string must be located in program space (flash).

Returns:
The strncat_P() function returns a pointer to the resulting string dest.

int strncmp_P const char *  s1,
PGM_P  s2,
size_t  n
 

The strncmp_P() function is similar to strcmp_P() except it only compares the first (at most) n characters of s1 and s2.

Returns:
The strncmp_P() 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.

char * strncpy_P char *  dest,
PGM_P  src,
size_t  n
 

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.

Returns:
The strncpy_P() function returns a pointer to the destination string dest.

size_t strnlen_P PGM_P  src,
size_t  len
 

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.

Returns:
The strnlen_P function returns strlen_P(src), if that is less than len, or len if there is no '\0' character among the first len characters pointed to by src.


Automatically generated by Doxygen 1.4.1 on 18 Oct 2005.