/**
*
* This function does a minimal test on the UART device using the low-level
* driver macros and functions. This function sends data and expects to receive
* the data thru the UART. A physical loopback must be done by the user with the
* tranmit and receive signals of the UART.
*
* @param	UartBaseAddress is the base address of the UARTNS550 device
*		and is the XPAR_<UARTNS550_instance>_BASEADDR value from
*		xparameters.h.
*
* @return	XST_SUCCESS if successful, XST_FAILURE if unsuccessful.
*
* @note		None.
*
****************************************************************************/
int XUartNs550_LowLevelExample(u32 UartBaseAddress)
{
	int Index;

	/*
	 * 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';
		RecvBuffer[Index] = 0;
	}

	/*
	 * Set the baud rate and number of stop bits
	 */
	XUartNs550_SetBaud(UartBaseAddress, UART_CLOCK_HZ, UART_BAUDRATE);
	XUartNs550_SetLineControlReg(UartBaseAddress, XUN_LCR_8_DATA_BITS);


	/*
	 * Enable the FIFOs for 16550 mode since the defaults is NO FIFOs
	 */
	XUartNs550_WriteReg(UartBaseAddress, XUN_FCR_OFFSET, XUN_FIFO_ENABLE);

	/*
	 * Send the entire transmit buffer
	 */
	for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
		XUartNs550_SendByte(UartBaseAddress, SendBuffer[Index]);
	}

	/*
	 * Receive the entire buffer's worth. Note that the RecvByte function
	 * blocks waiting for a character
	 */
	for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
		RecvBuffer[Index] = XUartNs550_RecvByte(UartBaseAddress);
	}

	/*
	 * Check the receive buffer data against the send buffer and verify the
	 * data was correctly received
	 */
	for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {

		if (SendBuffer[Index] != RecvBuffer[Index]) {
			return XST_FAILURE;
		}
	}

	return XST_SUCCESS;
}
Example #2
0
File: inbyte.c Project: kimei/CTU
char inbyte(void) {
	 return XUartNs550_RecvByte(STDIN_BASEADDRESS);
}