Defines | |
| #define | uart_enable_clock(id) do { } while (0) |
| Enable the peripheral clock to UART id. | |
| #define | uart_disable_clock(id) do { } while (0) |
| Disable the peripheral clock to UART id. | |
Functions | |
| void | uart_init_priv (uart_t uart, uart_flags_t flags) |
| Initializes the UART. | |
| static bool | uart_transmit_is_complete_priv (uart_t uart) |
| Tests if all data has been transmitted. | |
| static bool | uart_tx_buffer_is_empty_priv (uart_t uart) |
| Test if tx buffer is empty. | |
| static bool | uart_rx_buffer_is_full_priv (uart_t uart) |
| Test if rx buffer is full. | |
| static void | uart_send_byte_priv (uart_t uart, uint8_t data) |
| Send data without checking if the pipline is empty. | |
| static bool | uart_put_byte_priv (uart_t uart, uint8_t data) |
| Send data if transmitter pipeline is empty. | |
| static bool | uart_get_byte_priv (uart_t uart, uint8_t *data) |
| Read data if data is available. | |
UART enable/disable flags | |
|
| |
| #define | UART_FLAG_TX (1 << 0) |
| Enable/disable transmitter. | |
| #define | UART_FLAG_RX (1 << 1) |
| Enable/disable receiver. | |
Initialization | |
|
| |
| #define | uart_enable(uart_id, flags) |
| Enable UART transmitter and/or receiver. | |
Transmitting Data | |
|
| |
| #define | uart_put_string(uart_id, data) |
| Send a string to the UART. | |
| #define | uart_put_bytes(uart_id, data, len) |
| Send a given number of bytes to the UART. | |
| #define | uart_transmit_is_complete(uart_id) uart_transmit_is_complete_priv(uart_t uart) |
| Tests if all data has been transmitted. | |
| #define | uart_tx_buffer_is_empty(uart_id) uart_tx_buffer_is_empty_priv(uart_get_regs(uart_id)) |
| Test if tx buffer is empty. | |
| #define | uart_send_byte(uart_id, data) uart_send_byte_priv(uart_get_regs(uart_id), data) |
| Send data without checking if the pipline is empty. | |
| #define | uart_put_byte(uart_id, data) uart_put_byte_priv(uart_get_regs(uart_id), data) |
| Sends data if room is left in the tx pipeline. | |
Receiving Data | |
|
| |
| #define | uart_rx_buffer_is_full(uart_id) uart_rx_buffer_is_full_priv(uart_get_regs(uart_id)) |
| Test if rx buffer is full. | |
| #define | uart_get_byte(uart_id, data) uart_get_byte_priv(uart_get_regs(uart_id), data) |
| Reads data if data is available in the rx buffer. | |
This is a simple and lightweight data transfer interface for UARTs. All transfers are polled, which means that neither the performance nor the power consumption is optimal, but in many cases, it is good enough.
| #define uart_disable_clock | ( | id | ) | do { } while (0) |
| #define uart_enable | ( | uart_id, | |||
| flags | ) |
do { \ uint8_t ctrlb; \ uint8_t _flags = (flags); \ void *regs = uart_get_regs(uart_id); \ ctrlb = usart_read_reg(regs, CTRLB); \ if (_flags & UART_FLAG_TX) \ ctrlb |= USART_BIT(TXEN); \ if (_flags & UART_FLAG_RX) \ ctrlb |= USART_BIT(RXEN); \ usart_write_reg(regs, CTRLB, ctrlb); \ } while (0)
Enable UART transmitter and/or receiver.
Note that this function is not IRQ safe in general (although it happens to be on AVR32.)
| uart_id | ID of the UART to be enabled | |
| flags | Bitwise combination of UART_FLAG_TX and UART_FLAG_RX specifying whether TX, RX or both should be enabled. |
Definition at line 72 of file uart_xmega.h.
| #define uart_enable_clock | ( | id | ) | do { } while (0) |
| #define UART_FLAG_RX (1 << 1) |
Enable/disable receiver.
Definition at line 56 of file uart_xmega.h.
| #define UART_FLAG_TX (1 << 0) |
Enable/disable transmitter.
Definition at line 55 of file uart_xmega.h.
| #define uart_get_byte | ( | uart_id, | |||
| data | ) | uart_get_byte_priv(uart_get_regs(uart_id), data) |
Reads data if data is available in the rx buffer.
This function checks if data is available in the receive queue and copies it to the user supplied data pointer.
| uart_id | UART id. | |
| data | Pointer to memory where to store rx data. |
| true | Data available and stored succesfully. | |
| false | No data available. |
Definition at line 69 of file uart_xmega.h.
| #define uart_put_byte | ( | uart_id, | |||
| data | ) | uart_put_byte_priv(uart_get_regs(uart_id), data) |
Sends data if room is left in the tx pipeline.
This function checks if there is room left to add new data (max is a byte) in transmitter pipeline and copies the new data into it.
| uart_id | UART id. | |
| data | Data to be sent. |
| true | Data was written to send-buffer successfully. | |
| false | Data could not be sent becausee data register is not empty. |
Definition at line 64 of file uart_xmega.h.
| #define uart_put_bytes | ( | uart_id, | |||
| data, | |||||
| len | ) |
do { \ unsigned int i; \ for (i = 0; i < len; i++) { \ while (!uart_put_byte(uart_id, data[i])); \ } \ } while (0)
Send a given number of bytes to the UART.
| uart_id | UART id. | |
| data | bytes to be sent. | |
| len | the number of bytes to be sent. |
| #define uart_put_string | ( | uart_id, | |||
| data | ) |
do { \ unsigned int i; \ for (i = 0; data[i] != 0; i++) { \ while (!uart_put_byte(uart_id, data[i])); \ } \ } while (0)
Send a string to the UART.
| uart_id | UART id. | |
| data | String to be sent. |
| #define uart_rx_buffer_is_full | ( | uart_id | ) | uart_rx_buffer_is_full_priv(uart_get_regs(uart_id)) |
Test if rx buffer is full.
| uart_id | UART id. |
| true | if buffer is full. | |
| false | if buffer is empty. |
Definition at line 67 of file uart_xmega.h.
| #define uart_send_byte | ( | uart_id, | |||
| data | ) | uart_send_byte_priv(uart_get_regs(uart_id), data) |
Send data without checking if the pipline is empty.
| uart_id | UART id. | |
| data | Data to be sent. |
Definition at line 62 of file uart_xmega.h.
| #define uart_transmit_is_complete | ( | uart_id | ) | uart_transmit_is_complete_priv(uart_t uart) |
Tests if all data has been transmitted.
| uart_id | UART id. |
| true | All data has been sent (shift and holding registers empty.) | |
| false | There is still data either in the shift register or in the holding register, or the transmitter is disabled. |
Definition at line 58 of file uart_xmega.h.
| #define uart_tx_buffer_is_empty | ( | uart_id | ) | uart_tx_buffer_is_empty_priv(uart_get_regs(uart_id)) |
Test if tx buffer is empty.
| uart_id | UART id. |
| true | The TX buffer is empty. | |
| false | The TX buffer is full. |
Definition at line 60 of file uart_xmega.h.
| static bool uart_get_byte_priv | ( | uart_t | uart, | |
| uint8_t * | data | |||
| ) | [inline, static] |
Read data if data is available.
For internal use only.
This function checks if data is available in the receive queue and copies it to the user supplied data pointer.
| uart | Pointer to UART module. | |
| data | Pointer to memory where to store rx data. |
| true | Data available and written to b successfully. | |
| false | No data available. |
Definition at line 190 of file uart_xmega.h.
References USART_BIT, and usart_read_reg.
| void uart_init_priv | ( | uart_t | uart, | |
| uart_flags_t | flags | |||
| ) |
Initializes the UART.
For internal use only.
| uart | Pointer to UART module. | |
| flags | UART configuration flags. |
| static bool uart_put_byte_priv | ( | uart_t | uart, | |
| uint8_t | data | |||
| ) | [inline, static] |
Send data if transmitter pipeline is empty.
For internal use only.
This function checks if there is room left to add new data (max is a byte) in transmitter pipeline and copies the new data into it.
| uart | Pointer to UART module. | |
| data | Data to be sent. |
| true | Data was written to send-buffer successfully. | |
| false | Data could not be sent because data register is not empty. |
Definition at line 168 of file uart_xmega.h.
References USART_BIT, usart_read_reg, and usart_write_reg.
| static bool uart_rx_buffer_is_full_priv | ( | uart_t | uart | ) | [inline, static] |
Test if rx buffer is full.
For internal use only.
| uart | Pointer to UART module. |
| true | if buffer is full. | |
| false | if buffer is empty. |
Definition at line 137 of file uart_xmega.h.
References USART_BIT, and usart_read_reg.
| static void uart_send_byte_priv | ( | uart_t | uart, | |
| uint8_t | data | |||
| ) | [inline, static] |
Send data without checking if the pipline is empty.
| uart | Pointer to UART module. | |
| data | Data to be sent. |
Definition at line 151 of file uart_xmega.h.
References usart_write_reg.
| static bool uart_transmit_is_complete_priv | ( | uart_t | uart | ) | [inline, static] |
Tests if all data has been transmitted.
For internal use only.
| uart | Pointer to UART module. |
| true | All data has been sent (shift register and THR is empty). | |
| false | There is still data either in the shift register or in the THR register, or the transmitter is disabled. |
Definition at line 105 of file uart_xmega.h.
References USART_BIT, and usart_read_reg.
| static bool uart_tx_buffer_is_empty_priv | ( | uart_t | uart | ) | [inline, static] |
Test if tx buffer is empty.
For internal use only.
| uart | Pointer to UART module. |
| true | if buffer is empty. | |
| false | if buffer is full. |
Definition at line 121 of file uart_xmega.h.
References USART_BIT, and usart_read_reg.
1.6.3