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