Rename eeprom files to more generic data_storage
This is a preparation for futur non-volatile storage in flash memory.
This commit is contained in:
+1
-1
@@ -5,11 +5,11 @@ zephyr_include_directories(.)
|
||||
target_sources(app PRIVATE
|
||||
bat_charger.cpp
|
||||
data_nodes.cpp
|
||||
data_storage.cpp
|
||||
daq.cpp
|
||||
daq_driver.c
|
||||
device_status.cpp
|
||||
dcdc.cpp
|
||||
eeprom.cpp
|
||||
half_bridge.cpp
|
||||
hardware.cpp
|
||||
leds.cpp
|
||||
|
||||
+4
-4
@@ -26,7 +26,7 @@ LOG_MODULE_REGISTER(data_nodes, CONFIG_DATA_NODES_LOG_LEVEL);
|
||||
#include "thingset.h"
|
||||
#include "hardware.h"
|
||||
#include "dcdc.h"
|
||||
#include "eeprom.h"
|
||||
#include "data_storage.h"
|
||||
|
||||
const char manufacturer[] = "Libre Solar";
|
||||
const char device_type[] = DT_PROP(DT_PATH(pcb), type);
|
||||
@@ -456,7 +456,7 @@ static DataNode data_nodes[] = {
|
||||
|
||||
TS_NODE_EXEC(0xE1, "reset", &reset_device, ID_EXEC, TS_ANY_RW),
|
||||
TS_NODE_EXEC(0xE2, "bootloader-stm", &start_stm32_bootloader, ID_EXEC, TS_ANY_RW),
|
||||
TS_NODE_EXEC(0xE3, "save-settings", &eeprom_store_data, ID_EXEC, TS_ANY_RW),
|
||||
TS_NODE_EXEC(0xE3, "save-settings", &data_storage_write, ID_EXEC, TS_ANY_RW),
|
||||
|
||||
TS_NODE_EXEC(0xEE, "auth", &thingset_auth, 0, TS_ANY_RW),
|
||||
TS_NODE_STRING(0xEF, "Password", auth_password, sizeof(auth_password), 0xEE, TS_ANY_RW, 0),
|
||||
@@ -501,7 +501,7 @@ void data_nodes_update_conf()
|
||||
changed = true; // temporary hack
|
||||
|
||||
if (changed) {
|
||||
eeprom_store_data();
|
||||
data_storage_write();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -517,7 +517,7 @@ void data_nodes_init()
|
||||
uint64_to_base32(id64, device_id, sizeof(device_id), alphabet_crockford);
|
||||
#endif
|
||||
|
||||
eeprom_restore_data();
|
||||
data_storage_read();
|
||||
if (battery_conf_check(&bat_conf_user)) {
|
||||
battery_conf_overwrite(&bat_conf_user, &bat_conf, &charger);
|
||||
}
|
||||
|
||||
@@ -4,23 +4,22 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "eeprom.h"
|
||||
|
||||
#ifdef CONFIG_EEPROM
|
||||
#include "data_storage.h"
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <device.h>
|
||||
#include <drivers/eeprom.h>
|
||||
|
||||
#include "mcu.h"
|
||||
#include "thingset.h"
|
||||
#include "data_nodes.h"
|
||||
#include "helper.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define EEPROM_HEADER_SIZE 8 // bytes
|
||||
#ifndef UNIT_TEST
|
||||
|
||||
K_MUTEX_DEFINE(eeprom_buf_lock);
|
||||
#include <device.h>
|
||||
|
||||
K_MUTEX_DEFINE(data_buf_lock);
|
||||
|
||||
// Buffer used by store and restore functions (must be word-aligned for hardware CRC calculation)
|
||||
static uint8_t buf[512] __aligned(sizeof(uint32_t));
|
||||
@@ -59,13 +58,21 @@ uint32_t _calc_crc(const uint8_t *buf, size_t len)
|
||||
return CRC->DR;
|
||||
}
|
||||
|
||||
#endif /* UNIT_TEST */
|
||||
|
||||
#ifdef CONFIG_EEPROM
|
||||
|
||||
#include <drivers/eeprom.h>
|
||||
|
||||
#define EEPROM_HEADER_SIZE 8 // bytes
|
||||
|
||||
// EEPROM layout:
|
||||
// bytes 0-1: Version number
|
||||
// bytes 2-3: number of data bytes
|
||||
// bytes 4-7: CRC32
|
||||
// byte 8: start of data
|
||||
|
||||
void eeprom_restore_data()
|
||||
void data_storage_read()
|
||||
{
|
||||
int err;
|
||||
|
||||
@@ -88,7 +95,7 @@ void eeprom_restore_data()
|
||||
// buf_header[4], buf_header[5], buf_header[6], buf_header[7]);
|
||||
|
||||
if (version == DATA_NODES_VERSION && len <= sizeof(buf)) {
|
||||
k_mutex_lock(&eeprom_buf_lock, K_FOREVER);
|
||||
k_mutex_lock(&data_buf_lock, K_FOREVER);
|
||||
err = eeprom_read(eeprom_dev, EEPROM_HEADER_SIZE, buf, len);
|
||||
|
||||
//printf("Data (len=%d): ", len);
|
||||
@@ -102,20 +109,20 @@ void eeprom_restore_data()
|
||||
printf("EEPROM: CRC of data not correct, expected 0x%x (data_len = %d)\n",
|
||||
(unsigned int)crc, len);
|
||||
}
|
||||
k_mutex_unlock(&eeprom_buf_lock);
|
||||
k_mutex_unlock(&data_buf_lock);
|
||||
}
|
||||
else {
|
||||
printf("EEPROM: Empty or data layout version changed\n");
|
||||
}
|
||||
}
|
||||
|
||||
void eeprom_store_data()
|
||||
void data_storage_write()
|
||||
{
|
||||
int err;
|
||||
|
||||
const struct device *eeprom_dev = device_get_binding("EEPROM_0");
|
||||
|
||||
k_mutex_lock(&eeprom_buf_lock, K_FOREVER);
|
||||
k_mutex_lock(&data_buf_lock, K_FOREVER);
|
||||
|
||||
int len = ts.bin_pub(buf + EEPROM_HEADER_SIZE, sizeof(buf) - EEPROM_HEADER_SIZE, PUB_NVM);
|
||||
uint32_t crc = _calc_crc(buf + EEPROM_HEADER_SIZE, len);
|
||||
@@ -143,21 +150,19 @@ void eeprom_store_data()
|
||||
printf("EEPROM: Write error.\n");
|
||||
}
|
||||
}
|
||||
k_mutex_unlock(&eeprom_buf_lock);
|
||||
k_mutex_unlock(&data_buf_lock);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void eeprom_store_data() {;}
|
||||
void eeprom_restore_data() {;}
|
||||
void data_storage_write() {;}
|
||||
void data_storage_read() {;}
|
||||
|
||||
#endif
|
||||
|
||||
#include "helper.h"
|
||||
|
||||
void eeprom_update()
|
||||
void data_storage_update()
|
||||
{
|
||||
if (uptime() % EEPROM_UPDATE_INTERVAL == 0 && uptime() > 0) {
|
||||
eeprom_store_data();
|
||||
if (uptime() % DATA_UPDATE_INTERVAL == 0 && uptime() > 0) {
|
||||
data_storage_write();
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,10 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef EEPROM_H
|
||||
#define EEPROM_H
|
||||
#ifndef DATA_STORAGE_H_
|
||||
#define DATA_STORAGE_H_
|
||||
|
||||
#define EEPROM_UPDATE_INTERVAL (6*60*60) // update every 6 hours
|
||||
#define DATA_UPDATE_INTERVAL (6*60*60) // update every 6 hours
|
||||
|
||||
/**
|
||||
* @file
|
||||
@@ -18,16 +18,16 @@
|
||||
/**
|
||||
* Store current charge controller data to EEPROM
|
||||
*/
|
||||
void eeprom_store_data();
|
||||
void data_storage_write();
|
||||
|
||||
/**
|
||||
* Restore charge controller data from EEPROM and write to variables in RAM
|
||||
*/
|
||||
void eeprom_restore_data();
|
||||
void data_storage_read();
|
||||
|
||||
/**
|
||||
* Stores data to EEPROM every 6 hours (can be called regularly)
|
||||
*/
|
||||
void eeprom_update();
|
||||
void data_storage_update();
|
||||
|
||||
#endif /* EEPROM_H */
|
||||
#endif /* DATA_STORAGE_H_ */
|
||||
+2
-2
@@ -23,7 +23,7 @@ LOG_MODULE_REGISTER(dcdc, CONFIG_DCDC_LOG_LEVEL);
|
||||
#include "device_status.h"
|
||||
#include "helper.h"
|
||||
#include "half_bridge.h"
|
||||
#include "eeprom.h"
|
||||
#include "data_storage.h"
|
||||
#include "setup.h"
|
||||
|
||||
extern DeviceStatus dev_stat;
|
||||
@@ -324,7 +324,7 @@ void Dcdc::fuse_destruction()
|
||||
|
||||
if (counter > 20) { // wait 20s to be able to send out data
|
||||
LOG_ERR("Charge controller fuse destruction called!\n");
|
||||
eeprom_store_data();
|
||||
data_storage_write();
|
||||
half_bridge_stop();
|
||||
half_bridge_init(50, 0, 0, 0.98); // reset safety limits to allow 0% duty cycle
|
||||
half_bridge_set_duty_cycle(0);
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@
|
||||
#include "pwm_switch.h" // PWM charge controller
|
||||
#include "bat_charger.h" // battery settings and charger state machine
|
||||
#include "daq.h" // ADC using DMA and conversion to measurement values
|
||||
#include "eeprom.h" // external I2C EEPROM
|
||||
#include "data_storage.h" // non-volatile data storage (e.g. EEPROM)
|
||||
#include "load.h" // load and USB output management
|
||||
#include "leds.h" // LED switching using charlieplexing
|
||||
#include "device_status.h" // log data (error memory, min/max measurements, etc.)
|
||||
@@ -120,7 +120,7 @@ void main(void)
|
||||
leds_update_soc(charger.soc, false);
|
||||
#endif
|
||||
|
||||
eeprom_update();
|
||||
data_storage_update();
|
||||
|
||||
t_start += 1000;
|
||||
k_sleep(K_TIMEOUT_ABS_MS(t_start));
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
#include "pwm_switch.h" // PWM charge controller
|
||||
#include "bat_charger.h" // battery settings and charger state machine
|
||||
#include "daq.h" // ADC using DMA and conversion to measurement values
|
||||
#include "eeprom.h" // external I2C EEPROM
|
||||
#include "data_storage.h" // external I2C EEPROM
|
||||
#include "load.h" // load and USB output management
|
||||
#include "leds.h" // LED switching using charlieplexing
|
||||
#include "device_status.h" // log data (error memory, min/max measurements, etc.)
|
||||
|
||||
Reference in New Issue
Block a user