This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Reentrant Functions

Hi I need to know if either of the functions defined below is set up the right way to make it reentrant. They are both delay functions that will be called more than once at the same time. I think there is something wrong here.
thank you!

static void delay2 (void) small reentrant {
unsigned long w;

for (w = 0; w < 10; w++) {
;
}
}

OR

static void delay1 (unsigned long w) small reentrant {
unsigned long a;

for (a = 0; a < w; a++) {
;
}
}

Parents
  • You've got the reentrant keyword in the declaration, and that's what counts.

    Do you have a reentrant stack set up and initialized in your STARTUP.A51?

    What sort of problems are you having with these functions?

    A delay loop is probably better programmed by looking at a timer register, or using NOP instructions for very short delays. Trying to code a specific delay with a for loop counter is going to lead to all sorts of tweaking, which will all go to waste the moment you change optimization levels or perhaps on the next compiler upgrade.

Reply
  • You've got the reentrant keyword in the declaration, and that's what counts.

    Do you have a reentrant stack set up and initialized in your STARTUP.A51?

    What sort of problems are you having with these functions?

    A delay loop is probably better programmed by looking at a timer register, or using NOP instructions for very short delays. Trying to code a specific delay with a for loop counter is going to lead to all sorts of tweaking, which will all go to waste the moment you change optimization levels or perhaps on the next compiler upgrade.

Children
  • Thanks Drew Davis. The problem I have is that at the beggining of my program there has to be a delay por instance 50 msec. But sometimes it takes up to a second for this short delay to be completely executed. I know this because an LED should go on and off with this delay. Now, I do not know if is this delay causing the problem or something else in the program, but this is the part I notice failing because it is the beginning of the program and after that everything works with a delay while processing (I mean takes longer) and it should not be that way...Is that clear to you?
    Thank you very much