In migrating from earlier Piccolo mcus to the TMS320F28075, I've noticed a number of changes in the how the chip is used in the Control Suite source files. One example of this is that there are now dedicated functions for writing to and reading GPIO pins (namely GPIO_ReadPin and GPIO_WritePin in "F2807x_Gpio.c"). This actually seems like a much better way of accessing GPIOs than the previous method of having a number of GPIO structures for groups of GPIOs (A, B, C, etc.). However, when inspecting the source code, it seems like a lot of computation for simply setting a GPIO (see write routine below).
volatile Uint32 *gpioDataReg;
Uint32 pinMask;
gpioDataReg = (volatile Uint32 *)&GpioDataRegs + (pin/32)*GPY_DATA_OFFSET;
pinMask = 1UL << (pin % 32);
if (outVal == 0)
gpioDataReg[GPYCLEAR] = pinMask;
else
gpioDataReg[GPYSET] = pinMask;
I rewrote the write and read routines as macros so that most of the routine could be handled by the preprocessor. Some timing tests using an oscilloscope to set and immediately clear a GPIO show that the write macro sets and clears in 16.8ns (vs. 324ns with the function calls) with an optimization setting of 2. Is there any reason why TI didn't opt for macros instead of functions for this?
#define GPIOREG(PIN) ((volatile Uint32 *)&GpioDataRegs + ((PIN / 32) * GPY_DATA_OFFSET))
#define PINMASK(PIN) (1UL << ((PIN) % 32))
#define GPIO_WRITE(PIN, VAL) if(VAL == 0) GPIOREG(PIN)[GPYCLEAR] = PINMASK(PIN); \
else GPIOREG(PIN)[GPYSET] = PINMASK(PIN)