Infinite loop... Waiting for an condition that's already true?

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Puzzled on this one.  I created a struct for SPI transactions that includes a ring buffer.  I have vars that tell me if the buffer is full or empty and in my code there's a section where I wait until there's something in the buffer to read.

 

I'm hitting a case where there's 10 bytes or so in the buffer and 'is_empty' is clear but the execution stops in this place anyway. 

(See diagram... execution nevers hits breakpoint and instead is stuck at the yellow line)

 

Anything I'm missing here?

 

Attachment(s): 

This topic has a solution.

-Adam
"Please don't judge my God by my inability to follow him" - Chris Mollins
================
www.onecircuit.com
================

Last Edited: Wed. Oct 11, 2017 - 07:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hard to tell from that.  Perhaps show the generated code for the loop.  "volatile" issue?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If '.is_empty' is modified by an ISR, it should be declared as volatile.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

  "volatile" issue?

 

Bingo!  Thanks for the quick response!

-Adam
"Please don't judge my God by my inability to follow him" - Chris Mollins
================
www.onecircuit.com
================