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

📄 timer.c

📁 44BO 的UCGUI包
💻 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           : interrupt_timer.c
//* Object              : Timer interrupt management
//*                     : Use LED7 & LED8 for status interrupt
//*
//* 1.0 03/Jan/03 JPP   : Creation
//*----------------------------------------------------------------------------

#include	"../SRC/includes.h"

unsigned long counter;

//extern void timer0_asm_irq_handler(void);
extern void timer1_asm_irq_handler(void);
extern void timer2_asm_irq_handler(void);

//*------------------------- 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_PS_EnablePeriphClock ( AT91C_BASE_PS, 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 called by the interrupts 
//*                       assembling routine
//* Input Parameters    : <RTC_pt> time rtc descriptor
//* Output Parameters   : increment count_timer0_interrupt
//*----------------------------------------------------------------------------
//void timer0_c_irq_handler(AT91PS_TC TC_pt)
//{
//    unsigned int dummy;
//        		
//    //* Acknowledge interrupt status
//    dummy = TC_pt->TC_SR;
//    //* Suppress warning variable "dummy" was set but never used
//    dummy = dummy;
//    count_timer0_interrupt++;
//	if(AT91F_PIO_GetInput(AT91C_BASE_PIO) & LEDR)
//    	AT91F_PIO_ClearOutput( AT91C_BASE_PIO, LEDR) ;
//    else
//		AT91F_PIO_SetOutput( AT91C_BASE_PIO, LEDR) ;	
//}

//*----------------------------------------------------------------------------
//* Function Name       : timer1_c_irq_handler
//* Object              : C handler interrupt function called by the interrupts 
//*                       assembling routine
//* Input Parameters    : <RTC_pt> time rtc descriptor
//* Output Parameters   : increment count_timer1_interrupt
//*----------------------------------------------------------------------------
void timer1_c_irq_handler(AT91PS_TC TC_pt)
{
//#if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register     */
//    OS_CPU_SR  cpu_sr;
//#endif
    long 	dummy;
//	char	*pWOTHER;
	
    //* Acknowledge interrupt status
    dummy = TC_pt->TC_SR;
    //* Suppress warning variable "dummy" was set but never used
    dummy = dummy;
   
	counter++;
   
//  GetKey();
   	
//	pWOTHER = (char *)WOTHER;
//    OS_ENTER_CRITICAL();
//    if( SpeakCtrl )
//	{	
//		SpeakCtrl--;
//		Other |= BELL;
//	}
//	else
//	{	
//		Other &= ~BELL;
//	}
//	if( DrawCtrl )
//	{	
//		DrawCtrl--;
//		Other |= DRAW;
//	}
//	else
//	{	
//		Other &= ~DRAW;
//	}
//	OS_EXIT_CRITICAL();
//	*pWOTHER = Other;	
}

//*----------------------------------------------------------------------------
//* Function Name       : timer2_c_irq_handler
//* Object              : C handler interrupt function called by the interrupts 
//*                       assembling routine
//* Input Parameters    : <RTC_pt> time rtc descriptor
//* Output Parameters   : increment count_timer1_interrupt
//*----------------------------------------------------------------------------
void timer2_c_irq_handler(AT91PS_TC TC_pt)
{
    unsigned int dummy;
    //* Acknowledge interrupt status
    dummy = TC_pt->TC_SR;
    //* Suppress warning variable "dummy" was set but never used
    dummy = dummy;
}

//*-------------------------- External Function -------------------------------

//*----------------------------------------------------------------------------
//* Function Name       : Timer_init
//* Object              : Init timer counter
//* Input Parameters    : none
//* Output Parameters   : TRUE
//*----------------------------------------------------------------------------
void Timer_init ( void )
//* Begin
{
    //* Open timer0
//	AT91F_TC_Open(AT91C_BASE_TC0,AT91C_TC_WAVE|AT91C_TC_CPCTRG|TC_CLKS_MCK32,AT91C_ID_TC0);

//    AT91C_BASE_TC0->TC_RC = 10240;	//32.768M-50MS

//	AT91F_AIC_ConfigureIt ( AT91C_BASE_AIC, AT91C_ID_TC0, TIMER0_INTERRUPT_LEVEL,AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE, OSTickISR); 
//	AT91C_BASE_TC0->TC_IER  = AT91C_TC_CPCS;  //  IRQ enable CPC
//	AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91C_ID_TC0);
	    
    //* Open timer1
	AT91F_TC_Open(AT91C_BASE_TC1,AT91C_TC_WAVE|AT91C_TC_CPCTRG|TC_CLKS_MCK32,AT91C_ID_TC1);

	AT91C_BASE_TC1->TC_RC = 20480;	//32.768M-30MS
    	
    //* Open Timer 1 interrupt
	AT91F_AIC_ConfigureIt ( AT91C_BASE_AIC, AT91C_ID_TC1, TIMER1_INTERRUPT_LEVEL,AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE, timer1_asm_irq_handler); 
	AT91C_BASE_TC1->TC_IER  = AT91C_TC_CPCS;  //  IRQ enable CPC
	AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91C_ID_TC1);
    

//    //* Generate interrupt by software
// 	AT91F_AIC_Trig (AT91C_BASE_AIC,AT91C_ID_TC1) ;
	
	//* Open timer2
//	AT91F_TC_Open(AT91C_BASE_TC2,AT91C_TC_CPCTRG | TC_CLKS_MCK1024,AT91C_ID_TC2);
//
//    //* Open Timer 2 interrupt
//	AT91F_AIC_ConfigureIt ( AT91C_BASE_AIC, AT91C_ID_TC2, TIMER2_INTERRUPT_LEVEL,AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE, timer2_asm_irq_handler); 
//	AT91C_BASE_TC2->TC_IER = AT91C_TC_CPCS;  //  IRQ enable CPC
//	AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91C_ID_TC2);
    
    //* Start timer0
//    AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG ;

    //* Start timer1
    AT91C_BASE_TC1->TC_CCR = AT91C_TC_SWTRG ;
	
	//* Start timer2
//    AT91C_BASE_TC2->TC_CCR = AT91C_TC_SWTRG ;

//* End
}

⌨️ 快捷键说明

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