I am trying to do bidirectional IPC between core 0 and core 1 using MessageQ. To do this I am creating 2 IPC at the same time one that is 0->1 and one that is 1->0. (NOTE: I will eventually want to create about 4 simultaneous IPC but need to get 2 working first!)
Both 0->1 and 1->0 allocate correctly but it fails at the first call to MessageQ_put() on core 0 with the abort() error
ti.sdo.ipc.transports.TransportShm: line 388: assertion failure: A_regionInvalid: Region is invalid
My CFG file is very similar to the Image Processing demo. I create different .OUT for the different cores. The MSMC is divided into 3 partitions, one for Core 0, one for Core 1, and one for IPC. Both CFG have sections like
/* Shared Memory base address and length */
var SHAREDMEM = 0x0c200000;
var SHAREDMEMSIZE = 0x00200000;
SharedRegion.setEntryMeta(0,
{ base: SHAREDMEM,
len: SHAREDMEMSIZE,
ownerProcId: 0,
isValid: true,
name: "MSMCSRAM_IPC",
});
Both MessageQ_alloc() correctly return an address in the 0x0c200000 region.
The Heap is created on core 0 as
/*
* Create the heap that will be used to allocate messages.
*/
HeapBufMP_Params_init(&heapBufParams);
heapBufParams.regionId = 0;
heapBufParams.name = "MSMCSRAM_IPC";
heapBufParams.numBlocks = 20;
heapBufParams.blockSize = sizeof(MessageQ_MsgHeader)+64;
heapHandle = HeapBufMP_create(&heapBufParams);
if (heapHandle == NULL) {
System_abort("HeapBufMP_create failed\n" );
} else {
printf("%i: Heap %s created\n",0,heapBufParams.name);
}
/* Register this heap with MessageQ */
MessageQ_registerHeap((IHeap_Handle)heapHandle, 0);
printf("%i: Heap registered\n",0);
Core 0's functions to open and write to the port are
#define MAX_MSG 64
static void *openControlPort(void *pdv, int size) {
ProcHandle pd = pdv;
Port p = calloc(1,sizeof(PortRec));
int status;
char port_name[32];
if (!size) size = MAX_MSG;
if (size > MAX_MSG) size = MAX_MSG;
sprintf(port_name,"controls%d",pd->unique);
printf("%i: MessageQ_open %s\n",0,port_name);
do {
status = MessageQ_open(port_name,&p->sqid);
} while (status < 0);
printf("%i: MessageQ_alloc %s\n",0,port_name);
p->smsg = (MessageQ_Msg *)MessageQ_alloc(0,32+size); /* header is 32 bytes */
sprintf(port_name,"controlr%d",pd->unique);
printf("%i: MessageQ_create %s %p\n",0,port_name,p->smsg);
p->rhandle = MessageQ_create(port_name,NULL);
p->rmsg = malloc(32+size);
printf("%i: done openControlPort\n",0);
return p; }
static void writeAll(void *pp, void *vbuf, int bytes) {
Port p = pp;
int offset = 0;
while (bytes > 0) {
int wbytes = bytes > MAX_MSG ? MAX_MSG : bytes;
printf("writeAll %d\n",wbytes);
memcpy((char *)p->smsg + 32,(char *)vbuf+offset,wbytes);
while (MessageQ_put(p->sqid,*p->smsg) != MessageQ_S_SUCCESS) printf("ack!\n");
bytes -= wbytes;
offset += wbytes;
}
}
Core 1's functions to open the port is
void *embOpenControlPort(int size) {
HostConnection p = calloc( 1, sizeof(HostConnectionRec));
int status;
char port_name[32];
if (!size) size = MAX_MSG;
if (size > MAX_MSG) size = MAX_MSG;
sprintf(port_name,"controls%d",embId());
printf("%i: MessageQ_create %s %d\n",(int)DNUM,port_name,size);
p->shandle = MessageQ_create(port_name,NULL);
p->smsg = malloc(32+size);
sprintf(port_name,"controlr%d",embId());
printf("%i: MessageQ_open %s\n",(int)DNUM,port_name);
do {
status = MessageQ_open(port_name,&p->rqid);
} while (status < 0);
printf("%i: MessageQ_alloc %s\n",(int)DNUM,port_name);
p->rmsg = (MessageQ_Msg *)MessageQ_alloc(0,32+size); /* header is 32 bytes */
printf("%i: done embOpenControlPort %p\n",(int)DNUM,p->rmsg);
return p;
}