Re: Help on: How to avoid placing millions of software checkpoints



rover8898 schrieb:

Hello all,

I have a programming problem/challenge.
Let explain my scenario:

I have a C program (distributed accross many files and functions) that
is responsible for handling hardware. This piece of hardware (a
microcontroller) can do several lengthy procedures depending on the
commands it receives.
The problem arises when the hardware receives a "stop command". The
stop command demands that the hardware ceases its current action and
goes in sleep mode. Since, the stop command can be received at any
arbitary momment (beginning, middle or end of the current procedure), I
am forced to have checkpoints for the [reception of the stop cmd]
almost everywhere in my program. Every time a function is about to do
an action, I have to check if the stop flag was set. Hence, as you can
probably guess, placing stop flag checkpoints at every decision
junction is very tedious. Using interrupts doesn't seem to help me
either since any interrupt that is called will bring me back in the
program after it is is completed. If I was coding in assembler, i would
be able to use the "jump" (assembly equivalent of the "goto" statement)
statement to jump at the near-end of the program. However, the "goto
statement" in C has only file (or function, i forget which) scope, and
as such, does not help me much.
Does anyone know of a course of action that will lead to me not having
to place checkpoints all over the program?

Maybe you should have a look at signals (interrupts) and
setjmp/longjmp.

In short: -
- before the main loop, call if (setjmp(jmp_buf)==1) { ... };
main_loop().
- In the signal handler, call longjmp(jmp_buf,1);
- a signal (interrupt) will execute {...} and reenter main_loop()
with
a correct stack).

Hubble.

.



Relevant Pages