[求助]nios 定时器中断控制IO口出错(利用定时器测量频率)
- UID
- 794497
- 性别
- 女
|
[求助]nios 定时器中断控制IO口出错(利用定时器测量频率)
我用nisoii里的定时器定时1s,使能中断,中断服务程序里控制IO口,关闭我的硬件计数器计数功能,同时读出计数。所得计数即为我要测的频率。 #include "alt_types.h" #include <stdio.h> #include "system.h" #include "sys/alt_irq.h" #include "altera_avalon_timer_regs.h" #define alt_cpu_freq 50000000 volatile alt_u32 counter; volatile int ito_capture; void init_timer0(void) { //设定1s定时周期 void *ito_capture_ptr=(void *)& ito_capture;//重置ito捕获事件,使其符合alt_irq_register()函数的要求 IOWR_ALTERA_AVALON_TIMER_PERIODL(TIMER0_BASE, (short)(alt_cpu_freq&0x0000ffff)); IOWR_ALTERA_AVALON_TIMER_PERIODH(TIMER0_BASE, (short)((alt_cpu_freq>>16)&0x0000ffff));
//开启定时器,并设定为循环工作,允许中断 IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER0_BASE,7);
//注册定时器0中断服务函数 int alt_irq_register(TIMER0_IRQ,ito_capture_ptr,timer0_interrupts); } void timer0_interrupts (void *context,alt_u32 id) { volatile int *ito_capture_ptr=(volatile int *) context;//调整context指针为整数型 // *ito_capture_ptr=IORD_ALTERA_AVALON_TIMER_CONTROL_ITO_MSK(TIMER0_BASE); //读计数器值 //向状态寄存器执行写操作,清除定时器溢出状态,即清timer0标志 IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER0_BASE, 0x0); IOWR_ALTERA_AVALON_PIO_DATA(PB0_BASE, *ito_capture_ptr); //写到pb0输出口
} int main(void) { // volatile alt_u32 counter;//暂存计数器计数(PB引脚状态) init_timer0(); while (1); return 0; } 编译出现这样的错误,好像是中断注册不对,不知道咋改了. **** Build of configuration Debug for project pinlvji ****
make -s all includes Compiling pinlvji.c... ../pinlvji.c: In function `init_timer0': ../pinlvji.c:21: error: parse error before numeric constant ../pinlvji.c:13: warning: unused variable `ito_capture_ptr' ../pinlvji.c: In function `timer0_interrupts': ../pinlvji.c:30: warning: implicit declaration of function `IOWR_ALTERA_AVALON_PIO_DATA' make: *** [obj/pinlvji.o] Error 1 Build completed in 3.313 seconds
|
|
|
|
|
|
- UID
- 121854
- 性别
- 男
|
|
|
|
|
|