I'm working in a micro controller using C language. In this specific micro, the interrupts have to be defined using #pragma
in following way:
static void func();
#pragma INTERRUPT func <interrupt_address> <interrupt_category>
static void func() { /* function body */ }
The <interrupt_address>
is address of the interrupt in vector table. The <interrupt_category>
is either 1 or 2. For example, to define an interrupt in Port 0 pin 0:
static void _int_p00();
#pragma INTERRUPT _int_p00 0x10 1
static void _int_p00() { (*isr_p00)(); }
We define actual interrupt service routine elsewhere and use function pointer (like isr_p00
in the example) to execute them.
It would be convenient if the interrupts could be defined using a macro. I want do define a macro in following way:
#define DECLARE_INTERRUPT(INT_NAME, INT_CAT) \
static void _int_##INT_NAME(); \
#pragma INTERRUPT _int_##INT_NAME INT_NAME##_ADDR INT_CAT \
static void _int_##INT_NAME() { (*isr_##INT_NAME)(); }
The compiler throwing the following error:
Formal parameter missing after '#'
indicating following line:
static void _int_##INT_NAME() { (*isr_##INT_NAME)(); }
I guess preprocessor directives cannot be used in #define
s? Is there any work around?
Thanks for your help.