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

📄 timer.c

📁 讲述LPC2468在无操作系统条件下使用YAFFS文件系统是如何实现的以及完整的测试代码,代码部分详见lpc2468_yaffs2.rar
💻 C
字号:
/*****************************************************************************
 *   timer.c:  Timer C file for NXP LPC24xx Family Microprocessors
 *
 *   Copyright(C) 2006, NXP Semiconductor
 *   All rights reserved.
 *
 *   History
 *   2006.09.01  ver 1.00    Prelimnary version, first Release
 *
******************************************************************************/
#include <target.h>
//#include <timer.h>
//#include "stdint.h"
//#include "LPC24xx.h"		/* LPC24xx Peripheral Registers	*/
//#include "type.h"
//#include "irq.h"
//#include "timer.h"
//#include "armVIC.h"

//volatile uint32_t timer_counter = 0;

volatile uint32_t time3_interval;


/******************************************************************************
** Function name:		Timer0Handler
**
** Descriptions:		Timer/Counter 0 interrupt handler
**				executes each 10ms @ 60 MHz CPU Clock
**
** parameters:			None
** Returned value:		None
** 
******************************************************************************/
void Timer3Handler (void)
{  
	// perform proper ISR entry so thumb-interwork works properly
	ISR_ENTRY();
	T3IR = 0xFF;  // clear timer0 ovrf interrupt flag  
	
	time3_interval++;
	
	//-----------------------------------------------------------------
	//-----------------------------------------------------------------
	
	VICVectAddr = 0x00000000;             // clear this interrupt from the VIC
	ISR_EXIT();                           // recover registers and return
}
//中断处理函数-定时器中断
/******************************************************************************
** Function name:		init_timer
**
** Descriptions:		Initialize timer, set timer interval, reset timer,
**						install timer interrupt handler
**
** parameters:			None
** Returned value:		true or false, if the interrupt handler can't be
**						installed, return false.
** 
******************************************************************************/
uint32_t init_timer3 ( uint32_t TimerInterval ) 
{
	//使能定时器3电源控制
	PCONP |= (1 << 23);
	// setup Timer 1 to count forever
	T3PR = 23999;               // set the prescale divider
	T3MCR = 3;				/* Interrupt and Reset on MR0 */
	T3MR0 = 1;
	T3TCR = 0;
	T3TC = 0;
	T3CCR = 0;                            // disable compare registers
	T3EMR = 0;                            // disable external match register
	T3TCR = 1;
    
    if ( install_irq( TIMER3_INT, (void *)Timer3Handler, 20 ) == FALSE )
    {
		return (FALSE);
    }
    else
    {
		return (TRUE);
    }
}

/******************************************************************************
** Function name:		Timer0Handler
**
** Descriptions:		Timer/Counter 0 interrupt handler
**				executes each 10ms @ 60 MHz CPU Clock
**
** parameters:			None
** Returned value:		None
** 
******************************************************************************/
void __irq Timer0Handler (void)  
{  
    T0IR = 1;			/* clear interrupt flag */
    IENABLE;			/* handles nested interrupt */

//    timer_counter++;

    IDISABLE;
    VICVectAddr = 0;		/* Acknowledge Interrupt */
}

/******************************************************************************
** Function name:		enable_timer
**
** Descriptions:		Enable timer
**
** parameters:			timer number: 0 or 1
** Returned value:		None
** 
******************************************************************************/
void enable_timer( uint8_t timer_num )
{
    if ( timer_num == 0 )
    {
		T0TCR = 1;
    }
    else
    {
		T1TCR = 1;
    }
    return;
}

/******************************************************************************
** Function name:		disable_timer
**
** Descriptions:		Disable timer
**
** parameters:			timer number: 0 or 1
** Returned value:		None
** 
******************************************************************************/
void disable_timer( uint8_t timer_num )
{
    if ( timer_num == 0 )
    {
		T0TCR = 0;
    }
    else
    {
		T1TCR = 0;
    }
    return;
}
#if 0
/******************************************************************************
** Function name:		reset_timer
**
** Descriptions:		Reset timer
**
** parameters:			timer number: 0 or 1
** Returned value:		None
** 
******************************************************************************/
void reset_timer( uint8_t timer_num )
{
    uint32_t regVal;

    if ( timer_num == 0 )
    {
		regVal = T0TCR;
		regVal |= 0x02;
		T0TCR = regVal;
    }
    else
    {
		regVal = T1TCR;
		regVal |= 0x02;
		T1TCR = regVal;
    }
    return;
}
#endif
/******************************************************************************
** Function name:		init_timer
**
** Descriptions:		Initialize timer, set timer interval, reset timer,
**						install timer interrupt handler
**
** parameters:			None
** Returned value:		true or false, if the interrupt handler can't be
**						installed, return false.
** 
******************************************************************************/
uint32_t init_timer ( uint32_t TimerInterval ) 
{
//    timer_counter = 0;
    T0MR0 = TimerInterval;
    T0MCR = 3;				/* Interrupt and Reset on MR0 */
    if ( install_irq( TIMER0_INT, (void *)Timer0Handler, HIGHEST_PRIORITY ) == FALSE )
    {
		return (FALSE);
    }
    else
    {
		return (TRUE);
    }
}

/******************************************************************************
**                            End Of File
******************************************************************************/

⌨️ 快捷键说明

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