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

📄 interrupt_timer.c

📁 详细介绍了arm7-at91r40008,的开发全过程
💻 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 Standard LIB  files 
#include "../ucos_ii/includes.h"
#include "../../../parts/r40008/reg_r40008.h"
#include "../../../parts/r40008/lib_r40008.h"
//unsigned int Frequency;

void extern OSTickISR(void);
//* Global variable

///////////////////////////////////////////////
struct SysPort 	*pp1;
struct SysPort 	*pp2;
extern INT8U	FiqFlag;
extern OS_EVENT *SemTimerTenMS;
extern OS_EVENT *SemTimerOneS;
extern OS_EVENT *SemFAOneS;
extern OS_EVENT *SemYC;
extern struct SysPort	*SysPorts;
extern struct SysPort*	ComDb[PORTNUM];
extern struct AbsTime_t	pAbsTime;
INT16U          pAbsMsecond = 61111, ppmsecond=0;
///////////////////////////////////////////////


//*------------------------- 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(TCDesc *TC_pt)
{
    volatile unsigned int dummy;
    
    //* Acknowledge interrupt status
    dummy = TC_pt->tc_base->TC_SR;
    //* Suppress warning variable "dummy" was set but never used


/////////////////////////////////////////////
	//扫描硬件遥信
	YXRead();

	pAbsTime.Msecond++;
	if (pAbsTime.Msecond > 59999)
	{
		pAbsTime.Msecond = 0;
		pAbsTime.Minute++;
	}

//////////////////////////////////////////////

//    dummy = *(volatile INT32U*)0xFFFE0020;
}

//*----------------------------------------------------------------------------
//* 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(TCDesc *TC_pt)
{
    unsigned int dummy;
    //* Acknowledge interrupt status
    dummy = TC_pt->tc_base->TC_SR;
    //* Suppress warning variable "dummy" was set but never used
    dummy = dummy;
}

//*----------------------------------------------------------------------------
//* 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(TCDesc *TC_pt)
{
    unsigned int dummy;
    //* Acknowledge interrupt status
    dummy = TC_pt->tc_base->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 )
{
    u_int RABC[3] ;
    u_int timer_value[3] = {0,0,8250};   // 1ms
    
    // 定时器0:提供1MS中断
    at91_tc_open(&TC0_DESC, TC_WAVE|TC_CPCTRG|TC_CLKS_MCK8,0,0);	//1ms
    at91_tc_write(&TC0_DESC, timer_value);
    at91_tc_trig_cmd(&TC0_DESC, TC_TRIG_CHANNEL);
    at91_irq_open(TC0_DESC.periph_id, TIMER0_INTERRUPT_LEVEL, AIC_SRCTYPE_INT_EDGE_TRIGGERED, timer0_asm_irq_handler); 

    // 定时器1:波形模式,输出采样启动脉冲
    at91_tc_open(&TC1_DESC, TC_CPCTRG | TC_WAVE | TC_ACPA_SET_OUTPUT | TC_ACPC_CLEAR_OUTPUT | TC_ASWTRG_CLEAR_OUTPUT , TRUE, FALSE);
    RABC[0] = 4 ;
    RABC[1] = 0 ;
    RABC[2] = 20625 ;
    at91_tc_write(&TC1_DESC, RABC) ;
    at91_tc_trig_cmd(&TC1_DESC, TC_TRIG_CHANNEL) ; 
    
	//打开中断
	TC0_IER = TC_CPCS;
	
}
void timer2_init(void)
{
   u_int RABC[3];
    
   at91_tc_open(&TC2_DESC, TC_CLKS_MCK32 | TC_ETRGEDG_RISING_EDGE | TC_ABETRG_TIOA | TC_LDRA_RISING_EDGE | TC_LDRB_FALLING_EDGE, TRUE, FALSE);
   RABC[0] = 0 ;
   RABC[1] = 0 ;
   RABC[2] = 0xffff ;
    
   at91_tc_write(&TC2_DESC, RABC) ; 
 
   at91_tc_trig_cmd(&TC2_DESC, TC_TRIG_CHANNEL);	 
   at91_irq_open(TC2_DESC.periph_id, TIMER2_INTERRUPT_LEVEL, AIC_SRCTYPE_EXT_POSITIVE_EDGE, timer2_asm_irq_handler); //中断测量频率

}

void Time0_Test(void)
{
/*    INT32U  i, dd[9];
    char	err[60];
    struct SysTime_t SystemTime;*/
    
    if (pAbsMsecond != pAbsTime.Msecond)
    {   
        pAbsMsecond = pAbsTime.Msecond;
        ppmsecond = 0;
        return ;
    }
    
    ppmsecond++;
    if (ppmsecond < 2)
        return ;
    
/*
    dd[0] = *(volatile INT32U*)0xFFFFF110;     //AIC_IMR
    dd[1] = *(volatile INT32U*)0xFFFE0004;     //TC_CMR
    dd[2] = *(volatile INT32U*)0xFFFE0010;     //TC_CV
    dd[3] = *(volatile INT32U*)0xFFFE0014;     //TC_RA
    dd[4] = *(volatile INT32U*)0xFFFE0018;     //TC_RB
    dd[5] = *(volatile INT32U*)0xFFFE001C;     //TC_RC
    dd[6] = *(volatile INT32U*)0xFFFE0020;     //TC_SR
    dd[7] = *(volatile INT32U*)0xFFFE002C;     //TC_IMR
    for (i=0; i<10000; i++) ;
    dd[8] = *(volatile INT32U*)0xFFFE0010;     //TC_CV
    
    GetTime((void *)&SystemTime, SYSTIME);
    #ifdef CHINESEINFO
		sprintf(err, "BUG:%04d-%02d-%02d %02d:%02d:%02d:%03d", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Hour,SystemTime.Minute, SystemTime.Second, SystemTime.MSecond);
	#else
		sprintf(err, "BUG:%04d-%02d-%02d %02d:%02d:%02d:%03d", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Hour,SystemTime.Minute, SystemTime.Second, SystemTime.MSecond);	
	#endif
	ErrorInfo(ROOTID, err);
	
    sprintf(err, "BUG:%x,%x,%x,%x,%x,%x,%x,%x,%x", dd[0], dd[1], dd[2], dd[3], dd[4], dd[5], dd[6], dd[7], dd[8]);
    ErrorInfo(ROOTID, err);

*/    
    timer_init();
}

void time10mscall(void *ptmr,void *callback_arg)
{
	OSSemPost(SemTimerTenMS);
}

void time100mscall(void *ptmr,void *callback_arg)
{
	INT8U err, i;

	if (pp1 != NULL)
		OSFlagPost(pp1->Event,RxdFrame,OS_FLAG_SET,&err);
	if (pp2 != NULL)
		OSFlagPost(pp2->Event,RxdFrame,OS_FLAG_SET,&err);
	
	for (i=0; i<PORTNUM; i++)
	{
		if (ComDb[i] != NULL)
			OSFlagPost(ComDb[i]->Event, TIME100MS, OS_FLAG_SET, &err);
	}

}

void time1scall(void *ptmr,void *callback_arg)
{
	INT8U err;
		
	OSSemPost(SemTimerOneS);

	OSFlagPost(SysPorts[0].Event, TIME100MS, OS_FLAG_SET, &err);

	if (pp1 != NULL)
		OSFlagPost(pp1->Event,Time1s,OS_FLAG_SET,&err);
	if (pp2 != NULL)
		OSFlagPost(pp2->Event,Time1s,OS_FLAG_SET,&err);
}





⌨️ 快捷键说明

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