Altera_Forum
Honored Contributor
11 years agoInterrupts on BareMetal Design
I am trying to trigger an interrupt based on the slider switch(GPIO2 on SoCKIT) toggling, but the code below doesn't seem to work. What could be the problem? Also, what is the difference between GPIO2 and ALT_GPIO_PORTB?
# include <stdio.h># include <stdint.h># include <unistd.h># include "hwlib.h"# include "socal/socal.h"# include "socal/hps.h"# include "socal/alt_gpio.h"# include <alt_generalpurpose_io.h># include <sys/time.h># include "alt_interrupt.h"
# define BIT_SW_0 (0x00100000)# define BIT_SW_1 (0x00080000)# define BIT_SW_2 (0x00040000)# define BIT_SW_3 (0x00020000)# define BIT_SW_ALL (BIT_SW_0 | BIT_SW_1 | BIT_SW_2 | BIT_SW_3)
static void alt_gpio_buffer_int_callback()
{
printf("Interrupt Triggered\n");
}
int main(int argc, char** argv) {
uint32_t a;
uint32_t b;
struct timeval t;
unsigned int last_time = 0;
ALT_STATUS_CODE status;
ALT_INT_INTERRUPT_t int_id = 0;
ALT_GPIO_PORT_t gpio_id = ALT_GPIO_PORTB;
alt_setbits_word(ALT_GPIO2_SWPORTA_DDR_ADDR, 0x00000000 );
alt_setbits_word(ALT_GPIO2_INTEN_ADDR, ALT_GPIO_INTEN_GPIO_INTEN_E_EN );
alt_setbits_word(ALT_GPIO2_INTTYPE_LEVEL_ADDR, ALT_GPIO_INTTYPE_LEVEL_GPIO_INTTYPE_LEVEL_E_LEVEL );
alt_setbits_word(ALT_GPIO2_INTMSK_ADDR, ALT_GPIO_INTMSK_GPIO_INTMSK_SET_MSK );
a = (alt_read_word((uint32_t)(ALT_GPIO2_EXT_PORTA_ADDR)) & (uint32_t)(BIT_SW_ALL)) >> 17;
status = alt_gpio_port_int_type_set(gpio_id, 0x1FFFFFFF, 0);
status = alt_gpio_port_int_pol_set(gpio_id, 0x1FFFFFFF, 1);
status = alt_gpio_port_int_enable(gpio_id, 1);
status = alt_gpio_port_int_mask_set(gpio_id, 1, 1);
status = alt_gpio_port_int_status_clear(gpio_id, 1);
status = alt_int_isr_register(int_id, alt_gpio_buffer_int_callback, NULL);
status = alt_int_global_enable();
if (status == ALT_E_SUCCESS)
{
status = alt_int_dist_enable(int_id);
}
while(1){
}
}
Thanks, Patel