Interrupts in library

General discussion on Package Manager Software.
Post Reply
Author
Message
Dafra
Posts: 30
Joined: 29 Nov 2010 21:40
Location: Brussels, Belgium

Interrupts in library

#1 Post by Dafra » 07 Jun 2011 16:48

Hi,

I want to make a library, but I use interrupts.
How can I do?

This would be similar to the USB library which also uses the interrupts.

Thank you
Dafra
Best Regards

Dafra

Dafra
Posts: 30
Joined: 29 Nov 2010 21:40
Location: Brussels, Belgium

Re: Interrupts in library

#2 Post by Dafra » 08 Jun 2011 13:34

Is it so possible ?

library :

void library_interrupt(){
...
}

and in the program

void interrupt {
void library_interrupt();
}

same as the usb library
Best Regards

Dafra

Muphy
Posts: 318
Joined: 24 Feb 2008 14:05
Location: Stonehaven Scotland

Re: Interrupts in library

#3 Post by Muphy » 08 Jun 2011 13:52

I think you will find that USB_Interrupt_Proc is not an interrupt function per se but is a regular function that is called within the actual interrupt function - check the examples in the help.

As I understand it, there can only be one interrupt routine and it must be in your source file and cannot be in a library. It would be pretty limiting to have the ISR in a library as there are many sources of interrupts and you generally want to be able to write code to handle one or more of them, you could not do that if the ISR was in a library.

It is entirely possible that you could have a function in a library that is called when a certain interrupt is triggered again I would refer you back to the help file for examples (Search for Interrupt).

M

Dafra
Posts: 30
Joined: 29 Nov 2010 21:40
Location: Brussels, Belgium

Re: Interrupts in library

#4 Post by Dafra » 16 Jun 2011 21:00

Ok, it's so that I say...
I find the answer with the RFid library...
Best Regards

Dafra

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Interrupts in library

#5 Post by filip » 14 Feb 2012 09:10

Hi,

It is not advisable that you put the interrupts in the library if you are not an experienced user,
as this may lead to some unpredictable results when using it with some other, custom codes.

Regards,
Filip.

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

Re: Interrupts in library

#6 Post by jpc » 14 Feb 2012 18:30

Dafra,

you certainly can put a specific ISR in a library, you will need to build it such that i can be simply called from within the interrupt procedure , this ISR should deal with its own flags and leave all other flags untouched. You also need to initialize this with its own Init-function providing all (global!) variables this ISR is using for which exactly the same rules are valid. Depending on the PIC family you will have to deal there with priority's as well. It is obvious that your ISR should be as fast as possible, it may not contain any local variables .
If any of the variables must be visible elsewhere it is gfood strategy to provide functions to access those if any risk of interference between ISR and main code is a risk.
As Filip states, not recommended if you are new to this but absolutely legitimate if you know how to do it.

to Muphy,

no, this is not just an ordinary procedure, it has to deal with interrupt flags at least.
Au royaume des aveugles, les borgnes sont rois.

Post Reply

Return to “Package Manager General”