1 /*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * o Redistributions of source code must retain the above copyright notice, this list
9 * of conditions and the following disclaimer.
10 *
11 * o Redistributions in binary form must reproduce the above copyright notice, this
12 * list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
14 *
15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef __RDC_H__
32 #define __RDC_H__
33
34 #include <stdint.h>
35 #include <stdbool.h>
36 #include <assert.h>
37 #include "device_imx.h"
38
39 /*!
40 * @addtogroup rdc_driver
41 * @{
42 */
43
44 /*******************************************************************************
45 * Definitions
46 ******************************************************************************/
47
48 /*******************************************************************************
49 * API
50 ******************************************************************************/
51
52 #if defined(__cplusplus)
53 extern "C" {
54 #endif
55
56 /*!
57 * @name RDC State Control
58 * @{
59 */
60
61 /*!
62 * @brief Get domain ID of core that is reading this
63 *
64 * @param base RDC base pointer.
65 * @return Domain ID of self core
66 */
RDC_GetSelfDomainID(RDC_Type * base)67 static inline uint32_t RDC_GetSelfDomainID(RDC_Type * base)
68 {
69 return (base->STAT & RDC_STAT_DID_MASK) >> RDC_STAT_DID_SHIFT;
70 }
71
72 /*!
73 * @brief Check whether memory region controlled by RDC is accessible after low power recovery
74 *
75 * @param base RDC base pointer.
76 * @return Memory region power status.
77 * - true: on and accessible.
78 * - false: off.
79 */
RDC_IsMemPowered(RDC_Type * base)80 static inline bool RDC_IsMemPowered(RDC_Type * base)
81 {
82 return (bool)(base->STAT & RDC_STAT_PDS_MASK);
83 }
84
85 /*!
86 * @brief Check whether there's pending RDC memory region restoration interrupt
87 *
88 * @param base RDC base pointer.
89 * @return RDC interrupt status
90 * - true: Interrupt pending.
91 * - false: No interrupt pending.
92 */
RDC_IsIntPending(RDC_Type * base)93 static inline bool RDC_IsIntPending(RDC_Type * base)
94 {
95 return (bool)(base->INTSTAT);
96 }
97
98 /*!
99 * @brief Clear interrupt status
100 *
101 * @param base RDC base pointer.
102 */
RDC_ClearStatusFlag(RDC_Type * base)103 static inline void RDC_ClearStatusFlag(RDC_Type * base)
104 {
105 base->INTSTAT = RDC_INTSTAT_INT_MASK;
106 }
107
108 /*!
109 * @brief Set RDC interrupt mode
110 *
111 * @param base RDC base pointer
112 * @param enable RDC interrupt control.
113 * - true: enable interrupt.
114 * - false: disable interrupt.
115 */
RDC_SetIntCmd(RDC_Type * base,bool enable)116 static inline void RDC_SetIntCmd(RDC_Type * base, bool enable)
117 {
118 base->INTCTRL = enable ? RDC_INTCTRL_RCI_EN_MASK : 0;
119 }
120
121 /*@}*/
122
123 /*!
124 * @name RDC Domain Control
125 * @{
126 */
127
128 /*!
129 * @brief Set RDC domain ID for RDC master
130 *
131 * @param base RDC base pointer
132 * @param mda RDC master assignment (see @ref _rdc_mda in rdc_defs_<device>.h)
133 * @param domainId RDC domain ID (0-3)
134 * @param lock Whether to lock this setting? Once locked, no one can change the domain assignment until reset
135 */
RDC_SetDomainID(RDC_Type * base,uint32_t mda,uint32_t domainId,bool lock)136 static inline void RDC_SetDomainID(RDC_Type * base, uint32_t mda, uint32_t domainId, bool lock)
137 {
138 assert (domainId <= RDC_MDA_DID_MASK);
139
140 base->MDA[mda] = RDC_MDA_DID(domainId) | (lock ? RDC_MDA_LCK_MASK : 0);
141 }
142
143 /*!
144 * @brief Get RDC domain ID for RDC master
145 *
146 * @param base RDC base pointer
147 * @param mda RDC master assignment (see @ref _rdc_mda in rdc_defs_<device>.h)
148 * @return RDC domain ID (0-3)
149 */
RDC_GetDomainID(RDC_Type * base,uint32_t mda)150 static inline uint32_t RDC_GetDomainID(RDC_Type * base, uint32_t mda)
151 {
152 return base->MDA[mda] & RDC_MDA_DID_MASK;
153 }
154
155 /*!
156 * @brief Set RDC peripheral access permission for RDC domains
157 *
158 * @param base RDC base pointer
159 * @param pdap RDC peripheral assignment (see @ref _rdc_pdap in rdc_defs_<device>.h)
160 * @param perm RDC access permission from RDC domain to peripheral (byte: D3R D3W D2R D2W D1R D1W D0R D0W)
161 * @param sreq Force acquiring SEMA42 to access this peripheral or not
162 * @param lock Whether to lock this setting or not. Once locked, no one can change the RDC setting until reset
163 */
RDC_SetPdapAccess(RDC_Type * base,uint32_t pdap,uint8_t perm,bool sreq,bool lock)164 static inline void RDC_SetPdapAccess(RDC_Type * base, uint32_t pdap, uint8_t perm, bool sreq, bool lock)
165 {
166 base->PDAP[pdap] = perm | (sreq ? RDC_PDAP_SREQ_MASK : 0) | (lock ? RDC_PDAP_LCK_MASK : 0);
167 }
168
169 /*!
170 * @brief Get RDC peripheral access permission for RDC domains
171 *
172 * @param base RDC base pointer
173 * @param pdap RDC peripheral assignment (see @ref _rdc_pdap in rdc_defs_<device>.h)
174 * @return RDC access permission from RDC domain to peripheral (byte: D3R D3W D2R D2W D1R D1W D0R D0W)
175 */
RDC_GetPdapAccess(RDC_Type * base,uint32_t pdap)176 static inline uint8_t RDC_GetPdapAccess(RDC_Type * base, uint32_t pdap)
177 {
178 return base->PDAP[pdap] & 0xFF;
179 }
180
181 /*!
182 * @brief Check whether RDC semaphore is required to access the peripheral
183 *
184 * @param base RDC base pointer
185 * @param pdap RDC peripheral assignment (see @ref _rdc_pdap in rdc_defs_<device>.h)
186 * @return RDC semaphore required or not.
187 * - true: RDC semaphore is required.
188 * - false: RDC semaphore is not required.
189 */
RDC_IsPdapSemaphoreRequired(RDC_Type * base,uint32_t pdap)190 static inline bool RDC_IsPdapSemaphoreRequired(RDC_Type * base, uint32_t pdap)
191 {
192 return (bool)(base->PDAP[pdap] & RDC_PDAP_SREQ_MASK);
193 }
194
195 /*!
196 * @brief Set RDC memory region access permission for RDC domains
197 *
198 * @param base RDC base pointer
199 * @param mr RDC memory region assignment (see @ref _rdc_mr in rdc_defs_<device>.h)
200 * @param startAddr memory region start address (inclusive)
201 * @param endAddr memory region end address (exclusive)
202 * @param perm RDC access permission from RDC domain to peripheral (byte: D3R D3W D2R D2W D1R D1W D0R D0W)
203 * @param enable Enable this memory region for RDC control or not
204 * @param lock Whether to lock this setting or not. Once locked, no one can change the RDC setting until reset
205 */
206 void RDC_SetMrAccess(RDC_Type * base, uint32_t mr, uint32_t startAddr, uint32_t endAddr,
207 uint8_t perm, bool enable, bool lock);
208
209 /*!
210 * @brief Get RDC memory region access permission for RDC domains
211 *
212 * @param base RDC base pointer
213 * @param mr RDC memory region assignment (see @ref _rdc_mr in rdc_defs_<device>.h)
214 * @param startAddr pointer to get memory region start address (inclusive), NULL is allowed.
215 * @param endAddr pointer to get memory region end address (exclusive), NULL is allowed.
216 * @return RDC access permission from RDC domain to peripheral (byte: D3R D3W D2R D2W D1R D1W D0R D0W)
217 */
218 uint8_t RDC_GetMrAccess(RDC_Type * base, uint32_t mr, uint32_t *startAddr, uint32_t *endAddr);
219
220
221 /*!
222 * @brief Check whether the memory region is enabled
223 *
224 * @param base RDC base pointer
225 * @param mr RDC memory region assignment (see _rdc_mr in rdc_defs_<device>.h)
226 * @return Memory region enabled or not.
227 * - true: Memory region is enabled.
228 * - false: Memory region is not enabled.
229 */
RDC_IsMrEnabled(RDC_Type * base,uint32_t mr)230 static inline bool RDC_IsMrEnabled(RDC_Type * base, uint32_t mr)
231 {
232 return (bool)(base->MR[mr].MRC & RDC_MRC_ENA_MASK);
233 }
234
235 /*!
236 * @brief Get memory violation status
237 *
238 * @param base RDC base pointer
239 * @param mr RDC memory region assignment (see @ref _rdc_mr in rdc_defs_<device>.h)
240 * @param violationAddr Pointer to store violation address, NULL allowed
241 * @param violationDomain Pointer to store domain ID causing violation, NULL allowed
242 * @return Memory violation occurred or not.
243 * - true: violation happened.
244 * - false: No violation happened.
245 */
246 bool RDC_GetViolationStatus(RDC_Type * base, uint32_t mr, uint32_t *violationAddr, uint32_t *violationDomain);
247
248 /*!
249 * @brief Clear RDC violation status
250 *
251 * @param base RDC base pointer
252 * @param mr RDC memory region assignment (see @ref _rdc_mr in rdc_defs_<device>.h)
253 */
RDC_ClearViolationStatus(RDC_Type * base,uint32_t mr)254 static inline void RDC_ClearViolationStatus(RDC_Type * base, uint32_t mr)
255 {
256 base->MR[mr].MRVS = RDC_MRVS_AD_MASK;
257 }
258
259 /*@}*/
260
261 #if defined(__cplusplus)
262 }
263 #endif
264
265 /*! @}*/
266
267 #endif /* __RDC_H__ */
268 /*******************************************************************************
269 * EOF
270 ******************************************************************************/
271