aboutsummaryrefslogtreecommitdiffstats
path: root/Bootloaders/Printer
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2017-10-01 16:25:36 +1100
committerDean Camera <dean@fourwalledcubicle.com>2017-10-01 16:25:36 +1100
commit06f53eed83b4ad639698aeb9bcc1a3702e2ac7c4 (patch)
tree9fb860d93b67d36eed9de55bdd691581d5389960 /Bootloaders/Printer
parent544c4dc9e18d56768be11dd16e3cad693e7cff46 (diff)
downloadlufa-06f53eed83b4ad639698aeb9bcc1a3702e2ac7c4.tar.gz
lufa-06f53eed83b4ad639698aeb9bcc1a3702e2ac7c4.tar.bz2
lufa-06f53eed83b4ad639698aeb9bcc1a3702e2ac7c4.zip
Fixed bootloaders not disabling global interrupts during erase and write operations (thanks to Zoltan).
Diffstat (limited to 'Bootloaders/Printer')
-rw-r--r--Bootloaders/Printer/BootloaderAPI.c23
-rw-r--r--Bootloaders/Printer/BootloaderAPI.h1
-rw-r--r--Bootloaders/Printer/BootloaderPrinter.c10
-rw-r--r--Bootloaders/Printer/BootloaderPrinter.h1
4 files changed, 22 insertions, 13 deletions
diff --git a/Bootloaders/Printer/BootloaderAPI.c b/Bootloaders/Printer/BootloaderAPI.c
index 2be156808..5198ea7f0 100644
--- a/Bootloaders/Printer/BootloaderAPI.c
+++ b/Bootloaders/Printer/BootloaderAPI.c
@@ -37,16 +37,22 @@
void BootloaderAPI_ErasePage(const uint32_t Address)
{
- boot_page_erase_safe(Address);
- boot_spm_busy_wait();
- boot_rww_enable();
+ ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
+ {
+ boot_page_erase_safe(Address);
+ boot_spm_busy_wait();
+ boot_rww_enable();
+ }
}
void BootloaderAPI_WritePage(const uint32_t Address)
{
- boot_page_write_safe(Address);
- boot_spm_busy_wait();
- boot_rww_enable();
+ ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
+ {
+ boot_page_write_safe(Address);
+ boot_spm_busy_wait();
+ boot_rww_enable();
+ }
}
void BootloaderAPI_FillWord(const uint32_t Address, const uint16_t Word)
@@ -71,5 +77,8 @@ uint8_t BootloaderAPI_ReadLock(void)
void BootloaderAPI_WriteLock(const uint8_t LockBits)
{
- boot_lock_bits_set_safe(LockBits);
+ ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
+ {
+ boot_lock_bits_set_safe(LockBits);
+ }
}
diff --git a/Bootloaders/Printer/BootloaderAPI.h b/Bootloaders/Printer/BootloaderAPI.h
index c2d9b4a18..4cef6d678 100644
--- a/Bootloaders/Printer/BootloaderAPI.h
+++ b/Bootloaders/Printer/BootloaderAPI.h
@@ -39,6 +39,7 @@
/* Includes: */
#include <avr/io.h>
#include <avr/boot.h>
+ #include <util/atomic.h>
#include <stdbool.h>
#include <LUFA/Common/Common.h>
diff --git a/Bootloaders/Printer/BootloaderPrinter.c b/Bootloaders/Printer/BootloaderPrinter.c
index 9021f998f..90321d4a3 100644
--- a/Bootloaders/Printer/BootloaderPrinter.c
+++ b/Bootloaders/Printer/BootloaderPrinter.c
@@ -146,7 +146,7 @@ void Application_Jump_Check(void)
JTAG_ENABLE();
#else
/* Check if the device's BOOTRST fuse is set */
- if (boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS) & FUSE_BOOTRST)
+ if (BootloaderAPI_ReadFuse(GET_HIGH_FUSE_BITS) & FUSE_BOOTRST)
{
/* If the reset source was not an external reset or the key is correct, clear it and jump to the application */
if (!(MCUSR & (1 << EXTRF)) || (MagicBootKey == MAGIC_BOOT_KEY))
@@ -221,8 +221,7 @@ static void FlushPageIfRequired(void)
uint32_t NewPageStartAddress = (HEXParser.CurrAddress & ~(SPM_PAGESIZE - 1));
if (HEXParser.PageStartAddress != NewPageStartAddress)
{
- boot_page_write(HEXParser.PageStartAddress);
- boot_spm_busy_wait();
+ BootloaderAPI_WritePage(HEXParser.PageStartAddress);
HEXParser.PageStartAddress = NewPageStartAddress;
@@ -321,14 +320,13 @@ static void ParseIntelHEXByte(const char ReadCharacter)
/* If we are writing to a new page, we need to erase it first */
if (!(PageDirty))
{
- boot_page_erase(HEXParser.PageStartAddress);
- boot_spm_busy_wait();
+ BootloaderAPI_ErasePage(HEXParser.PageStartAddress);
PageDirty = true;
}
/* Fill the FLASH memory buffer with the new word of data */
- boot_page_fill(HEXParser.CurrAddress, NewDataWord);
+ BootloaderAPI_FillWord(HEXParser.CurrAddress, NewDataWord);
HEXParser.CurrAddress += 2;
/* Flush the FLASH page to physical memory if we are crossing a page boundary */
diff --git a/Bootloaders/Printer/BootloaderPrinter.h b/Bootloaders/Printer/BootloaderPrinter.h
index 8bc1a6879..7146a5934 100644
--- a/Bootloaders/Printer/BootloaderPrinter.h
+++ b/Bootloaders/Printer/BootloaderPrinter.h
@@ -43,6 +43,7 @@
#include <avr/interrupt.h>
#include "Descriptors.h"
+ #include "BootloaderAPI.h"
#include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Drivers/USB/USB.h>