⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xuartps_options.c

📁 自学ZedBoard:使用IP通过ARM PS访问FPGA(源代码)
💻 C
📖 第 1 页 / 共 2 页
字号:
	 */	Xil_AssertNonvoid(InstancePtr != NULL);	Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);	/*	 * Read the Mode register.	 */	ModeRegister =		XUartPs_ReadReg(InstancePtr->Config.BaseAddress,				  XUARTPS_MR_OFFSET);	ModeRegister &= XUARTPS_MR_CHMODE_MASK;	/*	 * Return the constant	 */	switch (ModeRegister) {	case XUARTPS_MR_CHMODE_NORM:		OperMode = XUARTPS_OPER_MODE_NORMAL;		break;	case XUARTPS_MR_CHMODE_ECHO:		OperMode = XUARTPS_OPER_MODE_AUTO_ECHO;		break;	case XUARTPS_MR_CHMODE_L_LOOP:		OperMode = XUARTPS_OPER_MODE_LOCAL_LOOP;		break;	case XUARTPS_MR_CHMODE_R_LOOP:		OperMode = XUARTPS_OPER_MODE_REMOTE_LOOP;		break;	default:		OperMode = (u8) ((ModeRegister & XUARTPS_MR_CHMODE_MASK) >>			XUARTPS_MR_CHMODE_SHIFT);	}	return OperMode;}/****************************************************************************//**** This function sets the operational mode of the UART. The UART can operate* in one of four modes: Normal, Local Loopback, Remote Loopback, or automatic* echo.** @param	InstancePtr is a pointer to the XUartPs instance.* @param	OperationMode is the mode of the UART.** @return	None.** @note		None.******************************************************************************/void XUartPs_SetOperMode(XUartPs *InstancePtr, u8 OperationMode){	u32 ModeRegister;	/*	 * Assert validates the input arguments.	 */	Xil_AssertVoid(InstancePtr != NULL);	Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);	Xil_AssertVoid(OperationMode <= XUARTPS_OPER_MODE_REMOTE_LOOP);	/*	 * Read the Mode register.	 */	ModeRegister =		XUartPs_ReadReg(InstancePtr->Config.BaseAddress,				  XUARTPS_MR_OFFSET);	/*	 * Set the correct value by masking the bits, then ORing the const.	 */	ModeRegister &= ~XUARTPS_MR_CHMODE_MASK;	switch (OperationMode) {	case XUARTPS_OPER_MODE_NORMAL:		ModeRegister |= XUARTPS_MR_CHMODE_NORM;		break;	case XUARTPS_OPER_MODE_AUTO_ECHO:		ModeRegister |= XUARTPS_MR_CHMODE_ECHO;		break;	case XUARTPS_OPER_MODE_LOCAL_LOOP:		ModeRegister |= XUARTPS_MR_CHMODE_L_LOOP;		break;	case XUARTPS_OPER_MODE_REMOTE_LOOP:		ModeRegister |= XUARTPS_MR_CHMODE_R_LOOP;		break;	}	XUartPs_WriteReg(InstancePtr->Config.BaseAddress, XUARTPS_MR_OFFSET,			   ModeRegister);}/****************************************************************************//**** This function sets the Flow Delay.* 0 - 3: Flow delay inactive* 4 - 32: If Flow Control mode is enabled, UART_rtsN is deactivated when the* receive FIFO fills to this level.** @param	InstancePtr is a pointer to the XUartPs instance.** @return** The Flow Delay is specified by constants defined in xuartps_hw.h. The* constants are named XUARTPS_FLOWDEL*** @note		None.******************************************************************************/u8 XUartPs_GetFlowDelay(XUartPs *InstancePtr){	u32 FdelRegister;	/*	 * Assert validates the input arguments	 */	Xil_AssertNonvoid(InstancePtr != NULL);	Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);	/*	 * Read the Mode register.	 */	FdelRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress,					 XUARTPS_FLOWDEL_OFFSET);	/*	 * Return the contents of the flow delay register	 */	return (u8) (FdelRegister & XUARTPS_FLOWDEL_MASK);}/****************************************************************************//**** This function sets the Flow Delay.* 0 - 3: Flow delay inactive* 4 - 32: If Flow Control mode is enabled, UART_rtsN is deactivated when the* receive FIFO fills to this level.** @param	InstancePtr is a pointer to the XUartPs instance.* @param	FlowDelayValue is the Setting for the flow delay.** @return	None.** @note		None.******************************************************************************/void XUartPs_SetFlowDelay(XUartPs *InstancePtr, u8 FlowDelayValue){	u32 FdelRegister;	/*	 * Assert validates the input arguments	 */	Xil_AssertVoid(InstancePtr != NULL);	Xil_AssertVoid(FlowDelayValue > XUARTPS_FLOWDEL_MASK);	Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);	/*	 * Set the correct value by shifting the input constant, then masking	 * the bits	 */	FdelRegister = (FlowDelayValue & XUARTPS_FLOWDEL_MASK);	XUartPs_WriteReg(InstancePtr->Config.BaseAddress,			   XUARTPS_FLOWDEL_OFFSET, FdelRegister);}/****************************************************************************//**** This function gets the Receive Timeout of the UART.** @param	InstancePtr is a pointer to the XUartPs instance.** @return	The current setting for receive time out.** @note		None.******************************************************************************/u8 XUartPs_GetRecvTimeout(XUartPs *InstancePtr){	u32 RtoRegister;	/*	 * Assert validates the input arguments	 */	Xil_AssertNonvoid(InstancePtr != NULL);	Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);	/*	 * Read the Recieve Timeout register.	 */	RtoRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress,					XUARTPS_RXTOUT_OFFSET);	/*	 * Return the contents of the mode register shifted appropriately	 */	return (RtoRegister & XUARTPS_RXTOUT_MASK);}/****************************************************************************//**** This function sets the Receive Timeout of the UART.** @param	InstancePtr is a pointer to the XUartPs instance.* @param	RecvTimeout setting allows the UART to detect an idle connection*		on the reciever data line.*		Timeout duration = RecvTimeout x 4 x Bit Period. 0 disables the*		timeout function.** @return	None.** @note		None.******************************************************************************/void XUartPs_SetRecvTimeout(XUartPs *InstancePtr, u8 RecvTimeout){	u32 RtoRegister;	/*	 * Assert validates the input arguments	 */	Xil_AssertVoid(InstancePtr != NULL);	Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);	/*	 * Set the correct value by masking the bits	 */	RtoRegister = (RecvTimeout & XUARTPS_RXTOUT_MASK);	XUartPs_WriteReg(InstancePtr->Config.BaseAddress,			   XUARTPS_RXTOUT_OFFSET, RtoRegister);	/*	 * Configure CR to restart the receiver timeout counter	 */	RtoRegister =		XUartPs_ReadReg(InstancePtr->Config.BaseAddress,				  XUARTPS_CR_OFFSET);	XUartPs_WriteReg(InstancePtr->Config.BaseAddress, XUARTPS_CR_OFFSET,			   (RtoRegister | XUARTPS_CR_TORST));}/****************************************************************************//**** Sets the data format for the device. 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 XUartPs 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.* The asserts in this function will cause a warning if these fields are* bytes.* <br><br>******************************************************************************/int XUartPs_SetDataFormat(XUartPs *InstancePtr,			XUartPsFormat * FormatPtr){	int Status;	u32 ModeRegister;	Xil_AssertNonvoid(InstancePtr != NULL);	Xil_AssertNonvoid(FormatPtr != NULL);	Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);	/*	 * Verify the inputs specified are valid	 */	if ((FormatPtr->DataBits > XUARTPS_FORMAT_6_BITS) ||		(FormatPtr->StopBits > XUARTPS_FORMAT_2_STOP_BIT) ||		(FormatPtr->Parity > XUARTPS_FORMAT_NO_PARITY)) {		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 = XUartPs_SetBaudRate(InstancePtr, FormatPtr->BaudRate);	if (Status != XST_SUCCESS) {		return Status;	}	ModeRegister =		XUartPs_ReadReg(InstancePtr->Config.BaseAddress,				  XUARTPS_MR_OFFSET);	/*	 * Set the length of data (8,7,6) by first clearing out the bits	 * that control it in the register, then set the length in the register	 */	ModeRegister &= ~XUARTPS_MR_CHARLEN_MASK;	ModeRegister |= (FormatPtr->DataBits << XUARTPS_MR_CHARLEN_SHIFT);	/*	 * Set the number of stop bits in the mode register by first clearing	 * out the bits that control it in the register, then set the number	 * of stop bits in the register.	 */	ModeRegister &= ~XUARTPS_MR_STOPMODE_MASK;	ModeRegister |= (FormatPtr->StopBits << XUARTPS_MR_STOPMODE_SHIFT);	/*	 * 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	 */	ModeRegister &= ~XUARTPS_MR_PARITY_MASK;	ModeRegister |= (FormatPtr->Parity << XUARTPS_MR_PARITY_SHIFT);	/*	 * Update the mode register	 */	XUartPs_WriteReg(InstancePtr->Config.BaseAddress, XUARTPS_MR_OFFSET,			   ModeRegister);	return XST_SUCCESS;}/****************************************************************************//**** Gets the data format for the specified UART. The data format includes the* baud rate, number of data bits, number of stop bits, and parity.** @param	InstancePtr is a pointer to the XUartPs instance.* @param	FormatPtr is a pointer to a format structure that will contain*		the data format after this call completes.** @return	None.** @note		None.*******************************************************************************/void XUartPs_GetDataFormat(XUartPs *InstancePtr, XUartPsFormat * FormatPtr){	u32 ModeRegister;	/*	 * Assert validates the input arguments	 */	Xil_AssertVoid(InstancePtr != NULL);	Xil_AssertVoid(FormatPtr != NULL);	Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);	/*	 * Get the baud rate from the instance, this is not retrieved from the	 * hardware because it is only kept as a divisor such that it is more	 * difficult to get back to the baud rate	 */	FormatPtr->BaudRate = InstancePtr->BaudRate;	ModeRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress,				  XUARTPS_MR_OFFSET);	/*	 * Get the length of data (8,7,6,5)	 */	FormatPtr->DataBits =		(ModeRegister & XUARTPS_MR_CHARLEN_MASK) >>		XUARTPS_MR_CHARLEN_SHIFT;	/*	 * Get the number of stop bits	 */	FormatPtr->StopBits =		(ModeRegister & XUARTPS_MR_STOPMODE_MASK) >>		XUARTPS_MR_STOPMODE_SHIFT;	/*	 * Determine what parity is	 */	FormatPtr->Parity =		(ModeRegister & XUARTPS_MR_PARITY_MASK) >>		XUARTPS_MR_PARITY_SHIFT;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -