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

📄 interrupt_timer.c

📁 at91sam7 use PIO interrupt to finish PS2 protocl
💻 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           : interrupt_timer.c
// Object              : Timer interrupt management
//                     : Use AT91B_LED1 & AT91B_LED2 for status interrupt
// Creation            : JPP   11-May-2006
// ----------------------------------------------------------------------------

// Include Standard LIB  files
#include "project.h"

//* Global variable
extern int count_timer0_interrupt;
extern int count_timer1_interrupt;
int clkCurrent = 0;
extern int no_INT0_time;
#define TIMER0_INTERRUPT_LEVEL		1
#define TIMER1_INTERRUPT_LEVEL		1

/*-----------------*/
/* Clock Selection */
/*-----------------*/
#define TC_CLKS                  0x7
#define TC_CLKS_MCK2             0x0
#define TC_CLKS_MCK8             0x1
#define TC_CLKS_MCK32            0x2
#define TC_CLKS_MCK128           0x3
#define TC_CLKS_MCK1024          0x4

void AT91F_DBGU_Init (void);
void AT91F_DBGU_Printk(	char *buffer) ;
extern  void f6_delay(int num);
char print_buffer[30] = {0};
//*----------------------------------------------------------------------------
//* \fn    AT91F_DBGU_Init
//* \brief NandFlash init
//*----------------------------------------------------------------------------
void AT91F_DBGU_Init (void)
{
	// Configure DBGU
    AT91F_US_ResetRx((AT91PS_USART)AT91C_BASE_DBGU);
    AT91F_US_Configure(
		(AT91PS_USART)AT91C_BASE_DBGU, // DBGU base address
		AT91B_MASTER_CLOCK,            // 100 MHz
		AT91C_US_ASYNC_MODE,           // mode Register to be programmed
		AT91B_DBGU_BAUD_RATE,          // baudrate to be programmed
		0                              // timeguard to be programmed
	);
	// Open PIO for DBGU
    AT91F_DBGU_CfgPIO();
	// Enable Transmitter
    AT91F_US_EnableTx((AT91PS_USART)AT91C_BASE_DBGU);
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_DBGU_Printk
//* \brief This function is used to send a string through the DBGU channel
//* (Very low level debugging)
//*----------------------------------------------------------------------------
void AT91F_DBGU_Printk(	char *buffer) // \arg pointer to a string ending by \0
{
	while(*buffer != '\0') {
		while (!AT91F_US_TxReady((AT91PS_USART)AT91C_BASE_DBGU));
		AT91F_US_PutChar((AT91PS_USART)AT91C_BASE_DBGU, *buffer++);
	}
}
//*------------------------- Internal Function --------------------------------
//*----------------------------------------------------------------------------
//* Function Name       : AT91F_TC_Open
//* Object              : Initialize Timer Counter Channel and enable is clock
//* Input Parameters    : <tc_pt> = TC Channel Descriptor Pointer
//*                       <mode> = Timer Counter Mode
//*                     : <TimerId> = Timer peripheral ID definitions
//* Output Parameters   : None
//*----------------------------------------------------------------------------
void AT91F_TC_Open ( AT91PS_TC TC_pt, unsigned int Mode, unsigned int TimerId)
//* Begin
{
    unsigned int dummy;

    //* First, enable the clock of the TIMER
    	AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1<< TimerId ) ;

    //* Disable the clock and the interrupts
	TC_pt->TC_CCR = AT91C_TC_CLKDIS ;
	TC_pt->TC_IDR = 0xFFFFFFFF ;

    //* Clear status bit
        dummy = TC_pt->TC_SR;
    //* Suppress warning variable "dummy" was set but never used
        dummy = dummy;
    //* Set the Mode of the Timer Counter
	TC_pt->TC_CMR = Mode ;

    //* Enable the clock
	TC_pt->TC_CCR = AT91C_TC_CLKEN ;
//* End
}


//*------------------------- Interrupt Function -------------------------------

//*----------------------------------------------------------------------------
//* Function Name       : timer0_c_irq_handler
//* Object              : C handler interrupt function call by the interrupts
//*                       assembling routine
//* Output Parameters   : increment count_timer0_interrupt
//*----------------------------------------------------------------------------
 void timer0_c_irq_handler(void)
{
	AT91PS_TC TC_pt = AT91C_BASE_TC0;
    unsigned int dummy;
    //debug by suminhua 2007-5-29 for debug
     //AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91D_ID_PIO_SW);
    //* AcknowAT91B_LEDge interrupt status
    dummy = TC_pt->TC_SR;
    //* Suppress warning variable "dummy" was set but never used
    dummy = dummy;
	clkCurrent++;
	
       no_INT0_time++;            
	if(5==no_INT0_time)      AT91F_PIO_InterruptEnable(AT91C_BASE_PIOA,KEY_CLK);
/*
    count_timer0_interrupt++;
    AT91F_DBGU_Printk("timer0_c_irq_handler\r\n");
    for(i=0;i<11;i++){
    	  if(i==0){	
   		 	AT91F_PIO_ClearOutput( AT91D_BASE_PIO_LED, OUTPUT_DATA );
    	  	}
    	else if(i==10){
		 AT91F_PIO_SetOutput( AT91D_BASE_PIO_LED, OUTPUT_DATA );
    	}	 
	else
	{
		if((i==9)){
			if(i_num%2 == 1) {
				AT91F_PIO_ClearOutput( AT91D_BASE_PIO_LED, OUTPUT_DATA );
			}
			else{
				AT91F_PIO_SetOutput( AT91D_BASE_PIO_LED, OUTPUT_DATA );
			}
		}
		if(trandata&(1<<(8-i))){
			AT91F_PIO_SetOutput( AT91D_BASE_PIO_LED, OUTPUT_DATA );
		}
		else{
			AT91F_PIO_ClearOutput( AT91D_BASE_PIO_LED, OUTPUT_DATA );
		}
	}
	AT91F_PIO_ClearOutput( AT91D_BASE_PIO_LED, OUTPUT_CLK );
	f6_delay(117);
    	AT91F_PIO_SetOutput( AT91D_BASE_PIO_LED, OUTPUT_CLK );
    	f6_delay(117);
    } 
    */

}
//*----------------------------------------------------------------------------
//* Function Name       : timer1_c_irq_handler
//* Object              : C handler interrupt function call by the interrupts
//*                       assembling routine
//* Output Parameters   : increment count_timer1_interrupt
//*----------------------------------------------------------------------------
 void timer1_c_irq_handler(void)
{
	AT91PS_TC TC_pt = AT91C_BASE_TC1;
    unsigned int dummy;
    //* AcknowAT91B_LEDge interrupt status
    dummy = TC_pt->TC_SR;
    //* Suppress warning variable "dummy" was set but never used
    dummy = dummy;
    count_timer1_interrupt++;
    //* Read the output state
    if ( (AT91F_PIO_GetInput(AT91D_BASE_PIO_LED) & AT91B_LED2 ) == AT91B_LED2 )
    {
        AT91F_PIO_ClearOutput( AT91D_BASE_PIO_LED, AT91B_LED2 );
    } else {
        AT91F_PIO_SetOutput( AT91D_BASE_PIO_LED, AT91B_LED2 );
    }
}
//*-------------------------- External Function -------------------------------

//*----------------------------------------------------------------------------
//* Function Name       : timer_init
//* Object              : Init timer counter
//* Input Parameters    : none
//* Output Parameters   : TRUE
//*----------------------------------------------------------------------------
void timer_init ( void )
//* Begin
{
    //init the timer interrupt counter
    count_timer0_interrupt=0;
    count_timer1_interrupt=0;

    //* Open timer0
	AT91F_TC_Open(AT91C_BASE_TC0,TC_CLKS_MCK1024|AT91C_TC_CPCTRG,AT91C_ID_TC0);

    //* Open Timer 0 interrupt
	AT91F_AIC_ConfigureIt ( AT91C_BASE_AIC,
                                AT91C_ID_TC0,
                                TIMER0_INTERRUPT_LEVEL,
                                AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL,
                                timer0_c_irq_handler);
        AT91C_BASE_TC0->TC_RC = 0xb75;
	AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS;  //  IRQ enable CPC
	//delete by suminhua 2007-5-29 for debug
	AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91C_ID_TC0);
    //* Start timer0
       AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG ;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -