AVR-LibC
2.2.1
Standard C library for AVR-GCC
|
AVR-LibC Documentation |
![]() |
AVR-LibC Development Pages |
|||
Main Page |
User Manual |
Library Reference |
FAQ |
Example Projects |
File List |
Macros | |
#define | PROGMEM_FAR __attribute__((__section__(".progmemx.data"))) |
#define | PROGMEM __attribute__((__progmem__)) |
#define | PSTR(str) ({ static const PROGMEM char c[] = (str); &c[0]; }) |
#define | PSTR_FAR(str) ({ static const PROGMEM_FAR char c[] = (str); pgm_get_far_address(c[0]); }) |
#define | pgm_read_byte_near(__addr) __LPM ((uint16_t)(__addr)) |
#define | pgm_read_word_near(__addr) __LPM_word ((uint16_t)(__addr)) |
#define | pgm_read_dword_near(__addr) __LPM_dword ((uint16_t)(__addr)) |
#define | pgm_read_qword_near(__addr) __LPM_qword ((uint16_t)(__addr)) |
#define | pgm_read_float_near(addr) pgm_read_float (addr) |
#define | pgm_read_ptr_near(__addr) ((void*) __LPM_word ((uint16_t)(__addr))) |
#define | pgm_read_byte_far(__addr) __ELPM (__addr) |
#define | pgm_read_word_far(__addr) __ELPM_word (__addr) |
#define | pgm_read_dword_far(__addr) __ELPM_dword (__addr) |
#define | pgm_read_qword_far(__addr) __ELPM_qword (__addr) |
#define | pgm_read_ptr_far(__addr) ((void*) __ELPM_word (__addr)) |
#define | pgm_read_byte(__addr) pgm_read_byte_near(__addr) |
#define | pgm_read_word(__addr) pgm_read_word_near(__addr) |
#define | pgm_read_dword(__addr) pgm_read_dword_near(__addr) |
#define | pgm_read_qword(__addr) pgm_read_qword_near(__addr) |
#define | pgm_read_ptr(__addr) pgm_read_ptr_near(__addr) |
#define | pgm_get_far_address(var) |
The functions in this module provide interfaces for a program to access data stored in program space (flash memory) of the device.
_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.NVM.CMD
or NVM_CMD
) is set to 0x00 (NOP) before using any of these functions. #define pgm_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:
Comments:
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. #define pgm_read_byte | ( | __addr | ) | pgm_read_byte_near(__addr) |
Read a byte from the program space with a 16-bit (near) nyte-address.
#define pgm_read_byte_far | ( | __addr | ) | __ELPM (__addr) |
Read a byte from the program space with a 32-bit (far) byte-address.
#define pgm_read_byte_near | ( | __addr | ) | __LPM ((uint16_t)(__addr)) |
Read a byte from the program space with a 16-bit (near) byte-address.
#define pgm_read_dword | ( | __addr | ) | 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 | ) | __ELPM_dword (__addr) |
Read a double word from the program space with a 32-bit (far) byte-address.
#define pgm_read_dword_near | ( | __addr | ) | __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 | ) | pgm_read_float (addr) |
Read a float
from the program space with a 16-bit (near) byte-address.
#define pgm_read_ptr | ( | __addr | ) | 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 | ) | ((void*) __ELPM_word (__addr)) |
Read a pointer from the program space with a 32-bit (far) byte-address.
#define pgm_read_ptr_near | ( | __addr | ) | ((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 | ) | 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 | ) | __ELPM_qword (__addr) |
Read a quad-word from the program space with a 32-bit (far) byte-address.
#define pgm_read_qword_near | ( | __addr | ) | __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 | ) | 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 | ) | __ELPM_word (__addr) |
Read a word from the program space with a 32-bit (far) byte-address.
#define pgm_read_word_near | ( | __addr | ) | __LPM_word ((uint16_t)(__addr)) |
Read a word from the program space with a 16-bit (near) byte-address.
#define PROGMEM __attribute__((__progmem__)) |
Attribute to use in order to declare an object being located in flash ROM.
#define PROGMEM_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
. In order to access the object, the pgm_read_*_far
and _PF
functions declare in this header can be used. In order 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.
#define PSTR | ( | str | ) | ({ static const PROGMEM char c[] = (str); &c[0]; }) |
Used to declare a static pointer to a string in program space.
#define PSTR_FAR | ( | str | ) | ({ 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 type uint_farptr_t.