]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/intc_v3_2/src/xintc_selftest.c
f6ced2928556dad76e3ee570ed6178de423fe6f8
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / BSP / microblaze_0 / libsrc / intc_v3_2 / src / xintc_selftest.c
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 xintc_selftest.c
36 *
37 * Contains diagnostic self-test functions for the XIntc component. This file
38 * requires other files of the component to be linked in also.
39 *
40 * <pre>
41 * MODIFICATION HISTORY:
42 *
43 * Ver   Who  Date     Changes
44 * ----- ---- -------- -----------------------------------------------
45 * 1.00b jhl  02/21/02 First release
46 * 1.10c mta  03/21/07 Updated to new coding style
47 * 2.00a ktn  10/20/09 Updated to use HAL Processor APIs
48 * 2.04a bss  01/16/12 Removed CurrentMIE variable and reading of the
49 *                     MER register to remove warnings
50 * 2.06a bss  01/28/13 To support Cascade mode:
51 *                     Modified XIntc_SimulateIntr API.
52 * </pre>
53 *
54 ******************************************************************************/
55
56 /***************************** Include Files *********************************/
57
58 #include "xil_types.h"
59 #include "xil_assert.h"
60 #include "xintc.h"
61 #include "xintc_i.h"
62
63 /************************** Constant Definitions *****************************/
64
65 #define XIN_TEST_MASK 1
66
67 /**************************** Type Definitions *******************************/
68
69
70 /***************** Macros (Inline Functions) Definitions *********************/
71
72
73 /************************** Function Prototypes ******************************/
74
75
76 /************************** Variable Definitions *****************************/
77
78
79 /*****************************************************************************/
80 /**
81 *
82 * Run a self-test on the driver/device. This is a destructive test.
83 *
84 * This involves forcing interrupts into the controller and verifying that they
85 * are recognized and can be acknowledged. This test will not succeed if the
86 * interrupt controller has been started in real mode such that interrupts
87 * cannot be forced.
88 *
89 * @param        InstancePtr is a pointer to the XIntc instance to be worked on.
90 *
91 * @return
92 *               - XST_SUCCESS if self-test is successful.
93 *               - XST_INTC_FAIL_SELFTEST if the Interrupt controller fails the
94 *               self-test. It will fail the self test if the device has
95 *               previously been started in real mode.
96 *
97 * @note         None.
98 *
99 ******************************************************************************/
100 int XIntc_SelfTest(XIntc * InstancePtr)
101 {
102         u32 CurrentISR;
103         u32 Temp;
104
105         /*
106          * Assert the arguments
107          */
108         Xil_AssertNonvoid(InstancePtr != NULL);
109         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
110
111
112         /*
113          * Acknowledge all pending interrupts by reading the interrupt status
114          * register and writing the value to the acknowledge register
115          */
116         Temp = XIntc_In32(InstancePtr->BaseAddress + XIN_ISR_OFFSET);
117
118         XIntc_Out32(InstancePtr->BaseAddress + XIN_IAR_OFFSET, Temp);
119
120         /*
121          * Verify that there are no interrupts by reading the interrupt status
122          */
123         CurrentISR = XIntc_In32(InstancePtr->BaseAddress + XIN_ISR_OFFSET);
124
125         /*
126          * ISR should be zero after all interrupts are acknowledged
127          */
128         if (CurrentISR != 0) {
129                 return XST_INTC_FAIL_SELFTEST;
130         }
131
132         /*
133          * Set a bit in the ISR which simulates an interrupt
134          */
135         XIntc_Out32(InstancePtr->BaseAddress + XIN_ISR_OFFSET, XIN_TEST_MASK);
136
137         /*
138          * Verify that it was set
139          */
140         CurrentISR = XIntc_In32(InstancePtr->BaseAddress + XIN_ISR_OFFSET);
141
142         if (CurrentISR != XIN_TEST_MASK) {
143                 return XST_INTC_FAIL_SELFTEST;
144         }
145
146         /*
147          * Acknowledge the interrupt
148          */
149         XIntc_Out32(InstancePtr->BaseAddress + XIN_IAR_OFFSET, XIN_TEST_MASK);
150
151         /*
152          * Read back the ISR to verify that the interrupt is gone
153          */
154         CurrentISR = XIntc_In32(InstancePtr->BaseAddress + XIN_ISR_OFFSET);
155
156         if (CurrentISR != 0) {
157                 return XST_INTC_FAIL_SELFTEST;
158         }
159
160         return XST_SUCCESS;
161 }
162
163 /*****************************************************************************/
164 /**
165 *
166 * Allows software to simulate an interrupt in the interrupt controller. This
167 * function will only be successful when the interrupt controller has been
168 * started in simulation mode. Once it has been started in real mode,
169 * interrupts cannot be simulated. A simulated interrupt allows the interrupt
170 * controller to be tested without any device to drive an interrupt input
171 * signal into it. In Cascade mode writes to ISR of appropraite Slave
172 * controller depending on Id.
173 *
174 * @param        InstancePtr is a pointer to the XIntc instance to be worked on.
175 * @param        Id is the interrupt ID for which to simulate an interrupt.
176 *
177 * @return
178 *               - XST_SUCCESS if successful
179 *               - XST_FAILURE if the interrupt could not be
180 *               simulated because the interrupt controller is or
181 *               has previously been in real mode.
182 *
183 * @note         None.
184 *
185 ******************************************************************************/
186 int XIntc_SimulateIntr(XIntc * InstancePtr, u8 Id)
187 {
188         u32 Mask;
189         u32 MasterEnable;
190         XIntc_Config *CfgPtr;
191         int Index;
192         int DeviceId;
193
194         /*
195          * Assert the arguments
196          */
197         Xil_AssertNonvoid(InstancePtr != NULL);
198         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
199         Xil_AssertNonvoid(Id < XPAR_INTC_MAX_NUM_INTR_INPUTS);
200
201
202         /* Get the contents of the master enable register and determine if
203          * hardware interrupts have already been enabled, if so, this is a write
204          * once bit such that simulation can't be done at this point because
205          * the ISR register is no longer writable by software
206          */
207         MasterEnable = XIntc_In32(InstancePtr->BaseAddress + XIN_MER_OFFSET);
208         if (MasterEnable & XIN_INT_HARDWARE_ENABLE_MASK) {
209                 return XST_FAILURE;
210         }
211
212
213         if (Id > 31) {
214
215                 DeviceId = Id/32;
216
217                 CfgPtr = XIntc_LookupConfig(Id/32);
218                 Mask = XIntc_BitPosMask[Id%32];
219                 XIntc_Out32(CfgPtr->BaseAddress + XIN_ISR_OFFSET, Mask);
220
221                 /* Generate interrupt for 31 by writing to Interrupt Status
222                  * register of parent controllers. Primary controller ISR
223                  * will be written last in the loop
224                  */
225                 Mask = XIntc_BitPosMask[31];
226                 for (Index = DeviceId - 1; Index >= 0; Index--)
227                 {
228                         CfgPtr = XIntc_LookupConfig(Index);
229
230                         XIntc_Out32(CfgPtr->BaseAddress + XIN_ISR_OFFSET,
231                                                                         Mask);
232                 }
233         }
234         else {
235                 /*
236                  * The Id is used to create the appropriate mask for the
237                  * desired bit position.
238                  */
239                 Mask = XIntc_BitPosMask[Id];
240
241                 /*
242                  * Enable the selected interrupt source by reading the interrupt
243                  * enable register and then modifying only the specified
244                  * interrupt id enable
245                  */
246                 XIntc_Out32(InstancePtr->BaseAddress + XIN_ISR_OFFSET, Mask);
247
248         }
249         /* indicate the interrupt was successfully simulated */
250
251         return XST_SUCCESS;
252 }