mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-05-28 17:11:23 +02:00
Added phy_save() and phy_load() to save and load PHY.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
27
src/fs/phy.c
27
src/fs/phy.c
@@ -58,7 +58,7 @@ int phy_serialize_data(const phy_data_t *phy, uint8_t *data, uint16_t *len) {
|
|||||||
*len = p - data;
|
*len = p - data;
|
||||||
return PICOKEY_OK;
|
return PICOKEY_OK;
|
||||||
}
|
}
|
||||||
#include <stdio.h>
|
|
||||||
int phy_unserialize_data(const uint8_t *data, uint16_t len, phy_data_t *phy) {
|
int phy_unserialize_data(const uint8_t *data, uint16_t len, phy_data_t *phy) {
|
||||||
if (!phy || !data || !len) {
|
if (!phy || !data || !len) {
|
||||||
return PICOKEY_ERR_NULL_PARAM;
|
return PICOKEY_ERR_NULL_PARAM;
|
||||||
@@ -103,14 +103,25 @@ int phy_unserialize_data(const uint8_t *data, uint16_t len, phy_data_t *phy) {
|
|||||||
|
|
||||||
int phy_init() {
|
int phy_init() {
|
||||||
memset(&phy_data, 0, sizeof(phy_data_t));
|
memset(&phy_data, 0, sizeof(phy_data_t));
|
||||||
if (file_has_data(ef_phy)) {
|
return phy_load();
|
||||||
const uint8_t *data = file_get_data(ef_phy);
|
}
|
||||||
int ret = phy_unserialize_data(data, file_get_size(ef_phy), &phy_data);
|
|
||||||
if (ret != PICOKEY_OK) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
int phy_save() {
|
||||||
|
uint8_t tmp[PHY_MAX_SIZE] = {0};
|
||||||
|
uint16_t tmp_len = 0;
|
||||||
|
int ret = phy_serialize_data(&phy_data, tmp, &tmp_len);
|
||||||
|
if (ret != PICOKEY_OK) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
file_put_data(ef_phy, tmp, tmp_len);
|
||||||
|
low_flash_available();
|
||||||
|
return PICOKEY_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int phy_load() {
|
||||||
|
if (file_has_data(ef_phy)) {
|
||||||
|
return phy_unserialize_data(file_get_data(ef_phy), file_get_size(ef_phy), &phy_data);
|
||||||
|
}
|
||||||
return PICOKEY_OK;
|
return PICOKEY_OK;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ typedef struct phy_data {
|
|||||||
extern int phy_serialize_data(const phy_data_t *phy, uint8_t *data, uint16_t *len);
|
extern int phy_serialize_data(const phy_data_t *phy, uint8_t *data, uint16_t *len);
|
||||||
extern int phy_unserialize_data(const uint8_t *data, uint16_t len, phy_data_t *phy);
|
extern int phy_unserialize_data(const uint8_t *data, uint16_t len, phy_data_t *phy);
|
||||||
extern int phy_init();
|
extern int phy_init();
|
||||||
|
extern int phy_save();
|
||||||
|
extern int phy_load();
|
||||||
extern phy_data_t phy_data;
|
extern phy_data_t phy_data;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user