mirror of
https://github.com/eclipse/upm.git
synced 2025-07-03 18:31:13 +03:00
utilities: Update time/r methods for LINUX
Default to MONOTONIC clock for timer methods to avoid falling victim to clock corrections. Changed signatures from accepting pointers since this is not needed an complicates calls and Java/JS/Python bindings. * Switched from nanosleep to clock_nanosleep to allow developers to provide a clock for LINUX * Default upm_clock_init to CLOCK_MONOTONIC * Updated logic to calculating delay and elapsed to be more readable * Added ns flavors for completeness * Refactored all upm_* delay/timer methods * Added #else for preprocessor cases w/o an #else * Added test for AQI * Added test fixture with logic to identify a minimum delay time which is used as a metric for testing all delay methods * Much more lenient unit testing of delays to minimize false CI failures Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
@ -99,7 +99,7 @@ ppd42ns_dust_data ppd42ns_get_data(const ppd42ns_context dev)
|
||||
|
||||
unsigned int low_pulse_occupancy = 0;
|
||||
|
||||
upm_clock_init(&max_loop_time);
|
||||
max_loop_time = upm_clock_init();
|
||||
|
||||
do {
|
||||
low_pulse_occupancy += ppd42ns_pulse_in(dev, 0);
|
||||
@ -132,11 +132,10 @@ static uint32_t ppd42ns_pulse_in(const ppd42ns_context dev,
|
||||
assert(dev != NULL);
|
||||
|
||||
// we run for no more than 1 second at a time
|
||||
upm_clock_t max_time;
|
||||
upm_clock_t pulse_time;
|
||||
uint32_t total_pulse_time = 0;
|
||||
|
||||
upm_clock_init(&max_time);
|
||||
upm_clock_t max_time = upm_clock_init();
|
||||
bool pin_level;
|
||||
bool is_timing = false;
|
||||
|
||||
@ -146,7 +145,7 @@ static uint32_t ppd42ns_pulse_in(const ppd42ns_context dev,
|
||||
if (!is_timing && pin_level == high_low_value)
|
||||
{
|
||||
// level is desired level, but not currently timing
|
||||
upm_clock_init(&pulse_time);
|
||||
pulse_time = upm_clock_init();
|
||||
is_timing = true;
|
||||
}
|
||||
else if (is_timing && pin_level != high_low_value)
|
||||
|
Reference in New Issue
Block a user