Trying to do some macros on Code Composer for a MSP430FRx project. The expansion is not working out as expected.
The macro definitions
#define SMCLK PORT_PIN(1, 0)
#define PORT_PIN(port, pin) port,pin
#define GPIO_SEL0_SET(port, pin) \
_GPIO_SEL0_SET(port, pin)
#define _GPIO_SEL0_SET(port, pin) \
BIT_SET(P ## port ## SEL0, BIT ## pin)
#define BIT_SET(reg, bit) reg |= bit
This is the expansion that Code Composer does:
GPIO_SEL0_SET(SMCLK) -> GPIO_SEL0_SET(PORT_PIN(1, 0)) -> GPIO_SEL0_SET(1,0) -> _GPIO_SEL0_SET(1,0, )
Here already there is a non intended result. The last expansion added a comma. The expexted expansion was _GPIO_SEL0_SET(1,0)
_GPIO_SEL0_SET(1,0, ) -> BIT_SET(P1SEL0, BIT0) ) -> BIT_SET(P1SEL0,(0x0001)) ) -> P1SEL0 |= (0x0001) )
It ends up having an extra parenthesis.
The weirdest steps happens here:
What went wrong in this expansion?