Exemple #1
0
PACKET_BufHandle_t RPC_PACKET_AllocateBufferEx(PACKET_InterfaceType_t interfaceType, UInt32 requiredSize, UInt8 channel, UInt32 waitTime)
{
	int index = -1;
	IPC_Buffer bufHandle = 0;

	//Determine the pool index for the interface
	if( interfaceType == INTERFACE_PACKET)
	{
		index = 0;//All channels use the same buffer pool
	}
	else
	{
		for(index=0; index < MAX_CHANNELS; index++)
		{
			if(ipcBufList[interfaceType].pkt_size[index] >= requiredSize)
				break;
		}
		if(index >= MAX_CHANNELS)
		{
			_DBG_(RPC_TRACE("RPC_PACKET_AllocateBuffer itype=%d invalid channel %d\r\n",interfaceType, index));
			return NULL;
		}
	}

	//Create the pool om demand
	if(ipcInfoList[interfaceType].ipc_buf_pool[index] == 0)
		RPC_CreateBufferPool(interfaceType, index);
	
	if(interfaceType == INTERFACE_PACKET && DETAIL_DATA_LOG_ENABLED)
		_DBG_(RPC_TRACE_DATA_DETAIL("RPC_PACKET_AllocateBuffer(%c) PKT BEFORE %d\r\n",(gRpcProcType == RPC_COMMS)?'C':'A',requiredSize));

	if(waitTime == PKT_ALLOC_NOWAIT)
		bufHandle = IPC_AllocateBuffer(ipcInfoList[interfaceType].ipc_buf_pool[index]);
	else
		bufHandle = IPC_AllocateBufferWait(ipcInfoList[interfaceType].ipc_buf_pool[index], waitTime);
	
	if(interfaceType == INTERFACE_PACKET && DETAIL_DATA_LOG_ENABLED)
		_DBG_(RPC_TRACE_DATA_DETAIL("RPC_PACKET_AllocateBuffer(%c) PKT AFTER %d\r\n",(gRpcProcType == RPC_COMMS)?'C':'A',requiredSize));
	

	if(0 == bufHandle)
	{
		_DBG_(RPC_TRACE("RPC_PACKET_AllocateBuffer failed %d, %d, %d\r\n", interfaceType, requiredSize, index));
	}

	if(bufHandle)
		IPC_BufferSetDataSize(bufHandle, requiredSize);

	return (PACKET_BufHandle_t)bufHandle;
}
int brcm_ipc_aud_control_send(const void * const buff, UInt32 len)
{
        IPC_Buffer buffer;

        buffer = IPC_AllocateBuffer(brcm_ApAudioPool);

        if (buffer) {
                if (0 == (IPC_BufferSetDataSize(buffer, len))) {
                        return 1;
                }

                memcpy(IPC_BufferDataPointer(buffer), buff, len);
                IPC_SendBuffer(buffer, IPC_PRIORITY_DEFAULT);

        } else {
                pr_info(__AUD"IPC_AudioControlSend: Pool Empty\n");
                return 1;
        }
        return 0;
}
IPC_Buffer IPC_AllocateBufferWait(IPC_BufferPool Pool, IPC_U32 MilliSeconds)
{
	IPC_BufferPool_T *PoolPtr = IPC_PoolToPtr(Pool);
	IPC_Buffer Buffer;
	IPC_ReturnCode_T errCode;
	UInt32 curTick, endTick;
	UInt32 beforeTick, afterTick;

	curTick = 0;
	endTick = MilliSeconds;

	while (curTick < endTick) {
		/* Try straight allocate first
		   (saves event operations most of the time) */
		Buffer = IPC_AllocateBuffer(Pool);
		if (Buffer)
			return Buffer;

		/* Check Event exists */
		if (!PoolPtr->EmptyEvent) {
			/* Can't suspend without an event flag */
			IPC_TRACE(IPC_Channel_Error, "IPC_AllocateBufferWait",
				  "No Event Flag for Pool %08X", Pool, 0, 0, 0);
			return 0;
		}

		/* Clear event before waiting on it */
		if (IPC_OK != IPC_EVENT_CLEAR(PoolPtr->EmptyEvent)) {
			IPC_TRACE(IPC_Channel_Error, "IPC_AllocateBufferWait",
				  "Cannot clear Event Flag %08P for Pool %08X",
				  PoolPtr->EmptyEvent, Pool, 0, 0);
			return 0;
		}

		/* Check in case the event was set  before the clear */
		Buffer = IPC_AllocateBuffer(Pool);
		if (Buffer)
			return Buffer;

		/* Now can safely wait for the event to be set
		 * by the buffer free */
		IPC_TRACE(IPC_Channel_FlowControl, "IPC_AllocateBufferWait",
			  "Pool %08X Empty, waiting for %d Milliseconds, total=%d",
			  Pool, (endTick - curTick), MilliSeconds, 0);

		beforeTick = TIMER_GetValue();
		errCode =
		    IPC_EVENT_WAIT(PoolPtr->EmptyEvent, (endTick - curTick));
		afterTick = TIMER_GetValue();

		/* Handle wrap around for 0xFFFFFFFF */
		curTick += (UInt32)(afterTick - beforeTick);

		if (IPC_ERROR == errCode) {
			IPC_TRACE(IPC_Channel_Error, "IPC_AllocateBufferWait",
				  "Error from IPC_EVENT_WAIT; Event Flag %08P for Pool %08X",
				  PoolPtr->EmptyEvent, Pool, 0, 0);
			return 0;
		} else if (IPC_OK == errCode) {
			continue;	/* retry */
		} else {	/* IPC_TIMEOUT */
			break;
		}
	}

	return IPC_AllocateBuffer(Pool);
}