Using Interrupts with WinAVR

Hello all,

This is an AVR specific problem. When I write a function for timer2 overflow as follows:

// Timer 2 overflow interrupt service routine interrupt(SIG_OVERFLOW2)//SIG_INTERRUPT0)//SIG_OVERFLOW2) { // Place your code here PORTD ^= _BV(7); }

and make with winavr, I get the following warnings:

E:/AVR/WinAVR/testfiles/isr.c:6: warning: return type defaults to `int' E:/AVR/WinAVR/testfiles/isr.c:6: warning: function declaration isn't a prototype E:/AVR/WinAVR/testfiles/isr.c: In function `interrupt': E:/AVR/WinAVR/testfiles/isr.c:6: warning: type of "__vector_4" defaults to "int" E:/AVR/WinAVR/testfiles/isr.c:9: warning: control reaches end of non-void function

When I check the main.lss file, I notice that the interrupt routine is not correctly placed in the inetrrupt vector, and hence the code doesnt work,

Can someone please tell me that is wrong here? Why cant I point the interrupt vector table towards my desired routine using this syntax and WinAVR?

Thanks in advance

Mak

Reply to
Mak
Loading thread data ...

It should read INTERRUPT(SIG_OVERFLOW2)

Yout defined a function interrupr returning an int.

He is right. interrupt(xxx) is no prototype. But you did not want to write a prototype, you wanted the macro INTERRUPT

You can, but you must use the correct spelling. All capital letters fpr this macro.

Regards, Kurt

--
Kurt Harders
PiN -Präsenz im Netz GITmbH
 Click to see the full signature
Reply to
Kurt Harders

1 > E:/AVR/WinAVR/testfiles/isr.c:6: warning: return type defaults to `int' 2 > E:/AVR/WinAVR/testfiles/isr.c:6: warning: function declaration isn't a > prototype 3 > E:/AVR/WinAVR/testfiles/isr.c: In function `interrupt': 4 > E:/AVR/WinAVR/testfiles/isr.c:6: warning: type of "__vector_4" defaults > to "int" 5 > E:/AVR/WinAVR/testfiles/isr.c:9: warning: control reaches end of

Looks to me like you need a return type on your function which in this case should be void. That should solve 1,2,3 and 5. I reckon 4 has something to do with your _BV() macro/function.

As for positioning your code in the vector table I'm not sure but in the IAR compiler you need to use a pre-processor command __irq to tell the compiler to use a return from interrupt at the end of the ISR. It might instruct the linker where to put it as well but I'm not sure.

Reply to
Tom

Thanks for the input, I believe the capital letters solves the problem, I am at peace now :).

Um... I may be defying the very basic laws of computer architecture, but can we design an interrupt which after completion, doesnt return to the place where its called from (i.e. continues from Program Counter+1), rather loads the PC with a completely different (for instance the beginning of a state machine (idle)) value?

Thanks

Reply to
Mak

What should be done with the baseline code state saved at the entry to the interrupt routine?

You'll have to decide e.g. what to do with the call stack of te code that was interrupted.

It is not difficult to fudge the return PC. It is difficult to do it so that nothing collapses.

--
Tauno Voipio
tauno voipio (at) iki fi
 Click to see the full signature
Reply to
Tauno Voipio

Actually, in all likelihood it should read

SIGNAL(SIG_OVERFLOW2)

You almost never want to use INTERRUPT. Check the avr-libc docs.

You also need to #include and/or somewhere.

Regards, -=Dave

--
Change is inevitable, progress is not.
Reply to
Dave Hansen

Thats true. I expected the OP to have a reason to use interrupt :-).

Regards, Kurt

--
Kurt Harders
PiN -Präsenz im Netz GITmbH
 Click to see the full signature
Reply to
Kurt Harders

You might want to look at the setjmp() and longjmp() functions

--
:wq
^X^Cy^K^X^C^C^C^C
Reply to
usenet

Please do not use longjump() in an interrupt service routine in an AVR - you'll end up with locked-up interrupt hardware.

--
Tauno Voipio
tauno voipio (at) iki fi
 Click to see the full signature
Reply to
Tauno Voipio

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.