Skip to content

Commit

Permalink
os/arch/arm/src/amebasmart: Update arch layer critical zone usage
Browse files Browse the repository at this point in the history
- Change irqsave/irqrestore to enter/leave_critical_section
  • Loading branch information
edwakuwaku committed Apr 11, 2024
1 parent 67313f4 commit 130b587
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 44 deletions.
12 changes: 6 additions & 6 deletions os/arch/arm/src/amebasmart/amebasmart_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ static inline int amebasmart_i2c_sem_waitdone(FAR struct amebasmart_i2c_priv_s *
irqstate_t flags;
int ret;

flags = irqsave();
flags = enter_critical_section();

/* Enable I2C interrupts */
up_enable_irq(priv->config->irq);
Expand Down Expand Up @@ -533,7 +533,7 @@ static inline int amebasmart_i2c_sem_waitdone(FAR struct amebasmart_i2c_priv_s *

up_disable_irq(priv->config->irq);

irqrestore(flags);
leave_critical_section(flags);
return ret;
}
#else
Expand Down Expand Up @@ -1156,14 +1156,14 @@ FAR struct i2c_dev_s *up_i2cinitialize(int port)
/* Initialize private data for the first time, increment reference count,
* power-up hardware and configure GPIOs.
*/
flags = irqsave();
flags = enter_critical_section();

if ((volatile int)priv->refs++ == 0) {
amebasmart_i2c_sem_init(priv);
amebasmart_i2c_init(priv);
}

irqrestore(flags);
leave_critical_section(flags);

return (struct i2c_dev_s *)priv;
}
Expand All @@ -1189,14 +1189,14 @@ int up_i2cuninitialize(FAR struct i2c_dev_s *dev)
return ERROR;
}

flags = irqsave();
flags = enter_critical_section();

if (--priv->refs > 0) {
irqrestore(flags);
return OK;
}

irqrestore(flags);
leave_critical_section(flags);

/* Disable power and other HW resource (GPIO's) */

Expand Down
64 changes: 32 additions & 32 deletions os/arch/arm/src/amebasmart/amebasmart_i2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,14 +435,14 @@ static int i2s_tx_start(struct amebasmart_i2s_s *priv)
return OK;
}

flags = irqsave();
flags = enter_critical_section();

/* Remove the pending TX transfer at the head of the TX pending queue. */
bfcontainer = (struct amebasmart_buffer_s *)sq_remfirst(&priv->tx.pend);

/* Start first transfer */
amebasmart_i2s_tx(priv, bfcontainer);
irqrestore(flags);
leave_critical_section(flags);

/* Start a watchdog to catch DMA timeouts */
if (bfcontainer->timeout > 0) {
Expand Down Expand Up @@ -488,9 +488,9 @@ static void i2s_tx_worker(void *arg)
* also modified from the interrupt level.
*/

flags = irqsave();
flags = enter_critical_section();
bfcontainer = (struct amebasmart_buffer_s *)sq_remfirst(&priv->tx.done);
irqrestore(flags);
leave_critical_section(flags);
/* Perform the TX transfer done callback */

DEBUGASSERT(bfcontainer && bfcontainer->callback);
Expand Down Expand Up @@ -668,9 +668,9 @@ static int i2s_send(struct i2s_dev_s *dev, struct ap_buffer_s *apb, i2s_callback
bfcontainer->apb = apb;
bfcontainer->result = -EBUSY;

flags = irqsave();
flags = enter_critical_section();
sq_addlast((sq_entry_t *)bfcontainer, &priv->tx.pend);
irqrestore(flags);
leave_critical_section(flags);

ret = i2s_tx_start(priv);

Expand Down Expand Up @@ -788,7 +788,7 @@ static int i2s_rx_start(struct amebasmart_i2s_s *priv)
return OK;
}

flags = irqsave();
flags = enter_critical_section();
/* Remove the pending RX transfer at the head of the RX pending queue. */
bfcontainer = (struct amebasmart_buffer_s *)sq_remfirst(&priv->rx.pend);

Expand All @@ -799,7 +799,7 @@ static int i2s_rx_start(struct amebasmart_i2s_s *priv)

i2s_recv_page(&priv->i2s_object);
}
irqrestore(flags);
leave_critical_section(flags);

/* Start a watchdog to catch DMA timeouts */
if (bfcontainer->timeout > 0) {
Expand Down Expand Up @@ -844,9 +844,9 @@ static void i2s_rx_worker(void *arg)
* interrupts must be disabled to do this because the rx.done queue is
* also modified from the interrupt level.
*/
flags = irqsave();
flags = enter_critical_section();
bfcontainer = (struct amebasmart_buffer_s *)sq_remfirst(&priv->rx.done);
irqrestore(flags);
leave_critical_section(flags);

/* Perform the RX transfer done callback */
DEBUGASSERT(bfcontainer && bfcontainer->apb && bfcontainer->callback);
Expand Down Expand Up @@ -1027,9 +1027,9 @@ static int i2s_receive(struct i2s_dev_s *dev, struct ap_buffer_s *apb, i2s_callb
/* Prepare DMA microcode */
i2s_rxdma_prep(priv, bfcontainer);

flags = irqsave();
flags = enter_critical_section();
sq_addlast((sq_entry_t *)bfcontainer, &priv->rx.pend);
irqrestore(flags);
leave_critical_section(flags);
i2sinfo("i2s_rx_start\n");
/* Start transfer */
ret = i2s_rx_start(priv);
Expand Down Expand Up @@ -1121,13 +1121,13 @@ static struct amebasmart_buffer_s *i2s_buf_rx_allocate(struct amebasmart_i2s_s *
i2s_bufsem_rx_take(priv);

/* Get the buffer from the head of the free list */
flags = irqsave();
flags = enter_critical_section();
bfcontainer = priv->freelist_rx;
ASSERT(bfcontainer);

/* Unlink the buffer from the freelist */
priv->freelist_rx = bfcontainer->flink;
irqrestore(flags);
leave_critical_section(flags);

return bfcontainer;
}
Expand All @@ -1154,10 +1154,10 @@ static void i2s_buf_rx_free(struct amebasmart_i2s_s *priv, struct amebasmart_buf
irqstate_t flags;

/* Put the buffer container back on the free list */
flags = irqsave();
flags = enter_critical_section();
bfcontainer->flink = priv->freelist_rx;
priv->freelist_rx = bfcontainer;
irqrestore(flags);
leave_critical_section(flags);

/* Wake up any threads waiting for a buffer container */
i2s_bufsem_rx_give(priv);
Expand Down Expand Up @@ -1252,13 +1252,13 @@ static struct amebasmart_buffer_s *i2s_buf_tx_allocate(struct amebasmart_i2s_s *
i2s_bufsem_tx_take(priv);

/* Get the buffer from the head of the free list */
flags = irqsave();
flags = enter_critical_section();
bfcontainer = priv->freelist_tx;
ASSERT(bfcontainer);

/* Unlink the buffer from the freelist */
priv->freelist_tx = bfcontainer->flink;
irqrestore(flags);
leave_critical_section(flags);

return bfcontainer;
}
Expand All @@ -1285,10 +1285,10 @@ static void i2s_buf_tx_free(struct amebasmart_i2s_s *priv, struct amebasmart_buf
irqstate_t flags;

/* Put the buffer container back on the free list */
flags = irqsave();
flags = enter_critical_section();
bfcontainer->flink = priv->freelist_tx;
priv->freelist_tx = bfcontainer;
irqrestore(flags);
leave_critical_section(flags);

/* Wake up any threads waiting for a buffer container */
i2s_bufsem_tx_give(priv);
Expand Down Expand Up @@ -1469,25 +1469,25 @@ static int i2s_stop(struct i2s_dev_s *dev, i2s_ch_dir_t dir)
if (dir == I2S_TX) {
i2s_disable(&priv->i2s_object);
while (sq_peek(&priv->tx.pend) != NULL) {
flags = irqsave();
flags = enter_critical_section();
bfcontainer = (struct amebasmart_buffer_s *)sq_remfirst(&priv->tx.pend);
irqrestore(flags);
leave_critical_section(flags);
apb_free(bfcontainer->apb);
i2s_buf_tx_free(priv, bfcontainer);
}

while (sq_peek(&priv->tx.act) != NULL) {
flags = irqsave();
flags = enter_critical_section();
bfcontainer = (struct amebasmart_buffer_s *)sq_remfirst(&priv->tx.act);
irqrestore(flags);
leave_critical_section(flags);
apb_free(bfcontainer->apb);
i2s_buf_tx_free(priv, bfcontainer);
}

while (sq_peek(&priv->tx.done) != NULL) {
flags = irqsave();
flags = enter_critical_section();
bfcontainer = (struct amebasmart_buffer_s *)sq_remfirst(&priv->tx.done);
irqrestore(flags);
leave_critical_section(flags);
i2s_buf_tx_free(priv, bfcontainer);
}
}
Expand All @@ -1497,25 +1497,25 @@ static int i2s_stop(struct i2s_dev_s *dev, i2s_ch_dir_t dir)
if (dir == I2S_RX) {
i2s_disable(&priv->i2s_object);
while (sq_peek(&priv->rx.pend) != NULL) {
flags = irqsave();
flags = enter_critical_section();
bfcontainer = (struct amebasmart_buffer_s *)sq_remfirst(&priv->rx.pend);
irqrestore(flags);
leave_critical_section(flags);
apb_free(bfcontainer->apb);
i2s_buf_rx_free(priv, bfcontainer);
}

while (sq_peek(&priv->rx.act) != NULL) {
flags = irqsave();
flags = enter_critical_section();
bfcontainer = (struct amebasmart_buffer_s *)sq_remfirst(&priv->rx.act);
irqrestore(flags);
leave_critical_section(flags);
apb_free(bfcontainer->apb);
i2s_buf_rx_free(priv, bfcontainer);
}

while (sq_peek(&priv->rx.done) != NULL) {
flags = irqsave();
flags = enter_critical_section();
bfcontainer = (struct amebasmart_buffer_s *)sq_remfirst(&priv->rx.done);
irqrestore(flags);
leave_critical_section(flags);
i2s_buf_rx_free(priv, bfcontainer);
}
}
Expand Down
8 changes: 4 additions & 4 deletions os/arch/arm/src/amebasmart/amebasmart_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ FAR struct spi_dev_s *amebasmart_spibus_initialize(int bus)
{
FAR struct amebasmart_spidev_s *priv = NULL;

irqstate_t flags = irqsave();
irqstate_t flags = enter_critical_section();

if (bus == 0) {
/* Select SPI0 */
Expand Down Expand Up @@ -1186,7 +1186,7 @@ FAR struct spi_dev_s *amebasmart_spibus_initialize(int bus)
return NULL;
}

irqrestore(flags);
leave_critical_section(flags);

return (FAR struct spi_dev_s *)priv;
}
Expand All @@ -1209,7 +1209,7 @@ FAR struct spi_dev_s *up_spiinitialize(int port)
{
FAR struct amebasmart_spidev_s *priv = NULL;

irqstate_t flags = irqsave();
irqstate_t flags = enter_critical_section();

if (port == 0) {
/* Select SPI0 */
Expand Down Expand Up @@ -1242,7 +1242,7 @@ FAR struct spi_dev_s *up_spiinitialize(int port)
return NULL;
}

irqrestore(flags);
leave_critical_section(flags);

return (FAR struct spi_dev_s *)priv;
}
4 changes: 2 additions & 2 deletions os/arch/arm/src/amebasmart/amebasmart_timer_lowerhalf.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ static void amebasmart_gpt_setcallback(struct timer_lowerhalf_s *lower, tccb_t c
struct amebasmart_gpt_lowerhalf_s *priv = (struct amebasmart_gpt_lowerhalf_s *)lower;
DEBUGASSERT(priv);
if (priv) {
irqstate_t flags = irqsave();
irqstate_t flags = enter_critical_section();

/* Save the new callback */
priv->callback = callback;
Expand All @@ -363,7 +363,7 @@ static void amebasmart_gpt_setcallback(struct timer_lowerhalf_s *lower, tccb_t c
priv->obj.hid = 0;
}

irqrestore(flags);
leave_critical_section(flags);
}
}

Expand Down

0 comments on commit 130b587

Please sign in to comment.