[cross-post] nested interrupts

Jul 01, 2012 43 Replies

Agreed. Simpler if the hardware can keep track of its own state. Here we're seeing a software system running alongside the serial hardware, trying to keep track of state based on occasional hints. I feel very lucky that the uPs I've worked on all let me run the show using interrupt enables and persistent interrupt flags. Didn't know there were other kinds.

Mel.

The 8032 has a TI flag that gets set when the stop bit is sent. You have to clear it in the interrupt handler. When you use the scheme I presented, you only need to set the TI flag yourself to invoke the first interrupt from the main code.

Meindert

to

ou

the

IIRC the problem comes with a possible race condition. pseudocode FIFO is not empty, so set flag to indicate TI should not be set after char added. Interrupt empties buffer and clears TI Add char Do not set TI because buffer was not empty. In future TI will not be set because FIFO is not empty.

You can't just set TI every time a char is added to the FIFO as that will cause characters to be lost by overwriting SBUF.

Some times, you just need to turn off interrupts:

  • turn of interrupts (or just serial interrupt, if possible)
  • set TI if FIFO empty
  • add character
  • turn on interrupts

(and beware of the extra latency you're adding to everything else)

My liberal friends think I'm a conservative kook. My conservative friends think I'm a liberal kook. Why am I not happy that they have found common ground? Tim Wescott, Communications, Control, Circuits & Software http://www.wescottdesign.com

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required