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

📄 timer.c

📁 使用在TI 系列dsk5402 的很多可用例子
💻 C
字号:
/*
 *  Copyright 2003 by Texas Instruments Incorporated.
 *  All rights reserved. Property of Texas Instruments Incorporated.
 *  Restricted rights to use, duplicate or disclose this code are
 *  granted through contract.
 *  
 */
/* "@(#) DSP/BIOS 4.90.150 04-08-03 (barracuda-m02)" */
/******************************************************************************\
*           Copyright (C) 2000 Texas Instruments Incorporated.
*                           All Rights Reserved
*------------------------------------------------------------------------------
* FILENAME...... timer.c
* DATE CREATED.. 01/11/2000
* LAST MODIFIED. 12/29/2000
\******************************************************************************/
#include <stdio.h>

#include <csl.h>
#include <csl_irq.h>
#include <csl_timer.h>

/*----------------------------------------------------------------------------*/
/* In this exmaple, we are simply setting the timer to interrupt */
/* every 0x800 clock cycles. All timer setup will be done in a   */
/* TSK function that executes after exit from "main"            */


/* Create a timer control structure */
TIMER_Config myTConfig = {
  TIMER_TCR_RMK(
    TIMER_TCR_SOFT_WAITZERO,
    TIMER_TCR_FREE_NOSOFT,
    TIMER_TCR_TRB_RESET,
    TIMER_TCR_TSS_START,
    TIMER_TCR_TDDR_OF(0)
  ),                        /* TCR0 */
  0x0800u                   /* PRD0 */
};
       
/* Global declarations */

/* Reference to start of interrupt vectors */
extern void VECSTART(void);

TIMER_Handle mhTimer;
volatile Uint16 timer_int_cnt = 0;    
interrupt void timerIsr(void); 
void taskFunc(void);

/*----------------------------------------------------------------------------*/
void main() {

  /* Initialize CSL library, this step is required */
  CSL_init();
 
  /* Initialize IPTR */
  IRQ_setVecs((Uint16)(&VECSTART));

  /* Call example task function */
  taskFunc();
}

/*----------------------------------------------------------------------------*/
void taskFunc(void) {

  Uint16 eventId;
  int old_intm;
  Uint16 err = 0;    

  printf("<TIMER>\n");   

  /* Temporarily disable all maskable interrupts, preserving  */
  /* previous state of INTM                                   */
  old_intm = IRQ_globalDisable();

  /* Open Timer 0, this returns a pointer to a Timer Handle   */
  /* that will be used as an argument to other CSL functions  */  
  mhTimer = TIMER_open(TIMER_DEV0, TIMER_OPEN_RESET);    
 
  /* Write configuration structure values to Timer control    */
  /* registers.                                               */
  TIMER_config(mhTimer, &myTConfig);  
 
  /* Get Event ID associated with Timer interrupt */ 
  eventId = TIMER_getEventId(mhTimer);    

  /* Clear any pending Timer interrupts */
  IRQ_clear(eventId);                     

  /* Place event ID in interrupt map for dispatcher */
  IRQ_plug(eventId,timerIsr);

  /* Enable Timer interrupt */
  IRQ_enable(eventId);

  /* Enable all maskable interrupts */
  IRQ_globalEnable();

  /* Start Timer */   
  TIMER_start(mhTimer);  

  /* wait for 20 timer periods */ 
  while(timer_int_cnt < 20);

  /* We are through with the Timer, so close it */
  TIMER_close(mhTimer);

   /* Restore previous state of INTM */
   IRQ_globalRestore(old_intm);
   
   if (timer_int_cnt < 20)
      ++err;
 
   printf ("Timer interrupts every 0x800 clock cycles\n");
   printf("%s\n",err?"TEST FAILED":"TEST PASSED");
}

/*----------------------------------------------------------------------------*/     

/* Timer ISR - will be called by DSP/BIOS dispatcher */
interrupt void timerIsr(void) {  
   TIMER_stop(mhTimer);
    ++timer_int_cnt;
   TIMER_start(mhTimer);
}
   
  

⌨️ 快捷键说明

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