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  [ 3 posts ] 
Author Message
 Post subject: Interrupt Generation using Timer Counter AT91SAM7X256
PostPosted: Tue Jul 05, 2011 12:11 pm 
Offline

Joined: Fri Jul 01, 2011 4:01 pm
Posts: 3
Hi,
I am trying to do a basic use of interrupts with the AT91SAM7X256 board. As there are no LEDs in this board I am trying to turn on the Backlight of the LCD on and OFF every 1 sec using Timer Channel 1. But I have a problem with irq handler, I do not get the right asm code for the handler, can anyone help me with that please.
Thank you


Top
 Profile  
 
 Post subject: Re: Interrupt Generation using Timer Counter AT91SAM7X256
PostPosted: Tue Jul 05, 2011 6:31 pm 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 574
This is a bit of a cut-n-paste job from a Keil app I had for the SAM7S. Not sure it helps here, but you request isn't specific about toolchains or GPIO ports. The IRQ/FIQ vectors jump to the AIC vector address.

// Keil AT91SAM7S-EK

#include <AT91SAM7S64.H> /* AT91SAMT7S64 definitions */
#include <lib_AT91SAM7S64.h>
#include "Board.h"

/*****************************************************************************/

#define TCK 1000 /* Timer Clock */

#define PIV ((MCK/TCK/16)-1) /* Periodic Interval Value (1ms)*/

/*****************************************************************************/

volatile unsigned long timeval; /* Current Time Tick */
int led_pit = 0;

/*****************************************************************************/

__irq void system_int (void) /* System Interrupt Handler */
{
if (*AT91C_PITC_PISR & AT91C_PITC_PITS) /* Check PIT Interrupt */
{
timeval++; /* Increment Time Tick */

if ((timeval % 500) == 0) /* 500ms Elapsed ? */
{
if (led_pit++ & 1)
*AT91C_PIOA_CODR = LED4;
else
*AT91C_PIOA_SODR = LED4;
}

*AT91C_AIC_ICCR = (1 << AT91C_ID_SYS); // Clear the SYS interrupt
*AT91C_AIC_EOICR = *AT91C_PITC_PIVR; /* Ack & End of Interrupt */
}
}

/*****************************************************************************/

void init_timer (void) /* Setup PIT with Interrupt */
{
AT91S_AIC * pAIC = AT91C_BASE_AIC;

*AT91C_PITC_PIMR = AT91C_PITC_PITIEN | /* PIT Interrupt Enable */
AT91C_PITC_PITEN | /* PIT Enable */
PIV; /* Periodic Interval Value */

*AT91C_PITC_PIVR += 0;

/* Setup System Interrupt Mode and Vector with Priority 7 and Enable it */
pAIC->AIC_SMR[AT91C_ID_SYS] = AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | 7;
pAIC->AIC_SVR[AT91C_ID_SYS] = (unsigned long) system_int;
pAIC->AIC_ICCR = (1 << AT91C_ID_SYS); // Clear the SYS interrupt
pAIC->AIC_IECR = (1 << AT91C_ID_SYS); // Enable the SYS interrupt
}

/*****************************************************************************/

/*
* Main Program
*/

int main (void)
{
// Enable the Clock of the PIO
AT91F_PMC_EnablePeriphClock(AT91C_BASE_PMC, 1 << AT91C_ID_PIOA);

// Enable the Clock of the AIC & SYS
AT91F_PMC_EnablePeriphClock(AT91C_BASE_PMC, (1 << AT91C_ID_FIQ) | (1 << AT91C_ID_SYS));

// Configure the PIO Lines corresponding to LED1..LED4 as Outputs
AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, LED_MASK);

// Clear the LED's. On the Board we must apply a "1" to turn off LEDs
AT91F_PIO_SetOutput(AT91C_BASE_PIOA, LED_MASK);

init_timer(); /* Initialize Timer */

// Loop forever
for (;;);
}

/*****************************************************************************/


Top
 Profile  
 
 Post subject: Re: Interrupt Generation using Timer Counter AT91SAM7X256
PostPosted: Wed Jul 06, 2011 2:56 pm 
Offline

Joined: Fri Jul 01, 2011 4:01 pm
Posts: 3
Hi, thank you, but you gave a code to generate an interrupt through Periodic Timer, I want to do through the Timer Counters..


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 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: