Other Parts Discussed in Thread: MSP430F5438
Hello,
I am trying to figure out how to use the register definitions that are found in the MSP430xxxx header files to initialize data at compile time. Right now, I am having to hard code the actual addresses like the following:
#define GPIO_REG(reg) ((volatile unsigned char*)(reg))
typedef struct
{
volatile unsigned char *In,
*Out,
*Dir,
*Sel;
} GpioRegSet_t;
/* -- Dummy Register -- */
uint8_t GpioDummyReg;
GpioRegSet_t GpioRegSet[] =
{
/* *IN *OUT *DIR *SEL */
{ &GpioDummyReg, &GpioDummyReg, &GpioDummyReg, &GpioDummyReg }, // Port 0
{ GPIO_REG(0x0200), GPIO_REG(0x0202), GPIO_REG(0x0204), GPIO_REG(0x020A) }, // Port 1
{ GPIO_REG(0x0201), GPIO_REG(0x0203), GPIO_REG(0x0205), GPIO_REG(0x020B) }, // Port 2
{ GPIO_REG(0x0220), GPIO_REG(0x0222), GPIO_REG(0x0224), GPIO_REG(0x022A) }, // Port 3
{ GPIO_REG(0x0220), GPIO_REG(0x0223), GPIO_REG(0x0225), GPIO_REG(0x022B) } // Port 4
};
Ideally, I would love just to do the following:
GpioRegSet_t GpioRegSet[] =
{
/* *IN *OUT *DIR *SEL */
{ &GpioDummyReg, &GpioDummyReg, &GpioDummyReg, &GpioDummyReg }, // Port 0
{ P1IN, P1OUT, P1DIR, P1SEL }, // Port 1
{ P2IN, P2OUT, P2DIR, P2SEL }, // Port 1
{ P3IN, P3OUT, P3DIR, P3SEL }, // Port 1
{ P4IN, P4OUT, P4DIR, P4SEL }, // Port 1
};
But this will not work as I will get a compiler error of "#28 expression must have a constant value". For one example, P1IN is defined as:
#define P1IN (PAIN_L) /* Port 1 Input */
Which is defined as:
SFR_8BIT(PAIN_L); /* Port A Input */
where SFR_8BIT(x) is defined as
#define SFR_8BIT(address) extern volatile unsigned char address
I image the tool chain is filling in the addresses based upon the particular processor which is probably happening a link time (????), but I am not sure. Is there a way I can use these definition to initialize variable and arrays, if so how?
Oh, almost forgot, I am using Code Composer Studio v6.0.1
Thanks,
Mark