diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2012-10-29 09:44:59 +0100 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2012-10-29 09:44:59 +0100 |
commit | c3c76ef3d50f71a7bef2994df462c5add11658d9 (patch) | |
tree | 896f37ba323ff6a365e399ed495ba435d50d5d93 /apps/systemcmds/eeprom/24xxxx_mtd.c | |
parent | 1a70b2f4ed0feffd9c57721db3661f15e64af5cb (diff) | |
download | px4-firmware-c3c76ef3d50f71a7bef2994df462c5add11658d9.tar.gz px4-firmware-c3c76ef3d50f71a7bef2994df462c5add11658d9.tar.bz2 px4-firmware-c3c76ef3d50f71a7bef2994df462c5add11658d9.zip |
Hardened the EEPROM attach routine for param storage
Diffstat (limited to 'apps/systemcmds/eeprom/24xxxx_mtd.c')
-rw-r--r-- | apps/systemcmds/eeprom/24xxxx_mtd.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/apps/systemcmds/eeprom/24xxxx_mtd.c b/apps/systemcmds/eeprom/24xxxx_mtd.c index 79149caa0..781b01065 100644 --- a/apps/systemcmds/eeprom/24xxxx_mtd.c +++ b/apps/systemcmds/eeprom/24xxxx_mtd.c @@ -502,6 +502,33 @@ FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev) { priv->perf_write_errors = perf_alloc(PC_COUNT, "EEPROM write errors"); } + /* attempt to read to validate device is present */ + unsigned char buf[5]; + uint8_t addrbuf[2] = {0, 0}; + + struct i2c_msg_s msgv[2] = { + { + .addr = priv->addr, + .flags = 0, + .buffer = &addrbuf[0], + .length = sizeof(addrbuf), + }, + { + .addr = priv->addr, + .flags = I2C_M_READ, + .buffer = &buf[0], + .length = sizeof(buf), + } + }; + + perf_begin(priv->perf_reads); + int ret = I2C_TRANSFER(priv->dev, &msgv[0], 2); + perf_end(priv->perf_reads); + + if (ret < 0) { + return NULL; + } + /* Return the implementation-specific state structure as the MTD device */ fvdbg("Return %p\n", priv); |