Communication method and device based on SPI (Serial Peripheral Interface), computer equipment and storage medium
By determining the data transmission channel and obtaining and prioritizing service messages in SPI interface communication, the problem of service data transmission conflict in traditional SPI interface communication is solved, and orderly two-way communication between the host and the slave is realized.
Patent Information
- Application Number
- CN202411935576.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-26
- Publication Date
- 2025-05-13
AI Technical Summary
In traditional SPI interface communication, when the host and slave transmit multiple types of service data within the same cycle, conflicts are prone to occur, resulting in communication blockage.
By determining the data transmission channel with the host, multiple types of service messages are obtained and their priority is determined, service messages are transmitted in sequence according to priority, and service messages transmitted by the host are received to ensure the order of two-way communication and data transmission.
It realizes orderly service data transmission between the host and the slave, avoids communication conflicts, ensures the smoothness of two-way communication, and is adapted to two-way communication in different business scenarios.
Smart Images

Figure CN119988290A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a communication method, apparatus, computer equipment, computer-readable storage medium and computer program product based on an SPI interface. Background Art
[0002] The traditional SPI (Serial Peripheral Interface) compatible interface communication process is as follows: Generally, the host outputs the CS signal to activate the slave, and the slave's data must be ready at this time. When the host's data is ready, it starts and outputs the CLK signal. The host outputs its own data on the rising edge of the clock, and the slave samples the data output by the host on the falling edge. The slave also outputs its own data at the same time. The host samples and receives the data from the slave at the same time, and in the same cycle, data interaction between the hosts is realized.
[0003] However, when the host and the slave need to transmit multiple types of service data in the same cycle, the transmission of these service data is prone to conflict, resulting in obstruction of communication between the host and the slave. Summary of the invention
[0004] The embodiments of the present application provide a communication method, apparatus, computer device, computer-readable storage medium and computer program product based on an SPI interface, which can realize the orderly transmission of various types of business data between a host and a slave, and maintain smooth communication between the host and the slave.
[0005] In one aspect, the present application provides a communication method based on an SPI interface. The method comprises:
[0006] Determine a data transmission channel with a host, wherein the data transmission channel is constructed based on an SPI interface;
[0007] Acquire multiple types of first service messages, and determine priorities among the multiple types of first service messages;
[0008] Transmitting the plurality of types of service messages to the host in sequence based on the data transmission channel according to the priorities among the first service messages;
[0009] Based on the data transmission channel, multiple types of second service messages transmitted by the host are received, and the multiple types of second service messages are transmitted in sequence according to priority.
[0010] On the other hand, the present application also provides a communication device based on the SPI interface. The device comprises:
[0011] A determination module, used to determine a data transmission channel between the host and the host, wherein the data transmission channel is constructed based on an SPI interface;
[0012] An acquisition module, used to acquire multiple types of first service messages and determine the priorities among the multiple types of first service messages;
[0013] A transmission module, configured to transmit the plurality of types of service messages to the host in sequence based on the data transmission channel according to the priorities among the first service messages;
[0014] The receiving module is used to receive multiple types of second service messages transmitted by the host based on the data transmission channel, and the multiple types of second service messages are transmitted in sequence according to priority.
[0015] On the other hand, the present application also provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0016] Determine a data transmission channel between the host and the host, wherein the data transmission channel is constructed based on the SPI interface; obtain multiple types of first business messages and determine the priorities among the multiple types of first business messages; according to the priorities among the first business messages, based on the data transmission channel, transmit the multiple types of business messages to the host in sequence; based on the data transmission channel, receive multiple types of second business messages transmitted by the host, and the multiple types of second business messages are transmitted in sequence according to the priorities.
[0017] On the other hand, the present application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0018] Determine a data transmission channel between the host and the host, wherein the data transmission channel is constructed based on the SPI interface; obtain multiple types of first business messages and determine the priorities among the multiple types of first business messages; according to the priorities among the first business messages, based on the data transmission channel, transmit the multiple types of business messages to the host in sequence; based on the data transmission channel, receive multiple types of second business messages transmitted by the host, and the multiple types of second business messages are transmitted in sequence according to the priorities.
[0019] On the other hand, the present application also provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0020] Determine a data transmission channel between the host and the host, wherein the data transmission channel is constructed based on the SPI interface; obtain multiple types of first business messages and determine the priorities among the multiple types of first business messages; according to the priorities among the first business messages, based on the data transmission channel, transmit the multiple types of business messages to the host in sequence; based on the data transmission channel, receive multiple types of second business messages transmitted by the host, and the multiple types of second business messages are transmitted in sequence according to the priorities.
[0021] The above-mentioned communication method, device, computer equipment, computer-readable storage medium and computer program product based on the SPI interface, the slave determines the data transmission channel between the slave and the host, the data transmission channel is constructed based on the SPI interface, obtains multiple types of first business messages, and determines the priority between multiple types of first business messages, so that the multiple types of business messages can be transmitted to the host in sequence according to the priority between the first business messages based on the data transmission channel, so that the slave can also actively initiate communication with the host to achieve two-way communication between the slave and the host. Based on the data transmission channel, multiple types of second business messages transmitted by the host are received, and multiple types of second business messages are transmitted in sequence according to the priority, so that both the slave and the host can achieve two-way data transmission according to the priority of the business message, effectively avoiding conflicts in the transmission of business messages. In addition, business messages of different priorities adopt certain strategies to share the time period and data channel of SPI communication, so that SPI communication can be compatible with more functions and adapt to two-way communication in different business scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be 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.
[0023] Figure 1 FIG. 1 is an application environment diagram of a communication method based on an SPI interface in an embodiment;
[0024] Figure 2 is a flow chart of a communication method based on an SPI interface in one embodiment;
[0025] Figure 3 A schematic diagram of the architecture of a communication method based on an SPI interface in an embodiment;
[0026] Figure 4 A schematic diagram of priorities of various types of service messages in one embodiment;
[0027] Figure 5 A schematic diagram of transmission of a periodic message in an embodiment;
[0028] Figure 6 A schematic diagram of transmission of a high priority burst message in an embodiment;
[0029] Figure 7 A schematic diagram of transmission of a burst message of low priority in an embodiment;
[0030] Figure 8 is a structural block diagram of a communication device based on an SPI interface in one embodiment;
[0031] Fig. 9 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0032] 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.
[0033] The communication method based on the SPI interface provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the slave 102 communicates with the host 104 through the network. The data storage system can store the data that the host 104 needs to process. The data storage system can be integrated on the host 104, or it can be placed on the cloud or other network hosts. The slave 102 determines the data transmission channel between the slave 102 and the host 104, and the data transmission channel is constructed based on the SPI interface. The slave 102 obtains multiple types of first business messages and determines the priority between multiple types of first business messages. The slave 102 transmits multiple types of business messages to the host 104 in sequence based on the data transmission channel according to the priority between the first business messages. The slave 102 receives multiple types of second business messages transmitted by the host 104 based on the data transmission channel, and multiple types of second business messages are transmitted in sequence according to the priority. Among them, the slave 102 and the host 104 can both be terminals or servers. The terminal can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, Internet of Things devices and portable wearable devices, and the Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. The portable wearable device may be a smart watch, a smart bracelet, a head-mounted device, etc. The server may be implemented as an independent server or a server cluster consisting of multiple servers.
[0034] In one embodiment, Figure 2 As shown, a communication method based on SPI interface is provided, and the method is applied to Figure 1 The slave in the example is used to illustrate the following steps:
[0035] Step 202, determining a data transmission channel with a host, where the data transmission channel is constructed based on an SPI interface.
[0036] Specifically, the slave determines a data transmission channel with the host, and the data transmission channel is constructed based on the SPI interface expansion.
[0037] In this embodiment, the slave device is provided with a first GPIO, and the host device is provided with a second GPIO. The first GPIO and the second GPIO are respectively connected to two ends of the data transmission channel.
[0038] In this embodiment, the data transmission channel includes a first transmission channel for transmitting burst messages and a second transmission channel for transmitting periodic messages.
[0039] In this embodiment, the slave negotiates with the host about the duration of communication, and calls the data transmission channel to communicate with the host for the negotiated duration.
[0040] Step 204: Acquire multiple types of first service messages, and determine priorities among the multiple types of first service messages.
[0041] Among them, the first service message refers to the service message transmitted from the slave to the host. The first service message can specifically be a burst message or a periodic message. In different service scenarios, the priority of the burst message and the periodic message may be different. For example, in service scenario 1, the priority of the burst message is higher than the priority of the periodic message. In service scenario 2, the priority of the periodic message may be higher than the priority of the burst message.
[0042] Specifically, the slave obtains multiple types of first service messages, and determines the service scenario to which each type of first service message belongs. According to the service scenario to which each type of first service message belongs, the priority among the multiple types of first service messages is determined.
[0043] Step 206 , according to the priorities among the first service messages and based on the data transmission channel, the service messages of various types are transmitted to the host in sequence.
[0044] Specifically, according to the priorities among the first service messages, based on the data transmission channel, the service messages of various types are transmitted to the host in sequence.
[0045] Step 208: Based on the data transmission channel, multiple types of second service messages transmitted by the host are received, and the multiple types of second service messages are transmitted in sequence according to the priority.
[0046] The second service message refers to a service message transmitted from the host to the slave. The second service message may be a burst message or a periodic message.
[0047] Specifically, the host can transmit multiple types of second service messages to the slave based on the data transmission channel during the process of receiving the first service message sent by the slave. The slave can receive the second service message from the host during the process of transmitting the first service message to the host.
[0048] In this embodiment, the slave can transmit the first service message to the host in the uplink channel of the data transmission channel, and the host can transmit the second service message to the slave in the downlink channel of the data transmission channel.
[0049] In one embodiment, the slave can actively initiate communication, or the host can actively initiate communication. Regardless of whether the slave or the host actively initiates communication, bidirectional communication between the host and the slave can be achieved, thereby achieving bidirectional data transmission.
[0050] In this embodiment, the slave determines the data transmission channel between the slave and the host, and the data transmission channel is constructed based on the SPI interface, obtains multiple types of first business messages, and determines the priorities between the multiple types of first business messages, so that the multiple types of business messages can be transmitted to the host in sequence according to the priorities between the first business messages based on the data transmission channel, so that the slave can also actively initiate communication with the host to achieve two-way communication between the slave and the host. Based on the data transmission channel, multiple types of second business messages transmitted by the host are received, and multiple types of second business messages are transmitted in sequence according to the priority, so that both the slave and the host can achieve two-way data transmission according to the priority of the business message, effectively avoiding conflicts in the transmission of business messages. In addition, business messages of different priorities adopt certain strategies to share the time period and data channel of SPI communication, so that SPI communication can be compatible with more functions and adapt to two-way communication in different business scenarios.
[0051] In one embodiment, the method further comprises:
[0052] Based on the data transmission channel, a synchronization signal is sent to the host, and the synchronization signal is used to instruct the host to wait for receiving service messages.
[0053] Specifically, the slave sends a synchronization signal to the host based on the data transmission channel. After receiving the synchronization signal, the host enters a waiting state to wait for the slave to transmit a service message.
[0054] In this embodiment, the data transmission channel includes a first transmission channel for transmitting burst messages and a second transmission channel for transmitting periodic messages.
[0055] When the slave needs to send a periodic message to the host, the slave sends a synchronization signal to the host based on the second transmission channel. After receiving the synchronization signal, the host enters a waiting state to wait for the slave to transmit the periodic message.
[0056] In this embodiment, the slave can actively send a synchronization signal to the host based on the data transmission channel to instruct the host to wait for receiving a service message, so that the slave can also actively initiate communication to achieve two-way communication with the host.
[0057] In one embodiment, the method further comprises: negotiating with the host the duration of each round of communication;
[0058] According to the priority between the first service messages, based on the data transmission channel, multiple types of service messages are transmitted to the host in sequence, including:
[0059] For each type of first business message, the first business message is divided into multiple frames of data; based on the data transmission channel, multiple rounds of communication are performed with the host; wherein, during the duration of each round of communication, according to the priority between the first business messages, based on the data transmission channel, at least a part of the frame data is transmitted to the host until the divided multiple frames of data transmission are completed.
[0060] The negotiated communication duration refers to the duration of a round of communication between the slave and the master, which may be, for example, 10ms, 30ms, etc., but is not limited thereto. The duration of each round of communication may be the same or different, for example, the duration of the first round of communication is 10ms, and the duration of the second round of communication is 20ms.
[0061] Specifically, for each type of first service message, the first service message is divided into multiple frames of data.
[0062] The slave and the host negotiate the duration of each round of communication in advance, and communicate with the host based on the data transmission channel. In one round of communication, the slave transmits at least a portion of the frame data to the slave based on the data transmission channel according to the priority between the first service messages, and stops the current round of communication when the communication duration reaches the negotiated duration.
[0063] Then, the slave communicates with the host in the next round based on the data transmission channel, and transmits frame data in the same processing manner until all data divided by the first service message of each type are transmitted.
[0064] In one of the embodiments, the slave machine negotiates with the host machine on the duration of each round of communication and the number of frames transmitted within the duration, and for each type of first business message, divides the first business message into multiple frames of data; based on the data transmission channel, multiple rounds of communication are performed with the host machine; wherein, within the duration of each round of communication, at least a portion of the frame data is transmitted to the slave machine based on the data transmission channel according to the priority between the first business messages until the divided multi-frame data transmission is completed; wherein, within the duration of each round of communication, the negotiated number of frame data are transmitted to the slave machine through the data transmission channel according to the priority between the first business messages.
[0065] In one embodiment, the slave divides each type of first service message into multiple frames of data and stores them in a cache queue. In each round of communication, at least a portion of the frame data or the negotiated number of frame data can be taken out from the cache queue to send to the host through the data transmission channel.
[0066] In one of the embodiments, each type of first service message corresponds to a cache queue, and the slave machine can take out at least a portion of the frame data or the negotiated number of frame data from the corresponding cache queue according to the priority.
[0067] In this embodiment, the duration of each round of communication is negotiated with the host, and for each type of first business message, the first business message is divided into multiple frames of data. Based on the data transmission channel, multiple rounds of communication are performed with the host, so that within the duration of each round of communication, the slave transmits at least a part of the frame data to the host based on the data transmission channel according to the priority between the first business messages, until the divided multi-frame data transmission is completed, so that the slave can actively communicate with the host for multiple rounds, and transmit various types of business messages to the host in the form of frame data according to the priority of the business message, and can also receive the transmission data transmitted by the host, effectively realizing two-way communication and two-way data transmission with the host.
[0068] In one embodiment, the multiple types of first service messages include at least periodic messages and burst messages, and the data transmission channel includes a first transmission channel for transmitting burst messages and a second transmission channel for transmitting periodic messages.
[0069] Specifically, the multiple types of first service messages include at least periodic messages and burst messages, and the data transmission channel includes a first transmission channel and a second transmission channel. The first transmission channel is used to transmit burst messages, and the second transmission channel is used to transmit periodic messages.
[0070] The slave may transmit the burst message to the host through the first transmission channel, and transmit the periodic message to the host through the second transmission channel.
[0071] In one embodiment, when the priority of the periodic message is higher than the priority of the burst message, the slave can call the second transmission channel to transmit the periodic message to the master. After the periodic message transmission is completed, the first transmission channel is called to transmit the burst message to the master.
[0072] In one embodiment, when the priority of the burst message is higher than the priority of the periodic message, the slave can call the first transmission channel to transmit the burst message to the host. After the burst message transmission is completed, the second transmission channel is called to transmit the periodic message to the host.
[0073] In this embodiment, multiple types of first service messages include at least periodic messages and burst messages, and the data transmission channel includes a first transmission channel for transmitting burst messages and a second transmission channel for transmitting periodic messages. A first transmission channel for transmitting burst messages and a second transmission channel for transmitting periodic messages are provided. The first transmission channel and the second transmission channel can transmit different types of service messages according to the priorities of periodic messages and burst messages, and can realize orderly transmission of multiple service messages, thus avoiding the phenomenon that conflicts easily occur in the transmission of multiple service messages in traditional solutions.
[0074] In one embodiment, multiple rounds of communication are performed with the host based on the data transmission channel, including:
[0075] When the priority of the burst message is higher than the priority of the periodic message, the first transmission channel is called to transmit multiple frames of data of the burst message to the host through the first transmission channel; when the transmission of multiple frames of data of the burst message is completed, the second transmission channel is called; based on the called second transmission channel, multiple frames of data of the periodic message are transmitted to the host.
[0076] Specifically, when the priority of the burst message is higher than the priority of the periodic message, multiple rounds of communication are performed with the host based on the data transmission channel, and multiple frames of data of the burst message are transmitted to the host based on the first transmission channel in the multiple rounds of communication until the transmission of multiple frames of data of the burst message is completed. The duration of each round of communication is the negotiated duration.
[0077] After the multi-frame data transmission of the burst message is completed, the second transmission channel is called to communicate with the host for multiple rounds. In the multiple rounds of communication, the multi-frame data of the periodic message is transmitted to the host based on the called second transmission channel until the multi-frame data transmission of the periodic message is completed. The duration of each round of communication is the negotiated duration.
[0078] In this embodiment, when the priority of the burst message is higher than the priority of the periodic message, the first transmission channel is called, and multiple frames of data of the burst message are transmitted to the host through the first transmission channel, so that the burst message can be sent preferentially. When the transmission of multiple frames of data of the burst message is completed, the second transmission channel is called, and based on the called second transmission channel, multiple frames of data of the periodic message are transmitted to the host, so that the two-way burst communication and periodic communication are divided into multiple priorities, and service messages of different priorities adopt certain strategies to share the time cycle and data channel of SPI communication.
[0079] In one embodiment, multiple rounds of communication are performed with the host based on the data transmission channel, including:
[0080] Negotiate with the host the number of frames transmitted within the duration of each round of communication; each round of communication includes a first communication based on a first transmission channel and a second communication based on a second transmission channel;
[0081] When the priority of the periodic message is higher than the priority of the burst message, multiple rounds of first communication are performed with the host based on the second transmission channel; wherein in each round of the first communication, a first number of frame data of the periodic message is transmitted to the host based on the second transmission channel;
[0082] For each round of first communication, when the transmission of a first number of frame data of the periodic message in the first communication is completed, the first number has not reached the negotiated number of frames, and the communication duration of the first communication has not reached the negotiated duration, a second communication is performed with the host based on the first transmission channel;
[0083] Among them, in the second communication, a second number of frame data of the burst message is transmitted to the host based on the first transmission channel, the sum of the duration of the first communication and the duration of the second communication is equal to the negotiated duration, and the sum of the first number and the second number is equal to the negotiated frame number.
[0084] Specifically, the slave and the host negotiate the number of frames to be transmitted within the duration of each round of communication, and the negotiated frame data is the maximum number of frames that can be transmitted during the communication process. That is, the slave can transmit less than or equal to the negotiated number of frames in each round of communication.
[0085] Each round of communication includes a first communication based on a first transmission channel and a second communication based on a second transmission channel, and the sum of the duration of the first communication and the duration of the second communication is equal to the negotiated duration. That is, when the priority of the periodic message is higher than the priority of the burst message, the first communication within the negotiated duration of this round is performed with the host based on the second transmission channel. In the first communication of this round, the first number of frame data of the periodic message is transmitted to the host based on the second transmission channel. After the transmission is completed, the communication duration of the first communication of this round is determined.
[0086] When the communication duration of the first communication in this round does not reach the negotiated duration, and the first number does not reach the negotiated number of frames, the slave performs a second communication with the host based on the first transmission channel in this round. In the second communication in this round, the slave transmits a second number of frame data of the burst message to the host based on the first transmission channel, thereby completing the communication in this round. In this round of communication, the sum of the duration of the first communication and the duration of the second communication is equal to the negotiated duration, and the sum of the first number and the second number is equal to the negotiated number of frames.
[0087] According to the same process, the slave device can perform multiple rounds of communication with the host device, and complete the transmission of frame data of the periodic message and the transmission of frame data of the burst message in each round of communication.
[0088] In this embodiment, the number of frames transmitted within the duration of each round of communication is negotiated with the host; each round of communication includes a first communication based on a first transmission channel and a second communication based on a second transmission channel. When the priority of the periodic message is higher than the priority of the burst message, multiple rounds of first communication are performed with the host based on the second transmission channel, and in each round of first communication, the first number of frame data of the periodic message is transmitted to the host based on the second transmission channel, so that the frame data of the periodic message is preferentially transmitted in each round of communication. For each round of first communication, when the transmission of the first number of frame data of the periodic message in the first communication is completed, the first number has not reached the negotiated number of frames, and the communication duration of the first communication has not reached the negotiated duration, the second communication is performed with the host based on the first transmission channel, and in the second communication, the second number of frame data of the burst message is transmitted to the host based on the first transmission channel, so that the frame data of the burst message can be transmitted using the remaining communication duration and the remaining available number of frames of the first communication, so that the burst message with low priority is transmitted to the host at scattered time and frame number, thereby improving the utilization rate of transmission resources.
[0089] In one embodiment, a communication method based on an SPI interface is provided, which is applied to a host and a slave. The architecture of the communication method based on an SPI interface is as follows: Figure 3 As shown, it is necessary to add a second transmission channel for the slave to send communication to the host on the basis of the traditional 6-wire SPI. The two ends are respectively connected to the GPIO (graphic input and output interface) belonging to the host and the slave, so as to realize the bidirectional data receiving and sending function of multiple frames of periodic messages within the preset negotiation time. The preset negotiation time is the time of each round of communication negotiated by the host and the slave, for example, it can be 10ms. The 10msGPIO synchronizes the 10ms periodic message separately. The two ends of the first transmission channel are respectively connected to the two GPIOs set on the host and the slave, and the receiving and sending control of multiple frames of data of the burst message in this round of communication is completed through the two GPIOs.
[0090] In this embodiment, the priorities of various types of service messages are as follows: Figure 4As shown, various types of service messages include burst messages and periodic messages. In some service scenarios, the priority of burst messages is higher than that of periodic messages, while in some service scenarios, the priority of burst messages is lower than that of periodic messages. Therefore, according to the priority sorting, burst messages of high priority, periodic messages of medium priority, and burst messages of low priority can be obtained.
[0091] For periodic messages, priorities can be further divided according to business scenarios. For example, a periodic message of 100 milliseconds has the highest priority, a periodic message of 50 milliseconds has a middle priority, and a periodic message of 10 milliseconds has the lowest priority.
[0092] The specific processing process of this method is as follows:
[0093] A complete data transmission and reception cycle starts with the slave sending a 10ms synchronization signal. After the host receives the 10ms synchronization signal, it waits for the multi-frame data exchange of this cycle.
[0094] The host and slave in the system should agree in advance on the maximum number of frames that can be sent within a 10ms period.
[0095] 1) The transmission of periodic messages is as follows: Figure 5 As shown:
[0096] Periodic messages are organized into sending queues according to different time periods. When the scheduled time arrives, the sending message is obtained from the corresponding time period queue; the sending priority of the multi-period sending queue is configurable.
[0097] The data is sent in a configurable period (must be a multiple of 10ms). Multiple periods can be configured at the same time, but only one fixed-length frame data can be sent or received in the minimum common period. Service messages exceeding this length are not supported.
[0098] The trigger of the minimum common period uses an independent GPIO, and other periods are calculated using the internal count of the minimum common period.
[0099] Because the content of each frame of the periodic message must be independent and cannot have any logical dependency with other frames.
[0100] Periodic message: In each cycle, the total number of frames sent by the system is determined. If the maximum number is reached or exceeded, the periodic message of this cycle will no longer be sent; the message queue that should have been sent in this cycle will be cleared and all messages will be discarded.
[0101] When multiple periodic messages conflict, the strategy of discarding some periodic messages is adopted. The reason is that when the system cycle arrives, it only supports sending one fixed-length frame, and the frame length is insufficient. Assuming that the frame length is enough to accommodate multiple periodic messages, the system also needs to support the operation of splicing multiple periodic messages together, which consumes a lot of memory and CPU processing resources (unless DMA supports discrete data splicing and splitting transmission and reception modes). When multi-periodic messages conflict, the strategy of sending or discarding different periods allows users to configure and choose.
[0102] 2) Burst message:
[0103] Burst messages are organized into sending queues according to different priorities. When the sending time arrives, the sending message is obtained from the corresponding queue.
[0104] It supports burst transmission and supports service messages exceeding a fixed length. When sending, the platform splits the messages into multiple fixed-length multi-frames for sending and receiving data. The platform then assembles the messages into complete service messages at the receiving end and sends them to the service.
[0105] Burst messages support different priorities:
[0106] For burst messages of high priority messages, the total number of frames sent by the system within a period is not considered. As long as there is data, continuous multi-frame transmission and reception are always adopted.
[0107] The transmission of high priority burst messages is as follows: Figure 6 As shown: It is higher than periodic messages and low-priority burst messages, and is sent at the highest priority at any time, using continuous multi-frame priority sending until it is completed.
[0108] The low-priority burst messages will determine the total number of frames sent by the system in each cycle. If it reaches or exceeds the maximum value, the periodic messages of this cycle will no longer be sent, but will be sent in the next cycle.
[0109] The transmission of low priority burst messages is as follows: Figure 7 As shown: It has a lower priority than high-priority messages and periodic messages, and is sent in periodic discontinuous multi-frames. Only when the high-priority message is sent and the periodic message has no data to send, the remaining available frames in the cycle are used to send low-priority burst messages (equivalent to the low-priority burst message being cut into multiple fragments and sent step by step according to the cycle).
[0110] There may be a delay in sending a low-priority frame, which prevents the high-priority frame from being sent immediately. However, the high-priority frame can be sent first when the subsequent frame is sent. The delay in the start of sending the high-priority message:
[0111] If calculated based on a frame size of 2KB@20Mbps, a high-priority frame may be delayed by up to 1MS.
[0112] If calculated based on a frame size of 2KB@6Mbps, a high-priority frame may be delayed by up to 3MS.
[0113] In this embodiment, a group of bidirectional GPIO interfaces are used to specifically send and receive burst messages between the master and slave machines, and the original SPI function is expanded to support bidirectional burst real-time communication. A transmission channel initiated by the slave machine is used to specifically send and receive periodic messages between the master and slave machines, and the original SPI function is expanded to support bidirectional periodic real-time communication. Bidirectional burst messages and periodic messages are divided into multiple priorities, and periodic messages and burst messages of different priorities use certain strategies to share the time period and transmission channel of SPI communication.
[0114] 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.
[0115] Based on the same inventive concept, the embodiment of the present application also provides a communication device based on an SPI interface for implementing the communication method based on an SPI interface 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 the embodiments of one or more communication devices based on an SPI interface provided below can refer to the limitations on the communication method based on an SPI interface above, and will not be repeated here.
[0116] In one embodiment, Figure 8 As shown, a communication device 800 based on an SPI interface is provided, comprising:
[0117] The determination module 802 is used to determine a data transmission channel between the host and the host, where the data transmission channel is constructed based on the SPI interface.
[0118] The acquisition module 804 is used to acquire multiple types of first service messages and determine the priorities among the multiple types of first service messages.
[0119] The transmission module 806 is used to transmit the various types of service messages to the host in sequence according to the priorities between the first service messages and based on the data transmission channel.
[0120] The receiving module 808 is used to receive multiple types of second service messages transmitted by the host based on the data transmission channel, and the multiple types of second service messages are transmitted in sequence according to the priority.
[0121] In one embodiment, the transmission module 806 is further used to send a synchronization signal to the host based on the data transmission channel, and the synchronization signal is used to instruct the host to wait for receiving a service message.
[0122] In one embodiment, the transmission module 806 is also used to negotiate with the host the duration of each round of communication; for each type of first business message, divide the first business message into multiple frames of data; based on the data transmission channel, perform multiple rounds of communication with the host; wherein, within the duration of each round of communication, according to the priority between the first business messages, based on the data transmission channel, at least a portion of the frame data is transmitted to the slave until the divided multi-frame data transmission is completed.
[0123] In one embodiment, the multiple types of first service messages include at least periodic messages and burst messages, and the data transmission channel includes a first transmission channel for transmitting burst messages and a second transmission channel for transmitting periodic messages.
[0124] In one embodiment, the transmission module 806 is also used to call the first transmission channel when the priority of the burst message is higher than the priority of the periodic message, and transmit multiple frames of data of the burst message to the host through the first transmission channel; when the transmission of multiple frames of data of the burst message is completed, call the second transmission channel; and based on the called second transmission channel, transmit multiple frames of data of the periodic message to the host.
[0125] In one embodiment, the transmission module 806 is also used to negotiate with the host the number of frames transmitted within the duration of each round of communication; each round of communication includes a first communication based on a first transmission channel and a second communication based on a second transmission channel; when the priority of the periodic message is higher than the priority of the burst message, multiple rounds of first communication are performed with the host based on the second transmission channel; wherein, in each round of first communication, a first number of frame data of the periodic message is transmitted to the host based on the second transmission channel; for each round of first communication, when the transmission of the first number of frame data of the periodic message in the first communication is completed and the first number has not reached the negotiated number of frames, and the communication duration of the first communication has not reached the negotiated duration, a second communication is performed with the host based on the first transmission channel; wherein, in the second communication, a second number of frame data of the burst message is transmitted to the host based on the first transmission channel, the sum of the duration of the first communication and the duration of the second communication is equal to the negotiated duration, and the sum of the first number and the second number is equal to the negotiated number of frames.
[0126] Each module in the above-mentioned communication device based on the SPI interface can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.
[0127] In one embodiment, a computer device is provided, which may be a terminal or a server. Taking a terminal as an example, its internal structure diagram may be as follows: Fig. 9 As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. 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. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device 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 computer device is used to exchange information between the processor and the external device. The communication interface of the computer device 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 communication method based on the SPI interface is realized. The display unit of the computer device 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, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.
[0128] Those skilled in the art will understand that Fig. 9 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0129] The embodiment of the present application also provides a computer-readable storage medium. One or more non-volatile computer-readable storage media containing computer-executable instructions, when the computer-executable instructions are executed by one or more processors, the processors execute the steps of the communication method based on the SPI interface.
[0130] The embodiment of the present application also provides a computer program product including instructions, which, when executed on a computer, enables the computer to execute a communication method based on an SPI interface.
[0131] 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 laws, regulations and standards of relevant countries and regions.
[0132] 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.
[0133] The technical features of the above embodiments may be arbitrarily combined. 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.
[0134] 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 understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations 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 communication method based on SPI interface, characterized in that, The method comprises: Determine a data transmission channel with a host, wherein the data transmission channel is constructed based on an SPI interface; Acquire multiple types of first service messages, and determine priorities among the multiple types of first service messages; Transmitting the plurality of types of service messages to the host in sequence based on the data transmission channel according to the priorities among the first service messages; Based on the data transmission channel, multiple types of second service messages transmitted by the host are received, and the multiple types of second service messages are transmitted in sequence according to priority.
2. The method according to claim 1, characterized in that The method further comprises: Based on the data transmission channel, a synchronization signal is sent to the host, where the synchronization signal is used to instruct the host to wait for receiving a service message.
3. The method according to claim 1, characterized in that The method further comprises: Negotiate with the host the duration of each round of communication; The transmitting the plurality of types of service messages to the host in sequence according to the priorities among the first service messages and based on the data transmission channel comprises: For each type of first service message, dividing the first service message into multiple frames of data; Based on the data transmission channel, multiple rounds of communication are performed with the host; wherein, during the duration of each round of communication, at least a portion of the frame data is transmitted to the host based on the data transmission channel according to the priority between the first business messages until the divided multiple frames of data transmission are completed.
4. The method according to claim 3, characterized in that: The multiple types of first service messages include at least periodic messages and burst messages, and the data transmission channel includes a first transmission channel for transmitting the burst messages and a second transmission channel for transmitting periodic messages.
5. The method according to claim 4, characterized in that The performing multiple rounds of communication with the host based on the data transmission channel includes: When the priority of the burst message is higher than the priority of the periodic message, calling the first transmission channel, and transmitting multiple frames of data of the burst message to the host through the first transmission channel; When the multi-frame data transmission of the burst message is completed, calling the second transmission channel; Based on the called second transmission channel, multiple frames of data of the periodic message are transmitted to the host.
6. The method according to claim 4, characterized in that The performing multiple rounds of communication with the host based on the data transmission channel includes: Negotiate with the host the number of frames transmitted within the duration of each round of communication; each round of communication includes a first communication based on the first transmission channel and a second communication based on the second transmission channel; When the priority of the periodic message is higher than the priority of the burst message, multiple rounds of first communication are performed with the host based on the second transmission channel; wherein in each round of first communication, a first number of frame data of the periodic message is transmitted to the host based on the second transmission channel; For each round of first communication, when a first number of frame data of the periodic message in the first communication is transmitted, the first number does not reach the negotiated number of frames, and the communication duration of the first communication does not reach the negotiated duration, performing a second communication with the host based on the first transmission channel; Among them, in the second communication, a second number of frame data of the burst message is transmitted to the host based on the first transmission channel, the sum of the duration of the first communication and the duration of the second communication is equal to the negotiated duration, and the sum of the first number and the second number is equal to the negotiated frame number.
7. A communication device based on SPI interface, characterized in that: include: A determination module, used to determine a data transmission channel between the host and the host, wherein the data transmission channel is constructed based on an SPI interface; An acquisition module, used to acquire multiple types of first service messages and determine the priorities among the multiple types of first service messages; A transmission module, configured to transmit the plurality of types of service messages to the host in sequence based on the data transmission channel according to the priorities among the first service messages; The receiving module is used to receive multiple types of second service messages transmitted by the host based on the data transmission channel, and the multiple types of second service messages are transmitted in sequence according to priority.
8. A computer device comprising a memory and a processor, wherein a computer program is stored in the memory, wherein: When the computer program is executed by the processor, the processor is caused to perform the steps of the method according to any one of claims 1 to 6.
9. 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 6 are implemented.
10. A computer program product, comprising a computer program, 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 6 are implemented.
Citation Information
Cited By
Communication system, method and device based on SPI protocol and storage medium
CN120803999A