mirror of https://github.com/ARMmbed/mbed-os.git
47 lines
1000 B
C
47 lines
1000 B
C
/*
|
|
* lfs utility functions
|
|
*
|
|
* Copyright (c) 2017 Christopher Haster
|
|
* Distributed under the Apache 2.0 license
|
|
*/
|
|
#ifndef LFS_UTIL_H
|
|
#define LFS_UTIL_H
|
|
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include "mbed_debug.h"
|
|
|
|
|
|
// Builtin functions
|
|
static inline uint32_t lfs_max(uint32_t a, uint32_t b) {
|
|
return (a > b) ? a : b;
|
|
}
|
|
|
|
static inline uint32_t lfs_min(uint32_t a, uint32_t b) {
|
|
return (a < b) ? a : b;
|
|
}
|
|
|
|
static inline uint32_t lfs_ctz(uint32_t a) {
|
|
return __builtin_ctz(a);
|
|
}
|
|
|
|
static inline uint32_t lfs_npw2(uint32_t a) {
|
|
return 32 - __builtin_clz(a-1);
|
|
}
|
|
|
|
static inline int lfs_scmp(uint32_t a, uint32_t b) {
|
|
return (int)(unsigned)(a - b);
|
|
}
|
|
|
|
void lfs_crc(uint32_t *crc, const void *buffer, size_t size);
|
|
|
|
|
|
// Logging functions
|
|
#define LFS_DEBUG(fmt, ...) debug("lfs debug: " fmt "\n", __VA_ARGS__)
|
|
#define LFS_WARN(fmt, ...) debug("lfs warn: " fmt "\n", __VA_ARGS__)
|
|
#define LFS_ERROR(fmt, ...) debug("lfs error: " fmt "\n", __VA_ARGS__)
|
|
|
|
|
|
#endif
|