ARM7 uIP Demo interrupts

brakova wrote on Wednesday, November 09, 2011:

Hi,
I’m working on the ARM7 uIP demo for IAR (uIP_Demo_IAR_ARM7) that’s provided with the source. I know that this may be an easy question but I have lost too much time trying to do it on my own. I want to be able to handle PIO button interrupts.
I have a netduino plus board (with at91sam7x512) which has an onaboard button (PA29) and I want to initialise and handle the interrupt so that when you press the button the onboard LED (PB23) will turn ON.
I want to achieve this using the provided FreeRTOS at91sam7x256 port. I already have it working with the demos which come from the atmel site but they use a very different port which fails to work together with the FreeRTOS. I want to use the FreeRTOS port because the main goal of the application will be far different from turning LEDs on and off.

I have the FreeRTOS practical guide and I know that there is a whole chapter about interrupts but I didn’t find out how can you handle a button press interrupt.

Thanks!

brakova wrote on Wednesday, November 09, 2011:

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 :slight_smile:

edwards3 wrote on Wednesday, November 09, 2011:

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.

brakova wrote on Wednesday, November 09, 2011:

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.

brakova wrote on Tuesday, November 15, 2011:

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!

rtel wrote on Tuesday, November 15, 2011:

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.

brakova wrote on Tuesday, November 15, 2011:

OK, sorry about that… :slight_smile: it looked so confising the first time, but now I fonund some documentation from Atmel that will help.

Best Regards