UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Scholar pumaju1808
Scholar
581 Views
Registered: ‎08-14-2007

multiple Interrupt C code for Microblaze

Jump to solution

Hi,

I have a basic MB system , with Interrupt Controller, also I have two interrupt sources (In0 and In1) , which are concatenated and goes to the "intr[1:0]" port of the intc

Do you have some example C code to manage multiple input interrupt sources?

 I basically want to do an application where is prints:

"Interrupt happens for In0, performing task0 ..."

or 

"Interrupt happens for In1, performing task1 ..."

 

 

0 Kudos
1 Solution

Accepted Solutions
Xilinx Employee
Xilinx Employee
488 Views
Registered: ‎10-21-2010

Re: multiple Interrupt C code for Microblaze

Jump to solution

Hi @pumaju1808,

1. This is reasonable, but generally we register device driver level handler with XIntc_Connect, and then register user level handler with device driver handler. See example below

XIntc_Connect(&InterruptController, UARTLITE_INT_IRQ_ID, (XInterruptHandler)XUartLite_InterruptHandler, (void *)UartLitePtr);

Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler)XIntc_InterruptHandler, &InterruptController);

XUartLite_SetSendHandler(&UartLite, SendHandler, &UartLite);
XUartLite_SetRecvHandler(&UartLite, RecvHandler, &UartLite);

XUartLite_InterruptHandler is in the uartlite driver, while Send/RecvHandler are in application layer.

When an interrupt is triggered, the exception handling code in the BSP calls the first level interrupt handler (XIntc_InterruptHandler) in interrupt controller's driver. Based on the interrupt source, this handler then calls the appropriate device driver handler (XUartLite_InterruptHandler for uartlite interrupt), which in turn calls user level handlers (SendHandler and RecvHandler for Tx and Rx events)

2. The 4th arg to XIntc_Connect is a pointer to user data, which can be used in interrupt handler. For example, if you have a data structure with device level info, and need it in callback, you can pass it to XIntc_Connect

 

0 Kudos
7 Replies
Xilinx Employee
Xilinx Employee
538 Views
Registered: ‎10-21-2010

Re: multiple Interrupt C code for Microblaze

Jump to solution

Hi @pumaju1808,

You can refer to examples in device drivers shipped with SDK; for example, data/embeddedsw/XilinxProcessorIPLib/drivers/uartlite_v3_2/examples/xuartlite_intr_example.c

SetupInterruptSystem() shows how to register a handle for an interrupt source. To be more specific, XIntc_Connect() registers uartlite driver handler for uartlite interrupt source, and XUartLite_Set{Send/Recv}Handler registers application level handlers for Tx and Rx events.

If you have multiple interrupt sources from different devices, then you can register an handler for each device using XIntc_Connect(), which should in turn call application handlers

0 Kudos
Scholar pumaju1808
Scholar
506 Views
Registered: ‎08-14-2007

Re: multiple Interrupt C code for Microblaze

Jump to solution

Hi @sadanan, thanks for the answer,

I have a question regarding XIntc_Connect, I have these 2 external inputs that goes to the Intr controller, those inputs are not connected to any microblaze GPIO or anything, they just come from "outside" of the MB system

So trying to do my 2 XIntc_Connect functions for every input, my first attempts would be:

XIntc_Connect(IntcPtr, 0, (XInterruptHandler) Int0_handler,  ??)

XIntc_Connect(IntcPtr, 1, (XInterruptHandler) Int1_handler,  ??)

And then define every Interrupt handler:

Int0_Handler(void *CallbackRef){

printf("Interupt 0 happens"); }

Int1_Handler(void *CallbackRef){

printf("Interupt 1 happens"); }

My questions here are:

* Is this correct idea? please correct me in any part of the code

* In the XIntc_Connect function, about the 4th parameter, what should I put ?

intc.jpg

0 Kudos
Xilinx Employee
Xilinx Employee
489 Views
Registered: ‎10-21-2010

Re: multiple Interrupt C code for Microblaze

Jump to solution

Hi @pumaju1808,

1. This is reasonable, but generally we register device driver level handler with XIntc_Connect, and then register user level handler with device driver handler. See example below

XIntc_Connect(&InterruptController, UARTLITE_INT_IRQ_ID, (XInterruptHandler)XUartLite_InterruptHandler, (void *)UartLitePtr);

Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler)XIntc_InterruptHandler, &InterruptController);

XUartLite_SetSendHandler(&UartLite, SendHandler, &UartLite);
XUartLite_SetRecvHandler(&UartLite, RecvHandler, &UartLite);

XUartLite_InterruptHandler is in the uartlite driver, while Send/RecvHandler are in application layer.

When an interrupt is triggered, the exception handling code in the BSP calls the first level interrupt handler (XIntc_InterruptHandler) in interrupt controller's driver. Based on the interrupt source, this handler then calls the appropriate device driver handler (XUartLite_InterruptHandler for uartlite interrupt), which in turn calls user level handlers (SendHandler and RecvHandler for Tx and Rx events)

2. The 4th arg to XIntc_Connect is a pointer to user data, which can be used in interrupt handler. For example, if you have a data structure with device level info, and need it in callback, you can pass it to XIntc_Connect

 

0 Kudos
Scholar pumaju1808
Scholar
467 Views
Registered: ‎08-14-2007

Re: multiple Interrupt C code for Microblaze

Jump to solution

Hi @sadanan

I didn't get the part of Xil_ExceptionRegisterHandler , how should I apply this function in my particular example?

I dont have any of those pre-defined functions as in UART IP (like XUartLite_SetSendHandler or XUartLite_SetRecvHandler), since my interrupt sources are external to the MB system

0 Kudos
Xilinx Employee
Xilinx Employee
450 Views
Registered: ‎10-21-2010

Re: multiple Interrupt C code for Microblaze

Jump to solution

If you're using XIntc driver, then you can always register XIntc_InterruptHandler with Xil_ExceptionRegisterHandler. If you have a custom driver for INTC, then you have to define a handler of type Xil_ExceptionHandler in your custom driver.

Then, for each of your interrupt sources, you should register a handler of type XInterruptHandler, with XIntc driver (if you have a custom driver, it could handle this differently). This handler can be in a device driver, in which case, the driver handler should have a provision to register application level handler (similar to the uartlite example), or you can directly register an application level handler with XIntc driver, which should then process the interrupt appropriately (for example, if the interrupt can be triggered for multiple events like tx/rx, then your handler should be able to understand whether its a tx interrupt or rx interrupt)

Exception type == Interrupt => Branch to XIntc_InterruptHandler (registered by Xil_ExceptionRegisterHandler) => Determine the interrupt source => Branch to handler of the interrupt source (registered by XIntc_Connect) => If this is a handler is provided by device driver, process the interrupt and branch to user level handler. If this is a user level handler, process the interrupt as needed

0 Kudos
Scholar pumaju1808
Scholar
413 Views
Registered: ‎08-14-2007

Re: multiple Interrupt C code for Microblaze

Jump to solution

Thakns @sadanan for your explanation

My doubt about "Xil_ExceptionRegisterHandler" function was more in the sense that I have a GPIO example interrupt (see attach), in there I see next flow:

1. XGpio_Initialize()

2. XGpioSetupIntrSystem() --> where it calls XIntc_Initialize(), XInt_Connect(), XIntc_Enable(), XIntc_Start()

3. wait loop for interrupt

4. GpioDisableIntr()

5. In parallel, the Interrupt Handler definition

On any part of this code I see "Xil_ExceptionRegisterHandler" funcion being used, so I was wondering why or when this function should be used.

 

0 Kudos
Xilinx Employee
Xilinx Employee
395 Views
Registered: ‎10-21-2010

Re: multiple Interrupt C code for Microblaze

Jump to solution

Hi @pumaju1808,

You should use Xil_ExceptionRegisterHandler to register a handler in interrupt controller driver for exceptions of type interrupt. You should do this once per application, irrespective of the number of interrupt sources you have. However, if you want to handle other exceptions (ex. aborts), you can register other handlers using Xil_ExceptionRegisterHandler, but with a different exception ID

0 Kudos