Skip to content

Commit

Permalink
STM32: Fixed CS in pollErrorFlags()
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-kirienko committed Jan 31, 2016
1 parent cf9edf1 commit 702f6f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class CanIface : public uavcan::ICanIface, uavcan::Noncopyable
*
* Should be called from RX ISR, TX ISR, and select(); interrupts must be enabled.
*/
void pollErrorFlags();
void pollErrorFlagsFromISR();

void discardTimedOutTxMailboxes(uavcan::MonotonicTime current_time);

Expand Down
18 changes: 11 additions & 7 deletions libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ void CanIface::handleTxInterrupt(const uavcan::uint64_t utc_usec)
}
update_event_.signalFromInterrupt();

pollErrorFlags();
pollErrorFlagsFromISR();
}

void CanIface::handleRxInterrupt(uavcan::uint8_t fifo_index, uavcan::uint64_t utc_usec)
Expand Down Expand Up @@ -679,16 +679,14 @@ void CanIface::handleRxInterrupt(uavcan::uint8_t fifo_index, uavcan::uint64_t ut
had_activity_ = true;
update_event_.signalFromInterrupt();

pollErrorFlags();
pollErrorFlagsFromISR();
}

void CanIface::pollErrorFlags()
void CanIface::pollErrorFlagsFromISR()
{
const uavcan::uint8_t lec = uavcan::uint8_t((can_->ESR & bxcan::ESR_LEC_MASK) >> bxcan::ESR_LEC_SHIFT);
if (lec != 0)
{
CriticalSectionLocker cs_locker;

can_->ESR = 0;
error_cnt_++;

Expand Down Expand Up @@ -837,11 +835,17 @@ uavcan::int16_t CanDriver::select(uavcan::CanSelectMasks& inout_masks,
const uavcan::MonotonicTime time = clock::getMonotonic();

if0_.discardTimedOutTxMailboxes(time); // Check TX timeouts - this may release some TX slots
if0_.pollErrorFlags();
{
CriticalSectionLocker cs_locker;
if0_.pollErrorFlagsFromISR();
}

#if UAVCAN_STM32_NUM_IFACES > 1
if1_.discardTimedOutTxMailboxes(time);
if1_.pollErrorFlags();
{
CriticalSectionLocker cs_locker;
if1_.pollErrorFlagsFromISR();
}
#endif

inout_masks = makeSelectMasks(pending_tx); // Check if we already have some of the requested events
Expand Down

0 comments on commit 702f6f0

Please sign in to comment.