amiro-os / os / core / inc / aos_iostream.h @ dd8738ea
History | View | Annotate | Download (3.86 KB)
1 |
/*
|
---|---|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2018 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 |
#ifndef _AMIROOS_IOSTREAM_H_
|
20 |
#define _AMIROOS_IOSTREAM_H_
|
21 |
|
22 |
#include <hal.h> |
23 |
#include <aos_types.h> |
24 |
#include <stdarg.h> |
25 |
|
26 |
|
27 |
|
28 |
/**
|
29 |
* @brief Channel flag to indicate whether the channel is attached to a stream.
|
30 |
*/
|
31 |
#define AOS_IOCHANNEL_ATTACHED (1 << 0) |
32 |
|
33 |
/**
|
34 |
* @brief Channel flag to indicate whether the channel is set as input.
|
35 |
*/
|
36 |
#define AOS_IOCHANNEL_INPUT_ENABLE (1 << 1) |
37 |
|
38 |
/**
|
39 |
* @brief Channel flag to indicate whether the channel is set as output.
|
40 |
*/
|
41 |
#define AOS_IOCHANNEL_OUTPUT_ENABLE (1 << 2) |
42 |
|
43 |
/*
|
44 |
* forward definitions
|
45 |
*/
|
46 |
typedef struct aos_iochannel AosIOChannel; |
47 |
typedef struct aos_ostream AosIOStream; |
48 |
|
49 |
/**
|
50 |
* @brief AosI=Channel specific methods.
|
51 |
*/
|
52 |
#define _aos_iochannel_methods \
|
53 |
_base_asynchronous_channel_methods |
54 |
|
55 |
/**
|
56 |
* @brief AosIOChannel specific data.
|
57 |
*/
|
58 |
#define _aos_iochannel_data \
|
59 |
/* pointer to a BaseAsynchronousChannel object */ \
|
60 |
BaseAsynchronousChannel* asyncchannel; \ |
61 |
/* pointer to the next channel in a AosIOStream */ \
|
62 |
AosIOChannel* next; \ |
63 |
/* flags related to the channel */ \
|
64 |
uint8_t flags; |
65 |
|
66 |
/**
|
67 |
* @extends BaseAsynchronousChannelVMT
|
68 |
*
|
69 |
* @brief AosIOChannel virtual methods table.
|
70 |
*/
|
71 |
struct AosIOChannelVMT {
|
72 |
_aos_iochannel_methods |
73 |
}; |
74 |
|
75 |
/**
|
76 |
* @extends BaseAsynchronousChannel
|
77 |
*
|
78 |
* @brief I/O Channel class.
|
79 |
* @details This class implements an asynchronous I/O channel.
|
80 |
*/
|
81 |
struct aos_iochannel {
|
82 |
/** @brief Virtual Methods Table. */
|
83 |
const struct AosIOChannelVMT* vmt; |
84 |
_aos_iochannel_data |
85 |
}; |
86 |
|
87 |
/**
|
88 |
* @brief AosIOStream methods.
|
89 |
*/
|
90 |
#define _aos_iostream_methods \
|
91 |
_base_sequential_stream_methods |
92 |
|
93 |
/**
|
94 |
* @brief AosIOStream data.
|
95 |
*/
|
96 |
#define _aos_iostream_data \
|
97 |
/* Pointer to the first channel in a list. */ \
|
98 |
AosIOChannel* channel; |
99 |
|
100 |
/**
|
101 |
* @extends BaseSequentialStream
|
102 |
*
|
103 |
* @brief AosIOStream virtual methods table.
|
104 |
*/
|
105 |
struct AosIOStreamVMT {
|
106 |
_aos_iostream_methods |
107 |
}; |
108 |
|
109 |
/**
|
110 |
* @extends BaseSequentialStream
|
111 |
*
|
112 |
* @brief I/O Stream class.
|
113 |
* @details This class implements an base sequential stream.
|
114 |
* @todo So far only output but no input is supported.
|
115 |
*/
|
116 |
struct aos_ostream {
|
117 |
const struct AosIOStreamVMT* vmt; |
118 |
_aos_iostream_data |
119 |
}; |
120 |
|
121 |
#ifdef __cplusplus
|
122 |
extern "C" { |
123 |
#endif
|
124 |
void aosIOStreamInit(AosIOStream* stream);
|
125 |
void aosIOChannelInit(AosIOChannel* channel, BaseAsynchronousChannel* asyncchannel);
|
126 |
void aosIOStreamAddChannel(AosIOStream* stream, AosIOChannel* channel);
|
127 |
aos_status_t aosIOStreamRemoveChannel(AosIOStream* stream, AosIOChannel* channel); |
128 |
void aosIOChannelInputEnable(AosIOChannel* channel);
|
129 |
void aosIOChannelInputDisable(AosIOChannel* channel);
|
130 |
void aosIOChannelOutputEnable(AosIOChannel* channel);
|
131 |
void aosIOChannelOutputDisable(AosIOChannel* channel);
|
132 |
#ifdef __cplusplus
|
133 |
} |
134 |
#endif
|
135 |
|
136 |
#endif /* _AMIROOS_IOSTREAM_H_ */ |