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

📄 timer.c

📁 三星S34510板子上移植的uCosII源码
💻 C
字号:
#include "s3c4510b.h"
#include "isr.h"
#include "typDef.h"

#include "timer.h"

extern  void time0_isr(void);
/* Timer0,1 can be used for system real time clock */

/*************************************************************************/
/*                                                                       */
/* NAME : tm_init(timer device, time periode)                            */
/*                                                                       */
/* FUNCTIONS : Initialize the TIMER0,1.                                  */
/*                                                                       */
/* EXAMPLES :                                                            */
/*             tm_init(TIMER_DEV0,ONE_SECOND/TICKS_PER_SECOND);          */
/*                                                                       */
/*               Where, the TIMER_DEV0 means timer0.                     */
/*                          ONE_SECOND = 1000,                           */
/*                          TICKS_PER_SECOND = 100,                      */
/*                then timer0 timer periode become to 10ms.              */
/*                                                                       */
/* VARIABLES USED                                                        */
/*                                                                       */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*        in4maker      06-07-1999      Created initial version 1.0      */
/*                                                                       */
/*************************************************************************/
void tm_init(int TIMER_DEV, int t) 
{

   if(TIMER_DEV)  /* for TIMER 1 */
   {
         Disable_Int(nTIMER1_INT);    
	     SysSetInterrupt(nTIMER1_INT, time0_isr);

         TDATA1 = t_data_ms(t);    /* unit is [ms] */
         TCNT1 = 0x0;
         TMOD  = TM1_TOGGLE;       /* Toggle pulse will be out to port */
         Enable_Int(nTIMER1_INT);  /* Timer interrupt enable */
      
   }
   else  /* for TIMER0 */
   {
         Disable_Int(nTIMER0_INT);    
	     SysSetInterrupt(nTIMER0_INT, time0_isr);

         TDATA0 = t_data_ms(t);  
         TCNT0 = 0x0;
         TMOD  = TM0_TOGGLE;        
         Enable_Int(nTIMER0_INT); 
    }
}


/*************************************************************************/
/*                                                                       */
/* NAME : tmReset(timer device )                                         */
/*                                                                       */
/* FUNCTIONS : Clear and initialize the TIMER0 or TIMER1                 */
/*                                                                       */
/* EXAMPLES :                                                            */
/*             tmReset(TIMER_DEV0);                                      */
/*                                                                       */
/*               Where, the TIMER_DEV0 means timer0.                     */
/*                                                                       */
/* VARIABLES USED                                                        */
/*                                                                       */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*        in4maker      06-07-1999      Created initial version 1.0      */
/*                                                                       */
/*************************************************************************/
void tmReset(int TIMER_DEV)
{

    if(TIMER_DEV) {
              TMOD &= ~TM1_RUN;       /* Clear Timer mode register */     
              TDATA1 = 0;             /* Clear Timer data register */
              TCNT1  = 0xffffffff;    /* Clear timer counter register */
    }
    else {
              TMOD &= ~TM0_RUN;       /* Clear Timer mode register */     
              TDATA0 = 0;             /* Clear Timer data register */
              TCNT0  = 0xffffffff;    /* Clear timer counter register */
    }

    //ClrTimeVar(TIMER_DEV); /* Initialize timer variable */
}

⌨️ 快捷键说明

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