XilinxProcessorIPLib/drivers/uartns550/src/xuartns550_format.c
int XUartNs550_SetDataFormat(XUartNs550 *InstancePtr,
					XUartNs550Format *FormatPtr)
{
	int Status;
	u32 LcrRegister;

	Xil_AssertNonvoid(InstancePtr != NULL);
	Xil_AssertNonvoid(FormatPtr != NULL);

	/*
	 * Verify the inputs specified are valid and return an error if any
	 * are not, without setting the data format
	 */
	if ((FormatPtr->DataBits > XUN_FORMAT_8_BITS)	||
		(FormatPtr->Parity > XUN_FORMAT_EVEN_PARITY) ||
		((FormatPtr->StopBits != XUN_FORMAT_2_STOP_BIT) &&
		(FormatPtr->StopBits != XUN_FORMAT_1_STOP_BIT))) {
		return XST_INVALID_PARAM;
	}

	/*
	 * Try to set the baud rate and if it's not successful then don't
	 * continue altering the data format, this is done first to avoid the
	 * format from being altered when an error occurs
	 */
	Status = XUartNs550_SetBaudRate(InstancePtr, FormatPtr->BaudRate);
	if (Status != XST_SUCCESS) {
		return Status;
	}

	/*
	 * Read the line control register which contains the parity, length and
	 * stop bits so they can be updated without affecting any other bits
	 */
	LcrRegister = XUartNs550_GetLineControlReg(InstancePtr->BaseAddress);

	/*
	 * Set the length of data (8,7,6,5) by first clearing out the bits
	 * that control it in the register, then set the length in the register
	 */
	LcrRegister &= ~XUN_LCR_LENGTH_MASK;
	LcrRegister |= FormatPtr->DataBits;

	/*
	 * Set the number of stop bits in the line control register, if the
	 * number of stop bits is not 2, then it must be one which is the bit
	 * in the register cleared
	 */
	if (FormatPtr->StopBits == XUN_FORMAT_2_STOP_BIT) {
		LcrRegister |= XUN_LCR_2_STOP_BITS;
	} else {
		LcrRegister &= ~XUN_LCR_2_STOP_BITS;
	}

	/*
	 * Set the parity by first clearing out the bits that control it in the
	 * register, then set the bits in the register, the default is no parity
	 * after clearing the register bits
	 */
	LcrRegister &= ~XUN_LCR_PARITY_MASK;
	if (FormatPtr->Parity != XUN_FORMAT_NO_PARITY) {
		/*
		 * Some form of parity is specified, set the bit indicating that
		 * parity is enabled, then setup even or odd, the default is odd
		 * after clearing the register bits
		 */
		LcrRegister |= XUN_LCR_ENABLE_PARITY;
		if (FormatPtr->Parity == XUN_FORMAT_EVEN_PARITY) {
			LcrRegister |= XUN_LCR_EVEN_PARITY;
		}
	}

	/*
	 * Write the line control register out to save the new data format
	 * that has been created
	 */
	XUartNs550_SetLineControlReg(InstancePtr->BaseAddress, LcrRegister);

	return XST_SUCCESS;
}
/****************************************************************************/
/**
*
* Sets the data format for the specified UART. The data format includes the
* baud rate, number of data bits, number of stop bits, and parity. It is the
* caller's responsibility to ensure that the UART is not sending or receiving
* data when this function is called.
*
* @param	InstancePtr is a pointer to the XUartNs550 instance .
* @param	FormatPtr is a pointer to a format structure containing the data
*		format to be set.
*
* @return
*
*		- XST_SUCCESS if the data format was successfully set.
*		- XST_UART_BAUD_ERROR indicates the baud rate could not be set
*		because of the amount of error with the baud rate and the input
*		clock frequency.
*		- XST_INVALID_PARAM if one of the parameters was not valid.
*
* @note
*
* The data types in the format type, data bits and parity, are 32 bit fields
* to prevent a compiler warning that is a bug with the GNU PowerPC compiler.
* The asserts in this function will cause a warning if these fields are
* bytes.
* <br><br>
* The baud rates tested include: 1200, 2400, 4800, 9600, 19200, 38400, 57600
* and 115200.
*
*****************************************************************************/
Sets the data format for the specified UART. The data format includes the
baud rate, number of data bits, number of stop bits, and parity. It is the
caller's responsibility to ensure that the UART is not sending or receiving
data when this function is called.
Sets the data format for the specified UART . The data format includes the baud rate number of data bits number of stop bits and parity . It is the caller ' s responsibility to ensure that the UART is not sending or receiving data when this function is called .
int XUartNs550_SetDataFormat(XUartNs550 *InstancePtr,
					XUartNs550Format *FormatPtr)
{
	int Status;
	u32 LcrRegister;
	Xil_AssertNonvoid(InstancePtr != NULL);
	Xil_AssertNonvoid(FormatPtr != NULL);
	if ((FormatPtr->DataBits > XUN_FORMAT_8_BITS)	||
		(FormatPtr->Parity > XUN_FORMAT_EVEN_PARITY) ||
		((FormatPtr->StopBits != XUN_FORMAT_2_STOP_BIT) &&
		(FormatPtr->StopBits != XUN_FORMAT_1_STOP_BIT))) {
		return XST_INVALID_PARAM;
	}
	Status = XUartNs550_SetBaudRate(InstancePtr, FormatPtr->BaudRate);
	if (Status != XST_SUCCESS) {
		return Status;
	}
	LcrRegister = XUartNs550_GetLineControlReg(InstancePtr->BaseAddress);
	LcrRegister &= ~XUN_LCR_LENGTH_MASK;
	LcrRegister |= FormatPtr->DataBits;
	if (FormatPtr->StopBits == XUN_FORMAT_2_STOP_BIT) {
		LcrRegister |= XUN_LCR_2_STOP_BITS;
	} else {
		LcrRegister &= ~XUN_LCR_2_STOP_BITS;
	}
	LcrRegister &= ~XUN_LCR_PARITY_MASK;
	if (FormatPtr->Parity != XUN_FORMAT_NO_PARITY) {
		LcrRegister |= XUN_LCR_ENABLE_PARITY;
		if (FormatPtr->Parity == XUN_FORMAT_EVEN_PARITY) {
			LcrRegister |= XUN_LCR_EVEN_PARITY;
		}
	}
	XUartNs550_SetLineControlReg(InstancePtr->BaseAddress, LcrRegister);
	return XST_SUCCESS;
}
int XUartNs550_SetDataFormat ( XUartNs550 * InstancePtr , XUartNs550Format * FormatPtr ) { int Status ; u32 LcrRegister ; Xil_AssertNonvoid ( InstancePtr != NULL ) ; Xil_AssertNonvoid ( FormatPtr != NULL ) ; if ( ( FormatPtr -> DataBits > XUN_FORMAT_8_BITS ) || ( FormatPtr -> Parity > XUN_FORMAT_EVEN_PARITY ) || ( ( FormatPtr -> StopBits != XUN_FORMAT_2_STOP_BIT ) && ( FormatPtr -> StopBits != XUN_FORMAT_1_STOP_BIT ) ) ) { return XST_INVALID_PARAM ; } Status = XUartNs550_SetBaudRate ( InstancePtr , FormatPtr -> BaudRate ) ; if ( Status != XST_SUCCESS ) { return Status ; } LcrRegister = XUartNs550_GetLineControlReg ( InstancePtr -> BaseAddress ) ; LcrRegister &= ~ XUN_LCR_LENGTH_MASK ; LcrRegister |= FormatPtr -> DataBits ; if ( FormatPtr -> StopBits == XUN_FORMAT_2_STOP_BIT ) { LcrRegister |= XUN_LCR_2_STOP_BITS ; } else { LcrRegister &= ~ XUN_LCR_2_STOP_BITS ; } LcrRegister &= ~ XUN_LCR_PARITY_MASK ; if ( FormatPtr -> Parity != XUN_FORMAT_NO_PARITY ) { LcrRegister |= XUN_LCR_ENABLE_PARITY ; if ( FormatPtr -> Parity == XUN_FORMAT_EVEN_PARITY ) { LcrRegister |= XUN_LCR_EVEN_PARITY ; } } XUartNs550_SetLineControlReg ( InstancePtr -> BaseAddress , LcrRegister ) ; return XST_SUCCESS ; }
Sets the data format for the specified UART.
Sets the data format for the specified UART .
/*
	 * Verify the inputs specified are valid and return an error if any
	 * are not, without setting the data format
	 */ /*
	 * Try to set the baud rate and if it's not successful then don't
	 * continue altering the data format, this is done first to avoid the
	 * format from being altered when an error occurs
	 */ /*
	 * Read the line control register which contains the parity, length and
	 * stop bits so they can be updated without affecting any other bits
	 */ /*
	 * Set the length of data (8,7,6,5) by first clearing out the bits
	 * that control it in the register, then set the length in the register
	 */ /*
	 * Set the number of stop bits in the line control register, if the
	 * number of stop bits is not 2, then it must be one which is the bit
	 * in the register cleared
	 */ /*
	 * Set the parity by first clearing out the bits that control it in the
	 * register, then set the bits in the register, the default is no parity
	 * after clearing the register bits
	 */ /*
		 * Some form of parity is specified, set the bit indicating that
		 * parity is enabled, then setup even or odd, the default is odd
		 * after clearing the register bits
		 */ /*
	 * Write the line control register out to save the new data format
	 * that has been created
	 */