1 /*
2  * Copyright (c) 2020 Oticon A/S
3  * Copyright (c) 2020-2023 Nordic Semiconductor ASA
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  *
7  * Note that the function prototypes are taken from the NRFx HAL
8  */
9 #include "hal/nrf_aar.h"
10 #include "bs_tracing.h"
11 #include "NHW_AAR.h"
12 
nrf_aar_int_enable(NRF_AAR_Type * p_reg,uint32_t mask)13 void nrf_aar_int_enable(NRF_AAR_Type * p_reg, uint32_t mask)
14 {
15   p_reg->INTENSET = mask;
16   nhw_AAR_regw_sideeffects_INTENSET();
17 }
18 
nrf_aar_int_disable(NRF_AAR_Type * p_reg,uint32_t mask)19 void nrf_aar_int_disable(NRF_AAR_Type * p_reg, uint32_t mask)
20 {
21   p_reg->INTENCLR = mask;
22   nhw_AAR_regw_sideeffects_INTENCLR();
23 }
24 
nrf_aar_task_trigger(NRF_AAR_Type * p_reg,nrf_aar_task_t task)25 void nrf_aar_task_trigger(NRF_AAR_Type * p_reg, nrf_aar_task_t task)
26 {
27   *(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task) = 1;
28   if (task == NRF_AAR_TASK_START) {
29     nhw_AAR_regw_sideeffects_TASKS_START();
30   } else if (task == NRF_AAR_TASK_STOP) {
31     nhw_AAR_regw_sideeffects_TASKS_STOP();
32   }  else {
33     bs_trace_error_line_time("Not supported task started in nrf_aar\n");
34   }
35 }
36 
nrf_aar_event_clear(NRF_AAR_Type * p_reg,nrf_aar_event_t event)37 void nrf_aar_event_clear(NRF_AAR_Type * p_reg, nrf_aar_event_t event)
38 {
39   *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)) = 0x0UL;
40   nhw_AAR_regw_sideeffects_EVENTS_all(0);
41 }
42 
43 #if defined(DPPI_PRESENT)
44 
nrf_aar_subscribe_common(NRF_AAR_Type * p_reg,nrf_aar_task_t task)45 static void nrf_aar_subscribe_common(NRF_AAR_Type * p_reg,
46                                      nrf_aar_task_t task)
47 {
48   if (task == NRF_AAR_TASK_START) {
49       nhw_AAR_regw_sideeffects_SUBSCRIBE_START(0);
50   } else if ( task == NRF_AAR_TASK_STOP ) {
51       nhw_AAR_regw_sideeffects_SUBSCRIBE_STOP(0);
52   } else {
53       bs_trace_error_line_time("Attempted to subscribe to an not-supported task in the nrf_aar (%i)\n",
54                                task);
55   }
56 }
57 
nrf_aar_subscribe_set(NRF_AAR_Type * p_reg,nrf_aar_task_t task,uint8_t channel)58 void nrf_aar_subscribe_set(NRF_AAR_Type * p_reg,
59                            nrf_aar_task_t task,
60                            uint8_t        channel)
61 {
62     *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) =
63             ((uint32_t)channel | NRF_SUBSCRIBE_PUBLISH_ENABLE);
64     nrf_aar_subscribe_common(p_reg, task);
65 }
66 
nrf_aar_subscribe_clear(NRF_AAR_Type * p_reg,nrf_aar_task_t task)67 void nrf_aar_subscribe_clear(NRF_AAR_Type * p_reg,
68                              nrf_aar_task_t task)
69 {
70     *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0;
71     nrf_aar_subscribe_common(p_reg, task);
72 }
73 
74 #endif /* defined(DPPI_PRESENT) */
75