Go to the documentation of this file.
32 #define _AVR_BOOT_H_ 1
104 #include <avr/eeprom.h>
111 # define __SPM_REG SPMCSR
112 #elif defined (SPMCR)
113 # define __SPM_REG SPMCR
115 # error AVR processor does not provide bootloader support!
121 # define __SPM_ENABLE SPMEN
122 #elif defined(SELFPRGEN)
123 # define __SPM_ENABLE SELFPRGEN
125 # error Cannot find SPM Enable bit definition!
136 #define BOOTLOADER_SECTION __attribute__ ((section (".bootloader")))
140 #define __COMMON_ASB ASB
142 #define __COMMON_ASB RWWSB
146 #define __COMMON_ASRE ASRE
148 #define __COMMON_ASRE RWWSRE
162 #define boot_spm_interrupt_enable() (__SPM_REG |= (uint8_t)_BV(SPMIE))
168 #define boot_spm_interrupt_disable() (__SPM_REG &= (uint8_t)~_BV(SPMIE))
174 #define boot_is_spm_interrupt() (__SPM_REG & (uint8_t)_BV(SPMIE))
180 #define boot_rww_busy() (__SPM_REG & (uint8_t)_BV(__COMMON_ASB))
186 #define boot_spm_busy() (__SPM_REG & (uint8_t)_BV(__SPM_ENABLE))
192 #define boot_spm_busy_wait() do{}while(boot_spm_busy())
194 #define __BOOT_PAGE_ERASE (_BV(__SPM_ENABLE) | _BV(PGERS))
195 #define __BOOT_PAGE_WRITE (_BV(__SPM_ENABLE) | _BV(PGWRT))
196 #define __BOOT_PAGE_FILL _BV(__SPM_ENABLE)
197 #define __BOOT_RWW_ENABLE (_BV(__SPM_ENABLE) | _BV(__COMMON_ASRE))
199 #define __BOOT_LOCK_BITS_SET (_BV(__SPM_ENABLE) | _BV(BLBSET))
201 #define __BOOT_LOCK_BITS_SET (_BV(__SPM_ENABLE) | _BV(RFLB))
204 #define __boot_page_fill_normal(address, data) \
206 __asm__ __volatile__ \
213 : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
214 "r" ((uint8_t)(__BOOT_PAGE_FILL)), \
215 "z" ((uint16_t)(address)), \
216 "r" ((uint16_t)(data)) \
221 #define __boot_page_fill_alternate(address, data)\
223 __asm__ __volatile__ \
232 : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
233 "r" ((uint8_t)(__BOOT_PAGE_FILL)), \
234 "z" ((uint16_t)(address)), \
235 "r" ((uint16_t)(data)) \
240 #define __boot_page_fill_extended(address, data) \
242 __asm__ __volatile__ \
245 "movw r30, %A3\n\t" \
251 : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
252 "i" (_SFR_MEM_ADDR(RAMPZ)), \
253 "r" ((uint8_t)(__BOOT_PAGE_FILL)), \
254 "r" ((uint32_t)(address)), \
255 "r" ((uint16_t)(data)) \
256 : "r0", "r30", "r31" \
260 #define __boot_page_erase_normal(address) \
262 __asm__ __volatile__ \
267 : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
268 "r" ((uint8_t)(__BOOT_PAGE_ERASE)), \
269 "z" ((uint16_t)(address)) \
273 #define __boot_page_erase_alternate(address) \
275 __asm__ __volatile__ \
282 : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
283 "r" ((uint8_t)(__BOOT_PAGE_ERASE)), \
284 "z" ((uint16_t)(address)) \
288 #define __boot_page_erase_extended(address) \
290 __asm__ __volatile__ \
292 "movw r30, %A3\n\t" \
297 : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
298 "i" (_SFR_MEM_ADDR(RAMPZ)), \
299 "r" ((uint8_t)(__BOOT_PAGE_ERASE)), \
300 "r" ((uint32_t)(address)) \
305 #define __boot_page_write_normal(address) \
307 __asm__ __volatile__ \
312 : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
313 "r" ((uint8_t)(__BOOT_PAGE_WRITE)), \
314 "z" ((uint16_t)(address)) \
318 #define __boot_page_write_alternate(address) \
320 __asm__ __volatile__ \
327 : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
328 "r" ((uint8_t)(__BOOT_PAGE_WRITE)), \
329 "z" ((uint16_t)(address)) \
333 #define __boot_page_write_extended(address) \
335 __asm__ __volatile__ \
337 "movw r30, %A3\n\t" \
342 : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
343 "i" (_SFR_MEM_ADDR(RAMPZ)), \
344 "r" ((uint8_t)(__BOOT_PAGE_WRITE)), \
345 "r" ((uint32_t)(address)) \
350 #define __boot_rww_enable() \
352 __asm__ __volatile__ \
357 : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
358 "r" ((uint8_t)(__BOOT_RWW_ENABLE)) \
362 #define __boot_rww_enable_alternate() \
364 __asm__ __volatile__ \
371 : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
372 "r" ((uint8_t)(__BOOT_RWW_ENABLE)) \
393 #define __boot_lock_bits_set(lock_bits) \
395 uint8_t value = (uint8_t)(~(lock_bits)); \
396 __asm__ __volatile__ \
404 : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
405 "r" ((uint8_t)(__BOOT_LOCK_BITS_SET)), \
407 : "r0", "r30", "r31" \
411 #define __boot_lock_bits_set_alternate(lock_bits) \
413 uint8_t value = (uint8_t)(~(lock_bits)); \
414 __asm__ __volatile__ \
424 : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
425 "r" ((uint8_t)(__BOOT_LOCK_BITS_SET)), \
427 : "r0", "r30", "r31" \
454 #define GET_LOW_FUSE_BITS (0x0000)
459 #define GET_LOCK_BITS (0x0001)
464 #define GET_EXTENDED_FUSE_BITS (0x0002)
469 #define GET_HIGH_FUSE_BITS (0x0003)
483 #define boot_lock_fuse_bits_get(address) \
486 __asm__ __volatile__ \
491 : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
492 "r" ((uint8_t)(__BOOT_LOCK_BITS_SET)), \
493 "z" ((uint16_t)(address)) \
509 #define __BOOT_SIGROW_READ (_BV(__SPM_ENABLE) | _BV(SIGRD))
511 #define boot_signature_byte_get(addr) \
514 __asm__ __volatile__ \
519 : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
520 "r" ((uint8_t)(__BOOT_SIGROW_READ)), \
521 "z" ((uint16_t)(addr)) \
587 #if defined(__AVR_ATmega161__) || defined(__AVR_ATmega163__) \
588 || defined(__AVR_ATmega323__)
591 #define boot_page_fill(address, data) __boot_page_fill_alternate(address, data)
592 #define boot_page_erase(address) __boot_page_erase_alternate(address)
593 #define boot_page_write(address) __boot_page_write_alternate(address)
594 #define boot_rww_enable() __boot_rww_enable_alternate()
595 #define boot_lock_bits_set(lock_bits) __boot_lock_bits_set_alternate(lock_bits)
597 #elif (FLASHEND > USHRT_MAX)
600 #define boot_page_fill(address, data) __boot_page_fill_extended(address, data)
601 #define boot_page_erase(address) __boot_page_erase_extended(address)
602 #define boot_page_write(address) __boot_page_write_extended(address)
603 #define boot_rww_enable() __boot_rww_enable()
604 #define boot_lock_bits_set(lock_bits) __boot_lock_bits_set(lock_bits)
609 #define boot_page_fill(address, data) __boot_page_fill_normal(address, data)
610 #define boot_page_erase(address) __boot_page_erase_normal(address)
611 #define boot_page_write(address) __boot_page_write_normal(address)
612 #define boot_rww_enable() __boot_rww_enable()
613 #define boot_lock_bits_set(lock_bits) __boot_lock_bits_set(lock_bits)
622 #define boot_page_fill_safe(address, data) \
624 boot_spm_busy_wait(); \
625 eeprom_busy_wait(); \
626 boot_page_fill(address, data); \
634 #define boot_page_erase_safe(address) \
636 boot_spm_busy_wait(); \
637 eeprom_busy_wait(); \
638 boot_page_erase (address); \
646 #define boot_page_write_safe(address) \
648 boot_spm_busy_wait(); \
649 eeprom_busy_wait(); \
650 boot_page_write (address); \
658 #define boot_rww_enable_safe() \
660 boot_spm_busy_wait(); \
661 eeprom_busy_wait(); \
670 #define boot_lock_bits_set_safe(lock_bits) \
672 boot_spm_busy_wait(); \
673 eeprom_busy_wait(); \
674 boot_lock_bits_set (lock_bits); \
Automatically generated by Doxygen 1.8.7 on Tue Jul 8 2014. Dash Docset conversion by Matt Kane