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

CCS 3.249 producing erroneous interrupt code?

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



Joined: 17 Aug 2007
Posts: 19

View user's profile Send private message

CCS 3.249 producing erroneous interrupt code?
PostPosted: Sun Aug 19, 2007 2:10 pm     Reply with quote

I have placed my entire project here: http://wintermute.csbnet.se/~zilog/kod/styrkort_riktiga/ for you to have a look at. What is interesting is that during close examination of the assembler code in main.lst, I have found that the assembler code for #INT_EXT3 high void ChainHighCurrentIsr(void) in chain.c which is present in main.lst at adress 0x1F18 destroys the contents of register 0x5A8. Have a look below:
Code:

.................... #INT_EXT3 high
.................... void ChainHighCurrentIsr(void)
.................... {
.................... #ifdef DEBUG_ISR
....................   ScopeDebugViaAD(3);
01F18:  MOVLW  03
01F1A:  MOVLB  5
01F1C:  MOVWF  xA8
01F1E:  MOVLB  0
01F20:  CALL   0E70


Am I just missing something here, or does the compiler actually make a mistake here, and makes similar mistakes in other places as well? I found this searching for a reason that my project executes random adresses in memory, making a mess of the execution.
Ttelmah
Guest







PostPosted: Sun Aug 19, 2007 2:32 pm     Reply with quote

That is what 'ScopeDebugViaAD does. The value passed, is put into the register at 05A8, and is then used in the routine itself. 5A8, is used as a scratch for this putpose, by each routine calling this sub.

Best Wishes
Mogge



Joined: 13 Aug 2007
Posts: 14
Location: Sweden

View user's profile Send private message

PostPosted: Sun Aug 19, 2007 4:00 pm     Reply with quote

This is inside an high pri interrupt routine.

The point is that the used register is not saved before being used here, and not saved afterwards, although it is used elswhere in the program.

Here is the relvant asembler from high pri int, snipped from th elst file on the link zilog gave:

In high pri interrupt:
Code:


00008:  GOTO   00E4

000E4:  MOVLB  0
000E6:  MOVFF  FE9,1F
000EA:  MOVFF  FEA,1A
000EE:  MOVFF  FE1,1B
000F2:  MOVFF  FE2,1C
000F6:  MOVFF  FD9,1D
000FA:  MOVFF  FDA,1E
000FE:  MOVFF  FF3,26
00102:  MOVFF  FF4,27
00106:  MOVFF  FFA,28
0010A:  MOVFF  FFB,29
0010E:  MOVFF  00,21
00112:  MOVFF  01,22
00116:  MOVFF  02,23
0011A:  MOVFF  03,24
0011E:  MOVFF  04,25
00122:  BTFSS  FF0.5
00124:  GOTO   012E
00128:  BTFSC  FF0.2
0012A:  GOTO   1F18

01F18:  MOVLW  03
01F1A:  MOVLB  5
01F1C:  MOVWF  xA8


i.e: some registers but not x5A8 saved, then interrupt flags are checked to cause jump to the right routine, then x5A8 is used.
Ttelmah
Guest







PostPosted: Mon Aug 20, 2007 3:34 am     Reply with quote

The compiler never 'saves' anything of this sort.
Don't confuse variables, and registers.
The only things that are saved, are _registers_. ie., the internal stuff in the processor itself (note that the stuff being 'saved', is all up in the Fxx area), and processor scratch values (the five bytes of the universal scratch area at the base of memory). _Variables_ (values used inside functions, _are not saved for interrupts_. However they are _protected_, by disabling interrupts around the routines themselves. So in this case, high priority interrupts will be disabled around the ScopeDebugViaAD function, to avoid both 'normal' routines, and those in the interrupt using the same area at the _same time_. However both _will_ use the same area, so if you rely on the value being in some way saved when you interrupt, it won't be.
This is why if you want to use the same routine, inside interrupts,and in the main code, you need to generate two copies, if you want them to be independant, and also avoid having the interrupts disabled...

Best Wishes
Mogge



Joined: 13 Aug 2007
Posts: 14
Location: Sweden

View user's profile Send private message

PostPosted: Wed Aug 22, 2007 5:23 am     Reply with quote

OK
Thank you for the insight Smile
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