XilinxProcessorIPLib/drivers/hdcp22_tx_dp/src/xhdcp22_tx.c
static int XHdcp22Tx_WaitForReceiver(XHdcp22_Tx *InstancePtr, int ExpectedSize, u8 ReadyBit)
{
	/*
	 * Timer is counting down.
	 * The interval count is the number of clock ticks for a polling interval.
	 * The RxStatus register is read each time the difference between the
	 * previous poll count and the current timer count is greater than
	 * or equal to the interval count.
	 */
	u32 TimerCount = 0;
	u32 IntervalCount = InstancePtr->Info.PollingValue *
		((u32)InstancePtr->Timer.TmrCtr.Config.SysClockFreqHz / 1000);

	/* busy waiting...*/
	if (InstancePtr->Timer.TimerExpired == (FALSE)) {

		/* Poll if requested */
		/* Read current timer count */
		TimerCount = XHdcp22Tx_GetTimerCount(InstancePtr);

		/* Apply polling value: 0=poll always, 1=poll after 1ms, etc... */
		if ((InstancePtr->Info.PollingValue == 0) ||
				((InstancePtr->Timer.InitialTicks - TimerCount) >= IntervalCount))
		{
			/* Update InitialTicks to the current counter value */
			InstancePtr->Timer.InitialTicks = TimerCount;
			if (InstancePtr->Config.Protocol == XHDCP22_TX_DP) {
				if (InstancePtr->Timer.ReasonId ==
						XHDCP22_TX_AKE_SEND_H_PRIME)
				{
					/*Check if H'Avaiable is set through CP_IRQ*/
					if (InstancePtr->Info.Dp_RxStatus &
							XHDCP22_RX_STATUS_H_PRIME_AVAILABLE) {
						InstancePtr->Info.Dp_RxStatus &=
							~XHDCP22_RX_STATUS_H_PRIME_AVAILABLE;
						InstancePtr->Info.MsgAvailable = (TRUE);
						xdbg_printf(XDBG_DEBUG_GENERAL,
								"HDCP22TX: H' is Available through CP_IRQ\n\r");
					}
				} else if (InstancePtr->Timer.ReasonId ==
						XHDCP22_TX_AKE_SEND_PAIRING_INFO) {
					/*Check if Pairing Available is set through CP_IRQ*/
					if (InstancePtr->Info.Dp_RxStatus &
							XHDCP22_RX_STATUS_PAIRING_AVAILABLE) {
						InstancePtr->Info.Dp_RxStatus &=
							~XHDCP22_RX_STATUS_PAIRING_AVAILABLE;
						InstancePtr->Info.MsgAvailable = (TRUE);
						xdbg_printf(XDBG_DEBUG_GENERAL,
								"HDCP22TX: Pairing is Available through CP_IRQ\n\r");
					}
				} else if (InstancePtr->Timer.ReasonId ==
						XHDCP22_TX_REPEATAUTH_SEND_RECVID_LIST) {
					if (InstancePtr->Info.Dp_RxStatus &
							XHDCP22_RX_STATUS_RPTR_RDY) {
						InstancePtr->Info.Dp_RxStatus =
								~XHDCP22_RX_STATUS_RPTR_RDY;
						InstancePtr->Info.MsgAvailable = (TRUE);
					}
				}

				if (InstancePtr->Info.MsgAvailable == (TRUE)) {
					/* Stop the hardware timer */
					XTmrCtr_Stop(&InstancePtr->Timer.TmrCtr,
							XHDCP22_TX_TIMER_CNTR_0);

					/* Set timer expired flag to signal
					 * we've finished waiting*/
					XHdcp22Tx_LogWr(InstancePtr,
							XHDCP22_TX_LOG_EVT_DBG,
							XHDCP22_TX_LOG_DBG_MSGAVAILABLE);
					InstancePtr->Timer.TimerExpired = (TRUE);
				}

				return XST_SUCCESS;

			} else {
				/* Read Rx status. */
				XHdcp22Tx_ReadRxStatus(InstancePtr);

				if (((ReadyBit == FALSE) && ((InstancePtr->Info.RxStatus & XHDCP22_TX_RXSTATUS_AVAIL_BYTES_MASK) == ExpectedSize)) ||
						(((ReadyBit == TRUE) && (InstancePtr->Info.RxStatus & XHDCP22_TX_RXSTATUS_READY_MASK)) &&
						 ((InstancePtr->Info.RxStatus & XHDCP22_TX_RXSTATUS_AVAIL_BYTES_MASK) > 0))) {

					/* Stop the hardware timer */
					XTmrCtr_Stop(&InstancePtr->Timer.TmrCtr, XHDCP22_TX_TIMER_CNTR_0);

					/* Set timer expired flag and MsgAvailable flag to signal we've finished waiting */
					XHdcp22Tx_LogWr(InstancePtr, XHDCP22_TX_LOG_EVT_DBG, XHDCP22_TX_LOG_DBG_MSGAVAILABLE);
					InstancePtr->Timer.TimerExpired = (TRUE);
					InstancePtr->Info.MsgAvailable = (TRUE);
				}
			}
		}
		return XST_SUCCESS;
	}

	/* timer expired: waiting done...check Msg is ready*/
	if (InstancePtr->Config.Protocol == XHDCP22_TX_DP) {
		/*Considering Msg is available as the timeout happened*/
		InstancePtr->Info.MsgAvailable = (TRUE);
		return XST_SUCCESS;
	} else {
		/* timer expired: waiting done...check size in the status */
		if (((ReadyBit == FALSE) && ((InstancePtr->Info.RxStatus & XHDCP22_TX_RXSTATUS_AVAIL_BYTES_MASK) == ExpectedSize)) ||
			((ReadyBit == TRUE) && (InstancePtr->Info.RxStatus & XHDCP22_TX_RXSTATUS_READY_MASK))) {
			XHdcp22Tx_LogWr(InstancePtr, XHDCP22_TX_LOG_EVT_DBG, XHDCP22_TX_LOG_DBG_MSGAVAILABLE);
			InstancePtr->Info.MsgAvailable = (TRUE);
			return XST_SUCCESS;
		}
	}

	/* The receiver has timed out...and the data size does not match
	 * the expected size! */
	XHdcp22Tx_LogWr(InstancePtr, XHDCP22_TX_LOG_EVT_DBG, XHDCP22_TX_LOG_DBG_TIMEOUT);
	return XST_FAILURE;
}
/*****************************************************************************/
/**
*
* This function waits for receiving expected messages from the receiver.
* If the timer is not started, it will be started.
* This has to be used to avoid blocking waits, and allows polling to return
* to allow the main thread to continue handling other requests.
* Some receivers require to read status as soon as possible otherwise the
* receiver may request for a re-authentication so we must poll!
*
* @param  InstancePtr is a pointer to the XHdcp22Tx core instance.
* @param  ExpectedSize indicates the expected message size in bytes.
* @param  ReadyBit indicates if the repeater ready bit from RxStatus register
*         should be used or the specified ExpectedSize.
*         - TRUE Ready bit from RxStatus is used. ExpectedSize will be ignored.
*         - FALSE ExpectedSize is used. Ready bit from RxStatus will be ignored.
*
* @return
*         - XST_SUCCESS if no problems
*         - XST_FAILURE if the receiver has timed out
*
* @note   None.
*
******************************************************************************/
This function waits for receiving expected messages from the receiver.
If the timer is not started, it will be started.
This has to be used to avoid blocking waits, and allows polling to return
to allow the main thread to continue handling other requests.
Some receivers require to read status as soon as possible otherwise the
receiver may request for a re-authentication so we must poll!
This function waits for receiving expected messages from the receiver . If the timer is not started it will be started . This has to be used to avoid blocking waits and allows polling to return to allow the main thread to continue handling other requests . Some receivers require to read status as soon as possible otherwise the receiver may request for a re - authentication so we must poll!
static int XHdcp22Tx_WaitForReceiver(XHdcp22_Tx *InstancePtr, int ExpectedSize, u8 ReadyBit)
{
	u32 TimerCount = 0;
	u32 IntervalCount = InstancePtr->Info.PollingValue *
		((u32)InstancePtr->Timer.TmrCtr.Config.SysClockFreqHz / 1000);
	if (InstancePtr->Timer.TimerExpired == (FALSE)) {
		TimerCount = XHdcp22Tx_GetTimerCount(InstancePtr);
		if ((InstancePtr->Info.PollingValue == 0) ||
				((InstancePtr->Timer.InitialTicks - TimerCount) >= IntervalCount))
		{
			InstancePtr->Timer.InitialTicks = TimerCount;
			if (InstancePtr->Config.Protocol == XHDCP22_TX_DP) {
				if (InstancePtr->Timer.ReasonId ==
						XHDCP22_TX_AKE_SEND_H_PRIME)
				{
					if (InstancePtr->Info.Dp_RxStatus &
							XHDCP22_RX_STATUS_H_PRIME_AVAILABLE) {
						InstancePtr->Info.Dp_RxStatus &=
							~XHDCP22_RX_STATUS_H_PRIME_AVAILABLE;
						InstancePtr->Info.MsgAvailable = (TRUE);
						xdbg_printf(XDBG_DEBUG_GENERAL,
								"HDCP22TX: H' is Available through CP_IRQ\n\r");
					}
				} else if (InstancePtr->Timer.ReasonId ==
						XHDCP22_TX_AKE_SEND_PAIRING_INFO) {
					if (InstancePtr->Info.Dp_RxStatus &
							XHDCP22_RX_STATUS_PAIRING_AVAILABLE) {
						InstancePtr->Info.Dp_RxStatus &=
							~XHDCP22_RX_STATUS_PAIRING_AVAILABLE;
						InstancePtr->Info.MsgAvailable = (TRUE);
						xdbg_printf(XDBG_DEBUG_GENERAL,
								"HDCP22TX: Pairing is Available through CP_IRQ\n\r");
					}
				} else if (InstancePtr->Timer.ReasonId ==
						XHDCP22_TX_REPEATAUTH_SEND_RECVID_LIST) {
					if (InstancePtr->Info.Dp_RxStatus &
							XHDCP22_RX_STATUS_RPTR_RDY) {
						InstancePtr->Info.Dp_RxStatus =
								~XHDCP22_RX_STATUS_RPTR_RDY;
						InstancePtr->Info.MsgAvailable = (TRUE);
					}
				}
				if (InstancePtr->Info.MsgAvailable == (TRUE)) {
					XTmrCtr_Stop(&InstancePtr->Timer.TmrCtr,
							XHDCP22_TX_TIMER_CNTR_0);
					XHdcp22Tx_LogWr(InstancePtr,
							XHDCP22_TX_LOG_EVT_DBG,
							XHDCP22_TX_LOG_DBG_MSGAVAILABLE);
					InstancePtr->Timer.TimerExpired = (TRUE);
				}
				return XST_SUCCESS;
			} else {
				XHdcp22Tx_ReadRxStatus(InstancePtr);
				if (((ReadyBit == FALSE) && ((InstancePtr->Info.RxStatus & XHDCP22_TX_RXSTATUS_AVAIL_BYTES_MASK) == ExpectedSize)) ||
						(((ReadyBit == TRUE) && (InstancePtr->Info.RxStatus & XHDCP22_TX_RXSTATUS_READY_MASK)) &&
						 ((InstancePtr->Info.RxStatus & XHDCP22_TX_RXSTATUS_AVAIL_BYTES_MASK) > 0))) {
					XTmrCtr_Stop(&InstancePtr->Timer.TmrCtr, XHDCP22_TX_TIMER_CNTR_0);
					XHdcp22Tx_LogWr(InstancePtr, XHDCP22_TX_LOG_EVT_DBG, XHDCP22_TX_LOG_DBG_MSGAVAILABLE);
					InstancePtr->Timer.TimerExpired = (TRUE);
					InstancePtr->Info.MsgAvailable = (TRUE);
				}
			}
		}
		return XST_SUCCESS;
	}
	if (InstancePtr->Config.Protocol == XHDCP22_TX_DP) {
		InstancePtr->Info.MsgAvailable = (TRUE);
		return XST_SUCCESS;
	} else {
		if (((ReadyBit == FALSE) && ((InstancePtr->Info.RxStatus & XHDCP22_TX_RXSTATUS_AVAIL_BYTES_MASK) == ExpectedSize)) ||
			((ReadyBit == TRUE) && (InstancePtr->Info.RxStatus & XHDCP22_TX_RXSTATUS_READY_MASK))) {
			XHdcp22Tx_LogWr(InstancePtr, XHDCP22_TX_LOG_EVT_DBG, XHDCP22_TX_LOG_DBG_MSGAVAILABLE);
			InstancePtr->Info.MsgAvailable = (TRUE);
			return XST_SUCCESS;
		}
	}
	XHdcp22Tx_LogWr(InstancePtr, XHDCP22_TX_LOG_EVT_DBG, XHDCP22_TX_LOG_DBG_TIMEOUT);
	return XST_FAILURE;
}
static int XHdcp22Tx_WaitForReceiver ( XHdcp22_Tx * InstancePtr , int ExpectedSize , u8 ReadyBit ) { u32 TimerCount = 0 ; u32 IntervalCount = InstancePtr -> Info . PollingValue * ( ( u32 ) InstancePtr -> Timer . TmrCtr . Config . SysClockFreqHz / 1000 ) ; if ( InstancePtr -> Timer . TimerExpired == ( FALSE ) ) { TimerCount = XHdcp22Tx_GetTimerCount ( InstancePtr ) ; if ( ( InstancePtr -> Info . PollingValue == 0 ) || ( ( InstancePtr -> Timer . InitialTicks - TimerCount ) >= IntervalCount ) ) { InstancePtr -> Timer . InitialTicks = TimerCount ; if ( InstancePtr -> Config . Protocol == XHDCP22_TX_DP ) { if ( InstancePtr -> Timer . ReasonId == XHDCP22_TX_AKE_SEND_H_PRIME ) { if ( InstancePtr -> Info . Dp_RxStatus & XHDCP22_RX_STATUS_H_PRIME_AVAILABLE ) { InstancePtr -> Info . Dp_RxStatus &= ~ XHDCP22_RX_STATUS_H_PRIME_AVAILABLE ; InstancePtr -> Info . MsgAvailable = ( TRUE ) ; xdbg_printf ( XDBG_DEBUG_GENERAL , " \n \r " ) ; } } else if ( InstancePtr -> Timer . ReasonId == XHDCP22_TX_AKE_SEND_PAIRING_INFO ) { if ( InstancePtr -> Info . Dp_RxStatus & XHDCP22_RX_STATUS_PAIRING_AVAILABLE ) { InstancePtr -> Info . Dp_RxStatus &= ~ XHDCP22_RX_STATUS_PAIRING_AVAILABLE ; InstancePtr -> Info . MsgAvailable = ( TRUE ) ; xdbg_printf ( XDBG_DEBUG_GENERAL , " \n \r " ) ; } } else if ( InstancePtr -> Timer . ReasonId == XHDCP22_TX_REPEATAUTH_SEND_RECVID_LIST ) { if ( InstancePtr -> Info . Dp_RxStatus & XHDCP22_RX_STATUS_RPTR_RDY ) { InstancePtr -> Info . Dp_RxStatus = ~ XHDCP22_RX_STATUS_RPTR_RDY ; InstancePtr -> Info . MsgAvailable = ( TRUE ) ; } } if ( InstancePtr -> Info . MsgAvailable == ( TRUE ) ) { XTmrCtr_Stop ( & InstancePtr -> Timer . TmrCtr , XHDCP22_TX_TIMER_CNTR_0 ) ; XHdcp22Tx_LogWr ( InstancePtr , XHDCP22_TX_LOG_EVT_DBG , XHDCP22_TX_LOG_DBG_MSGAVAILABLE ) ; InstancePtr -> Timer . TimerExpired = ( TRUE ) ; } return XST_SUCCESS ; } else { XHdcp22Tx_ReadRxStatus ( InstancePtr ) ; if ( ( ( ReadyBit == FALSE ) && ( ( InstancePtr -> Info . RxStatus & XHDCP22_TX_RXSTATUS_AVAIL_BYTES_MASK ) == ExpectedSize ) ) || ( ( ( ReadyBit == TRUE ) && ( InstancePtr -> Info . RxStatus & XHDCP22_TX_RXSTATUS_READY_MASK ) ) && ( ( InstancePtr -> Info . RxStatus & XHDCP22_TX_RXSTATUS_AVAIL_BYTES_MASK ) > 0 ) ) ) { XTmrCtr_Stop ( & InstancePtr -> Timer . TmrCtr , XHDCP22_TX_TIMER_CNTR_0 ) ; XHdcp22Tx_LogWr ( InstancePtr , XHDCP22_TX_LOG_EVT_DBG , XHDCP22_TX_LOG_DBG_MSGAVAILABLE ) ; InstancePtr -> Timer . TimerExpired = ( TRUE ) ; InstancePtr -> Info . MsgAvailable = ( TRUE ) ; } } } return XST_SUCCESS ; } if ( InstancePtr -> Config . Protocol == XHDCP22_TX_DP ) { InstancePtr -> Info . MsgAvailable = ( TRUE ) ; return XST_SUCCESS ; } else { if ( ( ( ReadyBit == FALSE ) && ( ( InstancePtr -> Info . RxStatus & XHDCP22_TX_RXSTATUS_AVAIL_BYTES_MASK ) == ExpectedSize ) ) || ( ( ReadyBit == TRUE ) && ( InstancePtr -> Info . RxStatus & XHDCP22_TX_RXSTATUS_READY_MASK ) ) ) { XHdcp22Tx_LogWr ( InstancePtr , XHDCP22_TX_LOG_EVT_DBG , XHDCP22_TX_LOG_DBG_MSGAVAILABLE ) ; InstancePtr -> Info . MsgAvailable = ( TRUE ) ; return XST_SUCCESS ; } } XHdcp22Tx_LogWr ( InstancePtr , XHDCP22_TX_LOG_EVT_DBG , XHDCP22_TX_LOG_DBG_TIMEOUT ) ; return XST_FAILURE ; }
This function waits for receiving expected messages from the receiver.
This function waits for receiving expected messages from the receiver .
/*
	 * Timer is counting down.
	 * The interval count is the number of clock ticks for a polling interval.
	 * The RxStatus register is read each time the difference between the
	 * previous poll count and the current timer count is greater than
	 * or equal to the interval count.
	 */ /* busy waiting...*/ /* Poll if requested */ /* Read current timer count */ /* Apply polling value: 0=poll always, 1=poll after 1ms, etc... */ /* Update InitialTicks to the current counter value */ /*Check if H'Avaiable is set through CP_IRQ*/ /*Check if Pairing Available is set through CP_IRQ*/ /* Stop the hardware timer */ /* Set timer expired flag to signal
					 * we've finished waiting*/ /* Read Rx status. */ /* Stop the hardware timer */ /* Set timer expired flag and MsgAvailable flag to signal we've finished waiting */ /* timer expired: waiting done...check Msg is ready*/ /*Considering Msg is available as the timeout happened*/ /* timer expired: waiting done...check size in the status */ /* The receiver has timed out...and the data size does not match
	 * the expected size! */