AXI UART Lite v2.0 IP使用——ZYNQ学习笔记19
主播造车日记,PS端自带的两路串口以全部占用,因此调用了AXI UART Lite v2.0这个IP,特此记录一下。


阻塞方式:
#include "xparameters.h"
#include "xuartlite.h"
#include "xil_printf.h"#define UARTLITE_DEVICE_ID XPAR_AXI_UARTLITE_0_DEVICE_ID
static XUartLite UartLite;int UartLiteInit(void);
void UartLiteSend(u8 *Buf, u32 Len);
void UartLiteRecv(u8 *Buf, u32 Len);/* 初始化 UARTLite */
int UartLiteInit(void)
{int Status;Status = XUartLite_Initialize(&UartLite, UARTLITE_DEVICE_ID);if (Status != XST_SUCCESS) {xil_printf("UartLite init failed\r\n");return XST_FAILURE;}XUartLite_ResetFifos(&UartLite);return XST_SUCCESS;
}/* 阻塞发送 */
void UartLiteSend( u8 *Buf, u32 Len)
{u32 Sent = 0;while (Sent < Len) {Sent += XUartLite_Send(&UartLite, Buf + Sent, Len - Sent);}
}/* 阻塞接收 */
void UartLiteRecv(u8 *Buf, u32 Len)
{u32 Received = 0;while (Received < Len) {Received += XUartLite_Recv(&UartLite, Buf + Received, Len - Received);}
}int main()
{u8 TxStr[] = "Hello AXI-UART-Lite\n";u8 RxByte;if (UartLiteInit() != XST_SUCCESS)return -1;UartLiteSend(TxStr, sizeof(TxStr) - 1);while (1) {UartLiteRecv(&RxByte, 1);UartLiteSend(&RxByte, 1);}return 0;
}

