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
*/
#include <sys/printk.h>
#include <bluetooth/hci.h>
#include <random/rand32.h>
#include <sys/printk.h>
#include "exposure-notification.h"
#include "covid_types.h"
#include "contacts.h"
#include "gatt_service.h"
#include "covid.h"
#include "covid_types.h"
#include "exposure-notification.h"
#include "gatt_service.h"
#include "io.h"
#include "storage.h"
void main(void)
{
int err = 0;
printk("Starting Covid Contact Tracer\n");
void main(void) {
int err = 0;
printk("Starting Covid Contact Tracer\n");
// 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);
if (err) {
printk("Cyrpto init failed (err %d)\n", err);
return;
}
if (err) {
printk("Cyrpto init failed (err %d)\n", err);
return;
}
printk("init contacts\n");
init_contacts();
err = init_io();
if(err){
printk("Button init failed (err %d)\n", err);
return;
}
printk("init contacts\n");
init_contacts();
err = init_io();
if (err) {
printk("Button init failed (err %d)\n", err);
return;
}
/* Initialize the Bluetooth Subsystem */
err = bt_enable(NULL);
if (err) {
printk("Bluetooth init failed (err %d)\n", err);
return;
}
/* Initialize the Bluetooth Subsystem */
err = bt_enable(NULL);
if (err) {
printk("Bluetooth init failed (err %d)\n", err);
return;
}
printk("Bluetooth initialized\n");
printk("Bluetooth initialized\n");
err = init_gatt();
if (err) {
printk("init gatt failed(err %d)\n", err);
return;
}
err = init_gatt();
if (err) {
printk("init gatt failed(err %d)\n", err);
return;
}
err = init_covid();
if (err) {
printk("init covid failed (err %d)\n", err);
return;
}
err = init_covid();
if (err) {
printk("init covid failed (err %d)\n", err);
return;
}
do{
do_covid();
do_gatt();
} while (1);
err = init_storage();
if (err) {
printk("init storage failed (err %d)\n", err);
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