1.7. types — Common types

Source code: src/kernel/types.h


Defines

UNUSED(v) (void)(v)
STRINGIFY(x) STRINGIFY2(x)

Create a string of an identifier using the pre-processor.

STRINGIFY2(x) #x

Used internally by STRINGIFY().

TOKENPASTE(x, y) TOKENPASTE2(x, y)

Concatenate two tokens.

TOKENPASTE2(x, y) x ## y

Used internally by TOKENPASTE().

UNIQUE(x) TOKENPASTE(x, TOKENPASTE(___, __LINE__))

Create a unique token.

PRINT_FILE_LINE std_printf(OSTR("%s:%d:\r\n"), __FILE__, __LINE__);

Debug print of file and line.

STD_PRINTF_DEBUG(...)
membersof(a) ((ssize_t)(sizeof(a) / sizeof((a)[0])))

Get the number of elements in an array.

As an example, the code below outputs number of members in foo = 10.

int foo[10];

std_printf(FSTR("number of members in foo = %d\\r\\n"),
           membersof(foo));

container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );})
DIV_CEIL(n, d) (((n) + (d) - 1) / d)

Integer division that rounds the result up.

DIV_ROUND(n, d) (((n) + (d / 2)) / d)

Integer division that rounds the result to the closest integer.

MIN(a, b) (((a) < (b)) ? (a) : (b))

Get the minimum value of the two.

MAX(a, b) (((a) > (b)) ? (a) : (b))

Get the maximum value of the two.

BIT(pos) (1 << (pos))
BITFIELD_SET(name, value) (((value) << name ## _POS) & name ## _MASK)
BITFIELD_GET(name, value) (((value) & name ## _MASK) >> name ## _POS)
OSTR(string) FSTR(string)
CSTR(string) FSTR(string)

Typedefs

typedef uint8_t u8_t
typedef int8_t s8_t
typedef uint16_t u16_t
typedef int16_t s16_t
typedef uint32_t u32_t
typedef int32_t s32_t
struct thrd_prio_list_elem_t

Public Members

struct thrd_prio_list_elem_t *next_p
struct thrd_t *thrd_p
struct thrd_prio_list_t

Public Members

struct thrd_prio_list_elem_t *head_p