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?