1 /******************************************************************************
3 * Copyright (C) 2002 - 2014 Xilinx, Inc. All rights reserved.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
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
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.
31 ******************************************************************************/
32 /*****************************************************************************/
35 * @file xintc_selftest.c
37 * Contains diagnostic self-test functions for the XIntc component. This file
38 * requires other files of the component to be linked in also.
41 * MODIFICATION HISTORY:
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.
54 ******************************************************************************/
56 /***************************** Include Files *********************************/
58 #include "xil_types.h"
59 #include "xil_assert.h"
63 /************************** Constant Definitions *****************************/
65 #define XIN_TEST_MASK 1
67 /**************************** Type Definitions *******************************/
70 /***************** Macros (Inline Functions) Definitions *********************/
73 /************************** Function Prototypes ******************************/
76 /************************** Variable Definitions *****************************/
79 /*****************************************************************************/
82 * Run a self-test on the driver/device. This is a destructive test.
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
89 * @param InstancePtr is a pointer to the XIntc instance to be worked on.
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.
99 ******************************************************************************/
100 int XIntc_SelfTest(XIntc * InstancePtr)
106 * Assert the arguments
108 Xil_AssertNonvoid(InstancePtr != NULL);
109 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
113 * Acknowledge all pending interrupts by reading the interrupt status
114 * register and writing the value to the acknowledge register
116 Temp = XIntc_In32(InstancePtr->BaseAddress + XIN_ISR_OFFSET);
118 XIntc_Out32(InstancePtr->BaseAddress + XIN_IAR_OFFSET, Temp);
121 * Verify that there are no interrupts by reading the interrupt status
123 CurrentISR = XIntc_In32(InstancePtr->BaseAddress + XIN_ISR_OFFSET);
126 * ISR should be zero after all interrupts are acknowledged
128 if (CurrentISR != 0) {
129 return XST_INTC_FAIL_SELFTEST;
133 * Set a bit in the ISR which simulates an interrupt
135 XIntc_Out32(InstancePtr->BaseAddress + XIN_ISR_OFFSET, XIN_TEST_MASK);
138 * Verify that it was set
140 CurrentISR = XIntc_In32(InstancePtr->BaseAddress + XIN_ISR_OFFSET);
142 if (CurrentISR != XIN_TEST_MASK) {
143 return XST_INTC_FAIL_SELFTEST;
147 * Acknowledge the interrupt
149 XIntc_Out32(InstancePtr->BaseAddress + XIN_IAR_OFFSET, XIN_TEST_MASK);
152 * Read back the ISR to verify that the interrupt is gone
154 CurrentISR = XIntc_In32(InstancePtr->BaseAddress + XIN_ISR_OFFSET);
156 if (CurrentISR != 0) {
157 return XST_INTC_FAIL_SELFTEST;
163 /*****************************************************************************/
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.
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.
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.
185 ******************************************************************************/
186 int XIntc_SimulateIntr(XIntc * InstancePtr, u8 Id)
190 XIntc_Config *CfgPtr;
195 * Assert the arguments
197 Xil_AssertNonvoid(InstancePtr != NULL);
198 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
199 Xil_AssertNonvoid(Id < XPAR_INTC_MAX_NUM_INTR_INPUTS);
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
207 MasterEnable = XIntc_In32(InstancePtr->BaseAddress + XIN_MER_OFFSET);
208 if (MasterEnable & XIN_INT_HARDWARE_ENABLE_MASK) {
217 CfgPtr = XIntc_LookupConfig(Id/32);
218 Mask = XIntc_BitPosMask[Id%32];
219 XIntc_Out32(CfgPtr->BaseAddress + XIN_ISR_OFFSET, Mask);
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
225 Mask = XIntc_BitPosMask[31];
226 for (Index = DeviceId - 1; Index >= 0; Index--)
228 CfgPtr = XIntc_LookupConfig(Index);
230 XIntc_Out32(CfgPtr->BaseAddress + XIN_ISR_OFFSET,
236 * The Id is used to create the appropriate mask for the
237 * desired bit position.
239 Mask = XIntc_BitPosMask[Id];
242 * Enable the selected interrupt source by reading the interrupt
243 * enable register and then modifying only the specified
244 * interrupt id enable
246 XIntc_Out32(InstancePtr->BaseAddress + XIN_ISR_OFFSET, Mask);
249 /* indicate the interrupt was successfully simulated */