📄 main.c
字号:
// ----------------------------------------------------------------------------
// ATMEL Microcontroller Software Support - ROUSSET -
// ----------------------------------------------------------------------------
// DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// ----------------------------------------------------------------------------
// File Name : main.c
// Object : main application written in C
// Creation : JPP 08-Sep-2005
// ----------------------------------------------------------------------------
// Include Standard LIB files
#include "project.h"
//* Waiting time between AT91B_LED1 and AT91B_LED2
#define WAIT_TIME AT91B_MCK
#define PIO_INTERRUPT_LEVEL 6
#define SOFT_INTERRUPT_LEVEL 2
#define FIQ_INTERRUPT_LEVEL 7 // Always high
//* Global variable
int count_timer0_interrupt;
int count_timer1_interrupt;
// Use the Library Handler defined in file periph/pio/pio_irq/irq_pio.s
extern void FIQ_init_handler(void);
// External Function Prototype
extern void timer_init (void );
extern void Usart_init (void);
//*----------------------------------------------------------------------------
//* Function Name : aic_software_interrupt
//* Object : Software interrupt function
//* Input Parameters : none
//* Output Parameters : none
//* Functions calAT91B_LED : at91_pio_write
//*----------------------------------------------------------------------------
__ramfunc void aic_software_interrupt(void)
{
//* Read the output state
if ( (AT91F_PIO_GetInput(AT91C_BASE_PIOB) & AT91B_LED2 ) == AT91B_LED2 )
{
AT91F_PIO_ClearOutput( AT91C_BASE_PIOB, AT91B_LED2 );
}
else
{
AT91F_PIO_SetOutput( AT91C_BASE_PIOB, AT91B_LED2 );
}
}
//*----------------------------------------------------------------------------
//* Function Name : pio_c_irq_handler
//* Object : Irq Handler calAT91B_LED by the irq_pio.s
//* Input Parameters : none
//* Output Parameters : none
//* Functions calAT91B_LED : at91_pio_read, at91_pio_write
//*----------------------------------------------------------------------------
//__ramfunc void pio_c_irq_handler ( void )
void pio_c_irq_handler ( void )
{
int dummy;
//* Read the output state
if ( (AT91F_PIO_GetInput(AT91C_BASE_PIOB) & AT91B_LED2 ) == AT91B_LED2 )
{
AT91F_PIO_ClearOutput( AT91C_BASE_PIOB, AT91B_LED2);
}
else
{
AT91F_PIO_SetOutput( AT91C_BASE_PIOB, AT91B_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) & AT91B_SW5 ) != AT91B_SW5 );
}
//*----------------------------------------------------------------------------
//* Function Name : delay
//* Object : Wait
//* Input Parameters : none
//* Output Parameters : none
//* Functions calAT91B_LED : 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
//* 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_PIOB ) ;
//* then, we configure the PIO Lines corresponding to AT91B_LEDx
//* 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_PIOB, AT91B_LED_MASK ) ;
//* Clear the AT91B_LED's. On the EK we must apply a "1" to turn off AT91B_LEDs
AT91F_PIO_SetOutput( AT91C_BASE_PIOB, AT91B_LED_MASK ) ;
//* Clear the AT91B_LED's. On the EK we must apply a "1" to turn off AT91B_LEDs
//* open external PIO interrupt
//* define switch SW5 at PIO input for interrupt IRQ loop
AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA ) ;
AT91F_PIO_CfgInput(AT91C_BASE_PIOA, AT91B_SW5 | AT91B_SW4);
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,AT91B_SW4);
//* set the interrupt by software
AT91F_AIC_EnableIt (pAic, AT91C_ID_PIOA);
//* 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);
//* open FIQ interrupt
AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA,AT91B_SW1,0);
AT91F_AIC_ConfigureIt ( pAic, AT91C_ID_FIQ, FIQ_INTERRUPT_LEVEL,AT91C_AIC_SRCTYPE_EXT_NEGATIVE_EDGE, FIQ_init_handler);
AT91F_AIC_EnableIt (pAic, AT91C_ID_FIQ);
//* generate FIQ interrupt by software
AT91F_AIC_Trig (pAic,AT91C_ID_FIQ) ;
//* Init timer interrupt
timer_init();
//* Init Usart
Usart_init();
//* generate software interrupt
AT91F_AIC_Trig (pAic,AT91C_ID_SYS) ;
for (;;)
{
AT91F_PIO_ClearOutput( AT91C_BASE_PIOB, AT91B_LED1 );
delay () ;
AT91F_PIO_SetOutput( AT91C_BASE_PIOB, AT91B_LED1 );
delay () ;
loop_count ++ ;
//* Set AT91B_LED by software interrupt
if (loop_count == 10)
{
loop_count=0;
//* Software interrupt
AT91F_AIC_Trig (pAic,AT91C_ID_SYS) ;
}
}
//* End
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -