]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/libsrc/standalone_v4_1/src/xenv_standalone.h
Preparing for next release...
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / libsrc / standalone_v4_1 / src / xenv_standalone.h
1 /******************************************************************************
2 *
3 * Copyright (C) 2002 - 2014 Xilinx, Inc.  All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 *
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
30 *
31 ******************************************************************************/
32 /*****************************************************************************/
33 /**
34 *
35 * @file xenv_standalone.h
36 *
37 * Defines common services specified by xenv.h.
38 *
39 * @note
40 *       This file is not intended to be included directly by driver code.
41 *       Instead, the generic xenv.h file is intended to be included by driver
42 *       code.
43 *
44 * <pre>
45 * MODIFICATION HISTORY:
46 *
47 * Ver   Who  Date     Changes
48 * ----- ---- -------- -----------------------------------------------
49 * 1.00a wgr  02/28/07 Added cache handling macros.
50 * 1.00a wgr  02/27/07 Simplified code. Deprecated old-style macro names.
51 * 1.00a rmm  01/24/06 Implemented XENV_USLEEP. Assume implementation is being
52 *                     used under Xilinx standalone BSP.
53 * 1.00a xd   11/03/04 Improved support for doxygen.
54 * 1.00a rmm  03/21/02 First release
55 * 1.00a wgr  03/22/07 Converted to new coding style.
56 * 1.00a rpm  06/29/07 Added udelay macro for standalone
57 * 1.00a xd   07/19/07 Included xparameters.h as XPAR_ constants are referred
58 *                     to in MICROBLAZE section
59 * 1.00a ecm  09/19/08 updated for v7.20 of Microblaze, new functionality
60 *
61 * </pre>
62 *
63 *
64 ******************************************************************************/
65
66 #ifndef XENV_STANDALONE_H
67 #define XENV_STANDALONE_H
68
69 #ifdef __cplusplus
70 extern "C" {
71 #endif
72
73 /***************************** Include Files *********************************/
74 /******************************************************************************
75  *
76  * Get the processor dependent includes
77  *
78  ******************************************************************************/
79
80 #include <string.h>
81
82 #if defined __MICROBLAZE__
83 #  include "mb_interface.h"
84 #  include "xparameters.h"   /* XPAR constants used below in MB section */
85
86 #elif defined __PPC__
87 #  include "sleep.h"
88 #  include "xcache_l.h"      /* also include xcache_l.h for caching macros */
89 #endif
90
91 /******************************************************************************
92  *
93  * MEMCPY / MEMSET related macros.
94  *
95  * The following are straight forward implementations of memset and memcpy.
96  *
97  * NOTE: memcpy may not work if source and target memory area are overlapping.
98  *
99  ******************************************************************************/
100 /*****************************************************************************/
101 /**
102  *
103  * Copies a non-overlapping block of memory.
104  *
105  * @param       DestPtr
106  *              Destination address to copy data to.
107  *
108  * @param       SrcPtr
109  *              Source address to copy data from.
110  *
111  * @param       Bytes
112  *              Number of bytes to copy.
113  *
114  * @return      None.
115  *
116  * @note
117  *              The use of XENV_MEM_COPY is deprecated. Use memcpy() instead.
118  *
119  * @note
120  *              This implemention MAY BREAK work if source and target memory
121  *              area are overlapping.
122  *
123  *****************************************************************************/
124
125 #define XENV_MEM_COPY(DestPtr, SrcPtr, Bytes) \
126         memcpy((void *) DestPtr, (const void *) SrcPtr, (size_t) Bytes)
127
128
129
130 /*****************************************************************************/
131 /**
132  *
133  * Fills an area of memory with constant data.
134  *
135  * @param       DestPtr
136  *              Destination address to copy data to.
137  *
138  * @param       Data
139  *              Value to set.
140  *
141  * @param       Bytes
142  *              Number of bytes to copy.
143  *
144  * @return      None.
145  *
146  * @note
147  *              The use of XENV_MEM_FILL is deprecated. Use memset() instead.
148  *
149  *****************************************************************************/
150
151 #define XENV_MEM_FILL(DestPtr, Data, Bytes) \
152         memset((void *) DestPtr, (int) Data, (size_t) Bytes)
153
154
155
156 /******************************************************************************
157  *
158  * TIME related macros
159  *
160  ******************************************************************************/
161
162 /**
163  * A structure that contains a time stamp used by other time stamp macros
164  * defined below. This structure is processor dependent.
165  */
166 typedef int XENV_TIME_STAMP;
167
168 /*****************************************************************************/
169 /**
170  *
171  * Time is derived from the 64 bit PPC timebase register
172  *
173  * @param   StampPtr is the storage for the retrieved time stamp.
174  *
175  * @return  None.
176  *
177  * @note
178  *
179  * Signature: void XENV_TIME_STAMP_GET(XTIME_STAMP *StampPtr)
180  * <br><br>
181  * This macro must be implemented by the user.
182  *
183  *****************************************************************************/
184 #define XENV_TIME_STAMP_GET(StampPtr)
185
186 /*****************************************************************************/
187 /**
188  *
189  * This macro is not yet implemented and always returns 0.
190  *
191  * @param   Stamp1Ptr is the first sampled time stamp.
192  * @param   Stamp2Ptr is the second sampled time stamp.
193  *
194  * @return  0
195  *
196  * @note
197  *
198  * This macro must be implemented by the user.
199  *
200  *****************************************************************************/
201 #define XENV_TIME_STAMP_DELTA_US(Stamp1Ptr, Stamp2Ptr)     (0)
202
203 /*****************************************************************************/
204 /**
205  *
206  * This macro is not yet implemented and always returns 0.
207  *
208  * @param   Stamp1Ptr is the first sampled time stamp.
209  * @param   Stamp2Ptr is the second sampled time stamp.
210  *
211  * @return  0
212  *
213  * @note
214  *
215  * This macro must be implemented by the user.
216  *
217  *****************************************************************************/
218 #define XENV_TIME_STAMP_DELTA_MS(Stamp1Ptr, Stamp2Ptr)     (0)
219
220 /*****************************************************************************/
221 /**
222  * XENV_USLEEP(unsigned delay)
223  *
224  * Delay the specified number of microseconds. Not implemented without OS
225  * support.
226  *
227  * @param       delay
228  *              Number of microseconds to delay.
229  *
230  * @return      None.
231  *
232  *****************************************************************************/
233
234 #ifdef __PPC__
235 #define XENV_USLEEP(delay)      usleep(delay)
236 #define udelay(delay)   usleep(delay)
237 #else
238 #define XENV_USLEEP(delay)
239 #define udelay(delay)
240 #endif
241
242
243 /******************************************************************************
244  *
245  * CACHE handling macros / mappings
246  *
247  ******************************************************************************/
248 /******************************************************************************
249  *
250  * Processor independent macros
251  *
252  ******************************************************************************/
253
254 #define XCACHE_ENABLE_CACHE()   \
255                 { XCACHE_ENABLE_DCACHE(); XCACHE_ENABLE_ICACHE(); }
256
257 #define XCACHE_DISABLE_CACHE()  \
258                 { XCACHE_DISABLE_DCACHE(); XCACHE_DISABLE_ICACHE(); }
259
260
261 /******************************************************************************
262  *
263  * MicroBlaze case
264  *
265  * NOTE: Currently the following macros will only work on systems that contain
266  * only ONE MicroBlaze processor. Also, the macros will only be enabled if the
267  * system is built using a xparameters.h file.
268  *
269  ******************************************************************************/
270
271 #if defined __MICROBLAZE__
272
273 /* Check if MicroBlaze data cache was built into the core.
274  */
275 #if (XPAR_MICROBLAZE_USE_DCACHE == 1)
276 #  define XCACHE_ENABLE_DCACHE()                microblaze_enable_dcache()
277 #  define XCACHE_DISABLE_DCACHE()               microblaze_disable_dcache()
278 #  define XCACHE_INVALIDATE_DCACHE()    microblaze_invalidate_dcache()
279
280 #  define XCACHE_INVALIDATE_DCACHE_RANGE(Addr, Len) \
281                         microblaze_invalidate_dcache_range((int)(Addr), (int)(Len))
282
283 #if (XPAR_MICROBLAZE_DCACHE_USE_WRITEBACK == 1)
284 #  define XCACHE_FLUSH_DCACHE()                 microblaze_flush_dcache()
285 #  define XCACHE_FLUSH_DCACHE_RANGE(Addr, Len) \
286                         microblaze_flush_dcache_range((int)(Addr), (int)(Len))
287 #else
288 #  define XCACHE_FLUSH_DCACHE()                 microblaze_invalidate_dcache()
289 #  define XCACHE_FLUSH_DCACHE_RANGE(Addr, Len) \
290                         microblaze_invalidate_dcache_range((int)(Addr), (int)(Len))
291 #endif  /*XPAR_MICROBLAZE_DCACHE_USE_WRITEBACK*/
292
293 #else
294 #  define XCACHE_ENABLE_DCACHE()
295 #  define XCACHE_DISABLE_DCACHE()
296 #  define XCACHE_INVALIDATE_DCACHE_RANGE(Addr, Len)
297 #  define XCACHE_FLUSH_DCACHE_RANGE(Addr, Len)
298 #endif  /*XPAR_MICROBLAZE_USE_DCACHE*/
299
300
301 /* Check if MicroBlaze instruction cache was built into the core.
302  */
303 #if (XPAR_MICROBLAZE_USE_ICACHE == 1)
304 #  define XCACHE_ENABLE_ICACHE()                microblaze_enable_icache()
305 #  define XCACHE_DISABLE_ICACHE()               microblaze_disable_icache()
306
307 #  define XCACHE_INVALIDATE_ICACHE()    microblaze_invalidate_icache()
308
309 #  define XCACHE_INVALIDATE_ICACHE_RANGE(Addr, Len) \
310                         microblaze_invalidate_icache_range((int)(Addr), (int)(Len))
311
312 #else
313 #  define XCACHE_ENABLE_ICACHE()
314 #  define XCACHE_DISABLE_ICACHE()
315 #endif  /*XPAR_MICROBLAZE_USE_ICACHE*/
316
317
318 /******************************************************************************
319  *
320  * PowerPC case
321  *
322  *   Note that the XCACHE_ENABLE_xxx functions are hardcoded to enable a
323  *   specific memory region (0x80000001). Each bit (0-30) in the regions
324  *   bitmask stands for 128MB of memory. Bit 31 stands for the upper 2GB
325  *   range.
326  *
327  *   regions    --> cached address range
328  *   ------------|--------------------------------------------------
329  *   0x80000000  | [0, 0x7FFFFFF]
330  *   0x00000001  | [0xF8000000, 0xFFFFFFFF]
331  *   0x80000001  | [0, 0x7FFFFFF],[0xF8000000, 0xFFFFFFFF]
332  *
333  ******************************************************************************/
334
335 #elif defined __PPC__
336
337 #define XCACHE_ENABLE_DCACHE()          XCache_EnableDCache(0x80000001)
338 #define XCACHE_DISABLE_DCACHE()         XCache_DisableDCache()
339 #define XCACHE_ENABLE_ICACHE()          XCache_EnableICache(0x80000001)
340 #define XCACHE_DISABLE_ICACHE()         XCache_DisableICache()
341
342 #define XCACHE_INVALIDATE_DCACHE_RANGE(Addr, Len) \
343                 XCache_InvalidateDCacheRange((unsigned int)(Addr), (unsigned)(Len))
344
345 #define XCACHE_FLUSH_DCACHE_RANGE(Addr, Len) \
346                 XCache_FlushDCacheRange((unsigned int)(Addr), (unsigned)(Len))
347
348 #define XCACHE_INVALIDATE_ICACHE()      XCache_InvalidateICache()
349
350
351 /******************************************************************************
352  *
353  * Unknown processor / architecture
354  *
355  ******************************************************************************/
356
357 #else
358 /* #error "Unknown processor / architecture. Must be MicroBlaze or PowerPC." */
359 #endif
360
361
362 #ifdef __cplusplus
363 }
364 #endif
365
366 #endif  /* #ifndef XENV_STANDALONE_H */
367