|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
在nios SBT中写了一个测试代码,用按键产生中断控制LED灯的亮灭,可是下载程序测试的时候总会出现几次按键没有正常响应的情况,即按一次灯无反应,按键消抖是用的FPGA硬件消抖,设置的应该没有问题,后再调试的时候发现在debug模式下,却表现的非常正常,按键无论怎么按都能正常效应到中断,为啥会出现这种情况?代码如下所示,请大家指点下!
#include <stdio.h>
#include <unistd.h>
#include "../inc/sopc.h"
#include "sys/alt_irq.h"
typedef struct
{
unsigned long int DATA;
unsigned long int DIRECTION;
unsigned long int INTERRUPT_MASK;
unsigned long int EDGE_CAPTURE;
}PIO_STR;
#define KEY_BASE 0x0
#define KEY_IRQ 1
#define LED ((PIO_STR *)PIO_LED_BASE)
#define KEY ((PIO_STR *)KEY_BASE)
volatile int key_flag = 0;
void ISR_key(void * context,unsigned long id){
key_flag = ~key_flag;
}
int init_key(void){
KEY->INTERRUPT_MASK = 1;
return alt_irq_register(KEY_IRQ,NULL,ISR_key);
}
void delay(){
int i,j;
for(i=0;i<1000;i++)
for(j=0;j<100;j++);
}
int main()
{
printf("Hello from Nios II!\n");
printf("int:%d\n",sizeof(int));
printf("char:%d\n",sizeof(char));
printf("short:%d\n",sizeof(short));
printf("long:%d\n",sizeof(short));
printf("short int:%d\n",sizeof(short int));
printf("long int:%d\n",sizeof(long int));
printf("long long:%d\n",sizeof(long long));
printf("long long int:%d\n",sizeof(long long int));
printf("double:%d\n",sizeof(double));
printf("float:%d\n",sizeof(float));
printf("signed long:%d\n",sizeof(signed long));
printf("unsigned long:%d\n",sizeof(unsigned long));
if(!init_key()){
printf("register successfuly!\n");
}
else {
printf("Error:register failure!\n");
}
while(1)
{
if(key_flag){
LED->DATA = 1;
}
else{
LED->DATA = 0;
}
}
return 0;
} |
|