CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

Error compilation when trying write an interrupt handler

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ElectronPIC



Joined: 26 Dec 2016
Posts: 9

View user's profile Send private message

Error compilation when trying write an interrupt handler
PostPosted: Sun Dec 03, 2017 9:20 am     Reply with quote

Hi everyone!

I want to write my own interrupt dispatcher. To start I've just copied the dispatcher generated automatically by CCS:

Code:

#INT_GLOBAL
void InterruptDispatcher(void)
{

#ASM
MOVWF  04
MOVFF  STATUS,05
MOVFF  BSR,06
MOVLB  0
MOVFF  FSR0L,0C
MOVFF  FSR0H,07
MOVFF  FSR1L,08
MOVFF  FSR1H,09
MOVFF  FSR2L,0A
MOVFF  FSR2H,0B
MOVFF  PRODL,12
MOVFF  PRODH,13
MOVFF  PCLATH,14
MOVFF  TABLAT,15
MOVFF  TBLPTRL,16
MOVFF  TBLPTRH,17
MOVFF  00,0E
MOVFF  01,0F
MOVFF  02,10
MOVFF  03,11
BTFSS  PIE1.RCIE
GOTO   0060
BTFSC  PIR1.RCIF
GOTO   0394
BTFSS  PIE1.TXIE
GOTO   006C
BTFSC  PIR1.TXIF
GOTO   0412
BTFSS  PIE1.CCP1IE
GOTO   0078
BTFSC  PIR1.CCP1IF
GOTO   0476
MOVFF  0E,00
MOVFF  0F,01
MOVFF  10,02
MOVFF  11,03
MOVFF  0C,FSR0L
MOVFF  07,FSR0H
BSF    07.7
MOVFF  08,FSR1L
MOVFF  09,FSR1H
MOVFF  0A,FSR2L
MOVFF  0B,FSR2H
MOVFF  12,PRODL
MOVFF  13,PRODH
MOVFF  14,PCLATH
MOVFF  15,TABLAT
MOVFF  16,TBLPTRL
MOVFF  17,TBLPTRH
MOVF   04,W
MOVFF  06,BSR
MOVFF  05,STATUS
RETFIE 0
#ENDASM
}


But I get this error when compiling: "Invalid interrupt directive Can not mix GLOBAL with non-global"

I'm using: PIC18F2550, CCS 5.061.

Is it right what I'm trying to do? Am I missing something?
PCM programmer



Joined: 06 Sep 2003
Posts: 20370

View user's profile Send private message

PostPosted: Sun Dec 03, 2017 9:43 am     Reply with quote

It means you can't have #int_global and #int_rda (for example) at the
same time. If you use #int_global, ALL interrupt handling must be done
by you in the #int_global routine.

Do a forum search for #int_global to find examples of how to do this.

Also look at the CCS example file ex_glint.c in your compiler examples
folder on your PC.
Ttelmah



Joined: 11 Mar 2010
Posts: 13396

View user's profile Send private message

PostPosted: Sun Dec 03, 2017 10:23 am     Reply with quote

and (important to understand), the only reason to do this, is if you have a handler that must be handled really quickly. In this case you only save the registers that are used in this handler, and get in an out of this ASAP.
If you call multiple handlers, your global has to save every register used in all the handlers, which then means you end up duplicating the CCS handler and gain nothing.....
Your handler is potentially handling INT_RDA, INT_TBE, and INT_CCP.

If you want one of these handled quickly, leave CCS to handle the rest, and declare just the interrupt you want dealt with quickly as a high priority interrupt. If you declare is as 'FAST', then it'll be called like the INT_GLOBAL, but as a high priority interrupt (you need to have HIGH_INTS=TRUE as well). You will be responsible only for saving the registers it uses, and things will be as fast as possible. Smile
ElectronPIC



Joined: 26 Dec 2016
Posts: 9

View user's profile Send private message

PostPosted: Sun Dec 03, 2017 2:56 pm     Reply with quote

PCM programmer wrote:
It means you can't have #int_global and #int_rda (for example) at the
same time. If you use #int_global, ALL interrupt handling must be done
by you in the #int_global routine.

Do a forum search for #int_global to find examples of how to do this.

Also look at the CCS example file ex_glint.c in your compiler examples
folder on your PC.



PCM programmer, thanks for your reply.

That means that I should delete #int_rda and make sure that that isr is in the direction invoked by GOTO instruction, in the interrupt handler?
ElectronPIC



Joined: 26 Dec 2016
Posts: 9

View user's profile Send private message

PostPosted: Sun Dec 03, 2017 3:03 pm     Reply with quote

Ttelmah wrote:
and (important to understand), the only reason to do this, is if you have a handler that must be handled really quickly. In this case you only save the registers that are used in this handler, and get in an out of this ASAP.
If you call multiple handlers, your global has to save every register used in all the handlers, which then means you end up duplicating the CCS handler and gain nothing.....
Your handler is potentially handling INT_RDA, INT_TBE, and INT_CCP.

If you want one of these handled quickly, leave CCS to handle the rest, and declare just the interrupt you want dealt with quickly as a high priority interrupt. If you declare is as 'FAST', then it'll be called like the INT_GLOBAL, but as a high priority interrupt (you need to have HIGH_INTS=TRUE as well). You will be responsible only for saving the registers it uses, and things will be as fast as possible. Smile




Ttelmah, thanks for your reply.

What I wanted was to make sure that all registers modified by all isrs are being saved.
Is the compiler generated interrupt handler already doing this?
Ttelmah



Joined: 11 Mar 2010
Posts: 13396

View user's profile Send private message

PostPosted: Sun Dec 03, 2017 3:17 pm     Reply with quote

Yes.

In fact the one complaint about it, is that if you do something very minor in your interrupts (so no array accesses, but just increment a simple counter for example), it still saves everything, including the index registers.
PCM programmer



Joined: 06 Sep 2003
Posts: 20370

View user's profile Send private message

PostPosted: Sun Dec 03, 2017 8:44 pm     Reply with quote

ElectronPIC wrote:

That means that I should delete #int_rda

Yes, delete your existing #int_rda function.

ElectronPIC wrote:

and make sure that that isr is in the direction invoked by GOTO instruction,
in the interrupt handler?

Ttelmah has posted sample code of how to do this in the following thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=44031
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group