Forum Discussion
FawazJ_Altera
Frequent Contributor
7 years agoI think the 0 in the middle should be a pointer to the edge capture pointer alt_irq_register (KEY_IRQ, 0, KEY_ISR);
I have tried the enhanced Interrupt before, you need to modify the system.h file, Nios ii section, you will find:
ALT_LEGACY_INTERRUPT_API_PRESENT
change it to:
ALT_ENHANCED_INTERRUPT_API_PRESENT
Then, dont re-build or update the BSP, since it will change it back to legacy mode.
This might be something like this:
#include "sys/alt_irq.h"
#include "system.h"
/* Declare a global variable to hold the edge capture value. */
volatile int edge_capture;
/* 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 ISR. */
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
alt_ic_isr_register(BUTTON_PIO_IRQ_INTERRUPT_CONTROLLER_ID,
BUTTON_PIO_IRQ,
handle_button_interrupts,
edge_capture_ptr, 0x0);
#else
alt_irq_register( BUTTON_PIO_IRQ, edge_capture_ptr,
handle_button_interrupts );
#endif
}
adamS
New Contributor
7 years agoHi FJumaah,
Thanks for the reply!
Now I modify my code to use alt_ic_isr_register(...) function,
But unfortunately, the code is still stuck at the 65th press of the key😞
whether alt_ic_isr_register or alt_irq_register the results are the same.
#include <stdio.h>
#include <unistd.h>
#include "system.h"
#include "alt_types.h"
#include "io.h"
#include "altera_avalon_pio_regs.h"
#include "sys/alt_irq.h"
int bKeyPressed = 0;
int cnt = 1;
alt_u16 incre = 0;
alt_u16 data;
volatile int edge_capture;
void KEY_ISR(void* context){
bKeyPressed = 1;
// clear interrupt flag
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE,0);
printf("isr\n");
}
static void init_button_pio(){
void* edge_capture_ptr = (void*) &edge_capture;
// enable interrupt, 2-keybutton
IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY_BASE,0x03);
// clear capture flag
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE,0);
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
alt_ic_isr_register(
KEY_IRQ_INTERRUPT_CONTROLLER_ID,
KEY_IRQ,
KEY_ISR,
edge_capture_ptr,
0x0);
printf("ENHANCED mode\n");
#else
alt_irq_register (KEY_IRQ, edge_capture_ptr, KEY_ISR);
printf("LEGACY mode\n");
#endif
}
int main()
{
init_button_pio();
IOWR(LED_BASE, 0, (alt_u8)0);
while(1)
{
if(bKeyPressed)
{
bKeyPressed = 0;
*((alt_u8*)NEW_SDRAM_CONTROLLER_0_BASE + incre) = cnt;
data = *((alt_u8*)NEW_SDRAM_CONTROLLER_0_BASE + incre);
printf("cnt = %d, ", cnt);
printf("incre = %d, ", incre);
printf("data=%x\n", data);
IOWR(LED_BASE, 0, (alt_u8)data);
cnt ++;
incre += 1;
}
}
printf("b\n");
return 0;
}