My Kernel v0.1.0
Utility macro definitions

This is a regroupment of commmon macro and defintions used throughout the project, to avoid repetitive tasks or ease the development process. More...

Collaboration diagram for Utility macro definitions:

Modules

 Bit manipulation
 This file contains common (or not) bitwise operations.
 
 Compiler
 This file contains macros designed to be used with the compiler.
 
 Constants
 Common known constants.
 
 Mapping
 These macros allow to map another macro or function onto a list of arguments.
 
 Mathematical operations
 Collection of macros to perform simple and common math operations.
 

Macros

#define container_of(_ptr, _struct, _field)    ((_struct *)(((void *)_ptr) - offsetof(_struct, _field)))
 Cast a member of a structure out to the containing structure. More...
 
#define MSB(_x)   ((_x) >> 8)
 Retrieve the most significant bytes from 16bit integer.
 
#define LSB(_x)   ((_x)&0xFF)
 Retrieve the less significant bytes from 16bit integer.
 
#define WAIT_FOR(_cond)
 Loop infinitely while the condition _cond is not met.
 
#define INFINITE_LOOP()   while (true)
 Loop infinitely.
 
#define BETWEEN(_x, _l, _h)   ((_l) < (_x) && (_x) < (_h))
 Check if x is strictly between l and h (l < x < h)
 
#define IN_RANGE(_x, _l, _h)   ((_l) <= (_x) && (_x) <= (_h))
 Check if x is between l and h (l <= x <= h)
 
#define RANGES_OVERLAP(_start1, _end1, _start2, _end2)    ((_start1) <= (_end2) && (_end1) >= (_start2))
 Check if two ranges overlap with each other.
 
#define UNUSED(_x)   (void)(_x);
 Avoid compiler warning when not using a symbol.
 
#define ARRAY_SIZE(_arr)   (sizeof(_arr) / sizeof(_arr[0]))
 Compute the number of element inside an array at compile time.
 
#define RETURN_CMP(_x, _y)
 Retun the result of a comparison, similar to what's returned by strcmp.
 
#define stringify(_x)   stringify1(_x)
 Preprocess an expression into a raw string.
 

Detailed Description

Macro Definition Documentation

◆ container_of

#define container_of (   _ptr,
  _struct,
  _field 
)     ((_struct *)(((void *)_ptr) - offsetof(_struct, _field)))
Parameters
_ptrThe pointer to the member
_typeThe type of the container struct
_fieldThe name of the field within the struct