blob: cdb2b16df5bd61ba97706358a195e73342206a6e [file] [log] [blame]
Andrzej Puzdrowski94ff3392018-02-02 14:30:56 +01001/*
2 * Copyright (c) 2018 Nordic Semiconductor ASA
3 * Copyright (c) 2015 Runtime Inc
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
Andrzej Puzdrowski94ff3392018-02-02 14:30:56 +01008#include <string.h>
9#include <stdio.h>
10#include <stdbool.h>
11
12#include <errno.h>
13
Fabio Baltierie24314f2022-05-25 16:31:28 +010014#include <zephyr/settings/settings.h>
Andrzej Puzdrowski94ff3392018-02-02 14:30:56 +010015#include "settings/settings_file.h"
Gerard Marull-Paretas5113c142022-05-06 11:12:04 +020016#include <zephyr/zephyr.h>
Andrzej Puzdrowski94ff3392018-02-02 14:30:56 +010017
Radoslaw Koppelb748a542019-06-03 10:23:34 +020018
19bool settings_subsys_initialized;
20
Andrzej Puzdrowski94ff3392018-02-02 14:30:56 +010021void settings_init(void);
22
François Delawarde94451b22019-04-02 11:06:05 +020023int settings_backend_init(void);
24
Andrzej Puzdrowski9fe30532018-04-16 12:48:37 +020025int settings_subsys_init(void)
Andrzej Puzdrowski94ff3392018-02-02 14:30:56 +010026{
Radoslaw Koppelb748a542019-06-03 10:23:34 +020027
François Delawarde94451b22019-04-02 11:06:05 +020028 int err = 0;
Johan Hedberg72050f42018-05-16 18:56:18 +030029
Radoslaw Koppelb748a542019-06-03 10:23:34 +020030 if (settings_subsys_initialized) {
Johan Hedberg72050f42018-05-16 18:56:18 +030031 return 0;
32 }
33
Andrzej Puzdrowski94ff3392018-02-02 14:30:56 +010034 settings_init();
35
François Delawarde94451b22019-04-02 11:06:05 +020036 err = settings_backend_init(); /* func rises kernel panic once error */
Johan Hedberg72050f42018-05-16 18:56:18 +030037
38 if (!err) {
Radoslaw Koppelb748a542019-06-03 10:23:34 +020039 settings_subsys_initialized = true;
Johan Hedberg72050f42018-05-16 18:56:18 +030040 }
41
42 return err;
Andrzej Puzdrowski94ff3392018-02-02 14:30:56 +010043}