这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » FPGA » [原创]altera杯nios设计大赛源码奉献

共40条 1/4 1 2 3 4 跳转至

[原创]altera杯nios设计大赛源码奉献

工程师
2007-04-25 22:54:20     打赏
[replyview]

niosII button 中断

volatile int edge_capture;

static void handle_button_interrupts(void* context, alt_u32 id)
{
/* Cast context to edge_capture's type.
* It is important to keep this volatile,
* to avoid compiler optimization issues.
*/
volatile int* edge_capture_ptr = (volatile int*) context;
/* Store the value in the Button's edge capture register in *context. */
*edge_capture_ptr = IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE);
/* Reset the Button's edge capture register. */
IOWR_ALTERA_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_PIO_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 );
}

static void TestButtons( void )
{
alt_u8 buttons_tested;
alt_u8 all_tested;
/* Variable which holds the last value of edge_capture to avoid
* "double counting" button/switch presses
*/
int last_tested;
/* Initialize the Buttons/Switches (SW0-SW3) */
init_button_pio();
/* Initialize the variables which keep track of which buttons have been tested. */
buttons_tested = 0x0;
all_tested = 0xf;

/* Initialize edge_capture to avoid any "false" triggers from
* a previous run.
*/

edge_capture = 0;

/* Set last_tested to a value that edge_capture can never equal
* to avoid accidental equalities in the while() loop below.
*/

last_tested = 0xffff;

/* Print a quick message stating what is happening */

printf("\nA loop will be run until all buttons/switches have been pressed.\n\n");
printf("\n\tNOTE: Once a button press has been detected, for a particular button,\n\tany further presses will be ignored!\n\n");

/* Loop until all buttons have been pressed.
* This happens when buttons_tested == all_tested.
*/

while ( buttons_tested != all_tested )
{
if (last_tested == edge_capture)
{
continue;
}
else
{
last_tested = edge_capture;
switch (edge_capture)
{
case 0x1:
printf("\nButton 1 (SW0) Pressed.\n");
buttons_tested = buttons_tested | 0x1;
break;
case 0x2:
printf("\nButton 2 (SW1) Pressed.\n");
buttons_tested = buttons_tested | 0x2;
break;
case 0x4:
printf("\nButton 3 (SW2) Pressed.\n");
buttons_tested = buttons_tested | 0x4;
break;
case 0x8:
printf("\nButton 4 (SW3) Pressed.\n");
buttons_tested = buttons_tested | 0x8;
break;
}
}
}
/* Disable button interrupts for anything outside this loop. */
IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE, 0x0);
printf ("\nAll Buttons (SW0-SW3) were pressed, at least, once.\n");
usleep(2000000);
return;
}

有问题的请在后面跟帖提出!


[em09][em09][em09][em09][em09][em09][em09][em09][/replyview] [align=right][color=#000066][此贴子已经被作者于2007-5-8 15:49:23编辑过][/color][/align]



关键词: 原创     altera     设计     大赛     源码     奉献     but    

工程师
2007-04-27 06:17:00     打赏
2楼

这可是竞赛的源码哦,潜力股,望斑竹加精华!

[em07][em07][em07]

菜鸟
2007-04-27 06:23:00     打赏
3楼

支持加精!


院士
2007-04-27 06:58:00     打赏
4楼
以下是引用FPGAer在2007-4-26 22:23:00的发言:

支持加精!

既然有支持者~~


菜鸟
2007-04-29 23:52:00     打赏
5楼

连注释都是英文,看样子今年中国Altera公司的竞赛水平又要提高哦

我得加油了


菜鸟
2007-05-11 07:24:00     打赏
6楼
hao dong xi ya

菜鸟
2007-05-17 03:19:00     打赏
7楼

看看呀 ``````````````````


菜鸟
2007-05-17 05:14:00     打赏
8楼

thanks alot


菜鸟
2007-05-17 22:22:00     打赏
9楼
连注释都是英文,看样子今年中国Altera公司的竞赛水平又要提高哦

菜鸟
2007-05-18 04:37:00     打赏
10楼

呵呵,先谢谢了


共40条 1/4 1 2 3 4 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]