1 /*
2 * Copyright (c) 2023 - 2024, Nordic Semiconductor ASA
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * 3. Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #ifndef NRF_RAMC_H__
35 #define NRF_RAMC_H__
36
37 #include <nrfx.h>
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 #define NRF_RAMC_WAITSTATES_MAX RAMC_WAITSTATES_WAITSTATES_Max
44
45 /**
46 * @defgroup nrf_ramc_hal RAMC RAM Controller HAL
47 * @{
48 * @ingroup nrf_ramc
49 * @brief Hardware access layer for managing the Random Access Memory Controller (RAMC)
50 * peripheral.
51 */
52
53 /** @brief RAMC events. */
54 typedef enum
55 {
56 NRF_RAMC_EVENT_ERROR_FIXABLE = offsetof(NRF_RAMC_Type, EVENTS_ERRORFIX), /**< ECC detected fixable (one bit) error in read data from RAM. */
57 NRF_RAMC_EVENT_ERROR_NON_FIXABLE = offsetof(NRF_RAMC_Type, EVENTS_ERRORNONFIX), /**< ECC detected non-fixable (multiple bits) error in read data from RAM. */
58 } nrf_ramc_event_t;
59
60 /**
61 * @brief Function for clearing the specified RAMC event.
62 *
63 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
64 * @param[in] event Event to be cleared.
65 */
66 NRF_STATIC_INLINE void nrf_ramc_event_clear(NRF_RAMC_Type * p_reg, nrf_ramc_event_t event);
67
68 /**
69 * @brief Function for retrieving the state of the RAMC event.
70 *
71 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
72 * @param[in] event Event to be checked.
73 *
74 * @retval true The event has been generated.
75 * @retval false The event has not been generated.
76 */
77 NRF_STATIC_INLINE bool nrf_ramc_event_check(NRF_RAMC_Type const * p_reg, nrf_ramc_event_t event);
78
79 /**
80 * @brief Function for returning the address of the specified RAMC event register.
81 *
82 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
83 * @param[in] event The specified event.
84 *
85 * @return Address of specified event register.
86 */
87 NRF_STATIC_INLINE uint32_t nrf_ramc_event_address_get(NRF_RAMC_Type const * p_reg,
88 nrf_ramc_event_t event);
89
90 /**
91 * @brief Function for setting number of waitstates for a read from the RAM.
92 *
93 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
94 * @param[in] waitstates Number of waitstates [0...1].
95 */
96 NRF_STATIC_INLINE void nrf_ramc_waitstates_set(NRF_RAMC_Type * p_reg, uint8_t waitstates);
97
98 /**
99 * @brief Function for getting number of waitstates for a read from the RAM.
100 *
101 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
102 *
103 * @return Number of waitstates.
104 */
105 NRF_STATIC_INLINE uint8_t nrf_ramc_waitstates_get(NRF_RAMC_Type const * p_reg);
106
107 /**
108 * @brief Function for setting base address for secure access area.
109 *
110 * @note When the SECENABLE is enabled, any non-secure accesses to the address within
111 * the RAM which are above or equal to the base address generates an error.
112 *
113 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
114 * @param[in] addr Base address. Writes to the bits [11:0] are ignored and are read as zero.
115 * Similarly, the MSB size depends on the size of the RAM, writes to those
116 * MSB above the size are ignored and are read as zero.
117 */
118 NRF_STATIC_INLINE void nrf_ramc_secbase_set(NRF_RAMC_Type * p_reg, uint32_t addr);
119
120 /**
121 * @brief Function for getting base address for secure access area.
122 *
123 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
124 *
125 * @return Base address.
126 */
127 NRF_STATIC_INLINE uint32_t nrf_ramc_secbase_get(NRF_RAMC_Type const * p_reg);
128
129 /**
130 * @brief Function for setting secure access restrictions.
131 *
132 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
133 * @param[in] enable True if secure access restrictions are to be enabled, false otherwise
134 */
135 NRF_STATIC_INLINE void nrf_ramc_secenable_set(NRF_RAMC_Type * p_reg, bool enable);
136
137 /**
138 * @brief Function for checking secure access restrictions.
139 *
140 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
141 *
142 * @retval true Secure access restrictions are enabled.
143 * @retval false Secure access restrictions are disabled.
144 */
145 NRF_STATIC_INLINE bool nrf_ramc_secenable_check(NRF_RAMC_Type const * p_reg);
146
147 #ifndef NRF_DECLARE_ONLY
148
nrf_ramc_event_clear(NRF_RAMC_Type * p_reg,nrf_ramc_event_t event)149 NRF_STATIC_INLINE void nrf_ramc_event_clear(NRF_RAMC_Type * p_reg, nrf_ramc_event_t event)
150 {
151 *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)) = 0x0UL;
152 nrf_event_readback((uint8_t *)p_reg + (uint32_t)event);
153 }
154
nrf_ramc_event_check(NRF_RAMC_Type const * p_reg,nrf_ramc_event_t event)155 NRF_STATIC_INLINE bool nrf_ramc_event_check(NRF_RAMC_Type const * p_reg, nrf_ramc_event_t event)
156 {
157 return nrf_event_check(p_reg, event);
158 }
159
nrf_ramc_event_address_get(NRF_RAMC_Type const * p_reg,nrf_ramc_event_t event)160 NRF_STATIC_INLINE uint32_t nrf_ramc_event_address_get(NRF_RAMC_Type const * p_reg,
161 nrf_ramc_event_t event)
162 {
163 return nrf_task_event_address_get(p_reg, event);
164 }
165
nrf_ramc_waitstates_set(NRF_RAMC_Type * p_reg,uint8_t waitstates)166 NRF_STATIC_INLINE void nrf_ramc_waitstates_set(NRF_RAMC_Type * p_reg, uint8_t waitstates)
167 {
168 NRFX_ASSERT(waitstates <= NRF_RAMC_WAITSTATES_MAX);
169 p_reg->WAITSTATES = (uint32_t)waitstates;
170 }
171
nrf_ramc_waitstates_get(NRF_RAMC_Type const * p_reg)172 NRF_STATIC_INLINE uint8_t nrf_ramc_waitstates_get(NRF_RAMC_Type const * p_reg)
173 {
174 return (uint8_t)p_reg->WAITSTATES;
175 }
176
nrf_ramc_secbase_set(NRF_RAMC_Type * p_reg,uint32_t addr)177 NRF_STATIC_INLINE void nrf_ramc_secbase_set(NRF_RAMC_Type * p_reg, uint32_t addr)
178 {
179 p_reg->SECBASE = addr;
180 }
181
nrf_ramc_secbase_get(NRF_RAMC_Type const * p_reg)182 NRF_STATIC_INLINE uint32_t nrf_ramc_secbase_get(NRF_RAMC_Type const * p_reg)
183 {
184 return p_reg->SECBASE;
185 }
186
nrf_ramc_secenable_set(NRF_RAMC_Type * p_reg,bool enable)187 NRF_STATIC_INLINE void nrf_ramc_secenable_set(NRF_RAMC_Type * p_reg, bool enable)
188 {
189 p_reg->SECENABLE = (enable ? RAMC_SECENABLE_ENABLE_Enable : RAMC_SECENABLE_ENABLE_Disable) <<
190 RAMC_SECENABLE_ENABLE_Pos;
191 }
192
nrf_ramc_secenable_check(NRF_RAMC_Type const * p_reg)193 NRF_STATIC_INLINE bool nrf_ramc_secenable_check(NRF_RAMC_Type const * p_reg)
194 {
195 return p_reg->SECENABLE == (RAMC_SECENABLE_ENABLE_Enable << RAMC_SECENABLE_ENABLE_Pos);
196 }
197
198 #endif // NRF_DECLARE_ONLY
199
200 /** @} */
201
202 #ifdef __cplusplus
203 }
204 #endif
205
206 #endif // NRF_RAMC_H__
207