Skip to content

Commit 798695a

Browse files
hujun260xiaoxiang781216
authored andcommitted
use small lock in following files:
arch/arm/src/tiva/common/tiva_hciuart.c arch/arm/src/tms570/tms570_lowputc.c arch/arm/src/xmc4/xmc4_serial.c arch/arm64/src/a64/a64_serial.c arch/mips/src/pic32mx/pic32mx_serial.c arch/mips/src/pic32mz/pic32mz_serial.c arch/risc-v/src/c906/c906_serial.c arch/risc-v/src/fe310/fe310_serial.c arch/risc-v/src/hpm6750/hpm6750_serial.c arch/risc-v/src/k210/k210_serial.c arch/sparc/src/bm3803/bm3803-serial.c arch/sparc/src/bm3823/bm3823-serial.c Signed-off-by: hujun5 <[email protected]>
1 parent 4d7be17 commit 798695a

File tree

12 files changed

+164
-95
lines changed

12 files changed

+164
-95
lines changed

arch/arm/src/tiva/common/tiva_hciuart.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ struct hciuart_config_s
103103
{
104104
struct btuart_lowerhalf_s lower; /* Generic HCI-UART lower half */
105105
struct hciuart_state_s *state; /* Reference to variable state */
106+
spinlock_t lock; /* Spinlock */
106107
uint8_t *rxbuffer; /* Rx buffer start */
107108
uint8_t *txbuffer; /* Tx buffer start */
108109
uint16_t rxbufsize; /* Size of the Rx buffer */
@@ -205,6 +206,7 @@ static const struct hciuart_config_s g_hciuart0_config =
205206
},
206207

207208
.state = &g_hciuart0_state,
209+
.lock = SP_UNLOCKED,
208210

209211
.rxbuffer = g_uart0_rxbuffer,
210212
.txbuffer = g_uart0_txbuffer,
@@ -255,6 +257,7 @@ static const struct hciuart_config_s g_hciuart1_config =
255257
},
256258

257259
.state = &g_hciuart1_state,
260+
.lock = SP_UNLOCKED,
258261

259262
.rxbuffer = g_uart1_rxbuffer,
260263
.txbuffer = g_uart1_txbuffer,
@@ -305,6 +308,7 @@ static const struct hciuart_config_s g_hciuart2_config =
305308
},
306309

307310
.state = &g_hciuart2_state,
311+
.lock = SP_UNLOCKED,
308312

309313
.rxbuffer = g_uart2_rxbuffer,
310314
.txbuffer = g_uart2_txbuffer,
@@ -355,6 +359,7 @@ static const struct hciuart_config_s g_hciuart3_config =
355359
},
356360

357361
.state = &g_hciuart3_state,
362+
.lock = SP_UNLOCKED,
358363

359364
.rxbuffer = g_uart3_rxbuffer,
360365
.txbuffer = g_uart3_txbuffer,
@@ -405,6 +410,7 @@ static const struct hciuart_config_s g_hciuart4_config =
405410
},
406411

407412
.state = &g_hciuart4_state,
413+
.lock = SP_UNLOCKED,
408414

409415
.rxbuffer = g_uart4_rxbuffer,
410416
.txbuffer = g_uart4_txbuffer,
@@ -455,6 +461,7 @@ static const struct hciuart_config_s g_hciuart5_config =
455461
},
456462

457463
.state = &g_hciuart5_state,
464+
.lock = SP_UNLOCKED,
458465

459466
.rxbuffer = g_uart5_rxbuffer,
460467
.txbuffer = g_uart5_txbuffer,
@@ -505,6 +512,7 @@ static const struct hciuart_config_s g_hciuart6_config =
505512
},
506513

507514
.state = &g_hciuart6_state,
515+
.lock = SP_UNLOCKED,
508516

509517
.rxbuffer = g_uart6_rxbuffer,
510518
.txbuffer = g_uart6_txbuffer,
@@ -555,6 +563,7 @@ static const struct hciuart_config_s g_hciuart7_config =
555563
},
556564

557565
.state = &g_hciuart7_state,
566+
.lock = SP_UNLOCKED,
558567

559568
.rxbuffer = g_uart7_rxbuffer,
560569
.txbuffer = g_uart7_txbuffer,
@@ -1272,7 +1281,7 @@ static void hciuart_rxattach(const struct btuart_lowerhalf_s *lower,
12721281

12731282
/* If the callback is NULL, then we are detaching */
12741283

1275-
flags = spin_lock_irqsave(NULL);
1284+
flags = spin_lock_irqsave(&config->lock);
12761285
if (callback == NULL)
12771286
{
12781287
uint32_t intset;
@@ -1294,7 +1303,7 @@ static void hciuart_rxattach(const struct btuart_lowerhalf_s *lower,
12941303
state->callback = callback;
12951304
}
12961305

1297-
spin_unlock_irqrestore(NULL, flags);
1306+
spin_unlock_irqrestore(&config->lock, flags);
12981307
}
12991308

13001309
/****************************************************************************
@@ -1322,7 +1331,7 @@ static void hciuart_rxenable(const struct btuart_lowerhalf_s *lower,
13221331
uint32_t intset;
13231332
irqstate_t flags;
13241333

1325-
flags = spin_lock_irqsave(NULL);
1334+
flags = spin_lock_irqsave(&config->lock);
13261335
if (enable)
13271336
{
13281337
/* Receive an interrupt when their is anything in the Rx data
@@ -1338,7 +1347,7 @@ static void hciuart_rxenable(const struct btuart_lowerhalf_s *lower,
13381347
hciuart_disableints(config, intset);
13391348
}
13401349

1341-
spin_unlock_irqrestore(NULL, flags);
1350+
spin_unlock_irqrestore(&config->lock, flags);
13421351
}
13431352
}
13441353

@@ -1524,9 +1533,9 @@ static ssize_t hciuart_write(const struct btuart_lowerhalf_s *lower,
15241533

15251534
/* Make sure that the Tx Interrupts are disabled. */
15261535

1527-
flags = spin_lock_irqsave(NULL);
1536+
flags = spin_lock_irqsave(&config->lock);
15281537
hciuart_disableints(config, UART_IM_TXIM);
1529-
spin_unlock_irqrestore(NULL, flags);
1538+
spin_unlock_irqrestore(&config->lock, flags);
15301539

15311540
/* Loop until all of the user data have been moved to the Tx buffer */
15321541

@@ -1621,9 +1630,9 @@ static ssize_t hciuart_write(const struct btuart_lowerhalf_s *lower,
16211630

16221631
if (state->txhead != state->txtail)
16231632
{
1624-
flags = spin_lock_irqsave(NULL);
1633+
flags = spin_lock_irqsave(&config->lock);
16251634
hciuart_enableints(config, UART_IM_TXIM);
1626-
spin_unlock_irqrestore(NULL, flags);
1635+
spin_unlock_irqrestore(&config->lock, flags);
16271636
}
16281637

16291638
return ntotal;

arch/arm/src/tms570/tms570_lowputc.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@
8282
# undef HAVE_SERIAL_CONSOLE
8383
#endif
8484

85+
/****************************************************************************
86+
* Private Data
87+
****************************************************************************/
88+
89+
static spinlock_t g_tms570_lowputc_lock = SP_UNLOCKED;
90+
8591
/****************************************************************************
8692
* Public Data
8793
****************************************************************************/
@@ -187,30 +193,18 @@ void arm_lowputc(char ch)
187193
#ifdef HAVE_SERIAL_CONSOLE
188194
irqstate_t flags;
189195

190-
for (; ; )
191-
{
192-
/* Wait for the transmitter to be available */
196+
/* Wait for the transmitter to be available */
193197

194-
while ((getreg32(TMS570_CONSOLE_BASE + TMS570_SCI_FLR_OFFSET) &
195-
SCI_FLR_TXRDY) == 0);
198+
flags = spin_lock_irqsave(&g_tms570_lowputc_lock);
196199

197-
/* Disable interrupts so that the test and the transmission are
198-
* atomic.
199-
*/
200+
while ((getreg32(TMS570_CONSOLE_BASE + TMS570_SCI_FLR_OFFSET) &
201+
SCI_FLR_TXRDY) == 0);
200202

201-
flags = spin_lock_irqsave(NULL);
202-
if ((getreg32(TMS570_CONSOLE_BASE + TMS570_SCI_FLR_OFFSET) &
203-
SCI_FLR_TXRDY) != 0)
204-
{
205-
/* Send the character */
203+
/* Send the character */
206204

207-
putreg32((uint32_t)ch, TMS570_CONSOLE_BASE + TMS570_SCI_TD_OFFSET);
208-
spin_unlock_irqrestore(NULL, flags);
209-
return;
210-
}
205+
putreg32((uint32_t)ch, TMS570_CONSOLE_BASE + TMS570_SCI_TD_OFFSET);
211206

212-
spin_unlock_irqrestore(NULL, flags);
213-
}
207+
spin_unlock_irqrestore(&g_tms570_lowputc_lock, flags);
214208
#endif
215209
}
216210

arch/arm/src/xmc4/xmc4_serial.c

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ struct xmc4_dev_s
238238
/* UART configuration */
239239

240240
struct uart_config_s config;
241+
spinlock_t lock;
241242
};
242243

243244
/****************************************************************************
@@ -326,7 +327,8 @@ static struct xmc4_dev_s g_uart0priv =
326327
.startbufferptr = 0,
327328
.txbuffersize = CONFIG_XMC4_USIC0_CHAN0_TX_BUFFER_SIZE,
328329
.rxbuffersize = CONFIG_XMC4_USIC0_CHAN0_RX_BUFFER_SIZE,
329-
}
330+
},
331+
.lock = SP_UNLOCKED,
330332
};
331333

332334
static uart_dev_t g_uart0port =
@@ -365,7 +367,8 @@ static struct xmc4_dev_s g_uart1priv =
365367
+ CONFIG_XMC4_USIC0_CHAN0_RX_BUFFER_SIZE,
366368
.txbuffersize = CONFIG_XMC4_USIC0_CHAN1_TX_BUFFER_SIZE,
367369
.rxbuffersize = CONFIG_XMC4_USIC0_CHAN1_RX_BUFFER_SIZE,
368-
}
370+
},
371+
.lock = SP_UNLOCKED,
369372
};
370373

371374
static uart_dev_t g_uart1port =
@@ -403,7 +406,8 @@ static struct xmc4_dev_s g_uart2priv =
403406
.startbufferptr = 0,
404407
.txbuffersize = CONFIG_XMC4_USIC1_CHAN0_TX_BUFFER_SIZE,
405408
.rxbuffersize = CONFIG_XMC4_USIC1_CHAN0_RX_BUFFER_SIZE,
406-
}
409+
},
410+
.lock = SP_UNLOCKED,
407411
};
408412

409413
static uart_dev_t g_uart2port =
@@ -442,7 +446,8 @@ static struct xmc4_dev_s g_uart3priv =
442446
+ CONFIG_XMC4_USIC1_CHAN0_RX_BUFFER_SIZE,
443447
.txbuffersize = CONFIG_XMC4_USIC1_CHAN1_TX_BUFFER_SIZE,
444448
.rxbuffersize = CONFIG_XMC4_USIC1_CHAN1_RX_BUFFER_SIZE,
445-
}
449+
},
450+
.lock = SP_UNLOCKED,
446451
};
447452

448453
static uart_dev_t g_uart3port =
@@ -480,7 +485,8 @@ static struct xmc4_dev_s g_uart4priv =
480485
.startbufferptr = 0,
481486
.txbuffersize = CONFIG_XMC4_USIC2_CHAN0_TX_BUFFER_SIZE,
482487
.rxbuffersize = CONFIG_XMC4_USIC2_CHAN0_RX_BUFFER_SIZE,
483-
}
488+
},
489+
.lock = SP_UNLOCKED,
484490
};
485491

486492
static uart_dev_t g_uart4port =
@@ -519,7 +525,8 @@ static struct xmc4_dev_s g_uart5priv =
519525
+ CONFIG_XMC4_USIC2_CHAN0_RX_BUFFER_SIZE,
520526
.txbuffersize = CONFIG_XMC4_USIC2_CHAN1_TX_BUFFER_SIZE,
521527
.rxbuffersize = CONFIG_XMC4_USIC2_CHAN1_RX_BUFFER_SIZE,
522-
}
528+
},
529+
.lock = SP_UNLOCKED,
523530
};
524531

525532
static uart_dev_t g_uart5port =
@@ -567,22 +574,28 @@ static inline void xmc4_serialout(struct xmc4_dev_s *priv,
567574
* Name: xmc4_modifyreg
568575
****************************************************************************/
569576

570-
static inline void xmc4_modifyreg(struct xmc4_dev_s *priv, unsigned
577+
static inline void xmc4_modifyreg_nolock(struct xmc4_dev_s *priv, unsigned
571578
int offset, uint32_t setbits,
572579
uint32_t clrbits)
573580
{
574-
irqstate_t flags;
575581
uintptr_t regaddr = priv->uartbase + offset;
576582
uint32_t regval;
577583

578-
flags = spin_lock_irqsave(NULL);
579-
580584
regval = getreg32(regaddr);
581585
regval &= ~clrbits;
582586
regval |= setbits;
583587
putreg32(regval, regaddr);
588+
}
584589

585-
spin_unlock_irqrestore(NULL, flags);
590+
static inline void xmc4_modifyreg(struct xmc4_dev_s *priv, unsigned
591+
int offset, uint32_t setbits,
592+
uint32_t clrbits)
593+
{
594+
irqstate_t flags;
595+
596+
flags = spin_lock_irqsave(&priv->lock);
597+
xmc4_modifyreg_nolock(priv, offset, setbits, clrbits);
598+
spin_unlock_irqrestore(&priv->lock, flags);
586599
}
587600

588601
/****************************************************************************
@@ -591,15 +604,11 @@ static inline void xmc4_modifyreg(struct xmc4_dev_s *priv, unsigned
591604

592605
static void xmc4_setuartint(struct xmc4_dev_s *priv)
593606
{
594-
irqstate_t flags;
595-
596607
/* Re-enable/re-disable event interrupts corresponding to the state of
597608
* bits in priv->ccr.
598609
*/
599610

600-
flags = spin_lock_irqsave(NULL);
601611
xmc4_modifyreg(priv, XMC4_USIC_CCR_OFFSET, CCR_ALL_EVENTS, priv->ccr);
602-
spin_unlock_irqrestore(NULL, flags);
603612
}
604613

605614
/****************************************************************************
@@ -614,10 +623,11 @@ static void xmc4_restoreuartint(struct xmc4_dev_s *priv, uint32_t ccr)
614623
* in the ccr argument.
615624
*/
616625

617-
flags = spin_lock_irqsave(NULL);
626+
flags = spin_lock_irqsave(&priv->lock);
618627
priv->ccr = ccr;
619-
xmc4_setuartint(priv);
620-
spin_unlock_irqrestore(NULL, flags);
628+
xmc4_modifyreg_nolock(priv, XMC4_USIC_CCR_OFFSET, CCR_ALL_EVENTS,
629+
priv->ccr);
630+
spin_unlock_irqrestore(&priv->lock, flags);
621631
}
622632

623633
/****************************************************************************
@@ -626,16 +636,12 @@ static void xmc4_restoreuartint(struct xmc4_dev_s *priv, uint32_t ccr)
626636

627637
static void xmc4_disableuartint(struct xmc4_dev_s *priv, uint32_t *ccr)
628638
{
629-
irqstate_t flags;
630-
631-
flags = spin_lock_irqsave(NULL);
632639
if (ccr)
633640
{
634641
*ccr = priv->ccr;
635642
}
636643

637644
xmc4_restoreuartint(priv, 0);
638-
spin_unlock_irqrestore(NULL, flags);
639645
}
640646

641647
/****************************************************************************

arch/arm64/src/a64/a64_serial.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ struct a64_uart_port_s
269269
bool is_console; /* 1 if this UART is console */
270270
};
271271

272+
/***************************************************************************
273+
* Private Data
274+
***************************************************************************/
275+
276+
static spinlock_t g_a64_serial_lock = SP_UNLOCKED;
277+
272278
/***************************************************************************
273279
* Private Function Prototypes
274280
***************************************************************************/
@@ -967,7 +973,7 @@ static int a64_uart_init(uint32_t gating, uint32_t rst, pio_pinset_t tx,
967973
irqstate_t flags;
968974
int ret = OK;
969975

970-
flags = spin_lock_irqsave(NULL);
976+
flags = spin_lock_irqsave(&g_a64_serial_lock);
971977

972978
/* Enable clocking to UART */
973979

@@ -993,7 +999,7 @@ static int a64_uart_init(uint32_t gating, uint32_t rst, pio_pinset_t tx,
993999
}
9941000
}
9951001

996-
spin_unlock_irqrestore(NULL, flags);
1002+
spin_unlock_irqrestore(&g_a64_serial_lock, flags);
9971003
return ret;
9981004
};
9991005

0 commit comments

Comments
 (0)