Data transmission method and device, electronic equipment and storage medium

By establishing shared memory and using protocol packets between microcontrollers, the problem of low communication efficiency between microcontrollers is solved, efficient and reliable data transmission is achieved, and the communication efficiency and stability of the system is improved.

CN118981445APending Publication Date: 2024-11-19CHONGQING CHANGAN AUTOMOBILE CO LTD
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202411058218.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-02
Publication Date
2024-11-19

AI Technical Summary

Technical Problem

The communication methods between existing microcontrollers are limited by IO port hardware, resulting in data transmission delay and number of transmissions, increasing system complexity and reducing communication efficiency and stability.

Method used

By establishing shared memory between microcontrollers, using shared memory mapping and protocol packets, direct data copying and concurrent access is achieved, and latency and bandwidth limitations of bus or other communication interfaces are avoided, ensuring data consistency and efficient transmission.

Benefits of technology

It improves the data transmission speed and concurrency performance between microcontrollers, enhances communication efficiency and system reliability, and meets the needs of real-time data processing and high concurrency scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118981445A_ABST
    Figure CN118981445A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a data transmission method and device, electronic equipment and a storage medium, and the method comprises the steps: obtaining to-be-transmitted data through a first controller, copying the to-be-transmitted data to a write shared memory through the first controller, and transmitting a protocol data packet to a second controller; wherein a read shared memory and a write shared memory of the first processor and the second processor are pre-established in the shared memory, receiving the protocol data packet through the second controller, checking the protocol data packet, and if the protocol data packet passes the checking, reading the to-be-transmitted data from the read shared memory through the second controller. According to the invention, efficient data transmission between MCU cores is realized through shared memory mapping, the first controller and the second controller are allowed to access data concurrently, the data transmission speed and the concurrency performance of communication between MCU cores are greatly improved, and efficient and reliable data transmission between MCUs is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the field of communication technology, and in particular, to a data transmission method, device, electronic device, and storage medium. Background Art

[0002] As the amount and complexity of data to be processed by computers continue to increase, a single controller system can no longer meet user needs. Current systems usually include two or more microcontrollers (Microcontroller Unit, MCU), each of which is used to complete its own tasks. Microcontrollers need to exchange data to ensure coordinated and parallel processing of related tasks.

[0003] The traditional communication method between microcontrollers usually uses IO ports for data transmission. However, this communication method is limited by the hardware of the IO port, and will cause problems such as data transmission delay and transmission frequency limit. Some communication methods based on bus protocols such as SPI and I2C to achieve inter-core communication will increase system complexity and reduce system stability. In other words, the current communication method between microcontrollers affects data transmission efficiency and further affects system stability. Summary of the invention

[0004] One of the purposes of the present invention is to provide a data transmission method to solve the problem that the current communication method between microcontrollers affects the data transmission efficiency and realize automatic and efficient inter-core data transmission; the second purpose is to provide a data transmission device; the third purpose is to provide an electronic device; the fourth purpose is to provide a storage medium.

[0005] In order to achieve the above object, the technical solution adopted by the present invention is as follows:

[0006] A first aspect of an embodiment of the present invention provides a data transmission method, which is applied to a microcontroller, wherein the microcontroller includes a first controller, a second controller, and a shared memory, and the first controller communicates with the second controller through the shared memory. The method includes:

[0007] Acquiring data to be transmitted through the first controller;

[0008] The data to be transmitted is copied to the write shared memory through the first controller, and a protocol data packet is sent to the second controller; wherein the read shared memory and the write shared memory of the first processor and the second processor are pre-established in the shared memory;

[0009] receiving the protocol data packet through the second controller, and inspecting the protocol data packet;

[0010] If the protocol data packet passes the verification, the data to be transmitted is read from the read shared memory by the second controller.

[0011] Optionally, the sending of a protocol data packet to the second controller through the first controller, and copying the data to be transmitted to a write shared memory, wherein a read shared memory and a write shared memory of the first processor and the second processor are pre-established in the shared memory, includes:

[0012] Determine the memory address of the data to be transmitted, and use the memory address to copy the data to be transmitted to the write shared memory;

[0013] generating a protocol data packet using a communication protocol between the first controller and the second controller;

[0014] The protocol data packet is sent to the second controller through the first controller; wherein the protocol data packet is used by the second controller to determine whether data is written into the write shared memory.

[0015] Optionally, the receiving the protocol data packet through the second controller and inspecting the protocol data packet includes:

[0016] Reading the protocol data packet sent by the first controller through a blocking read function of the second controller;

[0017] Parsing the protocol data packet to obtain a header address of the shared memory in the protocol data packet;

[0018] The head address of the write shared memory is checked to determine whether the head address of the write shared memory satisfies the communication protocol.

[0019] Optionally, if the protocol data packet verification passes, reading the data to be transmitted from the read shared memory by the second controller includes:

[0020] If the header address of the first controller writing to the shared memory satisfies the communication protocol, determining that the protocol data packet verification passes;

[0021] The data to be transmitted is read from the read shared memory by the second controller; wherein a shared memory mapping is pre-established between the first controller and the second controller.

[0022] Optionally, if the header address of the first controller writing the shared memory satisfies the communication protocol, after determining that the protocol data packet verification passes, the method further includes:

[0023] A mutual exclusion lock is added to the read shared memory; wherein the mutual exclusion lock is used to lock the data reading of the read shared memory, and is released after the second controller reads the data to be transmitted from the read shared memory.

[0024] A second aspect of an embodiment of the present invention provides a data transmission device, which is applied to a microcontroller, wherein the microcontroller includes a first controller, a second controller, and a shared memory, wherein the first controller communicates with the second controller through the shared memory, and the device includes:

[0025] A data acquisition module, used for acquiring data to be transmitted through the first controller;

[0026] A data sending module, used for copying the data to be transmitted to the write shared memory through the first controller, and sending a protocol data packet to the second controller; wherein the read shared memory and the write shared memory of the first processor and the second processor are pre-established in the shared memory;

[0027] A data receiving module, used for receiving the protocol data packet through the second controller and checking the protocol data packet;

[0028] A data reading module is used to read the data to be transmitted from the read shared memory through the second controller if the protocol data packet is verified.

[0029] Optionally, the data sending module includes:

[0030] The copy submodule is used to determine the memory address of the data to be transmitted, and copy the data to be transmitted to the write shared memory using the memory address;

[0031] A generating submodule, configured to generate a protocol data packet using a communication protocol between the first controller and the second controller;

[0032] A sending submodule is used to send the protocol data packet to the second controller through the first controller; wherein the protocol data packet is used by the second controller to determine whether data is written in the write shared memory.

[0033] Optionally, the data receiving module includes:

[0034] A first reading submodule, configured to read the protocol data packet sent by the first controller through a blocking read function of the second controller;

[0035] A parsing submodule, used for parsing the protocol data packet to obtain a header address of the write shared memory in the protocol data packet;

[0036] The check submodule is used to check the head address of the write shared memory to determine whether the head address of the write shared memory satisfies the communication protocol.

[0037] Optionally, the data reading module includes:

[0038] A determination submodule, configured to determine that the protocol data packet verification has passed if the header address of the first controller writing the shared memory satisfies the communication protocol;

[0039] The second reading submodule is used to read the data to be transmitted from the read shared memory through the second controller; wherein a shared memory mapping is pre-established between the first controller and the second controller.

[0040] Optionally, the data reading module further includes:

[0041] The locking submodule is used to add a mutual exclusion lock to the read shared memory; wherein the mutual exclusion lock is used to lock the data reading of the read shared memory and is released after the second controller reads the data to be transmitted from the read shared memory.

[0042] A third aspect of an embodiment of the present invention provides an electronic device, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed by the processor, the steps of the data transmission method as described in the first aspect of the embodiment of the present invention are implemented.

[0043] A fourth aspect of an embodiment of the present invention provides a readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the data transmission method described in the first aspect of the embodiment of the present invention are implemented.

[0044] The data transmission method provided by an embodiment of the present invention is applied to a microcontroller, wherein the microcontroller includes a first controller, a second controller and a shared memory, wherein the first controller communicates with the second controller through the shared memory, obtains data to be transmitted through the first controller, copies the data to be transmitted to the write shared memory through the first controller, and sends a protocol data packet to the second controller; wherein a read shared memory and a write shared memory of the first processor and the second processor are pre-established in the shared memory, the protocol data packet is received through the second controller, and the protocol data packet is checked, and if the protocol data packet passes the check, the data to be transmitted is read from the read shared memory through the second controller. The present invention realizes efficient data transmission between MCU cores through shared memory mapping, avoids delays and bandwidth limitations when transmitting data through a bus or other communication interfaces, and reduces the data transmission burden of the bus and the network. The first controller directly copies the data to be transmitted to the write shared memory, which simplifies the data processing process. The read-write shared memory of the first controller and the second controller is pre-established, and data transmission is performed through the shared memory, which ensures the consistency of data transmission in the controller. The use of shared memory allows the first controller and the second controller to access data concurrently, which greatly improves the data transmission speed and the concurrency performance of communication between MCU cores. Through the combination of shared memory and protocol data packets, efficient and reliable data transmission between MCUs is achieved, which meets the requirements of real-time data processing and high concurrency scenarios, and further improves communication efficiency and system reliability. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.

[0046] Figure 1 is a flowchart of a data transmission method provided by an embodiment of the present invention;

[0047] Figure 2 yes Figure 1 A flowchart of step 102 of a data transmission method provided by an embodiment of the present invention;

[0048] Figure 3 yes Figure 1 A flowchart of step 103 of a data transmission method provided in an embodiment of the present invention;

[0049] Figure 4 yes Figure 1 A flowchart of step 104 of a data transmission method provided in an embodiment of the present invention;

[0050] Figure 5 is a scenario schematic diagram of a data transmission method provided by an embodiment of the present invention;

[0051] Figure 6 is an interactive schematic diagram of a data transmission method provided by an embodiment of the present invention;

[0052] Figure 7 is a structural block diagram of a data transmission device provided by an embodiment of the present invention;

[0053] Figure 8 It is a structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0054] The following will describe the embodiments of the present invention with reference to the accompanying drawings and preferred embodiments. Those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be understood that the preferred embodiments are only for illustrating the present invention, not for limiting the scope of protection of the present invention.

[0055] Reference Figure 1 , shows a flow chart of the steps of a data transmission method provided by an embodiment of the present invention, wherein the microcontroller includes a first controller, a second controller and a shared memory, and the first controller communicates with the second controller through the shared memory. The method may include:

[0056] Step 101: Acquire data to be transmitted through a first controller.

[0057] In an embodiment of the present invention, in order to solve the problem that the current communication transmission between microcontrollers is limited by the hardware limitations of the IO interface, resulting in data transmission delay and transmission number restrictions, and the use of a bus protocol to implement inter-core communication will increase system complexity, reduce system stability, and affect the efficiency and stability of communication between microcontrollers, this embodiment implements data exchange and communication between at least two MCUs (Microcontroller Units) through shared memory.

[0058] It should be noted that, in this embodiment, since the shared memory allows different cores to directly access the same memory area, thereby realizing fast data exchange, in order to realize efficient communication between MCUs, this embodiment forms a multi-core system with the first controller and the second controller, and performs inter-core communication of the multi-core system by means of shared memory. Since multiple MCUs simultaneously access the shared memory, they will wait for each other to release resources, so that the multi-core system cannot continue to perform data transmission, thereby causing data inconsistency. In this embodiment, a synchronization mechanism (such as a mutex lock) is used in the first controller and the second controller to ensure data consistency, ensuring that this shared memory area is visible to all controllers that need to access it, and the current communication transmission between microcontrollers is subject to the hardware limitation of the IO interface. When designing the PCB, this embodiment needs to ensure that the static random access memory is close to the SPI interface of the two MCUs, wherein the SPI interface is a synchronous serial communication interface, which is usually used for short-distance, high-speed data transmission. The SPI interface can be configured to a high-speed mode, such as 10MHz or even higher. The first controller and the second controller are connected using the SPI interface and communicate through the shared memory, thereby shortening the connection line, avoiding the data transmission delay and transmission number limit caused by transmission through the IO port, and effectively improving the communication efficiency and reliability of the system.

[0059] It should be noted that, refer to Figure 5 , shows a scenario schematic diagram of a data transmission method provided by an embodiment of the present invention. In this embodiment, the microcontroller includes a first controller MCU1, a second controller MCU2 and a shared memory. The first controller communicates with the second controller through the shared memory. The microcontroller is a single-chip system that integrates a processor core, a memory (RAM, ROM or Flash), an input / output interface (I / O) and other peripherals (such as a timer, ADC, UART, SPI, I2C, etc.), and is designed to perform specific tasks. The microcontroller includes at least two MCUs. The MCUs can be of the same model or different models, but both need to be able to access the shared memory. The shared memory is used to share data between multiple processes or threads, allowing multiple processes or threads to access the same memory area to achieve fast exchange and communication data between multiple processes. Shared memory is an efficient way to achieve communication between MCUs, avoiding the process of copying data between different memory spaces, thereby reducing data transmission delays and system resource consumption.

[0060] Specifically, the first controller obtains data to be transmitted, and the data to be transmitted is data that the first controller needs to communicate and transmit to the second controller. This embodiment does not specifically limit the type and content of the data to be transmitted, and it can be data that any controller needs to interact with. In this embodiment, it is necessary to ensure that the first controller and the second controller, that is, the two MCUs, have consistent address mappings to the same shared memory. Different MCUs may have different memory address spaces and management mechanisms, so it is necessary to obtain the MCU database, determine the mapping relationship between the physical address and the virtual address of the shared memory based on the MCU database, and set the address mapping of the two MCUs in the initialization phase to ensure that they access the same physical memory. When the two MCUs access the shared memory at the same time, data competition and inconsistency problems will be caused. This embodiment ensures data consistency by using synchronization mechanisms such as mutex and semaphore, which will not be described in detail here.

[0061] It should be noted that the embodiment of the present invention does not impose specific restrictions on data transmission between the first controller and the second controller. If either the first controller or the second controller needs to transmit data to the other controller, shared memory is used for data transmission. This embodiment is explained by taking the first controller directly using the shared memory address and the second controller reading the transmission data in the shared memory through memory mapping as an example.

[0062] Step 102, copying the data to be transmitted to the write shared memory through the first controller, and sending a protocol data packet to the second controller; wherein the read shared memory and the write shared memory of the first processor and the second processor are pre-established in the shared memory.

[0063] In an embodiment of the present invention, data is exchanged between MCUs through a shared memory, and a shared memory mapping is established. Specifically, the data to be transmitted is copied to the write shared memory by the first controller, and a protocol data packet is sent to the second controller, wherein the read shared memory and the write shared memory of the first processor and the second processor are pre-established in the shared memory, and respective read shared memories and write shared memories are established between the two MCUs. After the memory mapping is established, each MCU can access its respective read shared memory to obtain the data transmitted by the other party, and use the write shared memory to transmit the data it wants to transmit.

[0064] It should be noted that the first controller can directly access the physical address of the shared memory. This method is usually suitable for the case where the MCU has direct memory access (DMA) capability or can directly operate the memory address. The second controller accesses the shared memory through memory mapping. Memory mapping is a technology that maps physical memory addresses to virtual address space, allowing the MCU to access the shared memory like accessing ordinary memory. The MCUs need to coordinate the read and write operations of the shared memory through another communication method. This communication method is a prerequisite to ensure that before reading and writing the shared memory, the communication connection has been established between the MCUs, and the data exchange protocol and parameters have been negotiated. In addition, the shared memory is equivalent to creating an intermediate cache between the MCUs, so that the data transmission and processing time can be effectively reduced during the data processing process. The intermediate cache can buffer data and reduce the number of accesses to slow external storage devices, thereby improving the performance of the overall system.

[0065] Specifically, a read shared memory and a write shared memory of the first processor and the second processor are pre-established in the shared memory. The first controller copies the data to be transmitted to the write shared memory, and at the same time, sends a protocol data packet to the second controller. Specifically, the first controller determines the memory address of the data to be transmitted, uses the memory address to copy the data to be transmitted to the write shared memory, and uses the communication protocol between the first controller and the second controller to generate a protocol data packet. After that, the first controller sends a protocol data packet to the second controller, and the protocol data packet is used to notify the second controller that the data has been written to the write shared memory.

[0066] Step 103: Receive the protocol data packet through the second controller and check the protocol data packet.

[0067] In an embodiment of the present invention, the second controller uses a blocking read function to read the protocol data packet sent by the first controller, parses the protocol data packet, and thus verifies the protocol data packet, obtains the header address of the write shared memory in the protocol data packet, verifies the header address of the write shared memory, and determines whether the header address of the write shared memory satisfies the communication protocol to receive the protocol data packet.

[0068] Specifically, the two MCUs establish read and write threads respectively. The write thread mainly consists of two steps. First, the data to be transmitted to the other controller is copied into the write shared memory and a protocol data packet is sent to inform the other controller that it has copied the data into its own write shared memory. The read thread also consists of two steps. A blocking read function is used to read the corresponding protocol data packet, and the protocol data packet is parsed to verify whether it complies with the communication protocol. If it complies, the required number of bytes in the protocol data packet are read from the read shared memory.

[0069] Step 104: If the protocol data packet verification passes, the data to be transmitted is read from the shared memory by the second controller.

[0070] In an embodiment of the present invention, if the header address of the write shared memory of the first controller satisfies the communication protocol, it is determined that the protocol data packet has passed the verification, and the second controller reads the data to be transmitted from the read shared memory, that is, reads the required number of bytes in the protocol data packet from the read shared memory, and pre-establishes a shared memory mapping between the first controller and the second controller. The first controller and the second controller need to coordinate the read and write operations of the shared memory to ensure that before reading and writing the shared memory, a communication connection has been established between the MCUs, and the data exchange protocol and parameters have been negotiated.

[0071] The data transmission method provided by an embodiment of the present invention is applied to a microcontroller, wherein the microcontroller includes a first controller, a second controller and a shared memory, wherein the first controller communicates with the second controller through the shared memory, obtains data to be transmitted through the first controller, copies the data to be transmitted to the write shared memory through the first controller, and sends a protocol data packet to the second controller; wherein a read shared memory and a write shared memory of the first processor and the second processor are pre-established in the shared memory, the protocol data packet is received through the second controller, and the protocol data packet is checked, and if the protocol data packet passes the check, the data to be transmitted is read from the read shared memory through the second controller. The present invention realizes efficient data transmission between MCU cores through shared memory mapping, avoids delays and bandwidth limitations when transmitting data through a bus or other communication interfaces, and reduces the data transmission burden of the bus and the network. The first controller directly copies the data to be transmitted to the write shared memory, which simplifies the data processing process. The read-write shared memory of the first controller and the second controller is pre-established, and data transmission is performed through the shared memory, which ensures the consistency of data transmission in the controller. The use of shared memory allows the first controller and the second controller to access data concurrently, which greatly improves the data transmission speed and the concurrency performance of communication between MCU cores. Through the combination of shared memory and protocol data packets, efficient and reliable data transmission between MCUs is achieved, which meets the requirements of real-time data processing and high concurrency scenarios, and further improves communication efficiency and system reliability.

[0072] Further, see Figure 2 , Figure 2 yes Figure 1 The method flow chart of step 102 of the data transmission method provided in the embodiment of the present invention is substantially the same as the server testing method provided in the first embodiment of the present invention. Step 102 may specifically include the following steps:

[0073] Step 201, determine the memory address of the data to be transmitted, and use the memory address to copy the data to be transmitted to the write shared memory.

[0074] It should be noted that, in this embodiment, MCUs exchange data through shared memory and establish shared memory mapping. Respective read shared memory and write shared memory are established between the two MCUs. After the memory mapping is established, each MCU can access its own read shared memory to obtain data transmitted by the other party, and use the write shared memory to transmit the data it wants to transmit. For example, the write shared memory of the first controller is relative to the read shared memory of the second controller, and the read shared memory of the first controller is relative to the write shared memory of the second controller. The first controller copies the data to be transmitted to its own write shared memory, and the second controller reads the data in its own read shared memory after confirming that the data can be read.

[0075] Step 202: Generate a protocol data packet using a communication protocol between the first controller and the second controller.

[0076] In this embodiment, when the first controller needs to transmit data to the second controller, the memory address of the data to be transmitted is determined, and the memory address is used to copy the data to be transmitted to the write shared memory. At the same time, a protocol data packet is generated using the communication protocol between the first controller and the second controller, wherein the protocol data packet is generated according to the communication protocol between the first controller and the second controller, and the protocol data packet is used to notify the second controller that the first controller has copied the data to be transmitted to the write shared memory, so that the second controller can accurately judge and start reading the data. The protocol data packet may include control commands, the address of the write shared memory, data length and other information, which is not specifically limited in this embodiment.

[0077] Step 203: Send a protocol data packet to the second controller through the first controller; wherein the protocol data packet is used by the second controller to determine whether to write data into the shared memory.

[0078] It should be noted that, in an embodiment of the present invention, a protocol data packet is sent from the first controller to the second controller, and the protocol data packet is used by the second controller to determine whether data is written to the write shared memory. Specifically, the second controller waits for and receives the protocol data packet from the first controller through a blocking read function. After receiving the protocol packet, the second controller parses it to check whether the control command, the address of the write shared memory, the data length and other information in the protocol packet comply with the predetermined communication protocol. If the protocol packet complies with the protocol, the second controller proceeds to the next step; if not, the protocol packet may be discarded or other error handling measures may be taken.

[0079] The embodiment of the present invention reduces the process of copying data between different memory spaces and improves communication efficiency through the combination of shared memory and protocol data packets. The verification mechanism of the protocol data packets ensures the correctness and integrity of data transmission and enhances the reliability of the system. Through the mechanism of read-write threads, the interface design between MCUs is simplified and the complexity of external circuits and wiring is reduced. The concurrent execution of read-write threads improves the concurrent performance of the system, so that the system can better handle multiple tasks and multiple data streams.

[0080] Further, see Figure 3 , Figure 3 yes Figure 1 The method flow chart of step 103 of the data transmission method provided in the embodiment of the present invention is substantially the same as the server testing method provided in the first embodiment of the present invention. Step 103 may specifically include the following steps:

[0081] Step 301: read the protocol data packet sent by the first controller through the blocking read function of the second controller.

[0082] Step 302: parse the protocol data packet to obtain a header address for writing to the shared memory in the protocol data packet.

[0083] Step 303: Verify the head address of the shared memory to determine whether the head address of the shared memory satisfies the communication protocol.

[0084] It should be noted that in the above steps of the embodiment of the present invention, the second controller waits for and receives the protocol data packet from the first controller through a blocking read function. The blocking read function will suspend execution when there is no data to read until data arrives. The blocking read function ensures that the second controller will not perform invalid read operations before the data arrives. After receiving the protocol data packet, the second controller parses it and obtains the header address of the write shared memory in the protocol data packet. The header address is specified by the first controller when sending data and is used to indicate the starting position of the data in the shared memory. The second controller can accurately obtain the position of the data in the shared memory, providing necessary information for subsequent data reading operations. The second controller verifies the obtained header address of the write shared memory to determine whether the address meets the requirements of the communication protocol, including checking the validity, range, and permissions of the address. By verifying the header address of the write shared memory, the correctness and security of data transmission are ensured. If the address does not meet the protocol requirements, the second controller can take corresponding error handling measures, such as discarding the data packet or notifying the first controller to resend.

[0085] The embodiment of the present invention ensures the correctness and integrity of data transmission by parsing and verifying protocol data packets, verifies the header address of writing shared memory, prevents the use of illegal or invalid addresses, and read shared memory data can be directly used by the second controller without complex data conversion.

[0086] Further, see Figure 4 , Figure 4 yes Figure 1 The method flow chart of step 104 of the data transmission method provided in the embodiment of the present invention is substantially the same as the server testing method provided in the first embodiment of the present invention. Step 104 may specifically include the following steps:

[0087] Step 401: If the header address of the first controller writing to the shared memory satisfies the communication protocol, it is determined that the protocol data packet verification has passed.

[0088] Step 402: read the data to be transmitted from the read shared memory through the second controller; wherein a shared memory mapping is pre-established between the first controller and the second controller.

[0089] It should be noted that, in the embodiment of the present invention, if the header address of the write shared memory of the first controller meets the requirements of the communication protocol, the second controller determines that the protocol data packet has passed the verification, and the control information, address, data length, etc. in the protocol data packet all comply with the predetermined communication protocol. After the protocol data packet has passed the verification, the second controller reads the data to be transmitted from the read shared memory. The read shared memory is relative to the second controller, and is actually the write shared memory of the first controller, storing the data to be transmitted written by the first controller. The second controller reads the required number of bytes from the specified address according to the information in the protocol data packet.

[0090] The embodiment of the present invention ensures the correctness and integrity of data transmission by verifying the protocol data packet, thereby improving the reliability of the system. Through shared memory mapping, the second controller can directly read the data written into the shared memory by the first controller without complicated data conversion or address mapping, thereby simplifying the data processing process and improving the efficiency of data transmission.

[0091] Specifically, in step 401, if the header address of the write shared memory of the first controller meets the communication protocol, it is determined that after the protocol data packet verification is passed, it also includes: adding a mutex lock to the read shared memory; wherein the mutex lock is used to lock the data reading of the read shared memory, and is released after the second controller reads the data to be transmitted from the read shared memory.

[0092] In an embodiment of the present invention, in order to ensure data consistency and integrity of the read shared memory in a multi-threaded or multi-process environment, this embodiment uses a mutex lock to control access to the read shared memory. Before the second controller reads data from the read shared memory, it is necessary to first obtain the mutex lock. After obtaining the mutex lock, the second controller reads the data to be transmitted from the read shared memory. After the reading is completed, the second controller releases the mutex lock to allow other threads or processes to access the read shared memory. The mutex lock is a synchronization mechanism used to ensure that only one thread or process can access the read shared memory at the same time. By using the mutex lock, multiple threads or processes can be prevented from reading or writing the read shared memory at the same time.

[0093] Specifically, in order to ensure that the two MCUs can correctly access the same shared memory, detailed address mapping configuration and synchronization mechanism settings are required. The physical address and virtual address mapping relationship of the shared memory can be determined by obtaining the database of the two MCUs, obtaining the respective memory address space, memory management mechanism and address mapping strategy from the database, and the physical address is the actual hardware address of the memory, and the virtual address is the logical address used inside the MCU. In this embodiment, the address mapping of the two MCUs is set to ensure that they can access the same physical memory, and a mutex is used to ensure that only one MCU can access the shared memory at any time. When an MCU obtains a mutex, the other MCUs must wait until the lock is released. After the data is read, the mutex is released in time, ensuring that other threads or processes can access the shared memory in time, improving the concurrency performance and efficiency of the system. It should be noted that the present embodiment can also use semaphores to meet more complex synchronization requirements, specifically, the number of shared resources accessed can be controlled, and the semaphore can be a binary semaphore (similar to a mutex) or a counting semaphore, thereby avoiding data competition and inconsistency problems, and improving the stability and reliability of the system.

[0094] In order to enable those skilled in the art to more clearly understand the process of the switch operation control method disclosed in the above embodiment of the present invention, refer to Figure 6 , showing an interactive schematic diagram of the data transmission method provided by an embodiment of the present invention: when the first controller needs to transmit data to the second controller, the first controller sends a protocol data packet to the second controller and copies the data to be transmitted to its own write shared memory. The second controller waits for and receives the protocol data packet from the first controller through a blocking read function. After receiving the protocol packet, the second controller parses it to check whether the control command, write shared memory address, data length and other information in the protocol packet comply with the predetermined communication protocol. If the protocol packet complies with the protocol, the second controller reads the data to be transmitted from the read shared memory.

[0095] Reference Figure 7, shows a structural block diagram of a data transmission device provided by an embodiment of the present invention, which is applied to a microcontroller, the microcontroller includes a first controller, a second controller and a shared memory, the first controller communicates with the second controller through the shared memory, and the device may include:

[0096] A data acquisition module 501 is used to acquire data to be transmitted through the first controller;

[0097] The data sending module 502 is used to copy the data to be transmitted to the write shared memory through the first controller, and send the protocol data packet to the second controller; wherein the read shared memory and the write shared memory of the first processor and the second processor are pre-established in the shared memory;

[0098] A data receiving module 503, configured to receive the protocol data packet through the second controller and to check the protocol data packet;

[0099] The data reading module 504 is configured to read the data to be transmitted from the read shared memory through the second controller if the protocol data packet verification passes.

[0100] Optionally, the data sending module 502 includes:

[0101] The copy submodule is used to determine the memory address of the data to be transmitted, and copy the data to be transmitted to the write shared memory using the memory address;

[0102] A generating submodule, configured to generate a protocol data packet using a communication protocol between the first controller and the second controller;

[0103] A sending submodule is used to send the protocol data packet to the second controller through the first controller; wherein the protocol data packet is used by the second controller to determine whether data is written in the write shared memory.

[0104] Optionally, the data receiving module 503 includes:

[0105] A first reading submodule, configured to read the protocol data packet sent by the first controller through a blocking read function of the second controller;

[0106] A parsing submodule, used for parsing the protocol data packet to obtain a header address of the write shared memory in the protocol data packet;

[0107] The check submodule is used to check the head address of the write shared memory to determine whether the head address of the write shared memory satisfies the communication protocol.

[0108] Optionally, the data reading module 504 includes:

[0109] A determination submodule, configured to determine that the protocol data packet verification has passed if the header address of the first controller writing the shared memory satisfies the communication protocol;

[0110] The second reading submodule is used to read the data to be transmitted from the read shared memory through the second controller; wherein a shared memory mapping is pre-established between the first controller and the second controller.

[0111] Optionally, the data reading module 504 further includes:

[0112] The locking submodule is used to add a mutual exclusion lock to the read shared memory; wherein the mutual exclusion lock is used to lock the data reading of the read shared memory and is released after the second controller reads the data to be transmitted from the read shared memory.

[0113] A data transmission device provided in an embodiment of the present invention is applied to a microcontroller, wherein the microcontroller includes a first controller, a second controller and a shared memory, wherein the first controller communicates with the second controller through the shared memory, obtains data to be transmitted through the first controller, copies the data to be transmitted to the write shared memory through the first controller, and sends a protocol data packet to the second controller; wherein a read shared memory and a write shared memory of the first processor and the second processor are pre-established in the shared memory, the protocol data packet is received through the second controller, and the protocol data packet is checked, and if the protocol data packet passes the check, the data to be transmitted is read from the read shared memory through the second controller. The present invention realizes efficient data transmission between MCU cores through shared memory mapping, avoids delays and bandwidth limitations when transmitting data through a bus or other communication interfaces, and reduces the data transmission burden of the bus and the network. The first controller directly copies the data to be transmitted to the write shared memory, which simplifies the data processing process. The read-write shared memory of the first controller and the second controller is pre-established, and data transmission is performed through the shared memory, which ensures the consistency of data transmission in the controller. The use of shared memory allows the first controller and the second controller to access data concurrently, which greatly improves the data transmission speed and the concurrency performance of communication between MCU cores. Through the combination of shared memory and protocol data packets, efficient and reliable data transmission between MCUs is achieved, which meets the requirements of real-time data processing and high concurrency scenarios, and further improves communication efficiency and system reliability.

[0114] Reference Figure 8 , an embodiment of the present invention further provides an electronic device, such as Figure 8As shown, it includes a processor 601, a communication interface 602, a memory 603 and a communication bus 604, wherein the processor 601, the communication interface 602, and the memory 603 communicate with each other through the communication bus 604.

[0115] Memory 603, used for storing computer programs;

[0116] The processor 601 is used to execute the program stored in the memory 603 to implement the following steps:

[0117] Acquiring data to be transmitted through the first controller;

[0118] The data to be transmitted is copied to the write shared memory through the first controller, and a protocol data packet is sent to the second controller; wherein the read shared memory and the write shared memory of the first processor and the second processor are pre-established in the shared memory;

[0119] receiving the protocol data packet through the second controller, and inspecting the protocol data packet;

[0120] If the protocol data packet passes the verification, the data to be transmitted is read from the read shared memory by the second controller.

[0121] The communication bus mentioned in the above terminal can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0122] The communication interface is used for communication between the above terminal and other devices.

[0123] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0124] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0125] In another embodiment of the present invention, a computer-readable storage medium is provided. The computer-readable storage medium stores instructions. When the instructions are executed on a computer, the computer executes the data transmission method described in any one of the above embodiments.

[0126] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.

[0127] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0128] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0129] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims

1. A data transmission method, It is characterized in that Applied to a microcontroller, the microcontroller includes a first controller, a second controller and a shared memory, the first controller communicates with the second controller through the shared memory, and the method includes: Acquiring data to be transmitted through the first controller; The data to be transmitted is copied to the write shared memory through the first controller, and a protocol data packet is sent to the second controller; wherein the read shared memory and the write shared memory of the first processor and the second processor are pre-established in the shared memory; receiving the protocol data packet through the second controller, and inspecting the protocol data packet; If the protocol data packet passes the verification, the data to be transmitted is read from the read shared memory by the second controller.

2. The method according to claim 1, It is characterized in that The sending of a protocol data packet to the second controller through the first controller and copying the data to be transmitted to a write shared memory, wherein the read shared memory and the write shared memory of the first processor and the second processor are pre-established in the shared memory, comprises: Determine the memory address of the data to be transmitted, and use the memory address to copy the data to be transmitted to the write shared memory; generating a protocol data packet using a communication protocol between the first controller and the second controller; The protocol data packet is sent to the second controller through the first controller; wherein the protocol data packet is used by the second controller to determine whether data is written into the write shared memory.

3. The method according to claim 1, It is characterized in that The receiving the protocol data packet through the second controller and inspecting the protocol data packet includes: Reading the protocol data packet sent by the first controller through a blocking read function of the second controller; Parsing the protocol data packet to obtain a header address of the shared memory in the protocol data packet; The head address of the write shared memory is checked to determine whether the head address of the write shared memory satisfies the communication protocol.

4. The method according to claim 1, It is characterized in that If the protocol data packet is verified to be passed, reading the data to be transmitted from the read shared memory by the second controller includes: If the header address of the first controller writing to the shared memory satisfies the communication protocol, determining that the protocol data packet verification passes; The data to be transmitted is read from the read shared memory by the second controller; wherein a shared memory mapping is pre-established between the first controller and the second controller.

5. The method according to claim 4, It is characterized in that If the header address of the first controller writing the shared memory satisfies the communication protocol, after determining that the protocol data packet verification passes, the method further includes: A mutual exclusion lock is added to the read shared memory; wherein the mutual exclusion lock is used to lock the data reading of the read shared memory, and is released after the second controller reads the data to be transmitted from the read shared memory.

6. A data transmission device, It is characterized in that Applied to a microcontroller, the microcontroller includes a first controller, a second controller and a shared memory, the first controller communicates with the second controller through the shared memory, and the device includes: A data acquisition module, used for acquiring data to be transmitted through the first controller; A data sending module, used for copying the data to be transmitted to the write shared memory through the first controller, and sending a protocol data packet to the second controller; wherein the read shared memory and the write shared memory of the first processor and the second processor are pre-established in the shared memory; A data receiving module, used for receiving the protocol data packet through the second controller and checking the protocol data packet; A data reading module is used to read the data to be transmitted from the read shared memory through the second controller if the protocol data packet is verified.

7. The device according to claim 6, It is characterized in that The data sending module comprises: The copy submodule is used to determine the memory address of the data to be transmitted, and copy the data to be transmitted to the write shared memory using the memory address; A generating submodule, configured to generate a protocol data packet using a communication protocol between the first controller and the second controller; A sending submodule is used to send the protocol data packet to the second controller through the first controller; wherein the protocol data packet is used by the second controller to determine whether data is written in the write shared memory.

8. The device according to claim 6, It is characterized in that The data receiving module comprises: A first reading submodule, configured to read the protocol data packet sent by the first controller through a blocking read function of the second controller; A parsing submodule, used for parsing the protocol data packet to obtain a header address of the write shared memory in the protocol data packet; The check submodule is used to check the head address of the write shared memory to determine whether the head address of the write shared memory satisfies the communication protocol.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the computer program is executed by the processor, the method according to any one of claims 1 to 5 is implemented.

10. A readable storage medium, It is characterized in that The readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.

Citation Information

Cited By

  • A high-speed data exchange method and system for embedded heterogeneous platforms

    CN119739548A

  • Synchronization method of controller and electronic equipment

    CN122450866A

  • Data sharing method and apparatus, device, and storage medium

    WO2026112995A1