Browse Source

HAL_F4Light: take account of available bytes in receive_time_constraint_us

mission-4.1.18
Andrew Tridgell 7 years ago
parent
commit
f983c8a906
  1. 4
      libraries/AP_HAL_F4Light/UARTDriver.cpp
  2. 2
      libraries/AP_HAL_F4Light/UARTDriver.h

4
libraries/AP_HAL_F4Light/UARTDriver.cpp

@ -149,14 +149,14 @@ void UARTDriver::update_timestamp(){ // called from ISR
} }
// this is mostly a // this is mostly a
uint64_t UARTDriver::receive_time_constraint_us(uint16_t nbytes) const { uint64_t UARTDriver::receive_time_constraint_us(uint16_t nbytes) {
// timestamp is 32 bits so read is atomic, in worst case we get 2nd timestamp // timestamp is 32 bits so read is atomic, in worst case we get 2nd timestamp
uint32_t time_from_last_byte = AP_HAL::micros() - _receive_timestamp[_time_idx]; uint32_t time_from_last_byte = AP_HAL::micros() - _receive_timestamp[_time_idx];
uint32_t transport_time_us = 0; uint32_t transport_time_us = 0;
if (_baudrate > 0) { if (_baudrate > 0) {
// assume 10 bits per byte // assume 10 bits per byte
transport_time_us = (1000000UL * 10UL / _baudrate) * nbytes; transport_time_us = (1000000UL * 10UL / _baudrate) * (nbytes+available());
} }
return AP_HAL::micros64() - (time_from_last_byte + transport_time_us); return AP_HAL::micros64() - (time_from_last_byte + transport_time_us);
} }

2
libraries/AP_HAL_F4Light/UARTDriver.h

@ -53,7 +53,7 @@ public:
inline void disable(){ _usart_device = NULL; } // pins used for another needs inline void disable(){ _usart_device = NULL; } // pins used for another needs
uint64_t receive_time_constraint_us(uint16_t nbytes) const override; uint64_t receive_time_constraint_us(uint16_t nbytes) override;
void update_timestamp(); void update_timestamp();

Loading…
Cancel
Save