BIT/_MASK doesn't necessarily handle 64 bits, so provide comparable
functionality for BIT64/_MASK.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Adds CLAMP macro to complement the current min/max macros, as well as a
gcc specific Z_CLAMP macro for single-evaluation expansion.
CLAMP combines the functionality of MIN and MAX, eliminating the
bug-prone usage of MIN(MAX(value, FLOOR), CEIL) found throughout the
codebase in every possible combination.
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
The <sys/util.h>, in current form, can not be used with DTS as it
contains non-C pre-processor definitions which breake DTS interpreter.
This commit fixes the problem by moving most of preprocessor macros
from util.h to util_macro.h. Since util_mcaro.h contains only
preprocessor macros, without include dependencies, it can be safely
included in DTS. It is similar way the
<dts/arm/<manufacturer>/pinctrl_<manufacturer>_<soc>.h files are
included.
This fix and align the extern "C" closing brack inside non assembly
block.
The issue was raised when try create a macro for pincrtl with a
variable length flag list.
Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
Several utility macros must be given the name of a macro to apply to
every element in a sequence to transform it. When no transformation
is necessary a macro still needs to be provided. That macro is
IDENTITY.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Both operands of an operator in the arithmetic conversions
performed shall have the same essential type category.
Changes are related to converting the integer constants to the
unsigned integer constants
Signed-off-by: Aastha Grover <aastha.grover@intel.com>
This is an extension to the existing FOR_EACH family of macros that
has a couple of twists that make it more useful in certain contexts,
as explained in the docstring.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
true and false in a C environment are macros that are defined to 1 and
0 respectively. In C++ they are keywords, and as such cause failures
when macro tests require they expand to a 1 or 0 token. Use the
actual token values rather than the macro names when defining the
macros.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Numbers in C macros are treated as signed integer. This causes
issues when using macro KB(x). If the result is larger than
(2^31 - 1), it is treated as a negative number downstream.
For example, the RAM size of up_squared is 2GB. The result of
KB(CONFIG_SRAM_SIZE) should be 2147483648, but due to being
casted as signed, the result is instead -2147483648. Any
calculations using this would be incorrectly. Fix it by
casting x in KB(x) to size_t first.
Fixes#27164
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Macro GET_ARG_N is geting nth argument from the variable list provided.
GET_ARGS_LESS_N returns argument list without n first arguments.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Since this is an experimental API and MACRO_MAP() was deprecated in
favor of FOR_EACH() in zephyr v2.3.0, we are within our rights to just
remove it without notice now. Do so and mention it in the release
notes.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This file contains definitions for macros which are integral to
significant Zephyr use cases, such as CONTAINER_OF() and various
macros used by devicetree.h internally.
As such, in practice we expect at least advanced (if not intermediate)
users to understand it, so the fact that it's not formally documented
as an API with a stability level is a problem.
Fix that by giving the docstrings a once-over and adding new ones
where they are missing. Move all the remaining non-API macros to
util_internal.h.
Add a Sphinx API page for this header, and include it in the API
overview at "experimental" stability level.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Move the repetitive definitions used to add and subtract 1 at
preprocessor time into their own file. Make the behavior consistent,
so that you can invoke UTIL_INC(x) for any x you can invoke
UTIL_DEC(x) on.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This was added because GNU G++ doesn't support the built-in function
used to produce a compile-time error when invalid parameters are
passed to the macro imlementation. The template implementation does
not work on declarations like this:
mytype array[] = { ... }
because it requires an explicit size for the template parameter.
Remove the template specialization, and support C++ with a version of
the macro that doesn't involve references to undefined builtins.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Added separator (e.g. comma or semicolon) parameter to FOR_EACH_ family.
Separator is added between macro execution for each argument and not at
the end.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
IS_EMPTY macro allows to check if defined name is empty, i.e.
does not contain replacement list.
LIST_DROP_EMPTY macro may be used to process __VA_ARGS__ type lists,
e.g. a,b,,c , and remove empty elements.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
INLINE is a very common macro, just like MAX or MIN.
Defining it always can easily collide with libraries or
application headers.
And option would be to add a ifdef guard around it,
But it was used in only 1 place in Zephyr, instead
of keeping it just for that, remove it.
Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
MACRO_MAP has the same functionality as FOR_EACH macro. Removed macro
implementation and replaced with FOR_EACH call.
Deprecated macro to avoid having two macros with the same
functionality.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Updated implementation of FOR_EACH and FOR_EACH_FIXED_ARG to use same
engine as FOR_EACH_IDX macro.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Added macros which iterate over provided parameters and call specific
macro with this parameter, index and fixed argument
(FOR_EACH_IDX_FIXED_ARG).
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Z_IS_ENABLED2 uses true and false, however when we preprocess the linker
scripts we invoke the compiler with `-x assembler-with-cpp` so
_ASMLANGUAGE ends up being defined and thus stdbool.h wouldn't convert
'true' and 'false' to '1' and '0'.
Move the include of stdbool.h outside the #ifndef _ASMLANGUAGE check so
that 'true' and 'false' get converted correctly.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
extern "C" is missing.
This commit adds conditional extern "C" for cpp to
the beginning of the file and brackets the cpp template with
extern "C++"
Signed-off-by: Steven Slupsky <sslupsky@gmail.com>
These are short-circuiting utility helpers that can save typing
in situations where avoiding evaluation of the not-taken branch
skips invalid expressions.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This is like MACRO_MAP(), but it pastes the results together into a
single token. The result is kind of a fold of the ## operator.
I wasn't able to figure out a way to implement this using any of the
existing macros, so there's some more copy/pasting of handler macros
for different numbers of arguments.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Added macro for code inserting based on configuration flag.
This macro is wrapper around COND_CODE_1().
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
constexpr and noexcept were introduced as specifiers in C++11. Avoid
referencing them when compiling for earlier versions of the language.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
The struct definitions for pdpt, pd, and pt entries has been
removed:
- Bitfield ordering in a struct is implementation dependent,
it can be right-to-left or left-to-right
- The two different structures for page directory entries were
not being used consistently, or when the type of the PDE
was unknown
- Anonymous structs/unions are GCC extensions
Instead these are now u64_t, with bitwise operations used to
get/set fields.
A new set of inline functions for fetcing various page table
structures has been implemented, replacing the older macros.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
MAX() and MIN() were evaluating arguments twice. If arguments are
functions they were called twice which resulted in bigger code
and potential misbehavior.
Added alternative macros (Z_MAX, Z_MIN) which can be used instead.
Macros have usage limitations thus they are not replacements. They
are also relying on GCC extension thus placed in gcc.h
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Some modules use snprintk to format the settings keys. Unfortunately
snprintk is tied with printk which is very large for some embedded
systems.
To be able to have settings enabled without also enabling printk
support, change creation of settings key strings to use bin2hex, strlen
and strcpy instead.
A utility function to make decimal presentation of a byte value is
added as u8_to_dec in lib/os/dec.c
Add new Kconfig setting BT_SETTINGS_USE_PRINTK
Signed-off-by: Kim Sekkelund <ksek@oticon.com>
This reverts commit 755cc644cc.
This approach is problematic in several ways. First, `intptr_t` could
cause undefined behavior in the subtraction when the pointer converts to
a negative value. Except in weird cases where the sign of the pointer
identifies a memory domain (like kernel vs userspace) I'm unaware of any
valid use of `intptr_t`.
Second, this macro was created to address a special need that cannot
rely on defined behavior: i.e. to ensure that data definitions are
placed in contiguous space and access is provided through linker-defined
symbols, for which the language required alignment and continuity is not
guaranteed.
A macro that calculates the span between linker symbols has very
different semantics than one that calculates the difference between
pointers. Replace the global PTR_DIFF with a documented local macro
that tests what's necessary without risking integer overflow.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Move duplicate hex2bin and add bin2hex function so that application can
use the functions and avoid code duplication.
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Some code casts pointers to ints in order to obtain their difference.
The compiler complains on 64-bit targets as an int is not wide enough
to hold a pointer.
Let's introduce the PTR_DIFF() helper macro to applies the proper cast
to pointers before performing a difference on them, and still return the
result as an int which should be large enough in practice.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.
No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.
Related to #16539
Signed-off-by: Anas Nashif <anas.nashif@intel.com>