XilinxProcessorIPLib/drivers/v_sditx/src/xv_sditx.c
u32 XV_SdiTx_GetPayload(XV_SdiTx *InstancePtr, XVidC_VideoMode VideoMode, XSdiVid_TransMode SdiMode, u8 DataStream)
{
	u32 Data = 0, Status;
	u8 Byte1;
	u16 VActiveValid;
	const XVidC_VideoTiming *TimingPtr;
	XVidC_FrameRate FrameRateValid;

	if (SdiMode == XSDIVID_MODE_3GB)
		InstancePtr->Stream[DataStream].CAssignment = (DataStream << 1);
	else
		InstancePtr->Stream[DataStream].CAssignment = 0;

	TimingPtr = XVidC_GetTimingInfo((u32)VideoMode);
	if (!TimingPtr) {
		return XST_FAILURE;
	}

	if (InstancePtr->Stream[DataStream].Video.IsInterlaced) {
		VActiveValid = TimingPtr->VActive * 2;;
		FrameRateValid = InstancePtr->Stream[DataStream].Video.FrameRate/2;
	} else {
		VActiveValid = TimingPtr->VActive;
		FrameRateValid = InstancePtr->Stream[DataStream].Video.FrameRate;
	}
	Status = XV_SdiTx_GetPayloadByte1(VActiveValid, SdiMode, &Byte1);
	if (Status == XST_FAILURE)
		return Status;

	Data = Byte1;
	Data |=	XV_SDITX_COLORFORMAT;

	if (InstancePtr->bitdepth == 12)
		Data |=	XV_SDITX_COLORDEPTH_12;
	else
		Data |=	XV_SDITX_COLORDEPTH_10;

	Data |=	(XV_SdiTx_GetPayloadFrameRate(FrameRateValid, InstancePtr->Transport.IsFractional) << 8);

	/* Bit 6 and Bit 7 of st352 byte 2 tells about progressive or interlaced
	 * transport and picture structures. Read Chapter 5.3 of
	 * SMPTE ST 352:2013 document.
	 */
	if (InstancePtr->Stream[DataStream].IsPsF) {
		Data |= (0x1 << XST352_BYTE2_PIC_TYPE_SHIFT);
		Data &= ~(0x1 << XST352_BYTE2_TS_TYPE_SHIFT);
	} else {
		Data |=	(XV_SdiTx_GetPayloadIsInterlaced(InstancePtr->Stream[DataStream].Video.IsInterlaced) << XST352_BYTE2_PIC_TYPE_SHIFT);
		if ((InstancePtr->Stream[DataStream].Video.Timing.F0PVTotal >= 1125) &&
			(SdiMode != XSDIVID_MODE_3GB))
			Data |=	(XV_SdiTx_GetPayloadIsInterlaced(InstancePtr->Stream[DataStream].Video.IsInterlaced) << XST352_BYTE2_TS_TYPE_SHIFT);
	}

	if( ( (SdiMode == XSDIVID_MODE_3GA)  && (InstancePtr->Transport.IsLevelB3G == 1) ) ||
		 (SdiMode == XSDIVID_MODE_3GB) )
	{
		Data |= 1 << XST352_BYTE2_PIC_TYPE_SHIFT;
		Data |= 0 << XST352_BYTE2_TS_TYPE_SHIFT;
	}

	Data |= (XV_SdiTx_GetPayloadEotf(InstancePtr, InstancePtr->Stream[DataStream].Video.Eotf,
			InstancePtr->Stream[DataStream].Video.ColorStd));

	Data |=	 (XV_SdiTx_GetPayloadColorFormat(SdiMode, InstancePtr->Stream[DataStream].Video.ColorFormatId) <<
												XST352_BYTE3_COLOR_FORMAT_SHIFT);

	Data |=	 (XV_SdiTx_GetPayloadAspectRatio(InstancePtr->Stream[DataStream].Video.AspectRatio) <<
												XST352_BYTE3_ASPECT_RATIO_SHIFT);

	/*for 4096 or 2048 horizontal pixels, set BIT(6) of byte 3 to 1.
	 * Refer Table 3 SMPTE ST 2081-10.
	 */
	if (InstancePtr->Stream[DataStream].Video.Timing.HActive == 2048 ||
		InstancePtr->Stream[DataStream].Video.Timing.HActive == 4096)
		Data |= 0x1 << XST352_BYTE3_ACT_LUMA_COUNT_SHIFT;
	else if (InstancePtr->Stream[DataStream].Video.Timing.HActive == 1920)
		Data |= 0x1 << XST352_BYTE3_BIT5_SHIFT;
	else if (InstancePtr->Stream[DataStream].Video.Timing.HActive == 3840)
		Data |= 0x1 << XST352_BYTE3_BIT7_SHIFT;
	else
		Data |= 0x0 << XST352_BYTE3_BIT5_SHIFT;

	Data |=	 ((InstancePtr->Stream[DataStream].CAssignment & 0x7) << 29);

	if (SdiMode == XSDIVID_MODE_3GB)
		Data |= (DataStream << 1) << XSDI_CH_SHIFT;
	InstancePtr->Stream[DataStream].PayloadId = Data;
	return XST_SUCCESS;
}
/*****************************************************************************/
/**
 *
 * This function calculates the final st352 payload value for all SDI modes
 * with given video mode and SDI data stream number
 *
 * @param	InstancePtr is a pointer to the XV_SdiTx core instance.
 * @param	VideoMode is a variable of type XVidC_VideoMode.
 * @param	SdiMode is a variable of type XSdiVid_TransMode.
 * @param	DataStream is the stream number for which payload is calculated.
 *
 * @return
*		XST_SUCCESS / XST_FAILURE.
 *
 * @note		None.
 *
 ******************************************************************************/
This function calculates the final st352 payload value for all SDI modes
with given video mode and SDI data stream number

@param       InstancePtr is a pointer to the XV_SdiTx core instance.
@param       VideoMode is a variable of type XVidC_VideoMode.
@param       SdiMode is a variable of type XSdiVid_TransMode.
@param       DataStream is the stream number for which payload is calculated.



@note                None.
This function calculates the final st352 payload value for all SDI modes with given video mode and SDI data stream number @param InstancePtr is a pointer to the XV_SdiTx core instance . @param VideoMode is a variable of type XVidC_VideoMode . @param SdiMode is a variable of type XSdiVid_TransMode . @param DataStream is the stream number for which payload is calculated . @note None .
u32 XV_SdiTx_GetPayload(XV_SdiTx *InstancePtr, XVidC_VideoMode VideoMode, XSdiVid_TransMode SdiMode, u8 DataStream)
{
	u32 Data = 0, Status;
	u8 Byte1;
	u16 VActiveValid;
	const XVidC_VideoTiming *TimingPtr;
	XVidC_FrameRate FrameRateValid;
	if (SdiMode == XSDIVID_MODE_3GB)
		InstancePtr->Stream[DataStream].CAssignment = (DataStream << 1);
	else
		InstancePtr->Stream[DataStream].CAssignment = 0;
	TimingPtr = XVidC_GetTimingInfo((u32)VideoMode);
	if (!TimingPtr) {
		return XST_FAILURE;
	}
	if (InstancePtr->Stream[DataStream].Video.IsInterlaced) {
		VActiveValid = TimingPtr->VActive * 2;;
		FrameRateValid = InstancePtr->Stream[DataStream].Video.FrameRate/2;
	} else {
		VActiveValid = TimingPtr->VActive;
		FrameRateValid = InstancePtr->Stream[DataStream].Video.FrameRate;
	}
	Status = XV_SdiTx_GetPayloadByte1(VActiveValid, SdiMode, &Byte1);
	if (Status == XST_FAILURE)
		return Status;
	Data = Byte1;
	Data |=	XV_SDITX_COLORFORMAT;
	if (InstancePtr->bitdepth == 12)
		Data |=	XV_SDITX_COLORDEPTH_12;
	else
		Data |=	XV_SDITX_COLORDEPTH_10;
	Data |=	(XV_SdiTx_GetPayloadFrameRate(FrameRateValid, InstancePtr->Transport.IsFractional) << 8);
	if (InstancePtr->Stream[DataStream].IsPsF) {
		Data |= (0x1 << XST352_BYTE2_PIC_TYPE_SHIFT);
		Data &= ~(0x1 << XST352_BYTE2_TS_TYPE_SHIFT);
	} else {
		Data |=	(XV_SdiTx_GetPayloadIsInterlaced(InstancePtr->Stream[DataStream].Video.IsInterlaced) << XST352_BYTE2_PIC_TYPE_SHIFT);
		if ((InstancePtr->Stream[DataStream].Video.Timing.F0PVTotal >= 1125) &&
			(SdiMode != XSDIVID_MODE_3GB))
			Data |=	(XV_SdiTx_GetPayloadIsInterlaced(InstancePtr->Stream[DataStream].Video.IsInterlaced) << XST352_BYTE2_TS_TYPE_SHIFT);
	}
	if( ( (SdiMode == XSDIVID_MODE_3GA)  && (InstancePtr->Transport.IsLevelB3G == 1) ) ||
		 (SdiMode == XSDIVID_MODE_3GB) )
	{
		Data |= 1 << XST352_BYTE2_PIC_TYPE_SHIFT;
		Data |= 0 << XST352_BYTE2_TS_TYPE_SHIFT;
	}
	Data |= (XV_SdiTx_GetPayloadEotf(InstancePtr, InstancePtr->Stream[DataStream].Video.Eotf,
			InstancePtr->Stream[DataStream].Video.ColorStd));
	Data |=	 (XV_SdiTx_GetPayloadColorFormat(SdiMode, InstancePtr->Stream[DataStream].Video.ColorFormatId) <<
												XST352_BYTE3_COLOR_FORMAT_SHIFT);
	Data |=	 (XV_SdiTx_GetPayloadAspectRatio(InstancePtr->Stream[DataStream].Video.AspectRatio) <<
												XST352_BYTE3_ASPECT_RATIO_SHIFT);
	if (InstancePtr->Stream[DataStream].Video.Timing.HActive == 2048 ||
		InstancePtr->Stream[DataStream].Video.Timing.HActive == 4096)
		Data |= 0x1 << XST352_BYTE3_ACT_LUMA_COUNT_SHIFT;
	else if (InstancePtr->Stream[DataStream].Video.Timing.HActive == 1920)
		Data |= 0x1 << XST352_BYTE3_BIT5_SHIFT;
	else if (InstancePtr->Stream[DataStream].Video.Timing.HActive == 3840)
		Data |= 0x1 << XST352_BYTE3_BIT7_SHIFT;
	else
		Data |= 0x0 << XST352_BYTE3_BIT5_SHIFT;
	Data |=	 ((InstancePtr->Stream[DataStream].CAssignment & 0x7) << 29);
	if (SdiMode == XSDIVID_MODE_3GB)
		Data |= (DataStream << 1) << XSDI_CH_SHIFT;
	InstancePtr->Stream[DataStream].PayloadId = Data;
	return XST_SUCCESS;
}
u32 XV_SdiTx_GetPayload ( XV_SdiTx * InstancePtr , XVidC_VideoMode VideoMode , XSdiVid_TransMode SdiMode , u8 DataStream ) { u32 Data = 0 , Status ; u8 Byte1 ; u16 VActiveValid ; const XVidC_VideoTiming * TimingPtr ; XVidC_FrameRate FrameRateValid ; if ( SdiMode == XSDIVID_MODE_3GB ) InstancePtr -> Stream [ DataStream ] . CAssignment = ( DataStream << 1 ) ; else InstancePtr -> Stream [ DataStream ] . CAssignment = 0 ; TimingPtr = XVidC_GetTimingInfo ( ( u32 ) VideoMode ) ; if ( ! TimingPtr ) { return XST_FAILURE ; } if ( InstancePtr -> Stream [ DataStream ] . Video . IsInterlaced ) { VActiveValid = TimingPtr -> VActive * 2 ; ; FrameRateValid = InstancePtr -> Stream [ DataStream ] . Video . FrameRate / 2 ; } else { VActiveValid = TimingPtr -> VActive ; FrameRateValid = InstancePtr -> Stream [ DataStream ] . Video . FrameRate ; } Status = XV_SdiTx_GetPayloadByte1 ( VActiveValid , SdiMode , & Byte1 ) ; if ( Status == XST_FAILURE ) return Status ; Data = Byte1 ; Data |= XV_SDITX_COLORFORMAT ; if ( InstancePtr -> bitdepth == 12 ) Data |= XV_SDITX_COLORDEPTH_12 ; else Data |= XV_SDITX_COLORDEPTH_10 ; Data |= ( XV_SdiTx_GetPayloadFrameRate ( FrameRateValid , InstancePtr -> Transport . IsFractional ) << 8 ) ; if ( InstancePtr -> Stream [ DataStream ] . IsPsF ) { Data |= ( 0x1 << XST352_BYTE2_PIC_TYPE_SHIFT ) ; Data &= ~ ( 0x1 << XST352_BYTE2_TS_TYPE_SHIFT ) ; } else { Data |= ( XV_SdiTx_GetPayloadIsInterlaced ( InstancePtr -> Stream [ DataStream ] . Video . IsInterlaced ) << XST352_BYTE2_PIC_TYPE_SHIFT ) ; if ( ( InstancePtr -> Stream [ DataStream ] . Video . Timing . F0PVTotal >= 1125 ) && ( SdiMode != XSDIVID_MODE_3GB ) ) Data |= ( XV_SdiTx_GetPayloadIsInterlaced ( InstancePtr -> Stream [ DataStream ] . Video . IsInterlaced ) << XST352_BYTE2_TS_TYPE_SHIFT ) ; } if ( ( ( SdiMode == XSDIVID_MODE_3GA ) && ( InstancePtr -> Transport . IsLevelB3G == 1 ) ) || ( SdiMode == XSDIVID_MODE_3GB ) ) { Data |= 1 << XST352_BYTE2_PIC_TYPE_SHIFT ; Data |= 0 << XST352_BYTE2_TS_TYPE_SHIFT ; } Data |= ( XV_SdiTx_GetPayloadEotf ( InstancePtr , InstancePtr -> Stream [ DataStream ] . Video . Eotf , InstancePtr -> Stream [ DataStream ] . Video . ColorStd ) ) ; Data |= ( XV_SdiTx_GetPayloadColorFormat ( SdiMode , InstancePtr -> Stream [ DataStream ] . Video . ColorFormatId ) << XST352_BYTE3_COLOR_FORMAT_SHIFT ) ; Data |= ( XV_SdiTx_GetPayloadAspectRatio ( InstancePtr -> Stream [ DataStream ] . Video . AspectRatio ) << XST352_BYTE3_ASPECT_RATIO_SHIFT ) ; if ( InstancePtr -> Stream [ DataStream ] . Video . Timing . HActive == 2048 || InstancePtr -> Stream [ DataStream ] . Video . Timing . HActive == 4096 ) Data |= 0x1 << XST352_BYTE3_ACT_LUMA_COUNT_SHIFT ; else if ( InstancePtr -> Stream [ DataStream ] . Video . Timing . HActive == 1920 ) Data |= 0x1 << XST352_BYTE3_BIT5_SHIFT ; else if ( InstancePtr -> Stream [ DataStream ] . Video . Timing . HActive == 3840 ) Data |= 0x1 << XST352_BYTE3_BIT7_SHIFT ; else Data |= 0x0 << XST352_BYTE3_BIT5_SHIFT ; Data |= ( ( InstancePtr -> Stream [ DataStream ] . CAssignment & 0x7 ) << 29 ) ; if ( SdiMode == XSDIVID_MODE_3GB ) Data |= ( DataStream << 1 ) << XSDI_CH_SHIFT ; InstancePtr -> Stream [ DataStream ] . PayloadId = Data ; return XST_SUCCESS ; }
This function calculates the final st352 payload value for all SDI modes
 with given video mode and SDI data stream number
This function calculates the final st352 payload value for all SDI modes with given video mode and SDI data stream number
/* Bit 6 and Bit 7 of st352 byte 2 tells about progressive or interlaced
	 * transport and picture structures. Read Chapter 5.3 of
	 * SMPTE ST 352:2013 document.
	 */ /*for 4096 or 2048 horizontal pixels, set BIT(6) of byte 3 to 1.
	 * Refer Table 3 SMPTE ST 2081-10.
	 */