EmbeddedRelated.com
Forums

[cross-post] nested interrupts

Started by alb July 1, 2012
Meindert Sprang wrote:

> "alb" <alessandro.basili@cern.ch> wrote in message > news:a5igkjFb0oU1@mid.individual.net... >> On 7/4/2012 9:12 AM, Meindert Sprang wrote: >> >>>[...] If >> > no transmission is in progress, the TX interrupt of sport should be >> > disabled. If you write something to the fifo, you just enable the TX >> > interrupt, nothing more. At that time, the sport TX buffers are empty > and an >> > interrupt will occur immediately, reading a byte from the fifo and > writing >> > it to sport. >> >> Uhm that is interesting, but since my interrupt is edge sensitive I do >> not believe that when I enable it the interrupt will be seen immediately. >> I may change the interrupt to level sensitive, but I'm not sure if it is >> beneficial. > > Yes it is because then you can use the procedure I outlined. And this is > not pure theoretical, I use this in a commercial product. And I have no > race conditions and use nested interrupts.
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.
"Rocky" <robertgush@gmail.com> wrote in message
news:01525c1a-bf1d-4eb1-91cd-700a1af4a582@e20g2000vbm.googlegroups.com...
> 8032. Bit of a pain, but once the code is in place it is OK.
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
On Jul 5, 12:01=A0pm, "Meindert Sprang" <m...@NOJUNKcustomORSPAMware.nl>
wrote:
> "Rocky" <robertg...@gmail.com> wrote in message > > news:01525c1a-bf1d-4eb1-91cd-700a1af4a582@e20g2000vbm.googlegroups.com... > > > 8032. Bit of a pain, but once the code is in place it is OK. > > 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, y=
ou
> only need to set the TI flag yourself to invoke the first interrupt from =
the
> main code. >
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.
On Thu, 05 Jul 2012 05:15:21 -0700, Rocky wrote:

> On Jul 5, 12:01&nbsp;pm, "Meindert Sprang" <m...@NOJUNKcustomORSPAMware.nl> > wrote: >> "Rocky" <robertg...@gmail.com> wrote in message >> >> news:01525c1a-
bf1d-4eb1-91cd-700a1af4a582@e20g2000vbm.googlegroups.com...
>> >> > 8032. Bit of a pain, but once the code is in place it is OK. >> >> 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. >> > 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