//------------------------------------------------------------------------------ tHostifReturn hostif_createInt(tHostif* pHostif_p) { tHostifReturn ret = kHostifSuccessful; tHostifBufDesc aInitVec[] = HOSTIF_INIT_VEC; int i; // Allocate init parameter memory pHostif_p->pInitParam = (tHostifInitParam*)HOSTIF_UNCACHED_MALLOC(sizeof(tHostifInitParam)); if (pHostif_p->pInitParam == NULL) { ret = kHostifNoResource; goto Exit; } memset(pHostif_p->pInitParam, 0, sizeof(tHostifInitParam)); // Initialize init parameter memory pHostif_p->pInitParam->initMemLength = HOSTIF_DYNBUF_COUNT + HOSTIF_BUF_COUNT; memcpy(pHostif_p->pInitParam->aInitMem, aInitVec, sizeof(aInitVec)); // Now set init parameter address to hostif hostif_writeInitBase(pHostif_p->pBase, (UINT32)pHostif_p->pInitParam); // Write span of buffers into buf map table, malloc them and write to hostif for (i = 0; i < kHostifInstIdLast; i++) { pHostif_p->aBufMap[i].span = aInitVec[i + HOSTIF_DYNBUF_COUNT].span; pHostif_p->aBufMap[i].pBase = (UINT8*)HOSTIF_UNCACHED_MALLOC(pHostif_p->aBufMap[i].span); if (pHostif_p->aBufMap[i].pBase == NULL) { ret = kHostifNoResource; goto Exit; } hostif_writeBufPcp(pHostif_p->pBase, i, (UINT32)pHostif_p->aBufMap[i].pBase); } // since everything is fine, activate bridge ret = controlBridge(pHostif_p, TRUE); if (ret != kHostifSuccessful) { goto Exit; } Exit: return ret; }
//------------------------------------------------------------------------------ tQueueReturn lfq_create (tQueueConfig *pQueueConfig_p, tQueueInstance *ppInstance_p) { tQueue *pQueue = NULL; if(pQueueConfig_p == NULL || ppInstance_p == NULL) return kQueueInvalidParameter; if(UNALIGNED32(pQueueConfig_p->span - sizeof(tQueueBufferHdr))) return kQueueAlignment; pQueue = (tQueue*)malloc(sizeof(tQueue)); if(pQueue == NULL) return kQueueNoResource; memset(pQueue, 0, sizeof(tQueue)); /// store configuration pQueue->config = *pQueueConfig_p; /// allocate memory for queue pQueue->span = pQueue->config.span; if(pQueue->config.fAllocHeap != FALSE) pQueue->pBase = (UINT8*)HOSTIF_UNCACHED_MALLOC(pQueue->span); else pQueue->pBase = pQueue->config.pBase; /// kill instance if allocation is faulty if(pQueue->pBase == NULL || UNALIGNED32(pQueue->pBase)) { lfq_delete(pQueue); return kQueueNoResource; } /// set queue buffer pQueue->pQueueBuffer = (tQueueBuffer*)pQueue->pBase; pQueue->queueBufferSpan = pQueue->span - sizeof(tQueueBufferHdr); /// initialize max entries (=mask) pQueue->maxEntries = pQueue->queueBufferSpan / ENTRY_MIN_SIZE; if(pQueue->maxEntries > QUEUE_MAX_ENTRIES) { lfq_delete(pQueue); return kQueueNoResource; } /// initialize queue header switch(pQueue->config.queueRole) { case kQueueProducer: break; case kQueueConsumer: case kQueueBoth: { setHwQueueState(pQueue, kQueueStateReset); resetHwQueue(pQueue); /// check if initializing was successful (queue must be empty) getHwQueueBufferHeader(pQueue); if(!checkQueueEmpty(pQueue)) return kQueueHwError; setHwQueueState(pQueue, kQueueStateOperational); } } /// return initialized queue instance *ppInstance_p = pQueue; return kQueueSuccessful; }