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_ecb.h"
9 #include "bs_tracing.h"
10 #include "NHW_54_AAR_CCM_ECB.h"
11
ecb_inst_from_ptr(NRF_ECB_Type * p_reg)12 static int ecb_inst_from_ptr(NRF_ECB_Type * p_reg)
13 {
14 int i = ( (int)p_reg - (int)NRF_ECB_regs ) / sizeof(NRF_ECB_Type);
15 return i;
16 }
17
nrf_ecb_task_trigger(NRF_ECB_Type * p_reg,nrf_ecb_task_t task)18 void nrf_ecb_task_trigger(NRF_ECB_Type * p_reg, nrf_ecb_task_t task)
19 {
20 int inst = ecb_inst_from_ptr(p_reg);
21
22 *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task)) = 0x1UL;
23
24 if (task == NRF_ECB_TASK_START) {
25 nhw_ECB_regw_sideeffects_TASKS_START(inst);
26 } else if (task == NRF_ECB_TASK_STOP) {
27 nhw_ECB_regw_sideeffects_TASKS_STOP(inst);
28 } else {
29 bs_trace_error_line_time("Not supported task started in nrf_ecb\n");
30 }
31 }
32
nrf_ecb_int_enable(NRF_ECB_Type * p_reg,uint32_t mask)33 void nrf_ecb_int_enable(NRF_ECB_Type * p_reg, uint32_t mask)
34 {
35 int inst = ecb_inst_from_ptr(p_reg);
36 p_reg->INTENSET = mask;
37 nhw_ECB_regw_sideeffects_INTENSET(inst);
38 }
39
nrf_ecb_int_disable(NRF_ECB_Type * p_reg,uint32_t mask)40 void nrf_ecb_int_disable(NRF_ECB_Type * p_reg, uint32_t mask)
41 {
42 int inst = ecb_inst_from_ptr(p_reg);
43 p_reg->INTENCLR = mask;
44 nhw_ECB_regw_sideeffects_INTENCLR(inst);
45 }
46
nrf_ecb_event_clear(NRF_ECB_Type * p_reg,nrf_ecb_event_t event)47 void nrf_ecb_event_clear(NRF_ECB_Type * p_reg, nrf_ecb_event_t event)
48 {
49 int inst = ecb_inst_from_ptr(p_reg);
50 *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)) = 0x0UL;
51 nhw_ECB_regw_sideeffects_EVENTS_all(inst);
52 }
53
nrf_ecb_subscribe_common(NRF_ECB_Type * p_reg,nrf_ecb_task_t task)54 static void nrf_ecb_subscribe_common(NRF_ECB_Type * p_reg,
55 nrf_ecb_task_t task)
56 {
57 int inst = ecb_inst_from_ptr(p_reg);
58
59 if (task == NRF_ECB_TASK_START) {
60 nhw_ECB_regw_sideeffects_SUBSCRIBE_START(inst);
61 } else if (task == NRF_ECB_TASK_STOP) {
62 nhw_ECB_regw_sideeffects_SUBSCRIBE_STOP(inst);
63 } else {
64 bs_trace_error_line_time("Attempted to subscribe to a not-supported task in the nrf_ecb (%i)\n",
65 task);
66 }
67 }
68
nrf_ecb_subscribe_set(NRF_ECB_Type * p_reg,nrf_ecb_task_t task,uint8_t channel)69 void nrf_ecb_subscribe_set(NRF_ECB_Type * p_reg,
70 nrf_ecb_task_t task,
71 uint8_t channel)
72 {
73 *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) =
74 ((uint32_t)channel | NRF_SUBSCRIBE_PUBLISH_ENABLE);
75 nrf_ecb_subscribe_common(p_reg, task);
76 }
77
nrf_ecb_subscribe_clear(NRF_ECB_Type * p_reg,nrf_ecb_task_t task)78 void nrf_ecb_subscribe_clear(NRF_ECB_Type * p_reg,
79 nrf_ecb_task_t task)
80 {
81 *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0;
82 nrf_ecb_subscribe_common(p_reg, task);
83 }
84