|
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 (;;); }
/*****************************************************************************/
|