Skip to content

Commit

Permalink
firmware/sys/shell_extended: Adding storage network modules default p…
Browse files Browse the repository at this point in the history
…arams
  • Loading branch information
CW-75 committed Oct 20, 2022
1 parent 1bef075 commit 06c258b
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 76 deletions.
36 changes: 32 additions & 4 deletions firmware/default_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* @file
* @name Defaults params for the m4a firmware
* @author xkevin190 <[email protected]>
* @author eduazocar <[email protected]>
*/

#ifndef DEFAULT_PARAMS_H
Expand Down Expand Up @@ -52,18 +53,45 @@ typedef struct {
uint8_t pin : 6; /*!< Input pin -> Max pin 63*/
} sensors_t;

#if ((MODULE_RPL_PROTOCOL) || (DOXYGEN))
/**
* @brief Data type to all network elements, here will saved protocols.
*
*/
typedef struct {
uint8_t mode : 1; /*!< Routing protocol rpl modes (DAG or DODAG)*/
uint8_t : 7; /*!< Reserved bits */
uint8_t id; /*!< Rpl instance id */
} rpl_settings_t;
#endif

typedef struct {
uint8_t routing; /*!< Routing Protocol in use*/
#ifdef MODULE_RPL_PROTOCOL
rpl_settings_t rpl;
#endif
#ifdef MODULE_BORDER_ROUTER
uint8_t br_status : 1;
uint8_t : 7;
#endif
#ifdef MODULE_UNIQUEID
uint8_t uidmode : 1;
uint8_t : 7;
#endif
} settings_net_t;

/**
* @brief struct to save interface data settings.
*/
typedef struct {
uint8_t id;
uint8_t type;
uint8_t id; /*!< Iface id*/
uint8_t type; /*!< Type of interface */
uint16_t channel; /*!< Channel of the radio */
int16_t tx_power; /*!< The transmit power from a radio interface*/
uint16_t freq;
uint16_t freq; /*!< Frequency of radio interface */
} settings_ifaces_t;

#define IF_KEY (uint8_t*)("IFKEY")
#define IF_KEY ("IFKEY")

/**
* @name storage address this address will be the storage keys
Expand Down
4 changes: 4 additions & 0 deletions firmware/sys/shell_extended/se_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ int storage_cmd(int argc, char **argv) {
return 0;
}
if (strcmp(argv[1], "save") == 0) {
/*ToDo: Create a group of options to manage network params*/
stg_save_if_settings();
} else if (strcmp(argv[1], "load") == 0) {
/*ToDo: Create a group of options to manage network params*/
stg_load_if_settings();
} else if (strcmp(argv[1], "show") == 0) {
/*ToDo: Create a group of options to manage network params*/
puts("Todo: show all firmware params saved in mtd storage");
} else if (strcmp(argv[1], "del") == 0) {
/*ToDo: Create a group of options to manage network params*/
stg_del_if_settings();
}
return 0;
Expand Down
45 changes: 15 additions & 30 deletions firmware/sys/storage/include/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,10 @@ extern "C" {
int8_t mtd_start(void);

/**
* @brief Saves any value in any position of mtd_storage.
* @brief removes all content in the mtd_Storage
*
* @param [in] value Any type of value.
* @param [in] len size of @p value that will be saved.
* @param [in] offset reference to an position in mtd_storage.
* @return int8_t
*/
int mtd_save(const void *value, uint32_t len, uint32_t offset);

/**
* @brief Loads any value in any position of mtd_storage.
*
* @param [out] value Any type of value.
* @param [in] len size of @p value that will be loaded.
* @param [in] offset reference to an position in mtd_storage.
* @return int8_t
*/
int mtd_load(void *value, uint16_t len, uint32_t offset);

int8_t mtd_erase_all(void);

/**
Expand Down Expand Up @@ -93,47 +78,47 @@ int8_t mtd_dump_flashpage(uint16_t page);
* @param [in] key An unique identifier string for the uint8_t data @p value.
* @return int
*/
int mtd_put_u8(const uint8_t value, const uint8_t *key);
int mtd_put_u8(const uint8_t value, const char *key);
/**
* @brief Saves an unsigned int 16 bits data type in the mtd_storage.
*
* @param [in] value uint16_t data.
* @param [in] key An unique identifier string for the uint16_t data @p value.
* @return int
*/
int mtd_put_u16(const uint16_t value, const uint8_t *key);
int mtd_put_u16(const uint16_t value, const char *key);
/**
* @brief Saves an unsigned int 32 bits data type in the mtd_storage.
*
* @param [in] value uint32_t data.
* @param [in] key An unique identifier string for the uint32_t data @p value.
* @return int
*/
int mtd_put_u32(const uint32_t value, const uint8_t *key);
int mtd_put_u32(const uint32_t value, const char *key);
/**
* @brief Load an unsigned int 8 bits data type in the mtd_storage
*
* @param [out] value uint8_t data variable that will load the value from mtd_storage
* @param [in] key An unique identifier string for the uint8_t data @p value.
* @return int
*/
int mtd_get_u8(uint8_t *value, const uint8_t *key);
int mtd_get_u8(uint8_t *value, const char *key);
/**
* @brief Load an unsigned int 16 bits data type in the mtd_storage
*
* @param [out] value uint16_t data variable that will load the value from mtd_storage
* @param [in] key An unique identifier string for the uint16_t data @p value.
* @return int
*/
int mtd_get_u16(uint16_t *value, const uint8_t *key);
int mtd_get_u16(uint16_t *value, const char *key);
/**
* @brief Load an unsigned int 32 bits data type in the mtd_storage
*
* @param [out] value uint32_t data variable that will load the value from mtd_storage
* @param [in] key An unique identifier string for the uint32_t data @p value.
* @return int
*/
int mtd_get_u32(uint32_t *value, const uint8_t *key);
int mtd_get_u32(uint32_t *value, const char *key);

/* Int put/set operations */

Expand All @@ -144,47 +129,47 @@ int mtd_get_u32(uint32_t *value, const uint8_t *key);
* @param [in] key An unique identifier string for the int8_t data @p value.
* @return int
*/
int mtd_put_i8(const int8_t value, const uint8_t *key);
int mtd_put_i8(const int8_t value, const char *key);
/**
* @brief Saves an signed int 16 bits data type in the mtd_storage.
*
* @param [in] value uint16_t data.
* @param [in] key An unique identifier string for the uint16_t data @p value.
* @return int
*/
int mtd_put_i16(const int16_t value, const uint8_t *key);
int mtd_put_i16(const int16_t value, const char *key);
/**
* @brief Saves an signed int 32 bits data type in the mtd_storage.
*
* @param [in] value uint32_t data.
* @param [in] key An unique identifier string for the uint32_t data @p value.
* @return int
*/
int mtd_put_i32(const int32_t value, const uint8_t *key);
int mtd_put_i32(const int32_t value, const char *key);
/**
* @brief Load an signed int 8 bits data type in the mtd_storage
*
* @param [out] value int8_t data variable that will load the value from mtd_storage
* @param [in] key An unique identifier string for the int8_t data @p value.
* @return int
*/
int mtd_get_i8(int8_t *value, const uint8_t *key);
int mtd_get_i8(int8_t *value, const char *key);
/**
* @brief Load an unsigned int 16 bits data type in the mtd_storage
*
* @param [out] value int16_t data variable that will load the value from mtd_storage
* @param [in] key An unique identifier string for the int16_t data @p value.
* @return int
*/
int mtd_get_i16(int16_t *value, const uint8_t *key);
int mtd_get_i16(int16_t *value, const char *key);
/**
* @brief Load an unsigned int 32 bits data type in the mtd_storage
*
* @param [out] value uint32_t data variable that will load the value from mtd_storage
* @param [in] key An unique identifier string for the uint32_t data @p value.
* @return int
*/
int mtd_get_i32(int32_t *value, const uint8_t *key);
int mtd_get_i32(int32_t *value, const char *key);

/* String put/set operations */

Expand All @@ -197,7 +182,7 @@ int mtd_get_i32(int32_t *value, const uint8_t *key);
* @param [in] len size of @p value string.
* @return int
*/
int mtd_put_str(const char *value, const uint8_t *key, uint8_t len);
int mtd_put_str(const char *value, const char *key, uint8_t len);
/**
* @brief Loads a string using its identifier.
*
Expand All @@ -206,7 +191,7 @@ int mtd_put_str(const char *value, const uint8_t *key, uint8_t len);
* @param [in] len size of @p value string.
* @return int
*/
int mtd_get_str(char *value, const uint8_t *key, uint8_t len);
int mtd_get_str(char *value, const char *key, uint8_t len);

#ifdef __cplusplus
}
Expand Down
14 changes: 7 additions & 7 deletions firmware/sys/storage/include/storage_register.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ extern "C" {
#define RWP_WRITE_BITMASK (0x80) /*!< Read/Write protection bit mask to set Writeable register*/
#define RWP_READ_BITMASK (0x00) /*!< Read/Write protection bit mask to set only-read register*/
typedef struct {
uint16_t size;
uint8_t key[25];
uint8_t rwp;
uint32_t ptr_content;
uint16_t size; /*!< saved data size*/
char key[25]; /*!< name or identifier assigned a register where there is a saved dara */
uint8_t rwp; /*!< Read and write protection bit */
uint32_t ptr_content; /*!< pointer to the content of a register */
} mtd_register_t;

#define MTD_REG_IDX_NUMOF \
Expand All @@ -55,7 +55,7 @@ typedef struct {
* @param [in] len size of @p value that will be saved.
* @return int8_t
*/
int mtd_save_reg(const void *value, const uint8_t *key, uint16_t len);
int mtd_save_reg(const void *value, const char *key, uint16_t len);

/**
* @brief Load data from mtd_storage localizating with its knew key and saves in @p value the data.
Expand All @@ -68,7 +68,7 @@ int mtd_save_reg(const void *value, const uint8_t *key, uint16_t len);
* value parameter.
* @return int8_t
*/
int mtd_load_reg(void *value, const uint8_t *key, uint16_t len);
int mtd_load_reg(void *value, const char *key, uint16_t len);

/**
* @brief Removes all saved data in mtd_storage. This will erase all until the
Expand All @@ -80,7 +80,7 @@ int mtd_load_reg(void *value, const uint8_t *key, uint16_t len);
* @retval 0 Erased data success
* @retval -1 Erased Fail.
*/
int8_t mtd_reg_del(uint8_t *key, uint16_t size);
int8_t mtd_reg_del(char *key, uint16_t size);

/**
* @brief
Expand Down
28 changes: 14 additions & 14 deletions firmware/sys/storage/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,59 +52,59 @@ int8_t mtd_start(void) {
return ret;
}

int mtd_put_u8(const uint8_t value, const uint8_t *key) {
int mtd_put_u8(const uint8_t value, const char *key) {
return mtd_save_reg(&value, key, sizeof(uint8_t));
}

int mtd_put_u16(const uint16_t value, const uint8_t *key) {
int mtd_put_u16(const uint16_t value, const char *key) {
return mtd_save_reg(&value, key, sizeof(uint16_t));
}

int mtd_put_u32(const uint32_t value, const uint8_t *key) {
int mtd_put_u32(const uint32_t value, const char *key) {
return mtd_save_reg(&value, key, sizeof(uint32_t));
}

int mtd_get_u8(uint8_t *value, const uint8_t *key) {
int mtd_get_u8(uint8_t *value, const char *key) {
return mtd_load_reg(value, key, sizeof(uint8_t));
}

int mtd_get_u16(uint16_t *value, const uint8_t *key) {
int mtd_get_u16(uint16_t *value, const char *key) {
return mtd_load_reg(value, key, sizeof(uint16_t));
}

int mtd_get_u32(uint32_t *value, const uint8_t *key) {
int mtd_get_u32(uint32_t *value, const char *key) {
return mtd_load_reg(value, key, sizeof(uint32_t));
}

int mtd_put_i8(const int8_t value, const uint8_t *key) {
int mtd_put_i8(const int8_t value, const char *key) {
return mtd_save_reg(&value, key, sizeof(int8_t));
}

int mtd_put_i16(const int16_t value, const uint8_t *key) {
int mtd_put_i16(const int16_t value, const char *key) {
return mtd_save_reg(&value, key, sizeof(int16_t));
}

int mtd_put_i32(const int32_t value, const uint8_t *key) {
int mtd_put_i32(const int32_t value, const char *key) {
return mtd_save_reg(&value, key, sizeof(int32_t));
}

int mtd_get_i8(int8_t *value, const uint8_t *key) {
int mtd_get_i8(int8_t *value, const char *key) {
return mtd_load_reg(value, key, sizeof(int8_t));
}

int mtd_get_i16(int16_t *value, const uint8_t *key) {
int mtd_get_i16(int16_t *value, const char *key) {
return mtd_load_reg(value, key, sizeof(int16_t));
}

int mtd_get_i32(int32_t *value, const uint8_t *key) {
int mtd_get_i32(int32_t *value, const char *key) {
return mtd_load_reg(value, key, sizeof(int32_t));
}

int mtd_put_str(const char *value, const uint8_t *key, uint8_t len) {
int mtd_put_str(const char *value, const char *key, uint8_t len) {
return mtd_save_reg(value, key, len);
}

int mtd_get_str(char *value, const uint8_t *key, uint8_t len) {
int mtd_get_str(char *value, const char *key, uint8_t len) {
return mtd_load_reg(value, key, len);
}

Expand Down
2 changes: 1 addition & 1 deletion firmware/sys/storage/storage_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ int8_t mtd_dump(void) {
uint32_t addr = MTD_START_ADDR;
uint32_t erased_data = 0;
for (uint32_t i = 0; i < MAX_SIZE_STORAGE / dev->write_size; i++) {
printf("0x%" PRIX32 " : ", addr);
DEBUG("0x%" PRIX32 " : ", addr);
mtd_read_block(value, addr, dev->write_size, 0);
for (uint8_t j = 0; j < dev->write_size; j++) {
DEBUG("%02X ", value[j]);
Expand Down
6 changes: 3 additions & 3 deletions firmware/sys/storage/storage_register.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int mtd_clear_all_regs(void) {
return 0;
}

int mtd_save_reg(const void *value, const uint8_t *key, uint16_t len) {
int mtd_save_reg(const void *value, const char *key, uint16_t len) {
mtd_register_t buff, mtd_reg = {.size = len};
memcpy(mtd_reg.key, key, sizeof(mtd_reg.key));
mtd_reg.rwp = 0xFF & RWP_READ_BITMASK;
Expand Down Expand Up @@ -122,7 +122,7 @@ int mtd_save_reg(const void *value, const uint8_t *key, uint16_t len) {
return -1;
}

int mtd_load_reg(void *value, const uint8_t *key, uint16_t len) {
int mtd_load_reg(void *value, const char *key, uint16_t len) {
mtd_register_t buff, mtd_reg = {.size = len};
memcpy(mtd_reg.key, key, sizeof(mtd_reg.key));
uint8_t reg_count = 0;
Expand Down Expand Up @@ -181,7 +181,7 @@ int8_t mtd_available_idx(uint8_t *idx, uint8_t *count) {
return 0;
}

int8_t mtd_reg_del(uint8_t *key, uint16_t size) {
int8_t mtd_reg_del(char *key, uint16_t size) {
mtd_register_t regs[MTD_REG_IDX_NUMOF], reg = {.size = size};
memcpy(reg.key, key, sizeof(reg.key));
uint8_t *content[MTD_REG_IDX_NUMOF];
Expand Down
Loading

0 comments on commit 06c258b

Please sign in to comment.