From eda6b6a24a03ea3833531ca96f82eccccef71ab3 Mon Sep 17 00:00:00 2001 From: "Richard Flay (Hyper)" Date: Sat, 10 Nov 2012 20:47:10 +1030 Subject: [PATCH 1/3] Improved type-safety. Replaced flight side UAVO access macros with inline functions to ensure that correct pointer types are always passed to UAVO access functions. --- flight/UAVObjects/inc/uavobjecttemplate.h | 77 +++++++++++++++-------- 1 file changed, 52 insertions(+), 25 deletions(-) diff --git a/flight/UAVObjects/inc/uavobjecttemplate.h b/flight/UAVObjects/inc/uavobjecttemplate.h index 2938c218f..4799eb9cb 100644 --- a/flight/UAVObjects/inc/uavobjecttemplate.h +++ b/flight/UAVObjects/inc/uavobjecttemplate.h @@ -46,40 +46,67 @@ #define $(NAMEUC)_ISSETTINGS $(ISSETTINGS) #define $(NAMEUC)_NUMBYTES sizeof($(NAME)Data) -// Object access macros -/** - * @function $(NAME)Get(dataOut) - * @brief Populate a $(NAME)Data object - * @param[out] dataOut - */ -#define $(NAME)Get(dataOut) UAVObjGetData($(NAME)Handle(), dataOut) -#define $(NAME)Set(dataIn) UAVObjSetData($(NAME)Handle(), dataIn) -#define $(NAME)InstGet(instId, dataOut) UAVObjGetInstanceData($(NAME)Handle(), instId, dataOut) -#define $(NAME)InstSet(instId, dataIn) UAVObjSetInstanceData($(NAME)Handle(), instId, dataIn) -#define $(NAME)ConnectQueue(queue) UAVObjConnectQueue($(NAME)Handle(), queue, EV_MASK_ALL_UPDATES) -#define $(NAME)ConnectCallback(cb) UAVObjConnectCallback($(NAME)Handle(), cb, EV_MASK_ALL_UPDATES) -#define $(NAME)CreateInstance() UAVObjCreateInstance($(NAME)Handle(),&$(NAME)SetDefaults) -#define $(NAME)RequestUpdate() UAVObjRequestUpdate($(NAME)Handle()) -#define $(NAME)RequestInstUpdate(instId) UAVObjRequestInstanceUpdate($(NAME)Handle(), instId) -#define $(NAME)Updated() UAVObjUpdated($(NAME)Handle()) -#define $(NAME)InstUpdated(instId) UAVObjUpdated($(NAME)Handle(), instId) -#define $(NAME)GetMetadata(dataOut) UAVObjGetMetadata($(NAME)Handle(), dataOut) -#define $(NAME)SetMetadata(dataIn) UAVObjSetMetadata($(NAME)Handle(), dataIn) -#define $(NAME)ReadOnly() UAVObjReadOnly($(NAME)Handle()) +// Generic interface functions +int32_t $(NAME)Initialize(); +UAVObjHandle $(NAME)Handle(); +void $(NAME)SetDefaults(UAVObjHandle obj, uint16_t instId); // Object data typedef struct { $(DATAFIELDS) } __attribute__((packed)) $(NAME)Data; +// Typesafe Object access functions +/** + * @function $(NAME)Get(dataOut) + * @brief Populate a $(NAME)Data object + * @param[out] dataOut + */ +static inline __attribute__((always_inline)) +int32_t $(NAME)Get($(NAME)Data* dataOut) { return UAVObjGetData($(NAME)Handle(), dataOut); } + +static inline __attribute__((always_inline)) +int32_t $(NAME)Set(const $(NAME)Data* dataIn) { return UAVObjSetData($(NAME)Handle(), dataIn); } + +static inline __attribute__((always_inline)) +int32_t $(NAME)InstGet(uint16_t instId, $(NAME)Data* dataOut) { return UAVObjGetInstanceData($(NAME)Handle(), instId, dataOut); } + +static inline __attribute__((always_inline)) +int32_t $(NAME)InstSet(uint16_t instId, const $(NAME)Data* dataIn) { return UAVObjSetInstanceData($(NAME)Handle(), instId, dataIn); } + +static inline __attribute__((always_inline)) +int32_t $(NAME)ConnectQueue(xQueueHandle queue) { return UAVObjConnectQueue($(NAME)Handle(), queue, EV_MASK_ALL_UPDATES); } + +static inline __attribute__((always_inline)) +int32_t $(NAME)ConnectCallback(UAVObjEventCallback cb) { return UAVObjConnectCallback($(NAME)Handle(), cb, EV_MASK_ALL_UPDATES); } + +static inline __attribute__((always_inline)) +uint16_t $(NAME)CreateInstance() { return UAVObjCreateInstance($(NAME)Handle(), &$(NAME)SetDefaults); } + +static inline __attribute__((always_inline)) +void $(NAME)RequestUpdate() { UAVObjRequestUpdate($(NAME)Handle()); } + +static inline __attribute__((always_inline)) +void $(NAME)RequestInstUpdate(uint16_t instId) { UAVObjRequestInstanceUpdate($(NAME)Handle(), instId); } + +static inline __attribute__((always_inline)) +void $(NAME)Updated() { UAVObjUpdated($(NAME)Handle()); } + +static inline __attribute__((always_inline)) +void $(NAME)InstUpdated(uint16_t instId) { UAVObjInstanceUpdated($(NAME)Handle(), instId); } + +static inline __attribute__((always_inline)) +int32_t $(NAME)GetMetadata(UAVObjMetadata* dataOut) { return UAVObjGetMetadata($(NAME)Handle(), dataOut); } + +static inline __attribute__((always_inline)) +int32_t $(NAME)SetMetadata(const UAVObjMetadata* dataIn) { return UAVObjSetMetadata($(NAME)Handle(), dataIn); } + +static inline __attribute__((always_inline)) +int8_t $(NAME)ReadOnly() { return UAVObjReadOnly($(NAME)Handle()); } + // Field information $(DATAFIELDINFO) -// Generic interface functions -int32_t $(NAME)Initialize(); -UAVObjHandle $(NAME)Handle(); -void $(NAME)SetDefaults(UAVObjHandle obj, uint16_t instId); - // set/Get functions $(SETGETFIELDSEXTERN) From 6c0b91dee7d730e14d8e7d457d722559b1ddb2bf Mon Sep 17 00:00:00 2001 From: "Richard Flay (Hyper)" Date: Thu, 15 Nov 2012 07:45:35 +1030 Subject: [PATCH 2/3] Minor tweak for coding standard compliance. --- flight/UAVObjects/inc/uavobjecttemplate.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flight/UAVObjects/inc/uavobjecttemplate.h b/flight/UAVObjects/inc/uavobjecttemplate.h index 4799eb9cb..fc0da7afe 100644 --- a/flight/UAVObjects/inc/uavobjecttemplate.h +++ b/flight/UAVObjects/inc/uavobjecttemplate.h @@ -63,16 +63,16 @@ $(DATAFIELDS) * @param[out] dataOut */ static inline __attribute__((always_inline)) -int32_t $(NAME)Get($(NAME)Data* dataOut) { return UAVObjGetData($(NAME)Handle(), dataOut); } +int32_t $(NAME)Get($(NAME)Data *dataOut) { return UAVObjGetData($(NAME)Handle(), dataOut); } static inline __attribute__((always_inline)) -int32_t $(NAME)Set(const $(NAME)Data* dataIn) { return UAVObjSetData($(NAME)Handle(), dataIn); } +int32_t $(NAME)Set(const $(NAME)Data *dataIn) { return UAVObjSetData($(NAME)Handle(), dataIn); } static inline __attribute__((always_inline)) -int32_t $(NAME)InstGet(uint16_t instId, $(NAME)Data* dataOut) { return UAVObjGetInstanceData($(NAME)Handle(), instId, dataOut); } +int32_t $(NAME)InstGet(uint16_t instId, $(NAME)Data *dataOut) { return UAVObjGetInstanceData($(NAME)Handle(), instId, dataOut); } static inline __attribute__((always_inline)) -int32_t $(NAME)InstSet(uint16_t instId, const $(NAME)Data* dataIn) { return UAVObjSetInstanceData($(NAME)Handle(), instId, dataIn); } +int32_t $(NAME)InstSet(uint16_t instId, const $(NAME)Data *dataIn) { return UAVObjSetInstanceData($(NAME)Handle(), instId, dataIn); } static inline __attribute__((always_inline)) int32_t $(NAME)ConnectQueue(xQueueHandle queue) { return UAVObjConnectQueue($(NAME)Handle(), queue, EV_MASK_ALL_UPDATES); } @@ -96,10 +96,10 @@ static inline __attribute__((always_inline)) void $(NAME)InstUpdated(uint16_t instId) { UAVObjInstanceUpdated($(NAME)Handle(), instId); } static inline __attribute__((always_inline)) -int32_t $(NAME)GetMetadata(UAVObjMetadata* dataOut) { return UAVObjGetMetadata($(NAME)Handle(), dataOut); } +int32_t $(NAME)GetMetadata(UAVObjMetadata *dataOut) { return UAVObjGetMetadata($(NAME)Handle(), dataOut); } static inline __attribute__((always_inline)) -int32_t $(NAME)SetMetadata(const UAVObjMetadata* dataIn) { return UAVObjSetMetadata($(NAME)Handle(), dataIn); } +int32_t $(NAME)SetMetadata(const UAVObjMetadata *dataIn) { return UAVObjSetMetadata($(NAME)Handle(), dataIn); } static inline __attribute__((always_inline)) int8_t $(NAME)ReadOnly() { return UAVObjReadOnly($(NAME)Handle()); } From 5864219d275be046da89a961eca6d5b55e0da00b Mon Sep 17 00:00:00 2001 From: "Richard Flay (Hyper)" Date: Fri, 23 Nov 2012 07:15:28 +1030 Subject: [PATCH 3/3] Removed __attribute__((always_inline)) after review discussions. --- flight/UAVObjects/inc/uavobjecttemplate.h | 42 ++++++++--------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/flight/UAVObjects/inc/uavobjecttemplate.h b/flight/UAVObjects/inc/uavobjecttemplate.h index fc0da7afe..8bbbda12a 100644 --- a/flight/UAVObjects/inc/uavobjecttemplate.h +++ b/flight/UAVObjects/inc/uavobjecttemplate.h @@ -62,47 +62,33 @@ $(DATAFIELDS) * @brief Populate a $(NAME)Data object * @param[out] dataOut */ -static inline __attribute__((always_inline)) -int32_t $(NAME)Get($(NAME)Data *dataOut) { return UAVObjGetData($(NAME)Handle(), dataOut); } +static inline int32_t $(NAME)Get($(NAME)Data *dataOut) { return UAVObjGetData($(NAME)Handle(), dataOut); } -static inline __attribute__((always_inline)) -int32_t $(NAME)Set(const $(NAME)Data *dataIn) { return UAVObjSetData($(NAME)Handle(), dataIn); } +static inline int32_t $(NAME)Set(const $(NAME)Data *dataIn) { return UAVObjSetData($(NAME)Handle(), dataIn); } -static inline __attribute__((always_inline)) -int32_t $(NAME)InstGet(uint16_t instId, $(NAME)Data *dataOut) { return UAVObjGetInstanceData($(NAME)Handle(), instId, dataOut); } +static inline int32_t $(NAME)InstGet(uint16_t instId, $(NAME)Data *dataOut) { return UAVObjGetInstanceData($(NAME)Handle(), instId, dataOut); } -static inline __attribute__((always_inline)) -int32_t $(NAME)InstSet(uint16_t instId, const $(NAME)Data *dataIn) { return UAVObjSetInstanceData($(NAME)Handle(), instId, dataIn); } +static inline int32_t $(NAME)InstSet(uint16_t instId, const $(NAME)Data *dataIn) { return UAVObjSetInstanceData($(NAME)Handle(), instId, dataIn); } -static inline __attribute__((always_inline)) -int32_t $(NAME)ConnectQueue(xQueueHandle queue) { return UAVObjConnectQueue($(NAME)Handle(), queue, EV_MASK_ALL_UPDATES); } +static inline int32_t $(NAME)ConnectQueue(xQueueHandle queue) { return UAVObjConnectQueue($(NAME)Handle(), queue, EV_MASK_ALL_UPDATES); } -static inline __attribute__((always_inline)) -int32_t $(NAME)ConnectCallback(UAVObjEventCallback cb) { return UAVObjConnectCallback($(NAME)Handle(), cb, EV_MASK_ALL_UPDATES); } +static inline int32_t $(NAME)ConnectCallback(UAVObjEventCallback cb) { return UAVObjConnectCallback($(NAME)Handle(), cb, EV_MASK_ALL_UPDATES); } -static inline __attribute__((always_inline)) -uint16_t $(NAME)CreateInstance() { return UAVObjCreateInstance($(NAME)Handle(), &$(NAME)SetDefaults); } +static inline uint16_t $(NAME)CreateInstance() { return UAVObjCreateInstance($(NAME)Handle(), &$(NAME)SetDefaults); } -static inline __attribute__((always_inline)) -void $(NAME)RequestUpdate() { UAVObjRequestUpdate($(NAME)Handle()); } +static inline void $(NAME)RequestUpdate() { UAVObjRequestUpdate($(NAME)Handle()); } -static inline __attribute__((always_inline)) -void $(NAME)RequestInstUpdate(uint16_t instId) { UAVObjRequestInstanceUpdate($(NAME)Handle(), instId); } +static inline void $(NAME)RequestInstUpdate(uint16_t instId) { UAVObjRequestInstanceUpdate($(NAME)Handle(), instId); } -static inline __attribute__((always_inline)) -void $(NAME)Updated() { UAVObjUpdated($(NAME)Handle()); } +static inline void $(NAME)Updated() { UAVObjUpdated($(NAME)Handle()); } -static inline __attribute__((always_inline)) -void $(NAME)InstUpdated(uint16_t instId) { UAVObjInstanceUpdated($(NAME)Handle(), instId); } +static inline void $(NAME)InstUpdated(uint16_t instId) { UAVObjInstanceUpdated($(NAME)Handle(), instId); } -static inline __attribute__((always_inline)) -int32_t $(NAME)GetMetadata(UAVObjMetadata *dataOut) { return UAVObjGetMetadata($(NAME)Handle(), dataOut); } +static inline int32_t $(NAME)GetMetadata(UAVObjMetadata *dataOut) { return UAVObjGetMetadata($(NAME)Handle(), dataOut); } -static inline __attribute__((always_inline)) -int32_t $(NAME)SetMetadata(const UAVObjMetadata *dataIn) { return UAVObjSetMetadata($(NAME)Handle(), dataIn); } +static inline int32_t $(NAME)SetMetadata(const UAVObjMetadata *dataIn) { return UAVObjSetMetadata($(NAME)Handle(), dataIn); } -static inline __attribute__((always_inline)) -int8_t $(NAME)ReadOnly() { return UAVObjReadOnly($(NAME)Handle()); } +static inline int8_t $(NAME)ReadOnly() { return UAVObjReadOnly($(NAME)Handle()); } // Field information $(DATAFIELDINFO)