Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions arch/risc-v/src/litex/litex_emac.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ struct litex_emac_s
uint8_t phyaddr; /* PHY address (pre-defined by pins on reset) */

uint8_t txslot;
spinlock_t lock;
};

/****************************************************************************
Expand Down Expand Up @@ -511,7 +512,7 @@ static int litex_transmit(struct litex_emac_s *priv)

/* Make the following operations atomic */

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&priv->lock);

/* Now start transmission */

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

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&priv->lock, flags);

return OK;
}
Expand Down Expand Up @@ -1524,6 +1525,8 @@ static void litex_ethinitialize(void)
return;
}

spin_lock_init(&priv->lock);

nerr("ERROR: netdev_register() failed: %d\n", ret);
}

Expand Down
6 changes: 4 additions & 2 deletions arch/risc-v/src/mpfs/mpfs_coremmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ static void mpfs_callback(void *arg);
* Private Data
****************************************************************************/

static spinlock_t g_mpfs_modifyreg_lock = SP_UNLOCKED;

struct mpfs_dev_s g_coremmc_dev =
{
.dev =
Expand Down Expand Up @@ -282,12 +284,12 @@ static void mpfs_modifyreg8(uintptr_t addr, uint8_t clearbits,
irqstate_t flags;
uint8_t regval;

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_mpfs_modifyreg_lock);
regval = getreg8(addr);
regval &= ~clearbits;
regval |= setbits;
putreg8(regval, addr);
spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_mpfs_modifyreg_lock, flags);
}

/****************************************************************************
Expand Down
10 changes: 6 additions & 4 deletions arch/risc-v/src/mpfs/mpfs_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ static void mpfs_epset_reset(struct mpfs_usbdev_s *priv, uint16_t epset);
* Private Data
****************************************************************************/

static spinlock_t g_mpfs_modifyreg_lock = SP_UNLOCKED;

static struct mpfs_usbdev_s g_usbd;
static uint8_t g_clkrefs;

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

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_mpfs_modifyreg_lock);
regval = getreg16(addr);
regval &= ~clearbits;
regval |= setbits;
putreg16(regval, addr);
spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_mpfs_modifyreg_lock, flags);
}

/****************************************************************************
Expand Down Expand Up @@ -331,12 +333,12 @@ static void mpfs_modifyreg8(uintptr_t addr, uint8_t clearbits,
DEBUGASSERT((addr >= MPFS_USB_BASE) && addr < (MPFS_USB_BASE +
MPFS_USB_REG_MAX));

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_mpfs_modifyreg_lock);
regval = getreg8(addr);
regval &= ~clearbits;
regval |= setbits;
putreg8(regval, addr);
spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_mpfs_modifyreg_lock, flags);
}

/****************************************************************************
Expand Down
15 changes: 11 additions & 4 deletions arch/xtensa/src/esp32/esp32_idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@
#define EXPECTED_IDLE_TIME_US (800)
#define EARLY_WAKEUP_US (200)

#endif
/****************************************************************************
* Private Data
****************************************************************************/

#ifdef CONFIG_PM
static spinlock_t g_esp32_idle_lock = SP_UNLOCKED;
#endif

/****************************************************************************
Expand All @@ -109,7 +116,7 @@ static void esp32_idlepm(void)
irqstate_t flags;

#ifdef CONFIG_ESP32_AUTO_SLEEP
flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_esp32_idle_lock);
if (esp32_pm_lockstatus() == 0)
{
uint64_t os_start_us;
Expand Down Expand Up @@ -155,7 +162,7 @@ static void esp32_idlepm(void)
}
}

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_esp32_idle_lock, flags);
#else /* CONFIG_ESP32_AUTO_SLEEP */
static enum pm_state_e oldstate = PM_NORMAL;
enum pm_state_e newstate;
Expand All @@ -169,7 +176,7 @@ static void esp32_idlepm(void)

if (newstate != oldstate)
{
flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_esp32_idle_lock);

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

Expand All @@ -191,7 +198,7 @@ static void esp32_idlepm(void)
oldstate = newstate;
}

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_esp32_idle_lock, flags);

/* MCU-specific power management logic */

Expand Down
12 changes: 8 additions & 4 deletions arch/xtensa/src/esp32/esp32_rtc_lowerhalf.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct esp32_lowerhalf_s
*/

const struct rtc_ops_s *ops;
spinlock_t lock;
#ifdef CONFIG_RTC_ALARM
/* Alarm callback information */

Expand Down Expand Up @@ -116,6 +117,7 @@ static const struct rtc_ops_s g_rtc_ops =
static struct esp32_lowerhalf_s g_rtc_lowerhalf =
{
.ops = &g_rtc_ops,
.lock = SP_UNLOCKED
};

/****************************************************************************
Expand Down Expand Up @@ -376,6 +378,7 @@ static int rtc_lh_setalarm(struct rtc_lowerhalf_s *lower,
static int rtc_lh_setrelative(struct rtc_lowerhalf_s *lower,
const struct lower_setrelative_s *alarminfo)
{
struct esp32_lowerhalf_s *priv = (struct esp32_lowerhalf_s *)lower;
struct lower_setalarm_s setalarm;
time_t seconds;
int ret = -EINVAL;
Expand All @@ -387,7 +390,7 @@ static int rtc_lh_setrelative(struct rtc_lowerhalf_s *lower,

if (alarminfo->reltime > 0)
{
flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&priv->lock);

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

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&priv->lock, flags);
}

return ret;
Expand Down Expand Up @@ -466,6 +469,7 @@ static int rtc_lh_cancelalarm(struct rtc_lowerhalf_s *lower, int alarmid)
static int rtc_lh_rdalarm(struct rtc_lowerhalf_s *lower,
struct lower_rdalarm_s *alarminfo)
{
struct esp32_lowerhalf_s *priv = (struct esp32_lowerhalf_s *)lower;
struct timespec ts;
int ret;
irqstate_t flags;
Expand All @@ -474,13 +478,13 @@ static int rtc_lh_rdalarm(struct rtc_lowerhalf_s *lower,
DEBUGASSERT((RTC_ALARM0 <= alarminfo->id) &&
(alarminfo->id < RTC_ALARM_LAST));

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&priv->lock);

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

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&priv->lock, flags);

return ret;
}
Expand Down
12 changes: 10 additions & 2 deletions arch/xtensa/src/esp32s2/esp32s2_idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@

#endif

/****************************************************************************
* Private Data
****************************************************************************/

#ifdef CONFIG_PM
static spinlock_t g_esp32s2_idle_lock = SP_UNLOCKED;
#endif

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -86,7 +94,7 @@ static void up_idlepm(void)

if (newstate != oldstate)
{
flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_esp32s2_idle_lock);

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

Expand All @@ -108,7 +116,7 @@ static void up_idlepm(void)
oldstate = newstate;
}

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_esp32s2_idle_lock, flags);

/* MCU-specific power management logic */

Expand Down
6 changes: 4 additions & 2 deletions arch/xtensa/src/esp32s2/esp32s2_lowputc.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ struct esp32s2_uart_s g_uart0_config =
.rs485_dir_polarity = true,
#endif
#endif
.lock = SP_UNLOCKED;
};

#endif /* CONFIG_ESP32S2_UART0 */
Expand Down Expand Up @@ -146,6 +147,7 @@ struct esp32s2_uart_s g_uart1_config =
.rs485_dir_polarity = true,
#endif
#endif
.lock = SP_UNLOCKED;
};

#endif /* CONFIG_ESP32S2_UART1 */
Expand Down Expand Up @@ -654,7 +656,7 @@ void esp32s2_lowputc_disable_all_uart_int(const struct esp32s2_uart_s *priv,
{
irqstate_t flags;

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&priv->lock);

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

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

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
Expand Down
1 change: 1 addition & 0 deletions arch/xtensa/src/esp32s2/esp32s2_lowputc.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ struct esp32s2_uart_s
uint8_t rs485_dir_gpio; /* UART RS-485 DIR GPIO pin cfg */
bool rs485_dir_polarity; /* UART RS-485 DIR TXEN polarity */
#endif
spinlock_t lock; /* Spinlock */
};

extern struct esp32s2_uart_s g_uart0_config;
Expand Down
12 changes: 8 additions & 4 deletions arch/xtensa/src/esp32s2/esp32s2_rtc_lowerhalf.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct esp32s2_lowerhalf_s
*/

const struct rtc_ops_s *ops;
spinlock_t lock;
#ifdef CONFIG_RTC_ALARM
/* Alarm callback information */

Expand Down Expand Up @@ -115,6 +116,7 @@ static const struct rtc_ops_s g_rtc_ops =
static struct esp32s2_lowerhalf_s g_rtc_lowerhalf =
{
.ops = &g_rtc_ops,
.lock = SP_UNLOCKED,
};

/****************************************************************************
Expand Down Expand Up @@ -375,6 +377,7 @@ static int rtc_lh_setalarm(struct rtc_lowerhalf_s *lower,
static int rtc_lh_setrelative(struct rtc_lowerhalf_s *lower,
const struct lower_setrelative_s *alarminfo)
{
struct esp32s2_lowerhalf_s *priv = (struct esp32s2_lowerhalf_s *)lower;
struct lower_setalarm_s setalarm;
time_t seconds;
int ret = -EINVAL;
Expand All @@ -386,7 +389,7 @@ static int rtc_lh_setrelative(struct rtc_lowerhalf_s *lower,

if (alarminfo->reltime > 0)
{
flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&priv->lock);

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

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&priv->lock, flags);
}

return ret;
Expand Down Expand Up @@ -465,6 +468,7 @@ static int rtc_lh_cancelalarm(struct rtc_lowerhalf_s *lower, int alarmid)
static int rtc_lh_rdalarm(struct rtc_lowerhalf_s *lower,
struct lower_rdalarm_s *alarminfo)
{
struct esp32s2_lowerhalf_s *priv = (struct esp32s2_lowerhalf_s *)lower;
struct timespec ts;
int ret;
irqstate_t flags;
Expand All @@ -473,13 +477,13 @@ static int rtc_lh_rdalarm(struct rtc_lowerhalf_s *lower,
DEBUGASSERT((RTC_ALARM0 <= alarminfo->id) &&
(alarminfo->id < RTC_ALARM_LAST));

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&priv->lock);

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

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&priv->lock, flags);

return ret;
}
Expand Down
12 changes: 10 additions & 2 deletions arch/xtensa/src/esp32s3/esp32s3_idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@

#endif

/****************************************************************************
* Private Data
****************************************************************************/

#ifdef CONFIG_PM
static spinlock_t g_esp32s3_idle_lock = SP_UNLOCKED;
#endif

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -91,7 +99,7 @@ static void up_idlepm(void)

if (newstate != oldstate)
{
flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_esp32s3_idle_lock);

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

Expand All @@ -113,7 +121,7 @@ static void up_idlepm(void)
oldstate = newstate;
}

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_esp32s3_idle_lock, flags);

/* MCU-specific power management logic */

Expand Down