ISR push pop optimize

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have WinAvr 20090303 and PN. Is there any way to keep the compiler from push / pop so many regs. ( even if only a few are used ?

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do not call other functions in the ISR. Turn on optimization -Os.

Stealing Proteus doesn't make you an engineer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah i have done both of those things.

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Then it should not push excessive registers.

Post your ISR code.

JW

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you do call functions from the ISR:

1) if possible define the "static inline"

2) at any rate put them in the same .c file as the ISR() itself so the compiler is free to inline if it chooses to, either way, because it can "see" the function at the time the ISR is compiled it should be able to see which registers it's using.

But in fast response MCU interrupt handlers the ultimate is to do nothing in an ISR but set a flag to say it occurred and let the mainline handle he rest at leisure. Though there may be some timing sensitive stuff that has no option but to be done within the ISR. But the bottom line is always "lean and mean"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is code from FATFS 7e. I answered ArnoldB wrong, since the ISR does make a call( missed it before i posted ). So with a call w/in an ISR, I guess there's not much else to be done than what's been recommended. I tried putting called function in main.c and got undefined reference errors in mmc.c. I don't have time to try to fix those.disk_timerproc()uses 2 static volatile vars local to mmc.c and 1 local, but the whole routine ONLY uses 1 reg. Ok careful programming techniques, but no compiler setting to optimize context saves for this situation.

Now i know, thanks.

in main.c
 ISR(RTC_OVF_vect)
{
	Timer++;			/* Performance counter for this module */
	disk_timerproc();	/* Drive timer procedure of low level disk I/O module */
}

in   mmc.c
	void disk_timerproc (void)
{
   BYTE n;

   n=Timer1;                  /* 100Hz decrement timer */
   if(n)
      Timer1 = --n;
   n=Timer2;
   if(n)
      Timer2 = --n;
} 

main.lss

ISR(RTC_OVF_vect)
{
     382:	1f 92       	push	r1
     384:	0f 92       	push	r0
     386:	0f b6       	in	r0, 0x3f	; 63
     388:	0f 92       	push	r0
     38a:	11 24       	eor	r1, r1
     38c:	2f 93       	push	r18
     38e:	3f 93       	push	r19
     390:	4f 93       	push	r20
     392:	5f 93       	push	r21
     394:	6f 93       	push	r22
     396:	7f 93       	push	r23
     398:	8f 93       	push	r24
     39a:	9f 93       	push	r25
     39c:	af 93       	push	r26
     39e:	bf 93       	push	r27
     3a0:	ef 93       	push	r30
     3a2:	ff 93       	push	r31
	Timer++;			/* Performance counter for this module */
     3a4:	80 91 bd 20 	lds	r24, 0x20BD
     3a8:	90 91 be 20 	lds	r25, 0x20BE
     3ac:	01 96       	adiw	r24, 0x01	; 1
     3ae:	80 93 bd 20 	sts	0x20BD, r24
     3b2:	90 93 be 20 	sts	0x20BE, r25
	disk_timerproc();	/* Drive timer procedure of low level disk I/O module */
     3b6:	0e 94 56 02 	call	0x4ac	; 0x4ac 
}
     3ba:	ff 91       	pop	r31
     3bc:	ef 91       	pop	r30
     3be:	bf 91       	pop	r27
     3c0:	af 91       	pop	r26
     3c2:	9f 91       	pop	r25
     3c4:	8f 91       	pop	r24
     3c6:	7f 91       	pop	r23
     3c8:	6f 91       	pop	r22
     3ca:	5f 91       	pop	r21
     3cc:	4f 91       	pop	r20
     3ce:	3f 91       	pop	r19
     3d0:	2f 91       	pop	r18
     3d2:	0f 90       	pop	r0
     3d4:	0f be       	out	0x3f, r0	; 63
     3d6:	0f 90       	pop	r0
     3d8:	1f 90       	pop	r1
     3da:	18 95       	reti

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This all is so trivial that it deserves to be written in asm.

Or is it just my C hatred showing through? ;-)

JW

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I don't have time to try to fix those.
Sure, and after you lied to us about the use of functions you expect us to fix your problem.

Stealing Proteus doesn't make you an engineer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you can't put the disk_timerproc() into main.c then why not put the ISR() into mmc.c?

(Just be careful if you ever update the FatFs files as Chan's next version of mmc.c will lose your modification)

Don't forget to add:

#include 

to the top of mmc.c

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

no compiler setting to optimize context saves for this situation

...or mod for inline? (I'd speculate that would help. I guess if the system was heavily-loaded it might be significant. Then drop in the simple code directly, one way or the other, as suggested. Or do it in-line. A few microseconds every 10ms. is <1% of AVR. And from all indications Tinyfatfs would be enough but the Big Dog has been trotted out for the hunt.)

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Clawson, I moved the ISR to mmc.c and that helped big time!

Quote:
Sure, and after you lied to us about the use of functions you expect us to fix your problem.

1) Since it is a general programming skills question, it makes no sense to LIE. Arrogant of you to accuse a stranger when you have no evidence ( which suspicion is not )to begin with.

2) I didn't ASK or hint for anybody to fix them. My last post's last sentence was a goodbye.

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1