打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
ZedBoard UART 1 Rx | Zedboard

xuartps_low_echo_example is an example pointed to by my projects board support package for ps7_uart_1. This is running as a standalone application and putty is configured to 115200 baud, 8 data bits, 1 stop bit, and no parity or flow control. I also ran the self_test which configures UART 1 to loopback mode and it worked. xuartps_low_echo_example source follows.

#include "xparameters.h"
#include "xstatus.h"
#include "xil_types.h"
#include "xil_assert.h"
#include "xuartps_hw.h"

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

/*
* The following constants map to the XPAR parameters created in the
* xparameters.h file. They are defined here such that a user can easily
* change all the needed parameters in one place.
*/
#define UART_BASEADDR XPAR_XUARTPS_0_BASEADDR
#define UART_CLOCK_HZ XPAR_XUARTPS_0_CLOCK_HZ
/*
* The following constant controls the length of the buffers to be sent
* and received with the device. This constant must be 32 bytes or less so the
* entire buffer will fit into the TX and RX FIFOs of the device.
*/
#define TEST_BUFFER_SIZE 16

#define CHAR_ESC 0x1b /* 'ESC' character is used as terminator */

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

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

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

int UartPsEchoExample(u32 UartBaseAddress);

/************************** Variable Definitions ***************************/

/*
* The following buffers are used in this example to send and receive data
* with the UART.
*/
u8 SendBuffer[TEST_BUFFER_SIZE]; /* Buffer for Transmitting Data */

/***************************************************************************/
/**
*
* Main function to call the Uart Echo example.
*
* @param None
*
* @return XST_SUCCESS if successful, XST_FAILURE if unsuccessful
*
* @note None
*
****************************************************************************/
int main(void)
{
int Status;

/*
* Run the Uart Echo example , specify the Base Address that is
* generated in xparameters.h
*/
Status = UartPsEchoExample(UART_BASEADDR);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}

return XST_SUCCESS;
}

/**************************************************************************/
/**
*
* This function does a minimal test on the UART device using the hardware
* interface.
*
* @param UartBaseAddress is the base address of the device
*
* @return XST_SUCCESS if successful, XST_FAILURE if unsuccessful
*
* @note None.
*
**************************************************************************/
int UartPsEchoExample(u32 UartBaseAddress)
{
int Index;
u32 Running;
u8 RecvChar;
u32 CntrlRegister;

CntrlRegister = XUartPs_ReadReg(UartBaseAddress, XUARTPS_CR_OFFSET);

/*
* Enable TX and RX for the device
*/
XUartPs_WriteReg(UartBaseAddress, XUARTPS_CR_OFFSET,
((CntrlRegister & ~XUARTPS_CR_EN_DIS_MASK) |
XUARTPS_CR_TX_EN | XUARTPS_CR_RX_EN));
/*
* 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';
}

/*
* Send the entire transmit buffer.
*/
for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
/*
* Wait until there is space in TX FIFO
*/
while (XUartPs_IsTransmitFull(UartBaseAddress));

/*
* Write the byte into the TX FIFO
*/
XUartPs_WriteReg(UartBaseAddress, XUARTPS_FIFO_OFFSET,
SendBuffer[Index]);
}

Running = TRUE;
while (Running) {
/*
* Wait until there is data
*/
while (!XUartPs_IsReceiveData(UartBaseAddress));

RecvChar = XUartPs_ReadReg(UartBaseAddress,
XUARTPS_FIFO_OFFSET);

/* Change the capitalization */
if (('a' <= RecvChar) && ('z' >= RecvChar)) {
/* Convert the Capital letter to a small. */
RecvChar = RecvChar - 'a' + 'A';
}
else if (('A' <= RecvChar) && ('Z' >= RecvChar)) {
/* Convert the small letter to a Capital. */
RecvChar = RecvChar - 'A' + 'a';
}
else if (CHAR_ESC == RecvChar) {
Running = FALSE;
}

/* Echo the character back */
XUartPs_WriteReg(UartBaseAddress, XUARTPS_FIFO_OFFSET,
RecvChar);
}

return XST_SUCCESS;
}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Linux的DMA高速串口驱动的设计
esp32运行的第一个程序(串口回环测试)
(转载)基于ZedBoard的Webcam设计(三):视频的采集和动态显示
stm32f103 uart+DMA发送接收
干货|高质量代码是怎么写出来的?串口环形队列
FPGA串口实现(带FIFO)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服