Commit graph

8529 commits

Author SHA1 Message Date
Peter Mitsis
d1353a4584 kernel: pipes: add pipe flush routines
Adds two routines to flush pipe objects:
   k_pipe_flush()
     - This routine flushes the entire pipe. That includes both
     the pipe's buffer and all pended writers. It is equivalent
     to reading everything into a giant temporary buffer which
     is then discarded.
   k_pipe_buffer_flush()
     - This routine flushes only the pipe's buffer (if it exists).
     It is equivalent to reading a maximum of "buffer size" bytes
     into a temporary buffer which is then discarded.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2022-01-10 12:17:14 -05:00
Peter Mitsis
0ebd6c7f26 kernel/sched: enable/disable runtime stats
Adds support to enable/disable both thread and cpu runtime
stats.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2022-01-10 10:38:06 -05:00
Peter Mitsis
f498118daa debug: thread analyzer to display runtime stats
Updates the thread analyzer to display the thread runtime
stats.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2022-01-10 10:38:06 -05:00
Peter Mitsis
4eb1dd02cc kernel: extend CPU runtime stats
Extends the CPU usage runtime stats to track current, total, peak
and average usage (as bounded by the scheduling of the idle thread).
This permits a developer to obtain more system information if desired
to tune the system.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2022-01-10 10:38:06 -05:00
Peter Mitsis
572f1db56a kernel: extend thread runtime stats
When the new Kconfig option CONFIG_SCHED_THREAD_USAGE_ANALYSIS
is enabled, additional timing stats are collected during context
switches. This extra information allows a developer to obtain the
the current, longest, average and total lengths of the time that
a thread has been scheduled to execute.

A developer can in turn use this information to tune their app and/or
alter their scheduling policies.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2022-01-10 10:38:06 -05:00
Daniel Leung
ae415272c1 sys: heap_listener: extend to cover more events
This extends the heap_listener to cover more events,
specifically, allocation, free and realloc.

Note that typedef are used so the callback can be
documented.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-01-10 10:28:04 -05:00
Daniel Leung
39d17a180a sys: heap_listener: resize_cb to also take heap ID
Add a parameter to the resize callback to also take the heap ID.
This allows a single callback to be used for multiple heaps if
so desired.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-01-10 10:28:04 -05:00
Henrik Brix Andersen
abaf7cc70d drivers: clock_control: lpc: syscon: add MCAN clock support
Add support for the LPC MCAN clock to the LPC SYSCON clock controller
driver.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2022-01-10 12:00:20 +01:00
Henrik Brix Andersen
8af4bb722d drivers: can: rename API functions for better consistency
Rename a few CAN API functions for clarity and consistency with other
Zephyr RTOS APIs.

CAN_DEFINE_MSGQ() becomes CAN_MSGQ_DEFINE() to match K_MSGQ_DEFINE().

can_attach_isr() becomes can_add_rx_filter() since a filter callback
function is not an interrupt service routine (although it is called in
isr context). The word "attach" is replaced with "add" since filters are
added, not attached. This matches the terminology used is other Zephyr
APIs better.

can_detach() becomes can_remove_rx_filter() to pair with
can_add_rx_filter().

can_attach_msgq() becomes can_add_rx_filter_msgq() and documentation is
updated to mention its relationship with can_add_rx_filter().

can_register_state_change_isr() becomes can_set_state_change_callback()
since a state change callback function is not an interrupt service
routine (although it is called in isr context). The word "register" is
replaced with "set" since only one state change callback can be in
place.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-01-10 10:44:37 +01:00
Tomasz Bursztyka
479215100d spi: Grab relevant properties from DTS into the operation bitfield
duplex and frame_format where recently added and obviously need to be
grabbed from DTS relevantly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-08 06:28:57 -05:00
Martin Jäger
b710fa0a3c include: drivers: uart: Fix wording and return value docs
Further improvement of Doxygen comments based on PR review comments.

Signed-off-by: Martin Jäger <martin@libre.solar>
2022-01-07 14:01:12 -05:00
Martin Jäger
3a197cad02 include: drivers: uart: Restructure to improve docs
- Introduce Doxygen groups for the different APIs (polling, interrupt-
  driven, asynchronous).
- Hide internal driver API as it confuses the average user.
- Move Async API to the bottom so that the file is ordered from generic
  to more specific/sophisticated functions.

No code was changed.

Signed-off-by: Martin Jäger <martin@libre.solar>
2022-01-07 14:01:12 -05:00
Aleksander Wasaznik
e97413057a Bluetooth: Host: Fix type mismatch in bt_gatt_cancel
`bt_gatt_cancel` takes a `bt_gatt_.._params` pointer. The `params`
pointer is mistakenly passed on to `bt_att_req_cancel`, which expects a
`bt_att_req`.

This change makes bt_gatt_cancel locate the `req` and pass that to
`bt_att_req_cancel`.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
Co-authored-by: Emil Gydesen <Thalley@users.noreply.github.com>
2022-01-07 12:48:52 -05:00
Marc Herbert
61fe69dded sys: device_mmio.h replace <toolchain/common.h> with <toolchain.h>
In include/sys/device_mmio.h, replacing <toolchain/common.h>
fixes the following warning:

$ west build -b qemu_x86  tests/arch/x86/static_idt/

In file included from zephyr/include/toolchain.h:50,
             from zephyr/include/linker/section_tags.h:12,
             from zephyr/include/linker/sections.h:132,
             from zephyr/include/sys/device_mmio.h:19,
             from zephyr/include/drivers/interrupt_controller/loapic.h:14,
             from zephyr/include/drivers/interrupt_controller/sysapic.h:10,
             from zephyr/include/arch/x86/arch.h:231,
             from zephyr/include/arch/cpu.h:15,
             from zephyr/tests/arch/x86/static_idt/src/test_stubs.S:17:
zephyr/include/toolchain/gcc.h:61: error: BUILD_ASSERT redefined [-Werror]
   61 | #define BUILD_ASSERT(EXPR, MSG...) _Static_assert(EXPR, "" MSG)
      |
In file included from zephyr/include/sys/device_mmio.h:18,
             from zephyr/include/drivers/interrupt_controller/loapic.h:14,
             from zephyr/include/drivers/interrupt_controller/sysapic.h:10,
             from zephyr/include/arch/x86/arch.h:231,
             from zephyr/include/arch/cpu.h:15,
             from zephyr/tests/arch/x86/static_idt/src/test_stubs.S:17:
zephyr/include/toolchain/common.h:165: note: this is the location of the
  previous definition
  165 | #define BUILD_ASSERT(EXPR, MSG...) \

<toolchain.h> provides a compiler-specific BUILD_ASSERT.
<toolchain/common.h> provides a generic, fallback BUILD_ASSERT and
should probably never be included directly.

Thanks to Gerard Marull-Paretas for recommending this fix.

Related to commit af20208cd9 ("devices: mark device MMIO declarations
to boot/pinned sections") that added #include <linker/sections.h>

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2022-01-07 12:47:31 -05:00
Krzysztof Chruscinski
bd8cc594d9 lib: os: mpsc_pbuf: Add const to mpsc_pbuf_free argument
Added const qualifier to argument in a function.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-01-07 18:47:19 +01:00
Peter Mitsis
48f516469a kernel: Fix typo in macro name
Fixes a typo in the macro ARCH_DYMANIC_OBJ_K_THREAD_ALIGNMENT
so that DYMANIC becomes DYNAMIC.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2022-01-07 11:20:46 -05:00
Torsten Rasmussen
77a7615eb2 linker: update posix linker template, linker.ld
The function `zephyr_linker_sources()` states:
> When placing into NOINIT, RWDATA, RODATA, ROM_START, the contents of
> the files will be placed inside an output section, so assume the
> section definition is already present.

However, in the posix linker.ld template the NOINIT, RWDATA, RODATA, and
ROM_START was not placed inside a pre-defined output section, which
means that linker scripts created for native_posix when
`zephyr_linker_sources()` is used are invalid

This result in the following failure:
> /usr/bin/ld:zephyr/linker_zephyr_prebuilt.cmd:81: syntax error
> collect2: error: ld returned 1 exit status

This PR fixes this issue be predefining output sections according to
the documented behavior.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-01-07 17:00:28 +01:00
Tomasz Bursztyka
4090962386 drivers/interrupt_controller: Add source id to VT-D interrupt remap
Change the API and apply that change where relevant.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Tomasz Bursztyka
345e122dd2 arch/x86: Add a function to retrieve ID from ACPI's DMAR
This will be necessary to get IOAPIC and HPET source ids for VT-D.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Tomasz Bursztyka
149cef11ce drivers/interrupt_controller: VT-D may manipulate the cache
Depending on a VT-D capability, it might be necessary to flush objects
from the cache.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Tomasz Bursztyka
25640f65c9 drivers/interrupt_controller: VT-D IRTE table should be 4kb aligned
As specified by the IRTA location.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Tomasz Bursztyka
2c904b379b drivers/interrupt_controller: Adding QI support in VT-D
Looks like it's mandatory to invalidate the Interrupt Entry Cache in
VT-D and the only way to do so is to enable Queued Interface.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Tomasz Bursztyka
640e651cd8 drivers/interrupt_controller: Add fault event support on Intel VT-D
IR faults are non-recoverable, so it's good to know why. Thus let's
handle the fault event and print the fault.

Other faults are printed as well.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Tomasz Bursztyka
2efd874dcc drivers/interrupt_controller: Make IOAPIC VT-D aware when relevant
If VT-D's interrupt remapping is in place, all IOAPIC RTEs need to get
remapped as well (or then they will be simply blocked).

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Tomasz Bursztyka
edef8e6b0d drivers/interrupt_controller: Expanding VT-D public API
Adding a way to pre-install the irg/vector on an irte and a way to get
an irte based on irq/vector.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Tomasz Bursztyka
1a1bc0d242 drivers/interrupt_controller: Make VT-D remap generic and handle flags
This will not only be used by MSI remapping but by all relevant
interrupts.

Fix also IRTE settings:
- handle x2apic for destination id
- destination mode is always logical (as for IOAPIC)

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Tomasz Bursztyka
e2b4f7e50f drivers/interrupt_controller: Fix VT-D EIME value
It's the 11th bit and not 11.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Tomasz Bursztyka
4047b793c8 drivers/interrupt_controller: Generate proper MSI address on VT-D
SHV bit depends on the number of vectors allocated.
If it's facing a multi-vector MSI array, it will set the bit.
If not the bit must be 0.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Tomasz Bursztyka
6ed593f861 drivers/pcie: Extending parameters to pcie_msi_map
n_vector will be necessary for VT-D actually.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Tomasz Bursztyka
5b3d94510c arch/x86: Implementing ARCH_PCIE_IRQ_CONNECT for ia32 and intel64
While this does not change anything for ia32, this is fixing the chicken
& egg issue on intel64 if (and only if) interrupt remapping is enabled
so pcie_connect_dynamic_irq() is to be called properly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Tomasz Bursztyka
b5ad9739df drivers/pcie: Add a marco for fixed or MSI IRQ
This is meant to be called by drivers on PCIe BUS with a fixed (from
DTS) IRQ or an MSI one. I.e.: all drivers without a runtime IRQ
detection/allocation.

The arch-specific macro is required to be implemented relevantly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Tomasz Bursztyka
b5fecc5ff8 drivers/pcie: Add a function for dynamic PCIe IRQ connection
The is meant to fix a chicken & egg issue with MSI interrupt remapping.
Currently, drivers first connect the irq (by-passing any possible MSI
remapping), so the IRQ ends-up being remapped at the IOAPIC level which
is not what we want.

So adding a dedicated function to properly handle this case. This is
valid only for runtime dynamic IRQ connection obviously.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Tomasz Bursztyka
fbb2f1511c drivers/pcie: Add a function to know MSI/MSI-x support of an endpoint
And since it does yet another round of pcie_get_cap() on PCIE_MSI_CAP_ID
and PCIE_MSIX_CAP_ID, let's factorize that into a utility function and
change the relevant places to use that function instead.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Gerard Marull-Paretas
8d04deb2d9 device: improve (z_)device_is_ready docs
Improve the documentation so that both z_device_is_ready and
device_is_ready are consistent with each other. Information about PM has
been removed since device_is_ready does not take into account the PM
status of a device.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-07 10:41:23 -05:00
Gerard Marull-Paretas
0b0435a96c device: deprecate (z_)device_usable_check
The functionality provided by device_usable_check is already provided by
device_is_ready. The (z_)device_usable_check APIs have been
re-implemented using the (z_)device_is_ready APIs and have been marked
as deprecated.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-07 10:41:23 -05:00
Gerard Marull-Paretas
8b3560a119 drivers: clock_control: use device_is_ready
device_usable_check() can return 0 or -ENODEV, so using device_is_ready
is equivalent if we return -ENODEV when the device is not ready.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-07 10:41:23 -05:00
Gerard Marull-Paretas
47bfb6fb4c device: implement device_is_ready as syscall
Instead of using device_usable_check() syscall, implement a new syscall
for device_is_ready that uses z_device_is_ready underneath.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-07 10:41:23 -05:00
Gerard Marull-Paretas
b2b8fdf539 device: s/z_device_ready/z_device_is_ready
Rename z_device_ready to z_device_is_ready. Function name suggests a
boolean result this way, in line with other functions (e.g.
device_is_ready).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-07 10:41:23 -05:00
Immo Birnbaum
131a5dfd62 arch: arm: aarch32: fix section alignment behind rodata region start marker
Fix for issue 39978. This commit assigns the __rodata_region_start marker
to the ROMABLE region prior to the inclusion of linker/common-rom.ld,
linker/thread-local-storage.ld and linker/cplusplus-rom.ld. Prior to this
fix, the __rodata_region_start marker was properly aligned and indicated
the expected memory location for the start of the rodata section and
similar sections, but it was disconnected from the ROMABLE region into
which the subsequent sections are being integrated, resulting in placement
of those sections right behind the previous section in the ROMABLE region
and therefore at addresses below the __rodata_region_start marker.

For the sake of consistent behaviour, the end marker of the text region
has been modified accordingly.

Signed-off-by: Immo Birnbaum <Immo.Birnbaum@weidmueller.com>
2022-01-07 07:58:43 -06:00
Jakub Rzeszutko
d4559f53fa lib: getopt: rework and extend getopt library
Getopt has been rework in this way that calling it does not require
extra state parameter and its execution is thread safe.
Global parameters describing the state of the getopt function have been
made available to ensure full API compatibility in using this library.
However, referencing these global variables directly is not thread
safe. In order to get the state of the getopt function for the thread
that is currently using it, call: getopt_state_get();

Extended the library with getopt_long and getopt_long_only functions.

Moved getopt libary from utils to posix.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2022-01-06 21:26:59 +01:00
Immo Birnbaum
cd13e25bb3 arch: arm: aarch32: linker file fix for OCM
Fix the mapping of the sections to be located in the On-Chip
Memory so that the OCM memory region name always matches that
of the chosen OCM DT node's memory-region attribute.

Signed-off-by: Immo Birnbaum <Immo.Birnbaum@weidmueller.com>
2022-01-06 11:56:48 -05:00
Krzysztof Chruscinski
4100c57faa shell: Fix immediate logging case
When logging is using immediate mode then logging messages
can be processed from any context, including interrupt context.
z_shell_fprintf was asserting in that case since it allowed to
be called from interrupt context only when logging was in panic
mode. However, shell works in the same way when logging is in
immediate mode as in panic mode.

Renamed internal shell flag from panic_mode to sync_mode. Flag
is also set when shell log backend is started in synchronous
mode (immediate logging) which prevents assertion.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-01-05 14:58:46 -05:00
Chris McDonald
f882d43b56 sys/util: Stricter bytecpy impl
The docstring for this function states that it is guaranteed to perform
a copy byte by byte, but this is not true in general without a
`volatile` storage type on the casted pointer.

Signed-off-by: Chris McDonald <cjmcdonald@chromium.org>
2022-01-04 20:52:16 -05:00
Gerard Marull-Paretas
996a708abd drivers: interrupt_controller: initial support for GD32 EXTI
Add initial support for the GigaDevice External Interrupt Controller.
This driver is required to manage GPIO interrupts. Only EXTI lines 0 to
15 are supported for now (no LVD, RTC, etc.). Driver can be extended in
the future to add support for extra EXTI lines.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2022-01-04 20:49:00 -05:00
Krzysztof Chruscinski
194c0acdfd logging: Add option to have tag which is prepended to all messages
Tag can be changed at runtime. Feature is enabled by setting
maximum tag length to positive value. Additionally, default
tag can be configured in Kconfig.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-01-04 14:57:31 -06:00
Jedrzej Ciupis
fcda8699cb drivers: timer: extend nrf_rtc_timer
This commit introduces the following changes:

* nrf_rtc_timer is extended with a capability to handle RTC overflow,
allowing it to operate on absolute RTC ticks, rather than relative
ticks.
* overflow handling is ZLI-proof and relies on the sys clock
handler being executed twice every RTC counter's overflow.
* callbacks are given an absolute RTC tick value as a parameter instead
of CC register's value. The absolute RTC tick value is the RTC counter
value set during CC channel configuration extended to 64 bits.
* in case the timer's target time is in the past or is the current tick,
the timer fires as soon as possible, however still from the RTC's ISR
context.
* in case an active timer is set again with the same target time, it is
not scheduled again - only its event data is updated. Otherwise, the
timer is scheduled as usual.
* a scheduled timer can be aborted.
* system clock functions are now using 64 bit values internally.

Signed-off-by: Andrzej Kuroś <andrzej.kuros@nordicsemi.no>
Signed-off-by: Jedrzej Ciupis <jedrzej.ciupis@nordicsemi.no>
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Signed-off-by: Paweł Kwiek <pawel.kwiek@nordicsemi.no>
2022-01-04 17:44:32 +01:00
Piotr Pryga
3b5c1efc16 Bluetooth: host: Align usage of cte_type in DF host implementation
The CTE type is used in two ways by HCI layer:
1) single value representing particular CTE type: AoA, AoD 1 us,
  AoD 2 us
2) bit-filed where bits 0-2 represent particular CTE types AoA
  AoD 1 us, AoD 2 us

The bit-field is used to inform Controller about allowed types
of CTE, hence single value carries more than one value.
To avoid confusion between these use cases in code that refers
to case 1) all named cte_type (singular form). For case 2)
cte_types (plural form) is used.

There is an enumeration that is used for both cases:
bt_df_cte_type. For cte_type only single value from the
enumeration may be assigned to variable except
BT_DF_CTE_TYPE_NONE and BT_DF_CTE_TYPE_ALL.
For cte_types all enum members may be used. Ocasionally
BT_DF_CTE_TYPE_NONE may be excluded. If that is true,
it is described in code documentation.

Thanks to that applications are released from requirement
to include hci.h header file.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-01-04 16:02:40 +01:00
Piotr Pryga
b76b5750ee Bluetooth: host: Add API to HCI CTE conn request enable procedure
There were no implementation for HCI_LE_Connection_CTE_Request_Enable
command from BT 5.3 Core specification.

The PR adds implementation and API to be used by applications.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-01-04 16:02:40 +01:00
Emil Gydesen
b78cd855b8 Bluetooth: GATT: Add BT_GATT_WRITE_FLAG_EXECUTE flag
Add the BT_GATT_WRITE_FLAG_EXECUTE flag that indicates
whether a write callback is from an ATT execute write.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-01-04 09:05:23 -05:00
Piotr Pryga
87448f99fe Bluetooth: host: Add host API to run conn CTE TX params set
Add host API to allow execution of HCI_LE_Set_Connection_CTE_Transmit_-
Parameters HCI command.

The commit also provides a refactored version of hci_df_set_conn_cte_tx-
_param function. The function was aligned to other hci_df_XXX functions
structure with separated parameters validation and preparation of
command object before it is send to controller.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
Co-authored-by: Emil Gydesen <Thalley@users.noreply.github.com>
2022-01-04 14:12:15 +01:00