mikroSDK Reference Manual
hal_uart.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** Copyright (C) 2024 MikroElektronika d.o.o.
4** Contact: https://www.mikroe.com/contact
5**
6** This file is part of the mikroSDK package
7**
8** Commercial License Usage
9**
10** Licensees holding valid commercial NECTO compilers AI licenses may use this
11** file in accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The MikroElektronika Company.
14** For licensing terms and conditions see
15** https://www.mikroe.com/legal/software-license-agreement.
16** For further information use the contact form at
17** https://www.mikroe.com/contact.
18**
19**
20** GNU Lesser General Public License Usage
21**
22** Alternatively, this file may be used for
23** non-commercial projects under the terms of the GNU Lesser
24** General Public License version 3 as published by the Free Software
25** Foundation: https://www.gnu.org/licenses/lgpl-3.0.html.
26**
27** The above copyright notice and this permission notice shall be
28** included in all copies or substantial portions of the Software.
29**
30** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31** OF MERCHANTABILITY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
32** TO THE WARRANTIES FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
34** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
35** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
36** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37**
38****************************************************************************/
44#ifndef _HAL_UART_H_
45#define _HAL_UART_H_
46
47#ifdef __cplusplus
48extern "C"{
49#endif
50
51#include "hal_target.h"
52#include "ring.h"
53
61typedef struct
62{
63 handle_t *hal_uart_handle;
64 handle_t *drv_uart_handle;
67
79
88
100
112
125
174
199
251
300err_t hal_uart_open( handle_t *handle, bool hal_obj_open_state );
301
325err_t hal_uart_set_baud( handle_t *handle, hal_uart_config_t *config );
326
344err_t hal_uart_set_parity( handle_t *handle, hal_uart_config_t *config );
345
363err_t hal_uart_set_stop_bits( handle_t *handle, hal_uart_config_t *config );
364
382err_t hal_uart_set_data_bits( handle_t *handle, hal_uart_config_t *config );
383
398void hal_uart_set_blocking( handle_t *handle, bool blocking );
399
420size_t hal_uart_write( handle_t *handle, uint8_t *buffer, size_t size );
421
441size_t hal_uart_print( handle_t *handle, char *text );
442
462size_t hal_uart_println( handle_t *handle, char *text );
463
484size_t hal_uart_read( handle_t *handle, uint8_t *buffer, size_t size );
485
502
516void hal_uart_clear( hal_uart_t *hal_obj );
517
534err_t hal_uart_close( handle_t *handle );
535
536 // haluartgroup
537 // halgroup
538 // pergroup
539
540#ifdef __cplusplus
541}
542#endif
543
544#endif // _HAL_UART_H_
545// ------------------------------------------------------------------------- END
err_t hal_uart_close(handle_t *handle)
Close UART HAL layer object.
err_t hal_uart_set_data_bits(handle_t *handle, hal_uart_config_t *config)
Set the number of UART data bits.
size_t hal_uart_println(handle_t *handle, char *text)
Print the string to UART and append new line.
err_t hal_uart_set_stop_bits(handle_t *handle, hal_uart_config_t *config)
Set the number of UART stop bits.
size_t hal_uart_bytes_available(hal_uart_t *hal_obj)
Check number of data available to read.
void hal_uart_clear(hal_uart_t *hal_obj)
Discard all characters from UART buffers.
size_t hal_uart_write(handle_t *handle, uint8_t *buffer, size_t size)
Write data to UART.
err_t hal_uart_open(handle_t *handle, bool hal_obj_open_state)
Open the UART HAL layer object on selected pins.
err_t hal_uart_set_baud(handle_t *handle, hal_uart_config_t *config)
Set the UART baud rate.
err_t hal_uart_set_parity(handle_t *handle, hal_uart_config_t *config)
Set the UART parity.
void hal_uart_set_blocking(handle_t *handle, bool blocking)
Set UART HAL in blocking/non-blocking mode.
void hal_uart_configure_default(hal_uart_config_t *config)
Configure UART configuration structure with default values.
size_t hal_uart_read(handle_t *handle, uint8_t *buffer, size_t size)
Read data from UART.
size_t hal_uart_print(handle_t *handle, char *text)
Print the string to UART.
HAL target macros and typedefs.
int32_t err_t
Definition hal_target.h:64
hal_ll_pin_name_t hal_pin_name_t
Definition hal_target.h:60
hal_uart_data_bits_t
Predefined enum values for data bit selection.
Definition hal_uart.h:93
@ HAL_UART_DATA_BITS_8
Definition hal_uart.h:95
@ HAL_UART_DATA_BITS_9
Definition hal_uart.h:96
@ HAL_UART_DATA_BITS_DEFAULT
Definition hal_uart.h:98
@ HAL_UART_DATA_BITS_7
Definition hal_uart.h:94
hal_uart_parity_t
Predefined enum values for parity selection.
Definition hal_uart.h:105
@ HAL_UART_PARITY_NONE
Definition hal_uart.h:106
@ HAL_UART_PARITY_ODD
Definition hal_uart.h:108
@ HAL_UART_PARITY_DEFAULT
Definition hal_uart.h:110
@ HAL_UART_PARITY_EVEN
Definition hal_uart.h:107
hal_uart_err_t
Definition hal_uart.h:72
@ HAL_UART_ERROR
Definition hal_uart.h:77
@ HAL_UART_SUCCESS
Definition hal_uart.h:73
@ HAL_UART_MODULE_ERROR
Definition hal_uart.h:75
@ HAL_UART_WRONG_PINS
Definition hal_uart.h:74
hal_uart_irq_t
Predefined enum values for interrupt request type.
Definition hal_uart.h:84
@ HAL_UART_IRQ_TX
Definition hal_uart.h:86
@ HAL_UART_IRQ_RX
Definition hal_uart.h:85
hal_uart_stop_bits_t
Predefined enum values for stop bit selection.
Definition hal_uart.h:117
@ HAL_UART_STOP_BITS_TWO
Definition hal_uart.h:121
@ HAL_UART_STOP_BITS_HALF
Definition hal_uart.h:118
@ HAL_UART_STOP_BITS_ONE
Definition hal_uart.h:119
@ HAL_UART_STOP_BITS_ONE_AND_A_HALF
Definition hal_uart.h:120
@ HAL_UART_STOP_BITS_DEFAULT
Definition hal_uart.h:123
UART HAL init configuration structure, consisted of the following fields :
Definition hal_uart.h:159
uint32_t baud
Definition hal_uart.h:163
ring_buf8_t tx_buf
Definition hal_uart.h:168
ring_buf8_t rx_buf
Definition hal_uart.h:169
size_t rx_ring_size
Definition hal_uart.h:172
hal_uart_data_bits_t data_bits
Definition hal_uart.h:164
hal_uart_stop_bits_t stop_bits
Definition hal_uart.h:166
size_t tx_ring_size
Definition hal_uart.h:171
hal_pin_name_t rx_pin
Definition hal_uart.h:161
hal_uart_parity_t parity
Definition hal_uart.h:165
hal_pin_name_t tx_pin
Definition hal_uart.h:160
Definition hal_uart.h:62
handle_t * drv_uart_handle
Definition hal_uart.h:64
bool init_state
Definition hal_uart.h:65
handle_t * hal_uart_handle
Definition hal_uart.h:63
UART HAL context structure, consisted of the following fields :
Definition hal_uart.h:186
uint8_t * rx_ring_buffer
Definition hal_uart.h:192
bool is_blocking
Definition hal_uart.h:197
uint8_t * tx_ring_buffer
Definition hal_uart.h:191
handle_t handle
Definition hal_uart.h:187
bool is_tx_irq_enabled
Definition hal_uart.h:194
hal_uart_config_t config
Definition hal_uart.h:189
bool is_rx_irq_enabled
Definition hal_uart.h:195