DSP5509的定时器实验-第2篇

1. 导入Easy5509开发板的例程EX02_TIME,5509有2个16位的定时器,有点少啊

2. 直接编译,提示找不到CSL.h,其实我也好奇,CSL库是从哪里来的?RTS库从哪里来的?头文件在哪里?上个实验的时候,我发现CSL有个安装包,去官网找了一下安装包http://www.ti.com/tool/sprc133

3. 安装CSL库,在CCS中增加头文件搜索路径,程序编译通过。

4. 看下主程序,主程序比较简单,有几个关键点,包含的库文件

  1 #include <stdio.h>
  2 #include <csl.h>
  3 #include <csl_irq.h>
  4 #include <csl_timer.h>
  5 #include <csl_chiphal.h>
  6 
  7 extern void VECSTART(void);
  8 
  9 #define TIMER_CTRL    TIMER_TCR_RMK(
 10                       TIMER_TCR_IDLEEN_DEFAULT,    /* IDLEEN == 0 */ 
 11                       TIMER_TCR_FUNC_OF(0),        /* FUNC   == 0 */ 
 12                       TIMER_TCR_TLB_RESET,         /* TLB    == 1 */ 
 13                       TIMER_TCR_SOFT_BRKPTNOW,     /* SOFT   == 0 */ 
 14                       TIMER_TCR_FREE_WITHSOFT,     /* FREE   == 0 */ 
 15                       TIMER_TCR_PWID_OF(0),        /* PWID   == 0 */ 
 16                       TIMER_TCR_ARB_RESET,         /* ARB    == 1 */ 
 17                       TIMER_TCR_TSS_START,         /* TSS    == 0 */ 
 18                       TIMER_TCR_CP_PULSE,          /* CP     == 0 */ 
 19                       TIMER_TCR_POLAR_LOW,         /* POLAR  == 0 */ 
 20                       TIMER_TCR_DATOUT_0           /* DATOUT == 0 */ 
 21 )  
 22 
 23 TIMER_Config timCfg0 = {
 24    TIMER_CTRL,               /* TCR0 */
 25    0x3400u,                  /* PRD0 */
 26    0x0000                    /* PRSC */
 27 };
 28 
 29 
 30 Uint16 eventId0;  
 31 
 32 TIMER_Handle mhTimer0;
 33 
 34 volatile Uint16 timer0_cnt = 0;
 35 
 36 /* Function/ISR prototypes */
 37 interrupt void timer0Isr(void);
 38 void taskFxn(void);
 39 
 40 int old_intm;
 41 Uint16 tim_val;
 42 Uint16 xfchange = 0;
 43 Uint16 ms,f;
 44 
 45 void main(void)
 46 {
 47      /* Initialize CSL library - This is REQUIRED !!! */
 48      /*CLS库的初始化,这是必需的*/
 49      CSL_init();
 50     
 51      /* Set IVPH/IVPD to start of interrupt vector table */
 52      /*修改寄存器IVPH,IVPD,重新定义中断向量表*/
 53      IRQ_setVecs((Uint32)(&VECSTART));
 54      
 55      /* Temporarily disable all maskable interrupts */
 56     /*禁止所有可屏蔽的中断源*/
 57     old_intm = IRQ_globalDisable();   
 58     
 59     /* Open Timer 0, set registers to power on defaults */
 60     /*打开定时器0,设置其为上电的的默认值,并返回其句柄*/
 61     mhTimer0 = TIMER_open(TIMER_DEV0, TIMER_OPEN_RESET);
 62     
 63     /* Get Event Id associated with Timer 0, for use with */
 64     /* CSL interrupt enable functions.                    */
 65     /*获取定时器0的中断ID号*/         
 66     eventId0 = TIMER_getEventId(mhTimer0);
 67     
 68     /* Clear any pending Timer interrupts */
 69     /*清除定时器0的中断状态位*/
 70     IRQ_clear(eventId0);
 71     
 72     /* Place interrupt service routine address at */
 73     /* associated vector location */
 74     /*为定时器0设置中断服务程序*/
 75     IRQ_plug(eventId0,&timer0Isr);
 76     
 77     /* Write configuration structure values to Timer control regs */
 78     /*设置定时器0的控制与周期寄存器*/ 
 79     TIMER_config(mhTimer0, &timCfg0);  
 80     
 81     /* Enable Timer interrupt */
 82     /*使能定时器的中断*/
 83     IRQ_enable(eventId0);             
 84     
 85     /* Enable all maskable interrupts */
 86     /*设置寄存器ST1的INTM位,使能所有的中断*/
 87     IRQ_globalEnable();      
 88     
 89     /* Start Timer */
 90     /*启动定时器0*/
 91     TIMER_start(mhTimer0);
 92        
 93     //以下是原来的TIMER子段
 94     f=210;
 95     ms=0;
 96     for(;;)
 97     {
 98         // Wait for at least 10 timer periods
 99         //等待10个定时周期
100         if(xfchange == 0) 
101         {
102            //点亮XF的LED
103            CHIP_FSET(ST1_55,XF,1);  
104         }
105         else
106         {
107             //关掉XF的LED
108               CHIP_FSET(ST1_55,XF,0); 
109         }
110     }
111 126     /* Restore old value of INTM */
127     /*恢复INTM旧的值*/
128     IRQ_globalRestore(old_intm);
129     
130     /* We are through with timer, so close it */
131     /*关掉定时器0*/
132     TIMER_close(mhTimer0); 
133 }

5. 中断服务函数

 1 interrupt void timer0Isr(void)
 2 {
 3     ms++;
 4     ++timer0_cnt;
 5     if(timer0_cnt == f)
 6     {
 7         xfchange = 1;
 8         f=f-3;
 9         if(f==0)
10           f=210;
11     }
12     if(timer0_cnt == 2*f)
13     {
14         timer0_cnt = 0;
15         xfchange = 0;    
16         f=f-3;
17         if(f==0)
18           f=210;
19     }
20 }
原文地址:https://www.cnblogs.com/429512065qhq/p/8119936.html