mikroSDK Reference Manual
hal_uart.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2023 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
48 extern "C"{
49 #endif
50 
51 #include "hal_target.h"
52 #include "ring.h"
53 
61 typedef struct
62 {
63  handle_t *hal_uart_handle;
64  handle_t *drv_uart_handle;
65  bool init_state;
67 
71 typedef enum
72 {
77  HAL_UART_ERROR = (-1)
79 
83 typedef enum
84 {
88 
92 typedef enum
93 {
100 
104 typedef enum
105 {
112 
116 typedef enum
117 {
125 
158 typedef struct
159 {
160  hal_pin_name_t tx_pin;
161  hal_pin_name_t rx_pin;
163  uint32_t baud;
166  hal_uart_stop_bits_t stop_bits;
168  ring_buf8_t tx_buf;
169  ring_buf8_t rx_buf;
171  size_t tx_ring_size;
172  size_t rx_ring_size;
174 
184 typedef struct
185 {
186  handle_t handle;
188  hal_uart_config_t config;
190  uint8_t *tx_ring_buffer;
191  uint8_t *rx_ring_buffer;
193  bool is_tx_irq_enabled;
194  bool is_rx_irq_enabled;
196  bool is_blocking;
197 } hal_uart_t;
198 
250 
299 err_t hal_uart_open( handle_t *handle, bool hal_obj_open_state );
300 
323 err_t hal_uart_set_baud( handle_t *handle, hal_uart_config_t *config );
324 
341 err_t hal_uart_set_parity( handle_t *handle, hal_uart_config_t *config );
342 
359 err_t hal_uart_set_stop_bits( handle_t *handle, hal_uart_config_t *config );
360 
377 err_t hal_uart_set_data_bits( handle_t *handle, hal_uart_config_t *config );
378 
392 void hal_uart_set_blocking( handle_t *handle, bool blocking );
393 
414 size_t hal_uart_write( handle_t *handle, uint8_t *buffer, size_t size );
415 
434 size_t hal_uart_print( handle_t *handle, char *text );
435 
455 size_t hal_uart_println( handle_t *handle, char *text );
456 
477 size_t hal_uart_read( handle_t *handle, uint8_t *buffer, size_t size );
478 
494 size_t hal_uart_bytes_available( hal_uart_t *hal_obj );
495 
508 void hal_uart_clear( hal_uart_t *hal_obj );
509 
526 err_t hal_uart_close( handle_t *handle );
527  // haluartgroup // halgroup // pergroup
531 
532 #ifdef __cplusplus
533 }
534 #endif
535 
536 #endif // _HAL_UART_H_
537 // ------------------------------------------------------------------------- END
hal_uart_read
size_t hal_uart_read(handle_t *handle, uint8_t *buffer, size_t size)
Read data from UART.
HAL_UART_PARITY_NONE
Definition: hal_uart.h:105
hal_uart_print
size_t hal_uart_print(handle_t *handle, char *text)
Print the string to UART.
HAL_UART_DATA_BITS_DEFAULT
Definition: hal_uart.h:97
HAL_UART_ERROR
Definition: hal_uart.h:76
HAL_UART_SUCCESS
Definition: hal_uart.h:72
HAL_UART_IRQ_RX
Definition: hal_uart.h:84
HAL_UART_STOP_BITS_DEFAULT
Definition: hal_uart.h:122
HAL_UART_STOP_BITS_ONE
Definition: hal_uart.h:118
HAL_UART_DATA_BITS_8
Definition: hal_uart.h:94
hal_uart_err_t
hal_uart_err_t
Definition: hal_uart.h:70
hal_uart_t
UART HAL context structure, consisted of the following fields :
Definition: hal_uart.h:183
hal_uart_bytes_available
size_t hal_uart_bytes_available(hal_uart_t *hal_obj)
Check number of data available to read.
HAL_UART_STOP_BITS_HALF
Definition: hal_uart.h:117
hal_uart_open
err_t hal_uart_open(handle_t *handle, bool hal_obj_open_state)
Open the UART HAL layer object on selected pins.
HAL_UART_DATA_BITS_7
Definition: hal_uart.h:93
hal_uart_println
size_t hal_uart_println(handle_t *handle, char *text)
Print the string to UART and append new line.
hal_target.h
HAL target macros and typedefs.
hal_pin_name_t
hal_ll_pin_name_t hal_pin_name_t
Definition: hal_target.h:59
HAL_UART_PARITY_EVEN
Definition: hal_uart.h:106
HAL_UART_STOP_BITS_TWO
Definition: hal_uart.h:120
hal_uart_stop_bits_t
hal_uart_stop_bits_t
Predefined enum values for stop bit selection.
Definition: hal_uart.h:115
HAL_UART_STOP_BITS_ONE_AND_A_HALF
Definition: hal_uart.h:119
hal_uart_clear
void hal_uart_clear(hal_uart_t *hal_obj)
Discard all characters from UART buffers.
hal_uart_irq_t
hal_uart_irq_t
Predefined enum values for interrupt request type.
Definition: hal_uart.h:82
HAL_UART_WRONG_PINS
Definition: hal_uart.h:73
hal_uart_parity_t
hal_uart_parity_t
Predefined enum values for parity selection.
Definition: hal_uart.h:103
hal_uart_set_parity
err_t hal_uart_set_parity(handle_t *handle, hal_uart_config_t *config)
Set the UART parity.
hal_uart_set_blocking
void hal_uart_set_blocking(handle_t *handle, bool blocking)
Set UART HAL in blocking/non-blocking mode.
hal_uart_write
size_t hal_uart_write(handle_t *handle, uint8_t *buffer, size_t size)
Write data to UART.
HAL_UART_IRQ_TX
Definition: hal_uart.h:85
hal_uart_set_stop_bits
err_t hal_uart_set_stop_bits(handle_t *handle, hal_uart_config_t *config)
Set the number of UART stop bits.
hal_uart_data_bits_t
hal_uart_data_bits_t
Predefined enum values for data bit selection.
Definition: hal_uart.h:91
HAL_UART_MODULE_ERROR
Definition: hal_uart.h:74
HAL_UART_DATA_BITS_9
Definition: hal_uart.h:95
HAL_UART_PARITY_ODD
Definition: hal_uart.h:107
HAL_UART_PARITY_DEFAULT
Definition: hal_uart.h:109
hal_uart_close
err_t hal_uart_close(handle_t *handle)
Close UART HAL layer object.
hal_uart_set_baud
err_t hal_uart_set_baud(handle_t *handle, hal_uart_config_t *config)
Set the UART baud rate.
err_t
int32_t err_t
Definition: hal_target.h:63
hal_uart_configure_default
void hal_uart_configure_default(hal_uart_config_t *config)
Configure UART configuration structure with default values.
hal_uart_handle_register_t
Definition: hal_uart.h:60
hal_uart_set_data_bits
err_t hal_uart_set_data_bits(handle_t *handle, hal_uart_config_t *config)
Set the number of UART data bits.
hal_uart_config_t
UART HAL init configuration structure, consisted of the following fields :
Definition: hal_uart.h:157