You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.0 KiB
38 lines
1.0 KiB
#pragma once
|
|
|
|
#if defined(STM32F0) || defined(STM32F1)
|
|
#define PRSZu "u"
|
|
#else
|
|
#define PRSZu "zu"
|
|
#endif
|
|
|
|
#include <limits.h>
|
|
#include <stdarg.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)
|
|
|
|
#define container_of(ptr, type, member) \
|
|
(type *)((char *)ptr - offsetof(type, member))
|
|
|
|
/* 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))
|
|
#define BIT_MASK(x, k) ((x) & ((1 << (k)) - 1))
|
|
|