static inline Void _FNPROF_InitHeap() { HeapMem_Params heapMemPrm; UTILS_assert((FNPROF_GBLINFO.hProfileHeapExtMem == NULL)); /* create memory pool heap */ HeapMem_Params_init(&heapMemPrm); heapMemPrm.buf = cProfileHeapExtMem; heapMemPrm.size = sizeof(cProfileHeapExtMem); FNPROF_GBLINFO.hProfileHeapExtMem = HeapMem_Handle_upCast(HeapMem_create(&heapMemPrm, NULL)); UTILS_assert((FNPROF_GBLINFO.hProfileHeapExtMem != NULL)); UTILS_assert((FNPROF_GBLINFO.hProfileHeapIntMem == NULL)); /* create memory pool heap */ HeapMem_Params_init(&heapMemPrm); heapMemPrm.buf = cProfileHeapIntMem; heapMemPrm.size = sizeof(cProfileHeapIntMem); FNPROF_GBLINFO.hProfileHeapIntMem = HeapMem_Handle_upCast(HeapMem_create(&heapMemPrm, NULL)); UTILS_assert((FNPROF_GBLINFO.hProfileHeapIntMem != NULL)); }
/* * ======== Memory_redefine ======== */ Bool ti_sdo_ce_osal_Memory_redefine(Int segId, Uint32 base, Uint32 size) { HeapMem_Params params; HeapMem_Handle heap; Memory_Stat stat; if ((segId < 0) || (segId >= Memory_numHeaps)) { Log_print2(Diags_USER7, "Memory_redefine> segId (%d) out of range. " "Should be < %d", (IArg)segId, (IArg)Memory_numHeaps); return (FALSE); } if (!Memory_segStat(segId, &stat)) { Log_print0(Diags_USER7, "Memory_redefine> Memory_segStat() failed!"); return (FALSE); } if (stat.used > 0) { Log_print0(Diags_USER7, "Memory_redefine> Heap in use!"); return (FALSE); } heap = ti_sdo_ce_osal_Memory_heapList[segId]; HeapMem_destruct(HeapMem_struct(heap)); HeapMem_Params_init(¶ms); params.size = size; params.buf = (Ptr)base; HeapMem_construct(HeapMem_struct(heap), ¶ms); return (TRUE); }
/* * ======== MEM_redefine ======== */ Void MEM_redefine(Int id, Ptr base, MEM_sizep length) { IArg key; HeapMem_Params params; HeapMem_Handle heap; /* Make sure the segid is valid. */ if ((id < 0) || (id == 0) || ((Uns)id >= MEM_tabSize)) { SYS_error("MEM", SYS_EINVAL); return; } key = HeapMem_enter(); if (MEM_table[id] == NULL) { HeapMem_leave(key); SYS_error("MEM", SYS_EINVAL); return; } heap = HeapMem_Handle_from_xdc_runtime_IHeap(MEM_table[id]); HeapMem_destruct(HeapMem_struct(heap)); HeapMem_Params_init(¶ms); params.size = length; params.buf = base; HeapMem_construct(HeapMem_struct(heap), ¶ms); HeapMem_leave(key); }
/* * ======== MEM_define ======== */ extern Int MEM_define(Ptr base, MEM_sizep length, MEM_Attrs *attrs) { Int id; IArg key; HeapMem_Params params; HeapMem_Handle heap; IHeap_Handle *tmpTable; Error_Block eb; HeapMem_Params_init(¶ms); params.size = length; params.buf = base; Error_init(&eb); heap = HeapMem_create(¶ms, &eb); if (heap == NULL) { return(-1); } /* Use HeapMem's gate for thread-safety */ key = HeapMem_enter(); /* look for empty slot in memory table */ for (id = 0; id < MEM_tabSize; id++) { if (MEM_table[id] == NULL) { break; } } /* increase table size if no empty slot found */ if (id == MEM_tabSize) { tmpTable = Memory_calloc(MEM_table[0], (MEM_tabSize + 1) * sizeof(IHeap_Handle), 0, &eb); if (tmpTable == NULL) { HeapMem_leave(key); return(-1); } memcpy(tmpTable, MEM_table, MEM_tabSize * sizeof(IHeap_Handle)); if ((MEM_tabSize != 0) && (staticTable != TRUE)) { Memory_free(MEM_table[0], MEM_table, MEM_tabSize * sizeof(IHeap_Handle)); } staticTable = FALSE; MEM_table = tmpTable; MEM_tabSize++; } MEM_table[id] = HeapMem_Handle_to_xdc_runtime_IHeap(heap); HeapMem_leave(key); return (id); }
/* ========================================================================== */ TIMM_OSAL_ERRORTYPE TIMM_OSAL_CreateMemoryPool (void) { TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_NONE; HeapMem_Params heapMemPrm; /* create memory pool heap */ HeapMem_Params_init(&heapMemPrm); heapMemPrm.buf = g_IntHeapMemory_0; heapMemPrm.size = sizeof(g_IntHeapMemory_0); g_IntHeapMemory_Handle_0 = HeapMem_create(&heapMemPrm, NULL); assert(g_IntHeapMemory_Handle_0 != NULL); HeapMem_Params_init(&heapMemPrm); heapMemPrm.buf = g_IntHeapMemory_1; heapMemPrm.size = sizeof(g_IntHeapMemory_1); g_IntHeapMemory_Handle_1 = HeapMem_create(&heapMemPrm, NULL); assert(g_IntHeapMemory_Handle_1 != NULL); HeapMem_Params_init(&heapMemPrm); heapMemPrm.buf = g_IntHeapMemory_2; heapMemPrm.size = sizeof(g_IntHeapMemory_2); g_IntHeapMemory_Handle_2 = HeapMem_create(&heapMemPrm, NULL); assert(g_IntHeapMemory_Handle_2 != NULL); /*Nothing to be done*/ return bReturnStatus; }
/* * ======== main ======== */ Int main() { /* Call board init functions */ Board_initGeneral(); /* Construct BIOS objects */ Task_Params taskParams; HeapBuf_Params heapBufParams; HeapMem_Params heapMemParams; /* Construct writer/reader Task threads */ Task_Params_init(&taskParams); taskParams.stackSize = TASKSTACKSIZE; taskParams.stack = &task0Stack; Task_construct(&task0Struct, (Task_FuncPtr)task0Fxn, &taskParams, NULL); taskParams.stack = &task1Stack; Task_construct(&task1Struct, (Task_FuncPtr)task1Fxn, &taskParams, NULL); /* Construct two heaps to be used by two separate tasks for alloc and free. */ HeapBuf_Params_init(&heapBufParams); heapBufParams.blockSize = HEAPBUFSIZE / 2; heapBufParams.numBlocks = 2; heapBufParams.align = 8; heapBufParams.buf = heapBufBuffer; heapBufParams.bufSize = HEAPBUFSIZE; HeapBuf_construct(&heapBufStruct, &heapBufParams, NULL); task0Heap = HeapBuf_handle(&heapBufStruct); HeapMem_Params_init(&heapMemParams); heapMemParams.size = HEAPMEMSIZE; heapMemParams.minBlockAlign = 8; heapMemParams.buf = heapMemBuffer; HeapMem_construct(&heapMemStruct, &heapMemParams); task1Heap = HeapMem_handle(&heapMemStruct); System_printf("Memory example started.\n"); BIOS_start(); /* Does not return */ return(0); }