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
12 changes: 8 additions & 4 deletions arch/xtensa/src/esp32s3/esp32s3_rtc_lowerhalf.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct esp32s3_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 esp32s3_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 esp32s3_lowerhalf_s *priv = (struct esp32s3_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 esp32s3_lowerhalf_s *priv = (struct esp32s3_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
50 changes: 34 additions & 16 deletions arch/z16/src/z16f/z16f_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ struct z16f_uart_s
uint8_t rxirq; /* RX IRQ associated with this UART */
uint8_t txirq; /* RX IRQ associated with this UART */
uint8_t parity; /* 0=none, 1=odd, 2=even */
spinlock_t lock; /* */
bool stopbits2; /* true: Configure with 2 stop bits instead of 1 */
};

Expand Down Expand Up @@ -139,6 +140,7 @@ static struct z16f_uart_s g_uart0priv =
Z16F_IRQ_UART0RX, /* rxirq */
Z16F_IRQ_UART0TX, /* txirq */
CONFIG_UART0_PARITY, /* parity */
SP_UNLOCKED, /* Spinlock */
CONFIG_UART0_2STOP /* stopbits2 */
};

Expand All @@ -157,6 +159,7 @@ static struct z16f_uart_s g_uart1priv =
Z16F_IRQ_UART1RX, /* rxirq */
Z16F_IRQ_UART1TX, /* txirq */
CONFIG_UART1_PARITY, /* parity */
SP_UNLOCKED, /* Spinlock */
CONFIG_UART1_2STOP /* stopbits2 */
};

Expand Down Expand Up @@ -215,16 +218,16 @@ static uart_dev_t g_uart1port;
static uint8_t z16f_disableuartirq(struct uart_dev_s *dev)
{
struct z16f_uart_s *priv = (struct z16f_uart_s *)dev->priv;
irqstate_t flags = spin_lock_irqsave(NULL);
irqstate_t flags = spin_lock_irqsave(&priv->lock);
uint8_t state = priv->rxenabled ? STATE_RXENABLED :
STATE_DISABLED |
priv->txenabled ? STATE_TXENABLED :
STATE_DISABLED;

z16f_txint(dev, false);
z16f_rxint(dev, false);
z16f_txint_nolock(dev, false);
z16f_rxint_nolock(dev, false);

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

Expand All @@ -234,12 +237,13 @@ static uint8_t z16f_disableuartirq(struct uart_dev_s *dev)

static void z16f_restoreuartirq(struct uart_dev_s *dev, uint8_t state)
{
irqstate_t flags = spin_lock_irqsave(NULL);
struct z16f_uart_s *priv = (struct z16f_uart_s *)dev->priv;
irqstate_t flags = spin_lock_irqsave(&priv->lock);

z16f_txint(dev, (state & STATE_TXENABLED) ? true : false);
z16f_rxint(dev, (state & STATE_RXENABLED) ? true : false);
z16f_txint_nolock(dev, (state & STATE_TXENABLED) ? true : false);
z16f_rxint_nolock(dev, (state & STATE_RXENABLED) ? true : false);

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

/****************************************************************************
Expand Down Expand Up @@ -507,10 +511,9 @@ static int z16f_receive(struct uart_dev_s *dev, uint32_t *status)
*
****************************************************************************/

static void z16f_rxint(struct uart_dev_s *dev, bool enable)
static void z16f_rxint_nolock(struct uart_dev_s *dev, bool enable)
{
struct z16f_uart_s *priv = (struct z16f_uart_s *)dev->priv;
irqstate_t flags = enter_critical_section();
struct z16f_uart_s *priv = (struct z16f_uart_s *)dev->priv;

if (enable)
{
Expand All @@ -524,7 +527,15 @@ static void z16f_rxint(struct uart_dev_s *dev, bool enable)
}

priv->rxenabled = enable;
leave_critical_section(flags);
}

static void z16f_rxint(struct uart_dev_s *dev, bool enable)
{
struct z16f_uart_s *priv = (struct z16f_uart_s *)dev->priv;
irqstate_t flags = spin_lock_irqsave(&priv->lock);

z16f_rxint_nolock(dev, enable);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
Expand Down Expand Up @@ -564,10 +575,9 @@ static void z16f_send(struct uart_dev_s *dev, int ch)
*
****************************************************************************/

static void z16f_txint(struct uart_dev_s *dev, bool enable)
static void z16f_txint_nolock(struct uart_dev_s *dev, bool enable)
{
struct z16f_uart_s *priv = (struct z16f_uart_s *)dev->priv;
irqstate_t flags = enter_critical_section();
struct z16f_uart_s *priv = (struct z16f_uart_s *)dev->priv;

if (enable)
{
Expand All @@ -587,7 +597,15 @@ static void z16f_txint(struct uart_dev_s *dev, bool enable)
}

priv->txenabled = enable;
leave_critical_section(flags);
}

static void z16f_txint(struct uart_dev_s *dev, bool enable)
{
struct z16f_uart_s *priv = (struct z16f_uart_s *)dev->priv;
irqstate_t flags = spin_lock_irqsave(&priv->lock);

z16f_txint_nolock(dev, enable);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
Expand Down
59 changes: 38 additions & 21 deletions arch/z80/src/z8/z8_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ struct z8_uart_s
uint8_t rxirq; /* RX IRQ associated with this UART */
uint8_t txirq; /* RX IRQ associated with this UART */
uint8_t parity; /* 0=none, 1=odd, 2=even */
spinlock_t lock; /* Spinlock */
bool stopbits2; /* true: Configure with 2 stop bits
* (instead of 1) */
};
Expand Down Expand Up @@ -134,6 +135,7 @@ static struct z8_uart_s g_uart0priv =
Z8_UART0_RX_IRQ, /* rxirq */
Z8_UART0_TX_IRQ, /* txirq */
CONFIG_UART0_PARITY, /* parity */
SP_UNLOCKED, /* Spinlock */
CONFIG_UART0_2STOP /* stopbits2 */
};

Expand Down Expand Up @@ -179,6 +181,7 @@ static struct z8_uart_s g_uart1priv =
Z8_UART1_RX_IRQ, /* rxirq */
Z8_UART1_TX_IRQ, /* txirq */
CONFIG_UART1_PARITY, /* parity */
SP_UNLOCKED, /* Spinlock */
CONFIG_UART1_2STOP /* stopbits2 */
};

Expand Down Expand Up @@ -254,17 +257,17 @@ static inline uint8_t z8_getuart(FAR struct z8_uart_s *priv, uint8_t offset)

static uint8_t z8_disableuartirq(FAR struct uart_dev_s *dev)
{
struct z8_uart_s *priv = (struct z8_uart_s *)dev->priv;
irqstate_t flags = spin_lock_irqsave(NULL);
uint8_t state = priv->rxenabled ?
STATE_RXENABLED : STATE_DISABLED | \
priv->txenabled ?
STATE_TXENABLED : STATE_DISABLED;
struct z8_uart_s *priv = (struct z8_uart_s *)dev->priv;
irqstate_t flags = spin_lock_irqsave(&priv->lock);
uint8_t state = priv->rxenabled ?
STATE_RXENABLED : STATE_DISABLED | \
priv->txenabled ?
STATE_TXENABLED : STATE_DISABLED;

z8_txint(dev, false);
z8_rxint(dev, false);
z8_txint_nolock(dev, false);
z8_rxint_nolock(dev, false);

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

Expand All @@ -274,12 +277,12 @@ static uint8_t z8_disableuartirq(FAR struct uart_dev_s *dev)

static void z8_restoreuartirq(FAR struct uart_dev_s *dev, uint8_t state)
{
irqstate_t flags = spin_lock_irqsave(NULL);
irqstate_t flags = spin_lock_irqsave(&priv->lock);

z8_txint(dev, (state & STATE_TXENABLED) ? true : false);
z8_rxint(dev, (state & STATE_RXENABLED) ? true : false);
z8_txint_nolock(dev, (state & STATE_TXENABLED) ? true : false);
z8_rxint_nolock(dev, (state & STATE_RXENABLED) ? true : false);

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

/****************************************************************************
Expand Down Expand Up @@ -582,10 +585,9 @@ static int z8_receive(FAR struct uart_dev_s *dev, FAR uint32_t *status)
*
****************************************************************************/

static void z8_rxint(FAR struct uart_dev_s *dev, bool enable)
static void z8_rxint_nolock(FAR struct uart_dev_s *dev, bool enable)
{
struct z8_uart_s *priv = (struct z8_uart_s *)dev->priv;
irqstate_t flags = enter_critical_section();
struct z8_uart_s *priv = (struct z8_uart_s *)dev->priv;

if (enable)
{
Expand All @@ -599,7 +601,15 @@ static void z8_rxint(FAR struct uart_dev_s *dev, bool enable)
}

priv->rxenabled = enable;
leave_critical_section(flags);
}

static void z8_rxint(FAR struct uart_dev_s *dev, bool enable)
{
struct z8_uart_s *priv = (struct z8_uart_s *)dev->priv;
irqstate_t flags = spin_lock_irqsave(&priv->lock);

z8_rxint_nolock(dev, enable);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
Expand Down Expand Up @@ -638,10 +648,9 @@ static void z8_send(FAR struct uart_dev_s *dev, int ch)
*
****************************************************************************/

static void z8_txint(FAR struct uart_dev_s *dev, bool enable)
static void z8_txint_nolock(FAR struct uart_dev_s *dev, bool enable)
{
struct z8_uart_s *priv = (struct z8_uart_s *)dev->priv;
irqstate_t flags = enter_critical_section();
struct z8_uart_s *priv = (struct z8_uart_s *)dev->priv;

if (enable)
{
Expand All @@ -655,7 +664,15 @@ static void z8_txint(FAR struct uart_dev_s *dev, bool enable)
}

priv->txenabled = enable;
leave_critical_section(flags);
}

static void z8_txint(FAR struct uart_dev_s *dev, bool enable)
{
struct z8_uart_s *priv = (struct z8_uart_s *)dev->priv;
irqstate_t flags = spin_lock_irqsave(&priv->lock);

z8_txint_nolock(dev, enable);
spin_unlock_irqrestore(&priv->lock, flags);
}

/****************************************************************************
Expand Down
12 changes: 10 additions & 2 deletions boards/arm/max326xx/max32660-evsys/src/max326_button.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@

#ifdef CONFIG_ARCH_BUTTONS

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

#if defined(CONFIG_SAMA5_PIOB_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
static spinlock_t g_max326_lock = SP_UNLOCKED;
#endif

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down Expand Up @@ -108,7 +116,7 @@ int board_button_irq(int id, xcpt_t irqhandler, void *arg)
* following operations are atomic.
*/

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_max326_lock);

/* Are we attaching or detaching? */

Expand All @@ -127,7 +135,7 @@ int board_button_irq(int id, xcpt_t irqhandler, void *arg)
irq_detach(BUTTON_IRQ);
}

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_max326_lock, flags);
ret = OK;
}

Expand Down
Loading