15#include <mpix/config.h>
17#include <mpix/types.h>
21#if CONFIG_MPIX_LOG_LEVEL >= 1
22#define MPIX_ERR(fmt, ...) mpix_port_printf("E: %s: " fmt "\n", __func__, ## __VA_ARGS__)
24#define MPIX_ERR(fmt, ...) ((void)0)
27#if CONFIG_MPIX_LOG_LEVEL >= 2
28#define MPIX_WRN(fmt, ...) mpix_port_printf("W: %s: " fmt "\n", __func__, ## __VA_ARGS__)
30#define MPIX_WRN(fmt, ...) ((void)0)
33#if CONFIG_MPIX_LOG_LEVEL >= 3
34#define MPIX_INF(fmt, ...) mpix_port_printf("I: %s: " fmt "\n", __func__, ## __VA_ARGS__)
36#define MPIX_INF(fmt, ...) ((void)0)
39#if CONFIG_MPIX_LOG_LEVEL >= 4
40#define MPIX_DBG(fmt, ...) mpix_port_printf("D: %s: " fmt "\n", __func__, ## __VA_ARGS__)
42#define MPIX_DBG(fmt, ...) ((void)0)
47extern const struct mpix_str mpix_str_fmt[];
48extern const char *
const mpix_str_op[];
49extern const char *
const mpix_str_cid[];
50extern const char *
const mpix_str_kernel[];
51extern const char *
const mpix_str_jpeg[];
53static inline int mpix_enum(
const struct mpix_str *table,
const char *
name)
55 for (
size_t i = 0; table[i].
name != NULL; i++) {
56 if (strcmp(table[i].
name,
name) == 0) {
57 return table[i].
value;
67#define BITS_PER_BYTE 8
71#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*(arr)))
75#define CLAMP(n, min, max) ((n) < (min) ? (min) : (n) > (max) ? (max) : (n))
79#define MIN(a, b) ((a) < (b) ? (a) : (b))
83#define MAX(a, b) ((a) > (b) ? (a) : (b))
87#define RGB32(r8, g8, b8) (((uint8_t)(r8) << 16) | ((uint8_t)(g8) << 8) | (uint8_t)(b8))
91#define IN_RANGE(n, min, max) ((n) >= (min) && (n) <= (max))
95#define WITHIN(n, ref, margin) ((n) >= (ref) - (margin) && (n) <= (ref) + (margin))
99#define _LOG2D(x) (32 - __builtin_clz(x) - 1)
100#define _LOG2Q(x) (64 - __builtin_clzll(x) - 1)
101#define _LOG2(x) (sizeof(__typeof__(x)) > 4 ? _LOG2Q(x) : _LOG2D(x))
102#define LOG2(x) ((x) < 1 ? -1 : _LOG2(x))
107static inline uint16_t mpix_bswap16(uint16_t u)
109 return ((u & 0xff00U) >> 8) | ((u & 0x00ffU) << 8);
112static inline uint32_t mpix_bswap32(uint32_t u)
114 return ((u & 0xff000000UL) >> 24) | ((u & 0x000000ffUL) << 24) |
115 ((u & 0x00ff0000UL) >> 8) | ((u & 0x0000ff00UL) << 8);
118static inline uint64_t mpix_bswap64(uint64_t u)
120 return ((u & 0xff00000000000000ULL) >> 56) | ((u & 0x00000000000000ffULL) << 56) |
121 ((u & 0x00ff000000000000ULL) >> 40) | ((u & 0x000000000000ff00ULL) << 40) |
122 ((u & 0x0000ff0000000000ULL) >> 24) | ((u & 0x0000000000ff0000ULL) << 24) |
123 ((u & 0x000000ff00000000ULL) >> 8) | ((u & 0x00000000ff000000ULL) << 8);
126#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
128#define MPIX_CONV_BE(bits, u) (u)
129#define MPIX_CONV_LE(bits, u) mpix_bswap##bits(u)
131#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
133#define MPIX_CONV_BE(bits, u) mpix_bswap##bits(u)
134#define MPIX_CONV_LE(bits, u) (u)
138static inline uint16_t mpix_htobe16(uint16_t u) {
return MPIX_CONV_BE(16, u); }
139static inline uint16_t mpix_htole16(uint16_t u) {
return MPIX_CONV_LE(16, u); }
140static inline uint16_t mpix_be16toh(uint16_t u) {
return MPIX_CONV_BE(16, u); }
141static inline uint16_t mpix_le16toh(uint16_t u) {
return MPIX_CONV_LE(16, u); }
142static inline uint32_t mpix_htobe32(uint32_t u) {
return MPIX_CONV_BE(32, u); }
143static inline uint32_t mpix_htole32(uint32_t u) {
return MPIX_CONV_LE(32, u); }
144static inline uint32_t mpix_be32toh(uint32_t u) {
return MPIX_CONV_BE(32, u); }
145static inline uint32_t mpix_le32toh(uint32_t u) {
return MPIX_CONV_LE(32, u); }
146static inline uint64_t mpix_htobe64(uint64_t u) {
return MPIX_CONV_BE(64, u); }
147static inline uint64_t mpix_htole64(uint64_t u) {
return MPIX_CONV_LE(64, u); }
148static inline uint64_t mpix_be64toh(uint64_t u) {
return MPIX_CONV_BE(64, u); }
149static inline uint64_t mpix_le64toh(uint64_t u) {
return MPIX_CONV_LE(64, u); }
uint32_t value
Definition types.h:156
const char * name
Definition types.h:154