Skip to content

Commit 2668476

Browse files
nordic-krchfabiobaltieri
authored andcommitted
drivers: serial: nrfx_uarte: Use nrfx_gppi helper
Use nrfx_gppi as abstraction over (D)PPI. Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent da6b607 commit 2668476

File tree

1 file changed

+7
-42
lines changed

1 file changed

+7
-42
lines changed

drivers/serial/uart_nrfx_uarte.c

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,6 @@ LOG_MODULE_REGISTER(uart_nrfx_uarte, CONFIG_UART_LOG_LEVEL);
2424

2525
#include <zephyr/drivers/pinctrl.h>
2626

27-
/* Generalize PPI or DPPI channel management */
28-
#if defined(PPI_PRESENT)
29-
#include <nrfx_ppi.h>
30-
#define gppi_channel_t nrf_ppi_channel_t
31-
#define gppi_channel_alloc nrfx_ppi_channel_alloc
32-
#define gppi_channel_enable nrfx_ppi_channel_enable
33-
#elif defined(DPPI_PRESENT)
34-
#include <nrfx_dppi.h>
35-
#define gppi_channel_t uint8_t
36-
#define gppi_channel_alloc nrfx_dppi_channel_alloc
37-
#define gppi_channel_enable nrfx_dppi_channel_enable
38-
#else
39-
#error "No PPI or DPPI"
40-
#endif
41-
4227
#define UARTE(idx) DT_NODELABEL(uart##idx)
4328
#define UARTE_HAS_PROP(idx, prop) DT_NODE_HAS_PROP(UARTE(idx), prop)
4429
#define UARTE_PROP(idx, prop) DT_PROP(UARTE(idx), prop)
@@ -185,7 +170,7 @@ struct uarte_nrfx_data {
185170
atomic_val_t poll_out_lock;
186171
uint8_t *char_out;
187172
uint8_t *rx_data;
188-
gppi_channel_t ppi_ch_endtx;
173+
uint8_t ppi_ch_endtx;
189174
};
190175

191176
#define UARTE_LOW_POWER_TX BIT(0)
@@ -618,6 +603,8 @@ static int uarte_nrfx_rx_counting_init(const struct device *dev)
618603
if (HW_RX_COUNTING_ENABLED(cfg)) {
619604
nrfx_timer_config_t tmr_config = NRFX_TIMER_DEFAULT_CONFIG(
620605
NRF_TIMER_BASE_FREQUENCY_GET(cfg->timer.p_reg));
606+
uint32_t evt_addr = nrf_uarte_event_address_get(uarte, NRF_UARTE_EVENT_RXDRDY);
607+
uint32_t tsk_addr = nrfx_timer_task_address_get(&cfg->timer, NRF_TIMER_TASK_COUNT);
621608

622609
tmr_config.mode = NRF_TIMER_MODE_COUNTER;
623610
tmr_config.bit_width = NRF_TIMER_BIT_WIDTH_32;
@@ -632,37 +619,15 @@ static int uarte_nrfx_rx_counting_init(const struct device *dev)
632619
nrfx_timer_clear(&cfg->timer);
633620
}
634621

635-
ret = gppi_channel_alloc(&data->async->rx.cnt.ppi);
622+
ret = nrfx_gppi_channel_alloc(&data->async->rx.cnt.ppi);
636623
if (ret != NRFX_SUCCESS) {
637624
LOG_ERR("Failed to allocate PPI Channel");
638625
nrfx_timer_uninit(&cfg->timer);
639626
return -EINVAL;
640627
}
641628

642-
#if CONFIG_HAS_HW_NRF_PPI
643-
ret = nrfx_ppi_channel_assign(
644-
data->async->rx.cnt.ppi,
645-
nrf_uarte_event_address_get(uarte,
646-
NRF_UARTE_EVENT_RXDRDY),
647-
nrfx_timer_task_address_get(&cfg->timer,
648-
NRF_TIMER_TASK_COUNT));
649-
650-
if (ret != NRFX_SUCCESS) {
651-
return -EIO;
652-
}
653-
#else
654-
nrf_uarte_publish_set(uarte,
655-
NRF_UARTE_EVENT_RXDRDY,
656-
data->async->rx.cnt.ppi);
657-
nrf_timer_subscribe_set(cfg->timer.p_reg,
658-
NRF_TIMER_TASK_COUNT,
659-
data->async->rx.cnt.ppi);
660-
661-
#endif
662-
ret = gppi_channel_enable(data->async->rx.cnt.ppi);
663-
if (ret != NRFX_SUCCESS) {
664-
return -EIO;
665-
}
629+
nrfx_gppi_channel_endpoints_setup(data->async->rx.cnt.ppi, evt_addr, tsk_addr);
630+
nrfx_gppi_channels_enable(BIT(data->async->rx.cnt.ppi));
666631
} else {
667632
nrf_uarte_int_enable(uarte, NRF_UARTE_INT_RXDRDY_MASK);
668633
}
@@ -1745,7 +1710,7 @@ static int endtx_stoptx_ppi_init(NRF_UARTE_Type *uarte,
17451710
{
17461711
nrfx_err_t ret;
17471712

1748-
ret = gppi_channel_alloc(&data->ppi_ch_endtx);
1713+
ret = nrfx_gppi_channel_alloc(&data->ppi_ch_endtx);
17491714
if (ret != NRFX_SUCCESS) {
17501715
LOG_ERR("Failed to allocate PPI Channel");
17511716
return -EIO;

0 commit comments

Comments
 (0)