Skip to content
This repository was archived by the owner on Oct 23, 2025. It is now read-only.

Commit d6ecc00

Browse files
auroraslbwopu-ot
authored andcommitted
Added APIs for AAR
Signed-off-by: Sletnes Bjørlo, Aurora <[email protected]>
1 parent b8fbafd commit d6ecc00

File tree

3 files changed

+262
-0
lines changed

3 files changed

+262
-0
lines changed

src/HW_models/NRF_AAR.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ void nrf_aar_clean_up();
1919

2020
void nrf_aar_TASK_START();
2121
void nrf_aar_TASK_STOP() ;
22+
void nrf_aar_regw_sideeffects_INTENCLR();
23+
void nrf_aar_regw_sideeffects_TASKS_START();
24+
void nrf_aar_regw_sideeffects_TASKS_STOP();
2225

2326
void nrf_aar_timer_triggered();
2427

src/nrfx/hal/nrf_aar.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "nrf_aar.h"
2+
#include "bs_tracing.h"
3+
#include "NRF_AAR.h"
4+
5+
void nrf_aar_int_disable(NRF_AAR_Type * p_reg, uint32_t mask)
6+
{
7+
p_reg->INTENCLR = mask;
8+
nrf_aar_regw_sideeffects_INTENCLR();
9+
}
10+
11+
void nrf_aar_task_trigger(NRF_AAR_Type * p_reg, nrf_aar_task_t task)
12+
{
13+
if (task == NRF_AAR_TASK_START) {
14+
p_reg->TASKS_START = 1;
15+
nrf_aar_regw_sideeffects_TASKS_START();
16+
} else if (task == NRF_AAR_TASK_STOP) {
17+
p_reg->TASKS_STOP = 1;
18+
nrf_aar_regw_sideeffects_TASKS_STOP();
19+
} else {
20+
bs_trace_error_line_time("Not supported task started in nrf_aar\n");
21+
}
22+
}

src/nrfx/hal/nrf_aar.h

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
/**
2+
* Part of the real nrf_aar.h from Nordic's NRFx HAL
3+
*
4+
* Note that there is a few changes compared to the original
5+
* Where relevant, these changes are:
6+
* Copyright (c) 2020 Nordic Semiconductor ASA
7+
* SPDX-License-Identifier: BSD-3-Clause
8+
*/
9+
10+
/*
11+
* Copyright (c) 2019 - 2020, Nordic Semiconductor ASA
12+
* All rights reserved.
13+
*
14+
* Redistribution and use in source and binary forms, with or without
15+
* modification, are permitted provided that the following conditions are met:
16+
*
17+
* 1. Redistributions of source code must retain the above copyright notice, this
18+
* list of conditions and the following disclaimer.
19+
*
20+
* 2. Redistributions in binary form must reproduce the above copyright
21+
* notice, this list of conditions and the following disclaimer in the
22+
* documentation and/or other materials provided with the distribution.
23+
*
24+
* 3. Neither the name of the copyright holder nor the names of its
25+
* contributors may be used to endorse or promote products derived from this
26+
* software without specific prior written permission.
27+
*
28+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
32+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38+
* POSSIBILITY OF SUCH DAMAGE.
39+
*/
40+
41+
#ifndef BS_NRF_AAR_H__
42+
#define BS_NRF_AAR_H__
43+
44+
#include "nrf_soc_if.h"
45+
#include "../drivers/nrfx_common.h"
46+
47+
#ifdef __cplusplus
48+
extern "C" {
49+
#endif
50+
51+
/** @brief AAR events. */
52+
typedef enum
53+
{
54+
NRF_AAR_EVENT_END = offsetof(NRF_AAR_Type, EVENTS_END), ///< Address resolution procedure complete.
55+
NRF_AAR_EVENT_RESOLVED = offsetof(NRF_AAR_Type, EVENTS_RESOLVED), ///< Address resolved.
56+
NRF_AAR_EVENT_NOTRESOLVED = offsetof(NRF_AAR_Type, EVENTS_NOTRESOLVED), ///< Address not resolved.
57+
} nrf_aar_event_t;
58+
59+
/** @brief AAR tasks. */
60+
typedef enum
61+
{
62+
NRF_AAR_TASK_START = offsetof(NRF_AAR_Type, TASKS_START), ///< Start address resolution procedure.
63+
NRF_AAR_TASK_STOP = offsetof(NRF_AAR_Type, TASKS_STOP), ///< Stop address resolution procedure.
64+
} nrf_aar_task_t;
65+
66+
/**
67+
* @brief Function for retrieving the state of the AAR event.
68+
*
69+
* @param[in] p_reg Pointer to the structure of registers of the peripheral.
70+
* @param[in] event Event to be checked.
71+
*
72+
* @retval true Event is set.
73+
* @retval false Event is not set.
74+
*/
75+
NRF_STATIC_INLINE bool nrf_aar_event_check(NRF_AAR_Type const * p_reg,
76+
nrf_aar_event_t event);
77+
78+
/**
79+
* @brief Function for clearing the specified AAR event.
80+
*
81+
* @param[in] p_reg Pointer to the structure of registers of the peripheral.
82+
* @param[in] event Event to be cleared.
83+
*/
84+
NRF_STATIC_INLINE void nrf_aar_event_clear(NRF_AAR_Type * p_reg,
85+
nrf_aar_event_t event);
86+
87+
/**
88+
* @brief Function for disabling the specified interrupts.
89+
*
90+
* @param[in] p_reg Pointer to the structure of registers of the peripheral.
91+
* @param[in] mask Mask of interrupts to be disabled.
92+
*/
93+
void nrf_aar_int_disable(NRF_AAR_Type * p_reg, uint32_t mask);
94+
95+
/**
96+
* @brief Function for starting an AAR task.
97+
*
98+
* @param[in] p_reg Pointer to the structure of registers of the peripheral.
99+
* @param[in] task Task to be activated.
100+
*/
101+
void nrf_aar_task_trigger(NRF_AAR_Type * p_reg, nrf_aar_task_t task);
102+
103+
/**
104+
* @brief Function for enabling AAR.
105+
*
106+
* @param[in] p_reg Pointer to the structure of registers of the peripheral.
107+
*/
108+
NRF_STATIC_INLINE void nrf_aar_enable(NRF_AAR_Type * p_reg);
109+
110+
/**
111+
* @brief Function for disabling AAR.
112+
*
113+
* @param[in] p_reg Pointer to the structure of registers of the peripheral.
114+
*/
115+
NRF_STATIC_INLINE void nrf_aar_disable(NRF_AAR_Type * p_reg);
116+
117+
/**
118+
* @brief Function for setting the pointer to the Identity Resolving Keys (IRK) data structure.
119+
*
120+
* The size of the provided data structure must correspond to the number of keys available.
121+
* Each key occupies 16 bytes.
122+
*
123+
* @param[in] p_reg Pointer to the structure of registers of the peripheral.
124+
* @param[in] irk_ptr Pointer to the IRK data structure. Must point to the Data RAM region.
125+
*
126+
* @sa nrf_aar_irk_number_set
127+
*/
128+
NRF_STATIC_INLINE void nrf_aar_irk_pointer_set(NRF_AAR_Type * p_reg, uint8_t const * irk_ptr);
129+
130+
/**
131+
* @brief Function for setting the number of keys available in the Identity Resolving Keys
132+
* data structure.
133+
*
134+
* @param[in] p_reg Pointer to the structure of registers of the peripheral.
135+
* @param[in] irk_num Number of keys available in the IRK data structure. Maximum is 16.
136+
* Must correspond to the size of the provided IRK data structure.
137+
*
138+
* @sa nrf_aar_irk_pointer_set
139+
*/
140+
NRF_STATIC_INLINE void nrf_aar_irk_number_set(NRF_AAR_Type * p_reg, uint8_t irk_num);
141+
142+
/**
143+
* @brief Function for setting the pointer to the resolvable address.
144+
*
145+
* The resolvable address must consist of 6 bytes.
146+
*
147+
* @param[in] p_reg Pointer to the structure of registers of the peripheral.
148+
* @param[in] addr_ptr Pointer to the address to resolve using the available IRK keys.
149+
* Must point to the Data RAM region.
150+
*/
151+
NRF_STATIC_INLINE void nrf_aar_addr_pointer_set(NRF_AAR_Type * p_reg, uint8_t const * addr_ptr);
152+
153+
/**
154+
* @brief Function for setting the pointer to the scratch data area.
155+
*
156+
* The scratch data area is used for temporary storage during the address resolution procedure.
157+
* A space of minimum 3 bytes must be reserved for the scratch data area.
158+
*
159+
* @param[in] p_reg Pointer to the structure of registers of the peripheral.
160+
* @param[in] scratch_ptr Pointer to the scratch data area. Must point to the Data RAM region.
161+
*/
162+
NRF_STATIC_INLINE void nrf_aar_scratch_pointer_set(NRF_AAR_Type * p_reg, uint8_t * scratch_ptr);
163+
164+
/**
165+
* @brief Function for getting the index of the Identity Resolving Key that was used
166+
* the last time an address was resolved.
167+
*
168+
* This function can be used to get the IRK index that matched the resolvable address,
169+
* provided that @ref NRF_AAR_EVENT_RESOLVED occured. Otherwise, it will return
170+
* the index of the last IRK stored in the IRK data structure.
171+
*
172+
* @param[in] p_reg Pointer to the structure of registers of the peripheral.
173+
*
174+
* @return The index of the IRK that was used the last time an address was resolved.
175+
*/
176+
NRF_STATIC_INLINE uint8_t nrf_aar_resolution_status_get(NRF_AAR_Type const * p_reg);
177+
178+
/*****************************/
179+
/* Inlined functions bodies: */
180+
/*****************************/
181+
182+
NRF_STATIC_INLINE bool nrf_aar_event_check(NRF_AAR_Type const * p_reg,
183+
nrf_aar_event_t aar_event)
184+
{
185+
return (bool)*(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)aar_event);
186+
}
187+
188+
NRF_STATIC_INLINE void nrf_aar_event_clear(NRF_AAR_Type * p_reg,
189+
nrf_aar_event_t aar_event)
190+
{
191+
*((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)aar_event)) = 0;
192+
#if __CORTEX_M == 0x04
193+
volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)aar_event));
194+
(void)dummy;
195+
#endif
196+
}
197+
198+
NRF_STATIC_INLINE void nrf_aar_enable(NRF_AAR_Type * p_reg)
199+
{
200+
p_reg->ENABLE = AAR_ENABLE_ENABLE_Enabled << AAR_ENABLE_ENABLE_Pos;
201+
}
202+
203+
NRF_STATIC_INLINE void nrf_aar_disable(NRF_AAR_Type * p_reg)
204+
{
205+
p_reg->ENABLE = AAR_ENABLE_ENABLE_Disabled << AAR_ENABLE_ENABLE_Pos;
206+
}
207+
208+
NRF_STATIC_INLINE void nrf_aar_irk_pointer_set(NRF_AAR_Type * p_reg, uint8_t const * irk_ptr)
209+
{
210+
p_reg->IRKPTR = (uint32_t)irk_ptr;
211+
}
212+
213+
NRF_STATIC_INLINE void nrf_aar_irk_number_set(NRF_AAR_Type * p_reg, uint8_t irk_num)
214+
{
215+
p_reg->NIRK = irk_num;
216+
}
217+
218+
NRF_STATIC_INLINE void nrf_aar_addr_pointer_set(NRF_AAR_Type * p_reg, uint8_t const * addr_ptr)
219+
{
220+
p_reg->ADDRPTR = (uint32_t)addr_ptr;
221+
}
222+
223+
NRF_STATIC_INLINE void nrf_aar_scratch_pointer_set(NRF_AAR_Type * p_reg, uint8_t * scratch_ptr)
224+
{
225+
p_reg->SCRATCHPTR = (uint32_t)scratch_ptr;
226+
}
227+
228+
NRF_STATIC_INLINE uint8_t nrf_aar_resolution_status_get(NRF_AAR_Type const * p_reg)
229+
{
230+
return (uint8_t)(p_reg->STATUS);
231+
}
232+
233+
#ifdef __cplusplus
234+
}
235+
#endif
236+
237+
#endif /* BS_NRF_AAR_H__ */

0 commit comments

Comments
 (0)