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.

IWR6843: Sending messages between threads with the Mailbox on the DSS

Part Number: IWR6843

I want to send messages between two threads running on the DSS using the mailbox. I think I am initializing the mailbox correctly, and writing to it correctly, but I can't read the correct value, so something is wrong! 

Here I initialize the Mailbox:

#include <ti/drivers/mailbox/mailbox.h>
#include <ti/drivers/mailbox/include/mailbox_internal.h>


/**
 * @brief
 *  Millimeter Wave Demo Data Path Information.
 *
 * @details
 *  The structure is used to hold all the relevant information for
 *  the data path.
 */
typedef struct Test_DataPathObj_t
{
    /*! @brief For notification to test task that the cdf processing is completed  */
    Mbox_Handle mboxHandle;

} Test_DataPathObj;

Test_DataPathObj gDataPathObj;


void Test_initComponents(Test_DataPathObj *dataPathObj)
{

    int32_t errCode;
    Mailbox_Config cfg;
    Mailbox_init(MAILBOX_TYPE_DSS);

    /* Setup the default Mailbox Parameters */
    if (Mailbox_Config_init(&cfg) < 0)
    {
        System_printf("Error: Unable to initialize configuration.\n");
        return;
    }

    /* Modify the default configuration as needed */
    cfg.writeMode = MAILBOX_MODE_POLLING;
    cfg.readMode = MAILBOX_MODE_POLLING;

    /* Open the Mailbox Instance to DSS */
    dataPathObj->mboxHandle = Mailbox_open(MAILBOX_TYPE_BSS, &cfg, &errCode);
    if (dataPathObj->mboxHandle == NULL || errCode != 0)
    {
        System_printf("Error: Unable to open the Mailbox Instance. Error=%d\n", errCode);
        return;
    }


}



I write to the mailbox in a separate task:

void computationTask(UArg arg0, UArg arg1)
{

    uint8_t signalValue; // Signal value to be sent
    int32_t size;


    /* Write the boolean value to the mailbox */
    signalValue = 1; 
    size = Mailbox_write(gDataPathObj.mboxHandle, (uint8_t*)&signalValue, sizeof(signalValue));
    if (size < 0)
    {
        System_printf("Error: Mailbox write failed with error %d\n", size);
    }
    else
    {
        System_printf("Signal sent via mailbox successfully.\n");
    }

    /* Clean up and stop the thread */
    Task_exit();
}


I read in a separate task:

void Test_task(UArg arg0, UArg arg1)
{
    int size;
    uint8_t receivedSignal;
    Mailbox_Stats stats;

    /* Attempt to read the signal value from the mailbox */
    while(1){

        receivedSignal = 0;
        System_printf("Entering Mailbox Read...\n");
        size = Mailbox_read(gDataPathObj.mboxHandle, &receivedSignal, sizeof(receivedSignal));
        System_printf("Read Answer: %d %d\n", size, receivedSignal);
        if (size < 0)
        {
            System_printf("Error: Mailbox read failed with error %d\n", size);
        }
        else if (receivedSignal)
        {
            System_printf("Received signal via the mailbox.\n");
            // Proceed with the task knowing the signal was received
            break;
        }
    }
    
    
    /* Close the Mailbox */
    Mailbox_close(gDataPathObj.mboxHandle);
    System_printf("Mailbox closed successfully.\n");

    
    /* Exit BIOS */
    BIOS_exit(0);


}

Here is where I init the tasks:


int main (void)
{
    Task_Params taskParams;
    Task_Params compTaskParams;
    int32_t     errCode;
    SOC_Cfg     socCfg;

    // Initialize test logger //
    MCPI_Initialize();

    Cycleprofiler_init();

    // Initialize the SOC configuration: //
    memset ((void *)&socCfg, 0, sizeof(SOC_Cfg));

    // Populate the SOC configuration: //
    socCfg.clockCfg = SOC_SysClock_INIT;

    // Initialize the SOC Module: This is done as soon as the application is started
    //to ensure that the MPU is correctly configured. //
    socHandle = SOC_init (&socCfg, &errCode);
    if (socHandle == NULL)
    {
        System_printf ("Error: SOC Module Initialization failed [Error code %d]\n", errCode);
        return -1;
    }

    // Initialize the Task Parameters. //
    Task_Params_init(&taskParams);
    taskParams.stackSize = 4*1024;//4*1024;
    taskParams.priority = 1; //Default
    Task_create(Test_task, &taskParams, NULL);


    /* Launch the Computation Task */
    Task_Params_init(&compTaskParams);
    compTaskParams.priority = 1;
    compTaskParams.stackSize = 2*1024;
    Task_create(computationTask, &compTaskParams, NULL);


    // Start BIOS //
    BIOS_start();

    return 0;
}

When I read, I always get that size = 0 and receivedSignal = 0...why? It looks like I am writing 1 to Mailbox_write, so I expect to get size = 1 and receivedSignal = 1.

Note when I force the issue:

void computationTask(UArg arg0, UArg arg1)
{

    ...

    uint32_t*         dataPtr;
    Mailbox_Driver*   driver;
    driver = (Mailbox_Driver*)(gDataPathObj.mboxHandle);
    dataPtr = (uint32_t *)((driver->hwCfg)->baseRemoteToLocal.data);


    uint32_t gTestPatternWord_0=100;
    uint32_t gTestPatternWord_1=200;
    uint32_t gTestPatternWord_2=600;

    memcpy ((void *)(&dataPtr[0]), (void *)&gTestPatternWord_0, sizeof(gTestPatternWord_0)); 
    memcpy ((void *)(&dataPtr[1]), (void *)&gTestPatternWord_1, sizeof(gTestPatternWord_1)); 
    memcpy ((void *)(&dataPtr[2]), (void *)&gTestPatternWord_2, sizeof(gTestPatternWord_2)); 
    
    ...
}


void Test_task(UArg arg0, UArg arg1)
{

...

        /*trigger a fake "mailbox full" interrupt from remote to local endpoint*/
        Mailbox_Driver*   driver;
        driver = (Mailbox_Driver*)(gDataPathObj.mboxHandle);
        ((driver->hwCfg)->baseRemoteToLocal.reg)->INT_TRIG = 0x1U;

...
}

then I can read 100, 200, 600 etc. Why doesn't Mailbox_write do the same thing? What am I missing?

  • Hello.

    Let me look into this and I will provide an update by the end of day tomorrow.

    Sincerely,

    Santosh

  • Thank you! I am looking forward to your reply.

  • Hello Alex.

    Thank you for your patience.  I am still looking into this and will provide an update by tomorrow.

    Sincerely,

    Santosh

  • Hello Alex.

    According to the documentation, the mailbox is intended for communication between the two cores as opposed to within the same cores.  However, it would make sense that this could be extended to two different tasks, although you could also just write to a section in memory that could be accessed by both tasks.  Please refer to the Mailbox Driver documentation in SDK 3.6 in <sdk-install-dir>/docs/mmwave_sdk_module_documentation.html.  From here you can navigate to the Mailbox driver documentation page.  In here there is an example for communicating between the MSS and DSS, though you could modify this so that you set it up to communicate within the DSS.  It looks like you are missing some steps in initializing the mailbox, so I would try that to see if it resolves your issue.

    Sincerely,

    Santosh