TMS320C54X C compiler

xiaoxiao2021-03-06  109

TMS320C54X C compiler

1 Introduction

TMS

320C

54X is a medium-high-end 16-bit DSP series device in which TI is introduced for communication applications. The series of devices is powerful, flexible, and more TMS

320C

2xx, with the following highlights:

(1) Faster speed: 40 ~ 100MIPS;

(2) The instruction set is more rich;

(3) More addressing mode selection;

(4) Two 40-bit accumulators;

(5) Hardware stack pointer;

(6) Support block repeat and ring buffer management.

TMS

320C

54X applications are generally more complicated, so it is very difficult, and it is also very difficult to use assembly language. The C language has become a trend in the development of single-chip microcomputer in its flexibility, and is even more complex DSP application.

TI company is TMS

320C

54X provides a powerful C compiler that supports optimization. Let's use TMS below

320C

Some things in the 54x C compiler are introduced to the reader. TMS used in practice

320C

The version of the 54x C compiler is version 1.10, and the following discussion is based on this version.

2. C language transplantation

When complex algorithm development, the general approach is to simulate the PC (such as C language), and then transplanted into the DSP platform. Considering efficiency problems, the adjustment of manual assembly can be further performed. The compiler can be roughly divided into two categories: a class directly generates a target code from the advanced language; the other class is the first class of assembly code, and then edit the target code. The C compiler provided by TI is the latter. In this way, the user can easily adjust and rewrite according to the intermediate assembly code.

When performing C language, it involves two problems: First, the use of library functions, the second is the word long problem. TMS

320C

The 54x C compiler provides a library that conforms to ANSI C. As for the word length, it is dependent on the hardware machine word length and operating system, but in general, in different systems, the SHORT type is 16 bits, the LONG type is 32 bits, but the int type is different. For example, in the VC environment, the int type is 32 bits, and for TMS

320C

The 54x C compiler, the INT model is 16 bits. Therefore, in the C source program, the simulation environment is to TMS

320C

When the 54x platform is migrated, the INT type should be classified as Short type or long type according to the range of value of each variable.

3. Assignment of paragraph

Although the C language is a relatively efficient advanced language, and the C compiler provided by Ti also supports the hardware feature to support the three-level optimization function, but the generated assembly code efficiency may not be satisfactory. If the ring buffer management function is predicted, this buffer should be positioned to a relatively specific location. Therefore, the user should have a certain understanding of how the C compiler is stored.

The target code is organized in paragraphs. Here, combined with the characteristics of C language, simply introduce several common segments.

In general, all paragraphs can be divided into two categories: the initialization segment and the uninited segment.

The initialization segment contains data tables and executable code, there are three commonly used: .Text sections, .cinit segments, and .const sections. The .Text segment contains all the executable code and constants; .CINIT segment contains an externally or static (STATIC) data table without the Const declaration; an external or external or in the .conSt segment Static data tables and string often. The uninitial segment reserves space in the memory (typically RAM), creating and storeing variables for program runtime, and there are two commonly used: .bss segments and .stack segments. Where the .BSS segment is used to reserve space for global and static variables, and when the program starts, copy the initialized data in the .cinit segment to the .bss segment. The .stack segment is used as a system stack to C, transfer parameters to the modulated function, and assigns space for local variables.

In the above five common sections, the .Text segment and the .cinit section are fixed to the program space, the memory type can be a ROM or RAM (generally a ROM, depending on the selection of RAM or ROM mode) ;. BSS segment And. Stack segment is fixed to the data space, and the memory type can only be RAM.

The use of the .const segment is more flexible. The .const segment is fixed to the data space, but the memory type can be a ROM or RAM. This is different from the .cinit section: .cinit section is connected to the program space, the program is executed, and then copied to the .bss segment in the data space. In this way, a part of the data that does not use Const declaration should take a part of the program (.cinit segment) and the data space (.bss segment). Compared with it, if the system supports the data ROM, then the data table changes to the Const declaration, only part of the data space (.const Segment) is taken up.

If the program is more complicated, it is more difficult to generate by the C compiler. BSS segment will be more difficult to perform a specific operation on the .bss segment. If several commonly used data tables are connected to the inner RAM, not the film outside RAM; or require special addressing for a data table. At this time, even if the target system does not support the data ROM, it is necessary to use the .const segment. This requires the next to the .const segment as follows: Load in the program space, and run in the data space. The C boot program is similar to the .cinit segment, copies it from the program space to the data space. But use the 1.10 version of TMS

320C

The 54x C compiler found that the version of the boot program does not support the loading of the .const segment. By reading the source code of the library function belled by the C compiler, refer to the processing of the .cinit segment, modify the segment boot program, so that it supports loading of the .conSt segment.

In addition to the above five common sections, TMS

320C

The 54x C compiler may also generate two segments: .switch segment and .sysmem segment. Where, .switch segments include data tables for switch (Switch) statements; and .sysmem segment is used to dynamically store allocation. If assembly is used directly, it is also possible to use .DATA segment and self-nammetry segment and unaptured (variable) segment.

4. C and assembly language mixed

Using assembly languages ​​in C language, two ways: First, call assembly language subroutines; second, use embedding compilation.

4.1 Call assembly language subroutine

TMS

320C

The assembly language subroutine calls in the 54x C program must follow their function call rules and register usage rules.

TMS

320C

The 54x C compiler is a strict rule for how to pass the entry parameters and how to return the exit parameters. See Document [2] for details. TMS

320C

54X has 8 universal registers (Ar0 ~ Ar7), where Ar1, Ar6, and Ar7 may be used by the compiler, where Ar1 is generally used as a local variable, and Ar7 is often used as a global variable. Therefore, if these three registers are used in the called assembly language subroutine, context protection should be made.

TMS

320C

The 54x C compiler supports the use of register variables, up to two, respectively: Ar1 and Ar6. The usual usage is to create a global register variable. Compared with the general storage unit, the C54x has the fastest access to the register. Therefore, for some variables with high frequency, it is declared as a register variable, which can significantly improve processing speed.

If a global register variable is used, all code (including library functions) should be recompiled to prohibit the use of Ar1 or Ar6 to prohibit the use of Ar1 or Ar6.

4.2 Embedding Compilation

Although TMS

320C

The 54x C compiler provides a three-level optimization function, but the author actually used is not satisfactory. The assembly language subroutine is called in C, and it is required to strictly follow its parameter transfer rules. Due to TMS

320C

The 54x C compiler supports embedding assembly in the C source code, so on the intermediate assembly code generated by the C compiler, it can be partially embedded. In this way, on the one hand, it can greatly improve the efficiency of some frequently used code segments, and do not change the original function frame, which is also easy to debug the results of the control simulation.

Special pay special attention to the conflict of the pipeline when embedding assembly. TMS

320C

54X uses a 6-level pipeline structure that can be solved in an air operation (NOP) instruction in place where the pipeline conflict occurs. The common instructions such as STLM, Addm, etc.

Regarding version 1.10, there is also a payable problem, that is, how to get 32-bit long integer products by two short integers.

Such as:

Short M1, M2;

Long Result;

Result = (long) (m1 * m2); (1)

Result = ((long) m1 * (long) m2; (2)

For (1), the compiler is only stored in the lower 16 bits of the product; for (2), it is a 32-bit long integer product, but it is called two long intense multiplication. The library function (L $$ MPY) is obtained, which is difficult to accept in efficiency for DSP applications containing a large number of multiplying operations. To this end, this problem can be easily solved using embedded compilation.

5.ccs installation

(1) Install SETUP CCS software

(2) Open the setup ccs.exe file as shown below

Figure 3-1

The middle one is the installed hardware device. After selecting the desired device, double-click Open

Figure 3-2

Select the Bord PropArties item, change the value of I / O port to 0x378,

Figure 3-3

Select the Processor Configuration item, select the desired processor in the Available Processors box on the left, and then press the Add Single button to complete the installation settings for the processor.

6.CCS use (take CCS C5000 1.2 as an example)

Figure 3-4

1. Create a .gel file

The .gel file is a DSP chip initializer. It contains allocated memory, setting pin level. To note that different DSP chips are used. Thegel files are different, if used .gel files with the chip used If you do not meet, an error occurs when the .out file generated by the source program is imported into the DSP chip.

The specific approach is: First open the GEL Files 1 folder in the upper left frame in the upper left of the figure, and remove the original default .gel file, right-click the Gel Files folder, select the Load Gel item, and then The DSP model used is imported. Thegel file is imported. The following is the 'C5402.gel file

Startup ()

{

GEL_RESET (); / * RESET the TARGET * /

GEL_MAPON (); / * enable the memory map * /

GEL_MAPRESET ();

/ * Uncomment for extended Address Support

GEL_XMDEF (0, 0x1e, 1, 0x8000, 0x

7f

);

GEL_XMON ();

GEL_MAPADD (0x18000, 0, 0x8000, 1, 1);

* /

GEL_MAPADD (0x0000, 0, 0x10000, 1, 1); / * int vectors * /

GEL_MAPADD (0x0000, 1,0x10000, 1, 1); / * data space * /

GEL_MAPADD (0x0000, 2, 0x0010, 1, 1); / * UART * /

PMST = 0xffa0; / * ON-Chip Program * /

SWWSR = 0x7492; / * 2 Wait State * /

BSCR = 0x0002; / * Bank-switch * /

* (int *) 0x0004 @ IO = 1; / * Enable External Ram At 0x8000 * /

}

2. Establish .mak file

The .mak file is a project file.

The specific practice is: Click on the Project 4 item in the toolbar, select New in the drop-down menu, and then change the file attribute to .mak when saving.

3. Become the source program into .out file

CCS can use both C language source programs (* .c) and assembly language source programs (* .asm). It must be generated to be .out files before writing the source program to the DSP.

The specific approach is: Click the Project item in the toolbar, select Add Files to Project in the drop-down menu, select the source program to import the source program into the Source folder under. Mak. 2. Double click to the right The program content is displayed in the box. Click Rebuild 5 in the control bar, compile the source program, and display the results in the lower left box. If there is an error in the source program, "The Program Contains Compile Error Do YOU WISH TO Continue Linking? "Dialog, after cancellation, you can modify the source program according to the prompt in the box. After compiling, you will generate a .out and .obj file with the same name in the source file .Obj file .out file is used to write to the output file of the DSP, and .Obj is a link file.

4. Write the .out file to DSP

Click the File item in the toolbar, select Load Program in the drop-down menu, select the generated .Out file, write the program to the DSP.

5. Run the program

Select Register Window 7 in the control bar, which will appear in Figure 5-4, which is used to display the state of each register. In this box, right-click an optional menu, select Edit Register items. In the pop-up control box, the PC (program counter) value is changed to 0x0080 (the program default entry). Click Run 6 in the control bar to run.

If you want the program to click Step by Step12, click Halt13 to pause.

6. Reset and restart

Select Debug 8 in the toolbar to select RESET DSP or Restart in the drop-down menu.

When rewriting a new program, you should reset the DSP chip. When you need to re-execute the existing form, you can use Restart.

Restore the program counter pointer.

7. Change the value of registers and memory

During hardware debugging, the value of changing registers and memory is a very effective means. There are two Memory and Edit Register in the toolbar to implement this feature.

8. View all storage space

The value of each storage space is very important in software commissioning. The View Memory⑩ in the control bar can view the contents of each address in the Data, Program, and I / O total 192K word storage space. And View Stack 11 can view the values ​​in the stack.

9. Treatment of common problems

The following warnings often appear often: "Warning: entry point symbol _c_int00 undefined", which can select the Option item by selecting the Project 4 item in the toolbar, and select the Option item in the drop-down menu, there will be the following control box to play out as shown in Figure 5- 5 The control box shown.

Select the Linker item, select the NO AutoInitialization item in the drop-down menu shown in the figure, and then rebuild.

Figure 3-5

转载请注明原文地址:https://www.9cbs.com/read-102565.html

New Post(0)