CardSight 0.1.0
C API reference for the CardSight firmware and application
Loading...
Searching...
No Matches
bits.h File Reference

Small helpers shared by the whole tree: array sizes, value bounds, and address arithmetic. More...

#include <stddef.h>

Go to the source code of this file.

Macros

#define ARRAY_SIZE(array)
 Number of elements in a fixed-size array.
#define MIN(a, b)
 Smaller of a and b.
#define MAX(a, b)
 Larger of a and b.
#define CLAMP(value, low, high)
 value limited to the range from low to high.
#define BIT(n)
 Value with bit n set.
#define ALIGN_UP(value, alignment)
 value rounded up to the next multiple of alignment.
#define container_of(pointer, type, member)
 Address of the structure that contains pointer as its member.

Detailed Description

Small helpers shared by the whole tree: array sizes, value bounds, and address arithmetic.

Macro Definition Documentation

◆ ALIGN_UP

#define ALIGN_UP ( value,
alignment )
Value:
(((value) + (alignment) - 1U) & ~((alignment) - 1U))

value rounded up to the next multiple of alignment.

Note
alignment must be a power of two.

◆ container_of

#define container_of ( pointer,
type,
member )
Value:
((type *)((char *)(pointer) - offsetof(type, member)))

Address of the structure that contains pointer as its member.

Parameters
pointerAddress of the member.
typeType of the enclosing structure.
memberName of the member within that structure.

◆ MAX

#define MAX ( a,
b )
Value:
(((a) > (b)) ? (a) : (b))

Larger of a and b.

Note
The selected argument is evaluated twice; do not pass side-effecting expressions.

◆ MIN

#define MIN ( a,
b )
Value:
(((a) < (b)) ? (a) : (b))

Smaller of a and b.

Note
The selected argument is evaluated twice; do not pass side-effecting expressions.