amiro-os / core / inc / aos_iostream.h @ f3ac1c96
History | View | Annotate | Download (5.7 KB)
1 |
/*
|
---|---|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2019 Thomas Schöpping et al.
|
4 |
|
5 |
This program is free software: you can redistribute it and/or modify
|
6 |
it under the terms of the GNU General Public License as published by
|
7 |
the Free Software Foundation, either version 3 of the License, or
|
8 |
(at your option) any later version.
|
9 |
|
10 |
This program is distributed in the hope that it will be useful,
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
GNU General Public License for more details.
|
14 |
|
15 |
You should have received a copy of the GNU General Public License
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
*/
|
18 |
|
19 |
/**
|
20 |
* @file aos_iostream.h
|
21 |
* @brief Stream and channel macros and structures.
|
22 |
*
|
23 |
* @addtogroup aos_stream
|
24 |
* @{
|
25 |
*/
|
26 |
|
27 |
#ifndef AMIROOS_IOSTREAM_H
|
28 |
#define AMIROOS_IOSTREAM_H
|
29 |
|
30 |
#include <hal.h> |
31 |
#include <aos_types.h> |
32 |
#include <stdarg.h> |
33 |
|
34 |
|
35 |
/******************************************************************************/
|
36 |
/* CONSTANTS */
|
37 |
/******************************************************************************/
|
38 |
|
39 |
/**
|
40 |
* @brief Channel flag to indicate whether the channel is attached to a stream.
|
41 |
*/
|
42 |
#define AOS_IOCHANNEL_ATTACHED ((aos_iochannelflag_t)(1 << 0)) |
43 |
|
44 |
/**
|
45 |
* @brief Channel flag to indicate whether the channel is set as input.
|
46 |
*/
|
47 |
#define AOS_IOCHANNEL_INPUT_ENABLE ((aos_iochannelflag_t)(1 << 1)) |
48 |
|
49 |
/**
|
50 |
* @brief Channel flag to indicate whether the channel is set as output.
|
51 |
*/
|
52 |
#define AOS_IOCHANNEL_OUTPUT_ENABLE ((aos_iochannelflag_t)(1 << 2)) |
53 |
|
54 |
/******************************************************************************/
|
55 |
/* SETTINGS */
|
56 |
/******************************************************************************/
|
57 |
|
58 |
/******************************************************************************/
|
59 |
/* CHECKS */
|
60 |
/******************************************************************************/
|
61 |
|
62 |
/******************************************************************************/
|
63 |
/* DATA STRUCTURES AND TYPES */
|
64 |
/******************************************************************************/
|
65 |
|
66 |
typedef uint8_t aos_iochannelflag_t;
|
67 |
|
68 |
/**
|
69 |
* @brief AosIOChannel specific methods.
|
70 |
*/
|
71 |
#define _aos_iochannel_methods \
|
72 |
_base_asynchronous_channel_methods |
73 |
|
74 |
/**
|
75 |
* @brief AosIOChannel specific data.
|
76 |
*/
|
77 |
#define _aos_iochannel_data \
|
78 |
/* pointer to a BaseAsynchronousChannel object */ \
|
79 |
BaseAsynchronousChannel* asyncchannel; \ |
80 |
/* pointer to the next channel in a AosIOStream */ \
|
81 |
struct aos_iochannel* next; \
|
82 |
/* flags related to the channel */ \
|
83 |
aos_iochannelflag_t flags; |
84 |
|
85 |
/**
|
86 |
* @extends BaseAsynchronousChannelVMT
|
87 |
*
|
88 |
* @brief AosIOChannel virtual methods table.
|
89 |
*/
|
90 |
struct AosIOChannelVMT {
|
91 |
_aos_iochannel_methods |
92 |
}; |
93 |
|
94 |
/**
|
95 |
* @extends BaseAsynchronousChannel
|
96 |
*
|
97 |
* @brief I/O Channel class.
|
98 |
* @details This class implements an asynchronous I/O channel.
|
99 |
*/
|
100 |
typedef struct aos_iochannel { |
101 |
/** @brief Virtual Methods Table. */
|
102 |
const struct AosIOChannelVMT* vmt; |
103 |
_aos_iochannel_data |
104 |
} AosIOChannel; |
105 |
|
106 |
/**
|
107 |
* @brief AosIOStream methods.
|
108 |
*/
|
109 |
#define _aos_iostream_methods \
|
110 |
_base_sequential_stream_methods |
111 |
|
112 |
/**
|
113 |
* @brief AosIOStream data.
|
114 |
*/
|
115 |
#define _aos_iostream_data \
|
116 |
/* Pointer to the first channel in a list. */ \
|
117 |
AosIOChannel* channel; |
118 |
|
119 |
/**
|
120 |
* @extends BaseSequentialStream
|
121 |
*
|
122 |
* @brief AosIOStream virtual methods table.
|
123 |
*/
|
124 |
struct AosIOStreamVMT {
|
125 |
_aos_iostream_methods |
126 |
}; |
127 |
|
128 |
/**
|
129 |
* @extends BaseSequentialStream
|
130 |
*
|
131 |
* @brief I/O Stream class.
|
132 |
* @details This class implements an base sequential stream.
|
133 |
* @todo So far only output but no input is supported.
|
134 |
*/
|
135 |
typedef struct aos_ostream { |
136 |
const struct AosIOStreamVMT* vmt; |
137 |
_aos_iostream_data |
138 |
} AosIOStream; |
139 |
|
140 |
/******************************************************************************/
|
141 |
/* MACROS */
|
142 |
/******************************************************************************/
|
143 |
|
144 |
/******************************************************************************/
|
145 |
/* EXTERN DECLARATIONS */
|
146 |
/******************************************************************************/
|
147 |
|
148 |
#ifdef __cplusplus
|
149 |
extern "C" { |
150 |
#endif
|
151 |
void aosIOStreamInit(AosIOStream* stream);
|
152 |
void aosIOChannelInit(AosIOChannel* channel, BaseAsynchronousChannel* asyncchannel);
|
153 |
void aosIOStreamAddChannel(AosIOStream* stream, AosIOChannel* channel);
|
154 |
aos_status_t aosIOStreamRemoveChannel(AosIOStream* stream, AosIOChannel* channel); |
155 |
void aosIOChannelInputEnable(AosIOChannel* channel);
|
156 |
void aosIOChannelInputDisable(AosIOChannel* channel);
|
157 |
void aosIOChannelOutputEnable(AosIOChannel* channel);
|
158 |
void aosIOChannelOutputDisable(AosIOChannel* channel);
|
159 |
#ifdef __cplusplus
|
160 |
} |
161 |
#endif
|
162 |
|
163 |
/******************************************************************************/
|
164 |
/* INLINE FUNCTIONS */
|
165 |
/******************************************************************************/
|
166 |
|
167 |
#endif /* AMIROOS_IOSTREAM_H */ |
168 |
|
169 |
/** @} */
|