const char* MCP_HAL_LOG_SetModuleName(McpHalLogModuleId_e moduleId,const char* name) { if (moduleId > MCP_HAL_LOG_MODULE_TYPE_UNKNOWN && moduleId <= MCP_HAL_LOG_MODULE_TYPE_LAST && NULL != name) { MCP_HAL_STRING_StrnCpy(MCP_HAL_LOG_Modules[moduleId].name, name, MAX_MODULE_NAME_LENGTH-1); return MCP_HAL_LOG_Modules[moduleId].name; } return NULL; }
McpPoolStatus MCP_POOL_Create( McpPool *pool, const char *name, McpU32 *elementsMemory, McpU32 numOfElements, McpU32 elementSize) { McpPoolStatus status = MCP_POOL_STATUS_SUCCESS; McpU32 allocatedSize; MCP_FUNC_START("MCP_POOL_Create"); MCP_VERIFY_FATAL((0 != pool), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null pool argument")); MCP_VERIFY_FATAL((0 != name), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null name argument")); MCP_VERIFY_FATAL((0 != elementsMemory), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null elementsMemory argument")); MCP_VERIFY_FATAL((MCP_POOL_MAX_NUM_OF_POOL_ELEMENTS > numOfElements), MCP_POOL_STATUS_INTERNAL_ERROR, ("Max num of pool elements (%d) exceeded (%d)", numOfElements, MCP_POOL_MAX_NUM_OF_POOL_ELEMENTS)); MCP_VERIFY_FATAL((0 < elementSize), MCP_POOL_STATUS_INTERNAL_ERROR, ("Element size must be >0")); allocatedSize = MCP_POOL_ACTUAL_SIZE_TO_ALLOCATED_MEMORY_SIZE(elementSize); /* Copy init values to members */ pool->elementsMemory = elementsMemory; pool->elementAllocatedSize = allocatedSize; pool->numOfElements = numOfElements; /* Safely copy the pool name */ MCP_HAL_STRING_StrnCpy(pool->name, name, MCP_POOL_MAX_POOL_NAME_LEN); pool->name[MCP_POOL_MAX_POOL_NAME_LEN] = '\0'; /* Init the other auxiliary members */ pool->numOfAllocatedElements = 0; /* Mark all entries as free */ MCP_HAL_MEMORY_MemSet(pool->allocationMap, MCP_POOL_FREE_ELEMENT_MAP_INDICATION, MCP_POOL_MAX_NUM_OF_POOL_ELEMENTS); /* Fill memory in a special value to facilitate identification of dangling pointer usage */ MCP_HAL_MEMORY_MemSet((McpU8 *)pool->elementsMemory, MCP_POOL_FREE_MEMORY_VALUE, numOfElements * allocatedSize); McpPoolDebugAddPool(pool); MCP_FUNC_END(); return status; }