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.

Reference statically created mailboxes parameters in the C code.

Can I access the mailbox size of a statically created mailbox in the C code? I found a similar question linked below but it didn’t quite answer the question.

http://e2e.ti.com/support/embedded/tirtos/f/355/p/273360/954827.aspx#954827

 

For example, if I statically create a mailbox, the cfg file may have an entry like the line below.

Program.global.cmd_mbx = Mailbox.create(8, 4, mailbox0Params);

In the C source, can I access the mailbox “size of messages” and “max number of messages” in the C code? In this case, the size would be 8 and the max number of messages would be 4.

  • For the size, there is the following API

    Int Mailbox_getNumFreeMsgs(Mailbox_Object *obj)

    The count is not as clear. There are two APIs that return the information you need.

    Int Mailbox_getNumPendingMsgs(Mailbox_Object *obj)
    Int Mailbox_getNumFreeMsgs(Mailbox_Object *obj)

    These two added together will give you the total number of buffers. I'd disable interrupts around the two calls to make sure you get the accurate number. If not, you could get the first value, get swapped out by a higher priority thread that is going to pend or post to the same Mailbox. So when you get the second value, their sum does not equal the total count.

    Another option in the .cfg is to set the values to a global. For example:

    Program.global.MAILBOX_XXX_COUNT = 4;
    Program.global.MAILBOX_XXX_SIZE = 8;
    Program.global.cmd_mbx = Mailbox.create(Program.global.MAILBOX_XXX_SIZE, Program.global.MAILBOX_XXX_COUNT, mailbox0Params);

    Then in the .c file, if you have the following header, you can use the constants MAILBOX_XXX_COUNT and MAILBOX_XXX_SIZE:

    #include <xdc/cfg/global.h>

    The defines for these two constants will be in the generated header file in Debug\configPkg\cfg\<name of .cfg file>_p<target>.h.

    Todd