Class SCI

  • All Implemented Interfaces:
    Impc555, IntbMpc555HB, Ippc32

    public class SCI
    extends Interrupt

    Interrupt controlled driver for the Serial Communication Interface 1 or the Serial Communication Interface 2 of the Freescale MPC555.

    Remember:
    Depending on the baudrate configured, the effective baudrate can be different. This may cause miss interpretation of the bytes sent at the receiver! For more details, please consider table 14-29 in chapter 14.8.7.3 in the MPC555 User's manual.

    • Method Detail

      • getInstance

        public static SCI getInstance​(int sciNr)
        Returns an instance of Serial Communication Interface operating the SCI1 or SCI2.
        Parameters:
        sciNr - 0 selects SCI1, 1 selects SCI2
        Returns:
        Instance of SCI
      • action

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

        public void clearReceiveBuffer()
        Clear the receive buffer.
      • clearTransmitBuffer

        public void clearTransmitBuffer()
        Clear the transmit buffer.
      • clear

        public void clear()
        Clear the receive and transmit buffers.
      • stop

        public void stop()
        Stop the Serial Communication Interface.
      • start

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

        Initialize and start the Serial Communication Interface.

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

        Parameters:
        baudRate - The baud rate. Allowed Range: 64 to 500'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, than is no parity bit more available!
      • portStatus

        public short portStatus()
        Check the port status. Returns the port status bits.
        Every bit is representing a flag (e.g. PORT_OPEN).
        Returns:
        the port status bits.
      • availToRead

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

        public int availToWrite()
        Returns the number of free bytes available in the transmit buffer. It is possible, to send the returned number of bytes in one nonblocking transfer.
        Returns:
        the available free bytes in the transmit buffer.
      • read

        public int read​(byte[] buffer,
                        int off,
                        int count)
                 throws IOException
        Reads the given number of bytes from the SCI. 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.
      • read

        public int read​(byte[] buffer)
                 throws IOException
        Reads the given number of bytes from the SCI. 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()
                 throws IOException
        Reads one byte from the SCI. A call of this method is not blocking!
        Returns:
        byte single entry in queue.
        Throws:
        IOException - if no byte available.
      • 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.
      • 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 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.
      • reset

        public void reset()
        Resets the SCI. This means, the SCI will be stopped and reinitialized with the same configuration.