1 /*
2  * Copyright (c) 2018 Nordic Semiconductor ASA
3  * Copyright (c) 2015 Runtime Inc
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #include <string.h>
9 #include <stdio.h>
10 #include <stdbool.h>
11 
12 #include <errno.h>
13 
14 #include <zephyr/settings/settings.h>
15 #include "settings/settings_file.h"
16 #include <zephyr/kernel.h>
17 
18 extern struct k_mutex settings_lock;
19 
20 bool settings_subsys_initialized;
21 
22 void settings_init(void);
23 
24 int settings_backend_init(void);
25 
settings_subsys_init(void)26 int settings_subsys_init(void)
27 {
28 
29 	int err = 0;
30 
31 	k_mutex_lock(&settings_lock, K_FOREVER);
32 
33 	if (!settings_subsys_initialized) {
34 		settings_init();
35 
36 		err = settings_backend_init();
37 
38 		if (!err) {
39 			settings_subsys_initialized = true;
40 		}
41 	}
42 
43 	k_mutex_unlock(&settings_lock);
44 
45 	return err;
46 }
47