/* * ======== MEM_stat ======== */ Bool MEM_stat(Int id, MEM_Stat *statbuf) { IArg key; HeapMem_Handle heap; Memory_Stats stat; HeapMem_ExtendedStats extendedStats; if ((id < 0) || ((Uns)id >= MEM_tabSize) || (MEM_table[id] == NULL)) { SYS_error("MEM", SYS_EINVAL); return (FALSE); } heap = HeapMem_Handle_from_xdc_runtime_IHeap(MEM_table[id]); /* Use HeapMem's gate for thread-safety */ key = HeapMem_enter(); HeapMem_getExtendedStats(heap, &extendedStats); Memory_getStats(MEM_table[id], &stat); statbuf->size = stat.totalSize; statbuf->used = stat.totalSize - stat.totalFreeSize; statbuf->length = stat.largestFreeSize; statbuf->space = 1; statbuf->base = extendedStats.buf; HeapMem_leave(key); return (TRUE); }
UInt32 Utils_memGetBitBufferHeapFreeSpace(void) { Memory_Stats stats; Memory_getStats(gUtils_heapMemHandle[UTILS_MEM_VID_BITS_BUF_HEAP], &stats); return ((UInt32) (stats.totalFreeSize)); }
UInt32 Utils_memGetSystemHeapFreeSpace(void) { Memory_Stats stats; extern const IHeap_Handle Memory_defaultHeapInstance; Memory_getStats(Memory_defaultHeapInstance, &stats); return ((UInt32) (stats.totalFreeSize)); }
UInt32 Utils_memGetSR0HeapFreeSpace(void) { UInt32 size; Memory_Stats stats; Memory_getStats(SharedRegion_getHeap(0), &stats); size = stats.totalFreeSize; return ((UInt32) (size)); }
UInt32 Utils_memGetBufferHeapFreeSpace(void) { UInt32 size; Memory_Stats stats; Memory_getStats(gUtils_heapMemHandle[UTILS_MEM_VID_FRAME_BUF_HEAP], &stats); size = stats.totalFreeSize; return ((UInt32) (size)); }
static Void printHeapStats(IHeap_Handle heap) { Memory_Stats stats; Memory_getStats(heap, &stats); #ifdef xdc_target__isaCompatible_28 System_printf("largestFreeSize = %ld\n", (ULong)stats.largestFreeSize); System_printf("totalFreeSize = %ld\n", (ULong)stats.totalFreeSize); System_printf("totalSize = %ld\n", (ULong)stats.totalSize); #else System_printf("largestFreeSize = %d\n", stats.largestFreeSize); System_printf("totalFreeSize = %d\n", stats.totalFreeSize); System_printf("totalSize = %d\n", stats.totalSize); #endif }
/* * ======== main ======== */ Int main() { Task_Params taskParams; Error_Block eb; Memory_Stats stats; Error_init(&eb); /* Picking a stackSize such that the second Task_create() will fail */ Memory_getStats(Memory_defaultHeapInstance, &stats); Task_Params_init(&taskParams); taskParams.priority = 1; taskParams.stackSize = (stats.totalFreeSize/2) + 64; /* * Create two tasks, The first one succeeds and the second one fails * We catch the second failure in the Error_Block */ tsk1 = Task_create(task1, &taskParams, &eb); if (Error_check(&eb)) { /* Should not get here */ System_printf("First Task_create() failed\n"); BIOS_exit(0); } Error_init(&eb); tsk2 = Task_create(task2, &taskParams, &eb); if (Error_check(&eb)) { /* Should get here */ System_printf("Second Task_create() failed\n"); } BIOS_start(); /* does not return */ return(0); }