XilinxProcessorIPLib/drivers/v_hdmitx/src/xv_hdmitx.c
int XV_HdmiTx_SetAudioChannels(XV_HdmiTx *InstancePtr, u8 Value)
{
    u32 Data;
    u32 Status;
    u8 AudioStatus;
    u32 AudioCtrl;

    AudioCtrl = XV_HdmiTx_ReadReg((InstancePtr)->Config.BaseAddress,
			XV_HDMITX_AUD_CTRL_OFFSET);

    AudioStatus = AudioCtrl & XV_HDMITX_AUD_CTRL_RUN_MASK;

    // Stop peripheral
    XV_HdmiTx_WriteReg((InstancePtr)->Config.BaseAddress,
        (XV_HDMITX_AUD_CTRL_CLR_OFFSET), (XV_HDMITX_AUD_CTRL_RUN_MASK));
    AudioCtrl &= ~((u32)XV_HDMITX_AUD_CTRL_RUN_MASK);

    switch (Value) {
	// 32 Channels
	case 32:
            Data = 6;
            Status = (XST_SUCCESS);
            break;

	// 24 Channels
	case 24:
            Data = 5;
            Status = (XST_SUCCESS);
            break;

	// 12 Channels
	case 12:
            Data = 4;
            Status = (XST_SUCCESS);
            break;

        // 8 Channels
        case 8:
            Data = 3;
            Status = (XST_SUCCESS);
            break;

        // 6 Channels
        case 6:
            Data = 2;
            Status = (XST_SUCCESS);
            break;

        // 4 Channels
        case 4:
            Data = 1;
            Status = (XST_SUCCESS);
            break;

        // 2 Channels
        case 2:
            Data = 0;
            Status = (XST_SUCCESS);
            break;

        default :
            Status = (XST_FAILURE);
            break;
    }

    if (Status == (XST_SUCCESS)) {
	Data &= XV_HDMITX_AUD_CTRL_CH_MASK;
        Data <<= XV_HDMITX_AUD_CTRL_CH_SHIFT;

        AudioCtrl &= ~((u32)(XV_HDMITX_AUD_CTRL_CH_MASK <<
			XV_HDMITX_AUD_CTRL_CH_SHIFT));
        AudioCtrl |= Data;

        // Set active channels
        XV_HdmiTx_WriteReg((InstancePtr)->Config.BaseAddress,
            (XV_HDMITX_AUD_CTRL_OFFSET), (AudioCtrl));

        // Store active channel in structure
        (InstancePtr)->Stream.Audio.Channels = Value;

        // Start peripheral
        if (AudioStatus) {
			XV_HdmiTx_WriteReg((InstancePtr)->Config.BaseAddress,
					(XV_HDMITX_AUD_CTRL_SET_OFFSET),
					(XV_HDMITX_AUD_CTRL_RUN_MASK));
        }
    }

    return Status;
}
/*****************************************************************************/
/**
*
* This function sets the active audio channels
*
* @param    InstancePtr is a pointer to the XV_HdmiTx core instance.
*
* @return
*       - XST_SUCCESS if active channels were set.
*       - XST_FAILURE if no active channles were set.
*
* @note     None.
*
******************************************************************************/
This function sets the active audio channels
This function sets the active audio channels
int XV_HdmiTx_SetAudioChannels(XV_HdmiTx *InstancePtr, u8 Value)
{
    u32 Data;
    u32 Status;
    u8 AudioStatus;
    u32 AudioCtrl;
    AudioCtrl = XV_HdmiTx_ReadReg((InstancePtr)->Config.BaseAddress,
			XV_HDMITX_AUD_CTRL_OFFSET);
    AudioStatus = AudioCtrl & XV_HDMITX_AUD_CTRL_RUN_MASK;
    XV_HdmiTx_WriteReg((InstancePtr)->Config.BaseAddress,
        (XV_HDMITX_AUD_CTRL_CLR_OFFSET), (XV_HDMITX_AUD_CTRL_RUN_MASK));
    AudioCtrl &= ~((u32)XV_HDMITX_AUD_CTRL_RUN_MASK);
    switch (Value) {
	case 32:
            Data = 6;
            Status = (XST_SUCCESS);
            break;
	case 24:
            Data = 5;
            Status = (XST_SUCCESS);
            break;
	case 12:
            Data = 4;
            Status = (XST_SUCCESS);
            break;
        case 8:
            Data = 3;
            Status = (XST_SUCCESS);
            break;
        case 6:
            Data = 2;
            Status = (XST_SUCCESS);
            break;
        case 4:
            Data = 1;
            Status = (XST_SUCCESS);
            break;
        case 2:
            Data = 0;
            Status = (XST_SUCCESS);
            break;
        default :
            Status = (XST_FAILURE);
            break;
    }
    if (Status == (XST_SUCCESS)) {
	Data &= XV_HDMITX_AUD_CTRL_CH_MASK;
        Data <<= XV_HDMITX_AUD_CTRL_CH_SHIFT;
        AudioCtrl &= ~((u32)(XV_HDMITX_AUD_CTRL_CH_MASK <<
			XV_HDMITX_AUD_CTRL_CH_SHIFT));
        AudioCtrl |= Data;
        XV_HdmiTx_WriteReg((InstancePtr)->Config.BaseAddress,
            (XV_HDMITX_AUD_CTRL_OFFSET), (AudioCtrl));
        (InstancePtr)->Stream.Audio.Channels = Value;
        if (AudioStatus) {
			XV_HdmiTx_WriteReg((InstancePtr)->Config.BaseAddress,
					(XV_HDMITX_AUD_CTRL_SET_OFFSET),
					(XV_HDMITX_AUD_CTRL_RUN_MASK));
        }
    }
    return Status;
}
int XV_HdmiTx_SetAudioChannels ( XV_HdmiTx * InstancePtr , u8 Value ) { u32 Data ; u32 Status ; u8 AudioStatus ; u32 AudioCtrl ; AudioCtrl = XV_HdmiTx_ReadReg ( ( InstancePtr ) -> Config . BaseAddress , XV_HDMITX_AUD_CTRL_OFFSET ) ; AudioStatus = AudioCtrl & XV_HDMITX_AUD_CTRL_RUN_MASK ; XV_HdmiTx_WriteReg ( ( InstancePtr ) -> Config . BaseAddress , ( XV_HDMITX_AUD_CTRL_CLR_OFFSET ) , ( XV_HDMITX_AUD_CTRL_RUN_MASK ) ) ; AudioCtrl &= ~ ( ( u32 ) XV_HDMITX_AUD_CTRL_RUN_MASK ) ; switch ( Value ) { case 32 : Data = 6 ; Status = ( XST_SUCCESS ) ; break ; case 24 : Data = 5 ; Status = ( XST_SUCCESS ) ; break ; case 12 : Data = 4 ; Status = ( XST_SUCCESS ) ; break ; case 8 : Data = 3 ; Status = ( XST_SUCCESS ) ; break ; case 6 : Data = 2 ; Status = ( XST_SUCCESS ) ; break ; case 4 : Data = 1 ; Status = ( XST_SUCCESS ) ; break ; case 2 : Data = 0 ; Status = ( XST_SUCCESS ) ; break ; default : Status = ( XST_FAILURE ) ; break ; } if ( Status == ( XST_SUCCESS ) ) { Data &= XV_HDMITX_AUD_CTRL_CH_MASK ; Data <<= XV_HDMITX_AUD_CTRL_CH_SHIFT ; AudioCtrl &= ~ ( ( u32 ) ( XV_HDMITX_AUD_CTRL_CH_MASK << XV_HDMITX_AUD_CTRL_CH_SHIFT ) ) ; AudioCtrl |= Data ; XV_HdmiTx_WriteReg ( ( InstancePtr ) -> Config . BaseAddress , ( XV_HDMITX_AUD_CTRL_OFFSET ) , ( AudioCtrl ) ) ; ( InstancePtr ) -> Stream . Audio . Channels = Value ; if ( AudioStatus ) { XV_HdmiTx_WriteReg ( ( InstancePtr ) -> Config . BaseAddress , ( XV_HDMITX_AUD_CTRL_SET_OFFSET ) , ( XV_HDMITX_AUD_CTRL_RUN_MASK ) ) ; } } return Status ; }
This function sets the active audio channels
This function sets the active audio channels
// Stop peripheral // 32 Channels // 24 Channels // 12 Channels // 8 Channels // 6 Channels // 4 Channels // 2 Channels // Set active channels // Store active channel in structure // Start peripheral