diff --git a/support/platform/include/i2c_core.h b/support/platform/include/i2c_core.h index 81208c183f97cb341180c807dcec8d46ea7f7d8f..0e5d513ac5868fd2522cd915fc6fc06250e232b5 100644 --- a/support/platform/include/i2c_core.h +++ b/support/platform/include/i2c_core.h @@ -11,7 +11,6 @@ #include "hdf_base.h" #include "i2c_if.h" -#include "osal_atomic.h" #include "osal_mutex.h" #ifdef __cplusplus @@ -28,7 +27,6 @@ struct I2cLockMethod; struct I2cCntlr { struct OsalMutex lock; - OsalAtomic atom; void *owner; int16_t busId; void *priv; diff --git a/support/platform/src/i2c_core.c b/support/platform/src/i2c_core.c index 0ee4f3bd6025330a50bfc93c807c161d90daf859..815e43c4d300b1b60ad5fb1857194b397d83728c 100644 --- a/support/platform/src/i2c_core.c +++ b/support/platform/src/i2c_core.c @@ -32,20 +32,7 @@ static int32_t I2cCntlrLockDefault(struct I2cCntlr *cntlr) if (cntlr == NULL) { return HDF_ERR_INVALID_OBJECT; } - -__TRY_LOCK: - if (OsalAtomicRead(&cntlr->atom) >= 1) { - OsalAtomicDec(&cntlr->atom); - return HDF_SUCCESS; - } - - if (PlatInIrqContext()) { - OsalMDelay(LOCK_WAIT_SECONDS_M); - } else { - OsalMSleep(LOCK_WAIT_SECONDS_M); - } - - goto __TRY_LOCK; + return OsalMutexLock(&cntlr->lock); } static void I2cCntlrUnlockDefault(struct I2cCntlr *cntlr) @@ -53,8 +40,7 @@ static void I2cCntlrUnlockDefault(struct I2cCntlr *cntlr) if (cntlr == NULL) { return; } - - OsalAtomicInc(&cntlr->atom); + (void)OsalMutexUnlock(&cntlr->lock); } static const struct I2cLockMethod g_i2cLockOpsDefault = { @@ -165,6 +151,8 @@ void I2cCntlrPut(struct I2cCntlr *cntlr) int32_t I2cCntlrAdd(struct I2cCntlr *cntlr) { + int32_t ret; + if (cntlr == NULL) { return HDF_ERR_INVALID_OBJECT; } @@ -183,9 +171,13 @@ int32_t I2cCntlrAdd(struct I2cCntlr *cntlr) HDF_LOGE("I2cCntlrAdd: init lock fail!"); return HDF_FAILURE; } - OsalAtomicSet(&cntlr->atom, 1); - return I2cManagerAddCntlr(cntlr); + ret = I2cManagerAddCntlr(cntlr); + if (ret != HDF_SUCCESS) { + (void)OsalMutexDestroy(&cntlr->lock); + return ret; + } + return HDF_SUCCESS; } void I2cCntlrRemove(struct I2cCntlr *cntlr)