ChibiOS/HAL  6.1.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  */
63 typedef uint32_t uartflags_t;
64 
65 /**
66  * @brief Type of structure representing an UART driver.
67  */
68 typedef struct UARTDriver UARTDriver;
69 
70 /**
71  * @brief Generic UART notification callback type.
72  *
73  * @param[in] uartp pointer to the @p UARTDriver object
74  */
75 typedef 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  */
84 typedef 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  */
93 typedef 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  */
100 typedef struct {
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.*/
122 } UARTConfig;
123 
124 /**
125  * @brief Structure representing an UART driver.
126  * @note Implementations may extend this structure to contain more,
127  * architecture dependent, fields.
128  */
129 struct UARTDriver {
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__)
181 extern UARTDriver UARTD1;
182 #endif
183 
184 #ifdef __cplusplus
185 extern "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 /** @} */
const UARTConfig * config
Current configuration data.
Definition: hal_uart_lld.h:145
void(* uartecb_t)(UARTDriver *uartp, uartflags_t e)
Receive error UART notification callback type.
Definition: hal_uart_lld.h:93
void uart_lld_start(UARTDriver *uartp)
Configures and activates the UART peripheral.
Definition: hal_uart_lld.c:80
bool early
Synchronization flag for transmit operations.
Definition: hal_uart_lld.h:150
uartcb_t txend1_cb
End of transmission buffer callback.
Definition: hal_uart_lld.h:104
size_t uart_lld_stop_receive(UARTDriver *uartp)
Stops any ongoing receive operation.
Definition: hal_uart_lld.c:182
thread_reference_t threadrx
Waiting thread on RX.
Definition: hal_uart_lld.h:154
uartstate_t
Driver state machine possible states.
Definition: hal_uart.h:89
size_t uart_lld_stop_send(UARTDriver *uartp)
Stops any ongoing transmission.
Definition: hal_uart_lld.c:145
void(* uartcb_t)(UARTDriver *uartp)
Generic UART notification callback type.
Definition: hal_uart_lld.h:75
uarttxstate_t txstate
Transmitter state.
Definition: hal_uart_lld.h:137
void uart_lld_stop(UARTDriver *uartp)
Deactivates the UART peripheral.
Definition: hal_uart_lld.c:101
uartcb_t txend2_cb
Physical end of transmission callback.
Definition: hal_uart_lld.h:108
void uart_lld_start_receive(UARTDriver *uartp, size_t n, void *rxbuf)
Starts a receive operation on the UART peripheral.
Definition: hal_uart_lld.c:163
uarttxstate_t
Transmitter state machine states.
Definition: hal_uart.h:98
uartecb_t rxerr_cb
Receive error callback.
Definition: hal_uart_lld.h:120
void(* uartccb_t)(UARTDriver *uartp, uint16_t c)
Character received UART notification callback type.
Definition: hal_uart_lld.h:84
void uart_lld_start_send(UARTDriver *uartp, size_t n, const void *txbuf)
Starts a transmission on the UART peripheral.
Definition: hal_uart_lld.c:126
void uart_lld_init(void)
Low level UART driver initialization.
Definition: hal_uart_lld.c:65
uint32_t uartflags_t
UART driver condition flags type.
Definition: hal_uart_lld.h:63
uartrxstate_t
Receiver state machine states.
Definition: hal_uart.h:107
uartrxstate_t rxstate
Receiver state.
Definition: hal_uart_lld.h:141
uartcb_t rxend_cb
Receive buffer filled callback.
Definition: hal_uart_lld.h:112
void * thread_reference_t
Type of a thread reference.
Definition: osal.h:180
uartstate_t state
Driver state.
Definition: hal_uart_lld.h:133
UARTDriver UARTD1
UART1 driver identifier.
Definition: hal_uart_lld.c:41
Driver configuration structure.
Definition: hal_uart_lld.h:100
uartccb_t rxchar_cb
Character received while out if the UART_RECEIVE state.
Definition: hal_uart_lld.h:116
thread_reference_t threadtx
Waiting thread on TX.
Definition: hal_uart_lld.h:158
uint32_t mutex_t
Type of a mutex.
Definition: osal.h:223
Structure representing an UART driver.
Definition: hal_uart_lld.h:129
mutex_t mutex
Mutex protecting the peripheral.
Definition: hal_uart_lld.h:164