]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/standalone_v4_2/src/xil_exception.c
Update some more standard demos for use on 64-bit architectures.
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / BSP / microblaze_0 / libsrc / standalone_v4_2 / src / xil_exception.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2009 - 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 xil_exception.c
36 *
37 * This file contains implementation of exception related driver functions.
38 *
39 * <pre>
40 * MODIFICATION HISTORY:
41 *
42 * Ver   Who  Date     Changes
43 * ----- ---- -------- -------------------------------------------------------
44 * 1.00  hbm  07/28/09 Initial release
45 *
46 * </pre>
47 *
48 * @note
49 *
50 * None.
51 *
52 ******************************************************************************/
53
54 #include "xil_types.h"
55 #include "xil_exception.h"
56
57 #include "microblaze_exceptions_g.h"
58
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62
63 extern void microblaze_enable_exceptions(void);
64 extern void microblaze_disable_exceptions(void);
65 extern void microblaze_enable_interrupts(void);
66 extern void microblaze_disable_interrupts(void);
67
68 /**
69 * Currently HAL is an augmented part of standalone BSP, so the old definition
70 * of MB_ExceptionVectorTableEntry is used here.
71 */
72
73 typedef struct {
74    Xil_ExceptionHandler Handler;
75    void *CallBackRef;
76 } MB_ExceptionVectorTableEntry;
77
78 typedef struct {
79    Xil_ExceptionHandler Handler;
80    void *CallBackRef;
81 } MB_InterruptVectorTableEntry;
82
83 #ifdef __cplusplus
84 }
85 #endif
86
87
88 /************************** Variable Definitions *****************************/
89 extern MB_ExceptionVectorTableEntry MB_ExceptionVectorTable[];
90 extern MB_InterruptVectorTableEntry MB_InterruptVectorTable;
91
92 /**
93  *
94  * This function is a stub handler that is the default handler that gets called
95  * if the application has not setup a handler for a specific  exception. The
96  * function interface has to match the interface specified for a handler even
97  * though none of the arguments are used.
98  *
99  * @param       Data is unused by this function.
100  *
101  * @return
102  *
103  * None.
104  *
105  * @note
106  *
107  * None.
108  *
109  *****************************************************************************/
110 static void Xil_ExceptionNullHandler(void *Data)
111 {
112         (void) Data;
113 }
114
115 /****************************************************************************/
116 /**
117 *
118 * Initialize exception handling for the processor. The exception vector table
119 * is setup with the stub handler for all exceptions.
120 *
121 * @param    None.
122 *
123 * @return   None.
124 *
125 * @note
126 *
127 * None.
128 *
129 *****************************************************************************/
130 void Xil_ExceptionInit(void)
131 {
132         /*
133          * there is no need to setup the exception table here
134          */
135
136 }
137
138 /****************************************************************************/
139 /**
140 * Enable Exceptions.
141 *
142 * @return   None.
143 *
144 * @note     None.
145 *
146 ******************************************************************************/
147 void Xil_ExceptionEnable(void)
148 {
149 #ifdef MICROBLAZE_EXCEPTIONS_ENABLED
150         microblaze_enable_exceptions();
151 #endif
152         microblaze_enable_interrupts();
153 }
154
155 /****************************************************************************/
156 /**
157 * Disable Exceptions.
158 *
159 * @param    None.
160 *
161 * @return   None.
162 *
163 * @note     None.
164 *
165 ******************************************************************************/
166 void Xil_ExceptionDisable(void)
167 {
168 #ifdef MICROBLAZE_EXCEPTIONS_ENABLED
169         microblaze_disable_exceptions();
170 #endif
171         microblaze_disable_interrupts();
172 }
173
174 /*****************************************************************************/
175 /**
176 *
177 * Makes the connection between the Id of the exception source and the
178 * associated handler that is to run when the exception is recognized. The
179 * argument provided in this call as the DataPtr is used as the argument
180 * for the handler when it is called.
181 *
182 * @param    Id contains the ID of the exception source and should
183 *           be XIL_EXCEPTION_INT or be in the range of 0 to XIL_EXCEPTION_LAST.
184 *           See xil_mach_exception.h for further information.
185 * @param    Handler to the handler for that exception.
186 * @param    Data is a reference to data that will be passed to the handler
187 *           when it gets called.
188 *
189 * @return   None.
190 *
191 * @note
192 *
193 * None.
194 *
195 ****************************************************************************/
196 void Xil_ExceptionRegisterHandler(u32 Id, Xil_ExceptionHandler Handler,
197                                   void *Data)
198 {
199         if (Id == XIL_EXCEPTION_ID_INT) {
200                 MB_InterruptVectorTable.Handler = Handler;
201                 MB_InterruptVectorTable.CallBackRef = Data;
202         }
203         else {
204 #ifdef MICROBLAZE_EXCEPTIONS_ENABLED
205                 MB_ExceptionVectorTable[Id].Handler = Handler;
206                 MB_ExceptionVectorTable[Id].CallBackRef = Data;
207 #endif
208         }
209 }
210
211
212 /*****************************************************************************/
213 /**
214 *
215 * Removes the handler for a specific exception Id. The stub handler is then
216 * registered for this exception Id.
217 *
218 * @param    Id contains the ID of the exception source and should
219 *           be XIL_EXCEPTION_INT or in the range of 0 to XIL_EXCEPTION_LAST.
220 *           See xexception_l.h for further information.
221 *
222 * @return   None.
223 *
224 * @note
225 *
226 * None.
227 *
228 ****************************************************************************/
229 void Xil_ExceptionRemoveHandler(u32 Id)
230 {
231         if (Id == XIL_EXCEPTION_ID_INT) {
232                 MB_InterruptVectorTable.Handler = Xil_ExceptionNullHandler;
233                 MB_InterruptVectorTable.CallBackRef = NULL;
234         }
235         else {
236
237 #ifdef MICROBLAZE_EXCEPTIONS_ENABLED
238                 MB_ExceptionVectorTable[Id].Handler =
239                         Xil_ExceptionNullHandler;
240                 MB_ExceptionVectorTable[Id].CallBackRef = NULL;
241 #endif
242         }
243 }
244