mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-21 06:47:35 +08:00
STM32 NuttX driver: Edge-triggered poll(), sort of fixes #35
This commit is contained in:
@@ -194,8 +194,7 @@ class CanDriver : public uavcan::ICanDriver, uavcan::Noncopyable
|
||||
public:
|
||||
template <unsigned RxQueueCapacity>
|
||||
CanDriver(CanRxItem (&rx_queue_storage)[UAVCAN_STM32_NUM_IFACES][RxQueueCapacity])
|
||||
: update_event_(*this)
|
||||
, if0_(bxcan::Can[0], update_event_, 0, rx_queue_storage[0], RxQueueCapacity)
|
||||
: if0_(bxcan::Can[0], update_event_, 0, rx_queue_storage[0], RxQueueCapacity)
|
||||
#if UAVCAN_STM32_NUM_IFACES > 1
|
||||
, if1_(bxcan::Can[1], update_event_, 1, rx_queue_storage[1], RxQueueCapacity)
|
||||
#endif
|
||||
|
||||
@@ -34,11 +34,9 @@ class BusEvent
|
||||
chibios_rt::CounterSemaphore sem_;
|
||||
|
||||
public:
|
||||
BusEvent(CanDriver& can_driver)
|
||||
BusEvent()
|
||||
: sem_(0)
|
||||
{
|
||||
(void)can_driver;
|
||||
}
|
||||
{ }
|
||||
|
||||
bool wait(uavcan::MonotonicDuration duration);
|
||||
|
||||
@@ -58,13 +56,15 @@ public:
|
||||
|
||||
#elif UAVCAN_STM32_NUTTX
|
||||
|
||||
/**
|
||||
* All bus events are reported as POLLIN.
|
||||
*/
|
||||
class BusEvent : uavcan::Noncopyable
|
||||
{
|
||||
static const unsigned MaxPollWaiters = 8;
|
||||
|
||||
::file_operations file_ops_;
|
||||
::pollfd* pollset_[MaxPollWaiters];
|
||||
CanDriver& can_driver_;
|
||||
bool signal_;
|
||||
|
||||
static int openTrampoline(::file* filp);
|
||||
@@ -75,15 +75,13 @@ class BusEvent : uavcan::Noncopyable
|
||||
int close(::file* filp);
|
||||
int poll(::file* filp, ::pollfd* fds, bool setup);
|
||||
|
||||
unsigned makePollMask() const;
|
||||
|
||||
int addPollWaiter(::pollfd* fds);
|
||||
int removePollWaiter(::pollfd* fds);
|
||||
|
||||
public:
|
||||
static const char* const DevName;
|
||||
|
||||
BusEvent(CanDriver& can_driver);
|
||||
BusEvent();
|
||||
~BusEvent();
|
||||
|
||||
bool wait(uavcan::MonotonicDuration duration);
|
||||
|
||||
@@ -99,7 +99,7 @@ int BusEvent::poll(::file* filp, ::pollfd* fds, bool setup)
|
||||
ret = addPollWaiter(fds);
|
||||
if (ret == 0)
|
||||
{
|
||||
fds->revents |= fds->events & makePollMask();
|
||||
fds->revents |= fds->events & POLLIN;
|
||||
if (fds->revents != 0)
|
||||
{
|
||||
(void)sem_post(fds->sem);
|
||||
@@ -114,26 +114,11 @@ int BusEvent::poll(::file* filp, ::pollfd* fds, bool setup)
|
||||
return ret;
|
||||
}
|
||||
|
||||
unsigned BusEvent::makePollMask() const
|
||||
{
|
||||
const uavcan::CanSelectMasks select_masks = can_driver_.makeSelectMasks();
|
||||
unsigned poll_mask = 0;
|
||||
if (select_masks.read != 0)
|
||||
{
|
||||
poll_mask |= POLLIN;
|
||||
}
|
||||
if (select_masks.write != 0)
|
||||
{
|
||||
poll_mask |= POLLOUT;
|
||||
}
|
||||
return poll_mask;
|
||||
}
|
||||
|
||||
int BusEvent::addPollWaiter(::pollfd* fds)
|
||||
{
|
||||
for (unsigned i = 0; i < MaxPollWaiters; i++)
|
||||
{
|
||||
if (pollset_[i] == nullptr)
|
||||
if (pollset_[i] == NULL)
|
||||
{
|
||||
pollset_[i] = fds;
|
||||
return 0;
|
||||
@@ -148,16 +133,15 @@ int BusEvent::removePollWaiter(::pollfd* fds)
|
||||
{
|
||||
if (fds == pollset_[i])
|
||||
{
|
||||
pollset_[i] = nullptr;
|
||||
pollset_[i] = NULL;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
BusEvent::BusEvent(CanDriver& can_driver)
|
||||
: can_driver_(can_driver)
|
||||
, signal_(false)
|
||||
BusEvent::BusEvent()
|
||||
: signal_(false)
|
||||
{
|
||||
std::memset(&file_ops_, 0, sizeof(file_ops_));
|
||||
std::memset(pollset_, 0, sizeof(pollset_));
|
||||
@@ -201,9 +185,9 @@ void BusEvent::signalFromInterrupt()
|
||||
for (unsigned i = 0; i < MaxPollWaiters; i++)
|
||||
{
|
||||
::pollfd* const fd = pollset_[i];
|
||||
if (fd != nullptr)
|
||||
if (fd != NULL)
|
||||
{
|
||||
fd->revents = fd->events & makePollMask();
|
||||
fd->revents |= fd->events & POLLIN;
|
||||
if ((fd->revents != 0) && (fd->sem->semcount <= 0))
|
||||
{
|
||||
(void)sem_post(fd->sem);
|
||||
|
||||
Reference in New Issue
Block a user