Kernel utilities

Utilities and data structures used by the kernel. More...

Detailed Description

Utilities and data structures used by the kernel.

Files

file  assert.h
 POSIX.1-2008 compliant version of the assert macro.
 
file  bitarithm.h
 Helper functions for bit arithmetic.
 
file  byteorder.h
 Functions to work with different byte orders.
 
file  cib.h
 Circular integer buffer interface.
 
file  clist.h
 Circular linked list.
 
file  debug.h
 Debug-header.
 
file  kernel_types.h
 Types used by the kernel.
 
file  lifo.h
 LIFO buffer API, read long description carefully.
 
file  list.h
 Intrusive linked list.
 
file  log.h
 System logging header.
 
file  panic.h
 Crash handling header.
 
file  priority_queue.h
 A simple priority queue.
 
file  ringbuffer.h
 A utility for storing and retrieving byte data using a ring buffer.
 

Data Structures

union  le_uint16_t
 A 16 bit integer in little endian. More...
 
union  le_uint32_t
 A 32 bit integer in little endian. More...
 
union  le_uint64_t
 A 64 bit integer in little endian. More...
 
union  be_uint16_t
 A 16 bit integer in big endian aka network byte order. More...
 
union  be_uint32_t
 A 32 bit integer in big endian aka network byte order. More...
 
union  be_uint64_t
 A 64 bit integer in big endian aka network byte order. More...
 
struct  cib_t
 circular integer buffer structure More...
 
struct  list_node
 List node structure. More...
 
struct  priority_queue_node
 data type for priority queue nodes More...
 
struct  priority_queue_t
 data type for priority queues More...
 

Macros

#define DEBUG_ASSERT_VERBOSE
 Activate verbose output for assert() when defined. More...
 
#define assert(cond)
 abort the program if assertion is false More...
 
#define SETBIT(val, bit)   val |= (bit)
 Sets a bitmask for a bitfield. More...
 
#define CLRBIT(val, bit)   val &= (~(bit))
 Clears bitmask for a bitfield. More...
 
#define ARCH_32_BIT   (__INT_MAX__ == 2147483647)
 1 for 32 bit architectures, 0 otherwise
 
#define _byteorder_swap(V, T)   (byteorder_swap##T((V)))
 Swaps the byteorder according to the endianess.
 
#define CIB_INIT(SIZE)   { 0, 0, (SIZE) - 1 }
 Initialize cib_t to a given size.
 
#define DEBUG_PRINT(...)
 Print debug information if the calling thread stack is large enough. More...
 
#define DEBUG_EXTRA_STACKSIZE   THREAD_EXTRA_STACKSIZE_PRINTF
 Extra stacksize needed when ENABLE_DEBUG==1.
 
#define SSIZE_MAX   ((ssize_t) (SIZE_MAX / 2))
 Maximum value for ssize_t.
 
#define MAXTHREADS   32
 The maximum number of threads to be scheduled.
 
#define KERNEL_PID_UNDEF   0
 Canonical identifier for an invalid PID.
 
#define KERNEL_PID_FIRST   (KERNEL_PID_UNDEF + 1)
 The first valid PID (inclusive).
 
#define KERNEL_PID_LAST   (KERNEL_PID_FIRST + MAXTHREADS - 1)
 The last valid PID (inclusive).
 
#define PRIkernel_pid   PRIi16
 Macro for printing formatter.
 
#define LOG_LEVEL   LOG_INFO
 Default log level define.
 
#define LOG(level, ...)
 Log message if level <= LOG_LEVEL. More...
 
#define log_write(level, ...)   printf(__VA_ARGS__)
 Default log_write function, just maps to printf.
 
#define PRIORITY_QUEUE_NODE_INIT   { NULL, 0, 0 }
 Static initializer for priority_queue_node_t.
 
#define PRIORITY_QUEUE_INIT   { NULL }
 Static initializer for priority_queue_t.
 

Typedefs

typedef be_uint16_t network_uint16_t
 A 16 bit integer in network byte order.
 
typedef be_uint32_t network_uint32_t
 A 32 bit integer in network byte order.
 
typedef be_uint64_t network_uint64_t
 A 64 bit integer in network byte order.
 
typedef list_node_t clist_node_t
 List node structure. More...
 
typedef int(* clist_cmp_func_t) (clist_node_t *a, clist_node_t *b)
 Typedef for comparison function used by clist_sort() More...
 
typedef int16_t kernel_pid_t
 Unique process identifier.
 
typedef struct list_node list_node_t
 List node structure. More...
 
typedef struct priority_queue_node priority_queue_node_t
 data type for priority queue nodes
 

Enumerations

enum  {
  LOG_NONE, LOG_ERROR, LOG_WARNING, LOG_INFO,
  LOG_DEBUG, LOG_ALL
}
 defined log levels More...
 
enum  core_panic_t {
  PANIC_GENERAL_ERROR, PANIC_SOFT_REBOOT, PANIC_HARD_REBOOT, PANIC_ASSERT_FAIL,
  PANIC_SSP, PANIC_UNDEFINED
}
 Definition of available panic modes. More...
 

Functions

NORETURN void _assert_failure (const char *file, unsigned line)
 Function to handle failed assertion. More...
 
unsigned bitarithm_msb (unsigned v)
 Returns the number of the highest '1' bit in a value. More...
 
unsigned bitarithm_lsb (register unsigned v)
 Returns the number of the lowest '1' bit in a value. More...
 
unsigned bitarithm_bits_set (unsigned v)
 Returns the number of bits set in a value. More...
 
static be_uint16_t byteorder_ltobs (le_uint16_t v)
 Convert from little endian to big endian, 16 bit. More...
 
static be_uint32_t byteorder_ltobl (le_uint32_t v)
 Convert from little endian to big endian, 32 bit. More...
 
static be_uint64_t byteorder_ltobll (le_uint64_t v)
 Convert from little endian to big endian, 64 bit. More...
 
static le_uint16_t byteorder_btols (be_uint16_t v)
 Convert from big endian to little endian, 16 bit. More...
 
static le_uint32_t byteorder_btoll (be_uint32_t v)
 Convert from big endian to little endian, 32 bit. More...
 
static le_uint64_t byteorder_btolll (be_uint64_t v)
 Convert from big endian to little endian, 64 bit. More...
 
static network_uint16_t byteorder_htons (uint16_t v)
 Convert from host byte order to network byte order, 16 bit. More...
 
static network_uint32_t byteorder_htonl (uint32_t v)
 Convert from host byte order to network byte order, 32 bit. More...
 
static network_uint64_t byteorder_htonll (uint64_t v)
 Convert from host byte order to network byte order, 64 bit. More...
 
static uint16_t byteorder_ntohs (network_uint16_t v)
 Convert from network byte order to host byte order, 16 bit. More...
 
static uint32_t byteorder_ntohl (network_uint32_t v)
 Convert from network byte order to host byte order, 32 bit. More...
 
static uint64_t byteorder_ntohll (network_uint64_t v)
 Convert from network byte order to host byte order, 64 bit. More...
 
static uint16_t byteorder_swaps (uint16_t v)
 Swap byte order, 16 bit. More...
 
static uint32_t byteorder_swapl (uint32_t v)
 Swap byte order, 32 bit. More...
 
static uint64_t byteorder_swapll (uint64_t v)
 Swap byte order, 64 bit. More...
 
static uint16_t htons (uint16_t v)
 Convert from host byte order to network byte order, 16 bit. More...
 
static uint32_t htonl (uint32_t v)
 Convert from host byte order to network byte order, 32 bit. More...
 
static uint64_t htonll (uint64_t v)
 Convert from host byte order to network byte order, 64 bit. More...
 
static uint16_t ntohs (uint16_t v)
 Convert from network byte order to host byte order, 16 bit. More...
 
static uint32_t ntohl (uint32_t v)
 Convert from network byte order to host byte order, 32 bit. More...
 
static uint64_t ntohll (uint64_t v)
 Convert from network byte order to host byte order, 64 bit. More...
 
static void cib_init (cib_t *__restrict cib, unsigned int size)
 Initialize cib to 0 and set buffer size to size. More...
 
static unsigned int cib_avail (const cib_t *cib)
 Calculates difference between cib_put() and cib_get() accesses. More...
 
static unsigned int cib_full (const cib_t *cib)
 Check if cib is full. More...
 
static int cib_get (cib_t *__restrict cib)
 Get the index of the next item in buffer. More...
 
static int cib_peek (cib_t *__restrict cib)
 Get the index of the next item in buffer without removing it. More...
 
static int cib_get_unsafe (cib_t *cib)
 Get the index of the next item in buffer. More...
 
static int cib_put (cib_t *__restrict cib)
 Get index for item in buffer to put to. More...
 
static int cib_put_unsafe (cib_t *cib)
 Get index for item in buffer to put to. More...
 
static void clist_rpush (clist_node_t *list, clist_node_t *new_node)
 Appends new_node at the end of *list. More...
 
static void clist_lpush (clist_node_t *list, clist_node_t *new_node)
 Inserts new_node at the beginning of *list. More...
 
static clist_node_tclist_lpop (clist_node_t *list)
 Removes and returns first element from list. More...
 
static void clist_lpoprpush (clist_node_t *list)
 Advances the circle list. More...
 
static clist_node_tclist_lpeek (const clist_node_t *list)
 Returns first element in list. More...
 
static clist_node_tclist_rpeek (const clist_node_t *list)
 Returns last element in list. More...
 
static clist_node_tclist_rpop (clist_node_t *list)
 Removes and returns last element from list. More...
 
static clist_node_tclist_find_before (const clist_node_t *list, const clist_node_t *node)
 Finds node and returns its predecessor. More...
 
static clist_node_tclist_find (const clist_node_t *list, const clist_node_t *node)
 Finds and returns node. More...
 
static clist_node_tclist_remove (clist_node_t *list, clist_node_t *node)
 Finds and removes node. More...
 
static void clist_foreach (clist_node_t *list, int(*func)(clist_node_t *, void *), void *arg)
 Traverse clist, call function for each member. More...
 
clist_node_t_clist_sort (clist_node_t *list_head, clist_cmp_func_t cmp)
 List sorting helper function.
 
static void clist_sort (clist_node_t *list, clist_cmp_func_t cmp)
 Sort a list. More...
 
static int pid_is_valid (kernel_pid_t pid)
 Determine if the given pid is valid. More...
 
int lifo_empty (int *array)
 Check if the given lifo is empty. More...
 
void lifo_init (int *array, int n)
 Initialize a lifo array. More...
 
void lifo_insert (int *array, int i)
 Insert an element into the lifo. More...
 
int lifo_get (int *array)
 Extract the least recently inserted element from the lifo. More...
 
static void list_add (list_node_t *node, list_node_t *new_node)
 Insert object into list. More...
 
static list_node_tlist_remove_head (list_node_t *list)
 Removes the head of the list and returns it. More...
 
static list_node_tlist_remove (list_node_t *list, list_node_t *node)
 Removes the node from the list. More...
 
NORETURN void core_panic (core_panic_t crash_code, const char *message)
 Handle an unrecoverable error by halting or rebooting the system. More...
 
void panic_arch (void)
 architecture dependent handling of a panic case More...
 
static void priority_queue_node_init (priority_queue_node_t *priority_queue_node)
 Initialize a priority queue node object. More...
 
static void priority_queue_init (priority_queue_t *priority_queue)
 Initialize a priority queue object. More...
 
priority_queue_node_tpriority_queue_remove_head (priority_queue_t *root)
 remove the priority queue's head More...
 
void priority_queue_add (priority_queue_t *root, priority_queue_node_t *new_obj)
 insert new_obj into root based on its priority More...
 
void priority_queue_remove (priority_queue_t *root, priority_queue_node_t *node)
 remove node from root More...
 
void priority_queue_print (priority_queue_t *root)
 print the data and priority of every node in the given priority queue More...
 
void priority_queue_print_node (priority_queue_t *root)
 print the data, priority, and successor of a given node More...
 

Variables

const char assert_crash_message []
 the string that is passed to panic in case of a failing assertion
 

Single Bit Defines

#define BIT0   0x00000001
 
#define BIT1   0x00000002
 
#define BIT2   0x00000004
 
#define BIT3   0x00000008
 
#define BIT4   0x00000010
 
#define BIT5   0x00000020
 
#define BIT6   0x00000040
 
#define BIT7   0x00000080
 
#define BIT8   0x00000100
 
#define BIT9   0x00000200
 
#define BIT10   0x00000400
 
#define BIT11   0x00000800
 
#define BIT12   0x00001000
 
#define BIT13   0x00002000
 
#define BIT14   0x00004000
 
#define BIT15   0x00008000
 
#define BIT16   0x00010000
 
#define BIT17   0x00020000
 
#define BIT18   0x00040000
 
#define BIT19   0x00080000
 
#define BIT20   0x00100000
 
#define BIT21   0x00200000
 
#define BIT22   0x00400000
 
#define BIT23   0x00800000
 
#define BIT24   0x01000000
 
#define BIT25   0x02000000
 
#define BIT26   0x04000000
 
#define BIT27   0x08000000
 
#define BIT28   0x10000000
 
#define BIT29   0x20000000
 
#define BIT30   0x40000000
 
#define BIT31   0x80000000
 

Debugging defines

#define DEBUG_FUNC   ""
 Contains the function name if given compiler supports it. More...
 
#define DEBUG(...)   DEBUG_PRINT(__VA_ARGS__)
 Print debug information to stdout. More...
 

Logging convenience defines

#define LOG_ERROR(...)   LOG(LOG_ERROR, __VA_ARGS__)
 
#define LOG_WARNING(...)   LOG(LOG_WARNING, __VA_ARGS__)
 
#define LOG_INFO(...)   LOG(LOG_INFO, __VA_ARGS__)
 
#define LOG_DEBUG(...)   LOG(LOG_DEBUG, __VA_ARGS__)
 

Macro Definition Documentation

◆ assert

#define assert (   cond)
Value:
if (!(cond)) { \
_assert_failure(RIOT_FILE_RELATIVE, __LINE__); \
}

abort the program if assertion is false

If the macro NDEBUG was defined at the moment <assert.h> was last included, the macro assert() generates no code, and hence does nothing at all.

Otherwise, the macro assert() prints an error message to standard error and terminates the application by calling core_panic().

The purpose of this macro is to help programmers find bugs in their programs.

With DEBUG_ASSERT_VERBOSE defined this will print also the file, the line and the function this assertion failed in.

If NDEBUG and DEBUG_ASSERT_VERBOSE are not defined, a failed assertion generates output similar to:

0x89abcdef
*** RIOT kernel panic:
FAILED ASSERTION.

...

Where 0x89abcdef is an address. This address can be used with tools like addr2line (or e.g. arm-none-eabi-addr2line for ARM-based code), objdump, or gdb (with the command info line *(0x89abcdef)) to identify the line the assertion failed in.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/assert.html

Definition at line 104 of file assert.h.

◆ CLRBIT

#define CLRBIT (   val,
  bit 
)    val &= (~(bit))

Clears bitmask for a bitfield.

Parameters
[in]valThe bitfield
[in]bitSpecifies the bits to be cleared
Returns
The modified bitfield

Definition at line 47 of file bitarithm.h.

◆ DEBUG

#define DEBUG (   ...)    DEBUG_PRINT(__VA_ARGS__)

Print debug information to stdout.

Note
Another name for DEBUG_PRINT

Definition at line 95 of file debug.h.

◆ DEBUG_ASSERT_VERBOSE

#define DEBUG_ASSERT_VERBOSE

Activate verbose output for assert() when defined.

Without this macro defined the assert() macro will just print the address of the code line the assertion failed in. With the macro defined the macro will also print the file, the code line and the function this macro failed in.

To define just add it to your CFLAGS in your application's Makefile:

CFLAGS += -DDEBUG_ASSERT_VERBOSE

Definition at line 46 of file assert.h.

◆ DEBUG_FUNC

#define DEBUG_FUNC   ""

Contains the function name if given compiler supports it.

Otherwise it is an empty string.

Definition at line 85 of file debug.h.

◆ DEBUG_PRINT

#define DEBUG_PRINT (   ...)
Value:
do { \
printf(__VA_ARGS__); \
} \
else { \
puts("Cannot debug, stack too small"); \
} \
} while (0)
volatile thread_t * sched_active_thread
Currently active thread.
#define THREAD_EXTRA_STACKSIZE_PRINTF
Size of the task&#39;s printf stack in bytes.
Definition: thread.h:255
int stack_size
thread&#39;s stack size
Definition: thread.h:211

Print debug information if the calling thread stack is large enough.

Use this macro the same as printf. When DEVELHELP is defined inside an implementation file, all usages of DEBUG_PRINT will print the given information to stdout after verifying the stack is big enough. If DEVELHELP is not set, this check is not performed. (CPU exception may occur)

Definition at line 53 of file debug.h.

◆ LOG

#define LOG (   level,
  ... 
)
Value:
do { \
if ((level) <= LOG_LEVEL) log_write((level), __VA_ARGS__); } while (0U)
#define LOG_LEVEL
Default log level define.
Definition: log.h:70
#define log_write(level,...)
Default log_write function, just maps to printf.
Definition: log.h:105

Log message if level <= LOG_LEVEL.

Definition at line 83 of file log.h.

◆ SETBIT

#define SETBIT (   val,
  bit 
)    val |= (bit)

Sets a bitmask for a bitfield.

Parameters
[in]valThe bitfield
[in]bitSpecifies the bits to be set
Returns
The modified bitfield

Definition at line 36 of file bitarithm.h.

Typedef Documentation

◆ clist_cmp_func_t

typedef int(* clist_cmp_func_t) (clist_node_t *a, clist_node_t *b)

Typedef for comparison function used by clist_sort()

Definition at line 352 of file clist.h.

◆ clist_node_t

List node structure.

Used as is as reference to a list.

Definition at line 98 of file clist.h.

◆ list_node_t

typedef struct list_node list_node_t

List node structure.

Used as is as reference to a list, or as member of any data structure that should be member of a list.

Actual list objects should have a list_node_t as member and then use the container_of() macro in list operations. See thread_add_to_list() as example.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

defined log levels

These are the logging levels a user can choose. The idea is to set LOG_LEVEL to one of these values in the application's Makefile. That will restrict output of log statements to those with equal or lower log level.

The default log level is LOG_INFO, which will print every message.

The log function calls of filtered messages will be optimized out at compile time, so a lower log level might result in smaller code size.

Enumerator
LOG_NONE 

Lowest log level, will output nothing.

LOG_ERROR 

Error log level, will print only critical, non-recoverable errors like hardware initialization failures.

LOG_WARNING 

Warning log level, will print warning messages for temporary errors.

LOG_INFO 

Informational log level, will print purely informational messages like successful system bootup, network link state, ...

LOG_DEBUG 

Debug log level, printing developer stuff considered too verbose for production use.

LOG_ALL 

print everything

Definition at line 51 of file log.h.

◆ core_panic_t

Definition of available panic modes.

Enumerator
PANIC_SSP 

stack smashing protector failure

Definition at line 34 of file panic.h.

Function Documentation

◆ _assert_failure()

NORETURN void _assert_failure ( const char *  file,
unsigned  line 
)

Function to handle failed assertion.

Note
This function was introduced for memory size optimization
Warning
this function NEVER returns!
Parameters
[in]fileThe file name of the file the assertion failed in
[in]lineThe code line of file the assertion failed in

◆ bitarithm_bits_set()

unsigned bitarithm_bits_set ( unsigned  v)

Returns the number of bits set in a value.

Parameters
[in]vInput value
Returns
Number of set bits

Source: http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious

◆ bitarithm_lsb()

unsigned bitarithm_lsb ( register unsigned  v)

Returns the number of the lowest '1' bit in a value.

Parameters
[in]vInput value - must be unequal to '0', otherwise the function will produce an infinite loop
Returns
Bit Number

Source: http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious

◆ bitarithm_msb()

unsigned bitarithm_msb ( unsigned  v)

Returns the number of the highest '1' bit in a value.

Parameters
[in]vInput value
Returns
Bit Number

Source: http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious

◆ byteorder_btoll()

static le_uint32_t byteorder_btoll ( be_uint32_t  v)
inlinestatic

Convert from big endian to little endian, 32 bit.

Parameters
[in]vThe integer in big endian.
Returns
v converted to little endian.

Definition at line 332 of file byteorder.h.

◆ byteorder_btolll()

static le_uint64_t byteorder_btolll ( be_uint64_t  v)
inlinestatic

Convert from big endian to little endian, 64 bit.

Parameters
[in]vThe integer in big endian.
Returns
v converted to little endian.

Definition at line 338 of file byteorder.h.

◆ byteorder_btols()

static le_uint16_t byteorder_btols ( be_uint16_t  v)
inlinestatic

Convert from big endian to little endian, 16 bit.

Parameters
[in]vThe integer in big endian.
Returns
v converted to little endian.

Definition at line 326 of file byteorder.h.

◆ byteorder_htonl()

static network_uint32_t byteorder_htonl ( uint32_t  v)
inlinestatic

Convert from host byte order to network byte order, 32 bit.

Parameters
[in]vThe integer in host byte order.
Returns
v converted to network byte order.

Definition at line 361 of file byteorder.h.

◆ byteorder_htonll()

static network_uint64_t byteorder_htonll ( uint64_t  v)
inlinestatic

Convert from host byte order to network byte order, 64 bit.

Parameters
[in]vThe integer in host byte order.
Returns
v converted to network byte order.

Definition at line 367 of file byteorder.h.

◆ byteorder_htons()

static network_uint16_t byteorder_htons ( uint16_t  v)
inlinestatic

Convert from host byte order to network byte order, 16 bit.

Parameters
[in]vThe integer in host byte order.
Returns
v converted to network byte order.

Definition at line 355 of file byteorder.h.

◆ byteorder_ltobl()

static be_uint32_t byteorder_ltobl ( le_uint32_t  v)
inlinestatic

Convert from little endian to big endian, 32 bit.

Parameters
[in]vThe integer in little endian.
Returns
v converted to big endian.

Definition at line 314 of file byteorder.h.

◆ byteorder_ltobll()

static be_uint64_t byteorder_ltobll ( le_uint64_t  v)
inlinestatic

Convert from little endian to big endian, 64 bit.

Parameters
[in]vThe integer in little endian.
Returns
v converted to big endian.

Definition at line 320 of file byteorder.h.

◆ byteorder_ltobs()

static be_uint16_t byteorder_ltobs ( le_uint16_t  v)
inlinestatic

Convert from little endian to big endian, 16 bit.

Parameters
[in]vThe integer in little endian.
Returns
v converted to big endian.

Definition at line 308 of file byteorder.h.

◆ byteorder_ntohl()

static uint32_t byteorder_ntohl ( network_uint32_t  v)
inlinestatic

Convert from network byte order to host byte order, 32 bit.

Parameters
[in]vThe integer in network byte order.
Returns
v converted to host byte order.

Definition at line 378 of file byteorder.h.

◆ byteorder_ntohll()

static uint64_t byteorder_ntohll ( network_uint64_t  v)
inlinestatic

Convert from network byte order to host byte order, 64 bit.

Parameters
[in]vThe integer in network byte order.
Returns
v converted to host byte order.

Definition at line 383 of file byteorder.h.

◆ byteorder_ntohs()

static uint16_t byteorder_ntohs ( network_uint16_t  v)
inlinestatic

Convert from network byte order to host byte order, 16 bit.

Parameters
[in]vThe integer in network byte order.
Returns
v converted to host byte order.

Definition at line 373 of file byteorder.h.

◆ byteorder_swapl()

static uint32_t byteorder_swapl ( uint32_t  v)
inlinestatic

Swap byte order, 32 bit.

Parameters
[in]vThe integer to swap.
Returns
The swapped integer.

Definition at line 298 of file byteorder.h.

◆ byteorder_swapll()

static uint64_t byteorder_swapll ( uint64_t  v)
inlinestatic

Swap byte order, 64 bit.

Parameters
[in]vThe integer to swap.
Returns
The swapped integer.

Definition at line 303 of file byteorder.h.

◆ byteorder_swaps()

static uint16_t byteorder_swaps ( uint16_t  v)
inlinestatic

Swap byte order, 16 bit.

Parameters
[in]vThe integer to swap.
Returns
The swapped integer.

Definition at line 285 of file byteorder.h.

◆ cib_avail()

static unsigned int cib_avail ( const cib_t cib)
inlinestatic

Calculates difference between cib_put() and cib_get() accesses.

Parameters
[in]cibthe cib_t to check. Must not be NULL.
Returns
How often cib_get() can be called before cib is empty.

Definition at line 69 of file cib.h.

◆ cib_full()

static unsigned int cib_full ( const cib_t cib)
inlinestatic

Check if cib is full.

Parameters
[in]cibthe cib_t to check. Must not be NULL.
Returns
1 if cib_put() would return "-1", 0 otherwise

Definition at line 81 of file cib.h.

◆ cib_get()

static int cib_get ( cib_t *__restrict  cib)
inlinestatic

Get the index of the next item in buffer.

Parameters
[in,out]cibcorresponding cib to buffer. Must not be NULL.
Returns
index of next item, -1 if the buffer is empty

Definition at line 93 of file cib.h.

◆ cib_get_unsafe()

static int cib_get_unsafe ( cib_t cib)
inlinestatic

Get the index of the next item in buffer.

Unsafe version, must not be called if buffer is empty!

Parameters
[in,out]cibcorresponding cib to buffer. Must not be NULL.
Returns
index of next item

Definition at line 127 of file cib.h.

◆ cib_init()

static void cib_init ( cib_t *__restrict  cib,
unsigned int  size 
)
inlinestatic

Initialize cib to 0 and set buffer size to size.

Parameters
[out]cibBuffer to initialize. Must not be NULL.
[in]sizeSize of the buffer, must not exceed MAXINT/2. Should be equal to 0 or power of 2.

Definition at line 53 of file cib.h.

◆ cib_peek()

static int cib_peek ( cib_t *__restrict  cib)
inlinestatic

Get the index of the next item in buffer without removing it.

Parameters
[in,out]cibcorresponding cib to buffer. Must not be NULL.
Returns
index of next item, -1 if the buffer is empty

Definition at line 109 of file cib.h.

◆ cib_put()

static int cib_put ( cib_t *__restrict  cib)
inlinestatic

Get index for item in buffer to put to.

Parameters
[in,out]cibcorresponding cib to buffer. Must not be NULL.
Returns
index of item to put to, -1 if the buffer is full

Definition at line 139 of file cib.h.

◆ cib_put_unsafe()

static int cib_put_unsafe ( cib_t cib)
inlinestatic

Get index for item in buffer to put to.

Unsafe version, must not be called if buffer is full!

Parameters
[in,out]cibcorresponding cib to buffer. Must not be NULL.
Returns
index of item to put to

Definition at line 160 of file cib.h.

◆ clist_find()

static clist_node_t* clist_find ( const clist_node_t list,
const clist_node_t node 
)
inlinestatic

Finds and returns node.

Note
Complexity: O(n)
Parameters
[in]listpointer to clist
[in,out]nodeNode to look for Must not be NULL.
Returns
node if found
NULL if node is not a list member

Definition at line 278 of file clist.h.

◆ clist_find_before()

static clist_node_t* clist_find_before ( const clist_node_t list,
const clist_node_t node 
)
inlinestatic

Finds node and returns its predecessor.

Note
Complexity: O(n)
Parameters
[in]listpointer to clist
[in,out]nodeNode to look for Must not be NULL.
Returns
predecessor of node if found
NULL if node is not a list member

Definition at line 250 of file clist.h.

◆ clist_foreach()

static void clist_foreach ( clist_node_t list,
int(*)(clist_node_t *, void *)  func,
void *  arg 
)
inlinestatic

Traverse clist, call function for each member.

The pointer supplied by arg will be passed to every call to func.

If func returns non-zero, traversal will be aborted like when calling break within a for loop.

Parameters
[in]listList to traverse.
[in]funcFunction to call for each member.
[in]argPointer to pass to every call to func

Definition at line 334 of file clist.h.

◆ clist_lpeek()

static clist_node_t* clist_lpeek ( const clist_node_t list)
inlinestatic

Returns first element in list.

Note
: Complexity: O(1)
Parameters
[in]listThe list to work upon.
Returns
first (leftmost) list element, or NULL if list is empty

Definition at line 195 of file clist.h.

◆ clist_lpop()

static clist_node_t* clist_lpop ( clist_node_t list)
inlinestatic

Removes and returns first element from list.

Note
Complexity: O(1)
Parameters
[in,out]listPointer to the list to remove first element from.

Definition at line 150 of file clist.h.

◆ clist_lpoprpush()

static void clist_lpoprpush ( clist_node_t list)
inlinestatic

Advances the circle list.

The result of this function is will be a list with nodes shifted by one. So second list entry will be first, first is last.

[ A, B, C ] becomes [ B, C, A ]

Note
Complexity: O(1)
Parameters
[in,out]listThe list to work upon.

Definition at line 180 of file clist.h.

◆ clist_lpush()

static void clist_lpush ( clist_node_t list,
clist_node_t new_node 
)
inlinestatic

Inserts new_node at the beginning of *list.

Note
Complexity: O(1)
Parameters
[in,out]listPointer to clist
[in,out]new_nodeNode which gets inserted. Must not be NULL.

Definition at line 130 of file clist.h.

◆ clist_remove()

static clist_node_t* clist_remove ( clist_node_t list,
clist_node_t node 
)
inlinestatic

Finds and removes node.

Note
Complexity: O(n)
Parameters
[in]listpointer to clist
[in,out]nodeNode to remove for Must not be NULL.
Returns
node if found and removed
NULL if node is not a list member

Definition at line 301 of file clist.h.

◆ clist_rpeek()

static clist_node_t* clist_rpeek ( const clist_node_t list)
inlinestatic

Returns last element in list.

Note
: Complexity: O(1)
Parameters
[in]listThe list to work upon.
Returns
last (rightmost) list element, or NULL if list is empty

Definition at line 211 of file clist.h.

◆ clist_rpop()

static clist_node_t* clist_rpop ( clist_node_t list)
inlinestatic

Removes and returns last element from list.

Note
Complexity: O(n) with n being the number of elements in the list.
Parameters
[in,out]listPointer to the list to remove last element from.

Definition at line 224 of file clist.h.

◆ clist_rpush()

static void clist_rpush ( clist_node_t list,
clist_node_t new_node 
)
inlinestatic

Appends new_node at the end of *list.

Note
Complexity: O(1)
Parameters
[in,out]listPointer to clist
[in,out]new_nodeNode which gets inserted. Must not be NULL.

Definition at line 109 of file clist.h.

◆ clist_sort()

static void clist_sort ( clist_node_t list,
clist_cmp_func_t  cmp 
)
inlinestatic

Sort a list.

This function will sort list using merge sort. The sorting algorithm runs in O(N log N) time. It is also stable.

Apart from the to-be-sorted list, the function needs a comparison function. That function will be called by the sorting implementation for every comparison. It gets two pointers a, b of type "clist_node_t" as parameters and must return <0, 0 or >0 if a is lesser, equal or larger than b.

Example:

typedef struct {
    clist_node_t next;
    uint32_t value;
} mylist_node_t;

int _cmp(clist_node_t *a, clist_node_t *b)
{
    uint32_t a_val = ((mylist_node_t *)a)->value;
    uint32_t b_val = ((mylist_node_t *)b)->value;

    if (a_val < b_val) {
        return -1;
    }
    else if (a_val > b_val) {
        return 1;
    }
    else {
        return 0;
    }
}

...

clist_sort(list, _cmp);
Parameters
[in,out]listList to sort
[in]cmpComparison function

Definition at line 408 of file clist.h.

◆ core_panic()

NORETURN void core_panic ( core_panic_t  crash_code,
const char *  message 
)

Handle an unrecoverable error by halting or rebooting the system.

A numeric code indicating the failure reason can be given as the crash_code parameter.

Detailing the failure is possible using the message parameter. This function should serve a similar purpose as the panic() function of Unix/Linux kernels.

If the DEVELHELP macro is defined, the system will be halted; the system will be rebooted otherwise.

Warning
this function NEVER returns!
Parameters
[in]crash_codea unique code for identifying the crash reason
[in]messagea human readable reason for the crash
Returns
this function never returns

◆ htonl()

static uint32_t htonl ( uint32_t  v)
inlinestatic

Convert from host byte order to network byte order, 32 bit.

See also
byteorder_htonl()
Parameters
[in]vThe integer to convert.
Returns
Converted integer.

Definition at line 393 of file byteorder.h.

◆ htonll()

static uint64_t htonll ( uint64_t  v)
inlinestatic

Convert from host byte order to network byte order, 64 bit.

See also
byteorder_htonll()
Parameters
[in]vThe integer to convert.
Returns
Converted integer.

Definition at line 398 of file byteorder.h.

◆ htons()

static uint16_t htons ( uint16_t  v)
inlinestatic

Convert from host byte order to network byte order, 16 bit.

See also
byteorder_htons()
Parameters
[in]vThe integer to convert.
Returns
Converted integer.

Definition at line 388 of file byteorder.h.

◆ lifo_empty()

int lifo_empty ( int *  array)

Check if the given lifo is empty.

Parameters
[in]arrayThe lifo array to check.
Returns
1, if empty
0, otherwise.

◆ lifo_get()

int lifo_get ( int *  array)

Extract the least recently inserted element from the lifo.

Parameters
[in]arrayAn integer array, may not be NULL.
Returns
-1, if the lifo is empty.
the least recently inserted element, otherwise.

◆ lifo_init()

void lifo_init ( int *  array,
int  n 
)

Initialize a lifo array.

Parameters
[in,out]arrayAn array of size n + 1, may not be NULL.
[in]nMaximum integer value the lifo is able to store.

◆ lifo_insert()

void lifo_insert ( int *  array,
int  i 
)

Insert an element into the lifo.

Parameters
[in,out]arrayAn integer array of least i + 1 size that **does not already contain *i***, may not be NULL.
[in]iThe integer value to store, between 0 and the size of the array - 1, must not be stored already.

◆ list_add()

static void list_add ( list_node_t node,
list_node_t new_node 
)
inlinestatic

Insert object into list.

If called with a list reference as node, the new node will become the new list head.

Parameters
[in]nodelist node before new entry
[in]new_nodelist node to insert

Definition at line 53 of file list.h.

◆ list_remove()

static list_node_t* list_remove ( list_node_t list,
list_node_t node 
)
inlinestatic

Removes the node from the list.

Parameters
[in]listPointer to the list itself, where list->next points to the root node
[in]nodeList node to remove from the list
Returns
removed node, or NULL if empty or not found

Definition at line 86 of file list.h.

◆ list_remove_head()

static list_node_t* list_remove_head ( list_node_t list)
inlinestatic

Removes the head of the list and returns it.

Parameters
[in]listPointer to the list itself, where list->next points to the root node
Returns
removed old list head, or NULL if empty

Definition at line 67 of file list.h.

◆ ntohl()

static uint32_t ntohl ( uint32_t  v)
inlinestatic

Convert from network byte order to host byte order, 32 bit.

See also
byteorder_ntohl()
Parameters
[in]vThe integer to convert.
Returns
Converted integer.

Definition at line 409 of file byteorder.h.

◆ ntohll()

static uint64_t ntohll ( uint64_t  v)
inlinestatic

Convert from network byte order to host byte order, 64 bit.

See also
byteorder_ntohll()
Parameters
[in]vThe integer to convert.
Returns
Converted integer.

Definition at line 415 of file byteorder.h.

◆ ntohs()

static uint16_t ntohs ( uint16_t  v)
inlinestatic

Convert from network byte order to host byte order, 16 bit.

See also
byteorder_ntohs()
Parameters
[in]vThe integer to convert.
Returns
Converted integer.

Definition at line 403 of file byteorder.h.

◆ panic_arch()

void panic_arch ( void  )

architecture dependent handling of a panic case

This function gives the CPU the possibility to execute architecture dependent code in case of a severe error.

◆ pid_is_valid()

static int pid_is_valid ( kernel_pid_t  pid)
inlinestatic

Determine if the given pid is valid.

Parameters
[in]pidThe pid to check
Returns
true if the pid is valid, false otherwise

Definition at line 92 of file kernel_types.h.

◆ priority_queue_add()

void priority_queue_add ( priority_queue_t root,
priority_queue_node_t new_obj 
)

insert new_obj into root based on its priority

The new object will be appended after objects with the same priority.

Parameters
[in,out]rootthe queue's root
[in]new_objthe object to prepend
Precondition
The queue does not already contain new_obj.

◆ priority_queue_init()

static void priority_queue_init ( priority_queue_t priority_queue)
inlinestatic

Initialize a priority queue object.

For initialization of variables use PRIORITY_QUEUE_INIT instead. Only use this function for dynamically allocated priority queues.

Parameters
[out]priority_queuepre-allocated priority_queue_t object, must not be NULL.

Definition at line 78 of file priority_queue.h.

◆ priority_queue_node_init()

static void priority_queue_node_init ( priority_queue_node_t priority_queue_node)
inlinestatic

Initialize a priority queue node object.

For initialization of variables use PRIORITY_QUEUE_NODE_INIT instead. Only use this function for dynamically allocated priority queue nodes.

Parameters
[out]priority_queue_nodepre-allocated priority_queue_node_t object, must not be NULL.

Definition at line 58 of file priority_queue.h.

◆ priority_queue_print()

void priority_queue_print ( priority_queue_t root)

print the data and priority of every node in the given priority queue

Note
requires ENABLE_DEBUG to be set to 1 for this file

◆ priority_queue_print_node()

void priority_queue_print_node ( priority_queue_t root)

print the data, priority, and successor of a given node

Note
requires ENABLE_DEBUG to be set to 1 for this file

◆ priority_queue_remove()

void priority_queue_remove ( priority_queue_t root,
priority_queue_node_t node 
)

remove node from root

Parameters
[in,out]rootthe priority queue's root
[in]nodethe node to remove

◆ priority_queue_remove_head()

priority_queue_node_t* priority_queue_remove_head ( priority_queue_t root)

remove the priority queue's head

Parameters
[out]rootthe queue's root
Returns
the old head