Skip to content

Commit 2600251

Browse files
committed
debug: cpu_load: Improve PPI handling
Improve PPI handling to use GPPI where possible and DPPI directly only in case of sharing DPPI channels. Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
1 parent 0ab3422 commit 2600251

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

subsys/debug/cpu_load/cpu_load.c

+6-22
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
*/
66
#include <debug/cpu_load.h>
77
#include <zephyr/shell/shell.h>
8-
#ifdef DPPI_PRESENT
9-
#include <nrfx_dppi.h>
10-
#else
11-
#include <nrfx_ppi.h>
12-
#endif
138
#include <helpers/nrfx_gppi.h>
149
#include <nrfx_timer.h>
1510
#include <hal/nrf_rtc.h>
@@ -46,10 +41,7 @@ static uint32_t shared_ch_mask;
4641
/** @brief Allocate (D)PPI channel. */
4742
static nrfx_err_t ppi_alloc(uint8_t *ch, uint32_t evt)
4843
{
49-
nrfx_err_t err;
5044
#ifdef DPPI_PRESENT
51-
nrfx_dppi_t dppi = NRFX_DPPI_INSTANCE(0);
52-
5345
if (*PUBLISH_ADDR(evt) != 0) {
5446
if (!IS_ENABLED(CONFIG_NRF_CPU_LOAD_USE_SHARED_DPPI_CHANNELS)) {
5547
return NRFX_ERROR_BUSY;
@@ -59,31 +51,23 @@ static nrfx_err_t ppi_alloc(uint8_t *ch, uint32_t evt)
5951
* channel id.
6052
*/
6153
*ch = *PUBLISH_ADDR(evt) & DPPIC_SUBSCRIBE_CHG_EN_CHIDX_Msk;
62-
err = NRFX_SUCCESS;
6354
shared_ch_mask |= BIT(*ch);
64-
} else {
65-
err = nrfx_dppi_channel_alloc(&dppi, ch);
55+
return NRFX_SUCCESS;
6656
}
67-
#else
68-
err = nrfx_ppi_channel_alloc((nrf_ppi_channel_t *)ch);
6957
#endif
70-
return err;
58+
return nrfx_gppi_channel_alloc(ch);
7159
}
7260

7361
static nrfx_err_t ppi_free(uint8_t ch)
7462
{
7563
#ifdef DPPI_PRESENT
76-
nrfx_dppi_t dppi = NRFX_DPPI_INSTANCE(0);
77-
78-
if (!IS_ENABLED(CONFIG_NRF_CPU_LOAD_USE_SHARED_DPPI_CHANNELS)
79-
|| ((BIT(ch) & shared_ch_mask) == 0)) {
80-
return nrfx_dppi_channel_free(&dppi, ch);
81-
} else {
64+
if (IS_ENABLED(CONFIG_NRF_CPU_LOAD_USE_SHARED_DPPI_CHANNELS)
65+
&& ((BIT(ch) & shared_ch_mask) == 0)) {
66+
shared_ch_mask &= ~BIT(ch);
8267
return NRFX_SUCCESS;
8368
}
84-
#else
85-
return nrfx_ppi_channel_free((nrf_ppi_channel_t)ch);
8669
#endif
70+
return nrfx_gppi_channel_free(ch);
8771
}
8872

8973
static void ppi_cleanup(uint8_t ch_tick, uint8_t ch_sleep, uint8_t ch_wakeup)

0 commit comments

Comments
 (0)