XilinxProcessorIPLib/drivers/audio_formatter/src/xaudioformatter.c
void XAudioFormatterSetHwParams(XAudioFormatter *InstancePtr,
	XAudioFormatterHwParams *hw_params)
{
	u32 val;
	u32 offset;
	u32 bytes_per_ch;

	Xil_AssertVoid(InstancePtr != NULL);
	Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
	Xil_AssertVoid(hw_params != NULL);
	Xil_AssertVoid(hw_params->bits_per_sample <= BIT_DEPTH_32);
	Xil_AssertVoid(hw_params->periods >= XAUD_PERIODS_MIN &&
			hw_params->periods <= XAUD_PERIODS_MAX);
	Xil_AssertVoid(hw_params->bytes_per_period >= XAUD_PERIOD_BYTES_MIN &&
			hw_params->bytes_per_period <= XAUD_PERIOD_BYTES_MAX);
	if (InstancePtr->ChannelId == XAudioFormatter_S2MM) {
		Xil_AssertVoid(hw_params->active_ch >= XAUD_CHANNELS_MIN &&
			hw_params->active_ch <=
			InstancePtr->Config.MaxChannelsS2MM);
		offset = XAUD_FORMATTER_S2MM_OFFSET;
	}
	if (InstancePtr->ChannelId == XAudioFormatter_MM2S) {
		Xil_AssertVoid(hw_params->active_ch >= XAUD_CHANNELS_MIN &&
			hw_params->active_ch <=
			InstancePtr->Config.MaxChannelsMM2S);
		offset = XAUD_FORMATTER_MM2S_OFFSET;
	}
	XAudioFormatter_WriteReg(InstancePtr->BaseAddress,
		XAUD_FORMATTER_BUFF_ADDR_LSB + offset,
		(u32) hw_params->buf_addr);
	XAudioFormatter_WriteReg(InstancePtr->BaseAddress,
		XAUD_FORMATTER_BUFF_ADDR_MSB + offset,
		(u32) (hw_params->buf_addr >> 32));

	val = XAudioFormatter_ReadReg(InstancePtr->BaseAddress,
		XAUD_FORMATTER_CTRL + offset);
	val &= ~(XAUD_CTRL_DATA_WIDTH_MASK << XAUD_CTRL_DATA_WIDTH_SHIFT);
	switch (hw_params->bits_per_sample) {
		case BIT_DEPTH_8:
			val |= (BIT_DEPTH_8 << XAUD_CTRL_DATA_WIDTH_SHIFT);
			break;
		case BIT_DEPTH_16:
			val |= (BIT_DEPTH_16 << XAUD_CTRL_DATA_WIDTH_SHIFT);
			break;
		case BIT_DEPTH_20:
			val |= (BIT_DEPTH_20 << XAUD_CTRL_DATA_WIDTH_SHIFT);
			break;
		case BIT_DEPTH_24:
			val |= (BIT_DEPTH_24 << XAUD_CTRL_DATA_WIDTH_SHIFT);
			break;
		case BIT_DEPTH_32:
			val |= (BIT_DEPTH_32 << XAUD_CTRL_DATA_WIDTH_SHIFT);
			break;
	}

	val |= hw_params->active_ch << XAUD_CTRL_ACTIVE_CH_SHIFT;
	XAudioFormatter_WriteReg(InstancePtr->BaseAddress,
		XAUD_FORMATTER_CTRL + offset, val);

	val = (hw_params->periods << XAUD_PERIOD_CFG_PERIODS_SHIFT)
		| hw_params->bytes_per_period;
	XAudioFormatter_WriteReg(InstancePtr->BaseAddress,
		XAUD_FORMATTER_PERIOD_CONFIG + offset, val);
	bytes_per_ch = hw_params->bytes_per_period / hw_params->active_ch;
	XAudioFormatter_WriteReg(InstancePtr->BaseAddress,
		XAUD_FORMATTER_BYTES_PER_CH + offset, bytes_per_ch);
}
/*****************************************************************************/
/**
*
* This function sets the hw params for audio formatter core.
*
* @param	InstancePtr is a pointer to the XAudioFormatter instance.
* @param	hw_params is a pointer to the XAudioFormatterHwParams structure
*		which contains the no. of channels, bit width, no. of periods,
*		bytes per period, bytes per channel and buffer address.
*
* @return	None.
*
* @note		None.
*
******************************************************************************/
This function sets the hw params for audio formatter core.
This function sets the hw params for audio formatter core .
void XAudioFormatterSetHwParams(XAudioFormatter *InstancePtr,
	XAudioFormatterHwParams *hw_params)
{
	u32 val;
	u32 offset;
	u32 bytes_per_ch;
	Xil_AssertVoid(InstancePtr != NULL);
	Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
	Xil_AssertVoid(hw_params != NULL);
	Xil_AssertVoid(hw_params->bits_per_sample <= BIT_DEPTH_32);
	Xil_AssertVoid(hw_params->periods >= XAUD_PERIODS_MIN &&
			hw_params->periods <= XAUD_PERIODS_MAX);
	Xil_AssertVoid(hw_params->bytes_per_period >= XAUD_PERIOD_BYTES_MIN &&
			hw_params->bytes_per_period <= XAUD_PERIOD_BYTES_MAX);
	if (InstancePtr->ChannelId == XAudioFormatter_S2MM) {
		Xil_AssertVoid(hw_params->active_ch >= XAUD_CHANNELS_MIN &&
			hw_params->active_ch <=
			InstancePtr->Config.MaxChannelsS2MM);
		offset = XAUD_FORMATTER_S2MM_OFFSET;
	}
	if (InstancePtr->ChannelId == XAudioFormatter_MM2S) {
		Xil_AssertVoid(hw_params->active_ch >= XAUD_CHANNELS_MIN &&
			hw_params->active_ch <=
			InstancePtr->Config.MaxChannelsMM2S);
		offset = XAUD_FORMATTER_MM2S_OFFSET;
	}
	XAudioFormatter_WriteReg(InstancePtr->BaseAddress,
		XAUD_FORMATTER_BUFF_ADDR_LSB + offset,
		(u32) hw_params->buf_addr);
	XAudioFormatter_WriteReg(InstancePtr->BaseAddress,
		XAUD_FORMATTER_BUFF_ADDR_MSB + offset,
		(u32) (hw_params->buf_addr >> 32));
	val = XAudioFormatter_ReadReg(InstancePtr->BaseAddress,
		XAUD_FORMATTER_CTRL + offset);
	val &= ~(XAUD_CTRL_DATA_WIDTH_MASK << XAUD_CTRL_DATA_WIDTH_SHIFT);
	switch (hw_params->bits_per_sample) {
		case BIT_DEPTH_8:
			val |= (BIT_DEPTH_8 << XAUD_CTRL_DATA_WIDTH_SHIFT);
			break;
		case BIT_DEPTH_16:
			val |= (BIT_DEPTH_16 << XAUD_CTRL_DATA_WIDTH_SHIFT);
			break;
		case BIT_DEPTH_20:
			val |= (BIT_DEPTH_20 << XAUD_CTRL_DATA_WIDTH_SHIFT);
			break;
		case BIT_DEPTH_24:
			val |= (BIT_DEPTH_24 << XAUD_CTRL_DATA_WIDTH_SHIFT);
			break;
		case BIT_DEPTH_32:
			val |= (BIT_DEPTH_32 << XAUD_CTRL_DATA_WIDTH_SHIFT);
			break;
	}
	val |= hw_params->active_ch << XAUD_CTRL_ACTIVE_CH_SHIFT;
	XAudioFormatter_WriteReg(InstancePtr->BaseAddress,
		XAUD_FORMATTER_CTRL + offset, val);
	val = (hw_params->periods << XAUD_PERIOD_CFG_PERIODS_SHIFT)
		| hw_params->bytes_per_period;
	XAudioFormatter_WriteReg(InstancePtr->BaseAddress,
		XAUD_FORMATTER_PERIOD_CONFIG + offset, val);
	bytes_per_ch = hw_params->bytes_per_period / hw_params->active_ch;
	XAudioFormatter_WriteReg(InstancePtr->BaseAddress,
		XAUD_FORMATTER_BYTES_PER_CH + offset, bytes_per_ch);
}
void XAudioFormatterSetHwParams ( XAudioFormatter * InstancePtr , XAudioFormatterHwParams * hw_params ) { u32 val ; u32 offset ; u32 bytes_per_ch ; Xil_AssertVoid ( InstancePtr != NULL ) ; Xil_AssertVoid ( InstancePtr -> IsReady == XIL_COMPONENT_IS_READY ) ; Xil_AssertVoid ( hw_params != NULL ) ; Xil_AssertVoid ( hw_params -> bits_per_sample <= BIT_DEPTH_32 ) ; Xil_AssertVoid ( hw_params -> periods >= XAUD_PERIODS_MIN && hw_params -> periods <= XAUD_PERIODS_MAX ) ; Xil_AssertVoid ( hw_params -> bytes_per_period >= XAUD_PERIOD_BYTES_MIN && hw_params -> bytes_per_period <= XAUD_PERIOD_BYTES_MAX ) ; if ( InstancePtr -> ChannelId == XAudioFormatter_S2MM ) { Xil_AssertVoid ( hw_params -> active_ch >= XAUD_CHANNELS_MIN && hw_params -> active_ch <= InstancePtr -> Config . MaxChannelsS2MM ) ; offset = XAUD_FORMATTER_S2MM_OFFSET ; } if ( InstancePtr -> ChannelId == XAudioFormatter_MM2S ) { Xil_AssertVoid ( hw_params -> active_ch >= XAUD_CHANNELS_MIN && hw_params -> active_ch <= InstancePtr -> Config . MaxChannelsMM2S ) ; offset = XAUD_FORMATTER_MM2S_OFFSET ; } XAudioFormatter_WriteReg ( InstancePtr -> BaseAddress , XAUD_FORMATTER_BUFF_ADDR_LSB + offset , ( u32 ) hw_params -> buf_addr ) ; XAudioFormatter_WriteReg ( InstancePtr -> BaseAddress , XAUD_FORMATTER_BUFF_ADDR_MSB + offset , ( u32 ) ( hw_params -> buf_addr >> 32 ) ) ; val = XAudioFormatter_ReadReg ( InstancePtr -> BaseAddress , XAUD_FORMATTER_CTRL + offset ) ; val &= ~ ( XAUD_CTRL_DATA_WIDTH_MASK << XAUD_CTRL_DATA_WIDTH_SHIFT ) ; switch ( hw_params -> bits_per_sample ) { case BIT_DEPTH_8 : val |= ( BIT_DEPTH_8 << XAUD_CTRL_DATA_WIDTH_SHIFT ) ; break ; case BIT_DEPTH_16 : val |= ( BIT_DEPTH_16 << XAUD_CTRL_DATA_WIDTH_SHIFT ) ; break ; case BIT_DEPTH_20 : val |= ( BIT_DEPTH_20 << XAUD_CTRL_DATA_WIDTH_SHIFT ) ; break ; case BIT_DEPTH_24 : val |= ( BIT_DEPTH_24 << XAUD_CTRL_DATA_WIDTH_SHIFT ) ; break ; case BIT_DEPTH_32 : val |= ( BIT_DEPTH_32 << XAUD_CTRL_DATA_WIDTH_SHIFT ) ; break ; } val |= hw_params -> active_ch << XAUD_CTRL_ACTIVE_CH_SHIFT ; XAudioFormatter_WriteReg ( InstancePtr -> BaseAddress , XAUD_FORMATTER_CTRL + offset , val ) ; val = ( hw_params -> periods << XAUD_PERIOD_CFG_PERIODS_SHIFT ) | hw_params -> bytes_per_period ; XAudioFormatter_WriteReg ( InstancePtr -> BaseAddress , XAUD_FORMATTER_PERIOD_CONFIG + offset , val ) ; bytes_per_ch = hw_params -> bytes_per_period / hw_params -> active_ch ; XAudioFormatter_WriteReg ( InstancePtr -> BaseAddress , XAUD_FORMATTER_BYTES_PER_CH + offset , bytes_per_ch ) ; }
This function sets the hw params for audio formatter core.
This function sets the hw params for audio formatter core .