求教 复位后与初次下载程序结果不一致的问题
写了一段测试边沿触发的NIOS的程序,第一次下进去是正常的,按键复位后就无法从注册中断中出来了。下面是代码和控制台输出。#include <stdio.h>
#include <unistd.h>
#include "system.h"
#include "../inc/led.h"
#include "sys/alt_irq.h"
#include <alt_types.h>
#include "altera_avalon_pio_regs.h"
int key_flag=0;
void ISR_key(void *contxt,unsigned long id);
int init_key(void);
int main()
{
printf("\n");
printf("Hello from Nios ! +1 \n");
usleep(5000);
KEY ->INTERRUPT_MASK=0;
printf("hello +2 \n");
if(!init_key())
{
printf("register successfully!\n");
}
else
{
printf("register fail!\n");
}
printf("end Nios init\n");
while(1)
{
/* int i;
for(i=0;i<4;i++)
{
LED -> DATA = 1<<i;
usleep(500000);
}
*/
if(key_flag) LED->DATA =1;
else LED->DATA =0;
usleep(5000);
}
return 0;
}
void ISR_key(void *contxt,unsigned long id)
{
KEY->EDGE_CAPTURE=0;
key_flag =(KEY->DATA)& 0x01;//~key_flag;
KEY->EDGE_CAPTURE=0;
// printf("run into interrupt");
//printf("%d\n",key_flag);
//IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0);
}
int init_key(void)
{
// KEY ->INTERRUPT_MASK=1;
// KEY->EDGE_CAPTURE=0;
IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY_BASE,1);
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE, 0);
return (alt_irq_register(KEY_IRQ,NULL,ISR_key));
//KEY ->INTERRUPT_MASK=1;
//KEY->EDGE_CAPTURE=0;
}Hello from Nios ! +1
hello +2
register successfully!
end Nios init
Hello from Nios ! +1
hello +2 复位前打印四行信息,复位后就没法正常运行了,求教
页:
[1]