|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifdef STM32F0
|
|
|
|
#define PRSZu "u"
|
|
|
|
#else
|
|
|
|
#define PRSZu "zu"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
#define min(x, y) ((x < y) ? (x) : (y))
|
|
|
|
#define max(x, y) ((x > y) ? (x) : (y))
|
|
|
|
|
|
|
|
/* Human-readable sizes */
|
|
|
|
#define KIB 1024
|
|
|
|
#define MIB (1024 * KIB)
|
|
|
|
#define GIB (1024 * MIB)
|
|
|
|
|
|
|
|
/* Rounding */
|
|
|
|
#define IS_ROUND(x, k) (!((x) & ((k) - 1)))
|
|
|
|
#define ROUND_DOWN(x, k) ((x) & ~((k) - 1))
|
|
|
|
#define ROUND_UP(x, k) (((x) + (k) - 1) & ~((k) - 1))
|
|
|
|
|
|
|
|
#define mask(x, k) ((x) & ((1 << (k)) - 1))
|
|
|
|
#define align(x, k) ((x) & ~((1 << (k)) - 1))
|
|
|
|
#define align_up(x, k) align(x + ((1 << (k)) - 1), k)
|
|
|
|
#define is_aligned(x, k) (!((x) & ((1 << (k)) - 1)))
|
|
|
|
#define align_eq(x, y, k) (!(((x) ^ (y)) >> k))
|
|
|
|
|
|
|
|
/* Bit manipulation */
|
|
|
|
#define BIT_SIZE(t) (CHAR_BIT * sizeof(t))
|
|
|
|
#define BIT(n) (1 << (n))
|
|
|
|
#define BITS(_start, _end) ((BIT(_end) - BIT(_start)) + BIT(_end))
|