diff options
author | David Crocker <dcrocker@eschertech.com> | 2022-09-30 19:01:36 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2022-09-30 19:01:36 +0300 |
commit | 5b1d665c7ad05bc14cda6d6ef7eaa3c33e35c82c (patch) | |
tree | bb6b3787d50bb0e14aab78f727d9019477be9721 | |
parent | b70232c988f584c3520c8dcaccc13adde50989ea (diff) |
Simplified PanelDue flashing code to save flash space
-rw-r--r-- | src/Comms/PanelDueUpdater.cpp | 4 | ||||
-rw-r--r-- | src/bossa/BossaFlash.cpp | 29 | ||||
-rw-r--r-- | src/bossa/BossaFlash.h | 49 | ||||
-rw-r--r-- | src/bossa/Device.cpp | 9 | ||||
-rw-r--r-- | src/bossa/EefcFlash.cpp | 97 | ||||
-rw-r--r-- | src/bossa/EefcFlash.h | 16 | ||||
-rw-r--r-- | src/bossa/Flasher.cpp | 2 | ||||
-rw-r--r-- | src/bossa/SerialPort.h | 4 |
8 files changed, 90 insertions, 120 deletions
diff --git a/src/Comms/PanelDueUpdater.cpp b/src/Comms/PanelDueUpdater.cpp index bd381e6d..164bf130 100644 --- a/src/Comms/PanelDueUpdater.cpp +++ b/src/Comms/PanelDueUpdater.cpp @@ -24,8 +24,6 @@ public: SerialPort::StopBit stop = SerialPort::StopBitOne) noexcept override { return true; } void close() noexcept override {} - bool isUsb() noexcept override { return false; } - int read(uint8_t* data, int size) noexcept override; int write(const uint8_t* data, int size) noexcept override { return this->uart.write(data, size); } int get() noexcept override; @@ -33,8 +31,6 @@ public: bool timeout(int millisecs) noexcept override { _timeout = millisecs; return true; } void flush() noexcept override { this->uart.flush(); } - void setDTR(bool dtr) noexcept override {} - void setRTS(bool rts) noexcept override {} private: AsyncSerial& uart; diff --git a/src/bossa/BossaFlash.cpp b/src/bossa/BossaFlash.cpp index c1fbc0b0..f83d78a7 100644 --- a/src/bossa/BossaFlash.cpp +++ b/src/bossa/BossaFlash.cpp @@ -34,11 +34,11 @@ BossaFlash::BossaFlash(Samba& samba, uint32_t pages, uint32_t size, uint32_t planes, - uint32_t lockRegions, + uint32_t numLockRegions, uint32_t user, uint32_t stack) THROWS(GCodeException) : _samba(samba), _name(name), _addr(addr), _pages(pages), _size(size), - _planes(planes), _lockRegions(lockRegions), _user(user), _wordCopy(samba, user) + _planes(planes), _numLockRegions(numLockRegions), _user(user), _wordCopy(samba, user) { _wordCopy.setWords(size / sizeof(uint32_t)); @@ -51,44 +51,39 @@ BossaFlash::BossaFlash(Samba& samba, _pageBufferB = _pageBufferA + size; } -void -BossaFlash::setLockRegions(const Vector<bool, 16>& regions) THROWS(GCodeException) +void BossaFlash::setLockRegions(Bitmap<uint32_t>regions) THROWS(GCodeException) { - if (regions.Size() > _lockRegions) - throw FlashRegionError("Flash::setLockRegions: regions.Size() > _lockRegions"); - _regions.set(regions); } -void -BossaFlash::setSecurity() noexcept +#if ORIGINAL_BOSSA_CODE + +void BossaFlash::setSecurity() noexcept { _security.set(true); } -void -BossaFlash::setBor(bool enable) noexcept +void BossaFlash::setBor(bool enable) noexcept { if (canBor()) _bor.set(enable); } -void -BossaFlash::setBod(bool enable) noexcept +void BossaFlash::setBod(bool enable) noexcept { if (canBod()) _bod.set(enable); } -void -BossaFlash::setBootFlash(bool enable) noexcept +#endif + +void BossaFlash::setBootFlash(bool enable) noexcept { if (canBootFlash()) _bootFlash.set(enable); } -void -BossaFlash::loadBuffer(const uint8_t* data, uint16_t bufferSize) THROWS(GCodeException) +void BossaFlash::loadBuffer(const uint8_t* data, uint16_t bufferSize) THROWS(GCodeException) { _samba.write(_onBufferA ? _pageBufferA : _pageBufferB, data, bufferSize); } diff --git a/src/bossa/BossaFlash.h b/src/bossa/BossaFlash.h index 99b66a4e..b647bd93 100644 --- a/src/bossa/BossaFlash.h +++ b/src/bossa/BossaFlash.h @@ -69,53 +69,47 @@ public: uint32_t pages, // Number of pages uint32_t size, // Page size in bytes uint32_t planes, // Number of flash planes - uint32_t p_lockRegions, // Number of flash lock regions + uint32_t numLockRegions, // Number of flash lock regions uint32_t user, // Address in SRAM where the applet and buffers will be placed uint32_t stack) THROWS(GCodeException); // Address in SRAM where the applet stack will be placed virtual ~BossaFlash() {} - const char *_ecv_array name() noexcept { return _name; } + const char *_ecv_array name() const noexcept { return _name; } - virtual uint32_t address() noexcept { return _addr; } - virtual uint32_t pageSize() noexcept { return _size; } - virtual uint32_t numPages() noexcept { return _pages; } - virtual uint32_t numPlanes() noexcept { return _planes; } - virtual uint32_t totalSize() noexcept { return _size * _pages; } - virtual uint32_t lockRegions() noexcept { return _lockRegions; } + uint32_t address() const noexcept { return _addr; } + uint32_t pageSize() const noexcept { return _size; } + uint32_t numPages() const noexcept { return _pages; } + uint32_t numPlanes() const noexcept { return _planes; } + uint32_t totalSize() const noexcept { return _size * _pages; } + uint32_t getNumLockRegions() const noexcept { return _numLockRegions; } virtual void eraseAll(uint32_t offset) THROWS(GCodeException) = 0; virtual void eraseAuto(bool enable) noexcept = 0; - virtual Vector<bool, 16> getLockRegions() THROWS(GCodeException) = 0; - virtual void setLockRegions(const Vector<bool, 16>& regions) THROWS(GCodeException); + virtual Bitmap<uint32_t> getLockRegions() THROWS(GCodeException) = 0; + virtual void setLockRegions(Bitmap<uint32_t> regions) THROWS(GCodeException); #if ORIGINAL_BOSSA_CODE virtual bool getSecurity() = 0; -#endif - virtual void setSecurity() noexcept; - -#if ORIGINAL_BOSSA_CODE + void setSecurity() noexcept; virtual bool getBod() = 0; -#endif - virtual void setBod(bool enable) noexcept; - virtual bool canBod() noexcept = 0; - -#if ORIGINAL_BOSSA_CODE + void setBod(bool enable) noexcept; virtual bool getBor() = 0; + void setBor(bool enable) noexcept; + virtual bool canBor() const noexcept = 0; #endif - virtual void setBor(bool enable) noexcept; - virtual bool canBor() noexcept = 0; + virtual bool canBod() const noexcept = 0; virtual bool getBootFlash() THROWS(GCodeException) = 0; - virtual void setBootFlash(bool enable) noexcept; - virtual bool canBootFlash() noexcept = 0; + void setBootFlash(bool enable) noexcept; + virtual bool canBootFlash() const noexcept = 0; virtual void writeOptions() THROWS(GCodeException) = 0; virtual void writePage(uint32_t page) THROWS(GCodeException) = 0; virtual void readPage(uint32_t page, uint8_t* data) THROWS(GCodeException) = 0; - virtual void loadBuffer(const uint8_t* data, uint16_t size) THROWS(GCodeException); + void loadBuffer(const uint8_t* data, uint16_t size) THROWS(GCodeException); protected: Samba& _samba; @@ -124,15 +118,18 @@ protected: uint32_t _pages; uint32_t _size; uint32_t _planes; - uint32_t _lockRegions; + uint32_t _numLockRegions; uint32_t _user; WordCopyApplet _wordCopy; FlashOption<bool> _bootFlash; - FlashOption<Vector<bool, 16>> _regions; + FlashOption<Bitmap<uint32_t>> _regions; + +#if ORIGINAL_BOSSA_CODE FlashOption<bool> _bod; FlashOption<bool> _bor; FlashOption<bool> _security; +#endif bool _onBufferA; uint32_t _pageBufferA; diff --git a/src/bossa/Device.cpp b/src/bossa/Device.cpp index df7f9d5b..ab51285f 100644 --- a/src/bossa/Device.cpp +++ b/src/bossa/Device.cpp @@ -26,12 +26,12 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /////////////////////////////////////////////////////////////////////////////// + #include "Device.h" #include "EefcFlash.h" #if ORIGINAL_BOSSA_CODE -void -Device::readChipId(uint32_t& chipId, uint32_t& extChipId) +void Device::readChipId(uint32_t& chipId, uint32_t& extChipId) { if ((chipId = _samba.readWord(0x400e0740)) != 0) { @@ -44,8 +44,7 @@ Device::readChipId(uint32_t& chipId, uint32_t& extChipId) } #endif -void -Device::create() THROWS(GCodeException) +void Device::create() THROWS(GCodeException) { BossaFlash* flashPtr; #if ORIGINAL_BOSSA_CODE @@ -695,4 +694,4 @@ void Device::reset() noexcept } } - +// End diff --git a/src/bossa/EefcFlash.cpp b/src/bossa/EefcFlash.cpp index 153e38b7..65ba291b 100644 --- a/src/bossa/EefcFlash.cpp +++ b/src/bossa/EefcFlash.cpp @@ -63,19 +63,21 @@ EefcFlash::EefcFlash(Samba& samba, uint32_t pages, uint32_t size, uint32_t planes, - uint32_t lockRegions, + uint32_t numLockRegions, uint32_t user, uint32_t stack, uint32_t regs, bool canBrownout) THROWS(GCodeException) - : BossaFlash(samba, name, addr, pages, size, planes, lockRegions, user, stack), + : BossaFlash(samba, name, addr, pages, size, planes, numLockRegions, user, stack), _regs(regs), _canBrownout(canBrownout), _eraseAuto(true) { // SAM3 Errata (FWS must be 6) _samba.writeWord(EEFC0_FMR, 0x6 << 8); if (planes == 2) + { _samba.writeWord(EEFC1_FMR, 0x6 << 8); + } } EefcFlash::~EefcFlash() @@ -96,8 +98,7 @@ EefcFlash::eraseAll(uint32_t offset) THROWS(GCodeException) writeFCR1(EEFC_FCMD_EA, 0); } - // Erase all can take an exceptionally long time on some devices - // so wait on FSR for up to 30 seconds + // Erase all can take an exceptionally long time on some devices so wait on FSR for up to 30 seconds waitFSR(30); } // Else we must do it by pages @@ -124,47 +125,49 @@ EefcFlash::eraseAll(uint32_t offset) THROWS(GCodeException) } } -void -EefcFlash::eraseAuto(bool enable) noexcept +void EefcFlash::eraseAuto(bool enable) noexcept { _eraseAuto = enable; } -Vector<bool, 16> -EefcFlash::getLockRegions() THROWS(GCodeException) +Bitmap<uint32_t> EefcFlash::getLockRegions() THROWS(GCodeException) { - Vector<bool, 16> regions(_lockRegions, false); - uint32_t frr; - uint32_t bit; + Bitmap<uint32_t> regions; waitFSR(); - for (uint32_t region = 0; region < _lockRegions; region++) + for (uint32_t region = 0; region < _numLockRegions; region++) { - if (_planes == 2 && region >= _lockRegions / 2) + if (_planes == 2 && region >= _numLockRegions / 2) { - bit = region - _lockRegions / 2; + uint32_t bit = region - _numLockRegions / 2; writeFCR1(EEFC_FCMD_GLB, 0); waitFSR(); - frr = readFRR1(); + uint32_t frr = readFRR1(); while (bit >= 32) { frr = readFRR1(); bit -= 32; } - regions[region] = (frr & (1 << bit)) != 0; + if ((frr & (1 << bit)) != 0) + { + regions.SetBit(region); + } } else { - bit = region; + uint32_t bit = region; writeFCR0(EEFC_FCMD_GLB, 0); waitFSR(); - frr = readFRR0(); + uint32_t frr = readFRR0(); while (bit >= 32) { frr = readFRR0(); bit -= 32; } - regions[region] = (frr & (1 << bit)) != 0; + if ((frr & (1 << bit)) != 0) + { + regions.SetBit(region); + } } } @@ -206,8 +209,7 @@ EefcFlash::getBor() } #endif -bool -EefcFlash::getBootFlash() THROWS(GCodeException) +bool EefcFlash::getBootFlash() THROWS(GCodeException) { waitFSR(); writeFCR0(EEFC_FCMD_GGPB, 0); @@ -215,8 +217,7 @@ EefcFlash::getBootFlash() THROWS(GCodeException) return (readFRR0() & (1 << (_canBrownout ? 3 : 1))); } -void -EefcFlash::writeOptions() THROWS(GCodeException) +void EefcFlash::writeOptions() THROWS(GCodeException) { if (canBootFlash() && _bootFlash.isDirty() && _bootFlash.get() != getBootFlash()) { @@ -237,29 +238,23 @@ EefcFlash::writeOptions() THROWS(GCodeException) #endif if (_regions.isDirty()) { - uint32_t page; - Vector<bool, 16> current; - - if (_regions.get().Size() > _lockRegions) - throw FlashRegionError("EefcFlash::writeOptions: FlashRegionError"); + Bitmap<uint32_t> current = getLockRegions(); - current = getLockRegions(); - - for (uint32_t region = 0; region < _lockRegions; region++) + for (uint32_t region = 0; region < _numLockRegions; region++) { - if (_regions.get()[region] != current[region]) + if (_regions.get().IsBitSet(region) != current.IsBitSet(region)) { - if (_planes == 2 && region >= _lockRegions / 2) + if (_planes == 2 && region >= _numLockRegions / 2) { - page = (region - _lockRegions / 2) * _pages / _lockRegions; + const uint32_t page = (region - _numLockRegions / 2) * _pages / _numLockRegions; waitFSR(); - writeFCR1(_regions.get()[region] ? EEFC_FCMD_SLB : EEFC_FCMD_CLB, page); + writeFCR1(_regions.get().IsBitSet(region) ? EEFC_FCMD_SLB : EEFC_FCMD_CLB, page); } else { - page = region * _pages / _lockRegions; + const uint32_t page = region * _pages / _numLockRegions; waitFSR(); - writeFCR0(_regions.get()[region] ? EEFC_FCMD_SLB : EEFC_FCMD_CLB, page); + writeFCR0(_regions.get().IsBitSet(region) ? EEFC_FCMD_SLB : EEFC_FCMD_CLB, page); } } } @@ -273,8 +268,7 @@ EefcFlash::writeOptions() THROWS(GCodeException) #endif } -void -EefcFlash::writePage(uint32_t page) THROWS(GCodeException) +void EefcFlash::writePage(uint32_t page) THROWS(GCodeException) { if (page >= _pages) throw FlashPageError("EefcFlash::writePage: FlashPageError"); @@ -285,13 +279,16 @@ EefcFlash::writePage(uint32_t page) THROWS(GCodeException) waitFSR(); _wordCopy.runv(); if (_planes == 2 && page >= _pages / 2) + { writeFCR1(_eraseAuto ? EEFC_FCMD_EWP : EEFC_FCMD_WP, page - _pages / 2); + } else + { writeFCR0(_eraseAuto ? EEFC_FCMD_EWP : EEFC_FCMD_WP, page); + } } -void -EefcFlash::readPage(uint32_t page, uint8_t* data) THROWS(GCodeException) +void EefcFlash::readPage(uint32_t page, uint8_t* data) THROWS(GCodeException) { if (page >= _pages) throw FlashPageError("EefcFlash::readPage: FlashPageError"); @@ -306,16 +303,14 @@ EefcFlash::readPage(uint32_t page, uint8_t* data) THROWS(GCodeException) _samba.read(_onBufferA ? _pageBufferA : _pageBufferB, data, _size); } -void -EefcFlash::waitFSR(int seconds) THROWS(GCodeException) +void EefcFlash::waitFSR(int seconds) THROWS(GCodeException) { int tries = seconds * 1000; - uint32_t fsr0; uint32_t fsr1 = 0x1; while (tries-- > 0) { - fsr0 = _samba.readWord(EEFC0_FSR); + uint32_t fsr0 = _samba.readWord(EEFC0_FSR); if (fsr0 & 0x2) throw FlashCmdError("EefcFlash::waitFSR: FlashCmdError 1"); if (fsr0 & 0x4) @@ -337,26 +332,22 @@ EefcFlash::waitFSR(int seconds) THROWS(GCodeException) throw FlashTimeoutError("EefcFlash::waitFSR: FlashTimeoutError"); } -void -EefcFlash::writeFCR0(uint8_t cmd, uint32_t arg) THROWS(GCodeException) +void EefcFlash::writeFCR0(uint8_t cmd, uint32_t arg) THROWS(GCodeException) { _samba.writeWord(EEFC0_FCR, (EEFC_KEY << 24) | (arg << 8) | cmd); } -void -EefcFlash::writeFCR1(uint8_t cmd, uint32_t arg) THROWS(GCodeException) +void EefcFlash::writeFCR1(uint8_t cmd, uint32_t arg) THROWS(GCodeException) { _samba.writeWord(EEFC1_FCR, (EEFC_KEY << 24) | (arg << 8) | cmd); } -uint32_t -EefcFlash::readFRR0() THROWS(GCodeException) +uint32_t EefcFlash::readFRR0() THROWS(GCodeException) { return _samba.readWord(EEFC0_FRR); } -uint32_t -EefcFlash::readFRR1() THROWS(GCodeException) +uint32_t EefcFlash::readFRR1() THROWS(GCodeException) { return _samba.readWord(EEFC1_FRR); } diff --git a/src/bossa/EefcFlash.h b/src/bossa/EefcFlash.h index a92241e6..4c277b82 100644 --- a/src/bossa/EefcFlash.h +++ b/src/bossa/EefcFlash.h @@ -42,7 +42,7 @@ public: uint32_t pages, uint32_t size, uint32_t planes, - uint32_t lockRegions, + uint32_t numLockRegions, uint32_t user, uint32_t stack, uint32_t regs, @@ -52,22 +52,18 @@ public: void eraseAll(uint32_t offset) THROWS(GCodeException) override; void eraseAuto(bool enable) noexcept override; - Vector<bool, 16> getLockRegions() THROWS(GCodeException) override; + Bitmap<uint32_t> getLockRegions() THROWS(GCodeException) override; #if ORIGINAL_BOSSA_CODE bool getSecurity(); - - bool getBod(); -#endif - bool canBod() noexcept override { return _canBrownout; } - -#if ORIGINAL_BOSSA_CODE bool getBor(); + bool getBod(); + bool canBor() const noexcept override { return _canBrownout; } #endif - bool canBor() noexcept override { return _canBrownout; } + bool canBod() const noexcept override { return _canBrownout; } bool getBootFlash() THROWS(GCodeException) override; - bool canBootFlash() noexcept override { return true; } + bool canBootFlash() const noexcept override { return true; } void writeOptions() THROWS(GCodeException) override; diff --git a/src/bossa/Flasher.cpp b/src/bossa/Flasher.cpp index 4b611874..f0f6a44b 100644 --- a/src/bossa/Flasher.cpp +++ b/src/bossa/Flasher.cpp @@ -176,7 +176,7 @@ void Flasher::lock(/* string& regionArg, */ bool enable) THROWS(GCodeException) { _observer.onStatus("%s all regions\n", enable ? "Lock" : "Unlock"); #endif - Vector<bool, 16> regions(_flash->lockRegions(), enable); + Bitmap<uint32_t> regions = Bitmap<uint32_t>::MakeLowestNBits((enable) ? _flash->getNumLockRegions() : 0); _flash->setLockRegions(regions); #if ORIGINAL_BOSSA_CODE } diff --git a/src/bossa/SerialPort.h b/src/bossa/SerialPort.h index e4cc5236..f29cb925 100644 --- a/src/bossa/SerialPort.h +++ b/src/bossa/SerialPort.h @@ -57,8 +57,6 @@ public: StopBit stop = StopBitOne) noexcept = 0; virtual void close() noexcept = 0; - virtual bool isUsb() noexcept = 0; - virtual int read(uint8_t* data, int size) noexcept = 0; virtual int write(const uint8_t* data, int size) noexcept = 0; virtual int get() noexcept = 0; @@ -66,8 +64,6 @@ public: virtual bool timeout(int millisecs) noexcept = 0; virtual void flush() noexcept = 0; - virtual void setDTR(bool dtr) noexcept = 0; - virtual void setRTS(bool rts) noexcept = 0; }; #endif // _SERIALPORT_H |