ChibiOS/HAL  7.0.3
hal_sio.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_sio.h
19  * @brief SIO Driver macros and structures.
20  *
21  * @addtogroup SIO
22  * @{
23  */
24 
25 #ifndef HAL_SIO_H
26 #define HAL_SIO_H
27 
28 #if (HAL_USE_SIO == TRUE) || defined(__DOXYGEN__)
29 
30 /*===========================================================================*/
31 /* Driver constants. */
32 /*===========================================================================*/
33 
34 /**
35  * @name SIO status flags
36  * @{
37  */
38 #define SIO_NO_ERROR 0 /**< @brief No pending conditions. */
39 #define SIO_PARITY_ERROR 4 /**< @brief Parity error happened. */
40 #define SIO_FRAMING_ERROR 8 /**< @brief Framing error happened. */
41 #define SIO_OVERRUN_ERROR 16 /**< @brief Overflow happened. */
42 #define SIO_NOISE_ERROR 32 /**< @brief Noise on the line. */
43 #define SIO_BREAK_DETECTED 64 /**< @brief Break detected. */
44 /** @} */
45 
46 /*===========================================================================*/
47 /* Driver pre-compile time settings. */
48 /*===========================================================================*/
49 
50 /**
51  * @name SIO configuration options
52  * @{
53  */
54 
55 /** @} */
56 
57 /*===========================================================================*/
58 /* Derived constants and error checks. */
59 /*===========================================================================*/
60 
61 /*===========================================================================*/
62 /* Driver data structures and types. */
63 /*===========================================================================*/
64 
65 /**
66  * @brief Type of structure representing a SIO driver.
67  */
68 typedef struct hal_sio_driver SIODriver;
69 
70 /**
71  * @brief Type of structure representing a SIO configuration.
72  */
73 typedef struct hal_sio_config SIOConfig;
74 
75 /**
76  * @brief Driver state machine possible states.
77  */
78 typedef enum {
79  SIO_UNINIT = 0, /**< Not initialized. */
80  SIO_STOP = 1, /**< Stopped. */
81  SIO_READY = 2 /**< Ready. */
82 } siostate_t;
83 
84 #include "hal_sio_lld.h"
85 
86 /*===========================================================================*/
87 /* Driver macros. */
88 /*===========================================================================*/
89 
90 /**
91  * @brief Returns the current set of flags and clears it.
92  */
93 #define sioGetFlagsX(siop) sio_lld_get_flags(siop)
94 
95 /**
96  * @brief Determines the state of the RX FIFO.
97  *
98  * @param[in] siop pointer to the @p SIODriver object
99  * @return The RX FIFO state.
100  * @retval false if RX FIFO is not empty
101  * @retval true if RX FIFO is empty
102  *
103  * @xclass
104  */
105 #define sioRXIsEmptyX(siop) sio_lld_rx_is_empty(siop)
106 
107 /**
108  * @brief Determines the state of the TX FIFO.
109  *
110  * @param[in] siop pointer to the @p SIODriver object
111  * @return The TX FIFO state.
112  * @retval false if TX FIFO is not full
113  * @retval true if TX FIFO is full
114  *
115  * @xclass
116  */
117 #define sioTXIsFullX(siop) sio_lld_tx_is_full(siop)
118 
119 /**
120  * @brief Returns one frame from the RX FIFO.
121  * @note If the FIFO is empty then the returned value is unpredictable.
122  *
123  * @param[in] siop pointer to the @p SIODriver object
124  * @return The frame from RX FIFO.
125  *
126  * @xclass
127  */
128 #define sioRXGetX(siop) sio_lld_rx_get(siop)
129 
130 /**
131  * @brief Pushes one frame into the TX FIFO.
132  * @note If the FIFO is full then the behavior is unpredictable.
133  *
134  * @param[in] siop pointer to the @p SIODriver object
135  * @param[in] data frame to be written
136  *
137  * @xclass
138  */
139 #define sioTXPutX(siop, data) sio_lld_tx_put(siop, data)
140 
141 /**
142  * @brief Reads data from the RX FIFO.
143  * @details This function is non-blocking, data is read if present and the
144  * effective amount is returned.
145  * @note This function can be called from any context but it is meant to
146  * be called from the @p rxne_cb callback handler.
147  *
148  * @param[in] siop pointer to the @p SIODriver object
149  * @param[in] buffer buffer for the received data
150  * @param[in] size maximum number of frames to read
151  * @return The number of received frames.
152  *
153  * @xclass
154  */
155 #define sioReadX(siop, buffer, size) sio_lld_read(siop, buffer, size)
156 
157 /**
158  * @brief Writes data into the TX FIFO.
159  * @details This function is non-blocking, data is written if there is space
160  * in the FIFO and the effective amount is returned.
161  * @note This function can be called from any context but it is meant to
162  * be called from the @p txnf_cb callback handler.
163  *
164  * @param[in] siop pointer to the @p SIODriver object
165  * @param[out] buffer buffer containing the data to be transmitted
166  * @param[in] size maximum number of frames to read
167  * @return The number of transmitted frames.
168  *
169  * @xclass
170  */
171 #define sioWriteX(siop, buffer, size) sio_lld_write(siop, buffer, size)
172 
173 /**
174  * @brief Control operation on a serial port.
175  *
176  * @param[in] siop pointer to the @p SIODriver object
177  * @param[in] operation control operation code
178  * @param[in,out] arg operation argument
179  *
180  * @return The control operation status.
181  * @retval MSG_OK in case of success.
182  * @retval MSG_TIMEOUT in case of operation timeout.
183  * @retval MSG_RESET in case of operation reset.
184  *
185  * @xclass
186  */
187 #define sioControlX(siop, operation, arg) sio_lld_control(siop, operation, arg)
188 
189 /*===========================================================================*/
190 /* External declarations. */
191 /*===========================================================================*/
192 
193 #ifdef __cplusplus
194 extern "C" {
195 #endif
196  void sioInit(void);
197  void sioObjectInit(SIODriver *siop);
198  void sioStart(SIODriver *siop, const SIOConfig *config);
199  void sioStop(SIODriver *siop);
200 #ifdef __cplusplus
201 }
202 #endif
203 
204 #endif /* HAL_USE_SIO == TRUE */
205 
206 #endif /* HAL_SIO_H */
207 
208 /** @} */
void sioObjectInit(SIODriver *siop)
Initializes the standard part of a SIODriver structure.
Definition: hal_sio.c:68
Structure representing a SIO driver.
Definition: hal_sio_lld.h:115
PLATFORM SIO subsystem low level driver header.
siostate_t
Driver state machine possible states.
Definition: hal_sio.h:78
void sioInit(void)
SIO Driver initialization.
Definition: hal_sio.c:56
void sioStop(SIODriver *siop)
Deactivates the SIO peripheral.
Definition: hal_sio.c:108
Driver configuration structure.
Definition: hal_sio_lld.h:86
void sioStart(SIODriver *siop, const SIOConfig *config)
Configures and activates the SIO peripheral.
Definition: hal_sio.c:87