interrupt tinkering

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

Is there a way I can add instructions to the enter and exit of an ISR without declaring it naked and putting my own push and pops in the routine?

i.e:

ISR(USART_RX_vect)
{
uint8_t timer_temp = TCCR2B;
TCCR2B = 0; // stop timer 2

uint8_t texp_rx = UDR0;

blah; // code body using a few registers
blah;
blah;

TCCR2B = timer_temp; // restore timer2
}

generates:

ISR(USART_RX_vect)
{
push blah
in blah
push blah
clr blah
push blah
push blah
push blah
push blah

lds r18, TCCR2B
sts TCCR2B, r1

sts TCCR2B, r18

blah // some code that uses registers
blah
blah

pop blah
pop blah
pop blah
pop blah
pop blah
out blah
pop blah

I would like to stop and start the timer at the earliest time and the latest posible time.

ISR(USART_RX_vect)
{
push blah
in blah
push blah
clr r1
lds blah,TCCR2B <----- here!!!
sts TCCR2B,r1
push blah
push blah
push blah
push blah

blah // some code that uses registers

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

If you don't make it naked then your first opportunity to get an instruction in (using asm("") probably if you want complete control) is after the prologue just as you have found.

So what's the issue about making it naked? (presumably because you can't predict what other registers the compiler might use if you have to do your own push/pop's ?). If you keep it "lean and mean" the register usage should be fairly predicatble anyway.

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

Yeah, unfortunately I can't keep it mean and lean, maybe a pitfall of being a newbie and not knowing what i'm doing! I had the idea of compiling and then cut and pasting the instructions in to the routine with a tweak. I thought maybe there was an easy way of doing so.

Cheers.

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

I'm kind of wondering what it is you are doing with the timer where you need to stop it so accurately at the point of UART reception anyway?

(just being nosey!)

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

errm probably something that maybe questionable by a seasoned C programmer! The problem is the timer is used in a routine that polls the timer overflow and this could happen more than 1 time in the short duration of the interrupt routine.

I think the problem really lies in the fact I wrote the code in asm that was quite tight in register/memory/time usage and now whilst trying to learn c and porting the code it needs to be re-jigged a bit to accomodate. All part of the learning process (I keep telling myself!)