// ==========================================================================
//
// Function Name: ConfigDMA
//
// Description: Configure DMA channel 
//
// =========================================================================
static Result_t ConfigDMA (
			UInt32 channel, 
			UInt8 *start, 
			UInt32 numBlocks, 
			UInt32 blockSize, 
			OSDAL_DMA_CLIENT dstClient, 
			OSDAL_DMA_DWIDTH dataWidth, 
			OSDAL_DMA_CALLBACK dmaCB)
{
	OSDAL_Dma_Data dmaData;
	OSDAL_Dma_Buffer_List *cirBufList;
	OSDAL_Dma_Chan_Info chanInfo;
	UInt32 i=0;
	UInt8	*currPos=NULL;
	UInt8	*dstAddr=NULL;

	// Configure DMA channel
    //chanInfo.chanNumber = channel;
    //chanInfo.prot = 0;
    //chanInfo.srcID = OSDAL_DMA_CLIENT_MEMORY;
    //chanInfo.dstID = dstClient;
    chanInfo.type = OSDAL_DMA_FCTRL_MEM_TO_PERI;//_CTRL_PERI;   // need to double check.
    chanInfo.srcBstSize = OSDAL_DMA_BURST_SIZE_64; // audio fifo spec
    chanInfo.dstBstSize = OSDAL_DMA_BURST_SIZE_64;
	chanInfo.srcDataWidth = dataWidth;
	chanInfo.dstDataWidth = dataWidth;
	chanInfo.incMode = OSDAL_DMA_INC_MODE_SRC; // mode_src
    chanInfo.xferCompleteCb = dmaCB;
    chanInfo.freeChan = FALSE;
    chanInfo.bCircular = TRUE;

    if(OSDAL_DMA_Config_Channel(channel, &chanInfo) != OSDAL_ERR_OK)
    {
        Log_DebugPrintf(LOGID_SOC_AUDIO,  "ConfigDMA:: Error, Configure channel failed.\n");
        return RESULT_ERROR;
    }


	switch (dstClient)
	{
		case OSDAL_DMA_CLIENT_AUDIO_OUT_FIFO:
			dstAddr = (UInt8 *) chal_audioaopath_getAFIFO_addr( NULL );
			break;
		
		case OSDAL_DMA_CLIENT_POLYRING_OUT_FIFO:
			dstAddr = (UInt8 *) chal_audiopopath_getPFIFO_addr( NULL );
			break;

		default:
			Log_DebugPrintf(LOGID_SOC_AUDIO,  "ConfigDMA:: Error, Wrong destination client, dstClient = 0x%x.\n", dstClient);
			break;
		
	}

	cirBufList = (OSDAL_Dma_Buffer_List *)OSDAL_ALLOCHEAPMEM(numBlocks * sizeof(OSDAL_Dma_Buffer_List));

	currPos = start;
	for (i = 0; i < numBlocks; i++)
	{
		cirBufList[i].buffers[0].srcAddr = (UInt32)currPos;
		cirBufList[i].buffers[0].destAddr = (UInt32)dstAddr;
		cirBufList[i].buffers[0].length = blockSize;
		cirBufList[i].buffers[0].bRepeat = 0;
		cirBufList[i].buffers[0].interrupt = 1;

		currPos += blockSize;
	}

	
	dmaData.numBuffer = numBlocks;
    dmaData.pBufList = (OSDAL_Dma_Buffer_List *)cirBufList;  
    if(OSDAL_DMA_Bind_Data(channel, &dmaData) != OSDAL_ERR_OK)
    {
        Log_DebugPrintf(LOGID_SOC_AUDIO,  "ConfigDMA:: Error, Add buffer failed.\n");
        return RESULT_ERROR;
    }

	OSDAL_FREEHEAPMEM (cirBufList);

	return RESULT_OK;
}
예제 #2
0
/* ****************************************************************************** */
static CHAL_DMA_STATUS_t dma_ucode_free(chal_dmac_ucode_t * ucode)
{
	OSDAL_FREEHEAPMEM((UInt32 *) ucode->vir_addr);

	return CHAL_DMA_STATUS_SUCCESS;
}
예제 #3
0
//============================================================================
//
// Function Name: AUDIO_DRIVER_Close
//
// Description:   This function is used to close the audio data driver
//
//============================================================================
void AUDIO_DRIVER_Close(AUDIO_DRIVER_HANDLE_t drv_handle)
{
    AUDIO_DDRIVER_t*  aud_drv = (AUDIO_DDRIVER_t*)drv_handle;
    Log_DebugPrintf(LOGID_AUDIO,"AUDIO_DRIVER_Close::  \n"  );

    if(aud_drv == NULL)
    {
        Log_DebugPrintf(LOGID_AUDIO,"AUDIO_DRIVER_Close::Invalid Handle  \n"  );
        return;
    }

    if ( aud_drv->tmp_buffer )
        OSDAL_FREEHEAPMEM(aud_drv->tmp_buffer);

    switch (aud_drv->drv_type)
    {
        case AUDIO_DRIVER_PLAY_VOICE:
        case AUDIO_DRIVER_PLAY_AUDIO:
        case AUDIO_DRIVER_PLAY_RINGER:
            {
                // un initialize audvoc render
                //csl_audio_render_deinit (aud_drv->stream_id);
                audio_render_driver = NULL;
            }
            break;
        case AUDIO_DRIVER_CAPT_HQ:
            {
                //csl_audio_capture_deinit (aud_drv->stream_id);
                audio_capture_driver = NULL;
            }
            break;
        case AUDIO_DRIVER_CAPT_VOICE:
            {
                dspif_VPU_record_deinit ();
                audio_capture_driver = NULL;
            }
            break;
        case AUDIO_DRIVER_CAPT_FM:
            {
                if( aud_drv->i2s_handle )
                {
                    I2S_STATE state;
                    state = I2SDRV_Get_rx_state (aud_drv->i2s_handle);
                    if (state == I2STST_STREAMING || state == I2STST_READY)
                    {
                        Log_DebugPrintf(LOGID_AUDIO, "AUDIO_DRIVER_ProcessCaptureFMCmd call I2SDRV_Stop_rxDMA.\n");
                        I2SDRV_Stop_rxDMA(aud_drv->i2s_handle);
                        aud_drv->i2s_handle = NULL;
                    }
                }
                audio_capture_driver = NULL;
            }
            break;

        case AUDIO_DRIVER_VOIP:
            {
                audio_voip_driver = NULL;
            }
            break;

        default:
            Log_DebugPrintf(LOGID_AUDIO,"AUDIO_DRIVER_Close::Unsupported driver  \n"  );
            break;
    }
    //free the driver structure
    OSDAL_FREEHEAPMEM(aud_drv);
    return;  
}
// ==========================================================================
//
// Function Name: ConfigDMA
//
// Description: Configure DMA channel 
//
// =========================================================================
static Result_t ConfigDMA(
			UInt32 channel, 
			UInt8 *start, 
			UInt32 numBlocks, 
			UInt32 blockSize, 
			OSDAL_DMA_CLIENT srcClient,
			OSDAL_DMA_DWIDTH dataWidth,
			OSDAL_DMA_CALLBACK dmaCB)
{
	OSDAL_Dma_Data dmaData;
	OSDAL_Dma_Buffer_List *cirBufList;
	OSDAL_Dma_Chan_Info chanInfo;
	UInt32 i=0;
	UInt8	*currPos = 0;
	UInt8	*srcAddr = 0;

    Log_DebugPrintf(LOGID_AUDIO, "ConfigDMA:: channel: 0x%x, numBlocks = 0x%x, blockSize = 0x%x\n", channel, numBlocks, blockSize);

	// Configure DMA channel
    //chanInfo.chanNumber = channel;
    //chanInfo.prot = 0;
    //chanInfo.srcID = srcClient;
    //chanInfo.dstID = DMA_CLIENT_MEMORY;
    chanInfo.type = OSDAL_DMA_FCTRL_PERI_TO_MEM;
/* [email protected] 2012.07.03 begin */
//DMA issue:obtain semaphore timeout  
//CSP#523614  
    chanInfo.srcBstSize = OSDAL_DMA_BURST_SIZE_16; // audio fifo spec
    chanInfo.dstBstSize = OSDAL_DMA_BURST_SIZE_16;
/* [email protected] 2012.07.03 end */
    chanInfo.srcDataWidth = dataWidth;
    chanInfo.dstDataWidth = dataWidth;
    chanInfo.srcMaster = 0;
    chanInfo.dstMaster = 0;
    chanInfo.incMode = OSDAL_DMA_INC_MODE_DST; // mode_dst
    chanInfo.xferCompleteCb = dmaCB;
    chanInfo.freeChan = FALSE;
    chanInfo.bCircular = TRUE;
   
    if(OSDAL_DMA_Config_Channel(channel, &chanInfo) != OSDAL_ERR_OK)
    {
        Log_DebugPrintf(LOGID_AUDIO, "ConfigDMA:: Error, Configure channel failed.\n");
        return RESULT_ERROR;
    }


	switch (srcClient)
	{
		case OSDAL_DMA_CLIENT_AUDIO_IN_FIFO:
			srcAddr = (UInt8 *) chal_audioaipath_getAFIFO_addr( NULL );
			break;
		
		case OSDAL_DMA_CLIENT_AUDIO_WB_MIXERTAP:
			srcAddr = (UInt8 *) chal_audiomixertap_getAFIFO_addr( NULL );
			break;

		default:
			Log_DebugPrintf(LOGID_AUDIO, "ConfigDMA:: Error, Wrong source client, srcClient = 0x%x.\n", srcClient);
			break;
		
	}

	cirBufList = (OSDAL_Dma_Buffer_List *)OSDAL_ALLOCHEAPMEM(numBlocks * sizeof(OSDAL_Dma_Buffer_List));

	currPos = start;
	for (i = 0; i < numBlocks; i++)
	{
		cirBufList[i].buffers[0].srcAddr = (UInt32)srcAddr;
		cirBufList[i].buffers[0].destAddr = (UInt32)currPos;
		cirBufList[i].buffers[0].length = blockSize;
		cirBufList[i].buffers[0].bRepeat = 0;
		cirBufList[i].buffers[0].interrupt = 1;

		currPos += blockSize;
	}

	dmaData.numBuffer = numBlocks;
    dmaData.pBufList = (OSDAL_Dma_Buffer_List *)cirBufList;  
    if(OSDAL_DMA_Bind_Data(channel, &dmaData) != OSDAL_ERR_OK)
    {
        Log_DebugPrintf(LOGID_AUDIO, "ConfigDMA:: Error, Add buffer failed.\n");
        return RESULT_ERROR;
    }

	OSDAL_FREEHEAPMEM (cirBufList);

	return RESULT_OK;
}