How to use C language to develop DSP embedded systems
Source: Internet
Author: User
How to Develop DSP embedded system in C Language
Xiao wanang Zeng Weimin
Xiao, wanang Ceng, Weimin
(China East Jiaotong University) Xiao wanang Zeng Weimin
Abstract: At present, many embedded systems are built with DSP as the core. However, there are development of DSP Systems Using assembly language.
It is difficult, has a long development cycle, and has poor maintainability. Developing a DSP system using C language is developed by many embedded developers.
Urgent requirements. For more information about the C language development of single chip microcomputer, see C Language Development of DSP system.
But it is rare. This article describes how to use the C language to develop the DSP Device of TI's tms320f24x series.
A complete DSP embedded system.
Key words: Embedded System; DSP system; C language development; tms320f24x Series
Introduction
When developing embedded products, you will first think of using the Controller's assembly language to write monitoring programs, mainly because:
The program generated by the programming language has less binary code, and the program execution is faster than the program generated by the advanced language. ② the Controller just
When it comes out, there is no corresponding advanced language available; ③ storage price issues and addressing space restrictions.
The above problems have been basically solved, so we will not discuss them here. The actual situation is: Development in the application field of Single Chip Microcomputer
Has started development in C language. We found that developing embedded products in advanced languages is so easy, and C
The compiled binary code of the Language Program is also very short and refined.
Currently, the most widely used digital signal processor (DSP) is the TMS320 family of Ti companies in the United States.
The most popular is the TMS320F2XX series. Ti provides the Assembly Language and C language for each DSP chip.
Developer selection. I have been using the C language for product development, but at present I seldom see this introduction
This article describes how to develop a DSP embedded system in C language with the example of TMS320F240.
1. particularity of dsp c Language
When using the 51 Series C language, you have noticed that the C language of the controller and the C language used on the PC are significant.
Features: hardware operations are often required. The program has a large number of statements that operate on the internal resources of the controller. Therefore, open
The sender should understand how to use the C language to manipulate the internal resources of the controller, that is, how to use the C statement to operate registers and internal memory
Storage device.
For example, in the 51 assembly, we write mov A, #20 h. The assembler can recognize that A is a accumulators.
In the C program of 51, we write ACC = 32;, and the compiler can recognize that ACC refers to accumulators rather than general variables. That is
Each register has a proprietary name for developers to use. They are defined in a header file reg51.h.
You only need to use the # include "reg51.h" statement at the beginning of the program to include the file. Note:
The register name cannot be used as the variable name.
Similarly, in the C language of TMS320F240, a header file c240.h defines the names of various registers.
Extract several statements for introduction.
For example: # define IMR (port) 0x0004)
# Define xinti_cr (port) 0x07070)
IMR and xint1_cr correspond to two registers, which are actually the register addresses. In advanced languages, they are pointers. Me
We also use the # include "c240.h" statement at the beginning of the program to include the file. In this way
To use them in a language, you only need to add an asterisk (*) to the front. For example,
* IMR = 0x1010;/* assign the hexadecimal number of 1010 H to the IMR register */
* Xint1_cr = 0x0a0b0;/* assign the hexadecimal number a0b0h to the xint1_cr register */
Developers are advised to print out the c240.h file to find out the definition names of each register. Hardware not involved
The syntax is the same as the ANSI syntax. Note that some ANSI functions are not mentioned in the DSP compiler.
For more information, see the C language manual of the DSP compiler. Clarified these special features and switched from assembly language to C Language
Language Development is easy. Of course, people without the basis of assembly language programming can also use C language to develop DSP Applications.
System.
For C-language programming of embedded systems, refer to single-chip microcomputer and embedded system application. November 1, 2001 ~ Issue 6 embedded
C programming technology, which is not discussed in this article. The following is only applicable to embedded C-language programming based on the tms320240 chip.
And hope to guide readers in specific operations.
2 C language development process of the TMS320F240 chip
To put it simply, the entire process includes the following five steps:
① Edit the C-language source program;
② Compile the source program (pay attention to the compilation parameters );
③ Link the target file (use the CMD file );
④ Online simulation;
⑤ Curing program.
2.1 edit source program
You can use any editor to write the source program, such as edit. Notepad and so on, and finally save the disk with the. c suffix. Source
The code can be written in a C file or multiple C files. Some predefined variables and function prototype declarations can be
To be concentrated in a header file.
Note: Do not forget to include the register definition file in # In-clude "c240.h" before the C program
.
2.2 source program Compilation
After the source program is edited, you can use the dspcl Compilation Program to compile and generate the OBJ file.
Format: dspcl source file name parameter
Example: dspcl EX1.C-V2XX-GK-MN
Meanings of common parameters:
V2xx -- indicates that the C compiler selects the 2XX series processor;
GK -- keep the compiled Assembly file (. ASM file );
Mn -- perform normal optimization.
For other parameters, see the DSP compiler manual. If multiple source files are compiled separately, after each source file is compiled
Generate an OBJ file and an ASM file.
2.3 link to the target file
2.3.1 company TI's coff File Format
Ti uses the coff (Common Object File Format) object for the new Assembler and the target file created by the compiler.
Standard file format. The coff format facilitates Modular programming and provides more information for managing code segments and target system memory.
Flexible methods. When compiling assembler or C-language programs in coff format
Specify the target address, which greatly facilitates programming and program porting.
The basic idea of COFF format is to encourage programmers to use code blocks and data blocks when programming in assembly or C.
Concept. This type of block is called a section, which is the smallest unit in the target file.
All blocks are classified into two categories: initialized blocks and uninitialized blocks. The initialized block contains program code and data.
Blocks are reserved for uninitialized data in the memory. After the C compiler compiles the C program, it generates the initialized block.
And uninitialized blocks. initialized blocks include. text blocks,. Const blocks, and. cinit blocks. uninitialized blocks include. BSS blocks.
For example, when a programmer uses the C statement float data [100]; To define an array, you do not need to specify the number of 100.
The compiler reserves the required space in the data area. The linker will locate the link.
2.3.2 handling of chunks by the linker
The linker has two functions for Block Processing: one is to use the block in the coff target file to create a program block and a data block,
And combine these blocks into coff output modules that can be executed by the DSP chip. Second, the linker specifies the memory for the output block.
Storage location.
The linker provides two commands to implement the above functions: memory and sections. Memory command definition Target System
The programmer can define each block of memory and specify the start address and length. The sections command is used to determine
The combination of the input block and the storage location of the output block in the memory. Without the memory and sections commands,
The linker uses the default allocation algorithm. We recommend that you use these two commands.
In the command file.
The following is a typical CMD file of the TMS320F240 chip. (Assume the file name is ex1.cmd .)
(1) Structure of the CMD file and its detailed explanation
Boot. OBJ/* f240 interrupt vector table, see the following description */
Ex1.obj/* target file corresponding to the source program after compilation */
/* If the program has multiple target files, write them here */
-Stack 0x400/* set the system stack */
-C/* Rom initialization */
-O ex1.out/* output file name */
-M ex1.map/* output image file name */
-L rts2xx. lib/* connect to the rts2xx. Lib library */
Memory/* MEMORY command specifies the memory configuration of the system */
{
Pageo: rom0: Origin = 0000 h, length = 003fh
/* Flash ROM */
Page0: rom1: Origin = 0040 H, length = 0200 H
/* Flash ROM */
Pageo: rom2. origin = 0240 H, length = 3000 h
/* Flash ROM */
Page1: ram_b2: Origin = 0060 H, length = 0020 H
/* Internal ramb2 */
Page1: ram_b1: Origin = 0300 H, length = 0100 H
/* Internal RAM B1 */
Page1: ram_b0: Origin = 0100 H, length = 0100 H
/* Internal RAM B0 */
Page1: ram_ex: Origin = 0d000h, length = 2800 H
/* External extended RAM */
}
The sections/* Sections command specifies the specific method for allocating blocks in the Program */
{
. Vectors: load = rom0/* specifies the location where the vector table is stored */
. Cinit: load = rom1/* C initialization table storage location */
. Text: load = rom2/* storage location of system programs */
. BSS load = ram_b0/* storage location of uninitialized data */
. Const load = ram_b1 * storage location of initialized data */
}
(2) The interrupt vector table file required for the link of TMS320F240
The target file of TMS320F240 needs to use the interrupt vector table when linking. The interrupt vector table is written in assembly language and is specific.
DSP chip. Assume that the assembler corresponding to the interrupt vector table of TMS320F240 is boot. ASM.
The file name is boot. obj.
The following is a typical vector table file. (Assume the program name is boot. ASM .)
. Port/* define the name of the interrupt function */
. Globl_c_int0/* function name corresponding to interrupt 0 */
. Globl_c_int1/* Name of the function corresponding to interrupt 1. The meanings of the following statements are the same */
. Globl_c_int2/* You can regard the interrupt function name as the interrupt entry address */
. Globl_c_int3/* Saving Vector tables requires no programmer intervention */
. Globl_c_int4
. Globl_c_int5
. Globl_c_int6
. Globl_c_int7
. Globl_c_int8
· Sect ". Vectors"/* use the. sect command to customize a block for storing the interrupt vector table */
When rsvect B _ c_int0/* interrupts 0, the program jumps to the destination address */
After int1 B _ c_int1/* interrupts 1, it jumps to the c_int1 () function */
Int2 B _ c_int2/* indicates the same as above, the same below */
Int3 B _ c_int3
Int4 B _ c_int4
Int5 B _ c_int5
Int6 B _ c_int6
Compile the program with assembler, command form: DSPABOOT.ASM-V2XX to generate boot. OBJ file Supply Chain
The connector is used. In this way, you can write the interrupt function in the C source program as follows:
Voidc_extract ()/* X is 1 ~ One in 8 */
{
The C statement series for program interruption;
}
Note: c_int0 () is a system entry function and cannot be written by users.
After introduction to the command file (CMD file) and interrupt vector table, you can link the command file to generate
The out file is used by the DSP chip for execution or soft simulation.
Command Format: dsplnk CMD file name
Example: dsplnk ex1.cmd
In another case, use the default configuration instead of the CMD file. The following is a brief introduction:
Command Format: dsplnk OBJ file name parameter
Example: dsplnk ex1.obj BOOT.OBJ-O XX1.OUT-M xx1.map
The preceding three steps can be described in Figure 1.
2.4 program simulation
Reset command using emurst Simulator
Emu2xxw ex1.out
Load the binary code in coff format for simulation. Usage of the debugger is omitted.
2.5 program SOLIDIFICATION
After the program simulation runs correctly, it needs to be solidified into the Flash ROM. Flash ROM with 16 k characters in the memory of TMS320F240
It can be used to solidify the program without the need to expand the EPROM (when the program cannot exceed 16 k characters ).
Ti provides software with curing program, which can be written into the chip through the JTAG port through the simulator.
A new curing technology can be written into DSP chip through serial port, which is particularly suitable for on-site debugging. The following describes
JTAG port curing method.
First use the emurst command to reset the debugger, and then execute the following three batch files.
Step 1: Run BCO. BAT to clear the Flash ROM (clear) and set all to 0.
Step 2: Execute the be0.bat batch processing file and erase Flash ROM (erase) to set all to 1.
(The two BAT files in the software package do not need to be modified in the preceding two steps .)
Step 3: Execute the bp16k. bat batch processing file and write your out file to the Flash ROM of the DSP.
. Before performing this step, you must modify bp16k and BAT to replace the out file to be written with your out file.
File. Next let's take a look at this batch processing file. Assume that the installation directory of the software package is c: \ DSP.
Directory SRC.
Prg2xx-p240-m0x0006-w6src \ c2xx_bpx.out the out file to be written
If you want to write ex1.out to the dsp flash, run the following command:
Prg2xx-p240-m0x0006-w6src \ c2xx_bpx.out c: \ DSP \ ex1.out
After the above steps, the program is fixed and the system can be put into the field experiment.
Note: When curing a program, the CPU must work at a frequency of 20 MHz. There is a configuration file in the SRC subdirectory.
C240_cfg. I, the reader can work the CPU according to the program instructions and the external crystal oscillator frequency of his system
The frequency is set to 20 MHz (the write frequency ).
This article takes the development of TMS320F240 as an example to introduce how to develop a DSP System in C language. To read
Will be enlightening and helpful.
References
[1] Texas Instruments. tms320f/c24xdsp con-trollers peripheral library and specific
Devive.1999
[2] Texas Instrument. tms320c2x/c5x optimizingc compiler user's guide.1994
[3] principle and development and application of Zhang xiongwei DSP chip. Beijing: Electronics Industry Press, 2001
[4] Chapter cloud. DSP Controller and Its Application. Beijing: Machinery Industry Press, 2001
(China East Jiaotong University) Xiao wanang Zeng Weimin
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.