mirror of
https://github.com/CovidBraceletPrj/CovidBracelet.git
synced 2024-11-12 22:48:52 +01:00
Add support for external onboard-storage
This commit is contained in:
parent
f1bee6fbe2
commit
9ddbe15170
@ -9,6 +9,20 @@
|
||||
#include "sequencenumber.h"
|
||||
#include "storage.h"
|
||||
|
||||
|
||||
// Get external flash device
|
||||
#if (CONFIG_SPI_NOR - 0) || \
|
||||
DT_NODE_HAS_STATUS(DT_INST(0, jedec_spi_nor), okay)
|
||||
#define FLASH_DEVICE DT_LABEL(DT_INST(0, jedec_spi_nor))
|
||||
#define FLASH_NAME "JEDEC SPI-NOR"
|
||||
#elif (CONFIG_NORDIC_QSPI_NOR - 0) || \
|
||||
DT_NODE_HAS_STATUS(DT_INST(0, nordic_qspi_nor), okay)
|
||||
#define FLASH_DEVICE DT_LABEL(DT_INST(0, nordic_qspi_nor))
|
||||
#define FLASH_NAME "JEDEC QSPI-NOR"
|
||||
#else
|
||||
#error Unsupported flash driver
|
||||
#endif
|
||||
|
||||
// Maybe use this as param for init function
|
||||
#define SEC_COUNT 8U
|
||||
|
||||
@ -67,7 +81,7 @@ int init_contact_storage(void) {
|
||||
struct flash_pages_info info;
|
||||
// define the nvs file system
|
||||
fs.offset = FLASH_AREA_OFFSET(storage);
|
||||
rc = flash_get_page_info_by_offs(device_get_binding(DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL), fs.offset, &info);
|
||||
rc = flash_get_page_info_by_offs(device_get_binding(FLASH_DEVICE), fs.offset, &info);
|
||||
|
||||
if (rc) {
|
||||
// Error during retrieval of page information
|
||||
@ -76,7 +90,7 @@ int init_contact_storage(void) {
|
||||
fs.sector_size = info.size;
|
||||
fs.sector_count = SEC_COUNT;
|
||||
|
||||
rc = nvs_init(&fs, DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL);
|
||||
rc = nvs_init(&fs, FLASH_DEVICE);
|
||||
if (rc) {
|
||||
// Error during nvs_init
|
||||
return rc;
|
||||
@ -86,6 +100,7 @@ int init_contact_storage(void) {
|
||||
rc = load_storage_information();
|
||||
|
||||
printk("Currently %d contacts stored!\n", contact_information.count);
|
||||
printk("Space available: %d\n", FLASH_AREA_SIZE(storage));
|
||||
|
||||
return rc;
|
||||
}
|
||||
@ -112,12 +127,12 @@ int add_contact(contact_t* src) {
|
||||
}
|
||||
|
||||
// TODO handle start and end
|
||||
// TODO lome: do we need this?
|
||||
int delete_contact(record_sequence_number_t sn) {
|
||||
storage_id_t id = convert_sn_to_storage_id(sn);
|
||||
int rc = nvs_delete(&fs, id);
|
||||
if (!rc) {
|
||||
// TODO lome: what happens, if contacts in the middle are deleted?
|
||||
// Magic
|
||||
contact_information.count--;
|
||||
if (sn_equal(sn, get_oldest_sequence_number())) {
|
||||
contact_information.oldest_contact = sn_increment(contact_information.oldest_contact);
|
||||
|
@ -1,4 +1,6 @@
|
||||
|
||||
/delete-node/ &storage_partition;
|
||||
|
||||
/ {
|
||||
buttons {
|
||||
compatible = "gpio-keys";
|
||||
@ -12,3 +14,16 @@
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
&mx25r64 {
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
partition@0 {
|
||||
label = "storage";
|
||||
reg = <0x0000000 0x00300000>;
|
||||
};
|
||||
};
|
||||
};
|
15
zephyr/nrf52840dk_nrf52840.overlay
Normal file
15
zephyr/nrf52840dk_nrf52840.overlay
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
/delete-node/ &storage_partition;
|
||||
|
||||
&mx25r64 {
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
partition@0 {
|
||||
label = "storage";
|
||||
reg = <0x0000000 0x00300000>;
|
||||
};
|
||||
};
|
||||
};
|
@ -20,6 +20,21 @@ CONFIG_FLASH=y
|
||||
CONFIG_FLASH_PAGE_LAYOUT=y
|
||||
|
||||
CONFIG_NVS=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_NVS_LOG_LEVEL_DBG=y
|
||||
CONFIG_MPU_ALLOW_FLASH_WRITE=y
|
||||
|
||||
# CONFIG_DISK_ACCESS=y
|
||||
CONFIG_MAIN_STACK_SIZE=2048
|
||||
|
||||
# Let __ASSERT do its job
|
||||
CONFIG_DEBUG=y
|
||||
|
||||
CONFIG_LOG=y
|
||||
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FLASH_MAP=y
|
||||
CONFIG_FLASH_PAGE_LAYOUT=y
|
||||
|
||||
# Need this when storage is on MX25R64
|
||||
CONFIG_NORDIC_QSPI_NOR=y
|
||||
CONFIG_NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
|
||||
|
Loading…
Reference in New Issue
Block a user