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

📄 timer.c

📁 DSP编程
💻 C
字号:
//modify by TI803
#include "timer.h"

/*-------------------------------------------------------------------------*/
/* timer_start() - used to start TIMER                                   */
/*-------------------------------------------------------------------------*/
void timer_start(int timerNum)
{
//  *(unsigned volatile int *)(TIMER_CTRL_ADDR(timerNum)) &= 0xff3f;   /* hold the timer    */ 
  *(unsigned volatile int *)(TIMER_CTRL_ADDR(timerNum)) = 0;
//  SET_BIT(TIMER_CTRL_ADDR(timerNum), CLKSRC);	//Internal clock source
//  RESET_BIT(TIMER_CTRL_ADDR(timerNum), C_P);	//TIMER_PULSE_MODE
//  *(unsigned volatile int *)(TIMER_CTRL_ADDR(timerNum)) |= ((1<<CLKSRC)+(TIMER_PULSE_MODE<<C_P));     /* use CPU CLK/8     */   
  *(unsigned volatile int *)(TIMER_PERIOD_ADDR(timerNum))  |= 0xffffffff;/* set for 32 bit cnt*/
//  *(unsigned volatile int *)(TIMER_CTRL_ADDR(timerNum)) |= (1<<GO) + (1<<HLD);    /* start the timer   */
 *(unsigned volatile int *)(TIMER_CTRL_ADDR(timerNum)) = (1<<GO) + (1<<HLD) + (0<<C_P) + (1<<CLKSRC);
}


/*-------------------------------------------------------------------------*/
/* timer_count2us() - Translate used timer count to used time in us        */
/*-------------------------------------------------------------------------*/
float timer_count2us(unsigned int count)                               
{
 return (((count*1000.0)/((unsigned int)Internal_CLK_F/1000.0)));
}

/*-------------------------------------------------------------------------*/
/* delay_msec() - used to delay DSP by user specified time in msec         */
/*-------------------------------------------------------------------------*/
void delay_msec(int timerNum , float msec)  
                                                 
{
  unsigned int time_start;
  unsigned int timer_limit = Internal_CLK_F*(msec/1000.0);	
  timer_start(timerNum);
  time_start = TIMER_READ(timerNum);
  while ((TIMER_READ(timerNum)-time_start) < timer_limit);
}

#if 1
/*-------------------------------------------------------------------------*/
/* C6000_Set_Up_TIMER_Tick_In_Microseconds() -  设置时钟中断频率           */
/*-------------------------------------------------------------------------*/
int C6000_Set_Up_TIMER_Tick_In_Microseconds(int Microseconds , int timerNum)   
{
   unsigned int clock_cycles ;

   volatile TIMER_REG  *timer_reg ;
   
   if(timerNum>2)
       return(1);
   else    
       timer_reg = (volatile TIMER_REG  *)(TIMER_CTRL_ADDR(timerNum));

   clock_cycles = (float)Microseconds * 1e-6 * Internal_CLK_F ; 

   timer_reg->Control  = 0;      /* Hold it */

   timer_reg->Period  = clock_cycles;
    
/*-----------------------------------**
**  9   CLKSRC = 1  CPU clock / 8    **
**  8   C/P    = 1  Clock mode       **
**  7   /HLD   = 1  Allowed to count **
**  6   GO     = 1  Here we go       **
**-----------------------------------*/
//  timer_reg->Control  = (1<<GO) +(1<<HLD) + (1<<C_P) + (1<<CLKSRC); 	        //old code
/*************************************************************************/
    timer_reg->Control  = (1<<GO) + (1<<HLD) + (0<<C_P) + (1<<CLKSRC);		//modified by shiyan 2002-09-18
/*************************************************************************/    
    return (0); 
}
#endif

⌨️ 快捷键说明

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