Altera_Forum
Honored Contributor
19 years agoPosible Problem with ISR Edge PIO
Hello,
This is more a theoretical view, but think it could be important to you. When working with an IRQ generating PIO with Edge Capture Register and multiple inputs, a ISR proccesing routine should look like this:void my_isr_procedure(...) __attribute__ ((section (".internal_ram.txt")));
void my_isr_procedure(...)
{
// read capture register
register alt_u32 edge_capture=IORD_ALTERA_AVALON_PIO_EDGE_CAP(IRQ_PIO_BASE);
// clear it imediatly
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(IRQ_PIO_BASE, 0);
... do interrupt work ...
if (edge_capture & ???) ... // do something
// set mask
IOWR_ALTERA_AVALON_PIO_IRQ_MASK(IRQ_PIO_BASE, 0xF);
} As you see, reading the capture register and clearing must be done imediate after each other. Otherwise, if clearing edge register at the end of your ISR, the possibility increases that a slightly async captured edge, which could apear during your ISR processing, get's lost. But, when i think a bit about it, i guess that even between reading and writing the edge capture register, a edge could get lost, if it is half long and half async to the cpu clock. Am i right? I guess so, because read and write are together no atomar operations and take two cpu cycles to handle the capture register. So, if a edge is captured right after i have read the edge capture register but not yet cleared the edge register, it will not get recognized. So i come to the conclusion that in certain situations, an edge can get lost. To avoid this, an atomar instruction which executes in one CPU cycle is needed, which deletes only the bits from the edge register, which has been detected. in pseudocode it whould look like this: edgeCapReg=edgeCapReg AND NOT ( bits ) I looked to the Altera HAL, but did not find anything simular. Regards