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_temp.h"
9 #include "bs_tracing.h"
10 #include "NHW_TEMP.h"
11 
nrf_temp_task_trigger(NRF_TEMP_Type * p_reg,nrf_temp_task_t temp_task)12 void nrf_temp_task_trigger(NRF_TEMP_Type * p_reg, nrf_temp_task_t temp_task)
13 {
14   *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)temp_task)) = 0x1UL;
15 
16   if ( temp_task == NRF_TEMP_TASK_START ) {
17     nhw_TEMP_regw_sideeffects_TASKS_START();
18   } else if ( temp_task == NRF_TEMP_TASK_STOP ) {
19     nhw_TEMP_regw_sideeffects_TASKS_STOP();
20   } else {
21     bs_trace_error_line_time("Not supported task started in %s\n", __func__);
22   }
23 }
24 
nrf_temp_int_enable(NRF_TEMP_Type * p_reg,uint32_t mask)25 void nrf_temp_int_enable(NRF_TEMP_Type * p_reg, uint32_t mask)
26 {
27   (void) p_reg;
28   NRF_TEMP_regs.INTENSET = mask;
29   nhw_TEMP_regw_sideeffects_INTENSET();
30 }
31 
nrf_temp_int_disable(NRF_TEMP_Type * p_reg,uint32_t mask)32 void nrf_temp_int_disable(NRF_TEMP_Type * p_reg, uint32_t mask)
33 {
34   (void) p_reg;
35   NRF_TEMP_regs.INTENCLR = mask;
36   nhw_TEMP_regw_sideeffects_INTENCLR();
37 }
38 
nrf_temp_event_clear(NRF_TEMP_Type * p_reg,nrf_temp_event_t event)39 void nrf_temp_event_clear(NRF_TEMP_Type * p_reg, nrf_temp_event_t event)
40 {
41   *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)) = 0x0UL;
42   nhw_TEMP_regw_sideeffects_EVENTS_all(0);
43 }
44 
45 #if defined(DPPI_PRESENT)
46 
nrf_temp_subscribe_common(NRF_TEMP_Type * p_reg,nrf_temp_task_t task)47 static void nrf_temp_subscribe_common(NRF_TEMP_Type * p_reg,
48                                      nrf_temp_task_t task)
49 {
50   (void) p_reg;
51   if (task == NRF_TEMP_TASK_START) {
52       nhw_TEMP_regw_sideeffects_SUBSCRIBE_START(0);
53   } else if ( task == NRF_TEMP_TASK_STOP ) {
54       nhw_TEMP_regw_sideeffects_SUBSCRIBE_STOP(0);
55   } else {
56       bs_trace_error_line_time("Attempted to subscribe to an not-supported task in the nrf_temp (%i)\n",
57                                task);
58   }
59 }
60 
nrf_temp_subscribe_set(NRF_TEMP_Type * p_reg,nrf_temp_task_t task,uint8_t channel)61 void nrf_temp_subscribe_set(NRF_TEMP_Type * p_reg,
62                            nrf_temp_task_t task,
63                            uint8_t        channel)
64 {
65     *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) =
66             ((uint32_t)channel | NRF_SUBSCRIBE_PUBLISH_ENABLE);
67     nrf_temp_subscribe_common(p_reg, task);
68 }
69 
nrf_temp_subscribe_clear(NRF_TEMP_Type * p_reg,nrf_temp_task_t task)70 void nrf_temp_subscribe_clear(NRF_TEMP_Type * p_reg,
71                              nrf_temp_task_t task)
72 {
73     *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0;
74     nrf_temp_subscribe_common(p_reg, task);
75 }
76 
77 #endif /* defined(DPPI_PRESENT) */
78