source: rtems/c/src/lib/libbsp/arm/altera-cyclone-v/hwlib/include/socal/socal.h @ 0b03ca39

4.115
Last change on this file since 0b03ca39 was 0b03ca39, checked in by Ralf Kirchner <ralf.kirchner@…>, on 02/14/14 at 14:00:31

bsp/altera-cyclone-v: Add Alteras hwlib

Add files from Alteras hwlib

  • Property mode set to 100644
File size: 16.0 KB
Line 
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,       *
22* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
23* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;  *
24* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,     *
25* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR      *
26* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF       *
27* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                                   *
28*                                                                              *
29*******************************************************************************/
30
31/*! \file Altera - ALT_SOCAL */
32
33#ifndef __ALTERA_SOCAL_H__
34#define __ALTERA_SOCAL_H__
35
36#ifdef __cplusplus
37extern "C"
38{
39#endif  /* __cplusplus */
40
41/*!
42 * \addtogroup ALT_SOCAL_UTIL SoCAL Utilities
43 *
44 * This file contains utility and support functions for the Altera SoCAL.
45 * @{
46 */
47
48#ifdef __ASSEMBLY__
49#define ALT_CAST(type, ptr)  ptr
50#else   /* __ASSEMBLY__ */
51/*! Cast the pointer to specified pointer type.
52 *
53 *  Note: This macro expands to \e ptr value only for assembler language
54 *        targets.
55 *
56 *  \param type     The pointer type to cast to
57 *  \param ptr      The pointer to apply the type cast to
58 */
59#define ALT_CAST(type, ptr)  ((type) (ptr))
60#endif  /* __ASSEMBLY__ */
61
62
63/*!
64 * \addtogroup ALT_SOCAL_UTIL_RW_FUNC SoCAL Memory Read/Write Utilities
65 *
66 * This section implements read and write functionality for various
67 * memory untis. The memory unit terms used for these functions are
68 * consistent with those used in the ARM Architecture Reference Manual
69 * ARMv7-A and ARMv7-R edition manual. The terms used for units of memory are:
70 *
71 *  Unit of Memory | Abbreviation | Size in Bits
72 * :---------------|:-------------|:------------:
73 *  Byte           | byte         |       8
74 *  Half Word      | hword        |      16
75 *  Word           | word         |      32
76 *  Double Word    | dword        |      64
77 *
78 * @{
79 */
80
81/*! Write the 8 bit byte to the destination address in device memory.
82 *  \param dest - Write destination pointer address
83 *  \param src  - 8 bit data byte to write to memory
84 */
85#define alt_write_byte(dest, src)       (*ALT_CAST(volatile uint8_t *, (dest)) = (src))
86
87/*! Read and return the 8 bit byte from the source address in device memory.
88 *  \param src    Read source pointer address
89 *  \returns      8 bit data byte value
90 */
91#define alt_read_byte(src)              (*ALT_CAST(volatile uint8_t *, (src)))
92
93/*! Write the 16 bit half word to the destination address in device memory.
94 *  \param dest - Write destination pointer address
95 *  \param src  - 16 bit data half word to write to memory
96 */
97#define alt_write_hword(dest, src)      (*ALT_CAST(volatile uint16_t *, (dest)) = (src))
98
99/*! Read and return the 16 bit half word from the source address in device memory.
100 *  \param src    Read source pointer address
101 *  \returns      16 bit data half word value
102 */
103#define alt_read_hword(src)             (*ALT_CAST(volatile uint16_t *, (src)))
104
105/*! Write the 32 bit word to the destination address in device memory.
106 *  \param dest - Write destination pointer address
107 *  \param src  - 32 bit data word to write to memory
108 */
109#define alt_write_word(dest, src)       (*ALT_CAST(volatile uint32_t *, (dest)) = (src))
110
111/*! Read and return the 32 bit word from the source address in device memory.
112 *  \param src    Read source pointer address
113 *  \returns      32 bit data word value
114 */
115#define alt_read_word(src)              (*ALT_CAST(volatile uint32_t *, (src)))
116
117/*! Write the 64 bit double word to the destination address in device memory.
118 *  \param dest - Write destination pointer address
119 *  \param src  - 64 bit data double word to write to memory
120 */
121#define alt_write_dword(dest, src)      (*ALT_CAST(volatile uint64_t *, (dest)) = (src))
122
123/*! Read and return the 64 bit double word from the source address in device memory.
124 *  \param src    Read source pointer address
125 *  \returns      64 bit data double word value
126 */
127#define alt_read_dword(src)             (*ALT_CAST(volatile uint64_t *, (src)))
128
129/*! @} */
130
131/*!
132 * \addtogroup ALT_SOCAL_UTIL_SC_FUNC SoCAL Memory Bit Set/Clr/XOR/Replace Utilities
133 *
134 * This section implements useful macros to set, clear, change, and replace
135 * selected bits within a word in memory or a memory-mapped register.
136 * @{
137 *
138 */
139
140/*! Set selected bits in the 8 bit byte at the destination address in device memory.
141 *  \param dest - Destination pointer address
142 *  \param bits - Bits to set in destination byte
143 */
144#define     alt_setbits_byte(dest, bits)        (alt_write_byte(dest, alt_read_byte(dest) | (bits)))
145
146/*! Clear selected bits in the 8 bit byte at the destination address in device memory.
147 *  \param dest - Destination pointer address
148 *  \param bits - Bits to clear in destination byte
149 */
150#define     alt_clrbits_byte(dest, bits)        (alt_write_byte(dest, alt_read_byte(dest) & ~(bits)))
151
152/*! Change or toggle 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 change in destination byte
155 */
156#define     alt_xorbits_byte(dest, bits)        (alt_write_byte(dest, alt_read_byte(dest) ^ (bits)))
157
158/*! Replace selected bits in the 8 bit byte at the destination address in device memory.
159 *  \param  dest - Destination pointer address
160 *  \param  msk  - Bits to replace in destination byte
161 *  \param  src  - Source bits to write to cleared bits in destination byte
162 */
163#define     alt_replbits_byte(dest, msk, src)   (alt_write_byte(dest,(alt_read_byte(dest) & ~(msk)) | ((src) & (msk))))
164
165/*! Set selected bits in the 16 bit halfword at the destination address in device memory.
166 *  \param dest - Destination pointer address
167 *  \param bits - Bits to set in destination halfword
168 */
169#define     alt_setbits_hword(dest, bits)       (alt_write_hword(dest, alt_read_hword(dest) | (bits)))
170
171/*! Clear selected bits in the 16 bit halfword at the destination address in device memory.
172 *  \param dest - Destination pointer address
173 *  \param bits - Bits to clear in destination halfword
174 */
175#define     alt_clrbits_hword(dest, bits)       (alt_write_hword(dest, alt_read_hword(dest) & ~(bits)))
176
177/*! Change or toggle 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 change in destination halfword
180 */
181#define     alt_xorbits_hword(dest, bits)       (alt_write_hword(dest, alt_read_hword(dest) ^ (bits)))
182
183/*! Replace selected bits in the 16 bit halfword at the destination address in device memory.
184 *  \param  dest - Destination pointer address
185 *  \param  msk  - Bits to replace in destination halfword
186 *  \param  src  - Source bits to write to cleared bits in destination halfword
187 */
188#define     alt_replbits_hword(dest, msk, src)   (alt_write_hword(dest,(alt_read_hword(dest) & ~(msk)) | ((src) & (msk))))
189
190/*! Set selected bits in the 32 bit word at the destination address in device memory.
191 *  \param dest - Destination pointer address
192 *  \param bits - Bits to set in destination word
193 */
194#define     alt_setbits_word(dest, bits)        (alt_write_word(dest, alt_read_word(dest) | (bits)))
195
196/*! Clear selected bits in the 32 bit word at the destination address in device memory.
197 *  \param dest - Destination pointer address
198 *  \param bits - Bits to clear in destination word
199 */
200#define     alt_clrbits_word(dest, bits)        (alt_write_word(dest, alt_read_word(dest) & ~(bits)))
201
202/*! Change or toggle 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 change in destination word
205 */
206#define     alt_xorbits_word(dest, bits)        (alt_write_word(dest, alt_read_word(dest) ^ (bits)))
207
208/*! Replace selected bits in the 32 bit word at the destination address in device memory.
209 *  \param  dest - Destination pointer address
210 *  \param  msk  - Bits to replace in destination word
211 *  \param  src  - Source bits to write to cleared bits in destination word
212 */
213#define     alt_replbits_word(dest, msk, src)   (alt_write_word(dest,(alt_read_word(dest) & ~(msk)) | ((src) & (msk))))
214
215/*! Set selected bits in the 64 bit doubleword at the destination address in device memory.
216 *  \param dest - Destination pointer address
217 *  \param bits - Bits to set in destination doubleword
218 */
219#define     alt_setbits_dword(dest, bits)       (alt_write_dword(dest, alt_read_dword(dest) | (bits)))
220
221/*! Clear selected bits in the 64 bit doubleword at the destination address in device memory.
222 *  \param dest - Destination pointer address
223 *  \param bits - Bits to clear in destination doubleword
224 */
225#define     alt_clrbits_dword(dest, bits)       (alt_write_dword(dest, alt_read_dword(dest) & ~(bits)))
226
227/*! Change or toggle 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 change in destination doubleword
230 */
231#define     alt_xorbits_dword(dest, bits)       (alt_write_dword(dest, alt_read_dword(dest) ^ (bits)))
232
233/*! Replace selected bits in the 64 bit doubleword at the destination address in device memory.
234 *  \param  dest - Destination pointer address
235 *  \param  msk  - Bits to replace in destination doubleword
236 *  \param  src  - Source bits to write to cleared bits in destination word
237 */
238#define     alt_replbits_dword(dest, msk, src)   (alt_write_dword(dest,(alt_read_dword(dest) & ~(msk)) | ((src) & (msk))))
239
240
241
242/*! @} */
243
244/*!
245 * \addtogroup ALT_SOCAL_TYPE_IND_FUNC SoCAL Indirect (pointer-based) Utilities
246 *
247 * This section implements two other useful forms of the alt_write_*() macros above that
248 * are preferable to use in some situations. These use an intermediate pointer (defined
249 * in the containing compile unit) to move data in an indirect manner. These compile to very
250 * tight ARM code, equivalent to the above versions.
251 *
252 * @{
253 */
254
255/*! Write the 8 bit byte to the destination address in device memory.
256 *  \param dest  - Write destination pointer address
257 *  \param tmptr - Temporary pointer to byte data
258 *  \param src   - 8 bit data value to write to memory
259 */
260#define alt_indwrite_byte(dest, tmptr, src)  {(tmptr)=ALT_CAST(uint8_t*,(dest));(*ALT_CAST(volatile uint8_t*,(tmptr))=(src));}
261
262/*! Write the 8 bit byte to the destination address in device memory.
263 *  \param dest  - Write destination pointer address
264 *  \param tmptr - Temporary pointer to byte data
265 *  \param src   - Read destination pointer address
266 */
267#define alt_indread_byte(dest, tmptr, src)   {(tmptr)=ALT_CAST(uint8_t*,(src));(*ALT_CAST(volatile uint8_t*,(dest))=*(tmptr));}
268
269/*! Write the 16 bit halfword to the destination address in device memory.
270 *  \param dest  - Write destination pointer address
271 *  \param tmptr - Temporary pointer to halfword data
272 *  \param src   - 16 bit data value to write to memory
273 */
274#define alt_indwrite_hword(dest, tmptr, src) {(tmptr)=ALT_CAST(uint16_t*,(dest));(*ALT_CAST(volatile uint16_t*,(tmptr))=(src));}
275
276/*! Write the 16 bit halfword to the destination address in device memory.
277 *  \param dest  - Write destination pointer address
278 *  \param tmptr - Temporary pointer to halfword data
279 *  \param src   - Read destination pointer address
280 */
281#define alt_indread_hword(dest, tmptr, src)  {(tmptr)=ALT_CAST(uint16_t*,(src));(*ALT_CAST(volatile uint16_t*,(dest))=*(tmptr));}
282
283/*! Write the 32 bit word to the destination address in device memory.
284 *  \param dest  - Write destination pointer address
285 *  \param tmptr - Temporary pointer to word data
286 *  \param src   - 32 bit data value to write to memory
287 */
288#define alt_indwrite_word(dest, tmptr, src)  {(tmptr)=ALT_CAST(uint32_t*,(dest));(*ALT_CAST(volatile uint32_t*,(tmptr))=(src));}
289
290/*! Write the 32 bit word to the destination address in device memory.
291 *  \param dest  - Write destination pointer address
292 *  \param tmptr - Temporary pointer to word data
293 *  \param src   - Read destination pointer address
294 */
295#define alt_indread_word(dest, tmptr, src)   {(tmptr)=ALT_CAST(uint32_t*,(src));(*ALT_CAST(volatile uint32_t*,(dest))=*(tmptr));}
296
297/*! Write the 64 bit dword to the destination address in device memory.
298 *  \param dest  - Write destination pointer address
299 *  \param tmptr - Temporary pointer to double-word data
300 *  \param src   - 64 bit data value to write to memory
301 */
302#define alt_indwrite_dword(dest, tmptr, src) {(tmptr)=ALT_CAST(uint64_t*,(dest));(*ALT_CAST(volatile uint64_t*,(tmptr))=(src));}
303
304/*! Write the 64 bit dword to the destination address in device memory.
305 *  \param dest  - Write destination pointer address
306 *  \param tmptr - Temporary pointer to double-word data
307 *  \param src   - Read destination pointer address
308 */
309#define alt_indread_dword(dest, tmptr, src)  {(tmptr)=ALT_CAST(uint64_t*,(src));(*ALT_CAST(volatile uint64_t*,(dest))=*(tmptr));}
310
311
312/*! @} */
313
314/*!
315 * \addtogroup ALT_SOCAL_CMPL_ASRT_FUNC SoCAL Compile Assert Utilities
316 *
317 * This section implements an assert-type functionality in the compiler rather than in the
318 * debug run-time code. Additional macros can be built on the basic structure and defined
319 * to test various conditions and throw a compile-time error if necessary.
320 *
321 * @{
322 */
323
324/*! alt_cat_compile_assert_text() concatenates text.
325 *  \param txta - The first text fragment to be joined
326 *  \param txtb - The second text fragment to be joined
327 */
328#define alt_cat_compile_assert_text(txta, txtb) txta##txtb
329
330/*! alt_form_compile_assert_line() is the basis of other functions that check various
331 *  conditions and possibly throw a compile-time error in response, giving an
332 *  assert equivalent that operates at compile time rather than at run-time.
333 *  \param test - Any valid boolean expression
334 *  \param file - The filename where this expression is located (ASCII string)
335 *  \param line - The line number where this expression is located
336 */
337#define alt_form_compile_assert_line(test, file, line) \
338typedef char alt_cat_compile_assert_text(assertion_at_##file##_line_, line)[2*!!(test)-1]
339
340/*! alt_check_struct_size() throws a compile-time error if the structure size (a) is
341 *  larger than the size of the reference (b). \n
342 *  alt_check_struct_size() works with groups of bitfields up to much larger
343 *  structure sizes.
344 *  \param a - Structure to be evaluated
345 *  \param b - Reference size
346 */
347#define alt_check_struct_size(a, b) alt_form_compile_assert_line((sizeof(a) <= sizeof(b)),__FILE__,__LINE__)
348
349
350/*! @} */
351/*! @} */
352
353#ifdef __cplusplus
354}
355#endif  /* __cplusplus */
356#endif  /* __ALTERA_SOCAL_H__ */
Note: See TracBrowser for help on using the repository browser.