DM642定时器能定时1us么,赋好初值后 实际试验中发现定时器中断内没任何指认 定时时间约为1.16us,内部指认愈多中断时间变的越长,我想问下这定时器中断是怎么工作的?从现象看好像是出定时器中断后计数器才开始重新计数,否则进中断周期不应该与中断服务函数内的指认有关?另外进栈出栈大概要多少时间 时钟是600M? 是中断结束后 定时器计数才开始重新计数么?为何中断内指认越多,进入中断时间周期越长,?定时周期不变 代码:
/* Header file created by DSP/BIOS tool */ #include "spicfgcfg.h"
#include <std.h>
#include <log.h> #include <sys.h> #include <mem.h> #include <sio.h> #include <csl.h> #include <csl_cache.h> #include <csl_irq.h> #include <gio.h>
#define DRR0 *((unsigned char *)(0x018C0000)) #define DXR0 *((unsigned char *)(0x018C0004)) #define DRR1 *((unsigned char *)(0x01900000)) #define DXR1 *((unsigned char *)(0x01900004))
#define GPIO_EN (*((unsigned int*)(0x01b00000))) #define GPIO_DIR (*((unsigned int*)(0x01b00004))) #define GPIO_VAL (*((unsigned int*)(0x01b00008))) #define GPIO_DH (*((unsigned int*)(0x01b00010))) #define GPIO_HM (*((unsigned int*)(0x01b00014))) #define GPIO_DL (*((unsigned int*)(0x01b00018))) #define GPIO_LM (*((unsigned int*)(0x01b0001c))) #define GPIO_GC (*((unsigned int*)(0x01b00020))) #define GPIO_POL (*((unsigned int*)(0x01b00024)))
void InitGPIO(); //初始化GPIO接口
void SpiRcv0(); void SpiRcv1(); void MCBSP_init(); #define PRDValue0 0x0000004b // 1US Uint32 x[100],y[100]; Uint32 i,j; #pragma CODE_SECTION(timer1,".jpgtbls "); #pragma CODE_SECTION(writed,".jpgtbls "); #pragma CODE_SECTION(SpiRcv0,".jpgtbls "); #pragma CODE_SECTION(SpiRcv1,".jpgtbls ");//定义到内部ISRAM
void writed(); Uint32 KK=0,l=0; Uint32 x[100],y[100]; Uint32 i,j; TIMER_Handle hTimer1; Uint32 TimerEventid; //定时器配置系数结构体 TIMER_Config MyConfig1= { 0x00000305,//CTL PRDValue0,//PRD 0x00000000,//CNT }; void writed() {
GPIO_VAL |= 0x00002002; GPIO_VAL &= 0xffffdffd; GPIO_VAL |= 0x00002002; GPIO_VAL &= 0xffffdffd; GPIO_VAL |= 0x00002002; GPIO_VAL &= 0xffffdffd; GPIO_VAL |= 0x00002002; GPIO_VAL &= 0xffffdffd; GPIO_VAL |= 0x00002002; GPIO_VAL &= 0xffffdffd;//加上这几句后 通过示波器观察 发现进入此函数时间间隔变成2.2us 但定时时间初值为1us
} //定时器1硬件中断 定时1us检测高速AD值 void timer1(void) {
writed();//屏蔽这句通过仿真进入时间为1.16us
//SWI_post(&TIME_swi); } /*----------------------------------------------------------------------------*/ void main() {
volatile Uint32 y; int success = 1; CSL_init(); IRQ_globalEnable(); //IRQ global enable IRQ_nmiEnable(); //NMIE IRQ_enable(IRQ_EVT_RINT0); //McBSP0 interrupt enable IRQ_enable(IRQ_EVT_RINT1); //McBSP1 interrupt enable
MCBSP_init(); InitGPIO(); //打开定时器0及GPIO口 hTimer1 = TIMER_open(TIMER_DEV1, 0);
//获取定时器0的事件号 TimerEventid = TIMER_getEventId(hTimer1);
//中断向量表的初始化
IRQ_globalEnable(); // IRQ_nmiEnable(); //NMIE IRQ_enable(TimerEventid); IRQ_enable(IRQ_EVT_RINT0); //McBSP0 interrupt enable IRQ_enable(IRQ_EVT_RINT1); //McBSP1 interrupt enable //对定时器0及GPIO口进行配置 TIMER_config(hTimer1, &MyConfig1);
//开始运行 TIMER_start(hTimer1);
}
//AD0 interrupt void SpiRcv0() { x[i++] = DRR0; if(i>99) i=0; }
//AD1 interrupt void SpiRcv1() { y[j++] = DRR1; if(j>99) j=0; }
void MCBSP_init() { MCBSP_enableSrgr(hMcbsp0); MCBSP_enableRcv(hMcbsp0); MCBSP_enableXmt(hMcbsp0); MCBSP_enableFsync(hMcbsp0); MCBSP_start(hMcbsp0,MCBSP_RCV_START | MCBSP_XMIT_START | MCBSP_SRGR_START| MCBSP_SRGR_FRAMESYNC, 0);
MCBSP_enableSrgr(hMcbsp1); MCBSP_enableRcv(hMcbsp1); MCBSP_enableXmt(hMcbsp1); MCBSP_enableFsync(hMcbsp1); MCBSP_start(hMcbsp1,MCBSP_RCV_START | MCBSP_XMIT_START | MCBSP_SRGR_START| MCBSP_SRGR_FRAMESYNC, 0); }
void InitGPIO() { /* GPIO */ GPIO_EN = 0x0000ffff; GPIO_DIR = 0x00002222; }
/*----------------------------------------------------------------------------*/
/****************************************************************************** * End of main.c ******************************************************************************/
|