diff --git a/host_bios/simple_buffer_example/host/App.c b/host_bios/simple_buffer_example/host/App.c
index 3cac50b19cc4a5cbcd79fac07e8f575ed739239f..b6c302de23bd08c88ee07a1e4b25eb091a8526e1 100644 (file)
#define ROUNDUP(size, align) \
(UInt32)(((UInt32)(size) + ((UInt32)(align) - 1)) & ~((UInt32)(align) - 1))
#define ROUNDUP(size, align) \
(UInt32)(((UInt32)(size) + ((UInt32)(align) - 1)) & ~((UInt32)(align) - 1))
-#define NUM_MSGS 4
+#define MAX_NUM_MSGS 4
/* module structure */
typedef struct {
/* module structure */
typedef struct {
/* private data */
static App_Module Module;
/* private data */
static App_Module Module;
-
/*
* ======== App_create ========
*/
/*
* ======== App_create ========
*/
Module.msgSize = ROUNDUP(sizeof(App_Msg), align);
/* compute message pool size */
Module.msgSize = ROUNDUP(sizeof(App_Msg), align);
/* compute message pool size */
- Module.poolSize = Module.msgSize * NUM_MSGS;
+ Module.poolSize = Module.msgSize * MAX_NUM_MSGS;
/* acquire message pool memory */
srHeap = (IHeap_Handle)SharedRegion_getHeap(0);
/* acquire message pool memory */
srHeap = (IHeap_Handle)SharedRegion_getHeap(0);
/* create a heap in shared memory for message pool */
HeapBuf_Params_init(&heapParams);
heapParams.blockSize = Module.msgSize;
/* create a heap in shared memory for message pool */
HeapBuf_Params_init(&heapParams);
heapParams.blockSize = Module.msgSize;
- heapParams.numBlocks = NUM_MSGS;
+ heapParams.numBlocks = MAX_NUM_MSGS;
heapParams.bufSize = Module.poolSize;
heapParams.align = align;
heapParams.buf = Module.store;
heapParams.bufSize = Module.poolSize;
heapParams.align = align;
heapParams.buf = Module.store;
return(status);
}
return(status);
}
-
/*
* ======== App_delete ========
*/
/*
* ======== App_delete ========
*/
return(status);
}
return(status);
}
-
/*
* ======== App_exec ========
*/
/*
* ======== App_exec ========
*/
{
Int status;
App_Msg * msg;
{
Int status;
App_Msg * msg;
- Uint32 *bigDataPtr;
- SharedRegion_SRPtr bigDataSharedPtr;
- Int16 i,j;
+ UInt32 *bigDataLocalPtr;
+ Int i,j;
UInt16 regionId1;
Memory_Stats stats;
HeapMemMP_ExtendedStats extStats;
SharedRegion_Entry *pSrEntry;
HeapMemMP_Params heapMemMp_params;
HeapMemMP_Handle sr1Heap;
UInt16 regionId1;
Memory_Stats stats;
HeapMemMP_ExtendedStats extStats;
SharedRegion_Entry *pSrEntry;
HeapMemMP_Params heapMemMp_params;
HeapMemMP_Handle sr1Heap;
- Uint16 regionId;
+ UInt16 regionId;
HeapMemMP_Handle srHeap;
UInt32 errorCount=0;
HeapMemMP_Handle srHeap;
UInt32 errorCount=0;
-
+ Int retVal;
+ bigDataLocalDesc_t bigDataLocalDesc;
+
Log_print0(Diags_INFO, "App_exec: -->");
Log_print0(Diags_INFO, "App_exec: -->");
- // obtain information about heap (if any) in SR_1
+ /* obtain information about heap (if any) in SR_1 */
regionId1 = SharedRegion_getIdByName("SR_1");
Log_print1(Diags_INFO, "App_taskFxn: SR_1 region Id=%d",regionId1);
sr1Heap = SharedRegion_getHeap(regionId1);
if (sr1Heap != NULL)
{
regionId1 = SharedRegion_getIdByName("SR_1");
Log_print1(Diags_INFO, "App_taskFxn: SR_1 region Id=%d",regionId1);
sr1Heap = SharedRegion_getHeap(regionId1);
if (sr1Heap != NULL)
{
- /* SR has predefined heap */
- HeapMemMP_getStats((HeapMemMP_Handle)sr1Heap, &stats);
- Log_print3(Diags_INFO, "App_taskFxn: SR_1 heap, totalSize=%d,totalFreeSize=%d,largestFreeSize=%d", (IArg)stats.totalSize, (IArg)stats.totalFreeSize, (IArg)stats.largestFreeSize);
- HeapMemMP_getExtendedStats((HeapMemMP_Handle)sr1Heap, &extStats);
- Log_print2(Diags_INFO, "App_taskFxn: SR_1 heap, buf=0x%x,size=%d", (IArg)extStats.buf, (IArg)extStats.size);
Log_error0("App_taskFxn: Error: Example assumes shared region without preconfigured heap");
status = -1;
goto leave;
Log_error0("App_taskFxn: Error: Example assumes shared region without preconfigured heap");
status = -1;
goto leave;
pSrEntry = SharedRegion_getEntryPtr(regionId1);
Log_print1(Diags_INFO, "App_taskFxn: SR_1, len=%d", pSrEntry->len);
pSrEntry = SharedRegion_getEntryPtr(regionId1);
Log_print1(Diags_INFO, "App_taskFxn: SR_1, len=%d", pSrEntry->len);
- // Create HeapMP at run-time
+ /* Create HeapMP at run-time:
+ This heap is intended to be used for big data ipc */
HeapMemMP_Params_init(&heapMemMp_params);
heapMemMp_params.name = "sr1HeapMemMp";
heapMemMp_params.sharedAddr = pSrEntry->base;
HeapMemMP_Params_init(&heapMemMp_params);
heapMemMp_params.name = "sr1HeapMemMp";
heapMemMp_params.sharedAddr = pSrEntry->base;
MessageQ_setReplyQueue(Module.hostQue, (MessageQ_Msg)msg);
if ( i == 1) {
MessageQ_setReplyQueue(Module.hostQue, (MessageQ_Msg)msg);
if ( i == 1) {
- /* fill in message payload */
+ /* fill in message payload for Shared region init*/
msg->cmd = App_CMD_SHARED_REGION_INIT;
msg->id = i;
msg->regionId = regionId;
msg->cmd = App_CMD_SHARED_REGION_INIT;
msg->id = i;
msg->regionId = regionId;
}
/* process steady state (keep pipeline full) */
}
/* process steady state (keep pipeline full) */
- for (i = 4; i <= 18; i++) {
+ for (i = 4; i <= 16; i++) {
+
+ /* Now this section of code starts receiving messages
+ See the next section for the code for sending further messages */
+ /* Receive messages: Start <======================================= */
/* wait for return message */
status = MessageQ_get(Module.hostQue, (MessageQ_Msg *)&msg,
/* wait for return message */
status = MessageQ_get(Module.hostQue, (MessageQ_Msg *)&msg,
/* extract message payload */
/* extract message payload */
- if ((msg->cmd == App_CMD_BIGDATA) && (msg->u.bigDataBuffer.sharedPtr) ) {
+ if (msg->cmd == App_CMD_BIGDATA) {
- /* Translate to local address */
- bigDataPtr = (Uint32 *)SharedRegion_getPtr(msg->u.bigDataBuffer.sharedPtr);
-
- /* If shared region is configured for cache enabled do cache operation */
- if (SharedRegion_isCacheEnabled(msg->regionId)) {
- Cache_inv(bigDataPtr,
- msg->u.bigDataBuffer.size, Cache_Type_ALL, TRUE);
+ retVal = bigDataXlatetoLocalAndSync(msg->regionId,
+ &msg->u.bigDataSharedDesc, &bigDataLocalDesc);
+ if (retVal) {
+ status = -1;
+ goto leave;
}
}
+ bigDataLocalPtr = (UInt32 *)bigDataLocalDesc.localPtr;
#ifdef DEBUG
/* print data from big data buffer */
Log_print1(Diags_INFO, " Received back buffer %d", msg->id);
Log_print0(Diags_INFO, " First 8 bytes: ");
#ifdef DEBUG
/* print data from big data buffer */
Log_print1(Diags_INFO, " Received back buffer %d", msg->id);
Log_print0(Diags_INFO, " First 8 bytes: ");
- for ( j = 0; j < 8 && j < msg->u.bigDataBuffer.size/sizeof(uint32_t); j+=4)
+ for ( j = 0; j < 8 && j < bigDataLocalDesc.size/sizeof(uint32_t); j+=4)
Log_print4(Diags_INFO, "0x%x, 0x%x, 0x%x, 0x%x",
Log_print4(Diags_INFO, "0x%x, 0x%x, 0x%x, 0x%x",
- bigDataPtr[j], bigDataPtr[j+1], bigDataPtr[j+2], bigDataPtr[j+3]);
+ bigDataLocalPtr[j], bigDataLocalPtr[j+1], bigDataLocalPtr[j+2], bigDataLocalPtr[j+3]);
Log_print0(Diags_INFO, " Last 8 bytes: ");
Log_print0(Diags_INFO, " Last 8 bytes: ");
- for ( j = (msg->u.bigDataBuffer.size/sizeof(uint32_t))-8 ;
- j < msg->u.bigDataBuffer.size/sizeof(uint32_t); j+=4)
+ for ( j = (bigDataLocalDesc.size/sizeof(uint32_t))-8 ;
+ j < bigDataLocalDesc.size/sizeof(uint32_t); j+=4)
Log_print4(Diags_INFO, "0x%x, 0x%x, 0x%x, 0x%x",
Log_print4(Diags_INFO, "0x%x, 0x%x, 0x%x, 0x%x",
- bigDataPtr[j], bigDataPtr[j+1], bigDataPtr[j+2], bigDataPtr[j+3]);
+ bigDataLocalPtr[j], bigDataLocalPtr[j+1], bigDataLocalPtr[j+2], bigDataLocalPtr[j+3]);
#endif
/* Check values to see expected results */
#endif
/* Check values to see expected results */
- for( j=0; j < msg->u.bigDataBuffer.size/sizeof(uint32_t); j++) {
- if ( bigDataPtr[j] != (msg->id+10+j) ) {
+ for( j=0; j < bigDataLocalDesc.size/sizeof(uint32_t); j++) {
+ if ( bigDataLocalPtr[j] != (msg->id+10+j) ) {
errorCount++;
}
}
/* Free big data buffer */
errorCount++;
}
}
/* Free big data buffer */
- HeapMemMP_free(srHeap, bigDataPtr, msg->u.bigDataBuffer.size);
+ HeapMemMP_free(srHeap, bigDataLocalPtr, bigDataLocalDesc.size);
}
/* free the message */
}
/* free the message */
Log_print1(Diags_INFO, "App_exec: message received, sending message %d",
(IArg)i);
Log_print1(Diags_INFO, "App_exec: message received, sending message %d",
(IArg)i);
+ /* Receive messages: End =======================================> */
+
+ /* Send messages: Start <======================================= */
/* allocate message */
msg = (App_Msg *)MessageQ_alloc(Module.heapId, Module.msgSize);
/* allocate message */
msg = (App_Msg *)MessageQ_alloc(Module.heapId, Module.msgSize);
MessageQ_setReplyQueue(Module.hostQue, (MessageQ_Msg)msg);
/* fill in message payload */
MessageQ_setReplyQueue(Module.hostQue, (MessageQ_Msg)msg);
/* fill in message payload */
- if (i == 18) {
- /* Last message will tell the slave to shutdown */
- msg->cmd = App_CMD_SHUTDOWN;
- msg->id = i;
- } else if (i < 15) {
+ if (i < 14) {
+
+ /* Send Big data messages */
+
msg->cmd = App_CMD_BIGDATA;
msg->id = i;
/* Allocate buffer from HeapMemMP */
msg->cmd = App_CMD_BIGDATA;
msg->id = i;
/* Allocate buffer from HeapMemMP */
- bigDataPtr = (Uint32 *)(HeapMemMP_alloc(srHeap, BIGDATA_SIZE, BIGDATA_ALIGN));
+ bigDataLocalPtr = (UInt32 *)(HeapMemMP_alloc(srHeap, BIGDATA_BUF_SIZE, BIGDATA_ALIGN));
- if ( ! bigDataPtr ) {
+ if (!bigDataLocalPtr) {
status = -1;
goto leave;
}
/* Fill Big data buffer */
status = -1;
goto leave;
}
/* Fill Big data buffer */
- for(j=0; j< BIGDATA_SIZE/sizeof(uint32_t); j++) {
- bigDataPtr[j] = j+i;
- }
-
- /* Cache write back data buffer */
- if (SharedRegion_isCacheEnabled(regionId)) {
- Cache_wb(bigDataPtr, BIGDATA_SIZE, Cache_Type_ALL, TRUE);
+ for(j=0; j< BIGDATA_BUF_SIZE/sizeof(uint32_t); j++) {
+ bigDataLocalPtr[j] = j+i;
}
}
- /* Translate Address to Shared address */
- bigDataSharedPtr = SharedRegion_getSRPtr(bigDataPtr, regionId);
+ /* Populate the Local descriptor */
+ bigDataLocalDesc.localPtr = (Ptr)bigDataLocalPtr;
+ bigDataLocalDesc.size = BIGDATA_BUF_SIZE;
- msg->u.bigDataBuffer.sharedPtr = bigDataSharedPtr;
- msg->u.bigDataBuffer.size = BIGDATA_SIZE;
+ retVal = bigDataXlatetoGlobalAndSync(regionId,
+ &bigDataLocalDesc, &msg->u.bigDataSharedDesc);
+ if (retVal) {
+ status = -1;
+ goto leave;
+ }
msg->regionId = regionId;
msg->regionId = regionId;
- }
- else {
- msg->cmd = App_CMD_NOP;
- msg->id = i;
+ } else {
+ if (i == 16) {
+ /* Last message will tell the slave to shutdown */
+ msg->cmd = App_CMD_SHUTDOWN;
+ msg->id = i;
+ } else {
+ /* Send dummy NOP messages before shutdown */
+ msg->cmd = App_CMD_NOP;
+ msg->id = i;
+ }
}
/* send message */
MessageQ_put(Module.slaveQue, (MessageQ_Msg)msg);
}
/* send message */
MessageQ_put(Module.slaveQue, (MessageQ_Msg)msg);
+
+ /* Send messages: End =======================================> */
+
}
/* drain process pipeline */
}
/* drain process pipeline */