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

📄 timer.c

📁 DSP5502的定时器发生器部分
💻 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.270 06-11-03 (barracuda-m10)" */
/******************************************************************************\
*           Copyright (C) 2000 Texas Instruments Incorporated.
*                           All Rights Reserved
*------------------------------------------------------------------------------
* FILENAME...... timer.c
* DATE CREATED.. 01/11/2000
* LAST MODIFIED. 12/29/2000
\******************************************************************************/
#include <std.h>
#include <log.h>

#include "timercfg.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 */
TIMER_Handle mhTimer;
volatile Uint16 timer_int_cnt = 0;    
void timer_isr(void); 

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

  /* Initialize CSL library, this step is required */
  CSL_init();
}

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

  Uint16 eventId;
  int old_intm;
  Uint16 err = 0;    

  LOG_printf(&LogMain,"<TIMER>");   

  /* 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_map(eventId);

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

  /* Enable all maskable interrupts */
  IRQ_globalRestore(old_intm);

  /* 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;

   LOG_printf(&LogMain,"%s",err?"Timer example FAILED":"Timer example PASSED");
   LOG_printf(&LogMain,"<DONE>");
}

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

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

⌨️ 快捷键说明

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