我现在使用的是DM642,ext_int5,ext_int6分别用作两个外部中断信号 相信大家也遇到过这样的问题,比如一个车轮压在前后两个磁钢上,这两个磁钢分别产生中断信号送给CPU。这里有两个问题请教一下各位高手: 一、下面是我的一个简单程序用来不断计算两次中断之间的时间差值, 我觉得定时器既然在不断计数,那么我得到的差值 t=t2-t1也应该不断地输出来呀,但是无论我用LOG_printf还是watch windows却只能得到一个差值t,后面的差值就观察不到了,请各位给指点一下应该怎么观察t值呢? 二、还有一个就是希望大家帮看看我下面这个程序有问题吗?定时器计数是这样记吗? #include <std.h> #include <csl.h> #include <log.h> #include <csl_emifa.h> #include <csl_irq.h> #include <csl_chip.h> #include <csl_timer.h> #include <csl_gpio.h> #include "seeddm642.h" #include "seeddm642_uart.h"
/*SEEDDM642的emifa的设置结构*/ EMIFA_Config Seeddm642ConfigA ={ 0x00052078,/*gblctl EMIFA(B)global control register value */ /*将CLK6、4、1使能;将MRMODE置1;使能EK2EN,EK2RATE*/ 0xffffffd3,/*cectl0 CE0 space control register value*/ /*将CE0空间设为SDRAM*/ 0x73a28e01,/*cectl1 CE1 space control register value*/ /*Read hold: 1 clock; MTYPE : 0000,选择8位的异步接口 Read strobe :001110;14个clock宽度 TA:2 clock; Read setup 2 clock; Write hold :2 clock; Write strobe: 14 clock Write setup :7 clock -- --------------- 14c /1c ----------------/ */ 0x22a28a22, /*cectl2 CE2 space control register value*/ 0x22a28a42, /*cectl3 CE3 space control register value*/ 0x57115000, /*sdctl SDRAM control register value*/ 0x0000081b, /*sdtim SDRAM timing register value*/ 0x001faf4d, /*sdext SDRAM extension register value*/ 0x00000002, /*cesec0 CE0 space secondary control register value*/ 0x00000002, /*cesec1 CE1 space secondary control register value*/ 0x00000002, /*cesec2 CE2 space secondary control register value*/ 0x00000073 /*cesec3 CE3 space secondary control register value*/ };
SEEDDM642_UART_Config UartConfig ={ 0x01,/*寄存器IER*/ 0x5f,/*寄存器FCR*/ 0x03,/*寄存器LCR*/ 0x08,/*寄存器MCR*/ }; extern far LOG_Obj trace; static unsigned int t1 = 0; static unsigned int t2 = 0; static unsigned int t = 0; static int cnt = 0; static TIMER_Handle hTimer1; static Uint32 TimerEventId;
Uint8 IOreadback; Uint16 buffer; SEEDDM642_UART_Handle SEEDuartHandleA; SEEDDM642_UART_Handle SEEDuartHandleB;
void ExtInt_init();//外部中断初始化
/*此程序可将四个采集口的数据经过Video Port0送出*/ void main() { /* perform all initializations */ /*-------------------------------------------------------*/ /*Initialise CSL,初始化CSL库*/ TIMER_Config myTimConfig; CSL_init(); GPIO_RSET(GPEN,0x1E0);// GPIO_RSET(GPDIR,0x100); GPIO_RSET(GPVAL,0x000); /*----------------------------------------------------------*/ /*EMIFA的初始化,将CE0设为SDRAM空间,CE1设为异步空间 注,DM642支持的是EMIFA,而非EMIF*/ EMIFA_config(&Seeddm642ConfigA); /*----------------------------------------------------------*/ hTimer1 = TIMER_open(TIMER_DEV1, 0);
TimerEventId = TIMER_getEventId(hTimer1); IRQ_globalDisable(); IRQ_reset(IRQ_EVT_EXTINT5); IRQ_nmiDisable(); IRQ_nmiEnable(); IRQ_map(TimerEventId, 15); IRQ_reset(TimerEventId); myTimConfig.cnt = 0x0; myTimConfig.ctl = 0x305;
myTimConfig.prd = 0x00124f8; TIMER_config(hTimer1, &myTimConfig); IRQ_enable(TimerEventId);
IRQ_enable(IRQ_EVT_EXTINT5); IRQ_globalEnable(); ExtInt_init(); TIMER_start(hTimer1); /*测试串口A*/ /* Open UART */ SEEDuartHandleA = SEEDDM642_UART_open(SEEDDM642_UARTA, SEEDDM642_UART_BAUD9600, &UartConfig); /*Open UARTB*/ SEEDuartHandleB = SEEDDM642_UART_open(SEEDDM642_UARTB, SEEDDM642_UART_BAUD9600, &UartConfig); }
void ExtInt_init() { IRQ_nmiEnable(); IRQ_globalEnable(); IRQ_map(IRQ_EVT_EXTINT6,6); IRQ_map(IRQ_EVT_EXTINT7,7); IRQ_reset(IRQ_EVT_EXTINT6); IRQ_reset(IRQ_EVT_EXTINT7); IRQ_RSET(EXTPOL,0x0E);//下降沿中断 IRQ_enable(IRQ_EVT_EXTINT6); IRQ_enable(IRQ_EVT_EXTINT7); }
void Extint6_isr() { t1 = cnt; }
void Extint7_isr() { t2 = cnt;//75000对应myTimConfig.prd = 0x00124f8
t = t2 -t1 ; LOG_printf(&trace,"t VAL is %d
", t); }
void CLK_cnt() { cnt++; } |