I try to run the simple code for GPIO’s interrupt on a SoCkit board (Cyclone V).
When I configure interrupt as level-sensitive, it seems to work properly, and the ISR is called many times when i press a buttton on the board. But when i configure the interrupt as edge sensitive, it doesn’t work properly. The ISR is called when i press the button first time, and then called again and again, as if interrupt in level mode. I tried all possible combinations of level/edge modes and polarity modes, but it doesn’t work.
My example:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <inttypes.h>
#include “alt_interrupt.h”
#include “alt_timers.h”
#include “alt_generalpurpose_io.h”
volatile bool blink = false;
/******************************************************************************/
/*!
* ISR Callback
*
* \param icciar
* \param context ISR context.
* \return none
*/
static void gpio_isr_callback() {
long mask = alt_gpio_port_int_status_get(ALT_GPIO_PORTC);
// Clear interrupt source don't care about the return value
long status = alt_gpio_port_int_status_clear(ALT_GPIO_PORTC, 0x00200000);
mask = alt_gpio_port_int_status_get(ALT_GPIO_PORTC);
alt_gpio_port_data_write(ALT_GPIO_PORTB, 0x0F000000, blink << 24);
blink = !blink;
}
/******************************************************************************/
/*!
* Main entry point
*
*/
int main(void) {
alt_gpio_init();
alt_gpio_port_datadir_set(ALT_GPIO_PORTB, 0x0F000000, 0x0F000000);
// System init
alt_gpt_all_tmr_init();
// Setup Interrupt
alt_int_global_init();
// Initialize CPU interrupts
alt_int_cpu_init();
// Set interrupt distributor target
int cpu_target = 0x1; //CPU0 will handle the interrupts
alt_int_dist_target_set(ALT_INT_INTERRUPT_GPIO2, cpu_target);
// Set interrupt trigger type
alt_int_dist_trigger_set(ALT_INT_INTERRUPT_GPIO2, ALT_INT_TRIGGER_EDGE);
// Enable interrupt at the distributor level
alt_int_dist_enable(ALT_INT_INTERRUPT_GPIO2);
// Enable CPU interrupts
alt_int_cpu_enable();
// Enable global interrupts
alt_int_global_enable();
alt_gpio_port_datadir_set(ALT_GPIO_PORTC, 0x01e00000, 0x00000000);
alt_gpio_port_debounce_set(ALT_GPIO_PORTC, 0x01e00000, 0x00200000);
alt_gpio_port_int_type_set(ALT_GPIO_PORTC, 0x01e00000, 0x002000000);
alt_gpio_port_int_pol_set(ALT_GPIO_PORTC, 0x01e00000, 0x00200000);
// Register gpio ISR
alt_int_isr_register(ALT_INT_INTERRUPT_GPIO2, gpio_isr_callback, NULL);
alt_gpio_port_int_enable(ALT_GPIO_PORTC, 0x00200000);
while(1);
return 0; //unreachable
}
Thanks in advance.