1 /*
2  * Copyright (c) 2017 Oticon A/S
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_AES_ECB.h"
11 
nrf_ecb_task_trigger(NRF_ECB_Type * p_reg,nrf_ecb_task_t task)12 void nrf_ecb_task_trigger(NRF_ECB_Type * p_reg, nrf_ecb_task_t task)
13 {
14   *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task)) = 0x1UL;
15 
16   if ( task == NRF_ECB_TASK_STARTECB ) {
17     nhw_ECB_regw_sideeffects_TASKS_STARTECB();
18   } else if ( task == NRF_ECB_TASK_STOPECB ) {
19     nhw_ECB_regw_sideeffects_TASKS_STOPECB();
20   } else {
21     bs_trace_error_line_time("Not supported task started in nrf_ecb\n");
22   }
23 }
24 
nrf_ecb_int_enable(NRF_ECB_Type * p_reg,uint32_t mask)25 void nrf_ecb_int_enable(NRF_ECB_Type * p_reg, uint32_t mask)
26 {
27   p_reg->INTENSET = mask;
28   nhw_ECB_regw_sideeffects_INTENSET();
29 }
30 
nrf_ecb_int_disable(NRF_ECB_Type * p_reg,uint32_t mask)31 void nrf_ecb_int_disable(NRF_ECB_Type * p_reg, uint32_t mask)
32 {
33   p_reg->INTENCLR = mask;
34   nhw_ECB_regw_sideeffects_INTENCLR();
35 }
36 
nrf_ecb_event_clear(NRF_ECB_Type * p_reg,nrf_ecb_event_t event)37 void nrf_ecb_event_clear(NRF_ECB_Type * p_reg, nrf_ecb_event_t event)
38 {
39   *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)) = 0x0UL;
40   nhw_ECB_regw_sideeffects_EVENTS_all(0);
41 }
42 
43 #if defined(DPPI_PRESENT)
44 
nrf_ecb_subscribe_common(NRF_ECB_Type * p_reg,nrf_ecb_task_t task)45 static void nrf_ecb_subscribe_common(NRF_ECB_Type * p_reg,
46                                      nrf_ecb_task_t task)
47 {
48   (void) p_reg;
49   if (task == NRF_ECB_TASK_STARTECB) {
50       nhw_ECB_regw_sideeffects_SUBSCRIBE_STARTECB(0);
51   } else if ( task == NRF_ECB_TASK_STOPECB ) {
52       nhw_ECB_regw_sideeffects_SUBSCRIBE_STOPECB(0);
53   } else {
54       bs_trace_error_line_time("Attempted to subscribe to an not-supported task in the nrf_ecb (%i)\n",
55                                task);
56   }
57 }
58 
nrf_ecb_subscribe_set(NRF_ECB_Type * p_reg,nrf_ecb_task_t task,uint8_t channel)59 void nrf_ecb_subscribe_set(NRF_ECB_Type * p_reg,
60                            nrf_ecb_task_t task,
61                            uint8_t        channel)
62 {
63     *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) =
64             ((uint32_t)channel | NRF_SUBSCRIBE_PUBLISH_ENABLE);
65     nrf_ecb_subscribe_common(p_reg, task);
66 }
67 
nrf_ecb_subscribe_clear(NRF_ECB_Type * p_reg,nrf_ecb_task_t task)68 void nrf_ecb_subscribe_clear(NRF_ECB_Type * p_reg,
69                              nrf_ecb_task_t task)
70 {
71     *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0;
72     nrf_ecb_subscribe_common(p_reg, task);
73 }
74 
75 #endif /* defined(DPPI_PRESENT) */
76