Folks,
It would be neat to be able to make the ISR a private method on a class, and to make the variables (e.g. counters) used by the ISR private fields on the same class. That would encapsulate the ISR inside of the class. The information from the ISR will be available through public getter methods.
I wrote the following quick test class. To my surprise, it had compiled (CCStudio 6.1.0.00104). I was expecting that the compiler would demand that I make the ISRs and private fields static. Why didn't it complain? Where will the ISR call be routed at runtime (there may be multiple instances)?
class InterruptHandler {
public:
bool GetNMIFlag() { return m_nmiFlag; }
bool GetWDTFlag() { return m_wdtFlag; }
private:
bool m_nmiFlag, m_wdtFlag;
// PURPOSE: Keep track of button presses
#pragma vector=NMI_VECTOR
__interrupt void nmi_isr(void) {
m_nmiFlag = true;
__bic_SR_register_on_exit(LPM4_bits); // exit the LPM on return from the ISR
}
// PURPOSE: Keep track of time while napping. Allow cyclic wake up.
#pragma vector=WDT_VECTOR
__interrupt void wdt_isr(void) {
m_wdtFlag = true;
__bic_SR_register_on_exit(LPM3_bits); // exit the LPM on return from the ISR
}
};
Of course, I can call the interrupt handler object from a free-standing ISR function, but that doesn't completely encapsulate the interrupt handling.
Any suggestion, insight or reference is really appreciated!
Cheers,
- Nick