Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12686 Discussions

Why overwrite/reset the complete edge register in a PIO ISR?

BeB
Beginner
287 Views

Hello,

Refering to the Nios 2 software handbook (code below), why overwrite *edge_capture_ptr completely and clear the entire edge capture register  with IOWR_ALTERA_AVALON_PIO_EDGE_CAP systematically?

Let's say that there are 2 buttons for this PIO. If two buttons are activated very close to each other, wouldn't the second ISR call overwrite *edge_capture_ptr? So if the program was slightly busy doing something else in the mean time, it would miss the first button. Why not do a logical OR with the current value obtained with IORD_ALTERA_AVALON_PIO_EDGE_CAP and let the program clear the corresponding bit of *edge_capture_ptr when it has done what it is supposed to do.

With the IOWR operation: why not just reset the one edge that was detected instead of doing a blanket reset?

Thanks!

Bertrand

 

#include "system.h"
#include "altera_avalon_pio_regs.h"
#include "alt_types.h"
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
static void handle_button_interrupts(void* context)
#else
static void handle_button_interrupts(void* context, alt_u32 id)
#endif
{
/* Cast context to edge_capture's type. It is important that this
be declared volatile to avoid unwanted compiler optimization. */
volatile int* edge_capture_ptr = (volatile int*) context;
/*
* Read the edge capture register on the button PIO.
* Store value.
*/
*edge_capture_ptr =
IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE);
/* Write to the edge capture register to reset it. */
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0);
/* Read the PIO to delay ISR exit. This is done to prevent a
spurious interrupt in systems with high processor -> pio
latency and fast interrupts. */
IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE);
}

0 Kudos
4 Replies
JingyangTeh
Employee
188 Views

Hi

 

To enable bit wise operation, you will need to enable "individual bit clearing/setting" settings in the PIO IP.

This will only affect the edge register. With this setting enabled, setting will only affect the bit instead of the entire register.

 

2025-02-14_10h09_00.png

 

Regards

Jingyang, Teh

 

0 Kudos
JingyangTeh
Employee
154 Views

Hi


Do you have any update on this case?

Did you try out the suggested parameters?


Regards

Jingyang


0 Kudos
BeB
Beginner
33 Views

Hello,

Sorry for the late reply.

Your suggestion concerns the pio output register, which was not really the matter.

I am trying to understand why the complete variable 'edge_capture_ptr' should be overwritten when reading the edge capture register, and whether information from previous interrupts may be lost because of that.

Thank you!

Bertrand

0 Kudos
JingyangTeh
Employee
112 Views

Hi


As we do not receive any response from you on the previous question/reply/answer that we have provided. Please login to ‘https://supporttickets.intel.com/s/?language=en_US’, view details of the desire request, and post a feed/response within the next 15 days to allow me to continue to support you. After 15 days, this thread will be transitioned to community support. The community users will be able to help you on your follow-up questions.


Regards

Jingyang, Teh


0 Kudos
Reply