RTEMS CPU Kit with SuperCore
4.11.3
|
Bootloader Support Utilities. More...
Go to the source code of this file.
Macros | |
#define | BOOTLOADER_SECTION __attribute__ ((section (".bootloader"))) |
Used to declare a function or variable to be placed into a new section called .bootloader. More... | |
#define | __COMMON_ASB RWWSB |
#define | __COMMON_ASRE RWWSRE |
#define | BLB12 5 |
#define | BLB11 4 |
#define | BLB02 3 |
#define | BLB01 2 |
#define | boot_spm_interrupt_enable() (__SPM_REG |= (uint8_t)_BV(SPMIE)) |
Enable the SPM interrupt. More... | |
#define | boot_spm_interrupt_disable() (__SPM_REG &= (uint8_t)~_BV(SPMIE)) |
Disable the SPM interrupt. More... | |
#define | boot_is_spm_interrupt() (__SPM_REG & (uint8_t)_BV(SPMIE)) |
Check if the SPM interrupt is enabled. More... | |
#define | boot_rww_busy() (__SPM_REG & (uint8_t)_BV(__COMMON_ASB)) |
Check if the RWW section is busy. More... | |
#define | boot_spm_busy() (__SPM_REG & (uint8_t)_BV(__SPM_ENABLE)) |
Check if the SPM instruction is busy. More... | |
#define | boot_spm_busy_wait() do{}while(boot_spm_busy()) |
Wait while the SPM instruction is busy. More... | |
#define | __BOOT_PAGE_ERASE (_BV(__SPM_ENABLE) | _BV(PGERS)) |
#define | __BOOT_PAGE_WRITE (_BV(__SPM_ENABLE) | _BV(PGWRT)) |
#define | __BOOT_PAGE_FILL _BV(__SPM_ENABLE) |
#define | __BOOT_RWW_ENABLE (_BV(__SPM_ENABLE) | _BV(__COMMON_ASRE)) |
#define | __boot_page_fill_normal(address, data) |
#define | __boot_page_fill_alternate(address, data) |
#define | __boot_page_fill_extended(address, data) |
#define | __boot_page_erase_normal(address) |
#define | __boot_page_erase_alternate(address) |
#define | __boot_page_erase_extended(address) |
#define | __boot_page_write_normal(address) |
#define | __boot_page_write_alternate(address) |
#define | __boot_page_write_extended(address) |
#define | __boot_rww_enable() |
#define | __boot_rww_enable_alternate() |
#define | __boot_lock_bits_set(lock_bits) |
#define | __boot_lock_bits_set_alternate(lock_bits) |
#define | GET_LOW_FUSE_BITS (0x0000) |
address to read the low fuse bits, using boot_lock_fuse_bits_get | |
#define | GET_LOCK_BITS (0x0001) |
address to read the lock bits, using boot_lock_fuse_bits_get | |
#define | GET_EXTENDED_FUSE_BITS (0x0002) |
address to read the extended fuse bits, using boot_lock_fuse_bits_get | |
#define | GET_HIGH_FUSE_BITS (0x0003) |
address to read the high fuse bits, using boot_lock_fuse_bits_get | |
#define | boot_lock_fuse_bits_get(address) |
Read the lock or fuse bits at address . More... | |
#define | __BOOT_SIGROW_READ (_BV(__SPM_ENABLE) | _BV(SIGRD)) |
#define | boot_signature_byte_get(addr) |
Read the Signature Row byte at address . More... | |
#define | boot_page_fill(address, data) __boot_page_fill_normal(address, data) |
Fill the bootloader temporary page buffer for flash address with data word. More... | |
#define | boot_page_erase(address) __boot_page_erase_normal(address) |
Erase the flash page that contains address. More... | |
#define | boot_page_write(address) __boot_page_write_normal(address) |
Write the bootloader temporary page buffer to flash page that contains address. More... | |
#define | boot_rww_enable() __boot_rww_enable() |
Enable the Read-While-Write memory section. More... | |
#define | boot_lock_bits_set(lock_bits) __boot_lock_bits_set(lock_bits) |
Set the bootloader lock bits. More... | |
#define | boot_page_fill_safe(address, data) |
Same as boot_page_fill() except it waits for eeprom and spm operations to complete before filling the page. More... | |
#define | boot_page_erase_safe(address) |
Same as boot_page_erase() except it waits for eeprom and spm operations to complete before erasing the page. More... | |
#define | boot_page_write_safe(address) |
Same as boot_page_write() except it waits for eeprom and spm operations to complete before writing the page. More... | |
#define | boot_rww_enable_safe() |
Same as boot_rww_enable() except waits for eeprom and spm operations to complete before enabling the RWW mameory. More... | |
#define | boot_lock_bits_set_safe(lock_bits) |
Same as boot_lock_bits_set() except waits for eeprom and spm operations to complete before setting the lock bits. More... | |
Bootloader Support Utilities.
The macros in this module provide a C language interface to the bootloader support functionality of certain AVR processors. These macros are designed to work with all sizes of flash memory.
Global interrupts are not automatically disabled for these macros. It is left up to the programmer to do this. See the code example below. Also see the processor datasheet for caveats on having global interrupts enabled during writing of the Flash.
From email with Marek: On smaller devices (all except ATmega64/128), __SPM_REG is in the I/O space, accessible with the shorter "in" and "out" instructions - since the boot loader has a limited size, this could be an important optimization.
API Usage Example The following code shows typical usage of the boot API.
#include <inttypes.h> #include <avr/interrupt.h> #include <avr/pgmspace.h>
void boot_program_page (uint32_t page, uint8_t *buf) { uint16_t i; uint8_t sreg;
// Disable interrupts.
sreg = SREG; cli();
eeprom_busy_wait ();
boot_page_erase (page); boot_spm_busy_wait (); // Wait until the memory is erased.
for (i=0; i<SPM_PAGESIZE; i+=2) { // Set up little-endian word.
uint16_t w = *buf++; w += (*buf++) << 8;
boot_page_fill (page + i, w); }
boot_page_write (page); // Store buffer in flash page. boot_spm_busy_wait(); // Wait until the memory is written.
// Reenable RWW-section again. We need this if we want to jump back // to the application after bootloading.
boot_rww_enable ();
// Re-enable interrupts (if they were ever enabled).
SREG = sreg; }