Software Drivers

xuartns550.c File Reference

#include "xstatus.h"
#include "xuartns550.h"
#include "xuartns550_i.h"
#include "xil_io.h"

Defines

#define XUN_MAX_BAUD_ERROR_RATE   3

Functions

int XUartNs550_CfgInitialize (XUartNs550 *InstancePtr, XUartNs550_Config *Config, u32 EffectiveAddr)
unsigned int XUartNs550_Send (XUartNs550 *InstancePtr, u8 *BufferPtr, unsigned int NumBytes)
unsigned int XUartNs550_Recv (XUartNs550 *InstancePtr, u8 *BufferPtr, unsigned int NumBytes)
unsigned int XUartNs550_SendBuffer (XUartNs550 *InstancePtr)
unsigned int XUartNs550_ReceiveBuffer (XUartNs550 *InstancePtr)
int XUartNs550_SetBaudRate (XUartNs550 *InstancePtr, u32 BaudRate)

Detailed Description

This file contains the required functions for the 16450/16550 UART driver. Refer to the header file xuartns550.h for more detailed information.

 MODIFICATION HISTORY:
 Ver   Who  Date     Changes
 ----- ---- -------- -----------------------------------------------
 1.00a ecm  08/16/01 First release
 1.00b jhl  03/11/02 Repartitioned driver for smaller files.
 1.00b rmm  05/14/03 Fixed diab compiler warnings relating to asserts.
 1.01a jvb  12/13/05 I changed Initialize() into CfgInitialize(), and made
                     CfgInitialize() take a pointer to a config structure
                     instead of a device id. I moved Initialize() into
                     xgpio_sinit.c, and had Initialize() call CfgInitialize()
                     after it retrieved the config structure using the device
                     id. I removed include of xparameters.h along with any
                     dependencies on xparameters.h and the _g.c config table.
 1.11a sv   03/20/07 Updated to use the new coding guidelines.
 2.00a ktn  10/20/09 Converted all register accesses to 32 bit access.
		      Updated to use HAL Processor APIs. _m is removed from the
		      name of all the macro definitions. XUartNs550_mClearStats
		      macro is removed, XUartNs550_ClearStats function should be
		      used in its place.
 2.01a bss  01/13/12 Removed unneccessary read of the LCR register in the
                     XUartNs550_CfgInitialize function. Removed compiler
		      warnings for unused variables in the
		      XUartNs550_StubHandler.
 

Define Documentation

#define XUN_MAX_BAUD_ERROR_RATE   3

Function Documentation

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.

Parameters:
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.
Returns:
  • XST_SUCCESS if initialization was successful.
  • XST_UART_BAUD_ERROR if the baud rate is not possible because the input clock frequency is not divisible with an acceptable amount of error.
Note:
None.
unsigned int XUartNs550_ReceiveBuffer ( XUartNs550 InstancePtr  ) 

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 XUartNs550 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. Interrupt mode must be enabled using the SetOptions function.

Parameters:
InstancePtr is a pointer to the XUartNs550 instance.
Returns:
The number of bytes received.
Note:
None.
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.

Parameters:
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.
Returns:
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 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.

Parameters:
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.
Returns:
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.

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.

unsigned int XUartNs550_SendBuffer ( XUartNs550 InstancePtr  ) 

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 XUartNs550 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.

Parameters:
InstancePtr is a pointer to the XUartNs550 instance.
Returns:
NumBytes is the number of bytes actually sent (put into the UART tranmitter and/or FIFO).
Note:
None.
int XUartNs550_SetBaudRate ( XUartNs550 InstancePtr,
u32  BaudRate 
)