PX4 Firmware
PX4 Autopilot Software http://px4.io
|
Single CAN iface. More...
#include <can.hpp>
Classes | |
class | RxQueue |
struct | Timings |
struct | TxItem |
Public Types | |
enum | { MaxRxQueueCapacity = 254 } |
enum | OperatingMode { NormalMode, SilentMode } |
Public Member Functions | |
CanIface (flexcan::CanType *can, BusEvent &update_event, uavcan::uint8_t self_index, CanRxItem *rx_queue_buffer, uavcan::uint8_t rx_queue_capacity) | |
int | init (const uavcan::uint32_t bitrate, const OperatingMode mode) |
Initializes the hardware CAN controller. More... | |
void | handleTxInterrupt (uavcan::uint32_t tx_iflags, uavcan::uint64_t utc_usec) |
void | handleRxInterrupt (uavcan::uint32_t rx_iflags, uavcan::uint64_t utc_usec) |
void | pollErrorFlagsFromISR () |
This method is used to count errors and abort transmission on error if necessary. More... | |
void | discardTimedOutTxMailboxes (uavcan::MonotonicTime current_time) |
bool | canAcceptNewTxFrame (const uavcan::CanFrame &frame) const |
bool | isRxBufferEmpty () const |
uavcan::uint32_t | getRxQueueOverflowCount () const |
Number of RX frames lost due to queue overflow. More... | |
virtual uavcan::uint64_t | getErrorCount () const |
Total number of hardware failures and other kinds of errors (e.g. More... | |
uavcan::uint32_t | getVoluntaryTxAbortCount () const |
Number of times the driver exercised library's requirement to abort transmission on first error. More... | |
unsigned | getRxQueueLength () const |
Returns the number of frames pending in the RX queue. More... | |
bool | hadActivity () |
Whether this iface had at least one successful IO since the previous call of this method. More... | |
uavcan::uint8_t | getPeakNumTxMailboxesUsed () const |
Peak number of TX mailboxes used concurrently since initialization. More... | |
Private Types | |
enum | { NumTxMesgBuffers = 6 } |
enum | { NumFilters = 16 } |
Private Member Functions | |
int | computeTimings (uavcan::uint32_t target_bitrate, Timings &out_timings) |
virtual uavcan::int16_t | send (const uavcan::CanFrame &frame, uavcan::MonotonicTime tx_deadline, uavcan::CanIOFlags flags) |
virtual uavcan::int16_t | receive (uavcan::CanFrame &out_frame, uavcan::MonotonicTime &out_ts_monotonic, uavcan::UtcTime &out_ts_utc, uavcan::CanIOFlags &out_flags) |
virtual uavcan::int16_t | configureFilters (const uavcan::CanFilterConfig *filter_configs, uavcan::uint16_t num_configs) |
virtual uavcan::uint16_t | getNumFilters () const |
void | handleTxMailboxInterrupt (uavcan::uint8_t mailbox_index, bool txok, uavcan::uint64_t utc_usec) |
bool | waitMCRChange (uavcan::uint32_t mask, bool target_state) |
void | setMCR (uavcan::uint32_t mask, bool target_state) |
bool | setEnable (bool enable_true) |
uavcan::int16_t | doReset (Timings timings) |
bool | waitFreezeAckChange (bool target_state) |
void | setFreeze (bool freeze_true) |
Private Attributes | |
const uavcan::uint32_t | FIFO_IFLAG1 = flexcan::CAN_FIFO_NE | flexcan::CAN_FIFO_WARN | flexcan::CAN_FIFO_OV |
uavcan::uint8_t | MaxMB |
RxQueue | rx_queue_ |
flexcan::CanType *const | can_ |
uavcan::uint64_t | error_cnt_ |
uavcan::uint64_t | fifo_warn_cnt_ |
uavcan::uint32_t | pending_aborts_ |
uavcan::uint32_t | served_aborts_cnt_ |
BusEvent & | update_event_ |
TxItem | pending_tx_ [NumTxMesgBuffers] |
uavcan::uint8_t | peak_tx_mailbox_index_ |
const uavcan::uint8_t | self_index_ |
bool | had_activity_ |
Single CAN iface.
The application shall not use this directly.
|
inline |
Definition at line 174 of file can.hpp.
References uavcan_kinetis::CanRxItem::frame, and ToneAlarmInterface::init().
bool uavcan_kinetis::CanIface::canAcceptNewTxFrame | ( | const uavcan::CanFrame & | frame | ) | const |
Definition at line 758 of file uc_kinetis_flexcan.cpp.
References uavcan_kinetis::flexcan::ESR2_IMB, uavcan_kinetis::flexcan::ESR2_VPS, and MicroBenchHRT::lock().
|
private |
Definition at line 138 of file uc_kinetis_flexcan.cpp.
References uavcan_kinetis::flexcan::canclk, uavcan_kinetis::ErrInvalidBitRate, math::min(), uavcan_kinetis::CanIface::Timings::prescaler, uavcan_kinetis::CanIface::Timings::propseg, uavcan_kinetis::CanIface::Timings::pseg1, uavcan_kinetis::CanIface::Timings::pseg2, and uavcan_kinetis::CanIface::Timings::rjw.
|
privatevirtual |
Definition at line 318 of file uc_kinetis_flexcan.cpp.
References uavcan_kinetis::ErrFilterNumConfigs, uavcan_kinetis::ErrMcrFRZACKAckNotCleared, uavcan_kinetis::ErrMcrFRZACKAckNotSet, uavcan_kinetis::flexcan::FilterType::ext, uavcan_kinetis::flexcan::FirstFilter, uavcan_kinetis::flexcan::FilterType::ide, MicroBenchHRT::lock(), uavcan_kinetis::flexcan::FilterType::rtr, uavcan_kinetis::flexcan::FilterType::std, and uavcan_kinetis::flexcan::FilterType::w.
void uavcan_kinetis::CanIface::discardTimedOutTxMailboxes | ( | uavcan::MonotonicTime | current_time | ) |
Definition at line 743 of file uc_kinetis_flexcan.cpp.
References uavcan_kinetis::CanIface::TxItem::deadline, MicroBenchHRT::lock(), uavcan_kinetis::flexcan::NumMBinFiFoAndFilters, uavcan_kinetis::CanIface::TxItem::pending, and uavcan_kinetis::flexcan::TxMbAbort.
|
private |
Definition at line 441 of file uc_kinetis_flexcan.cpp.
References uavcan_kinetis::flexcan::busclck, uavcan_kinetis::flexcan::canclk, uavcan_kinetis::flexcan::CTRL2_EACEN, uavcan_kinetis::flexcan::CTRL2_RRS, uavcan_kinetis::flexcan::CTRL2_TASD_MASK, uavcan_kinetis::flexcan::CTRL2_TASD_SHIFT, uavcan_kinetis::ErrMcrSOFTRSTNotCleared, uavcan_kinetis::flexcan::HWMaxMB, uavcan_kinetis::flexcan::MCR_AEN, uavcan_kinetis::flexcan::MCR_IRMQ, uavcan_kinetis::flexcan::MCR_MAXMB_MASK, uavcan_kinetis::flexcan::MCR_MAXMB_SHIFT, uavcan_kinetis::flexcan::MCR_RFEN, uavcan_kinetis::flexcan::MCR_SLFWAK, uavcan_kinetis::flexcan::MCR_SOFTRST, uavcan_kinetis::flexcan::MCR_SRXDIS, uavcan_kinetis::flexcan::MCR_SUPV, uavcan_kinetis::flexcan::MCR_WAKSRC, uavcan_kinetis::flexcan::MCR_WRNEN, uavcan_kinetis::flexcan::numberFIFOFilters, uavcan_kinetis::CanIface::Timings::prescaler, uavcan_kinetis::CanIface::Timings::propseg, uavcan_kinetis::CanIface::Timings::pseg1, uavcan_kinetis::CanIface::Timings::pseg2, and uavcan_kinetis::flexcan::useFIFO.
|
virtual |
Total number of hardware failures and other kinds of errors (e.g.
queue overruns). May increase continuously if the interface is not connected to the bus.
Definition at line 793 of file uc_kinetis_flexcan.cpp.
References MicroBenchHRT::lock().
|
inlineprivatevirtual |
Definition at line 151 of file can.hpp.
References uavcan_kinetis::CanRxItem::utc_usec.
|
inline |
unsigned uavcan_kinetis::CanIface::getRxQueueLength | ( | ) | const |
Returns the number of frames pending in the RX queue.
This is intended for debug use only.
Definition at line 799 of file uc_kinetis_flexcan.cpp.
References MicroBenchHRT::lock().
|
inline |
Number of RX frames lost due to queue overflow.
This is an atomic read, it doesn't require a critical section.
Definition at line 221 of file can.hpp.
References uavcan_kinetis::CanIface::RxQueue::getOverflowCount().
|
inline |
bool uavcan_kinetis::CanIface::hadActivity | ( | ) |
Whether this iface had at least one successful IO since the previous call of this method.
This is designed for use with iface activity LEDs.
Definition at line 805 of file uc_kinetis_flexcan.cpp.
References MicroBenchHRT::lock().
void uavcan_kinetis::CanIface::handleRxInterrupt | ( | uavcan::uint32_t | rx_iflags, |
uavcan::uint64_t | utc_usec | ||
) |
Definition at line 644 of file uc_kinetis_flexcan.cpp.
References uavcan_kinetis::flexcan::DataType::b0, uavcan_kinetis::flexcan::DataType::b1, uavcan_kinetis::flexcan::DataType::b2, uavcan_kinetis::flexcan::DataType::b3, uavcan_kinetis::flexcan::DataType::b4, uavcan_kinetis::flexcan::DataType::b5, uavcan_kinetis::flexcan::DataType::b6, uavcan_kinetis::flexcan::DataType::b7, uavcan_kinetis::flexcan::CAN_FIFO_NE, uavcan_kinetis::flexcan::CAN_FIFO_OV, uavcan_kinetis::flexcan::CAN_FIFO_WARN, uavcan_kinetis::flexcan::RxFiFoType::CS, uavcan_kinetis::flexcan::RxFiFoType::data, uavcan_kinetis::flexcan::FIFOcsType::dlc, uavcan_kinetis::flexcan::IDType::ext, uavcan_kinetis::flexcan::FiFo, uavcan_kinetis::flexcan::RxFiFoType::ID, uavcan_kinetis::flexcan::FIFOcsType::ide, uavcan_kinetis::flexcan::FIFOcsType::rtr, uavcan_kinetis::flexcan::IDType::std, and UNUSED.
void uavcan_kinetis::CanIface::handleTxInterrupt | ( | uavcan::uint32_t | tx_iflags, |
uavcan::uint64_t | utc_usec | ||
) |
Definition at line 596 of file uc_kinetis_flexcan.cpp.
References uavcan_kinetis::flexcan::NumMBinFiFoAndFilters, and uavcan_kinetis::flexcan::TxMbAbort.
|
private |
Definition at line 581 of file uc_kinetis_flexcan.cpp.
References uavcan_kinetis::CanIface::TxItem::frame, uavcan_kinetis::CanIface::TxItem::loopback, and uavcan_kinetis::CanIface::TxItem::pending.
int uavcan_kinetis::CanIface::init | ( | const uavcan::uint32_t | bitrate, |
const OperatingMode | mode | ||
) |
Initializes the hardware CAN controller.
Assumes:
Definition at line 484 of file uc_kinetis_flexcan.cpp.
References uavcan_kinetis::flexcan::CLOCKSEL, uavcan_kinetis::flexcan::CTRL1_CLKSRC, uavcan_kinetis::flexcan::CTRL1_ERRMSK, uavcan_kinetis::flexcan::CTRL1_LOM, uavcan_kinetis::flexcan::CTRL1_PRESDIV_SHIFT, uavcan_kinetis::flexcan::CTRL1_PSEG1_SHIFT, uavcan_kinetis::flexcan::CTRL1_PSEG2_SHIFT, uavcan_kinetis::flexcan::CTRL1_RJW_SHIFT, uavcan_kinetis::flexcan::CTRL1_ROPSEG_SHIFT, uavcan_kinetis::flexcan::CTRL1_RWRNMSK, uavcan_kinetis::flexcan::CTRL1_TWRNMSK, uavcan_kinetis::ErrMcrFRZACKAckNotCleared, uavcan_kinetis::ErrMcrLPMAckNotCleared, uavcan_kinetis::ErrMcrLPMAckNotSet, uavcan_kinetis::flexcan::FirstFilter, uavcan_kinetis::flexcan::HWMaxMB, uavcan_kinetis::flexcan::NumHWFilters, uavcan_kinetis::CanIface::Timings::prescaler, uavcan_kinetis::CanIface::Timings::propseg, uavcan_kinetis::CanIface::Timings::pseg1, uavcan_kinetis::CanIface::Timings::pseg2, uavcan_kinetis::CanIface::Timings::rjw, uavcan_kinetis::flexcan::TXMBMask, UAVCAN_KINETIS_LOG, and uavcan_kinetis::flexcan::FilterType::w.
bool uavcan_kinetis::CanIface::isRxBufferEmpty | ( | ) | const |
Definition at line 787 of file uc_kinetis_flexcan.cpp.
References MicroBenchHRT::lock().
Referenced by uavcan_kinetis::CanInitHelper< RxQueueCapacity >::init().
void uavcan_kinetis::CanIface::pollErrorFlagsFromISR | ( | ) |
This method is used to count errors and abort transmission on error if necessary.
This functionality used to be implemented in the SCE interrupt handler, but that approach was generating too much processing overhead, especially on disconnected interfaces.
Should be called from RX ISR, TX ISR, and select(); interrupts must be enabled.
Definition at line 712 of file uc_kinetis_flexcan.cpp.
References uavcan_kinetis::CanIface::TxItem::abort_on_error, uavcan_kinetis::flexcan::ESR1_ACKERR, uavcan_kinetis::flexcan::ESR1_BIT0ERR, uavcan_kinetis::flexcan::ESR1_BIT1ERR, uavcan_kinetis::flexcan::ESR1_CRCERR, uavcan_kinetis::flexcan::ESR1_FRMERR, uavcan_kinetis::flexcan::ESR1_STFERR, uavcan_kinetis::flexcan::NumMBinFiFoAndFilters, uavcan_kinetis::CanIface::TxItem::pending, and uavcan_kinetis::flexcan::TxMbAbort.
|
privatevirtual |
Definition at line 300 of file uc_kinetis_flexcan.cpp.
References uavcan_kinetis::clock::getMonotonic(), and MicroBenchHRT::lock().
|
privatevirtual |
Definition at line 207 of file uc_kinetis_flexcan.cpp.
References uavcan_kinetis::CanIface::TxItem::abort_on_error, uavcan_kinetis::flexcan::DataType::b0, uavcan_kinetis::flexcan::DataType::b1, uavcan_kinetis::flexcan::DataType::b2, uavcan_kinetis::flexcan::DataType::b3, uavcan_kinetis::flexcan::DataType::b4, uavcan_kinetis::flexcan::DataType::b5, uavcan_kinetis::flexcan::DataType::b6, uavcan_kinetis::flexcan::DataType::b7, uavcan_kinetis::flexcan::MBcsType::code, uavcan_kinetis::flexcan::MessageBufferType::CS, uavcan_kinetis::flexcan::MessageBufferType::data, uavcan_kinetis::CanIface::TxItem::deadline, uavcan_kinetis::flexcan::MBcsType::dlc, uavcan_kinetis::ErrUnsupportedFrame, uavcan_kinetis::flexcan::ESR2_IMB, uavcan_kinetis::flexcan::ESR2_LPTM_MASK, uavcan_kinetis::flexcan::ESR2_LPTM_SHIFT, uavcan_kinetis::flexcan::ESR2_VPS, uavcan_kinetis::flexcan::IDType::ext, uavcan_kinetis::CanIface::TxItem::frame, uavcan_kinetis::flexcan::MessageBufferType::ID, uavcan_kinetis::flexcan::MBcsType::ide, MicroBenchHRT::lock(), uavcan_kinetis::CanIface::TxItem::loopback, math::max(), uavcan_kinetis::flexcan::NumMBinFiFoAndFilters, uavcan_kinetis::CanIface::TxItem::pending, uavcan_kinetis::flexcan::MBcsType::rtr, uavcan_kinetis::flexcan::IDType::std, uavcan_kinetis::flexcan::TxMbDataOrRemote, and uavcan_kinetis::flexcan::TxMbInactive.
|
private |
Definition at line 436 of file uc_kinetis_flexcan.cpp.
References uavcan_kinetis::flexcan::MCR_LPMACK, and uavcan_kinetis::flexcan::MCR_MDIS.
|
private |
Definition at line 418 of file uc_kinetis_flexcan.cpp.
References MicroBenchHRT::lock(), uavcan_kinetis::flexcan::MCR_FRZ, and uavcan_kinetis::flexcan::MCR_HALT.
|
private |
Definition at line 402 of file uc_kinetis_flexcan.cpp.
|
private |
Definition at line 413 of file uc_kinetis_flexcan.cpp.
References uavcan_kinetis::flexcan::MCR_FRZACK.
|
private |
Definition at line 385 of file uc_kinetis_flexcan.cpp.
References state.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |