DS80C400 reentrant multi tasking function calls with Keil compiler

DevUpdate <[email protected]>
Newsgroups gmane.comp.hardware.microcontrollers.tini
Organization Cyanica
Message-ID <[email protected]>
Thanks for the feedback so far, but on reflection, my previous post on 
reentrant functions was far from clear! So I've shortened it and 
hopefully it will be more concise.

Am I correct in thinking that the "reentrant" keyword allows a function 
to use the reentrant stack which "allows recursive function calls and 
for multiple processes to call a single function simultaneously" (quoted 
text from current Dallas startup400.a51 file)?  I have demonstrated, 
that a reentrant function called recursively  executes correctly.

I have also demonstrated that without the reentrant keyword, recursive 
calls do not work (as you would expect in the Keil environment).  The 
compiler helpfully raises a warning (C265) in this situation informing 
you of the danger of making a dodgy recursive call.

Thus I have seen that recursive calls to reentrant functions behave as 
expected, but when I try to demonstrate "..multiple processes to call a 
single function simultaneously" I find that a function's local variables 
are interfered with by separate tasks.  This would be illustrated in the 
following code fragment.

I would HOPE to see main create two tasks and that EACH task would *** 
DO SOMETHING *** 10 times.  Eg 20 times in total (MAX_COUNT * 
NUM_TASKS).  However I have experienced that each task will increment 
"counter" and hence *** DO SOMETHING *** will be executed only 10 times. 

Do I simply misunderstand reentrant functions or is my intended 
behaviour possible?

Thanks for you patience!

Richard

#define MAX_COUNT 10
#define NUM_TASKS 2

void foo() reentrant
{
    int counter;
    counter = 0;
    while(counter++ < MAX_COUNT)
    {
       // *** DO SOMETHING ***
    }
    // Tidy up after task
}

void main()
{
    // Var def & setup...

    // Create two tasks

    for (i=0;i<NUM_TASKS ;i++)
    {

        task_entercritsection();   // make sure we don't task swap 
before we can get the result out
        result = task_fork(NORM_PRIORITY, ROM_SAVESIZE);
  
        // Usually check for error code 0xFFFF

        // result is 0 for the child process, else it is the child PID

        if (result==0)
        {
            // This is the stuff that happens in the task just generated 
by the fork call
            foo();
        }
        else
        {
          // This is the parent task
          task_leavecritsection();
        }
    }  
    while(1)
    {
    } 
}

_______________________________________________
TINI mailing list
TINI-6tN4nzCoH/[email protected]
To UNSUBSCRIBE, edit your profile, or see list archives:
http://lists.dalsemi.com/mailman/listinfo/tini
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.