Class UART

  • All Implemented Interfaces:
    Iarm32, Izynq7000

    public class UART
    extends IrqInterrupt
    implements Izynq7000

    Interrupt controlled driver for the UART0 or the UART1 of the Zynq7000.

    Remember:
    Depending on the baudrate configured, the effective baudrate can be different. This may cause miss interpretation of the bytes sent!

    • Method Detail

      • getInstance

        public static UART getInstance​(int uartNr)
        Returns an instance of UART Interface operating the UART0 or UART1.
        Parameters:
        uartNr - 0 selects UART0, 1 selects UART1
        Returns:
        Instance of UART
      • action

        public void action()
        Description copied from class: IrqInterrupt
        This is the interrupt handler. Please make sure to overwrite this method for your own interrupt handlers.
        Overrides:
        action in class IrqInterrupt
      • start

        public void start​(int baudRate,
                          short parity,
                          short data)

        Initialize and start the Universal Asynchronous Receiver Transmitter.

        This method have to be called before using the UART! The number of stop bits can't be set. There is always one stop bit!

        Parameters:
        baudRate - The baud rate. Allowed Range: 64 to 1'000'000 bits/s.
        parity - Parity bits configuration. Possible values: NO_PARITY, ODD_PARITY or EVEN_PARITY.
        data - Number of data bits. Allowed values are 7 to 9 bits. If you choose 9 data bits, no parity bit is available!
      • write

        public void write​(byte b)
                   throws IOException
        Writes a given byte into the transmit buffer. A call of this method is blocking! If the buffer is full, the method blocks for a short period of time until a small amount of space is available again. After this an IOException is thrown.
        Parameters:
        b - Byte to write.
        Throws:
        IOException - if an error occurs while writing to this stream.
      • write

        public int write​(byte[] buffer)
                  throws IOException
        Writes a given number of bytes into the transmit buffer. A call of this method is not blocking! There will only as many bytes written, which are free in the buffer.
        Parameters:
        buffer - Array of bytes to send.
        Returns:
        the number of bytes written.
        Throws:
        IOException - if an error occurs while writing to this stream.
      • write

        public int write​(byte[] buffer,
                         int off,
                         int count)
                  throws IOException
        Writes a given number of bytes into the transmit buffer. A call of this method is not blocking! There will only as many bytes written, which are free in the buffer.
        Parameters:
        buffer - Array of bytes to send.
        off - Offset to the data which should be sent.
        count - Number of bytes to send.
        Returns:
        the number of bytes written.
        Throws:
        IOException - if an error occurs while writing to this stream.
        NullPointerException - if buffer is null.
        IndexOutOfBoundsException - if off < 0 or count < 0, or if off + count is bigger than the length of buffer.
      • availToRead

        public int availToRead()
        Returns the number of bytes available in the receive buffer.
        Returns:
        number of bytes in the receive buffer.
      • read

        public int read()
                 throws IOException
        Reads one byte from the UART. A call of this method is not blocking!
        Returns:
        byte read.
        Throws:
        IOException - if no byte available.
      • read

        public int read​(byte[] buffer)
                 throws IOException
        Reads the given number of bytes from the UART. A call of this method is not blocking!
        Parameters:
        buffer - Byte array to write the received data.
        Returns:
        the number of bytes read.
        Throws:
        IOException - if no data available.
      • read

        public int read​(byte[] buffer,
                        int off,
                        int count)
                 throws IOException
        Reads the given number of bytes from the UART. A call of this method is not blocking!
        Parameters:
        buffer - Byte aray to write the received data.
        off - Offset in the array to start writing the data.
        count - Length (number of bytes) to read.
        Returns:
        the number of bytes read.
        Throws:
        IOException - if an error occurs while reading from this stream.
        NullPointerException - if buffer is null.
        IndexOutOfBoundsException - if off < 0 or count < 0, or if off + count is bigger than the length of buffer.