amiro-os / core / inc / aos_iostream.h @ f3ac1c96
History | View | Annotate | Download (5.699 KB)
| 1 | ba516b61 | Thomas Schöpping | /*
|
|---|---|---|---|
| 2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
| 3 | 84f0ce9e | Thomas Schöpping | Copyright (C) 2016..2019 Thomas Schöpping et al.
|
| 4 | ba516b61 | Thomas Schöpping | |
| 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 | 53710ca3 | Marc Rothmann | /**
|
| 20 | * @file aos_iostream.h
|
||
| 21 | * @brief Stream and channel macros and structures.
|
||
| 22 | *
|
||
| 23 | * @addtogroup aos_stream
|
||
| 24 | * @{
|
||
| 25 | */
|
||
| 26 | |||
| 27 | 6ff06bbf | Thomas Schöpping | #ifndef AMIROOS_IOSTREAM_H
|
| 28 | #define AMIROOS_IOSTREAM_H
|
||
| 29 | ba516b61 | Thomas Schöpping | |
| 30 | #include <hal.h> |
||
| 31 | #include <aos_types.h> |
||
| 32 | #include <stdarg.h> |
||
| 33 | |||
| 34 | |||
| 35 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
| 36 | /* CONSTANTS */
|
||
| 37 | /******************************************************************************/
|
||
| 38 | ba516b61 | Thomas Schöpping | |
| 39 | /**
|
||
| 40 | * @brief Channel flag to indicate whether the channel is attached to a stream.
|
||
| 41 | */
|
||
| 42 | f3ac1c96 | Thomas Schöpping | #define AOS_IOCHANNEL_ATTACHED ((aos_iochannelflag_t)(1 << 0)) |
| 43 | ba516b61 | Thomas Schöpping | |
| 44 | /**
|
||
| 45 | dd8738ea | Thomas Schöpping | * @brief Channel flag to indicate whether the channel is set as input.
|
| 46 | */
|
||
| 47 | f3ac1c96 | Thomas Schöpping | #define AOS_IOCHANNEL_INPUT_ENABLE ((aos_iochannelflag_t)(1 << 1)) |
| 48 | dd8738ea | Thomas Schöpping | |
| 49 | /**
|
||
| 50 | ba516b61 | Thomas Schöpping | * @brief Channel flag to indicate whether the channel is set as output.
|
| 51 | */
|
||
| 52 | f3ac1c96 | Thomas Schöpping | #define AOS_IOCHANNEL_OUTPUT_ENABLE ((aos_iochannelflag_t)(1 << 2)) |
| 53 | ba516b61 | Thomas Schöpping | |
| 54 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
| 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 | ba516b61 | Thomas Schöpping | |
| 68 | /**
|
||
| 69 | f3ac1c96 | Thomas Schöpping | * @brief AosIOChannel specific methods.
|
| 70 | ba516b61 | Thomas Schöpping | */
|
| 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 | f3ac1c96 | Thomas Schöpping | struct aos_iochannel* next; \
|
| 82 | ba516b61 | Thomas Schöpping | /* flags related to the channel */ \
|
| 83 | f3ac1c96 | Thomas Schöpping | aos_iochannelflag_t flags; |
| 84 | ba516b61 | Thomas Schöpping | |
| 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 | f3ac1c96 | Thomas Schöpping | typedef struct aos_iochannel { |
| 101 | ba516b61 | Thomas Schöpping | /** @brief Virtual Methods Table. */
|
| 102 | const struct AosIOChannelVMT* vmt; |
||
| 103 | _aos_iochannel_data |
||
| 104 | f3ac1c96 | Thomas Schöpping | } AosIOChannel; |
| 105 | ba516b61 | Thomas Schöpping | |
| 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 | f3ac1c96 | Thomas Schöpping | typedef struct aos_ostream { |
| 136 | ba516b61 | Thomas Schöpping | const struct AosIOStreamVMT* vmt; |
| 137 | _aos_iostream_data |
||
| 138 | f3ac1c96 | Thomas Schöpping | } AosIOStream; |
| 139 | |||
| 140 | /******************************************************************************/
|
||
| 141 | /* MACROS */
|
||
| 142 | /******************************************************************************/
|
||
| 143 | |||
| 144 | /******************************************************************************/
|
||
| 145 | /* EXTERN DECLARATIONS */
|
||
| 146 | /******************************************************************************/
|
||
| 147 | ba516b61 | Thomas Schöpping | |
| 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 | dd8738ea | Thomas Schöpping | void aosIOChannelInputEnable(AosIOChannel* channel);
|
| 156 | void aosIOChannelInputDisable(AosIOChannel* channel);
|
||
| 157 | ba516b61 | Thomas Schöpping | void aosIOChannelOutputEnable(AosIOChannel* channel);
|
| 158 | void aosIOChannelOutputDisable(AosIOChannel* channel);
|
||
| 159 | #ifdef __cplusplus
|
||
| 160 | } |
||
| 161 | #endif
|
||
| 162 | |||
| 163 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
| 164 | /* INLINE FUNCTIONS */
|
||
| 165 | /******************************************************************************/
|
||
| 166 | |||
| 167 | 6ff06bbf | Thomas Schöpping | #endif /* AMIROOS_IOSTREAM_H */ |
| 168 | 53710ca3 | Marc Rothmann | |
| 169 | /** @} */ |