C Language Learning for DSP

Source: Internet
Author: User
C Language Learning for DSP
CMD file: In the DSP, there are also many places to jump during program execution, so the target address to jump. If you know the address you want to jump to during programming, it is better, but in fact, this is very difficult to control. So. CMD is generated. It has the biggest advantage of allocating an address for each segment, so when you want to jump from one segment to another, you can easily know the starting address of this segment.
CMD is used to allocate ROM and ram space. It tells the link program how to calculate the address and allocate space. so different chips have different sizes of ROM and ram. the places where user programs are stored are also different. so you need to modify it based on your chip. the CMD file is divided into two parts. memory and sections.
Memory
{
Page 0 ..........
Page 1 .........
}
Sections
{Sections
{
. Vectors .................
. Reset .................
................
}

Memory is used to specify the ROM and ram size of the chip and to divide several intervals.
Page 0 corresponds to Rom; Page 1 corresponds to ram
The interval name in the page and its subsequent parameters reflect the start address and length of the interval.
For example, page 0: VECs (interval name): origin (Starting address) = 0 h, length (length) = 040 h/* Vectors */
Sections :( Add the following segment name in the program, for example. vectors. this parameter is used to specify the following parts. The Program (which belongs to page0) or data (which belongs to page1) with the other part names is placed in the place where the space name after the ">" symbol is located.
For example, the program or data that references the field name ". vectors" will be stored in VECs. If VECs is page0, it means that the ROM space ranges from H to 40 h.
Sections
{
. Vectors: {}> VECs page 0/* interrupt vector table */
. Reset :{}> VECs page 0/* reset code */
............
}
. Vectors and. Reset are all segment names. Add "." As you like, that is,. vectors indicates the segment named ". vectors.
{} Indicates all segments. {}> VECs page 0 indicates placing all segments in the memory zone named VECs page 0.
Example:
/*************************************** *************************************/

*************************** *******/

/*************************************** *************************************/

Memory
{
Page 0: VECs: Origin = 00000 H, length = 00040 H
Low: Origin = 00040 H, length = 03fc0h
SARAM: Origin = 04000 H, length = 00800 H
B0: Origin = 0ff00h, length = 00100 H
Page 1: B0: Origin = 00200 H, length = 00100 H
B1: Origin = 00300 H, length = 00100 H
B2: Origin = 00060 H, length = 00020 H
SARAM: Origin = 08000 H, length = 00800 H
}
/*--------------------------------------------------------------------------*/
/* Sections allocation */
/*--------------------------------------------------------------------------*/
Sections
{
. Text: {}> low page 0
. Cinit: {}> low page 0
. Switch: {}> low page 0
. Const :{}> Saram page 1
. Data: {}> Saram page 1
. BSS :{}> Saram page 1
. STACK: {}> Saram page 1
. Sysmem :{}> Saram page 1
}
1. system definition:
. Cinit stores the initial values and constants of variables in the C program;
. Const stores character constants, floating point constants, and constants declared with const in C programs;
. Switch stores the switch statement in C program;
. Text stores the C program code;
. BSS reserves the storage space for global and static variables in the C program;
. Far reserves space for global and static variables declared by far in C Programs;
. Stack is a storage space reserved by the C program system stack. It is used to save the return address, PASS Parameters between functions, store local variables, and save intermediate results;
. Sysmem is used by the malloc, calloc, and realloc functions in C Programs to dynamically allocate buckets.
2. user defined:
# Pragma code_section (symbol, "section name ";
# Pragma data_section (symbol, "section name"

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 have a notable feature: hardware operations are often required, the program contains a large number of statements that operate on the internal resources of the controller. Therefore, developers should understand how to use the C language to manipulate the internal resources of the controller, and how to use the C statement to operate registers and internal memory.
For example, in the 51 assembly, we write mov A, #20 h. The assembler can recognize a as a accumulator, and in the 51 C program we write ACC = 32 ;, 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, the programmer only needs to use the # include "reg51.h" statement at the beginning of the program to include the file. Note: The names of these registers cannot be used as variable names.
Similarly, in the C language of TMS320F240, a head file c240.h defines the name of each register. Here we will extract several statements for introduction.
For example: # define IMR (port) 0x0004)
# Define xint1_cr (port) 0x07070)
IMR and xint1_cr correspond to two registers, which are actually the register addresses. In advanced languages, they are pointers. We also use the # include "c240.h" statement at the beginning of the program to include the file. In this way, you only need to add an asterisk (*) before using them in the C language of DSP. For example,
* IMR = 0x1010;/* assign the hexadecimal number 10h to the IMR register */
* Xint1_cr = 0x0a0b0;/* assign the hexadecimal number a0b0h to the xint1_cr register */

It is best to print out the c240.h file to find out the definition names of each register.
The C language development process of the tms320240 Chip
To put it simply, the entire process includes the following five steps:
1. Edit the C language source program
2. Compile the source program (pay attention to the compilation parameters)
3. link the target file (use the CMD file)
4. Online Simulation
5. Curing Program

 

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.