Project to convert cvavr source file to compile in avr-gcc

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi
I don't know if this is the right section or if I should post this to the gcc forum.
I started using win-avr a few days ago and I thought it would be nice to be able to convert the codevision code to be used with avr-gcc.
So far I have created a header file for tiny26, tiny2323, mega48, mega88, mega168, mega8, mega16, mega32, mega64, mega128 which define the interrupt vectors for each mc so that the codevision interrupt vector names can compile in a gcc compiler.
I also create a structure in this file to be able to use bitfield operations like you can in codevision, I had to change the name because I couldn't use the same format as codevision so PORTB.0 becomes PORT_B.b0 , PORTC.7 becomes PORT_C.b7, the same happens for DDRA.0 to DDR_A.b0 and PINA.0 becomes PIN_A.b0 etc.
If you think that a different name would be easier to use then I would be happy to change it.
I have also created a delphi (7.2) program which can work with a file or the contents of a memo and what it does actually is:
Convert bit field names , so PORTA.0 becomes PORT_A.b0 , also DDRA.0 and PINA.0 for all ports and bits.
Convert the interrupts from the original format "interrupt [EXT_INT0] void ext_int0_isr(void)" to "ISR(EXT_INT0)" ,this is done for all interrupts.

I also change:
#asm("sei") to sei();
#asm("cli") to cli();
#asm("nop") to nop();
#asm("wdr") to watchdog_reset();

All the conversion are stored in a cvavr2gcc.ini file next to the executable and have the format "old<->new" in each line so that the old is substituted with the new.
The interrupts are more complex so I do it inside the program, what I do is search for the word interrupt and [] in the same line and then I read the content inside the [] , comment the old line and insert ISR(X) where X is the content inside the [] so this works for all interrupt names without having to specify names.

The registers names are the same for codevision2 and the latest winavr 20090313 so there is no problem there.
After this conversions all you have to do is include cvavr_compat.h file (use it after the io.h) and you can compile your project with gcc and you can also use the bit field operations like in codevision.
The old includes will not be valid so the minimum you should use in the new file is:

#include 
#include  // if you have interrupts
#include 

I didn't make any conversion to USART or LCD etc so if your project uses that you will still have a problem but I will try to see if I can do something for that also, for now I am not familiar with the avrgcc library's so I can't do it until I know how.
Any suggestion or help would be appreciated, I have attached the cvavr_compat.h and the Delphi executable which does the conversion.
I can also post the delphi source code if needed.

update
----------------------------
I had a few errors in the header file, some DDR_B and PIN_B were by mistake written DDRB_B and PINB_B, the file is now correct.
I have also updated the executable to convert the delay functions, now the delay_ms() are changed to _delay_ms() and delay_us() are changed to _delay_us().
If a delay is found then the executable also asks for the clock speed of the mc and adds a #define F_CPU which is needed by the delay.h routines

Alex

Attachment(s): 

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

Last Edited: Mon. Jun 1, 2009 - 12:17 AM