I am working on embedded code and attempting to convert a lot of memory-mapped register assignments to get()/set() function calls. I was wondering if it would be possible to maintain the address assignments sprinkled throughout the code, but change the #defines so they take the assignment in as a function argument.
Old Way:
#define MOTOR_REG (*(volatile unsigned char *)(0xFEE002)); //a memory-mapped register
MOTOR_REG = value; //sets value into the memory-mapped register
Desired New Way:
#define MOTOR_REG( set_motor_reg(value); )
void set_motor_reg(unsigned char)
{
//logic to set the motor register
}
MOTOR_REG = value; //value should be passed in to MOTOR_REG macro
So, is this scenario possible with C macros? Thanks for your thoughts!