Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Kconfig.defaults.bluetooth
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ if INFUSE_SDK_BLUETOOTH
configdefault BT_DEVICE_NAME
default "Infuse-IoT"

# A dedicated workqueue for ECC crypto (that Infuse-IoT does not use by default)
# and GATT database hash (that only runs once on boot) is overkill. Disabling this
# workqueue saves >1kB of RAM.
configdefault BT_LONG_WQ
default n

# Uncoded LE Data Packet Format:
#
# | Preamble | Access | PDU (2 to 257 bytes) | CRC |
Expand Down
13 changes: 13 additions & 0 deletions include/infuse/fs/kv_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ struct kv_bluetooth_addr {
struct bt_addr_le address;
} __packed;

/* exFAT disk information */
struct kv_exfat_disk_info {
/* Disk block count */
uint32_t block_count;
/* Disk block size */
uint32_t block_size;
} __packed;

/* Fixed global location of the device */
struct kv_fixed_location {
/* Location */
Expand Down Expand Up @@ -242,6 +250,8 @@ enum kv_builtin_id {
KV_KEY_REBOOTS = 0,
/* Bluetooth advertising address */
KV_KEY_BLUETOOTH_ADDR = 1,
/* exFAT disk information */
KV_KEY_EXFAT_DISK_INFO = 2,
/* Fixed global location of the device */
KV_KEY_FIXED_LOCATION = 10,
/* WiFi network name */
Expand Down Expand Up @@ -289,6 +299,7 @@ enum kv_builtin_id {
enum kv_builtin_size {
_KV_KEY_REBOOTS_SIZE = sizeof(struct kv_reboots),
_KV_KEY_BLUETOOTH_ADDR_SIZE = sizeof(struct kv_bluetooth_addr),
_KV_KEY_EXFAT_DISK_INFO_SIZE = sizeof(struct kv_exfat_disk_info),
_KV_KEY_FIXED_LOCATION_SIZE = sizeof(struct kv_fixed_location),
_KV_KEY_EPACKET_UDP_PORT_SIZE = sizeof(struct kv_epacket_udp_port),
_KV_KEY_LTE_MODEM_IMEI_SIZE = sizeof(struct kv_lte_modem_imei),
Expand All @@ -298,6 +309,7 @@ enum kv_builtin_size {
/* Types of builtin KV definitions */
#define _KV_KEY_REBOOTS_TYPE struct kv_reboots
#define _KV_KEY_BLUETOOTH_ADDR_TYPE struct kv_bluetooth_addr
#define _KV_KEY_EXFAT_DISK_INFO_TYPE struct kv_exfat_disk_info
#define _KV_KEY_FIXED_LOCATION_TYPE struct kv_fixed_location
#define _KV_KEY_WIFI_SSID_TYPE struct kv_wifi_ssid
#define _KV_KEY_WIFI_PSK_TYPE struct kv_wifi_psk
Expand All @@ -317,6 +329,7 @@ enum kv_builtin_size {
/* Number of KV pairs that can be reflected */
#define KV_REFLECT_NUM ( \
IF_ENABLED(CONFIG_KV_STORE_BLUETOOTH_ADDR, (1 +)) \
IF_ENABLED(CONFIG_KV_STORE_EXFAT_DISK_INFO, (1 +)) \
IF_ENABLED(CONFIG_KV_STORE_FIXED_LOCATION, (1 +)) \
IF_ENABLED(CONFIG_KV_STORE_WIFI_SSID, (1 +)) \
IF_ENABLED(CONFIG_KV_STORE_WIFI_PSK, (1 +)) \
Expand Down
12 changes: 12 additions & 0 deletions scripts/west_commands/templates/kv_store.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@
{"name": "address", "type": "struct bt_addr_le", "description": "Broadcasting address"}
]
},
{
"name": "EXFAT_DISK_INFO",
"key": 2,
"description": "exFAT disk information",
"reflect": true,
"read_only": true,
"default": "y if DATA_LOGGER_EXFAT",
"fields": [
{"name": "block_count", "type": "uint32_t", "description": "Disk block count"},
{"name": "block_size", "type": "uint32_t", "description": "Disk block size"}
]
},
{
"name": "FIXED_LOCATION",
"key": 10,
Expand Down
20 changes: 20 additions & 0 deletions subsys/data_logger/backends/exfat_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <zephyr/storage/disk_access.h>

#include <infuse/time/epoch.h>
#include <infuse/fs/kv_store.h>
#include <infuse/fs/kv_types.h>

#include <ff.h>

Expand Down Expand Up @@ -138,6 +140,24 @@ int logger_exfat_filesystem_common_init(const struct device *dev)
return res == FR_OK ? 0 : -EIO;
}

void logger_exfat_disk_info_store(const struct device *dev)
{
#ifdef CONFIG_KV_STORE_EXFAT_DISK_INFO
const struct dl_exfat_config *config = dev->config;
struct kv_exfat_disk_info disk_info;
uint32_t block_count, block_size;

/* Get disk info */
disk_access_ioctl(config->disk, DISK_IOCTL_GET_SECTOR_COUNT, &block_count);
disk_access_ioctl(config->disk, DISK_IOCTL_GET_SECTOR_SIZE, &block_size);

disk_info.block_count = block_count;
disk_info.block_size = block_size;

(void)KV_STORE_WRITE(KV_KEY_EXFAT_DISK_INFO, &disk_info);
#endif /* CONFIG_KV_STORE_EXFAT_DISK_INFO */
}

const char *logger_exfat_filesystem_claim(const struct device *dev, uint8_t **buf, size_t *buf_size,
k_timeout_t timeout)
{
Expand Down
2 changes: 2 additions & 0 deletions subsys/data_logger/backends/exfat_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ bool logger_exfat_filesystem_is_infuse(const struct device *dev);

int logger_exfat_filesystem_common_init(const struct device *dev);

void logger_exfat_disk_info_store(const struct device *dev);

#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions subsys/data_logger/backends/exfat_multi_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ int logger_exfat_init(const struct device *dev)
f_closedir(&dj);
#endif

/* Store disk info */
logger_exfat_disk_info_store(dev);

/* Setup common data structure */
disk_access_ioctl(config->disk, DISK_IOCTL_GET_SECTOR_COUNT, &data->common.physical_blocks);
data->common.logical_blocks = data->common.physical_blocks;
Expand Down
3 changes: 3 additions & 0 deletions subsys/data_logger/backends/exfat_single_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ int logger_exfat_init(const struct device *dev)
f_closedir(&dj);
#endif

/* Store disk info */
logger_exfat_disk_info_store(dev);

/* Setup common data structure */
data->common.logical_blocks = data->common.physical_blocks;
data->common.block_size = DATA_LOGGER_EXFAT_BLOCK_SIZE;
Expand Down
15 changes: 11 additions & 4 deletions subsys/epacket/interfaces/epacket_bt_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,23 @@

#include <zephyr/bluetooth/bluetooth.h>

#include <infuse/identifiers.h>
#include <infuse/time/epoch.h>
#include <infuse/epacket/interface.h>
#include <infuse/epacket/packet.h>
#include <infuse/epacket/interface/epacket_bt_adv.h>
#include <infuse/identifiers.h>
#include <infuse/task_runner/runner.h>
#include <infuse/time/epoch.h>

#include "epacket_internal.h"

#define DT_DRV_COMPAT embeint_epacket_bt_adv

#ifdef CONFIG_TASK_RUNNER
#define TASK_WORKQ task_runner_work_q()
#else
#define TASK_WORKQ &k_sys_work_q
#endif

LOG_MODULE_REGISTER(epacket_bt_adv, CONFIG_EPACKET_BT_ADV_LOG_LEVEL);

static void adv_set_complete(struct bt_le_ext_adv *adv, struct bt_le_ext_adv_sent_info *info);
Expand Down Expand Up @@ -133,7 +140,7 @@ static void adv_set_complete_worker(struct k_work *work)
* workqueue.
*/
LOG_DBG("Rescheduling work");
k_work_submit(work);
k_work_submit_to_queue(TASK_WORKQ, work);
return;
}

Expand All @@ -157,7 +164,7 @@ static void adv_set_complete_worker(struct k_work *work)

static void adv_set_complete(struct bt_le_ext_adv *adv, struct bt_le_ext_adv_sent_info *info)
{
k_work_submit(&adv_set_complete_work);
k_work_submit_to_queue(TASK_WORKQ, &adv_set_complete_work);
}

static void epacket_bt_adv_send(const struct device *dev, struct net_buf *buf)
Expand Down
7 changes: 7 additions & 0 deletions subsys/fs/kv_store/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ module = KV_STORE
module-str = key-value store
source "subsys/logging/Kconfig.template.log_config"

config KV_STORE_INIT_PRIORITY
int "Flash init priority"
default 55
help
KV store initialization priority. The default value of 55 is
later than the default FLASH_INIT_PRIORITY value (50).

rsource "Kconfig.keys"

endif # KV_STORE
6 changes: 6 additions & 0 deletions subsys/fs/kv_store/Kconfig.keys
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ config KV_STORE_BLUETOOTH_ADDR
help
Bluetooth advertising address

config KV_STORE_EXFAT_DISK_INFO
bool "Enable KV key EXFAT_DISK_INFO"
default y if DATA_LOGGER_EXFAT
help
exFAT disk information

config KV_STORE_FIXED_LOCATION
bool "Enable KV key FIXED_LOCATION"
help
Expand Down
7 changes: 7 additions & 0 deletions subsys/fs/kv_store/kv_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ static struct key_value_slot_definition kv_slots[] = {
.flags = KV_FLAGS_REFLECT,
},
#endif /* CONFIG_KV_STORE_BLUETOOTH_ADDR */
#ifdef CONFIG_KV_STORE_EXFAT_DISK_INFO
{
.key = 2,
.range = 1,
.flags = KV_FLAGS_REFLECT | KV_FLAGS_READ_ONLY,
},
#endif /* CONFIG_KV_STORE_EXFAT_DISK_INFO */
#ifdef CONFIG_KV_STORE_FIXED_LOCATION
{
.key = 10,
Expand Down
2 changes: 1 addition & 1 deletion subsys/fs/kv_store/kv_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,4 @@ int kv_store_init(void)
return rc;
}

SYS_INIT(kv_store_init, POST_KERNEL, 80);
SYS_INIT(kv_store_init, POST_KERNEL, CONFIG_KV_STORE_INIT_PRIORITY);
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <mem.h>
#include <mem.h>

/delete-node/ &storage_partition;

/ {
chosen {
infuse,kv-partition = &storage_partition;
};
};

&flashcontroller0 {
reg = <0x00000000 DT_SIZE_K(2048 + 64)>;
Expand All @@ -16,8 +24,14 @@
#address-cells = <1>;
#size-cells = <1>;

storage: partition@0 {
reg = <0x00000000 DT_SIZE_K(2048 + 64)>;
/* Move storage partition to start so exFAT can take remaining space */
storage_partition: partition@0 {
label = "storage";
reg = < 0x0 0x4000 >;
};

storage: partition@4000 {
reg = <0x00004000 DT_SIZE_K(2048 + 64 - 16)>;
};
};
};
Expand Down
3 changes: 3 additions & 0 deletions tests/subsys/data_logger/backends/exfat_single_file/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ CONFIG_INFUSE_EPOCH_TIME=y
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_ZTEST_STACK_SIZE=4096

CONFIG_NVS=y
CONFIG_KV_STORE=y

# Disk Access
CONFIG_FLASHDISK_LOG_LEVEL_WRN=y

Expand Down
19 changes: 19 additions & 0 deletions tests/subsys/data_logger/backends/exfat_single_file/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <zephyr/pm/device.h>

#include <infuse/data_logger/logger.h>
#include <infuse/fs/kv_store.h>
#include <infuse/fs/kv_types.h>

#include <ff.h>

Expand Down Expand Up @@ -217,6 +219,23 @@ ZTEST(data_logger_exfat, test_device_move)
zassert_equal(FR_NO_FILE, f_stat(filename, &fno));
}

ZTEST(data_logger_exfat, test_kv_disk_info)
{
const struct device *logger = DEVICE_DT_GET(DT_NODELABEL(data_logger_exfat));
struct kv_exfat_disk_info disk_info;

/* Init logger */
zassert_equal(0, logger_exfat_init(logger));

/* Value should exist */
zassert_equal(sizeof(struct kv_exfat_disk_info),
KV_STORE_READ(KV_KEY_EXFAT_DISK_INFO, &disk_info));

/* Values should match disk query */
zassert_equal(sector_count, disk_info.block_count);
zassert_equal(sector_size, disk_info.block_size);
}

static bool test_data_init(const void *global_state)
{
disk_access_ioctl(DISK_NAME, DISK_IOCTL_GET_SECTOR_COUNT, &sector_count);
Expand Down
Loading