Split code for PICs. Creating the Object Files. Creating the Symbol-Only Object File. Creating the Absolute Object File for the Fixed Code

Страницы работы

Содержание работы

0.1  Split code for PICs

This text is to be used in conjunction with the tutorial in section 2.5 of the PIC compiler manual. Its purpose is to provide an example of the process as outlined in the PICC Manual for the creation of split code. Explanations or further information on certain sections of this text can be found in the manual.

Please refer to the following C source (and header) files. The processor used as an example in the PIC

Manual tutorial is the PIC17C756 - as is this example. The files that are part of this example include :-

fixed.c

code for the fixed internal memory

r_main.c

main replaceable code for the external memory

r_ext.c

replaceable code for external memory

r_ext.h

header file for r_ext.c

runsplit

batch file for the linking, XSTRIP & OBJTOHEX processes

These files are set up to run the PIC compiler found in the standard directory: C:\HT-PIC\. If this is not where you compiler is located, you will need to edit these file to specify the location of the library files used.

Within fixed.c, a call is made to the function twice() which is defined within this file as well as calls to the library functions strcpy() and strlen(). The other two functions defined in this file inc() and dosomething() are called by the external code. The interrupt service routine defined within this file, isr10(), calls an ordinary function defined in the external code placed at a specific address (4200h) by the linker.

0.1.1 Creating the Object Files

As outlined in the PICC Manual’s tutorial, first compile the files to ensure that the program works correctly and fix any errors. Once this has been completed, we can then create the object files.

This is done for both the internal and external files using the PICC driver. Include all the options as required (for example optimizers). In this example, we are using the MPLAB IDE to run the code, hence the -G and -FAKELOCAL options are used to generate source-level debugging information and MPLABspecific debugging information, respectively.

PICC -17C756 -C -G -FAKELOCAL fixed.c r_main.c r_ext.c

The next step is creating a file required by the internal code to prevent local variables and parameters from being overlapped in memory. Notice in fixed.c that the functions inc() and twice() are never called. If this file were to be linked in the usual way, the parameters and local objects (both these functions only have parameters in this example) would all be overlapped as the linker would believe that they are never actually executed. Although nothing in the fixed code calls these functions, code in the external space may. The file callgrph.as contains the necessary assembler directives to convince the linker that these functions have been called. You should include a FNCALL directive for any functions in

HI-TECH PIC C compiler    

your fixed code that are only called by the replaceable code. You will need a GLOBAL directive for any symbol referenced in this file. Compile this file using a command like,

PICC -17C756 -C callgrph.as

0.1.2 Creating the Symbol-Only Object File

The symbol-only object file is to used to supply the location of symbols used in the internal code that are required by the external code.

The first step is to create the initial linker command file,

PICC -17C756 -MF_SYM.MAP -L-F -L-I -V fixed.obj callgrph.obj > f_sym.lnk

The above command produces a linker command file, f_sym.lnk, which will be modified to suite our application. The option -M produces a map file,  f_sym.map, whereas the -F and -I after the -L linker option tells the compiler to create a symbol-only object file and ignore any undefined symbols, respectively. The next step is to modify the generated linker command file. The PICC Manual Section 2.3.5 explains how to modify the linker file. In this example we have modified the output object filename to be f_sym.obj. Removal of the excess lines as well as the HLINK command at the start is also required.

Linking the file with the following command produces the f_sym.obj object and f_sym.map map files.

HLINK < f_sym.lnk

Похожие материалы

Информация о работе