zephyr/modules
Gerard Marull-Paretas a5fd0d184a init: remove the need for a dummy device pointer in SYS_INIT functions
The init infrastructure, found in `init.h`, is currently used by:

- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices

They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:

```c
struct init_entry {
	int (*init)(const struct device *dev);
	/* only set by DEVICE_*, otherwise NULL */
	const struct device *dev;
}
```

As a result, we end up with such weird/ugly pattern:

```c
static int my_init(const struct device *dev)
{
	/* always NULL! add ARG_UNUSED to avoid compiler warning */
	ARG_UNUSED(dev);
	...
}
```

This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:

```c
static int my_init(void)
{
	...
}
```

This is achieved using a union:

```c
union init_function {
	/* for SYS_INIT, used when init_entry.dev == NULL */
	int (*sys)(void);
	/* for DEVICE*, used when init_entry.dev != NULL */
	int (*dev)(const struct device *dev);
};

struct init_entry {
	/* stores init function (either for SYS_INIT or DEVICE*)
	union init_function init_fn;
	/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
	 * to know which union entry to call.
	 */
	const struct device *dev;
}
```

This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.

**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

init: convert SYS_INIT functions to the new signature

Conversion scripted using scripts/utils/migrate_sys_init.py.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

manifest: update projects for SYS_INIT changes

Update modules with updated SYS_INIT calls:

- hal_ti
- lvgl
- sof
- TraceRecorderSource

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: devicetree: devices: adjust test

Adjust test according to the recently introduced SYS_INIT
infrastructure.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: kernel: threads: adjust SYS_INIT call

Adjust to the new signature: int (*init_fn)(void);

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 14:28:07 +00:00
..
canopennode init: remove the need for a dummy device pointer in SYS_INIT functions 2023-04-12 14:28:07 +00:00
fatfs modules: fs: Add reentrant zephyr support 2023-03-13 11:58:57 +01:00
hal_ethos_u modules: add an Arm Ethos-U HAL module 2022-11-15 14:47:43 +01:00
hal_gigadevice soc: gd32a50x: introduce gd32a50x soc series 2023-01-12 21:45:38 +01:00
hal_infineon modules: hal_infineon: Added abstraction-rtos asset for Infenion Cat1 2023-04-11 15:48:02 -04:00
hal_nordic init: remove the need for a dummy device pointer in SYS_INIT functions 2023-04-12 14:28:07 +00:00
hal_nxp hal: nxp: Check Kconfig before including HAL 2022-11-01 21:41:55 -05:00
hal_rpi_pico modules: hal_rpi_pico: Enable DMA driver 2023-03-22 09:33:52 +01:00
liblc3 modules: liblc3: Rename the module for consistency 2022-08-22 20:40:59 +02:00
littlefs treewide: Use CONFIG_*_ENDIAN instead of __BYTE_ORDER__ 2022-10-28 19:23:46 +09:00
loramac-node lora: compile drivers based on devicetree 2023-03-31 09:20:22 +02:00
lz4
mbedtls init: remove the need for a dummy device pointer in SYS_INIT functions 2023-04-12 14:28:07 +00:00
nanopb
openthread net: openthread: Remove duplicate option TREL in openthread. 2023-04-05 12:48:54 +00:00
segger init: remove the need for a dummy device pointer in SYS_INIT functions 2023-04-12 14:28:07 +00:00
tflite-micro treewide: Update deprecated CONFIG_LIB_CPLUSPLUS usages 2023-01-13 17:42:55 -05:00
thrift modules: add thrift module 2023-02-09 20:30:21 +09:00
TraceRecorder
trusted-firmware-a modules: tfa: integrate trusted-firmware-a 2022-09-09 16:36:37 +00:00
trusted-firmware-m init: remove the need for a dummy device pointer in SYS_INIT functions 2023-04-12 14:28:07 +00:00
uoscore-uedhoc modules: Add uoscore-uedhoc repository 2022-08-12 16:17:59 +02:00
zcbor modules: zcbor: Fix ZCBOR_ASSERT kconfig typo 2022-09-08 15:30:47 +00:00
Kconfig modules: add thrift module 2023-02-09 20:30:21 +09:00
Kconfig.altera
Kconfig.atmel
Kconfig.cmsis modules/cmsis: Change libc requirement to allow picolibc 2023-01-26 10:10:45 +00:00
Kconfig.cmsis_dsp math: Introduce a DSP basicmath subsystem with a cmsis backend 2022-12-02 20:15:55 +01:00
Kconfig.cmsis_nn
Kconfig.cypress
Kconfig.eos_s3
Kconfig.esp32 kconfig: add esp32s3 into configuration 2023-02-27 19:41:33 +01:00
Kconfig.imx drivers: pinctrl: refactor pin control support for imx rt 2022-05-12 16:57:17 -05:00
Kconfig.infineon drivers: spi: Add xmc4xxx driver 2023-03-03 17:20:17 +01:00
Kconfig.libmetal
Kconfig.lvgl lvgl: change misleading options for color depth 2023-03-01 06:36:25 -05:00
Kconfig.mcuboot_bootutil
Kconfig.mcux nxp_imx: rt: add XBARA Inter-Peripheral Crossbar Switch Kconfig option 2022-07-01 16:23:11 +00:00
Kconfig.microchip
Kconfig.nuvoton
Kconfig.open-amp
Kconfig.s32 soc: arm: introduce NXP S32Z/E support 2022-10-14 09:51:14 +02:00
Kconfig.silabs
Kconfig.simplelink soc: arm: ti_simplelink: Add support for TI CC13X2X7 SoC series 2023-03-21 16:03:43 -04:00
Kconfig.sof
Kconfig.st
Kconfig.stm32 drivers: flash: stm32 ospi driver for the stm32h5x 2023-04-07 08:33:51 +00:00
Kconfig.sysbuild sysbuild: support Zephyr modules 2023-03-09 09:25:00 +01:00
Kconfig.syst
Kconfig.telink
Kconfig.tinycrypt
Kconfig.vega
Kconfig.wurthelektronik modules: Added hal_wurthelektronik module. 2022-08-31 21:47:58 +00:00
Kconfig.xtensa
modules.cmake