arm: add uart echo app
This commit is contained in:
39
arm/hal/uart/Makefile
Normal file
39
arm/hal/uart/Makefile
Normal file
@@ -0,0 +1,39 @@
|
||||
DRIVER_LIB_VERSION = 1.0
|
||||
COMPILER=
|
||||
ARCHIVER=
|
||||
CP=cp
|
||||
COMPILER_FLAGS=
|
||||
EXTRA_COMPILER_FLAGS=
|
||||
LIB=libxil.a
|
||||
|
||||
CC_FLAGS = $(COMPILER_FLAGS)
|
||||
ECC_FLAGS = $(EXTRA_COMPILER_FLAGS)
|
||||
|
||||
RELEASEDIR=../../../lib/
|
||||
INCLUDEDIR=../../../include/
|
||||
INCLUDES=-I./. -I$(INCLUDEDIR)
|
||||
|
||||
SRCFILES:=$(wildcard *.c)
|
||||
|
||||
OBJECTS = $(addprefix $(RELEASEDIR), $(addsuffix .o, $(basename $(wildcard *.c))))
|
||||
|
||||
libs: $(OBJECTS)
|
||||
|
||||
DEPFILES := $(SRCFILES:%.c=$(RELEASEDIR)%.d)
|
||||
|
||||
include $(wildcard $(DEPFILES))
|
||||
|
||||
include $(wildcard ../../../../dep.mk)
|
||||
|
||||
$(RELEASEDIR)%.o: %.c
|
||||
${COMPILER} $(CC_FLAGS) $(ECC_FLAGS) $(INCLUDES) $(DEPENDENCY_FLAGS) $< -o $@
|
||||
|
||||
.PHONY: include
|
||||
include: $(addprefix $(INCLUDEDIR),$(wildcard *.h))
|
||||
|
||||
$(INCLUDEDIR)%.h: %.h
|
||||
$(CP) $< $@
|
||||
|
||||
clean:
|
||||
rm -rf ${OBJECTS}
|
||||
rm -rf $(DEPFILES)
|
655
arm/hal/uart/xuartlite.c
Normal file
655
arm/hal/uart/xuartlite.c
Normal file
@@ -0,0 +1,655 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2002 - 2022 Xilinx, Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
******************************************************************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* @file xuartlite.c
|
||||
* @addtogroup uartlite_v3_7
|
||||
* @{
|
||||
*
|
||||
* Contains required functions for the XUartLite driver. See the xuartlite.h
|
||||
* header file for more details on this driver.
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- ---- -------- -----------------------------------------------
|
||||
* 1.00a ecm 08/31/01 First release
|
||||
* 1.00b jhl 02/21/02 Repartitioned the driver for smaller files
|
||||
* 1.00b rmm 05/13/03 Fixed diab compiler warnings relating to asserts
|
||||
* 1.01a jvb 12/13/05 Changed Initialize() into CfgInitialize(), and made
|
||||
* CfgInitialize() take a pointer to a config structure
|
||||
* instead of a device id. Moved Initialize() into
|
||||
* xgpio_sinit.c, and had Initialize() call CfgInitialize()
|
||||
* after it retrieved the config structure using the device
|
||||
* id. Removed include of xparameters.h along with any
|
||||
* dependencies on xparameters.h and the _g.c config table.
|
||||
* 1.01a wsy 05/08/06 fix CR220811 and CR224103.
|
||||
* 1.12a mta 03/31/07 Updated to new coding conventions
|
||||
* 1.13a sv 01/21/08 Updated driver to support access through DCR bus
|
||||
* 1.14a sdm 09/26/08 Updated code to avoid race condition in
|
||||
* XUartLite_SendBuffer
|
||||
* 2.00a ktn 10/20/09 Updated to use HAL Processor APIs. The macros have been
|
||||
* renamed to remove _m from the name. XUartLite_mClearStats
|
||||
* macro is removed and XUartLite_ClearStats function should
|
||||
* be used in its place.
|
||||
* 2.00a hvm 08/11/11 Removed the SetOptions related information in the
|
||||
* Recv and RecvBuffer function header notes section.
|
||||
* CR620849.
|
||||
* 2.01a adk 18/04/13 Updated the code to avoid unused variable
|
||||
* warnings when compiling with the -Wextra -Wall flags
|
||||
* In the file xuartlite.c. CR:704999.
|
||||
* 3.1 nsk 21/07/15 Updated XUartLite_ReceiveBuffer function to update the
|
||||
* receive data into user buffer in critical region.
|
||||
* CR#865787.
|
||||
* 3.2 sk 11/10/15 Used UINTPTR instead of u32 for Baseaddress CR# 867425.
|
||||
* Changed the prototype of XUartLite_CfgInitialize API.
|
||||
* 3.6 rna 02/19/21 Added 'XUartLite_GetSR' internal API to read Status
|
||||
* register and update the error stats.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
/***************************** Include Files ********************************/
|
||||
|
||||
#include "xuartlite.h"
|
||||
#include "xuartlite_i.h"
|
||||
#include "xil_io.h"
|
||||
|
||||
/************************** Constant Definitions ****************************/
|
||||
|
||||
|
||||
/**************************** Type Definitions ******************************/
|
||||
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions ********************/
|
||||
|
||||
|
||||
/************************** Variable Definitions ****************************/
|
||||
/************************** Function Prototypes *****************************/
|
||||
|
||||
static void StubHandler(void *CallBackRef, unsigned int ByteCount);
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Initialize a XUartLite instance. The receive and transmit FIFOs of the
|
||||
* UART are not flushed, so the user may want to flush them. The hardware
|
||||
* device does not have any way to disable the receiver such that any valid
|
||||
* data may be present in the receive FIFO. This function disables the UART
|
||||
* interrupt. The baudrate and format of the data are fixed in the hardware
|
||||
* at hardware build time.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XUartLite instance.
|
||||
* @param Config is a reference to a structure containing information
|
||||
* about a specific UART Lite device. This function initializes an
|
||||
* InstancePtr object for a specific device specified by the
|
||||
* contents of Config. This function can initialize multiple
|
||||
* instance objects with the use of multiple calls giving different
|
||||
* Config information on each call.
|
||||
* @param EffectiveAddr is the device base address in the virtual memory
|
||||
* address space. The caller is responsible for keeping the address
|
||||
* mapping from EffectiveAddr to the device physical base address
|
||||
* unchanged once this function is invoked. Unexpected errors may
|
||||
* occur if the address mapping changes after this function is
|
||||
* called. If address translation is not used, use
|
||||
* Config->BaseAddress for this parameters, passing the physical
|
||||
* address instead.
|
||||
*
|
||||
* @return
|
||||
* - XST_SUCCESS if everything starts up as expected.
|
||||
*
|
||||
* @note The Config pointer argument is not used by this function,
|
||||
* but is provided to keep the function signature consistent
|
||||
* with other drivers.
|
||||
*
|
||||
*****************************************************************************/
|
||||
int XUartLite_CfgInitialize(XUartLite *InstancePtr, XUartLite_Config *Config,
|
||||
UINTPTR EffectiveAddr)
|
||||
{
|
||||
(void) Config;
|
||||
/*
|
||||
* Assert validates the input arguments
|
||||
*/
|
||||
Xil_AssertNonvoid(InstancePtr != NULL);
|
||||
|
||||
/*
|
||||
* Set some default values, including setting the callback
|
||||
* handlers to stubs.
|
||||
*/
|
||||
InstancePtr->SendBuffer.NextBytePtr = NULL;
|
||||
InstancePtr->SendBuffer.RemainingBytes = 0;
|
||||
InstancePtr->SendBuffer.RequestedBytes = 0;
|
||||
|
||||
InstancePtr->ReceiveBuffer.NextBytePtr = NULL;
|
||||
InstancePtr->ReceiveBuffer.RemainingBytes = 0;
|
||||
InstancePtr->ReceiveBuffer.RequestedBytes = 0;
|
||||
|
||||
InstancePtr->IsReady = XIL_COMPONENT_IS_READY;
|
||||
|
||||
#if (XPAR_XUARTLITE_USE_DCR_BRIDGE != 0)
|
||||
InstancePtr->RegBaseAddress = ((EffectiveAddr >> 2)) & 0xFFF;
|
||||
#else
|
||||
InstancePtr->RegBaseAddress = EffectiveAddr;
|
||||
#endif
|
||||
|
||||
InstancePtr->RecvHandler = StubHandler;
|
||||
InstancePtr->SendHandler = StubHandler;
|
||||
|
||||
/* Write to the control register to disable the interrupts, don't
|
||||
* reset the FIFOs are the user may want the data that's present
|
||||
*/
|
||||
XUartLite_WriteReg(InstancePtr->RegBaseAddress,
|
||||
XUL_CONTROL_REG_OFFSET, 0);
|
||||
|
||||
/*
|
||||
* Clear the statistics for this driver
|
||||
*/
|
||||
XUartLite_ClearStats(InstancePtr);
|
||||
|
||||
return XST_SUCCESS;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This functions sends the specified buffer of data using the UART in either
|
||||
* polled or interrupt driven modes. This function is non-blocking such that it
|
||||
* will return before the data has been sent by the UART. If the UART is busy
|
||||
* sending data, it will return and indicate zero bytes were sent.
|
||||
*
|
||||
* In a polled mode, this function will only send as much data as the UART can
|
||||
* buffer in the FIFO. The application may need to call it repeatedly to
|
||||
* send a buffer.
|
||||
*
|
||||
* In interrupt mode, this function will start sending the specified buffer and
|
||||
* then the interrupt handler of the driver will continue sending data until the
|
||||
* buffer has been sent. A callback function, as specified by the application,
|
||||
* will be called to indicate the completion of sending the buffer.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XUartLite instance.
|
||||
* @param DataBufferPtr is pointer to a buffer of data to be sent.
|
||||
* @param NumBytes contains the number of bytes to be sent. A value of
|
||||
* zero will stop a previous send operation that is in progress
|
||||
* in interrupt mode. Any data that was already put into the
|
||||
* transmit FIFO will be sent.
|
||||
*
|
||||
* @return The number of bytes actually sent.
|
||||
*
|
||||
* @note The number of bytes is not asserted so that this function may
|
||||
* be called with a value of zero to stop an operation that is
|
||||
* already in progress.
|
||||
*
|
||||
******************************************************************************/
|
||||
unsigned int XUartLite_Send(XUartLite *InstancePtr, u8 *DataBufferPtr,
|
||||
unsigned int NumBytes)
|
||||
{
|
||||
unsigned int BytesSent;
|
||||
u32 StatusRegister;
|
||||
|
||||
/*
|
||||
* Assert validates the input arguments
|
||||
*/
|
||||
Xil_AssertNonvoid(InstancePtr != NULL);
|
||||
Xil_AssertNonvoid(DataBufferPtr != NULL);
|
||||
Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
|
||||
Xil_AssertNonvoid(((signed)NumBytes) >= 0);
|
||||
|
||||
/*
|
||||
* Enter a critical region by disabling the UART interrupts to allow
|
||||
* this call to stop a previous operation that may be interrupt driven.
|
||||
*/
|
||||
StatusRegister = XUartLite_GetSR(InstancePtr);
|
||||
|
||||
XUartLite_WriteReg(InstancePtr->RegBaseAddress,
|
||||
XUL_CONTROL_REG_OFFSET, 0);
|
||||
|
||||
/*
|
||||
* Setup the specified buffer to be sent by setting the instance
|
||||
* variables so it can be sent with polled or interrupt mode
|
||||
*/
|
||||
InstancePtr->SendBuffer.RequestedBytes = NumBytes;
|
||||
InstancePtr->SendBuffer.RemainingBytes = NumBytes;
|
||||
InstancePtr->SendBuffer.NextBytePtr = DataBufferPtr;
|
||||
|
||||
/*
|
||||
* Restore the interrupt enable register to it's previous value such
|
||||
* that the critical region is exited.
|
||||
* This is done here to minimize the amount of time the interrupt is
|
||||
* disabled since there is only one interrupt and the receive could
|
||||
* be filling up while interrupts are blocked.
|
||||
*/
|
||||
|
||||
StatusRegister &= XUL_CR_ENABLE_INTR;
|
||||
XUartLite_WriteReg(InstancePtr->RegBaseAddress,
|
||||
XUL_CONTROL_REG_OFFSET, StatusRegister);
|
||||
|
||||
/*
|
||||
* Send the buffer using the UART and return the number of bytes sent
|
||||
*/
|
||||
BytesSent = XUartLite_SendBuffer(InstancePtr);
|
||||
|
||||
return BytesSent;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This function will attempt to receive a specified number of bytes of data
|
||||
* from the UART and store it into the specified buffer. This function is
|
||||
* designed for either polled or interrupt driven modes. It is non-blocking
|
||||
* such that it will return if no data has already received by the UART.
|
||||
*
|
||||
* In a polled mode, this function will only receive as much data as the UART
|
||||
* can buffer in the FIFO. The application may need to call it repeatedly to
|
||||
* receive a buffer. Polled mode is the default mode of operation for the driver.
|
||||
*
|
||||
* In interrupt mode, this function will start receiving and then the interrupt
|
||||
* handler of the driver will continue receiving data until the buffer has been
|
||||
* received. A callback function, as specified by the application, will be called
|
||||
* to indicate the completion of receiving the buffer or when any receive errors
|
||||
* or timeouts occur.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XUartLite instance.
|
||||
* @param DataBufferPtr is pointer to buffer for data to be received into.
|
||||
* @param NumBytes is the number of bytes to be received. A value of zero
|
||||
* will stop a previous receive operation that is in progress in
|
||||
* interrupt mode.
|
||||
*
|
||||
* @return The number of bytes received.
|
||||
*
|
||||
* @note The number of bytes is not asserted so that this function
|
||||
* may be called with a value of zero to stop an operation
|
||||
* that is already in progress.
|
||||
*
|
||||
*****************************************************************************/
|
||||
unsigned int XUartLite_Recv(XUartLite *InstancePtr, u8 *DataBufferPtr,
|
||||
unsigned int NumBytes)
|
||||
{
|
||||
unsigned int ReceivedCount;
|
||||
u32 StatusRegister;
|
||||
|
||||
/*
|
||||
* Assert validates the input arguments
|
||||
*/
|
||||
Xil_AssertNonvoid(InstancePtr != NULL);
|
||||
Xil_AssertNonvoid(DataBufferPtr != NULL);
|
||||
Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
|
||||
Xil_AssertNonvoid(((signed)NumBytes) >= 0);
|
||||
|
||||
/*
|
||||
* Enter a critical region by disabling all the UART interrupts to allow
|
||||
* this call to stop a previous operation that may be interrupt driven
|
||||
*/
|
||||
StatusRegister = XUartLite_GetSR(InstancePtr);
|
||||
XUartLite_WriteReg(InstancePtr->RegBaseAddress,
|
||||
XUL_CONTROL_REG_OFFSET, 0);
|
||||
|
||||
/*
|
||||
* Setup the specified buffer to be received by setting the instance
|
||||
* variables so it can be received with polled or interrupt mode
|
||||
*/
|
||||
InstancePtr->ReceiveBuffer.RequestedBytes = NumBytes;
|
||||
InstancePtr->ReceiveBuffer.RemainingBytes = NumBytes;
|
||||
InstancePtr->ReceiveBuffer.NextBytePtr = DataBufferPtr;
|
||||
|
||||
/*
|
||||
* Restore the interrupt enable register to it's previous value such
|
||||
* that the critical region is exited
|
||||
*/
|
||||
StatusRegister &= XUL_CR_ENABLE_INTR;
|
||||
XUartLite_WriteReg(InstancePtr->RegBaseAddress,
|
||||
XUL_CONTROL_REG_OFFSET, StatusRegister);
|
||||
|
||||
/*
|
||||
* Receive the data from the UART and return the number of bytes
|
||||
* received
|
||||
* This is done here to minimize the amount of time the interrupt is
|
||||
* disabled since there is only one interrupt and the transmit could
|
||||
* be emptying out while interrupts are blocked.
|
||||
*/
|
||||
ReceivedCount = XUartLite_ReceiveBuffer(InstancePtr);
|
||||
|
||||
return ReceivedCount;
|
||||
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This function resets the FIFOs, both transmit and receive, of the UART such
|
||||
* that they are emptied. Since the UART does not have any way to disable it
|
||||
* from receiving data, it may be necessary for the application to reset the
|
||||
* FIFOs to get rid of any unwanted data.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XUartLite instance .
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
*****************************************************************************/
|
||||
void XUartLite_ResetFifos(XUartLite *InstancePtr)
|
||||
{
|
||||
u32 Register;
|
||||
|
||||
Xil_AssertVoid(InstancePtr != NULL);
|
||||
Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
|
||||
|
||||
/*
|
||||
* Read the status register 1st such that the next write to the control
|
||||
* register won't destroy the state of the interrupt enable bit
|
||||
*/
|
||||
Register = XUartLite_ReadReg(InstancePtr->RegBaseAddress,
|
||||
XUL_STATUS_REG_OFFSET);
|
||||
|
||||
/*
|
||||
* Mask off the interrupt enable bit to maintain it's state.
|
||||
*/
|
||||
Register &= XUL_SR_INTR_ENABLED;
|
||||
|
||||
/*
|
||||
* Write to the control register to reset both FIFOs, these bits are
|
||||
* self-clearing such that there's no need to clear them
|
||||
*/
|
||||
XUartLite_WriteReg(InstancePtr->RegBaseAddress, XUL_CONTROL_REG_OFFSET,
|
||||
Register | XUL_CR_FIFO_TX_RESET | XUL_CR_FIFO_RX_RESET);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This function determines if the specified UART is sending data. If the
|
||||
* transmitter register is not empty, it is sending data.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XUartLite instance.
|
||||
*
|
||||
* @return A value of TRUE if the UART is sending data, otherwise FALSE.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
*****************************************************************************/
|
||||
int XUartLite_IsSending(XUartLite *InstancePtr)
|
||||
{
|
||||
u32 StatusRegister;
|
||||
|
||||
/*
|
||||
* Assert validates the input arguments
|
||||
*/
|
||||
Xil_AssertNonvoid(InstancePtr != NULL);
|
||||
|
||||
/*
|
||||
* Read the status register to determine if the transmitter is empty
|
||||
*/
|
||||
StatusRegister = XUartLite_ReadReg(InstancePtr->RegBaseAddress,
|
||||
XUL_STATUS_REG_OFFSET);
|
||||
|
||||
/*
|
||||
* If the transmitter is not empty then indicate that the UART is still
|
||||
* sending some data
|
||||
*/
|
||||
return ((StatusRegister & XUL_SR_TX_FIFO_EMPTY) == 0);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* This function provides a stub handler such that if the application does not
|
||||
* define a handler but enables interrupts, this function will be called.
|
||||
*
|
||||
* @param CallBackRef has no purpose but is necessary to match the
|
||||
* interface for a handler.
|
||||
* @param ByteCount has no purpose but is necessary to match the
|
||||
* interface for a handler.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
*****************************************************************************/
|
||||
static void StubHandler(void *CallBackRef, unsigned int ByteCount)
|
||||
{
|
||||
(void) CallBackRef;
|
||||
(void) ByteCount;
|
||||
/*
|
||||
* Assert occurs always since this is a stub and should never be called
|
||||
*/
|
||||
Xil_AssertVoidAlways();
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This function sends a buffer that has been previously specified by setting
|
||||
* up the instance variables of the instance. This function is designed to be
|
||||
* an internal function for the XUartLite component such that it may be called
|
||||
* from a shell function that sets up the buffer or from an interrupt handler.
|
||||
*
|
||||
* This function sends the specified buffer of data to the UART in either
|
||||
* polled or interrupt driven modes. This function is non-blocking such that
|
||||
* it will return before the data has been sent by the UART.
|
||||
*
|
||||
* In a polled mode, this function will only send as much data as the UART can
|
||||
* buffer, either in the transmitter or in the FIFO if present and enabled.
|
||||
* The application may need to call it repeatedly to send a buffer.
|
||||
*
|
||||
* In interrupt mode, this function will start sending the specified buffer and
|
||||
* then the interrupt handler of the driver will continue until the buffer
|
||||
* has been sent. A callback function, as specified by the application, will
|
||||
* be called to indicate the completion of sending the buffer.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XUartLite instance.
|
||||
*
|
||||
* @return NumBytes is the number of bytes actually sent (put into the
|
||||
* UART transmitter and/or FIFO).
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
*****************************************************************************/
|
||||
unsigned int XUartLite_SendBuffer(XUartLite *InstancePtr)
|
||||
{
|
||||
unsigned int SentCount = 0;
|
||||
u8 StatusRegister;
|
||||
u8 IntrEnableStatus;
|
||||
|
||||
/*
|
||||
* Read the status register to determine if the transmitter is full
|
||||
*/
|
||||
StatusRegister = XUartLite_GetSR(InstancePtr);
|
||||
|
||||
/*
|
||||
* Enter a critical region by disabling all the UART interrupts to allow
|
||||
* this call to stop a previous operation that may be interrupt driven
|
||||
*/
|
||||
StatusRegister = XUartLite_GetSR(InstancePtr);
|
||||
XUartLite_WriteReg(InstancePtr->RegBaseAddress,
|
||||
XUL_CONTROL_REG_OFFSET, 0);
|
||||
|
||||
/*
|
||||
* Save the status register contents to restore the interrupt enable
|
||||
* register to it's previous value when that the critical region is
|
||||
* exited
|
||||
*/
|
||||
IntrEnableStatus = StatusRegister;
|
||||
|
||||
/*
|
||||
* Fill the FIFO from the the buffer that was specified
|
||||
*/
|
||||
|
||||
while (((StatusRegister & XUL_SR_TX_FIFO_FULL) == 0) &&
|
||||
(SentCount < InstancePtr->SendBuffer.RemainingBytes)) {
|
||||
XUartLite_WriteReg(InstancePtr->RegBaseAddress,
|
||||
XUL_TX_FIFO_OFFSET,
|
||||
InstancePtr->SendBuffer.NextBytePtr[
|
||||
SentCount]);
|
||||
|
||||
SentCount++;
|
||||
|
||||
StatusRegister = XUartLite_GetSR(InstancePtr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Update the buffer to reflect the bytes that were sent from it
|
||||
*/
|
||||
InstancePtr->SendBuffer.NextBytePtr += SentCount;
|
||||
InstancePtr->SendBuffer.RemainingBytes -= SentCount;
|
||||
|
||||
/*
|
||||
* Increment associated counters
|
||||
*/
|
||||
InstancePtr->Stats.CharactersTransmitted += SentCount;
|
||||
|
||||
/*
|
||||
* Restore the interrupt enable register to it's previous value such
|
||||
* that the critical region is exited
|
||||
*/
|
||||
IntrEnableStatus &= XUL_CR_ENABLE_INTR;
|
||||
XUartLite_WriteReg(InstancePtr->RegBaseAddress, XUL_CONTROL_REG_OFFSET,
|
||||
IntrEnableStatus);
|
||||
|
||||
/*
|
||||
* Return the number of bytes that were sent, although they really were
|
||||
* only put into the FIFO, not completely sent yet
|
||||
*/
|
||||
return SentCount;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This function receives a buffer that has been previously specified by setting
|
||||
* up the instance variables of the instance. This function is designed to be
|
||||
* an internal function for the XUartLite component such that it may be called
|
||||
* from a shell function that sets up the buffer or from an interrupt handler.
|
||||
*
|
||||
* This function will attempt to receive a specified number of bytes of data
|
||||
* from the UART and store it into the specified buffer. This function is
|
||||
* designed for either polled or interrupt driven modes. It is non-blocking
|
||||
* such that it will return if there is no data has already received by the
|
||||
* UART.
|
||||
*
|
||||
* In a polled mode, this function will only receive as much data as the UART
|
||||
* can buffer, either in the receiver or in the FIFO if present and enabled.
|
||||
* The application may need to call it repeatedly to receive a buffer. Polled
|
||||
* mode is the default mode of operation for the driver.
|
||||
*
|
||||
* In interrupt mode, this function will start receiving and then the interrupt
|
||||
* handler of the driver will continue until the buffer has been received. A
|
||||
* callback function, as specified by the application, will be called to indicate
|
||||
* the completion of receiving the buffer or when any receive errors or timeouts
|
||||
* occur.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XUartLite instance.
|
||||
*
|
||||
* @return The number of bytes received.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
*****************************************************************************/
|
||||
unsigned int XUartLite_ReceiveBuffer(XUartLite *InstancePtr)
|
||||
{
|
||||
u8 StatusRegister;
|
||||
u8 StatusRegisterVal;
|
||||
unsigned int ReceivedCount = 0;
|
||||
|
||||
/*
|
||||
* Enter a critical region by disabling all the UART interrupts to allow
|
||||
* this call to stop a previous operation that may be interrupt driven
|
||||
*/
|
||||
StatusRegisterVal = XUartLite_GetSR(InstancePtr);
|
||||
XUartLite_WriteReg(InstancePtr->RegBaseAddress,
|
||||
XUL_CONTROL_REG_OFFSET, 0);
|
||||
/*
|
||||
* Loop until there is not more data buffered by the UART or the
|
||||
* specified number of bytes is received
|
||||
*/
|
||||
|
||||
while (ReceivedCount < InstancePtr->ReceiveBuffer.RemainingBytes) {
|
||||
/*
|
||||
* Read the Status Register to determine if there is any data in
|
||||
* the receiver/FIFO
|
||||
*/
|
||||
StatusRegister = XUartLite_GetSR(InstancePtr);
|
||||
|
||||
/*
|
||||
* If there is data ready to be removed, then put the next byte
|
||||
* received into the specified buffer and update the stats to
|
||||
* reflect any receive errors for the byte
|
||||
*/
|
||||
if (StatusRegister & XUL_SR_RX_FIFO_VALID_DATA) {
|
||||
InstancePtr->ReceiveBuffer.NextBytePtr[ReceivedCount++]=
|
||||
XUartLite_ReadReg(InstancePtr->RegBaseAddress,
|
||||
XUL_RX_FIFO_OFFSET);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* There's no more data buffered, so exit such that this
|
||||
* function does not block waiting for data
|
||||
*/
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Update the receive buffer to reflect the number of bytes that was
|
||||
* received
|
||||
*/
|
||||
InstancePtr->ReceiveBuffer.NextBytePtr += ReceivedCount;
|
||||
InstancePtr->ReceiveBuffer.RemainingBytes -= ReceivedCount;
|
||||
|
||||
/*
|
||||
* Increment associated counters in the statistics
|
||||
*/
|
||||
InstancePtr->Stats.CharactersReceived += ReceivedCount;
|
||||
|
||||
/*
|
||||
* Restore the interrupt enable register to it's previous value such
|
||||
* that the critical region is exited
|
||||
*/
|
||||
StatusRegisterVal &= XUL_CR_ENABLE_INTR;
|
||||
XUartLite_WriteReg(InstancePtr->RegBaseAddress,
|
||||
XUL_CONTROL_REG_OFFSET, StatusRegisterVal);
|
||||
|
||||
return ReceivedCount;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This function reads the status register and updates the error stats, before
|
||||
* returning the status register value. The status register is a clear on read
|
||||
* register, so the errors if occurred have to be recorded everytime status
|
||||
* register is read. This function is designed to be an internal function for
|
||||
* the XUartLite component such that it may be called from wherever the status
|
||||
* register needs to be read from the other driver functions.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XUartLite instance.
|
||||
*
|
||||
* @return The value of status register.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
*****************************************************************************/
|
||||
u8 XUartLite_GetSR(XUartLite *InstancePtr)
|
||||
{
|
||||
u8 StatusRegister;
|
||||
|
||||
StatusRegister = XUartLite_GetStatusReg(InstancePtr->RegBaseAddress);
|
||||
/*
|
||||
* Update Stats everytime status reg is read as it is a clear on read
|
||||
* register and as a result, there is a chance of missing the errors.
|
||||
*/
|
||||
XUartLite_UpdateStats(InstancePtr, StatusRegister);
|
||||
return StatusRegister;
|
||||
}
|
||||
|
||||
/** @} */
|
274
arm/hal/uart/xuartlite.h
Normal file
274
arm/hal/uart/xuartlite.h
Normal file
@@ -0,0 +1,274 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2002 - 2022 Xilinx, Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
******************************************************************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* @file xuartlite.h
|
||||
* @addtogroup uartlite_v3_7
|
||||
* @{
|
||||
* @details
|
||||
*
|
||||
* This component contains the implementation of the XUartLite component which is
|
||||
* the driver for the Xilinx UART Lite device. This UART is a minimal hardware
|
||||
* implementation with minimal features. Most of the features, including baud
|
||||
* rate, parity, and number of data bits are only configurable when the hardware
|
||||
* device is built, rather than at run time by software.
|
||||
*
|
||||
* The device has 16 byte transmit and receive FIFOs and supports interrupts.
|
||||
* The device does not have any way to disable the receiver such that the
|
||||
* receive FIFO may contain unwanted data. 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 when the transmit FIFO
|
||||
* transitions from having data to being empty or when any data is contained in
|
||||
* the receive FIFO.
|
||||
*
|
||||
* In order to use interrupts, it's necessary for the user to connect the driver
|
||||
* interrupt handler, XUartLite_InterruptHandler, to the interrupt system of the
|
||||
* application. This function does not save and restore the processor context
|
||||
* such that the user must provide it. Send and receive handlers may be set for
|
||||
* the driver such that the handlers are called when transmit and receive
|
||||
* interrupts occur. The handlers are called from interrupt context and are
|
||||
* designed to allow application specific processing to be performed.
|
||||
*
|
||||
* The functions, XUartLite_Send and XUartLite_Recv, are provided in the driver
|
||||
* to allow data to be sent and received. They are designed to be used in
|
||||
* polled or interrupt modes.
|
||||
*
|
||||
* The driver provides a status for each received byte indicating any parity
|
||||
* frame or overrun error. The driver provides statistics which allow visibility
|
||||
* into these errors.
|
||||
*
|
||||
* <b>Initialization & Configuration</b>
|
||||
*
|
||||
* The XUartLite_Config structure is used by the driver to configure itself. This
|
||||
* configuration structure is typically created by the tool-chain based on HW
|
||||
* build properties.
|
||||
*
|
||||
* To support multiple runtime loading and initialization strategies employed
|
||||
* by various operating systems, the driver instance can be initialized in one
|
||||
* of the following ways:
|
||||
*
|
||||
* - XUartLite_Initialize(InstancePtr, DeviceId) - The driver looks up its own
|
||||
* configuration structure created by the tool-chain based on an ID provided
|
||||
* by the tool-chain.
|
||||
*
|
||||
* - XUartLite_CfgInitialize(InstancePtr, CfgPtr, EffectiveAddr) - Uses a
|
||||
* configuration structure provided by the caller. If running in a system
|
||||
* with address translation, the provided virtual memory base address
|
||||
* replaces the physical address present in the configuration structure.
|
||||
*
|
||||
* <b>RTOS Independence</b>
|
||||
*
|
||||
* This driver is intended to be RTOS and processor independent. It works
|
||||
* with physical addresses only. Any needs for dynamic memory management,
|
||||
* threads or thread mutual exclusion, virtual memory, or cache control must
|
||||
* be satisfied by the layer above this driver.
|
||||
*
|
||||
* @note
|
||||
*
|
||||
* The driver is partitioned such that a minimal implementation may be used.
|
||||
* More features require additional files to be linked in.
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- ---- -------- -----------------------------------------------
|
||||
* 1.00a ecm 08/31/01 First release
|
||||
* 1.00b jhl 02/21/02 Repartitioned the driver for smaller files
|
||||
* 1.01a jvb 12/14/05 I separated dependency on the static config table and
|
||||
* xparameters.h from the driver initialization by moving
|
||||
* _Initialize and _LookupConfig to _sinit.c. I also added
|
||||
* the new _CfgInitialize routine.
|
||||
* 1.02a rpm 02/14/07 Added check for outstanding transmission before
|
||||
* calling the send callback (avoids extraneous
|
||||
* callback invocations) in interrupt service routine.
|
||||
* 1.12a mta 03/31/07 Updated to new coding conventions
|
||||
* 1.13a sv 01/21/08 Updated driver to support access through DCR bus
|
||||
* 1.14a sdm 08/22/08 Removed support for static interrupt handlers from the MDD
|
||||
* file
|
||||
* 1.14a sdm 09/26/08 Updated code to avoid race condition in
|
||||
* XUartLite_SendBuffer
|
||||
* 2.00a ktn 10/20/09 Updated to use HAL Processor APIs. The macros have been
|
||||
* renamed to remove _m from the name. XUartLite_mClearStats
|
||||
* macro is removed and XUartLite_ClearStats function should
|
||||
* be used in its place.
|
||||
* 2.01a adk 18/04/13 Updated the code to avoid unused variable
|
||||
* warnings when compiling with the -Wextra -Wall flags
|
||||
* In the file xuartlite.c. CR:704999.
|
||||
* Added notes for CR 710483 that the XUL_FIFO_SIZE is not
|
||||
* used in the driver. This is the size of the FIFO for
|
||||
* Transmit/Receive FIFOs which cannot be changed.
|
||||
* 3.0 adk 17/12/13 Fixed CR:741186,761863 Changes are made in the file
|
||||
* xuartlite_selftest.c
|
||||
* 3.0 adk 19/12/13 Update the driver as per new TCL API's
|
||||
* 3.1 nsk 21/07/15 Updated XUartLite_ReceiveBuffer function in xuartlite.c
|
||||
* to update the receive data into user buffer in critical
|
||||
* region.CR#865787.
|
||||
* 3.2 sk 11/10/15 Used UINTPTR instead of u32 for Baseaddress CR# 867425.
|
||||
* Changed the prototype of XUartLite_CfgInitialize API.
|
||||
* 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.
|
||||
* 3.3 sne 09/09/19 Updated driver tcl file for supporting pl and ps ip's.
|
||||
* 3.3 sne 09/13/19 Updated driver tcl file for mdm & tmr_sem ip's.
|
||||
* 3.7 adk 31/01/22 Fix interrupt controller name in SMP designs, Changes are
|
||||
* made in the interrupt app tcl file.
|
||||
* 3.7 adk 14/02/22 When generating peripheral tests for TMR subsystem based
|
||||
* designs don't pull the driver examples when uartlite is
|
||||
* configured as a TMR SEM fix for CR-1121291, changes are
|
||||
* made in the uartlite_tapp.tcl file.
|
||||
* </pre>
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef XUARTLITE_H /* prevent circular inclusions */
|
||||
#define XUARTLITE_H /* by using protection macros */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************** Include Files ********************************/
|
||||
|
||||
#include "xil_types.h"
|
||||
#include "xil_assert.h"
|
||||
#include "xstatus.h"
|
||||
|
||||
/************************** Constant Definitions ****************************/
|
||||
|
||||
/**************************** Type Definitions ******************************/
|
||||
|
||||
/**
|
||||
* Callback function. The first argument is a callback reference passed in by
|
||||
* the upper layer when setting the callback functions, and passed back to the
|
||||
* upper layer when the callback is invoked.
|
||||
* The second argument is the ByteCount which is the number of bytes that
|
||||
* actually moved from/to the buffer provided in the _Send/_Receive call.
|
||||
*/
|
||||
typedef void (*XUartLite_Handler)(void *CallBackRef, unsigned int ByteCount);
|
||||
|
||||
/**
|
||||
* Statistics for the XUartLite driver
|
||||
*/
|
||||
typedef struct {
|
||||
u32 TransmitInterrupts; /**< Number of transmit interrupts */
|
||||
u32 ReceiveInterrupts; /**< Number of receive interrupts */
|
||||
u32 CharactersTransmitted; /**< Number of characters transmitted */
|
||||
u32 CharactersReceived; /**< Number of characters received */
|
||||
u32 ReceiveOverrunErrors; /**< Number of receive overruns */
|
||||
u32 ReceiveParityErrors; /**< Number of receive parity errors */
|
||||
u32 ReceiveFramingErrors; /**< Number of receive framing errors */
|
||||
} XUartLite_Stats;
|
||||
|
||||
/**
|
||||
* The following data type is used to manage the buffers that are handled
|
||||
* when sending and receiving data in the interrupt mode. It is intended
|
||||
* for internal use only.
|
||||
*/
|
||||
typedef struct {
|
||||
u8 *NextBytePtr;
|
||||
unsigned int RequestedBytes;
|
||||
unsigned int RemainingBytes;
|
||||
} XUartLite_Buffer;
|
||||
|
||||
/**
|
||||
* This typedef contains configuration information for the device.
|
||||
*/
|
||||
typedef struct {
|
||||
u16 DeviceId; /**< Unique ID of device */
|
||||
UINTPTR RegBaseAddr; /**< Register base address */
|
||||
u32 BaudRate; /**< Fixed baud rate */
|
||||
u8 UseParity; /**< Parity generator enabled when TRUE */
|
||||
u8 ParityOdd; /**< Parity generated is odd when TRUE, even
|
||||
when FALSE */
|
||||
u8 DataBits; /**< Fixed data bits */
|
||||
} XUartLite_Config;
|
||||
|
||||
/**
|
||||
* The XUartLite driver instance data. The user is required to allocate a
|
||||
* variable of this type for every UART Lite device in the system. A pointer
|
||||
* to a variable of this type is then passed to the driver API functions.
|
||||
*/
|
||||
typedef struct {
|
||||
XUartLite_Stats Stats; /* Component Statistics */
|
||||
UINTPTR RegBaseAddress; /* Base address of registers */
|
||||
u32 IsReady; /* Device is initialized and ready */
|
||||
|
||||
XUartLite_Buffer SendBuffer;
|
||||
XUartLite_Buffer ReceiveBuffer;
|
||||
|
||||
XUartLite_Handler RecvHandler;
|
||||
void *RecvCallBackRef; /* Callback ref for recv handler */
|
||||
XUartLite_Handler SendHandler;
|
||||
void *SendCallBackRef; /* Callback ref for send handler */
|
||||
} XUartLite;
|
||||
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions ********************/
|
||||
|
||||
|
||||
/************************** Function Prototypes *****************************/
|
||||
|
||||
/*
|
||||
* Initialization functions in xuartlite_sinit.c
|
||||
*/
|
||||
int XUartLite_Initialize(XUartLite *InstancePtr, u16 DeviceId);
|
||||
XUartLite_Config *XUartLite_LookupConfig(u16 DeviceId);
|
||||
|
||||
/*
|
||||
* Required functions, in file xuart.c
|
||||
*/
|
||||
int XUartLite_CfgInitialize(XUartLite *InstancePtr,
|
||||
XUartLite_Config *Config,
|
||||
UINTPTR EffectiveAddr);
|
||||
|
||||
void XUartLite_ResetFifos(XUartLite *InstancePtr);
|
||||
|
||||
unsigned int XUartLite_Send(XUartLite *InstancePtr, u8 *DataBufferPtr,
|
||||
unsigned int NumBytes);
|
||||
unsigned int XUartLite_Recv(XUartLite *InstancePtr, u8 *DataBufferPtr,
|
||||
unsigned int NumBytes);
|
||||
|
||||
int XUartLite_IsSending(XUartLite *InstancePtr);
|
||||
|
||||
/*
|
||||
* Functions for statistics, in file xuartlite_stats.c
|
||||
*/
|
||||
void XUartLite_GetStats(XUartLite *InstancePtr, XUartLite_Stats *StatsPtr);
|
||||
void XUartLite_ClearStats(XUartLite *InstancePtr);
|
||||
|
||||
/*
|
||||
* Functions for self-test, in file xuartlite_selftest.c
|
||||
*/
|
||||
int XUartLite_SelfTest(XUartLite *InstancePtr);
|
||||
|
||||
/*
|
||||
* Functions for interrupts, in file xuartlite_intr.c
|
||||
*/
|
||||
void XUartLite_EnableInterrupt(XUartLite *InstancePtr);
|
||||
void XUartLite_DisableInterrupt(XUartLite *InstancePtr);
|
||||
|
||||
void XUartLite_SetRecvHandler(XUartLite *InstancePtr, XUartLite_Handler FuncPtr,
|
||||
void *CallBackRef);
|
||||
void XUartLite_SetSendHandler(XUartLite *InstancePtr, XUartLite_Handler FuncPtr,
|
||||
void *CallBackRef);
|
||||
|
||||
void XUartLite_InterruptHandler(XUartLite *InstancePtr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of protection macro */
|
||||
|
||||
/** @} */
|
63
arm/hal/uart/xuartlite_g.c
Normal file
63
arm/hal/uart/xuartlite_g.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2002 - 2022 Xilinx, Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
******************************************************************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* @file xuartlite_g.c
|
||||
* @addtogroup uartlite_v3_7
|
||||
* @{
|
||||
*
|
||||
* This file contains a configuration table that specifies the configuration of
|
||||
* UART Lite devices in the system. Each device in the system should have an
|
||||
* entry in the table.
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- ---- -------- -----------------------------------------------
|
||||
* 1.00a ecm 08/31/01 First release
|
||||
* 1.00b jhl 02/21/02 Repartitioned the driver for smaller files
|
||||
* </pre>
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/***************************** Include Files *********************************/
|
||||
|
||||
#include "xuartlite.h"
|
||||
#include "xparameters.h"
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
|
||||
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
|
||||
/************************** Function Prototypes ******************************/
|
||||
|
||||
|
||||
/************************** Variable Prototypes ******************************/
|
||||
|
||||
/**
|
||||
* The configuration table for UART Lite devices
|
||||
*/
|
||||
XUartLite_Config XUartLite_ConfigTable[XPAR_XUARTLITE_NUM_INSTANCES] =
|
||||
{
|
||||
{
|
||||
XPAR_UARTLITE_0_DEVICE_ID, /* Unique ID of device */
|
||||
XPAR_UARTLITE_0_BASEADDR, /* Device base address */
|
||||
XPAR_UARTLITE_0_BAUDRATE, /* Fixed baud rate */
|
||||
XPAR_UARTLITE_0_USE_PARITY, /* Fixed parity */
|
||||
XPAR_UARTLITE_0_ODD_PARITY, /* Fixed parity type */
|
||||
XPAR_UARTLITE_0_DATA_BITS /* Fixed data bits */
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/** @} */
|
100
arm/hal/uart/xuartlite_i.h
Normal file
100
arm/hal/uart/xuartlite_i.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2002 - 2022 Xilinx, Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
******************************************************************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* @file xuartlite_i.h
|
||||
* @addtogroup uartlite_v3_7
|
||||
* @{
|
||||
*
|
||||
* Contains data which is shared between the files of the XUartLite component.
|
||||
* It is intended for internal use only.
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- ---- -------- -----------------------------------------------
|
||||
* 1.00a ecm 08/31/01 First release
|
||||
* 1.00b jhl 02/21/02 Reparitioned the driver for smaller files
|
||||
* 1.00b rpm 04/24/02 Moved register definitions to xuartlite_l.h and
|
||||
* updated macro naming convention
|
||||
* 2.00a ktn 10/20/09 The macros have been renamed to remove _m from
|
||||
* the name. XUartLite_mClearStats macro is removed and
|
||||
* XUartLite_ClearStats function should be used in its place.
|
||||
* 3.6 rna 02/19/21 Added 'XUartLite_GetSR' internal API.
|
||||
* </pre>
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef XUARTLITE_I_H /* prevent circular inclusions */
|
||||
#define XUARTLITE_I_H /* by using protection macros */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************** Include Files ********************************/
|
||||
|
||||
#include "xuartlite.h"
|
||||
#include "xuartlite_l.h"
|
||||
|
||||
/************************** Constant Definitions ****************************/
|
||||
|
||||
/**************************** Type Definitions ******************************/
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions ********************/
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Update the statistics of the instance.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XUartLite instance.
|
||||
* @param StatusRegister contains the contents of the UART status
|
||||
* register to update the statistics with.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note
|
||||
*
|
||||
* Signature: void XUartLite_UpdateStats(XUartLite *InstancePtr,
|
||||
* u32 StatusRegister)
|
||||
*
|
||||
*****************************************************************************/
|
||||
#define XUartLite_UpdateStats(InstancePtr, StatusRegister) \
|
||||
{ \
|
||||
if ((StatusRegister) & XUL_SR_OVERRUN_ERROR) \
|
||||
{ \
|
||||
(InstancePtr)->Stats.ReceiveOverrunErrors++; \
|
||||
} \
|
||||
if ((StatusRegister) & XUL_SR_PARITY_ERROR) \
|
||||
{ \
|
||||
(InstancePtr)->Stats.ReceiveParityErrors++; \
|
||||
} \
|
||||
if ((StatusRegister) & XUL_SR_FRAMING_ERROR) \
|
||||
{ \
|
||||
(InstancePtr)->Stats.ReceiveFramingErrors++; \
|
||||
} \
|
||||
}
|
||||
|
||||
/************************** Variable Definitions ****************************/
|
||||
|
||||
/* the configuration table */
|
||||
extern XUartLite_Config XUartLite_ConfigTable[];
|
||||
|
||||
/************************** Function Prototypes *****************************/
|
||||
|
||||
unsigned int XUartLite_SendBuffer(XUartLite *InstancePtr);
|
||||
unsigned int XUartLite_ReceiveBuffer(XUartLite *InstancePtr);
|
||||
u8 XUartLite_GetSR(XUartLite *InstancePtr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of protection macro */
|
||||
|
||||
/** @} */
|
309
arm/hal/uart/xuartlite_intr.c
Normal file
309
arm/hal/uart/xuartlite_intr.c
Normal file
@@ -0,0 +1,309 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2002 - 2022 Xilinx, Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
******************************************************************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* @file xuartlite_intr.c
|
||||
* @addtogroup uartlite_v3_7
|
||||
* @{
|
||||
*
|
||||
* This file contains interrupt-related functions for the UART Lite component
|
||||
* (XUartLite).
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- ---- -------- -----------------------------------------------
|
||||
* 1.00a ecm 08/31/01 First release
|
||||
* 1.00b jhl 02/21/02 Repartitioned the driver for smaller files
|
||||
* 1.02a rpm 02/14/07 Added check for outstanding transmission before
|
||||
* calling the send callback (avoids extraneous
|
||||
* callback invocations)
|
||||
* 2.00a ktn 10/20/09 Updated to use HAL Processor APIs. The macros have been
|
||||
* renamed to remove _m from the name.
|
||||
* </pre>
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
/***************************** Include Files ********************************/
|
||||
|
||||
#include "xuartlite.h"
|
||||
#include "xuartlite_i.h"
|
||||
#include "xil_io.h"
|
||||
|
||||
/************************** Constant Definitions ****************************/
|
||||
|
||||
/**************************** Type Definitions ******************************/
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions ********************/
|
||||
|
||||
/************************** Function Prototypes *****************************/
|
||||
|
||||
static void ReceiveDataHandler(XUartLite *InstancePtr);
|
||||
static void SendDataHandler(XUartLite *InstancePtr);
|
||||
|
||||
/************************** Variable Definitions ****************************/
|
||||
|
||||
typedef void (*Handler)(XUartLite *InstancePtr);
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This function sets the handler that will be called when an event (interrupt)
|
||||
* occurs in the driver. The purpose of the handler is to allow application
|
||||
* specific processing to be performed.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XUartLite instance.
|
||||
* @param FuncPtr is the pointer to the callback function.
|
||||
* @param CallBackRef is the upper layer callback reference passed back
|
||||
* when the callback function is invoked.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note There is no assert on the CallBackRef since the driver doesn't
|
||||
* know what it is (nor should it)
|
||||
*
|
||||
*****************************************************************************/
|
||||
void XUartLite_SetRecvHandler(XUartLite *InstancePtr,
|
||||
XUartLite_Handler FuncPtr, void *CallBackRef)
|
||||
{
|
||||
/*
|
||||
* Assert validates the input arguments
|
||||
* CallBackRef not checked, no way to know what is valid
|
||||
*/
|
||||
Xil_AssertVoid(InstancePtr != NULL);
|
||||
Xil_AssertVoid(FuncPtr != NULL);
|
||||
Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
|
||||
|
||||
InstancePtr->RecvHandler = FuncPtr;
|
||||
InstancePtr->RecvCallBackRef = CallBackRef;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This function sets the handler that will be called when an event (interrupt)
|
||||
* occurs in the driver. The purpose of the handler is to allow application
|
||||
* specific processing to be performed.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XUartLite instance .
|
||||
* @param FuncPtr is the pointer to the callback function.
|
||||
* @param CallBackRef is the upper layer callback reference passed back
|
||||
* when the callback function is invoked.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note There is no assert on the CallBackRef since the driver doesn't
|
||||
* know what it is (nor should it)
|
||||
*
|
||||
*****************************************************************************/
|
||||
void XUartLite_SetSendHandler(XUartLite *InstancePtr,
|
||||
XUartLite_Handler FuncPtr, void *CallBackRef)
|
||||
{
|
||||
/*
|
||||
* Assert validates the input arguments
|
||||
* CallBackRef not checked, no way to know what is valid
|
||||
*/
|
||||
Xil_AssertVoid(InstancePtr != NULL);
|
||||
Xil_AssertVoid(FuncPtr != NULL);
|
||||
Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
|
||||
|
||||
InstancePtr->SendHandler = FuncPtr;
|
||||
InstancePtr->SendCallBackRef = CallBackRef;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This function is the interrupt handler for the UART lite driver.
|
||||
* It must be connected to an interrupt system by the user such that it is
|
||||
* called when an interrupt for any UART lite occurs. This function
|
||||
* does not save or restore the processor context such that the user must
|
||||
* ensure this occurs.
|
||||
*
|
||||
* @param InstancePtr contains a pointer to the instance of the UART that
|
||||
* the interrupt is for.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
******************************************************************************/
|
||||
void XUartLite_InterruptHandler(XUartLite *InstancePtr)
|
||||
{
|
||||
u32 IsrStatus;
|
||||
|
||||
Xil_AssertVoid(InstancePtr != NULL);
|
||||
|
||||
/*
|
||||
* Read the status register to determine which, coulb be both
|
||||
* interrupt is active
|
||||
*/
|
||||
IsrStatus = XUartLite_ReadReg(InstancePtr->RegBaseAddress,
|
||||
XUL_STATUS_REG_OFFSET);
|
||||
|
||||
if ((IsrStatus & (XUL_SR_RX_FIFO_FULL |
|
||||
XUL_SR_RX_FIFO_VALID_DATA)) != 0) {
|
||||
ReceiveDataHandler(InstancePtr);
|
||||
}
|
||||
|
||||
if (((IsrStatus & XUL_SR_TX_FIFO_EMPTY) != 0) &&
|
||||
(InstancePtr->SendBuffer.RequestedBytes > 0)) {
|
||||
SendDataHandler(InstancePtr);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This function handles the interrupt when data is received, either a single
|
||||
* byte when FIFOs are not enabled, or multiple bytes with the FIFO.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XUartLite instance.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
*****************************************************************************/
|
||||
static void ReceiveDataHandler(XUartLite *InstancePtr)
|
||||
{
|
||||
/*
|
||||
* If there are bytes still to be received in the specified buffer
|
||||
* go ahead and receive them
|
||||
*/
|
||||
if (InstancePtr->ReceiveBuffer.RemainingBytes != 0) {
|
||||
XUartLite_ReceiveBuffer(InstancePtr);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the last byte of a message was received then call the application
|
||||
* handler, this code should not use an else from the previous check of
|
||||
* the number of bytes to receive because the call to receive the buffer
|
||||
* updates the bytes to receive
|
||||
*/
|
||||
if (InstancePtr->ReceiveBuffer.RemainingBytes == 0) {
|
||||
InstancePtr->RecvHandler(InstancePtr->RecvCallBackRef,
|
||||
InstancePtr->ReceiveBuffer.RequestedBytes -
|
||||
InstancePtr->ReceiveBuffer.RemainingBytes);
|
||||
}
|
||||
|
||||
/*
|
||||
* Update the receive stats to reflect the receive interrupt
|
||||
*/
|
||||
InstancePtr->Stats.ReceiveInterrupts++;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This function handles the interrupt when data has been sent, the transmit
|
||||
* FIFO is empty (transmitter holding register).
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XUartLite instance .
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
*****************************************************************************/
|
||||
static void SendDataHandler(XUartLite *InstancePtr)
|
||||
{
|
||||
/*
|
||||
* If there are not bytes to be sent from the specified buffer,
|
||||
* call the callback function
|
||||
*/
|
||||
if (InstancePtr->SendBuffer.RemainingBytes == 0) {
|
||||
int SaveReq;
|
||||
|
||||
/*
|
||||
* Save and zero the requested bytes since transmission
|
||||
* is complete
|
||||
*/
|
||||
SaveReq = InstancePtr->SendBuffer.RequestedBytes;
|
||||
InstancePtr->SendBuffer.RequestedBytes = 0;
|
||||
|
||||
/*
|
||||
* Call the application handler to indicate
|
||||
* the data has been sent
|
||||
*/
|
||||
InstancePtr->SendHandler(InstancePtr->SendCallBackRef, SaveReq);
|
||||
}
|
||||
/*
|
||||
* Otherwise there is still more data to send in the specified buffer
|
||||
* so go ahead and send it
|
||||
*/
|
||||
else {
|
||||
XUartLite_SendBuffer(InstancePtr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Update the transmit stats to reflect the transmit interrupt
|
||||
*/
|
||||
InstancePtr->Stats.TransmitInterrupts++;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This function disables the UART interrupt. After calling this function,
|
||||
* data may still be received by the UART but no interrupt will be generated
|
||||
* since the hardware device has no way to disable the receiver.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XUartLite instance.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
*****************************************************************************/
|
||||
void XUartLite_DisableInterrupt(XUartLite *InstancePtr)
|
||||
{
|
||||
Xil_AssertVoid(InstancePtr != NULL);
|
||||
Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
|
||||
|
||||
/*
|
||||
* Write to the control register to disable the interrupts, the only
|
||||
* other bits in this register are the FIFO reset bits such that
|
||||
* writing them to zero will not affect them.
|
||||
*/
|
||||
XUartLite_WriteReg(InstancePtr->RegBaseAddress,
|
||||
XUL_CONTROL_REG_OFFSET, 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This function enables the UART interrupt such that an interrupt will occur
|
||||
* when data is received or data has been transmitted. The device contains
|
||||
* 16 byte receive and transmit FIFOs such that an interrupt is generated
|
||||
* anytime there is data in the receive FIFO and when the transmit FIFO
|
||||
* transitions from not empty to empty.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XUartLite instance.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
*****************************************************************************/
|
||||
void XUartLite_EnableInterrupt(XUartLite *InstancePtr)
|
||||
{
|
||||
Xil_AssertVoid(InstancePtr != NULL);
|
||||
Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
|
||||
|
||||
/*
|
||||
* Write to the control register to enable the interrupts, the only
|
||||
* other bits in this register are the FIFO reset bits such that
|
||||
* writing them to zero will not affect them.
|
||||
*/
|
||||
XUartLite_WriteReg(InstancePtr->RegBaseAddress,
|
||||
XUL_CONTROL_REG_OFFSET, XUL_CR_ENABLE_INTR);
|
||||
}
|
||||
|
||||
/** @} */
|
95
arm/hal/uart/xuartlite_l.c
Normal file
95
arm/hal/uart/xuartlite_l.c
Normal file
@@ -0,0 +1,95 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2002 - 2022 Xilinx, Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
******************************************************************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* @file xuartlite_l.c
|
||||
* @addtogroup uartlite_v3_7
|
||||
* @{
|
||||
*
|
||||
* This file contains low-level driver functions that can be used to access the
|
||||
* device. The user should refer to the hardware device specification for more
|
||||
* details of the device operation.
|
||||
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- ---- -------- -----------------------------------------------
|
||||
* 1.00b rpm 04/25/02 First release
|
||||
* 1.12a rpm 07/16/07 Fixed arg type for RecvByte
|
||||
* 2.00a ktn 10/20/09 The macros have been renamed to remove _m from the name.
|
||||
* 3.2 sk 11/10/15 Used UINTPTR instead of u32 for Baseaddress CR# 867425.
|
||||
* Changed the prototypes of XUartLite_SendByte,
|
||||
* XUartLite_RecvByte APIs.
|
||||
* </pre>
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/***************************** Include Files *********************************/
|
||||
|
||||
#include "xuartlite_l.h"
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
|
||||
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
|
||||
/************************** Function Prototypes ******************************/
|
||||
|
||||
|
||||
/************************** Variable Prototypes ******************************/
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This functions sends a single byte using the UART. It is blocking in that it
|
||||
* waits for the transmitter to become non-full before it writes the byte to
|
||||
* the transmit register.
|
||||
*
|
||||
* @param BaseAddress is the base address of the device
|
||||
* @param Data is the byte of data to send
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
******************************************************************************/
|
||||
void XUartLite_SendByte(UINTPTR BaseAddress, u8 Data)
|
||||
{
|
||||
while (XUartLite_IsTransmitFull(BaseAddress));
|
||||
|
||||
XUartLite_WriteReg(BaseAddress, XUL_TX_FIFO_OFFSET, Data);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This functions receives a single byte using the UART. It is blocking in that
|
||||
* it waits for the receiver to become non-empty before it reads from the
|
||||
* receive register.
|
||||
*
|
||||
* @param BaseAddress is the base address of the device
|
||||
*
|
||||
* @return The byte of data received.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
******************************************************************************/
|
||||
u8 XUartLite_RecvByte(UINTPTR BaseAddress)
|
||||
{
|
||||
while (XUartLite_IsReceiveEmpty(BaseAddress));
|
||||
|
||||
return (u8)XUartLite_ReadReg(BaseAddress, XUL_RX_FIFO_OFFSET);
|
||||
}
|
||||
|
||||
/** @} */
|
310
arm/hal/uart/xuartlite_l.h
Normal file
310
arm/hal/uart/xuartlite_l.h
Normal file
@@ -0,0 +1,310 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2002 - 2022 Xilinx, Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
******************************************************************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* @file xuartlite_l.h
|
||||
* @addtogroup uartlite_v3_7
|
||||
* @{
|
||||
*
|
||||
* This header file contains identifiers and low-level driver functions (or
|
||||
* macros) that can be used to access the device. High-level driver functions
|
||||
* are defined in xuartlite.h.
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- ---- -------- -------------------------------------------------------
|
||||
* 1.00b rpm 04/25/02 First release
|
||||
* 1.00b rpm 07/07/03 Removed references to XUartLite_GetControlReg macro
|
||||
* since the control register is write-only
|
||||
* 1.12a mta 03/21/07 Updated to new coding style
|
||||
* 1.13a sv 01/21/08 Updated driver to support access through DCR bus
|
||||
* 2.00a ktn 10/20/09 Updated to use HAL Processor APIs. The macros have been
|
||||
* renamed to remove _m from the name.
|
||||
* 3.2 sk 11/10/15 Used UINTPTR instead of u32 for Baseaddress CR# 867425.
|
||||
* Changed the prototypes of XUartLite_SendByte,
|
||||
* XUartLite_RecvByte APIs.
|
||||
* </pre>
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef XUARTLITE_L_H /* prevent circular inclusions */
|
||||
#define XUARTLITE_L_H /* by using protection macros */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************** Include Files ********************************/
|
||||
|
||||
#include "xil_types.h"
|
||||
#include "xil_assert.h"
|
||||
#include "xil_io.h"
|
||||
|
||||
/*
|
||||
* XPAR_XUARTLITE_USE_DCR_BRIDGE has to be set to 1 if the UartLite device is
|
||||
* accessed through a DCR bus connected to a bridge.
|
||||
*/
|
||||
#define XPAR_XUARTLITE_USE_DCR_BRIDGE 0
|
||||
|
||||
#if (XPAR_XUARTLITE_USE_DCR_BRIDGE != 0)
|
||||
#include "xio_dcr.h"
|
||||
#endif
|
||||
|
||||
|
||||
/************************** Constant Definitions ****************************/
|
||||
|
||||
/* UART Lite register offsets */
|
||||
|
||||
#if (XPAR_XUARTLITE_USE_DCR_BRIDGE != 0)
|
||||
#define XUL_RX_FIFO_OFFSET 0 /* receive FIFO, read only */
|
||||
#define XUL_TX_FIFO_OFFSET 1 /* transmit FIFO, write only */
|
||||
#define XUL_STATUS_REG_OFFSET 2 /* status register, read only */
|
||||
#define XUL_CONTROL_REG_OFFSET 3 /* control reg, write only */
|
||||
|
||||
#else
|
||||
|
||||
#define XUL_RX_FIFO_OFFSET 0 /* receive FIFO, read only */
|
||||
#define XUL_TX_FIFO_OFFSET 4 /* transmit FIFO, write only */
|
||||
#define XUL_STATUS_REG_OFFSET 8 /* status register, read only */
|
||||
#define XUL_CONTROL_REG_OFFSET 12 /* control reg, write only */
|
||||
|
||||
#endif
|
||||
|
||||
/* Control Register bit positions */
|
||||
|
||||
#define XUL_CR_ENABLE_INTR 0x10 /* enable interrupt */
|
||||
#define XUL_CR_FIFO_RX_RESET 0x02 /* reset receive FIFO */
|
||||
#define XUL_CR_FIFO_TX_RESET 0x01 /* reset transmit FIFO */
|
||||
|
||||
/* Status Register bit positions */
|
||||
|
||||
#define XUL_SR_PARITY_ERROR 0x80
|
||||
#define XUL_SR_FRAMING_ERROR 0x40
|
||||
#define XUL_SR_OVERRUN_ERROR 0x20
|
||||
#define XUL_SR_INTR_ENABLED 0x10 /* interrupt enabled */
|
||||
#define XUL_SR_TX_FIFO_FULL 0x08 /* transmit FIFO full */
|
||||
#define XUL_SR_TX_FIFO_EMPTY 0x04 /* transmit FIFO empty */
|
||||
#define XUL_SR_RX_FIFO_FULL 0x02 /* receive FIFO full */
|
||||
#define XUL_SR_RX_FIFO_VALID_DATA 0x01 /* data in receive FIFO */
|
||||
|
||||
/* The following constant specifies the size of the Transmit/Receive FIFOs.
|
||||
* The FIFO size is fixed to 16 in the Uartlite IP and the size is not
|
||||
* configurable. This constant is not used in the driver.
|
||||
*/
|
||||
#define XUL_FIFO_SIZE 16
|
||||
|
||||
/* Stop bits are fixed at 1. Baud, parity, and data bits are fixed on a
|
||||
* per instance basis
|
||||
*/
|
||||
#define XUL_STOP_BITS 1
|
||||
|
||||
/* Parity definitions
|
||||
*/
|
||||
#define XUL_PARITY_NONE 0
|
||||
#define XUL_PARITY_ODD 1
|
||||
#define XUL_PARITY_EVEN 2
|
||||
|
||||
/**************************** Type Definitions ******************************/
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions ********************/
|
||||
|
||||
/*
|
||||
* Define the appropriate I/O access method to memory mapped I/O or DCR.
|
||||
*/
|
||||
#if (XPAR_XUARTLITE_USE_DCR_BRIDGE != 0)
|
||||
|
||||
#define XUartLite_In32 XIo_DcrIn
|
||||
#define XUartLite_Out32 XIo_DcrOut
|
||||
|
||||
#else
|
||||
|
||||
#define XUartLite_In32 Xil_In32
|
||||
#define XUartLite_Out32 Xil_Out32
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Write a value to a UartLite register. A 32 bit write is performed.
|
||||
*
|
||||
* @param BaseAddress is the base address of the UartLite device.
|
||||
* @param RegOffset is the register offset from the base to write to.
|
||||
* @param Data is the data written to the register.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note C-style signature:
|
||||
* void XUartLite_WriteReg(u32 BaseAddress, u32 RegOffset,
|
||||
* u32 Data)
|
||||
*
|
||||
****************************************************************************/
|
||||
#define XUartLite_WriteReg(BaseAddress, RegOffset, Data) \
|
||||
XUartLite_Out32((BaseAddress) + (RegOffset), (u32)(Data))
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Read a value from a UartLite register. A 32 bit read is performed.
|
||||
*
|
||||
* @param BaseAddress is the base address of the UartLite device.
|
||||
* @param RegOffset is the register offset from the base to read from.
|
||||
*
|
||||
* @return Data read from the register.
|
||||
*
|
||||
* @note C-style signature:
|
||||
* u32 XUartLite_ReadReg(u32 BaseAddress, u32 RegOffset)
|
||||
*
|
||||
****************************************************************************/
|
||||
#define XUartLite_ReadReg(BaseAddress, RegOffset) \
|
||||
XUartLite_In32((BaseAddress) + (RegOffset))
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Set the contents of the control register. Use the XUL_CR_* constants defined
|
||||
* above to create the bit-mask to be written to the register.
|
||||
*
|
||||
* @param BaseAddress is the base address of the device
|
||||
* @param Mask is the 32-bit value to write to the control register
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note C-style Signature:
|
||||
* void XUartLite_SetControlReg(u32 BaseAddress, u32 Mask);
|
||||
*
|
||||
*****************************************************************************/
|
||||
#define XUartLite_SetControlReg(BaseAddress, Mask) \
|
||||
XUartLite_WriteReg((BaseAddress), XUL_CONTROL_REG_OFFSET, (Mask))
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Get the contents of the status register. Use the XUL_SR_* constants defined
|
||||
* above to interpret the bit-mask returned.
|
||||
*
|
||||
* @param BaseAddress is the base address of the device
|
||||
*
|
||||
* @return A 32-bit value representing the contents of the status register.
|
||||
*
|
||||
* @note C-style Signature:
|
||||
* u32 XUartLite_GetStatusReg(u32 BaseAddress);
|
||||
*
|
||||
*****************************************************************************/
|
||||
#define XUartLite_GetStatusReg(BaseAddress) \
|
||||
XUartLite_ReadReg((BaseAddress), XUL_STATUS_REG_OFFSET)
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Check to see if the receiver has data.
|
||||
*
|
||||
* @param BaseAddress is the base address of the device
|
||||
*
|
||||
* @return TRUE if the receiver is empty, FALSE if there is data present.
|
||||
*
|
||||
* @note C-style Signature:
|
||||
* int XUartLite_IsReceiveEmpty(u32 BaseAddress);
|
||||
*
|
||||
*****************************************************************************/
|
||||
#define XUartLite_IsReceiveEmpty(BaseAddress) \
|
||||
((XUartLite_GetStatusReg((BaseAddress)) & XUL_SR_RX_FIFO_VALID_DATA) != \
|
||||
XUL_SR_RX_FIFO_VALID_DATA)
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Check to see if the transmitter is full.
|
||||
*
|
||||
* @param BaseAddress is the base address of the device
|
||||
*
|
||||
* @return TRUE if the transmitter is full, FALSE otherwise.
|
||||
*
|
||||
* @note C-style Signature:
|
||||
* int XUartLite_IsTransmitFull(u32 BaseAddress);
|
||||
*
|
||||
*****************************************************************************/
|
||||
#define XUartLite_IsTransmitFull(BaseAddress) \
|
||||
((XUartLite_GetStatusReg((BaseAddress)) & XUL_SR_TX_FIFO_FULL) == \
|
||||
XUL_SR_TX_FIFO_FULL)
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Check to see if the interrupt is enabled.
|
||||
*
|
||||
* @param BaseAddress is the base address of the device
|
||||
*
|
||||
* @return TRUE if the interrupt is enabled, FALSE otherwise.
|
||||
*
|
||||
* @note C-style Signature:
|
||||
* int XUartLite_IsIntrEnabled(u32 BaseAddress);
|
||||
*
|
||||
*****************************************************************************/
|
||||
#define XUartLite_IsIntrEnabled(BaseAddress) \
|
||||
((XUartLite_GetStatusReg((BaseAddress)) & XUL_SR_INTR_ENABLED) == \
|
||||
XUL_SR_INTR_ENABLED)
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Enable the device interrupt. We cannot read the control register, so we
|
||||
* just write the enable interrupt bit and clear all others. Since the only
|
||||
* other ones are the FIFO reset bits, this works without side effects.
|
||||
*
|
||||
* @param BaseAddress is the base address of the device
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note C-style Signature:
|
||||
* void XUartLite_EnableIntr(u32 BaseAddress);
|
||||
*
|
||||
*****************************************************************************/
|
||||
#define XUartLite_EnableIntr(BaseAddress) \
|
||||
XUartLite_SetControlReg((BaseAddress), XUL_CR_ENABLE_INTR)
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Disable the device interrupt. We cannot read the control register, so we
|
||||
* just clear all bits. Since the only other ones are the FIFO reset bits,
|
||||
* this works without side effects.
|
||||
*
|
||||
* @param BaseAddress is the base address of the device
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note C-style Signature:
|
||||
* void XUartLite_DisableIntr(u32 BaseAddress);
|
||||
*
|
||||
*****************************************************************************/
|
||||
#define XUartLite_DisableIntr(BaseAddress) \
|
||||
XUartLite_SetControlReg((BaseAddress), 0)
|
||||
|
||||
/************************** Function Prototypes *****************************/
|
||||
|
||||
void XUartLite_SendByte(UINTPTR BaseAddress, u8 Data);
|
||||
u8 XUartLite_RecvByte(UINTPTR BaseAddress);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of protection macro */
|
||||
|
||||
|
||||
/** @} */
|
114
arm/hal/uart/xuartlite_selftest.c
Normal file
114
arm/hal/uart/xuartlite_selftest.c
Normal file
@@ -0,0 +1,114 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2002 - 2022 Xilinx, Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
******************************************************************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* @file xuartlite_selftest.c
|
||||
* @addtogroup uartlite_v3_7
|
||||
* @{
|
||||
*
|
||||
* This file contains the self-test functions for the UART Lite component
|
||||
* (XUartLite).
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- ---- -------- -----------------------------------------------
|
||||
* 1.00a ecm 08/31/01 First release
|
||||
* 1.00b jhl 02/21/02 Repartitioned the driver for smaller files
|
||||
* 2.00a ktn 10/20/09 Updated to use HAL Processor APIs. The macros have been
|
||||
* renamed to remove _m from the name.
|
||||
* 3.0 adk 17/12/13 Fixed CR:741186,761863 Reset the FIFO's before reading
|
||||
* the status register We don't know the status of the Status
|
||||
* Register in case of if there is more than one uartlite IP
|
||||
* instance in the h/w design.
|
||||
* </pre>
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
/***************************** Include Files ********************************/
|
||||
|
||||
#include "xil_types.h"
|
||||
#include "xil_assert.h"
|
||||
#include "xstatus.h"
|
||||
#include "xuartlite.h"
|
||||
#include "xuartlite_i.h"
|
||||
#include "xil_io.h"
|
||||
|
||||
/************************** Constant Definitions ****************************/
|
||||
|
||||
|
||||
/**************************** Type Definitions ******************************/
|
||||
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions ********************/
|
||||
|
||||
|
||||
/************************** Variable Definitions ****************************/
|
||||
|
||||
|
||||
/************************** Function Prototypes *****************************/
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Runs a self-test on the device hardware. Since there is no way to perform a
|
||||
* loopback in the hardware, this test can only check the state of the status
|
||||
* register to verify it is correct. This test assumes that the hardware
|
||||
* device is still in its reset state, but has been initialized with the
|
||||
* Initialize function.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XUartLite instance.
|
||||
*
|
||||
* @return
|
||||
* - XST_SUCCESS if the self-test was successful.
|
||||
* - XST_FAILURE if the self-test failed, the status register
|
||||
* value was not correct
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
******************************************************************************/
|
||||
int XUartLite_SelfTest(XUartLite *InstancePtr)
|
||||
{
|
||||
u32 StatusRegister;
|
||||
|
||||
/*
|
||||
* Assert validates the input arguments
|
||||
*/
|
||||
Xil_AssertNonvoid(InstancePtr != NULL);
|
||||
Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
|
||||
|
||||
/*
|
||||
* Reset the FIFO's before reading the status register.
|
||||
* It is likely that the Uartlite IP may not always have an
|
||||
* empty Tx and Rx FIFO when a selftest is performed if more than one
|
||||
* uartlite instance is present in the h/w design.
|
||||
*/
|
||||
XUartLite_ResetFifos(InstancePtr);
|
||||
|
||||
/*
|
||||
* Read the Status register value to check if it is the correct value
|
||||
* after a reset
|
||||
*/
|
||||
StatusRegister = XUartLite_ReadReg(InstancePtr->RegBaseAddress,
|
||||
XUL_STATUS_REG_OFFSET);
|
||||
|
||||
/*
|
||||
* If the status register is any other value other than
|
||||
* XUL_SR_TX_FIFO_EMPTY then the test is a failure since this is
|
||||
* the not the value after reset
|
||||
*/
|
||||
if (StatusRegister != XUL_SR_TX_FIFO_EMPTY) {
|
||||
return XST_FAILURE;
|
||||
}
|
||||
|
||||
return XST_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/** @} */
|
122
arm/hal/uart/xuartlite_sinit.c
Normal file
122
arm/hal/uart/xuartlite_sinit.c
Normal file
@@ -0,0 +1,122 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2005 - 2022 Xilinx, Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
******************************************************************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* @file xuartlite_sinit.c
|
||||
* @addtogroup uartlite_v3_7
|
||||
* @{
|
||||
*
|
||||
* The implementation of the XUartLite component's static initialization
|
||||
* functionality.
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- ---- -------- -----------------------------------------------
|
||||
* 1.01a jvb 10/13/05 First release
|
||||
* 2.00a ktn 10/20/09 Updated to use HAL Processor APIs.
|
||||
* </pre>
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
/***************************** Include Files ********************************/
|
||||
|
||||
#include "xstatus.h"
|
||||
#include "xparameters.h"
|
||||
#include "xuartlite_i.h"
|
||||
|
||||
/************************** Constant Definitions ****************************/
|
||||
|
||||
|
||||
/**************************** Type Definitions ******************************/
|
||||
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions ********************/
|
||||
|
||||
|
||||
/************************** Variable Definitions ****************************/
|
||||
|
||||
|
||||
/************************** Function Prototypes *****************************/
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Looks up the device configuration based on the unique device ID. The table
|
||||
* UartliteConfigTable contains the configuration info for each device in the
|
||||
* system.
|
||||
*
|
||||
* @param DeviceId is the unique device ID to match on.
|
||||
*
|
||||
* @return A pointer to the configuration data for the device, or
|
||||
* NULL if no match was found.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
******************************************************************************/
|
||||
XUartLite_Config *XUartLite_LookupConfig(u16 DeviceId)
|
||||
{
|
||||
XUartLite_Config *CfgPtr = NULL;
|
||||
u32 Index;
|
||||
|
||||
for (Index=0; Index < XPAR_XUARTLITE_NUM_INSTANCES; Index++) {
|
||||
if (XUartLite_ConfigTable[Index].DeviceId == DeviceId) {
|
||||
CfgPtr = &XUartLite_ConfigTable[Index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return CfgPtr;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Initialize a XUartLite instance. The receive and transmit FIFOs of the
|
||||
* UART are not flushed, so the user may want to flush them. The hardware
|
||||
* device does not have any way to disable the receiver such that any valid
|
||||
* data may be present in the receive FIFO. This function disables the UART
|
||||
* interrupt. The baudrate and format of the data are fixed in the hardware
|
||||
* at hardware build time.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XUartLite instance.
|
||||
* @param DeviceId is the unique id of the device controlled by this
|
||||
* XUartLite instance. Passing in a device id associates the
|
||||
* generic XUartLite instance to a specific device, as chosen by
|
||||
* the caller or application developer.
|
||||
*
|
||||
* @return
|
||||
* - XST_SUCCESS if everything starts up as expected.
|
||||
* - XST_DEVICE_NOT_FOUND if the device is not found in the
|
||||
* configuration table.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
*****************************************************************************/
|
||||
int XUartLite_Initialize(XUartLite *InstancePtr, u16 DeviceId)
|
||||
{
|
||||
XUartLite_Config *ConfigPtr;
|
||||
|
||||
/*
|
||||
* Assert validates the input arguments
|
||||
*/
|
||||
Xil_AssertNonvoid(InstancePtr != NULL);
|
||||
|
||||
/*
|
||||
* Lookup the device configuration in the configuration table. Use this
|
||||
* configuration info when initializing this component.
|
||||
*/
|
||||
ConfigPtr = XUartLite_LookupConfig(DeviceId);
|
||||
|
||||
if (ConfigPtr == (XUartLite_Config *)NULL) {
|
||||
return XST_DEVICE_NOT_FOUND;
|
||||
}
|
||||
return XUartLite_CfgInitialize(InstancePtr, ConfigPtr,
|
||||
ConfigPtr->RegBaseAddr);
|
||||
}
|
||||
|
||||
/** @} */
|
118
arm/hal/uart/xuartlite_stats.c
Normal file
118
arm/hal/uart/xuartlite_stats.c
Normal file
@@ -0,0 +1,118 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2002 - 2022 Xilinx, Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
******************************************************************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* @file xuartlite_stats.c
|
||||
* @addtogroup uartlite_v3_7
|
||||
* @{
|
||||
*
|
||||
* This file contains the statistics functions for the UART Lite component
|
||||
* (XUartLite).
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- ---- -------- -----------------------------------------------
|
||||
* 1.00a ecm 08/31/01 First release
|
||||
* 1.00b jhl 02/21/02 Repartitioned the driver for smaller files
|
||||
* 2.00a ktn 10/20/09 Updated to use HAL Processor APIs.
|
||||
* XUartLite_mClearStats macro is removed.
|
||||
* </pre>
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
/***************************** Include Files ********************************/
|
||||
|
||||
#include "xil_types.h"
|
||||
#include "xil_assert.h"
|
||||
#include "xuartlite.h"
|
||||
#include "xuartlite_i.h"
|
||||
|
||||
/************************** Constant Definitions ****************************/
|
||||
|
||||
|
||||
/**************************** Type Definitions ******************************/
|
||||
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions ********************/
|
||||
|
||||
|
||||
/************************** Variable Definitions ****************************/
|
||||
|
||||
|
||||
/************************** Function Prototypes *****************************/
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Returns a snapshot of the current statistics in the structure specified.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XUartLite instance.
|
||||
* @param StatsPtr is a pointer to a XUartLiteStats structure to where the
|
||||
* statistics are to be copied.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
*****************************************************************************/
|
||||
void XUartLite_GetStats(XUartLite *InstancePtr, XUartLite_Stats *StatsPtr)
|
||||
{
|
||||
/*
|
||||
* Assert validates the input arguments
|
||||
*/
|
||||
Xil_AssertVoid(InstancePtr != NULL);
|
||||
Xil_AssertVoid(StatsPtr != NULL);
|
||||
Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
|
||||
|
||||
/* Copy the stats from the instance to the specified stats */
|
||||
|
||||
StatsPtr->TransmitInterrupts = InstancePtr->Stats.TransmitInterrupts;
|
||||
StatsPtr->ReceiveInterrupts = InstancePtr->Stats.ReceiveInterrupts;
|
||||
StatsPtr->CharactersTransmitted =
|
||||
InstancePtr->Stats.CharactersTransmitted;
|
||||
StatsPtr->CharactersReceived = InstancePtr->Stats.CharactersReceived;
|
||||
StatsPtr->ReceiveOverrunErrors =
|
||||
InstancePtr->Stats.ReceiveOverrunErrors;
|
||||
StatsPtr->ReceiveFramingErrors =
|
||||
InstancePtr->Stats.ReceiveFramingErrors;
|
||||
StatsPtr->ReceiveParityErrors = InstancePtr->Stats.ReceiveParityErrors;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This function zeros the statistics for the given instance.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XUartLite instance.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
*****************************************************************************/
|
||||
void XUartLite_ClearStats(XUartLite *InstancePtr)
|
||||
{
|
||||
/*
|
||||
* Assert validates the input arguments
|
||||
*/
|
||||
Xil_AssertVoid(InstancePtr != NULL);
|
||||
Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
|
||||
|
||||
InstancePtr->Stats.TransmitInterrupts = 0;
|
||||
InstancePtr->Stats.ReceiveInterrupts = 0;
|
||||
InstancePtr->Stats.CharactersTransmitted = 0;
|
||||
InstancePtr->Stats.CharactersReceived = 0;
|
||||
InstancePtr->Stats.ReceiveOverrunErrors = 0;
|
||||
InstancePtr->Stats.ReceiveFramingErrors = 0;
|
||||
InstancePtr->Stats.ReceiveParityErrors = 0;
|
||||
|
||||
}
|
||||
|
||||
/** @} */
|
Reference in New Issue
Block a user