chore(radio): Reduce size of the data structures in FLASH storage (#3979)
* Reduce size of the YamlNode structure in FLASH storage. Fix compiler warning. * Further reduction of FLASH used by YamlNode structures. * Reduce size of sensor definition arrays and audio tone volumes array.
This commit is contained in:
@@ -74,18 +74,15 @@ struct YamlNode
|
||||
typedef bool (*cust_write_func)(void* user, uint8_t* data, uint32_t bitoffs,
|
||||
yaml_writer_func wf, void* opaque);
|
||||
|
||||
uint8_t type;
|
||||
uint32_t size; // bits
|
||||
uint8_t tag_len;
|
||||
uint16_t size; // bits
|
||||
uint8_t type:4;
|
||||
uint16_t elmts:12; // maximum number of array elements
|
||||
const char* tag;
|
||||
union {
|
||||
struct {
|
||||
const YamlNode* child;
|
||||
union {
|
||||
struct {
|
||||
is_active_func is_active;
|
||||
uint16_t elmts; // maximum number of elements
|
||||
} _a;
|
||||
is_active_func is_active;
|
||||
select_member_func select_member;
|
||||
} u;
|
||||
} _array;
|
||||
@@ -109,105 +106,108 @@ struct YamlNode
|
||||
cust_write_func write;
|
||||
} _cust_attr;
|
||||
} u;
|
||||
|
||||
uint8_t tag_len() const { return tag ? strlen(tag) : 0; }
|
||||
};
|
||||
|
||||
#if !defined(_MSC_VER)
|
||||
|
||||
#define YAML_TAG(str) \
|
||||
.tag_len=(sizeof(str)-1), .tag=(str)
|
||||
.tag=(str)
|
||||
|
||||
#define YAML_IDX \
|
||||
{ .type=YDT_IDX, .size=0, YAML_TAG("idx") }
|
||||
{ .size=0, .type=YDT_IDX, 0, YAML_TAG("idx") }
|
||||
|
||||
#define YAML_IDX_CUST(tag, f_read, f_write) \
|
||||
{ .type=YDT_IDX, .size=0, YAML_TAG(tag), .u={._cust_idx={.read=(f_read), .write=(f_write) }} }
|
||||
{ .size=0, .type=YDT_IDX, 0, YAML_TAG(tag), .u={._cust_idx={.read=(f_read), .write=(f_write) }} }
|
||||
|
||||
#define YAML_SIGNED(tag, bits) \
|
||||
{ .type=YDT_SIGNED, .size=(bits), YAML_TAG(tag) }
|
||||
{ .size=(bits), .type=YDT_SIGNED, 0, YAML_TAG(tag) }
|
||||
|
||||
#define YAML_UNSIGNED(tag, bits) \
|
||||
{ .type=YDT_UNSIGNED, .size=(bits), YAML_TAG(tag) }
|
||||
{ .size=(bits), .type=YDT_UNSIGNED, 0, YAML_TAG(tag) }
|
||||
|
||||
#define YAML_SIGNED_CUST(tag, bits, f_cust_to_uint, f_uint_to_cust) \
|
||||
{ .type=YDT_SIGNED, .size=(bits), YAML_TAG(tag), .u={._cust={ .cust_to_uint=f_cust_to_uint, .uint_to_cust=f_uint_to_cust }} }
|
||||
{ .size=(bits), .type=YDT_SIGNED, 0, YAML_TAG(tag), .u={._cust={ .cust_to_uint=f_cust_to_uint, .uint_to_cust=f_uint_to_cust }} }
|
||||
|
||||
#define YAML_UNSIGNED_CUST(tag, bits, f_cust_to_uint, f_uint_to_cust) \
|
||||
{ .type=YDT_UNSIGNED, .size=(bits), YAML_TAG(tag), .u={._cust={ .cust_to_uint=f_cust_to_uint, .uint_to_cust=f_uint_to_cust }} }
|
||||
{ .size=(bits), .type=YDT_UNSIGNED, 0, YAML_TAG(tag), .u={._cust={ .cust_to_uint=f_cust_to_uint, .uint_to_cust=f_uint_to_cust }} }
|
||||
|
||||
#define YAML_STRING(tag, max_len) \
|
||||
{ .type=YDT_STRING, .size=((max_len)<<3), YAML_TAG(tag) }
|
||||
{ .size=((max_len)<<3), .type=YDT_STRING, 0, YAML_TAG(tag) }
|
||||
|
||||
#define YAML_STRUCT(tag, bits, nodes, f_is_active) \
|
||||
{ .type=YDT_ARRAY, .size=(bits), YAML_TAG(tag), .u={._array={ .child=(nodes), .u={ ._a={.is_active=(f_is_active), .elmts=1 }}}} }
|
||||
{ .size=(bits), .type=YDT_ARRAY, .elmts=1, YAML_TAG(tag), .u={._array={ .child=(nodes), .u={.is_active=(f_is_active)}}} }
|
||||
|
||||
#define YAML_ARRAY(tag, bits, max_elmts, nodes, f_is_active) \
|
||||
{ .type=YDT_ARRAY, .size=(bits), YAML_TAG(tag), .u={._array={ .child=(nodes), .u={ ._a={.is_active=(f_is_active), .elmts=(max_elmts) }}}} }
|
||||
{ .size=(bits), .type=YDT_ARRAY, .elmts=(max_elmts), YAML_TAG(tag), .u={._array={ .child=(nodes), .u={.is_active=(f_is_active)}}} }
|
||||
|
||||
#define YAML_ENUM(tag, bits, id_strs) \
|
||||
{ .type=YDT_ENUM, .size=(bits), YAML_TAG(tag), .u={._enum={ .choices=(id_strs) }} }
|
||||
{ .size=(bits), .type=YDT_ENUM, 0, YAML_TAG(tag), .u={._enum={ .choices=(id_strs) }} }
|
||||
|
||||
#define YAML_UNION(tag, bits, nodes, f_sel_m) \
|
||||
{ .type=YDT_UNION, .size=(bits), YAML_TAG(tag), .u={._array={ .child=(nodes), .u={.select_member=(f_sel_m) }}} }
|
||||
{ .size=(bits), .type=YDT_UNION, 0, YAML_TAG(tag), .u={._array={ .child=(nodes), .u={.select_member=(f_sel_m) }}} }
|
||||
|
||||
#define YAML_PADDING(bits) \
|
||||
{ .type=YDT_PADDING, .size=(bits) }
|
||||
{ .size=(bits), .type=YDT_PADDING }
|
||||
|
||||
#define YAML_CUSTOM(tag, f_read, f_write) \
|
||||
{ .type=YDT_CUSTOM, .size=0, YAML_TAG(tag), .u={._cust_attr={.read=(f_read), .write=(f_write) }} }
|
||||
{ .size=0, .type=YDT_CUSTOM, 0, YAML_TAG(tag), .u={._cust_attr={.read=(f_read), .write=(f_write) }} }
|
||||
|
||||
#define YAML_END \
|
||||
{ .type=YDT_NONE }
|
||||
{ .size=0, .type=YDT_NONE }
|
||||
|
||||
#define YAML_ROOT(nodes) \
|
||||
{ .type=YDT_ARRAY, .size=0, .tag_len=0, .tag=NULL, \
|
||||
{ .size=0, .type=YDT_ARRAY, .elmts=1, .tag=NULL, \
|
||||
.u={ \
|
||||
._array={ .child=(nodes), \
|
||||
.u={._a={.is_active=NULL, .elmts=1 }} \
|
||||
.u={.is_active=NULL} \
|
||||
}} \
|
||||
}
|
||||
|
||||
#else // MSVC++ compat
|
||||
|
||||
#define YAML_TAG(str) \
|
||||
(sizeof(str)-1), (str)
|
||||
(str)
|
||||
|
||||
#define YAML_IDX \
|
||||
{ YDT_IDX , 0, YAML_TAG("idx") }
|
||||
{ 0, YDT_IDX, 0, YAML_TAG("idx") }
|
||||
|
||||
#define YAML_SIGNED(tag, bits) \
|
||||
{ YDT_SIGNED, (bits), YAML_TAG(tag) }
|
||||
{ (bits), YDT_SIGNED, 0, YAML_TAG(tag) }
|
||||
|
||||
#define YAML_UNSIGNED(tag, bits) \
|
||||
{ YDT_UNSIGNED, (bits), YAML_TAG(tag) }
|
||||
{ (bits), YDT_UNSIGNED, 0, YAML_TAG(tag) }
|
||||
|
||||
#define YAML_SIGNED_CUST(tag, bits, f_cust_to_uint, f_uint_to_cust) \
|
||||
{ YDT_SIGNED, (bits), YAML_TAG(tag), {{ (const YamlNode*)f_cust_to_uint, {{ (YamlNode::is_active_func)f_uint_to_cust, 0 }}}} }
|
||||
{ (bits), YDT_SIGNED, 0, YAML_TAG(tag), {{ (const YamlNode*)f_cust_to_uint, {{ (YamlNode::is_active_func)f_uint_to_cust, 0 }}}} }
|
||||
|
||||
#define YAML_UNSIGNED_CUST(tag, bits, f_cust_to_uint, f_uint_to_cust) \
|
||||
{ YDT_UNSIGNED, (bits), YAML_TAG(tag), {{ (const YamlNode*)f_cust_to_uint, {{ (YamlNode::is_active_func)f_uint_to_cust, 0}}}} }
|
||||
{ (bits), YDT_UNSIGNED, 0, YAML_TAG(tag), {{ (const YamlNode*)f_cust_to_uint, {{ (YamlNode::is_active_func)f_uint_to_cust, 0}}}} }
|
||||
|
||||
#define YAML_STRING(tag, max_len) \
|
||||
{ YDT_STRING, ((max_len)<<3), YAML_TAG(tag) }
|
||||
{ ((max_len)<<3), YDT_STRING, 0, YAML_TAG(tag) }
|
||||
|
||||
#define YAML_STRUCT(tag, bits, nodes, f_is_active) \
|
||||
{ YDT_ARRAY, (bits), YAML_TAG(tag), {{ (nodes), {{ (f_is_active), 1 }}}} }
|
||||
{ (bits), YDT_ARRAY, 1, YAML_TAG(tag), {{ (nodes), {{ (f_is_active) }}}} }
|
||||
|
||||
#define YAML_ARRAY(tag, bits, max_elmts, nodes, f_is_active) \
|
||||
{ YDT_ARRAY, (bits), YAML_TAG(tag), {{ (nodes), {{ (f_is_active), (max_elmts) }}}} }
|
||||
{ (bits), YDT_ARRAY, (max_elmts), YAML_TAG(tag), {{ (nodes), {{ (f_is_active) }}}} }
|
||||
|
||||
#define YAML_ENUM(tag, bits, id_strs) \
|
||||
{ YDT_ENUM, (bits), YAML_TAG(tag), {{ (const YamlNode*)(id_strs) }} }
|
||||
{ (bits), YDT_ENUM, 0, YAML_TAG(tag), {{ (const YamlNode*)(id_strs) }} }
|
||||
|
||||
#define YAML_UNION(tag, bits, nodes, f_sel_m) \
|
||||
{ YDT_UNION, (bits), YAML_TAG(tag), {{ (nodes), {{ (YamlNode::is_active_func)(f_sel_m), 0 }}}} }
|
||||
{ (bits), YDT_UNION, 0, YAML_TAG(tag), {{ (nodes), {{ (YamlNode::is_active_func)(f_sel_m) }}}} }
|
||||
|
||||
#define YAML_PADDING(bits) \
|
||||
{ YDT_PADDING, (bits) }
|
||||
{ (bits), YDT_PADDING }
|
||||
|
||||
#define YAML_END \
|
||||
{ YDT_NONE }
|
||||
{ 0, YDT_NONE }
|
||||
|
||||
#define YAML_ROOT(nodes) \
|
||||
{ YDT_ARRAY, 0, 0, NULL, {{ (nodes), {{ NULL, 1 }}}} }
|
||||
{ 0, YDT_ARRAY, 1, NULL, {{ (nodes), {{ NULL }}}} }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user