CPU: MC9S12XDT256
Codewarrior 4.5
I often need to change the configuration of the timer control register in my ISRs for things like PWM generation or pulse width measurement. Anyone who has done this knows that these shared registers are a real pain.
I'm trying to write wrapper functions that protect the registers and allow for channels to be easily reassigned with a single channel assignment macro.
Example:
#define PULSE_WIDTH_MEASUREMENT_CHANNEL 3
#define PWM_GEN_CHANNEL 4
I want something like this in my ISRs:
if(IS_IC_CHANNEL_RISING(PULSE_WIDTH_MEASUREMENT_CHANNEL))
Config_IC(PULSE_WIDTH_MEASUREMENT_CHANNEL, IC_ON_FALLING_ONLY);
else
Config_IC(PULSE_WIDTH_MEASUREMENT_CHANNEL, IC_ON_RISING_ONLY);
or
if(IS_OC_CHANNEL_RISING(PWM_GEN_CHANNEL))
Config_OC(PWM_GEN_CHANNEL, OC_CLR);
else
Config_OC(PWM_GEN_CHANNEL, OC_SET);
The functions would have to disable interrupts, read the register(s), modify and then re-enable interrupts.
Does anyone have any examples of good wrapper functions or macros that can help with the management of these registers?