AVR GCC错误初始化元素不是常量

时间:2016-02-17 09:08:29

标签: gcc avr atmelstudio

我正在使用Atmel Studio 6.2,芯片xmega64D3,我在初始化结构的某些字段时遇到问题:

typedef struct
{
    uint32_t val;
    uint32_t inv;
    uint32_t xor;
}SPROTU32;

typedef struct
{
    SPROTU32 SerialNr;
    SPROTU32 SwVersion;
    SPROTU32 HwVersion;
    SPROTU32 ProdCode;
    SPROTU32 ProdDate;
    SPROTU32 PartNum;
}BasicData;

#define sw_high                     02
#define sw_low                      12
#define sw_ver                      ((sw_high << 16) + sw_low)

#define hw_high                     01
#define hw_low                      06
#define hw_ver                      ((hw_high << 16) + hw_low)

#define DEFAULT_SERIAL              0
#define DEFAULT_SW_VERSION          sw_ver
#define DEFAULT_HW_VERSION          hw_ver
#define DEFAULT_PROD_CODE           0
#define DEFAULT_PROD_DATE           0
#define DEFAULT_PART_NUM            05545410

EEMEM BasicData eeBasicData =
{
    {DEFAULT_SERIAL,~DEFAULT_SERIAL,DEFAULT_SERIAL^0x55555555},
    {DEFAULT_SW_VERSION,~DEFAULT_SW_VERSION,DEFAULT_SW_VERSION^0x55555555},
    {DEFAULT_HW_VERSION,~DEFAULT_HW_VERSION,DEFAULT_HW_VERSION^0x55555555},
    {DEFAULT_PROD_CODE,~DEFAULT_PROD_CODE,DEFAULT_PROD_CODE^0x55555555},
    {DEFAULT_PROD_DATE,~DEFAULT_PROD_DATE,DEFAULT_PROD_DATE^0x55555555},
    {DEFAULT_PART_NUM,~DEFAULT_PART_NUM,DEFAULT_PART_NUM^0x55555555}
};

Compile output image

编译器说始终initilizer不是常量。那么,我该如何用我想要的东西来初始化我的结构呢?

1 个答案:

答案 0 :(得分:0)

尝试使用乘法运算而不是&lt;&lt;操作

 #define _VERSION(h,l) ((h * 65536) | l)
 #define DEFAULT_SW_VERSION _VERSION(sw_high, sw_low)