1111#endif
1212#include <haly/nrfy_rtc.h>
1313#include <zephyr/sys/atomic.h>
14- #ifdef DPPI_PRESENT
15- #include <nrfx_dppi.h>
16- #else
17- #include <nrfx_ppi.h>
18- #endif
14+ #include <helpers/nrfx_gppi.h>
1915
2016#define LOG_MODULE_NAME counter_rtc
2117#include <zephyr/logging/log.h>
@@ -58,7 +54,7 @@ struct counter_nrfx_data {
5854 /* Store channel interrupt pending and CC adjusted flags. */
5955 atomic_t ipend_adj ;
6056#if CONFIG_COUNTER_RTC_WITH_PPI_WRAP
61- uint8_t ppi_ch ;
57+ nrfx_gppi_handle_t ppi_handle ;
6258#endif
6359};
6460
@@ -379,41 +375,21 @@ static int ppi_setup(const struct device *dev, uint8_t chan)
379375 struct counter_nrfx_data * data = dev -> data ;
380376 NRF_RTC_Type * rtc = nrfx_config -> rtc ;
381377 nrf_rtc_event_t evt = NRF_RTC_CHANNEL_EVENT_ADDR (chan );
382- nrfx_err_t result ;
378+ uint32_t eep = nrf_rtc_event_address_get (rtc , evt );
379+ uint32_t tep = nrfy_rtc_task_address_get (rtc , NRF_RTC_TASK_CLEAR );
380+ int err ;
383381
384382 if (!nrfx_config -> use_ppi ) {
385383 return 0 ;
386384 }
387385
388386 nrfy_rtc_event_enable (rtc , NRF_RTC_CHANNEL_INT_MASK (chan ));
389- #ifdef DPPI_PRESENT
390- nrfx_dppi_t dppi = NRFX_DPPI_INSTANCE (0 );
391-
392- result = nrfx_dppi_channel_alloc (& dppi , & data -> ppi_ch );
393- if (result != NRFX_SUCCESS ) {
394- ERR ("Failed to allocate PPI channel." );
395- return - ENODEV ;
387+ err = nrfx_gppi_conn_alloc (eep , tep , & data -> ppi_handle );
388+ if (err < 0 ) {
389+ return err ;
396390 }
397-
398- nrfy_rtc_subscribe_set (rtc , NRF_RTC_TASK_CLEAR , data -> ppi_ch );
399- nrfy_rtc_publish_set (rtc , evt , data -> ppi_ch );
400- (void )nrfx_dppi_channel_enable (& dppi , data -> ppi_ch );
401- #else /* DPPI_PRESENT */
402- uint32_t evt_addr ;
403- uint32_t task_addr ;
404-
405- evt_addr = nrfy_rtc_event_address_get (rtc , evt );
406- task_addr = nrfy_rtc_task_address_get (rtc , NRF_RTC_TASK_CLEAR );
407-
408- result = nrfx_ppi_channel_alloc (& data -> ppi_ch );
409- if (result != NRFX_SUCCESS ) {
410- ERR ("Failed to allocate PPI channel." );
411- return - ENODEV ;
412- }
413- (void )nrfx_ppi_channel_assign (data -> ppi_ch , evt_addr , task_addr );
414- (void )nrfx_ppi_channel_enable (data -> ppi_ch );
391+ nrfx_gppi_conn_enable (data -> ppi_handle );
415392#endif
416- #endif /* CONFIG_COUNTER_RTC_WITH_PPI_WRAP */
417393 return 0 ;
418394}
419395
@@ -422,25 +398,17 @@ static void ppi_free(const struct device *dev, uint8_t chan)
422398#if CONFIG_COUNTER_RTC_WITH_PPI_WRAP
423399 const struct counter_nrfx_config * nrfx_config = dev -> config ;
424400 struct counter_nrfx_data * data = dev -> data ;
425- uint8_t ppi_ch = data -> ppi_ch ;
426401 NRF_RTC_Type * rtc = nrfx_config -> rtc ;
402+ nrf_rtc_event_t evt = NRF_RTC_CHANNEL_EVENT_ADDR (chan );
403+ uint32_t eep = nrf_rtc_event_address_get (rtc , evt );
404+ uint32_t tep = nrfy_rtc_task_address_get (rtc , NRF_RTC_TASK_CLEAR );
427405
428406 if (!nrfx_config -> use_ppi ) {
429407 return ;
430408 }
431409 nrfy_rtc_event_disable (rtc , NRF_RTC_CHANNEL_INT_MASK (chan ));
432- #ifdef DPPI_PRESENT
433- nrf_rtc_event_t evt = NRF_RTC_CHANNEL_EVENT_ADDR (chan );
434- nrfx_dppi_t dppi = NRFX_DPPI_INSTANCE (0 );
435-
436- (void )nrfx_dppi_channel_disable (& dppi , ppi_ch );
437- nrfy_rtc_subscribe_clear (rtc , NRF_RTC_TASK_CLEAR );
438- nrfy_rtc_publish_clear (rtc , evt );
439- (void )nrfx_dppi_channel_free (& dppi , ppi_ch );
440- #else /* DPPI_PRESENT */
441- (void )nrfx_ppi_channel_disable (ppi_ch );
442- (void )nrfx_ppi_channel_free (ppi_ch );
443- #endif
410+ nrfx_gppi_conn_disable (data -> ppi_handle );
411+ nrfx_gppi_conn_free (eep , tep , data -> ppi_handle );
444412#endif
445413}
446414
0 commit comments