mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-13 03:21:35 +08:00
Showcase clang-format google style
This commit is contained in:
@@ -39,10 +39,6 @@
|
||||
|
||||
#include <uORB/topics/event.h>
|
||||
|
||||
namespace events
|
||||
{
|
||||
namespace events {
|
||||
using EventType = event_s;
|
||||
} // namespace events
|
||||
|
||||
|
||||
|
||||
} // namespace events
|
||||
|
||||
@@ -40,11 +40,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace px4
|
||||
{
|
||||
namespace px4 {
|
||||
|
||||
class AppState
|
||||
{
|
||||
class AppState {
|
||||
public:
|
||||
~AppState() {}
|
||||
|
||||
@@ -59,11 +57,12 @@ public:
|
||||
protected:
|
||||
bool _exitRequested;
|
||||
bool _isRunning;
|
||||
|
||||
private:
|
||||
AppState(const AppState &);
|
||||
const AppState &operator=(const AppState &);
|
||||
};
|
||||
}
|
||||
} // namespace px4
|
||||
|
||||
// Task/process based build
|
||||
|
||||
|
||||
@@ -59,22 +59,19 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(__PX4_NUTTX)
|
||||
# include <nuttx/irq.h>
|
||||
#endif // __PX4_NUTTX
|
||||
#include <nuttx/irq.h>
|
||||
#endif // __PX4_NUTTX
|
||||
|
||||
namespace px4
|
||||
{
|
||||
namespace px4 {
|
||||
|
||||
template <typename T>
|
||||
class atomic
|
||||
{
|
||||
class atomic {
|
||||
public:
|
||||
|
||||
#if defined(__PX4_POSIX)
|
||||
// Ensure that all operations are lock-free, so that 'atomic' can be used from
|
||||
// IRQ handlers. This might not be required everywhere though.
|
||||
static_assert(__atomic_always_lock_free(sizeof(T), 0), "atomic is not lock-free for the given type T");
|
||||
#endif // __PX4_POSIX
|
||||
#endif // __PX4_POSIX
|
||||
|
||||
atomic() = default;
|
||||
explicit atomic(T value) : _value(value) {}
|
||||
@@ -82,8 +79,7 @@ public:
|
||||
/**
|
||||
* Atomically read the current value
|
||||
*/
|
||||
inline T load() const
|
||||
{
|
||||
inline T load() const {
|
||||
#if defined(__PX4_NUTTX)
|
||||
|
||||
if (!__atomic_always_lock_free(sizeof(T), 0)) {
|
||||
@@ -93,7 +89,7 @@ public:
|
||||
return val;
|
||||
|
||||
} else
|
||||
#endif // __PX4_NUTTX
|
||||
#endif // __PX4_NUTTX
|
||||
{
|
||||
return __atomic_load_n(&_value, __ATOMIC_SEQ_CST);
|
||||
}
|
||||
@@ -102,8 +98,7 @@ public:
|
||||
/**
|
||||
* Atomically store a value
|
||||
*/
|
||||
inline void store(T value)
|
||||
{
|
||||
inline void store(T value) {
|
||||
#if defined(__PX4_NUTTX)
|
||||
|
||||
if (!__atomic_always_lock_free(sizeof(T), 0)) {
|
||||
@@ -112,7 +107,7 @@ public:
|
||||
leave_critical_section(flags);
|
||||
|
||||
} else
|
||||
#endif // __PX4_NUTTX
|
||||
#endif // __PX4_NUTTX
|
||||
{
|
||||
__atomic_store(&_value, &value, __ATOMIC_SEQ_CST);
|
||||
}
|
||||
@@ -122,8 +117,7 @@ public:
|
||||
* Atomically add a number and return the previous value.
|
||||
* @return value prior to the addition
|
||||
*/
|
||||
inline T fetch_add(T num)
|
||||
{
|
||||
inline T fetch_add(T num) {
|
||||
#if defined(__PX4_NUTTX)
|
||||
|
||||
if (!__atomic_always_lock_free(sizeof(T), 0)) {
|
||||
@@ -133,7 +127,7 @@ public:
|
||||
return ret;
|
||||
|
||||
} else
|
||||
#endif // __PX4_NUTTX
|
||||
#endif // __PX4_NUTTX
|
||||
{
|
||||
return __atomic_fetch_add(&_value, num, __ATOMIC_SEQ_CST);
|
||||
}
|
||||
@@ -143,8 +137,7 @@ public:
|
||||
* Atomically substract a number and return the previous value.
|
||||
* @return value prior to the substraction
|
||||
*/
|
||||
inline T fetch_sub(T num)
|
||||
{
|
||||
inline T fetch_sub(T num) {
|
||||
#if defined(__PX4_NUTTX)
|
||||
|
||||
if (!__atomic_always_lock_free(sizeof(T), 0)) {
|
||||
@@ -154,7 +147,7 @@ public:
|
||||
return ret;
|
||||
|
||||
} else
|
||||
#endif // __PX4_NUTTX
|
||||
#endif // __PX4_NUTTX
|
||||
{
|
||||
return __atomic_fetch_sub(&_value, num, __ATOMIC_SEQ_CST);
|
||||
}
|
||||
@@ -164,8 +157,7 @@ public:
|
||||
* Atomic AND with a number
|
||||
* @return value prior to the operation
|
||||
*/
|
||||
inline T fetch_and(T num)
|
||||
{
|
||||
inline T fetch_and(T num) {
|
||||
#if defined(__PX4_NUTTX)
|
||||
|
||||
if (!__atomic_always_lock_free(sizeof(T), 0)) {
|
||||
@@ -176,7 +168,7 @@ public:
|
||||
return val;
|
||||
|
||||
} else
|
||||
#endif // __PX4_NUTTX
|
||||
#endif // __PX4_NUTTX
|
||||
{
|
||||
return __atomic_fetch_and(&_value, num, __ATOMIC_SEQ_CST);
|
||||
}
|
||||
@@ -186,8 +178,7 @@ public:
|
||||
* Atomic XOR with a number
|
||||
* @return value prior to the operation
|
||||
*/
|
||||
inline T fetch_xor(T num)
|
||||
{
|
||||
inline T fetch_xor(T num) {
|
||||
#if defined(__PX4_NUTTX)
|
||||
|
||||
if (!__atomic_always_lock_free(sizeof(T), 0)) {
|
||||
@@ -198,7 +189,7 @@ public:
|
||||
return val;
|
||||
|
||||
} else
|
||||
#endif // __PX4_NUTTX
|
||||
#endif // __PX4_NUTTX
|
||||
{
|
||||
return __atomic_fetch_xor(&_value, num, __ATOMIC_SEQ_CST);
|
||||
}
|
||||
@@ -208,8 +199,7 @@ public:
|
||||
* Atomic OR with a number
|
||||
* @return value prior to the operation
|
||||
*/
|
||||
inline T fetch_or(T num)
|
||||
{
|
||||
inline T fetch_or(T num) {
|
||||
#if defined(__PX4_NUTTX)
|
||||
|
||||
if (!__atomic_always_lock_free(sizeof(T), 0)) {
|
||||
@@ -220,7 +210,7 @@ public:
|
||||
return val;
|
||||
|
||||
} else
|
||||
#endif // __PX4_NUTTX
|
||||
#endif // __PX4_NUTTX
|
||||
{
|
||||
return __atomic_fetch_or(&_value, num, __ATOMIC_SEQ_CST);
|
||||
}
|
||||
@@ -230,8 +220,7 @@ public:
|
||||
* Atomic NAND (~(_value & num)) with a number
|
||||
* @return value prior to the operation
|
||||
*/
|
||||
inline T fetch_nand(T num)
|
||||
{
|
||||
inline T fetch_nand(T num) {
|
||||
#if defined(__PX4_NUTTX)
|
||||
|
||||
if (!__atomic_always_lock_free(sizeof(T), 0)) {
|
||||
@@ -242,7 +231,7 @@ public:
|
||||
return ret;
|
||||
|
||||
} else
|
||||
#endif // __PX4_NUTTX
|
||||
#endif // __PX4_NUTTX
|
||||
{
|
||||
return __atomic_fetch_nand(&_value, num, __ATOMIC_SEQ_CST);
|
||||
}
|
||||
@@ -256,8 +245,7 @@ public:
|
||||
* contents of _value are written into *expected.
|
||||
* @return If desired is written into _value then true is returned
|
||||
*/
|
||||
inline bool compare_exchange(T *expected, T desired)
|
||||
{
|
||||
inline bool compare_exchange(T *expected, T desired) {
|
||||
#if defined(__PX4_NUTTX)
|
||||
|
||||
if (!__atomic_always_lock_free(sizeof(T), 0)) {
|
||||
@@ -275,14 +263,15 @@ public:
|
||||
}
|
||||
|
||||
} else
|
||||
#endif // __PX4_NUTTX
|
||||
#endif // __PX4_NUTTX
|
||||
{
|
||||
return __atomic_compare_exchange(&_value, expected, &desired, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
|
||||
return __atomic_compare_exchange(&_value, expected, &desired, false, __ATOMIC_SEQ_CST,
|
||||
__ATOMIC_SEQ_CST);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
T _value {};
|
||||
T _value{};
|
||||
};
|
||||
|
||||
using atomic_int = atomic<int>;
|
||||
|
||||
@@ -35,18 +35,14 @@
|
||||
|
||||
#include "atomic.h"
|
||||
|
||||
namespace px4
|
||||
{
|
||||
namespace px4 {
|
||||
|
||||
template <size_t N>
|
||||
class AtomicBitset
|
||||
{
|
||||
class AtomicBitset {
|
||||
public:
|
||||
|
||||
AtomicBitset() = default;
|
||||
|
||||
size_t count() const
|
||||
{
|
||||
size_t count() const {
|
||||
size_t total = 0;
|
||||
|
||||
for (const auto &x : _data) {
|
||||
@@ -63,13 +59,9 @@ public:
|
||||
|
||||
size_t size() const { return N; }
|
||||
|
||||
bool operator[](size_t position) const
|
||||
{
|
||||
return _data[array_index(position)].load() & element_mask(position);
|
||||
}
|
||||
bool operator[](size_t position) const { return _data[array_index(position)].load() & element_mask(position); }
|
||||
|
||||
void set(size_t pos, bool val = true)
|
||||
{
|
||||
void set(size_t pos, bool val = true) {
|
||||
const uint32_t bitmask = element_mask(pos);
|
||||
|
||||
if (val) {
|
||||
@@ -80,8 +72,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
void reset() {
|
||||
// set bits to false
|
||||
for (auto &d : _data) {
|
||||
d.store(0);
|
||||
@@ -90,8 +81,8 @@ public:
|
||||
|
||||
private:
|
||||
static constexpr uint8_t BITS_PER_ELEMENT = 32;
|
||||
static constexpr size_t ARRAY_SIZE = ((N % BITS_PER_ELEMENT) == 0) ? (N / BITS_PER_ELEMENT) :
|
||||
(N / BITS_PER_ELEMENT + 1);
|
||||
static constexpr size_t ARRAY_SIZE =
|
||||
((N % BITS_PER_ELEMENT) == 0) ? (N / BITS_PER_ELEMENT) : (N / BITS_PER_ELEMENT + 1);
|
||||
static constexpr size_t ALLOCATED_BITS = ARRAY_SIZE * BITS_PER_ELEMENT;
|
||||
|
||||
size_t array_index(size_t position) const { return position / BITS_PER_ELEMENT; }
|
||||
@@ -100,4 +91,4 @@ private:
|
||||
px4::atomic<uint32_t> _data[ARRAY_SIZE];
|
||||
};
|
||||
|
||||
} // namespace px4
|
||||
} // namespace px4
|
||||
|
||||
@@ -42,110 +42,69 @@
|
||||
|
||||
#if defined(__cplusplus) && (defined(__PX4_POSIX) || defined(__PX4_LINUX))
|
||||
|
||||
#include<type_traits>
|
||||
#include <type_traits>
|
||||
|
||||
template<typename E>
|
||||
template <typename E>
|
||||
struct enable_bitmask_operators {
|
||||
static const bool enable = false;
|
||||
};
|
||||
|
||||
namespace px4
|
||||
{
|
||||
namespace px4 {
|
||||
|
||||
#define ENABLE_BIT_OPERATORS(E) \
|
||||
template<> \
|
||||
struct enable_bitmask_operators<E> \
|
||||
{ \
|
||||
#define ENABLE_BIT_OPERATORS(E) \
|
||||
template <> \
|
||||
struct enable_bitmask_operators<E> { \
|
||||
static const bool enable = true; \
|
||||
};
|
||||
|
||||
template<typename E>
|
||||
typename std::enable_if<enable_bitmask_operators<E>::enable, E>::type
|
||||
operator==(E lhs, E rhs)
|
||||
{
|
||||
template <typename E>
|
||||
typename std::enable_if<enable_bitmask_operators<E>::enable, E>::type operator==(E lhs, E rhs) {
|
||||
typedef typename std::underlying_type<E>::type underlying;
|
||||
return static_cast<E>(
|
||||
static_cast<underlying>(lhs) ==
|
||||
static_cast<underlying>(rhs)
|
||||
);
|
||||
return static_cast<E>(static_cast<underlying>(lhs) == static_cast<underlying>(rhs));
|
||||
}
|
||||
|
||||
template<typename E>
|
||||
typename std::enable_if<enable_bitmask_operators<E>::enable, E>::type
|
||||
operator~(E lhs)
|
||||
{
|
||||
template <typename E>
|
||||
typename std::enable_if<enable_bitmask_operators<E>::enable, E>::type operator~(E lhs) {
|
||||
typedef typename std::underlying_type<E>::type underlying;
|
||||
return static_cast<E>(
|
||||
~static_cast<underlying>(lhs)
|
||||
);
|
||||
return static_cast<E>(~static_cast<underlying>(lhs));
|
||||
}
|
||||
|
||||
template<typename E>
|
||||
typename std::enable_if<enable_bitmask_operators<E>::enable, E>::type
|
||||
operator|(E lhs, E rhs)
|
||||
{
|
||||
template <typename E>
|
||||
typename std::enable_if<enable_bitmask_operators<E>::enable, E>::type operator|(E lhs, E rhs) {
|
||||
typedef typename std::underlying_type<E>::type underlying;
|
||||
return static_cast<E>(
|
||||
static_cast<underlying>(lhs) |
|
||||
static_cast<underlying>(rhs)
|
||||
);
|
||||
return static_cast<E>(static_cast<underlying>(lhs) | static_cast<underlying>(rhs));
|
||||
}
|
||||
|
||||
template<typename E>
|
||||
typename std::enable_if<enable_bitmask_operators<E>::enable, E &>::type
|
||||
operator|=(E &lhs, E rhs)
|
||||
{
|
||||
template <typename E>
|
||||
typename std::enable_if<enable_bitmask_operators<E>::enable, E &>::type operator|=(E &lhs, E rhs) {
|
||||
typedef typename std::underlying_type<E>::type underlying;
|
||||
lhs = static_cast<E>(
|
||||
static_cast<underlying>(lhs) |
|
||||
static_cast<underlying>(rhs)
|
||||
);
|
||||
lhs = static_cast<E>(static_cast<underlying>(lhs) | static_cast<underlying>(rhs));
|
||||
return lhs;
|
||||
}
|
||||
|
||||
template<typename E>
|
||||
typename std::enable_if<enable_bitmask_operators<E>::enable, E>::type
|
||||
operator&(E lhs, E rhs)
|
||||
{
|
||||
template <typename E>
|
||||
typename std::enable_if<enable_bitmask_operators<E>::enable, E>::type operator&(E lhs, E rhs) {
|
||||
typedef typename std::underlying_type<E>::type underlying;
|
||||
return static_cast<E>(
|
||||
static_cast<underlying>(lhs) &
|
||||
static_cast<underlying>(rhs)
|
||||
);
|
||||
return static_cast<E>(static_cast<underlying>(lhs) & static_cast<underlying>(rhs));
|
||||
}
|
||||
|
||||
template<typename E>
|
||||
typename std::enable_if<enable_bitmask_operators<E>::enable, E &>::type
|
||||
operator&=(E &lhs, E rhs)
|
||||
{
|
||||
template <typename E>
|
||||
typename std::enable_if<enable_bitmask_operators<E>::enable, E &>::type operator&=(E &lhs, E rhs) {
|
||||
typedef typename std::underlying_type<E>::type underlying;
|
||||
lhs = static_cast<E>(
|
||||
static_cast<underlying>(lhs) &
|
||||
static_cast<underlying>(rhs)
|
||||
);
|
||||
lhs = static_cast<E>(static_cast<underlying>(lhs) & static_cast<underlying>(rhs));
|
||||
return lhs;
|
||||
}
|
||||
|
||||
template<typename E>
|
||||
typename std::enable_if<enable_bitmask_operators<E>::enable, E>::type
|
||||
operator^(E lhs, E rhs)
|
||||
{
|
||||
template <typename E>
|
||||
typename std::enable_if<enable_bitmask_operators<E>::enable, E>::type operator^(E lhs, E rhs) {
|
||||
typedef typename std::underlying_type<E>::type underlying;
|
||||
return static_cast<E>(
|
||||
static_cast<underlying>(lhs) ^
|
||||
static_cast<underlying>(rhs)
|
||||
);
|
||||
return static_cast<E>(static_cast<underlying>(lhs) ^ static_cast<underlying>(rhs));
|
||||
}
|
||||
|
||||
template<typename E>
|
||||
typename std::enable_if<enable_bitmask_operators<E>::enable, E &>::type
|
||||
operator^=(E &lhs, E rhs)
|
||||
{
|
||||
template <typename E>
|
||||
typename std::enable_if<enable_bitmask_operators<E>::enable, E &>::type operator^=(E &lhs, E rhs) {
|
||||
typedef typename std::underlying_type<E>::type underlying;
|
||||
lhs = static_cast<E>(
|
||||
static_cast<underlying>(lhs) ^
|
||||
static_cast<underlying>(rhs)
|
||||
);
|
||||
lhs = static_cast<E>(static_cast<underlying>(lhs) ^ static_cast<underlying>(rhs));
|
||||
return lhs;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
/************************************************************************************
|
||||
* Definitions
|
||||
@@ -57,19 +57,23 @@
|
||||
*/
|
||||
|
||||
#if defined(BOARD_I2C_BUS_CLOCK_INIT)
|
||||
# define PX4_I2C_BUS_CLOCK_INIT BOARD_I2C_BUS_CLOCK_INIT
|
||||
#define PX4_I2C_BUS_CLOCK_INIT BOARD_I2C_BUS_CLOCK_INIT
|
||||
#else
|
||||
# if (PX4_NUMBER_I2C_BUSES) == 1
|
||||
# define PX4_I2C_BUS_CLOCK_INIT {100000}
|
||||
# elif (PX4_NUMBER_I2C_BUSES) == 2
|
||||
# define PX4_I2C_BUS_CLOCK_INIT {100000, 100000}
|
||||
# elif (PX4_NUMBER_I2C_BUSES) == 3
|
||||
# define PX4_I2C_BUS_CLOCK_INIT {100000, 100000, 100000}
|
||||
# elif (PX4_NUMBER_I2C_BUSES) == 4
|
||||
# define PX4_I2C_BUS_CLOCK_INIT {100000, 100000, 100000, 100000}
|
||||
# else
|
||||
# error PX4_NUMBER_I2C_BUSES not supported
|
||||
# endif
|
||||
#if (PX4_NUMBER_I2C_BUSES) == 1
|
||||
#define PX4_I2C_BUS_CLOCK_INIT \
|
||||
{ 100000 }
|
||||
#elif (PX4_NUMBER_I2C_BUSES) == 2
|
||||
#define PX4_I2C_BUS_CLOCK_INIT \
|
||||
{ 100000, 100000 }
|
||||
#elif (PX4_NUMBER_I2C_BUSES) == 3
|
||||
#define PX4_I2C_BUS_CLOCK_INIT \
|
||||
{ 100000, 100000, 100000 }
|
||||
#elif (PX4_NUMBER_I2C_BUSES) == 4
|
||||
#define PX4_I2C_BUS_CLOCK_INIT \
|
||||
{ 100000, 100000, 100000, 100000 }
|
||||
#else
|
||||
#error PX4_NUMBER_I2C_BUSES not supported
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_SPI_BUS_MAX_BUS_ITEMS
|
||||
@@ -92,25 +96,25 @@
|
||||
* defaults
|
||||
*/
|
||||
#if !defined(ADC_V5_V_FULL_SCALE)
|
||||
#define ADC_V5_V_FULL_SCALE (6.6f) // 5 volt Rail full scale voltage
|
||||
#define ADC_V5_V_FULL_SCALE (6.6f) // 5 volt Rail full scale voltage
|
||||
#endif
|
||||
#if !defined(ADC_V5_SCALE)
|
||||
#define ADC_V5_SCALE (2.0f) // The scale factor defined by HW's resistive divider (Rt+Rb)/ Rb
|
||||
#define ADC_V5_SCALE (2.0f) // The scale factor defined by HW's resistive divider (Rt+Rb)/ Rb
|
||||
#endif
|
||||
|
||||
#if !defined(ADC_3V3_V_FULL_SCALE)
|
||||
#define ADC_3V3_V_FULL_SCALE (3.6f) // 3.3V volt Rail full scale voltage
|
||||
#define ADC_3V3_V_FULL_SCALE (3.6f) // 3.3V volt Rail full scale voltage
|
||||
#endif
|
||||
#if !defined(ADC_3V3_SCALE)
|
||||
#define ADC_3V3_SCALE (2.0f) // The scale factor defined by HW's resistive divider (Rt+Rb)/ Rb
|
||||
#define ADC_3V3_SCALE (2.0f) // The scale factor defined by HW's resistive divider (Rt+Rb)/ Rb
|
||||
#endif
|
||||
|
||||
#ifndef BOARD_ADC_POS_REF_V
|
||||
#define BOARD_ADC_POS_REF_V (3.3f) // Default reference voltage for every channels
|
||||
#define BOARD_ADC_POS_REF_V (3.3f) // Default reference voltage for every channels
|
||||
#endif
|
||||
|
||||
#if !defined(ADC_DP_V_DIV) // Analog differential pressure (analog airspeed sensor)
|
||||
#define ADC_DP_V_DIV (2.0f) // The scale factor defined by HW's resistive divider (Rt+Rb)/ Rb
|
||||
#if !defined(ADC_DP_V_DIV) // Analog differential pressure (analog airspeed sensor)
|
||||
#define ADC_DP_V_DIV (2.0f) // The scale factor defined by HW's resistive divider (Rt+Rb)/ Rb
|
||||
#endif
|
||||
|
||||
/* Provide define for Bricks and Battery */
|
||||
@@ -118,7 +122,7 @@
|
||||
/* Define the default maximum voltage resulting from the bias on ADC termination */
|
||||
|
||||
#if !defined(BOARD_ADC_OPEN_CIRCUIT_V)
|
||||
# define BOARD_ADC_OPEN_CIRCUIT_V (1.5f)
|
||||
#define BOARD_ADC_OPEN_CIRCUIT_V (1.5f)
|
||||
#endif
|
||||
|
||||
/* Define the default Under voltage Window on the LTC4417 as set by resistors on the
|
||||
@@ -126,70 +130,98 @@
|
||||
*/
|
||||
|
||||
#if !defined(BOARD_VALID_UV)
|
||||
# define BOARD_VALID_UV (3.7f)
|
||||
#define BOARD_VALID_UV (3.7f)
|
||||
#endif
|
||||
|
||||
/* Legacy default */
|
||||
|
||||
#if !defined(BOARD_NUMBER_BRICKS)
|
||||
# define BOARD_NUMBER_BRICKS 1
|
||||
# if !defined(BOARD_ADC_BRICK_VALID)
|
||||
# define BOARD_ADC_BRICK_VALID (1)
|
||||
# endif
|
||||
#define BOARD_NUMBER_BRICKS 1
|
||||
#if !defined(BOARD_ADC_BRICK_VALID)
|
||||
#define BOARD_ADC_BRICK_VALID (1)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if BOARD_NUMBER_BRICKS == 0
|
||||
/* allow SITL to disable all bricks */
|
||||
#elif BOARD_NUMBER_BRICKS == 1
|
||||
# define BOARD_BATT_V_LIST {ADC_BATTERY_VOLTAGE_CHANNEL}
|
||||
# define BOARD_BATT_I_LIST {ADC_BATTERY_CURRENT_CHANNEL}
|
||||
# define BOARD_BRICK_VALID_LIST {BOARD_ADC_BRICK_VALID}
|
||||
#define BOARD_BATT_V_LIST \
|
||||
{ ADC_BATTERY_VOLTAGE_CHANNEL }
|
||||
#define BOARD_BATT_I_LIST \
|
||||
{ ADC_BATTERY_CURRENT_CHANNEL }
|
||||
#define BOARD_BRICK_VALID_LIST \
|
||||
{ BOARD_ADC_BRICK_VALID }
|
||||
#elif BOARD_NUMBER_BRICKS == 2
|
||||
# if defined(BOARD_NUMBER_DIGITAL_BRICKS)
|
||||
# define BOARD_BATT_V_LIST {-1, -1}
|
||||
# define BOARD_BATT_I_LIST {-1, -1}
|
||||
# else
|
||||
# define BOARD_BATT_V_LIST {ADC_BATTERY1_VOLTAGE_CHANNEL, ADC_BATTERY2_VOLTAGE_CHANNEL}
|
||||
# define BOARD_BATT_I_LIST {ADC_BATTERY1_CURRENT_CHANNEL, ADC_BATTERY2_CURRENT_CHANNEL}
|
||||
# endif
|
||||
# define BOARD_BRICK_VALID_LIST {BOARD_ADC_BRICK1_VALID, BOARD_ADC_BRICK2_VALID}
|
||||
#elif BOARD_NUMBER_BRICKS == 3
|
||||
# define BOARD_BATT_V_LIST {ADC_BATTERY1_VOLTAGE_CHANNEL, ADC_BATTERY2_VOLTAGE_CHANNEL, ADC_BATTERY3_VOLTAGE_CHANNEL}
|
||||
# define BOARD_BATT_I_LIST {ADC_BATTERY1_CURRENT_CHANNEL, ADC_BATTERY2_CURRENT_CHANNEL, ADC_BATTERY3_CURRENT_CHANNEL}
|
||||
# define BOARD_BRICK_VALID_LIST {BOARD_ADC_BRICK1_VALID, BOARD_ADC_BRICK2_VALID, BOARD_ADC_BRICK3_VALID}
|
||||
#elif BOARD_NUMBER_BRICKS == 4
|
||||
# define BOARD_BATT_V_LIST {ADC_BATTERY1_VOLTAGE_CHANNEL, ADC_BATTERY2_VOLTAGE_CHANNEL, ADC_BATTERY3_VOLTAGE_CHANNEL, ADC_BATTERY4_VOLTAGE_CHANNEL}
|
||||
# define BOARD_BATT_I_LIST {ADC_BATTERY1_CURRENT_CHANNEL, ADC_BATTERY2_CURRENT_CHANNEL, ADC_BATTERY3_CURRENT_CHANNEL, ADC_BATTERY4_CURRENT_CHANNEL}
|
||||
# define BOARD_BRICK_VALID_LIST {BOARD_ADC_BRICK1_VALID, BOARD_ADC_BRICK2_VALID, BOARD_ADC_BRICK3_VALID, BOARD_ADC_BRICK4_VALID}
|
||||
#if defined(BOARD_NUMBER_DIGITAL_BRICKS)
|
||||
#define BOARD_BATT_V_LIST \
|
||||
{ -1, -1 }
|
||||
#define BOARD_BATT_I_LIST \
|
||||
{ -1, -1 }
|
||||
#else
|
||||
# error Unsuported BOARD_NUMBER_BRICKS number.
|
||||
#define BOARD_BATT_V_LIST \
|
||||
{ ADC_BATTERY1_VOLTAGE_CHANNEL, ADC_BATTERY2_VOLTAGE_CHANNEL }
|
||||
#define BOARD_BATT_I_LIST \
|
||||
{ ADC_BATTERY1_CURRENT_CHANNEL, ADC_BATTERY2_CURRENT_CHANNEL }
|
||||
#endif
|
||||
#define BOARD_BRICK_VALID_LIST \
|
||||
{ BOARD_ADC_BRICK1_VALID, BOARD_ADC_BRICK2_VALID }
|
||||
#elif BOARD_NUMBER_BRICKS == 3
|
||||
#define BOARD_BATT_V_LIST \
|
||||
{ ADC_BATTERY1_VOLTAGE_CHANNEL, ADC_BATTERY2_VOLTAGE_CHANNEL, ADC_BATTERY3_VOLTAGE_CHANNEL }
|
||||
#define BOARD_BATT_I_LIST \
|
||||
{ ADC_BATTERY1_CURRENT_CHANNEL, ADC_BATTERY2_CURRENT_CHANNEL, ADC_BATTERY3_CURRENT_CHANNEL }
|
||||
#define BOARD_BRICK_VALID_LIST \
|
||||
{ BOARD_ADC_BRICK1_VALID, BOARD_ADC_BRICK2_VALID, BOARD_ADC_BRICK3_VALID }
|
||||
#elif BOARD_NUMBER_BRICKS == 4
|
||||
#define BOARD_BATT_V_LIST \
|
||||
{ \
|
||||
ADC_BATTERY1_VOLTAGE_CHANNEL, ADC_BATTERY2_VOLTAGE_CHANNEL, ADC_BATTERY3_VOLTAGE_CHANNEL, \
|
||||
ADC_BATTERY4_VOLTAGE_CHANNEL \
|
||||
}
|
||||
#define BOARD_BATT_I_LIST \
|
||||
{ \
|
||||
ADC_BATTERY1_CURRENT_CHANNEL, ADC_BATTERY2_CURRENT_CHANNEL, ADC_BATTERY3_CURRENT_CHANNEL, \
|
||||
ADC_BATTERY4_CURRENT_CHANNEL \
|
||||
}
|
||||
#define BOARD_BRICK_VALID_LIST \
|
||||
{ BOARD_ADC_BRICK1_VALID, BOARD_ADC_BRICK2_VALID, BOARD_ADC_BRICK3_VALID, BOARD_ADC_BRICK4_VALID }
|
||||
#else
|
||||
#error Unsuported BOARD_NUMBER_BRICKS number.
|
||||
#endif
|
||||
|
||||
/* Choose the source for ADC_SCALED_V5_SENSE */
|
||||
#if defined(ADC_5V_RAIL_SENSE)
|
||||
#define ADC_SCALED_V5_SENSE ADC_5V_RAIL_SENSE
|
||||
#else
|
||||
# if defined(ADC_SCALED_V5_CHANNEL)
|
||||
# define ADC_SCALED_V5_SENSE ADC_SCALED_V5_CHANNEL
|
||||
# endif
|
||||
#if defined(ADC_SCALED_V5_CHANNEL)
|
||||
#define ADC_SCALED_V5_SENSE ADC_SCALED_V5_CHANNEL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Define the source for ADC_SCALED_V3V3_SENSORS_SENSE */
|
||||
|
||||
#if defined(ADC_SCALED_VDD_3V3_SENSORS_CHANNEL)
|
||||
# define ADC_SCALED_V3V3_SENSORS_SENSE { ADC_SCALED_VDD_3V3_SENSORS_CHANNEL }
|
||||
# define ADC_SCALED_V3V3_SENSORS_COUNT 1
|
||||
#define ADC_SCALED_V3V3_SENSORS_SENSE \
|
||||
{ ADC_SCALED_VDD_3V3_SENSORS_CHANNEL }
|
||||
#define ADC_SCALED_V3V3_SENSORS_COUNT 1
|
||||
#elif defined(ADC_SCALED_VDD_3V3_SENSORS4_CHANNEL)
|
||||
# define ADC_SCALED_V3V3_SENSORS_SENSE { ADC_SCALED_VDD_3V3_SENSORS1_CHANNEL, ADC_SCALED_VDD_3V3_SENSORS2_CHANNEL, \
|
||||
ADC_SCALED_VDD_3V3_SENSORS3_CHANNEL, ADC_SCALED_VDD_3V3_SENSORS4_CHANNEL }
|
||||
# define ADC_SCALED_V3V3_SENSORS_COUNT 4
|
||||
#define ADC_SCALED_V3V3_SENSORS_SENSE \
|
||||
{ \
|
||||
ADC_SCALED_VDD_3V3_SENSORS1_CHANNEL, ADC_SCALED_VDD_3V3_SENSORS2_CHANNEL, \
|
||||
ADC_SCALED_VDD_3V3_SENSORS3_CHANNEL, ADC_SCALED_VDD_3V3_SENSORS4_CHANNEL \
|
||||
}
|
||||
#define ADC_SCALED_V3V3_SENSORS_COUNT 4
|
||||
#elif defined(ADC_SCALED_VDD_3V3_SENSORS3_CHANNEL)
|
||||
# define ADC_SCALED_V3V3_SENSORS_SENSE { ADC_SCALED_VDD_3V3_SENSORS1_CHANNEL, ADC_SCALED_VDD_3V3_SENSORS2_CHANNEL, \
|
||||
ADC_SCALED_VDD_3V3_SENSORS3_CHANNEL }
|
||||
# define ADC_SCALED_V3V3_SENSORS_COUNT 3
|
||||
#define ADC_SCALED_V3V3_SENSORS_SENSE \
|
||||
{ \
|
||||
ADC_SCALED_VDD_3V3_SENSORS1_CHANNEL, ADC_SCALED_VDD_3V3_SENSORS2_CHANNEL, \
|
||||
ADC_SCALED_VDD_3V3_SENSORS3_CHANNEL \
|
||||
}
|
||||
#define ADC_SCALED_V3V3_SENSORS_COUNT 3
|
||||
#elif defined(ADC_SCALED_VDD_3V3_SENSORS2_CHANNEL)
|
||||
# define ADC_SCALED_V3V3_SENSORS_SENSE { ADC_SCALED_VDD_3V3_SENSORS1_CHANNEL, ADC_SCALED_VDD_3V3_SENSORS2_CHANNEL }
|
||||
# define ADC_SCALED_V3V3_SENSORS_COUNT 2
|
||||
#define ADC_SCALED_V3V3_SENSORS_SENSE \
|
||||
{ ADC_SCALED_VDD_3V3_SENSORS1_CHANNEL, ADC_SCALED_VDD_3V3_SENSORS2_CHANNEL }
|
||||
#define ADC_SCALED_V3V3_SENSORS_COUNT 2
|
||||
#endif
|
||||
|
||||
/* Define an overridable default of 0.0f V for batery v div
|
||||
@@ -221,78 +253,79 @@
|
||||
* We then publish the logical BOARD_USES_PX4IO
|
||||
*/
|
||||
#if defined(BOARD_USES_PX4IO_VERSION)
|
||||
# define BOARD_USES_PX4IO 1
|
||||
# if defined(BOARD_HAS_STATIC_MANIFEST) && BOARD_HAS_STATIC_MANIFEST == 1
|
||||
# define PX4_MFT_HW_SUPPORTED_PX4_MFT_PX4IO 1
|
||||
# endif
|
||||
#define BOARD_USES_PX4IO 1
|
||||
#if defined(BOARD_HAS_STATIC_MANIFEST) && BOARD_HAS_STATIC_MANIFEST == 1
|
||||
#define PX4_MFT_HW_SUPPORTED_PX4_MFT_PX4IO 1
|
||||
#endif
|
||||
/* Allow a board_config to override the PX4IO FW search paths */
|
||||
# if defined(BOARD_PX4IO_FW_SEARCH_PATHS)
|
||||
# define PX4IO_FW_SEARCH_PATHS BOARD_PX4IO_FW_SEARCH_PATHS
|
||||
# else
|
||||
#if defined(BOARD_PX4IO_FW_SEARCH_PATHS)
|
||||
#define PX4IO_FW_SEARCH_PATHS BOARD_PX4IO_FW_SEARCH_PATHS
|
||||
#else
|
||||
/* Use PX4IO FW search paths defaults based on version */
|
||||
# if BOARD_USES_PX4IO_VERSION == 2
|
||||
# define PX4IO_FW_SEARCH_PATHS {"/etc/extras/px4_io-v2_default.bin","/fs/microsd/px4_io-v2_default.bin", "/fs/microsd/px4io2.bin", nullptr }
|
||||
# endif
|
||||
# endif
|
||||
#if BOARD_USES_PX4IO_VERSION == 2
|
||||
#define PX4IO_FW_SEARCH_PATHS \
|
||||
{ "/etc/extras/px4_io-v2_default.bin", "/fs/microsd/px4_io-v2_default.bin", "/fs/microsd/px4io2.bin", nullptr }
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Provide an overridable default nop
|
||||
* for BOARD_EEPROM_WP_CTRL
|
||||
*/
|
||||
#if !defined(BOARD_EEPROM_WP_CTRL)
|
||||
# define BOARD_EEPROM_WP_CTRL(on_true)
|
||||
#define BOARD_EEPROM_WP_CTRL(on_true)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Defined when a supports version and type API.
|
||||
*/
|
||||
#if defined(BOARD_HAS_SIMPLE_HW_VERSIONING)
|
||||
# define BOARD_HAS_VERSIONING 1
|
||||
# define HW_VER_SIMPLE(s) 0x90000+(s)
|
||||
#define BOARD_HAS_VERSIONING 1
|
||||
#define HW_VER_SIMPLE(s) 0x90000 + (s)
|
||||
|
||||
# define HW_VER_FMUV2 HW_VER_SIMPLE(HW_VER_FMUV2_STATE)
|
||||
# define HW_VER_FMUV3 HW_VER_SIMPLE(HW_VER_FMUV3_STATE)
|
||||
# define HW_VER_FMUV2MINI HW_VER_SIMPLE(HW_VER_FMUV2MINI_STATE)
|
||||
# define HW_VER_FMUV2X HW_VER_SIMPLE(HW_VER_FMUV2X_STATE)
|
||||
#define HW_VER_FMUV2 HW_VER_SIMPLE(HW_VER_FMUV2_STATE)
|
||||
#define HW_VER_FMUV3 HW_VER_SIMPLE(HW_VER_FMUV3_STATE)
|
||||
#define HW_VER_FMUV2MINI HW_VER_SIMPLE(HW_VER_FMUV2MINI_STATE)
|
||||
#define HW_VER_FMUV2X HW_VER_SIMPLE(HW_VER_FMUV2X_STATE)
|
||||
#endif
|
||||
|
||||
#if defined(BOARD_HAS_HW_VERSIONING)
|
||||
# define BOARD_HAS_VERSIONING 1
|
||||
# define HW_VER_REV(v,r) ((uint32_t)((v) & 0xff) << 8) | ((uint32_t)(r) & 0xff)
|
||||
#define BOARD_HAS_VERSIONING 1
|
||||
#define HW_VER_REV(v, r) ((uint32_t)((v)&0xff) << 8) | ((uint32_t)(r)&0xff)
|
||||
#endif
|
||||
|
||||
/* Default LED logical to color mapping */
|
||||
|
||||
#if defined(BOARD_OVERLOAD_LED)
|
||||
# define BOARD_OVERLOAD_LED_TOGGLE() led_toggle(BOARD_OVERLOAD_LED)
|
||||
# define BOARD_OVERLOAD_LED_OFF() led_off(BOARD_OVERLOAD_LED)
|
||||
#define BOARD_OVERLOAD_LED_TOGGLE() led_toggle(BOARD_OVERLOAD_LED)
|
||||
#define BOARD_OVERLOAD_LED_OFF() led_off(BOARD_OVERLOAD_LED)
|
||||
#else
|
||||
# define BOARD_OVERLOAD_LED_TOGGLE()
|
||||
# define BOARD_OVERLOAD_LED_OFF()
|
||||
#define BOARD_OVERLOAD_LED_TOGGLE()
|
||||
#define BOARD_OVERLOAD_LED_OFF()
|
||||
#endif
|
||||
|
||||
#if defined(BOARD_HAS_CONTROL_STATUS_LEDS)
|
||||
|
||||
# if defined(BOARD_ARMED_LED)
|
||||
# define BOARD_ARMED_LED_TOGGLE() led_toggle(BOARD_ARMED_LED)
|
||||
# define BOARD_ARMED_LED_OFF() led_off(BOARD_ARMED_LED)
|
||||
# define BOARD_ARMED_LED_ON() led_on(BOARD_ARMED_LED)
|
||||
# else
|
||||
# define BOARD_ARMED_LED_TOGGLE()
|
||||
# define BOARD_ARMED_LED_OFF()
|
||||
# define BOARD_ARMED_LED_ON()
|
||||
# endif
|
||||
#if defined(BOARD_ARMED_LED)
|
||||
#define BOARD_ARMED_LED_TOGGLE() led_toggle(BOARD_ARMED_LED)
|
||||
#define BOARD_ARMED_LED_OFF() led_off(BOARD_ARMED_LED)
|
||||
#define BOARD_ARMED_LED_ON() led_on(BOARD_ARMED_LED)
|
||||
#else
|
||||
#define BOARD_ARMED_LED_TOGGLE()
|
||||
#define BOARD_ARMED_LED_OFF()
|
||||
#define BOARD_ARMED_LED_ON()
|
||||
#endif
|
||||
|
||||
# if defined(BOARD_ARMED_STATE_LED)
|
||||
# define BOARD_ARMED_STATE_LED_TOGGLE() led_toggle(BOARD_ARMED_STATE_LED)
|
||||
# define BOARD_ARMED_STATE_LED_OFF() led_off(BOARD_ARMED_STATE_LED)
|
||||
# define BOARD_ARMED_STATE_LED_ON() led_on(BOARD_ARMED_STATE_LED)
|
||||
# else
|
||||
# define BOARD_ARMED_STATE_LED_TOGGLE()
|
||||
# define BOARD_ARMED_STATE_LED_OFF()
|
||||
# define BOARD_ARMED_STATE_LED_ON()
|
||||
# endif
|
||||
#endif //
|
||||
#if defined(BOARD_ARMED_STATE_LED)
|
||||
#define BOARD_ARMED_STATE_LED_TOGGLE() led_toggle(BOARD_ARMED_STATE_LED)
|
||||
#define BOARD_ARMED_STATE_LED_OFF() led_off(BOARD_ARMED_STATE_LED)
|
||||
#define BOARD_ARMED_STATE_LED_ON() led_on(BOARD_ARMED_STATE_LED)
|
||||
#else
|
||||
#define BOARD_ARMED_STATE_LED_TOGGLE()
|
||||
#define BOARD_ARMED_STATE_LED_OFF()
|
||||
#define BOARD_ARMED_STATE_LED_ON()
|
||||
#endif
|
||||
#endif //
|
||||
|
||||
/************************************************************************************
|
||||
* Public Data
|
||||
@@ -300,14 +333,14 @@
|
||||
|
||||
/* board power button state notification */
|
||||
typedef enum board_power_button_state_notification_e {
|
||||
PWR_BUTTON_IDEL, /* Button went up without meeting shutdown button down time */
|
||||
PWR_BUTTON_DOWN, /* Button went Down */
|
||||
PWR_BUTTON_UP, /* Button went Up */
|
||||
PWR_BUTTON_REQUEST_SHUT_DOWN, /* Button went up after meeting shutdown button down time */
|
||||
PWR_BUTTON_IDEL, /* Button went up without meeting shutdown button down time */
|
||||
PWR_BUTTON_DOWN, /* Button went Down */
|
||||
PWR_BUTTON_UP, /* Button went Up */
|
||||
PWR_BUTTON_REQUEST_SHUT_DOWN, /* Button went up after meeting shutdown button down time */
|
||||
|
||||
PWR_BUTTON_RESPONSE_SHUT_DOWN_PENDING, /* Response from call back board code does nothing the
|
||||
* expectation is that board_shutdown will be called.
|
||||
*/
|
||||
* expectation is that board_shutdown will be called.
|
||||
*/
|
||||
PWR_BUTTON_RESPONSE_SHUT_DOWN_NOW, /* Response from call back board code does shutdown now. */
|
||||
} board_power_button_state_notification_e;
|
||||
|
||||
@@ -319,33 +352,31 @@ typedef int (*power_button_state_notification_t)(board_power_button_state_notifi
|
||||
* prepended to a padded Soc ID.
|
||||
*/
|
||||
|
||||
|
||||
typedef enum PX4_SOC_ARCH_ID_t {
|
||||
|
||||
PX4_SOC_ARCH_ID_UNUSED = 0x0000,
|
||||
PX4_SOC_ARCH_ID_UNUSED = 0x0000,
|
||||
|
||||
PX4_SOC_ARCH_ID_STM32F4 = 0x0001,
|
||||
PX4_SOC_ARCH_ID_STM32F7 = 0x0002,
|
||||
PX4_SOC_ARCH_ID_KINETISK66 = 0x0003,
|
||||
PX4_SOC_ARCH_ID_SAMV7 = 0x0004,
|
||||
PX4_SOC_ARCH_ID_NXPIMXRT1062 = 0x0005,
|
||||
PX4_SOC_ARCH_ID_STM32F4 = 0x0001,
|
||||
PX4_SOC_ARCH_ID_STM32F7 = 0x0002,
|
||||
PX4_SOC_ARCH_ID_KINETISK66 = 0x0003,
|
||||
PX4_SOC_ARCH_ID_SAMV7 = 0x0004,
|
||||
PX4_SOC_ARCH_ID_NXPIMXRT1062 = 0x0005,
|
||||
|
||||
PX4_SOC_ARCH_ID_STM32H7 = 0x0006,
|
||||
PX4_SOC_ARCH_ID_STM32H7 = 0x0006,
|
||||
|
||||
PX4_SOC_ARCH_ID_NXPS32K146 = 0x0007,
|
||||
PX4_SOC_ARCH_ID_NXPS32K146 = 0x0007,
|
||||
|
||||
PX4_SOC_ARCH_ID_EAGLE = 0x1001,
|
||||
PX4_SOC_ARCH_ID_QURT = 0x1002,
|
||||
PX4_SOC_ARCH_ID_EAGLE = 0x1001,
|
||||
PX4_SOC_ARCH_ID_QURT = 0x1002,
|
||||
|
||||
PX4_SOC_ARCH_ID_RPI = 0x1004,
|
||||
PX4_SOC_ARCH_ID_SIM = 0x1005,
|
||||
PX4_SOC_ARCH_ID_SITL = 0x1006,
|
||||
PX4_SOC_ARCH_ID_RPI = 0x1004,
|
||||
PX4_SOC_ARCH_ID_SIM = 0x1005,
|
||||
PX4_SOC_ARCH_ID_SITL = 0x1006,
|
||||
|
||||
PX4_SOC_ARCH_ID_BBBLUE = 0x1008,
|
||||
PX4_SOC_ARCH_ID_BBBLUE = 0x1008,
|
||||
|
||||
} PX4_SOC_ARCH_ID_t;
|
||||
|
||||
|
||||
/* UUID
|
||||
*
|
||||
* Define the types used for board UUID, MFG UID and PX4 GUID
|
||||
@@ -386,8 +417,8 @@ typedef enum PX4_SOC_ARCH_ID_t {
|
||||
*/
|
||||
|
||||
/* Define the PX4 Globally unique ID (GUID) length and format size */
|
||||
#define PX4_GUID_BYTE_LENGTH 18
|
||||
#define PX4_GUID_FORMAT_SIZE ((2*PX4_GUID_BYTE_LENGTH)+1)
|
||||
#define PX4_GUID_BYTE_LENGTH 18
|
||||
#define PX4_GUID_FORMAT_SIZE ((2 * PX4_GUID_BYTE_LENGTH) + 1)
|
||||
|
||||
/* DEPRICATED as of 1.7.0 A type suitable for defining the 8 bit format of the CPU UUID */
|
||||
typedef uint8_t uuid_byte_t[PX4_CPU_UUID_BYTE_LENGTH];
|
||||
@@ -411,7 +442,6 @@ typedef uint8_t px4_guid_t[PX4_GUID_BYTE_LENGTH];
|
||||
************************************************************************************/
|
||||
__BEGIN_DECLS
|
||||
|
||||
|
||||
/************************************************************************************
|
||||
* Name: board_rc_singlewire
|
||||
*
|
||||
@@ -474,9 +504,11 @@ static inline bool board_rc_swap_rxtx(const char *device) { return false; }
|
||||
************************************************************************************/
|
||||
|
||||
#ifdef RC_INVERT_INPUT
|
||||
static inline bool board_rc_invert_input(const char *device, bool invert)
|
||||
{
|
||||
if (strcmp(device, RC_SERIAL_PORT) == 0) { RC_INVERT_INPUT(invert); return true; }
|
||||
static inline bool board_rc_invert_input(const char *device, bool invert) {
|
||||
if (strcmp(device, RC_SERIAL_PORT) == 0) {
|
||||
RC_INVERT_INPUT(invert);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -503,14 +535,13 @@ static inline bool board_rc_invert_input(const char *device, bool invert) { retu
|
||||
************************************************************************************/
|
||||
|
||||
#if defined(__PX4_NUTTX) && !defined(CONFIG_BUILD_FLAT)
|
||||
inline static int board_read_VBUS_state(void)
|
||||
{
|
||||
inline static int board_read_VBUS_state(void) {
|
||||
platformiocvbusstate_t state = {false};
|
||||
boardctl(PLATFORMIOCVBUSSTATE, (uintptr_t)&state);
|
||||
return state.ret;
|
||||
}
|
||||
#elif defined(GPIO_OTGFS_VBUS)
|
||||
# define board_read_VBUS_state() (px4_arch_gpioread(GPIO_OTGFS_VBUS) ? 0 : 1)
|
||||
#define board_read_VBUS_state() (px4_arch_gpioread(GPIO_OTGFS_VBUS) ? 0 : 1)
|
||||
#else
|
||||
int board_read_VBUS_state(void);
|
||||
#endif
|
||||
@@ -542,7 +573,7 @@ int board_read_VBUS_state(void);
|
||||
|
||||
#if defined(BOARD_HAS_ON_RESET)
|
||||
__EXPORT void board_on_reset(int status);
|
||||
#endif // BOARD_HAS_ON_RESET
|
||||
#endif // BOARD_HAS_ON_RESET
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_power_off
|
||||
@@ -565,7 +596,7 @@ __EXPORT void board_on_reset(int status);
|
||||
|
||||
#if defined(BOARD_HAS_POWER_CONTROL)
|
||||
int board_power_off(int status);
|
||||
#endif // BOARD_HAS_POWER_CONTROL
|
||||
#endif // BOARD_HAS_POWER_CONTROL
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_reset
|
||||
@@ -609,12 +640,12 @@ int board_reset(int status);
|
||||
|
||||
#ifdef CONFIG_BOARDCTL_RESET
|
||||
|
||||
typedef enum reset_mode_e {
|
||||
BOARD_RESET_MODE_CLEAR = 0, /* Clear the mode */
|
||||
BOARD_RESET_MODE_BOOT_TO_BL = 1, /* Reboot and stay in the bootloader */
|
||||
typedef enum reset_mode_e {
|
||||
BOARD_RESET_MODE_CLEAR = 0, /* Clear the mode */
|
||||
BOARD_RESET_MODE_BOOT_TO_BL = 1, /* Reboot and stay in the bootloader */
|
||||
BOARD_RESET_MODE_BOOT_TO_VALID_APP = 2, /* Reboot to a valid app or stay in bootloader */
|
||||
BOARD_RESET_MODE_CAN_BL = 3, /* Used to pass a node ID and stay in the can bootloader */
|
||||
BOARD_RESET_MODE_RTC_BOOT_FWOK = 4 /* Set by a a watch dogged application after running > 30 Seconds */
|
||||
BOARD_RESET_MODE_CAN_BL = 3, /* Used to pass a node ID and stay in the can bootloader */
|
||||
BOARD_RESET_MODE_RTC_BOOT_FWOK = 4 /* Set by a a watch dogged application after running > 30 Seconds */
|
||||
} reset_mode_e;
|
||||
|
||||
int board_configure_reset(reset_mode_e mode, uint32_t arg);
|
||||
@@ -654,52 +685,51 @@ bool board_booted_by_px4(void);
|
||||
|
||||
typedef enum {
|
||||
PX4_MFT_PX4IO = 0,
|
||||
PX4_MFT_USB = 1,
|
||||
PX4_MFT_CAN2 = 2,
|
||||
PX4_MFT_CAN3 = 3,
|
||||
PX4_MFT_USB = 1,
|
||||
PX4_MFT_CAN2 = 2,
|
||||
PX4_MFT_CAN3 = 3,
|
||||
} px4_hw_mft_item_id_t;
|
||||
|
||||
typedef enum {
|
||||
px4_hw_con_unknown = 0,
|
||||
px4_hw_con_onboard = 1,
|
||||
px4_hw_con_unknown = 0,
|
||||
px4_hw_con_onboard = 1,
|
||||
px4_hw_con_connector = 3,
|
||||
} px4_hw_connection_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
unsigned int present: 1; /* 1 if this board have this item */
|
||||
unsigned int mandatory: 1; /* 1 if this item has to be present and working */
|
||||
unsigned int connection: 2; /* See px4_hw_connection_t */
|
||||
unsigned int present : 1; /* 1 if this board have this item */
|
||||
unsigned int mandatory : 1; /* 1 if this item has to be present and working */
|
||||
unsigned int connection : 2; /* See px4_hw_connection_t */
|
||||
} px4_hw_mft_item_t;
|
||||
|
||||
typedef const px4_hw_mft_item_t *px4_hw_mft_item;
|
||||
#define px4_hw_mft_uninitialized (px4_hw_mft_item) -1
|
||||
#define px4_hw_mft_unsupported (px4_hw_mft_item) 0
|
||||
typedef const px4_hw_mft_item_t *px4_hw_mft_item;
|
||||
#define px4_hw_mft_uninitialized (px4_hw_mft_item) - 1
|
||||
#define px4_hw_mft_unsupported (px4_hw_mft_item)0
|
||||
|
||||
#if defined(BOARD_HAS_VERSIONING)
|
||||
__EXPORT px4_hw_mft_item board_query_manifest(px4_hw_mft_item_id_t id);
|
||||
|
||||
# define PX4_MFT_HW_SUPPORTED(ID) (board_query_manifest((ID))->present)
|
||||
# define PX4_MFT_HW_REQUIRED(ID) (board_query_manifest((ID))->mandatory)
|
||||
# define PX4_MFT_HW_IS_ONBOARD(ID) (board_query_manifest((ID))->connection == px4_hw_con_onboard)
|
||||
# define PX4_MFT_HW_IS_OFFBOARD(ID) (board_query_manifest((ID))->connection == px4_hw_con_connector)
|
||||
# define PX4_MFT_HW_IS_CONNECTION_KNOWN(ID) (board_query_manifest((ID))->connection != px4_hw_con_unknown)
|
||||
#define PX4_MFT_HW_SUPPORTED(ID) (board_query_manifest((ID))->present)
|
||||
#define PX4_MFT_HW_REQUIRED(ID) (board_query_manifest((ID))->mandatory)
|
||||
#define PX4_MFT_HW_IS_ONBOARD(ID) (board_query_manifest((ID))->connection == px4_hw_con_onboard)
|
||||
#define PX4_MFT_HW_IS_OFFBOARD(ID) (board_query_manifest((ID))->connection == px4_hw_con_connector)
|
||||
#define PX4_MFT_HW_IS_CONNECTION_KNOWN(ID) (board_query_manifest((ID))->connection != px4_hw_con_unknown)
|
||||
#elif defined(BOARD_HAS_STATIC_MANIFEST) && BOARD_HAS_STATIC_MANIFEST == 1
|
||||
/* Board has a static configuration and will supply what it has */
|
||||
# define PX4_MFT_HW_SUPPORTED(ID) PX4_MFT_HW_SUPPORTED_##ID
|
||||
# define PX4_MFT_HW_REQUIRED(ID) PX4_MFT_HW_REQUIRED_##ID
|
||||
# define PX4_MFT_HW_IS_ONBOARD(ID) PX4_MFT_HW_IS_ONBOARD_##ID
|
||||
# define PX4_MFT_HW_IS_OFFBOARD(ID) PX4_MFT_HW_IS_OFFBOARD_##ID
|
||||
# define PX4_MFT_HW_IS_CONNECTION_KNOWN(ID) PX4_MFT_HW_IS_CONNECTION_KNOWN_##ID
|
||||
# define board_query_manifest(_na) px4_hw_mft_unsupported
|
||||
#define PX4_MFT_HW_SUPPORTED(ID) PX4_MFT_HW_SUPPORTED_##ID
|
||||
#define PX4_MFT_HW_REQUIRED(ID) PX4_MFT_HW_REQUIRED_##ID
|
||||
#define PX4_MFT_HW_IS_ONBOARD(ID) PX4_MFT_HW_IS_ONBOARD_##ID
|
||||
#define PX4_MFT_HW_IS_OFFBOARD(ID) PX4_MFT_HW_IS_OFFBOARD_##ID
|
||||
#define PX4_MFT_HW_IS_CONNECTION_KNOWN(ID) PX4_MFT_HW_IS_CONNECTION_KNOWN_##ID
|
||||
#define board_query_manifest(_na) px4_hw_mft_unsupported
|
||||
#else
|
||||
/* Default are Not Supported */
|
||||
# define PX4_MFT_HW_SUPPORTED(ID) (0)
|
||||
# define PX4_MFT_HW_REQUIRED(ID) (0)
|
||||
# define PX4_MFT_HW_IS_ONBOARD(ID) (0)
|
||||
# define PX4_MFT_HW_IS_OFFBOARD(ID) (0)
|
||||
# define PX4_MFT_HW_IS_CONNECTION_KNOWN(ID) (0)
|
||||
# define board_query_manifest(_na) px4_hw_mft_unsupported
|
||||
#define PX4_MFT_HW_SUPPORTED(ID) (0)
|
||||
#define PX4_MFT_HW_REQUIRED(ID) (0)
|
||||
#define PX4_MFT_HW_IS_ONBOARD(ID) (0)
|
||||
#define PX4_MFT_HW_IS_OFFBOARD(ID) (0)
|
||||
#define PX4_MFT_HW_IS_CONNECTION_KNOWN(ID) (0)
|
||||
#define board_query_manifest(_na) px4_hw_mft_unsupported
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
@@ -812,7 +842,7 @@ __EXPORT int board_get_hw_revision(void);
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
__EXPORT void board_get_uuid(uuid_byte_t uuid_bytes); // DEPRICATED use board_get_px4_guid
|
||||
__EXPORT void board_get_uuid(uuid_byte_t uuid_bytes); // DEPRICATED use board_get_px4_guid
|
||||
|
||||
/************************************************************************************
|
||||
* Name: board_get_uuid32 DEPRICATED use board_get_px4_guid
|
||||
@@ -834,7 +864,7 @@ __EXPORT void board_get_uuid(uuid_byte_t uuid_bytes); // DEPRICATED use board_ge
|
||||
* The uuid_words array is populated with the CPU uuid.
|
||||
*
|
||||
************************************************************************************/
|
||||
__EXPORT void board_get_uuid32(uuid_uint32_t uuid_words); // DEPRICATED use board_get_px4_guid
|
||||
__EXPORT void board_get_uuid32(uuid_uint32_t uuid_words); // DEPRICATED use board_get_px4_guid
|
||||
|
||||
/************************************************************************************
|
||||
* Name: board_get_uuid32_formated DEPRICATED use board_get_px4_guid_formated
|
||||
@@ -867,9 +897,8 @@ __EXPORT void board_get_uuid32(uuid_uint32_t uuid_words); // DEPRICATED use boar
|
||||
* Zero (OK) is returned on success;
|
||||
*
|
||||
************************************************************************************/
|
||||
__EXPORT int board_get_uuid32_formated(char *format_buffer, int size,
|
||||
const char *format,
|
||||
const char *seperator); // DEPRICATED use board_get_px4_guid_formated
|
||||
__EXPORT int board_get_uuid32_formated(char *format_buffer, int size, const char *format,
|
||||
const char *seperator); // DEPRICATED use board_get_px4_guid_formated
|
||||
|
||||
/************************************************************************************
|
||||
* Name: board_get_mfguid
|
||||
@@ -910,7 +939,7 @@ int board_get_mfguid(mfguid_t mfgid);
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
int board_get_mfguid_formated(char *format_buffer, int size); // DEPRICATED use board_get_px4_guid_formated
|
||||
int board_get_mfguid_formated(char *format_buffer, int size); // DEPRICATED use board_get_px4_guid_formated
|
||||
|
||||
/************************************************************************************
|
||||
* Name: board_get_px4_guid
|
||||
@@ -994,7 +1023,7 @@ int board_get_px4_guid_formated(char *format_buffer, int size);
|
||||
#define board_mcu_version(rev, revstr, errata) BOARD_OVERRIDE_CPU_VERSION
|
||||
#else
|
||||
__EXPORT int board_mcu_version(char *rev, const char **revstr, const char **errata);
|
||||
#endif // !defined(BOARD_OVERRIDE_CPU_VERSION)
|
||||
#endif // !defined(BOARD_OVERRIDE_CPU_VERSION)
|
||||
|
||||
#if defined(BOARD_HAS_POWER_CONTROL)
|
||||
/************************************************************************************
|
||||
@@ -1027,10 +1056,10 @@ enum board_bus_types {
|
||||
BOARD_INVALID_BUS = 0,
|
||||
#if defined(CONFIG_SPI)
|
||||
BOARD_SPI_BUS = 1,
|
||||
#endif // CONFIG_SPI
|
||||
#endif // CONFIG_SPI
|
||||
#if defined(CONFIG_I2C)
|
||||
BOARD_I2C_BUS = 2
|
||||
#endif // CONFIG_I2C
|
||||
#endif // CONFIG_I2C
|
||||
};
|
||||
|
||||
#if defined(BOARD_HAS_BUS_MANIFEST)
|
||||
@@ -1038,10 +1067,9 @@ enum board_bus_types {
|
||||
__EXPORT bool board_has_bus(enum board_bus_types type, uint32_t bus);
|
||||
|
||||
#else
|
||||
# define board_has_bus(t, b) true
|
||||
#define board_has_bus(t, b) true
|
||||
#endif /* BOARD_HAS_BUS_MANIFEST */
|
||||
|
||||
|
||||
/************************************************************************************
|
||||
* Name: board_spi_reset
|
||||
*
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
/**
|
||||
* Parse a CLI argument to an integer. There are 2 valid formats:
|
||||
* - 'p:<param_name>'
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
|
||||
|
||||
#define CONSOLE_BUFFER_DEVICE "/dev/console_buf"
|
||||
|
||||
#ifdef BOARD_ENABLE_CONSOLE_BUFFER
|
||||
@@ -82,18 +81,9 @@ __END_DECLS
|
||||
|
||||
#else
|
||||
|
||||
static inline int px4_console_buffer_init()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
static inline int px4_console_buffer_init() { return 0; }
|
||||
|
||||
static inline int px4_console_buffer_size()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
static inline int px4_console_buffer_size() { return 0; }
|
||||
|
||||
static inline int px4_console_buffer_read(char *buffer, int buffer_length, int *offset)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
static inline int px4_console_buffer_read(char *buffer, int buffer_length, int *offset) { return 0; }
|
||||
#endif /* BOARD_ENABLE_CONSOLE_BUFFER */
|
||||
|
||||
@@ -33,8 +33,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
static inline int _constexpr_assert_failure(const char *msg)
|
||||
{
|
||||
static inline int _constexpr_assert_failure(const char *msg) {
|
||||
// we do 2 things that the compiler will refuse to execute at compile-time
|
||||
// (and therefore trigger a compilation error):
|
||||
// - define a local static variable
|
||||
@@ -54,4 +53,7 @@ static inline int _constexpr_assert_failure(const char *msg)
|
||||
*
|
||||
* If executed at runtime, it has no effect other than slight runtime overhead.
|
||||
*/
|
||||
#define constexpr_assert(expr, msg) if (!(expr)) { _constexpr_assert_failure(msg); }
|
||||
#define constexpr_assert(expr, msg) \
|
||||
if (!(expr)) { \
|
||||
_constexpr_assert_failure(msg); \
|
||||
}
|
||||
|
||||
@@ -35,20 +35,19 @@
|
||||
|
||||
#ifdef PX4_CRYPTO
|
||||
|
||||
#include <px4_platform_common/crypto_algorithms.h>
|
||||
#include <px4_platform_common/sem.h>
|
||||
#include <px4_random.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <px4_random.h>
|
||||
#include <px4_platform_common/crypto_algorithms.h>
|
||||
#include <px4_platform_common/sem.h>
|
||||
#include "crypto_backend_definitions.h"
|
||||
|
||||
/*
|
||||
* Crypto API interface class
|
||||
*/
|
||||
|
||||
class PX4Crypto
|
||||
{
|
||||
class PX4Crypto {
|
||||
public:
|
||||
/*
|
||||
* Constructor & destructor
|
||||
@@ -91,8 +90,7 @@ public:
|
||||
* returns true on success, false on failure
|
||||
*/
|
||||
|
||||
bool generate_key(uint8_t idx,
|
||||
bool persistent);
|
||||
bool generate_key(uint8_t idx, bool persistent);
|
||||
|
||||
/*
|
||||
* Generate a key pair for asymmetric-key encryption
|
||||
@@ -103,13 +101,9 @@ public:
|
||||
* public_idx: the public key will be stored in this index in the keystore
|
||||
* persistent: whether the keys need to be stored persistently
|
||||
* returns true on success, false on failure
|
||||
*/
|
||||
|
||||
bool generate_keypair(size_t key_size,
|
||||
uint8_t private_idx,
|
||||
uint8_t public_idx,
|
||||
bool persistent);
|
||||
*/
|
||||
|
||||
bool generate_keypair(size_t key_size, uint8_t private_idx, uint8_t public_idx, bool persistent);
|
||||
|
||||
/*
|
||||
* Re-create or set nonce.
|
||||
@@ -123,7 +117,6 @@ public:
|
||||
|
||||
bool renew_nonce(const uint8_t *nonce, size_t nonce_size);
|
||||
|
||||
|
||||
/*
|
||||
* Get current crypto session nonce
|
||||
*
|
||||
@@ -134,8 +127,7 @@ public:
|
||||
* returns true on success, false on failure
|
||||
*/
|
||||
|
||||
bool get_nonce(uint8_t *nonce,
|
||||
size_t *nonce_len);
|
||||
bool get_nonce(uint8_t *nonce, size_t *nonce_len);
|
||||
|
||||
/*
|
||||
* Store a key into keystore
|
||||
@@ -144,12 +136,9 @@ public:
|
||||
* authenticating the key before storing
|
||||
* key: The pointer to the key
|
||||
* key_idx: Index where the key will be stored in keystore
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
bool set_key(uint8_t encryption_idx,
|
||||
const uint8_t *key,
|
||||
uint8_t key_idx);
|
||||
bool set_key(uint8_t encryption_idx, const uint8_t *key, uint8_t key_idx);
|
||||
|
||||
/*
|
||||
* Get a key from keystore. Key can be encrypted
|
||||
@@ -158,16 +147,13 @@ public:
|
||||
* key: The provided buffer to the key. If NULL, the function only provides
|
||||
* the length of the key.
|
||||
* key_len: input: the size of the provided "key" buffer.
|
||||
output: the actual size of the key
|
||||
output: the actual size of the key
|
||||
* encryption_key_idx: The key index in keystore to be used for encrypting
|
||||
* returns true on success, false on failure
|
||||
*
|
||||
*/
|
||||
|
||||
bool get_encrypted_key(uint8_t key_idx,
|
||||
uint8_t *key,
|
||||
size_t *key_len,
|
||||
uint8_t encryption_key_idx);
|
||||
bool get_encrypted_key(uint8_t key_idx, uint8_t *key, size_t *key_len, uint8_t encryption_key_idx);
|
||||
|
||||
/*
|
||||
* PX4 Crypto API functions
|
||||
@@ -180,13 +166,9 @@ public:
|
||||
* signature: pointer to the signature
|
||||
* message: pointer to the data to be verified
|
||||
* message_size: size of the message in bytes
|
||||
*/
|
||||
|
||||
bool signature_check(uint8_t key_index,
|
||||
const uint8_t *signature,
|
||||
const uint8_t *message,
|
||||
size_t message_size);
|
||||
*/
|
||||
|
||||
bool signature_check(uint8_t key_index, const uint8_t *signature, const uint8_t *message, size_t message_size);
|
||||
|
||||
/*
|
||||
* Encrypt data. This always supports encryption in-place
|
||||
@@ -200,10 +182,7 @@ public:
|
||||
* returns true on success, false on failure
|
||||
*/
|
||||
|
||||
bool encrypt_data(uint8_t key_index,
|
||||
const uint8_t *message,
|
||||
size_t message_size,
|
||||
uint8_t *cipher,
|
||||
bool encrypt_data(uint8_t key_index, const uint8_t *message, size_t message_size, uint8_t *cipher,
|
||||
size_t *cipher_size);
|
||||
|
||||
size_t get_min_blocksize(uint8_t key_idx);
|
||||
@@ -212,7 +191,10 @@ private:
|
||||
crypto_session_handle_t _crypto_handle;
|
||||
static px4_sem_t _lock;
|
||||
static bool _initialized;
|
||||
static void lock() { do {} while (px4_sem_wait(&PX4Crypto::_lock) != 0); }
|
||||
static void lock() {
|
||||
do {
|
||||
} while (px4_sem_wait(&PX4Crypto::_lock) != 0);
|
||||
}
|
||||
static void unlock() { px4_sem_post(&PX4Crypto::_lock); }
|
||||
};
|
||||
|
||||
|
||||
@@ -37,9 +37,10 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <px4_platform_common/crypto_algorithms.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <px4_platform_common/crypto_algorithms.h>
|
||||
|
||||
#include "crypto_backend_definitions.h"
|
||||
|
||||
/*
|
||||
@@ -80,7 +81,6 @@ size_t keystore_get_key(keystore_session_handle_t handle, uint8_t idx, uint8_t *
|
||||
*/
|
||||
bool keystore_put_key(keystore_session_handle_t handle, uint8_t idx, uint8_t *key, size_t key_size);
|
||||
|
||||
|
||||
/*
|
||||
* Architecture specific PX4 Crypto API functions
|
||||
*/
|
||||
@@ -113,9 +113,7 @@ void crypto_close(crypto_session_handle_t *handle);
|
||||
* idx: The key index, by which the key can be used
|
||||
* persistent: if set to "true", the key will be stored into the keystore
|
||||
*/
|
||||
bool crypto_generate_key(crypto_session_handle_t handle,
|
||||
uint8_t idx,
|
||||
bool persistent);
|
||||
bool crypto_generate_key(crypto_session_handle_t handle, uint8_t idx, bool persistent);
|
||||
|
||||
/*
|
||||
* Get a key from keystore, possibly encrypted
|
||||
@@ -128,10 +126,7 @@ bool crypto_generate_key(crypto_session_handle_t handle,
|
||||
* encryption_key_idx: The key index in keystore to be used for encrypting
|
||||
* returns true on success, false on failure
|
||||
*/
|
||||
bool crypto_get_encrypted_key(crypto_session_handle_t handle,
|
||||
uint8_t key_idx,
|
||||
uint8_t *key,
|
||||
size_t *max_len,
|
||||
bool crypto_get_encrypted_key(crypto_session_handle_t handle, uint8_t key_idx, uint8_t *key, size_t *max_len,
|
||||
uint8_t encryption_key_idx);
|
||||
|
||||
/*
|
||||
@@ -144,9 +139,7 @@ bool crypto_get_encrypted_key(crypto_session_handle_t handle,
|
||||
* encryption_key_idx: The key index in keystore to be used for encrypting
|
||||
* returns true on success, false on failure
|
||||
*/
|
||||
bool crypto_get_nonce(crypto_session_handle_t handle,
|
||||
uint8_t *nonce,
|
||||
size_t *nonce_len);
|
||||
bool crypto_get_nonce(crypto_session_handle_t handle, uint8_t *nonce, size_t *nonce_len);
|
||||
|
||||
/*
|
||||
* Perform signature check using an open session to crypto
|
||||
@@ -156,18 +149,11 @@ bool crypto_get_nonce(crypto_session_handle_t handle,
|
||||
* message_size: size of the data
|
||||
*/
|
||||
|
||||
bool crypto_signature_check(crypto_session_handle_t handle,
|
||||
uint8_t key_index,
|
||||
const uint8_t *signature,
|
||||
const uint8_t *message,
|
||||
size_t message_size);
|
||||
bool crypto_signature_check(crypto_session_handle_t handle, uint8_t key_index, const uint8_t *signature,
|
||||
const uint8_t *message, size_t message_size);
|
||||
|
||||
bool crypto_encrypt_data(crypto_session_handle_t handle,
|
||||
uint8_t key_index,
|
||||
const uint8_t *message,
|
||||
size_t message_size,
|
||||
uint8_t *cipher,
|
||||
size_t *cipher_size);
|
||||
bool crypto_encrypt_data(crypto_session_handle_t handle, uint8_t key_index, const uint8_t *message, size_t message_size,
|
||||
uint8_t *cipher, size_t *cipher_size);
|
||||
|
||||
/*
|
||||
* Returns a minimum data block size on which the crypto operations can be
|
||||
@@ -182,5 +168,5 @@ bool crypto_encrypt_data(crypto_session_handle_t handle,
|
||||
size_t crypto_get_min_blocksize(crypto_session_handle_t handle, uint8_t key_idx);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern "C"
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
@@ -63,7 +63,7 @@ static inline constexpr bool PX4_ISFINITE(double x) { return __builtin_isfinite(
|
||||
|
||||
#define PX4_ROOTFSDIR ""
|
||||
#define PX4_STORAGEDIR PX4_ROOTFSDIR "/fs/microsd"
|
||||
#define _PX4_IOC(x,y) _IOC(x,y)
|
||||
#define _PX4_IOC(x, y) _IOC(x, y)
|
||||
|
||||
// mode for open with O_CREAT
|
||||
#define PX4_O_MODE_777 0777
|
||||
@@ -82,14 +82,14 @@ static inline constexpr bool PX4_ISFINITE(double x) { return __builtin_isfinite(
|
||||
|
||||
// mode for open with O_CREAT
|
||||
#define PX4_O_MODE_777 (S_IRWXU | S_IRWXG | S_IRWXO)
|
||||
#define PX4_O_MODE_666 (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH )
|
||||
#define PX4_O_MODE_666 (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
|
||||
#define PX4_O_MODE_600 (S_IRUSR | S_IWUSR)
|
||||
|
||||
// NuttX _IOC is equivalent to Linux _IO
|
||||
#define _PX4_IOC(x,y) _IO(x,y)
|
||||
#define _PX4_IOC(x, y) _IO(x, y)
|
||||
|
||||
#define USEC_PER_TICK (1000000/PX4_TICKS_PER_SEC)
|
||||
#define USEC2TICK(x) (((x)+(USEC_PER_TICK/2))/USEC_PER_TICK)
|
||||
#define USEC_PER_TICK (1000000 / PX4_TICKS_PER_SEC)
|
||||
#define USEC2TICK(x) (((x) + (USEC_PER_TICK / 2)) / USEC_PER_TICK)
|
||||
|
||||
__BEGIN_DECLS
|
||||
extern long PX4_TICKS_PER_SEC;
|
||||
@@ -107,34 +107,34 @@ __END_DECLS
|
||||
#define ERROR -1
|
||||
#define MAX_RAND 32767
|
||||
|
||||
#endif // defined(__PX4_POSIX)
|
||||
#endif // defined(__PX4_POSIX)
|
||||
|
||||
/* Math macro's for float literals. Do not use M_PI et al as they aren't
|
||||
* defined (neither C nor the C++ standard define math constants) */
|
||||
#define M_E_F 2.71828183f
|
||||
#define M_LOG2E_F 1.44269504f
|
||||
#define M_LOG10E_F 0.43429448f
|
||||
#define M_LN2_F 0.69314718f
|
||||
#define M_LN10_F 2.30258509f
|
||||
#define M_PI_F 3.14159265f
|
||||
#define M_TWOPI_F 6.28318531f
|
||||
#define M_PI_2_F 1.57079632f
|
||||
#define M_PI_4_F 0.78539816f
|
||||
#define M_3PI_4_F 2.35619449f
|
||||
#define M_SQRTPI_F 1.77245385f
|
||||
#define M_1_PI_F 0.31830989f
|
||||
#define M_2_PI_F 0.63661977f
|
||||
#define M_2_SQRTPI_F 1.12837917f
|
||||
#define M_DEG_TO_RAD_F 0.0174532925f
|
||||
#define M_RAD_TO_DEG_F 57.2957795f
|
||||
#define M_SQRT2_F 1.41421356f
|
||||
#define M_SQRT1_2_F 0.70710678f
|
||||
#define M_LN2LO_F 1.90821484E-10f
|
||||
#define M_LN2HI_F 0.69314718f
|
||||
#define M_SQRT3_F 1.73205081f
|
||||
#define M_IVLN10_F 0.43429448f // 1 / log(10)
|
||||
#define M_LOG2_E_F 0.69314718f
|
||||
#define M_INVLN2_F 1.44269504f // 1 / log(2)
|
||||
#define M_E_F 2.71828183f
|
||||
#define M_LOG2E_F 1.44269504f
|
||||
#define M_LOG10E_F 0.43429448f
|
||||
#define M_LN2_F 0.69314718f
|
||||
#define M_LN10_F 2.30258509f
|
||||
#define M_PI_F 3.14159265f
|
||||
#define M_TWOPI_F 6.28318531f
|
||||
#define M_PI_2_F 1.57079632f
|
||||
#define M_PI_4_F 0.78539816f
|
||||
#define M_3PI_4_F 2.35619449f
|
||||
#define M_SQRTPI_F 1.77245385f
|
||||
#define M_1_PI_F 0.31830989f
|
||||
#define M_2_PI_F 0.63661977f
|
||||
#define M_2_SQRTPI_F 1.12837917f
|
||||
#define M_DEG_TO_RAD_F 0.0174532925f
|
||||
#define M_RAD_TO_DEG_F 57.2957795f
|
||||
#define M_SQRT2_F 1.41421356f
|
||||
#define M_SQRT1_2_F 0.70710678f
|
||||
#define M_LN2LO_F 1.90821484E-10f
|
||||
#define M_LN2HI_F 0.69314718f
|
||||
#define M_SQRT3_F 1.73205081f
|
||||
#define M_IVLN10_F 0.43429448f // 1 / log(10)
|
||||
#define M_LOG2_E_F 0.69314718f
|
||||
#define M_INVLN2_F 1.44269504f // 1 / log(2)
|
||||
|
||||
#define M_DEG_TO_RAD 0.017453292519943295
|
||||
#define M_RAD_TO_DEG 57.295779513082323
|
||||
#define M_DEG_TO_RAD 0.017453292519943295
|
||||
#define M_RAD_TO_DEG 57.295779513082323
|
||||
|
||||
@@ -46,35 +46,29 @@
|
||||
|
||||
#include <events/events_generated.h>
|
||||
#include <libevents_definitions.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace events
|
||||
{
|
||||
namespace events {
|
||||
|
||||
namespace util
|
||||
{
|
||||
namespace util {
|
||||
|
||||
// source: https://gist.github.com/ruby0x1/81308642d0325fd386237cfa3b44785c
|
||||
constexpr uint32_t val_32_const = 0x811c9dc5;
|
||||
constexpr uint32_t prime_32_const = 0x1000193;
|
||||
constexpr uint64_t val_64_const = 0xcbf29ce484222325;
|
||||
constexpr uint64_t prime_64_const = 0x100000001b3;
|
||||
inline constexpr uint32_t hash_32_fnv1a_const(const char *const str, const uint32_t value = val_32_const) noexcept
|
||||
{
|
||||
inline constexpr uint32_t hash_32_fnv1a_const(const char *const str, const uint32_t value = val_32_const) noexcept {
|
||||
return (str[0] == '\0') ? value : hash_32_fnv1a_const(&str[1], (value ^ uint32_t(str[0])) * prime_32_const);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline constexpr void fillEventArguments(uint8_t *buf, T arg)
|
||||
{
|
||||
template <typename T>
|
||||
inline constexpr void fillEventArguments(uint8_t *buf, T arg) {
|
||||
// This assumes we're on little-endian
|
||||
memcpy(buf, &arg, sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
inline constexpr void fillEventArguments(uint8_t *buf, T arg, Args... args)
|
||||
{
|
||||
template <typename T, typename... Args>
|
||||
inline constexpr void fillEventArguments(uint8_t *buf, T arg, Args... args) {
|
||||
fillEventArguments(buf, arg);
|
||||
fillEventArguments(buf + sizeof(T), args...);
|
||||
}
|
||||
@@ -82,13 +76,11 @@ inline constexpr void fillEventArguments(uint8_t *buf, T arg, Args... args)
|
||||
constexpr unsigned sizeofArguments() { return 0; }
|
||||
|
||||
template <typename T, typename... Args>
|
||||
constexpr unsigned sizeofArguments(const T &t, const Args &... args)
|
||||
{
|
||||
constexpr unsigned sizeofArguments(const T &t, const Args &... args) {
|
||||
return sizeof(T) + sizeofArguments(args...);
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
|
||||
} // namespace util
|
||||
|
||||
/**
|
||||
* publish/send an event
|
||||
@@ -98,17 +90,15 @@ void send(EventType &event);
|
||||
/**
|
||||
* Generate event ID from an event name
|
||||
*/
|
||||
template<size_t N>
|
||||
constexpr uint32_t ID(const char (&name)[N])
|
||||
{
|
||||
template <size_t N>
|
||||
constexpr uint32_t ID(const char (&name)[N]) {
|
||||
// Note: the generated ID must match with the python generator under Tools/px4events
|
||||
uint32_t component_id = 1u << 24; // autopilot component
|
||||
uint32_t component_id = 1u << 24; // autopilot component
|
||||
return (0xffffff & util::hash_32_fnv1a_const(name)) | component_id;
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void send(uint32_t id, const LogLevels &log_levels, const char *message, Args... args)
|
||||
{
|
||||
template <typename... Args>
|
||||
inline void send(uint32_t id, const LogLevels &log_levels, const char *message, Args... args) {
|
||||
EventType e{};
|
||||
e.log_levels = ((uint8_t)log_levels.internal << 4) | (uint8_t)log_levels.external;
|
||||
e.id = id;
|
||||
@@ -118,8 +108,7 @@ inline void send(uint32_t id, const LogLevels &log_levels, const char *message,
|
||||
send(e);
|
||||
}
|
||||
|
||||
inline void send(uint32_t id, const LogLevels &log_levels, const char *message)
|
||||
{
|
||||
inline void send(uint32_t id, const LogLevels &log_levels, const char *message) {
|
||||
EventType e{};
|
||||
e.log_levels = ((uint8_t)log_levels.internal << 4) | (uint8_t)log_levels.external;
|
||||
e.id = id;
|
||||
@@ -127,6 +116,6 @@ inline void send(uint32_t id, const LogLevels &log_levels, const char *message)
|
||||
send(e);
|
||||
}
|
||||
|
||||
static constexpr uint16_t initial_event_sequence = 65535 - 10; // initialize with a high number so it wraps soon
|
||||
static constexpr uint16_t initial_event_sequence = 65535 - 10; // initialize with a high number so it wraps soon
|
||||
|
||||
} // namespace events
|
||||
} // namespace events
|
||||
|
||||
@@ -34,13 +34,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
enum class LockoutComponent : uint8_t {
|
||||
Commander = 0,
|
||||
SystemShutdownLock = 1
|
||||
};
|
||||
enum class LockoutComponent : uint8_t { Commander = 0, SystemShutdownLock = 1 };
|
||||
|
||||
/**
|
||||
* A board may provide a mechanism to signal that PX4 is in a critical state
|
||||
@@ -53,6 +49,3 @@ enum class LockoutComponent : uint8_t {
|
||||
* @param enabled true if compoment is in critical state
|
||||
*/
|
||||
void px4_indicate_external_reset_lockout(LockoutComponent component, bool enabled);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -40,11 +40,12 @@
|
||||
#define I2C_BUS_MAX_BUS_ITEMS PX4_NUMBER_I2C_BUSES
|
||||
|
||||
struct px4_i2c_bus_t {
|
||||
int bus{-1}; ///< physical bus number (1, ...) (-1 means this is unused)
|
||||
bool is_external; ///< static external configuration. Use px4_i2c_bus_external() to check if a bus is really external
|
||||
int bus{-1}; ///< physical bus number (1, ...) (-1 means this is unused)
|
||||
bool is_external; ///< static external configuration. Use px4_i2c_bus_external() to check if a bus is really
|
||||
///< external
|
||||
};
|
||||
|
||||
__EXPORT extern const px4_i2c_bus_t px4_i2c_buses[I2C_BUS_MAX_BUS_ITEMS]; ///< board-specific I2C bus configuration
|
||||
__EXPORT extern const px4_i2c_bus_t px4_i2c_buses[I2C_BUS_MAX_BUS_ITEMS]; ///< board-specific I2C bus configuration
|
||||
|
||||
/**
|
||||
* runtime-check if a board has a specific bus as external.
|
||||
@@ -55,8 +56,7 @@ __EXPORT bool px4_i2c_bus_external(const px4_i2c_bus_t &bus);
|
||||
/**
|
||||
* runtime-check if a board has a specific bus as external.
|
||||
*/
|
||||
static inline bool px4_i2c_bus_external(int bus)
|
||||
{
|
||||
static inline bool px4_i2c_bus_external(int bus) {
|
||||
for (int i = 0; i < I2C_BUS_MAX_BUS_ITEMS; ++i) {
|
||||
if (px4_i2c_buses[i].bus == bus) {
|
||||
return px4_i2c_bus_external(px4_i2c_buses[i]);
|
||||
@@ -66,26 +66,23 @@ static inline bool px4_i2c_bus_external(int bus)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @class I2CBusIterator
|
||||
* Iterate over configured I2C buses by the board
|
||||
*/
|
||||
class I2CBusIterator
|
||||
{
|
||||
class I2CBusIterator {
|
||||
public:
|
||||
enum class FilterType {
|
||||
All, ///< specific or all buses
|
||||
InternalBus, ///< specific or all internal buses
|
||||
ExternalBus, ///< specific or all external buses
|
||||
All, ///< specific or all buses
|
||||
InternalBus, ///< specific or all internal buses
|
||||
ExternalBus, ///< specific or all external buses
|
||||
};
|
||||
|
||||
/**
|
||||
* @param bus specify bus: starts with 1, -1=all. Internal: arch-specific bus numbering is used,
|
||||
* external: n-th external bus
|
||||
*/
|
||||
I2CBusIterator(FilterType filter, int bus = -1)
|
||||
: _filter(filter), _bus(bus) {}
|
||||
I2CBusIterator(FilterType filter, int bus = -1) : _filter(filter), _bus(bus) {}
|
||||
|
||||
bool next();
|
||||
|
||||
@@ -102,4 +99,4 @@ private:
|
||||
int _external_bus_counter{0};
|
||||
};
|
||||
|
||||
#endif // CONFIG_I2C
|
||||
#endif // CONFIG_I2C
|
||||
|
||||
@@ -34,37 +34,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <board_config.h>
|
||||
|
||||
#include <lib/conversion/rotation.h>
|
||||
#include <px4_platform_common/atomic.h>
|
||||
#include <px4_platform_common/sem.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <containers/List.hpp>
|
||||
#include <lib/conversion/rotation.h>
|
||||
#include <px4_platform_common/atomic.h>
|
||||
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
|
||||
#include <px4_platform_common/sem.h>
|
||||
|
||||
#if defined(CONFIG_I2C)
|
||||
# include "i2c.h"
|
||||
#endif // CONFIG_I2C
|
||||
#include "i2c.h"
|
||||
#endif // CONFIG_I2C
|
||||
|
||||
#if defined(CONFIG_SPI)
|
||||
# include "spi.h"
|
||||
#endif // CONFIG_SPI
|
||||
#include "spi.h"
|
||||
#endif // CONFIG_SPI
|
||||
|
||||
#if defined(CONFIG_SPI)
|
||||
# include <drivers/device/spi.h>
|
||||
#endif // CONFIG_SPI
|
||||
#include <drivers/device/spi.h>
|
||||
#endif // CONFIG_SPI
|
||||
|
||||
enum class I2CSPIBusOption : uint8_t {
|
||||
All = 0, ///< select all runnning instances
|
||||
All = 0, ///< select all runnning instances
|
||||
#if defined(CONFIG_I2C)
|
||||
I2CInternal,
|
||||
I2CExternal,
|
||||
#endif // CONFIG_I2C
|
||||
#endif // CONFIG_I2C
|
||||
#if defined(CONFIG_SPI)
|
||||
SPIInternal,
|
||||
SPIExternal,
|
||||
#endif // CONFIG_SPI
|
||||
#endif // CONFIG_SPI
|
||||
};
|
||||
|
||||
class BusCLIArguments;
|
||||
@@ -81,13 +80,13 @@ struct I2CSPIDriverConfig {
|
||||
int bus;
|
||||
#if defined(CONFIG_I2C)
|
||||
uint8_t i2c_address;
|
||||
#endif // CONFIG_I2C
|
||||
#endif // CONFIG_I2C
|
||||
int bus_frequency;
|
||||
#if defined(CONFIG_SPI)
|
||||
spi_drdy_gpio_t drdy_gpio;
|
||||
spi_mode_e spi_mode;
|
||||
uint32_t spi_devid;
|
||||
#endif // CONFIG_SPI
|
||||
#endif // CONFIG_SPI
|
||||
int bus_device_index;
|
||||
|
||||
Rotation rotation;
|
||||
@@ -106,22 +105,25 @@ struct I2CSPIDriverConfig {
|
||||
* @class I2CSPIInstance
|
||||
* I2C/SPI driver instance used by BusInstanceIterator to find running instances.
|
||||
*/
|
||||
class I2CSPIInstance : public ListNode<I2CSPIInstance *>
|
||||
{
|
||||
class I2CSPIInstance : public ListNode<I2CSPIInstance *> {
|
||||
public:
|
||||
virtual ~I2CSPIInstance() = default;
|
||||
#if defined(CONFIG_I2C)
|
||||
virtual int8_t get_i2c_address() {return _i2c_address;}
|
||||
#endif // CONFIG_I2C
|
||||
virtual int8_t get_i2c_address() { return _i2c_address; }
|
||||
#endif // CONFIG_I2C
|
||||
private:
|
||||
I2CSPIInstance(const I2CSPIDriverConfig &config)
|
||||
: _module_name(config.module_name), _bus_option(config.bus_option), _bus(config.bus),
|
||||
_devid_driver_index(config.devid_driver_index), _bus_device_index(config.bus_device_index)
|
||||
: _module_name(config.module_name),
|
||||
_bus_option(config.bus_option),
|
||||
_bus(config.bus),
|
||||
_devid_driver_index(config.devid_driver_index),
|
||||
_bus_device_index(config.bus_device_index)
|
||||
#if defined(CONFIG_I2C)
|
||||
, _i2c_address(config.i2c_address)
|
||||
#endif // CONFIG_I2C
|
||||
{}
|
||||
|
||||
,
|
||||
_i2c_address(config.i2c_address)
|
||||
#endif // CONFIG_I2C
|
||||
{
|
||||
}
|
||||
|
||||
friend class BusInstanceIterator;
|
||||
friend class I2CSPIDriverBase;
|
||||
@@ -132,27 +134,27 @@ private:
|
||||
const uint16_t _devid_driver_index;
|
||||
const int8_t _bus_device_index;
|
||||
#if defined(CONFIG_I2C)
|
||||
const int8_t _i2c_address; ///< I2C address (optional)
|
||||
#endif // CONFIG_I2C
|
||||
const int8_t _i2c_address; ///< I2C address (optional)
|
||||
#endif // CONFIG_I2C
|
||||
};
|
||||
|
||||
class BusCLIArguments
|
||||
{
|
||||
class BusCLIArguments {
|
||||
public:
|
||||
BusCLIArguments(bool i2c_support, bool spi_support)
|
||||
#if defined(CONFIG_I2C) || defined(CONFIG_SPI)
|
||||
:
|
||||
#endif // CONFIG_I2C || CONFIG_SPI
|
||||
#endif // CONFIG_I2C || CONFIG_SPI
|
||||
#if defined(CONFIG_I2C)
|
||||
_i2c_support(i2c_support)
|
||||
#endif // CONFIG_I2C
|
||||
_i2c_support(i2c_support)
|
||||
#endif // CONFIG_I2C
|
||||
#if defined(CONFIG_I2C) && defined(CONFIG_SPI)
|
||||
,
|
||||
#endif // CONFIG_I2C && CONFIG_SPI
|
||||
,
|
||||
#endif // CONFIG_I2C && CONFIG_SPI
|
||||
#if defined(CONFIG_SPI)
|
||||
_spi_support(spi_support)
|
||||
#endif // CONFIG_SPI
|
||||
{}
|
||||
_spi_support(spi_support)
|
||||
#endif // CONFIG_SPI
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse CLI arguments (for drivers that don't need any custom arguments, otherwise getopt() should be used)
|
||||
@@ -171,56 +173,54 @@ public:
|
||||
*/
|
||||
const char *optArg() const { return _optarg; }
|
||||
|
||||
|
||||
I2CSPIBusOption bus_option{I2CSPIBusOption::All};
|
||||
int requested_bus{-1};
|
||||
int bus_frequency{0};
|
||||
#if defined(CONFIG_SPI)
|
||||
int chipselect {-1};
|
||||
int chipselect{-1};
|
||||
spi_mode_e spi_mode{SPIDEV_MODE3};
|
||||
#endif // CONFIG_SPI
|
||||
#endif // CONFIG_SPI
|
||||
#if defined(CONFIG_I2C)
|
||||
uint8_t i2c_address {0}; ///< I2C address (a driver must set the default address)
|
||||
#endif // CONFIG_I2C
|
||||
bool quiet_start {false}; ///< do not print a message when startup fails
|
||||
bool keep_running{false}; ///< keep driver running even if no device is detected on startup
|
||||
uint8_t i2c_address{0}; ///< I2C address (a driver must set the default address)
|
||||
#endif // CONFIG_I2C
|
||||
bool quiet_start{false}; ///< do not print a message when startup fails
|
||||
bool keep_running{false}; ///< keep driver running even if no device is detected on startup
|
||||
|
||||
Rotation rotation{ROTATION_NONE}; ///< sensor rotation (MAV_SENSOR_ROTATION_* or distance_sensor_s::ROTATION_*)
|
||||
Rotation rotation{ROTATION_NONE}; ///< sensor rotation (MAV_SENSOR_ROTATION_* or distance_sensor_s::ROTATION_*)
|
||||
|
||||
int custom1{0}; ///< driver-specific custom argument
|
||||
int custom2{0}; ///< driver-specific custom argument
|
||||
void *custom_data{nullptr}; ///< driver-specific custom argument
|
||||
int custom1{0}; ///< driver-specific custom argument
|
||||
int custom2{0}; ///< driver-specific custom argument
|
||||
void *custom_data{nullptr}; ///< driver-specific custom argument
|
||||
|
||||
// driver defaults, if not specified via CLI
|
||||
#if defined(CONFIG_SPI)
|
||||
int default_spi_frequency {-1}; ///< default spi bus frequency (driver needs to set this) [Hz]
|
||||
#endif // CONFIG_SPI
|
||||
int default_spi_frequency{-1}; ///< default spi bus frequency (driver needs to set this) [Hz]
|
||||
#endif // CONFIG_SPI
|
||||
#if defined(CONFIG_I2C)
|
||||
int default_i2c_frequency {-1}; ///< default i2c bus frequency (driver needs to set this) [Hz]
|
||||
#endif // CONFIG_I2C
|
||||
int default_i2c_frequency{-1}; ///< default i2c bus frequency (driver needs to set this) [Hz]
|
||||
#endif // CONFIG_I2C
|
||||
|
||||
bool support_keep_running{false}; ///< true if keep_running (see above) is supported
|
||||
bool support_keep_running{false}; ///< true if keep_running (see above) is supported
|
||||
|
||||
private:
|
||||
bool validateConfiguration();
|
||||
|
||||
char _options[32] {};
|
||||
char _options[32]{};
|
||||
int _optind{1};
|
||||
const char *_optarg{nullptr};
|
||||
#if defined(CONFIG_I2C)
|
||||
const bool _i2c_support;
|
||||
#endif // CONFIG_I2C
|
||||
#endif // CONFIG_I2C
|
||||
#if defined(CONFIG_SPI)
|
||||
const bool _spi_support;
|
||||
#endif // CONFIG_SPI
|
||||
#endif // CONFIG_SPI
|
||||
};
|
||||
|
||||
/**
|
||||
* @class BusInstanceIterator
|
||||
* Iterate over running instances and/or configured I2C/SPI buses with given filter options.
|
||||
*/
|
||||
class BusInstanceIterator
|
||||
{
|
||||
class BusInstanceIterator {
|
||||
public:
|
||||
BusInstanceIterator(const char *module_name, const BusCLIArguments &cli_arguments, uint16_t devid_driver_index);
|
||||
~BusInstanceIterator();
|
||||
@@ -239,7 +239,7 @@ public:
|
||||
|
||||
#if defined(CONFIG_SPI)
|
||||
spi_drdy_gpio_t DRDYGPIO() const;
|
||||
#endif // CONFIG_SPI
|
||||
#endif // CONFIG_SPI
|
||||
|
||||
bool external() const;
|
||||
int externalBusIndex() const;
|
||||
@@ -249,10 +249,10 @@ public:
|
||||
|
||||
#if defined(CONFIG_I2C)
|
||||
static I2CBusIterator::FilterType i2cFilter(I2CSPIBusOption bus_option);
|
||||
#endif // CONFIG_I2C
|
||||
#endif // CONFIG_I2C
|
||||
#if defined(CONFIG_SPI)
|
||||
static SPIBusIterator::FilterType spiFilter(I2CSPIBusOption bus_option);
|
||||
#endif // CONFIG_SPI
|
||||
#endif // CONFIG_SPI
|
||||
|
||||
const char *moduleName() const { return _module_name; }
|
||||
uint16_t devidDriverIndex() const { return _devid_driver_index; }
|
||||
@@ -263,13 +263,13 @@ private:
|
||||
const uint16_t _devid_driver_index;
|
||||
#if defined(CONFIG_I2C)
|
||||
const uint8_t _i2c_address;
|
||||
#endif // CONFIG_I2C
|
||||
#endif // CONFIG_I2C
|
||||
#if defined(CONFIG_SPI)
|
||||
SPIBusIterator _spi_bus_iterator;
|
||||
#endif // CONFIG_SPI
|
||||
#endif // CONFIG_SPI
|
||||
#if defined(CONFIG_I2C)
|
||||
I2CBusIterator _i2c_bus_iterator;
|
||||
#endif // CONFIG_I2C
|
||||
#endif // CONFIG_I2C
|
||||
List<I2CSPIInstance *>::Iterator _current_instance;
|
||||
};
|
||||
|
||||
@@ -277,19 +277,18 @@ private:
|
||||
* @class I2CSPIDriverBase
|
||||
* Base class for I2C/SPI driver modules (non-templated, used by I2CSPIDriver)
|
||||
*/
|
||||
class I2CSPIDriverBase : public px4::ScheduledWorkItem, public I2CSPIInstance
|
||||
{
|
||||
class I2CSPIDriverBase : public px4::ScheduledWorkItem, public I2CSPIInstance {
|
||||
public:
|
||||
I2CSPIDriverBase(const I2CSPIDriverConfig &config)
|
||||
: ScheduledWorkItem(config.module_name, config.wq_config),
|
||||
I2CSPIInstance(config) {}
|
||||
: ScheduledWorkItem(config.module_name, config.wq_config), I2CSPIInstance(config) {}
|
||||
|
||||
static int module_stop(BusInstanceIterator &iterator);
|
||||
static int module_status(BusInstanceIterator &iterator);
|
||||
static int module_custom_method(const BusCLIArguments &cli, BusInstanceIterator &iterator,
|
||||
bool run_on_work_queue = true);
|
||||
|
||||
using instantiate_method = I2CSPIDriverBase * (*)(const I2CSPIDriverConfig &config, int runtime_instance);
|
||||
using instantiate_method = I2CSPIDriverBase *(*)(const I2CSPIDriverConfig &config, int runtime_instance);
|
||||
|
||||
protected:
|
||||
virtual ~I2CSPIDriverBase() = default;
|
||||
|
||||
@@ -302,11 +301,14 @@ protected:
|
||||
* This will be called from the work queue.
|
||||
* A module overriding this, needs to call I2CSPIDriverBase::exit_and_cleanup() as the very last statement.
|
||||
*/
|
||||
virtual void exit_and_cleanup() { ScheduleClear(); _task_exited.store(true); }
|
||||
virtual void exit_and_cleanup() {
|
||||
ScheduleClear();
|
||||
_task_exited.store(true);
|
||||
}
|
||||
|
||||
bool should_exit() const { return _task_should_exit.load(); }
|
||||
|
||||
static int module_start(const BusCLIArguments &cli, BusInstanceIterator &iterator, void(*print_usage)(),
|
||||
static int module_start(const BusCLIArguments &cli, BusInstanceIterator &iterator, void (*print_usage)(),
|
||||
instantiate_method instantiate);
|
||||
|
||||
private:
|
||||
@@ -322,24 +324,20 @@ private:
|
||||
* @class I2CSPIDriver
|
||||
* Base class for I2C/SPI driver modules
|
||||
*/
|
||||
template<class T>
|
||||
class I2CSPIDriver : public I2CSPIDriverBase
|
||||
{
|
||||
template <class T>
|
||||
class I2CSPIDriver : public I2CSPIDriverBase {
|
||||
public:
|
||||
static int module_start(const BusCLIArguments &cli, BusInstanceIterator &iterator)
|
||||
{
|
||||
static int module_start(const BusCLIArguments &cli, BusInstanceIterator &iterator) {
|
||||
return I2CSPIDriverBase::module_start(cli, iterator, &T::print_usage, InstantiateHelper<T>::m);
|
||||
}
|
||||
|
||||
protected:
|
||||
I2CSPIDriver(const I2CSPIDriverConfig &config)
|
||||
: I2CSPIDriverBase(config) {}
|
||||
I2CSPIDriver(const I2CSPIDriverConfig &config) : I2CSPIDriverBase(config) {}
|
||||
|
||||
virtual ~I2CSPIDriver() = default;
|
||||
|
||||
// *INDENT-OFF* remove once there's astyle >3.1 in CI
|
||||
void Run() final
|
||||
{
|
||||
void Run() final {
|
||||
static_cast<T *>(this)->RunImpl();
|
||||
|
||||
if (should_exit()) {
|
||||
@@ -348,21 +346,23 @@ protected:
|
||||
}
|
||||
// *INDENT-ON*
|
||||
private:
|
||||
|
||||
// SFINAE to use R::instantiate if it exists, and R::instantiate_default otherwise
|
||||
template <typename R>
|
||||
class InstantiateHelper
|
||||
{
|
||||
class InstantiateHelper {
|
||||
template <typename C>
|
||||
static constexpr I2CSPIDriverBase::instantiate_method get(decltype(&C::instantiate)) { return &C::instantiate; }
|
||||
static constexpr I2CSPIDriverBase::instantiate_method get(decltype(&C::instantiate)) {
|
||||
return &C::instantiate;
|
||||
}
|
||||
template <typename C>
|
||||
static constexpr I2CSPIDriverBase::instantiate_method get(...) { return &C::instantiate_default; }
|
||||
static constexpr I2CSPIDriverBase::instantiate_method get(...) {
|
||||
return &C::instantiate_default;
|
||||
}
|
||||
|
||||
public:
|
||||
static constexpr I2CSPIDriverBase::instantiate_method m = get<R>(0);
|
||||
};
|
||||
|
||||
static I2CSPIDriverBase *instantiate_default(const I2CSPIDriverConfig &config, int runtime_instance)
|
||||
{
|
||||
static I2CSPIDriverBase *instantiate_default(const I2CSPIDriverConfig &config, int runtime_instance) {
|
||||
T *instance = new T(config);
|
||||
|
||||
if (!instance) {
|
||||
|
||||
@@ -41,8 +41,7 @@ __END_DECLS
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace px4
|
||||
{
|
||||
namespace px4 {
|
||||
|
||||
/**
|
||||
* Startup init method. It has no specific functionality, just prints a welcome
|
||||
@@ -50,6 +49,6 @@ namespace px4
|
||||
*/
|
||||
__EXPORT void init(int argc, char *argv[], const char *process_name);
|
||||
|
||||
} // namespace px4
|
||||
} // namespace px4
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -38,17 +38,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define _PX4_LOG_LEVEL_DEBUG 0
|
||||
#define _PX4_LOG_LEVEL_INFO 1
|
||||
#define _PX4_LOG_LEVEL_WARN 2
|
||||
#define _PX4_LOG_LEVEL_ERROR 3
|
||||
#define _PX4_LOG_LEVEL_PANIC 4
|
||||
#define _PX4_LOG_LEVEL_DEBUG 0
|
||||
#define _PX4_LOG_LEVEL_INFO 1
|
||||
#define _PX4_LOG_LEVEL_WARN 2
|
||||
#define _PX4_LOG_LEVEL_ERROR 3
|
||||
#define _PX4_LOG_LEVEL_PANIC 4
|
||||
|
||||
// Used to silence unused variable warning
|
||||
static inline void do_nothing(int level, ...)
|
||||
{
|
||||
(void)level;
|
||||
}
|
||||
static inline void do_nothing(int level, ...) { (void)level; }
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
@@ -63,74 +60,73 @@ __END_DECLS
|
||||
* __px4_log_omit:
|
||||
* Compile out the message
|
||||
****************************************************************************/
|
||||
#define __px4_log_omit(level, FMT, ...) do_nothing(level, ##__VA_ARGS__)
|
||||
#define __px4_log_omit(level, FMT, ...) do_nothing(level, ##__VA_ARGS__)
|
||||
|
||||
#if defined(__PX4_QURT)
|
||||
#include "qurt_log.h"
|
||||
/****************************************************************************
|
||||
* Messages that should never be filtered or compiled out
|
||||
****************************************************************************/
|
||||
#define PX4_INFO(FMT, ...) qurt_log(_PX4_LOG_LEVEL_INFO, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_INFO_RAW(FMT, ...) __px4_log_omit(_PX4_LOG_LEVEL_INFO, FMT, ##__VA_ARGS__)
|
||||
#define PX4_INFO(FMT, ...) qurt_log(_PX4_LOG_LEVEL_INFO, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_INFO_RAW(FMT, ...) __px4_log_omit(_PX4_LOG_LEVEL_INFO, FMT, ##__VA_ARGS__)
|
||||
|
||||
#if defined(TRACE_BUILD)
|
||||
/****************************************************************************
|
||||
* Extremely Verbose settings for a Trace build
|
||||
****************************************************************************/
|
||||
#define PX4_PANIC(FMT, ...) qurt_log(_PX4_LOG_LEVEL_PANIC, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_ERR(FMT, ...) qurt_log(_PX4_LOG_LEVEL_ERROR, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_WARN(FMT, ...) qurt_log(_PX4_LOG_LEVEL_WARN, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_DEBUG(FMT, ...) qurt_log(_PX4_LOG_LEVEL_DEBUG, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_PANIC(FMT, ...) qurt_log(_PX4_LOG_LEVEL_PANIC, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_ERR(FMT, ...) qurt_log(_PX4_LOG_LEVEL_ERROR, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_WARN(FMT, ...) qurt_log(_PX4_LOG_LEVEL_WARN, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_DEBUG(FMT, ...) qurt_log(_PX4_LOG_LEVEL_DEBUG, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
|
||||
#elif defined(DEBUG_BUILD)
|
||||
/****************************************************************************
|
||||
* Verbose settings for a Debug build
|
||||
****************************************************************************/
|
||||
#define PX4_PANIC(FMT, ...) qurt_log(_PX4_LOG_LEVEL_PANIC, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_ERR(FMT, ...) qurt_log(_PX4_LOG_LEVEL_ERROR, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_WARN(FMT, ...) qurt_log(_PX4_LOG_LEVEL_WARN, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_DEBUG(FMT, ...) qurt_log(_PX4_LOG_LEVEL_DEBUG, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_PANIC(FMT, ...) qurt_log(_PX4_LOG_LEVEL_PANIC, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_ERR(FMT, ...) qurt_log(_PX4_LOG_LEVEL_ERROR, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_WARN(FMT, ...) qurt_log(_PX4_LOG_LEVEL_WARN, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_DEBUG(FMT, ...) qurt_log(_PX4_LOG_LEVEL_DEBUG, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
|
||||
#elif defined(RELEASE_BUILD)
|
||||
/****************************************************************************
|
||||
* Non-verbose settings for a Release build to minimize strings in build
|
||||
****************************************************************************/
|
||||
#define PX4_PANIC(FMT, ...) qurt_log(_PX4_LOG_LEVEL_PANIC, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_ERR(FMT, ...) qurt_log(_PX4_LOG_LEVEL_ERROR, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_WARN(FMT, ...) __px4_log_omit(_PX4_LOG_LEVEL_WARN, FMT, ##__VA_ARGS__)
|
||||
#define PX4_DEBUG(FMT, ...) __px4_log_omit(_PX4_LOG_LEVEL_DEBUG, FMT, ##__VA_ARGS__)
|
||||
#define PX4_PANIC(FMT, ...) qurt_log(_PX4_LOG_LEVEL_PANIC, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_ERR(FMT, ...) qurt_log(_PX4_LOG_LEVEL_ERROR, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_WARN(FMT, ...) __px4_log_omit(_PX4_LOG_LEVEL_WARN, FMT, ##__VA_ARGS__)
|
||||
#define PX4_DEBUG(FMT, ...) __px4_log_omit(_PX4_LOG_LEVEL_DEBUG, FMT, ##__VA_ARGS__)
|
||||
|
||||
#else
|
||||
/****************************************************************************
|
||||
* Medium verbose settings for a default build
|
||||
****************************************************************************/
|
||||
#define PX4_PANIC(FMT, ...) qurt_log(_PX4_LOG_LEVEL_PANIC, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_ERR(FMT, ...) qurt_log(_PX4_LOG_LEVEL_ERROR, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_WARN(FMT, ...) qurt_log(_PX4_LOG_LEVEL_WARN, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_DEBUG(FMT, ...) __px4_log_omit(_PX4_LOG_LEVEL_DEBUG, FMT, ##__VA_ARGS__)
|
||||
#define PX4_PANIC(FMT, ...) qurt_log(_PX4_LOG_LEVEL_PANIC, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_ERR(FMT, ...) qurt_log(_PX4_LOG_LEVEL_ERROR, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_WARN(FMT, ...) qurt_log(_PX4_LOG_LEVEL_WARN, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_DEBUG(FMT, ...) __px4_log_omit(_PX4_LOG_LEVEL_DEBUG, FMT, ##__VA_ARGS__)
|
||||
|
||||
#endif
|
||||
#define PX4_LOG_NAMED(name, FMT, ...) qurt_log( _PX4_LOG_LEVEL_INFO, __FILE__, __LINE__, "%s " FMT, name, ##__VA_ARGS__)
|
||||
#define PX4_LOG_NAMED_COND(name, cond, FMT, ...) if( cond ) qurt_log( _PX4_LOG_LEVEL_INFO, __FILE__, __LINE__, "%s " FMT, name, ##__VA_ARGS__)
|
||||
#define PX4_LOG_NAMED(name, FMT, ...) qurt_log(_PX4_LOG_LEVEL_INFO, __FILE__, __LINE__, "%s " FMT, name, ##__VA_ARGS__)
|
||||
#define PX4_LOG_NAMED_COND(name, cond, FMT, ...) \
|
||||
if (cond) qurt_log(_PX4_LOG_LEVEL_INFO, __FILE__, __LINE__, "%s " FMT, name, ##__VA_ARGS__)
|
||||
|
||||
#else
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <px4_platform_common/defines.h>
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <inttypes.h>
|
||||
#include <px4_platform_common/defines.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
__EXPORT extern const char *__px4_log_level_str[_PX4_LOG_LEVEL_PANIC + 1];
|
||||
__EXPORT void px4_log_modulename(int level, const char *moduleName, const char *fmt, ...)
|
||||
__attribute__((format(printf, 3, 4)));
|
||||
__EXPORT void px4_log_raw(int level, const char *fmt, ...)
|
||||
__attribute__((format(printf, 2, 3)));
|
||||
__attribute__((format(printf, 3, 4)));
|
||||
__EXPORT void px4_log_raw(int level, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
|
||||
|
||||
#if __GNUC__
|
||||
// Allow empty format strings.
|
||||
@@ -139,7 +135,6 @@ __attribute__((format(printf, 2, 3)));
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of log section formatting based on printf
|
||||
*
|
||||
@@ -150,34 +145,33 @@ __END_DECLS
|
||||
* Additional behavior can be added using "{\" for __px4__log_startline and
|
||||
* "}" for __px4__log_endline and any other required setup or teardown steps
|
||||
****************************************************************************/
|
||||
#define __px4__log_printcond(cond, ...) if (cond) printf(__VA_ARGS__)
|
||||
#define __px4__log_printline(level, ...) printf(__VA_ARGS__)
|
||||
#define __px4__log_printcond(cond, ...) \
|
||||
if (cond) printf(__VA_ARGS__)
|
||||
#define __px4__log_printline(level, ...) printf(__VA_ARGS__)
|
||||
|
||||
#define __px4__log_timestamp_fmt "%-10" PRIu64 " "
|
||||
#define __px4__log_timestamp_arg ,hrt_absolute_time()
|
||||
#define __px4__log_level_fmt "%-5s "
|
||||
#define __px4__log_level_arg(level) ,__px4_log_level_str[level]
|
||||
#define __px4__log_thread_fmt "%#X "
|
||||
#define __px4__log_thread_arg ,(unsigned int)pthread_self()
|
||||
#define __px4__log_modulename_fmt "%-10s "
|
||||
#define __px4__log_modulename_pfmt "[%s] "
|
||||
#define __px4__log_modulename_arg ,"[" MODULE_NAME "]"
|
||||
#define __px4__log_timestamp_fmt "%-10" PRIu64 " "
|
||||
#define __px4__log_timestamp_arg , hrt_absolute_time()
|
||||
#define __px4__log_level_fmt "%-5s "
|
||||
#define __px4__log_level_arg(level) , __px4_log_level_str[level]
|
||||
#define __px4__log_thread_fmt "%#X "
|
||||
#define __px4__log_thread_arg , (unsigned int)pthread_self()
|
||||
#define __px4__log_modulename_fmt "%-10s "
|
||||
#define __px4__log_modulename_pfmt "[%s] "
|
||||
#define __px4__log_modulename_arg , "[" MODULE_NAME "]"
|
||||
|
||||
#define __px4__log_file_and_line_fmt " (file %s line %u)"
|
||||
#define __px4__log_file_and_line_arg , __FILE__, __LINE__
|
||||
#define __px4__log_end_fmt "\n"
|
||||
#define __px4__log_file_and_line_fmt " (file %s line %u)"
|
||||
#define __px4__log_file_and_line_arg , __FILE__, __LINE__
|
||||
#define __px4__log_end_fmt "\n"
|
||||
|
||||
#ifdef __PX4_POSIX
|
||||
#define PX4_LOG_COLORIZED_OUTPUT //if defined and output is a tty, colorize the output according to the log level
|
||||
#endif /* __PX4_POSIX */
|
||||
|
||||
#define PX4_LOG_COLORIZED_OUTPUT // if defined and output is a tty, colorize the output according to the log level
|
||||
#endif /* __PX4_POSIX */
|
||||
|
||||
/****************************************************************************
|
||||
* Output format macros
|
||||
* Use these to implement the code level macros below
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* __px4_log_named_cond:
|
||||
* Convert a message in the form:
|
||||
@@ -187,12 +181,7 @@ __END_DECLS
|
||||
* if the first arg/condition is true.
|
||||
****************************************************************************/
|
||||
#define __px4_log_named_cond(name, cond, FMT, ...) \
|
||||
__px4__log_printcond(cond,\
|
||||
"%s " \
|
||||
FMT\
|
||||
__px4__log_end_fmt \
|
||||
,name, ##__VA_ARGS__\
|
||||
)
|
||||
__px4__log_printcond(cond, "%s " FMT __px4__log_end_fmt, name, ##__VA_ARGS__)
|
||||
|
||||
/****************************************************************************
|
||||
* __px4_log:
|
||||
@@ -201,13 +190,9 @@ __END_DECLS
|
||||
* to
|
||||
* printf("%-5s val is %d\n", __px4_log_level_str[3], val);
|
||||
****************************************************************************/
|
||||
#define __px4_log(level, FMT, ...) \
|
||||
__px4__log_printline(level,\
|
||||
__px4__log_level_fmt \
|
||||
FMT\
|
||||
__px4__log_end_fmt \
|
||||
__px4__log_level_arg(level), ##__VA_ARGS__\
|
||||
)
|
||||
#define __px4_log(level, FMT, ...) \
|
||||
__px4__log_printline(level, __px4__log_level_fmt FMT __px4__log_end_fmt __px4__log_level_arg(level), \
|
||||
##__VA_ARGS__)
|
||||
|
||||
/****************************************************************************
|
||||
* __px4_log_modulename:
|
||||
@@ -218,10 +203,10 @@ __END_DECLS
|
||||
* MODULENAME, val);
|
||||
****************************************************************************/
|
||||
|
||||
#define __px4_log_modulename(level, fmt, ...) \
|
||||
do { \
|
||||
#define __px4_log_modulename(level, fmt, ...) \
|
||||
do { \
|
||||
px4_log_modulename(level, MODULE_NAME, fmt, ##__VA_ARGS__); \
|
||||
} while(0)
|
||||
} while (0)
|
||||
|
||||
/****************************************************************************
|
||||
* __px4_log_raw:
|
||||
@@ -232,11 +217,10 @@ __END_DECLS
|
||||
*
|
||||
* This can be used for simple printfs with all the formatting control.
|
||||
****************************************************************************/
|
||||
#define __px4_log_raw(level, fmt, ...) \
|
||||
do { \
|
||||
#define __px4_log_raw(level, fmt, ...) \
|
||||
do { \
|
||||
px4_log_raw(level, fmt, ##__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
} while (0)
|
||||
|
||||
/****************************************************************************
|
||||
* __px4_log_timestamp:
|
||||
@@ -246,16 +230,12 @@ __END_DECLS
|
||||
* printf("%-5s %10lu val is %d\n", __px4_log_level_str[3],
|
||||
* hrt_absolute_time(), val);
|
||||
****************************************************************************/
|
||||
#define __px4_log_timestamp(level, FMT, ...) \
|
||||
__px4__log_printline(level,\
|
||||
__px4__log_level_fmt\
|
||||
__px4__log_timestamp_fmt\
|
||||
FMT\
|
||||
__px4__log_end_fmt\
|
||||
__px4__log_level_arg(level)\
|
||||
__px4__log_timestamp_arg\
|
||||
, ##__VA_ARGS__\
|
||||
)
|
||||
#define __px4_log_timestamp(level, FMT, ...) \
|
||||
__px4__log_printline( \
|
||||
level, \
|
||||
__px4__log_level_fmt __px4__log_timestamp_fmt FMT __px4__log_end_fmt __px4__log_level_arg(level) \
|
||||
__px4__log_timestamp_arg, \
|
||||
##__VA_ARGS__)
|
||||
|
||||
/****************************************************************************
|
||||
* __px4_log_timestamp_thread:
|
||||
@@ -265,18 +245,12 @@ __END_DECLS
|
||||
* printf("%-5s %10lu %#X val is %d\n", __px4_log_level_str[3],
|
||||
* hrt_absolute_time(), pthread_self(), val);
|
||||
****************************************************************************/
|
||||
#define __px4_log_timestamp_thread(level, FMT, ...) \
|
||||
__px4__log_printline(level,\
|
||||
__px4__log_level_fmt\
|
||||
__px4__log_timestamp_fmt\
|
||||
__px4__log_thread_fmt\
|
||||
FMT\
|
||||
__px4__log_end_fmt\
|
||||
__px4__log_level_arg(level)\
|
||||
__px4__log_timestamp_arg\
|
||||
__px4__log_thread_arg\
|
||||
, ##__VA_ARGS__\
|
||||
)
|
||||
#define __px4_log_timestamp_thread(level, FMT, ...) \
|
||||
__px4__log_printline(level, \
|
||||
__px4__log_level_fmt __px4__log_timestamp_fmt __px4__log_thread_fmt FMT \
|
||||
__px4__log_end_fmt __px4__log_level_arg(level) \
|
||||
__px4__log_timestamp_arg __px4__log_thread_arg, \
|
||||
##__VA_ARGS__)
|
||||
|
||||
/****************************************************************************
|
||||
* __px4_log_file_and_line:
|
||||
@@ -286,18 +260,11 @@ __END_DECLS
|
||||
* printf("%-5s val is %d (file %s line %u)\n",
|
||||
* __px4_log_level_str[3], val, __FILE__, __LINE__);
|
||||
****************************************************************************/
|
||||
#define __px4_log_file_and_line(level, FMT, ...) \
|
||||
__px4__log_printline(level,\
|
||||
__px4__log_level_fmt\
|
||||
__px4__log_timestamp_fmt\
|
||||
FMT\
|
||||
__px4__log_file_and_line_fmt\
|
||||
__px4__log_end_fmt\
|
||||
__px4__log_level_arg(level)\
|
||||
__px4__log_timestamp_arg\
|
||||
, ##__VA_ARGS__\
|
||||
__px4__log_file_and_line_arg\
|
||||
)
|
||||
#define __px4_log_file_and_line(level, FMT, ...) \
|
||||
__px4__log_printline(level, \
|
||||
__px4__log_level_fmt __px4__log_timestamp_fmt FMT __px4__log_file_and_line_fmt \
|
||||
__px4__log_end_fmt __px4__log_level_arg(level) __px4__log_timestamp_arg, \
|
||||
##__VA_ARGS__ __px4__log_file_and_line_arg)
|
||||
|
||||
/****************************************************************************
|
||||
* __px4_log_timestamp_file_and_line:
|
||||
@@ -308,18 +275,11 @@ __END_DECLS
|
||||
* __px4_log_level_str[3], hrt_absolute_time(),
|
||||
* val, __FILE__, __LINE__);
|
||||
****************************************************************************/
|
||||
#define __px4_log_timestamp_file_and_line(level, FMT, ...) \
|
||||
__px4__log_printline(level,\
|
||||
__px4__log_level_fmt\
|
||||
__px4__log_timestamp_fmt\
|
||||
FMT\
|
||||
__px4__log_file_and_line_fmt\
|
||||
__px4__log_end_fmt\
|
||||
__px4__log_level_arg(level)\
|
||||
__px4__log_timestamp_arg\
|
||||
, ##__VA_ARGS__\
|
||||
__px4__log_file_and_line_arg\
|
||||
)
|
||||
#define __px4_log_timestamp_file_and_line(level, FMT, ...) \
|
||||
__px4__log_printline(level, \
|
||||
__px4__log_level_fmt __px4__log_timestamp_fmt FMT __px4__log_file_and_line_fmt \
|
||||
__px4__log_end_fmt __px4__log_level_arg(level) __px4__log_timestamp_arg, \
|
||||
##__VA_ARGS__ __px4__log_file_and_line_arg)
|
||||
|
||||
/****************************************************************************
|
||||
* __px4_log_thread_file_and_line:
|
||||
@@ -330,18 +290,11 @@ __END_DECLS
|
||||
* __px4_log_level_str[3], pthread_self(),
|
||||
* val, __FILE__, __LINE__);
|
||||
****************************************************************************/
|
||||
#define __px4_log_thread_file_and_line(level, FMT, ...) \
|
||||
__px4__log_printline(level,\
|
||||
__px4__log_level_fmt\
|
||||
__px4__log_thread_fmt\
|
||||
FMT\
|
||||
__px4__log_file_and_line_fmt\
|
||||
__px4__log_end_fmt\
|
||||
__px4__log_level_arg(level)\
|
||||
__px4__log_thread_arg\
|
||||
, ##__VA_ARGS__\
|
||||
__px4__log_file_and_line_arg\
|
||||
)
|
||||
#define __px4_log_thread_file_and_line(level, FMT, ...) \
|
||||
__px4__log_printline(level, \
|
||||
__px4__log_level_fmt __px4__log_thread_fmt FMT __px4__log_file_and_line_fmt \
|
||||
__px4__log_end_fmt __px4__log_level_arg(level) __px4__log_thread_arg, \
|
||||
##__VA_ARGS__ __px4__log_file_and_line_arg)
|
||||
|
||||
/****************************************************************************
|
||||
* __px4_log_timestamp_thread_file_and_line:
|
||||
@@ -352,21 +305,12 @@ __END_DECLS
|
||||
* __px4_log_level_str[3], hrt_absolute_time(),
|
||||
* pthread_self(), val, __FILE__, __LINE__);
|
||||
****************************************************************************/
|
||||
#define __px4_log_timestamp_thread_file_and_line(level, FMT, ...) \
|
||||
__px4__log_printline(level,\
|
||||
__px4__log_level_fmt\
|
||||
__px4__log_timestamp_fmt\
|
||||
__px4__log_thread_fmt\
|
||||
FMT\
|
||||
__px4__log_file_and_line_fmt\
|
||||
__px4__log_end_fmt\
|
||||
__px4__log_level_arg(level)\
|
||||
__px4__log_timestamp_arg\
|
||||
__px4__log_thread_arg\
|
||||
, ##__VA_ARGS__\
|
||||
__px4__log_file_and_line_arg\
|
||||
)
|
||||
|
||||
#define __px4_log_timestamp_thread_file_and_line(level, FMT, ...) \
|
||||
__px4__log_printline(level, \
|
||||
__px4__log_level_fmt __px4__log_timestamp_fmt __px4__log_thread_fmt FMT \
|
||||
__px4__log_file_and_line_fmt __px4__log_end_fmt __px4__log_level_arg(level) \
|
||||
__px4__log_timestamp_arg __px4__log_thread_arg, \
|
||||
##__VA_ARGS__ __px4__log_file_and_line_arg)
|
||||
|
||||
/****************************************************************************
|
||||
* Code level macros
|
||||
@@ -376,51 +320,51 @@ __END_DECLS
|
||||
/****************************************************************************
|
||||
* Messages that should never be filtered or compiled out
|
||||
****************************************************************************/
|
||||
#define PX4_INFO(FMT, ...) __px4_log_modulename(_PX4_LOG_LEVEL_INFO, FMT, ##__VA_ARGS__)
|
||||
#define PX4_INFO(FMT, ...) __px4_log_modulename(_PX4_LOG_LEVEL_INFO, FMT, ##__VA_ARGS__)
|
||||
|
||||
#ifdef __NUTTX
|
||||
#define PX4_INFO_RAW printf
|
||||
#define PX4_INFO_RAW printf
|
||||
#else
|
||||
#define PX4_INFO_RAW(FMT, ...) __px4_log_raw(_PX4_LOG_LEVEL_INFO, FMT, ##__VA_ARGS__)
|
||||
#define PX4_INFO_RAW(FMT, ...) __px4_log_raw(_PX4_LOG_LEVEL_INFO, FMT, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if defined(TRACE_BUILD)
|
||||
/****************************************************************************
|
||||
* Extremely Verbose settings for a Trace build
|
||||
****************************************************************************/
|
||||
#define PX4_PANIC(FMT, ...) __px4_log_timestamp_thread_file_and_line(_PX4_LOG_LEVEL_PANIC, FMT, ##__VA_ARGS__)
|
||||
#define PX4_ERR(FMT, ...) __px4_log_timestamp_thread_file_and_line(_PX4_LOG_LEVEL_ERROR, FMT, ##__VA_ARGS__)
|
||||
#define PX4_WARN(FMT, ...) __px4_log_timestamp_thread_file_and_line(_PX4_LOG_LEVEL_WARN, FMT, ##__VA_ARGS__)
|
||||
#define PX4_DEBUG(FMT, ...) __px4_log_timestamp_thread(_PX4_LOG_LEVEL_DEBUG, FMT, ##__VA_ARGS__)
|
||||
#define PX4_PANIC(FMT, ...) __px4_log_timestamp_thread_file_and_line(_PX4_LOG_LEVEL_PANIC, FMT, ##__VA_ARGS__)
|
||||
#define PX4_ERR(FMT, ...) __px4_log_timestamp_thread_file_and_line(_PX4_LOG_LEVEL_ERROR, FMT, ##__VA_ARGS__)
|
||||
#define PX4_WARN(FMT, ...) __px4_log_timestamp_thread_file_and_line(_PX4_LOG_LEVEL_WARN, FMT, ##__VA_ARGS__)
|
||||
#define PX4_DEBUG(FMT, ...) __px4_log_timestamp_thread(_PX4_LOG_LEVEL_DEBUG, FMT, ##__VA_ARGS__)
|
||||
|
||||
#elif defined(DEBUG_BUILD)
|
||||
/****************************************************************************
|
||||
* Verbose settings for a Debug build
|
||||
****************************************************************************/
|
||||
#define PX4_PANIC(FMT, ...) __px4_log_timestamp_file_and_line(_PX4_LOG_LEVEL_PANIC, FMT, ##__VA_ARGS__)
|
||||
#define PX4_ERR(FMT, ...) __px4_log_timestamp_file_and_line(_PX4_LOG_LEVEL_ERROR, FMT, ##__VA_ARGS__)
|
||||
#define PX4_WARN(FMT, ...) __px4_log_timestamp_file_and_line(_PX4_LOG_LEVEL_WARN, FMT, ##__VA_ARGS__)
|
||||
#define PX4_DEBUG(FMT, ...) __px4_log_timestamp(_PX4_LOG_LEVEL_DEBUG, FMT, ##__VA_ARGS__)
|
||||
#define PX4_PANIC(FMT, ...) __px4_log_timestamp_file_and_line(_PX4_LOG_LEVEL_PANIC, FMT, ##__VA_ARGS__)
|
||||
#define PX4_ERR(FMT, ...) __px4_log_timestamp_file_and_line(_PX4_LOG_LEVEL_ERROR, FMT, ##__VA_ARGS__)
|
||||
#define PX4_WARN(FMT, ...) __px4_log_timestamp_file_and_line(_PX4_LOG_LEVEL_WARN, FMT, ##__VA_ARGS__)
|
||||
#define PX4_DEBUG(FMT, ...) __px4_log_timestamp(_PX4_LOG_LEVEL_DEBUG, FMT, ##__VA_ARGS__)
|
||||
|
||||
#elif defined(RELEASE_BUILD)
|
||||
/****************************************************************************
|
||||
* Non-verbose settings for a Release build to minimize strings in build
|
||||
****************************************************************************/
|
||||
#define PX4_PANIC(FMT, ...) __px4_log_modulename(_PX4_LOG_LEVEL_PANIC, FMT, ##__VA_ARGS__)
|
||||
#define PX4_ERR(FMT, ...) __px4_log_modulename(_PX4_LOG_LEVEL_ERROR, FMT, ##__VA_ARGS__)
|
||||
#define PX4_WARN(FMT, ...) __px4_log_omit(_PX4_LOG_LEVEL_WARN, FMT, ##__VA_ARGS__)
|
||||
#define PX4_DEBUG(FMT, ...) __px4_log_omit(_PX4_LOG_LEVEL_DEBUG, FMT, ##__VA_ARGS__)
|
||||
#define PX4_PANIC(FMT, ...) __px4_log_modulename(_PX4_LOG_LEVEL_PANIC, FMT, ##__VA_ARGS__)
|
||||
#define PX4_ERR(FMT, ...) __px4_log_modulename(_PX4_LOG_LEVEL_ERROR, FMT, ##__VA_ARGS__)
|
||||
#define PX4_WARN(FMT, ...) __px4_log_omit(_PX4_LOG_LEVEL_WARN, FMT, ##__VA_ARGS__)
|
||||
#define PX4_DEBUG(FMT, ...) __px4_log_omit(_PX4_LOG_LEVEL_DEBUG, FMT, ##__VA_ARGS__)
|
||||
|
||||
#else
|
||||
/****************************************************************************
|
||||
* Medium verbose settings for a default build
|
||||
****************************************************************************/
|
||||
#define PX4_PANIC(FMT, ...) __px4_log_modulename(_PX4_LOG_LEVEL_PANIC, FMT, ##__VA_ARGS__)
|
||||
#define PX4_ERR(FMT, ...) __px4_log_modulename(_PX4_LOG_LEVEL_ERROR, FMT, ##__VA_ARGS__)
|
||||
#define PX4_WARN(FMT, ...) __px4_log_modulename(_PX4_LOG_LEVEL_WARN, FMT, ##__VA_ARGS__)
|
||||
#define PX4_DEBUG(FMT, ...) __px4_log_omit(_PX4_LOG_LEVEL_DEBUG, FMT, ##__VA_ARGS__)
|
||||
#define PX4_PANIC(FMT, ...) __px4_log_modulename(_PX4_LOG_LEVEL_PANIC, FMT, ##__VA_ARGS__)
|
||||
#define PX4_ERR(FMT, ...) __px4_log_modulename(_PX4_LOG_LEVEL_ERROR, FMT, ##__VA_ARGS__)
|
||||
#define PX4_WARN(FMT, ...) __px4_log_modulename(_PX4_LOG_LEVEL_WARN, FMT, ##__VA_ARGS__)
|
||||
#define PX4_DEBUG(FMT, ...) __px4_log_omit(_PX4_LOG_LEVEL_DEBUG, FMT, ##__VA_ARGS__)
|
||||
|
||||
#endif
|
||||
#define PX4_LOG_NAMED(name, FMT, ...) __px4_log_named_cond(name, true, FMT, ##__VA_ARGS__)
|
||||
#define PX4_LOG_NAMED(name, FMT, ...) __px4_log_named_cond(name, true, FMT, ##__VA_ARGS__)
|
||||
#define PX4_LOG_NAMED_COND(name, cond, FMT, ...) __px4_log_named_cond(name, cond, FMT, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
@@ -38,14 +38,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <px4_platform_common/atomic.h>
|
||||
#include <px4_platform_common/time.h>
|
||||
#include <px4_platform_common/log.h>
|
||||
#include <px4_platform_common/tasks.h>
|
||||
#include <px4_platform_common/time.h>
|
||||
#include <stdbool.h>
|
||||
#include <systemlib/px4_macros.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -111,9 +110,8 @@ extern pthread_mutex_t px4_modules_mutex;
|
||||
* // on error return != 0 (and _task_id must be -1)
|
||||
* }
|
||||
*/
|
||||
template<class T>
|
||||
class ModuleBase
|
||||
{
|
||||
template <class T>
|
||||
class ModuleBase {
|
||||
public:
|
||||
ModuleBase() : _task_should_exit{false} {}
|
||||
virtual ~ModuleBase() {}
|
||||
@@ -125,13 +123,9 @@ public:
|
||||
* @param argc Pointer to the task argument variable array.
|
||||
* @return Returns 0 iff successful, -1 otherwise.
|
||||
*/
|
||||
static int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc <= 1 ||
|
||||
strcmp(argv[1], "-h") == 0 ||
|
||||
strcmp(argv[1], "help") == 0 ||
|
||||
strcmp(argv[1], "info") == 0 ||
|
||||
strcmp(argv[1], "usage") == 0) {
|
||||
static int main(int argc, char *argv[]) {
|
||||
if (argc <= 1 || strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "help") == 0 ||
|
||||
strcmp(argv[1], "info") == 0 || strcmp(argv[1], "usage") == 0) {
|
||||
return T::print_usage();
|
||||
}
|
||||
|
||||
@@ -148,7 +142,7 @@ public:
|
||||
return stop_command();
|
||||
}
|
||||
|
||||
lock_module(); // Lock here, as the method could access _object.
|
||||
lock_module(); // Lock here, as the method could access _object.
|
||||
int ret = T::custom_command(argc - 1, argv + 1);
|
||||
unlock_module();
|
||||
|
||||
@@ -165,8 +159,7 @@ public:
|
||||
* @param argc Pointer to the task argument variable array.
|
||||
* @return Returns 0 iff successful, -1 otherwise.
|
||||
*/
|
||||
static int run_trampoline(int argc, char *argv[])
|
||||
{
|
||||
static int run_trampoline(int argc, char *argv[]) {
|
||||
int ret = 0;
|
||||
|
||||
// We don't need the task name at this point.
|
||||
@@ -196,8 +189,7 @@ public:
|
||||
* @param argc Pointer to the task argument variable array.
|
||||
* @return Returns 0 iff successful, -1 otherwise.
|
||||
*/
|
||||
static int start_command_base(int argc, char *argv[])
|
||||
{
|
||||
static int start_command_base(int argc, char *argv[]) {
|
||||
int ret = 0;
|
||||
lock_module();
|
||||
|
||||
@@ -222,8 +214,7 @@ public:
|
||||
* and waits for the task to complete.
|
||||
* @return Returns 0 iff successful, -1 otherwise.
|
||||
*/
|
||||
static int stop_command()
|
||||
{
|
||||
static int stop_command() {
|
||||
int ret = 0;
|
||||
lock_module();
|
||||
|
||||
@@ -237,10 +228,10 @@ public:
|
||||
|
||||
do {
|
||||
unlock_module();
|
||||
px4_usleep(10000); // 10 ms
|
||||
px4_usleep(10000); // 10 ms
|
||||
lock_module();
|
||||
|
||||
if (++i > 500 && _task_id != -1) { // wait at most 5 sec
|
||||
if (++i > 500 && _task_id != -1) { // wait at most 5 sec
|
||||
PX4_ERR("timeout, forcing stop");
|
||||
|
||||
if (_task_id != task_id_is_work_queue) {
|
||||
@@ -274,8 +265,7 @@ public:
|
||||
* @brief Handle 'command status': check if running and call print_status() if it is
|
||||
* @return Returns 0 iff successful, -1 otherwise.
|
||||
*/
|
||||
static int status_command()
|
||||
{
|
||||
static int status_command() {
|
||||
int ret = -1;
|
||||
lock_module();
|
||||
|
||||
@@ -296,8 +286,7 @@ public:
|
||||
* more specific information.
|
||||
* @return Returns 0 iff successful, -1 otherwise.
|
||||
*/
|
||||
virtual int print_status()
|
||||
{
|
||||
virtual int print_status() {
|
||||
PX4_INFO("running");
|
||||
return 0;
|
||||
}
|
||||
@@ -306,45 +295,32 @@ public:
|
||||
* @brief Main loop method for modules running in their own thread. Called from run_trampoline().
|
||||
* This method must return when should_exit() returns true.
|
||||
*/
|
||||
virtual void run()
|
||||
{
|
||||
}
|
||||
virtual void run() {}
|
||||
|
||||
/**
|
||||
* @brief Returns the status of the module.
|
||||
* @return Returns true if the module is running, false otherwise.
|
||||
*/
|
||||
static bool is_running()
|
||||
{
|
||||
return _task_id != -1;
|
||||
}
|
||||
static bool is_running() { return _task_id != -1; }
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* @brief Tells the module to stop (used from outside or inside the module thread).
|
||||
*/
|
||||
virtual void request_stop()
|
||||
{
|
||||
_task_should_exit.store(true);
|
||||
}
|
||||
virtual void request_stop() { _task_should_exit.store(true); }
|
||||
|
||||
/**
|
||||
* @brief Checks if the module should stop (used within the module thread).
|
||||
* @return Returns True iff successful, false otherwise.
|
||||
*/
|
||||
bool should_exit() const
|
||||
{
|
||||
return _task_should_exit.load();
|
||||
}
|
||||
bool should_exit() const { return _task_should_exit.load(); }
|
||||
|
||||
/**
|
||||
* @brief Exits the module and delete the object. Called from within the module's thread.
|
||||
* For work queue modules, this needs to be called from the derived class in the
|
||||
* cycle method, when should_exit() returns true.
|
||||
*/
|
||||
static void exit_and_cleanup()
|
||||
{
|
||||
static void exit_and_cleanup() {
|
||||
// Take the lock here:
|
||||
// - if startup fails and we're faster than the parent thread, it will set
|
||||
// _task_id and subsequently it will look like the task is running.
|
||||
@@ -354,7 +330,7 @@ protected:
|
||||
delete _object.load();
|
||||
_object.store(nullptr);
|
||||
|
||||
_task_id = -1; // Signal a potentially waiting thread for the module to exit that it can continue.
|
||||
_task_id = -1; // Signal a potentially waiting thread for the module to exit that it can continue.
|
||||
unlock_module();
|
||||
}
|
||||
|
||||
@@ -362,8 +338,7 @@ protected:
|
||||
* @brief Waits until _object is initialized, (from the new thread). This can be called from task_spawn().
|
||||
* @return Returns 0 iff successful, -1 on timeout or otherwise.
|
||||
*/
|
||||
static int wait_until_running(int timeout_ms = 1000)
|
||||
{
|
||||
static int wait_until_running(int timeout_ms = 1000) {
|
||||
int i = 0;
|
||||
|
||||
do {
|
||||
@@ -382,10 +357,7 @@ protected:
|
||||
/**
|
||||
* @brief Get the module's object instance, (this is null if it's not running).
|
||||
*/
|
||||
static T *get_instance()
|
||||
{
|
||||
return (T *)_object.load();
|
||||
}
|
||||
static T *get_instance() { return (T *)_object.load(); }
|
||||
|
||||
/**
|
||||
* @var _object Instance if the module is running.
|
||||
@@ -403,33 +375,25 @@ private:
|
||||
/**
|
||||
* @brief lock_module Mutex to lock the module thread.
|
||||
*/
|
||||
static void lock_module()
|
||||
{
|
||||
pthread_mutex_lock(&px4_modules_mutex);
|
||||
}
|
||||
static void lock_module() { pthread_mutex_lock(&px4_modules_mutex); }
|
||||
|
||||
/**
|
||||
* @brief unlock_module Mutex to unlock the module thread.
|
||||
*/
|
||||
static void unlock_module()
|
||||
{
|
||||
pthread_mutex_unlock(&px4_modules_mutex);
|
||||
}
|
||||
static void unlock_module() { pthread_mutex_unlock(&px4_modules_mutex); }
|
||||
|
||||
/** @var _task_should_exit Boolean flag to indicate if the task should exit. */
|
||||
px4::atomic_bool _task_should_exit{false};
|
||||
};
|
||||
|
||||
template<class T>
|
||||
template <class T>
|
||||
px4::atomic<T *> ModuleBase<T>::_object{nullptr};
|
||||
|
||||
template<class T>
|
||||
template <class T>
|
||||
int ModuleBase<T>::_task_id = -1;
|
||||
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/**
|
||||
@@ -482,20 +446,18 @@ __EXPORT void PRINT_MODULE_USAGE_SUBCATEGORY(const char *subcategory);
|
||||
*/
|
||||
__EXPORT void PRINT_MODULE_USAGE_NAME_SIMPLE(const char *executable_name, const char *category);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Prints a command with a short description what it does.
|
||||
*/
|
||||
__EXPORT void PRINT_MODULE_USAGE_COMMAND_DESCR(const char *name, const char *description);
|
||||
|
||||
#define PRINT_MODULE_USAGE_COMMAND(name) \
|
||||
PRINT_MODULE_USAGE_COMMAND_DESCR(name, NULL);
|
||||
#define PRINT_MODULE_USAGE_COMMAND(name) PRINT_MODULE_USAGE_COMMAND_DESCR(name, NULL);
|
||||
|
||||
/**
|
||||
* @brief Prints the default commands: stop & status.
|
||||
*/
|
||||
#define PRINT_MODULE_USAGE_DEFAULT_COMMANDS() \
|
||||
PRINT_MODULE_USAGE_COMMAND("stop"); \
|
||||
PRINT_MODULE_USAGE_COMMAND("stop"); \
|
||||
PRINT_MODULE_USAGE_COMMAND_DESCR("status", "print status info");
|
||||
|
||||
/**
|
||||
@@ -527,7 +489,7 @@ __EXPORT void PRINT_MODULE_USAGE_PARAMS_I2C_KEEP_RUNNING_FLAG(void);
|
||||
* @param is_optional true if this parameter is optional
|
||||
*/
|
||||
__EXPORT void PRINT_MODULE_USAGE_PARAM_INT(char option_char, int default_val, int min_val, int max_val,
|
||||
const char *description, bool is_optional);
|
||||
const char *description, bool is_optional);
|
||||
|
||||
/**
|
||||
* @brief Prints a float parameter.
|
||||
@@ -539,7 +501,7 @@ __EXPORT void PRINT_MODULE_USAGE_PARAM_INT(char option_char, int default_val, in
|
||||
* @param is_optional true if this parameter is optional
|
||||
*/
|
||||
__EXPORT void PRINT_MODULE_USAGE_PARAM_FLOAT(char option_char, float default_val, float min_val, float max_val,
|
||||
const char *description, bool is_optional);
|
||||
const char *description, bool is_optional);
|
||||
|
||||
/**
|
||||
* @brief Prints a flag parameter, without any value.
|
||||
@@ -564,7 +526,7 @@ __EXPORT void PRINT_MODULE_USAGE_PARAM_FLAG(char option_char, const char *descri
|
||||
* @param is_optional True iff this parameter is optional.
|
||||
*/
|
||||
__EXPORT void PRINT_MODULE_USAGE_PARAM_STRING(char option_char, const char *default_val, const char *values,
|
||||
const char *description, bool is_optional);
|
||||
const char *description, bool is_optional);
|
||||
|
||||
/**
|
||||
* @brief Prints a comment, that applies to the next arguments or parameters. For example to indicate that
|
||||
@@ -573,7 +535,6 @@ __EXPORT void PRINT_MODULE_USAGE_PARAM_STRING(char option_char, const char *defa
|
||||
*/
|
||||
__EXPORT void PRINT_MODULE_USAGE_PARAM_COMMENT(const char *comment);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Prints the definition for an argument, which does not have the typical -p <val> form,
|
||||
* but for example 'param set <param> <value>'
|
||||
@@ -583,5 +544,4 @@ __EXPORT void PRINT_MODULE_USAGE_PARAM_COMMENT(const char *comment);
|
||||
*/
|
||||
__EXPORT void PRINT_MODULE_USAGE_ARG(const char *values, const char *description, bool is_optional);
|
||||
|
||||
|
||||
__END_DECLS
|
||||
|
||||
@@ -43,21 +43,15 @@
|
||||
|
||||
#include "param.h"
|
||||
|
||||
class ModuleParams : public ListNode<ModuleParams *>
|
||||
{
|
||||
class ModuleParams : public ListNode<ModuleParams *> {
|
||||
public:
|
||||
|
||||
ModuleParams(ModuleParams *parent)
|
||||
{
|
||||
setParent(parent);
|
||||
}
|
||||
ModuleParams(ModuleParams *parent) { setParent(parent); }
|
||||
|
||||
/**
|
||||
* @brief Sets the parent module. This is typically not required,
|
||||
* only in cases where the parent cannot be set via constructor.
|
||||
*/
|
||||
void setParent(ModuleParams *parent)
|
||||
{
|
||||
void setParent(ModuleParams *parent) {
|
||||
if (parent) {
|
||||
parent->_children.add(this);
|
||||
}
|
||||
@@ -65,9 +59,10 @@ public:
|
||||
_parent = parent;
|
||||
}
|
||||
|
||||
virtual ~ModuleParams()
|
||||
{
|
||||
if (_parent) { _parent->_children.remove(this); }
|
||||
virtual ~ModuleParams() {
|
||||
if (_parent) {
|
||||
_parent->_children.remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Disallow copy construction and move assignment.
|
||||
@@ -81,8 +76,7 @@ protected:
|
||||
* @brief Call this method whenever the module gets a parameter change notification.
|
||||
* It will automatically call updateParams() for all children, which then call updateParamsImpl().
|
||||
*/
|
||||
virtual void updateParams()
|
||||
{
|
||||
virtual void updateParams() {
|
||||
for (const auto &child : _children) {
|
||||
child->updateParams();
|
||||
}
|
||||
|
||||
@@ -33,35 +33,36 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
MTD_PARAMETERS = 1,
|
||||
MTD_WAYPOINTS = 2,
|
||||
MTD_CALDATA = 3,
|
||||
MTD_MFT = 4,
|
||||
MTD_ID = 5,
|
||||
MTD_NET = 6,
|
||||
typedef enum {
|
||||
MTD_PARAMETERS = 1,
|
||||
MTD_WAYPOINTS = 2,
|
||||
MTD_CALDATA = 3,
|
||||
MTD_MFT = 4,
|
||||
MTD_ID = 5,
|
||||
MTD_NET = 6,
|
||||
} px4_mtd_types_t;
|
||||
#define PX4_MFT_MTD_TYPES {MTD_PARAMETERS, MTD_WAYPOINTS, MTD_CALDATA, MTD_MFT, MTD_ID, MTD_NET}
|
||||
#define PX4_MFT_MTD_STR_TYPES {"MTD_PARAMETERS", "MTD_WAYPOINTS", "MTD_CALDATA", "MTD_MFT", "MTD_ID", "MTD_NET"}
|
||||
#define PX4_MFT_MTD_TYPES \
|
||||
{ MTD_PARAMETERS, MTD_WAYPOINTS, MTD_CALDATA, MTD_MFT, MTD_ID, MTD_NET }
|
||||
#define PX4_MFT_MTD_STR_TYPES \
|
||||
{ "MTD_PARAMETERS", "MTD_WAYPOINTS", "MTD_CALDATA", "MTD_MFT", "MTD_ID", "MTD_NET" }
|
||||
|
||||
typedef struct {
|
||||
const px4_mtd_types_t type;
|
||||
const char *path;
|
||||
const uint32_t nblocks;
|
||||
typedef struct {
|
||||
const px4_mtd_types_t type;
|
||||
const char *path;
|
||||
const uint32_t nblocks;
|
||||
} px4_mtd_part_t;
|
||||
|
||||
typedef struct {
|
||||
const px4_mft_device_t *device;
|
||||
const uint32_t npart;
|
||||
const px4_mtd_part_t partd[];
|
||||
typedef struct {
|
||||
const px4_mft_device_t *device;
|
||||
const uint32_t npart;
|
||||
const px4_mtd_part_t partd[];
|
||||
} px4_mtd_entry_t;
|
||||
|
||||
typedef struct {
|
||||
const uint32_t nconfigs;
|
||||
typedef struct {
|
||||
const uint32_t nconfigs;
|
||||
const px4_mtd_entry_t *entries[];
|
||||
} px4_mtd_manifest_t;
|
||||
|
||||
|
||||
__BEGIN_DECLS
|
||||
/************************************************************************************
|
||||
* Name: px4_mtd_config
|
||||
|
||||
@@ -39,37 +39,29 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "param_macros.h"
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <parameters/px4_parameters.hpp>
|
||||
|
||||
#include "param_macros.h"
|
||||
|
||||
/**
|
||||
* get the parameter handle from a parameter enum
|
||||
*/
|
||||
inline static param_t param_handle(px4::params p)
|
||||
{
|
||||
return (param_t)p;
|
||||
}
|
||||
inline static param_t param_handle(px4::params p) { return (param_t)p; }
|
||||
|
||||
#define _DEFINE_SINGLE_PARAMETER(x) do_not_explicitly_use_this_namespace::PAIR(x);
|
||||
|
||||
|
||||
|
||||
#define _DEFINE_SINGLE_PARAMETER(x) \
|
||||
do_not_explicitly_use_this_namespace::PAIR(x);
|
||||
|
||||
#define _CALL_UPDATE(x) \
|
||||
STRIP(x).update();
|
||||
#define _CALL_UPDATE(x) STRIP(x).update();
|
||||
|
||||
// define the parameter update method, which will update all parameters.
|
||||
// It is marked as 'final', so that wrong usages lead to a compile error (see below)
|
||||
#define _DEFINE_PARAMETER_UPDATE_METHOD(...) \
|
||||
protected: \
|
||||
void updateParamsImpl() final { \
|
||||
APPLY_ALL(_CALL_UPDATE, __VA_ARGS__) \
|
||||
} \
|
||||
private:
|
||||
#define _DEFINE_PARAMETER_UPDATE_METHOD(...) \
|
||||
protected: \
|
||||
void updateParamsImpl() final { APPLY_ALL(_CALL_UPDATE, __VA_ARGS__) } \
|
||||
\
|
||||
private:
|
||||
|
||||
// Define a list of parameters. This macro also creates code to update parameters.
|
||||
// If you get a compile error like:
|
||||
@@ -77,47 +69,40 @@ inline static param_t param_handle(px4::params p)
|
||||
// It means you have a custom inheritance tree (at least one class with params that inherits from another
|
||||
// class with params) and you need to use DEFINE_PARAMETERS_CUSTOM_PARENT() for **all** classes in
|
||||
// that tree.
|
||||
#define DEFINE_PARAMETERS(...) \
|
||||
#define DEFINE_PARAMETERS(...) \
|
||||
APPLY_ALL(_DEFINE_SINGLE_PARAMETER, __VA_ARGS__) \
|
||||
_DEFINE_PARAMETER_UPDATE_METHOD(__VA_ARGS__)
|
||||
|
||||
|
||||
#define _DEFINE_PARAMETER_UPDATE_METHOD_CUSTOM_PARENT(parent_class, ...) \
|
||||
protected: \
|
||||
void updateParamsImpl() override { \
|
||||
parent_class::updateParamsImpl(); \
|
||||
APPLY_ALL(_CALL_UPDATE, __VA_ARGS__) \
|
||||
} \
|
||||
private:
|
||||
protected: \
|
||||
void updateParamsImpl() override { \
|
||||
parent_class::updateParamsImpl(); \
|
||||
APPLY_ALL(_CALL_UPDATE, __VA_ARGS__) \
|
||||
} \
|
||||
\
|
||||
private:
|
||||
|
||||
#define DEFINE_PARAMETERS_CUSTOM_PARENT(parent_class, ...) \
|
||||
APPLY_ALL(_DEFINE_SINGLE_PARAMETER, __VA_ARGS__) \
|
||||
APPLY_ALL(_DEFINE_SINGLE_PARAMETER, __VA_ARGS__) \
|
||||
_DEFINE_PARAMETER_UPDATE_METHOD_CUSTOM_PARENT(parent_class, __VA_ARGS__)
|
||||
|
||||
|
||||
|
||||
// This namespace never needs to be used directly. Use the DEFINE_PARAMETERS_CUSTOM_PARENT and
|
||||
// DEFINE_PARAMETERS macros instead (the Param classes don't depend on using the macro, the macro just
|
||||
// makes sure that update() is automatically called).
|
||||
namespace do_not_explicitly_use_this_namespace
|
||||
{
|
||||
namespace do_not_explicitly_use_this_namespace {
|
||||
|
||||
template<typename T, px4::params p>
|
||||
class Param
|
||||
{
|
||||
};
|
||||
template <typename T, px4::params p>
|
||||
class Param {};
|
||||
|
||||
// We use partial template specialization for each param type. This is only supported for classes, not individual methods,
|
||||
// which is why we have to repeat the whole class
|
||||
template<px4::params p>
|
||||
class Param<float, p>
|
||||
{
|
||||
// We use partial template specialization for each param type. This is only supported for classes, not individual
|
||||
// methods, which is why we have to repeat the whole class
|
||||
template <px4::params p>
|
||||
class Param<float, p> {
|
||||
public:
|
||||
// static type-check
|
||||
static_assert(px4::parameters_type[(int)p] == PARAM_TYPE_FLOAT, "parameter type must be float");
|
||||
|
||||
Param()
|
||||
{
|
||||
Param() {
|
||||
param_set_used(handle());
|
||||
update();
|
||||
}
|
||||
@@ -129,12 +114,12 @@ public:
|
||||
/// Store the parameter value to the parameter storage (@see param_set())
|
||||
bool commit() const { return param_set(handle(), &_val) == 0; }
|
||||
|
||||
/// Store the parameter value to the parameter storage, w/o notifying the system (@see param_set_no_notification())
|
||||
/// Store the parameter value to the parameter storage, w/o notifying the system (@see
|
||||
/// param_set_no_notification())
|
||||
bool commit_no_notification() const { return param_set_no_notification(handle(), &_val) == 0; }
|
||||
|
||||
/// Set and commit a new value. Returns true if the value changed.
|
||||
bool commit_no_notification(float val)
|
||||
{
|
||||
bool commit_no_notification(float val) {
|
||||
if (fabsf(val - _val) > FLT_EPSILON) {
|
||||
set(val);
|
||||
commit_no_notification();
|
||||
@@ -146,8 +131,7 @@ public:
|
||||
|
||||
void set(float val) { _val = val; }
|
||||
|
||||
void reset()
|
||||
{
|
||||
void reset() {
|
||||
param_reset_no_notification(handle());
|
||||
update();
|
||||
}
|
||||
@@ -155,21 +139,19 @@ public:
|
||||
bool update() { return param_get(handle(), &_val) == 0; }
|
||||
|
||||
param_t handle() const { return param_handle(p); }
|
||||
|
||||
private:
|
||||
float _val;
|
||||
};
|
||||
|
||||
// external version
|
||||
template<px4::params p>
|
||||
class Param<float &, p>
|
||||
{
|
||||
template <px4::params p>
|
||||
class Param<float &, p> {
|
||||
public:
|
||||
// static type-check
|
||||
static_assert(px4::parameters_type[(int)p] == PARAM_TYPE_FLOAT, "parameter type must be float");
|
||||
|
||||
Param(float &external_val)
|
||||
: _val(external_val)
|
||||
{
|
||||
Param(float &external_val) : _val(external_val) {
|
||||
param_set_used(handle());
|
||||
update();
|
||||
}
|
||||
@@ -181,12 +163,12 @@ public:
|
||||
/// Store the parameter value to the parameter storage (@see param_set())
|
||||
bool commit() const { return param_set(handle(), &_val) == 0; }
|
||||
|
||||
/// Store the parameter value to the parameter storage, w/o notifying the system (@see param_set_no_notification())
|
||||
/// Store the parameter value to the parameter storage, w/o notifying the system (@see
|
||||
/// param_set_no_notification())
|
||||
bool commit_no_notification() const { return param_set_no_notification(handle(), &_val) == 0; }
|
||||
|
||||
/// Set and commit a new value. Returns true if the value changed.
|
||||
bool commit_no_notification(float val)
|
||||
{
|
||||
bool commit_no_notification(float val) {
|
||||
if (fabsf(val - _val) > FLT_EPSILON) {
|
||||
set(val);
|
||||
commit_no_notification();
|
||||
@@ -198,8 +180,7 @@ public:
|
||||
|
||||
void set(float val) { _val = val; }
|
||||
|
||||
void reset()
|
||||
{
|
||||
void reset() {
|
||||
param_reset_no_notification(handle());
|
||||
update();
|
||||
}
|
||||
@@ -207,19 +188,18 @@ public:
|
||||
bool update() { return param_get(handle(), &_val) == 0; }
|
||||
|
||||
param_t handle() const { return param_handle(p); }
|
||||
|
||||
private:
|
||||
float &_val;
|
||||
};
|
||||
|
||||
template<px4::params p>
|
||||
class Param<int32_t, p>
|
||||
{
|
||||
template <px4::params p>
|
||||
class Param<int32_t, p> {
|
||||
public:
|
||||
// static type-check
|
||||
static_assert(px4::parameters_type[(int)p] == PARAM_TYPE_INT32, "parameter type must be int32_t");
|
||||
|
||||
Param()
|
||||
{
|
||||
Param() {
|
||||
param_set_used(handle());
|
||||
update();
|
||||
}
|
||||
@@ -231,12 +211,12 @@ public:
|
||||
/// Store the parameter value to the parameter storage (@see param_set())
|
||||
bool commit() const { return param_set(handle(), &_val) == 0; }
|
||||
|
||||
/// Store the parameter value to the parameter storage, w/o notifying the system (@see param_set_no_notification())
|
||||
/// Store the parameter value to the parameter storage, w/o notifying the system (@see
|
||||
/// param_set_no_notification())
|
||||
bool commit_no_notification() const { return param_set_no_notification(handle(), &_val) == 0; }
|
||||
|
||||
/// Set and commit a new value. Returns true if the value changed.
|
||||
bool commit_no_notification(int32_t val)
|
||||
{
|
||||
bool commit_no_notification(int32_t val) {
|
||||
if (val != _val) {
|
||||
set(val);
|
||||
commit_no_notification();
|
||||
@@ -248,8 +228,7 @@ public:
|
||||
|
||||
void set(int32_t val) { _val = val; }
|
||||
|
||||
void reset()
|
||||
{
|
||||
void reset() {
|
||||
param_reset_no_notification(handle());
|
||||
update();
|
||||
}
|
||||
@@ -257,21 +236,19 @@ public:
|
||||
bool update() { return param_get(handle(), &_val) == 0; }
|
||||
|
||||
param_t handle() const { return param_handle(p); }
|
||||
|
||||
private:
|
||||
int32_t _val;
|
||||
};
|
||||
|
||||
//external version
|
||||
template<px4::params p>
|
||||
class Param<int32_t &, p>
|
||||
{
|
||||
// external version
|
||||
template <px4::params p>
|
||||
class Param<int32_t &, p> {
|
||||
public:
|
||||
// static type-check
|
||||
static_assert(px4::parameters_type[(int)p] == PARAM_TYPE_INT32, "parameter type must be int32_t");
|
||||
|
||||
Param(int32_t &external_val)
|
||||
: _val(external_val)
|
||||
{
|
||||
Param(int32_t &external_val) : _val(external_val) {
|
||||
param_set_used(handle());
|
||||
update();
|
||||
}
|
||||
@@ -283,12 +260,12 @@ public:
|
||||
/// Store the parameter value to the parameter storage (@see param_set())
|
||||
bool commit() const { return param_set(handle(), &_val) == 0; }
|
||||
|
||||
/// Store the parameter value to the parameter storage, w/o notifying the system (@see param_set_no_notification())
|
||||
/// Store the parameter value to the parameter storage, w/o notifying the system (@see
|
||||
/// param_set_no_notification())
|
||||
bool commit_no_notification() const { return param_set_no_notification(handle(), &_val) == 0; }
|
||||
|
||||
/// Set and commit a new value. Returns true if the value changed.
|
||||
bool commit_no_notification(int32_t val)
|
||||
{
|
||||
bool commit_no_notification(int32_t val) {
|
||||
if (val != _val) {
|
||||
set(val);
|
||||
commit_no_notification();
|
||||
@@ -300,8 +277,7 @@ public:
|
||||
|
||||
void set(int32_t val) { _val = val; }
|
||||
|
||||
void reset()
|
||||
{
|
||||
void reset() {
|
||||
param_reset_no_notification(handle());
|
||||
update();
|
||||
}
|
||||
@@ -309,19 +285,18 @@ public:
|
||||
bool update() { return param_get(handle(), &_val) == 0; }
|
||||
|
||||
param_t handle() const { return param_handle(p); }
|
||||
|
||||
private:
|
||||
int32_t &_val;
|
||||
};
|
||||
|
||||
template<px4::params p>
|
||||
class Param<bool, p>
|
||||
{
|
||||
template <px4::params p>
|
||||
class Param<bool, p> {
|
||||
public:
|
||||
// static type-check
|
||||
static_assert(px4::parameters_type[(int)p] == PARAM_TYPE_INT32, "parameter type must be int32_t");
|
||||
|
||||
Param()
|
||||
{
|
||||
Param() {
|
||||
param_set_used(handle());
|
||||
update();
|
||||
}
|
||||
@@ -331,22 +306,20 @@ public:
|
||||
const bool &reference() const { return _val; }
|
||||
|
||||
/// Store the parameter value to the parameter storage (@see param_set())
|
||||
bool commit() const
|
||||
{
|
||||
bool commit() const {
|
||||
int32_t value_int = (int32_t)_val;
|
||||
return param_set(handle(), &value_int) == 0;
|
||||
}
|
||||
|
||||
/// Store the parameter value to the parameter storage, w/o notifying the system (@see param_set_no_notification())
|
||||
bool commit_no_notification() const
|
||||
{
|
||||
/// Store the parameter value to the parameter storage, w/o notifying the system (@see
|
||||
/// param_set_no_notification())
|
||||
bool commit_no_notification() const {
|
||||
int32_t value_int = (int32_t)_val;
|
||||
return param_set_no_notification(handle(), &value_int) == 0;
|
||||
}
|
||||
|
||||
/// Set and commit a new value. Returns true if the value changed.
|
||||
bool commit_no_notification(bool val)
|
||||
{
|
||||
bool commit_no_notification(bool val) {
|
||||
if (val != _val) {
|
||||
set(val);
|
||||
commit_no_notification();
|
||||
@@ -358,14 +331,12 @@ public:
|
||||
|
||||
void set(bool val) { _val = val; }
|
||||
|
||||
void reset()
|
||||
{
|
||||
void reset() {
|
||||
param_reset_no_notification(handle());
|
||||
update();
|
||||
}
|
||||
|
||||
bool update()
|
||||
{
|
||||
bool update() {
|
||||
int32_t value_int;
|
||||
int ret = param_get(handle(), &value_int);
|
||||
|
||||
@@ -378,6 +349,7 @@ public:
|
||||
}
|
||||
|
||||
param_t handle() const { return param_handle(p); }
|
||||
|
||||
private:
|
||||
bool _val;
|
||||
};
|
||||
@@ -399,15 +371,12 @@ using ParamBool = Param<bool, p>;
|
||||
|
||||
} /* namespace do_not_explicitly_use_this_namespace */
|
||||
|
||||
|
||||
// Raise an appropriate compile error if a Param class is used directly (just to simplify debugging)
|
||||
template<px4::params p>
|
||||
class ParamInt
|
||||
{
|
||||
static_assert((int)p &&false, "Do not use this class directly, use the DEFINE_PARAMETERS macro instead");
|
||||
template <px4::params p>
|
||||
class ParamInt {
|
||||
static_assert((int)p && false, "Do not use this class directly, use the DEFINE_PARAMETERS macro instead");
|
||||
};
|
||||
template<px4::params p>
|
||||
class ParamFloat
|
||||
{
|
||||
static_assert((int)p &&false, "Do not use this class directly, use the DEFINE_PARAMETERS macro instead");
|
||||
template <px4::params p>
|
||||
class ParamFloat {
|
||||
static_assert((int)p && false, "Do not use this class directly, use the DEFINE_PARAMETERS macro instead");
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -39,11 +39,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <px4_platform_common/defines.h>
|
||||
#include <px4_platform_common/tasks.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#if defined(__PX4_QURT)
|
||||
#include <dspal_types.h>
|
||||
@@ -53,8 +53,8 @@
|
||||
|
||||
#include "sem.h"
|
||||
|
||||
#define PX4_F_RDONLY 1
|
||||
#define PX4_F_WRONLY 2
|
||||
#define PX4_F_RDONLY 1
|
||||
#define PX4_F_WRONLY 2
|
||||
|
||||
#ifdef __PX4_NUTTX
|
||||
|
||||
@@ -68,20 +68,20 @@ typedef pollevent_t px4_pollevent_t;
|
||||
#else
|
||||
#define _GLOBAL
|
||||
#endif
|
||||
#define px4_open _GLOBAL open
|
||||
#define px4_close _GLOBAL close
|
||||
#define px4_ioctl _GLOBAL ioctl
|
||||
#define px4_write _GLOBAL write
|
||||
#define px4_read _GLOBAL read
|
||||
#define px4_poll _GLOBAL poll
|
||||
#define px4_access _GLOBAL access
|
||||
#define px4_getpid _GLOBAL getpid
|
||||
#define px4_open _GLOBAL open
|
||||
#define px4_close _GLOBAL close
|
||||
#define px4_ioctl _GLOBAL ioctl
|
||||
#define px4_write _GLOBAL write
|
||||
#define px4_read _GLOBAL read
|
||||
#define px4_poll _GLOBAL poll
|
||||
#define px4_access _GLOBAL access
|
||||
#define px4_getpid _GLOBAL getpid
|
||||
|
||||
#define PX4_STACK_OVERHEAD 0
|
||||
#define PX4_STACK_OVERHEAD 0
|
||||
|
||||
#elif defined(__PX4_POSIX)
|
||||
|
||||
#define PX4_STACK_OVERHEAD (1024 * 24)
|
||||
#define PX4_STACK_OVERHEAD (1024 * 24)
|
||||
|
||||
#define px4_cache_aligned_data()
|
||||
#define px4_cache_aligned_alloc malloc
|
||||
@@ -92,34 +92,33 @@ typedef short px4_pollevent_t;
|
||||
|
||||
typedef struct {
|
||||
/* This part of the struct is POSIX-like */
|
||||
int fd; /* The descriptor being polled */
|
||||
px4_pollevent_t events; /* The input event flags */
|
||||
px4_pollevent_t revents; /* The output event flags */
|
||||
int fd; /* The descriptor being polled */
|
||||
px4_pollevent_t events; /* The input event flags */
|
||||
px4_pollevent_t revents; /* The output event flags */
|
||||
|
||||
/* Required for PX4 compatibility */
|
||||
px4_sem_t *sem; /* Pointer to semaphore used to post output event */
|
||||
void *priv; /* For use by drivers */
|
||||
px4_sem_t *sem; /* Pointer to semaphore used to post output event */
|
||||
void *priv; /* For use by drivers */
|
||||
} px4_pollfd_struct_t;
|
||||
|
||||
#ifndef POLLIN
|
||||
#define POLLIN (0x01)
|
||||
#define POLLIN (0x01)
|
||||
#endif
|
||||
|
||||
__EXPORT int px4_open(const char *path, int flags, ...);
|
||||
__EXPORT int px4_close(int fd);
|
||||
__EXPORT ssize_t px4_read(int fd, void *buffer, size_t buflen);
|
||||
__EXPORT ssize_t px4_write(int fd, const void *buffer, size_t buflen);
|
||||
__EXPORT int px4_ioctl(int fd, int cmd, unsigned long arg);
|
||||
__EXPORT int px4_poll(px4_pollfd_struct_t *fds, unsigned int nfds, int timeout);
|
||||
__EXPORT int px4_access(const char *pathname, int mode);
|
||||
__EXPORT px4_task_t px4_getpid(void);
|
||||
__EXPORT int px4_open(const char *path, int flags, ...);
|
||||
__EXPORT int px4_close(int fd);
|
||||
__EXPORT ssize_t px4_read(int fd, void *buffer, size_t buflen);
|
||||
__EXPORT ssize_t px4_write(int fd, const void *buffer, size_t buflen);
|
||||
__EXPORT int px4_ioctl(int fd, int cmd, unsigned long arg);
|
||||
__EXPORT int px4_poll(px4_pollfd_struct_t *fds, unsigned int nfds, int timeout);
|
||||
__EXPORT int px4_access(const char *pathname, int mode);
|
||||
__EXPORT px4_task_t px4_getpid(void);
|
||||
|
||||
__END_DECLS
|
||||
#else
|
||||
#error "No TARGET OS Provided"
|
||||
#endif
|
||||
|
||||
|
||||
// The stack size is intended for 32-bit architectures; therefore
|
||||
// we often run out of stack space when pointers are larger than 4 bytes.
|
||||
// Double the stack size on posix when we're on a 64-bit architecture.
|
||||
@@ -128,6 +127,6 @@ __END_DECLS
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
__EXPORT void px4_show_files(void);
|
||||
__EXPORT void px4_show_files(void);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef CONFIG_FS_PROCFS_MAX_TASKS
|
||||
@@ -57,7 +56,7 @@ struct print_load_s {
|
||||
|
||||
uint64_t new_time{0};
|
||||
uint64_t interval_start_time{0};
|
||||
uint64_t last_times[CONFIG_FS_PROCFS_MAX_TASKS] {};
|
||||
uint64_t last_times[CONFIG_FS_PROCFS_MAX_TASKS]{};
|
||||
float interval_time_us{0.f};
|
||||
};
|
||||
|
||||
@@ -67,7 +66,6 @@ __EXPORT void init_print_load(struct print_load_s *s);
|
||||
|
||||
__EXPORT void print_load(int fd, struct print_load_s *print_state);
|
||||
|
||||
|
||||
typedef void (*print_load_callback_f)(void *user);
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,16 +41,18 @@
|
||||
|
||||
#if defined(__PX4_NUTTX)
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <board_config.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include "micro_hal.h"
|
||||
#include <board_config.h>
|
||||
|
||||
#elif defined (__PX4_POSIX)
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include "micro_hal.h"
|
||||
|
||||
#elif defined(__PX4_POSIX)
|
||||
|
||||
#include <board_config.h>
|
||||
|
||||
#include "micro_hal.h"
|
||||
|
||||
#endif
|
||||
|
||||
/* PX4 board kconfig symbols */
|
||||
|
||||
@@ -33,18 +33,15 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
MFT = 0,
|
||||
MTD = 1,
|
||||
LAST_MFT_TYPE
|
||||
} px4_manifest_types_e;
|
||||
typedef enum { MFT = 0, MTD = 1, LAST_MFT_TYPE } px4_manifest_types_e;
|
||||
|
||||
/* must match px4_manifest_types_e */
|
||||
#define PX4_MFT_TYPES {MFT, MTD}
|
||||
#define PX4_MFT_STR_TYPES {"MFT", "MTD"}
|
||||
|
||||
typedef struct {
|
||||
#define PX4_MFT_TYPES \
|
||||
{ MFT, MTD }
|
||||
#define PX4_MFT_STR_TYPES \
|
||||
{ "MFT", "MTD" }
|
||||
|
||||
typedef struct {
|
||||
enum px4_bus_type {
|
||||
I2C = 0,
|
||||
SPI = 1,
|
||||
@@ -54,23 +51,22 @@ typedef struct {
|
||||
uint32_t devid;
|
||||
} px4_mft_device_t;
|
||||
|
||||
#define PX4_MK_I2C_DEVID(b,a) ((b) << 16 | ((a) & 0xffff))
|
||||
#define PX4_I2C_DEVID_BUS(d) (((d) >> 16) & 0xffff)
|
||||
#define PX4_I2C_DEVID_ADDR(d) ((d) & 0xffff)
|
||||
#define PX4_MK_I2C_DEVID(b, a) ((b) << 16 | ((a)&0xffff))
|
||||
#define PX4_I2C_DEVID_BUS(d) (((d) >> 16) & 0xffff)
|
||||
#define PX4_I2C_DEVID_ADDR(d) ((d)&0xffff)
|
||||
|
||||
typedef struct {
|
||||
const px4_manifest_types_e type;
|
||||
const void *pmft;
|
||||
const void *pmft;
|
||||
} px4_mft_entry_s;
|
||||
|
||||
typedef struct {
|
||||
const uint32_t nmft;
|
||||
const uint32_t nmft;
|
||||
const px4_mft_entry_s *mfts;
|
||||
} px4_mft_s;
|
||||
|
||||
#include "px4_platform_common/mtd_manifest.h"
|
||||
|
||||
|
||||
__BEGIN_DECLS
|
||||
/************************************************************************************
|
||||
* Name: board_get_manifest
|
||||
@@ -120,6 +116,5 @@ __EXPORT int px4_mft_configure(const px4_mft_s *mft);
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
__EXPORT int px4_mft_query(const px4_mft_s *mft, px4_manifest_types_e type,
|
||||
const char *sub, const char *val);
|
||||
__EXPORT int px4_mft_query(const px4_mft_s *mft, px4_manifest_types_e type, const char *sub, const char *val);
|
||||
__END_DECLS
|
||||
|
||||
@@ -39,12 +39,12 @@ __BEGIN_DECLS
|
||||
|
||||
typedef struct {
|
||||
struct mtd_dev_s *mtd_dev;
|
||||
int *partition_block_counts;
|
||||
int *partition_types;
|
||||
const char **partition_names;
|
||||
int *partition_block_counts;
|
||||
int *partition_types;
|
||||
const char **partition_names;
|
||||
struct mtd_dev_s **part_dev;
|
||||
uint32_t devid;
|
||||
unsigned n_partitions_current;
|
||||
uint32_t devid;
|
||||
unsigned n_partitions_current;
|
||||
} mtd_instance_s;
|
||||
|
||||
/*
|
||||
@@ -66,16 +66,14 @@ __EXPORT mtd_instance_s *px4_mtd_get_instances(unsigned int *count);
|
||||
Get device complete geometry or a device
|
||||
*/
|
||||
|
||||
|
||||
__EXPORT int px4_mtd_get_geometry(const mtd_instance_s *instance, unsigned long *blocksize, unsigned long *erasesize,
|
||||
unsigned long *neraseblocks, unsigned *blkpererase, unsigned *nblocks,
|
||||
unsigned *partsize);
|
||||
__EXPORT int px4_mtd_get_geometry(const mtd_instance_s *instance, unsigned long *blocksize, unsigned long *erasesize,
|
||||
unsigned long *neraseblocks, unsigned *blkpererase, unsigned *nblocks,
|
||||
unsigned *partsize);
|
||||
/*
|
||||
Get size of a parttion on an instance.
|
||||
*/
|
||||
__EXPORT ssize_t px4_mtd_get_partition_size(const mtd_instance_s *instance, const char *partname);
|
||||
|
||||
FAR struct mtd_dev_s *px4_at24c_initialize(FAR struct i2c_master_s *dev,
|
||||
uint8_t address);
|
||||
FAR struct mtd_dev_s *px4_at24c_initialize(FAR struct i2c_master_s *dev, uint8_t address);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
@@ -33,17 +33,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "WorkItem.hpp"
|
||||
|
||||
#include <drivers/drv_hrt.h>
|
||||
|
||||
namespace px4
|
||||
{
|
||||
#include "WorkItem.hpp"
|
||||
|
||||
class ScheduledWorkItem : public WorkItem
|
||||
{
|
||||
namespace px4 {
|
||||
|
||||
class ScheduledWorkItem : public WorkItem {
|
||||
public:
|
||||
|
||||
bool Scheduled() { return !hrt_called(&_call); }
|
||||
|
||||
/**
|
||||
@@ -74,19 +71,17 @@ public:
|
||||
void ScheduleClear();
|
||||
|
||||
protected:
|
||||
|
||||
ScheduledWorkItem(const char *name, const wq_config_t &config) : WorkItem(name, config) {}
|
||||
virtual ~ScheduledWorkItem() override;
|
||||
|
||||
virtual void print_run_status() override;
|
||||
|
||||
private:
|
||||
|
||||
virtual void Run() override = 0;
|
||||
|
||||
static void schedule_trampoline(void *arg);
|
||||
static void schedule_trampoline(void *arg);
|
||||
|
||||
hrt_call _call{};
|
||||
hrt_call _call{};
|
||||
};
|
||||
|
||||
} // namespace px4
|
||||
} // namespace px4
|
||||
|
||||
@@ -33,25 +33,22 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "WorkQueueManager.hpp"
|
||||
#include "WorkQueue.hpp"
|
||||
|
||||
#include <containers/IntrusiveQueue.hpp>
|
||||
#include <containers/IntrusiveSortedList.hpp>
|
||||
#include <px4_platform_common/defines.h>
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <lib/mathlib/mathlib.h>
|
||||
#include <lib/perf/perf_counter.h>
|
||||
|
||||
#include <px4_platform_common/defines.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace px4
|
||||
{
|
||||
#include <containers/IntrusiveQueue.hpp>
|
||||
#include <containers/IntrusiveSortedList.hpp>
|
||||
|
||||
class WorkItem : public IntrusiveSortedListNode<WorkItem *>, public IntrusiveQueueNode<WorkItem *>
|
||||
{
|
||||
#include "WorkQueue.hpp"
|
||||
#include "WorkQueueManager.hpp"
|
||||
|
||||
namespace px4 {
|
||||
|
||||
class WorkItem : public IntrusiveSortedListNode<WorkItem *>, public IntrusiveQueueNode<WorkItem *> {
|
||||
public:
|
||||
|
||||
WorkItem() = delete;
|
||||
|
||||
// no copy, assignment, move, move assignment
|
||||
@@ -63,8 +60,7 @@ public:
|
||||
// WorkItems sorted by name
|
||||
bool operator<=(const WorkItem &rhs) const { return (strcmp(ItemName(), rhs.ItemName()) <= 0); }
|
||||
|
||||
inline void ScheduleNow()
|
||||
{
|
||||
inline void ScheduleNow() {
|
||||
if (_wq != nullptr) {
|
||||
_wq->Add(this);
|
||||
}
|
||||
@@ -84,7 +80,6 @@ public:
|
||||
const char *ItemName() const { return _item_name; }
|
||||
|
||||
protected:
|
||||
|
||||
explicit WorkItem(const char *name, const wq_config_t &config);
|
||||
|
||||
explicit WorkItem(const char *name, const WorkItem &work_item);
|
||||
@@ -95,10 +90,9 @@ protected:
|
||||
* Remove work item from the runnable queue, if it's there
|
||||
*/
|
||||
void ScheduleClear();
|
||||
protected:
|
||||
|
||||
void RunPreamble()
|
||||
{
|
||||
protected:
|
||||
void RunPreamble() {
|
||||
if (_run_count == 0) {
|
||||
_time_first_run = hrt_absolute_time();
|
||||
_run_count = 1;
|
||||
@@ -126,14 +120,12 @@ protected:
|
||||
float average_rate() const;
|
||||
float average_interval() const;
|
||||
|
||||
hrt_abstime _time_first_run{0};
|
||||
const char *_item_name;
|
||||
uint32_t _run_count{0};
|
||||
hrt_abstime _time_first_run{0};
|
||||
const char *_item_name;
|
||||
uint32_t _run_count{0};
|
||||
|
||||
private:
|
||||
|
||||
WorkQueue *_wq{nullptr};
|
||||
|
||||
WorkQueue *_wq{nullptr};
|
||||
};
|
||||
|
||||
} // namespace px4
|
||||
} // namespace px4
|
||||
|
||||
@@ -33,11 +33,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "WorkItem.hpp"
|
||||
#include <px4_platform_common/sem.h>
|
||||
|
||||
namespace px4
|
||||
{
|
||||
#include "WorkItem.hpp"
|
||||
|
||||
namespace px4 {
|
||||
|
||||
/**
|
||||
* @class WorkItemSingleShot
|
||||
@@ -47,8 +47,7 @@ namespace px4
|
||||
* initializer.ScheduleNow();
|
||||
* initializer.wait();
|
||||
*/
|
||||
class WorkItemSingleShot : public px4::WorkItem
|
||||
{
|
||||
class WorkItemSingleShot : public px4::WorkItem {
|
||||
public:
|
||||
using worker_method = void (*)(void *arg);
|
||||
|
||||
@@ -66,12 +65,14 @@ public:
|
||||
WorkItemSingleShot &operator=(WorkItemSingleShot &&) = delete;
|
||||
|
||||
void wait();
|
||||
|
||||
protected:
|
||||
void Run() override;
|
||||
|
||||
private:
|
||||
void *_argument;
|
||||
worker_method _method;
|
||||
px4_sem_t _sem;
|
||||
};
|
||||
|
||||
} // namespace px4
|
||||
} // namespace px4
|
||||
|
||||
@@ -33,23 +33,22 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "WorkQueueManager.hpp"
|
||||
|
||||
#include <containers/BlockingList.hpp>
|
||||
#include <containers/List.hpp>
|
||||
#include <containers/IntrusiveQueue.hpp>
|
||||
#include <px4_platform_common/atomic.h>
|
||||
#include <px4_platform_common/defines.h>
|
||||
#include <px4_platform_common/sem.h>
|
||||
#include <px4_platform_common/tasks.h>
|
||||
|
||||
namespace px4
|
||||
{
|
||||
#include <containers/BlockingList.hpp>
|
||||
#include <containers/IntrusiveQueue.hpp>
|
||||
#include <containers/List.hpp>
|
||||
|
||||
#include "WorkQueueManager.hpp"
|
||||
|
||||
namespace px4 {
|
||||
|
||||
class WorkItem;
|
||||
|
||||
class WorkQueue : public IntrusiveSortedListNode<WorkQueue *>
|
||||
{
|
||||
class WorkQueue : public IntrusiveSortedListNode<WorkQueue *> {
|
||||
public:
|
||||
explicit WorkQueue(const wq_config_t &wq_config);
|
||||
WorkQueue() = delete;
|
||||
@@ -74,10 +73,11 @@ public:
|
||||
void print_status(bool last = false);
|
||||
|
||||
// WorkQueues sorted numerically by relative priority (-1 to -255)
|
||||
bool operator<=(const WorkQueue &rhs) const { return _config.relative_priority >= rhs.get_config().relative_priority; }
|
||||
bool operator<=(const WorkQueue &rhs) const {
|
||||
return _config.relative_priority >= rhs.get_config().relative_priority;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
bool should_exit() const { return _should_exit.load(); }
|
||||
|
||||
inline void SignalWorkerThread();
|
||||
@@ -89,22 +89,24 @@ private:
|
||||
irqstate_t _flags;
|
||||
#else
|
||||
// loop as the wait may be interrupted by a signal
|
||||
void work_lock() { do {} while (px4_sem_wait(&_qlock) != 0); }
|
||||
void work_lock() {
|
||||
do {
|
||||
} while (px4_sem_wait(&_qlock) != 0);
|
||||
}
|
||||
void work_unlock() { px4_sem_post(&_qlock); }
|
||||
px4_sem_t _qlock;
|
||||
#endif
|
||||
|
||||
IntrusiveQueue<WorkItem *> _q;
|
||||
px4_sem_t _process_lock;
|
||||
px4_sem_t _exit_lock;
|
||||
const wq_config_t &_config;
|
||||
BlockingList<WorkItem *> _work_items;
|
||||
px4::atomic_bool _should_exit{false};
|
||||
IntrusiveQueue<WorkItem *> _q;
|
||||
px4_sem_t _process_lock;
|
||||
px4_sem_t _exit_lock;
|
||||
const wq_config_t &_config;
|
||||
BlockingList<WorkItem *> _work_items;
|
||||
px4::atomic_bool _should_exit{false};
|
||||
|
||||
#if defined(ENABLE_LOCKSTEP_SCHEDULER)
|
||||
int _lockstep_component {-1};
|
||||
#endif // ENABLE_LOCKSTEP_SCHEDULER
|
||||
|
||||
int _lockstep_component{-1};
|
||||
#endif // ENABLE_LOCKSTEP_SCHEDULER
|
||||
};
|
||||
|
||||
} // namespace px4
|
||||
} // namespace px4
|
||||
|
||||
@@ -35,20 +35,18 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace px4
|
||||
{
|
||||
namespace px4 {
|
||||
|
||||
class WorkQueue; // forward declaration
|
||||
class WorkQueue; // forward declaration
|
||||
|
||||
struct wq_config_t {
|
||||
const char *name;
|
||||
uint16_t stacksize;
|
||||
int8_t relative_priority; // relative to max
|
||||
int8_t relative_priority; // relative to max
|
||||
};
|
||||
|
||||
namespace wq_configurations
|
||||
{
|
||||
static constexpr wq_config_t rate_ctrl{"wq:rate_ctrl", 3150, 0}; // PX4 inner loop highest priority
|
||||
namespace wq_configurations {
|
||||
static constexpr wq_config_t rate_ctrl{"wq:rate_ctrl", 3150, 0}; // PX4 inner loop highest priority
|
||||
|
||||
static constexpr wq_config_t SPI0{"wq:SPI0", 2336, -1};
|
||||
static constexpr wq_config_t SPI1{"wq:SPI1", 2336, -2};
|
||||
@@ -94,7 +92,7 @@ static constexpr wq_config_t lp_default{"wq:lp_default", 1920, -50};
|
||||
static constexpr wq_config_t test1{"wq:test1", 2000, 0};
|
||||
static constexpr wq_config_t test2{"wq:test2", 2000, 0};
|
||||
|
||||
} // namespace wq_configurations
|
||||
} // namespace wq_configurations
|
||||
|
||||
/**
|
||||
* Start the work queue manager task.
|
||||
@@ -137,5 +135,4 @@ const wq_config_t &serial_port_to_wq(const char *serial);
|
||||
|
||||
const wq_config_t &ins_instance_to_wq(uint8_t instance);
|
||||
|
||||
|
||||
} // namespace px4
|
||||
} // namespace px4
|
||||
|
||||
@@ -44,10 +44,10 @@
|
||||
#if !defined(__PX4_NUTTX)
|
||||
/* Values for protocol attribute */
|
||||
|
||||
#define SEM_PRIO_NONE 0
|
||||
#define SEM_PRIO_INHERIT 1
|
||||
#define SEM_PRIO_PROTECT 2
|
||||
#define sem_setprotocol(s,p)
|
||||
#define SEM_PRIO_NONE 0
|
||||
#define SEM_PRIO_INHERIT 1
|
||||
#define SEM_PRIO_PROTECT 2
|
||||
#define sem_setprotocol(s, p)
|
||||
#endif
|
||||
|
||||
#if (defined(__PX4_DARWIN) || defined(__PX4_CYGWIN) || defined(__PX4_POSIX)) && !defined(__PX4_QURT)
|
||||
@@ -60,20 +60,20 @@ typedef struct {
|
||||
int value;
|
||||
} px4_sem_t;
|
||||
|
||||
__EXPORT int px4_sem_init(px4_sem_t *s, int pshared, unsigned value);
|
||||
__EXPORT int px4_sem_setprotocol(px4_sem_t *s, int protocol);
|
||||
__EXPORT int px4_sem_wait(px4_sem_t *s);
|
||||
__EXPORT int px4_sem_trywait(px4_sem_t *sem);
|
||||
__EXPORT int px4_sem_timedwait(px4_sem_t *sem, const struct timespec *abstime);
|
||||
__EXPORT int px4_sem_post(px4_sem_t *s);
|
||||
__EXPORT int px4_sem_getvalue(px4_sem_t *s, int *sval);
|
||||
__EXPORT int px4_sem_destroy(px4_sem_t *s);
|
||||
__EXPORT int px4_sem_init(px4_sem_t *s, int pshared, unsigned value);
|
||||
__EXPORT int px4_sem_setprotocol(px4_sem_t *s, int protocol);
|
||||
__EXPORT int px4_sem_wait(px4_sem_t *s);
|
||||
__EXPORT int px4_sem_trywait(px4_sem_t *sem);
|
||||
__EXPORT int px4_sem_timedwait(px4_sem_t *sem, const struct timespec *abstime);
|
||||
__EXPORT int px4_sem_post(px4_sem_t *s);
|
||||
__EXPORT int px4_sem_getvalue(px4_sem_t *s, int *sval);
|
||||
__EXPORT int px4_sem_destroy(px4_sem_t *s);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
//#elif defined(__PX4_QURT)
|
||||
|
||||
//typedef sem_t px4_sem_t;
|
||||
// typedef sem_t px4_sem_t;
|
||||
|
||||
//#define px4_sem_init sem_init
|
||||
//#define px4_sem_setprotocol sem_setprotocol
|
||||
@@ -89,18 +89,18 @@ typedef sem_t px4_sem_t;
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define px4_sem_init sem_init
|
||||
#define px4_sem_setprotocol sem_setprotocol
|
||||
#define px4_sem_wait sem_wait
|
||||
#define px4_sem_trywait sem_trywait
|
||||
#define px4_sem_post sem_post
|
||||
#define px4_sem_getvalue sem_getvalue
|
||||
#define px4_sem_destroy sem_destroy
|
||||
#define px4_sem_init sem_init
|
||||
#define px4_sem_setprotocol sem_setprotocol
|
||||
#define px4_sem_wait sem_wait
|
||||
#define px4_sem_trywait sem_trywait
|
||||
#define px4_sem_post sem_post
|
||||
#define px4_sem_getvalue sem_getvalue
|
||||
#define px4_sem_destroy sem_destroy
|
||||
|
||||
#if defined(__PX4_QURT)
|
||||
__EXPORT int px4_sem_timedwait(px4_sem_t *sem, const struct timespec *abstime);
|
||||
__EXPORT int px4_sem_timedwait(px4_sem_t *sem, const struct timespec *abstime);
|
||||
#else
|
||||
#define px4_sem_timedwait sem_timedwait
|
||||
#define px4_sem_timedwait sem_timedwait
|
||||
#endif
|
||||
|
||||
__END_DECLS
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
|
||||
#include "sem.h"
|
||||
|
||||
|
||||
/**
|
||||
* @class Smart locking object that uses a semaphore. It automatically
|
||||
* takes the lock when created and releases the lock when the object goes out of
|
||||
@@ -58,11 +57,14 @@
|
||||
* //critical section end
|
||||
* }
|
||||
*/
|
||||
class SmartLock
|
||||
{
|
||||
class SmartLock {
|
||||
public:
|
||||
SmartLock(px4_sem_t &sem) : _sem(sem) { do {} while (px4_sem_wait(&_sem) != 0); }
|
||||
SmartLock(px4_sem_t &sem) : _sem(sem) {
|
||||
do {
|
||||
} while (px4_sem_wait(&_sem) != 0);
|
||||
}
|
||||
~SmartLock() { px4_sem_post(&_sem); }
|
||||
|
||||
private:
|
||||
px4_sem_t &_sem;
|
||||
};
|
||||
|
||||
@@ -38,10 +38,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <inttypes.h>
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
@@ -51,7 +50,6 @@ __BEGIN_DECLS
|
||||
*/
|
||||
typedef bool (*shutdown_hook_t)(void);
|
||||
|
||||
|
||||
/**
|
||||
* Register a method that should be called when powering off (and also on reboot).
|
||||
* @param hook callback method. It must not block, but return immediately.
|
||||
@@ -62,7 +60,6 @@ typedef bool (*shutdown_hook_t)(void);
|
||||
*/
|
||||
__EXPORT int px4_register_shutdown_hook(shutdown_hook_t hook);
|
||||
|
||||
|
||||
/**
|
||||
* Unregister a shutdown hook
|
||||
* @param hook callback method to be removed
|
||||
@@ -70,7 +67,6 @@ __EXPORT int px4_register_shutdown_hook(shutdown_hook_t hook);
|
||||
*/
|
||||
__EXPORT int px4_unregister_shutdown_hook(shutdown_hook_t hook);
|
||||
|
||||
|
||||
/**
|
||||
* Request the system to reboot.
|
||||
* Note the following:
|
||||
@@ -84,8 +80,7 @@ __EXPORT int px4_unregister_shutdown_hook(shutdown_hook_t hook);
|
||||
*/
|
||||
#if defined(CONFIG_BOARDCTL_RESET)
|
||||
__EXPORT int px4_reboot_request(bool to_bootloader = false, uint32_t delay_us = 0);
|
||||
#endif // CONFIG_BOARDCTL_RESET
|
||||
|
||||
#endif // CONFIG_BOARDCTL_RESET
|
||||
|
||||
/**
|
||||
* Request the system to shut down or reboot.
|
||||
@@ -99,8 +94,7 @@ __EXPORT int px4_reboot_request(bool to_bootloader = false, uint32_t delay_us =
|
||||
*/
|
||||
#if defined(BOARD_HAS_POWER_CONTROL) || defined(__PX4_POSIX)
|
||||
__EXPORT int px4_shutdown_request(uint32_t delay_us = 0);
|
||||
#endif // BOARD_HAS_POWER_CONTROL
|
||||
|
||||
#endif // BOARD_HAS_POWER_CONTROL
|
||||
|
||||
/**
|
||||
* Grab the shutdown lock. It will prevent the system from shutting down until the lock is released.
|
||||
@@ -109,12 +103,10 @@ __EXPORT int px4_shutdown_request(uint32_t delay_us = 0);
|
||||
*/
|
||||
__EXPORT int px4_shutdown_lock(void);
|
||||
|
||||
|
||||
/**
|
||||
* Release the shutdown lock.
|
||||
* @return 0 on success, <0 on error
|
||||
*/
|
||||
__EXPORT int px4_shutdown_unlock(void);
|
||||
|
||||
|
||||
__END_DECLS
|
||||
|
||||
@@ -33,29 +33,32 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <board_config.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(CONFIG_SPI)
|
||||
|
||||
/*
|
||||
* Helper macros to handle device ID's. They are used to match drivers against SPI buses and chip-select signals.
|
||||
* They match with corresponding definitions in NuttX.
|
||||
* 'type' is typically PX4_SPI_DEVICE_ID for PX4 drivers, and 'index' is used for the driver (DRV_*) or chip-select index.
|
||||
* 'type' is typically PX4_SPI_DEVICE_ID for PX4 drivers, and 'index' is used for the driver (DRV_*) or chip-select
|
||||
* index.
|
||||
*/
|
||||
#define PX4_SPIDEV_ID(type, index) ((((type) & 0xffff) << 16) | ((index) & 0xffff))
|
||||
#define PX4_SPI_DEVICE_ID (1 << 12)
|
||||
#define PX4_SPI_DEV_ID(devid) ((devid) & 0xffff)
|
||||
#define PX4_SPIDEV_ID(type, index) ((((type)&0xffff) << 16) | ((index)&0xffff))
|
||||
#define PX4_SPI_DEVICE_ID (1 << 12)
|
||||
#define PX4_SPI_DEV_ID(devid) ((devid)&0xffff)
|
||||
#define PX4_SPIDEVID_TYPE(devid) (((uint32_t)(devid) >> 16) & 0xffff)
|
||||
|
||||
typedef uint32_t spi_drdy_gpio_t;
|
||||
|
||||
#define SPI_BUS_MAX_DEVICES 6
|
||||
struct px4_spi_bus_device_t {
|
||||
uint32_t cs_gpio; ///< chip-select GPIO (0 if this device is not used)
|
||||
spi_drdy_gpio_t drdy_gpio; ///< data ready GPIO (0 if not set)
|
||||
uint32_t devid; ///< SPIDEV_ID(type,index). For PX4 devices on NuttX: index is the device type, and for external buses the CS index
|
||||
uint16_t devtype_driver; ///< driver device type, e.g. DRV_IMU_DEVTYPE_ICM20689 (on NuttX: PX4_SPI_DEV_ID(devid) == devtype_driver)
|
||||
uint32_t cs_gpio; ///< chip-select GPIO (0 if this device is not used)
|
||||
spi_drdy_gpio_t drdy_gpio; ///< data ready GPIO (0 if not set)
|
||||
uint32_t devid; ///< SPIDEV_ID(type,index). For PX4 devices on NuttX: index is the device type, and for
|
||||
///< external buses the CS index
|
||||
uint16_t devtype_driver; ///< driver device type, e.g. DRV_IMU_DEVTYPE_ICM20689 (on NuttX:
|
||||
///< PX4_SPI_DEV_ID(devid) == devtype_driver)
|
||||
};
|
||||
|
||||
struct px4_spi_bus_devices_t {
|
||||
@@ -64,16 +67,19 @@ struct px4_spi_bus_devices_t {
|
||||
|
||||
struct px4_spi_bus_t {
|
||||
px4_spi_bus_device_t devices[SPI_BUS_MAX_DEVICES];
|
||||
int bus{-1}; ///< physical bus number (1, ...) (-1 means this is unused)
|
||||
uint32_t power_enable_gpio{0}; ///< GPIO (if non-zero) to control the power of the attached devices on this bus (0 means power is off)
|
||||
bool is_external; ///< static external configuration. Use px4_spi_bus_external() to check if a bus is really external
|
||||
bool requires_locking; ///< whether the bus should be locked during transfers (true if NuttX drivers access the bus)
|
||||
int bus{-1}; ///< physical bus number (1, ...) (-1 means this is unused)
|
||||
uint32_t power_enable_gpio{0}; ///< GPIO (if non-zero) to control the power of the attached devices on this bus
|
||||
///< (0 means power is off)
|
||||
bool is_external; ///< static external configuration. Use px4_spi_bus_external() to check if a bus is really
|
||||
///< external
|
||||
bool requires_locking; ///< whether the bus should be locked during transfers (true if NuttX drivers access the
|
||||
///< bus)
|
||||
};
|
||||
|
||||
|
||||
struct px4_spi_bus_all_hw_t {
|
||||
px4_spi_bus_t buses[SPI_BUS_MAX_BUS_ITEMS];
|
||||
int board_hw_version_revision{-1}; ///< 0=default, >0 for a specific revision (see board_get_hw_version & board_get_hw_revision), -1=unused
|
||||
int board_hw_version_revision{-1}; ///< 0=default, >0 for a specific revision (see board_get_hw_version &
|
||||
///< board_get_hw_revision), -1=unused
|
||||
};
|
||||
|
||||
#if BOARD_NUM_SPI_CFG_HW_VERSIONS > 1
|
||||
@@ -84,15 +90,15 @@ struct px4_spi_bus_all_hw_t {
|
||||
__EXPORT void px4_set_spi_buses_from_hw_version();
|
||||
|
||||
__EXPORT extern const px4_spi_bus_all_hw_t
|
||||
px4_spi_buses_all_hw[BOARD_NUM_SPI_CFG_HW_VERSIONS]; ///< board-specific SPI bus configuration all hw versions
|
||||
px4_spi_buses_all_hw[BOARD_NUM_SPI_CFG_HW_VERSIONS]; ///< board-specific SPI bus configuration all hw versions
|
||||
|
||||
__EXPORT extern const px4_spi_bus_t *px4_spi_buses; ///< board-specific SPI bus configuration for current board revision
|
||||
__EXPORT extern const px4_spi_bus_t
|
||||
*px4_spi_buses; ///< board-specific SPI bus configuration for current board revision
|
||||
#else
|
||||
static inline void px4_set_spi_buses_from_hw_version() {}
|
||||
__EXPORT extern const px4_spi_bus_t px4_spi_buses[SPI_BUS_MAX_BUS_ITEMS]; ///< board-specific SPI bus configuration
|
||||
__EXPORT extern const px4_spi_bus_t px4_spi_buses[SPI_BUS_MAX_BUS_ITEMS]; ///< board-specific SPI bus configuration
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Find a SPI bus given a device ID. Note: only internal buses are checked.
|
||||
* @return the bus or -1
|
||||
@@ -113,8 +119,7 @@ __EXPORT bool px4_spi_bus_external(const px4_spi_bus_t &bus);
|
||||
/**
|
||||
* runtime-check if a board has a specific bus as external.
|
||||
*/
|
||||
static inline bool px4_spi_bus_external(int bus)
|
||||
{
|
||||
static inline bool px4_spi_bus_external(int bus) {
|
||||
for (int i = 0; i < SPI_BUS_MAX_BUS_ITEMS; ++i) {
|
||||
if (px4_spi_buses[i].bus == bus) {
|
||||
return px4_spi_bus_external(px4_spi_buses[i]);
|
||||
@@ -124,17 +129,15 @@ static inline bool px4_spi_bus_external(int bus)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @class SPIBusIterator
|
||||
* Iterate over configured SPI buses by the board
|
||||
*/
|
||||
class SPIBusIterator
|
||||
{
|
||||
class SPIBusIterator {
|
||||
public:
|
||||
enum class FilterType {
|
||||
InternalBus, ///< specific or all internal buses
|
||||
ExternalBus, ///< specific external bus + CS index
|
||||
InternalBus, ///< specific or all internal buses
|
||||
ExternalBus, ///< specific external bus + CS index
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -143,11 +146,12 @@ public:
|
||||
* @param filter
|
||||
* @param devid_driver_index DRV_*
|
||||
* @param chipselect pin of SPIInternal (-1=all) or chip-select index of SPIExternal starting from 1 (optional)
|
||||
* @param bus starts with 1 (-1=all, but only for internal). Numbering for internal is arch-specific, for external
|
||||
* it is the n-th external bus.
|
||||
* @param bus starts with 1 (-1=all, but only for internal). Numbering for internal is arch-specific, for
|
||||
* external it is the n-th external bus.
|
||||
*/
|
||||
SPIBusIterator(FilterType filter, uint16_t devid_driver_index, int16_t chipselect = -1, int bus = -1)
|
||||
: _filter(filter), _devid_driver_index(devid_driver_index),
|
||||
: _filter(filter),
|
||||
_devid_driver_index(devid_driver_index),
|
||||
_chipselect(chipselect),
|
||||
_bus(filter == FilterType::ExternalBus && bus == -1 ? 1 : bus) {}
|
||||
|
||||
@@ -174,4 +178,4 @@ private:
|
||||
int _bus_device_index{-1};
|
||||
};
|
||||
|
||||
#endif // CONFIG_SPI
|
||||
#endif // CONFIG_SPI
|
||||
|
||||
@@ -52,9 +52,9 @@ typedef int px4_task_t;
|
||||
|
||||
/** Default scheduler type */
|
||||
#if CONFIG_RR_INTERVAL > 0
|
||||
# define SCHED_DEFAULT SCHED_RR
|
||||
#define SCHED_DEFAULT SCHED_RR
|
||||
#else
|
||||
# define SCHED_DEFAULT SCHED_FIFO
|
||||
#define SCHED_DEFAULT SCHED_FIFO
|
||||
#endif
|
||||
|
||||
#define px4_task_exit(x) _exit(x)
|
||||
@@ -65,13 +65,15 @@ typedef int px4_task_t;
|
||||
#include <sched.h>
|
||||
|
||||
/** Default scheduler type */
|
||||
#define SCHED_DEFAULT SCHED_FIFO
|
||||
#define SCHED_DEFAULT SCHED_FIFO
|
||||
|
||||
#if defined(__PX4_LINUX) || defined(__PX4_DARWIN) || defined(__PX4_CYGWIN)
|
||||
|
||||
#define SCHED_PRIORITY_MAX sched_get_priority_max(SCHED_FIFO)
|
||||
#define SCHED_PRIORITY_MIN sched_get_priority_min(SCHED_FIFO)
|
||||
#define SCHED_PRIORITY_DEFAULT (((sched_get_priority_max(SCHED_FIFO) - sched_get_priority_min(SCHED_FIFO)) / 2) + sched_get_priority_min(SCHED_FIFO))
|
||||
#define SCHED_PRIORITY_DEFAULT \
|
||||
(((sched_get_priority_max(SCHED_FIFO) - sched_get_priority_min(SCHED_FIFO)) / 2) + \
|
||||
sched_get_priority_min(SCHED_FIFO))
|
||||
|
||||
#elif defined(__PX4_QURT)
|
||||
|
||||
@@ -83,10 +85,10 @@ typedef int px4_task_t;
|
||||
#error "No target OS defined"
|
||||
#endif
|
||||
|
||||
#if defined (__PX4_LINUX)
|
||||
#if defined(__PX4_LINUX)
|
||||
#include <sys/prctl.h>
|
||||
#else
|
||||
#define PR_SET_NAME 1
|
||||
#define PR_SET_NAME 1
|
||||
#endif
|
||||
|
||||
typedef int px4_task_t;
|
||||
@@ -105,44 +107,44 @@ typedef struct {
|
||||
|
||||
// Fast drivers - they need to run as quickly as possible to minimize control
|
||||
// latency.
|
||||
#define SCHED_PRIORITY_FAST_DRIVER (SCHED_PRIORITY_MAX - 0)
|
||||
#define SCHED_PRIORITY_FAST_DRIVER (SCHED_PRIORITY_MAX - 0)
|
||||
|
||||
// Actuator outputs should run as soon as the rate controller publishes
|
||||
// the actuator controls topic
|
||||
#define SCHED_PRIORITY_ACTUATOR_OUTPUTS (PX4_WQ_HP_BASE - 3)
|
||||
#define SCHED_PRIORITY_ACTUATOR_OUTPUTS (PX4_WQ_HP_BASE - 3)
|
||||
|
||||
// Attitude controllers typically are in a blocking wait on driver data
|
||||
// they should be the first to run on an update, using the current sensor
|
||||
// data and the *previous* attitude reference from the position controller
|
||||
// which typically runs at a slower rate
|
||||
#define SCHED_PRIORITY_ATTITUDE_CONTROL (PX4_WQ_HP_BASE - 4)
|
||||
#define SCHED_PRIORITY_ATTITUDE_CONTROL (PX4_WQ_HP_BASE - 4)
|
||||
|
||||
// Estimators should run after the attitude controller but before anything
|
||||
// else in the system. They wait on sensor data which is either coming
|
||||
// from the sensor hub or from a driver. Keeping this class at a higher
|
||||
// priority ensures that the estimator runs first if it can, but will
|
||||
// wait for the sensor hub if its data is coming from it.
|
||||
#define SCHED_PRIORITY_ESTIMATOR (PX4_WQ_HP_BASE - 5)
|
||||
#define SCHED_PRIORITY_ESTIMATOR (PX4_WQ_HP_BASE - 5)
|
||||
|
||||
// Position controllers typically are in a blocking wait on estimator data
|
||||
// so when new sensor data is available they will run last. Keeping them
|
||||
// on a high priority ensures that they are the first process to be run
|
||||
// when the estimator updates.
|
||||
#define SCHED_PRIORITY_POSITION_CONTROL (PX4_WQ_HP_BASE - 7)
|
||||
#define SCHED_PRIORITY_POSITION_CONTROL (PX4_WQ_HP_BASE - 7)
|
||||
|
||||
// The log capture (which stores log data into RAM) should run faster
|
||||
// than other components, but should not run before the control pipeline
|
||||
#define SCHED_PRIORITY_LOG_CAPTURE (PX4_WQ_HP_BASE - 10)
|
||||
#define SCHED_PRIORITY_LOG_CAPTURE (PX4_WQ_HP_BASE - 10)
|
||||
|
||||
// Slow drivers should run at a rate where they do not impact the overall
|
||||
// system execution
|
||||
#define SCHED_PRIORITY_SLOW_DRIVER (PX4_WQ_HP_BASE - 35)
|
||||
#define SCHED_PRIORITY_SLOW_DRIVER (PX4_WQ_HP_BASE - 35)
|
||||
|
||||
// The navigation system needs to execute regularly but has no realtime needs
|
||||
#define SCHED_PRIORITY_NAVIGATION (SCHED_PRIORITY_DEFAULT + 5)
|
||||
#define SCHED_PRIORITY_NAVIGATION (SCHED_PRIORITY_DEFAULT + 5)
|
||||
// SCHED_PRIORITY_DEFAULT
|
||||
#define SCHED_PRIORITY_LOG_WRITER (SCHED_PRIORITY_DEFAULT - 10)
|
||||
#define SCHED_PRIORITY_PARAMS (SCHED_PRIORITY_DEFAULT - 15)
|
||||
#define SCHED_PRIORITY_LOG_WRITER (SCHED_PRIORITY_DEFAULT - 10)
|
||||
#define SCHED_PRIORITY_PARAMS (SCHED_PRIORITY_DEFAULT - 15)
|
||||
// SCHED_PRIORITY_IDLE
|
||||
|
||||
typedef int (*px4_main_t)(int argc, char *argv[]);
|
||||
@@ -150,11 +152,7 @@ typedef int (*px4_main_t)(int argc, char *argv[]);
|
||||
__BEGIN_DECLS
|
||||
|
||||
/** Starts a task and performs any specific accounting, scheduler setup, etc. */
|
||||
__EXPORT px4_task_t px4_task_spawn_cmd(const char *name,
|
||||
int scheduler,
|
||||
int priority,
|
||||
int stack_size,
|
||||
px4_main_t entry,
|
||||
__EXPORT px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int stack_size, px4_main_t entry,
|
||||
char *const argv[]);
|
||||
|
||||
/** Deletes a task - does not do resource cleanup **/
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined(__PX4_APPLE_LEGACY)
|
||||
#define clockid_t int
|
||||
@@ -24,9 +24,7 @@ __EXPORT int px4_clock_settime(clockid_t clk_id, const struct timespec *tp);
|
||||
|
||||
__EXPORT int px4_usleep(useconds_t usec);
|
||||
__EXPORT unsigned int px4_sleep(unsigned int seconds);
|
||||
__EXPORT int px4_pthread_cond_timedwait(pthread_cond_t *cond,
|
||||
pthread_mutex_t *mutex,
|
||||
const struct timespec *abstime);
|
||||
__EXPORT int px4_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime);
|
||||
__END_DECLS
|
||||
|
||||
#else
|
||||
|
||||
@@ -37,13 +37,13 @@
|
||||
|
||||
#if defined(__PX4_NUTTX)
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
#include <nuttx/clock.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
#elif defined(__PX4_POSIX)
|
||||
|
||||
#include <stdint.h>
|
||||
#include <queue.h>
|
||||
#include <px4_platform_types.h>
|
||||
#include <queue.h>
|
||||
#include <stdint.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
@@ -52,8 +52,8 @@ __BEGIN_DECLS
|
||||
#define NWORKERS 2
|
||||
|
||||
struct wqueue_s {
|
||||
pid_t pid; /* The task ID of the worker thread */
|
||||
struct dq_queue_s q; /* The queue of pending work */
|
||||
pid_t pid; /* The task ID of the worker thread */
|
||||
struct dq_queue_s q; /* The queue of pending work */
|
||||
};
|
||||
|
||||
extern struct wqueue_s g_work[NWORKERS];
|
||||
@@ -63,11 +63,11 @@ extern struct wqueue_s g_work[NWORKERS];
|
||||
typedef void (*worker_t)(void *arg);
|
||||
|
||||
struct work_s {
|
||||
struct dq_entry_s dq; /* Implements a doubly linked list */
|
||||
worker_t worker; /* Work callback */
|
||||
void *arg; /* Callback argument */
|
||||
uint64_t qtime; /* Time work queued */
|
||||
uint32_t delay; /* Delay until work performed */
|
||||
struct dq_entry_s dq; /* Implements a doubly linked list */
|
||||
worker_t worker; /* Work callback */
|
||||
void *arg; /* Callback argument */
|
||||
uint64_t qtime; /* Time work queued */
|
||||
uint32_t delay; /* Delay until work performed */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -42,6 +42,5 @@
|
||||
*/
|
||||
|
||||
__BEGIN_DECLS
|
||||
size_t px4_get_secure_random(uint8_t *out,
|
||||
size_t outlen);
|
||||
size_t px4_get_secure_random(uint8_t *out, size_t outlen);
|
||||
__END_DECLS
|
||||
|
||||
Reference in New Issue
Block a user