Skip to content

Commit 3f60dd1

Browse files
committed
[nrf fromlist] drivers: serial: nrfx_uarte: Minor code size optimization
Optimize function which enables UARTE peripheral. It is called only when interrupts are locked so data->flags does not require atomic operation. Use standard logical operations so save few bytes. Upstream PR: zephyrproject-rtos/zephyr#80201 Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent 79d9d57 commit 3f60dd1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/serial/uart_nrfx_uarte.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,11 +606,12 @@ static void uarte_periph_enable(const struct device *dev)
606606
}
607607
}
608608

609-
static void uarte_enable(const struct device *dev, uint32_t act_mask, uint32_t sec_mask)
609+
static void uarte_enable_locked(const struct device *dev, uint32_t act_mask, uint32_t sec_mask)
610610
{
611611
struct uarte_nrfx_data *data = dev->data;
612612

613-
if (atomic_or(&data->flags, act_mask) & sec_mask) {
613+
data->flags |= act_mask;
614+
if (data->flags & sec_mask) {
614615
/* Second direction already enabled so UARTE is enabled. */
615616
return;
616617
}
@@ -640,7 +641,7 @@ static void tx_start(const struct device *dev, const uint8_t *buf, size_t len)
640641
return;
641642
}
642643
} else if (config->flags & UARTE_CFG_FLAG_LOW_POWER) {
643-
uarte_enable(dev, UARTE_FLAG_LOW_POWER_TX, UARTE_FLAG_LOW_POWER_RX);
644+
uarte_enable_locked(dev, UARTE_FLAG_LOW_POWER_TX, UARTE_FLAG_LOW_POWER_RX);
644645
nrf_uarte_int_enable(uarte, NRF_UARTE_INT_TXSTOPPED_MASK);
645646
}
646647

@@ -1151,7 +1152,7 @@ static int uarte_nrfx_rx_enable(const struct device *dev, uint8_t *buf,
11511152
} else if (cfg->flags & UARTE_CFG_FLAG_LOW_POWER) {
11521153
unsigned int key = irq_lock();
11531154

1154-
uarte_enable(dev, UARTE_FLAG_LOW_POWER_RX, UARTE_FLAG_LOW_POWER_TX);
1155+
uarte_enable_locked(dev, UARTE_FLAG_LOW_POWER_RX, UARTE_FLAG_LOW_POWER_TX);
11551156
irq_unlock(key);
11561157
}
11571158

0 commit comments

Comments
 (0)