This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/CODECOMPOSER: MAVPACKED issue

Part Number: CODECOMPOSER


Tool/software: Code Composer Studio

Hello. I want to use mavlink in my project. Code generator generate next code

..... 
#define MAVPACKED( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) )
.....
MAVPACKED(
typedef struct __mavlink_message {
	uint16_t checksum;      ///< sent at end of packet
	uint8_t magic;          ///< protocol magic marker
	uint8_t len;            ///< Length of payload
	uint8_t incompat_flags; ///< flags that must be understood
	uint8_t compat_flags;   ///< flags that can be ignored if not understood
	uint8_t seq;            ///< Sequence of packet
	uint8_t sysid;          ///< ID of message sender system/aircraft
	uint8_t compid;         ///< ID of the message sender component
	uint32_t msgid:24;      ///< ID of message in payload
	uint64_t payload64[(MAVLINK_MAX_PAYLOAD_LEN+MAVLINK_NUM_CHECKSUM_BYTES+7)/8];
	uint8_t ck[2];          ///< incoming checksum bytes
	uint8_t signature[MAVLINK_SIGNATURE_BLOCK_LEN];
}) mavlink_message_t;

macros MAVPACKED used to change structure alignment. TI compiler doesn't compile this code. i try to change it like this

 

#define MAVPACKED( __Declaration__ ) #pragma pack(push, 1) __Declaration__ #pragma pack(pop)

but it doesn't compile too. who knows how to fix it? Replace this macros in each place of using is bad variant for me.

  • I can test my suggested solution only so much, so I am not completely confident it is correct.  But I think something close to this will work ...

    #if defined(__TI_COMPILER_VERSION__) // Test if using TI compiler
    #define MAVPACKED( __Declaration__ ) __Declaration__ __attribute__((packed))
    #else
    #define MAVPACKED( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) )
    #endif
    

    The TI compilers support many (not all) GCC attributes.  The attribute packed is supported by all of them except C2000.

    Thanks and regards,

    -George