|
|
@@ -9,6 +9,10 @@
|
|
|
#include <string.h>
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
+#ifdef __cplusplus
|
|
|
+extern "C"
|
|
|
+{
|
|
|
+#endif
|
|
|
// Macros, may be replaced by system specific wrappers. Arguments to these
|
|
|
// macros must not have side-effects as the macros can be removed for a smaller
|
|
|
// code footprint
|
|
|
@@ -16,30 +20,34 @@
|
|
|
// Logging functions
|
|
|
#ifdef LFS_YES_TRACE
|
|
|
#define LFS_TRACE(fmt, ...) \
|
|
|
- rt_kprintf("lfs_trace:%d: " fmt "\n", __LINE__, __VA_ARGS__)
|
|
|
+ rt_kprintf("%s:%d:trace: " fmt "%s\n", __FILE__, __LINE__, __VA_ARGS__)
|
|
|
+#define LFS_TRACE(...) LFS_TRACE_(__VA_ARGS__, "")
|
|
|
#else
|
|
|
-#define LFS_TRACE(fmt, ...)
|
|
|
+#define LFS_TRACE(...)
|
|
|
#endif
|
|
|
|
|
|
#ifndef LFS_NO_DEBUG
|
|
|
-#define LFS_DEBUG(fmt, ...) \
|
|
|
- rt_kprintf("lfs debug:%d: " fmt "\n", __LINE__, __VA_ARGS__)
|
|
|
+#define LFS_DEBUG_(fmt, ...) \
|
|
|
+ rt_kprintf("%s:%d:debug: " fmt "%s\n", __FILE__, __LINE__, __VA_ARGS__)
|
|
|
+#define LFS_DEBUG(...) LFS_DEBUG_(__VA_ARGS__, "")
|
|
|
#else
|
|
|
-#define LFS_DEBUG(fmt, ...)
|
|
|
+#define LFS_DEBUG(...)
|
|
|
#endif
|
|
|
|
|
|
#ifndef LFS_NO_WARN
|
|
|
-#define LFS_WARN(fmt, ...) \
|
|
|
- rt_kprintf("lfs warn:%d: " fmt "\n", __LINE__, __VA_ARGS__)
|
|
|
+#define LFS_WARN_(fmt, ...) \
|
|
|
+ rt_kprintf("%s:%d:warn: " fmt "%s\n", __FILE__, __LINE__, __VA_ARGS__)
|
|
|
+#define LFS_WARN(...) LFS_WARN_(__VA_ARGS__, "")
|
|
|
#else
|
|
|
-#define LFS_WARN(fmt, ...)
|
|
|
+#define LFS_WARN(...)
|
|
|
#endif
|
|
|
|
|
|
#ifndef LFS_NO_ERROR
|
|
|
-#define LFS_ERROR(fmt, ...) \
|
|
|
- rt_kprintf("lfs error:%d: " fmt "\n", __LINE__, __VA_ARGS__)
|
|
|
+#define LFS_ERROR_(fmt, ...) \
|
|
|
+ rt_kprintf("%s:%d:error: " fmt "%s\n", __FILE__, __LINE__, __VA_ARGS__)
|
|
|
+#define LFS_ERROR(...) LFS_ERROR_(__VA_ARGS__, "")
|
|
|
#else
|
|
|
-#define LFS_ERROR(fmt, ...)
|
|
|
+#define LFS_ERROR(...)
|
|
|
#endif
|
|
|
|
|
|
// Runtime assertions
|
|
|
@@ -72,7 +80,7 @@ static inline uint32_t lfs_alignup(uint32_t a, uint32_t alignment) {
|
|
|
return lfs_aligndown(a + alignment-1, alignment);
|
|
|
}
|
|
|
|
|
|
-// Find the next smallest power of 2 less than or equal to a
|
|
|
+// Find the smallest power of 2 greater than or equal to a
|
|
|
static inline uint32_t lfs_npw2(uint32_t a) {
|
|
|
#if !defined(LFS_NO_INTRINSICS) && (defined(__GNUC__) || defined(__CC_ARM))
|
|
|
return 32 - __builtin_clz(a-1);
|
|
|
@@ -118,14 +126,14 @@ static inline int lfs_scmp(uint32_t a, uint32_t b) {
|
|
|
// Convert between 32-bit little-endian and native order
|
|
|
static inline uint32_t lfs_fromle32(uint32_t a) {
|
|
|
#if !defined(LFS_NO_INTRINSICS) && ( \
|
|
|
- (defined( BYTE_ORDER ) && BYTE_ORDER == ORDER_LITTLE_ENDIAN ) || \
|
|
|
- (defined(__BYTE_ORDER ) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN ) || \
|
|
|
- (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
|
|
|
+ (defined( BYTE_ORDER ) && defined( ORDER_LITTLE_ENDIAN ) && BYTE_ORDER == ORDER_LITTLE_ENDIAN ) || \
|
|
|
+ (defined(__BYTE_ORDER ) && defined(__ORDER_LITTLE_ENDIAN ) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN ) || \
|
|
|
+ (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
|
|
|
return a;
|
|
|
#elif !defined(LFS_NO_INTRINSICS) && ( \
|
|
|
- (defined( BYTE_ORDER ) && BYTE_ORDER == ORDER_BIG_ENDIAN ) || \
|
|
|
- (defined(__BYTE_ORDER ) && __BYTE_ORDER == __ORDER_BIG_ENDIAN ) || \
|
|
|
- (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
|
|
|
+ (defined( BYTE_ORDER ) && defined( ORDER_BIG_ENDIAN ) && BYTE_ORDER == ORDER_BIG_ENDIAN ) || \
|
|
|
+ (defined(__BYTE_ORDER ) && defined(__ORDER_BIG_ENDIAN ) && __BYTE_ORDER == __ORDER_BIG_ENDIAN ) || \
|
|
|
+ (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
|
|
|
return __builtin_bswap32(a);
|
|
|
#else
|
|
|
return (((uint8_t*)&a)[0] << 0) |
|
|
|
@@ -142,14 +150,14 @@ static inline uint32_t lfs_tole32(uint32_t a) {
|
|
|
// Convert between 32-bit big-endian and native order
|
|
|
static inline uint32_t lfs_frombe32(uint32_t a) {
|
|
|
#if !defined(LFS_NO_INTRINSICS) && ( \
|
|
|
- (defined( BYTE_ORDER ) && BYTE_ORDER == ORDER_LITTLE_ENDIAN ) || \
|
|
|
- (defined(__BYTE_ORDER ) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN ) || \
|
|
|
- (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
|
|
|
+ (defined( BYTE_ORDER ) && defined( ORDER_LITTLE_ENDIAN ) && BYTE_ORDER == ORDER_LITTLE_ENDIAN ) || \
|
|
|
+ (defined(__BYTE_ORDER ) && defined(__ORDER_LITTLE_ENDIAN ) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN ) || \
|
|
|
+ (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
|
|
|
return __builtin_bswap32(a);
|
|
|
#elif !defined(LFS_NO_INTRINSICS) && ( \
|
|
|
- (defined( BYTE_ORDER ) && BYTE_ORDER == ORDER_BIG_ENDIAN ) || \
|
|
|
- (defined(__BYTE_ORDER ) && __BYTE_ORDER == __ORDER_BIG_ENDIAN ) || \
|
|
|
- (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
|
|
|
+ (defined( BYTE_ORDER ) && defined( ORDER_BIG_ENDIAN ) && BYTE_ORDER == ORDER_BIG_ENDIAN ) || \
|
|
|
+ (defined(__BYTE_ORDER ) && defined(__ORDER_BIG_ENDIAN ) && __BYTE_ORDER == __ORDER_BIG_ENDIAN ) || \
|
|
|
+ (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
|
|
|
return a;
|
|
|
#else
|
|
|
return (((uint8_t*)&a)[0] << 24) |
|
|
|
@@ -186,4 +194,9 @@ static inline void lfs_free(void *p) {
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+#ifdef __cplusplus
|
|
|
+} /* extern "C" */
|
|
|
+#endif
|
|
|
+
|
|
|
#endif
|