Commit Graph

36 Commits

Author SHA1 Message Date
Siddharth Purohit
0ca2f56b71 AP_HAL: add support for external buffer to be used in ByteBuffer 2020-09-24 12:32:19 +10:00
Andy Piper
ad895c2654 AP_HAL: ringbuffer get_size cannot be const because of semaphore 2020-09-22 09:37:02 +10:00
Peter Barker
85b1264ff4 AP_HAL: add WARN_IF_UNUSED to several methods 2020-07-20 10:19:47 +09:00
Peter Barker
fd3dd77489 AP_HAL: rename ringbuffer empty() to is_empty() 2020-06-09 10:21:48 +10:00
Andy Piper
e2ef0bd36e AP_HAL: collect data for three largest peaks
new dsp peak detection algorithm
add DSP sketch with frequency ascii art
tool to generate gyro data frames from batch sampled DF logs
add generated data from real Y6B flight
allow fft_start() to use ObjectBuffer<float> for lock-free access
allow ObjectBuffer to be resized
2020-05-24 07:43:34 +10:00
Peter Hall
2bd6d4674b AP_HAL: utility: add thread safe ring buffer duplicate 2020-02-12 07:05:05 +11:00
Andy Piper
22d6fd5e1f AP_HAL: update docs for ObjectBuffer 2019-12-10 21:07:58 +11:00
Andrew Tridgell
9ea03e085d AP_HAL: added readptr() and advance() to ObjectBuffer
this gives a more efficient way of accessing an ObjectBuffer, which
reduces interrupt latency in SoftSigReader
2018-11-07 07:35:45 +11:00
Andrew Tridgell
d030f2888b AP_HAL: added multi-object push to RingBuffer
this is much more efficient than pushing them one at a time
2018-01-20 17:40:07 +11:00
fnoop
149188de12 AP_HAL: Add size() method to RingBuffer ObjectArray 2017-09-22 09:56:00 -07:00
fnoop
3ddd9a6bca AP_HAL: RingBuffer: Prefix private members with underscore 2017-09-22 09:55:49 -07:00
Eugene Shamaev
d1792689f1 AP_HAL/utility: clear added to RingBuffer 2017-04-10 21:31:07 +01:00
Lucas De Marchi
b0ddf81687 Remove stdbool.h include for C++ sources
This header is not needed in our C++ sources.
2016-12-16 11:38:52 -08:00
murata
c808ee2f49 Global: To nullptr from NULL.
RC_Channel: To nullptr from NULL.

AC_Fence: To nullptr from NULL.

AC_Avoidance: To nullptr from NULL.

AC_PrecLand: To nullptr from NULL.

DataFlash: To nullptr from NULL.

SITL: To nullptr from NULL.

GCS_MAVLink: To nullptr from NULL.

DataFlash: To nullptr from NULL.

AP_Compass: To nullptr from NULL.

Global: To nullptr from NULL.

Global: To nullptr from NULL.
2016-11-02 16:04:47 -02:00
Murilo Belluzzo
3f1896b9b7 RingBuffer: Remove 'old style' version 2016-10-27 14:24:10 +11:00
Murilo Belluzzo
8526b25654 RingBuffer: Add a faster method to read a single byte 2016-10-27 14:23:42 +11:00
Murilo Belluzzo
b856d26087 RingBuffer: ::set_size now returns true or false 2016-08-03 01:44:02 -03:00
Murilo Belluzzo
f7f203efa9 RingBuffer: Add ::clear() method to discard the buffer content
The same could be achieved with ::set_size(::get_size()), but was not
obvious and hurts code readability.
2016-08-03 01:44:02 -03:00
Lucas De Marchi
6a80c3d70d AP_HAL: RingBuffer: remove trailing whitespaces 2016-07-08 16:44:26 -03:00
Lucas De Marchi
24c7f76034 AP_HAL: RingBuffer: remove C++11 initialization
They are already initialized in the constructor.
2016-07-08 16:44:09 -03:00
Murilo Belluzzo
3e1acdcbbf AP_HAL: Use atomic instead volatile on RingBuffer head/tail
Volatile will provide protection to sequence re-ordering and guarantee
the variable is fetched from memory, but it won't provide the memory
barrier needed to ensure that no re-ordering (by either the compiler or
the CPU) will happen among other threads of execution
accessing the same variables.

For more info about this effect can be found on articles about
std::memory_order.
2016-07-08 16:12:53 -03:00
Murilo Belluzzo
b7dd4dad64 AP_HAL: Fix ByteBuffer::reserve() breaking buffer state
When using reserved(), the reserved memory cannot be read before it's
written, therefore we cannot update 'tail' until the caller of
reserved() is done writing.

To solve that, a method called 'commit()' was added so the caller can
inform that is done with the memory usage and is safe to update 'tail'.
The caller also has to inform the length that was actually written.

This solution was developed to work considering the usage context of
this class: 1 reader and 1 writer **only**.
2016-07-08 13:10:16 -03:00
Murilo Belluzzo
9951b94d40 AP_HAL: Change the return type of 'peekiovec'
Possible values are '0', '1' and '2' so uint8_t is a better fit. Also,
invert 'if' condition so it's clear that is returning 0, 1 or 2.
2016-07-08 13:10:16 -03:00
Murilo Belluzzo
e9e31172c0 AP_HAL: Simplify ByteBuffer::readptr logic 2016-07-08 13:10:16 -03:00
Leandro Pereira
fbefe32017 AP_HAL: Add method to reserve space in the ring buffer
Adds a method called `reserve()`, that will take a ByteBuffer::IoVec
array of at least two elements, and return the number of elements
filled out.  0 will be returned if `len` is over the total space of
the buffer; 1 will be returned if there's enough contiguous bytes in
the buffer; 2 will be returned if there are two non-contiguous blocks
of memory.

This method is suitable to be used with POSIX system calls such as
readv(), and is an optimization to not require temporary memory copies
while reading from a file descriptor.

Also modify the write() method to use reserve(), so that similar checks
are performed only in one place.
2016-07-08 13:10:16 -03:00
Leandro Pereira
e3b676ba89 AP_HAL: Add method to peek non-contiguous parts of a ByteBuffer
Modify ByteBuffer class to have a `peekiovec()` method, that takes in a
`struct IoVec` array (similar to `struct iovec` from POSIX), and a
number of bytes, and returns the number of elements from this array
that have been filled out.  It is either 0 (buffer is empty), 1
(there's enough contiguous bytes to read that amount) or 2 (ring buffer
is wrapping around).

This enables using scatter-gather I/O (i.e. writev()), removing calls
to memcpy().  That's one call when no wrap-around is happening, and
two calls if it is.

Also, rewrite `ByteBuffer::peekbytes()` to use `peekiovec()`, so that
some of the checks performed by the former are not replicated in the
latter.
2016-07-08 13:10:16 -03:00
Andrew Tridgell
595d5c0002 AP_HAL: added set_size() to RingBuffer API 2016-05-23 23:41:02 +10:00
Andrew Tridgell
2120913ac2 AP_HAL: added ObjectArray template
this is a ring buffer that supports indexing for efficient handling of
queue peeking and manipulation
2016-02-24 09:18:06 +11:00
Tom Pittenger
9718ee23d1 AP_HAL: fix peekbytes casting 2016-02-24 09:18:06 +11:00
Andrew Tridgell
1df2512935 AP_HAL: added update() method for object ringbuffer
to support updating objects for GCS work Tom is doing
2016-02-23 16:34:06 +11:00
Tom Pittenger
1d528d552f AP_HAL: rename RingBuffer.force() to RingBuffer.push_force() 2016-02-21 22:13:27 -08:00
Andrew Tridgell
4ff396dfa8 AP_HAL: added force() and peek() method for object ringbuffers 2016-02-22 12:34:32 +11:00
Lucas De Marchi
97022a4161 AP_HAL: RingBuffer: fix macro expansion
Fix warning that reveals a real bug:

In file included from libraries/AP_HAL_Linux/UARTDriver.cpp:25:0:
libraries/AP_HAL_Linux/UARTDriver.cpp: In member function 'virtual bool Linux::UARTDriver::tx_pending()':
libraries/AP_HAL/utility/RingBuffer.h:21:35: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
 #define BUF_EMPTY(buf) buf##_head == buf##_tail
                                   ^
libraries/AP_HAL_Linux/UARTDriver.cpp:355:13: note: in expansion of macro 'BUF_EMPTY'
     return !BUF_EMPTY(_writebuf);

The problem is when there's a ! operator: without the parenthesis we would actually be doing

    return !_write_buf_head == _write_buf_tail

which is not what we want.
2015-12-28 21:50:27 -02:00
Andrew Tridgell
7c431b40f2 AP_HAL: enable HAL_QURT 2015-12-27 16:21:25 +11:00
Andrew Tridgell
ec6a679482 AP_HAL: added ByteBuffer and ObjectBuffer in RingBuffer
much better API than old macros
2015-12-20 07:33:54 +11:00
Andrew Tridgell
6fb00f4fc3 AP_HAL: create a common utility/RingBuffer.h header 2015-01-07 08:41:14 +11:00