- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Tags:
- Include
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
May I know which Quartus Version you are working on? Also which device are you targeting, Cyclone V SoC, Arria 10 SoC etc.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page