Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
bobgardner
PostPosted: Sep 18, 2007 - 05:54 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21257
Location: Orlando Florida

I'll start out with an imagrcraft example for a usart rx interrupt... someone kindly quote this and add a gcc exmple and a CV example? I think a side by side comparison will show how to convert from one compiler to another more easily.
Code:

//---------------------------
//imagecraft example
//required h files
#include <iom32v.h> //

//handler declaration
#pragma interrupt_handler uart_rx_isr:iv_USART_RX
void uart_rx_isr(void){
  //rest of code
}
//------------------------

//---------------------------
//gcc example
//h files

//handler


//--------------------------


//---------------------------
//codevision example

//h files

//handler

//---------------------------

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
lfmorrison
PostPosted: Sep 18, 2007 - 06:03 PM
Raving lunatic


Joined: Dec 08, 2004
Posts: 4719
Location: Nova Scotia, Canada

Here's the AVR-GCC equivalent:
Code:
//---------------------------
//imagecraft example
//required h files
#include <iom32v.h> //

//handler declaration
#pragma interrupt_handler uart_rx_isr:iv_USART_RX
void uart_rx_isr(void){
  //rest of code
}
//------------------------

//---------------------------
//gcc example
//required h files
#include <avr/io.h>
#include <avr/interrupt.h> //

//handler declaration
// The vector name (USART_RXC_vect in this case)
// will vary from part to part, based on the
// name given to that vector in your part's
// datasheet.
ISR(USART_RXC_vect){
  //rest of code
}
//--------------------------




//---------------------------
//codevision example

//h files

//handler

//---------------------------

 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Sep 18, 2007 - 06:05 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21257
Location: Orlando Florida

Looks simpler than I imagined so far.....

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
clawson
PostPosted: Sep 18, 2007 - 06:21 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62281
Location: (using avr-gcc in) Finchingfield, Essex, England

Code:
//---------------------------
//imagecraft example
//required h files
#include <iom32v.h> //

//handler declaration
#pragma interrupt_handler uart_rx_isr:iv_USART_RX
void uart_rx_isr(void){
  //rest of code
}
//------------------------

//---------------------------
//gcc example
//required h files
#include <avr/io.h>
#include <avr/interrupt.h> //

//handler declaration
// The vector name (USART_RXC_vect in this case)
// will vary from part to part, based on the
// name given to that vector in your part's
// datasheet.
ISR(USART_RXC_vect){
  //rest of code
}
//--------------------------

//---------------------------
//codevision example
//h files
#include <mega32.h>

//handler
// the bit that actually hooks the right vector in
// this is the USART_RXC that comes from mega32.h. As
// for GCC the names will vary from AVR to AVR
interrupt [USART_RXC] my_name_for_rx_isr(void) {
  //rest of code
}
//---------------------------

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Sep 18, 2007 - 06:36 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21257
Location: Orlando Florida

Cool stuff. I hope I'll be able to find this next time I try to port an example! Thanks!

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
david.prentice
PostPosted: Sep 18, 2007 - 06:56 PM
10k+ Postman


Joined: Feb 12, 2005
Posts: 16297
Location: Wormshill, England

I have files that will compile with PIC, 8051 and AVR. Compilers for each of these targets have different syntax for declaring an ISR.

I prefer to keep source code as portable as possible while using one common header file that copes with the differences.

However those that require #pragma make it very awkward to construct a generic #include "mcu.h" that defines correct macros for each mcu and compiler combination. Similarly a #asm is also not really allowed within a pre-processor expansion.

Would it not be nice if all C compiler vendors followed a similar syntax ! Not only this but my neighbour would love to fly his weaners to overcome the current Foot and Mouth restrictions.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
glitch
PostPosted: Sep 18, 2007 - 09:07 PM
Raving lunatic


Joined: Jan 12, 2002
Posts: 7829
Location: Canada

Code:
//---------------------------
//IAR example - AVR IAR Compiler [ICCAVR] (Current Version)
//h files
#include <iom32.h> // MCU include
#include <inavr.h> // Architecture include
//brings in __enable_interrupt() and __disable_interrupt()

//handler declaration
#pragma vector=USART_RXC_vect
__interrupt void my_name_for_rx_isr(void) {
  //rest of code
}
//---------------------------

//---------------------------
//IAR example - A90 IAR Compiler [ICCA90] (Old Version)
//h files
#include <iom32.h> // MCU include
#include <ina90.h> // Architecture include
// brings in _SEI() and _CLI()

//handler declaration
interrupt[USART_RXC_vect] void my_name_for_rx_isr(void) {
  //rest of code
}
//---------------------------

//---------------------------
//Rowley CrossWorks example
//h files
#include <ATmega32.h> // MCU include

//handler declaration
void my_name_for_rx_isr(void) __interrupt[UARTRX_VECTOR]
{
  //rest of code
}
//---------------------------

//---------------------------
//SPJ Systems' CAVR
//h files
#include <ATmega32.h> // MCU include

//handler declaration
interrupt(USART_RXC) void my_name_for_rx_isr(void) {
  //rest of code
}
//---------------------------

//---------------------------
//imagecraft example
//required h files
#include <iom32v.h> //

//handler declaration
#pragma interrupt_handler my_name_for_rx_isr:iv_USART_RX
void my_name_for_rx_isr(void){
  //rest of code
}
//------------------------

//---------------------------
//gcc example
//required h files
#include <avr/io.h>
#include <avr/interrupt.h> //

//handler declaration
// The vector name (USART_RXC_vect in this case)
// will vary from part to part, based on the
// name given to that vector in your part's
// datasheet.
ISR(USART_RXC_vect){
  //rest of code
}
//--------------------------

//---------------------------
//codevision example
//h files
#include <mega32.h>

//handler
// the bit that actually hooks the right vector in
// this is the USART_RXC that comes from mega32.h. As
// for GCC the names will vary from AVR to AVR
interrupt [USART_RXC] my_name_for_rx_isr(void) {
  //rest of code
}
//---------------------------


Added IAR (new & old) Since many of the Atmel APP notes are based on IAR code, both new and old versions.

Also, for completeness, added Rowley CrossWorks (based on the documentation for it) as well as SPJ System's CAVR (Also based on the documentation).


Last edited by glitch on Sep 18, 2007 - 10:58 PM; edited 1 time in total
 
 View user's profile Send private message  
Reply with quote Back to top
glitch
PostPosted: Sep 18, 2007 - 10:54 PM
Raving lunatic


Joined: Jan 12, 2002
Posts: 7829
Location: Canada

Code:
//---------------------------
// IAR - AVR IAR Compiler [ICCAVR] (Current Version)

// required includes
#include <processor-specific include>
#include <inavr.h> // Architecture include
// brings in __enable_interrupt() and __disable_interrupt()
// not requred for the ISR itself, but will be needed to
// enable interrupts in your code

//handler declaration
#pragma vector=interrupt-vector-name
__interrupt void my_name_for_this_isr(void) {
  //rest of code
}
// NOTE: The ISR function must immediately follow the #pragma

//---------------------------

//---------------------------
// IAR - A90 IAR Compiler [ICCA90] (Old Version)

// required includes
#include <processor-specific include>
#include <ina90.h> // Architecture include
// brings in _SEI() and _CLI()
// not requred for the ISR itself, but will be needed to
// enable interrupts in your code

//handler declaration
interrupt[interrupt-vector-name] my_name_for_this_isr(void) {
  //rest of code
}
//---------------------------

//---------------------------
// gcc-avr

// required includes
#include <avr/io.h>
#include <avr/interrupt.h>
// be sure to set the correct processor model in the make file

//handler declaration
ISR(interrupt-vector-name){
  //rest of code
}
//--------------------------

//---------------------------
// ImageCraft ICC for AVR

// required includes
#include <processor-specific include>

//handler declaration
#pragma interrupt_handler my_name_for_this_isr : interrupt-vector-name
void my_name_for_this_isr(void){
  //rest of code
}
// NOTE: The ISR function does not need to immediately follow the #pragma
//------------------------

//---------------------------
// HP InfoTech CodeVisionAVR

// required includes
#include <processor-specific include>

//handler declaration
interrupt [interrupt-vector-name] my_name_for_this_isr(void) {
  //rest of code
}
//---------------------------

//---------------------------
// HP InfoTech CodeVisionAVR
// alternate

// required includes
#include <io.h>
// be sure to set the correct processor model in the project options

//handler declaration
interrupt [interrupt-vector-name] my_name_for_this_isr(void) {
  //rest of code
}
//---------------------------

//---------------------------
// Rowley CrossWorks

// required includes
#include <processor-specific include>

//handler declaration
void my_name_for_this_isr(void) __interrupt[interrupt-vector-name]
{
  //rest of code
}
//---------------------------

//---------------------------
// SPJ Systems' CAVR

// required includes
#include <processor-specific include>

//handler declaration
interrupt(interrupt-vector-name) void my_name_for_this_isr(void) {
  //rest of code
}
//---------------------------


Made it more generic, by abstracting out the processor, function, and vector names.


Last edited by glitch on Sep 19, 2007 - 04:30 AM; edited 2 times in total
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Sep 18, 2007 - 11:12 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21257
Location: Orlando Florida

Now all the EEs can get their interrupts working and call themselves Software Engineers! I hope this comparison is helpful to some poor soul that has to adapt modules from one compiler to another. Is this a great forum or what?

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
theusch
PostPosted: Sep 19, 2007 - 12:06 AM
10k+ Postman


Joined: Feb 19, 2001
Posts: 25904
Location: Wisconsin USA

Quote:

//---------------------------
// HP InfoTech CodeVisionAVR

// required includes
#include <processor-specific include>
...


As an option, you can also
#include <io.h>

similar to your annotation for GCC and use the file indicated by the project options.

Lee
 
 View user's profile Send private message  
Reply with quote Back to top
AllN
PostPosted: Sep 19, 2007 - 12:12 AM
Posting Freak


Joined: Feb 14, 2007
Posts: 1858
Location: San Diego California

Most Excellent thread!!
Thanks for the post Bob; and to all the responders too!!!
John

_________________
Resistance is futile…… You will be compiled!
 
 View user's profile Send private message  
Reply with quote Back to top
zbaird
PostPosted: Sep 19, 2007 - 12:42 AM
Raving lunatic


Joined: Aug 13, 2006
Posts: 6700
Location: Bellingham, WA - USA

So Bob, when you're happy with this, why not have it moved to the tutorials forum where it will find a happy and appropriate home?

_________________
Chuck Baird
"It's better to catch the trapeze than test the safety net" -- RPi book
http://www.cbaird.org
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
bobgardner
PostPosted: Sep 19, 2007 - 01:15 AM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21257
Location: Orlando Florida

Make it so Number One!

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
microcarl
PostPosted: Sep 19, 2007 - 01:19 AM
Raving lunatic


Joined: May 30, 2004
Posts: 8118
Location: Cincinnati, Ohio

bobgardner wrote:
Make it so Number One!


You must be refering to Ensign ABCMiniUser of the AVRFreaks Star Fleet Command...

_________________
Carl W. Livingston, KC5OTL
microcarl@roadrunner.com

"There are only two ways to sleep well at night... be ignorant or be prepared."

The original Dragon Slayer !

Long live the AVR!!!
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
glitch
PostPosted: Sep 19, 2007 - 04:31 AM
Raving lunatic


Joined: Jan 12, 2002
Posts: 7829
Location: Canada

theusch wrote:

As an option, you can also
#include <io.h>

similar to your annotation for GCC and use the file indicated by the project options.

Lee


Added
 
 View user's profile Send private message  
Reply with quote Back to top
abcminiuser
PostPosted: Sep 19, 2007 - 04:55 AM
Moderator


Joined: Jan 23, 2004
Posts: 9825
Location: Trondheim, Norway

Ensign?! More like supreme commander!

Actually, despite being the supreme commander of this here ship, I don't seem to have a commander's access card to the moderation computer of this particular forum. I'm afraid I've only got my Tutorials, Off-Topic and General Electronics ones on me. Care to repost in the Tutorials section while I go berate the underlings responsible for this lamentable oversight?

- Dean Twisted Evil

_________________
Atmel Studio 6.1 is now released, grab it here.
Report AS6/ASF bugs here.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
theusch
PostPosted: Sep 19, 2007 - 05:51 AM
10k+ Postman


Joined: Feb 19, 2001
Posts: 25904
Location: Wisconsin USA

So, who is going to volunteer to do the whomping macro (somewhat akin to ISR() ) to make a generic interface? I modified one purchased commercial source library to add CV to it; it was fairly straightforward IIRC--each of the compilers has a preprocessor signature that one can access.

Example: "Prototype"
Code:
#ifdef __ICCAVR__
#pragma interrupt_handler CpCoreIntHandler:2
#endif
#ifdef __CODEVISIONAVR__
interrupt [EXT_INT0] void    CpCoreIntHandler      (void);
#endif

Function definition:
Code:
#ifdef __ICCAVR__
void CpCoreIntHandler(void)
#endif
#ifdef __CODEVISIONAVR__
interrupt [EXT_INT0] void    CpCoreIntHandler      (void)
#endif
 
 View user's profile Send private message  
Reply with quote Back to top
lfmorrison
PostPosted: Sep 19, 2007 - 12:54 PM
Raving lunatic


Joined: Dec 08, 2004
Posts: 4719
Location: Nova Scotia, Canada

IMHO the problem is that a macro (like GCC's ISR) cannot legally contain a preprocessor #pragma such as ImageCraft or the new version of IAR uses.

I think Jörg (dl8dtl) has written an abstraction layer that bypasses this constraint and allows common source code (within some constraints such as not allowing the use of IAR's built-in handling of the Flash address space) to be compiled on either IAR or GCC. IIRC he uses the alternative C99 Pragma() construct instead of the preprocessor equivalent, because it can be legally embedded within a macro.

IAR obviously has an implementation of this C99 form of pragma, but apparently it is somewhat finicky. Does ImageCraft?
 
 View user's profile Send private message  
Reply with quote Back to top
theusch
PostPosted: Sep 19, 2007 - 03:27 PM
10k+ Postman


Joined: Feb 19, 2001
Posts: 25904
Location: Wisconsin USA

Quote:

macro (like GCC's ISR) cannot legally contain a preprocessor #pragma

Even within a false #ifdef ? [I'd just assume it was only scanning for the matching #endif. But I just do K.I.S.S. C and preprocessor.]

Lee
 
 View user's profile Send private message  
Reply with quote Back to top
lfmorrison
PostPosted: Sep 19, 2007 - 04:59 PM
Raving lunatic


Joined: Dec 08, 2004
Posts: 4719
Location: Nova Scotia, Canada

Well, at that level, I think it would work. But that means you couldn't wrap everything up in a neat macro like you might be able to if it weren't for those darned pragmas.

For example, I think this:
Code:
#include "compatibility.h"

COMPILER_INDEPENDENT_INTERRUPT(vector_name)
{
}


Looks nicer than this:
Code:
#ifdef __ICCAVR__
#include "something"
#elif defined(__CODEVISIONAVR__)
#include "something else"
#endif

#ifdef __ICCAVR__
#pragma interrupt_handler CpCoreIntHandler:2
void CpCoreIntHandler(void)
#elif defined(__CODEVISIONAVR__)
interrupt [EXT_INT0] void    CpCoreIntHandler      (void)
#endif
{
}


In the past, I wrote COMPILER_INDEPENDENT_INTERRUPT()-like macro that I saw to work correctly for both GCC and CodeVision. I understand that Jörg has already written something that he says worked correctly for both GCC and IAR.

But I haven't figured out how I'd write one that also encompasses ImageCraft because the C preprocessor chokes when one tries to wrap a #pragma up inside a #define.
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits