ZYQN-UART

UART

一、简介

UART控制器是一种全双工异步接收器和发送器,支持多种软件可编程波特率和数据格式。它还可以适应自动奇偶校验生成和几种错误检测方案,并在接收FIFO(RxFIFO)和发送FIFO(TxFIFO)中提供数据缓冲。PS提供两个UART控制器,UARTx,其中x=0或1。

二、Functional Description”功能说明功能

2.1“Baud Rate Generator” 波特率发生器

在这里插入图片描述
外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

波特率发生器可以使用主时钟信号UART_REF_CLK,也可以使用主时钟除以8的UART_REF_CLK/8。使用的时钟信号是根据模式寄存器(UA_MR)中CLKS位的值选择的。所得到的所选时钟在下面的描述中被称为SEL_CLK。

SEL_CLK时钟被分频以产生另外三个时钟:“baud_sample, baud_tx_rate, and baud_rx_rate”。baud_tx_rate是用于传输数据的目标波特率。baud_rx_rate名义上是相同的速率,但会与传入的接收数据重新同步。baud_sample以baud_tx_rate, and baud_rx_rate倍数运行,用于对接收的数据进行过采样。

SEL_CLK时钟频率除以波特率生成器寄存器中的CD字段值,即可生成波特率采样时钟使能。该寄存器可以编程为1到65535之间的值。

波特_SAMPLE时钟除以BDIV加1。BDIV是波特率分频寄存器中的一个可编程字段,可以用0到255之间的值进行编程。它的复位值为15,即每个波特_TX_CLOCK/波特_RX_RATE的默认比率为16个波特_SAMPLE时钟。

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

在这里插入图片描述

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

注意:在写入波特率生成器寄存器(UA_Brgr)或波特率分频寄存器(UA_Div)之前,必须禁用发送器和接收器。必须向发送器和接收器发出软重置,然后才能重新启用它们。

2.2Transmit FIFO” 传输FIFO

在这里插入图片描述

当数据加载到TxFIFO时,TxFIFO空标志被清零,并保持此低电平状态,直到TxFIFO中的最后一个字被移除并加载到发射器移位寄存器中。这意味着主机软件在需要下一个数据之前还有另一个完整的串行字时间,使其能够对设置的空标志作出反应,并在不损失传输时间的情况下将另一个字写入TxFIFO。

TxFIFO已满标志表示TxFIFO已完全满,并防止任何进一步的数据加载到TxFIFO中。如果对TxFIFO执行另一次APB写入,则会触发溢出,写入数据不会加载到TxFIFO中。

TxFIFO接近满标志表示TxFIFO中只有空闲字节。

阈值触发器可以设置在TxFIFO填充电平上。发送器触发寄存器可用于设置此值,以便在TxFIFO填充电平达到此编程值时设置触发。

2.3“Transmitter Data Stream” 发送器数据流

发送模块从TxFIFO中移除并行数据,并将其加载到发送器移位寄存器中,以便将其串行化。

发送模块将起始位、数据位、奇偶校验位和停止位作为串行数据流移出。数据在发送波特率时钟使能(baud_TX_RATE)的下降沿以最低有效位优先的方式发送。典型的传输数据流如图19-4所示。

模式寄存器中的CHRL根据数据位数选择字符长度。模式寄存器中的NBSTOP字段选择要发送的停止位数。

2.4 Receiver FIFO” 接收器FIFO

RxFIFO存储接收器串行移位寄存器接收的数据。RxFIFO的最大数据宽度为8位。

当数据被加载到RxFIFO时,RxFIFO空标志被清零,并且该状态保持为低,直到RxFIFO中的所有数据通过APB接口传输完毕。从空的RxFIFO读取将返回零。

RxFIFO FULL标志(RFIFO_FULL)表示RxFIFO已满,并防止任何进一步的数据加载到RxFIFO中。当RxFIFO中的空间可用时,将加载接收器中存储的任何字符。

阈值触发可以设置在RxFIFO填充电平上。接收器触发寄存器可用于设置此值,以便在RxFIFO填充电平达到此编程值时设置触发。

2.5Receiver Data Capture” 接收器数据捕获

注意:当不传输数据时, UART 数据传输线通常保持高电压电平。若要开始数据传输,发送UART 会将传输线从高电平拉到低电平并保持1 个时钟周期。

为了表示数据包结束,发送 UART 将数据传输线从低电压驱动到高电压并保持1 到 2 位时间。

当接收 UART 检测到高到低电压跃迁时,便开始以波特率对应的频率读取数据帧中的位。

UART使用UARTx REF_CLK和时钟使能(BOUD_SAMPLE)连续过采样UARTx_RxD信号。当样本检测到向低电平的转变时,它可以指示起始位的开始。当UART在UART_RxD输入端检测到低电平时,它会等待BDIV波特率时钟周期的一半计数,然后再采样三次。如果所有三个位仍然指示低电平,则接收器认为这是一个有效的起始位,如图19-5所示,默认BDIV为15。

在这里插入图片描述

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

当识别出有效的起始位时,接收器波特率时钟使能(Baud_Rx_Rate)重新同步,以便进入的UA_rxd的进一步采样发生在每个位的理论中点附近,如图19-6所示。

当重新同步的波特率_RX_RATE为高时,比较最后三个采样比特。逻辑值由多数投票决定;具有相同值的两个样本定义数据位的值。当已确定串行数据位的值时,将其移位到接收移位寄存器。当一个完整的字符汇编完成后,寄存器的内容随后被推送到RxFIFO。

2.6Mode Switch” 模式开关

模式开关控制控制器和MIO/EMIO之间的RxD和TXD信号的路由。有四种操作模式,如图19-7所示。该模式由uart.mode_reg0[CHMODE]寄存器位字段控制:正常、自动回送、本地环回和远程环回。

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

2.7Modem Control” 调制解调器控制

调制解调器控制模块便于控制调制解调器和UART之间的通信。它包含调制解调器状态寄存器和调制解调器控制寄存器。

只读调制解调器状态寄存器用于读取允许发送、数据载体检测、数据集就绪和振铃指示器调制解调器输入的值。它还报告这些输入中的任何一个的变化,并指示当前是否启用了自动流量控制模式。通过将高电平写入特定位,可清除调制解调器状态寄存器中的位。

三、Programming Guide” 编程指南

1.软件重置(参见19.4.2重置)

2.配置I/O信号路由和MIO引脚(参见19.5.1 MIO编程)

3.配置时钟

4.配置波特率发生器(参见第19.2.1节波特率发生器)

5.调制解调器控制(参见第19.3.2节调制解调器流控制)

6.中断控制(参见第19.3.4节中断控制)

7.Rx和Tx数据传输(参见第19.3.3 Rx和Tx数据传输)

Referred in FPGA的学习

四、“MIO – EMIO Signals” MIO-EMIO信号

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

在这里插入图片描述
外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

代码解读:xuartps.h

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\*

\* Copyright (C) 2010 - 2015 Xilinx, Inc.  All rights reserved.

\*

\* Permission is hereby granted, free of charge, to any person obtaining a copy

\* of this software and associated documentation files (the "Software"), to deal

\* in the Software without restriction, including without limitation the rights

\* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

\* copies of the Software, and to permit persons to whom the Software is

\* furnished to do so, subject to the following conditions:

\*

\* The above copyright notice and this permission notice shall be included in

\* all copies or substantial portions of the Software.

\*

\* Use of the Software is limited solely to applications:

\* (a) running on a Xilinx device, or

\* (b) that interact with a Xilinx device through a bus or interconnect.

\*

\* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

\* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

\* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL

\* XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,

\* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF

\* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

\* SOFTWARE.

\*

\* Except as contained in this notice, the name of the Xilinx shall not be used

\* in advertising or otherwise to promote the sale, use or other dealings in

\* this Software without prior written authorization from Xilinx.

\*

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

/\*\*

\*

\* @file xuartps.h

\* @addtogroup uartps\_v3\_4

\* @{

\* @details

\*

\* This driver supports the following features:

\*

\* - Dynamic data format (baud rate, data bits, stop bits, parity)

\* - Polled mode

\* - Interrupt driven mode

\* - Transmit and receive FIFOs (32 byte FIFO depth)

\* - Access to the external modem control lines

\*

\* \<b>Initialization & Configuration\</b>

\*

\* The XUartPs\_Config structure is used by the driver to configure itself.

\* Fields inside this structure are properties of XUartPs based on its hardware

\* build.

\*

\* To support multiple runtime loading and initialization strategies employed

\* by various operating systems, the driver instance can be initialized in the

\* following way:

\*

\*   - XUartPs\_CfgInitialize(InstancePtr, CfgPtr, EffectiveAddr) - Uses a

\* configuration structure provided by the caller. If running in a system

\* with address translation, the parameter EffectiveAddr should be the

\*  virtual address.

\*

\* \<b>Baud Rate\</b>

\*

\* The UART has an internal baud rate generator, which furnishes the baud rate

\* clock for both the receiver and the transmitter. Ther input clock frequency

\* can be either the master clock or the master clock divided by 8, configured

\* through the mode register.

\*

\* Accompanied with the baud rate divider register, the baud rate is determined

\* by:

\* \<pre>

\* baud\_rate = input\_clock / (bgen \* (bdiv + 1)

\* \</pre>

\* where bgen is the value of the baud rate generator, and bdiv is the value of

\* baud rate divider.

\*

\* \<b>Interrupts\</b>

\*

\* The FIFOs are not flushed when the driver is initialized, but a function is

\* provided to allow the user to reset the FIFOs if desired.

\*

\* The driver defaults to no interrupts at initialization such that interrupts

\* must be enabled if desired. An interrupt is generated for one of the

\* following conditions.

\*

\* - A change in the modem signals

\* - Data in the receive FIFO for a configuable time without receiver activity

\* - A parity error

\* - A framing error

\* - An overrun error

\* - Transmit FIFO is full

\* - Transmit FIFO is empty

\* - Receive FIFO is full

\* - Receive FIFO is empty

\* - Data in the receive FIFO equal to the receive threshold

\*

\* The application can control which interrupts are enabled using the

\* XUartPs\_SetInterruptMask() function.

\*

\* In order to use interrupts, it is necessary for the user to connect the

\* driver interrupt handler, XUartPs\_InterruptHandler(), to the interrupt

\* system of the application. A separate handler should be provided by the

\* application to communicate with the interrupt system, and conduct

\* application specific interrupt handling. An application registers its own

\* handler through the XUartPs\_SetHandler() function.

\*

\* \<b>Data Transfer\</b>

\*

\* The functions, XUartPs\_Send() and XUartPs\_Recv(), are provided in the

\* driver to allow data to be sent and received. They can be used in either

\* polled or interrupt mode.

\*

\* @note

\*

\* The default configuration for the UART after initialization is:

\*

\* - 9,600 bps or XPAR\_DFT\_BAUDRATE if defined

\* - 8 data bits

\* - 1 stop bit

\* - no parity

\* - FIFO's are enabled with a receive threshold of 8 bytes

\* - The RX timeout is enabled with a timeout of 1 (4 char times)

\*

\* \<pre>

\* MODIFICATION HISTORY:

\*

\* Ver   Who    Date Changes

\* ----- ------ -------- ----------------------------------------------

\* 1.00a drg/jz 01/12/10 First Release

\* 1.00a sdm    09/27/11 Fixed compiler warnings and also a bug

\*        in XUartPs\_SetFlowDelay where the value was not

\* being written to the register.

\* 1.01a sdm    12/20/11 Removed the InputClockHz parameter from the XUartPs

\* instance structure and the driver is updated to use

\* InputClockHz parameter from the XUartPs\_Config config

\* structure.

\* Added a parameter to XUartPs\_Config structure which

\* specifies whether the user has selected Modem pins

\* to be connected to MIO or FMIO.

\* Added the tcl file to generate the xparameters.h

\* 1.02a sg     05/16/12 Changed XUARTPS\_RXWM\_MASK to 0x3F for CR 652540 fix.

\* 1.03a sg     07/16/12 Updated XUARTPS\_FORMAT\_7\_BITS and XUARTPS\_FORMAT\_6\_BITS

\* with the correct values for CR 666724

\* Added defines for XUARTPS\_IXR\_TOVR,  XUARTPS\_IXR\_TNFUL

\* and XUARTPS\_IXR\_TTRIG.

\* Modified the name of these defines

\* XUARTPS\_MEDEMSR\_DCDX to XUARTPS\_MODEMSR\_DDCD

\* XUARTPS\_MEDEMSR\_RIX to XUARTPS\_MODEMSR\_TERI

\* XUARTPS\_MEDEMSR\_DSRX to XUARTPS\_MODEMSR\_DDSR

\* XUARTPS\_MEDEMSR\_CTSX to XUARTPS\_MODEMSR\_DCTS

\* 1.05a hk     08/22/13 Added API for uart reset and related

\* constant definitions.

\* 2.0   hk      03/07/14 Version number revised.

\* 2.1   hk     04/16/14 Change XUARTPS\_MAX\_RATE to 921600. CR# 780625.

\* 2.2   hk     06/23/14 SW reset of RX and TX should be done when changing

\*                       baud rate. CR# 804281.

\* 3.0   vm     12/09/14 Modified source code according to misrac guideline.

\* Support for Zynq Ultrascale Mp added.

\* 3.1 kvn    04/10/15 Modified code for latest RTL changes. Also added

\* platform variable in driver instance structure.

\* 3.1   adk   14/03/16  Include interrupt examples in the peripheral test when

\* uart is connected to a valid interrupt controller CR#946803.

\* 3.2   rk     07/20/16 Modified the logic for transmission break bit set

\* 3.4   ms     01/23/17 Added xil\_printf statement in main function for all

\*                       examples to ensure that "Successfully ran" and "Failed"

\*                       strings are available in all examples. This is a fix

\*                       for CR-965028.

\*       ms     03/17/17 Added readme.txt file in examples folder for doxygen

\*                       generation.

\*

\* \</pre>

\*

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

\#ifndef XUARTPS\_H /\* prevent circular inclusions \*/

\#define XUARTPS\_H /\* by using protection macros \*/

\#ifdef \_\_cplusplus

extern "C" {

\#endif

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Include Files \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

\#include "xil\_types.h"

\#include "xil\_assert.h"

\#include "xstatus.h"

\#include "xuartps\_hw\.h"

\#include "xplatform\_info.h"

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Constant Definitions \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

/\*

\* The following constants indicate the max and min baud rates and these

\* numbers are based only on the testing that has been done. The hardware

\* is capable of other baud rates.

\* 以下常量表示最特率和最小波特率,这些数字仅基于已完成的测试。硬件支持其他波特率。

\*/

\#define XUARTPS\_MAX\_RATE 921600U

\#define XUARTPS\_MIN\_RATE 110U

\#define XUARTPS\_DFT\_BAUDRATE  115200U   /\* Default baud rate \*/

/\*\* @name Configuration options

\* @{

\*/

/\*\*

\* These constants specify the options that may be set or retrieved

\* with the driver, each is a unique bit mask such that multiple options

\* may be specified.  These constants indicate the available options

\* in active state.

\*这些常量指定可以使用驱动程序设置或检索的选项,每个选项都是唯一的位掩码,因此可以指定多个选项。 这些常量指示处于活动状态的可用选项。

\*/

\#define XUARTPS\_OPTION\_SET\_BREAK 0x0080U /\*\*< Starts break transmission \*/

\#define XUARTPS\_OPTION\_STOP\_BREAK 0x0040U /\*\*< Stops break transmission \*/

\#define XUARTPS\_OPTION\_RESET\_TMOUT 0x0020U /\*\*< Reset the receive timeout \*/

\#define XUARTPS\_OPTION\_RESET\_TX 0x0010U /\*\*< Reset the transmitter \*/

\#define XUARTPS\_OPTION\_RESET\_RX 0x0008U /\*\*< Reset the receiver \*/

\#define XUARTPS\_OPTION\_ASSERT\_RTS 0x0004U /\*\*< Assert the RTS bit \*/

\#define XUARTPS\_OPTION\_ASSERT\_DTR 0x0002U /\*\*< Assert the DTR bit \*/

\#define XUARTPS\_OPTION\_SET\_FCM 0x0001U /\*\*< Turn on flow control mode \*/

/\*@}\*/

/\*\* @name Channel Operational Mode

\*

\* The UART can operate in one of four modes: Normal, Local Loopback, Remote

\* Loopback, or automatic echo.

\*

\* @{

\*/

\#define XUARTPS\_OPER\_MODE\_NORMAL (u8)0x00U /\*\*< Normal Mode \*/

\#define XUARTPS\_OPER\_MODE\_AUTO\_ECHO (u8)0x01U /\*\*< Auto Echo Mode \*/

\#define XUARTPS\_OPER\_MODE\_LOCAL\_LOOP (u8)0x02U /\*\*< Local Loopback Mode \*/

\#define XUARTPS\_OPER\_MODE\_REMOTE\_LOOP (u8)0x03U /\*\*< Remote Loopback Mode \*/

/\* @} \*/

/\*\* @name Data format values

\*数据格式值

\* These constants specify the data format that the driver supports.

\* The data format includes the number of data bits, the number of stop

\* bits and parity.

\*这些常量指定驱动程序支持的数据格式。

\* 数据格式包括数据位数、停止数

\* 位和奇偶校验。

\* @{

\*/

\#define XUARTPS\_FORMAT\_8\_BITS 0U /\*\*< 8 data bits \*/

\#define XUARTPS\_FORMAT\_7\_BITS 2U /\*\*< 7 data bits \*/

\#define XUARTPS\_FORMAT\_6\_BITS 3U /\*\*< 6 data bits \*/

\#define XUARTPS\_FORMAT\_NO\_PARITY 4U /\*\*< No parity \*/

\#define XUARTPS\_FORMAT\_MARK\_PARITY 3U /\*\*< Mark parity \*/

\#define XUARTPS\_FORMAT\_SPACE\_PARITY 2U /\*\*< parity \*/

\#define XUARTPS\_FORMAT\_ODD\_PARITY 1U /\*\*< Odd parity \*/

\#define XUARTPS\_FORMAT\_EVEN\_PARITY 0U /\*\*< Even parity \*/

\#define XUARTPS\_FORMAT\_2\_STOP\_BIT 2U /\*\*< 2 stop bits \*/

\#define XUARTPS\_FORMAT\_1\_5\_STOP\_BIT 1U /\*\*< 1.5 stop bits \*/

\#define XUARTPS\_FORMAT\_1\_STOP\_BIT 0U /\*\*< 1 stop bit \*/

/\*@}\*/

/\*\* @name Callback events

\*

\* These constants specify the handler events that an application can handle

\* using its specific handler function. Note that these constants are not bit

\* mask, so only one event can be passed to an application at a time.

\*回调事件

\*

\* 这些常量指定应用程序可以处理的处理程序事件

\* 使用其特定的处理程序函数。请注意,这些常量不是位

\* 掩码,因此一次只能将一个事件传递给应用程序。

\* @{

\*/

\#define XUARTPS\_EVENT\_RECV\_DATA 1U /\*\*< Data receiving done \*/

\#define XUARTPS\_EVENT\_RECV\_TOUT 2U /\*\*< A receive timeout occurred \*/

\#define XUARTPS\_EVENT\_SENT\_DATA 3U /\*\*< Data transmission done \*/

\#define XUARTPS\_EVENT\_RECV\_ERROR 4U /\*\*< A receive error detected \*/

\#define XUARTPS\_EVENT\_MODEM 5U /\*\*< Modem status changed \*/

\#define XUARTPS\_EVENT\_PARE\_FRAME\_BRKE 6U /\*\*< A receive parity, frame, break

\* error detected \*/

\#define XUARTPS\_EVENT\_RECV\_ORERR 7U /\*\*< A receive overrun error detected \*/

/\*@}\*/

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Type Definitions \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

/\*\*

\* This typedef contains configuration information for the device.

\*/

typedef struct {

u16 DeviceId; /\*\*< Unique ID  of device \*/

u32 BaseAddress; /\*\*< Base address of device (IPIF) \*/

u32 InputClockHz;/\*\*< Input clock frequency \*/

s32 ModemPinsConnected; /\*\* Specifies whether modem pins are connected

\*  to MIO or FMIO指定是否连接调制解调器引脚到 MIO 或 FMIO\*/

} XUartPs\_Config;

/\* Keep track of state information about a data buffer in the interrupt mode.在中断模式下跟踪有关数据缓冲区的状态信息。 \*/

typedef struct {

u8 \*NextBytePtr;

u32 RequestedBytes;

u32 RemainingBytes;

} XUartPsBuffer;

/\*\*

\* Keep track of data format setting of a device.

\*/

typedef struct {

u32 BaudRate; /\*\*< In bps, ie 1200 \*/

u32 DataBits; /\*\*< Number of data bits \*/

u32 Parity; /\*\*< Parity \*/

u8 StopBits; /\*\*< Number of stop bits \*/

} XUartPsFormat;

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

/\*\*

\* This data type defines a handler that an application defines to communicate

\* with interrupt system to retrieve state information about an application.

\*

\* @param CallBackRef is a callback reference passed in by the upper layer

\* when setting the handler, and is passed back to the upper layer

\* when the handler is called. It is used to find the device driver

\* instance.

\* @param Event contains one of the event constants indicating events that

\* have occurred.

\* @param EventData contains the number of bytes sent or received at the

\* time of the call for send and receive events and contains the

\* modem status for modem events.

\*

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

typedef void (\*XUartPs\_Handler) (void \*CallBackRef, u32 Event,

 u32 EventData);

/\*\*

\* The XUartPs driver instance data structure. A pointer to an instance data

\* structure is passed around by functions to refer to a specific driver

\* instance.

\*/

typedef struct {

XUartPs\_Config Config; /\* Configuration data structure \*/

u32 InputClockHz; /\* Input clock frequency \*/

u32 IsReady; /\* Device is initialized and ready \*/

u32 BaudRate; /\* Current baud rate \*/

XUartPsBuffer SendBuffer;

XUartPsBuffer ReceiveBuffer;

XUartPs\_Handler Handler;

void \*CallBackRef; /\* Callback reference for event handler \*/

u32 Platform;

u8 is\_rxbs\_error;

} XUartPs;

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Macros (Inline Functions) Definitions \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

/\*\*

\* Get the UART Channel Status Register.

\*

\* @param InstancePtr is a pointer to the XUartPs instance.

\*

\* @return The value read from the register.

\*

\* @note C-Style signature:

\* u16 XUartPs\_GetChannelStatus(XUartPs \*InstancePtr)

\*

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

\#define XUartPs\_GetChannelStatus(InstancePtr)   \\

Xil\_In32(((InstancePtr)->Config.BaseAddress) + (u32)XUARTPS\_SR\_OFFSET)

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

/\*\*

\* Get the UART Mode Control Register.

\*

\* @param InstancePtr is a pointer to the XUartPs instance.

\*

\* @return The value read from the register.

\*

\* @note C-Style signature:

\* u32 XUartPs\_GetControl(XUartPs \*InstancePtr)

\*

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

\#define XUartPs\_GetModeControl(InstancePtr)  \\

Xil\_In32(((InstancePtr)->Config.BaseAddress) + (u32)XUARTPS\_CR\_OFFSET)

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

/\*\*

\* Set the UART Mode Control Register.

\*

\* @param InstancePtr is a pointer to the XUartPs instance.

\* @param RegisterValue is the value to be written to the register.

\*

\* @return None.

\*

\* @note C-Style signature:

\* void XUartPs\_SetModeControl(XUartPs \*InstancePtr, u16 RegisterValue)

\*

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

\#define XUartPs\_SetModeControl(InstancePtr, RegisterValue) \\

  Xil\_Out32(((InstancePtr)->Config.BaseAddress) + (u32)XUARTPS\_CR\_OFFSET, \\

(u32)(RegisterValue))

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

/\*\*

\* Enable the transmitter and receiver of the UART.

\*

\* @param InstancePtr is a pointer to the XUartPs instance.

\*

\* @return None.

\*

\* @note C-Style signature:

\* void XUartPs\_EnableUart(XUartPs \*InstancePtr)

\*

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

\#define XUartPs\_EnableUart(InstancePtr) \\

  Xil\_Out32(((InstancePtr)->Config.BaseAddress + (u32)XUARTPS\_CR\_OFFSET), \\

 ((Xil\_In32((InstancePtr)->Config.BaseAddress + (u32)XUARTPS\_CR\_OFFSET) & \\

 (u32)(\~XUARTPS\_CR\_EN\_DIS\_MASK)) | ((u32)XUARTPS\_CR\_RX\_EN | (u32)XUARTPS\_CR\_TX\_EN)))

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

/\*\*

\* Disable the transmitter and receiver of the UART.

\*

\* @param InstancePtr is a pointer to the XUartPs instance.

\*

\* @return None.

\*

\* @note C-Style signature:

\* void XUartPs\_DisableUart(XUartPs \*InstancePtr)

\*

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

\#define XUartPs\_DisableUart(InstancePtr) \\

  Xil\_Out32(((InstancePtr)->Config.BaseAddress + (u32)XUARTPS\_CR\_OFFSET), \\

 (((Xil\_In32((InstancePtr)->Config.BaseAddress + (u32)XUARTPS\_CR\_OFFSET)) & \\

 (u32)(\~XUARTPS\_CR\_EN\_DIS\_MASK)) | ((u32)XUARTPS\_CR\_RX\_DIS | (u32)XUARTPS\_CR\_TX\_DIS)))

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

/\*\*

\* Determine if the transmitter FIFO is empty.

\*

\* @param InstancePtr is a pointer to the XUartPs instance.

\*

\* @return

\* - TRUE if a byte can be sent

\* - FALSE if the Transmitter Fifo is not empty

\*

\* @note C-Style signature:

\* u32 XUartPs\_IsTransmitEmpty(XUartPs InstancePtr)

\*

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

\#define XUartPs\_IsTransmitEmpty(InstancePtr) \\

((Xil\_In32(((InstancePtr)->Config.BaseAddress) + (u32)XUARTPS\_SR\_OFFSET) & \\

(u32)XUARTPS\_SR\_TXEMPTY) == (u32)XUARTPS\_SR\_TXEMPTY)

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Function Prototypes \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

/\* Static lookup function implemented in xuartps\_sinit.c 在 xuartps\_sinit.c 中实现的静态查找功能 \*/

XUartPs\_Config \*XUartPs\_LookupConfig(u16 DeviceId);

/\* Interface functions implemented in xuartps.c在 xuartps.c 中实现的接口函数 \*/

s32 XUartPs\_CfgInitialize(XUartPs \*InstancePtr,

 XUartPs\_Config \* Config, u32 EffectiveAddr);

u32 XUartPs\_Send(XUartPs \*InstancePtr,u8 \*BufferPtr,

  u32 NumBytes);

u32 XUartPs\_Recv(XUartPs \*InstancePtr,u8 \*BufferPtr,

  u32 NumBytes);

s32 XUartPs\_SetBaudRate(XUartPs \*InstancePtr, u32 BaudRate);

/\* Options functions in xuartps\_options.c \*/

void XUartPs\_SetOptions(XUartPs \*InstancePtr, u16 Options);

u16 XUartPs\_GetOptions(XUartPs \*InstancePtr);

void XUartPs\_SetFifoThreshold(XUartPs \*InstancePtr, u8 TriggerLevel);

u8 XUartPs\_GetFifoThreshold(XUartPs \*InstancePtr);

u16 XUartPs\_GetModemStatus(XUartPs \*InstancePtr);

u32 XUartPs\_IsSending(XUartPs \*InstancePtr);

u8 XUartPs\_GetOperMode(XUartPs \*InstancePtr);

void XUartPs\_SetOperMode(XUartPs \*InstancePtr, u8 OperationMode);

u8 XUartPs\_GetFlowDelay(XUartPs \*InstancePtr);

void XUartPs\_SetFlowDelay(XUartPs \*InstancePtr, u8 FlowDelayValue);

u8 XUartPs\_GetRecvTimeout(XUartPs \*InstancePtr);

void XUartPs\_SetRecvTimeout(XUartPs \*InstancePtr, u8 RecvTimeout);

s32 XUartPs\_SetDataFormat(XUartPs \*InstancePtr, XUartPsFormat \* FormatPtr);

void XUartPs\_GetDataFormat(XUartPs \*InstancePtr, XUartPsFormat \* FormatPtr);

/\* interrupt functions in xuartps\_intr.c \*/

u32 XUartPs\_GetInterruptMask(XUartPs \*InstancePtr);

void XUartPs\_SetInterruptMask(XUartPs \*InstancePtr, u32 Mask);

void XUartPs\_InterruptHandler(XUartPs \*InstancePtr);

void XUartPs\_SetHandler(XUartPs \*InstancePtr, XUartPs\_Handler FuncPtr,

void \*CallBackRef);

/\* self-test functions in xuartps\_selftest.c \*/

s32 XUartPs\_SelfTest(XUartPs \*InstancePtr);

\#ifdef \_\_cplusplus

}

\#endif

\#endif /\* end of protection macro \*/

/\*\* @} \*/
  • 25
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值