//*----------------------------------------------------------------------------
//* Function Name : aic_software_interrupt
//* Object : Software interrupt function
//* Input Parameters : none
//* Output Parameters : none
//* Functions called : at91_pio_write
//*----------------------------------------------------------------------------
__ramfunc void aic_software_interrupt(void)
{
//* Read the output state
if ( (AT91F_PIO_GetInput(AT91C_BASE_PIOA) & LED2 ) == LED2 )
{
AT91F_PIO_ClearOutput( AT91C_BASE_PIOA, LED2 );
}
else
{
AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED2 );
}
}
//*----------------------------------------------------------------------------
//* Function Name : pio_c_irq_handler
//* Object : Irq Handler called by the irq_pio.s
//* Input Parameters : none
//* Output Parameters : none
//* Functions called : at91_pio_read, at91_pio_write
//*----------------------------------------------------------------------------
__ramfunc void pio_c_irq_handler ( void )
{
int dummy;
//* Read the output state
if ( (AT91F_PIO_GetInput(AT91C_BASE_PIOA) & LED2 ) == LED2 )
{
AT91F_PIO_ClearOutput( AT91C_BASE_PIOA, LED2);
}
else
{
AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED2);
}
//* enable the next PIO IRQ
dummy =AT91C_BASE_PIOA->PIO_ISR;
//* suppress the compilation warning
dummy =dummy;
//* while SW3 is push wait
while ( (AT91F_PIO_GetInput(AT91C_BASE_PIOA) & SW3_MASK ) != SW3_MASK );
}
//*----------------------------------------------------------------------------
//* Function Name : delay
//* Object : Wait
//* Input Parameters : none
//* Output Parameters : none
//* Functions called : none
//*----------------------------------------------------------------------------
void delay ( void )
{
//* Set in Volatile for Optimisation
volatile unsigned int i ;
//* loop delay
for ( i = 0 ;(i < WAIT_TIME/100 );i++ ) ;
}
//*----------------------------------------------------------------------------
//* Function Name : main
//* Object : Main interrupt function
//* level timer 0 => 1
//* SW2 level Irq0 => 2
//* level timer 1 => 4
//* SW4 level PIOA => 6
//* level USART => 7
//* LEVEL FIQ => MAX
//* Input Parameters : none
//* Output Parameters : TRUE
//*----------------------------------------------------------------------------
int main( void )
//* Begin
{
unsigned int loop_count ;
AT91PS_AIC pAic;
//* Load System pAic Base address
pAic = AT91C_BASE_AIC;
//* Enable User Reset and set its minimal assertion to 960 us
AT91C_BASE_RSTC->RSTC_RMR = AT91C_RSTC_URSTEN | (0x4<<8) | (unsigned int)(0xA5<<24);
//* Init
loop_count = 0 ;
// First, enable the clock of the PIOB
AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA ) ;
//* then, we configure the PIO Lines corresponding to LED1 to LED8
//* to be outputs. No need to set these pins to be driven by the PIO because it is GPIO pins only.
AT91F_PIO_CfgOutput( AT91C_BASE_PIOA, LED_MASK ) ;
//* Clear the LED's. On the EB55 we must apply a "1" to turn off LEDs
AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED_MASK ) ;
//* open external PIO interrupt
//* define switch SW3 at PIO input for interrupt IRQ loop
AT91F_PIO_CfgInput(AT91C_BASE_PIOA, SW3_MASK | SW4_MASK);
AT91F_AIC_ConfigureIt ( pAic, AT91C_ID_PIOA, PIO_INTERRUPT_LEVEL,AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL, pio_c_irq_handler);
AT91F_PIO_InterruptEnable(AT91C_BASE_PIOA,SW4_MASK);//*
//* set the interrupt by software
AT91F_AIC_EnableIt (pAic, AT91C_ID_PIOA);
//* open external IRQ interrupt
AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA,SW2_MASK,0);
//* open external IRQ0 interrupt
AT91F_AIC_ConfigureIt ( pAic, AT91C_ID_IRQ0, IRQ0_INTERRUPT_LEVEL,AT91C_AIC_SRCTYPE_EXT_NEGATIVE_EDGE, at91_IRQ0_handler);
AT91F_AIC_EnableIt (pAic, AT91C_ID_IRQ0);
//* Open the software interrupt on the AIC
AT91F_AIC_ConfigureIt ( pAic, AT91C_ID_SYS, SOFT_INTERRUPT_LEVEL, AT91C_AIC_SRCTYPE_INT_POSITIVE_EDGE, aic_software_interrupt);
AT91F_AIC_EnableIt (pAic, AT91C_ID_SYS);