#include "xil_types.h"
#include "xil_assert.h"
#include "xstatus.h"
#include "xuartns550_l.h"
#define XUARTNS550_H |
#define XUN_ERROR_BREAK_MASK 0x10 |
These constants specify the errors that may be retrieved from the driver using the XUartNs550_GetLastErrors function. All of them are bit masks, except no error, such that multiple errors may be specified. Break detected
#define XUN_ERROR_FRAMING_MASK 0x08 |
Receive framing error
#define XUN_ERROR_NONE 0x00 |
No error
#define XUN_ERROR_OVERRUN_MASK 0x02 |
Receive overrun error
#define XUN_ERROR_PARITY_MASK 0x04 |
Receive parity error
#define XUN_EVENT_MODEM 5 |
A change in modem status
#define XUN_EVENT_RECV_DATA 1 |
These constants specify the handler events that are passed to a handler from the driver. These constants are not bit masks such that only one will be passed at a time to the handler. Data has been received
#define XUN_EVENT_RECV_ERROR 4 |
A receive error was detected
#define XUN_EVENT_RECV_TIMEOUT 2 |
A receive timeout occurred
#define XUN_EVENT_SENT_DATA 3 |
Data has been sent
#define XUN_FIFO_TRIGGER_01 0x00 |
1 byte trigger level
#define XUN_FIFO_TRIGGER_04 0x40 |
4 byte trigger level
#define XUN_FIFO_TRIGGER_08 0x80 |
8 byte trigger level
#define XUN_FIFO_TRIGGER_14 0xC0 |
14 byte trigger level
#define XUN_FORMAT_1_STOP_BIT 0 |
1 stop bit
#define XUN_FORMAT_2_STOP_BIT 1 |
2 stop bits
#define XUN_FORMAT_5_BITS 0 |
5 data bits
#define XUN_FORMAT_6_BITS 1 |
6 data bits
#define XUN_FORMAT_7_BITS 2 |
7 data bits
#define XUN_FORMAT_8_BITS 3 |
These constants specify the data format that may be set or retrieved with the driver. The data format includes the number of data bits, the number of stop bits and parity. 8 data bits
#define XUN_FORMAT_EVEN_PARITY 2 |
Even Parity
#define XUN_FORMAT_NO_PARITY 0 |
No Parity
#define XUN_FORMAT_ODD_PARITY 1 |
Odd Parity
#define XUN_MODEM_CTS_DELTA_MASK 0x01 |
CTS signal changed state
#define XUN_MODEM_CTS_MASK 0x10 |
Current state of CTS signal
#define XUN_MODEM_DCD_DELTA_MASK 0x08 |
These constants specify the modem status that may be retrieved from the driver. DCD signal changed state
#define XUN_MODEM_DCD_MASK 0x80 |
Current state of DCD signal
#define XUN_MODEM_DSR_DELTA_MASK 0x02 |
DSR signal changed state
#define XUN_MODEM_DSR_MASK 0x20 |
Current state of DSR signal
#define XUN_MODEM_RING_STOP_MASK 0x04 |
Ringing has stopped
#define XUN_MODEM_RINGING_MASK 0x40 |
Ring signal is active
#define XUN_NS16550_MAX_RATE 115200 |
#define XUN_NS16550_MIN_RATE 300 |
#define XUN_OPTION_ASSERT_DTR 0x0001 |
Assert DTR signal
#define XUN_OPTION_ASSERT_OUT1 0x0004 |
Assert out1 signal
#define XUN_OPTION_ASSERT_OUT2 0x0008 |
Assert out2 signal
#define XUN_OPTION_ASSERT_RTS 0x0002 |
Assert RTS signal
#define XUN_OPTION_DATA_INTR 0x0100 |
Enable data interrupts
#define XUN_OPTION_FIFOS_ENABLE 0x0040 |
Enable FIFOs
#define XUN_OPTION_LOOPBACK 0x0200 |
Enable local loopback
#define XUN_OPTION_MODEM_INTR 0x0080 |
Enable modem interrupts
#define XUN_OPTION_RESET_RX_FIFO 0x0010 |
Reset the receive FIFO
#define XUN_OPTION_RESET_TX_FIFO 0x0020 |
Reset the transmit FIFO
#define XUN_OPTION_RXLINE_INTR 0x0800 |
These constants specify the options that may be set or retrieved with the driver, each is a unique bit mask such that multiple options may be specified. These constants indicate the function of the option when in the active state. Enable status interrupt
#define XUN_OPTION_SET_BREAK 0x0400 |
Set a break condition
typedef void(* XUartNs550_Handler)(void *CallBackRef, u32 Event, unsigned int EventData) |
This data type defines a handler which the application must define when using interrupt mode. The handler will be called from the driver in an interrupt context to handle application specific processing.
CallBackRef | is a callback reference passed in by the upper layer when setting the handler, and is passed back to the upper layer when the handler is called. | |
Event | contains one of the event constants indicating why the handler is being called. | |
EventData | contains the number of bytes sent or received at the time of the call for send and receive events and contains the modem status for modem events. |
int XUartNs550_CfgInitialize | ( | XUartNs550 * | InstancePtr, | |
XUartNs550_Config * | Config, | |||
u32 | EffectiveAddr | |||
) |
Initializes a specific XUartNs550 instance such that it is ready to be used. The data format of the device is setup for 8 data bits, 1 stop bit, and no parity by default. The baud rate is set to a default value specified by Config->DefaultBaudRate if set, otherwise it is set to 19.2K baud. If the device has FIFOs (16550), they are enabled and the a receive FIFO threshold is set for 8 bytes. The default operating mode of the driver is polled mode.
InstancePtr | is a pointer to the XUartNs550 instance. | |
Config | is a reference to a structure containing information about a specific UART 16450/16550 device. XUartNs550_Init initializes an InstancePtr object for a specific device specified by the contents f Config. XUartNs550_Init can initialize multiple instance objects with the use of multiple calls giving different Config information on each call. | |
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. |
void XUartNs550_ClearStats | ( | XUartNs550 * | InstancePtr | ) |
This function zeros the statistics for the given instance.
InstancePtr | is a pointer to the XUartNs550 instance. |
void XUartNs550_GetDataFormat | ( | XUartNs550 * | InstancePtr, | |
XUartNs550Format * | FormatPtr | |||
) |
Gets the data format for the specified UART. The data format includes the baud rate, number of data bits, number of stop bits, and parity.
InstancePtr | is a pointer to the XUartNs550 instance. | |
FormatPtr | is a pointer to a format structure that will contain the data format after this call completes. |
u8 XUartNs550_GetFifoThreshold | ( | XUartNs550 * | InstancePtr | ) |
This function gets the receive FIFO trigger level. The receive trigger level indicates the number of bytes in the receive FIFO that cause a receive data event (interrupt) to be generated.
InstancePtr | is a pointer to the XUartNs550 instance. |
u8 XUartNs550_GetLastErrors | ( | XUartNs550 * | InstancePtr | ) |
This function returns the last errors that have occurred in the specified UART. It also clears the errors such that they cannot be retrieved again. The errors include parity error, receive overrun error, framing error, and break detection.
The last errors is an accumulation of the errors each time an error is discovered in the driver. A status is checked for each received byte and this status is accumulated in the last errors.
If this function is called after receiving a buffer of data, it will indicate any errors that occurred for the bytes of the buffer. It does not indicate which bytes contained errors.
InstancePtr | is a pointer to the XUartNs550 instance. |
u8 XUartNs550_GetModemStatus | ( | XUartNs550 * | InstancePtr | ) |
This function gets the modem status from the specified UART. The modem status indicates any changes of the modem signals. This function allows the modem status to be read in a polled mode. The modem status is updated whenever it is read such that reading it twice may not yield the same results.
InstancePtr | is a pointer to the XUartNs550 instance . |
The bit masks used for the modem status are the exact bits of the modem status register with no abstraction.
u16 XUartNs550_GetOptions | ( | XUartNs550 * | InstancePtr | ) |
Gets the options for the specified driver instance. The options are implemented as bit masks such that multiple options may be enabled or disabled simulataneously.
InstancePtr | is a pointer to the XUartNs550 instance. |
void XUartNs550_GetStats | ( | XUartNs550 * | InstancePtr, | |
XUartNs550Stats * | StatsPtr | |||
) |
This functions returns a snapshot of the current statistics in the area provided.
InstancePtr | is a pointer to the XUartNs550 instance. | |
StatsPtr | is a pointer to a XUartNs550Stats structure to where the statistics are to be copied to. |
int XUartNs550_Initialize | ( | XUartNs550 * | InstancePtr, | |
u16 | DeviceId | |||
) |
Initializes a specific XUartNs550 instance such that it is ready to be used. The data format of the device is setup for 8 data bits, 1 stop bit, and no parity by default. The baud rate is set to a default value specified by XPAR_DEFAULT_BAUD_RATE if the symbol is defined, otherwise it is set to 19.2K baud. If the device has FIFOs (16550), they are enabled and the a receive FIFO threshold is set for 8 bytes. The default operating mode of the driver is polled mode.
InstancePtr | is a pointer to the XUartNs550 instance . | |
DeviceId | is the unique id of the device controlled by this XUartNs550 instance. Passing in a device id associates the generic XUartNs550 instance to a specific device, as chosen by the caller or application developer. |
void XUartNs550_InterruptHandler | ( | XUartNs550 * | InstancePtr | ) |
This function is the interrupt handler for the 16450/16550 UART driver. It must be connected to an interrupt system by the user such that it is called when an interrupt for any 16450/16550 UART occurs. This function does not save or restore the processor context such that the user must ensure this occurs.
InstancePtr | contains a pointer to the instance of the UART that the interrupt is for. |
int XUartNs550_IsSending | ( | XUartNs550 * | InstancePtr | ) |
This function determines if the specified UART is sending data. If the transmitter register is not empty, it is sending data.
InstancePtr | is a pointer to the XUartNs550 instance. |
XUartNs550_Config* XUartNs550_LookupConfig | ( | u16 | DeviceId | ) |
Looks up the device configuration based on the unique device ID. A table contains the configuration info for each device in the system.
DeviceId | contains the ID of the device to look up the configuration for. |
unsigned int XUartNs550_Recv | ( | XUartNs550 * | InstancePtr, | |
u8 * | BufferPtr, | |||
unsigned int | NumBytes | |||
) |
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, 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 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. Interrupt mode must be enabled using the SetOptions function.
InstancePtr | is a pointer to the XUartNs550 instance. | |
BufferPtr | is pointer to buffer for data to be received into | |
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. |
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.
int XUartNs550_SelfTest | ( | XUartNs550 * | InstancePtr | ) |
This functions runs a self-test on the driver and hardware device. This self test performs a local loopback and verifies data can be sent and received.
The statistics are cleared at the end of the test. The time for this test to execute is proportional to the baud rate that has been set prior to calling this function.
InstancePtr | is a pointer to the XUartNs550 instance. |
unsigned int XUartNs550_Send | ( | XUartNs550 * | InstancePtr, | |
u8 * | BufferPtr, | |||
unsigned int | NumBytes | |||
) |
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, 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 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.
InstancePtr | is a pointer to the XUartNs550 instance. | |
BufferPtr | is pointer to a buffer of data to be sent. | |
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. |
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.
This function and the XUartNs550_SetOptions() function modify shared data such that there may be a need for mutual exclusion in a multithreaded environment and if XUartNs550_SetOptions() if called from a handler.
int XUartNs550_SetDataFormat | ( | XUartNs550 * | InstancePtr, | |
XUartNs550Format * | FormatPtr | |||
) |
Sets the data format for the specified UART. The data format includes the baud rate, number of data bits, number of stop bits, and parity. It is the caller's responsibility to ensure that the UART is not sending or receiving data when this function is called.
InstancePtr | is a pointer to the XUartNs550 instance . | |
FormatPtr | is a pointer to a format structure containing the data format to be set. |
The data types in the format type, data bits and parity, are 32 bit fields to prevent a compiler warning that is a bug with the GNU PowerPC compiler. The asserts in this function will cause a warning if these fields are bytes.
The baud rates tested include: 1200, 2400, 4800, 9600, 19200, 38400, 57600 and 115200.
int XUartNs550_SetFifoThreshold | ( | XUartNs550 * | InstancePtr, | |
u8 | TriggerLevel | |||
) |
This functions sets the receive FIFO trigger level. The receive trigger level specifies the number of bytes in the receive FIFO that cause a receive data event (interrupt) to be generated. The FIFOs must be enabled to set the trigger level.
InstancePtr | is a pointer to the XUartNs550 instance. | |
TriggerLevel | contains the trigger level to set. Constants which define each trigger level are contained in the file xuartns550.h and named XUN_FIFO_TRIGGER_*. |
void XUartNs550_SetHandler | ( | XUartNs550 * | InstancePtr, | |
XUartNs550_Handler | FuncPtr, | |||
void * | 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.
InstancePtr | is a pointer to the XUartNs550 instance. | |
FuncPtr | is the pointer to the callback function. | |
CallBackRef | is the upper layer callback reference passed back when the callback function is invoked. |
There is no assert on the CallBackRef since the driver doesn't know what it is (nor should it)
int XUartNs550_SetOptions | ( | XUartNs550 * | InstancePtr, | |
u16 | Options | |||
) |
Sets the options for the specified driver instance. The options are implemented as bit masks such that multiple options may be enabled or disabled simultaneously.
The GetOptions function may be called to retrieve the currently enabled options. The result is ORed in the desired new settings to be enabled and ANDed with the inverse to clear the settings to be disabled. The resulting value is then used as the options for the SetOption function call.
InstancePtr | is a pointer to the XUartNs550 instance. | |
Options | contains the options to be set which are bit masks contained in the file xuartns550.h and named XUN_OPTION_*. |
Copyright © 1995-2014 Xilinx, Inc. All rights reserved.