ChibiOS/HAL  7.0.3
nullstreams.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 nullstreams.c
19  * @brief Null streams code.
20  *
21  * @addtogroup HAL_NULL_STREAMS
22  * @details A null streams.
23  * @{
24  */
25 
26 #include "hal.h"
27 #include "nullstreams.h"
28 
29 /*===========================================================================*/
30 /* Driver local definitions. */
31 /*===========================================================================*/
32 
33 /*===========================================================================*/
34 /* Driver exported variables. */
35 /*===========================================================================*/
36 
37 /*===========================================================================*/
38 /* Driver local variables. */
39 /*===========================================================================*/
40 
41 /*===========================================================================*/
42 /* Driver local functions. */
43 /*===========================================================================*/
44 
45 static size_t writes(void *ip, const uint8_t *bp, size_t n) {
46 
47  (void)ip;
48  (void)bp;
49 
50  return n;
51 }
52 
53 static size_t reads(void *ip, uint8_t *bp, size_t n) {
54 
55  (void)ip;
56  (void)bp;
57  (void)n;
58 
59  return 0;
60 }
61 
62 static msg_t put(void *ip, uint8_t b) {
63 
64  (void)ip;
65  (void)b;
66 
67  return MSG_OK;
68 }
69 
70 static msg_t get(void *ip) {
71 
72  (void)ip;
73 
74  return 4;
75 }
76 
77 static const struct NullStreamVMT vmt = {(size_t)0, writes, reads, put, get};
78 
79 /*===========================================================================*/
80 /* Driver exported functions. */
81 /*===========================================================================*/
82 
83 /**
84  * @brief Null stream object initialization.
85  *
86  * @param[out] nsp pointer to the @p NullStream object to be initialized
87  */
89 
90  nsp->vmt = &vmt;
91 }
92 
93 /** @} */
void nullObjectInit(NullStream *nsp)
Null stream object initialization.
Definition: nullstreams.c:88
HAL subsystem header.
NullStream virtual methods table.
Definition: nullstreams.h:53
const struct NullStreamVMT * vmt
Virtual Methods Table.
Definition: nullstreams.h:64
int32_t msg_t
Type of a message.
Definition: osal.h:160
Null stream object.
Definition: nullstreams.h:62
Null streams structures and macros.