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

RTX51 and function calls

Hi all,

This is my second message on the issue to clarify the question.

From the documentation:

****************
Standart C51 functions must not be called simultaneously from several tasks or interrupt procedures. These functions store their parameters and local data in static memory segments; for this reason, this data is overwritten by a repetitive call.

In order to solve this problem, C51 provides reentrant functions. ..... Since RTX51 Tiny does not contaion any management for the reentrant stack, the round robin task switching must be disabled when reentrant functions are used. RTX51 Tiny can manage reentrant functions in the compact model.
****************

In the light of these, can I use reentrant functions with task switching in the compact model?

If I cannot use task switching with reentrant function, where is the multi-tasking property of RTX51? If round-robin task switching disabled, is a task switching performed when an os_wait() function is executed?

regards,

Parents
  • Which version do you have?

    Here is the text from the latest manual (v2.95):

    It is not allowed to call non-reentrant C functions from several tasks or interrupt proce-dures.
    Non-reentrant C51 functions store their parameters and automatic variables (local data) in static memory segments; for this reason, this data is overwritten when multiple function calls occur simultaneously. Therefore non-reentrant C functions can only be call for several tasks, if the user can ensure that they are not called recursive. Usally this means that the Round-Robin task scheduling must be disabled and that such functions do not call any RTX51 Tiny system functions.
    C functions which are only using registers for parameter and automatic variables are in-herently reentrant and can be called without any restrictions from different RTX51 Tiny
    tasks.
    The C51 Compiler provides also reentrant functions. Refer to the C51 User's Manual for more information. Reentrant functions store their parameters and local data variables on
    a reentrant stack and the data are protected in this way against multiple calls. However, RTX51 Tiny does not contain any management for the C51 reentrant stack. If you are using reentrant functions in your application you must ensure that these functions do not call any RTX51 Tiny system functions and that reentrant functions are not interrupted by the Round-Robin task scheduling of RTX51 Tiny. The full version, RTX51 Full contains a stack management for reentrant functions.


    dunno if that makes it any clearer!?

Reply
  • Which version do you have?

    Here is the text from the latest manual (v2.95):

    It is not allowed to call non-reentrant C functions from several tasks or interrupt proce-dures.
    Non-reentrant C51 functions store their parameters and automatic variables (local data) in static memory segments; for this reason, this data is overwritten when multiple function calls occur simultaneously. Therefore non-reentrant C functions can only be call for several tasks, if the user can ensure that they are not called recursive. Usally this means that the Round-Robin task scheduling must be disabled and that such functions do not call any RTX51 Tiny system functions.
    C functions which are only using registers for parameter and automatic variables are in-herently reentrant and can be called without any restrictions from different RTX51 Tiny
    tasks.
    The C51 Compiler provides also reentrant functions. Refer to the C51 User's Manual for more information. Reentrant functions store their parameters and local data variables on
    a reentrant stack and the data are protected in this way against multiple calls. However, RTX51 Tiny does not contain any management for the C51 reentrant stack. If you are using reentrant functions in your application you must ensure that these functions do not call any RTX51 Tiny system functions and that reentrant functions are not interrupted by the Round-Robin task scheduling of RTX51 Tiny. The full version, RTX51 Full contains a stack management for reentrant functions.


    dunno if that makes it any clearer!?

Children
  • Thank you for your kind reply and quotation. Yes, the quotation clarified the issue.

    According to the text;

    1. We cannot use non-reentrant
    functions from several tasks. C
    functions which only uses registers
    for parameters are inherently
    reentrant.

    Then when task switching performed,
    registers are backed up to the
    system. Is this true?

    Then how can I define a variable in
    register? I tried "register data
    int..", but this did not work.

    2. When using reentrant functions, task
    switching should be disabled (for
    tiny).

    Then where are the benefits of using
    RTX51?

    Cannot I use functions and RTX51 tiny
    together?

    Thanks for reading...

  • Then where are the benefits of using RTX51?

    Cannot I use functions and RTX51 tiny together?


    The only problem comes when you have a function that is called from more than 1 task.

    The problem is that since arguments and locals are stored in fixed memory locations, functions are no reentrant (by default).

    If you need reentrant functions, declare them as follows:

    int function (arg_list) compact reentrant
    {
    }
    

    Then, you may call them from multiple tasks.

    Jon

  • Dear Ward,

    Following is a quotation from Andrew's mail:

    *****************
    calls. However, RTX51 Tiny does not contain any management for the C51 reentrant stack. If you are using reentrant functions in your application you must ensure that these functions do not call any RTX51 Tiny system functions and that reentrant functions are not interrupted by the Round-Robin task scheduling of RTX51 Tiny. The full version, RTX51 Full contains a stack management for reentrant functions.
    *******************

    According to this, even with reentrant functions you CANNOT use task switching.

    In fact I have a PID routine which calculates and acts properly in an *infinite loop*.

    I want to call this function for different channels from 8 different task. This way, I can manage 8 different channels using a single PID routine.

    But the manuel says that I cannot use functions with task switching enabled.

    Am I wrong?