Skip to content

Commit f25e3d2

Browse files
hujun260xiaoxiang781216
authored andcommitted
use small lock in following files
arch/risc-v/src/litex/litex_emac.c arch/risc-v/src/mpfs/mpfs_coremmc.c arch/risc-v/src/mpfs/mpfs_usb.c arch/xtensa/src/esp32/esp32_idle.c arch/xtensa/src/esp32/esp32_rtc_lowerhalf.c arch/xtensa/src/esp32s2/esp32s2_idle.c arch/xtensa/src/esp32s2/esp32s2_lowputc.c arch/xtensa/src/esp32s2/esp32s2_lowputc.h arch/xtensa/src/esp32s2/esp32s2_rtc_lowerhalf.c arch/xtensa/src/esp32s3/esp32s3_idle.c Signed-off-by: hujun5 <[email protected]>
1 parent 2d062a9 commit f25e3d2

File tree

10 files changed

+67
-26
lines changed

10 files changed

+67
-26
lines changed

arch/risc-v/src/litex/litex_emac.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ struct litex_emac_s
169169
uint8_t phyaddr; /* PHY address (pre-defined by pins on reset) */
170170

171171
uint8_t txslot;
172+
spinlock_t lock;
172173
};
173174

174175
/****************************************************************************
@@ -511,7 +512,7 @@ static int litex_transmit(struct litex_emac_s *priv)
511512

512513
/* Make the following operations atomic */
513514

514-
flags = spin_lock_irqsave(NULL);
515+
flags = spin_lock_irqsave(&priv->lock);
515516

516517
/* Now start transmission */
517518

@@ -528,7 +529,7 @@ static int litex_transmit(struct litex_emac_s *priv)
528529
wd_start(&priv->txtimeout, LITEX_TXTIMEOUT,
529530
litex_txtimeout_expiry, (wdparm_t)priv);
530531

531-
spin_unlock_irqrestore(NULL, flags);
532+
spin_unlock_irqrestore(&priv->lock, flags);
532533

533534
return OK;
534535
}
@@ -1524,6 +1525,8 @@ static void litex_ethinitialize(void)
15241525
return;
15251526
}
15261527

1528+
spin_lock_init(&priv->lock);
1529+
15271530
nerr("ERROR: netdev_register() failed: %d\n", ret);
15281531
}
15291532

arch/risc-v/src/mpfs/mpfs_coremmc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ static void mpfs_callback(void *arg);
214214
* Private Data
215215
****************************************************************************/
216216

217+
static spinlock_t g_mpfs_modifyreg_lock = SP_UNLOCKED;
218+
217219
struct mpfs_dev_s g_coremmc_dev =
218220
{
219221
.dev =
@@ -282,12 +284,12 @@ static void mpfs_modifyreg8(uintptr_t addr, uint8_t clearbits,
282284
irqstate_t flags;
283285
uint8_t regval;
284286

285-
flags = spin_lock_irqsave(NULL);
287+
flags = spin_lock_irqsave(&g_mpfs_modifyreg_lock);
286288
regval = getreg8(addr);
287289
regval &= ~clearbits;
288290
regval |= setbits;
289291
putreg8(regval, addr);
290-
spin_unlock_irqrestore(NULL, flags);
292+
spin_unlock_irqrestore(&g_mpfs_modifyreg_lock, flags);
291293
}
292294

293295
/****************************************************************************

arch/risc-v/src/mpfs/mpfs_usb.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ static void mpfs_epset_reset(struct mpfs_usbdev_s *priv, uint16_t epset);
224224
* Private Data
225225
****************************************************************************/
226226

227+
static spinlock_t g_mpfs_modifyreg_lock = SP_UNLOCKED;
228+
227229
static struct mpfs_usbdev_s g_usbd;
228230
static uint8_t g_clkrefs;
229231

@@ -297,12 +299,12 @@ static void mpfs_modifyreg16(uintptr_t addr, uint16_t clearbits,
297299
DEBUGASSERT((addr >= MPFS_USB_BASE) && addr < (MPFS_USB_BASE +
298300
MPFS_USB_REG_MAX));
299301

300-
flags = spin_lock_irqsave(NULL);
302+
flags = spin_lock_irqsave(&g_mpfs_modifyreg_lock);
301303
regval = getreg16(addr);
302304
regval &= ~clearbits;
303305
regval |= setbits;
304306
putreg16(regval, addr);
305-
spin_unlock_irqrestore(NULL, flags);
307+
spin_unlock_irqrestore(&g_mpfs_modifyreg_lock, flags);
306308
}
307309

308310
/****************************************************************************
@@ -331,12 +333,12 @@ static void mpfs_modifyreg8(uintptr_t addr, uint8_t clearbits,
331333
DEBUGASSERT((addr >= MPFS_USB_BASE) && addr < (MPFS_USB_BASE +
332334
MPFS_USB_REG_MAX));
333335

334-
flags = spin_lock_irqsave(NULL);
336+
flags = spin_lock_irqsave(&g_mpfs_modifyreg_lock);
335337
regval = getreg8(addr);
336338
regval &= ~clearbits;
337339
regval |= setbits;
338340
putreg8(regval, addr);
339-
spin_unlock_irqrestore(NULL, flags);
341+
spin_unlock_irqrestore(&g_mpfs_modifyreg_lock, flags);
340342
}
341343

342344
/****************************************************************************

arch/xtensa/src/esp32/esp32_idle.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@
8989
#define EXPECTED_IDLE_TIME_US (800)
9090
#define EARLY_WAKEUP_US (200)
9191

92+
#endif
93+
/****************************************************************************
94+
* Private Data
95+
****************************************************************************/
96+
97+
#ifdef CONFIG_PM
98+
static spinlock_t g_esp32_idle_lock = SP_UNLOCKED;
9299
#endif
93100

94101
/****************************************************************************
@@ -109,7 +116,7 @@ static void esp32_idlepm(void)
109116
irqstate_t flags;
110117

111118
#ifdef CONFIG_ESP32_AUTO_SLEEP
112-
flags = spin_lock_irqsave(NULL);
119+
flags = spin_lock_irqsave(&g_esp32_idle_lock);
113120
if (esp32_pm_lockstatus() == 0)
114121
{
115122
uint64_t os_start_us;
@@ -155,7 +162,7 @@ static void esp32_idlepm(void)
155162
}
156163
}
157164

158-
spin_unlock_irqrestore(NULL, flags);
165+
spin_unlock_irqrestore(&g_esp32_idle_lock, flags);
159166
#else /* CONFIG_ESP32_AUTO_SLEEP */
160167
static enum pm_state_e oldstate = PM_NORMAL;
161168
enum pm_state_e newstate;
@@ -169,7 +176,7 @@ static void esp32_idlepm(void)
169176

170177
if (newstate != oldstate)
171178
{
172-
flags = spin_lock_irqsave(NULL);
179+
flags = spin_lock_irqsave(&g_esp32_idle_lock);
173180

174181
/* Perform board-specific, state-dependent logic here */
175182

@@ -191,7 +198,7 @@ static void esp32_idlepm(void)
191198
oldstate = newstate;
192199
}
193200

194-
spin_unlock_irqrestore(NULL, flags);
201+
spin_unlock_irqrestore(&g_esp32_idle_lock, flags);
195202

196203
/* MCU-specific power management logic */
197204

arch/xtensa/src/esp32/esp32_rtc_lowerhalf.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct esp32_lowerhalf_s
6161
*/
6262

6363
const struct rtc_ops_s *ops;
64+
spinlock_t lock;
6465
#ifdef CONFIG_RTC_ALARM
6566
/* Alarm callback information */
6667

@@ -116,6 +117,7 @@ static const struct rtc_ops_s g_rtc_ops =
116117
static struct esp32_lowerhalf_s g_rtc_lowerhalf =
117118
{
118119
.ops = &g_rtc_ops,
120+
.lock = SP_UNLOCKED
119121
};
120122

121123
/****************************************************************************
@@ -376,6 +378,7 @@ static int rtc_lh_setalarm(struct rtc_lowerhalf_s *lower,
376378
static int rtc_lh_setrelative(struct rtc_lowerhalf_s *lower,
377379
const struct lower_setrelative_s *alarminfo)
378380
{
381+
struct esp32_lowerhalf_s *priv = (struct esp32_lowerhalf_s *)lower;
379382
struct lower_setalarm_s setalarm;
380383
time_t seconds;
381384
int ret = -EINVAL;
@@ -387,7 +390,7 @@ static int rtc_lh_setrelative(struct rtc_lowerhalf_s *lower,
387390

388391
if (alarminfo->reltime > 0)
389392
{
390-
flags = spin_lock_irqsave(NULL);
393+
flags = spin_lock_irqsave(&priv->lock);
391394

392395
seconds = alarminfo->reltime;
393396
gmtime_r(&seconds, (struct tm *)&setalarm.time);
@@ -399,7 +402,7 @@ static int rtc_lh_setrelative(struct rtc_lowerhalf_s *lower,
399402
setalarm.priv = alarminfo->priv;
400403
ret = rtc_lh_setalarm(lower, &setalarm);
401404

402-
spin_unlock_irqrestore(NULL, flags);
405+
spin_unlock_irqrestore(&priv->lock, flags);
403406
}
404407

405408
return ret;
@@ -466,6 +469,7 @@ static int rtc_lh_cancelalarm(struct rtc_lowerhalf_s *lower, int alarmid)
466469
static int rtc_lh_rdalarm(struct rtc_lowerhalf_s *lower,
467470
struct lower_rdalarm_s *alarminfo)
468471
{
472+
struct esp32_lowerhalf_s *priv = (struct esp32_lowerhalf_s *)lower;
469473
struct timespec ts;
470474
int ret;
471475
irqstate_t flags;
@@ -474,13 +478,13 @@ static int rtc_lh_rdalarm(struct rtc_lowerhalf_s *lower,
474478
DEBUGASSERT((RTC_ALARM0 <= alarminfo->id) &&
475479
(alarminfo->id < RTC_ALARM_LAST));
476480

477-
flags = spin_lock_irqsave(NULL);
481+
flags = spin_lock_irqsave(&priv->lock);
478482

479483
ret = up_rtc_rdalarm(&ts, alarminfo->id);
480484
localtime_r((const time_t *)&ts.tv_sec,
481485
(struct tm *)alarminfo->time);
482486

483-
spin_unlock_irqrestore(NULL, flags);
487+
spin_unlock_irqrestore(&priv->lock, flags);
484488

485489
return ret;
486490
}

arch/xtensa/src/esp32s2/esp32s2_idle.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@
5858

5959
#endif
6060

61+
/****************************************************************************
62+
* Private Data
63+
****************************************************************************/
64+
65+
#ifdef CONFIG_PM
66+
static spinlock_t g_esp32s2_idle_lock = SP_UNLOCKED;
67+
#endif
68+
6169
/****************************************************************************
6270
* Private Functions
6371
****************************************************************************/
@@ -86,7 +94,7 @@ static void up_idlepm(void)
8694

8795
if (newstate != oldstate)
8896
{
89-
flags = spin_lock_irqsave(NULL);
97+
flags = spin_lock_irqsave(&g_esp32s2_idle_lock);
9098

9199
/* Perform board-specific, state-dependent logic here */
92100

@@ -108,7 +116,7 @@ static void up_idlepm(void)
108116
oldstate = newstate;
109117
}
110118

111-
spin_unlock_irqrestore(NULL, flags);
119+
spin_unlock_irqrestore(&g_esp32s2_idle_lock, flags);
112120

113121
/* MCU-specific power management logic */
114122

arch/xtensa/src/esp32s2/esp32s2_lowputc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ struct esp32s2_uart_s g_uart0_config =
9999
.rs485_dir_polarity = true,
100100
#endif
101101
#endif
102+
.lock = SP_UNLOCKED;
102103
};
103104

104105
#endif /* CONFIG_ESP32S2_UART0 */
@@ -146,6 +147,7 @@ struct esp32s2_uart_s g_uart1_config =
146147
.rs485_dir_polarity = true,
147148
#endif
148149
#endif
150+
.lock = SP_UNLOCKED;
149151
};
150152

151153
#endif /* CONFIG_ESP32S2_UART1 */
@@ -654,7 +656,7 @@ void esp32s2_lowputc_disable_all_uart_int(const struct esp32s2_uart_s *priv,
654656
{
655657
irqstate_t flags;
656658

657-
flags = spin_lock_irqsave(NULL);
659+
flags = spin_lock_irqsave(&priv->lock);
658660

659661
if (current_status != NULL)
660662
{
@@ -671,7 +673,7 @@ void esp32s2_lowputc_disable_all_uart_int(const struct esp32s2_uart_s *priv,
671673

672674
putreg32(UINT32_MAX, UART_INT_CLR_REG(priv->id));
673675

674-
spin_unlock_irqrestore(NULL, flags);
676+
spin_unlock_irqrestore(&priv->lock, flags);
675677
}
676678

677679
/****************************************************************************

arch/xtensa/src/esp32s2/esp32s2_lowputc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ struct esp32s2_uart_s
106106
uint8_t rs485_dir_gpio; /* UART RS-485 DIR GPIO pin cfg */
107107
bool rs485_dir_polarity; /* UART RS-485 DIR TXEN polarity */
108108
#endif
109+
spinlock_t lock; /* Spinlock */
109110
};
110111

111112
extern struct esp32s2_uart_s g_uart0_config;

arch/xtensa/src/esp32s2/esp32s2_rtc_lowerhalf.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct esp32s2_lowerhalf_s
6161
*/
6262

6363
const struct rtc_ops_s *ops;
64+
spinlock_t lock;
6465
#ifdef CONFIG_RTC_ALARM
6566
/* Alarm callback information */
6667

@@ -115,6 +116,7 @@ static const struct rtc_ops_s g_rtc_ops =
115116
static struct esp32s2_lowerhalf_s g_rtc_lowerhalf =
116117
{
117118
.ops = &g_rtc_ops,
119+
.lock = SP_UNLOCKED,
118120
};
119121

120122
/****************************************************************************
@@ -375,6 +377,7 @@ static int rtc_lh_setalarm(struct rtc_lowerhalf_s *lower,
375377
static int rtc_lh_setrelative(struct rtc_lowerhalf_s *lower,
376378
const struct lower_setrelative_s *alarminfo)
377379
{
380+
struct esp32s2_lowerhalf_s *priv = (struct esp32s2_lowerhalf_s *)lower;
378381
struct lower_setalarm_s setalarm;
379382
time_t seconds;
380383
int ret = -EINVAL;
@@ -386,7 +389,7 @@ static int rtc_lh_setrelative(struct rtc_lowerhalf_s *lower,
386389

387390
if (alarminfo->reltime > 0)
388391
{
389-
flags = spin_lock_irqsave(NULL);
392+
flags = spin_lock_irqsave(&priv->lock);
390393

391394
seconds = alarminfo->reltime;
392395
gmtime_r(&seconds, (struct tm *)&setalarm.time);
@@ -398,7 +401,7 @@ static int rtc_lh_setrelative(struct rtc_lowerhalf_s *lower,
398401
setalarm.priv = alarminfo->priv;
399402
ret = rtc_lh_setalarm(lower, &setalarm);
400403

401-
spin_unlock_irqrestore(NULL, flags);
404+
spin_unlock_irqrestore(&priv->lock, flags);
402405
}
403406

404407
return ret;
@@ -465,6 +468,7 @@ static int rtc_lh_cancelalarm(struct rtc_lowerhalf_s *lower, int alarmid)
465468
static int rtc_lh_rdalarm(struct rtc_lowerhalf_s *lower,
466469
struct lower_rdalarm_s *alarminfo)
467470
{
471+
struct esp32s2_lowerhalf_s *priv = (struct esp32s2_lowerhalf_s *)lower;
468472
struct timespec ts;
469473
int ret;
470474
irqstate_t flags;
@@ -473,13 +477,13 @@ static int rtc_lh_rdalarm(struct rtc_lowerhalf_s *lower,
473477
DEBUGASSERT((RTC_ALARM0 <= alarminfo->id) &&
474478
(alarminfo->id < RTC_ALARM_LAST));
475479

476-
flags = spin_lock_irqsave(NULL);
480+
flags = spin_lock_irqsave(&priv->lock);
477481

478482
ret = up_rtc_rdalarm(&ts, alarminfo->id);
479483
localtime_r((const time_t *)&ts.tv_sec,
480484
(struct tm *)alarminfo->time);
481485

482-
spin_unlock_irqrestore(NULL, flags);
486+
spin_unlock_irqrestore(&priv->lock, flags);
483487

484488
return ret;
485489
}

arch/xtensa/src/esp32s3/esp32s3_idle.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@
6363

6464
#endif
6565

66+
/****************************************************************************
67+
* Private Data
68+
****************************************************************************/
69+
70+
#ifdef CONFIG_PM
71+
static spinlock_t g_esp32s3_idle_lock = SP_UNLOCKED;
72+
#endif
73+
6674
/****************************************************************************
6775
* Private Functions
6876
****************************************************************************/
@@ -91,7 +99,7 @@ static void up_idlepm(void)
9199

92100
if (newstate != oldstate)
93101
{
94-
flags = spin_lock_irqsave(NULL);
102+
flags = spin_lock_irqsave(&g_esp32s3_idle_lock);
95103

96104
/* Perform board-specific, state-dependent logic here */
97105

@@ -113,7 +121,7 @@ static void up_idlepm(void)
113121
oldstate = newstate;
114122
}
115123

116-
spin_unlock_irqrestore(NULL, flags);
124+
spin_unlock_irqrestore(&g_esp32s3_idle_lock, flags);
117125

118126
/* MCU-specific power management logic */
119127

0 commit comments

Comments
 (0)