samples/subsys/settings: FS and native_posix support
Added support for native_posix targets. Added setting FS back-end initialization which is used by native_posix targets. The test harness was adapted to the fact that key-value pairs read-out order might be different for each back-end when call settings_load(). Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
This commit is contained in:
parent
d518f6a784
commit
8fa5b44389
6 changed files with 98 additions and 4 deletions
6
samples/subsys/settings/boards/native_posix.conf
Normal file
6
samples/subsys/settings/boards/native_posix.conf
Normal file
|
@ -0,0 +1,6 @@
|
|||
# Enable the LittleFS file system.
|
||||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_FILE_SYSTEM_LITTLEFS=y
|
||||
CONFIG_SETTINGS_FS=y
|
||||
CONFIG_SETTINGS_FS_DIR="/ff/settings"
|
||||
CONFIG_SETTINGS_FS_FILE="/ff/settings/run"
|
25
samples/subsys/settings/boards/native_posix.overlay
Normal file
25
samples/subsys/settings/boards/native_posix.overlay
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Jan Van Winkel <jan.van_winkel@dxplore.eu>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/delete-node/ &storage_partition;
|
||||
/delete-node/ &scratch_partition;
|
||||
|
||||
&flash0 {
|
||||
/*
|
||||
* For more information, see:
|
||||
* http://docs.zephyrproject.org/latest/guides/dts/index.html#flash-partitions
|
||||
*/
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
storage_partition: partition@70000 {
|
||||
label = "storage";
|
||||
reg = <0x00070000 0x8000>;
|
||||
};
|
||||
};
|
||||
};
|
6
samples/subsys/settings/boards/native_posix_64.conf
Normal file
6
samples/subsys/settings/boards/native_posix_64.conf
Normal file
|
@ -0,0 +1,6 @@
|
|||
# Enable the LittleFS file system.
|
||||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_FILE_SYSTEM_LITTLEFS=y
|
||||
CONFIG_SETTINGS_FS=y
|
||||
CONFIG_SETTINGS_FS_DIR="/ff/settings"
|
||||
CONFIG_SETTINGS_FS_FILE="/ff/settings/run"
|
25
samples/subsys/settings/boards/native_posix_64.overlay
Normal file
25
samples/subsys/settings/boards/native_posix_64.overlay
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Jan Van Winkel <jan.van_winkel@dxplore.eu>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/delete-node/ &storage_partition;
|
||||
/delete-node/ &scratch_partition;
|
||||
|
||||
&flash0 {
|
||||
/*
|
||||
* For more information, see:
|
||||
* http://docs.zephyrproject.org/latest/guides/dts/index.html#flash-partitions
|
||||
*/
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
storage_partition: partition@70000 {
|
||||
label = "storage";
|
||||
reg = <0x00070000 0x8000>;
|
||||
};
|
||||
};
|
||||
};
|
|
@ -5,7 +5,7 @@ tests:
|
|||
sample.subsys.settings:
|
||||
tags: settings
|
||||
timeout: 10
|
||||
platform_whitelist: qemu_x86
|
||||
platform_whitelist: qemu_x86 native_posix native_posix_64
|
||||
harness: console
|
||||
harness_config:
|
||||
type: multi_line
|
||||
|
@ -16,14 +16,16 @@ tests:
|
|||
- "[.]*Can\\'t to load the <alpha/length> value as expected"
|
||||
- "<gamma> = 0 \\(default\\)"
|
||||
- "# iteration 1"
|
||||
- "<alpha/length/2> = 59"
|
||||
- "# iteration 2"
|
||||
- "<alpha/length/1> = 42"
|
||||
- "# iteration 3"
|
||||
- "<alpha/beta/voltage> = -3100"
|
||||
- "# iteration 4"
|
||||
- "<alpha/beta/source> = abcd"
|
||||
- "# iteration 5"
|
||||
- "<alpha/length/2> = 55"
|
||||
- "<alpha/length/1> = 45"
|
||||
- "<alpha/angle/1> = 5"
|
||||
- "<alpha/beta/source> is not compatible with the application"
|
||||
- "<alpha/beta/voltage> = -3125"
|
||||
- "direct.length = 100"
|
||||
- "direct.length_1 = 46"
|
||||
- "direct.length_2 = 54"
|
||||
|
|
|
@ -12,6 +12,11 @@
|
|||
#include <errno.h>
|
||||
#include <sys/printk.h>
|
||||
|
||||
#if IS_ENABLED(CONFIG_SETTINGS_FS)
|
||||
#include <fs/fs.h>
|
||||
#include <fs/littlefs.h>
|
||||
#endif
|
||||
|
||||
#define GAMMA_DEFAULT_VAl 0
|
||||
#define FAIL_MSG "fail (err %d)\n"
|
||||
#define SECTION_BEGIN_LINE \
|
||||
|
@ -414,6 +419,31 @@ static void example_initialization(void)
|
|||
{
|
||||
int rc;
|
||||
|
||||
#if IS_ENABLED(CONFIG_SETTINGS_FS)
|
||||
FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(cstorage);
|
||||
|
||||
/* mounting info */
|
||||
static struct fs_mount_t littlefs_mnt = {
|
||||
.type = FS_LITTLEFS,
|
||||
.fs_data = &cstorage,
|
||||
.storage_dev = (void *)DT_FLASH_AREA_STORAGE_ID,
|
||||
.mnt_point = "/ff"
|
||||
};
|
||||
|
||||
rc = fs_mount(&littlefs_mnt);
|
||||
if (rc != 0) {
|
||||
printk("mounting littlefs error: [%d]\n", rc);
|
||||
} else {
|
||||
|
||||
rc = fs_unlink(CONFIG_SETTINGS_FS_FILE);
|
||||
if ((rc != 0) && (rc != -ENOENT)) {
|
||||
printk("can't delete config file%d\n", rc);
|
||||
} else {
|
||||
printk("FS initiqalized: OK\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
rc = settings_subsys_init();
|
||||
if (rc) {
|
||||
printk("settings subsys initialization: fail (err %d)\n", rc);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue