POSIX: Fixes for HRT implementation of simulated HW clock polling

There is a race condition for the accel and mag polling rates.
Whichever one gets set first, the other will be uninitialized.

Set the mag polling rate to 1ms if uninitilized.

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
Mark Charlebois
2015-06-02 16:55:34 +00:00
parent cced8ed69e
commit 5e95b83eff
11 changed files with 213 additions and 63 deletions
@@ -759,6 +759,8 @@ ACCELSIM::mag_ioctl(device::file_t *filp, int cmd, unsigned long arg)
/* XXX this is a bit shady, but no other way to adjust... */
_mag_call.period = _call_mag_interval = period;
//PX4_INFO("SET _call_mag_interval=%u", _call_mag_interval);
/* if we need to start the poll state machine, do it */
if (want_start)
start();
@@ -934,7 +936,17 @@ ACCELSIM::start()
_mag_reports->flush();
/* start polling at the specified rate */
//PX4_INFO("ACCELSIM::start accel %u", _call_accel_interval);
hrt_call_every(&_accel_call, 1000, _call_accel_interval, (hrt_callout)&ACCELSIM::measure_trampoline, this);
// There is a race here where SENSORIOCSPOLLRATE on the accel starts polling of mag but mag period is set to 0
if (_call_mag_interval == 0) {
PX4_ERR("_call_mag_interval uninitilized - would have set period delay of 0");
_call_mag_interval = 1000;
}
//PX4_INFO("ACCELSIM::start mag %u", _call_mag_interval);
hrt_call_every(&_mag_call, 1000, _call_mag_interval, (hrt_callout)&ACCELSIM::mag_measure_trampoline, this);
}
@@ -948,6 +960,7 @@ ACCELSIM::stop()
void
ACCELSIM::measure_trampoline(void *arg)
{
//PX4_INFO("ACCELSIM::measure_trampoline");
ACCELSIM *dev = (ACCELSIM *)arg;
/* make another measurement */
@@ -957,6 +970,7 @@ ACCELSIM::measure_trampoline(void *arg)
void
ACCELSIM::mag_measure_trampoline(void *arg)
{
//PX4_INFO("ACCELSIM::mag_measure_trampoline");
ACCELSIM *dev = (ACCELSIM *)arg;
/* make another measurement */