I was trying to create a simple IPC example between DSP cores through MessageQ.
I wrote the code(Mainly taken from Image processing demo code) like this.
Master core:
#include <c6x.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <xdc/runtime/Error.h>
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/IHeap.h>
#include <ti/ipc/Ipc.h>
#include <ti/ipc/MessageQ.h>
#include <ti/ipc/HeapBufMP.h>
#include <ti/ipc/MultiProc.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <xdc/cfg/global.h>
#include "ti/platform/platform.h"
#include "ti/platform/resource_mgr.h"
#include "messageQ_try.h"
void messageQ_Master(UArg arg0, UArg arg1 );
char slave_queue_name[4][16];
int main(void)
{
//Task_Params taskParams;
System_printf ("**************************************************\n");
System_printf ("************ MessageQ Example: Master **************\n");
System_printf ("**************************************************\n");
/* Create the task for MessageSharing */
//Task_Params_init (&taskParams);
//taskParams.priority = 1;
//Task_create (messageQ_Master, &taskParams, NULL);
Task_Params taskParams;
Task_Handle task0;
Error_Block eb;
Error_init(&eb);
/* Create 1 task with priority 15 */
Task_Params_init(&taskParams);
taskParams.stackSize = 512;
taskParams.priority = 15;
task0 = Task_create((Task_FuncPtr)messageQ_Master, &taskParams, &eb);
if (task0 == NULL) {
System_abort("Task create failed");
}
int status;
/* Call Ipc_start() */
status = Ipc_start();
if (status < 0) {
System_abort("Ipc_start failed\n");
}
BIOS_start();
return (0);
}
process_message_t ** p_queue_msg = 0;
void messageQ_Master(UArg arg0, UArg arg1)
{
System_printf ("************ Inside the master task **************\n");
int number_of_cores = 4;
int msgId = 0;
int j = 0;
HeapBufMP_Handle heapHandle;
HeapBufMP_Params heapBufParams;
int status;
process_message_t *p_msg;
/* Create the heap that will be used to allocate messages. */
HeapBufMP_Params_init(&heapBufParams);
MessageQ_QueueId queue_id[4];
int i=0;
p_queue_msg = (process_message_t **) calloc(number_of_cores, sizeof(process_message_t *));
if (!p_queue_msg) {
printf("alloc_queue_message: Can't allocate memory for queue message\n");
return -1;
}
System_printf ("************ After heapinit **************\n");
heapBufParams.regionId = 0;
heapBufParams.name = MESSAGEQ_TRY_HEAP_NAME;
heapBufParams.numBlocks = 10;
heapBufParams.blockSize = sizeof(process_message_t);
heapHandle = HeapBufMP_create(&heapBufParams);
System_printf ("************ After heapCreate **************\n");
MessageQ_QueueId remoteQueueId;
if (heapHandle == NULL) {
System_printf("Main: HeapBufMP_create failed\n" );
}
/* Register this heap with MessageQ */
status = MessageQ_registerHeap((IHeap_Handle)heapHandle, MESSAGEQ_TRY_HEAPID);
if(status != MessageQ_S_SUCCESS) {
System_printf("Main: MessageQ_registerHeap failed\n" );
}
for (i = 0; i < number_of_cores; i++) {
p_queue_msg[i] = (process_message_t *) MessageQ_alloc(MESSAGEQ_TRY_HEAPID, sizeof(process_message_t));
if (!p_queue_msg[i]) {
printf("alloc_queue_message: Can't allocate memory for queue message %d\n", i);
return -1;
}
}
memset(slave_queue_name, 0, 4*16);
for (i = 0; i < number_of_cores; i++) {
GET_SLAVE_QUEUE_NAME(slave_queue_name[i], i);
}
System_printf ("****queue name= %s*******\n",slave_queue_name[0]);
System_printf ("************ waiting the messageQ to open**************\n");
for (j = 0; j < number_of_cores; j++) {
do {
i = MessageQ_open(slave_queue_name[j], &queue_id[j]);
} while (i < 0);
}
for (i = number_of_cores-1; i >= 0; i-- ) {
p_msg = p_queue_msg[i];
p_msg->count = i;
MessageQ_setMsgId(p_msg, ++msgId);
// MessageQ_setReplyQueue(h_receive_queue, (MessageQ_Msg)p_msg);
/* send the message to the remote processor */
if (MessageQ_put(queue_id[i], (MessageQ_Msg)p_msg) < 0) {
printf("MessageQ_put had a failure error\n");
}
}
}
Slave core:
#include <c6x.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/IHeap.h>
#include <ti/ipc/Ipc.h>
#include <ti/ipc/MessageQ.h>
#include <ti/ipc/HeapBufMP.h>
#include <ti/ipc/MultiProc.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <xdc/cfg/global.h>
#include "ti/platform/platform.h"
#include "ti/platform/resource_mgr.h"
#include "messageQ_try.h"
void messageQ_Slave(UArg arg0, UArg arg1);
int main(void)
{
// Task_Params taskParams;
System_printf ("**************************************************\n");
System_printf ("************ MessageQ Example: Slave **************\n");
System_printf ("**************************************************\n");
/* Create the task for MessageSharing */
// Task_Params_init (&taskParams);
// taskParams.priority = 1;
//Task_create (messageQ_Slave, &taskParams, NULL);
Task_Params taskParams;
Task_Handle task0;
Error_Block eb;
Error_init(&eb);
/* Create 1 task with priority 15 */
Task_Params_init(&taskParams);
taskParams.stackSize = 512;
taskParams.priority = 15;
task0 = Task_create((Task_FuncPtr)messageQ_Slave, &taskParams, &eb);
if (task0 == NULL) {
System_abort("Task create failed");
}
int status;
/* Call Ipc_start() */
status = Ipc_start();
if (status < 0) {
System_abort("Ipc_start failed\n");
}
BIOS_start();
return (0);
}
void messageQ_Slave(UArg arg0, UArg arg1)
{
char receive_queue_name[16];
GET_SLAVE_QUEUE_NAME(receive_queue_name, DNUM);
System_printf ("************ Inside the slave task **************\n");
process_message_t * p_msg = 0;
MessageQ_Handle h_receive_queue = 0;
System_printf ("***queue name =%s**************\n",receive_queue_name);
/* Create the local message queue */
h_receive_queue = MessageQ_create(receive_queue_name, NULL);
System_printf ("************ waiting on messageQ to RX data **************\n");
if (MessageQ_get(h_receive_queue, (MessageQ_Msg *)&p_msg, MessageQ_FOREVER) < 0) {
System_printf("%s: This should not happen since timeout is forever\n", receive_queue_name);
}
System_printf("Count sent by master is %d: \n", p_msg->count);
}
cfg file
/*
* Copyright 2009-2013 by Texas Instruments Incorporated.
*
* All rights reserved. Property of Texas Instruments Incorporated.
* Restricted rights to use, duplicate or disclose this code are
* granted through contract.
*
*/
/* THIS FILE WAS GENERATED BY ti.sysbios.genx */
/*
* ======== memory.cfg ========
*
*/
var Memory = xdc.useModule('xdc.runtime.Memory');
var BIOS = xdc.useModule('ti.sysbios.BIOS');
var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
var HeapBuf = xdc.useModule('ti.sysbios.heaps.HeapBuf');
var Task = xdc.useModule('ti.sysbios.knl.Task');
var Idle = xdc.useModule('ti.sysbios.knl.Idle');
var Log = xdc.useModule('xdc.runtime.Log');
var Diags = xdc.useModule('xdc.runtime.Diags');
var XdcText = xdc.useModule('xdc.runtime.Text');
XdcText.isLoaded = true;
var Exception =xdc.useModule('ti.sysbios.family.c64p.Exception');
Exception.enablePrint = true;
/* Load the CPPI package */
var Cppi = xdc.loadPackage('ti.drv.cppi');
/* Load the QMSS package */
var Qmss = xdc.loadPackage('ti.drv.qmss');
/* Load the RM package */
var Rm = xdc.loadPackage('ti.drv.rm');
/* Use the CSL module and indicate that INTC library will be used. */
var devType = "k2l";
var Csl = xdc.useModule('ti.csl.Settings');
Csl.deviceType = devType;
Csl.useCSLIntcLib = true;
var System = xdc.useModule('xdc.runtime.System');
var SysStd = xdc.useModule('xdc.runtime.SysStd');
System.SupportProxy = SysStd;
/* IPC packages */
var SharedRegion = xdc.useModule('ti.sdo.ipc.SharedRegion');
var MultiProc = xdc.useModule('ti.sdo.utils.MultiProc');
var Ipc = xdc.useModule('ti.sdo.ipc.Ipc');
var HeapBufMP = xdc.useModule('ti.sdo.ipc.heaps.HeapBufMP');
/* Create a default system heap using ti.bios.HeapMem. */
var heapMemParams1 = new HeapMem.Params;
heapMemParams1.size = 32768;
heapMemParams1.sectionName = "systemHeap";
Program.global.heap0 = HeapMem.create(heapMemParams1);
/* This is the default memory heap. */
Memory.defaultHeapInstance = Program.global.heap0;
Program.sectMap["systemHeap"] = Program.platform.stackMemory;
MultiProc.setConfig(null, ["CORE0", "CORE1", "CORE2", "CORE3"]);
/* Synchronize all processors (this will be done in Ipc_start) */
Ipc.procSync = Ipc.ProcSync_ALL;
SharedRegion.translate = false;
SharedRegion.setEntryMeta(0,
{ base: 0x0C000000,
len: 0x00008000,
ownerProcId: 0,
isValid: true,
name: "sharemem",
});
/* Create a default system heap using ti.bios.HeapMem. */
/*
var heapMemParams1 = new HeapMem.Params;
if (prog.build.target.name == "C28_large" ||
prog.build.target.name == "C28_float" ) {
heapMemParams1.size = 2048;
}
else {
heapMemParams1.size = 8192;
}
heapMemParams1.sectionName = "systemHeap";
Program.global.heap0 = HeapMem.create(heapMemParams1);
*/
/* Plug in systemheap as default heap to be used by Memory */
/* Memory.defaultHeapInstance = Program.global.heap0; */
var heapMemParams2 = new HeapMem.Params;
heapMemParams2.size = 16384;
heapMemParams2.align = 8;
heapMemParams2.sectionName = "cppiSharedHeap";
Program.global.cppiSharedHeap = HeapMem.create(heapMemParams2);
/* Place user sections */
/*
Program.sectMap["systemHeap"] = Program.platform.stackMemory;
Program.sectMap["task0Heap"] = Program.platform.dataMemory;
Program.sectMap["task1Heap"] = Program.platform.dataMemory;
Program.sectMap["task0Stack"] = Program.platform.stackMemory;
*/
/* Add idle function */
/*Idle.addFunc('&idl0Fxn');*/
/*
* @(#) ti.sysbios.genx; 2, 0, 0, 0,275; 4-29-2009 15:45:06; /db/vtree/library/trees/avala/avala-k25x/src/
*/
while running the code is giving run time errors
[C66xx_0] **************************************************
************ MessageQ Example: Master **************
**************************************************
[C66xx_2] **************************************************
************ MessageQ Example: Slave **************
**************************************************
[C66xx_1] **************************************************
[C66xx_3] **************************************************
[C66xx_1] ************ MessageQ Example: Slave **************
[C66xx_3] ************ MessageQ Example: Slave **************
[C66xx_1] **************************************************
[C66xx_3] **************************************************
************ Inside the slave task **************
***queue name =core3_queue**************
************ waiting on messageQ to RX data **************
9ƒxdc.runtime.Error.raise: terminating execution
[C66xx_1] ************ Inside the slave task **************
[C66xx_2] ************ Inside the slave task **************
[C66xx_1] ***queue name =core1_queue**************
[C66xx_2] ***queue name =core2_queue**************
[C66xx_1] ************ waiting on messageQ to RX data **************
[C66xx_2] ************ waiting on messageQ to RX data **************
[C66xx_1] 9ƒ[C66xx_2] 9ƒ[C66xx_1] xdc.runtime.Error.raise: terminating execution
[C66xx_2] xdc.runtime.Error.raise: terminating execution
[C66xx_0] ************ Inside the master task **************
Please suggest some solution
I am using the following tools
ccs_base_6.1.3.00033
xdais_7_24_00_04
pdk_k2l_4_0_1
ipc_3_42_00_02
processor_sdk_rtos_k2l_2_00_02_11
bios_6_45_01_29