Functions to use the Universal Asynchronous Receiver-Transmitter (UART).
Two UART channels can be instantiated, UART0 and UART1. Before sending and receiving bytes the UART must be connect to some I/O pins through the switchbox, e.g.
@ IO_AR0
Analog reference pins (Arduino header).
void switchbox_set_pin(const io_t pin_number, const io_configuration_t io_type)
Set the type of a switch pin.
After that, an example of how to use this library for the MASTER.
int main (void)
{
uint8_t byte[] = "Hello\n";
int i = 0;
while (byte[i] != '\0') {
printf("sent byte %d\n", byte[i]);
i++;
}
return EXIT_SUCCESS;
}
void uart_reset_fifos(const int uart)
This function resets both the transmit and receive FIFOs of the UART specified by the uart parameter....
void uart_send(const int uart, const uint8_t data)
Send a byte of data on the specified UART index by waiting for the transmit FIFO to have space and th...
void uart_init(const int uart)
Initialize the UART specified by the index with a shared memory handle and a buffer size of 4096 byte...
void pynq_init(void)
Initialise the switchbox and GPIO of the PYNQ.
void pynq_destroy(void)
Reset and destroy the switchbox and GPIO of the PYNQ.
An example of how to use this library for the SLAVE.
int main (void)
{
printf("listening\n");
do {
printf("received byte %d\n", msg);
} while (1);
return EXIT_SUCCESS;
}
uint8_t uart_recv(const int uart)
Receive a byte of data from the specified UART index by waiting for the receive FIFO to have data and...
UARTs can be routed through the switch box (see switchbox.h). Note that switchbox numbering (SWB_UART0..SWB_UART1) is then used instead of 0..NUM_UARTS-1 (UART0..UART1).
◆ uart_index_t
Enum of UARTs. Functions use a switch numbered from 0..NUM_UARTS-1. Alternatively, you can use UARTi instead of just i if you find that clearer.
Enumerator |
---|
UART0 | |
UART1 | |
NUM_UARTS | |
Definition at line 107 of file uart.h.
◆ uart_destroy()
void uart_destroy |
( |
const int |
uart | ) |
|
|
extern |
Close the shared memory handle for the specified UART index.
- Parameters
-
uart | The UART index to remove from the shared memory space. |
- Warning
- Fails with program exit if the UART channel is outside valid range.
Definition at line 61 of file uart.c.
◆ uart_has_data()
bool uart_has_data |
( |
const int |
uart | ) |
|
|
extern |
Check if the receive FIFO for the specified UART index has data available.
- Parameters
-
uart | The UART index used to check for data. |
- Returns
- True if the receive FIFO has data, false otherwise.
- Warning
- Fails with program exit if the UART channel is outside valid range.
Definition at line 98 of file uart.c.
◆ uart_has_space()
bool uart_has_space |
( |
const int |
uart | ) |
|
|
extern |
Check if the transmit FIFO for the specified UART index has space available.
- Parameters
-
uart | The UART index to check for space. |
- Returns
- True if the FIFO has space, false otherwise.
- Warning
- Fails with program exit if the UART channel is outside valid range.
Definition at line 110 of file uart.c.
◆ uart_init()
void uart_init |
( |
const int |
uart | ) |
|
|
extern |
Initialize the UART specified by the index with a shared memory handle and a buffer size of 4096 bytes.
- Parameters
-
uart | The UART index to initialize. |
- Warning
- Fails with program exit if the UART channel is outside valid range or when the shared memory system has not been instantiated.
Definition at line 48 of file uart.c.
◆ uart_recv()
uint8_t uart_recv |
( |
const int |
uart | ) |
|
|
extern |
Receive a byte of data from the specified UART index by waiting for the receive FIFO to have data and then reading the data from the receive buffer.
- Parameters
-
uart | The UART index to receive data from. |
- Returns
- The received data byte.
- Warning
- Fails with program exit if the UART channel is outside valid range.
Definition at line 85 of file uart.c.
◆ uart_reset_fifos()
void uart_reset_fifos |
( |
const int |
uart | ) |
|
|
extern |
This function resets both the transmit and receive FIFOs of the UART specified by the uart
parameter. This can be useful when there is data stuck in the FIFOs or when the FIFOs are not behaving as expected.
- Parameters
-
uart | The UART index of the UART whose FIFOs should be reset. |
- Warning
- This function is specific to UARTs that have FIFOs, and will have no effect on UARTs that do not have FIFOs.
-
Resetting the FIFOs will result in the loss of any data that is currently in the FIFOs. Therefore, this function should be used with caution, and only when it is absolutely necessary to do so.
-
Fails with program exit if the UART channel is outside valid range.
Definition at line 121 of file uart.c.
◆ uart_send()
void uart_send |
( |
const int |
uart, |
|
|
const uint8_t |
data |
|
) |
| |
|
extern |
Send a byte of data on the specified UART index by waiting for the transmit FIFO to have space and then writing the data to the transmit buffer.
- Parameters
-
uart | The UART index to send data to. |
data | The data to send to the UART index. |
- Warning
- Fails with program exit if the UART channel is outside valid range.
Definition at line 72 of file uart.c.