ChibiOS/HAL 9.0.0
hal_sio_lld.c
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_lld.c
19 * @brief PLATFORM SIO subsystem low level driver source.
20 *
21 * @addtogroup SIO
22 * @{
23 */
24
25#include "hal.h"
26
27#if (HAL_USE_SIO == TRUE) || defined(__DOXYGEN__)
28
29/*===========================================================================*/
30/* Driver local definitions. */
31/*===========================================================================*/
32
33/*===========================================================================*/
34/* Driver exported variables. */
35/*===========================================================================*/
36
37/**
38 * @brief SIO1 driver identifier.
39 */
40#if (PLATFORM_SIO_USE_SIO1 == TRUE) || defined(__DOXYGEN__)
42#endif
43
44/*===========================================================================*/
45/* Driver local variables and types. */
46/*===========================================================================*/
47
48/*===========================================================================*/
49/* Driver local functions. */
50/*===========================================================================*/
51
52/*===========================================================================*/
53/* Driver interrupt handlers. */
54/*===========================================================================*/
55
56/*===========================================================================*/
57/* Driver exported functions. */
58/*===========================================================================*/
59
60/**
61 * @brief Low level SIO driver initialization.
62 *
63 * @notapi
64 */
65void sio_lld_init(void) {
66
67#if PLATFORM_SIO_USE_SIO1 == TRUE
68 /* Driver initialization.*/
70#endif
71}
72
73/**
74 * @brief Configures and activates the SIO peripheral.
75 *
76 * @param[in] siop pointer to the @p SIODriver object
77 * @return The operation status.
78 *
79 * @notapi
80 */
82
83 if (siop->state == SIO_STOP) {
84 /* Enables the peripheral.*/
85
86 /* Enables the peripheral.*/
87 if (false) {
88 }
89
90#if PLATFORM_SIO_USE_SIO1 == TRUE
91 else if (&SIOD1 == siop) {
92
93 }
94#endif
95
96 else {
97 osalDbgAssert(false, "invalid SIO instance");
98 return HAL_RET_IS_INVALID;
99 }
100 }
101
102 /* Configures the peripheral.*/
103
104 return HAL_RET_SUCCESS;
105}
106
107/**
108 * @brief Deactivates the SIO peripheral.
109 *
110 * @param[in] siop pointer to the @p SIODriver object
111 *
112 * @notapi
113 */
115
116 if (siop->state == SIO_READY) {
117 /* Resets the peripheral.*/
118
119 /* Disables the peripheral.*/
120#if PLATFORM_SIO_USE_SIO1 == TRUE
121 if (&SIOD1 == siop) {
122
123 }
124#endif
125 }
126}
127
128/**
129 * @brief Enable flags change notification.
130 *
131 * @param[in] siop pointer to the @p SIODriver object
132 */
134
135 (void)siop;
136 }
137
138/**
139 * @brief Get and clears SIO error event flags.
140 *
141 * @param[in] siop pointer to the @p SIODriver object
142 * @return The pending event flags.
143 *
144 * @notapi
145 */
147 sioevents_t errors = 0U;
148
149 (void)siop;
150
151 return errors;
152}
153
154/**
155 * @brief Get and clears SIO event flags.
156 *
157 * @param[in] siop pointer to the @p SIODriver object
158 * @return The pending event flags.
159 *
160 * @notapi
161 */
163 sioevents_t events = 0U;
164
165 (void)siop;
166
167 return events;
168}
169
170/**
171 * @brief Returns the pending SIO event flags.
172 *
173 * @param[in] siop pointer to the @p SIODriver object
174 * @return The pending event flags.
175 *
176 * @notapi
177 */
179 sioevents_t events = 0U;
180
181 (void)siop;
182
183 return events;
184}
185
186/**
187 * @brief Reads data from the RX FIFO.
188 * @details The function is not blocking, it writes frames until there
189 * is space available without waiting.
190 *
191 * @param[in] siop pointer to an @p SIODriver structure
192 * @param[in] buffer pointer to the buffer for read frames
193 * @param[in] n maximum number of frames to be read
194 * @return The number of frames copied from the buffer.
195 * @retval 0 if the TX FIFO is full.
196 */
197size_t sio_lld_read(SIODriver *siop, uint8_t *buffer, size_t n) {
198
199 (void)siop;
200 (void)buffer;
201
202 return n;
203}
204
205/**
206 * @brief Writes data into the TX FIFO.
207 * @details The function is not blocking, it writes frames until there
208 * is space available without waiting.
209 *
210 * @param[in] siop pointer to an @p SIODriver structure
211 * @param[in] buffer pointer to the buffer for read frames
212 * @param[in] n maximum number of frames to be written
213 * @return The number of frames copied from the buffer.
214 * @retval 0 if the TX FIFO is full.
215 */
216size_t sio_lld_write(SIODriver *siop, const uint8_t *buffer, size_t n) {
217
218 (void)siop;
219 (void)buffer;
220
221 return n;
222}
223
224/**
225 * @brief Returns one frame from the RX FIFO.
226 * @note If the FIFO is empty then the returned value is unpredictable.
227 *
228 * @param[in] siop pointer to the @p SIODriver object
229 * @return The frame from RX FIFO.
230 *
231 * @notapi
232 */
234 msg_t msg = (msg_t)0;
235
236 (void)siop;
237
238 return msg;
239}
240
241/**
242 * @brief Pushes one frame into the TX FIFO.
243 * @note If the FIFO is full then the behavior is unpredictable.
244 *
245 * @param[in] siop pointer to the @p SIODriver object
246 * @param[in] data frame to be written
247 *
248 * @notapi
249 */
250void sio_lld_put(SIODriver *siop, uint_fast16_t data) {
251
252 (void)siop;
253 (void)data;
254}
255
256/**
257 * @brief Control operation on a serial port.
258 *
259 * @param[in] siop pointer to the @p SIODriver object
260 * @param[in] operation control operation code
261 * @param[in,out] arg operation argument
262 *
263 * @return The control operation status.
264 * @retval MSG_OK in case of success.
265 * @retval MSG_TIMEOUT in case of operation timeout.
266 * @retval MSG_RESET in case of operation reset.
267 *
268 * @notapi
269 */
270msg_t sio_lld_control(SIODriver *siop, unsigned int operation, void *arg) {
271
272 (void)siop;
273 (void)operation;
274 (void)arg;
275
276 return MSG_OK;
277}
278
279/**
280 * @brief Serves an UART interrupt.
281 *
282 * @param[in] siop pointer to the @p SIODriver object
283 *
284 * @notapi
285 */
287
288 (void)siop;
289}
290
291#endif /* HAL_USE_SIO == TRUE */
292
293/** @} */
#define HAL_RET_IS_INVALID
Invalid instance pointer.
Definition hal.h:123
#define HAL_RET_SUCCESS
Definition hal.h:93
int32_t msg_t
Type of a message.
Definition osal.h:159
#define MSG_OK
Definition osal.h:56
#define osalDbgAssert(c, remark)
Condition assertion.
Definition osal.h:264
msg_t sio_lld_control(SIODriver *siop, unsigned int operation, void *arg)
Control operation on a serial port.
struct hal_sio_driver SIODriver
Type of structure representing a SIO driver.
Definition hal_sio.h:138
sioevents_t sio_lld_get_events(SIODriver *siop)
Returns the pending SIO event flags.
msg_t sio_lld_get(SIODriver *siop)
Returns one frame from the RX FIFO.
void sio_lld_put(SIODriver *siop, uint_fast16_t data)
Pushes one frame into the TX FIFO.
void sioObjectInit(SIODriver *siop)
Initializes the standard part of a SIODriver structure.
Definition hal_sio.c:216
SIODriver SIOD1
SIO1 driver identifier.
Definition hal_sio_lld.c:41
void sio_lld_stop(SIODriver *siop)
Deactivates the SIO peripheral.
sioevents_t sio_lld_get_and_clear_errors(SIODriver *siop)
Get and clears SIO error event flags.
void sio_lld_serve_interrupt(SIODriver *siop)
Serves an UART interrupt.
void sio_lld_init(void)
Low level SIO driver initialization.
Definition hal_sio_lld.c:65
eventflags_t sioevents_t
Type of event flags.
Definition hal_sio.h:133
sioevents_t sio_lld_get_and_clear_events(SIODriver *siop)
Get and clears SIO event flags.
void sio_lld_update_enable_flags(SIODriver *siop)
Enable flags change notification.
msg_t sio_lld_start(SIODriver *siop)
Configures and activates the SIO peripheral.
Definition hal_sio_lld.c:81
size_t sio_lld_read(SIODriver *siop, uint8_t *buffer, size_t n)
Reads data from the RX FIFO.
size_t sio_lld_write(SIODriver *siop, const uint8_t *buffer, size_t n)
Writes data into the TX FIFO.
@ SIO_READY
Definition hal_sio.h:158
@ SIO_STOP
Definition hal_sio.h:157
HAL subsystem header.
siostate_t state
Driver state.
Definition hal_sio.h:206