Package org.deepjava.flink.subdevices
Class FlinkUART
- java.lang.Object
-
- org.deepjava.flink.subdevices.FlinkUART
-
- All Implemented Interfaces:
FlinkDefinitions
public class FlinkUART extends Object implements FlinkDefinitions
The flink UART subdevice realizes an UART function within a flink device. It offers several channels. Each channel has its own baudrate generator together with transmit and receive queues.- Author:
- Urs Graf
-
-
Field Summary
Fields Modifier and Type Field Description FlinkUARTInputStream
in
Input stream to read from this UART..FlinkUARTOutputStream
out
Output stream to write to this UART.static int
pUART0
static int
pUART1
static int
pUART2
static int
pUART3
static int
pUART4
static int
pUART5
static int
pUART6
static int
pUART7
static int
TX_FULL
-
Fields inherited from interface org.deepjava.flink.core.FlinkDefinitions
ANALOG_INPUT_INTERFACE_ID, ANALOG_OUTPUT_INTERFACE_ID, CHANNEL_OFFSET, COUNTER_INTERFACE_ID, GPIO_INTERFACE_ID, HEADER_SIZE, INFO_DEVICE_ID, INFO_DEVICE_SIZE, INTERFACE_TYPE_MASK, MOD_CONF_OFFSET, MOD_STATUS_OFFSET, PPWA_INTERFACE_ID, PWM_INTERFACE_ID, REGISTER_WIDTH, REGISTER_WIDTH_BIT, SIZE_OFFSET, SUBHEADER_SIZE, TOTAL_HEADER_SIZE, TYPE_OFFSET, UART_INTERFACE_ID, UNIQUE_ID_OFFSET, WD_INTERFACE_ID
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
availToRead()
Returns the number of bytes available in the receive buffer.static FlinkUART
getInstance(FlinkSubDevice dev, int uartNr)
Returns an instance of FlinkUART Interface operating one of the UARTS in the flink UART subdevice.int
read()
Reads one byte from the UART.int
read(byte[] buffer)
Reads the given number of bytes from the UART.int
read(byte[] buffer, int off, int count)
Reads the given number of bytes from the UART.void
reset()
Resets the UART.void
start(int baudRate)
Initialize and start the flink Universal Asynchronous Receiver Transmitter.void
write(byte b)
Writes a given byte into the transmit buffer.int
write(byte[] buffer)
Writes a given number of bytes into the transmit buffer.int
write(byte[] buffer, int off, int count)
Writes a given number of bytes into the transmit buffer.
-
-
-
Field Detail
-
pUART0
public static final int pUART0
- See Also:
- Constant Field Values
-
pUART1
public static final int pUART1
- See Also:
- Constant Field Values
-
pUART2
public static final int pUART2
- See Also:
- Constant Field Values
-
pUART3
public static final int pUART3
- See Also:
- Constant Field Values
-
pUART4
public static final int pUART4
- See Also:
- Constant Field Values
-
pUART5
public static final int pUART5
- See Also:
- Constant Field Values
-
pUART6
public static final int pUART6
- See Also:
- Constant Field Values
-
pUART7
public static final int pUART7
- See Also:
- Constant Field Values
-
TX_FULL
public static final int TX_FULL
- See Also:
- Constant Field Values
-
out
public FlinkUARTOutputStream out
Output stream to write to this UART.
-
in
public FlinkUARTInputStream in
Input stream to read from this UART..
-
-
Method Detail
-
getInstance
public static FlinkUART getInstance(FlinkSubDevice dev, int uartNr)
Returns an instance of FlinkUART Interface operating one of the UARTS in the flink UART subdevice.- Parameters:
dev
- handle to the subdeviceuartNr
- 0 selects UART0, 1 selects UART1, ..- Returns:
- instance of UART
-
start
public void start(int baudRate)
Initialize and start the flink Universal Asynchronous Receiver Transmitter.
This method have to be called before using the flink UART! The number of stop bits, the parity mode and number of data bits can't be set. There is always one stop bit. Parity is off. Number of data bits is 8.
- Parameters:
baudRate
- The baud rate. Allowed Range: 64 to 1'000'000 bits/s.
-
reset
public void reset()
Resets the UART. All the pending transmissions will be stopped, the buffers will be emptied and the UART will be restarted.
-
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
- ifbuffer
is null.IndexOutOfBoundsException
- ifoff < 0
orcount < 0
, or ifoff + count
is bigger than the length ofbuffer
.
-
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
- ifbuffer
is null.IndexOutOfBoundsException
- ifoff < 0
orcount < 0
, or ifoff + count
is bigger than the length ofbuffer
.
-
-