ChibiOS 21.11.4
hal_buffered_serial.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_buffered_serial.h
19 * @brief Buffered Serial Driver code.
20 *
21 * @addtogroup HAL_BUFFERED_SERIAL
22 * @{
23 */
24
25#include "hal.h"
26
27/*===========================================================================*/
28/* Driver local definitions. */
29/*===========================================================================*/
30
31/*===========================================================================*/
32/* Driver exported variables. */
33/*===========================================================================*/
34
35/*===========================================================================*/
36/* Driver local variables and types. */
37/*===========================================================================*/
38
39/*===========================================================================*/
40/* Driver local functions. */
41/*===========================================================================*/
42
43/*===========================================================================*/
44/* Driver exported functions. */
45/*===========================================================================*/
46
47/**
48 * @brief Handles incoming data.
49 * @details This function must be called from the input interrupt service
50 * routine in order to enqueue incoming data and generate the
51 * related events.
52 * @note The incoming data event is only generated when the input queue
53 * becomes non-empty.
54 *
55 * @param[in] bsp pointer to a @p BufferedSerial structure
56 * @param[in] b the byte to be written in the driver's Input Queue
57 *
58 * @iclass
59 */
60void bsIncomingDataI(BufferedSerial *bsp, uint8_t b) {
61
63 osalDbgCheck(bsp != NULL);
64
65 if (iqIsEmptyI(&bsp->iqueue)) {
67 }
68
69 if (iqPutI(&bsp->iqueue, b) < MSG_OK) {
71 }
72}
73
74/**
75 * @brief Handles outgoing data.
76 * @details Must be called from the output interrupt service routine in order
77 * to get the next byte to be transmitted.
78 * @note In order to gain some performance it is suggested to not use
79 * this function directly but copy this code directly into the
80 * interrupt service routine.
81 *
82 * @param[in] bsp pointer to a @p BufferedSerial structure
83 * @return The byte value read from the driver's output queue.
84 * @retval MSG_TIMEOUT if the queue is empty.
85 *
86 * @iclass
87 */
89 msg_t b;
90
92 osalDbgCheck(bsp != NULL);
93
94 b = oqGetI(&bsp->oqueue);
95 if (b < MSG_OK) {
97 }
98
99 return b;
100}
101
102/** @} */
struct hal_buffered_serial BufferedSerial
Structure representing a buffered serial class.
msg_t bsRequestDataI(BufferedSerial *bsp)
Handles outgoing data.
void bsIncomingDataI(BufferedSerial *bsp, uint8_t b)
Handles incoming data.
#define iqIsEmptyI(iqp)
Evaluates to true if the specified input queue is empty.
Definition hal_queues.h:198
msg_t iqPutI(input_queue_t *iqp, uint8_t b)
Input queue write.
Definition hal_queues.c:224
msg_t oqGetI(output_queue_t *oqp)
Output queue read.
Definition hal_queues.c:576
#define CHN_BUFFER_FULL_ERROR
#define CHN_OUTPUT_EMPTY
Output queue empty.
#define CHN_INPUT_AVAILABLE
Data available in the input queue.
#define chnAddFlagsI(ip, flags)
Adds status flags to the listeners's flags mask.
#define osalDbgCheck(c)
Function parameters check.
Definition osal.h:284
#define osalDbgCheckClassI()
I-Class state check.
Definition osal.h:298
int32_t msg_t
Definition chearly.h:88
#define MSG_OK
Normal wakeup message.
Definition chschd.h:39
HAL subsystem header.