Professional Documents
Culture Documents
http://particle.teco.edu/software/sdcc/sdccmigration.html#co...
Contents
Comparison of the two compilers Feature matrix Language differences Tools for your convenience Resources
convert.pl ren_ident enum-o-matic convert.sh
CCS Compiler
SDCC
05/02/12 11:29
http://particle.teco.edu/software/sdcc/sdccmigration.html#co...
aspect general cost linkable object files support supported platforms supported target hardware common data type sizes built-in support for RS232, I2C, LCD stability (16bit PIC targets) function pointers interrupt handling documentation call stack stack reentrant functions recursion variable argument lists
CCS Compiler
SDCC
0 (GPL) yes community Windows, Linux, Un*x, Mac OS X MicroChip PIC (14 and 16 bit), Intel 8051, Z80 ...
char (signed 8 bit), int int (unsigned 8 bit), long (unsigned 16 bit), int32 (unsigned (16 bit), long (32 bit) 32 bit) yes stable/production yes (very limited) complex, built-in dispatcher available in print and online no in development yes basic support for 2 priority levels rather incomplete pdf file, active mailing lists
no no no no
overhead for function nearly zero calls code quality inline functions code size yes very densed code (closed world assumption)
Language differences
If existing code for the CCS compiler is to be compiled using the SDCC, the following
2 de 9 05/02/12 11:29
http://particle.teco.edu/software/sdcc/sdccmigration.html#co...
language extensions have to be replaced: Pragmas #fuses (configuration words) #byte, #bit, #locate, #reserve, #rom, #org #use [LIB] (built-in libraries) #use [IO-MODES] (switch between different i/o modes) #int_X, #priority (interrupt handler declaration) ... "sloppy" C accepted by the CCS compiler declaration without typedef implicitly defines type argument lists like foo(byte a, b, c) prototype of function and the signature of the implementation may differ binary literals like 0b11001010 data types (sizes and signedness)
enum
after
code char at _OSC_HS_1H; code char at _WDT_OFF_2H; code char at _PUT_ON_2L & code char at _LVP_OFF_4L; __CONFIG1H config1h = 0xFF & __CONFIG2H config2h = 0xFF & __CONFIG2L config2l = 0xFF & _BODEN_OFF_2L; __CONFIG4L config4l = 0xFF &
3 de 9
05/02/12 11:29
http://particle.teco.edu/software/sdcc/sdccmigration.html#co...
before
#use fixed_io(a_outputs=PIN_A2, PIN_A3) Has only effects on the CCS style io-functions.
after
#undef FIXEDMASK_TRISA #define FIXEDMASK_TRISA 0xF3 #undef set_mode_A #define set_mode_A(input, pin) portmode_fixed(A, input, pin) #undef set_mode_A #define set_mode_A(input, pin) portmode_standard(A, input, pin) a = 0x96; #include <path/to/file.h> _asm ... _endasm;
#use standard_io(A) Has only effects on the CCS style io-functions. a = 0b10010110; #include <path\to\file.h> #asm ... #endasm ASIS will not be handled separately - #asm is always handled that way. #int_timer1 fast noclear void foo() Interrupt handler function foo has to appear in the line immediately below #int_X, with the whole signature in one line. #use delay(clock=20000000, restart_wdt)
delay_us(5) (only replaced for constant values 0-19, #defines will not be recognized) char a; signed char b; unsigned char c; int d; signed int e; unsigned int f; long g; signed long h; unsigned long i; signed int8 j; unsigned int8 k; #byte name = 0x30
unsigned char a; char b; unsigned char c; uint8_t d; int8_t e; uint8_t f; uint16_t g; int16_t h; // alternative: int uint16_t i; int8_t j; uint8_t k; uint8_t at 0x30 name; Keep in mind, you must not pin variables on existing
4 de 9
05/02/12 11:29
http://particle.teco.edu/software/sdcc/sdccmigration.html#co...
before
after
special function registers 0xF60-0xFFF or the area 0x000-0x022 used for local variables (SDCC specific).
long x; #locate x = 0x50 #locate has to appear in the line immediately below the variable declaration; only uintX_t and intX_t types supported at the moment. #use i2c(master, scl=PIN_C3, sda=PIN_C4, FORCE_HW) I2C slave mode, WDT restart and speed selection are not supported at the moment.
uint16_t at 0x50 x;
#undef I2C_SCL #undef I2C_SDA #undef I2C_SUFFIX #define I2C_SCL PIN_C4 #define I2C_SDA PIN_C3 #define I2C_SUFFIX _PIN_C4_PIN_C3 #include <compat_i2c.h> #undef I2C_SCL #undef I2C_SDA #undef I2C_SUFFIX #define I2C_SCL PIN_D4 #define I2C_SDA PIN_E2 #define I2C_SUFFIX _PIN_D4_PIN_E2 #include <software_i2c.c> i2c_read(1)
#use i2c(master, scl=PIN_E2, sda=PIN_D4) I2C slave mode, WDT restart and fast mode are not supported at the moment.
Because of the limitation to regexps, convert.pl will not work properly, if there are line endings at unexpected positions. The following pragmas will be ignored and/or removed and should be replaced manually
#inline #separate #bit #org #list / #nolist #case #device #id #int_default #int_global #type #use rs232 #zero_ram
5 de 9
05/02/12 11:29
http://particle.teco.edu/software/sdcc/sdccmigration.html#co...
pragmas will only be converted correctly when appearing outside of function bodies! Otherwise you will get invalid C. The usage of macros may break our pattern matching.
#use
ren_ident SDCC has some reserved words that CCS does not know. If the sources contain such reserved words, the lexer ren_ident replaces these identifiers. Example:
void foo(byte data);
becomes:
void foo(byte __PIC_data);
In addition to this, ren_ident tries to find identifiers in inline assembler code and prefixes them with a "_", because SDCC cannot reference variable names, only symbols known to the linker. An identifier foo is not modified to _foo but to ASM(foo), where ASM(...) as a macro. enum-o-matic CCSC allows enum type definitions without the use of be fixed with this lexer (in some cases). convert.sh This bash script runs the programs and script mentioned above, converting all .c and .h files in the current directory and its subdirectories. It creates the new directory SDCC and places the current subtree with the modified source files there. Other files are simply copied, also some of the compatibility files. (see below) The script requires a working bash, the tools above and dos2unix. The source files are converted by these tools in the following order: dos2unix, ren_ident, convert.pl and enum-omatic.
typedef.
How to use
Run the convert.sh script in the root directory of your project you want to convert. After processing the files, check your modified sources with the help of the following section.
6 de 9
05/02/12 11:29
http://particle.teco.edu/software/sdcc/sdccmigration.html#co...
Just enabling interrupts globally is not enough! If you want to use our interrupt dispatcher, insert #include <disptab.c>. For additional information concerning the dispatcher, read the disptab.c documentation. No floating point operations have been tested so far. Check your inlined assembler code. CCS inserts BANKSELs where needed, SDCC does not. CCS modifies some commands (makes branches out of gotos if possible); SDCC will not touch anything. So you may face a slightly different runtime behaviour. Labels used in inlined assembler code have to be unique. As a consequence you might also face problems when "converting" former #inline functions to #define macros, when they contain inlined assembler with labels and these macros are used more than once. All in all, keep in mind: This port of the SDCC is still in development. So: handle with care. Fragile.
Compatibility files
compat.h
This file provides most of the CCS-builtin function replacements. If you want to know
7 de 9 05/02/12 11:29
http://particle.teco.edu/software/sdcc/sdccmigration.html#co...
which are already implemented, have a look at the source. Generally, any of the RS232 related functions is working, also EEPROM access, ADC, PWM, SPI or functions you would expect in string.h. But corresponding libraries are in development from the SDCC pic16 core team. SDCC expects one stack pragma in each project. compat.h adds such a line providing 96 bytes of stack at position 0x380. If you want to set your own stack, modify the first line of the main file to
#define USERDEF_STACK #include <compat.h> compat.h
and
compat_i2c.h.
compat_defs.h
This header file contains many definitions of constants and types for CCS compatibility.
stdint.h
Some standard data types are defined here.
delay.c
This file provides the functions delay_us and delay_ms and so may only be included once. The code relys on some macros, so if you want to use the functions, include it the way convert.pl does.
disptab.c
This source file contains our interrupt dispatche and also includes the requrired initprio.c. If you want to use our interrupt dispatcher, insert #include <disptab.c> at the end of your main file. If you want to pack the irq handlers into separate object files, you have to copy all #define macros convert.pl created from the former #int pragma in front of #include <disptab.c> so the dispatch table is generated properly. If you want to write your own dispatcher, change the first line of the main file to
#define OWN_IRQ_HANDLERS #include <compat.h>.
initprio.c
The init_irq_priorites() function provided in initprio.c sets the interrupt priotiy registers according to the #define X_fast macros, generated by convert.pl from the #int directives of CCSC. It is included by disptab.c. If you compile everything at a glance, it
8 de 9
05/02/12 11:29
http://particle.teco.edu/software/sdcc/sdccmigration.html#co...
is enough to include this file at the end of the main file. If you want to pack the irq handlers into separate object files, you have to copy the #define X_fast macros in front of #include <disptab.c> so the code is generated properly. Call
init_irq_priorities()
Example
You can have a look at this example to get an impression of the conversion.
General hints
Use the function attribute wparam where possible to increase speed Use unsigned literals where possible. If you compare an unsigned int like if (i < 3) ... use if (i < 3U) ... to avoid signed compares and get higher execution speed. SDCC is still under development. If you face a crash or other problems, have a look at the SDCC bug tracking system to see if is already known. You can also contact the SDCC mailing lists, especially since the documentation is still rather incomplete.
Links
TecO SDCC information SDCC SDCC SourceForge project site CCS MicroChip PIC18F6520/8520/6620/8620/6720/8720 Data Sheet MicroChip presentation about the I2C hardware support SDCC Open Knowledge Resource
9 de 9
05/02/12 11:29