Sunday, August 14, 2011

PC-Lint: Interrupt Service Routines

PC-Lint regularly warns about Interrupt Service Routines (ISR) not being used. The simplest remedy is just an esym for every ISR: /*lint -esym(528,Interrupt_SCI0_ERI0) */ #pragma interrupt Interrupt_SCI0_ERI0(vect=VECT_SCI0_ERI0) static void Interrupt_SCI0_ERI0(void) { ... } But see how WET this code is? First you tell PC-Lint it's an ISR. Then you tell the toolchain it's an ISR. Then you write the function head, which - surprise! - has the signature of an ISR. We can do better than that: /* Define this once */ #ifdef _lint /*lint -e(961) Suppress MISRA warning for function-like macro */ #define INTERRUPT(VECT,HANDLER) \ /*lint -esym(528,HANDLER) Suppress warning for unused function */ \ static void HANDLER(void) #else #define DO_PRAGMA(X) _Pragma(#X) #define INTERRUPT(VECT,HANDLER) \ DO_PRAGMA(interrupt HANDLER(vect=VECT)) \ static void HANDLER(void) #endif /* And define all your ISR like this: */ INTERRUPT(VECT_SCI0_ERI0,Interrupt_SCI0_ERI0) { ... } More examples for different pragmas expected by other toolchains to follow.

1 comment: