C Microkernel Realtime eXecutive
Realtime Operating System for Cortex-M based microcontrollers
 
Loading...
Searching...
No Matches
Utilities

This is set of small and generally "one can live without" utilities, which may make one's life easier. More...

Modules

 Assertions
 CMRX SDK provides assertiong mechanism.
 

Detailed Description

This is set of small and generally "one can live without" utilities, which may make one's life easier.

Macro Definition Documentation

◆ CONTAINER_OF

#define CONTAINER_OF (   ptr,
  type,
  member 
)
Value:
({\
const typeof(((type *) 0)->member) * member_ptr = (ptr);\
(type *) ((char *) member_ptr - offsetof(type, member));\
})

Return pointer to enclosing container.

This macro will provide a pointer to container enclosing the member of certain type. Useful for traversing up the data structure without having back-pointers.

Parameters
ptrpointer to known container member
typetype of the enclosing container
membername of the member inside enclosing container
Returns
pointer to the enclosing container

◆ LENGTH

#define LENGTH (   obj)    (sizeof(obj)/sizeof(obj[0]))

Returns length (count of items) in static array.

This function is a shortcut for determining size of typed static array. It is useful for determining amount of for iterations. Type of item must be known at compile time.

Parameters
objstatically allocated array of known type
Returns
amount of items contained in an array

◆ LOG2

#define LOG2 (   x)    (31 - __builtin_clz((uint32_t) x))

Returns integer lowest aproximation of log_2 for given value.

Provides approximation of binary logarithm of given value. More specifically returns log_2 of lowest set bit. This may be useful during bit unmasking.

Parameters
xvalue
Returns
y such that 1 << y will set bit, which is lowest set bit in x