Add IS_BIT_MASK() macro for determining whether a value is set bits
continuously from the LSB.
This macro is not dependent on bit-width and works in contrast to
BIT_MASK() and BIT64_MASK().
IS_SHIFTED_BIT_MASK() is a version of IS_BIT_MASK() that allows setting
the start bit of continuous bits.
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@fujitsu.com>
Use flag instead of word in the buffer. Using this method allows
to dedicate full buffer capacity for data.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Ranges with step 0, that is, multiple indices representing the same
value, need to report the count exclusively based on indices. This makes
it possible to later retrieve all values, e.g. in a group.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Add a no-op stub for __ASSERT_POST_ACTION.
This allows code to reference __ASSERT_POST_ACTION even when Zephyr
asserts are off.
Signed-off-by: Rob Barnes <robbarnes@google.com>
When dealing with groups, the specified window in
linear_range_group_get_win_index can span across multiple groups. In the
current implementation, if maximum value was not in the same sub-window
as the minimum value the function would return -EINVAL. This patch fixes
the problem and updates test cases to cover such scenario.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
The cache operations must be quick, optimized and possibly inlined. The
current API is clunky, functions are not inlined and passing parameters
around that are basically always known at compile time.
In this patch we rework the cache functions to allow us to get rid of
useless parameters and make inlining easier.
In particular this changeset is doing three things:
1. `CONFIG_HAS_ARCH_CACHE` is now `CONFIG_ARCH_CACHE` and
`CONFIG_HAS_EXTERNAL_CACHE` is now `CONFIG_EXTERNAL_CACHE`
2. The cache API has been reworked.
3. Comments are added.
Signed-off-by: Carlo Caione <ccaione@baylibre.com>
Rather than hard-coding calls to each individual CRC function, it
may be more convenient to specify the crc algorithm to use
parametrically.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
This patch adds a new API to map values in a linear range to a range
index. This API is useful in the context of regulators, where it is
common that devices map regulator voltages to a set of indices with a
linear relationship.
The original idea is borrowed from Linux.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
If gcc compiler option -Werror is used the warning,
declared inside parameter list will not be visible outside of this
definition or declaration [-Werror]
is treated as error, for
sockets_internal.h:18:28: ‘struct net_context’
sockets_internal.h:19:32: ‘struct zsock_pollfd’
fdtable.h:108:17: ‘struct k_mutex’
Signed-off-by: Christoph Schnetzler <christoph.schnetzler@husqvarnagroup.com>
Enables logging testing for qemu_xtensa along with the fixes needed to
correctly run the tests.
Several tests in log_api rely on being able to calculate the size of
the message in the mpsc_pbuf to know when an overflow occurs. The
size being calculated assumed a ROUND_UP size alignment to sizeof(long
long). On xtensa this is actually 16 bytes as defined by
CBPRINTF_PACKAGE_ALIGNMENT.
Changes the size calculation for SIMPLE_MSG_LEN to account for this.
The second issue was a misaligned package that would cause reading
from the incorrect memory when going to format the package with cbpprintf.
Fixes the padding used to align the package in cbprintf.h and adds a build
assert ensuring correct alignment when building against xtensa in both
cbprintf.h and log_msg.h.
Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
ARC ABI requires stack to be 32 / 64 bit aligned for 32bit and
64 bit architecture variant.
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
Picolibc aliases the printfcb functions directly to printf
equivalents. There were a couple of these macros that were broken.
Signed-off-by: Keith Packard <keithp@keithp.com>
In order to avoid using multiple sources of truth for the platfom's
endianness, convert the in-tree code to use the (BIG|LITTLE)_ENDIAN
Kconfig variables exclusively, instead of the compiler's
__BYTE_ORDER__.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Move arch_num_cpus outside of CONFIG_SMP in sys/arch_interface.h and
add define arch_num_cpus on all platforms (added arch_inlines.h on
those platforms that didn't have it before).
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
Spin locks held for any lengthy duration prevent interrupts and
in a real time system where interrupts drive tasks this can be
problematic. Add an option to assert if a spin lock is held for
a duration longer than the configurable number of microseconds.
Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
Introduce a Kconfig (MP_MAX_NUM_CPUS) and an api arch_num_cpus() to
allow for systems that might determine the number of CPUs available to
Zephyr at runtime.
CONFIG_MP_MAX_NUM_CPUS is intented to be use for any array initialization
and such that need to occur at build time. For most systems
arch_num_cpus() will just report the value of CONFIG_MP_MAX_NUM_CPUS.
The intent is to phase out CONFIG_NP_NUM_CPUS.
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
Doxygen comment containing <tt>__VA_ARGS__</tt> does not render
correctly, i.e. __VA_ARGS__ is completely missing from the html
output. The Markdown syntax `__VA_ARGS__` renders as expected.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
We compile with the gcc compiler flags -Werror and -Wshadow. So
the mentioned macro rasies a warning (and with the flags the
warning becoms to an error). It uses the same variable names
as on of its caller. Add an addidional underscore to the
affected variables to prevent this warning.
Signed-off-by: Peter Tönz <peter.tonz@husqvarnagroup.com>
Currently, to compute the 'item' size in a ring buffer, we have
`SIZE32_OF`.
Several issues with this:
- `SIZE32_OF` only works on variables, not types, due to an extra
parenthesis pair. Indeed, `sizeof((int))` is not valid C, whereas
`sizeof((my_var))` is.
- `SIZE32_OF` is not a proper public API
- `SIZE32_OF` rounds down if the argument size is not a multiple
of 4 bytes.
Thus, we introduce a proper `RING_BUF_ITEM_SIZEOF`, fixing the
aforementioned issues.
Signed-off-by: Henri Xavier <datacomos@huawei.com>
Static packaging is using only argument types to build a package. There
is one case where analysing argument type only is not enough to
determine package content. That is %p with (unsigned) char pointer vs
%s. In case of %s a string might need to be appended to the package
and in case of %p it must be avoided. Format string analysis is required
to distinguish those two cases.
In order to speed up the runtime inspection, additional information is
added to a static package. That is index of the string argument (where
first argument has index 0). This information allows quick format string
inspection where nth format specifier is found and checked if it is a
pointer format specifier.
Inspection algorithm is added to cbprintf_package_convert() and if %p
is found then data for that argument is discarded. Additionally, log
warning is printed with suggestion to cast pointer argument to void *
to avoid confusion. It is desired to get rid of this ambiguity because
there are going to be logging configurations where strings are stripped
from a binary and runtime inspection cannot be performed.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Static packaging is analyzing string argument type and based
on that builds a package. The most tricky one are pointers
which can be used for %s or %p. %s are strings which may be
transient and must be appended to the package to allow string
formatting from that package when original transient string
location is lost.
It is allowed (gcc printflike extension does not complain) to
using unsigned char for %s. So far static packaging allowed
only char or wchar_t pointers. Extending detection to unsigned
char as well.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
`IS_ARRAY_ELEMENT(array, ptr)` behaves like `PART_OF_ARRAY()`
except that it checks that `ptr` is aligned to an array-element
boundary.
`ARRAY_INDEX(array, ptr)` returns the index of `ptr`, where
`ptr` is aligned to an array-element boundary.
`ARRAY_INDEX_FLOOR(array, ptr)` returns the index of `ptr`,
where `ptr` does not need to be aligned to an array-element
boundary.
If `CONFIG_ASSERT=y`, then `ARRAY_INDEX()` and
`ARRAY_INDEX_FLOOR()` will trigger an assertion for invalid
`ptr`.
Signed-off-by: Christopher Friedt <cfriedt@fb.com>
Use k_us_to_cyc_ceil32() for calculating the number of hardware cycles for
the given timeout value instead of using a custom calculation.
Fixes: #50032
Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This moves padding needed for Xtensa in the cbprintf package header
from the extended header to the simple header. This is due to
the cbprintf packaging function uses the simple header to calculate
offset. This results in the padding not being there in the package,
and the printing function reading incorrect data in the package.
This was discovered while looking into #49016. Without the padding
in the simple header, turning on tagged argument on cbprintf would
crash on qemu_xtensa.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Downcast from const void* to void* is unnecessary since the signature of
memcpy expects a const in second param. This downcast will raise a
compile error when -Werror=cast-qual is on.
Signed-off-by: Rob Barnes <robbarnes@google.com>
At some point, package copy function was extended and renamed
to cbprintf_package_convert. However, flags used by this
function were not renamed and used contained COPY idiom.
Deprecating flags with COPY and replacing them with flags
with CONVERT idiom to match function which is utilizing them.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
We have now:
- CPU_HAS_{D,I}CACHE: when the CPU has support for d-cache and i-cache
- {D,I}CACHE: to enable / disable d-cache and i-cache
Signed-off-by: Carlo Caione <ccaione@baylibre.com>
The cbprintf formatter cbvprintf_exteral_formatter_func has a typo
in it with a missing 'n'. So add it.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit adds the `CODE_UNREACHABLE` hint at the end of the
assertion failure branch so that the compiler takes note of the assert
function not returning when an assertion fails.
This prevents the compiler from generating misguided warnings assuming
the asserted execution paths.
It also introduces the `ASSERT_TEST` Kconfig symbol, which indicates
that the "assert test mode" is enabled. This symbol may be selected by
the tests that require the assert post action function to return
without aborting so that the test can proceed.
Note that the `CODE_UNREACHABLE` hint is specified only when the assert
test mode is disabled in order to prevent the tests from crashing when
the assert post action function returns.
Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
The def command Indicates that a comment block contains documentation
for a #define macro. This is useful if the comment block documents a
macro not adjacent to it, e.g.
```c
/**
* @def MAX(x,y)
* @brief Computes the maximum of @a x and @a y.
*/
#ifdef XXX
#define MAX(x,y) ...
#endif
```
However, it is not necessary if the comment is adjacent to the
definition, e.g.
```c
/**
* @brief Computes the maximum of @a x and @a y.
*/
#define MAX(x,y) ...
```
This patch removes all unnecessary def entries in-tree.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This macro compares two integers from 0 to 255 at compile time, using
the preprocessor.
Signed-off-by: Kumar Gala <galak@kernel.org>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Add the "zephyr/" prefix to various #include statements that are
preventing the CI form running with LEGACY_INCLUDE_PATH=n.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
MISRA C:2012 Rule 14.4 (The controlling expression of an if statement
and the controlling expression of an iteration-statement shall have
essentially Boolean type.)
Use comparisons with NULL instead of implicitly testing pointers.
Use `do { ... } while (false)' instead of `do { ... } while (0)'.
Use comparisons with zero instead of implicitly testing integers.
The commit is a subset of the original auditable-branch commit:
5d02614e34a86b549c7707d3d9f0984bc3a5f22a
Signed-off-by: Simon Hein <SHein@baumer.com>
When compiling with '-Werror=missing-field-initializers', the cbprintf
header causes an error since 'off' isn't initialized.
Signed-off-by: Yuval Peress <peress@google.com>
Use CONFIG_DCACHE_LINE_SIZE to determine distance between
fields modified by different cores.
Add option which specifies what is the data cache line
of the remote core. Maximum from local and remote cache
line sizes is used as distance and alignement.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Any project with Kconfig option CONFIG_LEGACY_INCLUDE_PATH set to n
couldn't be built because some files were missing zephyr/ prefix in
includes
Re-run the migrate_includes.py script to fix all legacy include paths
Signed-off-by: Tomislav Milkovic <milkovic@byte-lab.com>
add a sys_mem_blocks_is_region_free procedure to test
if the block in question is free or taken
Signed-off-by: Marcin Szkudlinski <marcin.szkudlinski@intel.com>
Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
Since the retrieved heap memory statistics are identical to those of
the retrieved mem_block statistics, it makes sense to use a single
generic-named structure for both instead of two identical structures
with different names.
Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
Both the current and maximum number of allocations in a given memory
blocked are tracked (and can be queried) when the
CONFIG_SYS_MEM_BLOCKS_RUNTIME_STATS Kconfig option is selected.
Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
Move scripts needed by the build system and not designed to be run
individually or standalone into the build subfolder.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>