Background
----------
Nowadays, devices rely on the `init.h` (i.e. `SYS_INIT`) infrastructure
to get initialized automatically. The `init.h` infrastructure is a basic
mechanism that allows to register an init function when the system is
initialized (before `main`). It provides with multiple initialization
levels: `PRE_KERNEL_*`, `POST_KERNEL`, etc., and within each level a
numeric priority (0-99). Using this information, each registered init
entry is sorted by the linker so that the Kernel can later iterate over
them in the correct order. This all sounds nice and simple, but when it
comes to devices, this mechanism has proven to be insufficient.
Before starting with the changes proposed in this patch, let's first dig
into the implementation details of the current model. When devices are
defined, using any of the `DEVICE_*DEFINE` macros, they also create an
init entry using the internal `init.h` APIs (see
`Z_DEVICE_INIT_ENTRY_DEFINE`). This entry, stores a pointer to the
device init call and to the device itself. As the reader can imagine,
this implies a coupling between `init.h` and `device.h`. The only link
between a device and an init entry is the device pointer stored in the
init entry. This allows the Kernel init machinery to call the init
function with the right device pointer. However, there is no direct
relationship between a device and its init function, that is, `struct
device` does not keep the device init function reference. This is not a
problem nowadays, but it could be a problem if features like deferred
initialization or init/de-init have to be implemented. However, in
reality, this is a _secondary_ problem. The most problematic issue we
have today is that devices are mixed with `SYS_INIT` calls. They are all
part of the same init block, and are treated equally. So for example,
one can theoretically have a system where the init sequence can be like:
```
- PRE_KERNEL_1
- init call 1
- device 0
- init call 2
- init call 3
- device 1
- device 2
- init call 4
- PRE_KERNEL_2
- init call 5
- device 3
...
```
This is problematic because:
(1) Init calls can depend on devices, but dependency is not tracked
anywhere. So the user must check that init priorities are correct to
avoid runtime failures.
(2) Device drivers can have multiple instances, and each instance may
require a different set of priorities, while `SYS_INIT` calls are
singletons.
(3) Devices don't likely need so many init priorities (`SMP`?
`APPLICATION`?)
(1) is particularly important because init calls do not have a specific
purpose. They usage ranges from SoC init code, to system services. So
it's _unpredictable_ what can happen in there. (2) is a tangential
topic, actually not fixed by this patch, even though it helps. (3) is
more of a post-patch cleanup we need.
So, what does this patch propose...?
------------------------------------
**First, this patch is still a HACK, so please, focus on the description
rather than with the implementation**
So it's about providing devices with their own init infrastructure,
minimizing the coupling with init.h. This patch groups devices in a
separate section, but, keeps the same init levels as before. Therefore,
the list above would look like:
```
/* devices */
- PRE_KERNEL_1
- device 0
- device 1
- device 2
- PRE_KERNEL_2
- device 3
...
/* init calls */
- PRE_KERNEL_1
- init call 1
- init call 2
- init call 3
- init call 4
- PRE_KERNEL_2
- init call 5
...
```
This means that **it is no longer possible** to mix init calls and
devices within the same level. So how does it work now? Within each
level, devices are initialized first, then init calls. It is done this
way because I believe it is init calls who depend on devices and not
vice versa. I may be wrong, and so the whole proposal would need a
rework. So the init order would look like:
```
- PRE_KERNEL_1
- device 0
- device 1
- device 2
- init call 1
- init call 2
- init call 3
- init call 4
- PRE_KERNEL_2
- device 3
- init call 5
...
```
Why does this matter for future development?
--------------------------------------------
First, we have devices grouped at least on a level basis. This means
that we could likely start using devicetree ordinals, by reducing the
source of problems to the init level only. We can also re-think device
init levels (probably init levels as well, hey `PRE_KERNEL_1/2`). For
example, there could be pre-kernel and post-kernel devices only. The
other side effect of this change is that `struct device` stores the
device init call, so we can potentially do things like defer device
initialization or implement things like init/de-init. They all come with
their own complexity, of course, but this patch could be a step forward.
Problems
--------
This is a breaking change. Sorry, guys, another one to the list. The API
does not change, so builds should continue to work. However, the system
changes its behavior, so if anyone was relying on mixed init call/device
sequences, things will break. This is why it is important to analyze
lots of use cases before moving forward with this proposal.
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
Device handles are only meant to identify a device, nothing else.
Reserve negative values for any potential future use, though.
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
Introduce hwinfo driver for Texas Instruments SimpleLink CC13xx/CC26xx
SOC series, with support for retrieving device's ID and cause of reset.
By default, the pre-programmed, 8-bytes length IEEE MAC address is used
for device's ID, with option ('HWINFO_CC13XX_CC26XX_USE_BLE_MAC') for
use 6-bytes length BLE MAC instead. By default, read-only values stored
in FCFG (Factory Configuration) are used but additional Kconfig option
('HWINFO_CC13XX_CC26XX_ALWAYS_USE_FACTORY_DEFAULT') is also provided,
which allows to use values from writable CCFG (Customer Configuration)
area. In all cases, device ID value is provided in big-endian which
matches what TI's UniFlash tool returns.
For reset cause, 'SysCtrlResetSourceGet()' function from TI's driver
library is used and its value is mapped to Zephyr's implementation.
Importantly, only root cause of reset is available on CC13xx/CC26xx
platform as described in MCU Technical Reference Manual ('RESET_SRC'
field in 'RESETCTL' register):
"Shows the root cause of the last system reset. More than the
reported reset source can have been active during the last
system reset but only the root cause is reported."
Signed-off-by: Piotr Dymacz <pepe2k@gmail.com>
Moving from APPLICATION level to POST_KERNEL and keeping both parent and
child on the same level is causing problems, so fix this by putting them
on different priorities in POST_KERNEL.
Also, this sample runs fine in qemu, so make it the integration
platform.
Fixes#62772
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Use clock control API to retrieve the module's frequency and
update the boards using it to provide the source clocks.
Signed-off-by: Manuel Argüelles <manuel.arguelles@nxp.com>
Deprecate the advanced CAN timing devicetree properties in favor of setting
advanced timing parameters from application code.
The advanced timing properties are giving in number of time quanta (Tq) and
requires reverse-calculation to find a suitable CAN clock divider. The
resulting bitrate error is compared against a threshold in the driver
initialization code, but the application is not able to retrieve it.
Forcing applications to use the CAN timing APIs directly instead makes it
up to the application to determine if the bitrate error is acceptable or
not.
The deprecated properties are:
- prop-seg
- phase-seg1
- phase-seg2
- prop-seg-data
- phase-seg1-data
- phase-seg2-data
Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Add CAN stats for MCAN drivers.
Update MCAN drivers to use CAN_DEVICE_DT_INST_DEFINE
which initialises and registers CAN stats if enabled.
Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
A few attributes isn't cloned togerder with pkt.
This commit add missing part.
Additionally, because the `eof` flag in net_pkt structure is
avilable unconditionally hence `#if defined(CONFIG_NET_SOCKETS)`
guard has been removed form setter and getter functions for
this flag.
Signed-off-by: Marcin Gasiorek <marcin.gasiorek@nordicsemi.no>
Because `forwarding` flag is available unconditionally the compilation
guard has no make sense. Additionally this flag and related getter and
setter can be used for e.g. IPv4 packets forwarding in future, which
would be impossible looking at `NET_ROUTE` dependencies.
Signed-off-by: Marcin Gasiorek <marcin.gasiorek@nordicsemi.no>
In net_pkt structure couple of flags are no longer used.
Flag pkt_queued can be removed permanently togeter with setter
and getter functions.
Second flag sent_or_eof has been renamed because it is still
used partially only for indicating EOF. Additionally unused setter
and getter for 'sent_' part of this flag are removed.
Signed-off-by: Marcin Gasiorek <marcin.gasiorek@nordicsemi.no>
A file just named `init.c` is not that descriptive inside of a project
that has a lot of files of already. Rename to `ethos_u.c`.
Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
The Ethos-U driver was using IRQ_DIRECT_CONNECT. This is not what the
driver needs as this will not detect a context switch when coming out
of the isr, and this is needed as the isr will release a semaphore.
Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
Maximize BIG event length to extend upto ISO interval, and
allow PTO and Control subevents to be pre-emptible.
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Calculate Broadcast ISO event overheads due to extended and
periodic advertising events.
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Updates possible return errors for fs mgmt file upload, to clarify
when a provided path is on a read-only filesystem or if the mount
point does not exist.
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
The native simulator final link can garbage collect unused
symbols. So let's ensure the symbol to keep ones are indeed
kept even if not used.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
The test fixture used an invalid struct for the param
due to a renaming of the struct in another commit.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
We don't need to have two different sets of Zephyr-specific default
values overriding one another, it's confusing.
Note this commit makes NO functional change, the effective defaults stay
the same. It does however make it easier to change defaults in the
future.
Signed-off-by: Marc Herbert <marc.herbert@intel.com>
In spec:
The LwM2M Client MUST reject any LwM2M Server operation on
the Security Object (ID: 0) with an "4.01 Unauthorized" response
code.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
With bootstrap one function is unused. Fix by changing
ifdef to if (IS_ENABLED()) so linker can drop it.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
If autoinit is not enebled, it is allowed to build a few backends and
initialize a proper one in runtime.
Check number of backends only if autoinit is enabled.
Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
The header file contains mixture of functions and static arrays.
Replacing static arrays to functions.
Initialize functions in C file.
Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
This migrates the subsys code samples to the new Sphinx code-sample
extension, making it easier to find relevant samples when browsing
API reference.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Fix missing Coded PHY implementation conditional compile
causing compile error when disabling Coded PHY support in
SoCs that have radio that support Coded PHY.
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Revert EVENT_OVERHEAD_START_US value for Coded PHY support,
needed to pass LL/DDI/SCN/BV-21-C and LL/DDI/SCN/BV-25-C.
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Reduce number of successive calls to ticker_job() by
disabling mayflies in the ULL_HIGH priority, enqueue
ticker_yield_abs() and ticker_start() before re-enabling
so that single ticker_job() handles both yield and start.
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Fix short prepare handling when more than one event is
enqueued in the pipeline and the short prepare is placed at
the end of the prepare pipeline.
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Fix ticks_slot_window use in Observer, do not use for
unreserved continuous scanning, and do not use when scanning
on both 1M and Coded PHY simultaneously.
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Use ticker_ticks_diff_get consistently when calculating
difference between ticker ticks when determining short
prepare requests.
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Use the state/role context parameter in prepare pipeline
to identify the preempt timeout that was setup.
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
These change are reverted as part of fixing regression
failure in LL/DDI/SCN/BV-21-C and LL/DDI/SCN/BV-25-C.
This reverts commit 0d54ca8761.
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Add phandle prop to reference any regulator that must
be enabled in order for the LPADC to function as intended.
Change LPADC driver to use this property if present.
LPADC on LPC55S36 depends on VREF peripheral, enable for this platform.
Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
Add node for VREF0 peripheral to LPC55S3X SOC DT
Clock VREF peripheral if status = okay in DT
Enable VREF on lpcxpresso55s36
Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
Add binding, include header, and driver for NXP VREF IP block.
NXP VREF is an internal voltage reference generator on some SOCs
that fits well with the regulator API in zephyr.
Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
The script does not play well with armclang binariest at the moment.
Disable the automatic invocation when running with armclang, at least
until this is investigated and fixed.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>