Skip to content

Commit

Permalink
Merge pull request #129 from ArduPilot/pr-usec-wait
Browse files Browse the repository at this point in the history
stm32: allow for less than 1ms wait time on ChibiOS
  • Loading branch information
pavel-kirienko authored May 26, 2018
2 parents c759e54 + a4754d1 commit 8bb62cd
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ namespace uavcan_stm32
*/
bool BusEvent::wait(uavcan::MonotonicDuration duration)
{
static const uavcan::int64_t MaxDelayMSec = 0x000FFFFF;
// set maximum time to allow for 16 bit timers running at 1MHz
static const uavcan::int64_t MaxDelayUSec = 0x000FFFF;

const uavcan::int64_t msec = duration.toMSec();
const uavcan::int64_t usec = duration.toUSec();
msg_t ret = msg_t();

if (msec <= 0)
if (usec <= 0)
{
# if (CH_KERNEL_MAJOR == 2)
ret = sem_.waitTimeout(TIME_IMMEDIATE);
Expand All @@ -33,11 +34,11 @@ bool BusEvent::wait(uavcan::MonotonicDuration duration)
else
{
# if (CH_KERNEL_MAJOR == 2)
ret = sem_.waitTimeout((msec > MaxDelayMSec) ? MS2ST(MaxDelayMSec) : MS2ST(msec));
ret = sem_.waitTimeout((usec > MaxDelayUSec) ? US2ST(MaxDelayUSec) : US2ST(usec));
# elif defined(MS2ST) // ChibiOS 3+
ret = sem_.wait((msec > MaxDelayMSec) ? MS2ST(MaxDelayMSec) : MS2ST(msec));
ret = sem_.wait((usec > MaxDelayUSec) ? US2ST(MaxDelayUSec) : US2ST(usec));
# else // ChibiOS 17+
ret = sem_.wait(::systime_t((msec > MaxDelayMSec) ? TIME_MS2I(MaxDelayMSec) : TIME_MS2I(msec)));
ret = sem_.wait(::systime_t((usec > MaxDelayUSec) ? TIME_US2I(MaxDelayUSec) : TIME_US2I(usec)));
# endif
}
# if (CH_KERNEL_MAJOR == 2)
Expand Down

0 comments on commit 8bb62cd

Please sign in to comment.