I need to program peripheral registers in an ARM9 microcontroller.
For example, for USART, I save the corresponding memory addresses in enum :
enum USART { US_BASE = (int) 0xFFFC4000, US_BRGR = US_BASE + 0x16,
Then I use pointers in the function to initialize the registers:
void init_usart (void) { vuint* pBRGR = (vuint*) US_BRGR; *pBRGR = 0x030C;
But my teacher says I better use #define s, for example:
#define US_BASE (0xFFFC4000) #define US_BRGR (US_BASE + 0x16) #define pBRGR ((vuint*) US_BRGR) void init_usart (void) { *pBRGR = 0x030C; }
So, he says, you don't have the overhead of allocating pointers on the stack.
Personally, I don't like the #define many other preprocessor directives. So, the question is in this particular case: is it really worth using #define instead of enum and pointers assigned by stacks?
Related question: Want to configure a specific peripheral register in an ARM9-based chip
c enums c-preprocessor arm embedded
paulo.arras
source share