diff options
author | Drashna Jaelre <drashna@live.com> | 2019-07-03 07:54:39 -0700 |
---|---|---|
committer | Drashna Jaelre <drashna@live.com> | 2019-07-03 07:54:49 -0700 |
commit | 110622eaa2787cc54818083d4243653b088e5b5a (patch) | |
tree | b1637e4dc8d8aa13e9face4998cf25ae620361e5 /Bootloaders/CDC/BootloaderAPI.c | |
parent | d0fd80affba97b37eb00c650e87cb5982a4f260e (diff) | |
parent | 5ba628d10b54d58d445896290ba9799bd76a73b3 (diff) | |
download | lufa-110622eaa2787cc54818083d4243653b088e5b5a.tar.gz lufa-110622eaa2787cc54818083d4243653b088e5b5a.tar.bz2 lufa-110622eaa2787cc54818083d4243653b088e5b5a.zip |
Merge remote-tracking branch 'abcminiuser/master'
Diffstat (limited to 'Bootloaders/CDC/BootloaderAPI.c')
-rw-r--r-- | Bootloaders/CDC/BootloaderAPI.c | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/Bootloaders/CDC/BootloaderAPI.c b/Bootloaders/CDC/BootloaderAPI.c index 2be156808..21d13bbe3 100644 --- a/Bootloaders/CDC/BootloaderAPI.c +++ b/Bootloaders/CDC/BootloaderAPI.c @@ -1,13 +1,13 @@ /* LUFA Library - Copyright (C) Dean Camera, 2017. + Copyright (C) Dean Camera, 2019. dean [at] fourwalledcubicle [dot] com www.lufa-lib.org */ /* - Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2019 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted @@ -35,18 +35,39 @@ #include "BootloaderAPI.h" +static bool IsPageAddressValid(const uint32_t Address) +{ + /* Determine if the given page address is correctly aligned to the + start of a flash page. */ + bool PageAddressIsAligned = !(Address & (SPM_PAGESIZE - 1)); + + return (Address < BOOT_START_ADDR) && PageAddressIsAligned; +} + void BootloaderAPI_ErasePage(const uint32_t Address) { - boot_page_erase_safe(Address); - boot_spm_busy_wait(); - boot_rww_enable(); + if (! IsPageAddressValid(Address)) + return; + + 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(); + if (! IsPageAddressValid(Address)) + return; + + 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 +92,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); + } } |