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.

TMS320F28374S: Can I post to a mailbox then pend on that mailbox in the same context?

Part Number: TMS320F28374S


Hello,

I have a task that I'm using for some communication scheduling, and I was wondering if it was possible to do a Mailbox_post() and a Mailbox_pend() in the same task for an initialization. I was trying something like the code listed below and I've been getting errors in the data listed in the Mailbox pointer:

typedef struct 
{
	int id;
	char firstname[25];
	char lastname[25];
} MY_MAILBOX_STRUCT;

/*---------------------------------------------------------------------------*/
/** @brief A Task for Scheduling Messages
 * This task pends on messages being posted into it's mailbox
 *//*------------------------------------------------------------------------*/
void someTask(void)
{
	void* msgPtr;
	MY_MAILBOX_STRUCT *MbxPtr;
	
    MY_MAILBOX_STRUCT mbx = 
	{
		10, "HELLO", "WORLD"
	}
		
    Mailbox_post(someMailbox, (void*)&mbx, BIOS_NO_WAIT);

    while(true)
    {
		Mailbox_pend(someMailbox, msgPtr, BIOS_WAIT_FOREVER);
		MbxPtr = (MY_MAILBOX_STRUCT*)msgPtr;
		
		//Do whatever work with the newMbxPtr I have
    }
}

Thank you for any help!

  • I wouldn't think there would be a problem with that. When you say you are seeing errors, you mean the data is not the expected value?

    If you look at the return values of the post and pend functions, are they as expected?

    Whitney

  • Thank you for your response Whitney Smile

    So slight typo that I needed to correct: I'm trying to post to and then pend on the same mailbox. Before my edit there were different mailbox names but I corrected the code.

    The returns from the pend and post functions are both true and I can see that the message was placed into the Mailbox and pulled back out. The problem is when I cast the 'void*' msgPtr to a 'MY_MAILBOX_STRUCT*' none of the fields are correct it's like there's garbage data being pulled out of the Mailbox or something. If I keep this code the same but I have a separate, lower priority task perform the first Mailbox_post() then everything works fine and I'm not to sure why. I have the same problem when I set that separate task as a higher priority. It's as if the Mailbox needs to be pending before any messages are posted to it. Is that how the Mailbox system is supposed to work?

    Again thank you for answering and sorry for all the questions this is pretty new to me Sweat smile

  • Do you mind sharing how your Mailbox is configured? In your config file or dynamically? What parameters?

    I went searching for some examples and found these. I tried out that first project and it worked fine. Even when I added a task sleep to make sure the post happened before the pend or moved both loops into a single task, the printed results were still okay, so I don't think there's anything wrong with either order.

    Are you seeing any errors in ROV?

    Whitney

  • I don't mind sharing at all! And I was viewing the data in the expressions window of CCS while debugging. I configure the mailbox in the config file, here's what that looks like:

    /*
     * Mailboxes
     */
    var i2cManagerMailboxParams = new Mailbox.Params();
    i2cManagerMailboxParams.instance.name = "i2cManagerMailbox";
    Program.global.i2cManagerMailbox = Mailbox.create(24, 100, i2cManagerMailboxParams);

    Let me know if you need anything else!

  • Also when I went to use ROV for the first time I had this error:

    Error: Failed to start ROV using 'comm=DSLite,wsPort=58820':InternalError: Can't find method xdc.rta.Formatter.setOFReader(org.mozilla.javascript.Undefined). (C:/ti/ccs1020/xdctools_3_62_00_08_core/packages/xdc/rov/Model.xs#315)

    Could be a separate issue but I figured I should mention it. Thank you again Whitney!

  • Why the message size 24 in your Mailbox.create? Isn't MY_MAILBOX_STRUCT at least 51?

    Whitney

  • Oh, sorry. When I asked my question I was using some generic Mailbox Object Struct to give an idea of what I was doing. What I'm actually using all of this for is a way to schedule I2C Messages. When I did a sizeof on the I2C_Mailbox_Struct I have, the value came out to 12. I doubled that value to be safe. Here's how my actual Mailbox Struct looks:

    typedef struct
    {
        I2CM_TRANSACTION_ID transactionID;
        volatile I2C_MESSAGE_STRUCT *msg;
        int16_dtc messageCount;
        I2C_SETTINGS_STRUCT *settings;
        I2C_DEVICE_ID deviceID;
        void *i2cDevice;
    }I2C_MAILBOX_STRUCT;

    I didn't know if all of those details were relevant because I have things working from when I call a Mailbox_post() after a Mailbox_pend() has started. I can give you all the specifics if you need it though. I apologize for the confusion.

  • Not sure what could be going on with your ROV, but it would be nice to have that working. Do you get errors with both the Classic ROV and the regular one (assuming you're using a version of CCS that has both)?

    Can you try putting a breakpoint on the Mailbox_pend() and single stepping through it and making sure everything looks okay? I'm particularly wondering about the parameters to the memcpy. If it's hard to step through, you can change your SYS/BIOS runtime options to do a custom build where you can change the optimization compiler option to -o0 or -ooff

    Whitney

  • Hey Whitney I found my issue.

    I had 2 Problems:

    The 1st one being that the I2C_MAILBOX_STRUCT I made wasn't packed properly so I had memory alignment issues. I rearranged my struct as follows to fix that problem:

    typedef struct
    {
        void *i2cDevice;
        volatile I2C_MESSAGE_STRUCT *msg;
        I2C_SETTINGS_STRUCT *settings;
        I2CM_TRANSACTION_ID transactionID;
        I2C_DEVICE_ID deviceID;
        int16_dtc messageCount;
    }I2C_MAILBOX_STRUCT;

    Put the 2 Word Variables First and the 1 Word Variables after.

    The 2nd Problem is I had variables going out of context. I put up a general version of my code, but I was actually doing a Mailbox_post() from a separate function that was in the same file scope of the Mailbox Task. Inside that local function, I made local variables that went into my Mailbox Struct, which would've been ok if I didn't create a new I2C_MESSAGE_STRUCT inside of the local function and only passed the Pointer to that I2C_MAILBOX_STRUCT. I only copied a pointer, which when the local function ended, would point to nothing, like it's supposed to, cause that's how local variables work Sweat smile. That was something I should've caught so I'm sorry about that.

    I thank you for the help though you've been wonderful and now I know about the ROV so that's something else I can use! Thank you again I really appreciate the help!