Refactor getting bootloader size from lambda to function
This commit is contained in:
parent
355160dedb
commit
289e66160e
@ -332,6 +332,27 @@ void writeEepromByte(uint8_t *addr, uint8_t value)
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
static inline uint16_t getBootloaderSize()
|
||||||
|
{
|
||||||
|
const auto highFuse = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS);
|
||||||
|
constexpr auto BOOTSZ0 = 1;
|
||||||
|
constexpr auto BOOTSZ1 = 2;
|
||||||
|
|
||||||
|
if (highFuse & (1 << BOOTSZ1) && highFuse & (1 << BOOTSZ0))
|
||||||
|
return 256 * 2;
|
||||||
|
else if (highFuse & (1 << BOOTSZ1))
|
||||||
|
return 512 * 2;
|
||||||
|
else if (highFuse & (1 << BOOTSZ0))
|
||||||
|
return 1024 * 2;
|
||||||
|
return 2048 * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t getFlashSize()
|
||||||
|
{
|
||||||
|
const auto bootloaderSize = getBootloaderSize();
|
||||||
|
return (FLASHEND - bootloaderSize + 1);
|
||||||
|
}
|
||||||
|
|
||||||
static inline void performChipErase()
|
static inline void performChipErase()
|
||||||
{
|
{
|
||||||
constexpr auto getEepromEraseFuseBit = []() -> bool {
|
constexpr auto getEepromEraseFuseBit = []() -> bool {
|
||||||
@ -339,23 +360,8 @@ static inline void performChipErase()
|
|||||||
return boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS) & (1 << EESAVE);
|
return boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS) & (1 << EESAVE);
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr auto getBootloaderSize = []() -> uint16_t {
|
constexpr auto eraseFlash = []() {
|
||||||
const auto highFuse = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS);
|
const auto flashSize = getFlashSize();
|
||||||
constexpr auto BOOTSZ0 = 1;
|
|
||||||
constexpr auto BOOTSZ1 = 2;
|
|
||||||
|
|
||||||
if (highFuse & (1 << BOOTSZ1) && highFuse & (1 << BOOTSZ0))
|
|
||||||
return 256 * 2;
|
|
||||||
else if (highFuse & (1 << BOOTSZ1))
|
|
||||||
return 512 * 2;
|
|
||||||
else if (highFuse & (1 << BOOTSZ0))
|
|
||||||
return 1024 * 2;
|
|
||||||
return 2048 * 2;
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr auto eraseFlash = [getBootloaderSize]() {
|
|
||||||
const auto bootloaderSize = getBootloaderSize();
|
|
||||||
const auto flashSize = (FLASHEND - bootloaderSize + 1);
|
|
||||||
|
|
||||||
for (uint16_t i = 0; i < flashSize; i += SPM_PAGESIZE) {
|
for (uint16_t i = 0; i < flashSize; i += SPM_PAGESIZE) {
|
||||||
boot_page_erase(i);
|
boot_page_erase(i);
|
||||||
|
Loading…
Reference in New Issue
Block a user