Software Drivers

xuartps.c File Reference

#include "xstatus.h"
#include "xuartps.h"
#include "xil_io.h"

Defines

#define XUARTPS_MAX_BAUD_ERROR_RATE   3

Functions

unsigned int XUartPs_SendBuffer (XUartPs *InstancePtr)
unsigned int XUartPs_ReceiveBuffer (XUartPs *InstancePtr)
int XUartPs_CfgInitialize (XUartPs *InstancePtr, XUartPs_Config *Config, u32 EffectiveAddr)
unsigned int XUartPs_Send (XUartPs *InstancePtr, u8 *BufferPtr, unsigned int NumBytes)
unsigned int XUartPs_Recv (XUartPs *InstancePtr, u8 *BufferPtr, unsigned int NumBytes)
int XUartPs_SetBaudRate (XUartPs *InstancePtr, u32 BaudRate)

Detailed Description

This file contains the implementation of the interface functions for XUartPs driver. Refer to the header file xuartps.h for more detailed information.

 MODIFICATION HISTORY:
 Ver   Who    Date	 Changes
 ----- ------ -------- ----------------------------------------------
 1.00	drg/jz 01/13/10 First Release
 2.2   hk     06/23/14 SW reset of RX and TX should be done when changing
                       baud rate. CR# 804281.
 

Define Documentation

#define XUARTPS_MAX_BAUD_ERROR_RATE   3

Function Documentation

int XUartPs_CfgInitialize ( XUartPs InstancePtr,
XUartPs_Config Config,
u32  EffectiveAddr 
)

Initializes a specific XUartPs 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. The 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 XUartPs instance.
Config is a reference to a structure containing information about a specific XUartPs driver.
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, pass in the physical address instead.
Returns:
  • XST_SUCCESS if initialization was successful
  • XST_UART_BAUD_ERROR if the baud rate is not possible because the inputclock frequency is not divisible with an acceptable amount of error
Note:

The default configuration for the UART after initialization is:

  • 19,200 bps or XPAR_DFT_BAUDRATE if defined
  • 8 data bits
  • 1 stop bit
  • no parity
  • FIFO's are enabled with a receive threshold of 8 bytes
  • The RX timeout is enabled with a timeout of 1 (4 char times)

All interrupts are disabled.

unsigned int XUartPs_ReceiveBuffer ( XUartPs InstancePtr  ) 
unsigned int XUartPs_Recv ( XUartPs InstancePtr,
u8 *  BufferPtr,
unsigned int  NumBytes 
)

This function attempts to receive a specified number of bytes of data from the device and store it into the specified buffer. This function works for both polled or interrupt driven modes. It is non-blocking.

In a polled mode, this function will only receive the data already in the RX FIFO. The application may need to call it repeatedly to receive the entire buffer. Polled mode is the default mode of operation for the device.

In interrupt mode, this function will start the receiving, if not the entire buffer has been received, the interrupt handler will continue receiving data until the entire buffer has been received. A callback function, as specified by the application, will be called to indicate the completion of the receiving or error conditions.

Parameters:
InstancePtr is a pointer to the XUartPs 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 XUartPs_Send ( XUartPs InstancePtr,
u8 *  BufferPtr,
unsigned int  NumBytes 
)

This functions sends the specified buffer using the device in either polled or interrupt driven mode. This function is non-blocking, if the device is busy sending data, it will return and indicate zero bytes were sent. Otherwise, it fills the TX FIFO as much as it can, and return the number of bytes sent.

In a polled mode, this function will only send as much data as TX FIFO can buffer. The application may need to call it repeatedly to send the entire buffer.

In interrupt mode, this function will start sending the specified buffer, then the interrupt handler will continue sending data until the entire buffer has been sent. A callback function, as specified by the application, will be called to indicate the completion of sending.

Parameters:
InstancePtr is a pointer to the XUartPs 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.

unsigned int XUartPs_SendBuffer ( XUartPs InstancePtr  ) 
int XUartPs_SetBaudRate ( XUartPs InstancePtr,
u32  BaudRate 
)

Sets the baud rate for the device. Checks the input value for validity and also verifies that the requested rate can be configured to within the maximum error range specified by XUARTPS_MAX_BAUD_ERROR_RATE. If the provided rate is not possible, the current setting is unchanged.

Parameters:
InstancePtr is a pointer to the XUartPs instance
BaudRate to be set
Returns:
  • XST_SUCCESS if everything configured as expected
  • XST_UART_BAUD_ERROR if the requested rate is not available because there was too much error
Note:
None.