McpPoolStatus MCP_POOL_Allocate(McpPool *pool, void ** element) { McpPoolStatus status = MCP_POOL_STATUS_SUCCESS; McpU32 allocatedIndex = MCP_POOL_INVALID_ELEMENT_INDEX; MCP_FUNC_START("MCP_POOL_Allocate"); MCP_VERIFY_FATAL((0 != pool), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null pool argument")); MCP_VERIFY_FATAL((0 != element), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null element argument")); MCP_VERIFY_FATAL((MCP_FALSE == MCP_POOL_IsDestroyed(pool)), MCP_POOL_STATUS_INTERNAL_ERROR, ("Pool Already Destroyed")); allocatedIndex = MCP_POOL_GetFreeElementIndex(pool); if (MCP_POOL_INVALID_ELEMENT_INDEX == allocatedIndex) { return MCP_POOL_STATUS_NO_RESOURCES; } ++(pool->numOfAllocatedElements); pool->allocationMap[allocatedIndex] = MCP_POOL_ALLOCATED_ELEMENT_MAP_INDICATION; *element = MCP_POOL_GetElementAddressFromIndex(pool, allocatedIndex); MCP_FUNC_END(); return status; }
_CcmImStatus _CCM_IM_BtTranSm_StaticInit(void) { _CcmImStatus status; BtHciIfStatus btHciIfStatus; MCP_FUNC_START("_CCM_IM_BtTranSm_StaticInit"); _CCM_IM_BtTranSm_StaticInitSm(); _CCM_IM_BtTranSm_StaticInitInstances(); btHciIfStatus = BT_HCI_IF_StaticInit(); MCP_VERIFY_FATAL((btHciIfStatus == _CCM_IM_STATUS_SUCCESS), _CCM_IM_STATUS_INTERNAL_ERROR, ("_CCM_IM_BtTranSm_StaticInit: BT_HCI_IF_StaticInit Failed")); status = _CCM_IM_BtTranOnSm_StaticInit(); MCP_VERIFY_FATAL((status == _CCM_IM_STATUS_SUCCESS), _CCM_IM_STATUS_INTERNAL_ERROR, ("_CCM_IM_BtTranSm_StaticInit: _CCM_IM_BtTranOnSm_StaticInit Failed")); status = _CCM_IM_BtTranOffSm_StaticInit(); MCP_VERIFY_FATAL((status == _CCM_IM_STATUS_SUCCESS), _CCM_IM_STATUS_INTERNAL_ERROR, ("_CCM_IM_BtTranSm_StaticInit: _CCM_IM_BtTranOffSm_StaticInit Failed")); status = _CCM_IM_STATUS_SUCCESS; MCP_FUNC_END(); return status; }
_CcmImStatus _CCM_IM_BtTranSm_Destroy(_CcmIm_BtTranSm_Obj **thisObj) { _CcmImStatus status; BtHciIfStatus btHciIfStatus; MCP_FUNC_START("_CCM_IM_BtTranSm_Create"); status = _CCM_IM_BtTranOffSm_Destroy(&(*thisObj)->tranOffSmObj); MCP_VERIFY_FATAL((status == _CCM_IM_STATUS_SUCCESS), _CCM_IM_STATUS_INTERNAL_ERROR, ("_CCM_IM_BtTranSm_Destroy: _CCM_IM_BtTranOffSm_Destroy Failed")); status = _CCM_IM_BtTranOnSm_Destroy(&(*thisObj)->tranOnSmObj); MCP_VERIFY_FATAL((status == _CCM_IM_STATUS_SUCCESS), _CCM_IM_STATUS_INTERNAL_ERROR, ("_CCM_IM_BtTranSm_Destroy: _CCM_IM_BtTranOnSm_Destroy Failed")); btHciIfStatus = BT_HCI_IF_Destroy(&((*thisObj)->btHciIfObj)); MCP_VERIFY_FATAL((btHciIfStatus == _CCM_IM_STATUS_SUCCESS), _CCM_IM_STATUS_INTERNAL_ERROR, ("_CCM_IM_BtTranSm_Destroy: BT_HCI_IF_Destroy Failed")); *thisObj = NULL; MCP_FUNC_END(); return status; }
McpPoolStatus MCP_POOL_IsElelementAllocated(McpPool *pool, const void* element, McpBool *answer) { McpPoolStatus status = MCP_POOL_STATUS_SUCCESS; /* Map the element's address to a map index */ McpU32 freedIndex = MCP_POOL_INVALID_ELEMENT_INDEX; MCP_FUNC_START("MCP_POOL_IsElelementAllocated"); MCP_VERIFY_FATAL((0 != pool), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null pool argument")); MCP_VERIFY_FATAL((0 != element), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null element argument")); MCP_VERIFY_FATAL((0 != answer), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null answer argument")); MCP_VERIFY_FATAL((MCP_FALSE == MCP_POOL_IsDestroyed(pool)), MCP_POOL_STATUS_INTERNAL_ERROR, ("Pool Already Destroyed")); freedIndex = MCP_POOL_GetElementIndexFromAddress(pool, (void*)element); MCP_VERIFY_ERR((MCP_POOL_INVALID_ELEMENT_INDEX != freedIndex), MCP_POOL_STATUS_INVALID_PARM, ("Invalid element address")); if (MCP_POOL_ALLOCATED_ELEMENT_MAP_INDICATION == pool->allocationMap[freedIndex]) { *answer = MCP_TRUE; } else { *answer = MCP_FALSE; } MCP_FUNC_END(); return status; }
/* The function needs to do the following: - Perform CCM "class" static initialization (if necessary - first time) - "Create" the instance (again, if it's the first creation of this instance) */ CcmStatus CCM_Create(McpHalChipId chipId, CcmObj **thisObj) { CcmStatus status; CcmImStatus imStatus; ECCM_VAC_Status vacStatus; McpConfigParserStatus eConfigParserStatus; McpUtf8 scriptPath[MCP_HAL_CONFIG_FS_MAX_PATH_LEN_CHARS * MCP_HAL_CONFIG_MAX_BYTES_IN_UTF8_CHAR] = ""; MCP_FUNC_START("CCM_Create"); MCP_VERIFY_FATAL((chipId < MCP_HAL_MAX_NUM_OF_CHIPS), CCM_STATUS_INTERNAL_ERROR, (("Invalid Chip Id"), chipId)); if (_CCM_StaticData._ccm_Objs[chipId].refCount == 0) { _CCM_StaticData._ccm_Objs[chipId].chipId = chipId; /* read ini file */ MCP_StrCpyUtf8(scriptPath, (const McpUtf8 *)CCM_VAC_CONFIG_PATH_NAME); MCP_StrCatUtf8(scriptPath, (const McpUtf8 *)CCM_VAC_CONFIG_FILE_NAME); eConfigParserStatus = MCP_CONFIG_PARSER_Open(scriptPath, (McpU8*)CCM_VAC_MEM_CONFIG, &(_CCM_StaticData._ccm_Objs[chipId].tConfigParser)); MCP_VERIFY_ERR ((MCP_CONFIG_PARSER_STATUS_SUCCESS == eConfigParserStatus), CCM_VAC_STATUS_FAILURE_UNSPECIFIED, ("_CCM_VAC_ConfigurationEngine_Create: reading config file failed with status %d", eConfigParserStatus)); imStatus = CCM_IM_Create(chipId, &_CCM_StaticData._ccm_Objs[chipId].imObj, _CCM_NotifyChipOn, &_CCM_StaticData._ccm_Objs[chipId]); MCP_VERIFY_FATAL((imStatus == CCM_IM_STATUS_SUCCESS), CCM_STATUS_INTERNAL_ERROR, ("CCM_IM_Create Failed")); CAL_Create (chipId, CCM_IMI_GetBtHciIfObj (_CCM_StaticData._ccm_Objs[chipId].imObj), &(_CCM_StaticData._ccm_Objs[chipId].calObj),&(_CCM_StaticData._ccm_Objs[chipId].tConfigParser)); /* CAL creation cannot fail */ vacStatus = CCM_VAC_Create (chipId, _CCM_StaticData._ccm_Objs[chipId].calObj, &(_CCM_StaticData._ccm_Objs[chipId].vacObj), &(_CCM_StaticData._ccm_Objs[chipId].tConfigParser)); MCP_VERIFY_FATAL ((CCM_VAC_STATUS_SUCCESS == vacStatus), CCM_STATUS_INTERNAL_ERROR, ("CCM_Create: VAC creation failed with status %d", vacStatus)); } ++_CCM_StaticData._ccm_Objs[chipId].refCount; /* Set the instance pointer (out parameter) to be used in external references to this instance */ *thisObj = &_CCM_StaticData._ccm_Objs[chipId]; status = CCM_STATUS_SUCCESS; MCP_FUNC_END(); return status; }
McpPoolStatus MCP_POOL_GetNumOfAllocatedElements(const McpPool *pool, McpU32 *num) { McpPoolStatus status = MCP_POOL_STATUS_SUCCESS; MCP_FUNC_START("MCP_POOL_GetNumOfAllocatedElements"); MCP_VERIFY_FATAL((0 != pool), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null pool argument")); MCP_VERIFY_FATAL((MCP_FALSE == MCP_POOL_IsDestroyed(pool)), MCP_POOL_STATUS_INTERNAL_ERROR, ("Pool Already Destroyed")); *num = pool->numOfAllocatedElements; MCP_FUNC_END(); return status; }
McpPoolStatus MCP_POOL_Destroy(McpPool *pool) { McpPoolStatus status = MCP_POOL_STATUS_SUCCESS; McpU32 numOfAllocatedElements; MCP_FUNC_START("MCP_POOL_Destroy"); MCP_LOG_INFO(("Destroying Pool %s", pool->name)); MCP_VERIFY_FATAL((0 != pool), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null pool argument")); /* It is illegal to destroy a pool while there are allocated elements in the pool */ status = MCP_POOL_GetNumOfAllocatedElements(pool, &numOfAllocatedElements); MCP_VERIFY_ERR_NORET( (0 == numOfAllocatedElements), ("Pool %s still has %d allocated elements", pool->name, numOfAllocatedElements)); pool->elementsMemory = 0; pool->numOfElements = 0; pool->elementAllocatedSize = 0; pool->numOfAllocatedElements = 0; MCP_HAL_STRING_StrCpy(pool->name, ""); MCP_FUNC_END(); return status; }
McpPoolStatus MCP_POOL_GetCapacity(const McpPool *pool, McpU32 *capacity) { McpPoolStatus status = MCP_POOL_STATUS_SUCCESS; MCP_FUNC_START("MCP_POOL_GetCapacity"); MCP_VERIFY_FATAL((0 != pool), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null pool argument")); MCP_VERIFY_FATAL((0 != capacity), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null capacity argument")); MCP_VERIFY_FATAL((MCP_FALSE == MCP_POOL_IsDestroyed(pool)), MCP_POOL_STATUS_INTERNAL_ERROR, ("Pool Already Destroyed")); *capacity = pool->numOfElements; MCP_FUNC_END(); return status; }
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; }
_CcmImStatus _CCM_IM_BtTranSm_Create( McpHalChipId chipId, _CcmIm_BtTranSm_CompletionCb parentCb, McpHalOsSemaphoreHandle ccmImMutexHandle, _CcmIm_BtTranSm_Obj **thisObj) { _CcmImStatus status; BtHciIfStatus btHciIfStatus; MCP_FUNC_START("_CCM_IM_BtTranSm_Create"); *thisObj = &_ccmIm_BtTranSm_Data.smObjs[chipId]; (*thisObj)->chipId = chipId; (*thisObj)->parentCb = parentCb; /* Create the BT HCI If obj that is used by both BtTranSmOn and BtTranSmOff state instances */ btHciIfStatus = BT_HCI_IF_Create((*thisObj)->chipId, NULL, &((*thisObj)->btHciIfObj)); MCP_VERIFY_FATAL((btHciIfStatus == _CCM_IM_STATUS_SUCCESS), _CCM_IM_STATUS_INTERNAL_ERROR, ("_CCM_IM_BtTranSm_Create: BT_HCI_IF_Create Failed")); status = _CCM_IM_BtTranOnSm_Create( (*thisObj)->chipId, (*thisObj)->btHciIfObj, _CCM_IM_BtTranSm_TranOnSmCb, ccmImMutexHandle, &(*thisObj)->tranOnSmObj); MCP_VERIFY_FATAL((status == _CCM_IM_STATUS_SUCCESS), _CCM_IM_STATUS_INTERNAL_ERROR, ("_CCM_IM_BtTranSm_Create: _CCM_IM_BtTranOnSm_Create Failed")); status = _CCM_IM_BtTranOffSm_Create( (*thisObj)->chipId, (*thisObj)->btHciIfObj, _CCM_IM_BtTranSm_TranOffSmCb, ccmImMutexHandle, &(*thisObj)->tranOffSmObj); MCP_VERIFY_FATAL((status == _CCM_IM_STATUS_SUCCESS), _CCM_IM_STATUS_INTERNAL_ERROR, ("_CCM_IM_BtTranSm_Create: _CCM_IM_BtTranOffSm_Create Failed")); status = _CCM_IM_STATUS_SUCCESS; MCP_FUNC_END(); return status; }
McpPoolStatus MCP_POOL_Free(McpPool *pool, void **element) { McpPoolStatus status = MCP_POOL_STATUS_SUCCESS; /* Map the element's address to a map index */ McpU32 freedIndex = MCP_POOL_INVALID_ELEMENT_INDEX; MCP_FUNC_START("MCP_POOL_Free"); MCP_VERIFY_FATAL((0 != pool), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null pool argument")); MCP_VERIFY_FATAL((0 != element), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null element argument")); MCP_VERIFY_FATAL((0 != *element), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null *element argument")); MCP_VERIFY_FATAL((MCP_FALSE == MCP_POOL_IsDestroyed(pool)), MCP_POOL_STATUS_INTERNAL_ERROR, ("Pool Already Destroyed")); freedIndex = MCP_POOL_GetElementIndexFromAddress(pool, *element); MCP_VERIFY_FATAL((MCP_POOL_INVALID_ELEMENT_INDEX != freedIndex), MCP_POOL_STATUS_INTERNAL_ERROR, ("Invalid element address")); MCP_VERIFY_FATAL( (MCP_POOL_ALLOCATED_ELEMENT_MAP_INDICATION == pool->allocationMap[freedIndex]), MCP_POOL_STATUS_INTERNAL_ERROR, ("Invalid element address")); pool->allocationMap[freedIndex] = MCP_POOL_FREE_ELEMENT_MAP_INDICATION; --(pool->numOfAllocatedElements); /* Fill memory in a special value to facilitate identification of dangling pointer usage */ MCP_HAL_MEMORY_MemSet( (McpU8 *)MCP_POOL_GetElementAddressFromIndex(pool, freedIndex), MCP_POOL_FREE_MEMORY_VALUE, pool->elementAllocatedSize); /* Make sure caller's pointer stops pointing to the freed element */ *element = 0; MCP_FUNC_END(); return status; }
CcmStatus CCM_StaticInit(void) { CcmStatus status; CcmImStatus imStatus; ECCM_VAC_Status vacStatus; /* Used to init once only */ static McpBool firstInit = MCP_TRUE; MCP_FUNC_START("CCM_StaticInit"); if (firstInit == MCP_FALSE) { MCP_LOG_INFO(("_CCM_StaticInit Already Initialized, Exiting Successfully")); MCP_RET(CCM_STATUS_SUCCESS); } firstInit = MCP_FALSE; status = _CCM_StaticInit(); MCP_VERIFY_FATAL((status == CCM_STATUS_SUCCESS), CCM_STATUS_INTERNAL_ERROR, ("_CCM_StaticInit")); /* Initialize contained entities (IM, PM, VAC) */ imStatus = CCM_IM_StaticInit(); MCP_VERIFY_FATAL((imStatus == CCM_IM_STATUS_SUCCESS), CCM_STATUS_INTERNAL_ERROR, ("CCM_IM_StaticInit")); vacStatus = CCM_VAC_StaticInit(); MCP_VERIFY_FATAL ((CCM_VAC_STATUS_SUCCESS == vacStatus), CCM_STATUS_INTERNAL_ERROR, ("CCM_StaticInit: VAC initialization failed with status %d", vacStatus)); CCM_CAL_StaticInit(); status = CCM_STATUS_SUCCESS; MCP_FUNC_END(); return status; }
McpPoolStatus MCP_POOL_IsFull(McpPool *pool, McpBool *answer) { McpPoolStatus status = MCP_POOL_STATUS_SUCCESS; MCP_FUNC_START("MCP_POOL_IsFull"); MCP_VERIFY_FATAL((0 != pool), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null pool argument")); MCP_VERIFY_FATAL((0 != answer), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null answer argument")); MCP_VERIFY_FATAL((MCP_FALSE == MCP_POOL_IsDestroyed(pool)), MCP_POOL_STATUS_INTERNAL_ERROR, ("Pool Already Destroyed")); if (pool->numOfAllocatedElements == pool->numOfElements) { *answer = MCP_TRUE; } else { *answer = MCP_FALSE; } MCP_FUNC_END(); return status; }
CcmStatus _CCM_StaticInit(void) { CcmStatus status; McpHalOsStatus mcpHalOsStatus; CcmHalPwrUpDwnStatus ccmHalPwrUpDwnStatus; McpHalFsStatus halFsStatus; McpUint chipIdx; McpHalPmStatus halPmStatus; MCP_FUNC_START("_CCM_StaticInit"); mcpHalOsStatus = MCP_HAL_OS_Init(); MCP_VERIFY_FATAL((mcpHalOsStatus == MCP_HAL_OS_STATUS_SUCCESS), CCM_STATUS_INTERNAL_ERROR, ("MCP_HAL_OS_Init Failed (%d)", mcpHalOsStatus)); halFsStatus = MCP_HAL_FS_Init(); MCP_VERIFY_FATAL((halFsStatus == MCP_HAL_FS_STATUS_SUCCESS), CCM_STATUS_INTERNAL_ERROR, ("MCP_HAL_FS_Init Failed (%d)", halFsStatus)); halPmStatus = MCP_HAL_PM_Init(); MCP_VERIFY_FATAL((halFsStatus == MCP_HAL_FS_STATUS_SUCCESS), CCM_STATUS_INTERNAL_ERROR, ("MCP_HAL_FS_Init Failed (%d)", halFsStatus)); ccmHalPwrUpDwnStatus = CCM_HAL_PWR_UP_DWN_Init(); MCP_VERIFY_FATAL((ccmHalPwrUpDwnStatus == CCM_HAL_PWR_UP_DWN_STATUS_SUCCESS), CCM_STATUS_INTERNAL_ERROR, ("CCM_HAL_PWR_UP_DWN_Init Failed (%d)", ccmHalPwrUpDwnStatus)); for (chipIdx = 0; chipIdx < MCP_HAL_MAX_NUM_OF_CHIPS; ++chipIdx) { _CCM_StaticData._ccm_Objs[chipIdx].refCount = 0; } status = CCM_STATUS_SUCCESS; MCP_FUNC_END(); return status; }
CcmStatus CCM_Destroy(CcmObj **thisObj) { CcmStatus status; CcmImStatus imStatus; McpHalChipId chipId = (*thisObj)->chipId; MCP_FUNC_START("CCM_Destroy"); MCP_VERIFY_FATAL((_CCM_StaticData._ccm_Objs[chipId].refCount > 0), CCM_STATUS_INTERNAL_ERROR, ("CCM_IM_Destroy: CCM(#%d) Doesn't Exist", chipId)); /* Another client of this instance wishes to destroy it */ --_CCM_StaticData._ccm_Objs[chipId].refCount; if (_CCM_StaticData._ccm_Objs[chipId].refCount == 0) { /* Last instance client, now we can actually perform destruction*/ imStatus = CCM_IM_Destroy(&((*thisObj)->imObj)); MCP_VERIFY_FATAL((imStatus == CCM_IM_STATUS_SUCCESS), CCM_STATUS_INTERNAL_ERROR, ("CCM_IM_Destroy Failed")); CCM_VAC_Destroy (&((*thisObj)->vacObj)); /* VAC destruction cannot fail */ CAL_Destroy (&((*thisObj)->calObj)); /* CAL destruction cannot fail */ } *thisObj = NULL; status = CCM_STATUS_SUCCESS; MCP_FUNC_END(); return status; }
/* This function is called to abort the transport on process The event is forwarded to tran_on_sm that should handle it according to its state */ _CcmImStatus _CCM_IM_BtTranSm_HandlerAbortOn(_CcmIm_BtTranSm_Obj *thisObj, void *eventData) { _CcmImStatus status; MCP_FUNC_START("_CCM_IM_BtTranSm_HandlerAbortOn"); MCP_UNUSED_PARAMETER(eventData); status = _CCM_IM_BtTranOnSm_HandleEvent( thisObj->tranOnSmObj, _CCM_IM_BT_TRAN_ON_SM_EVENT_ABORT, NULL); MCP_VERIFY_FATAL((status == _CCM_IM_STATUS_PENDING), status, ("_CCM_IM_BtTranOnSm_HandleEvent")); MCP_FUNC_END(); return status; }
/* This function is called to shutdown the BT transport The tran_off_sm will be called to handle that */ _CcmImStatus _CCM_IM_BtTranSm_HandlerTranOff(_CcmIm_BtTranSm_Obj *thisObj, void *eventData) { _CcmImStatus status; MCP_FUNC_START("_CCM_IM_BtTranSm_HandlerTranOff"); MCP_UNUSED_PARAMETER(eventData); status = _CCM_IM_BtTranOffSm_HandleEvent( thisObj->tranOffSmObj, _CCM_IM_BT_TRAN_OFF_SM_EVENT_START, NULL); MCP_VERIFY_FATAL((status == _CCM_IM_STATUS_SUCCESS) || (status == _CCM_IM_STATUS_PENDING), status, ("_CCM_IM_BtTranSm_HandlerTurnTranOff")); MCP_FUNC_END(); return status; }
ECCM_VAC_Status _CCM_VAC_MappingEngine_Configure (TCCM_VAC_MappingEngine *ptMappEngine, TCAL_ResourceSupport *ptAvailResources, TCAL_OperationSupport *ptAvailOperations) { McpU32 uOperationNum, uOperationIndex, uOptResourceNum, uOptResourceIndex, uIndex; McpConfigParserStatus eCPStatus; McpU8 *pTempValue; ECAL_Operation eOperation; ECAL_Resource eResource; TCAL_OptionalResource tTempOptResource; ECCM_VAC_Status status; /* * The configuration process involves reading chip capabilities and ini file settings * (host capabilities). Chip capabilities are read by the configuration engine and are * set in advance to the mapping engine configuration. This function than read the * mapping section of the ini file. For every operation it read the possible optional * resources and arrange them accordingly. It also read the default resource to be used * and set it. */ MCP_FUNC_START ("_CCM_VAC_MappingEngine_Configure"); MCP_UNUSED_PARAMETER (ptAvailOperations); MCP_UNUSED_PARAMETER (ptAvailResources); /* read number of operations from ini file */ eCPStatus = MCP_CONFIG_PARSER_GetIntegerKey (ptMappEngine->pConfigParser, (McpU8 *)CCM_VAC_CONFIG_INI_OPERATIONS_SECTION_NAME, (McpU8 *)CCM_VAC_CONFIG_INI_OPERATIONS_NUMBER_KEY_NAME, (McpS32 *)&uOperationNum); MCP_VERIFY_FATAL (((eCPStatus == MCP_CONFIG_PARSER_STATUS_SUCCESS) && (0 < uOperationNum)), CCM_VAC_STATUS_FAILURE_INVALID_CONFIGURATION, ("_CCM_VAC_MappingEngine_Configure: error reading number of operations " "from file, number: %d, status: %d", uOperationNum, eCPStatus)); /* for every operation */ for (uOperationIndex = 0; uOperationIndex < uOperationNum; uOperationIndex++) { /* read operation */ eCPStatus = MCP_CONFIG_PARSER_GetAsciiKey (ptMappEngine->pConfigParser, (McpU8 *)CCM_VAC_CONFIG_INI_MAPPING_SECTION_NAME, (McpU8 *)CCM_VAC_CONFIG_INI_MAPPING_OP_KEY_NAME, &pTempValue); MCP_VERIFY_FATAL ((eCPStatus == MCP_CONFIG_PARSER_STATUS_SUCCESS), CCM_VAC_STATUS_FAILURE_INVALID_CONFIGURATION, ("_CCM_VAC_MappingEngine_Configure: error reading operation name, status: %d", eCPStatus)); /* convert operation name to enum value */ eOperation = StringtoOperation ((const McpU8*)pTempValue); MCP_VERIFY_FATAL ((CAL_OPERATION_INVALID != eOperation), CCM_VAC_STATUS_FAILURE_INVALID_CONFIGURATION, ("_CCM_VAC_MappingEngine_Configure: erro converting string %s to operation", pTempValue)); /* read number of optional resources */ eCPStatus = MCP_CONFIG_PARSER_GetIntegerKey (ptMappEngine->pConfigParser, (McpU8 *)CCM_VAC_CONFIG_INI_MAPPING_SECTION_NAME, (McpU8 *)CCM_VAC_CONFIG_INI_MAPPING_CONFIG_NUM_KEY_NAME, (McpS32*)&uOptResourceNum); MCP_VERIFY_FATAL ((eCPStatus == MCP_CONFIG_PARSER_STATUS_SUCCESS), CCM_VAC_STATUS_FAILURE_INVALID_CONFIGURATION, ("_CCM_VAC_MappingEngine_Configure: error reading number of optional resources for " "operation %s, status %d", _CCM_VAC_DebugOperationStr(eOperation), eCPStatus)); /* for each optional resource */ for (uOptResourceIndex = 0; uOptResourceIndex < uOptResourceNum; uOptResourceIndex++) { /* read resource name */ eCPStatus = MCP_CONFIG_PARSER_GetAsciiKey (ptMappEngine->pConfigParser, (McpU8 *)CCM_VAC_CONFIG_INI_MAPPING_SECTION_NAME, (McpU8 *)CCM_VAC_CONFIG_INI_MAPPING_RESOURCE_KEY_NAME, &pTempValue); MCP_VERIFY_FATAL ((eCPStatus == MCP_CONFIG_PARSER_STATUS_SUCCESS), CCM_VAC_STATUS_FAILURE_INVALID_CONFIGURATION, ("_CCM_VAC_MappingEngine_Configure: error reading resource name (index %d) " "for operation %s, status: %d", uOptResourceIndex, _CCM_VAC_DebugOperationStr(eOperation), eCPStatus)); /* convert resource name to enum value */ eResource = StringtoResource ((const McpU8 *)pTempValue); MCP_VERIFY_FATAL ((CAL_RESOURCE_INVALID != eResource), CCM_VAC_STATUS_FAILURE_INVALID_CONFIGURATION, ("_CCM_VAC_MappingEngine_Configure: error converting string %s to resource", pTempValue)); /* find the resource entry in the optional resources list */ for (uIndex = 0; uIndex < ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.uNumOfResourceLists; uIndex++) { if (eResource == ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.tOptionalResourceLists[ uIndex ].eOptionalResource) { break; } } /* verify resource was found */ MCP_VERIFY_FATAL ((uIndex < ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.uNumOfResourceLists), CCM_VAC_STATUS_FAILURE_INVALID_CONFIGURATION, ("_CCM_VAC_MappingEngine_Configure: optional resource %s for operation %s in " "ini file is not within chip capabilities", _CCM_VAC_DebugResourceStr(eResource), _CCM_VAC_DebugOperationStr(eOperation))); /* if needed, move it to the beginning of the list */ if (uIndex > uOptResourceIndex) { /* copy resource at the list beginning to temp storage */ MCP_HAL_MEMORY_MemCopy (&tTempOptResource, &(ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.tOptionalResourceLists[ uOptResourceIndex ]), sizeof (TCAL_OptionalResource)); /* copy found resource to list beginning */ MCP_HAL_MEMORY_MemCopy (&(ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.tOptionalResourceLists[ uOptResourceIndex ]), &(ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.tOptionalResourceLists[ uIndex ]), sizeof (TCAL_OptionalResource)); /* finally, copy back temp storage to found resource */ MCP_HAL_MEMORY_MemCopy (&(ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.tOptionalResourceLists[ uIndex ]), &tTempOptResource, sizeof (TCAL_OptionalResource)); } /* mark the resource as unused */ ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.tOptionalResourceLists[ uOptResourceIndex ].bIsUsed = MCP_FALSE; } /* set number of possible optional resources */ ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.uNumOfResourceLists = uOptResourceNum; /* if there are optional resources, read and indicate the default optional resource */ if (0 < uOptResourceNum) { /* read the default resource */ eCPStatus = MCP_CONFIG_PARSER_GetAsciiKey (ptMappEngine->pConfigParser, (McpU8 *)CCM_VAC_CONFIG_INI_MAPPING_SECTION_NAME, (McpU8 *)CCM_VAC_CONFIG_INI_MAPPING_DEF_RESOURCE_KEY_NAME, &pTempValue); MCP_VERIFY_FATAL ((eCPStatus == MCP_CONFIG_PARSER_STATUS_SUCCESS), CCM_VAC_STATUS_FAILURE_INVALID_CONFIGURATION, ("_CCM_VAC_MappingEngine_Configure: error reading default resource name " "for operation %s, status: %d", uOptResourceIndex, _CCM_VAC_DebugOperationStr(eOperation), eCPStatus)); /* convert default resource name to enum value */ eResource = StringtoResource ((const McpU8 *)pTempValue); MCP_VERIFY_FATAL ((CAL_RESOURCE_INVALID != eResource), CCM_VAC_STATUS_FAILURE_INVALID_CONFIGURATION, ("_CCM_VAC_MappingEngine_Configure: error converting string %s to resource", pTempValue)); /* search default resource within optional resources */ for (uIndex = 0; uIndex < ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.uNumOfResourceLists; uIndex++) { /* if this is the default resource */ if (eResource == ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.tOptionalResourceLists[ uIndex ].eOptionalResource) { /* mark it as current mapping for this operation */ ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.tOptionalResourceLists[ uIndex ].bIsUsed = MCP_TRUE; } } } } MCP_FUNC_END (); return CCM_VAC_STATUS_SUCCESS; }
McpBool _CCM_VAC_AllocationEngine_TryAllocate (TCCM_VAC_AllocationEngine *ptAllocEngine, ECAL_Resource eResource, ECAL_Operation *peOperation) { McpBool status = MCP_FALSE; MCP_FUNC_START ("_CCM_VAC_AllocationEngine_TryAllocate"); MCP_LOG_INFO (("_CCM_VAC_AllocationEngine_TryAllocate: operation %s requesting resource %s", _CCM_VAC_DebugOperationStr(*peOperation), _CCM_VAC_DebugResourceStr (eResource))); /* verify object pointer and resource availability */ MCP_VERIFY_FATAL ((NULL != ptAllocEngine), MCP_FALSE, ("_CCM_VAC_AllocationEngine_TryAllocate: NULL object!")); MCP_VERIFY_ERR ((MCP_TRUE == ptAllocEngine->tResources[ eResource ].bAvailable), MCP_FALSE, ("_CCM_VAC_AllocationEngine_TryAllocate: attempting to allocate resource %s " "which is unavailable, for operation %s", _CCM_VAC_DebugResourceStr (eResource), _CCM_VAC_DebugOperationStr (*peOperation))); /* if the resource is currently not allocated at all */ if (0 == ptAllocEngine->tResources[ eResource ].uNumberOfOwners) { MCP_LOG_INFO (("_CCM_VAC_AllocationEngine_TryAllocate: no current owner, resource is allocated")); /* allocate the resource to the requesting operation */ ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ] = *peOperation; ptAllocEngine->tResources[ eResource ].uNumberOfOwners++; status = MCP_TRUE; } /* one operation is already holding the resource */ else if (1 == ptAllocEngine->tResources[ eResource ].uNumberOfOwners) { TCAL_OperationPair tNewPair; /* first check if this is a re-allocation (e.g. for resource change) */ if (*peOperation == ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ]) { MCP_LOG_INFO (("_CCM_VAC_AllocationEngine_TryAllocate: operation %s already owning the " "resource, allocation succeeds", _CCM_VAC_DebugOperationStr(ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ]))); status = MCP_TRUE; } /* now check if both operations may share the resource */ else { /* fill in the new operation pair */ tNewPair.eOperations[ 0 ] = ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ]; tNewPair.eOperations[ 1 ] = *peOperation; /* if the new pair is allowed */ if (MCP_TRUE == _CCM_VAC_AEIsPairAllowed (ptAllocEngine, eResource, &tNewPair)) { MCP_LOG_INFO (("_CCM_VAC_AllocationEngine_TryAllocate: operation %s already owning the " "resource, operation pair is allowed, allocation succeeded", _CCM_VAC_DebugOperationStr(ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ]))); /* fill in the new operation mutually owning the resource */ ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 1 ] = *peOperation; ptAllocEngine->tResources[ eResource ].uNumberOfOwners++; status = MCP_TRUE; } else { MCP_LOG_INFO (("_CCM_VAC_AllocationEngine_TryAllocate: operation %s already owns the " "resource, allocation failed", _CCM_VAC_DebugOperationStr(ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ]))); /* indicate current owner */ *peOperation = ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ]; status = MCP_FALSE; } } } /* two operations are currently mutually owning the resource */ else { /* first check if this is a re-allocation */ if ((*peOperation == ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ]) || (*peOperation == ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 1 ])) { MCP_LOG_INFO (("_CCM_VAC_AllocationEngine_TryAllocate: operations %s and %s already owning the " "resource, allocation succeeded", _CCM_VAC_DebugOperationStr(ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ]), _CCM_VAC_DebugOperationStr(ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 1 ]))); status = MCP_TRUE; } else { MCP_LOG_INFO (("_CCM_VAC_AllocationEngine_TryAllocate: operations %s and %s already owning the " "resource, allocation failed", _CCM_VAC_DebugOperationStr(ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ]), _CCM_VAC_DebugOperationStr(ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 1 ]))); /* the current owner is indicated as the first operation */ *peOperation = ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ]; status = MCP_FALSE; } } MCP_FUNC_END (); return status; }
ECCM_VAC_Status _CCM_VAC_AllocationEngine_Configure (TCCM_VAC_AllocationEngine *ptAllocEngine, TCAL_ResourceSupport *ptAvailResources, TCAL_OperationSupport *ptAvailOperations) { McpConfigParserStatus eCPStatus; McpU32 uResourcesNum, uIndex; McpU8 *pTempValue; ECAL_Resource eResource; ECCM_VAC_Status status; MCP_FUNC_START ("_CCM_VAC_AllocationEngine_Configure"); MCP_UNUSED_PARAMETER (ptAvailOperations); /* configure available resources: */ /* 1. update all available external resources (read from ini file and compare with CAL) */ /* get number of resources from ini file */ eCPStatus = MCP_CONFIG_PARSER_GetIntegerKey (ptAllocEngine->pConfigParser, (McpU8 *)CCM_VAC_CONFIG_INI_RESOURCES_SECTION_NAME, (McpU8 *)CCM_VAC_CONFIG_INI_RESOURCES_NUMBER_KEY_NAME, (McpS32*)&uResourcesNum); MCP_VERIFY_FATAL (((eCPStatus == MCP_CONFIG_PARSER_STATUS_SUCCESS) && (0 < uResourcesNum)), CCM_VAC_STATUS_FAILURE_INVALID_CONFIGURATION, ("_CCM_VAC_AllocationEngine_Configure: error reading number of resources " "from file, number: %d, status: %d", uResourcesNum, eCPStatus)); /* for each resource */ for (uIndex = 0; uIndex < uResourcesNum; uIndex++) { /* read resource name */ eCPStatus = MCP_CONFIG_PARSER_GetAsciiKey (ptAllocEngine->pConfigParser, (McpU8 *)CCM_VAC_CONFIG_INI_RESOURCES_SECTION_NAME, (McpU8 *)CCM_VAC_CONFIG_INI_RESOURCE_NAME_KEY_NAME, &pTempValue); MCP_VERIFY_FATAL (((eCPStatus == MCP_CONFIG_PARSER_STATUS_SUCCESS) && (NULL != pTempValue)), CCM_VAC_STATUS_FAILURE_INVALID_CONFIGURATION, ("_CCM_VAC_AllocationEngine_Configure: Can't get resource name for resource number %d", uIndex)); /* convert to enum value */ eResource = StringtoResource (pTempValue); MCP_VERIFY_FATAL ((CAL_RESOURCE_INVALID != eResource), CCM_VAC_STATUS_FAILURE_INVALID_CONFIGURATION, ("_CCM_VAC_AllocationEngine_Configure: Can't convert resource number %d, " "string %s to enum value", uIndex, pTempValue)); /* verify it is available by the chip */ MCP_VERIFY_FATAL ((MCP_TRUE == ptAvailResources->bResourceSupport[ eResource ]), CCM_VAC_STATUS_FAILURE_INVALID_CONFIGURATION, ("_CCM_VAC_AllocationEngine_Configure: resource %s required by ini file" "is not supported by chip!", _CCM_VAC_DebugResourceStr(eResource))); /* and finally, mark it as enabled */ ptAllocEngine->tResources[ eResource ].bAvailable = MCP_TRUE; } /* 2. update all available internal resources (read from CAL) */ for (uIndex = CAL_RESOURCE_LAST_EX_RESOURCE + 1; uIndex < CAL_RESOURCE_MAX_NUM; uIndex++) { /* if the internal resource is supported by the chip, mark it as supported */ ptAllocEngine->tResources[ uIndex ].bAvailable = ptAvailResources->bResourceSupport[ uIndex ]; } MCP_FUNC_END (); return CCM_VAC_STATUS_SUCCESS; }
_CcmImStatus _CCM_IM_BtTranSm_InternalHandleEvent( _CcmIm_BtTranSm_Obj *thisObj, _CcmIm_BtTranSm_Event event, void *eventData) { _CcmImStatus status; _CcmIm_BtTranSm_Entry *smEntry; MCP_FUNC_START("_CCM_IM_BtTranSm_InternalHandleEvent"); MCP_VERIFY_FATAL((thisObj != NULL), _CCM_IM_STATUS_INVALID_PARM, ("_CCM_IM_BtTranSm_InternalHandleEvent: Null this")); MCP_VERIFY_FATAL((event < _CCM_IM_NUM_OF_BT_TRAN_SM_EVENTS), _CCM_IM_STATUS_INVALID_PARM, ("_CCM_IM_BtTranSm_InternalHandleEvent: Invalid event (%d)", event)); MCP_LOG_INFO(("_CCM_IM_BtTranSm_InternalHandleEvent: Handling SM{%s, %s}", _CCM_IM_BtTranSm_DebugStatetStr(thisObj->state), _CCM_IM_BtTranSm_DebugEventStr(event))); /* Extract the SM entry matching the current {state, event} */ smEntry = &_ccmIm_BtTranSm_Data.sm[thisObj->state][event]; MCP_VERIFY_FATAL((smEntry->action != NULL), _CCM_IM_STATUS_NULL_SM_ENTRY, ("_CCM_IM_BtTranSm_InternalHandleEvent: No matching SM Entry")); /* Transit to the next SM state */ thisObj->state = smEntry->nextState; /* The entry is valid, invoke the action */ status = (smEntry->action)(thisObj, eventData); if (status == _CCM_IM_STATUS_SUCCESS) { MCP_LOG_INFO(("_CCM_IM_BtTranSm_InternalHandleEvent: Action Completed Synchronously")); } else if (status == _CCM_IM_STATUS_PENDING) { thisObj->asyncCompletion = MCP_TRUE; } else { /* Action failed */ MCP_FATAL(status, ("_CCM_IM_BtTranSm_InternalHandleEvent")); } if (status == _CCM_IM_STATUS_SUCCESS) { MCP_VERIFY_FATAL((smEntry->syncNextEvent != _CCM_IM_INVALID_BT_TRAN_SM_EVENT), _CCM_IM_STATUS_INTERNAL_ERROR, ("_CCM_IM_BtTranSm_InternalHandleEvent: Missing syncNextEvent")); if (smEntry->syncNextEvent != _CCM_IM_BT_TRAN_SM_EVENT_NULL_EVENT) { status = _CCM_IM_BtTranSm_InternalHandleEvent(thisObj, smEntry->syncNextEvent, NULL); } } MCP_LOG_INFO(("_CCM_IM_BtTranSm_InternalHandleEvent: On Exit, State: %s", _CCM_IM_BtTranSm_DebugStatetStr(thisObj->state))); MCP_FUNC_END(); return status; }