aboutsummaryrefslogtreecommitdiff
path: root/apps/drivers/ms5611/ms5611.cpp
diff options
context:
space:
mode:
authorpx4dev <px4@purgatory.org>2012-08-21 22:04:38 -0700
committerpx4dev <px4@purgatory.org>2012-08-21 22:04:38 -0700
commit63831fa908f9deb848c20433c0235554b261bec3 (patch)
tree7b552c930f084d792b52c8949c4221a97f8e4a0c /apps/drivers/ms5611/ms5611.cpp
parenta0ae2cb175b8f83ee7731335d452cc5ca30e820b (diff)
downloadpx4-firmware-63831fa908f9deb848c20433c0235554b261bec3.tar.gz
px4-firmware-63831fa908f9deb848c20433c0235554b261bec3.tar.bz2
px4-firmware-63831fa908f9deb848c20433c0235554b261bec3.zip
Fix an issue where the baro ORB topic was advertised from the wrong context and thus could not be published to.
Diffstat (limited to 'apps/drivers/ms5611/ms5611.cpp')
-rw-r--r--apps/drivers/ms5611/ms5611.cpp32
1 files changed, 20 insertions, 12 deletions
diff --git a/apps/drivers/ms5611/ms5611.cpp b/apps/drivers/ms5611/ms5611.cpp
index 6c6951d9b..187de178b 100644
--- a/apps/drivers/ms5611/ms5611.cpp
+++ b/apps/drivers/ms5611/ms5611.cpp
@@ -246,6 +246,7 @@ MS5611::MS5611(int bus) :
_measure_phase(0),
_dT(0),
_temp64(0),
+ _baro_topic(-1),
_reads(0),
_measure_errors(0),
_read_errors(0),
@@ -277,18 +278,6 @@ MS5611::init()
/* do I2C init (and probe) first */
ret = I2C::init();
- /* assuming we're good, advertise the object */
- if (ret == OK) {
- struct baro_report b;
-
- /* if this fails (e.g. no object in the system) that's OK */
- memset(&b, 0, sizeof(b));
- _baro_topic = orb_advertise(ORB_ID(sensor_baro), &b);
-
- if (_baro_topic < 0)
- debug("failed to create sensor_baro object");
- }
-
return ret;
}
@@ -538,6 +527,25 @@ MS5611::cycle_trampoline(void *arg)
void
MS5611::cycle()
{
+ /*
+ * We have to publish the baro topic in the context of the workq
+ * in order to ensure that the descriptor is valid when we go to publish.
+ *
+ * @bug We can't really ever be torn down and restarted, since this
+ * descriptor will never be closed and on the restart we will be
+ * unable to re-advertise.
+ */
+ if (_baro_topic == -1) {
+ struct baro_report b;
+
+ /* if this fails (e.g. no object in the system) we will cope */
+ memset(&b, 0, sizeof(b));
+ _baro_topic = orb_advertise(ORB_ID(sensor_baro), &b);
+
+ if (_baro_topic < 0)
+ debug("failed to create sensor_baro object");
+ }
+
/* collection phase? */
if (_collect_phase) {