mirror of
https://github.com/Optiboot/optiboot.git
synced 2025-08-19 09:02:05 +03:00
Add EIND setting for chips with more than 128k flash.
Untabify and fix some comment formatting.
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
| There are 5 convenient functions available here: |
|
| There are 5 convenient functions available here: |
|
||||||
| * optiboot_page_erase - to erase a FLASH page |
|
| * optiboot_page_erase - to erase a FLASH page |
|
||||||
| * optiboot_page_fill - to put words into temporary buffer |
|
| * optiboot_page_fill - to put words into temporary buffer |
|
||||||
| * optiboot_page_write - to write contents of temporary buffer into FLASH | |
|
| * optiboot_page_write - to write contents of temporary buffer into FLASH |
|
||||||
| * optiboot_readPage - higher level function to read a flash page and |
|
| * optiboot_readPage - higher level function to read a flash page and |
|
||||||
| store it in an array |
|
| store it in an array |
|
||||||
| * optiboot_writePage - higher level function to write content to |
|
| * optiboot_writePage - higher level function to write content to |
|
||||||
@@ -39,7 +39,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// 'typedef' (in following line) and 'const' (few lines below) are a way to define external function at some arbitrary address
|
// 'typedef' (in following line) and 'const' (few lines below)
|
||||||
|
// are a way to define external function at some arbitrary address
|
||||||
typedef void (*do_spm_t)(uint16_t address, uint8_t command, uint16_t data);
|
typedef void (*do_spm_t)(uint16_t address, uint8_t command, uint16_t data);
|
||||||
|
|
||||||
|
|
||||||
@@ -74,12 +75,21 @@ void do_spm_cli(optiboot_addr_t address, uint8_t command, uint16_t data) {
|
|||||||
|
|
||||||
sreg_save = SREG; // save old SREG value
|
sreg_save = SREG; // save old SREG value
|
||||||
asm volatile("cli"); // disable interrupts
|
asm volatile("cli"); // disable interrupts
|
||||||
#ifdef RAMPZ
|
#ifdef RAMPZ
|
||||||
RAMPZ = (address >> 16) & 0xff; // address bits 23-16 goes to RAMPZ
|
RAMPZ = (address >> 16) & 0xff; // address bits 23-16 goes to RAMPZ
|
||||||
do_spm((address & 0xffff), command, data); // do_spm accepts only lower 16 bits of address
|
#ifdef EIND
|
||||||
#else
|
uint8_t eind = EIND;
|
||||||
do_spm(address, command, data); // 16 bit address - no problems to pass directly
|
EIND = FLASHEND / 0x20000;
|
||||||
#endif
|
#endif
|
||||||
|
// do_spm accepts only lower 16 bits of address
|
||||||
|
do_spm((address & 0xffff), command, data);
|
||||||
|
#ifdef EIND
|
||||||
|
EIND = eind;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
// 16 bit address - no problems to pass directly
|
||||||
|
do_spm(address, command, data);
|
||||||
|
#endif
|
||||||
SREG = sreg_save; // restore last interrupts state
|
SREG = sreg_save; // restore last interrupts state
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +119,9 @@ void optiboot_page_write(optiboot_addr_t address) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Function to read a flash page and store it in an array (storage_array[])
|
// Function to read a flash page and store it in an array (storage_array[])
|
||||||
void optiboot_readPage(const uint8_t allocated_flash_space[], uint8_t storage_array[], uint16_t page, char blank_character)
|
void optiboot_readPage(const uint8_t allocated_flash_space[],
|
||||||
|
uint8_t storage_array[], uint16_t page,
|
||||||
|
char blank_character)
|
||||||
{
|
{
|
||||||
uint8_t read_character;
|
uint8_t read_character;
|
||||||
for(uint16_t j = 0; j < SPM_PAGESIZE; j++)
|
for(uint16_t j = 0; j < SPM_PAGESIZE; j++)
|
||||||
@@ -123,8 +135,10 @@ void optiboot_readPage(const uint8_t allocated_flash_space[], uint8_t storage_ar
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Function to read a flash page and store it in an array (storage_array[]), but without blank_character
|
// Function to read a flash page and store it in an array (storage_array[]),
|
||||||
void optiboot_readPage(const uint8_t allocated_flash_space[], uint8_t storage_array[], uint16_t page)
|
// but without blank_character
|
||||||
|
void optiboot_readPage(const uint8_t allocated_flash_space[],
|
||||||
|
uint8_t storage_array[], uint16_t page)
|
||||||
{
|
{
|
||||||
uint8_t read_character;
|
uint8_t read_character;
|
||||||
for(uint16_t j = 0; j < SPM_PAGESIZE; j++)
|
for(uint16_t j = 0; j < SPM_PAGESIZE; j++)
|
||||||
@@ -137,7 +151,8 @@ void optiboot_readPage(const uint8_t allocated_flash_space[], uint8_t storage_ar
|
|||||||
|
|
||||||
|
|
||||||
// Function to write data to a flash page
|
// Function to write data to a flash page
|
||||||
void optiboot_writePage(const uint8_t allocated_flash_space[], uint8_t data_to_store[], uint16_t page)
|
void optiboot_writePage(const uint8_t allocated_flash_space[],
|
||||||
|
uint8_t data_to_store[], uint16_t page)
|
||||||
{
|
{
|
||||||
uint16_t word_buffer = 0;
|
uint16_t word_buffer = 0;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user