Andrzej Puzdrowski | 94ff339 | 2018-02-02 14:30:56 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 Nordic Semiconductor ASA |
| 3 | * Copyright (c) 2015 Runtime Inc |
| 4 | * |
| 5 | * SPDX-License-Identifier: Apache-2.0 |
| 6 | */ |
| 7 | |
Andrzej Puzdrowski | 94ff339 | 2018-02-02 14:30:56 +0100 | [diff] [blame] | 8 | #include <string.h> |
| 9 | #include <stdio.h> |
| 10 | #include <stdbool.h> |
| 11 | |
| 12 | #include <errno.h> |
| 13 | |
Fabio Baltieri | e24314f | 2022-05-25 16:31:28 +0100 | [diff] [blame] | 14 | #include <zephyr/settings/settings.h> |
Andrzej Puzdrowski | 94ff339 | 2018-02-02 14:30:56 +0100 | [diff] [blame] | 15 | #include "settings/settings_file.h" |
Gerard Marull-Paretas | 5113c14 | 2022-05-06 11:12:04 +0200 | [diff] [blame] | 16 | #include <zephyr/zephyr.h> |
Andrzej Puzdrowski | 94ff339 | 2018-02-02 14:30:56 +0100 | [diff] [blame] | 17 | |
Radoslaw Koppel | b748a54 | 2019-06-03 10:23:34 +0200 | [diff] [blame] | 18 | |
| 19 | bool settings_subsys_initialized; |
| 20 | |
Andrzej Puzdrowski | 94ff339 | 2018-02-02 14:30:56 +0100 | [diff] [blame] | 21 | void settings_init(void); |
| 22 | |
François Delawarde | 94451b2 | 2019-04-02 11:06:05 +0200 | [diff] [blame] | 23 | int settings_backend_init(void); |
| 24 | |
Andrzej Puzdrowski | 9fe3053 | 2018-04-16 12:48:37 +0200 | [diff] [blame] | 25 | int settings_subsys_init(void) |
Andrzej Puzdrowski | 94ff339 | 2018-02-02 14:30:56 +0100 | [diff] [blame] | 26 | { |
Radoslaw Koppel | b748a54 | 2019-06-03 10:23:34 +0200 | [diff] [blame] | 27 | |
François Delawarde | 94451b2 | 2019-04-02 11:06:05 +0200 | [diff] [blame] | 28 | int err = 0; |
Johan Hedberg | 72050f4 | 2018-05-16 18:56:18 +0300 | [diff] [blame] | 29 | |
Radoslaw Koppel | b748a54 | 2019-06-03 10:23:34 +0200 | [diff] [blame] | 30 | if (settings_subsys_initialized) { |
Johan Hedberg | 72050f4 | 2018-05-16 18:56:18 +0300 | [diff] [blame] | 31 | return 0; |
| 32 | } |
| 33 | |
Andrzej Puzdrowski | 94ff339 | 2018-02-02 14:30:56 +0100 | [diff] [blame] | 34 | settings_init(); |
| 35 | |
François Delawarde | 94451b2 | 2019-04-02 11:06:05 +0200 | [diff] [blame] | 36 | err = settings_backend_init(); /* func rises kernel panic once error */ |
Johan Hedberg | 72050f4 | 2018-05-16 18:56:18 +0300 | [diff] [blame] | 37 | |
| 38 | if (!err) { |
Radoslaw Koppel | b748a54 | 2019-06-03 10:23:34 +0200 | [diff] [blame] | 39 | settings_subsys_initialized = true; |
Johan Hedberg | 72050f4 | 2018-05-16 18:56:18 +0300 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | return err; |
Andrzej Puzdrowski | 94ff339 | 2018-02-02 14:30:56 +0100 | [diff] [blame] | 43 | } |