]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R5_UltraScale_MPSoC/RTOSDemo_R5_bsp/psu_cortexr5_0/libsrc/scugic_v3_5/src/xscugic_intr.c
xTaskGenericNotify() now sets xYieldPending to pdTRUE even when the 'higher priority...
[freertos] / FreeRTOS / Demo / CORTEX_R5_UltraScale_MPSoC / RTOSDemo_R5_bsp / psu_cortexr5_0 / libsrc / scugic_v3_5 / src / xscugic_intr.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2010 - 2015 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 xscugic_intr.c
36 * @addtogroup scugic_v3_1
37 * @{
38 *
39 * This file contains the interrupt processing for the driver for the Xilinx
40 * Interrupt Controller.  The interrupt processing is partitioned separately such
41 * that users are not required to use the provided interrupt processing.  This
42 * file requires other files of the driver to be linked in also.
43 *
44 * The interrupt handler, XScuGic_InterruptHandler, uses an input argument which
45 * is an instance pointer to an interrupt controller driver such that multiple
46 * interrupt controllers can be supported.  This handler requires the calling
47 * function to pass it the appropriate argument, so another level of indirection
48 * may be required.
49 *
50 * The interrupt processing may be used by connecting the interrupt handler to
51 * the interrupt system.  The handler does not save and restore the processor
52 * context but only handles the processing of the Interrupt Controller. The user
53 * is encouraged to supply their own interrupt handler when performance tuning is
54 * deemed necessary.
55 *
56 * <pre>
57 * MODIFICATION HISTORY:
58 *
59 * Ver   Who  Date     Changes
60 * ----- ---- -------- ---------------------------------------------------------
61 * 1.00a drg  01/19/10 First release
62 * 1.01a sdm  11/09/11 XScuGic_InterruptHandler has changed correspondingly
63 *                     since the HandlerTable has now moved to XScuGic_Config.
64 * 3.00  kvn  02/13/15 Modified code for MISRA-C:2012 compliance.
65 *
66 * </pre>
67 *
68 * @internal
69 *
70 * This driver assumes that the context of the processor has been saved prior to
71 * the calling of the Interrupt Controller interrupt handler and then restored
72 * after the handler returns. This requires either the running RTOS to save the
73 * state of the machine or that a wrapper be used as the destination of the
74 * interrupt vector to save the state of the processor and restore the state
75 * after the interrupt handler returns.
76 *
77 ******************************************************************************/
78
79 /***************************** Include Files *********************************/
80
81 #include "xil_types.h"
82 #include "xil_assert.h"
83 #include "xscugic.h"
84
85 /************************** Constant Definitions *****************************/
86
87 /**************************** Type Definitions *******************************/
88
89 /***************** Macros (Inline Functions) Definitions *********************/
90
91 /************************** Function Prototypes ******************************/
92
93 /************************** Variable Definitions *****************************/
94
95 /*****************************************************************************/
96 /**
97 * This function is the primary interrupt handler for the driver.  It must be
98 * connected to the interrupt source such that it is called when an interrupt of
99 * the interrupt controller is active. It will resolve which interrupts are
100 * active and enabled and call the appropriate interrupt handler. It uses
101 * the Interrupt Type information to determine when to acknowledge the interrupt.
102 * Highest priority interrupts are serviced first.
103 *
104 * This function assumes that an interrupt vector table has been previously
105 * initialized.  It does not verify that entries in the table are valid before
106 * calling an interrupt handler.
107 *
108 *
109 * @param        InstancePtr is a pointer to the XScuGic instance.
110 *
111 * @return       None.
112 *
113 * @note         None.
114 *
115 ******************************************************************************/
116 void XScuGic_InterruptHandler(XScuGic *InstancePtr)
117 {
118
119         u32 InterruptID;
120             u32 IntIDFull;
121             XScuGic_VectorTableEntry *TablePtr;
122
123             /* Assert that the pointer to the instance is valid
124              */
125             Xil_AssertVoid(InstancePtr != NULL);
126
127             /*
128              * Read the int_ack register to identify the highest priority interrupt ID
129              * and make sure it is valid. Reading Int_Ack will clear the interrupt
130              * in the GIC.
131              */
132             IntIDFull = XScuGic_CPUReadReg(InstancePtr, XSCUGIC_INT_ACK_OFFSET);
133             InterruptID = IntIDFull & XSCUGIC_ACK_INTID_MASK;
134
135             if(XSCUGIC_MAX_NUM_INTR_INPUTS < InterruptID){
136                 goto IntrExit;
137             }
138
139             /*
140              * If the interrupt is shared, do some locking here if there are multiple
141              * processors.
142              */
143             /*
144              * If pre-eption is required:
145              * Re-enable pre-emption by setting the CPSR I bit for non-secure ,
146              * interrupts or the F bit for secure interrupts
147              */
148
149             /*
150              * If we need to change security domains, issue a SMC instruction here.
151              */
152
153             /*
154              * Execute the ISR. Jump into the Interrupt service routine based on the
155              * IRQSource. A software trigger is cleared by the ACK.
156              */
157             TablePtr = &(InstancePtr->Config->HandlerTable[InterruptID]);
158                 if(TablePtr != NULL) {
159                 TablePtr->Handler(TablePtr->CallBackRef);
160                 }
161
162         IntrExit:
163             /*
164              * Write to the EOI register, we are all done here.
165              * Let this function return, the boot code will restore the stack.
166              */
167             XScuGic_CPUWriteReg(InstancePtr, XSCUGIC_EOI_OFFSET, IntIDFull);
168
169             /*
170              * Return from the interrupt. Change security domains could happen here.
171      */
172 }
173 /** @} */