Home

Migration from Keil to SDCC for XC800

image

Contents

1. does NOT include listing the differences between both compilers SDCC v2 5 4 B4 R1 6 the beta release of standalone SDCC for XC800 family and Keil Compiler C51 v8 04b are considered for discussion in this application note For more information please refer to SDCC User Manual for Infineon XC800 family sdcc_xc800_usermanual pdf and SDCC User Manual for Assembler and Linker for Infineon XC800 family sdcc_xc800_asm_Ink pdf 2 Memory Models Keil supports 3 memory models e SMALL All variables are located by default to internal data memory e COMPACT All variables are located by default to one page or 256 bytes of external data memory pdata accessed indirectly via registers RO amp R1 e LARGE All variables are located by default to external data memory or xdata accessed indirectly via the data page pointer DPTR SDCC supports only 2 memory models e SMALL All variables are default to internal data memory e LARGE All variables are default to external data memory or xdata Source programs written for COMPACT model in Keil should be adapted to LARGE model in SDCC 3 Storage classes for variables Both compilers support all the memory qualifiers available for XC800 The only difference is that Keil supports bdata for bit addressable objects in internal data memory and bit for bit variables where as SDCC supports only bit variables using bit keyword This means using SDCC only bit variables can be defined in bit addressable m
2. for a user program It is the user s responsibility to provide heap space for malloc to allocate memory from In SDCC it is supported only in large memory model and can be done like the following define DYNAMIC MEMORY SIZE 128 unsigned char xdata dynamic memory pool DYNAMIC MEMORY SIZE void main void init_dynamic_memory MEMHEADER xdata dynamic_memory_pool DYNAMIC_MEMORY_SIZE Allocate heap space In Keil it is done like the following unsigned char xdata malloc_mempool 0x100 void main init_mempool amp malloc_mempool sizeof malloc mempool Application Note 13 V1 0 2007 09 rr AP08065 Infineon Keil to SDCC Migration Dynamic memory allocation Example 16 SDCC Example on dynamic memory allocation malloc_test_sdcc c include lt xc886 h gt include lt string h gt include lt stdlib h gt include lt stdio h gt define DYNAMIC_MEMORY_SIZE 128 unsigned char xdata dynamic_mem_pool DYNAMIC_MEMORY_SIZE unsigned char xdata src_str xdata dst_str void main void init dynamic memory MEMHEADER xdata dynamic_mem_pool DYNAMIC_MEMORY_SIZE uart_init src str malloc 10 src str Hello printf The source string is s r n src str dst_str malloc 10 strcpyl dst str src_str printf The copied string is s r n dst str Command line option to compile the code sdcc mxc886 malloc test c model large
3. usage of structures struet st ses TE struct s sl s2 foo is invalid in SDCC although allowed in ANSI struct s fool struct s parms invalid in SDCC although allowed in ANSI struct s rets return rets is invalid in SDCC though allowed in ANSI The following can be used as workaround for the above limitations e Members of a structure can be assigned values directly e Pointer to a structure can be passed as a function parameter e Pointer to a structure can be a return value from a function Application Note 16 V1 0 2007 09 rd AP08065 Infineon Keil to SDCC Migration References Example 19 SDCC Example on workarounds for limitations on structures usage typedef struct int no_of_lines char info X X max X x X y Pointer to structures as parameters if x gt no_of_lines gt y gt no_of_lines return x return y Pointer to structures as return values void main void Xxl x2 m x1 no of lines 100 Members of a structure can be assigned values directly x2 no_of_lines 200 m max amp xl amp x2 Pointer to structures as parameters 12 Conclusion SDCC has support for all major features that Keil supports The migration from Keil to SDCC will need some effort in bit addressable and in a few language constructs and mostly depends on how extensively the Keil specific language extensions are used 13 Acknowledgem
4. xram loc 0xF000 xram size 512 o malloc_test_output hex Application Note 14 V1 0 2007 09 rd AP08065 Infineon Keil to SDCC Migration Dynamic memory allocation Example 17 Keil Example on dynamic memory allocation malloc_test_keil c include lt MAIN H gt Header file for XC886 include lt string h gt include lt stdlib h gt include lt stdio h gt unsigned char xdata malloc_mempool 0x100 unsigned char xdata src_str unsigned char xdata dst_str void main void init_mempool amp malloc_mempool sizeof malloc mempool Include UART initialization here loc 10 Lio printf The source string is s r n src str dst_str malloc 10 strcpy dst_str src_str printf The copied string is s r n dst_str Note Error checking code and UART initialization code is omitted in the examples for clarity Application Note 15 V1 0 2007 09 rd AP08065 Infineon Keil to SDCC Migration Support for structures 11 Support for structures Both compilers support struct keyword Keil has no limitations on the usage of structures where as SDCC have the following limitations on the usage of structures e Structures cannot be assigned values directly e Structures cannot be passed as function parameters e Structures cannot be assigned to each other e Structure cannot be a return value from a function Example 18 spcc Invalid
5. Application Note V1 0 Sep 2007 AP08065 XC800 Migration from Keil to SDCC Microcontrollers ad evan Never stop thinking Edition 2007 09 17 Published by Infineon Technologies AG 81726 Miinchen Germany Infineon Technologies AG 2007 All Rights Reserved LEGAL DISCLAIMER THE INFORMATION GIVEN IN THIS APPLICATION NOTE IS GIVEN AS A HINT FOR THE IMPLEMENTATION OF THE INFINEON TECHNOLOGIES COMPONENT ONLY AND SHALL NOT BE REGARDED AS ANY DESCRIPTION OR WARRANTY OF A CERTAIN FUNCTIONALITY CONDITION OR QUALITY OF THE INFINEON TECHNOLOGIES COMPONENT THE RECIPIENT OF THIS APPLICATION NOTE MUST VERIFY ANY FUNCTION DESCRIBED HEREIN IN THE REAL APPLICATION INFINEON TECHNOLOGIES HEREBY DISCLAIMS ANY AND ALL WARRANTIES AND LIABILITIES OF ANY KIND INCLUDING WITHOUT LIMITATION WARRANTIES OF NON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OF ANY THIRD PARTY WITH RESPECT TO ANY AND ALL INFORMATION GIVEN IN THIS APPLICATION NOTE Information For further information on technology delivery terms and conditions and prices please contact your nearest Infineon Technologies Office www infineon com Warnings Due to technical requirements components may contain dangerous substances For information on the types in question please contact your nearest Infineon Technologies Office Infineon Technologies Components may only be used in life support devices or systems with the express written approval of Infineon Technologies if a fa
6. E EE E sued E Ea E aaa Ta E aE 8 6 Double Precision Floating Point Support sesse ee RR ER KERR Rea Ge Ee AR Ek ER RE Rae Ge Ee AR EK RE Rae Ge ee 9 7 Interrupt FUNCIONS se RR BREER REKORD ERK RES AA Eoaea EER ORE NEAR SEK ERA EE NEAR AS KERE EER R EKG GEREEN ER EREE ERGE EE RE 9 8 Relocating FunctionS ee EER ER Ee Ee EE EE Ee EE REK REDE ER Re Ee Ee EER EE Ee EER ENE Ee EE EE EE De ek RE Ee Ee eek KERR Ee REKE Eed ee Gee ei 10 9 Inline TT EE EE EE ER EE eieeeeeeteenteens 12 10 Dynamic memory allocation ee ee RE Re RR RE REG RR RE EER R AR RE KEER AR RE KEER AR RE REG R RR RE KEER RR RE EER RAK RE Ee ER KERKE Ee Ee ee 13 11 Support TOM structufeS EE EERSTE RR n SEN EE RE ENE ER EA RR EERDER DER RENE EE WE EN ENE WERE RE eke ee 16 12 CONCIUSION N EE A E 17 13 Acknowledgements EE Po Gee DES Ere cee ge ee DE EE Er De DR Ke Ee ei ge EES SR DES Ge 17 14 ME le N EE EE EE ER EE 17 Application Note 4 V1 0 2007 09 rd AP08065 Infineon Keil to SDCC Migration Storage classes for variables 1 Introduction amp Scope SDCC for XC800 family and Keil compilers are both ANSI C compliant The main motivation for the migration from Keil to SDCC SDCC is a free compiler where as Keil is a commercial compiler Migrating from Keil C51 to SDCC for XC800 may need more care than just translating the source files The scope of this application note is to outline clearly the SDCC extensions and syntax and their Keil equivalents The scope of this document
7. SEG 0x20 simulate_bdata c o simulate bdata hex Wl bBSEG 0x20 gt locates segment BSEG at 0x20 Output num_byte value before modifying is 0 num_byte value after modifying is 16 Application Note 7 V1 0 2007 09 rd AP08065 Infineon Keil to SDCC Migration SFR SBIT definitions 5 SFR SBIT definitions The on chip peripherals of the XC800 are accessed using special function registers or SFRs These core registers occupy direct internal data memory locations in the range 80 to FFy Both the compilers have processor specific header files that contain the definitions of SFRs Example 6 Keil sfr PO 0x80 SDCC sfr at 0x80 P0 special function register PO at location 0x80 Keil provides sfr16 keyword to define 16 bit SFRs SDCC does not have any equivalent keyword It can be converted to volatile unsigned int as below Example 7 Keil sfrl6 T2 OxCC Timer 2 TAL O0CCh T2H OCDh spcc volatile unsigned int at OxCC T2 Special function registers which are located on an address divisible by 8 are bit addressable A variable of type sbit addresses a specific bit within these sfrs Keil supports 3 variants for specifying the address of a sbit register variable e sbit sbit_name sfr address bit position e sbitsbit name sbit address e sbitsbit name sfr name bit position SDCC supports 2 variants for defining a sbit e sbit at sfr address bit position sbi
8. ble SDCC bit at 0x02 bit var Allocate the variable at offset 0x02 in the bit addressable space The SDCC will not track variables declared at absolute addresses and may declare other variables so that they will overlap A use for absolute addressing is to simulate bit addressable variables In the following example we will define the variable of type char num_byte at address 0x0020 which is the first byte in bit addressable memory Next we will define 8 variables of type bit num bit0 to num_bit7 and locate them such that they will overlap with the address of the variable num byte Application Note 6 V1 0 2007 09 Infineon AP08065 Keil to SDCC Migration Example 5 Absolute addressing spcc Simulating bit addressable variables simulate bdata c include lt xc886 h gt data unsigned int at 0x0020 num_byte bit at 0x0 Locate num bit0 at offset 0x1 0x2 0x3 0x4 0x5 0x6 0x7 bit at bit at bit at bit bit at at bit at bit at void main void uart_init num_byte 0x00 printf num byte num_bit0 0 in BSEG bit addressable segment num_bit1 num_bit2 num_bit3 num_bit4 num_bit5 num_bit6 num_bit7 value before modifying is d r n num_byte num_bit4 1 TENO num_byte printf num byte while 1 Program Loop value after modifying is d r n num_byte sy Command line option for compiling the code sdcc mxc886 Wl bB
9. emory where as in Keil variables of type int char etc and arrays can also be defined and located in bit addressable memory Example 1 Keil int bdata ibase Bit addressable int char bdata bary 4 Bit addressable array sbit mybit15 ibase 15 bit 15 of ibase sbit Ary07 bary 0 7 bit 7 of bary 0 bit test_bit 0 bit variable SDCC bit test bit bit variable Application Note 5 V1 0 2007 09 rd AP08065 Infineon Keil to SDCC Migration Absolute addressing An alternative method for simulating bit addressable objects using SDCC is suggested in Example 5 Also both compilers support XC800 memory specific pointers Both compilers support bit variables as return values 4 Absolute addressing Keil uses _at_ keyword for locating a variable at an absolute memory location where as SDCC uses at keyword Example 2 Keil int chksum _at_ 0x23 chksum at 0x23 SDCC unsigned int at 0x23 chksum chksum at 0x23 While locating the variables at absolute addresses storage classes can also be specified in the variable definitions for both the compilers Example 3 Keil int xdata chksum at OxF010 chksum at xdata OXFO10 spcc xdata at 0xF010 unsigned int chksum chksum at xdata OxF010 Keil has an exception that variables defined with bit storage class cannot be located at an absolute address unlike in SDCC Example 4 Keil Not availa
10. ents My sincere acknowledgements go to Rizal Prasetyokusuma Manoj Palat and Christober Rayappan for giving the idea to write this application note and their valuable feedback and also to Mike Copeland Sonali nath Kasinath and Nagappan Rethinam for their suggestions 14 References e SDCC User Manual for Infineon XC800 family sdcc_xc800_usermanual pdf which is part of the package SDCC XC800 2 5 4B4 R1 6 Setup zip e SDCC User Manual for Assembler and Linker for Infineon XC800 family sdcc xc800 asm Ink pdf which is part of the package SDCC XC800 2 5 4B4 R1 6 Setup zip e Keil C51 Compiler User Guide Application Note 17 V1 0 2007 09 or AP08065 Infineon Keil to SDCC Migration References e Using the Free SDCC Compiler to develop firmware for DS89C420 family of microcontrollers 2005JUNO7 EMS CTRLD AN pdf Application Note 18 V1 0 2007 09
11. ication Note 9 V1 0 2007 09 rd AP08065 Infineon Keil to SDCC Migration Relocating Functions SDCC has the following exception If a source program containing main uses any ISR which is NOT present in the same source file then a prototype of the ISR should be included in the source file containing main 8 Relocating Functions Functions can be relocated to a specific memory address in both the compilers Keil provides the following macro as a linker directive to locate code segments CODE range segment address Where range specifies the address range s to use for CODE segments segment is the name of a segment address is a physical address at which the segment is to be located Example 11 Keil CODE PR FUNC1 A 0x2800 Locates the PR FUNC1 A segment at 2800h Note In Keil each segment has a prefix e g PR which denotes that the segments corresponds to Executable Program Code Segment names include a module_name which is the name of the source file in which the object is declared In this example FUNC1 is the function name and A is the source file name In SDCC relocation of segments can be done using the following linker option barea expression This option sets the area base address Where area is the segment name and the expression may contain constants and or defined symbols from the linked files If multiple segments have
12. ilure of such components can reasonably be expected to cause the failure of that life support device or system or to affect the safety or effectiveness of that device or system Life support devices or systems are intended to be implanted in the human body or to support and or maintain and sustain and or protect human life If they fail it is reasonable to assume that the health of the user or other persons may be endangered rr AP08065 Infineon Keil to SDCC Migration AP08065 Revision History 2007 09 V1 0 Previous Version none Page Subjects major changes since last revision We Listen to Your Comments Any information within this document that you feel is wrong unclear or missing at all Your feedback will help us to continuously improve the quality of this document Please send your proposal including a reference to this document to mcdocu comments infineon com DY Application Note 3 V1 0 2007 09 rd AP08065 Infineon Keil to SDCC Migration Table of Contents Page 1 Introduction amp Scope EE ER RESERWE AR SE RE Ee Ee EE RE Re annaed Ke ER EN Ka End Ee RA WER We Nee de eed Ve ke EE gee 5 2 Memory LERE AE EA EE N EE een peoeee 5 3 Storage classes for variables eie sees ee ee sees RE REG ARK RE Re GR AR RE Re GR AR RE KEER AR KERE ER RR RE ERe GR RR RE REG RAK RE KEER RR RE EER ERG 5 4 Absolute Addressing EE ceseecie aAA SAA ENAA 6 5 SFR SBIT definitions EE NE O
13. s Sdcc Funcl c S codeseg FUNC1CODE Sdcc Func2 c S codeseg FUNC2CODE Sdcc main c Funcl s Func2 s Wl bFUNC1CODE 0x2800 bFUNC2CODE 0xA000 code loc 0x0000 stack loc 0xE0 Note Code segment location and Stack pointer initial values might also have to be changed correspondingly to avoid overlaps 9 Inline Assembly In SDCC assembly code can be enclosed between the keywords asm and _endasm Inline assembly code can also access C variables by prefixing the variable name with an underscore character However labels declared in C code cannot be accessed in inline assembly and viceversa Example 14 SDCC Usage of Inline Assembly in a C program include lt xc886 h gt unsigned char a void main void while 1 program loop a PO DATA _asm nop nop nop inc _a Accessing variable a declared in C _endasm P1 DATA a Application Note 12 V1 0 2007 09 rd AP08065 Infineon Keil to SDCC Migration Dynamic memory allocation In Keil inline assembly should be embedded with in the directives asm and endasm which can be used as part of pragma Variables declared in C cannot be accessed in inline assembly Example 15 Keil Usage of Inline Assembly in a C program include MAIN H void main void pragma asm nop inc PO_DATA pragma endasm 10 Dynamic memory allocation SDCC does not create heap space automatically
14. t_name e sbitat sbit address sbit_name Application Note 8 V1 0 2007 09 rd AP08065 Infineon Keil to SDCC Migration Interrupt Functions Example 8 Keil sbit sbit CY at bit position 7 of the byte at address 0x00D0 SDCC sbit at 0xD0 7 CY Example 9 Keil sbit CY OxD7 sbit CY at bit address OxD7 SDCC sbit at OxD7 CY Example 10 Keil sfr PSW 0xD0 Base address OxDO is evenly divisibly by 8 sbit CY PSW 7 Previously declared sfr PSW is the base address for the sbit CY sbit CY is declared at bit address 0xD7 SDCC sbit at OxD7 CY Bit address is directly specified 6 Double Precision Floating Point Support Keil has support for double precision floating point where as SDCC does not have support for the same If any variable is declared as double SDCC issues a warning and assumes it as a float Note SDCC supports the float data type in large memory model only where as Keil supports float in small memory model also 7 Interrupt Functions Both Keil and SDCC have the same syntax for defining interrupt routines The syntax is as below void interrupt_id void interrupt interrupt_num using bank_num Where interrupt_id is the interrupt function name interrupt_num is the interrupt s position within the interrupt vector table bank_num indicates which register bank has to be used for storing local variables This parameter is optional Appl
15. to be located to different addresses this option should be put as one definition per line in the linker script or should be issued multiple times one for each segment to the linker using WI option of SDCC The directive area can be used to define multiple programming sections CSEG is the default code segment area TEST REL CON Where TEST is the section name and REL CON denotes that this section is relocatable and concatenated with other sections of this program area Application Note 10 V1 0 2007 09 rd AP08065 Infineon Keil to SDCC Migration Relocating Functions Example 12 SDCC Example on usage of area directive sample s overlayable register banks area REG BANK 0 REL OVR DATA ds 8 internal ram data area DSEG DATA 0x0021 Stack segment in internal ram area SSEG DATA __start__stack ds 1 external ram data area XSEG XDATA counter 0x10 T f area HOME CODE area CSEG CODE __sdcc_program_startup lcall main return from main will lock up sjmp area CSEG CODE main The following can also be used to define a program section Sdcc test c S codeseg TESTCODE This defines a code segment with name TESTCODE Application Note 11 V1 0 2007 09 rd AP08065 Infineon Keil to SDCC Migration Inline Assembly Example 13 SDCC Example for relocating two segments at different addresse

Download Pdf Manuals

image

Related Search

Related Contents

Sauna á infrarouge  974-0750 Onan MDJA to MDJF Marine Diesel Engine Service Manual  Película protectora Manual de instruções  SYSTEME D`INJECTION SECONDAIRE  平成 21 年度経済産業省委託事業 平成 21 年度戦略的技術開発委託費  ITB RO11.99.8946 USB cable  

Copyright © All rights reserved.
Failed to retrieve file