Intel® SoC FPGA Embedded Development Suite
Support for SoC FPGA Software Development, SoC FPGA HPS Architecture, HPS SoC Boot and Configuration, Operating Systems
489 Discussions

Hi, I am trying to write a simple ISR for handling button presses. I am trying to print "Interrupt!" on every interrupt on the falling edge of a press. The following code is printing nothing:

Shubham_P_Intel
Employee
1,021 Views

I have configured the PIO module by checking the Synchronously Capture, Enable bit clearing for edge-capture register and Generate IRQ options. IRQ type is set to EDGE, and EDGE type is set to falling.

 

Following is my code:

 

#include <stdio.h>

#include "system.h"

#include "altera_avalon_pio_regs.h"

#include "sys/alt_irq.h"

 

volatile int edge_capture;

 

/* button IRQ function */

//static void handle_button_interrupts(void* context, alt_u32 id)

static void handle_button_interrupts(void* context)

{

  /* Cast context to edge_capture's type. It is important that this be

   * declared volatile to avoid unwanted compiler optimization.

   */

  //int delay;

  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_BASE);

  /* Reset the Button's edge capture register. */

  IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_BASE, 0x0);

// Delay before exiting ISR.

  IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_BASE);

}

/* 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_BASE, 0x1);

  /* Reset the edge capture register. */

  IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_BASE, 0x0);

  /* Register the interrupt handler. */

  alt_ic_isr_register(BUTTON_IRQ_INTERRUPT_CONTROLLER_ID, BUTTON_IRQ, handle_button_interrupts, edge_capture_ptr, 0x0);

}

 

static void handle_button_press(alt_u8 type)

{

  /* Button press actions while counting. */

  if (type == 'r')

  {

 

   printf("Interrupt!\n");

  }

}

 

int main()

{

  //IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0xf);

printf("Init\n");

init_button_pio();

  while (1)

  {

    if(edge_capture!=0)

    {

      handle_button_press('r');

    }

    //for(int i=0;i<1000000;i++){}

  }

  return 0;

}

 

Any help/guidance will be greatly appreciated, thanks a lot!

0 Kudos
1 Reply
EBERLAZARE_I_Intel
1,007 Views

Hello,


May I know which Quartus Version you are working on? Also which device are you targeting, Cyclone V SoC, Arria 10 SoC etc.






0 Kudos
Reply