/* Allocates the specified number of bytes and memory is set to zero. */ Ptr Memory_calloc (IHeap_Handle heap, SizeT size, SizeT align, Ptr eb) { Ptr buffer = NULL; GT_4trace (curTrace, GT_ENTER, "Memory_calloc", heap, size, align, eb); /* Check whether the right paramaters are passed or not.*/ GT_assert (curTrace, (size > 0)); (Void) eb; /* Not used. */ if (heap == NULL) { buffer = MemoryOS_calloc (size, align, 0); #if !defined(SYSLINK_BUILD_OPTIMIZE) if (buffer == NULL) { /*! @retval NULL Failed to allocate memory */ GT_setFailureReason (curTrace, GT_4CLASS, "Memory_calloc", Memory_E_MEMORY, "Failed to allocate memory!"); } #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */ } else { buffer = Memory_valloc (heap, size, align, 0u, eb); #if !defined(SYSLINK_BUILD_OPTIMIZE) if (buffer == NULL) { /*! @retval NULL Memory_valloc failed */ GT_setFailureReason (curTrace, GT_4CLASS, "Memory_calloc", Memory_E_MEMORY, "Memory_valloc failed!"); } #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */ } GT_0trace (curTrace, GT_LEAVE, "Memory_calloc"); /*! @retval Pointer Success: Pointer to allocated buffer */ return buffer; }
/* * ======== NotifyDriverShm_Instance_init ======== */ Int NotifyDriverShm_Instance_init(NotifyDriverShm_Object *obj, const NotifyDriverShm_Params *params, Error_Block *eb) { UInt16 regionId; SizeT regionCacheSize, minAlign, procCtrlSize; /* * Check whether remote proc ID has been set and isn't the same as the * local proc ID */ Assert_isTrue ((params->remoteProcId != MultiProc_INVALIDID) && (params->remoteProcId != MultiProc_self()), ti_sdo_ipc_Ipc_A_invParam); /* * Determine obj->cacheEnabled using params->cacheEnabled and SharedRegion * cache flag setting, if applicable. */ obj->cacheEnabled = params->cacheEnabled; minAlign = params->cacheLineSize; if (minAlign == 0) { /* Fix alignment of zero */ minAlign = sizeof(Ptr); } regionId = SharedRegion_getId(params->sharedAddr); if (regionId != SharedRegion_INVALIDREGIONID) { /* * Override the user cacheEnabled setting if the region * cacheEnabled is FALSE. */ if (!SharedRegion_isCacheEnabled(regionId)) { obj->cacheEnabled = FALSE; } regionCacheSize = SharedRegion_getCacheLineSize(regionId); /* * Override the user cache line size setting if the region * cache line size is smaller. */ if (regionCacheSize < minAlign) { minAlign = regionCacheSize; } } /* Check if shared memory base addr is aligned to cache line boundary.*/ Assert_isTrue ((UInt32)params->sharedAddr % minAlign == 0, ti_sdo_ipc_Ipc_A_addrNotCacheAligned); obj->remoteProcId = params->remoteProcId; /* * Store all interrupt information so it may be used (if neccessary) by * the IInterrupt delegates */ obj->intInfo.remoteIntId = params->remoteIntId; obj->intInfo.localIntId = params->localIntId; obj->intInfo.intVectorId = params->intVectorId; obj->nesting = 0; if (params->remoteProcId > MultiProc_self()) { obj->selfId = 0; obj->otherId = 1; } else { obj->selfId = 1; obj->otherId = 0; } /* Initialize pointers to shared memory regions */ procCtrlSize = _Ipc_roundup(sizeof(NotifyDriverShm_ProcCtrl), minAlign); /* * Save the eventEntrySize in obj since we will need it at runtime to * index the event charts */ obj->eventEntrySize = _Ipc_roundup(sizeof(NotifyDriverShm_EventEntry), minAlign); obj->selfProcCtrl = (NotifyDriverShm_ProcCtrl *) ((UInt32)params->sharedAddr + (obj->selfId * procCtrlSize)); obj->otherProcCtrl = (NotifyDriverShm_ProcCtrl *) ((UInt32)params->sharedAddr + (obj->otherId * procCtrlSize)); obj->selfEventChart = (NotifyDriverShm_EventEntry *) ((UInt32)params->sharedAddr + (2 * procCtrlSize) + (obj->eventEntrySize * ti_sdo_ipc_Notify_numEvents * obj->selfId)); obj->otherEventChart = (NotifyDriverShm_EventEntry *) ((UInt32)params->sharedAddr + (2 * procCtrlSize) + (obj->eventEntrySize * ti_sdo_ipc_Notify_numEvents * obj->otherId)); /* Allocate memory for regChart and init to (UInt32)-1 (unregistered) */ obj->regChart = Memory_valloc( NotifyDriverShm_Object_heap(), (sizeof(UInt32) * ti_sdo_ipc_Notify_numEvents), NULL, ~0, eb); if (obj->regChart == NULL) { return (1); } /* Enable all events initially.*/ obj->selfProcCtrl->eventEnableMask = 0xFFFFFFFF; /* Write back our own ProcCtrl */ if (obj->cacheEnabled) { Cache_wbInv(obj->selfProcCtrl, sizeof(NotifyDriverShm_ProcCtrl), Cache_Type_ALL, TRUE); } /* Register the incoming interrupt */ NotifyDriverShm_InterruptProxy_intRegister(obj->remoteProcId, &(obj->intInfo), (Fxn)NotifyDriverShm_isr, (UArg)obj); return (0); }
/* * ======== Memory_calloc ======== */ Ptr Memory_calloc(IHeap_Handle heap, SizeT size, SizeT align, Error_Block *eb) { /* Call valloc with a value of zero */ return (Memory_valloc(heap, size, align, 0, eb)); }