XilinxProcessorIPLib/drivers/uartps/examples/xuartps_low_echo_example.c
int UartPsEchoExample(u32 UartBaseAddress)
{
	int Index;
	u32 Running;
	u8 RecvChar;
	u32 CntrlRegister;

	CntrlRegister = XUartPs_ReadReg(UartBaseAddress, XUARTPS_CR_OFFSET);

	/* Enable TX and RX for the device */
	XUartPs_WriteReg(UartBaseAddress, XUARTPS_CR_OFFSET,
			  ((CntrlRegister & ~XUARTPS_CR_EN_DIS_MASK) |
			   XUARTPS_CR_TX_EN | XUARTPS_CR_RX_EN));
	/*
	 * Initialize the send buffer bytes with a pattern to send and the
	 * the receive buffer bytes to zero
	 */
	for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
		SendBuffer[Index] = Index + '0';
	}

	/* Send the entire transmit buffer. */
	for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
		/* Wait until there is space in TX FIFO */
		 while (XUartPs_IsTransmitFull(UartBaseAddress));

		/* Write the byte into the TX FIFO */
		XUartPs_WriteReg(UartBaseAddress, XUARTPS_FIFO_OFFSET,
				  SendBuffer[Index]);
	}

	Running = TRUE;
	while (Running) {
		 /* Wait until there is data */
		while (!XUartPs_IsReceiveData(UartBaseAddress));

		RecvChar = XUartPs_ReadReg(UartBaseAddress,
					    XUARTPS_FIFO_OFFSET);

		/* Change the capitalization */
		if (('a' <= RecvChar) && ('z' >= RecvChar)) {
			/* Convert the Capital letter to a small. */
			RecvChar = RecvChar - 'a' + 'A';
		}
		else if (('A' <= RecvChar) && ('Z' >= RecvChar)) {
			/* Convert the small letter to a Capital. */
			RecvChar = RecvChar - 'A' + 'a';
		}
		else if (CHAR_ESC == RecvChar) {
			Running = FALSE;
		}

		/* Echo the character back */
		XUartPs_WriteReg(UartBaseAddress,  XUARTPS_FIFO_OFFSET,
				  RecvChar);
	}

	return XST_SUCCESS;
}
/**************************************************************************/
/**
*
* This function does a minimal test on the UART device using the hardware
* interface.
*
* @param	UartBaseAddress is the base address of the device
*
* @return	XST_SUCCESS if successful, XST_FAILURE if unsuccessful
*
* @note		None.
*
**************************************************************************/
This function does a minimal test on the UART device using the hardware
interface.
This function does a minimal test on the UART device using the hardware interface .
int UartPsEchoExample(u32 UartBaseAddress)
{
	int Index;
	u32 Running;
	u8 RecvChar;
	u32 CntrlRegister;
	CntrlRegister = XUartPs_ReadReg(UartBaseAddress, XUARTPS_CR_OFFSET);
	XUartPs_WriteReg(UartBaseAddress, XUARTPS_CR_OFFSET,
			  ((CntrlRegister & ~XUARTPS_CR_EN_DIS_MASK) |
			   XUARTPS_CR_TX_EN | XUARTPS_CR_RX_EN));
	for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
		SendBuffer[Index] = Index + '0';
	}
	for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
		 while (XUartPs_IsTransmitFull(UartBaseAddress));
		XUartPs_WriteReg(UartBaseAddress, XUARTPS_FIFO_OFFSET,
				  SendBuffer[Index]);
	}
	Running = TRUE;
	while (Running) {
		while (!XUartPs_IsReceiveData(UartBaseAddress));
		RecvChar = XUartPs_ReadReg(UartBaseAddress,
					    XUARTPS_FIFO_OFFSET);
		if (('a' <= RecvChar) && ('z' >= RecvChar)) {
			RecvChar = RecvChar - 'a' + 'A';
		}
		else if (('A' <= RecvChar) && ('Z' >= RecvChar)) {
			RecvChar = RecvChar - 'A' + 'a';
		}
		else if (CHAR_ESC == RecvChar) {
			Running = FALSE;
		}
		XUartPs_WriteReg(UartBaseAddress,  XUARTPS_FIFO_OFFSET,
				  RecvChar);
	}
	return XST_SUCCESS;
}
int UartPsEchoExample ( u32 UartBaseAddress ) { int Index ; u32 Running ; u8 RecvChar ; u32 CntrlRegister ; CntrlRegister = XUartPs_ReadReg ( UartBaseAddress , XUARTPS_CR_OFFSET ) ; XUartPs_WriteReg ( UartBaseAddress , XUARTPS_CR_OFFSET , ( ( CntrlRegister & ~ XUARTPS_CR_EN_DIS_MASK ) | XUARTPS_CR_TX_EN | XUARTPS_CR_RX_EN ) ) ; for ( Index = 0 ; Index < TEST_BUFFER_SIZE ; Index ++ ) { SendBuffer [ Index ] = Index + ' ' ; } for ( Index = 0 ; Index < TEST_BUFFER_SIZE ; Index ++ ) { while ( XUartPs_IsTransmitFull ( UartBaseAddress ) ) ; XUartPs_WriteReg ( UartBaseAddress , XUARTPS_FIFO_OFFSET , SendBuffer [ Index ] ) ; } Running = TRUE ; while ( Running ) { while ( ! XUartPs_IsReceiveData ( UartBaseAddress ) ) ; RecvChar = XUartPs_ReadReg ( UartBaseAddress , XUARTPS_FIFO_OFFSET ) ; if ( ( ' ' <= RecvChar ) && ( ' ' >= RecvChar ) ) { RecvChar = RecvChar - ' ' + ' ' ; } else if ( ( ' ' <= RecvChar ) && ( ' ' >= RecvChar ) ) { RecvChar = RecvChar - ' ' + ' ' ; } else if ( CHAR_ESC == RecvChar ) { Running = FALSE ; } XUartPs_WriteReg ( UartBaseAddress , XUARTPS_FIFO_OFFSET , RecvChar ) ; } return XST_SUCCESS ; }
This function does a minimal test on the UART device using the hardware
interface.
This function does a minimal test on the UART device using the hardware interface .
/* Enable TX and RX for the device */ /*
	 * Initialize the send buffer bytes with a pattern to send and the
	 * the receive buffer bytes to zero
	 */ /* Send the entire transmit buffer. */ /* Wait until there is space in TX FIFO */ /* Write the byte into the TX FIFO */ /* Wait until there is data */ /* Change the capitalization */ /* Convert the Capital letter to a small. */ /* Convert the small letter to a Capital. */ /* Echo the character back */