Skip to content

Commit c0cbcfd

Browse files
committed
[nrf fromlist] drivers: serial: nrfx_uarte: Reorder functions in the file
Move uarte_disable_locked and HW_RX_COUNTING_ENABLED macro up in the file so it can be used by more functions. This patch has no functional changes. Upstream PR #: 81631 Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent 4f3ef0a commit c0cbcfd

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

drivers/serial/uart_nrfx_uarte.c

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,13 @@ struct uarte_nrfx_config {
302302
uint8_t *poll_in_byte;
303303
};
304304

305+
/* Using Macro instead of static inline function to handle NO_OPTIMIZATIONS case
306+
* where static inline fails on linking.
307+
*/
308+
#define HW_RX_COUNTING_ENABLED(config) \
309+
(IS_ENABLED(UARTE_ANY_HW_ASYNC) ? \
310+
(config->flags & UARTE_CFG_FLAG_HW_BYTE_COUNTING) : false)
311+
305312
static inline NRF_UARTE_Type *get_uarte_instance(const struct device *dev)
306313
{
307314
const struct uarte_nrfx_config *config = dev->config;
@@ -324,6 +331,39 @@ static void endtx_isr(const struct device *dev)
324331

325332
}
326333

334+
/** @brief Disable UARTE peripheral is not used by RX or TX.
335+
*
336+
* It must be called with interrupts locked so that deciding if no direction is
337+
* using the UARTE is atomically performed with UARTE peripheral disabling. Otherwise
338+
* it would be possible that after clearing flags we get preempted and UARTE is
339+
* enabled from the higher priority context and when we come back UARTE is disabled
340+
* here.
341+
* @param dev Device.
342+
* @param dis_mask Mask of direction (RX or TX) which now longer uses the UARTE instance.
343+
*/
344+
static void uarte_disable_locked(const struct device *dev, uint32_t dis_mask)
345+
{
346+
struct uarte_nrfx_data *data = dev->data;
347+
348+
data->flags &= ~dis_mask;
349+
if (data->flags & UARTE_FLAG_LOW_POWER) {
350+
return;
351+
}
352+
353+
#if !defined(CONFIG_UART_NRFX_UARTE_ENHANCED_RX)
354+
const struct uarte_nrfx_config *config = dev->config;
355+
356+
if (data->async && HW_RX_COUNTING_ENABLED(config)) {
357+
nrfx_timer_disable(&config->timer);
358+
/* Timer/counter value is reset when disabled. */
359+
data->async->rx.total_byte_cnt = 0;
360+
data->async->rx.total_user_byte_cnt = 0;
361+
}
362+
#endif
363+
364+
nrf_uarte_disable(get_uarte_instance(dev));
365+
}
366+
327367
#ifdef UARTE_ANY_NONE_ASYNC
328368
/**
329369
* @brief Interrupt service routine.
@@ -575,13 +615,6 @@ static int wait_tx_ready(const struct device *dev)
575615
return key;
576616
}
577617

578-
/* Using Macro instead of static inline function to handle NO_OPTIMIZATIONS case
579-
* where static inline fails on linking.
580-
*/
581-
#define HW_RX_COUNTING_ENABLED(config) \
582-
(IS_ENABLED(UARTE_ANY_HW_ASYNC) ? \
583-
(config->flags & UARTE_CFG_FLAG_HW_BYTE_COUNTING) : false)
584-
585618
static void uarte_periph_enable(const struct device *dev)
586619
{
587620
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
@@ -672,39 +705,6 @@ static void tx_start(const struct device *dev, const uint8_t *buf, size_t len)
672705
}
673706

674707
#if defined(UARTE_ANY_ASYNC)
675-
/** @brief Disable UARTE peripheral is not used by RX or TX.
676-
*
677-
* It must be called with interrupts locked so that deciding if no direction is
678-
* using the UARTE is atomically performed with UARTE peripheral disabling. Otherwise
679-
* it would be possible that after clearing flags we get preempted and UARTE is
680-
* enabled from the higher priority context and when we come back UARTE is disabled
681-
* here.
682-
* @param dev Device.
683-
* @param dis_mask Mask of direction (RX or TX) which now longer uses the UARTE instance.
684-
*/
685-
static void uarte_disable_locked(const struct device *dev, uint32_t dis_mask)
686-
{
687-
struct uarte_nrfx_data *data = dev->data;
688-
689-
data->flags &= ~dis_mask;
690-
if (data->flags & UARTE_FLAG_LOW_POWER) {
691-
return;
692-
}
693-
694-
#if !defined(CONFIG_UART_NRFX_UARTE_ENHANCED_RX)
695-
const struct uarte_nrfx_config *config = dev->config;
696-
697-
if (data->async && HW_RX_COUNTING_ENABLED(config)) {
698-
nrfx_timer_disable(&config->timer);
699-
/* Timer/counter value is reset when disabled. */
700-
data->async->rx.total_byte_cnt = 0;
701-
data->async->rx.total_user_byte_cnt = 0;
702-
}
703-
#endif
704-
705-
nrf_uarte_disable(get_uarte_instance(dev));
706-
}
707-
708708
static void rx_timeout(struct k_timer *timer);
709709
static void tx_timeout(struct k_timer *timer);
710710

0 commit comments

Comments
 (0)