aboutsummaryrefslogtreecommitdiff
path: root/src/drivers/mpu6000
diff options
context:
space:
mode:
authorAndrew Tridgell <andrew@tridgell.net>2014-12-29 20:44:46 +1100
committerThomas Gubler <thomasgubler@gmail.com>2014-12-30 20:55:57 +0100
commit333039d3db7b1f3b4bfb06c27874bf3372b7d750 (patch)
tree92ac9f448945b8d92db957e1b17c6523e0f5d555 /src/drivers/mpu6000
parentb1574666084b64b43b241a56ac01596035ebccdf (diff)
downloadpx4-firmware-333039d3db7b1f3b4bfb06c27874bf3372b7d750.tar.gz
px4-firmware-333039d3db7b1f3b4bfb06c27874bf3372b7d750.tar.bz2
px4-firmware-333039d3db7b1f3b4bfb06c27874bf3372b7d750.zip
mpu6000: added "mpu6000 testerror" command
used to generate a error case for reset testing
Diffstat (limited to 'src/drivers/mpu6000')
-rw-r--r--src/drivers/mpu6000/mpu6000.cpp47
1 files changed, 45 insertions, 2 deletions
diff --git a/src/drivers/mpu6000/mpu6000.cpp b/src/drivers/mpu6000/mpu6000.cpp
index 91eb40b96..8dfac9859 100644
--- a/src/drivers/mpu6000/mpu6000.cpp
+++ b/src/drivers/mpu6000/mpu6000.cpp
@@ -210,6 +210,9 @@ public:
*/
int factory_self_test();
+ // deliberately cause a sensor error
+ void test_error();
+
protected:
virtual int probe();
@@ -1072,10 +1075,31 @@ MPU6000::factory_self_test()
write_reg(MPUREG_ACCEL_CONFIG, saved_accel_config);
_in_factory_test = false;
+ if (ret == OK) {
+ ::printf("PASSED\n");
+ }
return ret;
}
+
+/*
+ deliberately trigger an error in the sensor to trigger recovery
+ */
+void
+MPU6000::test_error()
+{
+ _in_factory_test = true;
+ // deliberately trigger an error. This was noticed during
+ // development as a handy way to test the reset logic
+ uint8_t data[16];
+ memset(data, 0, sizeof(data));
+ transfer(data, data, sizeof(data));
+ ::printf("error triggered\n");
+ print_registers();
+ _in_factory_test = false;
+}
+
ssize_t
MPU6000::gyro_read(struct file *filp, char *buffer, size_t buflen)
{
@@ -1810,6 +1834,7 @@ void test(bool);
void reset(bool);
void info(bool);
void regdump(bool);
+void testerror(bool);
void factorytest(bool);
void usage();
@@ -2003,6 +2028,21 @@ regdump(bool external_bus)
}
/**
+ * deliberately produce an error to test recovery
+ */
+void
+testerror(bool external_bus)
+{
+ MPU6000 **g_dev_ptr = external_bus?&g_dev_ext:&g_dev_int;
+ if (*g_dev_ptr == nullptr)
+ errx(1, "driver not running");
+
+ (*g_dev_ptr)->test_error();
+
+ exit(0);
+}
+
+/**
* Dump the register information
*/
void
@@ -2020,7 +2060,7 @@ factorytest(bool external_bus)
void
usage()
{
- warnx("missing command: try 'start', 'info', 'test', 'reset', 'regdump'");
+ warnx("missing command: try 'start', 'info', 'test', 'reset', 'regdump', 'factorytest', 'testerror'");
warnx("options:");
warnx(" -X (external bus)");
warnx(" -R rotation");
@@ -2086,5 +2126,8 @@ mpu6000_main(int argc, char *argv[])
if (!strcmp(verb, "factorytest"))
mpu6000::factorytest(external_bus);
- errx(1, "unrecognized command, try 'start', 'test', 'reset', 'info' or 'regdump'");
+ if (!strcmp(verb, "testerror"))
+ mpu6000::testerror(external_bus);
+
+ errx(1, "unrecognized command, try 'start', 'test', 'reset', 'info', 'regdump', 'factorytest' or 'testerror'");
}