tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
stream_buffer.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_FREERTOS_STREAM_BUFFER_HPP
4#define TETL_FREERTOS_STREAM_BUFFER_HPP
5
6#include <etl/version.hpp>
7
8#include <etl/cstdint.hpp>
9#include <etl/utility.hpp>
10
12
13#if defined(TETL_FREERTOS_USE_STUBS)
15#endif
16
18
32
36 stream_buffer(size_type size, size_type triggerLevel) noexcept;
37
41 ~stream_buffer() noexcept;
42
43 stream_buffer(stream_buffer const& other) = delete;
44 auto operator=(stream_buffer const& other) -> stream_buffer& = delete;
45
46 stream_buffer(stream_buffer&& other) = delete;
47 auto operator=(stream_buffer&& other) -> stream_buffer& = delete;
48
53 auto write(net::const_buffer data, TickType_t ticks) -> size_type;
54
59 auto write_from_isr(net::const_buffer data, BaseType_t* prio) -> size_type;
60
64 auto read(net::mutable_buffer data, TickType_t ticks) -> size_type;
65
69 auto read_from_isr(net::mutable_buffer data, BaseType_t* prio) -> size_type;
70
75 [[nodiscard]] auto empty() const noexcept -> bool;
76
82 [[nodiscard]] auto full() const noexcept -> bool;
83
89 [[nodiscard]] auto bytes_available() const noexcept -> size_type;
90
96 [[nodiscard]] auto space_available() const noexcept -> size_type;
97
104 auto reset() noexcept -> void;
105
123 auto trigger_level(size_type triggerLevel) noexcept -> void;
124
126 [[nodiscard]] auto native_handle() const noexcept -> StreamBufferHandle_t;
127
128private:
129 StreamBufferHandle_t _handle;
130};
131
132inline stream_buffer::stream_buffer(size_t size, size_t triggerLevel) noexcept
133 : _handle{xStreamBufferCreate(size, triggerLevel)}
134{
135}
136
138
140{
141 return xStreamBufferSend(_handle, data.data(), data.size(), ticks);
142}
143
145{
146 return xStreamBufferSendFromISR(_handle, data.data(), data.size(), prio);
147}
148
150{
151 return xStreamBufferReceive(_handle, data.data(), data.size(), ticks);
152}
153
155{
156 return xStreamBufferReceiveFromISR(_handle, data.data(), data.size(), prio);
157}
158
159inline auto stream_buffer::empty() const noexcept -> bool { return static_cast<bool>(xStreamBufferIsEmpty(_handle)); }
160
161inline auto stream_buffer::full() const noexcept -> bool { return static_cast<bool>(xStreamBufferIsFull(_handle)); }
162
163inline auto stream_buffer::bytes_available() const noexcept -> size_type
164{
165 return xStreamBufferBytesAvailable(_handle);
166}
167
168inline auto stream_buffer::space_available() const noexcept -> size_type
169{
170 return xStreamBufferSpacesAvailable(_handle);
171}
172
173inline auto stream_buffer::reset() noexcept -> void { xStreamBufferReset(_handle); }
174
175inline auto stream_buffer::trigger_level(size_type triggerLevel) noexcept -> void
176{
177 xStreamBufferSetTriggerLevel(_handle, triggerLevel);
178}
179
180inline auto stream_buffer::native_handle() const noexcept -> StreamBufferHandle_t { return _handle; }
181
182} // namespace etl::experimental::freertos
183
184#endif // TETL_FREERTOS_STREAM_BUFFER_HPP
constexpr auto data(C &c) noexcept(noexcept(c.data())) -> decltype(c.data())
Returns a pointer to the block of memory containing the elements of the container.
Definition data.hpp:11
constexpr auto size(C const &c) noexcept(noexcept(c.size())) -> decltype(c.size())
Returns the size of the given container c or array array. Returns c.size(), converted to the return t...
Definition size.hpp:18
Definition queue.hpp:15
Definition buffer.hpp:14
TETL_BUILTIN_SIZET size_t
etl::size_t is the unsigned integer type of the result of the sizeof operator.
Definition size_t.hpp:14
auto empty() const noexcept -> bool
Queries a stream buffer to see if it is empty. A stream buffer is empty if it does not contain any da...
Definition stream_buffer.hpp:159
auto space_available() const noexcept -> size_type
Queries a stream buffer to see how much free space it contains, which is equal to the amount of data ...
Definition stream_buffer.hpp:168
etl::size_t size_type
Definition stream_buffer.hpp:31
auto write_from_isr(net::const_buffer data, BaseType_t *prio) -> size_type
Interrupt safe version of the API function that sends a stream of bytes to the stream buffer.
Definition stream_buffer.hpp:144
auto native_handle() const noexcept -> StreamBufferHandle_t
Returns the native FreeRTOS handle to the stream_buffer.
Definition stream_buffer.hpp:180
auto trigger_level(size_type triggerLevel) noexcept -> void
A stream buffer's trigger level is the number of bytes that must be in the stream buffer before a tas...
Definition stream_buffer.hpp:175
auto bytes_available() const noexcept -> size_type
Queries a stream buffer to see how much data it contains, which is equal to the number of bytes that ...
Definition stream_buffer.hpp:163
~stream_buffer() noexcept
Deletes a stream buffer, then the allocated memory is freed.
Definition stream_buffer.hpp:137
auto read_from_isr(net::mutable_buffer data, BaseType_t *prio) -> size_type
Receives bytes from a stream buffer.
Definition stream_buffer.hpp:154
stream_buffer(size_type size, size_type triggerLevel) noexcept
Creates a new stream buffer using dynamically allocated memory.
Definition stream_buffer.hpp:132
auto reset() noexcept -> void
Resets a stream buffer to its initial, empty, state. Any data that was in the stream buffer is discar...
Definition stream_buffer.hpp:173
auto write(net::const_buffer data, TickType_t ticks) -> size_type
Sends bytes to a stream buffer. The bytes are copied into the stream buffer.
Definition stream_buffer.hpp:139
auto full() const noexcept -> bool
Queries a stream buffer to see if it is full. A stream buffer is full if it does not have any free sp...
Definition stream_buffer.hpp:161
auto read(net::mutable_buffer data, TickType_t ticks) -> size_type
Receives bytes from a stream buffer.
Definition stream_buffer.hpp:149
Definition buffer_const.hpp:12
Definition buffer_mutable.hpp:12
auto xStreamBufferSend(StreamBufferHandle_t handle, void const *data, etl::size_t size, TickType_t ticksToWait) -> etl::size_t
Definition stubs.hpp:109
auto xStreamBufferReceive(StreamBufferHandle_t handle, void *data, etl::size_t size, TickType_t ticks) -> etl::size_t
Definition stubs.hpp:125
auto xStreamBufferSpacesAvailable(StreamBufferHandle_t handle) -> etl::size_t
Definition stubs.hpp:146
StreamBufferDef_t * StreamBufferHandle_t
Definition stubs.hpp:99
long BaseType_t
Definition stubs.hpp:13
auto xStreamBufferIsEmpty(StreamBufferHandle_t handle) -> BaseType_t
Definition stubs.hpp:164
auto xStreamBufferReset(StreamBufferHandle_t handle) -> BaseType_t
Definition stubs.hpp:158
etl::uint32_t TickType_t
Definition stubs.hpp:24
auto xStreamBufferIsFull(StreamBufferHandle_t handle) -> BaseType_t
Definition stubs.hpp:170
auto xStreamBufferCreate(etl::size_t bufferSizeBytes, etl::size_t triggerLevelBytes) -> StreamBufferHandle_t
Definition stubs.hpp:101
auto xStreamBufferBytesAvailable(StreamBufferHandle_t handle) -> etl::size_t
Definition stubs.hpp:140
auto xStreamBufferReceiveFromISR(StreamBufferHandle_t handle, void *data, etl::size_t size, BaseType_t *prio) -> etl::size_t
Definition stubs.hpp:132
auto vStreamBufferDelete(StreamBufferHandle_t handle) -> void
Definition stubs.hpp:138
auto xStreamBufferSendFromISR(StreamBufferHandle_t handle, void const *data, etl::size_t size, BaseType_t *prio) -> etl::size_t
Definition stubs.hpp:117
auto xStreamBufferSetTriggerLevel(StreamBufferHandle_t handle, etl::size_t triggerLevel) -> BaseType_t
Definition stubs.hpp:152