AnsweredAssumed Answered

KBI - how to ensure that no edge sensitive interrupts are missed?

Question asked by Mark Butcher on Dec 24, 2014
Latest reply on Dec 25, 2014 by jeremyzhou

Hi All

 

The larger KE devices include the KBI (Keyboard Interrupts) which allows up to 64 inputs to be configured as rising or falling edge interrupts (or also level sensitive). There are two KBIs, each responsible for 32 of the inputs each).

The problem is that it doesn't look possible to guarantee that there are no potential edge interrupt loses due to the interrupt clearing mechanism.

 

When any one of the inputs triggers the interrupt the interrupt flag is set and the interrupt handler called. This handler can see which one or more inputs triggered by reading KBIx_SP, where there is flag for each source. This means that the interrupt routine can then dispatch a user handler specifically for the input, or inputs, that triggered.

 

The difficulty arises due to the fact that the input flags need to be reset by writing the RSTKBSP bit in the status register, which resets all set flags.

 

Consider the sequence:

1. read the input status flags (eg. KBIx_P0 is set so we known that this triggered and we can handle it during further steps)

2. reset flags

3. handle flagged inputs from 1.

 

Normally this works fine but what happens when a further input triggers between the actions 1. and 2. ? It means that the new input (which wasn't read in 1. because it was not yet ready) is reset by 2 and the result is that the interrupt handler doesn't know about this interrupt.

The new input event can set the interrupt flag again and this causes the interrupt to be re-entered, but this time there is no source flag showing why it came. It could be assumed that the flag was lost and so all input states need to be 'manually' checked to try to identify which it could be but this also fails if there is another one also that happens to fire at the same time because then this other one looks to be the only one).

 

After studing the KBI user's manual I don't see any mechanism built in to it that allows edges to be reliably detected in all instances without the need to check all input states each time there is an interrupt (the same as the more simple KBI in the smaller devices which doesn't have the KBIx_SP register), but this would mean that the KBIx_SP register is redundant to a degree because it can't be fully trusted.

 

I see that the KBI has been used in 8 bit parts for some time so I suppose that such a problem would be well understood. Is there however some inbuilt mechanism that protects against such flag loss which ensures that it can be used effectively?

 

Regards

 

Mark

Outcomes