#definepgm_get_far_address(var)
This macro evaluates to a uint_farptr_t 32-bit 'far' pointer (only 24 bits used) to data even beyond the
64 KiB limit for the 16-bit ordinary pointer. It is similar to the '&' operator, 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.
• var has to be resolved at link-time as an existing symbol, i.e. a simple variable name, an array name,
or an array or structure element provided the offset is known at compile-time, and var is located in
static storage, etc.
#definepgm_read_byte(__addr)pgm_read_byte_near(__addr)
Read a byte from the program space with a 16-bit (near) nyte-address.
#definepgm_read_byte_far(__addr)__ELPM(__addr)
Read a byte from the program space with a 32-bit (far) byte-address.
#definepgm_read_byte_near(__addr)__LPM((uint16_t)(__addr))
Read a byte from the program space with a 16-bit (near) byte-address.
#definepgm_read_dword(__addr)pgm_read_dword_near(__addr)
Read a double word from the program space with a 16-bit (near) byte-address.
#definepgm_read_dword_far(__addr)__ELPM_dword(__addr)
Read a double word from the program space with a 32-bit (far) byte-address.
#definepgm_read_dword_near(__addr)__LPM_dword((uint16_t)(__addr))
Read a double word from the program space with a 16-bit (near) byte-address.
#definepgm_read_float_near(addr)pgm_read_float(addr)
Read a float from the program space with a 16-bit (near) byte-address.
#definepgm_read_ptr(__addr)pgm_read_ptr_near(__addr)
Read a pointer from the program space with a 16-bit (near) byte-address.
#definepgm_read_ptr_far(__addr)((void*)__ELPM_word(__addr))
Read a pointer from the program space with a 32-bit (far) byte-address.
#definepgm_read_ptr_near(__addr)((void*)__LPM_word((uint16_t)(__addr)))
Read a pointer from the program space with a 16-bit (near) byte-address.
#definepgm_read_qword(__addr)pgm_read_qword_near(__addr)
Read a quad-word from the program space with a 16-bit (near) byte-address.
#definepgm_read_qword_far(__addr)__ELPM_qword(__addr)
Read a quad-word from the program space with a 32-bit (far) byte-address.
#definepgm_read_qword_near(__addr)__LPM_qword((uint16_t)(__addr))
Read a quad-word from the program space with a 16-bit (near) byte-address.
#definepgm_read_word(__addr)pgm_read_word_near(__addr)
Read a word from the program space with a 16-bit (near) byte-address.
#definepgm_read_word_far(__addr)__ELPM_word(__addr)
Read a word from the program space with a 32-bit (far) byte-address.
#definepgm_read_word_near(__addr)__LPM_word((uint16_t)(__addr))
Read a word from the program space with a 16-bit (near) byte-address.
#definePROGMEM__attribute__((__progmem__))
Attribute to use in order to declare an object being located in flash ROM.
#definePROGMEM_FAR__attribute__((__section__('.progmemx.data')))
Attribute to use in order to declare an object being located in far flash ROM. This is similar to
PROGMEM, except that it puts the static storage object in section .progmemx.data.Inordertoaccesstheobject,thepgm_read_*_farand_PFfunctionsdeclareinthisheadercanbeused.Inordertogetitsaddress,seepgm_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.
#definePSTR(str)({staticconstPROGMEMcharc[]=(str);&c[0];})
Used to declare a static pointer to a string in program space.
#definePSTR_FAR(str)({staticconstPROGMEM_FARcharc[]=(str);pgm_get_far_address(c[0]);})
Used to define a string literal in far program space, and to return its address of type uint_farptr_t.