ChibiOS/HAL 9.0.0
hal_uart_lld.h
Go to the documentation of this file.
1/*
2 ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file hal_uart_lld.h
19 * @brief PLATFORM UART subsystem low level driver header.
20 *
21 * @addtogroup UART
22 * @{
23 */
24
25#ifndef HAL_UART_LLD_H
26#define HAL_UART_LLD_H
27
28#if (HAL_USE_UART == TRUE) || defined(__DOXYGEN__)
29
30/*===========================================================================*/
31/* Driver constants. */
32/*===========================================================================*/
33
34/*===========================================================================*/
35/* Driver pre-compile time settings. */
36/*===========================================================================*/
37
38/**
39 * @name PLATFORM configuration options
40 * @{
41 */
42/**
43 * @brief UART driver enable switch.
44 * @details If set to @p TRUE the support for UART1 is included.
45 * @note The default is @p FALSE.
46 */
47#if !defined(PLATFORM_UART_USE_UART1) || defined(__DOXYGEN__)
48#define PLATFORM_UART_USE_UART1 FALSE
49#endif
50/** @} */
51
52/*===========================================================================*/
53/* Derived constants and error checks. */
54/*===========================================================================*/
55
56/*===========================================================================*/
57/* Driver data structures and types. */
58/*===========================================================================*/
59
60/**
61 * @brief UART driver condition flags type.
62 */
63typedef uint32_t uartflags_t;
64
65/**
66 * @brief Type of structure representing an UART driver.
67 */
69
70/**
71 * @brief Generic UART notification callback type.
72 *
73 * @param[in] uartp pointer to the @p UARTDriver object
74 */
75typedef void (*uartcb_t)(UARTDriver *uartp);
76
77/**
78 * @brief Character received UART notification callback type.
79 *
80 * @param[in] uartp pointer to the @p UARTDriver object triggering the
81 * callback
82 * @param[in] c received character
83 */
84typedef void (*uartccb_t)(UARTDriver *uartp, uint16_t c);
85
86/**
87 * @brief Receive error UART notification callback type.
88 *
89 * @param[in] uartp pointer to the @p UARTDriver object triggering the
90 * callback
91 * @param[in] e receive error mask
92 */
93typedef void (*uartecb_t)(UARTDriver *uartp, uartflags_t e);
94
95/**
96 * @brief Driver configuration structure.
97 * @note Implementations may extend this structure to contain more,
98 * architecture dependent, fields.
99 */
100typedef struct hal_uart_config {
101 /**
102 * @brief End of transmission buffer callback.
103 */
105 /**
106 * @brief Physical end of transmission callback.
107 */
109 /**
110 * @brief Receive buffer filled callback.
111 */
113 /**
114 * @brief Character received while out if the @p UART_RECEIVE state.
115 */
117 /**
118 * @brief Receive error callback.
119 */
121 /* End of the mandatory fields.*/
123
124/**
125 * @brief Structure representing an UART driver.
126 * @note Implementations may extend this structure to contain more,
127 * architecture dependent, fields.
128 */
130 /**
131 * @brief Driver state.
132 */
134 /**
135 * @brief Transmitter state.
136 */
138 /**
139 * @brief Receiver state.
140 */
142 /**
143 * @brief Current configuration data.
144 */
146#if (UART_USE_WAIT == TRUE) || defined(__DOXYGEN__)
147 /**
148 * @brief Synchronization flag for transmit operations.
149 */
150 bool early;
151 /**
152 * @brief Waiting thread on RX.
153 */
155 /**
156 * @brief Waiting thread on TX.
157 */
159#endif /* UART_USE_WAIT */
160#if (UART_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__)
161 /**
162 * @brief Mutex protecting the peripheral.
163 */
165#endif /* UART_USE_MUTUAL_EXCLUSION */
166#if defined(UART_DRIVER_EXT_FIELDS)
167 UART_DRIVER_EXT_FIELDS
168#endif
169 /* End of the mandatory fields.*/
170};
171
172/*===========================================================================*/
173/* Driver macros. */
174/*===========================================================================*/
175
176/*===========================================================================*/
177/* External declarations. */
178/*===========================================================================*/
179
180#if (PLATFORM_UART_USE_UART1 == TRUE) && !defined(__DOXYGEN__)
181extern UARTDriver UARTD1;
182#endif
183
184#ifdef __cplusplus
185extern "C" {
186#endif
187 void uart_lld_init(void);
188 void uart_lld_start(UARTDriver *uartp);
189 void uart_lld_stop(UARTDriver *uartp);
190 void uart_lld_start_send(UARTDriver *uartp, size_t n, const void *txbuf);
191 size_t uart_lld_stop_send(UARTDriver *uartp);
192 void uart_lld_start_receive(UARTDriver *uartp, size_t n, void *rxbuf);
193 size_t uart_lld_stop_receive(UARTDriver *uartp);
194#ifdef __cplusplus
195}
196#endif
197
198#endif /* HAL_USE_UART == TRUE */
199
200#endif /* HAL_UART_LLD_H */
201
202/** @} */
void * thread_reference_t
Type of a thread reference.
Definition osal.h:186
uint32_t mutex_t
Type of a mutex.
Definition osal.h:229
struct hal_uart_config UARTConfig
Driver configuration structure.
void(* uartecb_t)(UARTDriver *uartp, uartflags_t e)
Receive error UART notification callback type.
void uart_lld_start_send(UARTDriver *uartp, size_t n, const void *txbuf)
Starts a transmission on the UART peripheral.
void uart_lld_start(UARTDriver *uartp)
Configures and activates the UART peripheral.
void(* uartcb_t)(UARTDriver *uartp)
Generic UART notification callback type.
uartstate_t
Driver state machine possible states.
Definition hal_uart.h:89
uartrxstate_t
Receiver state machine states.
Definition hal_uart.h:107
uarttxstate_t
Transmitter state machine states.
Definition hal_uart.h:98
void(* uartccb_t)(UARTDriver *uartp, uint16_t c)
Character received UART notification callback type.
UARTDriver UARTD1
UART1 driver identifier.
void uart_lld_init(void)
Low level UART driver initialization.
uint32_t uartflags_t
UART driver condition flags type.
size_t uart_lld_stop_send(UARTDriver *uartp)
Stops any ongoing transmission.
void uart_lld_start_receive(UARTDriver *uartp, size_t n, void *rxbuf)
Starts a receive operation on the UART peripheral.
size_t uart_lld_stop_receive(UARTDriver *uartp)
Stops any ongoing receive operation.
void uart_lld_stop(UARTDriver *uartp)
Deactivates the UART peripheral.
struct hal_uart_driver UARTDriver
Type of structure representing an UART driver.
Driver configuration structure.
uartcb_t rxend_cb
Receive buffer filled callback.
uartecb_t rxerr_cb
Receive error callback.
uartcb_t txend1_cb
End of transmission buffer callback.
uartccb_t rxchar_cb
Character received while out if the UART_RECEIVE state.
uartcb_t txend2_cb
Physical end of transmission callback.
Structure representing an UART driver.
const UARTConfig * config
Current configuration data.
uartstate_t state
Driver state.
thread_reference_t threadrx
Waiting thread on RX.
uartrxstate_t rxstate
Receiver state.
thread_reference_t threadtx
Waiting thread on TX.
bool early
Synchronization flag for transmit operations.
mutex_t mutex
Mutex protecting the peripheral.
uarttxstate_t txstate
Transmitter state.