Fixed STM32 NuttX driver

This commit is contained in:
Pavel Kirienko
2015-06-01 16:45:12 +03:00
parent 5442c0ac04
commit 0dc18f9623
2 changed files with 14 additions and 22 deletions
@@ -58,6 +58,9 @@ public:
#elif UAVCAN_STM32_NUTTX
/**
* All bus events are reported as POLLIN.
*/
class BusEvent : uavcan::Noncopyable
{
static const unsigned MaxPollWaiters = 8;
@@ -75,8 +78,6 @@ 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);
@@ -99,7 +99,13 @@ int BusEvent::poll(::file* filp, ::pollfd* fds, bool setup)
ret = addPollWaiter(fds);
if (ret == 0)
{
fds->revents |= fds->events & makePollMask();
/*
* Two events can be reported via POLLIN:
* - The RX queue is not empty. This event is level-triggered.
* - Transmission complete. This event is edge-triggered.
* FIXME Since TX event is edge-triggered, it can be lost between poll() calls.
*/
fds->revents |= fds->events & ((can_driver_.makeSelectMasks().read == 0) ? 0 : POLLIN);
if (fds->revents != 0)
{
(void)sem_post(fds->sem);
@@ -114,26 +120,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,7 +139,7 @@ int BusEvent::removePollWaiter(::pollfd* fds)
{
if (fds == pollset_[i])
{
pollset_[i] = nullptr;
pollset_[i] = NULL;
return 0;
}
}
@@ -201,9 +192,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);