XilinxProcessorIPLib/drivers/uartpsv/examples/xuartpsv_polled_example.c
int UartPsvPolledExample(u16 DeviceId)
{
	int Status;
	XUartPsv_Config *Config;
	int Index;
	int BadByteCount = 0;
	unsigned int TotalSentCount, ReceivedCount;

	/*
	 * Initialize the UART driver so that it's ready to use.
	 * Look up the configuration in the config table, then initialize it.
	 */
	Config = XUartPsv_LookupConfig(DeviceId);
	if (NULL == Config) {
		return XST_FAILURE;
	}

	Status = XUartPsv_CfgInitialize(&UartPsv, Config, Config->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/* Check hardware build */
	Status = XUartPsv_SelfTest(&UartPsv);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/* Use local loopback mode. */
	XUartPsv_SetOperMode(&UartPsv, XUARTPSV_OPER_MODE_LOCAL_LOOP);

	/*
	 * Initialize the send buffer bytes with a pattern and the
	 * the receive buffer bytes to zero to allow the receive data to be
	 * verified
	 */
	for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
		SendBuffer[Index] = (Index % 26) + 'A';
		RecvBuffer[Index] = 0;
	}

	TotalSentCount = XUartPsv_Send(&UartPsv, SendBuffer, TEST_BUFFER_SIZE);

	while (XUartPsv_IsTransmitbusy(UartPsv.Config.BaseAddress));
	if (TotalSentCount != TEST_BUFFER_SIZE) {
		return XST_FAILURE;
	}

	ReceivedCount = 0;
	while (ReceivedCount < TEST_BUFFER_SIZE) {
		ReceivedCount +=
		XUartPsv_Recv(&UartPsv, &RecvBuffer[ReceivedCount],
				      (TEST_BUFFER_SIZE - ReceivedCount));
	}
	/* Verify the entire receive buffer was successfully received */
	for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
		if (RecvBuffer[Index] != SendBuffer[Index]) {
			BadByteCount++;
		}
	}

	/* Set the UART in Normal Mode */
	XUartPsv_SetOperMode(&UartPsv, XUARTPSV_OPER_MODE_NORMAL);

	/* If any bytes were not correct, return an error */
	if (BadByteCount != 0) {
		return XST_FAILURE;
	}

	return XST_SUCCESS;
}
/**************************************************************************/
/**
*
* This function does a minimal test on the UartPsv device and driver as a
* design example. The purpose of this function is to illustrate
* how to use the XUartPsv driver.
*
* This function does a minimal test on the XUartPs device in polled mode.
* This function sends data and expects to receive the same data through the
* device using the local loopback mode.
*
*
* @param	DeviceId is the device Id of the UART device and is typically
*		XPAR_<UartPsv_instance>_DEVICE_ID value from xparameters.h.
*
* @return	XST_SUCCESS if successful, otherwise XST_FAILURE.
*
* @note
* This function polls the UART, it may hang if the hardware is not
* working correctly.
*
**************************************************************************/
This function does a minimal test on the UartPsv device and driver as a
design example. The purpose of this function is to illustrate
how to use the XUartPsv driver.

This function does a minimal test on the XUartPs device in polled mode.
This function sends data and expects to receive the same data through the
device using the local loopback mode.
This function does a minimal test on the UartPsv device and driver as a design example . The purpose of this function is to illustrate how to use the XUartPsv driver . This function does a minimal test on the XUartPs device in polled mode . This function sends data and expects to receive the same data through the device using the local loopback mode .
int UartPsvPolledExample(u16 DeviceId)
{
	int Status;
	XUartPsv_Config *Config;
	int Index;
	int BadByteCount = 0;
	unsigned int TotalSentCount, ReceivedCount;
	Config = XUartPsv_LookupConfig(DeviceId);
	if (NULL == Config) {
		return XST_FAILURE;
	}
	Status = XUartPsv_CfgInitialize(&UartPsv, Config, Config->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = XUartPsv_SelfTest(&UartPsv);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XUartPsv_SetOperMode(&UartPsv, XUARTPSV_OPER_MODE_LOCAL_LOOP);
	for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
		SendBuffer[Index] = (Index % 26) + 'A';
		RecvBuffer[Index] = 0;
	}
	TotalSentCount = XUartPsv_Send(&UartPsv, SendBuffer, TEST_BUFFER_SIZE);
	while (XUartPsv_IsTransmitbusy(UartPsv.Config.BaseAddress));
	if (TotalSentCount != TEST_BUFFER_SIZE) {
		return XST_FAILURE;
	}
	ReceivedCount = 0;
	while (ReceivedCount < TEST_BUFFER_SIZE) {
		ReceivedCount +=
		XUartPsv_Recv(&UartPsv, &RecvBuffer[ReceivedCount],
				      (TEST_BUFFER_SIZE - ReceivedCount));
	}
	for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
		if (RecvBuffer[Index] != SendBuffer[Index]) {
			BadByteCount++;
		}
	}
	XUartPsv_SetOperMode(&UartPsv, XUARTPSV_OPER_MODE_NORMAL);
	if (BadByteCount != 0) {
		return XST_FAILURE;
	}
	return XST_SUCCESS;
}
int UartPsvPolledExample ( u16 DeviceId ) { int Status ; XUartPsv_Config * Config ; int Index ; int BadByteCount = 0 ; unsigned int TotalSentCount , ReceivedCount ; Config = XUartPsv_LookupConfig ( DeviceId ) ; if ( NULL == Config ) { return XST_FAILURE ; } Status = XUartPsv_CfgInitialize ( & UartPsv , Config , Config -> BaseAddress ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = XUartPsv_SelfTest ( & UartPsv ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XUartPsv_SetOperMode ( & UartPsv , XUARTPSV_OPER_MODE_LOCAL_LOOP ) ; for ( Index = 0 ; Index < TEST_BUFFER_SIZE ; Index ++ ) { SendBuffer [ Index ] = ( Index % 26 ) + ' ' ; RecvBuffer [ Index ] = 0 ; } TotalSentCount = XUartPsv_Send ( & UartPsv , SendBuffer , TEST_BUFFER_SIZE ) ; while ( XUartPsv_IsTransmitbusy ( UartPsv . Config . BaseAddress ) ) ; if ( TotalSentCount != TEST_BUFFER_SIZE ) { return XST_FAILURE ; } ReceivedCount = 0 ; while ( ReceivedCount < TEST_BUFFER_SIZE ) { ReceivedCount += XUartPsv_Recv ( & UartPsv , & RecvBuffer [ ReceivedCount ] , ( TEST_BUFFER_SIZE - ReceivedCount ) ) ; } for ( Index = 0 ; Index < TEST_BUFFER_SIZE ; Index ++ ) { if ( RecvBuffer [ Index ] != SendBuffer [ Index ] ) { BadByteCount ++ ; } } XUartPsv_SetOperMode ( & UartPsv , XUARTPSV_OPER_MODE_NORMAL ) ; if ( BadByteCount != 0 ) { return XST_FAILURE ; } return XST_SUCCESS ; }
This function does a minimal test on the UartPsv device and driver as a
design example.
This function does a minimal test on the UartPsv device and driver as a design example .
/*
	 * Initialize the UART driver so that it's ready to use.
	 * Look up the configuration in the config table, then initialize it.
	 */ /* Check hardware build */ /* Use local loopback mode. */ /*
	 * Initialize the send buffer bytes with a pattern and the
	 * the receive buffer bytes to zero to allow the receive data to be
	 * verified
	 */ /* Verify the entire receive buffer was successfully received */ /* Set the UART in Normal Mode */ /* If any bytes were not correct, return an error */