Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: PIO Interrupt basics
PostPosted: Wed Nov 09, 2011 4:29 pm 
Offline

Joined: Tue Nov 08, 2011 12:51 pm
Posts: 3
Hello,

I want to run a FreeRTOS program on my Netduino plus board which has AT91SAM7X512 microcontroller. I'm working on the ARM7 uIP demo for IAR (uIP_Demo_IAR_ARM7) that's provided with the FreeRTOS source code. 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.
The netduino has an onaboard button (PA29) and I want to initialise and handle the interrupts 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.

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:
[code]
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 );
}
}
[/code]

And in the prvSetupHardware function I have added the following:
[code]
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);

[/code]

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


Top
 Profile  
 
 Post subject: Re: PIO Interrupt basics
PostPosted: Thu Nov 10, 2011 1:54 pm 
Offline

Joined: Tue Nov 08, 2011 12:51 pm
Posts: 3
OK... when I read more carefully the sam7x documentation I found that I've made a bunch of mistakes and now it all looks fine but still not working...

The FreeRTOS team told me that I need to configure the SAM7 interrupt and this is not specific to the FreeRTOS stuff.

And here is my code:

[code]
void Handler(void)
{
unsigned int isr = AT91C_BASE_PIOA->PIO_ISR;
if( isr & SW1 )
{
// Button
AT91F_PIO_SetOutput( AT91C_BASE_PIOB, LED1 ); // turn ON
}

AT91C_BASE_AIC->AIC_EOICR = 0; // Clear AIC to complete ISR processing
}

static void prvSetupHardware( void )
{
AT91F_PIO_CfgOutput( AT91C_BASE_PIOB, LED1 );
AT91F_PIO_ClearOutput( AT91C_BASE_PIOB, LED1 ); // turn OFF
AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA );
AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_PIOB ) ;

AT91F_PIO_InterruptEnable( AT91C_BASE_PIOA, SW1 );

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,
PIO_INTERRUPT_LEVEL,
AT91C_AIC_SRCTYPE_EXT_NEGATIVE_EDGE,
Handler);
AT91F_AIC_EnableIt(AT91C_BASE_PIOA, AT91C_ID_PIOA);
}
[/code]

Is the interrupt initialization code OK?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: