avr_pgmspace(3avr)
okay bestie, sit down, hydrate π β we're doing avr_pgmspace(3avr), which is the <avr/pgmspace.h> situation, aka how you talk to your chip's program space (flash memory) without, like, losing your whole mind. it's a lot of functions. it's giving "the compiler's rich inner life". but we're gonna get through it together π
β¨ NAME β¨
avr_pgmspace β <avr/pgmspace.h>: Program Space Utilities π«Ά
like. flash memory access, bestie. that's the whole vibe.
π SYNOPSIS π
π Macros π
so first up, the macros. every single one, no skipping, i see you π
PROGMEM_FARβ expands to__attribute__((__section__('.progmemx.data'))). it's the far-flung cousin.PROGMEMβ expands to__attribute__((__progmem__)).PSTR(str)PSTR_FAR(str)pgm_read_byte_near(__addr)pgm_read_word_near(__addr)pgm_read_dword_near(__addr)pgm_read_qword_near(__addr)pgm_read_float_near(addr)pgm_read_ptr_near(__addr)pgm_read_byte_far(__addr)pgm_read_word_far(__addr)pgm_read_dword_far(__addr)pgm_read_qword_far(__addr)pgm_read_ptr_far(__addr)pgm_read_byte(__addr)pgm_read_word(__addr)pgm_read_dword(__addr)pgm_read_qword(__addr)pgm_read_ptr(__addr)pgm_get_far_address(var)
π§ Functions π§
kay so here's the near/un-suffixed crew. they take a pointer to const whatever and hand you the value back. no cap, that's the whole job β¨
static char pgm_read_char (const char *__addr)
static unsigned char pgm_read_unsigned_char (const unsigned char *__addr)
static signed char pgm_read_signed_char (const signed char *__addr)
static uint8_t pgm_read_u8 (const uint8_t *__addr)
static int8_t pgm_read_i8 (const int8_t *__addr)
static short pgm_read_short (const short *__addr)
static unsigned short pgm_read_unsigned_short (const unsigned short *__addr)
static uint16_t pgm_read_u16 (const uint16_t *__addr)
static int16_t pgm_read_i16 (const int16_t *__addr)
static int pgm_read_int (const int *__addr)
static signed pgm_read_signed (const signed *__addr)
static unsigned pgm_read_unsigned (const unsigned *__addr)
static signed int pgm_read_signed_int (const signed int *__addr)
static unsigned int pgm_read_unsigned_int (const unsigned int *__addr)
static __int24 pgm_read_i24 (const __int24 *__addr)
static __uint24 pgm_read_u24 (const __uint24 *__addr)
static uint32_t pgm_read_u32 (const uint32_t *__addr)
static int32_t pgm_read_i32 (const int32_t *__addr)
static long pgm_read_long (const long *__addr)
static unsigned long pgm_read_unsigned_long (const unsigned long *__addr)
static long long pgm_read_long_long (const long long *__addr)
static unsigned long long pgm_read_unsigned_long_long (const unsigned long long *__addr)
static uint64_t pgm_read_u64 (const uint64_t *__addr)
static int64_t pgm_read_i64 (const int64_t *__addr)
static float pgm_read_float (const float *__addr)
static double pgm_read_double (const double *__addr)
static long double pgm_read_long_double (const long double *__addr)
and now the far versions π
β same energy, except the address comes in as a uint_farptr_t instead of a pointer. that's the whole difference, periodt.
static char pgm_read_char_far (uint_farptr_t __addr)
static unsigned char pgm_read_unsigned_char_far (uint_farptr_t __addr)
static signed char pgm_read_signed_char_far (uint_farptr_t __addr)
static uint8_t pgm_read_u8_far (uint_farptr_t __addr)
static int8_t pgm_read_i8_far (uint_farptr_t __addr)
static short pgm_read_short_far (uint_farptr_t __addr)
static unsigned short pgm_read_unsigned_short_far (uint_farptr_t __addr)
static uint16_t pgm_read_u16_far (uint_farptr_t __addr)
static int16_t pgm_read_i16_far (uint_farptr_t __addr)
static int pgm_read_int_far (uint_farptr_t __addr)
static unsigned pgm_read_unsigned_far (uint_farptr_t __addr)
static unsigned int pgm_read_unsigned_int_far (uint_farptr_t __addr)
static signed pgm_read_signed_far (uint_farptr_t __addr)
static signed int pgm_read_signed_int_far (uint_farptr_t __addr)
static long pgm_read_long_far (uint_farptr_t __addr)
static unsigned long pgm_read_unsigned_long_far (uint_farptr_t __addr)
static __int24 pgm_read_i24_far (uint_farptr_t __addr)
static __uint24 pgm_read_u24_far (uint_farptr_t __addr)
static uint32_t pgm_read_u32_far (uint_farptr_t __addr)
static int32_t pgm_read_i32_far (uint_farptr_t __addr)
static long long pgm_read_long_long_far (uint_farptr_t __addr)
static unsigned long long pgm_read_unsigned_long_long_far (uint_farptr_t __addr)
static uint64_t pgm_read_u64_far (uint_farptr_t __addr)
static int64_t pgm_read_i64_far (uint_farptr_t __addr)
static float pgm_read_float_far (uint_farptr_t __addr)
static double pgm_read_double_far (uint_farptr_t __addr)
static long double pgm_read_long_double_far (uint_farptr_t __addr)
then the string/memory besties. these ones are literally just <string.h> but the source lives in flash, which is the plot twist π¦
const void * memchr_P (const void *, int __val, size_t __len)
int memcmp_P (const void *, const void *, size_t)
void * memccpy_P (void *, const void *, int __val, size_t)
void * memcpy_P (void *, const void *, size_t)
void * memmem_P (const void *, size_t, const void *, size_t)
const void * memrchr_P (const void *, int __val, size_t __len)
char * strcat_P (char *, const char *)
const char * strchr_P (const char *, int __val)
const char * strchrnul_P (const char *, int __val)
int strcmp_P (const char *, const char *)
char * strcpy_P (char *, const char *)
int strcasecmp_P (const char *, const char *)
char * strcasestr_P (const char *, const char *)
size_t strcspn_P (const char *__s, const char *__reject)
size_t strlcat_P (char *, const char *, size_t)
size_t strlcpy_P (char *, const char *, size_t)
size_t strnlen_P (const char *, size_t)
int strncmp_P (const char *, const char *, size_t)
int strncasecmp_P (const char *, const char *, size_t)
char * strncat_P (char *, const char *, size_t)
char * strncpy_P (char *, const char *, size_t)
char * strpbrk_P (const char *__s, const char *__accept)
const char * strrchr_P (const char *, int __val)
char * strstr_P (const char *, const char *)
char * strtok_P (char *__s, const char *__delim)
char * strtok_rP (char *__s, const char *__delim, char **__last)
and now the _PF girlies π β same idea but the flash side is addressed with a uint_farptr_t, so they reach way out past 64 KB.
size_t strlen_PF (uint_farptr_t src)
size_t strnlen_PF (uint_farptr_t src, size_t len)
void * memcpy_PF (void *dest, uint_farptr_t src, size_t len)
char * strcpy_PF (char *dest, uint_farptr_t src)
char * strncpy_PF (char *dest, uint_farptr_t src, size_t len)
char * strcat_PF (char *dest, uint_farptr_t src)
size_t strlcat_PF (char *dst, uint_farptr_t src, size_t siz)
char * strncat_PF (char *dest, uint_farptr_t src, size_t len)
int strcmp_PF (const char *s1, uint_farptr_t s2)
int strncmp_PF (const char *s1, uint_farptr_t s2, size_t n)
int strcasecmp_PF (const char *s1, uint_farptr_t s2)
int strncasecmp_PF (const char *s1, uint_farptr_t s2, size_t n)
uint_farptr_t strchr_PF (uint_farptr_t, int __val)
char * strstr_PF (const char *s1, uint_farptr_t s2)
size_t strlcpy_PF (char *dst, uint_farptr_t src, size_t siz)
int memcmp_PF (const void *, uint_farptr_t, size_t)
and the last three, the little C++ moments β¨ (yes, C++ templates, we contain multitudes):
static size_t strlen_P (const char *s)
template<typename T> T pgm_read< T > (const T *addr)
template<typename T> T pgm_read_far< T > (uint_farptr_t addr)
π§ Detailed Description π§
first, the includes, verbatim, because of course:
#include <avr/io.h>
#include <avr/pgmspace.h>
okay so the whole point of the functions in this module: they give your program a way to reach the data stored in program space β that's the flash memory of the device πΎ. like, data that lives in flash, not RAM. iconic.
π¬ Note π¬
bestie, several things, listen up π£
- these functions are an attempt to give you some compatibility with the header files that ship with IAR C, so that porting applications between different compilers is easier π«Ά. but heads up β it is not 100% compatibility (GCC does not have full support for multiple address spaces yet). so like, it's giving compatible, but it's not giving fully compatible, iykyk.
- if you're working with strings that are completely based in RAM, then use the standard string functions instead β the ones described in
<string.h>: Strings. don't come for the_Pfunctions with your RAM strings, that's not their moment π. - if it's possible, put your constant tables in the lower 64 KB and use
pgm_read_byte_near()orpgm_read_word_near()instead ofpgm_read_byte_far()orpgm_read_word_far()β because it's more efficient that way β‘, and you can still use the upper 64K for executable code. win-win, slay. - all functions that are suffixed with a
_Prequire their arguments to be in the lower 64 KB of the flash ROM, since they do not useELPMinstructions. normally this is not a big concern, because 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. fr fr, read that again. - for Xmega devices, make sure the NVM controller command register (
NVM.CMDorNVM_CMD) is set to0x00(NOP) before using any of these functions π. set it first, then vibe.
and that's where page one of five leaves us, so don't go anywhere β the next part is literally right there π
π Macro Definition Documentation π
Okay so these are the macros π β the little preprocessor spells that live in avr/pgmspace.h and do the actual flash-reading for you. Let's go one by one, no skipping, bestie.
π« #define pgm_get_far_address( var)
This macro evaluates to a uint_farptr_t β a 32-bit "far" pointer (only 24 of those bits are actually used, the rest are just vibing) β and it points at data even beyond the 64 KiB limit that the 16-bit ordinary pointer can't reach. It's basically the & operator, but with some limitations. π
Example:
#include <avr/pgmspace.h>
// Section .progmemx.data is located after all the code sections.
PROGMEM_FAR
const int data[] = { 2, 3, 5, 7, 9, 11 };
int get_data (uint8_t idx)
{
uint_farptr_t pdata = pgm_get_far_address (data[0]);
return pgm_read_int_far (pdata + idx * sizeof(int));
}
Comments:
- The overhead is minimal, and it's mainly due to the 32-bit size operation.
- 24 bit sizes guarantees the code compatibility for use in future devices.
varhas to be resolved at link-time as an existing symbol β like a simple variable name, an array name, or an array or structure element provided the offset is known at compile-time β andvaris located in static storage, etc.
πΈ #define pgm_read_byte( __addr)
Value: pgm_read_byte_near(__addr)
Read a byte from the program space with a 16-bit (near) byte-address. π¦
πΈ #define pgm_read_byte_far( __addr)
Value: __ELPM (__addr)
Read a byte from the program space with a 32-bit (far) byte-address. π¦
πΈ #define pgm_read_byte_near( __addr)
Value: __LPM ((uint16_t)(__addr))
Read a byte from the program space with a 16-bit (near) byte-address. π¦
π #define pgm_read_dword( __addr)
Value: pgm_read_dword_near(__addr)
Read a double word from the program space with a 16-bit (near) byte-address. π
π #define pgm_read_dword_far( __addr)
Value: __ELPM_dword (__addr)
Read a double word from the program space with a 32-bit (far) byte-address. π
π #define pgm_read_dword_near( __addr)
Value: __LPM_dword ((uint16_t)(__addr))
Read a double word from the program space with a 16-bit (near) byte-address. π
π§ #define pgm_read_float_near( addr)
Value: pgm_read_float (addr)
Read a float from the program space with a 16-bit (near) byte-address. β¨
π #define pgm_read_ptr( __addr)
Value: pgm_read_ptr_near(__addr)
Read a pointer from the program space with a 16-bit (near) byte-address. π«Ά
π #define pgm_read_ptr_far( __addr)
Value: ((void*) __ELPM_word (__addr))
Read a pointer from the program space with a 32-bit (far) byte-address. π«Ά
π #define pgm_read_ptr_near( __addr)
Value: ((void*) __LPM_word ((uint16_t)(__addr)))
Read a pointer from the program space with a 16-bit (near) byte-address. π«Ά
π¦ #define pgm_read_qword( __addr)
Value: pgm_read_qword_near(__addr)
Read a quad-word from the program space with a 16-bit (near) byte-address. π
π¦ #define pgm_read_qword_far( __addr)
Value: __ELPM_qword (__addr)
Read a quad-word from the program space with a 32-bit (far) byte-address. π
π¦ #define pgm_read_qword_near( __addr)
Value: __LPM_qword ((uint16_t)(__addr))
Read a quad-word from the program space with a 16-bit (near) byte-address. π
π #define pgm_read_word( __addr)
Value: pgm_read_word_near(__addr)
Read a word from the program space with a 16-bit (near) byte-address. β
π #define pgm_read_word_far( __addr)
Value: __ELPM_word (__addr)
Read a word from the program space with a 32-bit (far) byte-address. β
π #define pgm_read_word_near( __addr)
Value: __LPM_word ((uint16_t)(__addr))
Read a word from the program space with a 16-bit (near) byte-address. β
π #define PROGMEM __attribute__((__progmem__))
This is the attribute you slap onto a declaration so the object gets placed in flash ROM. Iconic, essential, we stan. π
π #define PROGMEM_FAR __attribute__((__section__('.progmemx.data')))
The attribute you use to declare an object living in far flash ROM. It's similar to PROGMEM, except it drops the static storage object into section .progmemx.data. To actually access the object, the pgm_read_*_far and _PF functions declared in this header are your besties. And to get its address, see pgm_get_far_address(). π«Ά
It only makes sense to put read-only objects in this section, though the compiler does not diagnose when this is not the case. So likeβ¦ behavior is on you, bestie. π
π #define PSTR( str)
Value: ({ static const PROGMEM char c[] = (str); &c[0]; })
Used to declare a static pointer to a string in program space. π
π #define PSTR_FAR( str)
Value: ({ static const PROGMEM_FAR char c[] = (str); pgm_get_far_address(c[0]); })
Used to define a string literal in far program space, and to return its address of the uint_farptr_t type. π
π Function Documentation π
Now the actual functions, bestie. These are the ones you call. Let's get into it. π
π§ void * memccpy_P (void * dest, const void * src, int val, size_t len)
[extern]
This function is similar to memccpy() except that src is a pointer to a string in program space. β¨
π§ const void * memchr_P (const void * s, int val, size_t len) [extern]
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 very first byte that matches val β interpreted as an unsigned character β stops the whole operation. π
Returns
The memchr_P() function returns a pointer to the matching byte, or NULL if the character does not occur in the given memory area. π«Ά
π§ int memcmp_P (const void * s1, const void * s2, size_t len) [extern]
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. π
Returns
The memcmp_P() 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. π
π§ int memcmp_PF (const void * s1, uint_farptr_t s2, size_t len) [extern]
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's the equivalent of the memcmp_P() function, except that it's 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_P (void * dest, const void * src, size_t n) [extern]
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. π«Ά
πΈ void * memcpy_PF (void * dest, uint_farptr_t src, size_t n) [extern]
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. π¦
Parameters
- dest β A pointer to the destination buffer
- src β A far pointer to the origin of data in flash memory
- 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. π
π void * memmem_P (const void * s1, size_t len1, const void * s2, size_t len2) [extern]
The memmem_P() function is similar to memmem(), except that s2 is a pointer to a string in program space. β
π const void * memrchr_P (const void * src, int val, size_t len) [extern]
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.) π
Returns
The memrchr_P() function returns a pointer to the matching byte, or NULL if the character does not occur in the given memory area. π«Ά
π template<typename T> T pgm_read< T > (const T * addr)
Read an object of type T from program memory address addr and return it. π This template is only available when macro __pgm_read_template__ is defined.
π char pgm_read_char (const char * __addr) [inline], [static]
Read a char from the 16-bit (near) byte-address __addr. The address is in the lower 64 KiB of program memory. π
π char pgm_read_char_far (uint_farptr_t __addr) [inline], [static]
Read a char from the far byte-address __addr. The address is in the program memory. π
π double pgm_read_double (const double * __addr) [inline], [static]
Read a double from the 16-bit (near) byte-address __addr. The address is in the lower 64 KiB of program memory. πΈ
π double pgm_read_double_far (uint_farptr_t __addr) [inline], [static]
Read a double from the far byte-address __addr. The address is in the program memory. πΈ
π template<typename T> T pgm_read_far< T > (uint_farptr_t addr)
Read an object of type T from program memory address addr and return it. π This template is only available when macro __pgm_read_template__ is defined.
π float pgm_read_float (const float * __addr) [inline], [static]
Read a float from the 16-bit (near) byte-address __addr. The address is in the lower 64 KiB of program memory. π¦
π float pgm_read_float_far (uint_farptr_t __addr) [inline], [static]
Read a float from the far byte-address __addr. The address is in the program memory. π¦
π§ int16_t pgm_read_i16 (const int16_t * __addr) [inline], [static]
Read an int16_t from the 16-bit (near) byte-address __addr. The address is in the lower 64 KiB of program memory. β¨
π§ int16_t pgm_read_i16_far (uint_farptr_t __addr) [inline], [static]
Read an int16_t from the far byte-address __addr. The address is in the program memory. β¨
π __int24 pgm_read_i24 (const __int24 * __addr) [inline], [static]
Read an __int24 from the 16-bit (near) byte-address __addr. The address is in the lower 64 KiB of program memory. π
π __int24 pgm_read_i24_far (uint_farptr_t __addr) [inline], [static]
Read an __int24 from the far byte-address __addr. The address is in the program memory. π
π int32_t pgm_read_i32 (const int32_t * __addr) [inline], [static]
Read an int32_t from the 16-bit (near) byte-address __addr. The address is in the lower 64 KiB of program memory. π₯
π int32_t pgm_read_i32_far (uint_farptr_t __addr) [inline], [static]
Read an int32_t from the far byte-address __addr. The address is in the program memory. π₯
π int64_t pgm_read_i64 (const int64_t * __addr) [inline], [static]
Read an int64_t from the 16-bit (near) byte-address __addr. The address is in the lower 64 KiB of program memory. π
π int64_t pgm_read_i64_far (uint_farptr_t __addr) [inline], [static]
Read an int64_t from the far byte-address __addr. The address is in the program memory. π
π¦ int8_t pgm_read_i8 (const int8_t * __addr) [inline], [static]
Read an int8_t from the 16-bit (near) byte-address __addr. The address is in the lower 64 KiB of program memory. β
π¦ int8_t pgm_read_i8_far (uint_farptr_t __addr) [inline], [static]
Read an int8_t from the far byte-address __addr. The address is in the program memory. β
int pgm_read_int (const int * __addr)[inline],[static]β reads anintfrom the 16-bit (near) byte-address__addr. That address is chilling in the lower 64 KiB of program memory. πint pgm_read_int_far (uint_farptr_t __addr)[inline],[static]β reads anintfrom the far byte-address__addr. Address lives somewhere in program memory, no 64 KiB fence required. β¨long pgm_read_long (const long * __addr)[inline],[static]β reads alongfrom the 16-bit (near) byte-address__addr, down in the lower 64 KiB of program memory.long double pgm_read_long_double (const long double * __addr)[inline],[static]β reads along doublefrom the 16-bit (near) byte-address__addr, lower 64 KiB of program memory vibes only.long double pgm_read_long_double_far (uint_farptr_t __addr)[inline],[static]β reads along doublefrom the far byte-address__addr, out there in program memory. π¦long pgm_read_long_far (uint_farptr_t __addr)[inline],[static]β reads alongfrom the far byte-address__addrin program memory.long long pgm_read_long_long (const long long * __addr)[inline],[static]β reads along longfrom the 16-bit (near) byte-address__addr, lower 64 KiB of program memory.long long pgm_read_long_long_far (uint_farptr_t __addr)[inline],[static]β reads along longfrom the far byte-address__addrin program memory.short pgm_read_short (const short * __addr)[inline],[static]β reads ashortfrom the 16-bit (near) byte-address__addr, lower 64 KiB of program memory. πΈshort pgm_read_short_far (uint_farptr_t __addr)[inline],[static]β reads ashortfrom the far byte-address__addrin program memory.signed pgm_read_signed (const signed * __addr)[inline],[static]β reads asignedfrom the 16-bit (near) byte-address__addr, lower 64 KiB of program memory.signed char pgm_read_signed_char (const signed char * __addr)[inline],[static]β reads asigned charfrom the 16-bit (near) byte-address__addr, lower 64 KiB of program memory.signed char pgm_read_signed_char_far (uint_farptr_t __addr)[inline],[static]β reads asigned charfrom the far byte-address__addrin program memory.signed pgm_read_signed_far (uint_farptr_t __addr)[inline],[static]β reads asignedfrom the far byte-address__addrin program memory.signed int pgm_read_signed_int (const signed int * __addr)[inline],[static]β reads asigned intfrom the 16-bit (near) byte-address__addr, lower 64 KiB of program memory.signed int pgm_read_signed_int_far (uint_farptr_t __addr)[inline],[static]β reads asigned intfrom the far byte-address__addrin program memory. πuint16_t pgm_read_u16 (const uint16_t * __addr)[inline],[static]β reads anuint16_tfrom the 16-bit (near) byte-address__addr, lower 64 KiB of program memory.uint16_t pgm_read_u16_far (uint_farptr_t __addr)[inline],[static]β reads anuint16_tfrom the far byte-address__addrin program memory.__uint24 pgm_read_u24 (const __uint24 * __addr)[inline],[static]β reads an__uint24from the 16-bit (near) byte-address__addr, lower 64 KiB of program memory. π__uint24 pgm_read_u24_far (uint_farptr_t __addr)[inline],[static]β reads an__uint24from the far byte-address__addrin program memory.uint32_t pgm_read_u32 (const uint32_t * __addr)[inline],[static]β reads anuint32_tfrom the 16-bit (near) byte-address__addr, lower 64 KiB of program memory.uint32_t pgm_read_u32_far (uint_farptr_t __addr)[inline],[static]β reads anuint32_tfrom the far byte-address__addrin program memory.uint64_t pgm_read_u64 (const uint64_t * __addr)[inline],[static]β reads anuint64_tfrom the 16-bit (near) byte-address__addr, lower 64 KiB of program memory.uint64_t pgm_read_u64_far (uint_farptr_t __addr)[inline],[static]β reads anuint64_tfrom the far byte-address__addrin program memory. π₯uint8_t pgm_read_u8 (const uint8_t * __addr)[inline],[static]β reads anuint8_tfrom the 16-bit (near) byte-address__addr, lower 64 KiB of program memory.uint8_t pgm_read_u8_far (uint_farptr_t __addr)[inline],[static]β reads anuint8_tfrom the far byte-address__addrin program memory.unsigned pgm_read_unsigned (const unsigned * __addr)[inline],[static]β reads anunsignedfrom the 16-bit (near) byte-address__addr, lower 64 KiB of program memory. β¨unsigned char pgm_read_unsigned_char (const unsigned char * __addr)[inline],[static]β reads anunsigned charfrom the 16-bit (near) byte-address__addr, lower 64 KiB of program memory.unsigned char pgm_read_unsigned_char_far (uint_farptr_t __addr)[inline],[static]β reads anunsigned charfrom the far byte-address__addrin program memory.unsigned pgm_read_unsigned_far (uint_farptr_t __addr)[inline],[static]β reads anunsignedfrom the far byte-address__addrin program memory.unsigned int pgm_read_unsigned_int (const unsigned int * __addr)[inline],[static]β reads anunsigned intfrom the 16-bit (near) byte-address__addr, lower 64 KiB of program memory.unsigned int pgm_read_unsigned_int_far (uint_farptr_t __addr)[inline],[static]β reads anunsigned intfrom the far byte-address__addrin program memory. πunsigned long pgm_read_unsigned_long (const unsigned long * __addr)[inline],[static]β reads anunsigned longfrom the 16-bit (near) byte-address__addr, lower 64 KiB of program memory.unsigned long pgm_read_unsigned_long_far (uint_farptr_t __addr)[inline],[static]β reads anunsigned longfrom the far byte-address__addrin program memory.unsigned long long pgm_read_unsigned_long_long (const unsigned long long * __addr)[inline],[static]β reads anunsigned long longfrom the 16-bit (near) byte-address__addr, lower 64 KiB of program memory. πunsigned long long pgm_read_unsigned_long_long_far (uint_farptr_t __addr)[inline],[static]β reads anunsigned long longfrom the far byte-address__addrin program memory.unsigned short pgm_read_unsigned_short (const unsigned short * __addr)[inline],[static]β reads anunsigned shortfrom the 16-bit (near) byte-address__addr, lower 64 KiB of program memory.unsigned short pgm_read_unsigned_short_far (uint_farptr_t __addr)[inline],[static]β reads anunsigned shortfrom the far byte-address__addrin program memory.
Okay bestie, that was the whole pgm_read_* glow-up era. π Now we get into the string functions, and these ones actually have lore (parameters, returns, the works). Buckle up. π«Ά
int strcasecmp_P (const char * s1, const char * s2) [extern]
Compares two strings while ignoring case. The strcasecmp_P() function compares the two strings s1 and s2 and just does not care about the case of the characters. Periodt. π
Parameters
- s1 β a pointer to a string in the device's SRAM.
- s2 β a pointer to a string in the device's Flash.
Returns
The strcasecmp_P() function returns an integer that's less than, equal to, or greater than zero if s1 is found to be, respectively, less than, matching, or greater than s2. And a lil consequence of the ordering strcasecmp_P() uses: if s1 is an initial substring of s2, then s1 counts as "less than" s2. iykyk. β¨
int strcasecmp_PF (const char * s1, uint_farptr_t s2) [extern]
Compares two strings, ignoring case. The strcasecmp_PF() function compares the two strings s1 and s2 without peeking at the character case. π¦
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 to be, respectively, less than, matching, or greater than s2.
Heads up, bestie: the contents of the RAMPZ SFR are undefined when the function returns. Not "maybe fine", not "usually zero" β undefined. Don't build on it. π
char * strcasestr_P (const char * s1, const char * s2) [extern]
This function is similar to strcasestr(), except that s2 is a pointer to a string in program space. Main character energy, just in flash. π
char * strcat_P (char * dest, const char * src) [extern]
The strcat_P() function is similar to strcat(), except that the src string has to be located in program space (flash). π
Returns
The strcat() function returns a pointer to the resulting string dest.
char * strcat_PF (char * dst, uint_farptr_t src) [extern]
Concatenates two strings. The strcat_PF() function is similar to strcat(), except that the src string has to be located in program space (flash) and is addressed using a far pointer. Fancy. π
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.
And again: the contents of the RAMPZ SFR are undefined when the function returns. π
const char * strchr_P (const char * s, int val) [extern]
Locates a character in a 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 part of the string, so yes, that counts too.
The strchr_P() function is similar to strchr(), except that s is a pointer to a string in program space. π
Returns
The strchr_P() function returns a pointer to the matched character, or NULL if the character is not found.
uint_farptr_t strchr_PF (uint_farptr_t s, int val) [extern]
Locates a character in a far program-space string. The strchr_PF() function locates the first occurrence of val (converted to a char) in the string pointed to by s in far program space. The terminating null character is considered part of the string here too.
The strchr_PF() function is similar to strchr(), except that s is a far pointer to a string in program space, and that string is not required to be located in the lower 64 KiB block β unlike the situation with strchr_P(). So it gets to roam free. π¦
Returns
The strchr_PF() function returns a far pointer to the matched character, or 0 if the character is not found. (Note the 0, not NULL β that's what it says, bestie.)
const char * strchrnul_P (const char * s, int c) [extern]
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.) β¨
Returns
The strchrnul_P() function returns a pointer to the matched character, or a pointer to the null byte at the end of s (i.e., s+strlen(s)) if the character is not found.
int strcmp_P (const char * s1, const char * s2) [extern]
The strcmp_P() function is similar to strcmp(), except that s2 is a pointer to a string in program space. Classic strcmp, but make it flash. π
Returns: okay bestie, so strcmp_P() hands you back an int that's less than, equal to, or greater than zero depending on whether s1 is found to be less than, to match, or to be greater than s2 respectively. And a lil consequence of the ordering it uses: if s1 is an initial substring of s2, then s1 is considered to be "less than" s2. periodt. π
int strcmp_PF (const char * s1, uint_farptr_t s2) [extern]
Compares two strings. The strcmp_PF() function is similar to strcmp() except that s2 is a far pointer to a string in program space. π¦
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_P (char * dest, const char * src) [extern]
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. π
char * strcpy_PF (char * dst, uint_farptr_t src) [extern]
Duplicate a string. The strcpy_PF() function is similar to strcpy() except that src is a far pointer to a string in program space. π
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 function returns. π
size_t strcspn_P (const char * s, const char * reject) [extern]
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. π§
Returns: The strcspn_P() function returns the number of characters in the initial segment of s which are not in the string reject. The terminating zero is not considered as a part of string. πΈ
size_t strlcat_P (char * dst, const char * src, size_t siz) [extern]
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 strlcat_PF (char * dst, uint_farptr_t src, size_t n) [extern]
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)). π
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 function returns. π«Ά
size_t strlcpy_P (char * dst, const char * src, size_t siz) [extern]
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. π
Returns: The strlcpy_P() function returns strlen(src). If retval >= siz, truncation occurred. π
size_t strlcpy_PF (char * dst, uint_farptr_t src, size_t siz) [extern]
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_P (const char * src) [inline], [static]
The strlen_P() function is similar to strlen(), except that src is a pointer to a string in program space. πΈ
Returns: The strlen_P() function returns the number of characters in src. β¨
Note:strlen_P()is implemented as an inline function in theavr/pgmspace.hheader file, which will check if the length of the string is a constant and known at compile time. If it is not known at compile time, the macro will issue a call to__strlen_P()which will then calculate the length of the string as normal. π§
size_t strlen_PF (uint_farptr_t s) [extern]
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. β
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_P (const char * s1, const char * s2, size_t n) [extern]
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β 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 strncasecmp_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. 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. π
int strncasecmp_PF (const char * s1, uint_farptr_t s2, size_t n) [extern]
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. π
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_P (char * dest, const char * src, size_t len) [extern]
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. π
char * strncat_PF (char * dst, uint_farptr_t src, size_t n) [extern]
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. π¦
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_P (const char * s1, const char * s2, size_t n) [extern]
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. π
int strncmp_PF (const char * s1, uint_farptr_t s2, size_t n) [extern]
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. π
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_P (char * dest, const char * src, size_t n) [extern]
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. β¨
char * strncpy_PF (char * dst, uint_farptr_t src, size_t n) [extern]
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. π¦
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_P (const char * src, size_t len) [extern]
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. π
size_t strnlen_PF (uint_farptr_t s, size_t len) [extern]
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 (fr fr, that's the wording)
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 * strpbrk_P (const char * s, const char * accept) [extern] β¨
Okay so strpbrk_P() locates the first occurrence in the string s of any of the characters in the flash string accept. It's giving strpbrk() energy except accept is a pointer to a string in program space. π
Returns π«Ά
The strpbrk_P() function returns a pointer to the character in 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. No cap. π
const char * strrchr_P (const char * s, int val) [extern] π¦
Locate character in string, bestie. The strrchr_P() function returns a pointer to the last occurrence of the character val in the flash string s. It's the last one, not the first β main character energy but backwards. π
Returns β
The strrchr_P() function returns a pointer to the matched character or NULL if the character is not found.
char * strstr_P (const char * s1, const char * s2) [extern] π
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. Literally the same but with program-space spice. β¨
Returns π
The strstr_P() 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.
char * strstr_PF (const char * s1, uint_farptr_t s2) [extern] π
Locate a substring again, but make it far. 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. Far pointer, far vibes. πΈ
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, const char * delim) [extern] π
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. So dramatic, so tokenizing. π
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 seestrtok_rP().
char * strtok_rP (char * string, const char * delim, char ** last) [extern] π
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(). Reentrant queen behavior. π
The strtok_rP() function is similar to strtok_r() except that delim is pointer to a string in program space.
Returns πΈ
The strtok_rP() function returns a pointer to the next token or NULL when no more tokens are found.
Author π
Generated automatically by Doxygen for AVR-LibC from the source code.
That's the whole thing, bestie. Source: AVR-LibC, Version 2.2.1, page avr_pgmspace(3avr). Periodt. π β¨
π¦ where this page comes from
- ubuntu resolute: avr-libc 1:2.2.1-1build1 Β· BSD-3-Clause
- ubuntu stonking: avr-libc 1:2.2.1-1build1 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms