driver/sensor: Solve the busy loop problem caused by sampling problems

Solve the problem that when a user modifies the sampling rate,
the difference between the generation and the mainline generation
may be greater than the own sampling interval.

After this problem occurs, sensor_is_update() will continue to
return true, resulting in a busy loop in the upper-layer application,
so, need update user generation according to mainline generation.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1
2023-09-15 21:21:37 +08:00
committed by Petro Karashchenko
parent 93b2a3744f
commit c22646c0d4
+8
View File
@@ -483,6 +483,14 @@ static ssize_t sensor_do_samples(FAR struct sensor_upperhalf_s *upper,
generation = next_generation;
}
if (pos - 1 == end && sensor_is_updated(upper, user))
{
generation = upper->state.generation - user->state.generation +
(upper->state.min_interval >> 1);
user->state.generation += ROUND_DOWN(generation,
user->state.interval);
}
return ret;
}