Forum Discussion
Altera_Forum
Honored Contributor
12 years agoHi ted,
I changed the ISR scheme from legacy to HAL Scheme. When I press the button the WRITE signal goes HIGH thus generating the interrupt. The interrupt occurs but the status isn't good after pressing the button.
# include "alt_types.h"
# include "altera_avalon_fifo_util.h"
# include "altera_avalon_pio_regs.h"
# include "altera_avalon_fifo_regs.h"
# include "sys/alt_irq.h"
# include "system.h"
# include <stdio.h>
# include <unistd.h>
# define IN_CSR_ADDRESS 0x2001800
# define OUT_CSR_ADDRESS 0x2001820
# define OUT_ADDRESS 0x2001878
volatile int edge_capture;
volatile alt_u8 global; //SDRAM
volatile int interrupted = 0;
//static void handle_input_fifo_wrclk_interrupts(void* context, alt_u32 id)
static void handle_input_fifo_wrclk_interrupts(void* context)
{
volatile int* input_fifo_wrclk_irq_event_ptr = (volatile int*) context;
*input_fifo_wrclk_irq_event_ptr = altera_avalon_fifo_read_event(IN_CSR_ADDRESS, ALTERA_AVALON_FIFO_EVENT_ALL);
altera_avalon_fifo_clear_event(IN_CSR_ADDRESS, ALTERA_AVALON_FIFO_EVENT_ALL);
altera_avalon_fifo_clear_event(OUT_CSR_ADDRESS, ALTERA_AVALON_FIFO_EVENT_ALL);
altera_avalon_fifo_clear_event(OUT_ADDRESS, ALTERA_AVALON_FIFO_EVENT_ALL);
interrupted = 1;
}
volatile int input_fifo_wrclk_irq_event;
int init_input_fifo()
{
int code = ALTERA_AVALON_FIFO_OK;
code = altera_avalon_fifo_init(IN_CSR_ADDRESS, // Address
0x3F, // Enable interrupts
500, // Almost empty
1000); // Almost full
code = altera_avalon_fifo_init(OUT_CSR_ADDRESS, // Address
0x3F, // Enable interrupts
500, // Almost empty
1000); // Almost full
printf("ALMOSTEMPTY = %d\n", altera_avalon_fifo_read_almostempty(IN_CSR_ADDRESS));
printf("ALMOSTFULL = %d\n", altera_avalon_fifo_read_almostfull(IN_CSR_ADDRESS));
printf("STATUS = %d\n", altera_avalon_fifo_read_status(IN_CSR_ADDRESS, ALTERA_AVALON_FIFO_STATUS_REG));
void* edge_capture_ptr = (void*) &edge_capture;
alt_ic_isr_register(0, 16, handle_input_fifo_wrclk_interrupts, edge_capture_ptr, NULL); //IN_CSR_IRQ
alt_ic_isr_register(0, 17, handle_input_fifo_wrclk_interrupts, edge_capture_ptr, NULL); //OUT_CSR_IRQ
return code;
}
int main(void)
{
init_input_fifo();
while(1)
{
if (interrupted)
{
alt_u32 level = altera_avalon_fifo_read_level(0x2001800);
printf("LEVEL: %u\n", level);
printf("STATUS = %d\n", altera_avalon_fifo_read_status(IN_CSR_ADDRESS, ALTERA_AVALON_FIFO_STATUS_REG));
printf("\n");
interrupted = 0;
}
}
return 0;
}
The output is (BEFORE press the button): status = 0 The output is (AFTER press the button): level: 0 status = 1 The FIFO seems full (i_status = 1) in the first press and in the first time when I check the "interrupted" flag. How can it occurs? NIOS is running a 100MHz. Is it slow for this application? Thanks