This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/TM4C1294NCPDT: Inter thread communication + Queue

Part Number: TM4C1294NCPDT

Tool/software: TI-RTOS

Hi,

I am trying to understand Ti RTOS and going through TI RTOS Workshop. I have few queries which i am trying to figure out.

1) For passing data from Hwi to either Swi or Task, only way is to use any one of the mechanisms as explained in chapter 9 of this workshop (inter thread communication) have to be used. If you do not want to use any of these mechanism, than only way is to use global; which is not recommended....... Pls correct me if i am wrong or let me have your comments for completeness of this understanding.

2) Structure defined for either using queue or mailbox, is global (as in lab 9). If the structure defined is already global, what benefit do we have (for the case of data to be passed is simple as 2 int, for example) using queue/mailbox over using directly same structure to pass information among different threads without using queue/mailbox ?

Please throw some light on this queries.

Thanks in advance.

Pranav.

  • Pranav,

    #1. That is correct. You should use one of the data constructs that TIRTOS has already defined.

    #2. The data constructs that TIRTOS provides like Queues, Semaphores and Mailboxes help prevent concurrent access and race conditions. If you simply have a global variable that more than 1 thread writes, how are you going to prevent concurrent access to it? Not saying it cannot be done but just be aware of the issues associated with writing a global variable in a RTOS environment.

    Judah
  • Dear Judah,

    Thanks for reply. That improved my understanding.

    Can you please confirm on one more doubt i have:

    Structure that we define for Queue/Mailbox, necessarily have to be defined as global, right ?



    Thanks and Regards.
    Pranav.
  • Pranav,

    They do not necessarily have to be defined as a global.  It depends on how you are using them, but generally you would want to define them as globals
    so you can use them across different threads.

    Judah

  • Thanks for reply.

    I would appreciate if you can point me some literature i can read to understand it thoroughly.

    Thanks and Best Regards,

    Pranav. 

  • Did you read the TI-RTOS Kernel (SYS/BIOS) User's Guide already? I would start there.
  • Hi,

    I have  gone through chapter queue of kernel UG, but it doent speak anything about structure definition....

    BR

    Pranav.

  • I'm not sure what to suggest for you. This is general RTOS information. Local variables are stored on the stack (task or system depending on your context). Global variables are stored in a particular memory section....(for example ".bss"). If you plan to share the queue/mailbox across different threads (like a task)....it cannot be stored on the stack as the stack would be "visible" only by one of the task....so it must be a global variable so that its "visible" to more than one thread. There is nothing wrong with using global variables from the app, in fact, its required in many cases.

    Now, its possible to have just a queue that is used just within a task...in such a case there would not be a need for it to be global. A local mailbox is less common as mailbox is generally used to share data across different threads.

    Queues are vary basic data structure....a double linked lists basically. It has a next and prev pointer. Typically you want to embed a queue at the top of your data structure so you can use the Queue APIs to insert/remove/delete etc...