Here is my code:
First in board.h I have defined that LED1 is (1 << 23) and SW1 is (1 << 29).
I have the following interrupt handler, which will turn the onboard LED ON:
void Handler(void)
{
if( AT91F_PIO_GetInput( AT91C_BASE_PIOA ) & LED1 )
{
AT91F_PIO_ClearOutput( AT91C_BASE_PIOA, LED1 );
}
else
{
AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED1 );
}
}
And in the prvSetupHardware function I have added the following:
AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA );
AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_PIOB ) ;
AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_EMAC ) ;
AT91F_PIO_CfgInput( AT91C_BASE_PIOA, SW1 );
AT91F_PIO_CfgPullup( AT91C_BASE_PIOA, SW1 );
AT91F_PIO_CfgInputFilter( AT91C_BASE_PIOA, SW1 );
AT91F_AIC_ConfigureIt(AT91C_BASE_PIOA, AT91C_ID_PIOA, 0x07, 0x0, Handler);
AT91F_AIC_EnableIt(AT91C_BASE_PIOA, AT91C_ID_PIOA);
And here I am confused about am I initializing the interrupt properly? As long as the button belongs to PA29 I know that I have to use the AT91C_BASE_PIOA when I make the call to AT91F_AIC_ConfigureIt. And here I am not sure about the irq_id parameter. Should it be 29 (as I am using PA29) or should it be AT91C_ID_PIOA? And if its AT91C_ID_PIOA where should I specify that I want to handle intterupts coming from PA29?
Thanks :)
If you want help configuring the SAM7 hardware, I recommend asking your question on the SAM7 forum, or asking Atmel support. This is a FreeRTOS forum, and I cannot see how your question relates to FreeRTOS, so you are unlikely to have success asking here.
Well the thing is that I have all this already working using the port which Atmel have provided in their getting started tutorials. The problems comes when I want to use FreeRTOS with the port they have provided.
Hi, sorry about the trouble...
The problem was very strange for me. I would be very happy if someone with more experience in FreeRTOS could explain it.
So the problem was in the way I am configuring the interrupt - exactly when I make the call:
AT91F_AIC_ConfigureIt(AT91C_BASE_PIOA, AT91C_ID_PIOA, 0x07, 0x0, Handler);
If I chnage this to
AT91F_AIC_ConfigureIt(AT91C_BASE_AIC, AT91C_ID_PIOA, driverINTERRUPT_LEVEL, AT91C_AIC_SRCTYPE_EXT_LOW_LEVEL, Handler);
I have no idea why it didn't work when I activated the interrupt on the AT91C_BASE_PIOA.
Could someone explain what thoes the AT91C_AIC_SRCTYPE_EXT_LOW_LEVEL value mean?
Thanks a lot!
Happy to hear you have it working.
“Could someone explain what thoes the AT91C_AIC_SRCTYPE_EXT_LOW_LEVEL value mean?”
It is a long time since I have used that library, but from my recollection it is explained in the library comments, and in the documentation, so with respect, you can read it yourself. It is definitely not a FreeRTOS related question.
Regards.
OK, sorry about that... :) it looked so confising the first time, but now I fonund some documentation from Atmel that will help.
Best Regards