Skip to content

Commit 9aa5eda

Browse files
hujun260xiaoxiang781216
authored andcommitted
use small lock in following file
arch/arm/src/efm32/efm32_leserial.c arch/arm/src/efm32/efm32_serial.c arch/arm/src/gd32f4/gd32f4xx_serial.c arch/arm/src/imx9/imx9_edma.c arch/arm/src/imxrt/imxrt_edma.c arch/arm/src/imxrt/imxrt_hprtc.c arch/arm/src/kinetis/kinetis_lpserial.c arch/arm/src/lc823450/lc823450_gpio.c arch/arm/src/s32k1xx/s32k1xx_edma.c arch/arm/src/s32k3xx/s32k3xx_edma.c arch/arm64/src/imx9/imx9_edma.c Signed-off-by: hujun5 <[email protected]>
1 parent b66c1b9 commit 9aa5eda

File tree

11 files changed

+254
-111
lines changed

11 files changed

+254
-111
lines changed

arch/arm/src/efm32/efm32_leserial.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ struct efm32_leuart_s
134134
{
135135
const struct efm32_config_s *config;
136136
uint16_t ien; /* Interrupts enabled */
137+
spinlock_t lock; /* Spinlock */
137138
};
138139

139140
/****************************************************************************
@@ -212,6 +213,7 @@ static const struct efm32_config_s g_leuart0config =
212213
static struct efm32_leuart_s g_leuart0priv =
213214
{
214215
.config = &g_leuart0config,
216+
.lock = SP_UNLOCKED
215217
};
216218

217219
static struct uart_dev_s g_leuart0port =
@@ -247,6 +249,7 @@ static struct efm32_config_s g_leuart1config =
247249
static struct efm32_leuart_s g_leuart1priv =
248250
{
249251
.config = &g_leuart1config,
252+
.lock = SP_UNLOCKED
250253
};
251254

252255
static struct uart_dev_s g_leuart1port =
@@ -303,6 +306,17 @@ static inline void efm32_setuartint(struct efm32_leuart_s *priv)
303306
* Name: efm32_restoreuartint
304307
****************************************************************************/
305308

309+
static void efm32_restoreuartint_nolock(struct efm32_leuart_s *priv,
310+
uint32_t ien)
311+
{
312+
/* Re-enable/re-disable interrupts corresponding to the state of
313+
* bits in ien.
314+
*/
315+
316+
priv->ien = ien;
317+
efm32_setuartint(priv);
318+
}
319+
306320
static void efm32_restoreuartint(struct efm32_leuart_s *priv, uint32_t ien)
307321
{
308322
irqstate_t flags;
@@ -311,10 +325,9 @@ static void efm32_restoreuartint(struct efm32_leuart_s *priv, uint32_t ien)
311325
* bits in ien.
312326
*/
313327

314-
flags = spin_lock_irqsave(NULL);
315-
priv->ien = ien;
316-
efm32_setuartint(priv);
317-
spin_unlock_irqrestore(NULL, flags);
328+
flags = spin_lock_irqsave(&priv->lock);
329+
efm32_restoreuartint_nolock(priv, len);
330+
spin_unlock_irqrestore(&priv->lock, flags);
318331
}
319332

320333
/****************************************************************************
@@ -325,14 +338,14 @@ static void efm32_disableuartint(struct efm32_leuart_s *priv, uint32_t *ien)
325338
{
326339
irqstate_t flags;
327340

328-
flags = spin_lock_irqsave(NULL);
341+
flags = spin_lock_irqsave(&priv->lock);
329342
if (ien)
330343
{
331344
*ien = priv->ien;
332345
}
333346

334-
efm32_restoreuartint(priv, 0);
335-
spin_unlock_irqrestore(NULL, flags);
347+
efm32_restoreuartint_nolock(priv, 0);
348+
spin_unlock_irqrestore(&priv->lock, flags);
336349
}
337350

338351
/****************************************************************************
@@ -607,7 +620,7 @@ static void efm32_rxint(struct uart_dev_s *dev, bool enable)
607620
struct efm32_leuart_s *priv = (struct efm32_leuart_s *)dev->priv;
608621
irqstate_t flags;
609622

610-
flags = enter_critical_section();
623+
flags = spin_lock_irqsave(&priv->lock);
611624
if (enable)
612625
{
613626
/* Receive an interrupt when there is anything in the Rx data register
@@ -625,7 +638,7 @@ static void efm32_rxint(struct uart_dev_s *dev, bool enable)
625638
efm32_setuartint(priv);
626639
}
627640

628-
leave_critical_section(flags);
641+
spin_unlock_irqrestore(&priv->lock, flags);
629642
}
630643

631644
/****************************************************************************
@@ -673,7 +686,7 @@ static void efm32_txint(struct uart_dev_s *dev, bool enable)
673686
struct efm32_leuart_s *priv = (struct efm32_leuart_s *)dev->priv;
674687
irqstate_t flags;
675688

676-
flags = enter_critical_section();
689+
flags = spin_lock_irqsave(&priv->lock);
677690
if (enable)
678691
{
679692
/* Enable the TX interrupt */
@@ -697,7 +710,7 @@ static void efm32_txint(struct uart_dev_s *dev, bool enable)
697710
efm32_setuartint(priv);
698711
}
699712

700-
leave_critical_section(flags);
713+
spin_unlock_irqrestore(&priv->lock, flags);
701714
}
702715

703716
/****************************************************************************

arch/arm/src/efm32/efm32_serial.c

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ struct efm32_usart_s
223223
const struct efm32_config_s *config;
224224
#endif
225225
uint16_t ien; /* Interrupts enabled */
226+
spinlock_t lock; /* Spinlock */
226227
};
227228

228229
/****************************************************************************
@@ -303,7 +304,7 @@ static char g_uart1txbuffer[CONFIG_UART1_TXBUFSIZE];
303304
/* This describes the state of the EFM32 USART0 port. */
304305

305306
#ifdef CONFIG_EFM32_USART0_ISUART
306-
static const struct efm32_usart_s g_usart0config =
307+
static const struct efm32_config_s g_usart0config =
307308
{
308309
.uartbase = EFM32_USART0_BASE,
309310
.baud = CONFIG_USART0_BAUD,
@@ -317,6 +318,7 @@ static const struct efm32_usart_s g_usart0config =
317318
static struct efm32_usart_s g_usart0priv =
318319
{
319320
.config = &g_usart0config,
321+
.lock = SP_UNLOCKED
320322
};
321323

322324
static struct uart_dev_s g_usart0port =
@@ -353,6 +355,7 @@ static struct efm32_config_s g_usart1config =
353355
static struct efm32_usart_s g_usart1priv =
354356
{
355357
.config = &g_usart1config,
358+
.lock = SP_UNLOCKED
356359
};
357360

358361
static struct uart_dev_s g_usart1port =
@@ -389,6 +392,7 @@ static struct efm32_config_s g_usart2config =
389392
static struct efm32_usart_s g_usart2priv =
390393
{
391394
.config = &g_usart2config,
395+
.lock = SP_UNLOCKED
392396
};
393397

394398
static struct uart_dev_s g_usart2port =
@@ -425,6 +429,7 @@ static struct efm32_config_s g_uart0config =
425429
static struct efm32_usart_s g_uart0priv =
426430
{
427431
.config = &g_uart0config,
432+
.lock = SP_UNLOCKED
428433
};
429434

430435
static struct uart_dev_s g_uart0port =
@@ -447,7 +452,7 @@ static struct uart_dev_s g_uart0port =
447452
/* This describes the state of the EFM32 UART1 port. */
448453

449454
#ifdef CONFIG_EFM32_UART1
450-
static struct efm32_usart_s g_uart1config =
455+
static struct efm32_config_s g_uart1config =
451456
{
452457
.uartbase = EFM32_UART1_BASE,
453458
.baud = CONFIG_UART1_BAUD,
@@ -461,6 +466,7 @@ static struct efm32_usart_s g_uart1config =
461466
static struct efm32_usart_s g_uart1priv =
462467
{
463468
.config = &g_uart1config,
469+
.lock = SP_UNLOCKED
464470
};
465471

466472
static struct uart_dev_s g_uart1port =
@@ -516,6 +522,13 @@ static inline void efm32_setuartint(struct efm32_usart_s *priv)
516522
* Name: efm32_restoreuartint
517523
****************************************************************************/
518524

525+
static void efm32_restoreuartint_nolock(struct efm32_usart_s *priv,
526+
uint32_t ien)
527+
{
528+
priv->ien = ien;
529+
efm32_setuartint(priv);
530+
}
531+
519532
static void efm32_restoreuartint(struct efm32_usart_s *priv, uint32_t ien)
520533
{
521534
irqstate_t flags;
@@ -524,10 +537,9 @@ static void efm32_restoreuartint(struct efm32_usart_s *priv, uint32_t ien)
524537
* ien
525538
*/
526539

527-
flags = spin_lock_irqsave(NULL);
528-
priv->ien = ien;
529-
efm32_setuartint(priv);
530-
spin_unlock_irqrestore(NULL, flags);
540+
flags = spin_lock_irqsave(&priv->lock);
541+
efm32_restoreuartint_nolock(priv, len);
542+
spin_unlock_irqrestore(&priv->lock, flags);
531543
}
532544

533545
/****************************************************************************
@@ -539,14 +551,14 @@ static void efm32_disableuartint(struct efm32_usart_s *priv, uint32_t *ien)
539551
{
540552
irqstate_t flags;
541553

542-
flags = spin_lock_irqsave(NULL);
554+
flags = spin_lock_irqsave(&priv->lock);
543555
if (ien)
544556
{
545557
*ien = priv->ien;
546558
}
547559

548-
efm32_restoreuartint(priv, 0);
549-
spin_unlock_irqrestore(NULL, flags);
560+
efm32_restoreuartint_nolock(priv, 0);
561+
spin_unlock_irqrestore(&priv->lock, flags);
550562
}
551563
#endif
552564

@@ -966,7 +978,7 @@ static void efm32_rxint(struct uart_dev_s *dev, bool enable)
966978
struct efm32_usart_s *priv = (struct efm32_usart_s *)dev->priv;
967979
irqstate_t flags;
968980

969-
flags = enter_critical_section();
981+
flags = spin_lock_irqsave(&priv->lock);
970982
if (enable)
971983
{
972984
/* Receive an interrupt when their is anything in the Rx data register
@@ -984,7 +996,7 @@ static void efm32_rxint(struct uart_dev_s *dev, bool enable)
984996
efm32_setuartint(priv);
985997
}
986998

987-
leave_critical_section(flags);
999+
spin_unlock_irqrestore(&priv->lock, flags);
9881000
}
9891001

9901002
/****************************************************************************
@@ -1032,7 +1044,7 @@ static void efm32_txint(struct uart_dev_s *dev, bool enable)
10321044
struct efm32_usart_s *priv = (struct efm32_usart_s *)dev->priv;
10331045
irqstate_t flags;
10341046

1035-
flags = enter_critical_section();
1047+
flags = spin_lock_irqsave(&priv->lock);
10361048
if (enable)
10371049
{
10381050
/* Enable the TX interrupt */
@@ -1056,7 +1068,7 @@ static void efm32_txint(struct uart_dev_s *dev, bool enable)
10561068
efm32_setuartint(priv);
10571069
}
10581070

1059-
leave_critical_section(flags);
1071+
spin_unlock_irqrestore(&priv->lock, flags);
10601072
}
10611073

10621074
/****************************************************************************

arch/arm/src/gd32f4/gd32f4xx_serial.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ struct up_dev_s
131131
uint8_t stop_2bits; /* True: Configure with 2 stop bits instead of 1 */
132132
uint32_t tx_gpio; /* USART TX GPIO pin configuration */
133133
uint32_t rx_gpio; /* USART RX GPIO pin configuration */
134+
spinlock_t lock; /* Spinlock */
134135

135136
# ifdef CONFIG_SERIAL_IFLOWCONTROL
136137
uint32_t rts_gpio; /* UART RTS GPIO pin configuration */
@@ -437,6 +438,7 @@ static struct up_dev_s g_usart0priv =
437438

438439
.tx_gpio = GPIO_USART0_TX,
439440
.rx_gpio = GPIO_USART0_RX,
441+
.lock = SP_UNLOCKED,
440442
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART0_IFLOWCONTROL)
441443
.iflow = true,
442444
.rts_gpio = GPIO_USART0_RTS,
@@ -509,6 +511,7 @@ static struct up_dev_s g_usart1priv =
509511

510512
.tx_gpio = GPIO_USART1_TX,
511513
.rx_gpio = GPIO_USART1_RX,
514+
.lock = SP_UNLOCKED,
512515
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART1_IFLOWCONTROL)
513516
.iflow = true,
514517
.rts_gpio = GPIO_USART1_RTS,
@@ -581,6 +584,7 @@ static struct up_dev_s g_usart2priv =
581584

582585
.tx_gpio = GPIO_USART2_TX,
583586
.rx_gpio = GPIO_USART2_RX,
587+
.lock = SP_UNLOCKED,
584588
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART2_IFLOWCONTROL)
585589
.iflow = true,
586590
.rts_gpio = GPIO_USART2_RTS,
@@ -653,6 +657,7 @@ static struct up_dev_s g_usart5priv =
653657

654658
.tx_gpio = GPIO_USART5_TX,
655659
.rx_gpio = GPIO_USART5_RX,
660+
.lock = SP_UNLOCKED,
656661
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART5_IFLOWCONTROL)
657662
.iflow = true,
658663
.rts_gpio = GPIO_USART5_RTS,
@@ -725,6 +730,7 @@ static struct up_dev_s g_uart3priv =
725730

726731
.tx_gpio = GPIO_UART3_TX,
727732
.rx_gpio = GPIO_UART3_RX,
733+
.lock = SP_UNLOCKED,
728734
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_UART3_IFLOWCONTROL)
729735
.iflow = true,
730736
.rts_gpio = GPIO_UART3_RTS,
@@ -797,6 +803,7 @@ static struct up_dev_s g_uart4priv =
797803

798804
.tx_gpio = GPIO_UART4_TX,
799805
.rx_gpio = GPIO_UART4_RX,
806+
.lock = SP_UNLOCKED,
800807
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_UART4_IFLOWCONTROL)
801808
.iflow = true,
802809
.rts_gpio = GPIO_UART4_RTS,
@@ -869,6 +876,7 @@ static struct up_dev_s g_uart6priv =
869876

870877
.tx_gpio = GPIO_UART6_TX,
871878
.rx_gpio = GPIO_UART6_RX,
879+
.lock = SP_UNLOCKED,
872880
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_UART6_IFLOWCONTROL)
873881
.iflow = true,
874882
.rts_gpio = GPIO_UART6_RTS,
@@ -941,6 +949,7 @@ static struct up_dev_s g_uart7priv =
941949

942950
.tx_gpio = GPIO_UART7_TX,
943951
.rx_gpio = GPIO_UART7_RX,
952+
.lock = SP_UNLOCKED,
944953
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_UART7_IFLOWCONTROL)
945954
.iflow = true,
946955
.rts_gpio = GPIO_UART7_RTS,
@@ -1127,7 +1136,7 @@ static void up_disableusartint(struct up_dev_s *priv, uint32_t *ie)
11271136
irqstate_t flags;
11281137
uint32_t ctl_ie;
11291138

1130-
flags = spin_lock_irqsave(NULL);
1139+
flags = spin_lock_irqsave(&priv->lock);
11311140

11321141
if (ie)
11331142
{
@@ -1161,7 +1170,7 @@ static void up_disableusartint(struct up_dev_s *priv, uint32_t *ie)
11611170
ctl_ie = (USART_CFG_CTL_MASK << USART_CFG_SHIFT);
11621171
up_setusartint(priv, ctl_ie);
11631172

1164-
spin_unlock_irqrestore(NULL, flags);
1173+
spin_unlock_irqrestore(&priv->lock, flags);
11651174
}
11661175

11671176
/****************************************************************************
@@ -1172,11 +1181,11 @@ static void up_restoreusartint(struct up_dev_s *priv, uint32_t ie)
11721181
{
11731182
irqstate_t flags;
11741183

1175-
flags = spin_lock_irqsave(NULL);
1184+
flags = spin_lock_irqsave(&priv->lock);
11761185

11771186
up_setusartint(priv, ie);
11781187

1179-
spin_unlock_irqrestore(NULL, flags);
1188+
spin_unlock_irqrestore(&priv->lock, flags);
11801189
}
11811190

11821191
/****************************************************************************

0 commit comments

Comments
 (0)