Skip to content

Commit 50fd02c

Browse files
hujun260xiaoxiang781216
authored andcommitted
use small lock in following files:
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]>
1 parent 9aa5eda commit 50fd02c

File tree

14 files changed

+142
-75
lines changed

14 files changed

+142
-75
lines changed

arch/arm/src/kinetis/kinetis_serial.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ struct up_dev_s
308308
uint32_t rxdmanext; /* Next byte in the DMA buffer to be read */
309309
char *const rxfifo; /* Receive DMA buffer */
310310
#endif
311+
spinlock_t lock; /* Spinlock */
311312
};
312313

313314
/****************************************************************************
@@ -486,6 +487,7 @@ static struct up_dev_s g_uart0priv =
486487
.rxdma_reqsrc = KINETIS_DMA_REQUEST_SRC_UART0_RX,
487488
.rxfifo = g_uart0rxfifo,
488489
# endif
490+
.lock = SP_UNLOCKED
489491
};
490492

491493
static uart_dev_t g_uart0port =
@@ -536,6 +538,7 @@ static struct up_dev_s g_uart1priv =
536538
.rxdma_reqsrc = KINETIS_DMA_REQUEST_SRC_UART1_RX,
537539
.rxfifo = g_uart1rxfifo,
538540
# endif
541+
.lock = SP_UNLOCKED
539542
};
540543

541544
static uart_dev_t g_uart1port =
@@ -586,6 +589,7 @@ static struct up_dev_s g_uart2priv =
586589
.rxdma_reqsrc = KINETIS_DMA_REQUEST_SRC_UART2_RX,
587590
.rxfifo = g_uart2rxfifo,
588591
# endif
592+
.lock = SP_UNLOCKED
589593
};
590594

591595
static uart_dev_t g_uart2port =
@@ -636,6 +640,7 @@ static struct up_dev_s g_uart3priv =
636640
.rxdma_reqsrc = KINETIS_DMA_REQUEST_SRC_UART3_RX,
637641
.rxfifo = g_uart3rxfifo,
638642
# endif
643+
.lock = SP_UNLOCKED
639644
};
640645

641646
static uart_dev_t g_uart3port =
@@ -686,6 +691,7 @@ static struct up_dev_s g_uart4priv =
686691
.rxdma_reqsrc = KINETIS_DMA_REQUEST_SRC_UART4_RXTX,
687692
.rxfifo = g_uart4rxfifo,
688693
# endif
694+
.lock = SP_UNLOCKED
689695
};
690696

691697
static uart_dev_t g_uart4port =
@@ -736,6 +742,7 @@ static struct up_dev_s g_uart5priv =
736742
.rxdma_reqsrc = KINETIS_DMA_REQUEST_SRC_UART5_RX,
737743
.rxfifo = g_uart5rxfifo,
738744
# endif
745+
.lock = SP_UNLOCKED
739746
};
740747

741748
static uart_dev_t g_uart5port =
@@ -786,21 +793,27 @@ static inline void up_serialout(struct up_dev_s *priv, int offset,
786793
* Name: up_setuartint
787794
****************************************************************************/
788795

789-
static void up_setuartint(struct up_dev_s *priv)
796+
static void up_setuartint_nolock(struct up_dev_s *priv)
790797
{
791-
irqstate_t flags;
792798
uint8_t regval;
793799

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

798-
flags = spin_lock_irqsave(NULL);
799804
regval = up_serialin(priv, KINETIS_UART_C2_OFFSET);
800805
regval &= ~UART_C2_ALLINTS;
801806
regval |= priv->ie;
802807
up_serialout(priv, KINETIS_UART_C2_OFFSET, regval);
803-
spin_unlock_irqrestore(NULL, flags);
808+
}
809+
810+
static void up_setuartint(struct up_dev_s *priv)
811+
{
812+
irqstate_t flags;
813+
814+
flags = spin_lock_irqsave(&priv->lock);
815+
up_setuartint_nolock(priv);
816+
spin_unlock_irqrestore(&priv->lock, flags);
804817
}
805818

806819
/****************************************************************************
@@ -815,10 +828,10 @@ static void up_restoreuartint(struct up_dev_s *priv, uint8_t ie)
815828
* ie
816829
*/
817830

818-
flags = spin_lock_irqsave(NULL);
831+
flags = spin_lock_irqsave(&priv->lock);
819832
priv->ie = ie & UART_C2_ALLINTS;
820-
up_setuartint(priv);
821-
spin_unlock_irqrestore(NULL, flags);
833+
up_setuartint_nolock(priv);
834+
spin_unlock_irqrestore(&priv->lock, flags);
822835
}
823836

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

833-
flags = spin_lock_irqsave(NULL);
846+
flags = spin_lock_irqsave(&priv->lock);
834847
if (ie)
835848
{
836849
*ie = priv->ie;
837850
}
838851

839-
up_restoreuartint(priv, 0);
840-
spin_unlock_irqrestore(NULL, flags);
852+
priv->ie = 0;
853+
up_setuartint_nolock(priv);
854+
spin_unlock_irqrestore(&priv->lock, flags);
841855
}
842856
#endif
843857

arch/arm/src/kl/kl_serial.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ struct up_dev_s
148148
uint8_t ie; /* Interrupts enabled */
149149
uint8_t parity; /* 0=none, 1=odd, 2=even */
150150
uint8_t bits; /* Number of bits (8 or 9) */
151+
spinlock_t lock; /* Spinlock */
151152
};
152153

153154
/****************************************************************************
@@ -216,6 +217,7 @@ static struct up_dev_s g_uart0priv =
216217
.irq = KL_IRQ_UART0,
217218
.parity = CONFIG_UART0_PARITY,
218219
.bits = CONFIG_UART0_BITS,
220+
.lock = SP_UNLOCKED
219221
};
220222

221223
static uart_dev_t g_uart0port =
@@ -246,6 +248,7 @@ static struct up_dev_s g_uart1priv =
246248
.irq = KL_IRQ_UART1,
247249
.parity = CONFIG_UART1_PARITY,
248250
.bits = CONFIG_UART1_BITS,
251+
.lock = SP_UNLOCKED
249252
};
250253

251254
static uart_dev_t g_uart1port =
@@ -276,6 +279,7 @@ static struct up_dev_s g_uart2priv =
276279
.irq = KL_IRQ_UART2,
277280
.parity = CONFIG_UART2_PARITY,
278281
.bits = CONFIG_UART2_BITS,
282+
.lock = SP_UNLOCKED
279283
};
280284

281285
static uart_dev_t g_uart2port =
@@ -322,27 +326,39 @@ static inline void up_serialout(struct up_dev_s *priv, int offset,
322326
* Name: up_setuartint
323327
****************************************************************************/
324328

325-
static void up_setuartint(struct up_dev_s *priv)
329+
static void up_setuartint_nolock(struct up_dev_s *priv)
326330
{
327-
irqstate_t flags;
328331
uint8_t regval;
329332

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

334-
flags = spin_lock_irqsave(NULL);
335337
regval = up_serialin(priv, KL_UART_C2_OFFSET);
336338
regval &= ~UART_C2_ALLINTS;
337339
regval |= priv->ie;
338340
up_serialout(priv, KL_UART_C2_OFFSET, regval);
339-
spin_unlock_irqrestore(NULL, flags);
341+
}
342+
343+
static void up_setuartint(struct up_dev_s *priv)
344+
{
345+
irqstate_t flags;
346+
347+
flags = spin_lock_irqsave(&priv->lock);
348+
up_setuartint_nolock(priv);
349+
spin_unlock_irqrestore(&priv->lock, flags);
340350
}
341351

342352
/****************************************************************************
343353
* Name: up_restoreuartint
344354
****************************************************************************/
345355

356+
static void up_restoreuartint_nolock(struct up_dev_s *priv, uint8_t ie)
357+
{
358+
priv->ie = ie & UART_C2_ALLINTS;
359+
up_setuartint_nolock(priv);
360+
}
361+
346362
static void up_restoreuartint(struct up_dev_s *priv, uint8_t ie)
347363
{
348364
irqstate_t flags;
@@ -351,10 +367,9 @@ static void up_restoreuartint(struct up_dev_s *priv, uint8_t ie)
351367
* in ie.
352368
*/
353369

354-
flags = spin_lock_irqsave(NULL);
355-
priv->ie = ie & UART_C2_ALLINTS;
356-
up_setuartint(priv);
357-
spin_unlock_irqrestore(NULL, flags);
370+
flags = spin_lock_irqsave(&priv->lock);
371+
up_restoreuartint_nolock(priv, ie);
372+
spin_unlock_irqrestore(&priv->lock, flags);
358373
}
359374

360375
/****************************************************************************
@@ -365,14 +380,14 @@ static void up_disableuartint(struct up_dev_s *priv, uint8_t *ie)
365380
{
366381
irqstate_t flags;
367382

368-
flags = spin_lock_irqsave(NULL);
383+
flags = spin_lock_irqsave(&priv->lock);
369384
if (ie)
370385
{
371386
*ie = priv->ie;
372387
}
373388

374-
up_restoreuartint(priv, 0);
375-
spin_unlock_irqrestore(NULL, flags);
389+
up_restoreuartint_nolock(priv, 0);
390+
spin_unlock_irqrestore(&priv->lock, flags);
376391
}
377392

378393
/****************************************************************************

arch/arm/src/lc823450/lc823450_irq.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ const uint32_t g_cpu_intstack_top[CONFIG_SMP_NCPUS] =
9797
* Private Data
9898
****************************************************************************/
9999

100+
static spinlock_t g_lc823450_irq_lock = SP_UNLOCKED;
101+
100102
#ifdef CONFIG_LC823450_VIRQ
101103
static struct lc823450_irq_ops *virq_ops[LC823450_IRQ_NVIRTUALIRQS];
102104
#endif /* CONFIG_LC823450_VIRQ */
@@ -625,7 +627,7 @@ void up_enable_irq(int irq)
625627
* set the bit in the System Handler Control and State Register.
626628
*/
627629

628-
flags = spin_lock_irqsave(NULL);
630+
flags = spin_lock_irqsave(&g_lc823450_irq_lock);
629631

630632
if (irq >= LC823450_IRQ_NIRQS)
631633
{
@@ -648,7 +650,7 @@ void up_enable_irq(int irq)
648650
putreg32(regval, regaddr);
649651
}
650652

651-
spin_unlock_irqrestore(NULL, flags);
653+
spin_unlock_irqrestore(&g_lc823450_irq_lock, flags);
652654
}
653655

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

776-
flags = spin_lock_irqsave(NULL);
778+
flags = spin_lock_irqsave(&g_lc823450_irq_lock);
777779

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

784786
putreg32(regval, regaddr);
785787

786-
spin_unlock_irqrestore(NULL, flags);
788+
spin_unlock_irqrestore(&g_lc823450_irq_lock, flags);
787789

788790
return OK;
789791
}

arch/arm/src/lc823450/lc823450_syscontrol.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
* Private Data
4444
****************************************************************************/
4545

46+
static spinlock_t g_lc823450_syscontrol_lock = SP_UNLOCKED;
4647
static struct clk_st lc823450_clocks[] = LC823450_CLOCKS;
4748

4849
/****************************************************************************
@@ -132,7 +133,7 @@ void mod_stby_regs(uint32_t enabits, uint32_t disbits)
132133
void up_enable_clk(enum clock_e clk)
133134
{
134135
irqstate_t flags;
135-
flags = spin_lock_irqsave(NULL);
136+
flags = spin_lock_irqsave(&g_lc823450_syscontrol_lock);
136137

137138
DEBUGASSERT(clk < LC823450_CLOCK_NUM);
138139

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

145-
spin_unlock_irqrestore(NULL, flags);
146+
spin_unlock_irqrestore(&g_lc823450_syscontrol_lock, flags);
146147
}
147148

148149
/****************************************************************************
@@ -152,7 +153,7 @@ void up_enable_clk(enum clock_e clk)
152153
void up_disable_clk(enum clock_e clk)
153154
{
154155
irqstate_t flags;
155-
flags = spin_lock_irqsave(NULL);
156+
flags = spin_lock_irqsave(&g_lc823450_syscontrol_lock);
156157

157158
DEBUGASSERT(clk < LC823450_CLOCK_NUM);
158159

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

172-
spin_unlock_irqrestore(NULL, flags);
173+
spin_unlock_irqrestore(&g_lc823450_syscontrol_lock, flags);
173174
}
174175

175176
/****************************************************************************

0 commit comments

Comments
 (0)