I am looking through some Atmel ARM code and cannot decipher the following:
I am trying to configure an interrupt and the example code to configure it is as follows:
Here you are calling a function with variables 'source', 'mode' and a general pointer 'handler'
All good so far..
Elsewhere in the text, the interrupt service routine is specified:
The bit I am having trouble with is when IRQ_ConfigureIT is called. The line used is:
Here it looks like they are using the function name (TC0_IrqHandler) as a variable in the function call.
Does C allow you to do this, or am I misinterpreting this? I thought function calls can only use variables, not function names.
Any thoughts would be most welcome.
Thanks
Simon
I am trying to configure an interrupt and the example code to configure it is as follows:
Code:
void IRQ_ConfigureIT(unsigned int source,
unsigned int mode,
void( *handler )( void ))
{
// Disable the interrupt first
AT91C_BASE_AIC->AIC_IDCR = 1 << source;
// Configure mode and handler
AT91C_BASE_AIC->AIC_SMR[source] = mode;
AT91C_BASE_AIC->AIC_SVR[source] = (unsigned int) handler;
// Clear interrupt
AT91C_BASE_AIC->AIC_ICCR = 1 << source;
}
Here you are calling a function with variables 'source', 'mode' and a general pointer 'handler'
All good so far..
Elsewhere in the text, the interrupt service routine is specified:
Code:
void TC0_IrqHandler(void)
{
volatile unsigned int dummy;
// Clear status bit to acknowledge interrupt
dummy = AT91C_BASE_TC0->TC_SR;
// Toggle LED state
LED_Toggle(1);
printf("2 ");
}
The bit I am having trouble with is when IRQ_ConfigureIT is called. The line used is:
Code:
IRQ_ConfigureIT(AT91C_ID_TC0, 0, TC0_IrqHandler);
Here it looks like they are using the function name (TC0_IrqHandler) as a variable in the function call.
Does C allow you to do this, or am I misinterpreting this? I thought function calls can only use variables, not function names.
Any thoughts would be most welcome.
Thanks
Simon