XilinxProcessorIPLib/drivers/spips/examples/xspips_tpm_polled_example.c
int SpiPsTpmDataTransfer(XSpiPs *SpiPtr, u8* TxBuf, u8* RxBuf, u16 Txlen)
{
	u8 StatusVal;
	int Status;
	u16 RxLen;

	do {
		/* Set command ready request */
		Status = SpiPsTpmStatusSet(SpiPtr, XSPIPS_TPM_STS_CMD_READY);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}

		/* Check for command ready status */
		Status = SpiPsTpmStatusGet(SpiPtr, &StatusVal);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
	} while (!(StatusVal & XSPIPS_TPM_STS_CMD_READY));

	/* Write Data to device */
	Status = SpiPsTpmFifoWrite(SpiPtr, TxBuf, Txlen);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/* Set command to go */
	Status = SpiPsTpmStatusSet(SpiPtr, XSPIPS_TPM_STS_GO);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	do {
		/* Check for command ready and valid */
		Status = SpiPsTpmStatusGet(SpiPtr, &StatusVal);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
	} while (!((StatusVal & XSPIPS_TPM_STS_VALID)
			&& (StatusVal & XSPIPS_TPM_STS_DATA_AVAIL)));

	/* Read Data from device */
	Status = SpiPsTpmFifoRead(SpiPtr, RxBuf, XSPIPS_TPM_RX_HEAD_SIZE);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	RxLen = RxBuf[5];

	if(RxLen > XSPIPS_TPM_RESP_MAX_SIZE)
		return XST_FAILURE;

	RxLen = RxBuf[5] - XSPIPS_TPM_RX_HEAD_SIZE;

	if(RxLen) {
		Status = SpiPsTpmFifoRead(SpiPtr, RxBuf + XSPIPS_TPM_RX_HEAD_SIZE, RxLen);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
	}

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* This function sets TPM access configuration.
*
* @param	SpiPtr is a pointer to the SPIPS driver component to use.
* @param	TxBuf is pointer to transmit buffer
* @param	RxBuf is pointer to receive buffer
* @param	Txlen is data transfer length
*
* @return	XST_SUCCESS if successful, else XST_FAILURE.
*
* @note		None.
*
******************************************************************************/
This function sets TPM access configuration.
This function sets TPM access configuration .
int SpiPsTpmDataTransfer(XSpiPs *SpiPtr, u8* TxBuf, u8* RxBuf, u16 Txlen)
{
	u8 StatusVal;
	int Status;
	u16 RxLen;
	do {
		Status = SpiPsTpmStatusSet(SpiPtr, XSPIPS_TPM_STS_CMD_READY);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
		Status = SpiPsTpmStatusGet(SpiPtr, &StatusVal);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
	} while (!(StatusVal & XSPIPS_TPM_STS_CMD_READY));
	Status = SpiPsTpmFifoWrite(SpiPtr, TxBuf, Txlen);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = SpiPsTpmStatusSet(SpiPtr, XSPIPS_TPM_STS_GO);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	do {
		Status = SpiPsTpmStatusGet(SpiPtr, &StatusVal);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
	} while (!((StatusVal & XSPIPS_TPM_STS_VALID)
			&& (StatusVal & XSPIPS_TPM_STS_DATA_AVAIL)));
	Status = SpiPsTpmFifoRead(SpiPtr, RxBuf, XSPIPS_TPM_RX_HEAD_SIZE);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	RxLen = RxBuf[5];
	if(RxLen > XSPIPS_TPM_RESP_MAX_SIZE)
		return XST_FAILURE;
	RxLen = RxBuf[5] - XSPIPS_TPM_RX_HEAD_SIZE;
	if(RxLen) {
		Status = SpiPsTpmFifoRead(SpiPtr, RxBuf + XSPIPS_TPM_RX_HEAD_SIZE, RxLen);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
	}
	return XST_SUCCESS;
}
int SpiPsTpmDataTransfer ( XSpiPs * SpiPtr , u8 * TxBuf , u8 * RxBuf , u16 Txlen ) { u8 StatusVal ; int Status ; u16 RxLen ; do { Status = SpiPsTpmStatusSet ( SpiPtr , XSPIPS_TPM_STS_CMD_READY ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = SpiPsTpmStatusGet ( SpiPtr , & StatusVal ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } } while ( ! ( StatusVal & XSPIPS_TPM_STS_CMD_READY ) ) ; Status = SpiPsTpmFifoWrite ( SpiPtr , TxBuf , Txlen ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = SpiPsTpmStatusSet ( SpiPtr , XSPIPS_TPM_STS_GO ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } do { Status = SpiPsTpmStatusGet ( SpiPtr , & StatusVal ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } } while ( ! ( ( StatusVal & XSPIPS_TPM_STS_VALID ) && ( StatusVal & XSPIPS_TPM_STS_DATA_AVAIL ) ) ) ; Status = SpiPsTpmFifoRead ( SpiPtr , RxBuf , XSPIPS_TPM_RX_HEAD_SIZE ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } RxLen = RxBuf [ 5 ] ; if ( RxLen > XSPIPS_TPM_RESP_MAX_SIZE ) return XST_FAILURE ; RxLen = RxBuf [ 5 ] - XSPIPS_TPM_RX_HEAD_SIZE ; if ( RxLen ) { Status = SpiPsTpmFifoRead ( SpiPtr , RxBuf + XSPIPS_TPM_RX_HEAD_SIZE , RxLen ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } } return XST_SUCCESS ; }
This function sets TPM access configuration.
This function sets TPM access configuration .
/* Set command ready request */ /* Check for command ready status */ /* Write Data to device */ /* Set command to go */ /* Check for command ready and valid */ /* Read Data from device */