Skip to content

Commit 97eef35

Browse files
hujun260xiaoxiang781216
authored andcommitted
use small lock in following file
arch/or1k/src/mor1kx/mor1kx_serial.c arch/risc-v/src/bl602/bl602_serial.c arch/risc-v/src/common/espressif/esp_lowputc.c arch/risc-v/src/common/espressif/esp_lowputc.h arch/risc-v/src/common/espressif/esp_tickless.c arch/risc-v/src/esp32c3-legacy/esp32c3_idle.c arch/risc-v/src/esp32c3-legacy/esp32c3_lowputc.c arch/risc-v/src/esp32c3-legacy/esp32c3_lowputc.h arch/risc-v/src/esp32c3-legacy/esp32c3_rtc_lowerhalf.c arch/risc-v/src/fe310/fe310_gpio.c Signed-off-by: hujun5 <[email protected]>
1 parent d59b8f2 commit 97eef35

File tree

10 files changed

+71
-33
lines changed

10 files changed

+71
-33
lines changed

arch/or1k/src/mor1kx/mor1kx_serial.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@
5252
#define OR1K_BAUD (115200)
5353
#define OR1K_DIVISOR (OR1K_SYS_CLK / (16*OR1K_BAUD))
5454

55+
/****************************************************************************
56+
* Private Data
57+
****************************************************************************/
58+
59+
#ifdef HAVE_SERIAL_CONSOLE
60+
static spinlock_t g_serial_lock = SP_UNLOCKED;
61+
#endif
62+
5563
/****************************************************************************
5664
* Public Functions
5765
****************************************************************************/
@@ -117,10 +125,10 @@ void up_putc(int ch)
117125
* interrupts from firing in the serial driver code.
118126
*/
119127

120-
flags = spin_lock_irqsave(NULL);
128+
flags = spin_lock_irqsave(&g_serial_lock);
121129

122130
/* or1k_lowputc(ch); */
123131

124-
spin_unlock_irqrestore(NULL, flags);
132+
spin_unlock_irqrestore(&g_serial_lock, flags);
125133
#endif
126134
}

arch/risc-v/src/bl602/bl602_serial.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ static bool bl602_txempty(struct uart_dev_s *dev);
152152
* Private Data
153153
****************************************************************************/
154154

155+
static spinlock_t g_bl602_serial_lock = SP_UNLOCKED;
156+
155157
static const struct uart_ops_s g_uart_ops =
156158
{
157159
.setup = bl602_setup,
@@ -891,10 +893,10 @@ void riscv_serialinit(void)
891893
void up_putc(int ch)
892894
{
893895
#ifdef HAVE_SERIAL_CONSOLE
894-
irqstate_t flags = spin_lock_irqsave(NULL);
896+
irqstate_t flags = spin_lock_irqsave(&g_bl602_serial_lock);
895897

896898
riscv_lowputc(ch);
897-
spin_unlock_irqrestore(NULL, flags);
899+
spin_unlock_irqrestore(&g_bl602_serial_lock, flags);
898900
#endif
899901
}
900902

arch/risc-v/src/common/espressif/esp_lowputc.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ struct esp_uart_s g_uart0_config =
102102
.oflow = false, /* output flow control (CTS) disabled */
103103
#endif
104104
#endif
105-
.hal = &g_uart0_hal
105+
.hal = &g_uart0_hal,
106+
.lock = SP_UNLOCKED
106107
};
107108

108109
#endif /* CONFIG_ESPRESSIF_UART0 */
@@ -147,7 +148,8 @@ struct esp_uart_s g_uart1_config =
147148
.oflow = false, /* output flow control (CTS) disabled */
148149
#endif
149150
#endif
150-
.hal = &g_uart1_hal
151+
.hal = &g_uart1_hal,
152+
.lock = SP_UNLOCKED
151153
};
152154

153155
#endif /* CONFIG_ESPRESSIF_UART1 */
@@ -210,7 +212,7 @@ void esp_lowputc_disable_all_uart_int(const struct esp_uart_s *priv,
210212
{
211213
irqstate_t flags;
212214

213-
flags = spin_lock_irqsave(NULL);
215+
flags = spin_lock_irqsave(&priv->lock);
214216

215217
if (current_status != NULL)
216218
{
@@ -227,7 +229,7 @@ void esp_lowputc_disable_all_uart_int(const struct esp_uart_s *priv,
227229

228230
uart_hal_clr_intsts_mask(priv->hal, UINT32_MAX);
229231

230-
spin_unlock_irqrestore(NULL, flags);
232+
spin_unlock_irqrestore(&priv->lock, flags);
231233
}
232234

233235
/****************************************************************************

arch/risc-v/src/common/espressif/esp_lowputc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#include <nuttx/arch.h>
4141
#include <nuttx/irq.h>
42+
#include <nuttx/spinlock.h>
4243

4344
#include "chip.h"
4445
#include "esp_irq.h"
@@ -76,6 +77,7 @@ struct esp_uart_s
7677
bool oflow; /* Output flow control (CTS) enabled */
7778
#endif
7879
uart_hal_context_t *hal; /* HAL context */
80+
spinlock_t lock; /* Spinlock */
7981
};
8082

8183
extern struct esp_uart_s g_uart0_config;

arch/risc-v/src/common/espressif/esp_tickless.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
* Private Data
6060
****************************************************************************/
6161

62+
static spinlock_t g_esp_tickless_lock = SP_UNLOCKED;
63+
6264
/* Systimer HAL layer object */
6365

6466
static systimer_hal_context_t systimer_hal;
@@ -126,10 +128,10 @@ uint32_t up_get_idletime(void)
126128
uint64_t counter;
127129
irqstate_t flags;
128130

129-
flags = spin_lock_irqsave(NULL);
131+
flags = spin_lock_irqsave(&g_esp_tickless_lock);
130132
if (!g_timer_started)
131133
{
132-
spin_unlock_irqrestore(NULL, flags);
134+
spin_unlock_irqrestore(&g_esp_tickless_lock, flags);
133135

134136
return 0;
135137
}
@@ -147,7 +149,7 @@ uint32_t up_get_idletime(void)
147149
us = 0;
148150
}
149151

150-
spin_unlock_irqrestore(NULL, flags);
152+
spin_unlock_irqrestore(&g_esp_tickless_lock, flags);
151153

152154
return us;
153155
}
@@ -172,12 +174,12 @@ void up_step_idletime(uint32_t idletime_us)
172174

173175
DEBUGASSERT(g_timer_started);
174176

175-
flags = spin_lock_irqsave(NULL);
177+
flags = spin_lock_irqsave(&g_esp_tickless_lock);
176178

177179
systimer_hal_counter_value_advance(&systimer_hal, SYSTIMER_COUNTER_OS_TICK,
178180
idletime_us);
179181

180-
spin_unlock_irqrestore(NULL, flags);
182+
spin_unlock_irqrestore(&g_esp_tickless_lock, flags);
181183
}
182184

183185
/****************************************************************************
@@ -216,13 +218,13 @@ void up_step_idletime(uint32_t idletime_us)
216218
int IRAM_ATTR up_timer_gettime(struct timespec *ts)
217219
{
218220
uint64_t time_us;
219-
irqstate_t flags = spin_lock_irqsave(NULL);
221+
irqstate_t flags = spin_lock_irqsave(&g_esp_tickless_lock);
220222

221223
time_us = systimer_hal_get_time(&systimer_hal, SYSTIMER_COUNTER_OS_TICK);
222224
ts->tv_sec = time_us / USEC_PER_SEC;
223225
ts->tv_nsec = (time_us % USEC_PER_SEC) * NSEC_PER_USEC;
224226

225-
spin_unlock_irqrestore(NULL, flags);
227+
spin_unlock_irqrestore(&g_esp_tickless_lock, flags);
226228

227229
return OK;
228230
}
@@ -267,7 +269,7 @@ int IRAM_ATTR up_timer_cancel(struct timespec *ts)
267269
{
268270
irqstate_t flags;
269271

270-
flags = spin_lock_irqsave(NULL);
272+
flags = spin_lock_irqsave(&g_esp_tickless_lock);
271273

272274
if (ts != NULL)
273275
{
@@ -314,7 +316,7 @@ int IRAM_ATTR up_timer_cancel(struct timespec *ts)
314316
systimer_ll_clear_alarm_int(systimer_hal.dev,
315317
SYSTIMER_ALARM_OS_TICK_CORE0);
316318

317-
spin_unlock_irqrestore(NULL, flags);
319+
spin_unlock_irqrestore(&g_esp_tickless_lock, flags);
318320

319321
return OK;
320322
}
@@ -350,7 +352,7 @@ int IRAM_ATTR up_timer_start(const struct timespec *ts)
350352
uint64_t alarm_ticks;
351353
irqstate_t flags;
352354

353-
flags = spin_lock_irqsave(NULL);
355+
flags = spin_lock_irqsave(&g_esp_tickless_lock);
354356

355357
if (g_timer_started)
356358
{
@@ -375,7 +377,7 @@ int IRAM_ATTR up_timer_start(const struct timespec *ts)
375377

376378
g_timer_started = true;
377379

378-
spin_unlock_irqrestore(NULL, flags);
380+
spin_unlock_irqrestore(&g_esp_tickless_lock, flags);
379381

380382
return OK;
381383
}

arch/risc-v/src/esp32c3-legacy/esp32c3_idle.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@
7676

7777
#endif
7878

79+
/****************************************************************************
80+
* Private Data
81+
****************************************************************************/
82+
83+
#ifdef CONFIG_PM
84+
static spinlock_t g_esp32c3_idle_lock = SP_UNLOCKED;
85+
#endif
86+
7987
/****************************************************************************
8088
* Private Functions
8189
****************************************************************************/
@@ -94,7 +102,7 @@ static void up_idlepm(void)
94102
irqstate_t flags;
95103

96104
#ifdef CONFIG_ESP32C3_AUTO_SLEEP
97-
flags = spin_lock_irqsave(NULL);
105+
flags = spin_lock_irqsave(&g_esp32c3_idle_lock);
98106
if (esp32c3_pm_lockstatus() == 0 &&
99107
(esp32c3_should_skip_light_sleep() == false))
100108
{
@@ -138,7 +146,7 @@ static void up_idlepm(void)
138146
}
139147
}
140148

141-
spin_unlock_irqrestore(NULL, flags);
149+
spin_unlock_irqrestore(&g_esp32c3_idle_lock, flags);
142150
#else /* CONFIG_ESP32C3_AUTO_SLEEP */
143151
static enum pm_state_e oldstate = PM_NORMAL;
144152
enum pm_state_e newstate;
@@ -152,7 +160,7 @@ static void up_idlepm(void)
152160

153161
if (newstate != oldstate)
154162
{
155-
flags = spin_lock_irqsave(NULL);
163+
flags = spin_lock_irqsave(&g_esp32c3_idle_lock);
156164

157165
/* Perform board-specific, state-dependent logic here */
158166

@@ -174,7 +182,7 @@ static void up_idlepm(void)
174182
oldstate = newstate;
175183
}
176184

177-
spin_unlock_irqrestore(NULL, flags);
185+
spin_unlock_irqrestore(&g_esp32c3_idle_lock, flags);
178186

179187
/* MCU-specific power management logic */
180188

arch/risc-v/src/esp32c3-legacy/esp32c3_lowputc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct esp32c3_uart_s g_uart0_config =
7979
.txsig = U0TXD_OUT_IDX,
8080
.rxpin = CONFIG_ESP32C3_UART0_RXPIN,
8181
.rxsig = U0RXD_IN_IDX,
82+
.lock = SP_UNLOCKED,
8283
#ifdef CONFIG_SERIAL_IFLOWCONTROL
8384
.rtspin = CONFIG_ESP32C3_UART0_RTSPIN,
8485
.rtssig = U0RTS_OUT_IDX,
@@ -118,6 +119,7 @@ struct esp32c3_uart_s g_uart1_config =
118119
.txsig = U1TXD_OUT_IDX,
119120
.rxpin = CONFIG_ESP32C3_UART1_RXPIN,
120121
.rxsig = U1RXD_IN_IDX,
122+
.lock = SP_UNLOCKED,
121123
#ifdef CONFIG_SERIAL_IFLOWCONTROL
122124
.rtspin = CONFIG_ESP32C3_UART1_RTSPIN,
123125
.rtssig = U1RTS_OUT_IDX,
@@ -708,12 +710,12 @@ void esp32c3_lowputc_enable_sysclk(const struct esp32c3_uart_s *priv)
708710
*
709711
****************************************************************************/
710712

711-
void esp32c3_lowputc_disable_all_uart_int(const struct esp32c3_uart_s *priv,
713+
void esp32c3_lowputc_disable_all_uart_int(struct esp32c3_uart_s *priv,
712714
uint32_t *current_status)
713715
{
714716
irqstate_t flags;
715717

716-
flags = spin_lock_irqsave(NULL);
718+
flags = spin_lock_irqsave(&priv->lock);
717719

718720
if (current_status != NULL)
719721
{
@@ -730,7 +732,7 @@ void esp32c3_lowputc_disable_all_uart_int(const struct esp32c3_uart_s *priv,
730732

731733
putreg32(0xffffffff, UART_INT_CLR_REG(priv->id));
732734

733-
spin_unlock_irqrestore(NULL, flags);
735+
spin_unlock_irqrestore(&priv->lock, flags);
734736
}
735737

736738
/****************************************************************************

arch/risc-v/src/esp32c3-legacy/esp32c3_lowputc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <nuttx/config.h>
3131
#include <nuttx/arch.h>
3232
#include <nuttx/irq.h>
33+
#include <nuttx/spinlock.h>
3334

3435
#include <sys/types.h>
3536
#include <stdint.h>
@@ -102,6 +103,7 @@ struct esp32c3_uart_s
102103
uint8_t txsig; /* TX signal */
103104
uint8_t rxpin; /* RX pin */
104105
uint8_t rxsig; /* RX signal */
106+
spinlock_t lock; /* Spinlock */
105107
#ifdef CONFIG_SERIAL_IFLOWCONTROL
106108
uint8_t rtspin; /* RTS pin number */
107109
uint8_t rtssig; /* RTS signal */
@@ -433,7 +435,7 @@ void esp32c3_lowputc_enable_sysclk(const struct esp32c3_uart_s *priv);
433435
*
434436
****************************************************************************/
435437

436-
void esp32c3_lowputc_disable_all_uart_int(const struct esp32c3_uart_s *priv,
438+
void esp32c3_lowputc_disable_all_uart_int(struct esp32c3_uart_s *priv,
437439
uint32_t *current_status);
438440

439441
/****************************************************************************

arch/risc-v/src/esp32c3-legacy/esp32c3_rtc_lowerhalf.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ struct esp32c3_lowerhalf_s
6363
*/
6464

6565
const struct rtc_ops_s *ops;
66+
spinlock_t lock;
6667
#ifdef CONFIG_RTC_ALARM
6768
/* Alarm callback information */
6869

@@ -118,6 +119,7 @@ static const struct rtc_ops_s g_rtc_ops =
118119
static struct esp32c3_lowerhalf_s g_rtc_lowerhalf =
119120
{
120121
.ops = &g_rtc_ops,
122+
.lock = SP_UNLOCKED,
121123
};
122124

123125
/****************************************************************************
@@ -378,6 +380,7 @@ static int rtc_lh_setalarm(struct rtc_lowerhalf_s *lower,
378380
static int rtc_lh_setrelative(struct rtc_lowerhalf_s *lower,
379381
const struct lower_setrelative_s *alarminfo)
380382
{
383+
struct esp32c3_lowerhalf_s *priv = (struct esp32c3_lowerhalf_s *)lower;
381384
struct lower_setalarm_s setalarm;
382385
time_t seconds;
383386
int ret = -EINVAL;
@@ -389,7 +392,7 @@ static int rtc_lh_setrelative(struct rtc_lowerhalf_s *lower,
389392

390393
if (alarminfo->reltime > 0)
391394
{
392-
flags = spin_lock_irqsave(NULL);
395+
flags = spin_lock_irqsave(&priv->lock);
393396

394397
seconds = alarminfo->reltime;
395398
gmtime_r(&seconds, (struct tm *)&setalarm.time);
@@ -401,7 +404,7 @@ static int rtc_lh_setrelative(struct rtc_lowerhalf_s *lower,
401404
setalarm.priv = alarminfo->priv;
402405
ret = rtc_lh_setalarm(lower, &setalarm);
403406

404-
spin_unlock_irqrestore(NULL, flags);
407+
spin_unlock_irqrestore(&priv->lock, flags);
405408
}
406409

407410
return ret;
@@ -468,6 +471,7 @@ static int rtc_lh_cancelalarm(struct rtc_lowerhalf_s *lower, int alarmid)
468471
static int rtc_lh_rdalarm(struct rtc_lowerhalf_s *lower,
469472
struct lower_rdalarm_s *alarminfo)
470473
{
474+
struct esp32c3_lowerhalf_s *priv = (struct esp32c3_lowerhalf_s *)lower;
471475
struct timespec ts;
472476
int ret;
473477
irqstate_t flags;
@@ -476,13 +480,13 @@ static int rtc_lh_rdalarm(struct rtc_lowerhalf_s *lower,
476480
DEBUGASSERT((RTC_ALARM0 <= alarminfo->id) &&
477481
(alarminfo->id < RTC_ALARM_LAST));
478482

479-
flags = spin_lock_irqsave(NULL);
483+
flags = spin_lock_irqsave(&priv->lock);
480484

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

485-
spin_unlock_irqrestore(NULL, flags);
489+
spin_unlock_irqrestore(&priv->lock, flags);
486490

487491
return ret;
488492
}

0 commit comments

Comments
 (0)