cancel
Showing results for 
Search instead for 
Did you mean: 

How to detect infinite loop in program flow

mailmail9116
Associate II
Posted on October 14, 2013 at 19:48

Hi ALL ,

I have a question that is bugging me lately and i could not find any good solution for the problem.

Suppose I have a function , that may or may not , depend on the input and the amount of fixed bugs ;) , to got stuck somewhere inside in an infinite loop .

Is there any way for the cortex to recover from this infinite loop , without doing a hardware reset ?

Thanks

Michael
5 REPLIES 5
Posted on October 14, 2013 at 20:01

Watchdog Interrupt?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dthedens23
Associate II
Posted on October 14, 2013 at 21:32

Any function that may get stuck in an infinite loop should be coded with some kind of timeout or maximum number of re-try.

Better yet, do not baby sit the hardware with CPU expensive loops and polling hardware status bits.

Use the hardware to it's full advantage, by using interrupts and DMA.

Use I/O pins to driver external devices power (via a FET or some such) so that if a part stops responding, power cycle it.  (it may latch up from ESD events)

Use state machine drivers, if a device gets stuck in some state, then re-init it or power cycle it.

Non of the firmware that any vendor supplies is production worthy!  They provide examples of perfectly working code, for perfectly working hardware in a perfect world, which you an I know, it does not exist.

Read up on ''correct'' vs ''robust'' code.  I also learned a lot from Safety Critical Design Patterns

 
emalund
Associate III
Posted on October 15, 2013 at 14:56

re watchdog interrupt.

the WD is NOT a fix, it is NOT a method, it is NOT a remedy.

If a device of my design creates a watchdo interrupt, it is recorded with all details and the unit report ''maintenance required''

do you want to have to use your fire extinguisher?
Posted on October 15, 2013 at 15:33

It does however represent the closest thing to a ''stupid code running'' detector.

The processor runs code blindly, it makes no cognitive decisions about whether a code sequence is sensible or not, that's the job of the coder.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
frankmeyer9
Associate II
Posted on October 15, 2013 at 16:11

the WD is NOT a fix, it is NOT a method, it is NOT a remedy.

 

It should of course not be used as such, but it is a proved method to deal with transient EMI problems. Sometimes, system integrity may get lost without SW designers's fault ...