mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 12:55:19 +03:00
Adding length to PG Registry to allow for use elsewhere.
This commit is contained in:
parent
b94da4a5ee
commit
f3f3693138
1 changed files with 18 additions and 14 deletions
|
@ -45,6 +45,7 @@ typedef void (pgResetFunc)(void * /* base */);
|
|||
|
||||
typedef struct pgRegistry_s {
|
||||
pgn_t pgn; // The parameter group number, the top 4 bits are reserved for version
|
||||
uint8_t length; // The number of elements in the group
|
||||
uint16_t size; // Size of the group in RAM, the top 4 bits are reserved for flags
|
||||
uint8_t *address; // Address of the group in RAM.
|
||||
uint8_t *copy; // Address of the copy in RAM.
|
||||
|
@ -58,6 +59,7 @@ typedef struct pgRegistry_s {
|
|||
static inline uint16_t pgN(const pgRegistry_t* reg) {return reg->pgn & PGR_PGN_MASK;}
|
||||
static inline uint8_t pgVersion(const pgRegistry_t* reg) {return (uint8_t)(reg->pgn >> 12);}
|
||||
static inline uint16_t pgSize(const pgRegistry_t* reg) {return reg->size & PGR_SIZE_MASK;}
|
||||
static inline uint16_t pgElementSize(const pgRegistry_t* reg) {return (reg->size & PGR_SIZE_MASK) / reg->length;}
|
||||
|
||||
#define PG_PACKED __attribute__((packed))
|
||||
|
||||
|
@ -103,12 +105,12 @@ extern const uint8_t __pg_resetdata_end[];
|
|||
/**/
|
||||
|
||||
// Declare system config array
|
||||
#define PG_DECLARE_ARRAY(_type, _size, _name) \
|
||||
extern _type _name ## _SystemArray[_size]; \
|
||||
extern _type _name ## _CopyArray[_size]; \
|
||||
#define PG_DECLARE_ARRAY(_type, _length, _name) \
|
||||
extern _type _name ## _SystemArray[_length]; \
|
||||
extern _type _name ## _CopyArray[_length]; \
|
||||
static inline const _type* _name(int _index) { return &_name ## _SystemArray[_index]; } \
|
||||
static inline _type* _name ## Mutable(int _index) { return &_name ## _SystemArray[_index]; } \
|
||||
static inline _type (* _name ## _array(void))[_size] { return &_name ## _SystemArray; } \
|
||||
static inline _type (* _name ## _array(void))[_length] { return &_name ## _SystemArray; } \
|
||||
struct _dummy \
|
||||
/**/
|
||||
|
||||
|
@ -120,6 +122,7 @@ extern const uint8_t __pg_resetdata_end[];
|
|||
extern const pgRegistry_t _name ## _Registry; \
|
||||
const pgRegistry_t _name ##_Registry PG_REGISTER_ATTRIBUTES = { \
|
||||
.pgn = _pgn | (_version << 12), \
|
||||
.length = 1, \
|
||||
.size = sizeof(_type) | PGR_SIZE_SYSTEM_FLAG, \
|
||||
.address = (uint8_t*)&_name ## _System, \
|
||||
.copy = (uint8_t*)&_name ## _Copy, \
|
||||
|
@ -143,13 +146,14 @@ extern const uint8_t __pg_resetdata_end[];
|
|||
/**/
|
||||
|
||||
// Register system config array
|
||||
#define PG_REGISTER_ARRAY_I(_type, _size, _name, _pgn, _version, _reset) \
|
||||
_type _name ## _SystemArray[_size]; \
|
||||
_type _name ## _CopyArray[_size]; \
|
||||
#define PG_REGISTER_ARRAY_I(_type, _length, _name, _pgn, _version, _reset) \
|
||||
_type _name ## _SystemArray[_length]; \
|
||||
_type _name ## _CopyArray[_length]; \
|
||||
extern const pgRegistry_t _name ##_Registry; \
|
||||
const pgRegistry_t _name ## _Registry PG_REGISTER_ATTRIBUTES = { \
|
||||
.pgn = _pgn | (_version << 12), \
|
||||
.size = (sizeof(_type) * _size) | PGR_SIZE_SYSTEM_FLAG, \
|
||||
.length = _length, \
|
||||
.size = (sizeof(_type) * _length) | PGR_SIZE_SYSTEM_FLAG, \
|
||||
.address = (uint8_t*)&_name ## _SystemArray, \
|
||||
.copy = (uint8_t*)&_name ## _CopyArray, \
|
||||
.ptr = 0, \
|
||||
|
@ -157,20 +161,20 @@ extern const uint8_t __pg_resetdata_end[];
|
|||
} \
|
||||
/**/
|
||||
|
||||
#define PG_REGISTER_ARRAY(_type, _size, _name, _pgn, _version) \
|
||||
PG_REGISTER_ARRAY_I(_type, _size, _name, _pgn, _version, .reset = {.ptr = 0}) \
|
||||
#define PG_REGISTER_ARRAY(_type, _length, _name, _pgn, _version) \
|
||||
PG_REGISTER_ARRAY_I(_type, _length, _name, _pgn, _version, .reset = {.ptr = 0}) \
|
||||
/**/
|
||||
|
||||
#define PG_REGISTER_ARRAY_WITH_RESET_FN(_type, _size, _name, _pgn, _version) \
|
||||
#define PG_REGISTER_ARRAY_WITH_RESET_FN(_type, _length, _name, _pgn, _version) \
|
||||
extern void pgResetFn_ ## _name(_type *); \
|
||||
PG_REGISTER_ARRAY_I(_type, _size, _name, _pgn, _version, .reset = {.fn = (pgResetFunc*)&pgResetFn_ ## _name}) \
|
||||
PG_REGISTER_ARRAY_I(_type, _length, _name, _pgn, _version, .reset = {.fn = (pgResetFunc*)&pgResetFn_ ## _name}) \
|
||||
/**/
|
||||
|
||||
#if 0
|
||||
// ARRAY reset mechanism is not implemented yet, only few places in code would benefit from it - See pgResetInstance
|
||||
#define PG_REGISTER_ARRAY_WITH_RESET_TEMPLATE(_type, _size, _name, _pgn, _version) \
|
||||
#define PG_REGISTER_ARRAY_WITH_RESET_TEMPLATE(_type, _length, _name, _pgn, _version) \
|
||||
extern const _type pgResetTemplate_ ## _name; \
|
||||
PG_REGISTER_ARRAY_I(_type, _size, _name, _pgn, _version, .reset = {.ptr = (void*)&pgResetTemplate_ ## _name}) \
|
||||
PG_REGISTER_ARRAY_I(_type, _length, _name, _pgn, _version, .reset = {.ptr = (void*)&pgResetTemplate_ ## _name}) \
|
||||
/**/
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue