⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main_rom_monitor.c

📁 ATMEL AT91RM9200开发板配套光盘上的全部示例程序
💻 C
字号:
//*----------------------------------------------------------------------------
//*         ATMEL Microcontroller Software Support  -  ROUSSET  -
//*----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*----------------------------------------------------------------------------
//* File Name           : main_Rom_monitor.c
//* Object              : main application written in C
//* Creation            : JPP   21/Nov/2002 use main file and suppress FIQ management
//*			
//*----------------------------------------------------------------------------

// Include Standart LIB  files 
#include "include/AT91M55800A.h"
#include "include/lib_AT91M55800A.h"
#include "eb55.h"

//*   Waiting time between LED1 and LED2
#define     WAIT_TIME       MCK

#define PIO_INTERRUPT_LEVEL		6
#define IRQ0_INTERRUPT_LEVEL		2
#define SOFT_INTERRUPT_LEVEL		5
#define FIQ_INTERRUPT_LEVEL		0



//* 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 pio_asm_irq_handler(void);
extern void irq0_asm_irq_handler(void);
extern void sw_asm_irq_handler(void);
extern void fiq_asm_handler(void);

// External Function Prototype
extern int timer_init (void );
extern void Usart_init (void);
//*----------------------------------------------------------------------------
//* Function Name       : aic_software_interrupt
//* Object              : Sofware interup function
//* Input Parameters    : none
//* Output Parameters   : none
//* Functions called    : at91_pio_write
//*----------------------------------------------------------------------------
void aic_software_interrupt(void)
{
    //* read the ouput state
    if ( (AT91F_PIO_GetInput(AT91C_BASE_PIOB) & LED3 ) == LED3 )
    {
        AT91F_PIO_ClearOutput( AT91C_BASE_PIOB, LED3 );
    }
    else
    {
        AT91F_PIO_SetOutput( AT91C_BASE_PIOB, LED3 );
    }
}

//*----------------------------------------------------------------------------
//* 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
//*----------------------------------------------------------------------------
void pio_c_irq_handler ( void )
{
int dummy;
    //* read the ouput state
    if ( (AT91F_PIO_GetInput(AT91C_BASE_PIOB) & LED5 ) == LED5 )
    {
       AT91F_PIO_ClearOutput( AT91C_BASE_PIOB, LED5);
    }
    else
    {
          AT91F_PIO_SetOutput( AT91C_BASE_PIOB, LED5);
    }
    //* enable the next PIO IRQ
    dummy =AT91C_BASE_PIOB->PIO_ISR;
    //* suppress the compilation warning
    dummy =dummy;
    //* while SW4 is push wait
    while ( (AT91F_PIO_GetInput(AT91C_BASE_PIOB) & SW4_MASK ) != SW4_MASK );
}

//*----------------------------------------------------------------------------
//* Function Name       : delay
//* Object              : Wait
//* Input Parameters    : none
//* Output Parameters   : none
//* Functions called    : none
//*----------------------------------------------------------------------------
void delay ( void )
{
    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
//*----------------------------------------------------------------------------
void main( void )
//* Begin
{
    unsigned int   loop_count ;
    AT91PS_AIC     pAic;
        // Load System pAic Base address 
        pAic = AT91C_BASE_AIC; 

	//* Init
     	loop_count = 0 ;
    	// First, enable the clock of the PIOB
    	AT91F_APMC_EnablePeriphClock ( AT91C_BASE_APMC, 1<<AT91C_ID_PIOB ) ;

    	// 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_PIOB, LED_MASK ) ;

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

    	//* define switch SW4 at PIO input interupt PIO_OPENDRAIN_BIT
 	AT91F_PIO_CfgInput(AT91C_BASE_PIOB,SW4_MASK);

    	//* define switch SW4 at PIO input interupt PIO_OPENDRAIN_BIT
	AT91F_PIO_CfgOpendrain(AT91C_BASE_PIOB,SW4_MASK);

    	//* open external PIO interrupt
    	//* define switch SW1 at PIO input for interrupt IRQ loop
 	AT91F_PIO_CfgInput(AT91C_BASE_PIOB,SW1_MASK);

	AT91F_AIC_ConfigureIt ( pAic, AT91C_ID_PIOB, PIO_INTERRUPT_LEVEL,AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE, pio_asm_irq_handler); 
	AT91F_PIO_EnableIt(AT91C_BASE_PIOB,SW4_MASK);
	AT91F_AIC_EnableIt (pAic, AT91C_ID_PIOB);


    	//* 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_INT_EDGE_TRIGGERED, irq0_asm_irq_handler); 
	AT91F_AIC_EnableIt (pAic, AT91C_ID_IRQ0);

        //* open  FIQ interrupt
	//* NOT Supported under ANGEL ROM MONITOR
//	AT91F_AIC_ConfigureIt ( pAic, AT91C_ID_FIQ, FIQ_INTERRUPT_LEVEL,AT91C_AIC_SRCTYPE_INT_EDGE_TRIGGERED, fiq_asm_handler); 
//	AT91F_AIC_EnableIt (pAic, AT91C_ID_FIQ);
    	//* generate FIQ interrupt by software
//	AT91F_AIC_Trig (pAic,AT91C_ID_FIQ) ;

    	//* Open the software interrupt on the AIC
	AT91F_AIC_ConfigureIt ( pAic, AT91C_ID_SYS, SOFT_INTERRUPT_LEVEL, AT91C_AIC_SRCTYPE_EXT_POSITIVE_EDGE,  sw_asm_irq_handler); 
	AT91F_AIC_EnableIt (pAic, AT91C_ID_SYS);

        //* 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, LED1 );
        delay () ;

        AT91F_PIO_ClearOutput( AT91C_BASE_PIOB, LED2 );

        delay () ;
        AT91F_PIO_SetOutput( AT91C_BASE_PIOB, LED1 );
        delay () ;

        AT91F_PIO_SetOutput( AT91C_BASE_PIOB, LED2 );
        delay () ;

        loop_count ++ ;
        //* Set 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 + -