Commit Graph

442 Commits

Author SHA1 Message Date
Lucas De Marchi b9f65996bc AP_HAL: sparse-endian: unconditionally use byteswap.h
This is either provided by a system header or a minimal header from
'missing' directory.
2016-07-08 19:49:32 -03:00
Lucas De Marchi 40338c3272 AP_HAL: sparse-endian: use pragma once 2016-07-08 19:49:32 -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 43d4012884 AP_HAL: Fix TOCTOU in ByteBuffer::peekiovec() 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 625f47def7 AP_HAL: Improve ByteBuffer::set_size
So it doesn't delete and re-create the buffer if the size
happens to be the same. Still resets the buffer content.
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
Siddharth Bharat Purohit 8903bc9eab AP_HAL: add support for get realtime on Darwin systems 2016-07-07 11:35:17 -03:00
Andrew Tridgell 6e065b3fe2 AP_HAL: fixed typo 2016-07-01 15:35:07 +10:00
Andrew Tridgell 8617db89dc AP_HAL: added hal.util->set_imu_target_temp() API 2016-07-01 15:29:52 +10:00
Lucas De Marchi 1f96336f7c Global: rename bus type enum entries 2016-06-27 17:51:41 -03:00
Gustavo Jose de Sousa 66f1ad9ed0 AP_HAL: Device: add support for read flag
Many of our SPI and I2C sensors define the protocol of setting the most
significant bit of the register address in order to perform a read operation.
Thus, enable the use of a "read flag" that is ORed with the register's address.
Since this is an abstraction for general devices, it's a good idea to have zero
as the default value for that flag.

While at it, add documentation to read_registers().
2016-06-27 17:18:35 -03:00
Gustavo Jose de Sousa b6a1d598e3 AP_HAL: Device: document write_register() 2016-06-27 17:18:35 -03:00
Gustavo Jose de Sousa 4693501d9d AP_HAL: Device: add bus_type field
Sometimes it's necessary to know the type of bus to make some decisions where
AP_HAL::Device abstraction is used.
2016-06-27 17:18:35 -03:00
Patrick J.P eb44d75ed8 AP_HAL: Remove trailing spaces from AP_HAL_Namespace.h 2016-06-22 16:03:30 -03:00
Lucas De Marchi 9738be0ed6 AP_HAL: remove tabs and trailing whitespaces 2016-06-21 13:09:00 -03:00
Lucas De Marchi e122b2b651 AP_HAL: GPIO: remove unused functions
These functions are not used by any HAL, so remove them.
2016-06-21 12:16:32 -03:00
Tom Pittenger d3ac1dc161 AP_HAL: defer calls to safety_state switch to queue an async attempt.
- this allows for auto-retries if the state does not set correctly
2016-05-27 21:34:40 +10:00
Andrew Tridgell 163783fefd AP_HAL: define CH_NONE
for servos not connected to a channel
2016-05-26 16:26:30 +10:00
Lucas De Marchi bbe3a94175 AP_HAL: remove support for main without argc
This was only used by flymaple. Also add missing copyright notice to
header.
2016-05-23 21:49:45 -03:00
Lucas De Marchi 346bdf5f8f AP_HAL: remove support for flymaple 2016-05-23 21:49:45 -03:00
Andrew Tridgell 595d5c0002 AP_HAL: added set_size() to RingBuffer API 2016-05-23 23:41:02 +10:00
Randy Mackay 67620f312d AP_HAL: fix comment for get_time_utc 2016-05-19 16:05:29 +09:00
Niti Rohilla faec752801 AP_HAL: add get_system_clock_utc functions to Util 2016-05-19 16:05:26 +09:00
Andrew Tridgell e3107a7e10 AP_HAL: fixed optflow typos 2016-05-14 08:26:10 +10:00
Ricardo de Almeida Gonzaga eb418f54ee AP_HAL: Fix typos 2016-05-13 19:20:06 -03:00
Staroselskii Georgii 2e5cfc2849 AP_Compass: added external compass autodetection on Navio 2016-05-10 17:24:43 -03:00
Staroselskii Georgii 8be5ef1642 AP_HAL: added possibility to use several compassed on Navio 2 2016-05-10 17:24:43 -03:00
Staroselskii Georgii b677f975e7 AP_Compass: added LSM9DS1 magnetometer support 2016-05-10 17:24:43 -03:00
Lucas De Marchi 68ae619448 AP_Compass: detect compasses for minlure
Minlure has an onboard compass (HMC5883L) as slave of MPU-6000, but also
allows the use of an external HMC5883L compass, which should be
connected to the lure's I2C port.
2016-05-10 16:08:39 -03:00
Lucas De Marchi 424434e31e AP_HAL: allow to build without HAL_COMPASS_DEFAULT
Otherwise we need to change the ifdef chain adding HAL_COMPASS_<BOARD>
definitions.
2016-05-10 16:07:23 -03:00
Lucas De Marchi cf11776150 AP_HAL: fix signed and unsigned comparison warning
../../libraries/AP_HAL/examples/Printf/Printf.cpp:63:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (ret != strlen(float_tests[i].result)) {
                 ^
...

ardupilot/modules/gtest/include/gtest/gtest.h:1448:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (expected == actual) {
                ^
And similar ones.
2016-05-04 08:58:37 -03:00
Lucas De Marchi 9ac63d7128 AP_HAL: examples: fix coding style 2016-05-04 08:58:37 -03:00
Julien Beraud d0114eac05 AP_HAL: Add bebop SPI Device to spi devices
Added to namespace
2016-05-03 16:43:39 -03:00
Lucas De Marchi 5a52533084 AP_OpticalFlow: move bus definition to AP_HAL header 2016-04-29 12:10:21 -03:00
Ricardo de Almeida Gonzaga 46fb57fcf1 AP_OpticalFlow: use I2CDevice interface 2016-04-29 12:01:04 -03:00
Peter Barker e83b10cbc5 AP_HAL: move definition of callbacks structure out of C linkage
This fixes all the examples which use the AP_HAL_MAIN macro.
2016-04-27 14:21:28 +10:00
mirkix b381045d5e AP_HAL: BBBmini rework for dual MPU9250 and external HMC5843 compass 2016-04-24 10:57:57 -03:00
Andrew Tridgell 76868dd070 AP_HAL: added uartF 2016-04-20 09:39:48 +10:00
Andrew Tridgell b94e577cb8 AP_HAL: added enable_sbus_out() call in RCOutput 2016-04-16 07:30:43 +10:00
Andrew Tridgell e24d600e78 AP_HAL: added hal.rcout->set_output_mode() 2016-04-14 08:05:05 +10:00
hiro2233 7814841cd6 AP_HAL: Add RCOutput interactive example with Menu 2016-04-09 07:01:35 -07:00
Ricardo de Almeida Gonzaga 5bd034a5a8 Global: start using cmath instead of math.h 2016-04-05 21:06:19 -07:00
Lucas De Marchi 57f8db5672 AP_HAL: sparse-endian: conditionally include byteswap header
This is not present in qurt.
2016-03-23 17:50:38 -03:00
Lucas De Marchi c5dc54dac7 AP_HAL: utility: import sparse-endian header 2016-03-23 17:50:38 -03:00