1 /*
2  * Copyright (c) 2024, Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Note that the function prototypes are taken from the NRFx HAL
7  */
8 #include "hal/nrf_ppib.h"
9 #include "NHW_PPIB.h"
10 #include "bs_tracing.h"
11 
ppib_number_from_ptr(NRF_PPIB_Type const * p_reg)12 static int ppib_number_from_ptr(NRF_PPIB_Type const * p_reg){
13   int i = ( (int)p_reg - (int)&NRF_PPIB_regs[0] ) / sizeof(NRF_PPIB_Type);
14   return i;
15 }
16 
17 /* Note: The PPIB task and events registers are not functional,
18  * and therefore have no HAL API */
19 
nrf_ppib_subscribe_set(NRF_PPIB_Type * p_reg,nrf_ppib_task_t task,uint8_t channel)20 void nrf_ppib_subscribe_set(NRF_PPIB_Type * p_reg,
21                             nrf_ppib_task_t task,
22                             uint8_t        channel)
23 {
24   NRFX_ASSERT(p_reg);
25   *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) =
26           ((uint32_t)channel | NRF_SUBSCRIBE_PUBLISH_ENABLE);
27 
28   int i = ppib_number_from_ptr(p_reg);
29   int task_nbr = (task - NRF_PPIB_TASK_SEND_0)/sizeof(uint32_t);
30 
31   nhw_PPIB_regw_sideeffects_SUBSCRIBE_SEND(i, task_nbr);
32 }
33 
nrf_ppib_subscribe_clear(NRF_PPIB_Type * p_reg,nrf_ppib_task_t task)34 void nrf_ppib_subscribe_clear(NRF_PPIB_Type * p_reg,
35                               nrf_ppib_task_t task)
36 {
37   NRFX_ASSERT(p_reg);
38   *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0;
39 
40   int i = ppib_number_from_ptr(p_reg);
41   int task_nbr = (task - NRF_PPIB_TASK_SEND_0)/sizeof(uint32_t);
42 
43   nhw_PPIB_regw_sideeffects_SUBSCRIBE_SEND(i, task_nbr);
44 }
45