Skip to content

Commit

Permalink
Revert "use small lock in following files:"
Browse files Browse the repository at this point in the history
This reverts commit bbaf1ff.
  • Loading branch information
wangzhi-art committed Feb 5, 2025
1 parent a443625 commit 44301ad
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 68 deletions.
18 changes: 6 additions & 12 deletions arch/arm64/src/a64/a64_twi.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#include <nuttx/i2c/i2c_master.h>

#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <arch/board/board.h>

#include "arm64_internal.h"
Expand Down Expand Up @@ -167,7 +166,6 @@ struct a64_twi_priv_s

int refs; /* Reference count */
mutex_t lock; /* Mutual exclusion mutex */
spinlock_t spinlock; /* Spinlock */
sem_t waitsem; /* Wait for TWI transfer completion */
struct wdog_s timeout; /* Watchdog to recover from bus hangs */
volatile int result; /* The result of the transfer */
Expand Down Expand Up @@ -290,7 +288,6 @@ static struct a64_twi_priv_s a64_twi0_priv =
.config = &a64_twi0_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
.waitsem = SEM_INITIALIZER(0),
.intstate = INTSTATE_IDLE,
.msgc = 0,
Expand Down Expand Up @@ -327,7 +324,6 @@ static struct a64_twi_priv_s a64_twi1_priv =
.config = &a64_twi1_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
.waitsem = SEM_INITIALIZER(0),
.intstate = INTSTATE_IDLE,
.msgc = 0,
Expand Down Expand Up @@ -364,7 +360,6 @@ static struct a64_twi_priv_s a64_twi2_priv =
.config = &a64_twi2_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
.waitsem = SEM_INITIALIZER(0),
.intstate = INTSTATE_IDLE,
.msgc = 0,
Expand Down Expand Up @@ -401,7 +396,6 @@ static struct a64_twi_priv_s a64_rtwi_priv =
.config = &a64_rtwi_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
.waitsem = SEM_INITIALIZER(0),
.intstate = INTSTATE_IDLE,
.msgc = 0,
Expand Down Expand Up @@ -1232,7 +1226,7 @@ static int a64_twi_isr_process(struct a64_twi_priv_s *priv)
*/

#ifdef CONFIG_I2C_POLLED
irqstate_t flags = spin_lock_irqsave(&priv->spinlock);
irqstate_t flags = enter_critical_section();
#endif

/* Transmit a byte */
Expand All @@ -1241,7 +1235,7 @@ static int a64_twi_isr_process(struct a64_twi_priv_s *priv)
priv->dcnt--;

#ifdef CONFIG_I2C_POLLED
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
#endif

break;
Expand Down Expand Up @@ -1564,7 +1558,7 @@ static int twi_transfer(struct i2c_master_s *dev,

twi_setclock(priv, msgs->frequency);

flags = spin_lock_irqsave(&priv->spinlock);
flags = enter_critical_section();

/* Initiate the transfer. The rest will be handled from interrupt
* logic. Interrupts must be disabled to prevent re-entrance from the
Expand Down Expand Up @@ -1618,7 +1612,7 @@ static int twi_transfer(struct i2c_master_s *dev,

/* Release the port for re-use by other clients */

spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
nxmutex_unlock(&priv->lock);
return ret;
}
Expand Down Expand Up @@ -1826,7 +1820,7 @@ static void twi_setclock(struct a64_twi_priv_s *priv, uint32_t freq)

static void twi_hw_initialize(struct a64_twi_priv_s *priv)
{
irqstate_t flags = spin_lock_irqsave(&priv->spinlock);
irqstate_t flags = enter_critical_section();

i2cinfo("TWI%d Initializing\n", priv->config->twi);

Expand Down Expand Up @@ -1862,7 +1856,7 @@ static void twi_hw_initialize(struct a64_twi_priv_s *priv)

twi_softreset(priv);

spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
}

/****************************************************************************
Expand Down
6 changes: 2 additions & 4 deletions arch/arm64/src/imx9/imx9_gpioirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>

#include "arm64_internal.h"
#include "imx9_gpio.h"
Expand Down Expand Up @@ -63,7 +62,6 @@ struct imx9_portisr_s
****************************************************************************/

static struct imx9_portisr_s g_isrtab[IMX9_GPIO_NPORTS];
static spinlock_t g_isrlock = SP_UNLOCKED;

/****************************************************************************
* Private Functions
Expand Down Expand Up @@ -199,12 +197,12 @@ int imx9_gpioirq_attach(gpio_pinset_t pinset, xcpt_t isr, void *arg)

/* Atomically change the handler */

irqstate_t flags = spin_lock_irqsave(&g_isrlock);
irqstate_t flags = enter_critical_section();

g_isrtab[port].pins[pin].isr = isr;
g_isrtab[port].pins[pin].arg = arg;

spin_unlock_irqrestore(&g_isrlock, flags);
leave_critical_section(flags);
return OK;
}

Expand Down
22 changes: 6 additions & 16 deletions arch/arm64/src/imx9/imx9_lpi2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <nuttx/clock.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
Expand Down Expand Up @@ -207,7 +206,6 @@ struct imx9_lpi2c_priv_s

int refs; /* Reference count */
mutex_t lock; /* Mutual exclusion mutex */
spinlock_t spinlock; /* Spinlock */
#ifndef CONFIG_I2C_POLLED
sem_t sem_isr; /* Interrupt wait semaphore */
#endif
Expand Down Expand Up @@ -366,7 +364,6 @@ static struct imx9_lpi2c_priv_s imx9_lpi2c1_priv =
.config = &imx9_lpi2c1_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
Expand Down Expand Up @@ -415,7 +412,6 @@ static struct imx9_lpi2c_priv_s imx9_lpi2c2_priv =
.config = &imx9_lpi2c2_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
Expand Down Expand Up @@ -464,7 +460,6 @@ static struct imx9_lpi2c_priv_s imx9_lpi2c3_priv =
.config = &imx9_lpi2c3_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
Expand Down Expand Up @@ -513,7 +508,6 @@ static struct imx9_lpi2c_priv_s imx9_lpi2c4_priv =
.config = &imx9_lpi2c4_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
Expand Down Expand Up @@ -562,7 +556,6 @@ static struct imx9_lpi2c_priv_s imx9_lpi2c5_priv =
.config = &imx9_lpi2c5_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
Expand Down Expand Up @@ -611,7 +604,6 @@ static struct imx9_lpi2c_priv_s imx9_lpi2c6_priv =
.config = &imx9_lpi2c6_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
Expand Down Expand Up @@ -660,7 +652,6 @@ static struct imx9_lpi2c_priv_s imx9_lpi2c7_priv =
.config = &imx9_lpi2c7_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
Expand Down Expand Up @@ -709,7 +700,6 @@ static struct imx9_lpi2c_priv_s imx9_lpi2c8_priv =
.config = &imx9_lpi2c8_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
Expand Down Expand Up @@ -1605,7 +1595,7 @@ static int imx9_lpi2c_isr_process(struct imx9_lpi2c_priv_s *priv)
*/

#ifdef CONFIG_I2C_POLLED
irqstate_t flags = spin_lock_irqsave(&priv->spinlock);
irqstate_t flags = enter_critical_section();
#endif

/* Receive a byte */
Expand All @@ -1620,7 +1610,7 @@ static int imx9_lpi2c_isr_process(struct imx9_lpi2c_priv_s *priv)
}

#ifdef CONFIG_I2C_POLLED
spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);
#endif
}

Expand Down Expand Up @@ -2386,7 +2376,7 @@ struct i2c_master_s *imx9_i2cbus_initialize(int port)
* power-up hardware and configure GPIOs.
*/

flags = spin_lock_irqsave(&priv->spinlock);
flags = enter_critical_section();

if ((volatile int)priv->refs++ == 0)
{
Expand All @@ -2407,7 +2397,7 @@ struct i2c_master_s *imx9_i2cbus_initialize(int port)
#endif
}

spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);

return (struct i2c_master_s *)priv;
}
Expand All @@ -2434,15 +2424,15 @@ int imx9_i2cbus_uninitialize(struct i2c_master_s *dev)
return ERROR;
}

flags = spin_lock_irqsave(&priv->spinlock);
flags = enter_critical_section();

if (--priv->refs > 0)
{
leave_critical_section(flags);
return OK;
}

spin_unlock_irqrestore(&priv->spinlock, flags);
leave_critical_section(flags);

/* Disable power and other HW resource (GPIO's) */

Expand Down
Loading

0 comments on commit 44301ad

Please sign in to comment.