Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2019-12-02 02:11:44 +0300
committerDavid Crocker <dcrocker@eschertech.com>2019-12-02 02:11:44 +0300
commit600aabe66c5087af4642946d3ee0191167b2830c (patch)
treea6b9b1a5dc3b41d805e4a3a176e8a84be0345de4 /src/Storage/CRC32.cpp
parentfda7f573aaf3d70d4c3dced459bdc75909a54de4 (diff)
Ethernet and other fixes
Fixed data corruption during file uploads. We now use a separate task to read data from the GMAC. Bug fix for M574 S0 Bug fix for software reset data report wheh no module was spinning
Diffstat (limited to 'src/Storage/CRC32.cpp')
-rw-r--r--src/Storage/CRC32.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/Storage/CRC32.cpp b/src/Storage/CRC32.cpp
index 1d563def..a69df0fe 100644
--- a/src/Storage/CRC32.cpp
+++ b/src/Storage/CRC32.cpp
@@ -53,17 +53,39 @@ CRC32::CRC32()
Reset();
}
-inline void CRC32::Update(char c)
+void CRC32::Update(char c)
{
crc = (CRC_32_TAB[(crc ^ c) & 0xFF] ^ (crc >> 8));
}
-void CRC32::Update(const char *c, size_t len)
+void CRC32::Update(const char *s, size_t len)
{
- for (size_t i = 0; i < len; ++i)
+ // The speed of this function affects the speed of file uploads, so make it as fast as possible. Sadly the SAME70 doesn't do hardware CRC calculation.
+ // Work on a local copy of the crc to avoid storing it all the time
+ uint32_t locCrc = crc;
+ const char * const end = s + len;
+
+ // Process any bytes at the start until we reach a dword boundary
+ while ((reinterpret_cast<uint32_t>(s) & 3) != 0 && s != end)
+ {
+ locCrc = (CRC_32_TAB[(locCrc ^ *s++) & 0xFF] ^ (locCrc >> 8));
+ }
+
+ const char * const endAligned = s + ((end - s) & ~3);
+ while (s != endAligned)
+ {
+ uint32_t data = *reinterpret_cast<const uint32_t*>(s);
+ s += 4;
+ locCrc = (CRC_32_TAB[(locCrc ^ data) & 0xFF] ^ (locCrc >> 8));
+ locCrc = (CRC_32_TAB[(locCrc ^ (data >> 8)) & 0xFF] ^ (locCrc >> 8));
+ locCrc = (CRC_32_TAB[(locCrc ^ (data >> 16)) & 0xFF] ^ (locCrc >> 8));
+ locCrc = (CRC_32_TAB[(locCrc ^ (data >> 24)) & 0xFF] ^ (locCrc >> 8));
+ }
+ while (s != end)
{
- Update(c[i]);
+ locCrc = (CRC_32_TAB[(locCrc ^ *s++) & 0xFF] ^ (locCrc >> 8));
}
+ crc = locCrc;
}
void CRC32::Reset()