Forum Discussion
Altera_Forum
Honored Contributor
14 years agoThis code works fine even with such delay in the handler. Without this delay I noticed only quick flash on the corresponding led.
Unfortunately, I still don't understand the core of the problem:(
/*
* "Hello World" example.
*
* This example prints 'Hello from Nios II' to the STDOUT stream. It runs on
* the Nios II 'standard', 'full_featured', 'fast', and 'low_cost' example
* designs. It runs with or without the MicroC/OS-II RTOS and requires a STDOUT
* device in your system's hardware.
* The memory footprint of this hosted application is ~69 kbytes by default
* using the standard reference design.
*
* For a reduced footprint version of this template, and an explanation of how
* to reduce the memory footprint for a given application, see the
* "small_hello_world" template.
*
*/
# include <stdio.h># include "system.h"# include "alt_types.h"# include "sys/alt_irq.h"# include "altera_avalon_pio_regs.h"
//#include <unistd.h>
/* A variable to hold the value of the button pio edge capture register. */
volatile int edge_capture;
/* button IRQ function */
static void handle_button_interrupts(void* context, alt_u32 id)
{
int delay;
IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, ~IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE));
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0);
delay=0x1;
while (delay<1)
{
delay++;
}
}
/* 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 );
}
int main()
{
printf("Hello from Nios II!\n");
init_button_pio();
IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0xf);
while (1);
return 0;
}