mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-03 14:58:53 +08:00
Merge pull request #81 from UAVCAN/stm32_can_error_codes
Returning meaningful error codes from STM32 CAN driver methods
This commit is contained in:
@@ -11,6 +11,19 @@
|
||||
|
||||
namespace uavcan_stm32
|
||||
{
|
||||
/**
|
||||
* Driver error codes.
|
||||
* These values can be returned from driver functions negated.
|
||||
*/
|
||||
//static const uavcan::int16_t ErrUnknown = 1000; ///< Reserved for future use
|
||||
static const uavcan::int16_t ErrNotImplemented = 1001; ///< Feature not implemented
|
||||
static const uavcan::int16_t ErrInvalidBitRate = 1002; ///< Bit rate not supported
|
||||
static const uavcan::int16_t ErrLogic = 1003; ///< Internal logic error
|
||||
static const uavcan::int16_t ErrUnsupportedFrame = 1004; ///< Frame not supported (e.g. RTR, CAN FD, etc)
|
||||
static const uavcan::int16_t ErrMsrInakNotSet = 1005; ///< INAK bit of the MSR register is not 1
|
||||
static const uavcan::int16_t ErrMsrInakNotCleared = 1006; ///< INAK bit of the MSR register is not 0
|
||||
static const uavcan::int16_t ErrBitRateNotDetected = 1007; ///< Auto bit rate detection could not be finished
|
||||
|
||||
/**
|
||||
* RX queue item.
|
||||
* The application shall not use this directly.
|
||||
@@ -287,7 +300,7 @@ public:
|
||||
* This overload simply configures the provided bitrate.
|
||||
* Auto bit rate detection will not be performed.
|
||||
* Bitrate value must be positive.
|
||||
* @return Negative value on error; non-negative on success.
|
||||
* @return Negative value on error; non-negative on success. Refer to constants Err*.
|
||||
*/
|
||||
int init(uavcan::uint32_t bitrate)
|
||||
{
|
||||
@@ -306,7 +319,7 @@ public:
|
||||
* If auto detection was used, the function will update the argument
|
||||
* with established bit rate. In case of an error the value will be undefined.
|
||||
*
|
||||
* @return Negative value on error; non-negative on success.
|
||||
* @return Negative value on error; non-negative on success. Refer to constants Err*.
|
||||
*/
|
||||
template <typename DelayCallable>
|
||||
int init(DelayCallable delay_callable, uavcan::uint32_t& inout_bitrate = BitRateAutoDetect)
|
||||
@@ -346,7 +359,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
return -ErrBitRateNotDetected;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ int CanIface::computeTimings(const uavcan::uint32_t target_bitrate, Timings& out
|
||||
{
|
||||
if (target_bitrate < 1)
|
||||
{
|
||||
return -1;
|
||||
return -ErrInvalidBitRate;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -263,7 +263,7 @@ int CanIface::computeTimings(const uavcan::uint32_t target_bitrate, Timings& out
|
||||
{
|
||||
if (bs1_bs2_sum <= 2)
|
||||
{
|
||||
return -1; // No solution
|
||||
return -ErrInvalidBitRate; // No solution
|
||||
}
|
||||
bs1_bs2_sum--;
|
||||
}
|
||||
@@ -271,7 +271,7 @@ int CanIface::computeTimings(const uavcan::uint32_t target_bitrate, Timings& out
|
||||
const uavcan::uint32_t prescaler = prescaler_bs / (1 + bs1_bs2_sum);
|
||||
if ((prescaler < 1U) || (prescaler > 1024U))
|
||||
{
|
||||
return -1; // No solution
|
||||
return -ErrInvalidBitRate; // No solution
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -334,7 +334,7 @@ int CanIface::computeTimings(const uavcan::uint32_t target_bitrate, Timings& out
|
||||
if ((target_bitrate != (pclk / (prescaler * (1 + solution.bs1 + solution.bs2)))) || !solution.isValid())
|
||||
{
|
||||
UAVCAN_ASSERT(0);
|
||||
return -1;
|
||||
return -ErrLogic;
|
||||
}
|
||||
|
||||
UAVCAN_STM32_LOG("Timings: quanta/bit: %d, sample point location: %.1f%%",
|
||||
@@ -352,7 +352,7 @@ uavcan::int16_t CanIface::send(const uavcan::CanFrame& frame, uavcan::MonotonicT
|
||||
{
|
||||
if (frame.isErrorFrame() || frame.dlc > 8)
|
||||
{
|
||||
return -1; // WTF man how to handle that
|
||||
return -ErrUnsupportedFrame;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -462,7 +462,7 @@ uavcan::int16_t CanIface::configureFilters(const uavcan::CanFilterConfig* filter
|
||||
CriticalSectionLocker lock;
|
||||
(void)filter_configs;
|
||||
(void)num_configs;
|
||||
return -1;
|
||||
return -ErrNotImplemented;
|
||||
}
|
||||
|
||||
bool CanIface::waitMsrINakBitStateChange(bool target_state)
|
||||
@@ -503,7 +503,7 @@ int CanIface::init(const uavcan::uint32_t bitrate, const OperatingMode mode)
|
||||
if (!waitMsrINakBitStateChange(true))
|
||||
{
|
||||
UAVCAN_STM32_LOG("MSR INAK not set");
|
||||
return -1;
|
||||
return -ErrMsrInakNotSet;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -551,7 +551,7 @@ int CanIface::init(const uavcan::uint32_t bitrate, const OperatingMode mode)
|
||||
if (!waitMsrINakBitStateChange(false))
|
||||
{
|
||||
UAVCAN_STM32_LOG("MSR INAK not cleared");
|
||||
return -1;
|
||||
return -ErrMsrInakNotCleared;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user