cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Voyager
Voyager
1,410 Views
Registered: ‎05-25-2016

MicroBlaze - multiple callback references for interrupt?

Jump to solution

I have a timer running using interrupts in a microblaze design.  I noticed in Xilinx examples the call back reference passed is usually the timer instance.  I'm doing this as well.  Is there a way to pass more data, another structure pointer or void function pointer in addition to the default CallBackRef?  I'm wondering if I can pass more information to the timer interrupt handler.

 

Here is my binding for the timer interrupt:

 

	status = XIntc_Connect(ptrXintc, XPAR_INTC_0_TMRCTR_0_VEC_ID,
							(XInterruptHandler)TimerCounterHandler, (void*)ptrXtmrCtr0);

The ptrXtmrCtr0 consists of the following:

 

#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "xgpio.h"
#include "xintc.h"
#include "xtmrctr.h"
#include "xspi.h"


u32 peripheral_init();

XGpio* ptrGPIO_LED;
XIntc* ptrXintc;
XTmrCtr* ptrXtmrCtr0;
XSpi* ptrXSpi0;
XSpi_Config* Spi0_cfg;


int main()
{
    init_platform();


	XGpio GPIO_LED;
	XIntc intc;
	XTmrCtr XTmrCtr0;
	XSpi XSpi0;


	ptrGPIO_LED = &GPIO_LED;
	ptrXintc = &intc;
	ptrXtmrCtr0 = &XTmrCtr0;
	ptrXSpi0 = &XSpi0;


    peripheral_init();
    xil_printf("-Peripherals Configured!\n");


	microblaze_enable_interrupts();
	xil_printf("-Interrupts Enabled!\n");

    XTmrCtr_Start(ptrXtmrCtr0, XPAR_AXI_TIMER_0_DEVICE_ID);
    xil_printf("-Timer Started!\n");


    while(1);

    cleanup_platform();
    return 0;
}

 

Basically I'm wondering if I can pass more information to an interrupt service routine than just the call back reference that consists of a pointer to the peripheral instance.  If I can't pass information to a service routine via the callback it seems as though I have to make the information I want to the interrupt routine to see global.  Is that a bad thing? To make stuff (data structures etc...) global so an ISR can see it?

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Scholar
Scholar
2,150 Views
Registered: ‎03-22-2016

@m3atwad You can pass any pointer you want. Make a struct with whatever you wish inside and pass a pointer to it then cast it back in the ISR. 

vitorian.com --- We do this for fun. Always give kudos. Accept as solution if your question was answered.
I will not answer to personal messages - use the forums instead.

View solution in original post

0 Kudos
3 Replies
Highlighted
Scholar
Scholar
2,151 Views
Registered: ‎03-22-2016

@m3atwad You can pass any pointer you want. Make a struct with whatever you wish inside and pass a pointer to it then cast it back in the ISR. 

vitorian.com --- We do this for fun. Always give kudos. Accept as solution if your question was answered.
I will not answer to personal messages - use the forums instead.

View solution in original post

0 Kudos
Highlighted
Voyager
Voyager
1,386 Views
Registered: ‎05-25-2016

Ok cool.  Just wanted to check because it seemed too simple to be a legit solution.

 

Thanks!

Highlighted
Scholar
Scholar
1,383 Views
Registered: ‎03-22-2016

@m3atwad

It is a very common pattern in C

vitorian.com --- We do this for fun. Always give kudos. Accept as solution if your question was answered.
I will not answer to personal messages - use the forums instead.
0 Kudos