Interrupt Return

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

Is there anyway to exit an interrupt like a break or return?

Life Is Like A Bucket Of Chicken.

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

A return statement should work. You may want to investigate what your compiler does with that, mine causes a jump to the epilog of the ISR that restores all registers and uses an RETI to return. If you mean an immediate exit, you can probably insert one using inline assembly. Hope you know what you are doing then.
Dave Raymond

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

The compiler I'm using is AVR-GCC

Life Is Like A Bucket Of Chicken.

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

Simply use "return". The compiler will see that it is an ISR and generate the proper code.

Regards,
Steve A.

The Board helps those that help themselves.

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

You are over thinking. The compiler is pretty smart.

Simple example-

ISR(TIMER0_COMPA_vect){
    if(PORTB) return;
    PORTC=0;
}

produces this-

ISR(TIMER0_COMPA_vect){
  b6:	1f 92       	push	r1
  b8:	0f 92       	push	r0
  ba:	0f b6       	in	r0, 0x3f
  bc:	0f 92       	push	r0
  be:	11 24       	eor	r1, r1
  c0:	8f 93       	push	r24
if(PORTB) return;
  c2:	85 b1       	in	r24, 0x05
  c4:	88 23       	and	r24, r24
  c6:	09 f4       	brne	.+2 
PORTC=0;
  c8:	88 b9       	out	0x08, r24
  ca:	8f 91       	pop	r24
  cc:	0f 90       	pop	r0
  ce:	0f be       	out	0x3f, r0
  d0:	0f 90       	pop	r0
  d2:	1f 90       	pop	r1
  d4:	18 95       	reti

notice how the return works- it simply branches over the portc part, and restores the saved registers on the stack. It knows it can't just 'ret' in the isr, but has to restore the previously saved registers and return with interrupts enabled again. Other non-isr functions may or may not compile a 'return' to a 'ret', depending on whether any registers were saved at the start of the function, etc. You are in a high(er) level language, and the return statement is not a literal 'ret' instruction, but simply a statement that tells the compiler that its time to exit the function (and if not told, it assumes you want to exit at the end of it). The compiler knows what to do to make that happen, and still keep everything 'in order'.