XilinxProcessorIPLib/drivers/spips/examples/xspips_tpm_polled_example.c
int SpiPsTpmTransfer(XSpiPs *SpiPtr, u32 Address, u8 *TxBuf, u8 *RxBuf,
		u16 Length)
{
	u16 TranLen;
	u16 RxOffset = 0;
	int Index;
	int Status;

	while (Length) {

		TranLen = (Length <= XSPIPS_TPM_SPI_MAX_SIZE) ? Length :
		XSPIPS_TPM_SPI_MAX_SIZE;

		TpmTxBuffer[0] = (RxBuf ? 0x80 : 0) | (TranLen - 1);
		TpmTxBuffer[1] = 0xD4;
		TpmTxBuffer[2] = Address >> 8;
		TpmTxBuffer[3] = Address;

		if (TxBuf != NULL) {
			for (Index = 0; Index < TranLen; Index++) {
				TpmTxBuffer[XSPIPS_TPM_TX_HEAD_SIZE + Index] = TxBuf[Index];
			}
		}

		Status = XSpiPs_PolledTransfer(SpiPtr, TpmTxBuffer, TpmRxBuffer,
				TranLen + XSPIPS_TPM_TX_HEAD_SIZE);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}

		if (RxBuf != NULL) {
			for (Index = 0; Index < TranLen; Index++) {
				RxBuf[Index + RxOffset] = TpmRxBuffer[XSPIPS_TPM_TX_HEAD_SIZE + Index];
			}
		}
		Length -= TranLen;
		RxOffset += TranLen;
	}

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* This function sets TPM access configuration.
*
* @param	SpiPtr is a pointer to the SPIPS driver component to use.
* @param 	Address register address
* @param	TxBuf is pointer to transmit buffer
* @param	RxBuf is pointer to receive buffer
* @param	Length is 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 SpiPsTpmTransfer(XSpiPs *SpiPtr, u32 Address, u8 *TxBuf, u8 *RxBuf,
		u16 Length)
{
	u16 TranLen;
	u16 RxOffset = 0;
	int Index;
	int Status;
	while (Length) {
		TranLen = (Length <= XSPIPS_TPM_SPI_MAX_SIZE) ? Length :
		XSPIPS_TPM_SPI_MAX_SIZE;
		TpmTxBuffer[0] = (RxBuf ? 0x80 : 0) | (TranLen - 1);
		TpmTxBuffer[1] = 0xD4;
		TpmTxBuffer[2] = Address >> 8;
		TpmTxBuffer[3] = Address;
		if (TxBuf != NULL) {
			for (Index = 0; Index < TranLen; Index++) {
				TpmTxBuffer[XSPIPS_TPM_TX_HEAD_SIZE + Index] = TxBuf[Index];
			}
		}
		Status = XSpiPs_PolledTransfer(SpiPtr, TpmTxBuffer, TpmRxBuffer,
				TranLen + XSPIPS_TPM_TX_HEAD_SIZE);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
		if (RxBuf != NULL) {
			for (Index = 0; Index < TranLen; Index++) {
				RxBuf[Index + RxOffset] = TpmRxBuffer[XSPIPS_TPM_TX_HEAD_SIZE + Index];
			}
		}
		Length -= TranLen;
		RxOffset += TranLen;
	}
	return XST_SUCCESS;
}
int SpiPsTpmTransfer ( XSpiPs * SpiPtr , u32 Address , u8 * TxBuf , u8 * RxBuf , u16 Length ) { u16 TranLen ; u16 RxOffset = 0 ; int Index ; int Status ; while ( Length ) { TranLen = ( Length <= XSPIPS_TPM_SPI_MAX_SIZE ) ? Length : XSPIPS_TPM_SPI_MAX_SIZE ; TpmTxBuffer [ 0 ] = ( RxBuf ? 0x80 : 0 ) | ( TranLen - 1 ) ; TpmTxBuffer [ 1 ] = 0xD4 ; TpmTxBuffer [ 2 ] = Address >> 8 ; TpmTxBuffer [ 3 ] = Address ; if ( TxBuf != NULL ) { for ( Index = 0 ; Index < TranLen ; Index ++ ) { TpmTxBuffer [ XSPIPS_TPM_TX_HEAD_SIZE + Index ] = TxBuf [ Index ] ; } } Status = XSpiPs_PolledTransfer ( SpiPtr , TpmTxBuffer , TpmRxBuffer , TranLen + XSPIPS_TPM_TX_HEAD_SIZE ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } if ( RxBuf != NULL ) { for ( Index = 0 ; Index < TranLen ; Index ++ ) { RxBuf [ Index + RxOffset ] = TpmRxBuffer [ XSPIPS_TPM_TX_HEAD_SIZE + Index ] ; } } Length -= TranLen ; RxOffset += TranLen ; } return XST_SUCCESS ; }
This function sets TPM access configuration.
This function sets TPM access configuration .