Skip to content

Commit

Permalink
use small lock in following files:
Browse files Browse the repository at this point in the history
arch/arm/src/kinetis/kinetis_serial.c
arch/arm/src/kl/kl_serial.c
arch/arm/src/lc823450/lc823450_irq.c
arch/arm/src/lc823450/lc823450_syscontrol.c
arch/arm/src/lpc54xx/lpc54_serial.c
arch/arm/src/max326xx/max32660/max32660_dma.c
arch/arm/src/max326xx/max32660/max32660_gpio.c
arch/arm/src/max326xx/max32660/max32660_lowputc.c
arch/arm/src/max326xx/max32660/max32660_serial.c
arch/arm/src/mx8mp/mx8mp_serial.c
arch/arm/src/nrf52/nrf52_gpio.c
arch/arm/src/nrf53/nrf53_gpio.c
arch/arm/src/nrf91/nrf91_gpio.c
arch/arm/src/rp2040/rp2040_uart.c

Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 authored and xiaoxiang781216 committed Dec 23, 2024
1 parent 9aa5eda commit 50fd02c
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 75 deletions.
34 changes: 24 additions & 10 deletions arch/arm/src/kinetis/kinetis_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ struct up_dev_s
uint32_t rxdmanext; /* Next byte in the DMA buffer to be read */
char *const rxfifo; /* Receive DMA buffer */
#endif
spinlock_t lock; /* Spinlock */
};

/****************************************************************************
Expand Down Expand Up @@ -486,6 +487,7 @@ static struct up_dev_s g_uart0priv =
.rxdma_reqsrc = KINETIS_DMA_REQUEST_SRC_UART0_RX,
.rxfifo = g_uart0rxfifo,
# endif
.lock = SP_UNLOCKED
};

static uart_dev_t g_uart0port =
Expand Down Expand Up @@ -536,6 +538,7 @@ static struct up_dev_s g_uart1priv =
.rxdma_reqsrc = KINETIS_DMA_REQUEST_SRC_UART1_RX,
.rxfifo = g_uart1rxfifo,
# endif
.lock = SP_UNLOCKED
};

static uart_dev_t g_uart1port =
Expand Down Expand Up @@ -586,6 +589,7 @@ static struct up_dev_s g_uart2priv =
.rxdma_reqsrc = KINETIS_DMA_REQUEST_SRC_UART2_RX,
.rxfifo = g_uart2rxfifo,
# endif
.lock = SP_UNLOCKED
};

static uart_dev_t g_uart2port =
Expand Down Expand Up @@ -636,6 +640,7 @@ static struct up_dev_s g_uart3priv =
.rxdma_reqsrc = KINETIS_DMA_REQUEST_SRC_UART3_RX,
.rxfifo = g_uart3rxfifo,
# endif
.lock = SP_UNLOCKED
};

static uart_dev_t g_uart3port =
Expand Down Expand Up @@ -686,6 +691,7 @@ static struct up_dev_s g_uart4priv =
.rxdma_reqsrc = KINETIS_DMA_REQUEST_SRC_UART4_RXTX,
.rxfifo = g_uart4rxfifo,
# endif
.lock = SP_UNLOCKED
};

static uart_dev_t g_uart4port =
Expand Down Expand Up @@ -736,6 +742,7 @@ static struct up_dev_s g_uart5priv =
.rxdma_reqsrc = KINETIS_DMA_REQUEST_SRC_UART5_RX,
.rxfifo = g_uart5rxfifo,
# endif
.lock = SP_UNLOCKED
};

static uart_dev_t g_uart5port =
Expand Down Expand Up @@ -786,21 +793,27 @@ static inline void up_serialout(struct up_dev_s *priv, int offset,
* Name: up_setuartint
****************************************************************************/

static void up_setuartint(struct up_dev_s *priv)
static void up_setuartint_nolock(struct up_dev_s *priv)
{
irqstate_t flags;
uint8_t regval;

/* Re-enable/re-disable interrupts corresponding to the state of bits in
* ie
*/

flags = spin_lock_irqsave(NULL);
regval = up_serialin(priv, KINETIS_UART_C2_OFFSET);
regval &= ~UART_C2_ALLINTS;
regval |= priv->ie;
up_serialout(priv, KINETIS_UART_C2_OFFSET, regval);
spin_unlock_irqrestore(NULL, flags);
}

static void up_setuartint(struct up_dev_s *priv)
{
irqstate_t flags;

flags = spin_lock_irqsave(&priv->lock);
up_setuartint_nolock(priv);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
Expand All @@ -815,10 +828,10 @@ static void up_restoreuartint(struct up_dev_s *priv, uint8_t ie)
* ie
*/

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&priv->lock);
priv->ie = ie & UART_C2_ALLINTS;
up_setuartint(priv);
spin_unlock_irqrestore(NULL, flags);
up_setuartint_nolock(priv);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
Expand All @@ -830,14 +843,15 @@ static void up_disableuartint(struct up_dev_s *priv, uint8_t *ie)
{
irqstate_t flags;

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&priv->lock);
if (ie)
{
*ie = priv->ie;
}

up_restoreuartint(priv, 0);
spin_unlock_irqrestore(NULL, flags);
priv->ie = 0;
up_setuartint_nolock(priv);
spin_unlock_irqrestore(&priv->lock, flags);
}
#endif

Expand Down
37 changes: 26 additions & 11 deletions arch/arm/src/kl/kl_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ struct up_dev_s
uint8_t ie; /* Interrupts enabled */
uint8_t parity; /* 0=none, 1=odd, 2=even */
uint8_t bits; /* Number of bits (8 or 9) */
spinlock_t lock; /* Spinlock */
};

/****************************************************************************
Expand Down Expand Up @@ -216,6 +217,7 @@ static struct up_dev_s g_uart0priv =
.irq = KL_IRQ_UART0,
.parity = CONFIG_UART0_PARITY,
.bits = CONFIG_UART0_BITS,
.lock = SP_UNLOCKED
};

static uart_dev_t g_uart0port =
Expand Down Expand Up @@ -246,6 +248,7 @@ static struct up_dev_s g_uart1priv =
.irq = KL_IRQ_UART1,
.parity = CONFIG_UART1_PARITY,
.bits = CONFIG_UART1_BITS,
.lock = SP_UNLOCKED
};

static uart_dev_t g_uart1port =
Expand Down Expand Up @@ -276,6 +279,7 @@ static struct up_dev_s g_uart2priv =
.irq = KL_IRQ_UART2,
.parity = CONFIG_UART2_PARITY,
.bits = CONFIG_UART2_BITS,
.lock = SP_UNLOCKED
};

static uart_dev_t g_uart2port =
Expand Down Expand Up @@ -322,27 +326,39 @@ static inline void up_serialout(struct up_dev_s *priv, int offset,
* Name: up_setuartint
****************************************************************************/

static void up_setuartint(struct up_dev_s *priv)
static void up_setuartint_nolock(struct up_dev_s *priv)
{
irqstate_t flags;
uint8_t regval;

/* Re-enable/re-disable interrupts corresponding to the state of bits
* in ie.
*/

flags = spin_lock_irqsave(NULL);
regval = up_serialin(priv, KL_UART_C2_OFFSET);
regval &= ~UART_C2_ALLINTS;
regval |= priv->ie;
up_serialout(priv, KL_UART_C2_OFFSET, regval);
spin_unlock_irqrestore(NULL, flags);
}

static void up_setuartint(struct up_dev_s *priv)
{
irqstate_t flags;

flags = spin_lock_irqsave(&priv->lock);
up_setuartint_nolock(priv);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
* Name: up_restoreuartint
****************************************************************************/

static void up_restoreuartint_nolock(struct up_dev_s *priv, uint8_t ie)
{
priv->ie = ie & UART_C2_ALLINTS;
up_setuartint_nolock(priv);
}

static void up_restoreuartint(struct up_dev_s *priv, uint8_t ie)
{
irqstate_t flags;
Expand All @@ -351,10 +367,9 @@ static void up_restoreuartint(struct up_dev_s *priv, uint8_t ie)
* in ie.
*/

flags = spin_lock_irqsave(NULL);
priv->ie = ie & UART_C2_ALLINTS;
up_setuartint(priv);
spin_unlock_irqrestore(NULL, flags);
flags = spin_lock_irqsave(&priv->lock);
up_restoreuartint_nolock(priv, ie);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
Expand All @@ -365,14 +380,14 @@ static void up_disableuartint(struct up_dev_s *priv, uint8_t *ie)
{
irqstate_t flags;

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&priv->lock);
if (ie)
{
*ie = priv->ie;
}

up_restoreuartint(priv, 0);
spin_unlock_irqrestore(NULL, flags);
up_restoreuartint_nolock(priv, 0);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
Expand Down
10 changes: 6 additions & 4 deletions arch/arm/src/lc823450/lc823450_irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const uint32_t g_cpu_intstack_top[CONFIG_SMP_NCPUS] =
* Private Data
****************************************************************************/

static spinlock_t g_lc823450_irq_lock = SP_UNLOCKED;

#ifdef CONFIG_LC823450_VIRQ
static struct lc823450_irq_ops *virq_ops[LC823450_IRQ_NVIRTUALIRQS];
#endif /* CONFIG_LC823450_VIRQ */
Expand Down Expand Up @@ -625,7 +627,7 @@ void up_enable_irq(int irq)
* set the bit in the System Handler Control and State Register.
*/

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_lc823450_irq_lock);

if (irq >= LC823450_IRQ_NIRQS)
{
Expand All @@ -648,7 +650,7 @@ void up_enable_irq(int irq)
putreg32(regval, regaddr);
}

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_lc823450_irq_lock, flags);
}

/* lc823450_dumpnvic("enable", irq); */
Expand Down Expand Up @@ -773,7 +775,7 @@ int lc823450_irq_srctype(int irq, enum lc823450_srctype_e srctype)
port = (irq & 0x70) >> 4;
gpio = irq & 0xf;

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_lc823450_irq_lock);

regaddr = INTC_REG(EXTINTCND_BASE, port);
regval = getreg32(regaddr);
Expand All @@ -783,7 +785,7 @@ int lc823450_irq_srctype(int irq, enum lc823450_srctype_e srctype)

putreg32(regval, regaddr);

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_lc823450_irq_lock, flags);

return OK;
}
Expand Down
9 changes: 5 additions & 4 deletions arch/arm/src/lc823450/lc823450_syscontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
* Private Data
****************************************************************************/

static spinlock_t g_lc823450_syscontrol_lock = SP_UNLOCKED;
static struct clk_st lc823450_clocks[] = LC823450_CLOCKS;

/****************************************************************************
Expand Down Expand Up @@ -132,7 +133,7 @@ void mod_stby_regs(uint32_t enabits, uint32_t disbits)
void up_enable_clk(enum clock_e clk)
{
irqstate_t flags;
flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_lc823450_syscontrol_lock);

DEBUGASSERT(clk < LC823450_CLOCK_NUM);

Expand All @@ -142,7 +143,7 @@ void up_enable_clk(enum clock_e clk)
0, lc823450_clocks[clk].regmask);
}

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_lc823450_syscontrol_lock, flags);
}

/****************************************************************************
Expand All @@ -152,7 +153,7 @@ void up_enable_clk(enum clock_e clk)
void up_disable_clk(enum clock_e clk)
{
irqstate_t flags;
flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_lc823450_syscontrol_lock);

DEBUGASSERT(clk < LC823450_CLOCK_NUM);

Expand All @@ -169,7 +170,7 @@ void up_disable_clk(enum clock_e clk)
lc823450_clocks[clk].count = 0;
}

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_lc823450_syscontrol_lock, flags);
}

/****************************************************************************
Expand Down
Loading

0 comments on commit 50fd02c

Please sign in to comment.