DSP 之定时器设置(TIMER)

DSP 之定时器设置(TIMER):

/*
 * Copyright (C) 2003 Texas Instruments Incorporated
 * All Rights Reserved
 */


#include <stdio.h>

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


//---------Global data definition---------
#define TIMER_CTRL    TIMER_TCR_RMK(\
                      TIMER_TCR_IDLEEN_DEFAULT,    /* IDLEEN == 0 */ \
                      TIMER_TCR_FUNC_OF(0),        /* FUNC   == 0 */ \
                      TIMER_TCR_TLB_RESET,         /* TLB    == 1 */ \
                      TIMER_TCR_SOFT_BRKPTNOW,     /* SOFT   == 0 */ \
                      TIMER_TCR_FREE_WITHSOFT,     /* FREE   == 0 */ \
                      TIMER_TCR_PWID_OF(0),        /* PWID   == 0 */ \
                      TIMER_TCR_ARB_RESET,         /* ARB    == 1 */ \
                      TIMER_TCR_TSS_START,         /* TSS    == 0 */ \
                      TIMER_TCR_CP_PULSE,          /* CP     == 0 */ \
                      TIMER_TCR_POLAR_LOW,         /* POLAR  == 0 */ \
                      TIMER_TCR_DATOUT_0           /* DATOUT == 0 */ \
)  

/* Create a TIMER configuration structure that can be passed */
/* to TIMER_config CSL function for initialization of Timer  */
/* control registers.                                        */
TIMER_Config timCfg0 = {
   TIMER_CTRL,               /* TCR0  Timer Control register */
   0x0400u,                  /* PRD0  Period Register(周期寄存器)*/
   0x0000                    /* PRSC  Timer Pre-scaler Register (定时器预分频寄存器  */
};

/* Create a TIMER_Handle object for use with TIMER_open */
TIMER_Handle mhTimer0;

Uint16 eventId0;
volatile Uint16 timer0_cnt = 0;
int old_intm;
Uint16 tim_val;


/* Reference start of interrupt vector table   */
/* This symbol is defined in file, vectors_timer1.s55 */
extern void VECSTART(void);

/* interupt Time0 handle function */
interrupt void timer0Isr(void);

/* User's function */
void taskFxn(void);


void main(void)
{
	/* Initialize CSL library */
	CSL_init();
	
	/* Set IVPH/IVPD to start of interrupt vector table */
	IRQ_setVecs((Uint32)(&VECSTART));
	
	/* Call function to set timer */
	taskFxn();
}


void taskFxn(void)
{
    /* Temporarily disable all maskable interrupts */
    old_intm = IRQ_globalDisable();   

    /* Open Timer 0, set registers to power on defaults */
    mhTimer0 = TIMER_open(TIMER_DEV0, TIMER_OPEN_RESET);

    /* Get Event Id associated with Timer 0, for use with */
    /* CSL interrupt enable functions.                    */ 
    /* Obtains IRQ event ID for TIMER device */        
    eventId0 = TIMER_getEventId(mhTimer0);

    /* Clear any pending Timer interrupts */
    IRQ_clear(eventId0);
    
    /* Place interrupt service routine address at */
    /* associated vector location
     * Initialize interrupt vector table 
     */
    IRQ_plug(eventId0,&timer0Isr);              

    /* Write configuration structure values to Timer control regs */ 
    TIMER_config(mhTimer0, &timCfg0);  
 
    /* Enable Timer interrupt */
    IRQ_enable(eventId0);             
   
    /* Enable all maskable interrupts 
     * extern interrupt
     */
    IRQ_globalEnable();      
 
    /* Start Timer device running */
    TIMER_start(mhTimer0);

    /* Wait for at least 10 timer periods */
    while(timer0_cnt != 10)
     {
        printf("Timer: %d \n", timer0_cnt);
    }

	/* Consider TEST PASSED if 10 interrupts occur */
	printf("\nTEST PASSED\n");
	
    /* Restore old value of INTM */
    IRQ_globalRestore(old_intm);
    
    /* We are through with timer, so close it */
    TIMER_close(mhTimer0);
}


/* Time interrupt */
interrupt void timer0Isr(void)
{
    ++timer0_cnt;
}


 

之前编译时一直出现警告:

 

现在解决如下:

 

搞定,接下来的几天我继续发表DSP的文章,嘿嘿,如果有时间的话我会写写Linux方面的东西。

                                                                            当我一个人的时候我常会听这首歌: playBtn&fr=-1 希望各位也喜欢!!

                                  

 

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值