From dcd70c807b69796366c8931bcea199df27d30bae Mon Sep 17 00:00:00 2001 From: PeterKietzmann Date: Thu, 29 Jan 2015 10:15:27 +0100 Subject: [PATCH] drivers/isl29020: Acquire exclusive access ti I2C bus --- drivers/isl29020/isl29020.c | 15 +++++++++++++++ drivers/l3g4200d/l3g4200d.c | 1 - drivers/lps331ap/lps331ap.c | 1 - drivers/lsm303dlhc/lsm303dlhc.c | 1 - drivers/mag3110/mag3110.c | 1 - drivers/mma8652/mma8652.c | 1 - drivers/mpl3115a2/mpl3115a2.c | 1 - drivers/srf02/srf02.c | 1 - drivers/tmp006/tmp006.c | 1 - 9 files changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/isl29020/isl29020.c b/drivers/isl29020/isl29020.c index 1ff16913a6..db779f2bf3 100644 --- a/drivers/isl29020/isl29020.c +++ b/drivers/isl29020/isl29020.c @@ -14,6 +14,7 @@ * @brief Device driver implementation for the ISL29020 light sensor * * @author Hauke Petersen + * @author Peter Kietzmann * * @} */ @@ -36,12 +37,16 @@ int isl29020_init(isl29020_t *dev, i2c_t i2c, uint8_t address, dev->address = address; dev->lux_fac = (float)((1 << (10 + (2 * range))) - 1) / 0xffff; + /* Acquire exclusive access to the bus. */ + i2c_acquire(dev->i2c); /* initialize the I2C bus */ i2c_init_master(i2c, I2C_SPEED_NORMAL); /* configure and enable the sensor */ tmp = ISL29020_CMD_EN | ISL29020_CMD_MODE | ISL29020_RES_INT_16 | range | (mode << 5); res = i2c_write_reg(dev->i2c, address, ISL29020_REG_CMD, tmp); + /* Release the bus for other threads. */ + i2c_release(dev->i2c); if (res < 1) { return -1; } @@ -53,9 +58,11 @@ int isl29020_read(isl29020_t *dev) char low, high; uint16_t res; + i2c_acquire(dev->i2c); /* read lightning value */ res = i2c_read_reg(dev->i2c, dev->address, ISL29020_REG_LDATA, &low); res += i2c_read_reg(dev->i2c, dev->address, ISL29020_REG_HDATA, &high); + i2c_release(dev->i2c); if (res < 2) { return -1; } @@ -70,15 +77,19 @@ int isl29020_enable(isl29020_t *dev) int res; char tmp; + i2c_acquire(dev->i2c); res = i2c_read_reg(dev->i2c, dev->address, ISL29020_REG_CMD, &tmp); if (res < 1) { + i2c_release(dev->i2c); return -1; } tmp |= ISL29020_CMD_EN; res = i2c_write_reg(dev->i2c, dev->address, ISL29020_REG_CMD, tmp); if (res < 1) { + i2c_release(dev->i2c); return -1; } + i2c_release(dev->i2c); return 0; } @@ -87,14 +98,18 @@ int isl29020_disable(isl29020_t *dev) int res; char tmp; + i2c_acquire(dev->i2c); res = i2c_read_reg(dev->i2c, dev->address, ISL29020_REG_CMD, &tmp); if (res < 1) { + i2c_release(dev->i2c); return -1; } tmp &= ~(ISL29020_CMD_EN); res = i2c_write_reg(dev->i2c, dev->address, ISL29020_REG_CMD, tmp); if (res < 1) { + i2c_release(dev->i2c); return -1; } + i2c_release(dev->i2c); return 0; } diff --git a/drivers/l3g4200d/l3g4200d.c b/drivers/l3g4200d/l3g4200d.c index 79bfab203d..8466d78e58 100644 --- a/drivers/l3g4200d/l3g4200d.c +++ b/drivers/l3g4200d/l3g4200d.c @@ -21,7 +21,6 @@ #include -#include "mutex.h" #include "l3g4200d.h" #include "l3g4200d-regs.h" #include "periph/i2c.h" diff --git a/drivers/lps331ap/lps331ap.c b/drivers/lps331ap/lps331ap.c index 86179f77da..d2a0c04ca8 100644 --- a/drivers/lps331ap/lps331ap.c +++ b/drivers/lps331ap/lps331ap.c @@ -25,7 +25,6 @@ #include -#include "mutex.h" #include "periph/i2c.h" #include "lps331ap.h" #include "lps331ap-internal.h" diff --git a/drivers/lsm303dlhc/lsm303dlhc.c b/drivers/lsm303dlhc/lsm303dlhc.c index e653f3a5c2..d2251b1147 100644 --- a/drivers/lsm303dlhc/lsm303dlhc.c +++ b/drivers/lsm303dlhc/lsm303dlhc.c @@ -19,7 +19,6 @@ * @} */ -#include "mutex.h" #include "lsm303dlhc.h" #include "lsm303dlhc-internal.h" diff --git a/drivers/mag3110/mag3110.c b/drivers/mag3110/mag3110.c index 9e23d8a5ef..0e70392505 100644 --- a/drivers/mag3110/mag3110.c +++ b/drivers/mag3110/mag3110.c @@ -22,7 +22,6 @@ #include #include -#include "mutex.h" #include "periph/i2c.h" #include "mag3110.h" #include "mag3110_reg.h" diff --git a/drivers/mma8652/mma8652.c b/drivers/mma8652/mma8652.c index bb0c6a25dd..99ae290238 100644 --- a/drivers/mma8652/mma8652.c +++ b/drivers/mma8652/mma8652.c @@ -22,7 +22,6 @@ #include #include -#include "mutex.h" #include "periph/i2c.h" #include "mma8652.h" #include "mma8652_reg.h" diff --git a/drivers/mpl3115a2/mpl3115a2.c b/drivers/mpl3115a2/mpl3115a2.c index 2efee4b27e..e0e8442c4a 100644 --- a/drivers/mpl3115a2/mpl3115a2.c +++ b/drivers/mpl3115a2/mpl3115a2.c @@ -22,7 +22,6 @@ #include #include -#include "mutex.h" #include "periph/i2c.h" #include "mpl3115a2.h" #include "mpl3115a2_reg.h" diff --git a/drivers/srf02/srf02.c b/drivers/srf02/srf02.c index 83cbe71146..ff4aced4f8 100644 --- a/drivers/srf02/srf02.c +++ b/drivers/srf02/srf02.c @@ -23,7 +23,6 @@ #include #include -#include "mutex.h" #include "hwtimer.h" #include "srf02.h" #include "periph/i2c.h" diff --git a/drivers/tmp006/tmp006.c b/drivers/tmp006/tmp006.c index a23f024efb..40917a79b8 100644 --- a/drivers/tmp006/tmp006.c +++ b/drivers/tmp006/tmp006.c @@ -23,7 +23,6 @@ #include #include #include -#include "mutex.h" #include "periph/i2c.h" #include "tmp006.h"