473,385 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help on: How to avoid placing millions of software checkpoints

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?

Regards
Roger Bourne

Sep 24 '06 #1
5 1555
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.

Sep 24 '06 #2
So use an ISR that doesn't 'complete' till it gets the awake command.

The ISR doesn't have to return to the same point of code that the
return address says it should. It can return anywhere it wants !
int sleep_indicator = 0;
void command_executer(void)
{
while (1)
{
if (sleep_indicator)
__asm("halt"); /* or whatever cput asm instruction turns off the
cpu till an ISR */
else if (entries_in_command_queue 0 )
execute_command(pop_command_from_command_queue());
else
__asm("halt"); /* sleep if there is nothing in the command queue
*/
}
}

/* this will have to be done in asm */
void ISR_command_reciever_routine(void)
{
int tmp = read_command()

/* does the command tell us to sleep ?
if (tmp == SLEEP)
{
sleep_indicator = 1;
isr_return_address = command_executer:
return_from_isr();
}
/* is this a new command after having been asleep */
else if (sleep_indicator == 1)
{
sleep_indicator = 0;
isr_push_command_to_queue(tmp);
re_init_appropriate_globals();
return_address = command_executer;
return_from_isr();
}
/* else this is a new command during normal execution of another
command */
else
{
push_command_to_queue(tmp);
return_from_isr();
}
}






rover8898 wrote:
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?

Regards
Roger Bourne
Sep 24 '06 #3
Thank you both Samuel and Hubble.

Both are good solutions to my problem.
I like the setjmp.h's setjmp and longjmp instructions. They are what I
was initially looking for: a non-local goto.

However, looking at Samuel code made me realize that my code
architecture is wrong. Now: My command handling+exution is done outside
of an ISR. It uses as parameter the contents of the reception buffer.

What is should be: My command handling+exution should be in an ISR.
However it brings 2 questions to mind:
1. Will nested ISRs pose a problem ? I will have to pop the stack an
extra to void the previous command....
2. Will the fact that the ISR routine disables all interrupts upon
iwhen its commencement pose a problem?

Those are minor problems. I am certain I will be able to resolve them.
Thanks guys.

-Roger

Sep 24 '06 #4
Hello again,

I looked at the setjmp/longjmp function description.
However, I can not discern if the setjmp/longjmp pair can cause stack
overflow problems.

Regards,
-Roger
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.
Sep 24 '06 #5
1. Will nested ISRs pose a problem ? I will have to pop the stack an
extra to void the previous command....
Yes and thats a bug in my ISR code, There isn't a
re_init_appropriate_globals(); when the sleep command is encountered,
to re-init the user space stack.
2. Will the fact that the ISR routine disables all interrupts upon
iwhen its commencement pose a problem?
Yes that is a problem.
I hoped to avoid nested ISR issues and ISR disabling issues by having a
distinct isr_receiver and command_executer that communicate via some
variables. How does your micro-controller exit the disabled interupt
state? Is it tied to the return from ISR instruction or can it be done
without having to return from the ISR ?

another issue:
Suppose your code looks like:

void massive_isr_routine_that_does_everything(void)
{
int a= 10; /* init variable a which is kept in a stack frame */
int b= 45; /* init variable b which is kept in a stack frame */
int x= 67; /* init variable x which is kept is a stack frame */

/* reset the stack */
...

/* remove ISR execution protection */
...

/* normal code */
...
}
So when you reset the stack, what do you set it to? And you have
variables that were already initialized on the stack. They now need to
be initialized on the new stack.

Ok fine so you can change the code to read
void massive_isr_routine_that_does_everything(void)
{
int a; /* init variable a which is kept in a stack frame */
int b; /* init variable b which is kept in a stack frame */
int x; /* init variable x which is kept is a stack frame */

/* reset the stack */
...

a= 10; /* init variable a which is kept in a stack frame */
b= 45; /* init variable b which is kept in a stack frame */
x= 67; /* init variable x which is kept is a stack frame */

/* remove ISR execution protection */
...

/* normal code */
...
}
But how do you know its not being optimized into the first routine?
Another issue:
Suppose when there are no variables on the stack and you have to
re-init it to be 0x1000.
Now that there are 3 variables you'll have to re-init it to 0x1000 - 3
* sizeof(int)
Everytime you add a variable you need to know if its going to end up on
the stack and adjust the stack init appropriately.
Thats another reason I like having the command_reciever be a supreme
ISR in asm: it can re-init the user space stack pointer every time to
0x1000 without worrying about what command_executer is going to do with
it.

rover8898 wrote:
Thank you both Samuel and Hubble.

Both are good solutions to my problem.
I like the setjmp.h's setjmp and longjmp instructions. They are what I
was initially looking for: a non-local goto.

However, looking at Samuel code made me realize that my code
architecture is wrong. Now: My command handling+exution is done outside
of an ISR. It uses as parameter the contents of the reception buffer.

What is should be: My command handling+exution should be in an ISR.
However it brings 2 questions to mind:
1. Will nested ISRs pose a problem ? I will have to pop the stack an
extra to void the previous command....
2. Will the fact that the ISR routine disables all interrupts upon
iwhen its commencement pose a problem?

Those are minor problems. I am certain I will be able to resolve them.
Thanks guys.

-Roger
Sep 24 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Rich | last post by:
I am trying to create a site that will re-direct a user based on their OS. For this site I will need to send NT4 and 95 users to site A and 2000/XP users to site B. All others should be directed...
13
by: Ben | last post by:
I have a program which is using a lot of memory. At the moment I store a lot of pointers to objects in std::vector. (millions of them) I have three questions: 1) Lets say the average Vector...
22
by: Rafia Tapia | last post by:
Hi all This is what I have in mind and I will appreciate any suggestions. I am trying to create a xml help system for my application. The schema of the xml file will be <helpsystem> <help...
2
by: Dickyb | last post by:
Extracting an Icon and Placing It On The Desktop (C# Language) I constructed a suite of programs in C++ several years ago that handle my financial portfolio, and now I have converted them to...
4
by: jao | last post by:
I'm using PostgreSQL 7.3.4 on RH9. Data and logs are on separate disks. (These are low-end IDE disks. That part of the problem is out of my control.) When a checkpoint occurs, all operations...
0
by: David Parker | last post by:
We are starting to ramp-up testing of our application, and we started getting these messages in our log file: LOG: checkpoints are occurring too frequently (15 seconds apart) HINT: Consider...
3
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here...
44
by: shuisheng | last post by:
Dear All, Assume there are three classes where CA has members of class CA1 and CA2 as follows. To make the public functions of CA1 and CA2 can work on the members a1 and a2 in a CA object, I...
2
by: abdiphp | last post by:
Hi every one, I need help to get the this going, Itried whatever I can but could not get the right xpath to this xml I need to get the value of this node (IMAGE_FILE) and this is not...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.