1 /*
2 * Copyright (c) 2023 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_egu.h"
9 #include "bs_tracing.h"
10 #include "NHW_EGU.h"
11
egu_number_from_ptr(NRF_EGU_Type const * p_reg)12 static int egu_number_from_ptr(NRF_EGU_Type const * p_reg){
13 int i = ( (int)p_reg - (int)&NRF_EGU_regs[0] ) / sizeof(NRF_EGU_Type);
14 return i;
15 }
16
nrf_egu_task_trigger(NRF_EGU_Type * p_reg,nrf_egu_task_t egu_task)17 void nrf_egu_task_trigger(NRF_EGU_Type * p_reg, nrf_egu_task_t egu_task)
18 {
19 *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)egu_task)) = 0x1UL;
20
21 int i = egu_number_from_ptr(p_reg);
22 int task_nbr = (egu_task - NRF_EGU_TASK_TRIGGER0)/sizeof(uint32_t);
23 nhw_egu_regw_sideeffects_TASK_TRIGGER(i, task_nbr);
24 }
25
26
nrf_egu_event_clear(NRF_EGU_Type * p_reg,nrf_egu_event_t egu_event)27 void nrf_egu_event_clear(NRF_EGU_Type * p_reg, nrf_egu_event_t egu_event)
28 {
29 *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)egu_event)) = 0x0UL;
30
31 int i = egu_number_from_ptr(p_reg);
32 int event_nbr = (egu_event - NRF_EGU_EVENT_TRIGGERED0)/sizeof(uint32_t);
33 nhw_egu_regw_sideeffect_EVENTS_TRIGGERED(i, event_nbr);
34 }
35
36
nrf_egu_int_enable(NRF_EGU_Type * p_reg,uint32_t mask)37 void nrf_egu_int_enable(NRF_EGU_Type * p_reg, uint32_t mask)
38 {
39 p_reg->INTENSET = mask;
40
41 int i = egu_number_from_ptr(p_reg);
42 nhw_egu_regw_sideeffect_INTENSET(i);
43 }
44
nrf_egu_int_disable(NRF_EGU_Type * p_reg,uint32_t mask)45 void nrf_egu_int_disable(NRF_EGU_Type * p_reg, uint32_t mask)
46 {
47 p_reg->INTENCLR = mask;
48
49 int i = egu_number_from_ptr(p_reg);
50 nhw_egu_regw_sideeffect_INTENCLR(i);
51 }
52
53 #if defined(DPPI_PRESENT)
nrf_egu_subscribe_set(NRF_EGU_Type * p_reg,nrf_egu_task_t task,uint8_t channel)54 void nrf_egu_subscribe_set(NRF_EGU_Type * p_reg,
55 nrf_egu_task_t task,
56 uint8_t channel)
57 {
58 NRFX_ASSERT(p_reg);
59 *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) =
60 ((uint32_t)channel | NRF_SUBSCRIBE_PUBLISH_ENABLE);
61
62 int i = egu_number_from_ptr(p_reg);
63 int task_nbr = (task - NRF_EGU_TASK_TRIGGER0)/sizeof(uint32_t);
64
65 nhw_egu_regw_sideeffects_SUBSCRIBE_TRIGGER(i, task_nbr);
66 }
67
nrf_egu_subscribe_clear(NRF_EGU_Type * p_reg,nrf_egu_task_t task)68 void nrf_egu_subscribe_clear(NRF_EGU_Type * p_reg,
69 nrf_egu_task_t task)
70 {
71 NRFX_ASSERT(p_reg);
72 *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0;
73
74 int i = egu_number_from_ptr(p_reg);
75 int task_nbr = (task - NRF_EGU_TASK_TRIGGER0)/sizeof(uint32_t);
76
77 nhw_egu_regw_sideeffects_SUBSCRIBE_TRIGGER(i, task_nbr);
78 }
79 #endif // defined(DPPI_PRESENT)
80