Skip to content

Commit e2ee8a4

Browse files
pilotakgeky
authored andcommitted
mbed 5.15 CRC update
1 parent a76802e commit e2ee8a4

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

LittleFileSystem2.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ namespace mbed {
2424

2525
extern "C" uint32_t lfs2_crc(uint32_t crc, const void *buffer, size_t size)
2626
{
27-
uint32_t initial_xor = crc;
28-
MbedCRC<POLY_32BIT_REV_ANSI, 32> ct(initial_xor, 0x0, true, false);
27+
uint32_t initial_xor = lfs2_rbit(crc);
28+
MbedCRC<POLY_32BIT_ANSI, 32, CrcMode::TABLE> ct(initial_xor, 0x0, true, true);
29+
2930
ct.compute((void *)buffer, size, &crc);
3031
return crc;
3132
}

littlefs/lfs2_util.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ extern "C"
5151
#ifdef __MBED__
5252
#include "mbed_debug.h"
5353
#include "mbed_assert.h"
54+
#include "cmsis_compiler.h"
5455
#else
5556
#define MBED_LFS2_ENABLE_INFO false
5657
#define MBED_LFS2_ENABLE_DEBUG true
@@ -211,6 +212,21 @@ static inline uint32_t lfs2_tole32(uint32_t a) {
211212
return lfs2_fromle32(a);
212213
}
213214

215+
// Reverse the bits in a
216+
static inline uint32_t lfs2_rbit(uint32_t a) {
217+
#if !defined(LFS2_NO_INTRINSICS) && MBED_LFS2_INTRINSICS && \
218+
defined(__MBED__)
219+
return __RBIT(a);
220+
#else
221+
a = ((a & 0xaaaaaaaa) >> 1) | ((a & 0x55555555) << 1);
222+
a = ((a & 0xcccccccc) >> 2) | ((a & 0x33333333) << 2);
223+
a = ((a & 0xf0f0f0f0) >> 4) | ((a & 0x0f0f0f0f) << 4);
224+
a = ((a & 0xff00ff00) >> 8) | ((a & 0x00ff00ff) << 8);
225+
a = (a >> 16) | (a << 16);
226+
return a;
227+
#endif
228+
}
229+
214230
// Convert between 32-bit big-endian and native order
215231
static inline uint32_t lfs2_frombe32(uint32_t a) {
216232
#if !defined(LFS2_NO_INTRINSICS) && MBED_LFS2_INTRINSICS && ( \

0 commit comments

Comments
 (0)