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.

Mailbox question.

Hello,

I'm working with CSS5, bios_5_41_10_38 and C6748.

I have two task with the same priority, created in DSP/BIOS statically:

  • Mailbox reader task.
  • Mailbox writer task.
Reader task is pending on a mailbox.
Writer task is posting a message into a mailbox.
I set fixed length of the mailbox buffer to 100.
I expect the reader task to execute since there's at least one element in the mailbox,
but instead the writer task runs till the mailbox is full, and only then the reader task continues to execute till the mailbox is empty.
If I set the priority of the reader's task to higher than the writer task has, the reader will preempt the writer right after writer has written one element to the mailbox. Then, the reader will block again. This creates a situation the elements are being enqueued and dequeued one by one.
What I need is the producer/consumer concept, when the consumer (reader task) runs independently from the producer (writer task), and the consumer doesn't block until the buffer is full, but both tasks run simultaneously. How can I achieve this effect with mailbox?
  • Anatoly,

    The behavior you describe is as expected for mailboxes.  The pend and post operations relate to individual messages being available or not, and not to *all* messages that the mailbox could hold.

    If you want to signal a reader task when the writer has filled the mailbox, you could explicitly create a semaphore for this purpose to signal “full”.  You’d need to then keep track of the number of messages to write before signaling full, and then to read when emptying the mailbox. 

    If you don’t want to explicitly track or define the number of messages that indicate “full”, I guess you could call MBX_pend() and MBX_post() with timeouts of zero, and be sure to check the return values of these calls to know if an individual message was really written or read successfully.  For example, the writer could post messages until MBX_post() returns FALSE indicating the mailbox is full, and then the writer posts the “full” semaphore.  And then the reader could call MBX_pend() to read messages, until a FALSE value is returned indicating the mailbox is empty.  I think this should work too.

    Scott

  • By adding a CLK object that periodically invokes TSK_yield(), you can effectively achieve time slicing among tasks of the same priority.

    tcf configuration code:

        clk_slice = bios.CLK.create("clk_slice");
        clk_slice.fxn = prog.extern("clk_fxn");

    C code:

        /* periodically call TSK_yield() */
        Void clk_fxn(Void)
        {
            TSK_yield();
        }

    If you want to times slice less often than on every CLK tick, you can use a PRD object configured with a longer period instead.

    Alan

  • Thank you for information.