Thomas Watson b2b1d9e1bd AP_HAL: un-weaken and un-define dump functions
Weak symbols have problems on cygwin. These are only defined and used in
SITL so no point having an empty definition here, which would cause a
redefinition error if not weak.

Keeping the declaration in AP_HAL itself is not the best, but it works
and avoids significant surgery to AP_HAL_SITL to move their declarations
and usages into a better place.
2025-09-03 11:00:41 +01:00

55 lines
2.1 KiB
C++

#pragma once
#include <stdint.h>
#include <AP_Common/AP_Common.h>
#include "AP_HAL_Macros.h"
namespace AP_HAL {
void init();
void panic(const char *errormsg, ...) FMT_PRINTF(1, 2) NORETURN;
uint16_t micros16();
uint32_t micros();
uint32_t millis();
uint16_t millis16();
uint64_t micros64();
uint64_t millis64();
// only defined and used on SITL, but declared here for historical reasons
void dump_stack_trace();
void dump_core_file();
// Function to reliably determine whether a timeout has expired using any unsigned time type and interval
// The template makes sure that callers do not mix up different types for storing time or assessing the
// current time.
// The comparison is guaranteed to work even if the present and the past cross a wrap boundary
template <typename T, typename S, typename R>
inline bool timeout_expired(const T past_time, const S now, const R timeout)
{
static_assert(std::is_same<T, S>::value, "timeout_expired() must compare values of the same unsigned type");
static_assert(std::is_unsigned<T>::value, "timeout_expired() must use unsigned times");
static_assert(std::is_unsigned<R>::value, "timeout_expired() must use unsigned timeouts");
const T dt = now - past_time;
return (dt >= timeout);
}
// Function to reliably determine whether how much of a timeout is left using any unsigned time type and interval
// The template makes sure that callers do not mix up different types for storing time or assessing the
// current time.
// The comparison is guaranteed to work even if the present and the past cross a wrap boundary
template <typename T, typename S, typename R>
inline T timeout_remaining(const T past_time, const S now, const R timeout)
{
static_assert(std::is_same<T, S>::value, "timeout_remaining() must compare values of the same unsigned type");
static_assert(std::is_unsigned<T>::value, "timeout_remaining() must use unsigned times");
static_assert(std::is_unsigned<R>::value, "timeout_remaining() must use unsigned timeouts");
const T dt = now - past_time;
return (dt >= timeout) ? T(0) : (timeout - dt);
}
} // namespace AP_HAL