1
0
mirror of https://github.com/CovidBraceletPrj/CovidBracelet.git synced 2024-06-08 05:37:53 +02:00

Add storage initialization

This commit is contained in:
H1ghBre4k3r 2021-01-26 16:14:58 +01:00 committed by Patrick Rathje
parent c554a89711
commit ae76b43ae0
3 changed files with 89 additions and 43 deletions

View File

@ -6,63 +6,67 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include <sys/printk.h>
#include <bluetooth/hci.h> #include <bluetooth/hci.h>
#include <random/rand32.h> #include <random/rand32.h>
#include <sys/printk.h>
#include "exposure-notification.h"
#include "covid_types.h"
#include "contacts.h" #include "contacts.h"
#include "gatt_service.h"
#include "covid.h" #include "covid.h"
#include "covid_types.h"
#include "exposure-notification.h"
#include "gatt_service.h"
#include "io.h" #include "io.h"
#include "storage.h"
void main(void) void main(void) {
{ int err = 0;
int err = 0; printk("Starting Covid Contact Tracer\n");
printk("Starting Covid Contact Tracer\n");
// first init everything // first init everything
// Use custom randomization as the mbdet_tls context initialization messes with the Zeyhr BLE stack. // Use custom randomization as the mbdet_tls context initialization messes with the Zeyhr BLE stack.
err = en_init(sys_csrand_get); err = en_init(sys_csrand_get);
if (err) { if (err) {
printk("Cyrpto init failed (err %d)\n", err); printk("Cyrpto init failed (err %d)\n", err);
return; return;
} }
printk("init contacts\n"); printk("init contacts\n");
init_contacts(); init_contacts();
err = init_io(); err = init_io();
if(err){ if (err) {
printk("Button init failed (err %d)\n", err); printk("Button init failed (err %d)\n", err);
return; return;
} }
/* Initialize the Bluetooth Subsystem */ /* Initialize the Bluetooth Subsystem */
err = bt_enable(NULL); err = bt_enable(NULL);
if (err) { if (err) {
printk("Bluetooth init failed (err %d)\n", err); printk("Bluetooth init failed (err %d)\n", err);
return; return;
} }
printk("Bluetooth initialized\n"); printk("Bluetooth initialized\n");
err = init_gatt(); err = init_gatt();
if (err) { if (err) {
printk("init gatt failed(err %d)\n", err); printk("init gatt failed(err %d)\n", err);
return; return;
} }
err = init_covid(); err = init_covid();
if (err) { if (err) {
printk("init covid failed (err %d)\n", err); printk("init covid failed (err %d)\n", err);
return; return;
} }
do{ err = init_storage();
do_covid(); if (err) {
do_gatt(); printk("init storage failed (err %d)\n", err);
} while (1); return;
}
do {
do_covid();
do_gatt();
} while (1);
} }

33
src/storage.c Normal file
View File

@ -0,0 +1,33 @@
#include <device.h>
#include <drivers/flash.h>
#include <fs/nvs.h>
#include <power/reboot.h>
#include <storage/flash_map.h>
#include <string.h>
#include <zephyr.h>
#include "storage.h"
// Maybe use this as param for init function
#define SEC_COUNT 10
static struct nvs_fs fs;
int init_storage(void) {
int rc = 0;
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);
if (rc) {
return rc;
}
fs.sector_size = info.size;
fs.sector_count = SEC_COUNT;
rc = nvs_init(&fs, DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL);
if (rc) {
return rc;
}
}

9
src/storage.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef STORAGE_H
#define STORAGE_H
/**
* Initialize the storage api.
*/
int init_storage(void);
#endif