Data transmission method, device, vehicle-mounted terminal and storage medium

By introducing six-wire SPI communication into the vehicle terminal and using additional signal lines for two-way notification, the data transmission efficiency problem caused by the lack of notification mechanism between the MCU and the SOC is solved, and more efficient and reliable data transmission is achieved.

CN118535510BActive Publication Date: 2025-02-18CHONGQING SELIS PHOENIX INTELLIGENT INNOVATION TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202410523316.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-28
Publication Date
2025-02-18
Estimated Expiration
2044-04-28

AI Technical Summary

Technical Problem

In the on-board terminal, there is a lack of a notification mechanism between the MCU and the SOC, which causes the MCU to fail to receive data successfully, resulting in invalid data transmission and affecting the data transmission efficiency.

Method used

By introducing six-wire SPI communication between the master and slave device, two signal lines are added for two-way notification, ensuring that the master device only starts data transmission before the slave device is ready to receive data.

Benefits of technology

It improves the success rate and efficiency of data transmission, reduces invalid data transmission, ensures that the data receiver is ready to receive data, thereby improving the reliability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118535510B_ABST
    Figure CN118535510B_ABST
Patent Text Reader

Abstract

The present application relates to a data transmission method, device, vehicle-mounted terminal, storage medium and computer program product. The method comprises: setting a first interrupt for a second master pin through an SPI driver in a driver layer, the first interrupt is triggered when the level of the second master pin is changed from a first level to a second level; when there is sending data in the application layer of the master device, the level of the first master pin is changed from a third level to a fourth level through an SPI driver, so that the level of the first slave pin is changed from the third level to the fourth level, triggering the second interrupt of the first slave pin, the second interrupt is used to instruct the slave device to change the level of the second slave pin from the first level to the second level, triggering the first interrupt of the second master pin; when the first interrupt is triggered, the sending data is sent to the slave device through the SPI driver. The use of this method can improve data transmission efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of communication technology, and in particular to a data transmission method, device, vehicle-mounted terminal, storage medium and computer program product. Background Art

[0002] In the field of communications, vehicle terminals can usually communicate through the SPI (Serial Peripheral Interface) bus. Taking the vehicle terminal TBOX (Telematics Box) as an example, TBOX is composed of a microcontroller unit (MCU) and a system on chip (SOC). The microcontroller and the system on chip each have different responsibilities and communicate through the SPI bus.

[0003] In traditional technology, four-wire SPI (also called four-wire SPI) is usually used for communication in vehicle terminals. When the MCU needs a signal on the vehicle Ethernet, the SOC needs to receive the signal and send it to the MCU. Due to the use of four-wire SPI, there is no notification mechanism between the MCU and the SOC. When the MCU slave is not ready to receive data, the SOC host directly initiates data transmission, which may easily cause the MCU to fail to successfully receive data, resulting in invalid data transmission and affecting data transmission efficiency. Summary of the invention

[0004] Based on this, it is necessary to provide a data transmission method, device, vehicle-mounted terminal, computer-readable storage medium and computer program product that can improve data transmission efficiency in response to the above technical problems.

[0005] On the one hand, the present application provides a data transmission method, which is executed by a master device in a vehicle-mounted terminal, and the master device communicates with a slave device in the vehicle-mounted terminal based on a serial peripheral interface SPI. A first master pin in the master device is connected to a first slave pin in the slave device through a first signal line, and a second master pin in the master device is connected to a second slave pin in the slave device through a second signal line. The SPI driver in the driver layer of the master device is provided with a first interrupt for the second master pin, and the first interrupt is triggered when the level of the second master pin changes from a first level to a second level, including: when there is sending data in the application layer of the master device, the level of the first master pin is changed from a third level to a fourth level through the SPI driver, so that the level of the first slave pin is changed from the third level to the fourth level, triggering the second interrupt of the first slave pin, and the second interrupt is used to instruct the slave device to change the level of the second slave pin from the first level to the second level, triggering the first interrupt of the second master pin; in response to the first interrupt, transmitting the sending data to the slave device through the SPI driver.

[0006] In some embodiments, in response to the first interrupt, transmitting the send data to the slave device through the SPI driver includes: in response to the first interrupt, calling the SPI interface function through the SPI driver, transmitting the send data to the slave device, and receiving receive data from the slave device.

[0007] In some embodiments, the method further includes: when sending and receiving are completed, restoring the level of the first master pin to a third level; the sending and receiving are completed, used to trigger the slave device to restore the level of the second slave pin to the first level.

[0008] In some embodiments, when there is sending data in the application layer of the master device, changing the level of the first master pin from the third level to the fourth level through the SPI driver includes: when there is sending data in the application layer of the master device, writing the sending data into the data sending queue of the driver layer through the SPI driver; changing the level of the first master pin from the third level to the fourth level through the SPI driver; in response to the first interrupt, transmitting the sending data to the slave device through the SPI driver, includes: in response to the first interrupt, sending the sending data in the data sending queue to the slave device through the SPI driver.

[0009] In some embodiments, in response to the first interrupt, transmitting the send data to the slave device through the SPI driver includes: in response to the first interrupt, writing the send data into a send register corresponding to the SPI driver through the SPI driver; and sending the send data in the send register to the slave device.

[0010] In some embodiments, in response to the first interrupt, transmitting the send data to the slave device through the SPI driver, includes: when the first interrupt is triggered within a preset time length after the level of the first master pin is changed from the third level to the fourth level, in response to the first interrupt, transmitting the send data to the slave device through the SPI driver; the method also includes: when the first interrupt is not triggered within the preset time length, changing the level of the first master pin from the fourth level to the third level.

[0011] In some embodiments, the application layer is deployed with an SPI application layer program corresponding to the SPI driver, and the method further includes: generating an SPI handle of the master device through the SPI application layer program, and the SPI handle points to a device file of the master device; accessing the device file through the SPI handle, and when the device file changes, obtaining received data from a data receive queue of the SPI driver.

[0012] On the other hand, the present application also provides a data transmission device, which belongs to a master device in a vehicle-mounted terminal, and the master device communicates with the slave device in the vehicle-mounted terminal based on a serial peripheral interface SPI. The first master pin in the master device is connected to the first slave pin in the slave device through a first signal line, and the second master pin in the master device is connected to the second slave pin in the slave device through a second signal line. The SPI driver in the driver layer of the master device is provided with a first interrupt for the second master pin, and the first interrupt is triggered when the level of the second master pin is changed from the first level to the second level. The device includes: a level change module, which is used to change the level of the first master pin from the third level to the fourth level through the SPI driver when there is sending data in the application layer of the master device, so that the level of the first slave pin is changed from the third level to the fourth level, triggering the second interrupt of the first slave pin, and the second interrupt is used to instruct the slave device to change the level of the second slave pin from the first level to the second level, triggering the first interrupt of the second master pin; a data transmission module, which is used to transmit the sending data to the slave device through the SPI driver in response to the first interrupt.

[0013] In some embodiments, the data transmission module is further used to respond to the first interrupt, call the SPI interface function through the SPI driver, transmit the send data to the slave device, and receive the receive data from the slave device.

[0014] In some embodiments, the level changing module is also used to restore the level of the first master pin to a third level when sending and receiving are completed; the sending and receiving are completed to trigger the slave device to restore the level of the second slave pin to the first level.

[0015] In some embodiments, the level change module is also used to, when there is sending data in the application layer of the master device, write the sending data into the data sending queue of the driver layer through the SPI driver; change the level of the first master pin from the third level to the fourth level through the SPI driver; the data transmission module is also used to respond to the first interrupt and send the sending data in the data sending queue to the slave device through the SPI driver.

[0016] In some embodiments, the data transmission module is further used to respond to the first interrupt, write the transmission data into a transmission register corresponding to the SPI driver through the SPI driver; and send the transmission data in the transmission register to the slave device.

[0017] In some embodiments, the data transmission module is also used to trigger the first interrupt within a preset time after the level of the first main pin is changed from the third level to the fourth level, and in response to the first interrupt, transmit the send data to the slave device through the SPI driver; the level change module is also used to change the level of the first main pin from the fourth level to the third level when the first interrupt is not triggered within the preset time.

[0018] In some embodiments, the application layer is deployed with an SPI application layer program corresponding to the SPI driver, and the device also includes an application layer data receiving module, which is used to generate an SPI handle of the master device through the SPI application layer program, and the SPI handle points to the device file of the master device; access the device file through the SPI handle, and when the device file changes, obtain the received data from the data receiving queue of the SPI driver.

[0019] On the other hand, the present application also provides a vehicle-mounted terminal, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps in the above-mentioned data transmission method when executing the computer program.

[0020] On the other hand, the present application also provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps in the above-mentioned data transmission method are implemented.

[0021] On the other hand, the present application also provides a computer program product, including a computer program, which implements the steps in the above-mentioned data transmission method when executed by a processor.

[0022] The above-mentioned data transmission method, device, vehicle-mounted terminal, storage medium and computer program product, through the SPI driver in the driver layer, sets the first interrupt for the second master pin, the first interrupt is triggered when the level of the second master pin changes from the first level to the second level, when the application layer of the master device has sending data, the level of the first master pin is changed from the third level to the fourth level through the SPI driver, so that the level of the first slave pin is changed from the third level to the fourth level, triggering the second interrupt of the first slave pin, the second interrupt is used to instruct the slave device to change the level of the second slave pin from the first level to the second level, triggering the first interrupt of the second master pin, when the first interrupt is triggered, the transmission data is sent to the slave device through the SPI driver. Because when the application layer of the master device has sending data, the level of the first slave pin of the slave device changes, so that the slave device can be notified by the level change of the first slave pin to accurately receive the data, improve the success rate of the slave device receiving data, reduce invalid data transmission, and improve data transmission efficiency. In addition, since the driver layer of the master device monitors the first signal line and the second signal line, when SPI is used for data communication, the application layer does not need to monitor the two newly added signal lines. Compared with deploying the signal line monitoring function at the application layer, the signal changes can be monitored in time, the SPI communication rate can be increased, and the data transmission efficiency can be further improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0024] Figure 1 is an application environment diagram of a data transmission method in an embodiment;

[0025] Figure 2 is a structural diagram of a vehicle-mounted terminal in one embodiment;

[0026] Figure 3 A system architecture diagram of a main device in an embodiment;

[0027] Figure 4 is a system architecture diagram of a main device in another embodiment;

[0028] Figure 5 A schematic diagram of a flow chart of a data transmission method in an embodiment;

[0029] Figure 6 A schematic diagram of a process of sending data by a master device in one embodiment;

[0030] Figure 7 A schematic diagram of an application layer program flow of a master device in one embodiment;

[0031] Figure 8 A schematic diagram of a process of receiving data by an application layer of a master device in one embodiment;

[0032] Fig. 9 A schematic diagram of a process of sending data by an application layer of a master device in one embodiment;

[0033] Fig.10 A schematic diagram of a flow chart of a data transmission method in another embodiment;

[0034] Fig.11 is a structural block diagram of a data transmission device in one embodiment;

[0035] Fig.12 FIG. 4 is a diagram showing the internal structure of a vehicle-mounted terminal in one embodiment. DETAILED DESCRIPTION

[0036] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0037] The data transmission method provided in the embodiment of the present application can be applied to Figure 1In the application environment shown, the application environment includes a vehicle 102, a vehicle-mounted terminal 104 and a control device 106, and the vehicle-mounted terminal 104 is a part of the vehicle 102. Among them, the vehicle 102 and the control device 106 can communicate through the vehicle-mounted terminal 104. The vehicle-mounted terminal 104 can receive data sent by the control device 106, and can also send data to the control device 106. The vehicle-mounted terminal 104 and the control device can communicate through a wired or wireless network, for example, they can communicate through Ethernet. The vehicle-mounted terminal 104 can be any vehicle-mounted terminal, for example, it can be TBOX, which is the abbreviation of Telematics BOX and is a smart vehicle-mounted terminal. Among them, the control device 106 can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers and portable wearable devices. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc.

[0038] The vehicle terminal 104 includes a master device and a slave device. The master device may be, for example, a SOC (System on Chip). The slave device may be, for example, an MCU (Microcontroller Unit). The master device and the slave device communicate via SPI (Serial Peripheral Interface), for example, via four-wire SPI. The SPI bus is a full-duplex synchronous serial communication interface. The four-wire SPI uses four wires to achieve communication between the master device and the slave device. The four wires are: (1) SCLK (Serial Clock): a serial clock line generated by the master device for synchronous data transmission; (2) MOSI (Master Out Slave In): a master device data output and slave device data input line; (3) MISO (Master In Slave Out): a master device data input and slave device data output line; (4) CS (ChipSelect): a slave device enable signal line, also known as SS (Slave Select), controlled by the master device.

[0039] However, the four-wire SPI communication method has the following problems: when the MCU needs a signal on the vehicle Ethernet, the SOC needs to receive the signal and send it to the MCU. If the four-wire SPI is used, there is no notification mechanism between the MCU and the SOC, which will cause the MCU's slave device to not be ready to receive data. The SOC, as the master device, directly initiates data transmission, causing the MCU to fail to successfully receive data.

[0040] In this application, the master device and the slave device communicate via a six-wire SPI. The six-wire SPI adds two signal lines between the master device and the slave device while keeping the original four-wire SPI hardware unchanged, so as to realize the two-way notification function when the SPI slave device and the SPI master device transmit data. This design can enhance the flexibility and reliability of SPI communication, especially in scenarios where asynchronous data transmission is required or it is necessary to ensure that the data receiver is ready. These two lines can be called "notification lines" and are used to transmit status information and control signals between the SPI master device and the SPI slave device. When one party is ready to send data or ready to receive data, it can send a signal to the other party through the notification line. Figure 2 As shown in the figure, the master device and the slave device communicate through the six-wire SPI. The six-wire SPI adds two signal lines on the basis of the four-wire SPI. The two newly added signal lines can be any two idle signal lines. These two signal lines are general-purpose input / output (GPIO) signal lines. GPIO can realize the functions of data input and data output. The two newly added signal lines are called the first signal line and the second signal line respectively. The first signal line is recorded as GPIO1 and the second signal line is recorded as GPIO2. The two newly added signal lines can realize the two-way notification function between the master device and the slave device during data transmission. Figure 2 In the figure, the four solid lines in the dotted box 1 represent the four signal lines in the four-wire SPI, and the two dotted lines in the dotted box 2 represent the two newly added signal lines in the six-wire SPI.

[0041] The master device can communicate with the control device 106 via Ethernet. For example, the SOC is usually connected to the vehicle's Ethernet network. Ethernet is used for high-speed, large-capacity data transmission in automobiles, especially when it is necessary to process multimedia content or interact with other vehicle systems (such as navigation systems, entertainment systems, etc.). The slave device can transmit information such as vehicle status and control instructions through the CAN bus. For example, if there is air conditioning on the vehicle, the control device 106 sends air conditioning control instructions to the master device, the master device transmits the air conditioning control instructions to the slave device, and the slave device transmits the air conditioning control instructions to the air conditioning through the CAN bus. The CAN (Controller Area Network) bus is a serial communication protocol bus for real-time applications. The CAN network is a communication protocol used to connect different electronic control units (ECUs) inside the vehicle, allowing ECUs to exchange information to realize various functions of the vehicle.

[0042] Since the six-wire SPI has two more signal lines than the four-wire SPI, the master device needs to monitor the two additional signal lines. Considering that the signal line monitoring function can be deployed to the application layer, a solution to deploy the signal line monitoring function to the application layer is implemented, such as Figure 3 As shown in the figure, a system architecture diagram of the main device is shown in which the signal line monitoring function is deployed to the application layer. The main device has an application layer, a driver layer and a hardware layer. The application layer provides a four-wire SPI communication interface, and also provides data processing and signal line monitoring functions. The signal line monitoring is used to monitor the two newly added signal lines, and the driver layer provides a four-wire SPI driver. Since the application layer program of the Linux operating system is affected by the system scheduling, the signal change cannot be detected immediately, resulting in a decrease in the SPI communication rate, which affects the data transmission efficiency. The operation of the application layer program is affected by the CPU occupancy rate. When the CPU occupancy rate is high, the execution of the application program will be significantly slowed down, which will reduce the SPI communication rate. The application layer monitors the two newly added signal lines, which will make the logic of the application layer program complicated, which does not conform to the concept of Linux application software and hardware layering, and reduces the stability of the application layer program. It is found that there are many problems in the solution of deploying the signal line monitoring function to the application layer, which affects the data transmission efficiency and the stability of the application layer program.

[0043] Since there are many problems with deploying the signal line monitoring function to the application layer, a solution to deploy the signal line monitoring function to the driver layer is further implemented, such as Figure 4 As shown, the system architecture diagram of the main device is shown when the signal line monitoring function is deployed to the driver layer. The driver layer is deployed with an SPI driver. The SPI driver includes a four-wire SPI driver and provides a signal line monitoring function. The four-wire SPI driver is the driver corresponding to the four-wire SPI. Signal line monitoring refers to monitoring the first signal line and the second signal line. The operating system on the SOC can be a Linux operating system, so the application layer can be a Linux application layer. The driver layer is in the Linux kernel space, and the driver layer can be called a Linux driver layer.

[0044] Specifically, the SPI used by the master device and the slave device is a six-wire SPI. The SPI driver in the driver layer of the master device sets the first interrupt on the second master pin, and the first interrupt is triggered when the level of the second master pin changes from the first level to the second level. When there is sending data in the application layer of the master device, the SPI driver in the driver layer changes the level of the first master pin from the third level to the fourth level. When the level of the first master pin changes from the third level to the fourth level, the second interrupt of the first slave pin is triggered in the slave device. The second interrupt is an interrupt pre-set for the first slave pin in the slave device. When the second interrupt is triggered, the slave device changes the level of the second slave pin from the first level to the second level. When the level of the second slave pin changes from the first level to the second level, the first interrupt of the second master pin is triggered in the master device; when the first interrupt is triggered, the SPI driver in the application layer of the master device sends the sending data to the slave device. Pins are pins.

[0045] In some embodiments, Figure 5 As shown, a data transmission method is provided, which is applied to Figure 1 Taking the master device in the vehicle terminal 104 in the vehicle terminal as an example, the master device and the slave device in the vehicle terminal communicate based on the serial peripheral interface SPI, the first signal line is the signal line between the first master pin in the master device and the first slave pin in the slave device, the second signal line is the signal line between the second master pin in the master device and the second slave pin in the slave device, the SPI driver in the driver layer of the master device is provided with a first interrupt for the second master pin, and the first interrupt is triggered when the level of the second master pin changes from the first level to the second level, including the following steps 502 to 504. Among them:

[0046] Step 502, when the application layer of the master device has data to send, the level of the first master pin is changed from the third level to the fourth level through the SPI driver, so that the level of the first slave pin is changed from the third level to the fourth level, triggering the second interrupt of the first slave pin, and the second interrupt is used to instruct the slave device to change the level of the second slave pin from the first level to the second level, so as to trigger the first interrupt of the second master pin.

[0047] The SPI used by the master device and the slave device is a six-wire SPI. The six-wire SPI adds a first signal line and a second signal line on the basis of the four-wire SPI. The first master pin and the second master pin are two different pins on the master device, and the first slave pin and the second slave pin are two different pins on the slave device. The first master pin and the first slave pin are connected, and the signal line connected between the first master pin and the first slave pin is the first signal line. The second master pin and the second slave pin are connected, and the signal line connected between the second master pin and the second slave pin is the second signal line.

[0048] Sending data refers to the data that the master device needs to send to the slave device. In the application layer, sending data refers to the data that needs to be sent to the slave device. The sending data can come from the control device.

[0049] The occurrence of the first interrupt is used to instruct the SPI driver to change the level of the first main pin from the third level to the fourth level. The first interrupt can be set by the SPI driver during initialization or startup. The SPI driver (i.e., the six-wire SPI driver) includes a four-wire SPI driver and provides a function of monitoring the first signal line and the second signal line. Monitoring the first signal line and the second signal line means monitoring the level and level change of the pins to which the first signal line and the second signal line are connected.

[0050] The first level is different from the second level. When the first interrupt is a rising edge interrupt, the first level is a low level and the second level is a high level. When the first interrupt is a falling edge interrupt, the first level is a high level and the second level is a low level.

[0051] The level initialized by the first master pin is the third level. The third level is different from the fourth level. When the second interrupt is a rising edge interrupt, the third level is a low level and the fourth level is a high level, thereby changing the level of the first master pin from the third level to the fourth level, so that the first master pin generates a rising edge. Since the first slave pin is connected to the first master pin, the first slave pin also generates a rising edge. When the first slave pin generates a rising edge, the second interrupt is triggered. Of course, the second interrupt can also be a falling edge interrupt. When the slave device determines that the level of the first slave pin is changed from the third level to the fourth level, the slave device can enter the data receiving state, which can ensure that the slave device can be ready to receive before the data arrives, thereby avoiding data loss or reception errors and improving the reliability of data transmission.

[0052] Specifically, when the SPI driver in the driver layer is initialized, the SPI driver in the driver layer of the master device sets a first interrupt for the second main pin, and the first interrupt is triggered when the level of the second main pin changes from the first level to the second level.

[0053] In some embodiments, when the SPI driver is initialized in the driver layer, the SPI driver sets the first signal line parameter and the second signal line parameter, and the first signal line parameter includes a master pin parameter and a slave pin parameter. The first signal line can be determined by setting the first signal line parameter. Similarly, the second signal line parameter includes a master pin parameter and a slave pin parameter, and the second signal line can be determined by setting the second signal line parameter. The SPI driver sets the master pin parameter in the first signal line parameter to the pin number of the first master pin and the slave pin parameter device to the pin number of the first slave pin, and sets the master pin parameter device in the second signal line parameter to the second master pin and the slave pin parameter to the pin number of the second slave pin. Thus, the first signal line and the second signal line for communication between the master device and the slave device are created.

[0054] In some embodiments, when the SPI driver is started in the driver layer, the SPI driver can set the SPI basic parameters, which include at least one parameter of clock frequency, bit width, and polarity. The SPI driver can also set other parameters of the four-wire SPI.

[0055] In some embodiments, after the SPI driver changes the level of the first master pin from the third level to the fourth level, it waits for feedback from the slave device, that is, waits for the slave device to change the level of the second slave pin from the first level to the second level, so that the level of the second master pin is changed from the first level to the second level. When the master device determines that the level of the second master pin is changed from the first level to the second level, it is determined that the slave device is already in a state where data can be received, and then the master device transmits data to the slave device through the SPI driver. The slave device sets a second interrupt for the first slave pin, and the second interrupt is triggered when the level of the first slave pin is changed from the third level to the fourth level. When the second interrupt is triggered in the slave device, the slave device changes the level of the second slave pin from the first level to the second level. Since the second slave pin is connected to the second master pin, changing the level of the second slave pin from the first level to the second level will cause the level of the second master pin to change from the first level to the second level, thereby triggering the first interrupt of the second master pin.

[0056] Step 504: In response to the first interrupt, transmit data to the slave device through the SPI driver.

[0057] Specifically, when determining that the first interrupt is triggered, the SPI driver in the master device writes the send data into the send register, which is used to store data sent to the slave device. The master device can send the send data in the send register to the slave device.

[0058] In some embodiments, the master device can call the SPI interface function to send the transmit data to the slave device. For example, the SPI driver in the master device can call the SPI interface function to send the transmit data to the slave device. The SPI interface function is a software interface used by the master device to control SPI communication. By calling these functions, the master device can generate the clock signal required by the SPI protocol and transmit the transmit data to the slave device through the SPI signal line MOSI.

[0059] In the above data transmission method, the first interrupt is set for the second master pin through the SPI driver in the driver layer, and the first interrupt is triggered when the level of the second master pin is changed from the first level to the second level. When the application layer of the master device has sending data, the level of the first master pin is changed from the third level to the fourth level through the SPI driver, so that the level of the first slave pin is changed from the third level to the fourth level, triggering the second interrupt of the first slave pin, and the second interrupt is used to instruct the slave device to change the level of the second slave pin from the first level to the second level, triggering the first interrupt of the second master pin, and when the first interrupt is triggered, the sending data is sent to the slave device through the SPI driver. Because when the application layer of the master device has sending data, the level of the first slave pin of the slave device changes, so that the slave device can be notified by the level change of the first slave pin to accurately receive data, improve the success rate of the slave device receiving data, reduce invalid data transmission, and improve data transmission efficiency and data transmission reliability. In addition, since the driver layer of the master device monitors the first signal line and the second signal line, when using six-wire SPI for data communication, the application layer does not need to monitor the two newly added signal lines. Compared with the above deployment of the signal line monitoring function at the application layer, the signal changes can be monitored in time, the SPI communication rate can be increased, thereby further improving the data transmission efficiency.

[0060] In addition, it can reduce the impact of system calls and CPU occupancy on data transmission efficiency, reduce the impact of application layer scheduling on SPI communication rate, simplify application layer program logic, and improve application layer program stability.

[0061] In some embodiments, in response to the first interrupt, transmitting data to the slave device through the SPI driver includes: in response to the first interrupt, calling the SPI interface function through the SPI driver, transmitting the data to the slave device, and receiving the received data from the slave device.

[0062] When the slave device changes the level of the second slave pin from the first level to the second level, the slave device can send data to the master device, so that the first interrupt is also used to trigger the master device to receive data from the slave device. The data from the slave device is called received data. The master device can transmit the send data to the slave device through the MOSI signal line, and the master device can receive the receive data from the slave device through the MISO signal line.

[0063] Specifically, the SPI driver in the driver layer of the master device responds to the first interrupt, calls the SPI interface function, sends the transmission data to the slave device, and receives the reception data from the slave device. The master device can store the reception data in the data reception queue corresponding to the SPI driver.

[0064] In this embodiment, in the first interruption, data can be sent to the slave device and data can be received from the slave device, thereby realizing parallel transmission and reception and improving data transmission effect.

[0065] Of course, when the master device does not send data to the slave device, it can also receive data from the slave device. Specifically, when the slave device needs to send data to the master device, the slave device can actively change the level of the second slave pin from the first level to the second level, for example, from the low level to the high level to generate a rising edge, and the SPI driver of the master device detects that the level of the second slave pin changes from the first level to the second level, generates an interrupt, and calls the SPI interface function in the interrupt callback function to receive data from the slave device. After the reception is completed, the slave device restores the level of the second slave pin to the first level.

[0066] In some embodiments, the method further includes: when sending and receiving are completed, restoring the level of the first master pin to a third level; when sending and receiving are completed, triggering the slave device to restore the level of the second slave pin to the first level.

[0067] The sending is completed and the receiving is completed, which means that the sending of the sending data to the slave device is completed, and the receiving of the receiving data from the slave device is completed.

[0068] Specifically, when the sending and receiving are completed, the SPI driver changes the level of the first master pin from the fourth level to the third level. The master device can use an interrupt to notify the SPI driver that the sending of the data has been completed.

[0069] In some embodiments, when sending and receiving are completed, the slave device restores the level of the second slave pin to the first level, and again enters the step of changing the level of the first master pin from the third level to the fourth level through the SPI driver when there is sending data in the application layer of the master device.

[0070] In this embodiment, when sending and receiving are completed, the level of the first main pin is restored to the third level, so that when there is sending data in the application layer of the main device, the step of changing the level of the first main pin from the third level to the fourth level through the SPI driver can be entered again, and the process of receiving and sending data can be cyclic.

[0071] In some embodiments, when there is sending data in the application layer of the master device, the level of the first master pin is changed from the third level to the fourth level through the SPI driver, including: when there is sending data in the application layer of the master device, the sending data is written into the data sending queue of the driver layer through the SPI driver; the level of the first master pin is changed from the third level to the fourth level through the SPI driver; in response to the first interrupt, the sending data is transmitted to the slave device through the SPI driver, including: in response to the first interrupt, the data is sent to the data sending queue of the slave device through the SPI driver.

[0072] The data transmission queue of the driver layer is used to store transmission data, that is, data to be sent to the slave device. The driver layer may also have a data reception queue, which is used to store data from the slave device.

[0073] Specifically, the SPI driver in the master device responds to the first interrupt and sends data in the data transmission queue to the slave device through the SPI driver. The SPI driver can directly transmit the transmission data in the transmission data transmission queue to the slave device, or the SPI driver can write the transmission data into the driver layer, obtain the transmission data from the driver layer, and then transmit it to the slave device.

[0074] In some embodiments, there may be at least one transmission data in the application layer, and the SPI driver may send each transmission data in turn. The data amount of the transmission data may be less than or equal to the preset data amount, and the preset data amount may be, for example, 100 bytes. When there is at least one transmission data in the application layer of the master device, the SPI driver may write one of the transmission data into the data transmission queue of the driver layer. When the transmission data in the at least one transmission data has a transmission sequence, the SPI driver may select a transmission data that needs to be sent first from the at least one transmission data according to the transmission sequence, and write the selected transmission data into the data transmission queue of the driver layer. And after writing the transmission data into the data transmission queue of the driver layer, the SPI driver in the master device changes the level of the first main pin from the third level to the fourth level, thereby changing the level of the first main pin from the third level to the fourth level while ensuring that there is transmission data in the driver layer.

[0075] In this embodiment, after the transmission data is written into the data transmission queue of the driver layer, the SPI driver in the master device changes the level of the first main pin from the third level to the fourth level, thereby ensuring that there is transmission data in the driver layer. The level of the first main pin is changed from the third level to the fourth level, which can ensure that the driver layer can carry out the subsequent data transmission process when there is transmission data, thereby improving data transmission efficiency.

[0076] In some embodiments, in response to the first interrupt, transmitting the transmit data to the slave device via the SPI driver, including: in response to the first interrupt, writing the transmit data into a transmit register corresponding to the SPI driver via the SPI driver; transmitting the transmit data in the transmit register to the slave device.

[0077] The sending register corresponding to the SPI driver may be a sending register corresponding to a four-wire SPI driver.

[0078] Specifically, the SPI driver in the master device writes the transmission data into the transmission register corresponding to the four-wire SPI driver in the SPI driver. The MOSI signal line in the four-wire SPI is the signal line for the master device to send data to the slave device. The master device can transmit the transmission data in the transmission register to the slave device through the MOSI signal line.

[0079] In some embodiments, when the SPI driver writes the transmit data into the data transmit queue of the driver layer, the SPI driver responds to the first interrupt, obtains the transmit data from the data transmit queue of the driver layer through the SPI driver, and writes the transmit data into the transmit register corresponding to the SPI driver; and sends the data to the transmit register transmitted from the device.

[0080] In this embodiment, the transmission register is fully utilized in the SPI driver to realize data transmission, thereby improving the data transmission efficiency.

[0081] In some embodiments, in response to a first interrupt, data is transmitted to a slave device via an SPI driver, including: when the first interrupt is triggered within a preset time after the level of the first master pin is changed from a third level to a fourth level, in response to the first interrupt, data is transmitted to the slave device via an SPI driver; the method also includes: when the first interrupt is not triggered within the preset time, changing the level of the first master pin from the fourth level to the third level.

[0082] The preset duration can be set as needed, for example, 3 seconds.

[0083] Specifically, the SPI driver in the master device can record the time point when the level of the first master pin changes from the third level to the fourth level, obtain the reference time point, and calculate the duration between the current time point and the reference time point. If the duration between the current time point and the reference time point does not reach the preset duration, continue to wait for the first interrupt. If the duration between the current time point and the reference time point reaches the preset duration, the level of the first master pin is changed from the fourth level to the third level, and the step of changing the level of the first master pin from the third level to the fourth level through the SPI driver when there is data to be sent at the application layer of the master device is entered again.

[0084] In this embodiment, if the duration between the current time point and the reference time point reaches the preset duration, the level of the first main pin is changed from the fourth level to the third level, thereby avoiding waiting when the slave device does not trigger the first interrupt, thereby improving data transmission efficiency.

[0085] Take an example to illustrate the operation process of SPI driver, such as Figure 6 As shown, the flowchart of the SPI driver is shown. Before transmitting data, the SPI driver is initialized first. The initialization includes: setting the basic parameters of SPI, "setting the pin number", setting the second main pin to the rising edge interrupt mode, and setting other parameters of the four-wire SPI. The basic parameters of SPI include at least one of clock frequency, bit width or polarity. Among them, "setting the pin number" means "setting the GPIO1 and GPIO2 pin numbers". GPIO1 represents the first information line, GPIO2 represents the second signal line, setting the GPIO1 pin number means setting the first signal line parameters, and setting the GPIO2 pin number means setting the second signal line parameters. How to set the first signal line parameters and the second signal line parameters has been described above and will not be repeated here. Setting the second main pin to the rising edge interrupt mode means setting the rising edge interrupt for the second main pin, that is, the first interrupt is a rising edge interrupt. After the SPI driver is initialized, it is determined whether the application layer has data to send. If so, the application layer data is copied to the data sending queue of the driver layer. "Setting the first main pin high level" means changing the level of the first main pin connected to the signal line GPIO1 from the third level (low level) to the fourth level (high level). Then, "wait for the first interrupt" means waiting for the level of the second slave pin to change from the first level to the second level to trigger the first interrupt. If it is reached, add the transmit data to the four-wire SPI transmit register, turn on the four-wire SPI data transmission interrupt, call the SPI interface function in the interrupt callback function, wait for the data transmission to be completed, and set the first master pin to a low level, that is, restore the level of the first master pin to the third level (low level).

[0086] In some embodiments, the method further includes: generating an SPI handle of the master device through the application layer; when the file pointed to by the SPI handle changes, obtaining the received data from the data receiving queue in the driver layer.

[0087] Among them, the SPI handle is a reference or identifier used to uniquely identify and access SPI devices or resources in a program. The handle is usually a pointer or integer, which allows software to communicate with SPI devices in an abstract way without directly understanding the complex details of the underlying hardware.

[0088] Specifically, when the device file changes, it indicates that the SPI driver has received new data from the slave device and written it into the data receiving queue of the SPI driver. The data receiving queue of the SPI driver is used to store data from the slave device and is used to transmit it to the application layer of the master device. Therefore, when the device file is sent and changed, the received data is obtained from the data receiving queue of the SPI driver. The SPI application layer program can parse the received data, and if the received data is the data requested by the control device, the SPI application layer program can send the received data to the control device. The SPI application layer program can call the read function to read the received data from the data receiving queue of the driver. After determining that the device file has changed, the SPI application layer program can set the data receiving area address and write the read received data into the storage space pointed to by the data receiving area address.

[0089] In some embodiments, the application layer is deployed with an SPI application layer program corresponding to the SPI driver, such as Figure 7 As shown in FIG. 1 , the overall flow chart of the SPI application layer program is provided. After the SPI application layer program is started, the SPI is initialized, a receiving data thread is created, and a sending data thread is created. Among them, the initialization of SPI is used to obtain the SPI handle. From Figure 7 It can be seen that the receiving (reading) data and sending (writing) data in the SPI application layer program are executed in independent threads, which improves the efficiency of reading and writing data in the application layer.

[0090] For example, the SPI handle can be represented as g_rpcSpiFd, g_rpcSpiFd = open(" / dev / spi5_0_0", O_RDWR | O_NONBLOCK), " / dev / spi5_0_0" is the name of the SPI device. O_RDWR means that the SPI device can be read and written, that is, data can be written to the SPI device and data can be read from the SPI device. In the Linux system, the open function is used to open a file or device. O_NONBLOCK means that the SPI device is in non-blocking mode. In blocking mode, if you try to read data from the SPI device but the SPI device currently has no data to read, the calling thread will be suspended until there is data to read. In non-blocking mode, if the SPI device has no data to read, the call will immediately return an error instead of suspending the thread. After successfully calling the open function, it will return a file descriptor (usually a non-negative integer).

[0091] In some embodiments, the SPI application layer program in the master device application layer can use the select method to monitor whether the driver layer of the master device has data to read. The select method is a mechanism for monitoring the state changes of multiple file descriptors. The SPI handle can be understood as a file descriptor. The master device can add the SPI handle to the select list, and then call the select method to monitor the SPI handle in the select list to determine whether the device file pointed to by the SPI handle has changed. Figure 8 As shown, a flow chart of the SPI application layer program receiving data is shown. The six-wire application adds the SPI handle to a list, such as a select list, and listens to the SPI handle in the list, such as calling the select method to listen to the SPI handle. If the SPI handle has not changed, the step of listening to the SPI handle in the list is entered again. If the SPI handle has changed (that is, new data is written to the device file pointed to by the SPI handle), the data receiving area address is set, and the read function is called to read data from the driver layer. The read data is parsed and the corresponding instructions are executed. The execution of the corresponding instructions can be, for example, sending the parsed data to the control device or processing the parsed data before sending it to the control device. After parsing the read data and executing the corresponding instructions, the step of listening to the SPI handle in the list is entered again.

[0092] In some embodiments, the SPI application layer program sends data by calling the write function. Fig. 9As shown, the flow chart of the application layer sending data is shown, which determines whether there is data to be sent. If not, it enters the step of determining whether there is data to be sent again. If so, it takes out the sending data and calls the write function to send the data to be sent to the driver layer, and then enters the step of determining whether there is data to be sent.

[0093] In this embodiment, the SPI application layer program can quickly determine whether it is necessary to obtain received data from the data receiving queue of the SPI driver by accessing the device file through the SPI handle, thereby improving the efficiency of the application layer in reading data.

[0094] In some embodiments, Fig.10 As shown, a data transmission method is provided, which is applied to Figure 1 Taking the master device in the vehicle terminal 104 as an example, the master device and the slave device in the vehicle terminal communicate based on the serial peripheral interface SPI, the first signal line is a signal line between the first master pin in the master device and the first slave pin in the slave device, and the second signal line is a signal line between the second master pin in the master device and the second slave pin in the slave device, including the following steps 1002 to 1010. Wherein:

[0095] Step 1002: Setting a first interrupt for a second main pin through an SPI driver in a driver layer of a master device, wherein the first interrupt is triggered when a level of the second main pin changes from a first level to a second level.

[0096] Step 1004 , when the application layer of the master device has data to send, the data to be sent is written into the data sending queue of the driver layer through the SPI driver.

[0097] Step 1006, changing the level of the first master pin from the third level to the fourth level through the SPI driver, so that the level of the first slave pin is changed from the third level to the fourth level, triggering the second interrupt of the first slave pin, the second interrupt is used to instruct the slave device to change the level of the second slave pin from the first level to the second level, triggering the first interrupt of the second master pin.

[0098] Step 1008, in response to the first interrupt, obtain the transmit data from the data transmit queue of the driver layer through the SPI driver, and write the transmit data into the transmit register corresponding to the SPI driver, call the SPI interface function through the SPI driver, send the data in the transmit register to the slave device, and receive the receive data from the slave device.

[0099] Step 1010: When the sending and receiving are completed, the level of the first main pin is restored to the third level.

[0100] Among them, when the sending and receiving are completed, the level of the first main pin is restored to the third level, and the step of changing the level of the first main pin from the third level to the fourth level through the SPI driver when there is sending data in the application layer of the main device is returned.

[0101] In this embodiment, in the scenario of using six-wire SPI communication, since the monitoring of hardware signals (monitoring of SPI signal lines) is placed in the driver layer of the operating system kernel state, the real-time performance is high, the communication rate of the six-wire SPI is improved, and the application layer program is made simple and stable. In addition, the impact of CPU occupancy on the six-wire SPI communication rate is reduced, thereby ensuring the real-time performance of data transmission as much as possible.

[0102] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0103] Based on the same inventive concept, the embodiment of the present application also provides a data transmission device for implementing the data transmission method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more data transmission device embodiments provided below can refer to the limitations on the data transmission method above, and will not be repeated here.

[0104] In some embodiments, Fig.11 As shown, a data transmission device is provided, which belongs to a master device in a vehicle-mounted terminal, the master device communicates with a slave device in the vehicle-mounted terminal based on a serial peripheral interface SPI, a first master pin in the master device is connected to a first slave pin in the slave device through a first signal line, a second master pin in the master device is connected to a second slave pin in the slave device through a second signal line, and a first interrupt is set for the second master pin in the SPI driver layer of the master device, and the first interrupt is triggered when the level of the second master pin changes from the first level to the second level, including: a level change module 1102 and a data transmission module 1104, wherein:

[0105] The level change module 1102 is used to change the level of the first master pin from the third level to the fourth level through the SPI driver when the application layer of the master device sends data, so that the level of the first slave pin is changed from the third level to the fourth level, triggering the second interrupt of the first slave pin, and the second interrupt is used to instruct the slave device to change the level of the second slave pin from the first level to the second level, triggering the first interrupt of the second master pin.

[0106] The data transmission module 1104 is used to transmit data to the slave device through the SPI driver in response to the first interrupt.

[0107] In some embodiments, the data transmission module 1104 is further used to respond to the first interrupt, call the SPI interface function through the SPI driver, transmit the send data to the slave device, and receive the receive data from the slave device.

[0108] In some embodiments, the level changing module 1102 is also used to restore the level of the first master pin to the third level when sending and receiving are completed; and to trigger the slave device to restore the level of the second slave pin to the first level when sending and receiving are completed.

[0109] In some embodiments, the level change module 1102 is also used to write the transmission data into the data transmission queue of the driver layer through the SPI driver when there is transmission data in the application layer of the master device; change the level of the first master pin from the third level to the fourth level through the SPI driver; the data transmission module 1104 is also used to respond to the first interrupt and send data to the data transmission queue of the slave device through the SPI driver.

[0110] In some embodiments, the data transmission module 1104 is further used to respond to the first interrupt, write the transmission data into the transmission register corresponding to the SPI driver through the SPI driver; and transmit the transmission data in the transmission register to the slave device.

[0111] In some embodiments, the data transmission module 1104 is also used to trigger a first interrupt within a preset time after the level of the first main pin is changed from the third level to the fourth level, and in response to the first interrupt, transmit and send data to the slave device through the SPI driver; the level change module 1102 is also used to change the level of the first main pin from the fourth level to the third level when the first interrupt is not triggered within the preset time.

[0112] In some embodiments, the application layer is deployed with an SPI application layer program corresponding to the SPI driver, and the device also includes an application layer data receiving module, which is used to generate an SPI handle of the master device through the SPI application layer program, and the SPI handle points to the device file of the master device; the device file is accessed through the SPI handle, and when the device file changes, the received data is obtained from the data receiving queue of the SPI driver.

[0113] Each module in the above data transmission device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of the processor in the vehicle terminal in the form of hardware, or can be stored in the memory in the vehicle terminal in the form of software, so that the processor can call and execute the corresponding operations of each module.

[0114] In some embodiments, a vehicle-mounted terminal is provided. The vehicle-mounted terminal may be a terminal, and its internal structure diagram may be as follows: Fig.12 As shown. The vehicle-mounted terminal includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. Among them, the processor of the vehicle-mounted terminal is used to provide computing and control capabilities. The memory of the vehicle-mounted terminal includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the vehicle-mounted terminal is used to exchange information between the processor and the external device. The communication interface of the vehicle-mounted terminal is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be realized through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a data transmission method is realized. The display unit of the vehicle-mounted terminal is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of the vehicle terminal can be a touch layer covering the display screen, or a button, trackball or touchpad set on the vehicle terminal shell, or an external keyboard, touchpad or mouse.

[0115] Those skilled in the art will understand that Fig.12 The structure shown in the figure is only a block diagram of a part of the structure related to the scheme of the present application, and does not constitute a limitation on the vehicle-mounted terminal to which the scheme of the present application is applied. The specific vehicle-mounted terminal may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0116] In some embodiments, a vehicle-mounted terminal is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned data transmission method when executing the computer program.

[0117] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above data transmission method are implemented.

[0118] In one embodiment, a computer program product is provided, comprising a computer program, which implements the steps in the above data transmission method when executed by a processor.

[0119] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.

[0120] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.

[0121] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0122] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be construed as limiting the scope of the present application. It should be noted that, for a person of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A data transmission method, characterized in that: The method is executed by a master device in a vehicle-mounted terminal, the master device communicates with a slave device in the vehicle-mounted terminal based on a serial peripheral interface SPI, a first master pin in the master device is connected to a first slave pin in the slave device through a first signal line, a second master pin in the master device is connected to a second slave pin in the slave device through a second signal line, an SPI driver in a driver layer of the master device includes a four-wire SPI driver and is used to monitor the first signal line and the second signal line, and the SPI driver in the driver layer of the master device is provided with a first interrupt for the second master pin, and the first interrupt is triggered when the level of the second master pin changes from a first level to a second level; the method comprises: Determine whether there is data to be sent through the SPI application layer program in the application layer of the master device, if not, then enter the step of determining whether there is data to be sent again, if so, take out the send data, send the taken out send data to the driver layer, and then enter the step of determining whether there is data to be sent again; When the application layer of the master device has transmission data, the transmission data is written into the data transmission queue of the driver layer through the SPI driver, and the level of the first master pin is changed from the third level to the fourth level through the SPI driver, so that the level of the first slave pin is changed from the third level to the fourth level, triggering the second interrupt of the first slave pin, and the second interrupt is used to instruct the slave device to change the level of the second slave pin from the first level to the second level, triggering the first interrupt of the second master pin; In response to the first interrupt, sending the transmission data in the data transmission queue to the slave device through the SPI driver; The data from the slave device is written into the data receiving queue of the driver layer through the SPI driver, and the received data is read from the data receiving queue through the SPI application layer program in the application layer.

2. The method according to claim 1, characterized in that The step of sending the sending data in the data sending queue to the slave device through the SPI driver in response to the first interrupt comprises: In response to the first interrupt, the SPI interface function is called through the SPI driver to send the transmission data in the data transmission queue to the slave device, and receive the reception data from the slave device.

3. The method according to claim 2, characterized in that The method further comprises: When the sending and receiving are completed, the level of the first master pin is restored to the third level; the sending and receiving are completed, which are used to trigger the slave device to restore the level of the second slave pin to the first level.

4. The method according to claim 3, characterized in that The amount of the transmitted data is less than or equal to a preset amount of data; When the sending and receiving are completed, restoring the level of the first main pin to the third level comprises: Wait for data transmission to be completed, and restore the level of the first main pin to the third level.

5. The method according to any one of claims 1 to 4, characterized in that: The step of sending the sending data in the data sending queue to the slave device through the SPI driver in response to the first interrupt comprises: In response to the first interrupt, writing the transmission data in the data transmission queue into a transmission register corresponding to the SPI driver through the SPI driver; The transmission data in the transmission register is transmitted to the slave device.

6. The method according to any one of claims 1 to 4, characterized in that: The step of sending the sending data in the data sending queue to the slave device through the SPI driver in response to the first interrupt comprises: When the first interrupt is triggered within a preset time after the level of the first master pin is changed from the third level to the fourth level, in response to the first interrupt, the transmission data in the data transmission queue is sent to the slave device through the SPI driver; The method further comprises: When the first interrupt is not triggered within the preset time period, the level of the first main pin is changed from the fourth level to the third level.

7. The method according to any one of claims 1 to 4, characterized in that: The method further comprises: Generate an SPI handle of the master device through the SPI application layer program, wherein the SPI handle points to a device file of the master device; The device file is accessed through the SPI handle, and when the device file is changed, the received data is obtained from the data receiving queue of the SPI driver.

8. A data transmission device, characterized in that: The data transmission device belongs to a master device in a vehicle-mounted terminal, the master device communicates with a slave device in the vehicle-mounted terminal based on a serial peripheral interface SPI, a first master pin in the master device is connected to a first slave pin in the slave device through a first signal line, a second master pin in the master device is connected to a second slave pin in the slave device through a second signal line, an SPI driver in a driver layer of the master device includes a four-wire SPI driver and is used to monitor the first signal line and the second signal line, and the SPI driver in the driver layer of the master device is provided with a first interrupt for the second master pin, and the first interrupt is triggered when the level of the second master pin changes from the first level to the second level; the device comprises: a level changing module, configured to, when there is sending data in the application layer of the master device, write the sending data into the data sending queue of the driver layer through the SPI driver, and change the level of the first master pin from the third level to the fourth level through the SPI driver, so that the level of the first slave pin is changed from the third level to the fourth level, triggering a second interrupt of the first slave pin, wherein the second interrupt is used to instruct the slave device to change the level of the second slave pin from the first level to the second level, triggering the first interrupt of the second master pin; A data transmission module, configured to respond to the first interrupt and drive the transmission data in the data transmission queue to the slave device through the SPI; The device is also used for: Determine whether there is data to be sent through the SPI application layer program in the application layer of the master device, if not, perform the step of determining whether there is data to be sent again, if so, take out the send data, send the taken out send data to the driver layer, and enter the step of determining whether there is data to be sent again; The data from the slave device is written into the data receiving queue of the driver layer through the SPI driver, and the received data is read from the data receiving queue through the SPI application layer program in the application layer.

9. A vehicle-mounted terminal, comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Data transmission realizing method and system based on SPI

    CN101552733A

  • Full-duplex communication device based on SPI and method thereof

    CN102819512A

  • Rdesktop optimization method based on Linux operating system of Loongson platform

    CN103677792A

  • SPI transmission control method, sending device and receiving device

    CN111061671A