Research on Several Key Issues in DSP Programming

Publisher:TranquilDreamerLatest update time:2009-10-20 Source: 电子技术应用 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 McBSP (Multichannel Buffered Serial Port) serial port uses DMA in multi-frame communication interrupt processing

In actual communication applications, after a burst, the program must prepare for the next burst. Therefore, the DMA multi-frame method of the serial port is generally used. However, there are some issues to be discussed when the serial port transmits data in DMA mode. First, the transmission synchronization event of DMA should be set to the transmission event of McBSP, that is, XEVT, so that after one byte is transmitted, another byte will be automatically prepared (the rising edge of McBSP's READY triggers DMA transmission). When an interrupt occurs, it means that a block has been transmitted. At this time, the DMA enable is automatically turned off, and the READY of McBSP will remain in a high state. However, when the DMA is directly enabled for the next burst transmission, the transmission cannot be started (I believe that many of me will encounter such problems). This is because the READY rising edge required for McBSP to trigger the start cannot be generated. The solution is to turn off the McBSP transmission in the interrupt program first, so that READY="0", then send and enable DMA in the program, and then turn on the McBSP transmission. If you turn on the McBSP transmission first and then turn on DMA, it will not work. Because the READY of McBSP has changed from 0 to 1, the READY rising edge can no longer be generated.

2The difference between turning off DMA and turning off McBSP

In the field of communication, in order to make full use of the on-chip peripheral resources of DSP, DMA is often used to put the data from the serial port or the data to be sent into the buffer and then process it. For DMA, as long as its pointer in the data buffer points to the position where the interrupt should occur, an interrupt will be generated. However, at this time, the last data only enters the McBSP but is not actually sent out, so in the interrupt program at the end of the transmission, only DMA can be turned off but not McBSP. Because at this time there is still a word in the send register DXR of McBSP that has not been sent.

3 Key timing of McBSP serial port configuration

The main thing is to configure register SPCR2: configure other serial port control registers while keeping RRST, XRST, and FRST all at 0. Wait for at least 2 CLKR/T clocks to ensure the synchronization inside the DSP.

(1) You can load data into DXR or enable DMA.

(2) Enable GRST (GRST = 1) (if the DSP needs to generate a sampling clock internally).

(3) Enable RRST or XRST. Note that only this bit in the SPCR must be changed.

(4) Enable FRST (FRST = 1) (if frame synchronization is required within the DSP).

(5) After waiting for 2 R/T CLK clock cycles, the receiving or transmitting end will be valid.

4 Variables in assembly language programs

Common variables in assembly language programs should be defined in files, such as .def carry. Local variables used in assembly language programs do not need to be defined and can be declared directly, such as trn_num .word 00h. If there are two variables with the same name that are not defined in two asm files, the compiler will think that they are not the same variable. There should be a .mmregs macro statement at the beginning of the assembly program. On the one hand, it indicates the confirmation of the default definition (ah, bh, trn, etc.), and on the other hand, it can redefine the registers used. For example: .mmregs DMPREC .set 54h; define the DMA priority and enable register address at 54h DMSA .set 55h DMSDN .set 57h DXR10 .set 23h; define the send register address of serial port 1 at 23h

5 Effect of the CPL bit in the ST1 register

The CPL bit is the compilation mode control bit, which indicates which pointer is used for relative direct addressing. When CPL=0, the page pointer DP is used; when CPL=1, the stack pointer SP is used. There is no difference between the two in actual use, but the program using SP addressing is easier to read. CPL=1 is often used in the program.

6. Ambiguity of Instructions

6.1 Compare the following instruction STLM B, AR4; send the content of bl to register AR4 (×)

STLM B,*AR4; send the contents of bl to register AR4 (√)

The former actually sends the contents of bl to a buffer used by the system. The latter can also be used: MVDM BL, AR4; send the contents of bl to register AR4 (√)

Other sentences that may cause ambiguity include:

LD AR5, A; send the contents of AR5 to register A (×)

LDM AR5, A; send the contents of AR5 to register A (√)

ANDM #0x107e,AR4; add #107e to register AR4 (×)

ANDN #0x107e, *AR4; add #107e to register AR4 (√)

Instructions that are valid only on certain registers:

MVDD * AR2+, *AR3+; copy the content with AR2 as address to AR3. This type of instruction is particularly effective for data block movement, but it is only valid for AR2, AR3, AR4, and AR5.

The error-prone statements that are most harmful to program execution are:

ST #0, * (bsp0_out_sign); bsp0_out_sign is a variable name (√)

STM #0, bsp0_out_sign; This statement is compiled as STM #0, PMST or STM #0, IMR (×)

This statement can cause random failures in program execution and is extremely difficult to detect.

6.2 Flow Conflict

Analyze the following program:

STM to_dce_buff,AR4 LDM AR4,B ADD A,B ;B=AR4+AL MVDM BL,AR4 ;AR4=to-dce-buff+AL In fact, the above program cannot get the result of AR4=to-dce-buff+AL. This is because DSP generally adopts a pipeline structure with a depth of 3 to 6 levels, which produces an unsolvable conflict, so it cannot be executed correctly. The solution is to insert one or more other instructions or NOP statements between the assignment and the reference.

7 Key issues in mixed programming of assembly language and C language

7.1 Sharing of C program variables with assembly program variables To make the program easier to interface and maintain, you can reference variables shared with the C program in the assembly program: .ref_to_dce_num,_to_dte_num,_to_dce_buff,_to_dte_buff

Variables that can be directly defined in C programs and referenced in the assembly program:

unsigned char to_dte_buff[BUFF_SIZE]; //Data sent from DSP to PC

int to_dte_num; //The number of valid bytes stored in the buffer

int to_dte_store: //buffer storage pointer

int to_dte_read; //buffer read pointer

In this way, the correspondence can be completed through the link.

7.2 Program entry problem In C programs, the program entry is the main() function. In assembly programs, its entry is determined by the command in the *.cmd file, such as: -emain_start; the program entry address is main_start. In this way, the mixed assembly program cannot get the correct result. Because the assembly from C to ASM has a default entry c-int00, the program starting from this section prepares for the running of the C program. These tasks include initializing variables, setting stack pointers, etc., which is equivalent to the system shell cannot be crossed. At this time, you can remove the statement: -e main_start in the *.cmd file. If you still want to execute some assembly programs, you can execute them in the form of C functions, such as:

main_start(); //Contains other assembly routines

But the prerequisite is that _main_start is used as the starting address in the assembler, the program ends with rete (as a callable function) and _main_start is referenced in the assembler, that is, .ref _main_start.

7.3 Shift Problem When a variable is set to char type in C language, it is 8-bit, but in DSP assembly, this variable is still treated as 16-bit. Therefore, the shift result in the C program is different from the shift result in the assembly program. The solution is to "AND" the shift result with 0X00FF in the C program.

7.4 Stack Issues In assembly programs, there is little reliance on the stack, but in C programs, allocating local variables, initializing variables, passing function variables, saving function return addresses, and protecting temporary results are all done with the stack. The C compiler cannot check whether the stack will overflow when the program is running. Therefore, try to allocate as much space as possible for the stack. The default size of the C compiler is 1KB. When the program runs abnormally, you should check whether the stack overflows.

7.5 Program Runaway Problems Runaway of compiled C programs is usually caused by accessing non-existent storage areas. First, check the .MAP file and compare it with the memory map to see if it is out of range. If the program runs away in an interrupted program, focus on checking whether the registers used in the interrupt program are pushed onto the stack for protection. If a C program is called in an interrupt program, check whether the unprotected registers are used in the assembled C program and provide protection (registers such as A and B are not protected during the compilation of the C program).

8. Writing command files

When editing the *.cmd file, the compiler defaults to: page 0 is the ROM area, page 1 is the RAM area. The following sections must be placed in the ROM area.

.text load="PROG" PAGE 0 ; program segment

.const load="data" PAGE 0 ; constant section

.cinit load="data" PAGE 0 ; Initialization section

.switch load="data" PAGE 0 ; switch instruction constant table

It is worth noting that you should try not to use the FILL option. Once filling is performed, the generated .out file will increase in size and even exceed the internal storage space and cannot be bootloaded.

Reference address:Research on Several Key Issues in DSP Programming

Previous article:Design of Micro Digital Storage System Based on FPGA
Next article:Application of TMS320VC5402 in Acceleration Wave Sensor

Recommended ReadingLatest update time:2024-11-16 17:33

Some Google Pixel phones have a daylight saving time update bug: no jump of 1 hour
    Foreign media 9to5 Google reported that due to the implementation of daylight saving time in the United States and Canada, some Google Pixel phones did not get the update and jumped an hour. Fortunately, a quick restart can fix the Google Pixel DST error.   The report said that users of various generations of Go
[Mobile phone portable]
Some Google Pixel phones have a daylight saving time update bug: no jump of 1 hour
Latest Embedded Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号