1 | /****************************************************************************** |
---|
2 | * |
---|
3 | * Copyright 2013 Altera Corporation. All Rights Reserved. |
---|
4 | * |
---|
5 | * Redistribution and use in source and binary forms, with or without |
---|
6 | * modification, are permitted provided that the following conditions are met: |
---|
7 | * |
---|
8 | * 1. Redistributions of source code must retain the above copyright notice, |
---|
9 | * this list of conditions and the following disclaimer. |
---|
10 | * |
---|
11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
---|
12 | * this list of conditions and the following disclaimer in the documentation |
---|
13 | * and/or other materials provided with the distribution. |
---|
14 | * |
---|
15 | * 3. The name of the author may not be used to endorse or promote products |
---|
16 | * derived from this software without specific prior written permission. |
---|
17 | * |
---|
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY EXPRESS OR |
---|
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
---|
20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. IN NO |
---|
21 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
---|
23 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
---|
26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
---|
27 | * OF SUCH DAMAGE. |
---|
28 | * |
---|
29 | ******************************************************************************/ |
---|
30 | |
---|
31 | |
---|
32 | /*! \file Altera - ALT_SOCAL */ |
---|
33 | |
---|
34 | #ifndef __ALTERA_SOCAL_H__ |
---|
35 | #define __ALTERA_SOCAL_H__ |
---|
36 | |
---|
37 | #ifndef __ASSEMBLY__ |
---|
38 | #ifdef __cplusplus |
---|
39 | #include <cstddef> |
---|
40 | #include <cstdbool> |
---|
41 | #include <cstdint> |
---|
42 | #else /* __cplusplus */ |
---|
43 | #include <stddef.h> |
---|
44 | #include <stdbool.h> |
---|
45 | #include <stdint.h> |
---|
46 | #endif /* __cplusplus */ |
---|
47 | #endif /* __ASSEMBLY__ */ |
---|
48 | |
---|
49 | #ifdef __cplusplus |
---|
50 | extern "C" |
---|
51 | { |
---|
52 | #endif /* __cplusplus */ |
---|
53 | |
---|
54 | /*! |
---|
55 | * \addtogroup ALT_SOCAL_UTIL SoCAL Utilities |
---|
56 | * |
---|
57 | * This file contains utility and support functions for the Altera SoCAL. |
---|
58 | * @{ |
---|
59 | */ |
---|
60 | |
---|
61 | #ifdef __ASSEMBLY__ |
---|
62 | #define ALT_CAST(type, ptr) ptr |
---|
63 | #else /* __ASSEMBLY__ */ |
---|
64 | /*! Cast the pointer to specified pointer type. |
---|
65 | * |
---|
66 | * Note: This macro expands to \e ptr value only for assembler language |
---|
67 | * targets. |
---|
68 | * |
---|
69 | * \param type The pointer type to cast to |
---|
70 | * \param ptr The pointer to apply the type cast to |
---|
71 | */ |
---|
72 | #define ALT_CAST(type, ptr) ((type) (ptr)) |
---|
73 | #endif /* __ASSEMBLY__ */ |
---|
74 | |
---|
75 | /*! |
---|
76 | * \addtogroup ALT_SOCAL_UTIL_RW_FUNC SoCAL Memory Read/Write Utilities |
---|
77 | * |
---|
78 | * This section implements read and write functionality for various |
---|
79 | * memory untis. The memory unit terms used for these functions are |
---|
80 | * consistent with those used in the ARM Architecture Reference Manual |
---|
81 | * ARMv7-A and ARMv7-R edition manual. The terms used for units of memory are: |
---|
82 | * |
---|
83 | * Unit of Memory | Abbreviation | Size in Bits |
---|
84 | * :---------------|:-------------|:------------: |
---|
85 | * Byte | byte | 8 |
---|
86 | * Half Word | hword | 16 |
---|
87 | * Word | word | 32 |
---|
88 | * Double Word | dword | 64 |
---|
89 | * |
---|
90 | * @{ |
---|
91 | */ |
---|
92 | |
---|
93 | /*! Write the 8 bit byte to the destination address in device memory. |
---|
94 | * \param dest - Write destination pointer address |
---|
95 | * \param src - 8 bit data byte to write to memory |
---|
96 | */ |
---|
97 | #define alt_write_byte(dest, src) (*ALT_CAST(volatile uint8_t *, (dest)) = (src)) |
---|
98 | |
---|
99 | /*! Read and return the 8 bit byte from the source address in device memory. |
---|
100 | * \param src Read source pointer address |
---|
101 | * \returns 8 bit data byte value |
---|
102 | */ |
---|
103 | #define alt_read_byte(src) (*ALT_CAST(volatile uint8_t *, (src))) |
---|
104 | |
---|
105 | /*! Write the 16 bit half word to the destination address in device memory. |
---|
106 | * \param dest - Write destination pointer address |
---|
107 | * \param src - 16 bit data half word to write to memory |
---|
108 | */ |
---|
109 | #define alt_write_hword(dest, src) (*ALT_CAST(volatile uint16_t *, (dest)) = (src)) |
---|
110 | |
---|
111 | /*! Read and return the 16 bit half word from the source address in device memory. |
---|
112 | * \param src Read source pointer address |
---|
113 | * \returns 16 bit data half word value |
---|
114 | */ |
---|
115 | #define alt_read_hword(src) (*ALT_CAST(volatile uint16_t *, (src))) |
---|
116 | |
---|
117 | /*! Write the 32 bit word to the destination address in device memory. |
---|
118 | * \param dest - Write destination pointer address |
---|
119 | * \param src - 32 bit data word to write to memory |
---|
120 | */ |
---|
121 | #define alt_write_word(dest, src) (*ALT_CAST(volatile uint32_t *, (dest)) = (src)) |
---|
122 | |
---|
123 | /*! Read and return the 32 bit word from the source address in device memory. |
---|
124 | * \param src Read source pointer address |
---|
125 | * \returns 32 bit data word value |
---|
126 | */ |
---|
127 | #define alt_read_word(src) (*ALT_CAST(volatile uint32_t *, (src))) |
---|
128 | |
---|
129 | /*! Write the 64 bit double word to the destination address in device memory. |
---|
130 | * \param dest - Write destination pointer address |
---|
131 | * \param src - 64 bit data double word to write to memory |
---|
132 | */ |
---|
133 | #define alt_write_dword(dest, src) (*ALT_CAST(volatile uint64_t *, (dest)) = (src)) |
---|
134 | |
---|
135 | /*! Read and return the 64 bit double word from the source address in device memory. |
---|
136 | * \param src Read source pointer address |
---|
137 | * \returns 64 bit data double word value |
---|
138 | */ |
---|
139 | #define alt_read_dword(src) (*ALT_CAST(volatile uint64_t *, (src))) |
---|
140 | |
---|
141 | /*! @} */ |
---|
142 | |
---|
143 | /*! |
---|
144 | * \addtogroup ALT_SOCAL_UTIL_SC_FUNC SoCAL Memory Bit Set/Clr/XOR/Replace Utilities |
---|
145 | * |
---|
146 | * This section implements useful macros to set, clear, change, and replace |
---|
147 | * selected bits within a word in memory or a memory-mapped register. |
---|
148 | * @{ |
---|
149 | * |
---|
150 | */ |
---|
151 | |
---|
152 | /*! Set selected bits in the 8 bit byte at the destination address in device memory. |
---|
153 | * \param dest - Destination pointer address |
---|
154 | * \param bits - Bits to set in destination byte |
---|
155 | */ |
---|
156 | #define alt_setbits_byte(dest, bits) (alt_write_byte(dest, alt_read_byte(dest) | (bits))) |
---|
157 | |
---|
158 | /*! Clear selected bits in the 8 bit byte at the destination address in device memory. |
---|
159 | * \param dest - Destination pointer address |
---|
160 | * \param bits - Bits to clear in destination byte |
---|
161 | */ |
---|
162 | #define alt_clrbits_byte(dest, bits) (alt_write_byte(dest, alt_read_byte(dest) & ~(bits))) |
---|
163 | |
---|
164 | /*! Change or toggle selected bits in the 8 bit byte at the destination address in device memory. |
---|
165 | * \param dest - Destination pointer address |
---|
166 | * \param bits - Bits to change in destination byte |
---|
167 | */ |
---|
168 | #define alt_xorbits_byte(dest, bits) (alt_write_byte(dest, alt_read_byte(dest) ^ (bits))) |
---|
169 | |
---|
170 | /*! Replace selected bits in the 8 bit byte at the destination address in device memory. |
---|
171 | * \param dest - Destination pointer address |
---|
172 | * \param msk - Bits to replace in destination byte |
---|
173 | * \param src - Source bits to write to cleared bits in destination byte |
---|
174 | */ |
---|
175 | #define alt_replbits_byte(dest, msk, src) (alt_write_byte(dest,(alt_read_byte(dest) & ~(msk)) | ((src) & (msk)))) |
---|
176 | |
---|
177 | /*! Set selected bits in the 16 bit halfword at the destination address in device memory. |
---|
178 | * \param dest - Destination pointer address |
---|
179 | * \param bits - Bits to set in destination halfword |
---|
180 | */ |
---|
181 | #define alt_setbits_hword(dest, bits) (alt_write_hword(dest, alt_read_hword(dest) | (bits))) |
---|
182 | |
---|
183 | /*! Clear selected bits in the 16 bit halfword at the destination address in device memory. |
---|
184 | * \param dest - Destination pointer address |
---|
185 | * \param bits - Bits to clear in destination halfword |
---|
186 | */ |
---|
187 | #define alt_clrbits_hword(dest, bits) (alt_write_hword(dest, alt_read_hword(dest) & ~(bits))) |
---|
188 | |
---|
189 | /*! Change or toggle selected bits in the 16 bit halfword at the destination address in device memory. |
---|
190 | * \param dest - Destination pointer address |
---|
191 | * \param bits - Bits to change in destination halfword |
---|
192 | */ |
---|
193 | #define alt_xorbits_hword(dest, bits) (alt_write_hword(dest, alt_read_hword(dest) ^ (bits))) |
---|
194 | |
---|
195 | /*! Replace selected bits in the 16 bit halfword at the destination address in device memory. |
---|
196 | * \param dest - Destination pointer address |
---|
197 | * \param msk - Bits to replace in destination halfword |
---|
198 | * \param src - Source bits to write to cleared bits in destination halfword |
---|
199 | */ |
---|
200 | #define alt_replbits_hword(dest, msk, src) (alt_write_hword(dest,(alt_read_hword(dest) & ~(msk)) | ((src) & (msk)))) |
---|
201 | |
---|
202 | /*! Set selected bits in the 32 bit word at the destination address in device memory. |
---|
203 | * \param dest - Destination pointer address |
---|
204 | * \param bits - Bits to set in destination word |
---|
205 | */ |
---|
206 | #define alt_setbits_word(dest, bits) (alt_write_word(dest, alt_read_word(dest) | (bits))) |
---|
207 | |
---|
208 | /*! Clear selected bits in the 32 bit word at the destination address in device memory. |
---|
209 | * \param dest - Destination pointer address |
---|
210 | * \param bits - Bits to clear in destination word |
---|
211 | */ |
---|
212 | #define alt_clrbits_word(dest, bits) (alt_write_word(dest, alt_read_word(dest) & ~(bits))) |
---|
213 | |
---|
214 | /*! Change or toggle selected bits in the 32 bit word at the destination address in device memory. |
---|
215 | * \param dest - Destination pointer address |
---|
216 | * \param bits - Bits to change in destination word |
---|
217 | */ |
---|
218 | #define alt_xorbits_word(dest, bits) (alt_write_word(dest, alt_read_word(dest) ^ (bits))) |
---|
219 | |
---|
220 | /*! Replace selected bits in the 32 bit word at the destination address in device memory. |
---|
221 | * \param dest - Destination pointer address |
---|
222 | * \param msk - Bits to replace in destination word |
---|
223 | * \param src - Source bits to write to cleared bits in destination word |
---|
224 | */ |
---|
225 | #define alt_replbits_word(dest, msk, src) (alt_write_word(dest,(alt_read_word(dest) & ~(msk)) | ((src) & (msk)))) |
---|
226 | |
---|
227 | /*! Set selected bits in the 64 bit doubleword at the destination address in device memory. |
---|
228 | * \param dest - Destination pointer address |
---|
229 | * \param bits - Bits to set in destination doubleword |
---|
230 | */ |
---|
231 | #define alt_setbits_dword(dest, bits) (alt_write_dword(dest, alt_read_dword(dest) | (bits))) |
---|
232 | |
---|
233 | /*! Clear selected bits in the 64 bit doubleword at the destination address in device memory. |
---|
234 | * \param dest - Destination pointer address |
---|
235 | * \param bits - Bits to clear in destination doubleword |
---|
236 | */ |
---|
237 | #define alt_clrbits_dword(dest, bits) (alt_write_dword(dest, alt_read_dword(dest) & ~(bits))) |
---|
238 | |
---|
239 | /*! Change or toggle selected bits in the 64 bit doubleword at the destination address in device memory. |
---|
240 | * \param dest - Destination pointer address |
---|
241 | * \param bits - Bits to change in destination doubleword |
---|
242 | */ |
---|
243 | #define alt_xorbits_dword(dest, bits) (alt_write_dword(dest, alt_read_dword(dest) ^ (bits))) |
---|
244 | |
---|
245 | /*! Replace selected bits in the 64 bit doubleword at the destination address in device memory. |
---|
246 | * \param dest - Destination pointer address |
---|
247 | * \param msk - Bits to replace in destination doubleword |
---|
248 | * \param src - Source bits to write to cleared bits in destination word |
---|
249 | */ |
---|
250 | #define alt_replbits_dword(dest, msk, src) (alt_write_dword(dest,(alt_read_dword(dest) & ~(msk)) | ((src) & (msk)))) |
---|
251 | |
---|
252 | /*! @} */ |
---|
253 | |
---|
254 | /*! @} */ |
---|
255 | |
---|
256 | #ifdef __cplusplus |
---|
257 | } |
---|
258 | #endif /* __cplusplus */ |
---|
259 | #endif /* __ALTERA_SOCAL_H__ */ |
---|