1. 导入Easy5509开发板的例程EX02_TIME,5509有2个16位的定时器,有点少啊
2. 直接编译,提示找不到CSL.h,其实我也好奇,CSL库是从哪里来的?RTS库从哪里来的?头文件在哪里?上个实验的时候,我发现CSL有个安装包,去官网找了一下安装包http://www.ti.com/tool/sprc133
3. 安装CSL库,在CCS中增加头文件搜索路径,程序编译通过。
4. 看下主程序,主程序比较简单,有几个关键点,包含的库文件
#include <stdio.h>
#include <csl.h>
#include <csl_irq.h>
#include <csl_timer.h>
#include <csl_chiphal.h> extern void VECSTART(void); #define TIMER_CTRL TIMER_TCR_RMK(\
TIMER_TCR_IDLEEN_DEFAULT, /* IDLEEN == 0 */ \
TIMER_TCR_FUNC_OF(), /* FUNC == 0 */ \
TIMER_TCR_TLB_RESET, /* TLB == 1 */ \
TIMER_TCR_SOFT_BRKPTNOW, /* SOFT == 0 */ \
TIMER_TCR_FREE_WITHSOFT, /* FREE == 0 */ \
TIMER_TCR_PWID_OF(), /* 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 */ \
) TIMER_Config timCfg0 = {
TIMER_CTRL, /* TCR0 */
0x3400u, /* PRD0 */
0x0000 /* PRSC */
}; Uint16 eventId0; TIMER_Handle mhTimer0; volatile Uint16 timer0_cnt = ; /* Function/ISR prototypes */
interrupt void timer0Isr(void);
void taskFxn(void); int old_intm;
Uint16 tim_val;
Uint16 xfchange = ;
Uint16 ms,f; void main(void)
{
/* Initialize CSL library - This is REQUIRED !!! */
/*CLS库的初始化,这是必需的*/
CSL_init(); /* Set IVPH/IVPD to start of interrupt vector table */
/*修改寄存器IVPH,IVPD,重新定义中断向量表*/
IRQ_setVecs((Uint32)(&VECSTART)); /* Temporarily disable all maskable interrupts */
/*禁止所有可屏蔽的中断源*/
old_intm = IRQ_globalDisable(); /* Open Timer 0, set registers to power on defaults */
/*打开定时器0,设置其为上电的的默认值,并返回其句柄*/
mhTimer0 = TIMER_open(TIMER_DEV0, TIMER_OPEN_RESET); /* Get Event Id associated with Timer 0, for use with */
/* CSL interrupt enable functions. */
/*获取定时器0的中断ID号*/
eventId0 = TIMER_getEventId(mhTimer0); /* Clear any pending Timer interrupts */
/*清除定时器0的中断状态位*/
IRQ_clear(eventId0); /* Place interrupt service routine address at */
/* associated vector location */
/*为定时器0设置中断服务程序*/
IRQ_plug(eventId0,&timer0Isr); /* Write configuration structure values to Timer control regs */
/*设置定时器0的控制与周期寄存器*/
TIMER_config(mhTimer0, &timCfg0); /* Enable Timer interrupt */
/*使能定时器的中断*/
IRQ_enable(eventId0); /* Enable all maskable interrupts */
/*设置寄存器ST1的INTM位,使能所有的中断*/
IRQ_globalEnable(); /* Start Timer */
/*启动定时器0*/
TIMER_start(mhTimer0); //以下是原来的TIMER子段
f=;
ms=;
for(;;)
{
// Wait for at least 10 timer periods
//等待10个定时周期
if(xfchange == )
{
//点亮XF的LED
CHIP_FSET(ST1_55,XF,);
}
else
{
//关掉XF的LED
CHIP_FSET(ST1_55,XF,);
}
}
/* Restore old value of INTM */
/*恢复INTM旧的值*/
IRQ_globalRestore(old_intm); /* We are through with timer, so close it */
/*关掉定时器0*/
TIMER_close(mhTimer0);
}
5. 中断服务函数
interrupt void timer0Isr(void)
{
ms++;
++timer0_cnt;
if(timer0_cnt == f)
{
xfchange = ;
f=f-;
if(f==)
f=;
}
if(timer0_cnt == *f)
{
timer0_cnt = ;
xfchange = ;
f=f-;
if(f==)
f=;
}
}