5
5
#ifdef FURI_NDEBUG
6
6
#define LFS_NO_ASSERT
7
7
#define LFS_ASSERT (x )
8
- #else
8
+ #else
9
9
#define LFS_ASSERT furi_assert
10
10
#endif
11
11
12
12
#define LFS_TAG "Lfs"
13
13
14
+ #ifdef FURI_LFS_DEBUG
14
15
#define LFS_TRACE (...) FURI_LOG_T(LFS_TAG, __VA_ARGS__);
15
16
16
17
#define LFS_DEBUG (...) FURI_LOG_D(LFS_TAG, __VA_ARGS__);
18
+ #else
19
+ #define LFS_TRACE (...)
20
+
21
+ #define LFS_DEBUG (...)
22
+ #endif // FURI_LFS_DEBUG
17
23
18
24
#define LFS_WARN (...) FURI_LOG_W(LFS_TAG, __VA_ARGS__);
19
25
20
26
#define LFS_ERROR (...) FURI_LOG_E(LFS_TAG, __VA_ARGS__);
21
27
22
-
23
28
// Because crc
24
29
#undef LFS_CONFIG
25
30
35
40
#ifndef LFS_NO_ASSERT
36
41
#include <assert.h>
37
42
#endif
38
- #if !defined(LFS_NO_DEBUG ) || \
39
- !defined(LFS_NO_WARN ) || \
40
- !defined(LFS_NO_ERROR ) || \
41
- defined(LFS_YES_TRACE )
43
+ #if !defined(LFS_NO_DEBUG ) || !defined(LFS_NO_WARN ) || !defined(LFS_NO_ERROR ) || \
44
+ defined(LFS_YES_TRACE )
42
45
#include <stdio.h>
43
46
#endif
44
47
45
48
#ifdef __cplusplus
46
- extern "C"
47
- {
49
+ extern "C" {
48
50
#endif
49
51
50
52
// Builtin functions, these may be replaced by more efficient
@@ -66,21 +68,29 @@ static inline uint32_t lfs_aligndown(uint32_t a, uint32_t alignment) {
66
68
}
67
69
68
70
static inline uint32_t lfs_alignup (uint32_t a , uint32_t alignment ) {
69
- return lfs_aligndown (a + alignment - 1 , alignment );
71
+ return lfs_aligndown (a + alignment - 1 , alignment );
70
72
}
71
73
72
74
// Find the smallest power of 2 greater than or equal to a
73
75
static inline uint32_t lfs_npw2 (uint32_t a ) {
74
76
#if !defined(LFS_NO_INTRINSICS ) && (defined(__GNUC__ ) || defined(__CC_ARM ))
75
- return 32 - __builtin_clz (a - 1 );
77
+ return 32 - __builtin_clz (a - 1 );
76
78
#else
77
79
uint32_t r = 0 ;
78
80
uint32_t s ;
79
81
a -= 1 ;
80
- s = (a > 0xffff ) << 4 ; a >>= s ; r |= s ;
81
- s = (a > 0xff ) << 3 ; a >>= s ; r |= s ;
82
- s = (a > 0xf ) << 2 ; a >>= s ; r |= s ;
83
- s = (a > 0x3 ) << 1 ; a >>= s ; r |= s ;
82
+ s = (a > 0xffff ) << 4 ;
83
+ a >>= s ;
84
+ r |= s ;
85
+ s = (a > 0xff ) << 3 ;
86
+ a >>= s ;
87
+ r |= s ;
88
+ s = (a > 0xf ) << 2 ;
89
+ a >>= s ;
90
+ r |= s ;
91
+ s = (a > 0x3 ) << 1 ;
92
+ a >>= s ;
93
+ r |= s ;
84
94
return (r | (a >> 1 )) + 1 ;
85
95
#endif
86
96
}
@@ -114,20 +124,23 @@ static inline int lfs_scmp(uint32_t a, uint32_t b) {
114
124
115
125
// Convert between 32-bit little-endian and native order
116
126
static inline uint32_t lfs_fromle32 (uint32_t a ) {
117
- #if !defined(LFS_NO_INTRINSICS ) && ( \
118
- (defined( BYTE_ORDER ) && defined( ORDER_LITTLE_ENDIAN ) && BYTE_ORDER == ORDER_LITTLE_ENDIAN ) || \
119
- (defined(__BYTE_ORDER ) && defined(__ORDER_LITTLE_ENDIAN ) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN ) || \
120
- (defined(__BYTE_ORDER__ ) && defined(__ORDER_LITTLE_ENDIAN__ ) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ))
127
+ #if !defined(LFS_NO_INTRINSICS ) && \
128
+ ((defined(BYTE_ORDER ) && defined(ORDER_LITTLE_ENDIAN ) && \
129
+ BYTE_ORDER == ORDER_LITTLE_ENDIAN ) || \
130
+ (defined(__BYTE_ORDER ) && defined(__ORDER_LITTLE_ENDIAN ) && \
131
+ __BYTE_ORDER == __ORDER_LITTLE_ENDIAN ) || \
132
+ (defined(__BYTE_ORDER__ ) && defined(__ORDER_LITTLE_ENDIAN__ ) && \
133
+ __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ))
121
134
return a ;
122
- #elif !defined(LFS_NO_INTRINSICS ) && ( \
123
- (defined( BYTE_ORDER ) && defined( ORDER_BIG_ENDIAN ) && BYTE_ORDER == ORDER_BIG_ENDIAN ) || \
124
- (defined(__BYTE_ORDER ) && defined(__ORDER_BIG_ENDIAN ) && __BYTE_ORDER == __ORDER_BIG_ENDIAN ) || \
125
- (defined(__BYTE_ORDER__ ) && defined(__ORDER_BIG_ENDIAN__ ) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ))
135
+ #elif !defined(LFS_NO_INTRINSICS ) && \
136
+ ((defined(BYTE_ORDER ) && defined(ORDER_BIG_ENDIAN ) && BYTE_ORDER == ORDER_BIG_ENDIAN ) || \
137
+ (defined(__BYTE_ORDER ) && defined(__ORDER_BIG_ENDIAN ) && \
138
+ __BYTE_ORDER == __ORDER_BIG_ENDIAN ) || \
139
+ (defined(__BYTE_ORDER__ ) && defined(__ORDER_BIG_ENDIAN__ ) && \
140
+ __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ))
126
141
return __builtin_bswap32 (a );
127
142
#else
128
- return (((uint8_t * )& a )[0 ] << 0 ) |
129
- (((uint8_t * )& a )[1 ] << 8 ) |
130
- (((uint8_t * )& a )[2 ] << 16 ) |
143
+ return (((uint8_t * )& a )[0 ] << 0 ) | (((uint8_t * )& a )[1 ] << 8 ) | (((uint8_t * )& a )[2 ] << 16 ) |
131
144
(((uint8_t * )& a )[3 ] << 24 );
132
145
#endif
133
146
}
@@ -138,21 +151,24 @@ static inline uint32_t lfs_tole32(uint32_t a) {
138
151
139
152
// Convert between 32-bit big-endian and native order
140
153
static inline uint32_t lfs_frombe32 (uint32_t a ) {
141
- #if !defined(LFS_NO_INTRINSICS ) && ( \
142
- (defined( BYTE_ORDER ) && defined( ORDER_LITTLE_ENDIAN ) && BYTE_ORDER == ORDER_LITTLE_ENDIAN ) || \
143
- (defined(__BYTE_ORDER ) && defined(__ORDER_LITTLE_ENDIAN ) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN ) || \
144
- (defined(__BYTE_ORDER__ ) && defined(__ORDER_LITTLE_ENDIAN__ ) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ))
154
+ #if !defined(LFS_NO_INTRINSICS ) && \
155
+ ((defined(BYTE_ORDER ) && defined(ORDER_LITTLE_ENDIAN ) && \
156
+ BYTE_ORDER == ORDER_LITTLE_ENDIAN ) || \
157
+ (defined(__BYTE_ORDER ) && defined(__ORDER_LITTLE_ENDIAN ) && \
158
+ __BYTE_ORDER == __ORDER_LITTLE_ENDIAN ) || \
159
+ (defined(__BYTE_ORDER__ ) && defined(__ORDER_LITTLE_ENDIAN__ ) && \
160
+ __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ))
145
161
return __builtin_bswap32 (a );
146
- #elif !defined(LFS_NO_INTRINSICS ) && ( \
147
- (defined( BYTE_ORDER ) && defined( ORDER_BIG_ENDIAN ) && BYTE_ORDER == ORDER_BIG_ENDIAN ) || \
148
- (defined(__BYTE_ORDER ) && defined(__ORDER_BIG_ENDIAN ) && __BYTE_ORDER == __ORDER_BIG_ENDIAN ) || \
149
- (defined(__BYTE_ORDER__ ) && defined(__ORDER_BIG_ENDIAN__ ) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ))
162
+ #elif !defined(LFS_NO_INTRINSICS ) && \
163
+ ((defined(BYTE_ORDER ) && defined(ORDER_BIG_ENDIAN ) && BYTE_ORDER == ORDER_BIG_ENDIAN ) || \
164
+ (defined(__BYTE_ORDER ) && defined(__ORDER_BIG_ENDIAN ) && \
165
+ __BYTE_ORDER == __ORDER_BIG_ENDIAN ) || \
166
+ (defined(__BYTE_ORDER__ ) && defined(__ORDER_BIG_ENDIAN__ ) && \
167
+ __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ))
150
168
return a ;
151
169
#else
152
- return (((uint8_t * )& a )[0 ] << 24 ) |
153
- (((uint8_t * )& a )[1 ] << 16 ) |
154
- (((uint8_t * )& a )[2 ] << 8 ) |
155
- (((uint8_t * )& a )[3 ] << 0 );
170
+ return (((uint8_t * )& a )[0 ] << 24 ) | (((uint8_t * )& a )[1 ] << 16 ) | (((uint8_t * )& a )[2 ] << 8 ) |
171
+ (((uint8_t * )& a )[3 ] << 0 );
156
172
#endif
157
173
}
158
174
@@ -161,11 +177,11 @@ static inline uint32_t lfs_tobe32(uint32_t a) {
161
177
}
162
178
163
179
// Calculate CRC-32 with polynomial = 0x04c11db7
164
- uint32_t lfs_crc (uint32_t crc , const void * buffer , size_t size );
180
+ uint32_t lfs_crc (uint32_t crc , const void * buffer , size_t size );
165
181
166
182
// Allocate memory, only used if buffers are not provided to littlefs
167
183
// Note, memory must be 64-bit aligned
168
- static inline void * lfs_malloc (size_t size ) {
184
+ static inline void * lfs_malloc (size_t size ) {
169
185
#ifndef LFS_NO_MALLOC
170
186
return malloc (size );
171
187
#else
@@ -175,15 +191,14 @@ static inline void *lfs_malloc(size_t size) {
175
191
}
176
192
177
193
// Deallocate memory, only used if buffers are not provided to littlefs
178
- static inline void lfs_free (void * p ) {
194
+ static inline void lfs_free (void * p ) {
179
195
#ifndef LFS_NO_MALLOC
180
196
free (p );
181
197
#else
182
198
(void )p ;
183
199
#endif
184
200
}
185
201
186
-
187
202
#ifdef __cplusplus
188
203
} /* extern "C" */
189
204
#endif
0 commit comments