ADSP-TS101S is a high-performance digital signal processor (DSP) chip launched by ADI in the United States. It is structurally optimized for large signal processing tasks and communication applications and is widely used in embedded signal processing. The software design of ADSP-TS101S can be programmed in assembly language, high-level language (C/C), or a mixture of high-level language and assembly language. Completely adopting assembly programming has high execution efficiency, but it is difficult to write complex algorithms, has a long development cycle, and has poor readability and portability; and although completely adopting C programming can make up for the defects of assembly, the execution efficiency of the program is relatively low, which is only about 10% to 20% of the assembly program. For processing with high real-time requirements, such as radar signal processing, it is difficult to meet the requirements. Using mixed language programming, using C language to build a framework, and using assembly to complete the core processing module with large computational volume and hardware bottom management, the advantages of the two can be effectively combined. There are three forms of mixed programming of C and assembly language: the first is to manually modify and optimize the assembly program formed after the C program is compiled; the second is to directly insert assembly statements into the C code, just add double quotes and brackets on both sides of the assembly statement, and add the identifier "asm" in front of the bracket, such as asm ("assembly statement"); the third is to write C program and assembly program separately, and then compile them into target code module link independently. The first method has a greater negative impact on program readability. The second method is suitable for situations where the efficiency difference between C and assembly is large, such as entering the interrupt subroutine of the interrupt. The third method is the most commonly used and needs to follow some prescribed interface specifications and standards.
1 Interface specifications and standards for mixed programming
① In the C/C environment, TigerSHARC defines a set of strict register rules, which are divided into three categories:
the first category is reserved registers, j16~j25, k16~k25, xr24~xr31, yr24~yr31, a total of 40, as registers used exclusively for compiling system library functions. When writing programs, you should avoid using these registers to avoid accidentally changing the system library functions. If used in a subroutine, it must be saved when called and released after the call.
The second category is stack-specific registers, including k26, 27 and j26, j27. These registers need to be protected when called.
The third category is high-speed temporary storage registers, including all registers except the above two categories of registers. The usage is the same as the ordinary registers in assembly, and the register content does not need to be saved before use.
By default, the cjmp register is used to store the return address of the called function, but this value will be modified in nested calls. In order to ensure safe return, the return address is generally stored at the offset address of the top of the stack 0.
Function calls sometimes require parameter passing. Usually, if there are less than 5 parameters, they are passed through registers, as listed in Table 1.
If the correct function return declaration is made in the C/C calling function, the called assembly function can use registers j8, xr8 and xr9 to return valid values. j8 is used to return integers or addresses; xr9:8 can provide double-word result returns. If the return value is greater than 2 words, storage space must be allocated for them. Let j8 be the return value and point to the first address of the space.
② Global variables and functions declared in C/C++ can only be used in assembly language after being prefixed with "-". Objects in assembly language must be named with the prefix "-" and declared as global variables using .g10bal before they can be accessed in C/C++. The specific format is listed in Table 2.
2 Calls and interrupts in mixed programming
2.1 Function calls
The C compiler has a series of strict rules for function calls. Except for special runtime support functions, any function that intercommunicates with C functions must follow these rules. The standard operation mode of function calls is: ① The caller pushes the parameters into the stack. The push is done in reverse order, that is, the rightmost parameter is at the top of the stack. ② Call the function. ③ At the end of the call, the caller pops the parameters out of the stack and returns. The whole process is inseparable from the stack operation. The schematic diagram of the stack structure in the function call is shown in Figure 1.
The stack of ADSP-TS101S is a first-in-last-out storage area (as shown in Figure 1), and the stack is managed by the stack pointer (j/k27) and the frame pointer (j/k26). When calling a function, the compiler creates a frame in the runtime stack to store information. The current function frame is called the local frame. j/k26 points to the beginning of the local frame of the current function, that is, the bottom of the stack. j/k27 points to the top of the stack, and the working method is to change to a lower address. Every time a function is called, a new frame is created. The C environment uses local frames to implement the following functions:
① Protect the return address and related registers of the function: Save the function return address at j27 0 (top of the stack), and set jZ6 to j27-0x40 (bottom of the stack) to obtain a stack area with a length of 64, and protect the related registers in the stack area.
② Allocate local variables: When assigning initial values to local variables, the system allocates a space for it in the stack.
③ Pass function parameters: The first four parameters are passed to the corresponding registers (see Table 1), and the subsequent parameters are loaded into the space starting from j27 0xC in sequence. Note that if the parameter passed is a structure type, all its elements will be pushed onto the stack. For example: If the fifth parameter is a two-element structure, element one is placed at jZ7 0xC and element two is placed at j27 0xD. When the assembly subroutine uses the parameters, it only needs to read them from the corresponding positions. The
C environment automatically manages these operations when calling C functions. When the assembly interface is used with C, it must be operated in the same way as C. This process can be described in detail by Figure 1. It is particularly important to note that since the C compiler does not provide any means to check stack overflow, it is necessary to ensure that there is enough space for the stack; otherwise, if an overflow occurs, the program's operating environment will be destroyed, resulting in the program being paralyzed.
2.2 Interrupts
Interrupts are an important way for DSP to control program execution. Usually, DSP works in an environment that contains multiple external asynchronous events. The random occurrence of these asynchronous events requires DSP to interrupt the current processing program and turn to execute the event processing program. After execution, it is required to return to the interrupted original program to continue the processing steps. This process is called interruption. The interrupt source can come from devices inside or outside the chip, such as clocks, A/D, etc. The interrupt setting includes two steps: ① turn on the corresponding interrupt bit of the interrupt mask register, ② set the entry address of the interrupt service program, so that the normal operation of the interrupt can be achieved. The interrupt service program is a special function that cannot have a return value or pass parameters, and the content must be short and valid. The standard operating mode is: ① save the breakpoint address and protect all used registers, ② execute the interrupt service program, ③ release the register and return.
There are two ways to implement C language interrupts in ADSP-TS101s: one is to use the interrupt(int, vuid(*func(int))) function to set the interrupt vector table, which is defined in the signal.h header file. The first parameter represents the interrupt bit to be responded to, which is also defined in this header file; the second parameter is the interrupt service program. It should be noted that when using this method, the exception interrupt bit of the IMASK register must be turned on, because the interrupt() library function uses the trap statement to generate a trap, and the exception interrupt must be turned on so that the trap can be set successfully and the interrupt vector table setting can be completed. Otherwise, the interrupt will not enter the specified interrupt service program. The other method is similar to the implementation of the assembly language interrupt service program. Taking timer O as an example, after setting IMASK, use the _builtin_sysreg_write(_ⅣTIMEROHP, (int)timer0h_isr) function to set the interrupt vector table, and use #pragma interrupt to identify the interrupt service program. This method is simpler and faster, but it only applies to Visua1DSP 3.5 and above, while the first method applies to any version.
3 Program Optimization
Program optimization includes assembly optimization and C optimization. There is a lot of room for optimization of handwritten assembly programs, which can generate very efficient program codes. Since many related books have introduced this, I will not repeat it here. Here I will mainly introduce the optimization of C programs.
Generally, the C compiler of DSP will provide an optimizing compiler. Using optimizing compilation can generate more efficient assembly code. In some cases, the execution of optimized program code is 10 to 20 times faster. To some extent, the efficiency of C programs depends mainly on the scope and amount of optimization that the C compiler can perform. It should be noted that the default setting of the TSl01S compiler is not to use the optimizer. It can perform the following different levels of optimization, from low to high:
①Debugging: "-g" is turned on. The compiler generates debugging information to ensure that the target code matches the corresponding source code.
②DefauIt: The compiler performs basic high-level optimizations. For example, inlining clearly marked inline functions.
③Procedural optimization: "-o" is turned on. The compiler performs high-level optimizations on each procedure in the file to be compiled. If "-g" is turned on at the same time, the debugging function will be limited because the "-O" item has a higher priority.
④Interprocedural optimization: "-ipa" is turned on. In addition to basic optimization, the compiler will perform advanced optimization operations on the entire program of all source files, delete functions and variables that have never been called, and significantly reduce the code length.
The above "-g", "-O", and "-ipa" can be seen in the compilation information. The higher the optimization level, the wider the optimization range. It should be noted that using C optimization compilation can improve the running efficiency of the program, but due to some optimization measures adopted during optimization, the cross-listing files of C and assembly are not as clear as those obtained without optimization. Therefore, when debugging a program, it is best to debug without optimization compilation first, and then use optimization compilation for optimization after the program is successfully debugged. When using C optimization compilation, in order to ensure the correctness of the program, special attention should be paid to the following points:
① Be particularly careful when using asm line assembly statements. The optimizer will reorganize the program code during the optimization process, and the use of registers is also more flexible. At the same time, some variables or expressions in the program may be deleted. Although the asm statement will not be deleted, the environment before and after the asm statement may change greatly due to optimization. Therefore, when the asm statement involves the C environment or accesses C variables, using the optimizer may result in incorrect results. At this point, the compiled assembly statements must be carefully checked to ensure the correctness of the asm statement in the program. Generally speaking, it is safer to use optimization when the asm statement only involves hardware operations such as controlling interrupt registers or I/0 ports.
② In high-level optimization, variables and functions that have never been used in the C language source function will be deleted. If the C external variables of the assembly subfunction have never been used in the C program, they may be deleted and cause compilation failure. Using retain_name pragma can prevent variables and functions from being deleted due to optimization. For example:
retaining functions
③ Using volatile variables to avoid optimization. A variable defined as volatile means that this variable may be changed unexpectedly, such as the hardware registers of parallel devices (such as status registers), non-automatic variables accessed in an interrupt service subroutine, and variables shared by several tasks in a multi-threaded application. With the volatile qualifier, the optimizer must re-read the value of this variable every time it uses this variable, instead of using the backup stored in the register.
④ C language programs should try to avoid using pointer operations. Pointer conversion will reduce the running efficiency to a certain extent.
⑤ When "-ipa' is enabled, using #pragmann_alias before the loop can further optimize the program. Generally speaking, the optimization effect is very good for the situation where there is no iterative operation in the loop (using the previous result).
⑥ Use the PM qualifier to define the data block. By default, the array is stored in the DM area, that is, the first data area (0x80000-0x8ffff). The array using PM qualifier is placed in the second data area (0x100000-0x10ffff). Since the two data areas are connected by an independent 128-bit data bus, dual data can be accessed simultaneously in a single cycle.
4 The application of mixed programming in system program management
is as follows: The system consists of 4 DSPs. DSP0, which is the system manager, is responsible for receiving the control word from the RS232 serial port through IRQ0, decoding it, and starting other DSPs by controlling the falling edge of flag3 to trigger the IRQ3 interrupt. C is used to build the framework and assemble the underlying hardware, which is efficient and readable. Due to space limitations, serial port initialization, serial port data receiving function and other chip processing procedures are omitted here.
The following is mixed programming in system management.
Main.c file:
5 Conclusion
Practice has proved that software using hybrid programming is more in line with the strict time and space constraints of general systems. Well-designed hybrid programming software can not only effectively meet the requirements of embedded systems for functions and performance, but also reserve enough space for program expansion and migration. In short, hybrid programming is an important way to optimize embedded system software.
Previous article:Combination of FPGA and DSP in Wireless Base Stations
Next article:Design of Sine Wave Output DC/AC Power Supply Based on DSP 56F801
- Popular Resources
- Popular amplifiers
- Machine Learning and Embedded Computing in Advanced Driver Assistance Systems (ADAS)
- Introduction to Artificial Intelligence and Robotics (Murphy)
- Embedded Systems with RISC-V and ESP32-C3 - A practical introduction to architecture, peripherals and
- Multiplexed Networks for Embedded Systems: CAN, LIN, FlexRay, Safe-by-Wire
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Tms320VC5502 and isp1581 high-speed data acquisition solution
- 2019FPGA Employment Competition and Guidance
- What kind of activities do you hope the RF/Radio Frequency section will carry out? Please leave a message in the thread.
- Oscilloscope usage tips you don't know
- Free Trial | Keysight Accelerates Signal Integrity and Power Integrity Testing
- Learning PLC technology is super easy
- Advantages of modules
- EEWORLD University Hall----Live Replay: What to listen to when stuck in traffic? New generation of in-car audio systems and software-defined cars
- Beautiful Pico Quad Keyboard
- Summary of msp430 built-in functions