TMS320C2X/C5X C language program development example[Copy link]
Taking TMS320C2X as an example, the development process of C program for fixed-point DSP chip is explained. The software development process is similar to that of floating-point DSP chip, and is mainly divided into the following steps: 1. Use an editor (such as EDIT, PE2, etc.) to edit one or more C programs, such as example1.c, example2.c. 2. Use the one-step compiler dspcl.exe to compile and assemble the C program to form target files, such as example1.obj, example2.obj: dspcl_v25_g_mn_o2 example1.c dspc_v25_g_mn_o2 example2.c Copy the code The _v25 in the command option indicates TMS320C2X. If it is TMS320C5X, the option is _v50. 3. Edit a link command file according to the actual application, such as example.cmd. The following is a typical TMS320C25 link command file: Example 2.3 TMS320C25 link command file example.cmd /* command file name*/ -c /*ROM initialization*/ -o example.out /*output file name example.out*/ -m example.map /*generate image file example.map at the same time*/ example1.obj /*first C target file*/ example2.obj /*second C target file*/ -l rts25.lib /*link in TMS320C25 runtime support library*/ -l flib25.lib /*link in TMS320C25 floating point library*/ MEMORY PAGE0:VECS: origin=0h len=30h PAGE0:PROG: orgin=30h len=0EFDOh /*program space*/ PAGE1:DATA: origin=800h len=OE800h /*data space*/ SECTIONS vecs:{}>VECS /*interrupt vector*/ .text:{}>PROG PAGE0 /*code*/ .cinit:{}> PROG PAGE0 /*C initialization table*/ .switch:{}>PROG PAGE0 /*switch statement table*/ .bss:{}>DATA PAGE1 /*variable*/ .const:{}>DATA PAGE1 /*constant variable*/ .stack:{}>DATA PAGE1 /*system stack*/ .sysmem:{}>DATA PAGE1 /*dynamic memory*/ Copy code 4. Link to form example.out: dsplnk example.cmd Copy code 5. Debug with C source code debugger (simulator, hardware emulator, etc.). Example 2.4 Write an input and output program for TMS320C5X in C language and debug with simulator. /*This program is an I/O port input and output program for TMS320C5X. The program reads 8-bit data from I/O port address 0x0 and stores it in an array, and writes the value of another array to I/O port address 0x1*/ #include "ioports.h" /*Include ioports.h header file*/ #define RD_PORT Ox00; /*Define input I/O port*/ #define WR_PORT Ox01; /*Define output I/O port*/ 1nt indata[5],outdata[5]; /*Define global array*/ main() int i; for(i=0;i<5;i++) outdata=i<<2; /*Initialize outdata array*/ for(i=0;i<5;i++) /*Loop 5 times*/ inport(RD_PORT,&indata); /*Read I/O port*/ outport(WR_PORT,outdata); /*Write I/O port*/ Copy code When debugging the I/O port with TMS320C5X simulator, associate the I/O port with a file. Here we create two files RD.DAT and WR.DAT, and initialize the RD.DAT file to: 0x0011 0x0022 0x0033 0x0044 0x0055 Copy code After the above program runs, you can observe the array indata and the file WR.DAT. The correct result should be indata[5]={0x11,0x22,0x33,0x44,0x55}, and the file WR.DAT should be 0x0000 0x0004 0x0008 0x00C0 0x0010