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.
#define PULSE_WIDTH_MEASUREMENT_CHANNEL 3
#define PWM_GEN_CHANNEL 4
I want something like this in my ISRs:
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?