zephyr/lib/os
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
..
assert.c includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h> 2022-09-05 16:31:47 +02:00
base64.c
bitarray.c os: bitarray.c: Address -Wextra warnings 2023-02-21 15:07:20 +01:00
cbprintf_complete.c sys: util: migrate all files to DIV_ROUND_UP 2023-04-11 12:00:37 +02:00
cbprintf_nano.c
cbprintf_packaged.c os: cbprintf: Address -Wextra warnings 2023-02-20 09:50:12 +01:00
cbprintf.c
CMakeLists.txt lib: hashmap: Move hash table files lib/hashmap 2023-03-02 12:03:07 -05:00
crc7_sw.c
crc8_sw.c
crc16_sw.c
crc32_sw.c
crc32c_sw.c
crc_shell.c posix: getopt: move declarations to unistd.h 2022-12-04 14:51:52 +01:00
dec.c
fdtable.c lib: os: Fix note on fdtable.c 2023-01-11 10:54:42 +01:00
heap_listener.c
heap-validate.c lib/os: use generic mem stats structure for heap 2022-07-12 13:59:26 +00:00
heap.c ARC: qemu: disable test where we trigger ARC QEMU bug #54720 2023-02-17 08:50:37 +09:00
heap.h
hex.c
json.c lib: os: fix armclang compiler warnings with is*() functions 2023-03-31 09:19:02 +02:00
Kconfig lib: hashmap: Move hash table files lib/hashmap 2023-03-02 12:03:07 -05:00
Kconfig.cbprintf lib: os: cbprintf: Mechanism for detecting %p in static package 2022-09-19 10:14:23 +00:00
Kconfig.heap lib/os: add statistics tracking to mem_blocks 2022-07-12 13:59:26 +00:00
mem_blocks.c includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h> 2022-09-05 16:31:47 +02:00
mpsc_pbuf.c lib: os: mpsc_pbuf: Fix concurrency issues 2022-12-29 10:33:29 +01:00
multi_heap.c lib: add mising braces to single line if statements 2022-07-06 11:00:45 -04:00
mutex.c
notify.c
onoff.c
p4wq.c init: remove the need for a dummy device pointer in SYS_INIT functions 2023-04-12 14:28:07 +00:00
printk.c
rb.c
reboot.c lib: os: reboot: include zephyr/cache.h 2023-01-24 14:35:49 +00:00
ring_buffer.c
sem.c
shared_multi_heap.c includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h> 2022-09-05 16:31:47 +02:00
spsc_pbuf.c spsc_pbuf: Fix cache wb in spsc_pbuf_free 2022-12-07 10:21:33 +00:00
thread_entry.c
timeutil.c
user_work.c
utf8.c zephyr: Fix n=0 for utf8_lcpy 2022-07-04 15:49:22 +02:00
winstream.c