mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-21 15:43:34 +08:00
Modified CAN driver API: Passing the next pending TX frames into the select() call to facilitate proper prioritization in the driver
This commit is contained in:
@@ -310,7 +310,9 @@ class VirtualCanDriver : public uavcan::ICanDriver,
|
||||
/**
|
||||
* This and other methods of ICanDriver will be invoked by the sub-node thread.
|
||||
*/
|
||||
int16_t select(uavcan::CanSelectMasks& inout_masks, uavcan::MonotonicTime blocking_deadline) override
|
||||
int16_t select(uavcan::CanSelectMasks& inout_masks,
|
||||
const uavcan::CanFrame* (&)[uavcan::MaxCanIfaces],
|
||||
uavcan::MonotonicTime blocking_deadline) override
|
||||
{
|
||||
bool need_block = (inout_masks.write == 0); // Write queue is infinite
|
||||
for (unsigned i = 0; need_block && (i < num_ifaces_); i++)
|
||||
|
||||
@@ -236,6 +236,8 @@ static void testDriver(const std::vector<std::string>& iface_names)
|
||||
ENFORCE(nullptr == driver.getIface(255));
|
||||
ENFORCE(nullptr == driver.getIface(driver.getNumIfaces()));
|
||||
|
||||
const uavcan::CanFrame* pending_tx[uavcan::MaxCanIfaces] = {};
|
||||
|
||||
const unsigned AllIfacesMask = (1 << driver.getNumIfaces()) - 1;
|
||||
|
||||
/*
|
||||
@@ -243,7 +245,7 @@ static void testDriver(const std::vector<std::string>& iface_names)
|
||||
*/
|
||||
std::cout << "select() 1" << std::endl;
|
||||
uavcan::CanSelectMasks masks; // Driver provides masks for all available events
|
||||
ENFORCE(driver.getNumIfaces() == driver.select(masks, tsMonoOffsetMs(1000)));
|
||||
ENFORCE(driver.getNumIfaces() == driver.select(masks, pending_tx, tsMonoOffsetMs(1000)));
|
||||
ENFORCE(masks.read == 0);
|
||||
ENFORCE(masks.write == AllIfacesMask);
|
||||
|
||||
@@ -253,7 +255,7 @@ static void testDriver(const std::vector<std::string>& iface_names)
|
||||
}
|
||||
|
||||
std::cout << "select() 2" << std::endl;
|
||||
ENFORCE(driver.getNumIfaces() == driver.select(masks, tsMonoOffsetMs(1000)));
|
||||
ENFORCE(driver.getNumIfaces() == driver.select(masks, pending_tx, tsMonoOffsetMs(1000)));
|
||||
ENFORCE(masks.read == 0);
|
||||
ENFORCE(masks.write == AllIfacesMask);
|
||||
|
||||
@@ -269,7 +271,7 @@ static void testDriver(const std::vector<std::string>& iface_names)
|
||||
}
|
||||
|
||||
std::cout << "select() 3" << std::endl;
|
||||
ENFORCE(driver.getNumIfaces() == driver.select(masks, tsMonoOffsetMs(1000)));
|
||||
ENFORCE(driver.getNumIfaces() == driver.select(masks, pending_tx, tsMonoOffsetMs(1000)));
|
||||
ENFORCE(masks.read == AllIfacesMask);
|
||||
ENFORCE(masks.write == AllIfacesMask);
|
||||
|
||||
@@ -294,7 +296,7 @@ static void testDriver(const std::vector<std::string>& iface_names)
|
||||
|
||||
std::cout << "select() 4" << std::endl;
|
||||
masks.write = 0;
|
||||
ENFORCE(driver.getNumIfaces() == driver.select(masks, tsMonoOffsetMs(1000)));
|
||||
ENFORCE(driver.getNumIfaces() == driver.select(masks, pending_tx, tsMonoOffsetMs(1000)));
|
||||
ENFORCE(masks.read == 0);
|
||||
ENFORCE(masks.write == AllIfacesMask);
|
||||
|
||||
|
||||
@@ -532,7 +532,9 @@ public:
|
||||
* early returns.
|
||||
* Also it can return more events than were originally requested by uavcan, which is also acceptable.
|
||||
*/
|
||||
std::int16_t select(uavcan::CanSelectMasks& inout_masks, uavcan::MonotonicTime blocking_deadline) override
|
||||
std::int16_t select(uavcan::CanSelectMasks& inout_masks,
|
||||
const uavcan::CanFrame* (&)[uavcan::MaxCanIfaces],
|
||||
uavcan::MonotonicTime blocking_deadline) override
|
||||
{
|
||||
// Detecting whether we need to block at all
|
||||
bool need_block = (inout_masks.write == 0); // Write queue is infinite
|
||||
|
||||
Reference in New Issue
Block a user