.TH "avr_pgmspace" 3avr "Fri Nov 24 2023 23:59:10" "Version 2.0.0" "avr-libc" \" -*- nroff -*- .ad l .nh .SH NAME avr_pgmspace \- : Program Space Utilities .SH SYNOPSIS .br .PP .SS "Macros" .in +1c .ti -1c .RI "#define \fBPROGMEM\fP __ATTR_PROGMEM__" .br .ti -1c .RI "#define \fBPGM_P\fP const char *" .br .ti -1c .RI "#define \fBPGM_VOID_P\fP const void *" .br .ti -1c .RI "#define \fBPSTR\fP(s) ((const \fBPROGMEM\fP char *)(s))" .br .ti -1c .RI "#define \fBpgm_read_byte_near\fP(address_short) __LPM((\fBuint16_t\fP)(address_short))" .br .ti -1c .RI "#define \fBpgm_read_word_near\fP(address_short) __LPM_word((\fBuint16_t\fP)(address_short))" .br .ti -1c .RI "#define \fBpgm_read_dword_near\fP(address_short) __LPM_dword((\fBuint16_t\fP)(address_short))" .br .ti -1c .RI "#define \fBpgm_read_float_near\fP(address_short) __LPM_float((\fBuint16_t\fP)(address_short))" .br .ti -1c .RI "#define \fBpgm_read_ptr_near\fP(address_short) (void*)__LPM_word((\fBuint16_t\fP)(address_short))" .br .ti -1c .RI "#define \fBpgm_read_byte_far\fP(address_long) __ELPM((\fBuint32_t\fP)(address_long))" .br .ti -1c .RI "#define \fBpgm_read_word_far\fP(address_long) __ELPM_word((\fBuint32_t\fP)(address_long))" .br .ti -1c .RI "#define \fBpgm_read_dword_far\fP(address_long) __ELPM_dword((\fBuint32_t\fP)(address_long))" .br .ti -1c .RI "#define \fBpgm_read_float_far\fP(address_long) __ELPM_float((\fBuint32_t\fP)(address_long))" .br .ti -1c .RI "#define \fBpgm_read_ptr_far\fP(address_long) (void*)__ELPM_word((\fBuint32_t\fP)(address_long))" .br .ti -1c .RI "#define \fBpgm_read_byte\fP(address_short) \fBpgm_read_byte_near\fP(address_short)" .br .ti -1c .RI "#define \fBpgm_read_word\fP(address_short) \fBpgm_read_word_near\fP(address_short)" .br .ti -1c .RI "#define \fBpgm_read_dword\fP(address_short) \fBpgm_read_dword_near\fP(address_short)" .br .ti -1c .RI "#define \fBpgm_read_float\fP(address_short) \fBpgm_read_float_near\fP(address_short)" .br .ti -1c .RI "#define \fBpgm_read_ptr\fP(address_short) \fBpgm_read_ptr_near\fP(address_short)" .br .ti -1c .RI "#define \fBpgm_get_far_address\fP(var)" .br .in -1c .SH "Detailed Description" .PP .PP .nf #include #include .fi .PP .PP 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 \fCLPM\fP or \fCELPM\fP instructions\&. .PP \fBNote\fP .RS 4 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)\&. .PP If you are working with strings which are completely based in ram, use the standard string functions described in \fB: Strings\fP\&. .PP If possible, put your constant tables in the lower 64 KB and use \fBpgm_read_byte_near()\fP or \fBpgm_read_word_near()\fP instead of \fBpgm_read_byte_far()\fP or \fBpgm_read_word_far()\fP 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 \fC_P\fP \fIrequire\fP 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\&. \fIAll these functions will not work in that situation\&.\fP .PP For \fBXmega\fP devices, make sure the NVM controller command register (\fCNVM\&.CMD\fP or \fCNVM_CMD\fP) is set to 0x00 (NOP) before using any of these functions\&. .RE .PP .SH "Macro Definition Documentation" .PP .SS "#define pgm_get_far_address(var)" \fBValue:\fP.PP .nf ({ \\ uint_farptr_t tmp; \\ \\ __asm__ __volatile__( \\ \\ "ldi %A0, lo8(%1)" "\\n\\t" \\ "ldi %B0, hi8(%1)" "\\n\\t" \\ "ldi %C0, hh8(%1)" "\\n\\t" \\ "clr %D0" "\\n\\t" \\ : \\ "=d" (tmp) \\ : \\ "p" (&(var)) \\ ); \\ tmp; \\ }) .fi 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\&. .PP Comments: .PP .IP "\(bu" 2 The overhead is minimal and it's mainly due to the 32 bit size operation\&. .IP "\(bu" 2 24 bit sizes guarantees the code compatibility for use in future devices\&. .IP "\(bu" 2 hh8() is an undocumented feature but seems to give the third significant byte of a 32 bit data and accepts symbols, complementing the functionality of hi8() and lo8()\&. There is not an equivalent assembler function to get the high significant byte\&. .IP "\(bu" 2 'var' has to be resolved at linking time as an existing symbol, i\&.e, a simple type variable name, an array name (not an indexed element of the array, if the index is a constant the compiler does not complain but fails to get the address if optimization is enabled), a struct name or a struct field name, a function identifier, a linker defined identifier,\&.\&.\&. .IP "\(bu" 2 The returned value is the identifier's VMA (virtual memory address) determined by the linker and falls in the corresponding memory region\&. The AVR Harvard architecture requires non overlapping VMA areas for the multiple address spaces in the processor: Flash ROM, RAM, and EEPROM\&. Typical offset for this are 0x00000000, 0x00800xx0, and 0x00810000 respectively, derived from the linker script used and linker options\&. The value returned can be seen then as a universal pointer\&. .PP .SS "#define PGM_P const char *" Used to declare a variable that is a pointer to a string in program space\&. .SS "#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\&. .PP \fBNote\fP .RS 4 The address is a byte address\&. The address is in the program space\&. .RE .PP .SS "#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\&. .PP \fBNote\fP .RS 4 The address is a byte address\&. The address is in the program space\&. .RE .PP .SS "#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\&. .PP \fBNote\fP .RS 4 The address is a byte address\&. The address is in the program space\&. .RE .PP .SS "#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\&. .PP \fBNote\fP .RS 4 The address is a byte address\&. The address is in the program space\&. .RE .PP .SS "#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\&. .PP \fBNote\fP .RS 4 The address is a byte address\&. The address is in the program space\&. .RE .PP .SS "#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\&. .PP \fBNote\fP .RS 4 The address is a byte address\&. The address is in the program space\&. .RE .PP .SS "#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\&. .PP \fBNote\fP .RS 4 The address is a byte address\&. The address is in the program space\&. .RE .PP .SS "#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\&. .PP \fBNote\fP .RS 4 The address is a byte address\&. The address is in the program space\&. .RE .PP .SS "#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\&. .PP \fBNote\fP .RS 4 The address is a byte address\&. The address is in the program space\&. .RE .PP .SS "#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\&. .PP \fBNote\fP .RS 4 The address is a byte address\&. The address is in the program space\&. .RE .PP .SS "#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\&. .PP \fBNote\fP .RS 4 The address is a byte address\&. The address is in the program space\&. .RE .PP .SS "#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\&. .PP \fBNote\fP .RS 4 The address is a byte address\&. The address is in the program space\&. .RE .PP .SS "#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\&. .PP \fBNote\fP .RS 4 The address is a byte address\&. The address is in the program space\&. .RE .PP .SS "#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\&. .PP \fBNote\fP .RS 4 The address is a byte address\&. The address is in the program space\&. .RE .PP .SS "#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\&. .PP \fBNote\fP .RS 4 The address is a byte address\&. The address is in the program space\&. .RE .PP .SS "#define PGM_VOID_P const void *" Used to declare a generic pointer to an object in program space\&. .SS "#define PROGMEM __ATTR_PROGMEM__" Attribute to use in order to declare an object being located in flash ROM\&. .SS "#define PSTR(s) ((const \fBPROGMEM\fP char *)(s))" Used to declare a static pointer to a string in program space\&. .SH "Author" .PP Generated automatically by Doxygen for avr-libc from the source code\&.