A dynamic setting method for communication mode between DSP and CPU

By dynamically setting the shared memory address and communication mode between DSP and CPU when the DSP firmware is loaded, the problem of insufficient flexibility in the prior art is solved, and the flexibility and complexity of system resource configuration are reduced.

CN114546441BActive Publication Date: 2025-02-18BEIJING SEMIDRIVE TECHNOLOGY LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210136810.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-15
Publication Date
2025-02-18
Estimated Expiration
2042-02-15

AI Technical Summary

Technical Problem

In the prior art, the shared memory address and communication method between DSP and CPU are directly determined during DSP firmware compilation, resulting in insufficient flexibility and inability to adapt to changes in system resource configuration in different projects, increasing the complexity of project resource adjustment. .

Method used

A dynamic setting method for communication between DSP and CPU is provided. When loading DSP firmware, the communication shared memory address used by DSP and CPU is dynamically set according to requirements, and the DSP and CPU use interrupt or polling modes are respectively configured.

Benefits of technology

By dynamically setting the communication method between DSP and CPU, the complexity of recompiling the DSP firmware when different projects are allocated resources is avoided, and the system flexibility is maintained.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114546441B_ABST
    Figure CN114546441B_ABST
Patent Text Reader

Abstract

A method for dynamically setting the communication mode between DSP and CPU includes the following steps: 1) adding a communication data segment for storing global symbols in a link script, adding a processing code for setting the communication mode, compiling and generating DSP firmware; 2) setting a communication shared memory address used by DSP and CPU, and loading DSP firmware; 3) starting DSP, reading the content of the communication shared memory address, and configuring according to the mode in the content. The method for dynamically setting the communication mode between DSP and CPU of the present invention dynamically configures the settings of the communication shared memory address and the communication mode when loading the DSP firmware, avoiding the need to recompile the respective DSP firmware and upgrade the file system for different resource allocations for different projects, thereby reducing the complexity of resource configuration.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of digital signal processing operation control, and in particular to a method for dynamically setting a communication mode between a DSP and a CPU. Background Art

[0002] With the development of the modern integrated circuit industry, DSP chips are used in more and more electronic products. Taking automotive electronics as an example, it is necessary to implement various processing such as images, voice, and neural networks based on DSP chips, and to interact with the application CPU for data and control execution to complete heterogeneous computing.

[0003] In order to complete the interaction between the DSP chip and the application CPU, setting the communication method between the DSP and the CPU is an indispensable and important step, which includes setting the communication shared memory address used by the DSP and the CPU, and the communication method between the two using interrupts or polling.

[0004] In the prior art, the communication shared memory address and communication mode used by the DSP and the CPU are generally directly determined when the DSP firmware is compiled. When the CPU loads the DSP firmware, communication is performed in the mode determined in the firmware. This approach is not flexible enough because system resource configuration is often adjusted in actual projects. If the communication shared memory address and communication mode between the DSP and the CPU are fixed, different projects have different resource configurations and all require modification and compilation of the DSP firmware, which increases the complexity of adjusting system resources for different projects. Summary of the invention

[0005] In order to solve the defects of the prior art, the purpose of the present invention is to provide a method for dynamically setting the communication mode between DSP and CPU. When loading the DSP firmware, the communication shared memory address used by DSP and CPU is dynamically set according to demand, and the DSP and CPU are respectively configured to use interrupt or polling mode to maintain the flexibility of the system.

[0006] In order to achieve the above object, the present invention provides a method for dynamically setting the communication mode between DSP and CPU, comprising the following steps:

[0007] 1) Add a communication data segment to store global symbols in the link script, add the processing code for communication mode settings, compile and generate DSP firmware;

[0008] 2) Set the communication shared memory address used by DSP and CPU and load DSP firmware;

[0009] 3) Start the DSP, read the content of the communication shared memory address, and configure it according to the mode in the content.

[0010] Furthermore, the step 1) further comprises:

[0011] Add a communication data segment named communication section in the link script;

[0012] Define communication_base as a global symbol of the communication shared memory address used by the DSP and CPU to communicate, and put it into the communication data segment;

[0013] Define handshake_data, which is used to place the global symbols for configuring the communication method used by the DSP and the CPU, and put it into the communication data segment;

[0014] Added processing code for communication mode settings;

[0015] Compile and generate DSP firmware in ELF format.

[0016] Furthermore, the data structure of the handshake_data is:

[0017] cpu_mode CPU communication mode configuration, 0: polling 1: interrupt dsp_mode DSP communication mode configuration, 0: polling 1: interrupt cpu_irq CPU irq number, for DSP to trigger CPU interrupt dsp_irq DSP irq number, for DSP to register interrupt processing function

[0018] Furthermore, the step 2) also includes,

[0019] The CPU reads the DSP firmware into memory, looks for the communication section and communication_base in the file, and confirms that the .communicaion section exists in the firmware;

[0020] Modify the content of the address where the communication_base symbol is located to the required communication shared memory address;

[0021] Put the handshake_data table into the communication section;

[0022] Start DSP loading and load all the code segments and data segments that need to be loaded to the specified memory address;

[0023] Write HANDSHAKE_START to the handshake flag handshake status flag at the communication shared memory address.

[0024] Furthermore, the content of the communication_base is:

[0025] handshake flag Handshake flag: Start-START, Success-READY, Failure-FAILED buffers DSP and CPU interaction content ,

[0026] Among them, handshake flag is the handshake status flag, and Buffers is the readable and writable shared memory.

[0027] Furthermore, the step 3) also includes,

[0028] DSP starts running, reads the content of the communication shared memory address pointed to by communication_base, and confirms that the content of the handshake flag is HANDSHAKE_START;

[0029] DSP reads the content of handshake_data and configures according to the mode in the content;

[0030] If the configuration is successful, write HANDSHAKE_READY to the handshake flag at the communication shared memory address pointed to by communication_base, otherwise write HANDSHAKE_FAILED;

[0031] If the configuration is successful, the DSP will enter the mode according to the mode configuration, otherwise it will stop.

[0032] Furthermore, the DSP reads the content of handshake_data and configures the mode according to the content, and further includes:

[0033] If cpu_mode is irq mode, configure the interrupt sending function according to the cpu_irq content;

[0034] If dsp_mode is irq mode, register the interrupt processing function according to the dsp_irq content.

[0035] In order to achieve the above object, the present invention also provides an electronic device, including a memory and a processor, wherein the memory stores a program running on the processor, and when the processor runs the program, the steps of the dynamic setting method of the communication mode between DSP and CPU are executed.

[0036] To achieve the above object, the present invention further provides a computer-readable storage medium on which computer instructions are stored. When the computer instructions are executed, the steps of the method for dynamically setting the communication mode between the DSP and the CPU are executed.

[0037] The method for dynamically setting the communication mode between DSP and CPU provided by the present invention has the following beneficial effects compared with the prior art:

[0038] The settings of the communication shared memory address and communication mode are dynamically configured when the DSP firmware is loaded. When the system resource configuration changes, it avoids the need to recompile the respective DSP firmware and upgrade the file system for different resource allocations for different projects, reducing the complexity of resource configuration.

[0039] Other features and advantages of the present invention will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:

[0041] Figure 1 A flow chart of a method for dynamically setting a communication mode between a DSP and a CPU according to the present invention;

[0042] Figure 2 A flowchart of the DSP firmware compilation process according to the present invention;

[0043] Figure 3 A flowchart of a CPU loading DSP firmware process according to the present invention;

[0044] Figure 4 Flowchart of a DSP startup process according to the present invention. DETAILED DESCRIPTION

[0045] The preferred embodiments of the present invention are described below in conjunction with the accompanying drawings. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention.

[0046] Example 1

[0047] Figure 1 The following is a flow chart of a method for dynamically setting the communication mode between the DSP and the CPU according to the present invention. Figure 1 , the dynamic setting method of the DSP and CPU communication mode of the present invention is described in detail.

[0048] First, in step 101, DSP firmware is compiled.

[0049] In the embodiment of the present invention, a communication data segment (communication section) is added to the link script to store a global symbol (communication_base) for storing the communication shared memory address used by the DSP and the CPU and a global symbol (handshake_data) for placing the configuration of the communication method used by the DSP and the CPU, and a processing code for setting the communication method is added, and the DSP firmware in the ELF format is compiled and generated.

[0050] In step 102, the CPU loads the DSP firmware and sets the communication shared memory address used by the DSP and the CPU.

[0051] In the embodiment of the present invention, the CPU reads the DSP firmware into the memory, queries the communication section and modifies the communication_base and handshake_data, loads all the communication sections to be loaded into the designated memory, and completes the setting of the communication shared memory address used by the DSP and the CPU.

[0052] In step 103, the DSP starts processing.

[0053] In the embodiment of the present invention, the communication shared memory address is read, and configuration is performed according to the mode in the read content to complete the DSP startup.

[0054] After the above steps are completed, the DSP and CPU can read and write interactive content through the buffers at the communication shared memory address pointed to by communication_base, and communicate through the configured interrupts or polling.

[0055] Example 2

[0056] Figure 2 For the DSP firmware compilation process flow chart according to the present invention, the following will refer to Figure 2 , the DSP firmware compilation process flow of the present invention is described in detail.

[0057] In the embodiment of the present invention, the processing during DSP firmware compilation mainly involves adding a communication data section and two symbols, as well as related processing codes.

[0058] In step 201, add a communication data segment named communication section to the link script:

[0059]

[0060] In step 202, define the global symbol communication_base as the communication shared memory address used by the DSP and the CPU, define the address as 0, and put it in the communication field added in step 201:

[0061] _attribute_((section(″.communication″)))void*communication_base=0.

[0062] In step 203, define the global symbol handshake_data to place the configuration of the communication method used by the DSP and CPU in the section defined in step 201:

[0063] _attribute_((section(″.communication″)))struct handshake handshake_data={0}.

[0064] In the embodiment of the present invention, the data structure of handshake_data is as follows:

[0065] cpu_mode CPU communication mode configuration, 0: polling 1: interrupt dsp_mode DSP communication mode configuration, 0: polling 1: interrupt cpu_irq CPU irq number, for DSP to trigger CPU interrupt dsp_irq DSP irq number, for DSP to register interrupt processing function .

[0066] In step 204, a processing code for setting the communication mode is added to read the contents of communication_base and handshake_data and process them.

[0067] In step 205, the firmware in ELF format is compiled and generated.

[0068] Example 3

[0069] Figure 3 For the CPU loading DSP firmware process flow chart according to the present invention, the following will refer to Figure 3 , the CPU loading DSP firmware processing flow of the present invention is described in detail.

[0070] In step 301, the DSP firmware is read into the memory, the communication section and the global symbol communication_base in the file are searched, and it is confirmed that the .communication section exists in the firmware.

[0071] In the embodiment of the present invention, the section table of the elf format firmware file displayed by the firmware readelf tool is as follows:

[0072]

[0073] Among them, Nr is the number of the section, Name is the name of the section, Type is the type of the section (strtab is a string table, symtab is a symbol table, and progbits is a code segment), Addr is the memory address where the section is loaded, Off is the offset of the section in the elf file, and Size is the size of the section. The specific values ​​of Addr, Off, and Size are dynamically determined by the compiler during compilation.

[0074] Find the symbol communication_base through .symtab and .strtab, and confirm that its ndx is the nr of .communication. Both ndx and nr are numbers. The readelf tool shows that the names of section and symbol table are slightly different.

[0075] The communication_base global symbol table entries printed by the readelf tool are:

[0076]

[0077] Among them, num is the number, value is the address, size is the memory size occupied by the symbol, type is the type, bind is local or global, vis is the visible range, and ndx is the number of the section where the symbol is located (num, value and ndx here are dynamically determined by the compiler during compilation and are not fixed). The main purpose here is to show that ndx will be consistent with nr in the previous section table.

[0078] In step 302, the content at the address of the global symbol communication_base is modified to the required communication shared memory address.

[0079] In the embodiment of the present invention, the offset of communication_base in communication section can be obtained by subtracting the Addr item of communication section from the Value item of communication_base global symbol obtained in step 301. The offset of communication section in firmware can be obtained from Off in firmware section. The two are added together to obtain the offset of communication_base symbol in firmware. The specific address of the symbol in memory can be obtained by adding the address placed in memory by reading firmware, and its content can be modified to the required value.

[0080] In step 303, a handshake_data table is placed in the communication section.

[0081] In the embodiment of the present invention, the communication_base global symbol table entry printed by the readelf tool is:

[0082]

[0083] Among them, Num is the number, Value is the address, Size is the memory size occupied by the symbol, Type is the type, Bind is local or global, Vis is the visible range, Ndx is the number of the section where the symbol is located, and Name is the symbol name. Here it just indicates that the symbol named handshake_data exists in the elf symbol table.

[0084] In the embodiment of the present invention, the offset of the handshake_data table in the firmware is obtained in the same manner as in step 302. The content of the handshake_data table is modified to the cpu communication mode, dsp communication mode, cpu irq and dsp irq placed according to the handshake structure.

[0085] In step 304, after all modifications are completed on the firmware that has been read into the memory, loading begins, and all code segments and data segments to be loaded are loaded into the designated memory (including the DSP internal RAM).

[0086] In step 305, HANDSHAKE_START (handshake start) is written into the communication shared memory address handshakeflag handshake status flag, and the DSP response is waited.

[0087] In the embodiment of the present invention, the content at the communication shared memory address pointed to by communication_base is:

[0088] handshake flag Handshake flag: Start-START, Success-READY, Failure-FAILED buffers DSP and CPU interaction content ,

[0089] Among them, handshake flag is the handshake status flag, the CPU will write HANDSHAKE_START to start the handshake process; DSP will configure according to the settings in the handshake_data table, if the configuration is successful, it will write HANDSHAKE_READY, if it fails, it will write HANDSHAKE_FAILED. The CPU determines the next operation based on the returned flag; Buffers is a shared memory that can be read and written by both parties. It can be allocated to store business-related interaction data as needed, and the operation of buffers is a normal operation.

[0090] Example 4

[0091] Figure 4 For the DSP startup process flow chart according to the present invention, the following will refer to Figure 4 , the DSP startup processing flow of the present invention is described in detail.

[0092] In step 401, the runtime environment is initialized.

[0093] In step 402, the content of the communication shared memory address pointed to by the communication_base global symbol is read.

[0094] In the embodiment of the present invention, the content of communication_base has been written as the required communication shared memory address by the CPU during loading, and this address is read.

[0095] In step 403, if the content of the address is HANDSHAKE_START, proceed to the next step, otherwise return to step 402 to read again.

[0096] In step 404, the content of handshake_data is read and configured according to the mode in the content.

[0097] In the embodiment of the present invention, the content of handshake_data has been written by the CPU as the required configuration. Read the content of handshake_data and parse it according to the structure of handshake:

[0098] If cpu_mode is 1, that is, irq mode, configure the interrupt sending function according to the cpu_irq content;

[0099] If dsp_mode is 1, that is, irq mode, register the interrupt processing function according to the dsp_irq content.

[0100] In step 405, HANDSHAKE_START or HANDSHAKE_FAILED is written into the handshake flag handshake status flag bit of the communication shared memory address pointed to by the communication_base global symbol according to the configuration result.

[0101] In the embodiment of the present invention, if the configuration is successful, HANDSHAKE_READY is written to the handshake flag handshake status flag bit of the communication shared memory address pointed to by communication_base to complete the setting of the communication mode. If the configuration fails, HANDSHAKE_FAILED is written to the handshake flag handshake status flag bit of the communication shared memory address pointed to by communication_base, and the DSP stops running.

[0102] In the case of successful configuration, if dsp_mode is 1, that is, irq mode, it enters interrupt waiting and waits for the CPU to send an interrupt; if dsp_mode is 0, that is, polling mode, it loops to read the buffers memory and waits for the CPU to write new data.

[0103] In step 406, the system enters the irq mode or the polling mode according to the configuration of dsp_mode and continues to run.

[0104] Example 5

[0105] In one embodiment of the present invention, an electronic device is provided, including a memory and a processor, wherein the memory stores a program running on the processor, and when the processor runs the program, the steps of the above-mentioned method for dynamically setting the communication mode between the DSP and the CPU are executed.

[0106] The present invention also provides a computer-readable storage medium on which computer instructions are stored. When the computer instructions are executed, the steps of the method for dynamically setting the communication mode between the DSP and the CPU are executed.

[0107] Those skilled in the art can understand that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention is described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions recorded in the aforementioned embodiments or replace some of the technical features therein by equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for dynamically setting a communication mode between a DSP and a CPU, comprising the following steps: 1) Add a communication data segment to store global symbols in the link script, add the processing code for communication mode settings, compile and generate DSP firmware; 2) Set the communication shared memory address used by DSP and CPU and load DSP firmware; 3) Start the DSP, read the content of the communication shared memory address, and configure it according to the mode in the content; The step 1) further comprises: Add a communication data segment named communication section in the link script; Define communication_base as a global symbol of the communication shared memory address used by the DSP and CPU to communicate, and put it into the communication data segment; Define handshake_data, which is used to place the global symbols for configuring the communication method used by the DSP and the CPU, and put it into the communication data segment; Added processing code for communication mode settings; Compile and generate DSP firmware in ELF format; The step 2) further comprises: The CPU reads the DSP firmware into memory, looks for the communication section and communication_base in the file, and confirms that the .communicaion section exists in the firmware; Modify the content of the address where the communication_base symbol is located to the required communication shared memory address; Put the handshake_data table into the communication section; Start DSP loading and load all the code segments and data segments that need to be loaded to the specified memory address; Write HANDSHAKE_START in the handshake flag handshake status flag at the communication shared memory address; the step 3) also includes, DSP starts running, reads the content of the communication shared memory address pointed to by communication_base, and confirms that the content of the handshake flag is HANDSHAKE_START; DSP reads the content of handshake_data and configures according to the mode in the content; If the configuration is successful, write HANDSHAKE_READY to the handshake flag at the communication shared memory address pointed to by communication_base, otherwise write HANDSHAKE_FAILED; If the configuration is successful, the DSP will enter the mode according to the mode configuration, otherwise it will stop.

2. The method for dynamically setting the communication mode between DSP and CPU according to claim 1, characterized in that: The data structure of the handshake_data is: 。 3. The method for dynamically setting the communication mode between DSP and CPU according to claim 1, characterized in that: The content of the communication_base is: Among them, handshake flag is the handshake status flag, and Buffers is the readable and writable shared memory.

4. The method for dynamically setting the communication mode between DSP and CPU according to claim 1, characterized in that: The DSP reads the content of handshake_data and configures the mode according to the content, and also includes: If cpu_mode is irq mode, configure the interrupt sending function according to the cpu_irq content; If dsp_mode is irq mode, register the interrupt processing function according to the dsp_irq content.

5. An electronic device, characterized in that: It comprises a memory and a processor, wherein the memory stores a program running on the processor, and the processor executes the steps of the method for dynamically setting the communication mode between DSP and CPU as described in any one of claims 1-4 when running the program.

6. A computer-readable storage medium, characterized in that: Computer instructions are stored thereon, and when the computer instructions are executed, the steps of the method for dynamically setting the communication mode between DSP and CPU as described in any one of claims 1 to 4 are executed.

Citation Information

Patent Citations

  • Dual-core data communication method for embedded type numerical control system

    CN103377157A

  • Communication data processing method, device and system, equipment and storage medium

    CN111190854A