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

github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Haster <geky@geky.net>2024-01-19 21:24:16 +0300
committerGitHub <noreply@github.com>2024-01-19 21:24:16 +0300
commit1195d606ae95be8544b23617cd8f4ee0a4f89738 (patch)
tree230d55ca235af3bdb3b34db490d4f7c311b4aa3b
parent1711bdef7682021a231f67105ccfa2746eb5bb14 (diff)
parent9a620c730c097a4ddccebca983e35625c1f4fb2e (diff)
Merge pull request #909 from littlefs-project/easy-util-defines
Add some easier util overrides: LFS_MALLOC/FREE/CRC
-rw-r--r--lfs_util.c3
-rw-r--r--lfs_util.h14
2 files changed, 15 insertions, 2 deletions
diff --git a/lfs_util.c b/lfs_util.c
index 9cdd1c6..dac72ab 100644
--- a/lfs_util.c
+++ b/lfs_util.c
@@ -11,6 +11,8 @@
#ifndef LFS_CONFIG
+// If user provides their own CRC impl we don't need this
+#ifndef LFS_CRC
// Software CRC implementation with small lookup table
uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size) {
static const uint32_t rtable[16] = {
@@ -29,6 +31,7 @@ uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size) {
return crc;
}
+#endif
#endif
diff --git a/lfs_util.h b/lfs_util.h
index 13e9396..45cefc9 100644
--- a/lfs_util.h
+++ b/lfs_util.h
@@ -212,12 +212,20 @@ static inline uint32_t lfs_tobe32(uint32_t a) {
}
// Calculate CRC-32 with polynomial = 0x04c11db7
+#ifdef LFS_CRC
+uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size) {
+ return LFS_CRC(crc, buffer, size)
+}
+#else
uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size);
+#endif
// Allocate memory, only used if buffers are not provided to littlefs
// Note, memory must be 64-bit aligned
static inline void *lfs_malloc(size_t size) {
-#ifndef LFS_NO_MALLOC
+#if defined(LFS_MALLOC)
+ return LFS_MALLOC(size);
+#elif !defined(LFS_NO_MALLOC)
return malloc(size);
#else
(void)size;
@@ -227,7 +235,9 @@ static inline void *lfs_malloc(size_t size) {
// Deallocate memory, only used if buffers are not provided to littlefs
static inline void lfs_free(void *p) {
-#ifndef LFS_NO_MALLOC
+#if defined(LFS_FREE)
+ LFS_FREE(p);
+#elif !defined(LFS_NO_MALLOC)
free(p);
#else
(void)p;