NTURT Zephyr v0.0.1
NTURT common library for Zephyr RTOS
Loading...
Searching...
No Matches
Utility

Utility macros and functions. More...

+ Collaboration diagram for Utility:

Data Structures

struct  work_ctx
 Work context. More...
 
struct  work_ctx_buf
 Work context buffer. More...
 

Macros

#define DISCARD(...)
 Discards all arguments and expend to Zephyr EMPTY.
 
#define GET_ARG_N_FIXED(N, ...)
 Same as Zephyr GET_GET_ARG_N but accepts macro expansion for N .
 
#define N_FOR_EACH_IDX_FIXED_ARG(F, sep, fixed_arg, ...)
 Same as Zephyr FOR_EACH_IDX_FIXED_ARG, useful for nested FOR_EACH macros.
 
#define N_FOR_EACH_FIXED_ARG(F, sep, fixed_arg, ...)
 Same as Zephyr FOR_EACH_FIXED_ARG, useful for nested FOR_EACH macros.
 
#define N_FOR_EACH_IDX(F, sep, ...)
 Same as Zephyr FOR_EACH_IDX, useful for nested FOR_EACH macros.
 
#define N_FOR_EACH(F, sep, ...)
 Same as Zephyr FOR_EACH, useful for nested FOR_EACH macros.
 
#define DEREF_TYPE(type)
 Get the deferenced type of a pointer type.
 
#define TYPEOF_FIELD(type, member)
 Get the type of a member in a structure (struct or union).
 
#define XOR(a, b)
 Logical XOR.
 
#define IS_MASK_SET(value, mask)
 Check if all bits in mask are set in value .
 
#define FLAG_SET_AND_CLEAR(num, flag)
 Check if a flag is set and clear that flag if it so.
 
#define BIT_SET_AND_CLEAR(num, bit)
 Check if a bit is set and clear that bit if it is so.
 
#define LOG_DBG_THROTTLE(min_separation, ...)
 Writes a DEBUG level message to the log with throttling.
 
#define LOG_INF_THROTTLE(min_separation, ...)
 Writes an INFO level message to the log with throttling.
 
#define LOG_WRN_THROTTLE(min_separation, ...)
 Writes a WARNING level message to the log with throttling.
 
#define LOG_ERR_THROTTLE(min_separation, ...)
 Writes an ERROR level message to the log with throttling.
 
#define WORK_CTX_BUF_DEFINE(_name, _size, _work_handler, _ctx, _args_type)
 Define work context buffer for the bottom half of an ISR.
 
#define WORK_CTX(_work)
 Get the context of the work.
 
#define WORK_CTX_ARGS(_work)
 Get the arguments for the work.
 

Functions

struct work_ctxwork_ctx_buf_alloc (struct work_ctx_buf *buf)
 Allocate a work context. Return NULL if all work context are in use.
 

Detailed Description

Utility macros and functions.

Macro Definition Documentation

◆ BIT_SET_AND_CLEAR

#define BIT_SET_AND_CLEAR ( num,
bit )

#include <nturt/sys/util.h>

Value:
FLAG_SET_AND_CLEAR(num, BIT(bit))
#define FLAG_SET_AND_CLEAR(num, flag)
Check if a flag is set and clear that flag if it so.
Definition util.h:137

Check if a bit is set and clear that bit if it is so.

Parameters
[in]numNumber to check.
[in]bitBit to check.
Returns
True if the bit is set.

◆ DEREF_TYPE

#define DEREF_TYPE ( type)

#include <nturt/sys/util.h>

Value:
__typeof__(*((type)0))

Get the deferenced type of a pointer type.

Parameters
[in]typeThe pointer type.
Returns
The type
Parameters
typepoints to.

◆ DISCARD

#define DISCARD ( ...)

#include <nturt/sys/util.h>

Value:
EMPTY

Discards all arguments and expend to Zephyr EMPTY.

Parameters
[in]...Arguments to discard.
Returns
Zephyr EMPTY.

◆ FLAG_SET_AND_CLEAR

#define FLAG_SET_AND_CLEAR ( num,
flag )

#include <nturt/sys/util.h>

Value:
((num & flag) && ((num &= ~flag)))

Check if a flag is set and clear that flag if it so.

Parameters
[in]numNumber to check.
[in]flagFlag to check.
Returns
True if the flag is set.

◆ GET_ARG_N_FIXED

#define GET_ARG_N_FIXED ( N,
... )

#include <nturt/sys/util.h>

Value:
CONCAT(Z_GET_ARG_, N)(__VA_ARGS__)

Same as Zephyr GET_GET_ARG_N but accepts macro expansion for N .

Parameters
[in]NThe index of argument to fetch. Count from 1.
[in]...Arguments from which one argument is returned.
Returns
Nth argument.

◆ IS_MASK_SET

#define IS_MASK_SET ( value,
mask )

#include <nturt/sys/util.h>

Value:
(((value) & (mask)) == (mask))

Check if all bits in mask are set in value .

Parameters
[in]valueValue to check.
[in]maskMask to check against.
Returns
True if all bits in mask are set in value .

◆ LOG_DBG_THROTTLE

#define LOG_DBG_THROTTLE ( min_separation,
... )

#include <nturt/sys/util.h>

Value:
_LOG_THROTTLE(DBG, min_separation, __VA_ARGS__)

Writes a DEBUG level message to the log with throttling.

Parameters
[in]min_separationMinimum time between log messages.
[in]...Same as Zephyr LOG_DBG.

◆ LOG_ERR_THROTTLE

#define LOG_ERR_THROTTLE ( min_separation,
... )

#include <nturt/sys/util.h>

Value:
_LOG_THROTTLE(ERR, min_separation, __VA_ARGS__)

Writes an ERROR level message to the log with throttling.

Parameters
[in]min_separationMinimum time between log messages.
[in]...Same as Zephyr LOG_ERR.

◆ LOG_INF_THROTTLE

#define LOG_INF_THROTTLE ( min_separation,
... )

#include <nturt/sys/util.h>

Value:
_LOG_THROTTLE(INF, min_separation, __VA_ARGS__)

Writes an INFO level message to the log with throttling.

Parameters
[in]min_separationMinimum time between log messages.
[in]...Same as Zephyr LOG_INF.

◆ LOG_WRN_THROTTLE

#define LOG_WRN_THROTTLE ( min_separation,
... )

#include <nturt/sys/util.h>

Value:
_LOG_THROTTLE(WARN, min_separation, __VA_ARGS__)

Writes a WARNING level message to the log with throttling.

Parameters
[in]min_separationMinimum time between log messages.
[in]...Same as Zephyr LOG_WRN.

◆ N_FOR_EACH

#define N_FOR_EACH ( F,
sep,
... )

#include <nturt/sys/util.h>

Value:
N_FOR_EACH_ENGINE(_FOR_EACH, sep, F, _, __VA_ARGS__)
#define N_FOR_EACH_ENGINE(x, sep, fixed_arg0, fixed_arg1,...)
Definition util_loops.h:269

Same as Zephyr FOR_EACH, useful for nested FOR_EACH macros.

◆ N_FOR_EACH_FIXED_ARG

#define N_FOR_EACH_FIXED_ARG ( F,
sep,
fixed_arg,
... )

#include <nturt/sys/util.h>

Value:
N_FOR_EACH_ENGINE(_FOR_EACH_FIXED_ARG, sep, F, fixed_arg, __VA_ARGS__)

Same as Zephyr FOR_EACH_FIXED_ARG, useful for nested FOR_EACH macros.

◆ N_FOR_EACH_IDX

#define N_FOR_EACH_IDX ( F,
sep,
... )

#include <nturt/sys/util.h>

Value:
N_FOR_EACH_ENGINE(_FOR_EACH_IDX, sep, F, _, __VA_ARGS__)

Same as Zephyr FOR_EACH_IDX, useful for nested FOR_EACH macros.

◆ N_FOR_EACH_IDX_FIXED_ARG

#define N_FOR_EACH_IDX_FIXED_ARG ( F,
sep,
fixed_arg,
... )

#include <nturt/sys/util.h>

Value:
N_FOR_EACH_ENGINE(_FOR_EACH_IDX_FIXED_ARG, sep, F, fixed_arg, __VA_ARGS__)

Same as Zephyr FOR_EACH_IDX_FIXED_ARG, useful for nested FOR_EACH macros.

◆ TYPEOF_FIELD

#define TYPEOF_FIELD ( type,
member )

#include <nturt/sys/util.h>

Value:
__typeof__(((type*)0)->member)

Get the type of a member in a structure (struct or union).

Parameters
[in]typeThe structure containing the member.
[in]memberThe member of the structure.
Returns
The type of the member.

◆ WORK_CTX

#define WORK_CTX ( _work)

#include <nturt/sys/util.h>

Value:
(((struct work_ctx*)CONTAINER_OF(_work, struct work_ctx, work))->ctx)
Work context.
Definition util.h:233
struct k_work work
Work.
Definition util.h:235

Get the context of the work.

Parameters
[in]_workPointer to work passed to work handler.
Returns
Context of the work.

◆ WORK_CTX_ARGS

#define WORK_CTX_ARGS ( _work)

#include <nturt/sys/util.h>

Value:
(((struct work_ctx*)CONTAINER_OF(_work, struct work_ctx, work))->args)

Get the arguments for the work.

Parameters
[in]_workPointer to work passed to the work handler.
Returns
Arguments for the work.

◆ WORK_CTX_BUF_DEFINE

#define WORK_CTX_BUF_DEFINE ( _name,
_size,
_work_handler,
_ctx,
_args_type )

#include <nturt/sys/util.h>

Value:
static _args_type CONCAT(_name, _work_args)[_size]; \
static struct work_ctx CONCAT(_name, _work_ctx)[] = { \
LISTIFY(_size, _WORK_CTX_DEFINE, (, ), _work_handler, _ctx, \
&CONCAT(_name, _work_args)), \
}; \
static struct work_ctx_buf _name = { \
.size = _size, \
.work_ctxs = CONCAT(_name, _work_ctx), \
}
Work context buffer.
Definition util.h:245

Define work context buffer for the bottom half of an ISR.

Parameters
[in]_nameName of the buffer.
[in]_sizeSize of the buffer, i.e. the number of simultaneous works that can be submitted.
[in]_work_handlerWork entry point.
[in]_ctxContext of the work.
[in]_args_typeType of the arguments for the work.

◆ XOR

#define XOR ( a,
b )

#include <nturt/sys/util.h>

Value:
(!(a) ^ !(b))

Logical XOR.

Parameters
[in]aFirst operand.
[in]bSecond operand.
Returns
True if and only if one of the operands is true-like, i.e. not equal to 0.

Function Documentation

◆ work_ctx_buf_alloc()

struct work_ctx * work_ctx_buf_alloc ( struct work_ctx_buf * buf)

#include <nturt/sys/util.h>

Allocate a work context. Return NULL if all work context are in use.

Parameters
[in]bufWork context buffer to allocate from.
Returns
Allocated work context. NULL if all work context are in use.