1 /*
2 * Copyright (c) 2017 Oticon A/S
3 * Copyright (c) 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_ccm.h"
10 #include "bs_tracing.h"
11 #include "NHW_AES_CCM.h"
12
nrf_ccm_task_trigger(NRF_CCM_Type * p_reg,nrf_ccm_task_t task)13 void nrf_ccm_task_trigger(NRF_CCM_Type * p_reg, nrf_ccm_task_t task)
14 {
15 *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task)) = 0x1UL;
16
17 if ( task == NRF_CCM_TASK_KSGEN ) {
18 nhw_CCM_regw_sideeffects_TASKS_KSGEN();
19 } else if ( task == offsetof(NRF_CCM_Type, TASKS_CRYPT) ) {
20 nhw_CCM_regw_sideeffects_TASKS_CRYPT();
21 } else if ( task == NRF_CCM_TASK_STOP ) {
22 nhw_CCM_regw_sideeffects_TASKS_STOP();
23 } else {
24 bs_trace_error_line_time("Not supported task started in nrf_ccm\n");
25 }
26 }
27
nrf_ccm_int_enable(NRF_CCM_Type * p_reg,uint32_t mask)28 void nrf_ccm_int_enable(NRF_CCM_Type * p_reg, uint32_t mask)
29 {
30 p_reg->INTENSET = mask;
31 nhw_CCM_regw_sideeffects_INTENSET();
32 }
33
nrf_ccm_int_disable(NRF_CCM_Type * p_reg,uint32_t mask)34 void nrf_ccm_int_disable(NRF_CCM_Type * p_reg, uint32_t mask)
35 {
36 p_reg->INTENCLR = mask;
37 nhw_CCM_regw_sideeffects_INTENCLR();
38 }
39
nrf_ccm_event_clear(NRF_CCM_Type * p_reg,nrf_ccm_event_t event)40 void nrf_ccm_event_clear(NRF_CCM_Type * p_reg, nrf_ccm_event_t event)
41 {
42 *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)) = 0x0UL;
43 nhw_CCM_regw_sideeffects_EVENTS_all(0);
44 }
45
46 #if defined(DPPI_PRESENT)
47
nrf_ccm_subscribe_common(NRF_CCM_Type * p_reg,nrf_ccm_task_t task)48 static void nrf_ccm_subscribe_common(NRF_CCM_Type * p_reg,
49 nrf_ccm_task_t task)
50 {
51 (void) p_reg;
52 if (task == NRF_CCM_TASK_KSGEN) {
53 nhw_CCM_regw_sideeffects_SUBSCRIBE_KSGEN(0);
54 } else if ( task == offsetof(NRF_CCM_Type, TASKS_CRYPT) ) {
55 nhw_CCM_regw_sideeffects_SUBSCRIBE_CRYPT(0);
56 } else if ( task == NRF_CCM_TASK_STOP ) {
57 nhw_CCM_regw_sideeffects_SUBSCRIBE_STOP(0);
58 } else if ( task == NRF_CCM_TASK_RATEOVERRIDE ) {
59 nhw_CCM_regw_sideeffects_SUBSCRIBE_RATEOVERRIDE(0);
60 } else {
61 bs_trace_error_line_time("Attempted to subscribe to an not-supported task in the nrf_ccm (%i)\n",
62 task);
63 }
64 }
65
nrf_ccm_subscribe_set(NRF_CCM_Type * p_reg,nrf_ccm_task_t task,uint8_t channel)66 void nrf_ccm_subscribe_set(NRF_CCM_Type * p_reg,
67 nrf_ccm_task_t task,
68 uint8_t channel)
69 {
70 *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) =
71 ((uint32_t)channel | NRF_SUBSCRIBE_PUBLISH_ENABLE);
72 nrf_ccm_subscribe_common(p_reg, task);
73 }
74
nrf_ccm_subscribe_clear(NRF_CCM_Type * p_reg,nrf_ccm_task_t task)75 void nrf_ccm_subscribe_clear(NRF_CCM_Type * p_reg,
76 nrf_ccm_task_t task)
77 {
78 *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0;
79 nrf_ccm_subscribe_common(p_reg, task);
80 }
81
82 #endif /* defined(DPPI_PRESENT) */
83