I develop an embedded application which uses the MindTree Bluetooth SDK.
I have the following in a header file:
typedef struct {
UCHAR outputDir;
UCHAR reset;
UCHAR nack;
UCHAR startCondition;
UCHAR stopCondition;
UCHAR busy;
} USCI_ConfigurationFlags;
static USCI_ConfigurationFlags usciConfigFlags = { UCTR, UCSWRST, UCNACKIFG, UCTXSTT, UCTXSTP, UCBBUSY };
Later in two .c files I include the above header and use the usciConfigFlags on different occasions sometimes from within an interrupt.
Is this legal?
I’m trying to understand why(and if it is related to the question) the values of the struct change at runtime, after calling the BT_bluetooth_on method in the SDK.
Thanks,
Adam.
statichere doesn’t mean what you think it means. It means that the declaration and variable will only be visible in one compilation unit. That is, you have two independent instances ofusciConfigFlags.If you want a global variable, you need to use
externnotstaticand make the actual declaration (withoutextern) with the initial value in one of your c files.Also be weary of changing the values in the struct without proper locking. Read-only concurrent access is usually fine.