26 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
27 |
POSSIBILITY OF SUCH DAMAGE. */ |
POSSIBILITY OF SUCH DAMAGE. */ |
28 |
|
|
29 |
|
#ifndef _AVR_BOOT_H_ |
30 |
|
#define _AVR_BOOT_H_ 1 |
31 |
|
|
32 |
/** \defgroup avr_boot Bootloader Support Utilities |
/** \defgroup avr_boot Bootloader Support Utilities |
33 |
\code |
\code |
34 |
#include <avr/io.h> |
#include <avr/io.h> |
39 |
bootloader support functionality of certain AVR processors. These |
bootloader support functionality of certain AVR processors. These |
40 |
macros are designed to work with all sizes of flash memory. |
macros are designed to work with all sizes of flash memory. |
41 |
|
|
42 |
\note Not all AVR processors provide bootloader support. See your processor |
\note Not all AVR processors provide bootloader support. See your |
43 |
datasheet to see if it provides bootloader support.*/ |
processor datasheet to see if it provides bootloader support. |
44 |
|
|
45 |
/* |
\todo From email with Marek: On smaller devices (all except ATmega64/128), |
46 |
TODO: |
__SPM_REG is in the I/O space, accessible with the shorter "in" and "out" |
47 |
From email with Marek: |
instructions - since the boot loader has a limited size, this could be an |
48 |
On smaller devices (all except ATmega64/128), __SPM_REG is in the I/O |
important optimization. |
|
space, accessible with the shorter "in" and "out" instructions - |
|
|
since the boot loader has a limited size, this could be an |
|
|
important optimization. |
|
|
*/ |
|
49 |
|
|
50 |
#ifndef _AVR_BOOT_H_ |
\par API Usage Example |
51 |
#define _AVR_BOOT_H_ 1 |
The following code shows typical usage of the boot API. |
52 |
|
|
53 |
|
\code |
54 |
|
#include <avr/interrupt.h> |
55 |
|
#include <avr/pgmspace.h> |
56 |
|
|
57 |
|
#define ADDRESS 0x1C000UL |
58 |
|
|
59 |
|
void boot_test(void) |
60 |
|
{ |
61 |
|
unsigned char buffer[8]; |
62 |
|
|
63 |
|
cli(); |
64 |
|
|
65 |
|
// Erase page. |
66 |
|
boot_page_erase((unsigned long)ADDRESS); |
67 |
|
while(boot_rww_busy()) |
68 |
|
{ |
69 |
|
boot_rww_enable(); |
70 |
|
} |
71 |
|
|
72 |
|
// Write data to buffer a word at a time. Note incrementing address |
73 |
|
// by 2. SPM_PAGESIZE is defined in the microprocessor IO header file. |
74 |
|
for(unsigned long i = ADDRESS; i < ADDRESS + SPM_PAGESIZE; i += 2) |
75 |
|
{ |
76 |
|
boot_page_fill(i, (i-ADDRESS) + ((i-ADDRESS+1) << 8)); |
77 |
|
} |
78 |
|
|
79 |
|
// Write page. |
80 |
|
boot_page_write((unsigned long)ADDRESS); |
81 |
|
while(boot_rww_busy()) |
82 |
|
{ |
83 |
|
boot_rww_enable(); |
84 |
|
} |
85 |
|
|
86 |
|
sei(); |
87 |
|
|
88 |
|
// Read back the values and display. |
89 |
|
// (The show() function is undefined and is used here as an example |
90 |
|
// only.) |
91 |
|
for(unsigned long i = ADDRESS; i < ADDRESS + 256; i++) |
92 |
|
{ |
93 |
|
show(utoa(pgm_read_byte(i), buffer, 16)); |
94 |
|
} |
95 |
|
|
96 |
|
return; |
97 |
|
}\endcode */ |
98 |
|
|
99 |
#include <avr/eeprom.h> |
#include <avr/eeprom.h> |
100 |
#include <avr/io.h> |
#include <avr/io.h> |
487 |
|
|
488 |
#endif |
#endif |
489 |
|
|
|
/** \ingroup avr_boot |
|
|
|
|
|
API Usage Example: |
|
|
|
|
|
\code |
|
|
#include <avr/interrupt.h> |
|
|
#include <avr/pgmspace.h> |
|
|
|
|
|
#define ADDRESS 0x1C000UL |
|
|
|
|
|
void boot_test(void) |
|
|
{ |
|
|
unsigned char buffer[8]; |
|
|
|
|
|
cli(); |
|
|
|
|
|
// Erase page. |
|
|
boot_page_erase((unsigned long)ADDRESS); |
|
|
while(boot_rww_busy()) |
|
|
{ |
|
|
boot_rww_enable(); |
|
|
} |
|
|
|
|
|
// Write data to buffer a word at a time. Note incrementing address by 2. |
|
|
// SPM_PAGESIZE is defined in the microprocessor IO header file. |
|
|
for(unsigned long i = ADDRESS; i < ADDRESS + SPM_PAGESIZE; i += 2) |
|
|
{ |
|
|
boot_page_fill(i, (i-ADDRESS) + ((i-ADDRESS+1) << 8)); |
|
|
} |
|
|
|
|
|
// Write page. |
|
|
boot_page_write((unsigned long)ADDRESS); |
|
|
while(boot_rww_busy()) |
|
|
{ |
|
|
boot_rww_enable(); |
|
|
} |
|
|
|
|
|
sei(); |
|
|
|
|
|
// Read back the values and display. |
|
|
// (The show() function is undefined and is used here as an example only.) |
|
|
for(unsigned long i = ADDRESS; i < ADDRESS + 256; i++) |
|
|
{ |
|
|
show(utoa(pgm_read_byte(i), buffer, 16)); |
|
|
} |
|
|
|
|
|
return; |
|
|
} |
|
|
\endcode */ |
|
|
|
|
490 |
#endif /* _AVR_BOOT_H_ */ |
#endif /* _AVR_BOOT_H_ */ |