Nios II按键中断调试程序及经验.doc

上传人:M****1 文档编号:556060201 上传时间:2024-01-12 格式:DOC 页数:3 大小:28KB
返回 下载 相关 举报
Nios II按键中断调试程序及经验.doc_第1页
第1页 / 共3页
Nios II按键中断调试程序及经验.doc_第2页
第2页 / 共3页
Nios II按键中断调试程序及经验.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《Nios II按键中断调试程序及经验.doc》由会员分享,可在线阅读,更多相关《Nios II按键中断调试程序及经验.doc(3页珍藏版)》请在金锄头文库上搜索。

1、Nios II按键中断调试程序及经验软件:Quatus II 6.1,Nios II 6.1硬件:EP1C3T144 FPGA开发板实验目的:熟悉nios II开发,掌握中断程序调试系统配置:CPU+OnChipRam(4K)+LED_PIO+BUTTON_PIO功能描述:按键实现中断,使led亮或灭led配置成开发板上的led0,led1,led2,led3按键采用简单按钮B17,B18,19,B20不给过多注释了(其实注释够多了)#include #include #include sys/alt_irq.h#include altera_avalon_pio_regs.h#include

2、 system.h/* A variable to hold the value of the button pio edge capture register. */volatile int edge_capture;#ifdef BUTTON_PIO_BASE/* 按键中断服务程序*/static void handle_button_interrupts(void* context, alt_u32 id) /* Cast context to edge_captures type. It is important that this be * declared volatile to

3、avoid unwanted compiler optimization. */ volatile int* edge_capture_ptr = (volatile int*) context; /* Store the value in the Buttons edge capture register in *context. */ *edge_capture_ptr = IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE); /* Reset the Buttons edge capture register. */ IOWR_ALTERA_

4、AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0);/* Initialize the button_pio. */static void init_button_pio() /* Recast the edge_capture pointer to match the alt_irq_register() function * prototype. */ void* edge_capture_ptr = (void*) &edge_capture; /* Enable all 4 button interrupts. */ IOWR_ALTERA_AVALON_P

5、IO_IRQ_MASK(BUTTON_PIO_BASE, 0xf); /* Reset the edge capture register. */ IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0x0); /* Register the interrupt handler. */ alt_irq_register( BUTTON_PIO_IRQ, edge_capture_ptr, handle_button_interrupts );#endifint main (void) _attribute_ (weak, alias (alt_ma

6、in);int alt_main(void) alt_irq_init(ALT_IRQ_BASE); /necessary,enable interrupts alt_sys_init(); /unnecessary alt_io_redirect(ALT_STDOUT,ALT_STDIN,ALT_STDERR);/unnecessary init_button_pio(); while(1) switch(edge_capture) case 0x01: IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,0xFF); break; case 0x02: IOW

7、R_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,0x00); break; case 0x04: IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,0xFF); break; case 0x08: IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,0x00); break; default: IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,0x0A); break; return 0;1 因为使用的是片上RAM,容量有限,故得重载alt_main(), 否则空间不够2 系统默认的alt_main()是干了很多活的.比如系统中断,IO设备驱动等,改写的时候得注意,哪些用户程序用到了.比如本例用到中断,故 alt_irq_init(ALT_IRQ_BASE);函数是必须的.开始没有调试成功就是因为没有开总中断中断的调试过程可以依次看以下: status:最低位PIE(使能),为禁止,为允许中断 ienable:32位,每位对应一个外部中断,为则对应使能 ipending:表示处理器正在处理的中断全局变量:alt_irq.若注册成功的话就会向向量表写入和Context.注册完后返回则成功,为负则失败

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号