Xilinx 中断函数配置
Angie An

Xilinx 中断函数配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/****************************************************************************

* Copyright (C) 2010 - 2020 Xilinx, Inc. All rights reserved.
* SPDX-License-Identifier: MIT
******************************************************************************/

/******************************************************************************/
/**
*

* @file xscugic_example.c
*

* This file contains a design example using the Interrupt Controller driver

* (XScuGic) and hardware device. Please reference other device driver examples

* to see more examples of how the intc and interrupts can be used by a software

* application.
*

* @note
*

* None
*

* <pre>
*

* MODIFICATION HISTORY:

* Ver Who Date Changes

* ----- ---- -------- ----------------------------------------------------

* 1.00a drg 01/18/10 First release

* </pre>
******************************************************************************/

/***************************** Include Files *********************************/

#include <stdio.h>
#include <stdlib.h>
#include "xil_io.h"
#include "xil_exception.h"
#include "xparameters.h"
#include "xil_cache.h"
#include "xil_printf.h"
#include "xil_types.h"
#include "xscugic.h"

/************************** Constant Definitions *****************************/

/*

* The following constants map to the XPAR parameters created in the
* xparameters.h file. They are defined here such that a user can easily
* change all the needed parameters in one place.
*/
#define INTC_DEVICE_ID XPAR_SCUGIC_0_DEVICE_ID
#define INTC_DEVICE_INT_ID 0x0E

/**************************** Type Definitions *******************************/

/***************** Macros (Inline Functions) Definitions *********************/

/************************** Function Prototypes ******************************/
int ScuGicExample(u16 DeviceId);
int SetUpInterruptSystem(XScuGic *XScuGicInstancePtr);
void DeviceDriverHandler(void *CallbackRef);

/************************** Variable Definitions *****************************/

XScuGic InterruptController; /* Instance of the Interrupt Controller */
static XScuGic_Config *GicConfig; /* The configuration parameters of the
controller */

/*

* Create a shared variable to be used by the main thread of processing and
* the interrupt processing
*/
volatile static int InterruptProcessed = FALSE;

static void AssertPrint(const char8 *FilenamePtr, s32 LineNumber){
xil_printf("ASSERT: File Name: %s ", FilenamePtr);
xil_printf("Line Number: %d\r\n",LineNumber);
}

/*****************************************************************************/
/**
*

* This is the main function for the Interrupt Controller example.
*
* @param None.
*
* @return XST_SUCCESS to indicate success, otherwise XST_FAILURE.
*
* @note None.
*
****************************************************************************/
int main(void)
{
int Status;


/*
* Setup an assert call back to get some info if we assert.
*/
Xil_AssertSetCallback(AssertPrint);

xil_printf("GIC Example Test\r\n");

/*
* Run the Gic example , specify the Device ID generated in xparameters.h
*/
Status = ScuGicExample(INTC_DEVICE_ID);
if (Status != XST_SUCCESS) {
xil_printf("GIC Example Test Failed\r\n");
return XST_FAILURE;
}

xil_printf("Successfully ran GIC Example Test\r\n");
return XST_SUCCESS;

}

/*****************************************************************************/
/**
*

* This function is an example of how to use the interrupt controller driver

* (XScuGic) and the hardware device. This function is designed to

* work without any hardware devices to cause interrupts. It may not return

* if the interrupt controller is not properly connected to the processor in

* either software or hardware.
*

* This function relies on the fact that the interrupt controller hardware

* has come out of the reset state such that it will allow interrupts to be

* simulated by the software.
*

* @param DeviceId is Device ID of the Interrupt Controller Device,

* typically XPAR_<INTC_instance>_DEVICE_ID value from

* xparameters.h
*

* @return XST_SUCCESS to indicate success, otherwise XST_FAILURE
*

* @note None.
*
******************************************************************************/
int ScuGicExample(u16 DeviceId)
{
int Status;

/*

* Initialize the interrupt controller driver so that it is ready to
* use.
*/
GicConfig = XScuGic_LookupConfig(DeviceId);
if (NULL == GicConfig) {
return XST_FAILURE;
}

Status = XScuGic_CfgInitialize(&InterruptController, GicConfig,
GicConfig->CpuBaseAddress);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}


/*
* Perform a self-test to ensure that the hardware was built
* correctly
*/
Status = XScuGic_SelfTest(&InterruptController);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}


/*
* Setup the Interrupt System
*/
Status = SetUpInterruptSystem(&InterruptController);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}

/*
* Connect a device driver handler that will be called when an
* interrupt for the device occurs, the device driver handler performs
* the specific interrupt processing for the device
*/
Status = XScuGic_Connect(&InterruptController, INTC_DEVICE_INT_ID,
(Xil_ExceptionHandler)DeviceDriverHandler,
(void *)&InterruptController);

if (Status != XST_SUCCESS) {
return XST_FAILURE;
}

/*
* Enable the interrupt for the device and then cause (simulate) an
* interrupt so the handlers will be called
*/
XScuGic_Enable(&InterruptController, INTC_DEVICE_INT_ID);

/*
* Simulate the Interrupt
*/
Status = XScuGic_SoftwareIntr(&InterruptController,
INTC_DEVICE_INT_ID,
XSCUGIC_SPI_CPU0_MASK);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}

/*
* Wait for the interrupt to be processed, if the interrupt does not
* occur this loop will wait forever
*/
while (1) {
/*
* If the interrupt occurred which is indicated by the global
* variable which is set in the device driver handler, then
* stop waiting
*/
if (InterruptProcessed) {
break;
}
}

return XST_SUCCESS;

}

/******************************************************************************/
/**
*

* This function connects the interrupt handler of the interrupt controller to

* the processor. This function is separate to allow it to be customized for

* each application. Each processor or RTOS may require unique processing to

* connect the interrupt handler.
*

* @param XScuGicInstancePtr is the instance of the interrupt controller

* that needs to be worked on.
*

* @return None.
*

* @note None.
*
****************************************************************************/
int SetUpInterruptSystem(XScuGic *XScuGicInstancePtr)
{

/*

* Connect the interrupt controller interrupt handler to the hardware
* interrupt handling logic in the ARM processor.
*/
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
(Xil_ExceptionHandler) XScuGic_InterruptHandler,
XScuGicInstancePtr);

/*

* Enable interrupts in the ARM
*/
Xil_ExceptionEnable();

return XST_SUCCESS;
}

/******************************************************************************/
/**
*

* This function is designed to look like an interrupt handler in a device
* driver. This is typically a 2nd level handler that is called from the
* interrupt controller interrupt handler. This handler would typically
* perform device specific processing such as reading and writing the registers
* of the device to clear the interrupt condition and pass any data to an
* application using the device driver. Many drivers already provide this
* handler and the user is not required to create it.
*
* @param CallbackRef is passed back to the device driver's interrupt
* handler by the XScuGic driver. It was given to the XScuGic
* driver in the XScuGic_Connect() function call. It is typically
* a pointer to the device driver instance variable.
* In this example, we do not care about the callback
* reference, so we passed it a 0 when connecting the handler to
* the XScuGic driver and we make no use of it here.
*
* @return None.
*
* @note None.
*
****************************************************************************/
void DeviceDriverHandler(void *CallbackRef)
{
/*
* Indicate the interrupt has been processed using a shared variable
*/
InterruptProcessed = TRUE;
}
 Comments