SPI Asynchronous Communication Scheduling Method, Apparatus, Device, and Storage Medium

By detecting asynchronous transmission tasks in SPI communication and performing asynchronous transmission operations under task queues and periodic trigger signals, the time delay problem in SPI communication is solved, and efficient SPI asynchronous communication scheduling is realized, reducing latency.

CN113806112BActive Publication Date: 2025-07-25SHANGHAI AUTOMOBILE GEAR WORKS
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111103876.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-18
Publication Date
2025-07-25
Estimated Expiration
2041-09-18

AI Technical Summary

Technical Problem

The existing SPI communication methods have time delay problems during big data transmission, especially in synchronous communication, the delay is more prominent after reducing the baud rate, and an asynchronous SPI communication method is urgently needed to reduce the time delay.

Method used

By detecting the asynchronous transmission task, calling the incoming operation command to put the task number into the task queue and adjusting the status to wait. After receiving the periodic trigger signal, the dequeue operation command is called to obtain the task number and status. When the task state is waiting and the SPI transmission channel is idle, the SPI asynchronous transmission operation is performed.

Benefits of technology

It realizes the scheduling management of multiple SPI asynchronous transmission requests in a short time, reduces the occurrence of transmission errors, and reduces the time delay during communication, so that the receiver and the sender do not need to maintain the same clock frequency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113806112B_ABST
    Figure CN113806112B_ABST
Patent Text Reader

Abstract

The present invention discloses an SPI asynchronous communication scheduling method, apparatus, device, and storage medium. The method includes: when an asynchronous transmission task is detected, calling an enqueue operation instruction to put the task number corresponding to the asynchronous transmission task into a task queue, and adjusting the task status to a waiting state; when a periodic trigger signal is received, calling a dequeue operation instruction to obtain the target task number and target task status corresponding to the task to be transmitted from the task queue; when the target task status is the waiting state and the current SPI transmission channel is in an idle state, entering an execution state; and performing an SPI asynchronous transmission operation on the task to be transmitted according to the target execution function corresponding to the target task number. Through the above manner, it is possible to schedule and manage multiple SPI asynchronous transmission requests generated within a short time, reduce the occurrence of transmission errors, implement SPI asynchronous communication, and reduce the time delay in the communication process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technologies, and in particular, to an SPI asynchronous communication scheduling method, apparatus, device, and storage medium. Background Art

[0002] A large number of peripheral chips are used in vehicle motor controllers, and some of them need to write driver software. The main control chip of the motor controller generally uses the SPI communication method to communicate with the peripheral chips. The SPI communication method has synchronous and asynchronous types. Due to its simple time model, the synchronous communication method does not require much attention to the scheduling timing of function interfaces during program design, so that this communication method has become the preferred SPI communication solution. However, when the amount of transmitted data increases, the time delay caused by synchronous waiting also increases. Especially in order to ensure communication quality, after taking measures to reduce the baud rate, this delay will become more prominent. Therefore, there is an urgent need to propose an SPI asynchronous communication method that fully considers the timing relationship between the SPI of the main control chip sending each control instruction and receiving the responses of each chip, so that there is no need to wait when transmitting data and the time delay is reduced.

[0003] The above content is only used to assist in understanding the technical solution of the present invention, and does not represent an admission that the above content is prior art. Summary of the Invention

[0004] The main purpose of the present invention is to provide an SPI asynchronous communication scheduling method, apparatus, device, and storage medium, aiming to solve the technical problem of how to implement SPI asynchronous communication to reduce the time delay.

[0005] To achieve the above object, the present invention provides an SPI asynchronous communication scheduling method, and the method includes the following steps:

[0006] When an asynchronous transmission task is detected, an enqueue operation instruction is called;

[0007] According to the enqueue operation instruction, the task number corresponding to the asynchronous transmission task is placed in the task queue, and the task state corresponding to the asynchronous transmission task in the task queue is adjusted to the waiting state;

[0008] When a periodic trigger signal is received, a dequeue operation instruction is called;

[0009] According to the dequeue operation instruction, the target task number and target task state corresponding to the task to be transmitted are obtained from the task queue;

[0010] When the target task state is the waiting state and the current SPI transmission channel is in the idle state, enter the execution state;

[0011] In the execution state, perform an SPI asynchronous transmission operation on the task to be transmitted according to the target execution function corresponding to the target task number.

[0012] Optionally, putting the task number corresponding to the asynchronous transmission task into the task queue according to the enqueue operation instruction, and adjusting the task status corresponding to the asynchronous transmission task in the task queue to the waiting state includes:

[0013] Find the corresponding status value from the active task status table according to the task number corresponding to the asynchronous transmission task;

[0014] Judge whether the asynchronous transmission task is in the active state according to the status value;

[0015] When the asynchronous transmission task is not in the active state, obtain the remaining space quantity corresponding to the task queue according to the queue information table;

[0016] Judge whether the task queue has remaining space according to the remaining space quantity;

[0017] When the task queue has remaining space, obtain the tail index number from the queue information table;

[0018] Obtain the element to be filled from the task queue according to the tail index number;

[0019] Write the task number corresponding to the asynchronous transmission task into the element to be filled according to the enqueue operation instruction, and adjust the task status corresponding to the asynchronous transmission task in the element to be filled to the waiting state.

[0020] Optionally, obtaining the target task number and target task status corresponding to the task to be transmitted from the task queue according to the dequeue operation instruction includes:

[0021] Obtain the head index number from the queue information table;

[0022] Obtain the queue element from the task queue according to the head index number;

[0023] Obtain the target task number and target task status corresponding to the task to be transmitted in the queue element according to the dequeue operation instruction.

[0024] Optionally, after performing the SPI asynchronous transmission operation on the task to be transmitted according to the target execution function corresponding to the target task number in the execution state, the method further includes:

[0025] When it is determined that the task to be transmitted does not need to be transmitted again according to the event trigger condition, the task status corresponding to the task to be transmitted in the task queue is adjusted to the stop state, and the head index number is moved forward to obtain the target head index number;

[0026] Update the queue information table according to the target head index number.

[0027] Optionally, the performing the SPI asynchronous transmission operation on the task to be transmitted according to the target execution function corresponding to the target task number in the execution state includes:

[0028] In the execution state, look up the preset task function table according to the target task number to obtain the target execution function;

[0029] Perform the SPI asynchronous transmission operation on the task to be transmitted according to the target execution function.

[0030] Optionally, the performing the SPI asynchronous transmission operation on the task to be transmitted according to the target execution function includes:

[0031] Enter the request sub-state;

[0032] In the request sub-state, write the request data to the SPI module, and control the SPI module to perform the SPI asynchronous transmission operation on the task to be transmitted according to the target execution function.

[0033] Optionally, before entering the request sub-state, the method further includes:

[0034] Write the target execution function and data into the preset SPI running status word, where the preset SPI running status word is used to indicate the execution function and data currently being transmitted;

[0035] After obtaining the target task number and the target task status corresponding to the task to be transmitted from the task queue according to the dequeue operation instruction, the method further includes:

[0036] When it is detected that the preset SPI running status word contains the current execution function and the current data, it is determined that the current SPI transmission channel is in a non-idle state. At this time, the waiting state is maintained until an event instruction triggered at the end of the transmission and / or the next periodic trigger signal is received.

[0037] In addition, to achieve the above object, the present invention also proposes an SPI asynchronous communication scheduling device, and the SPI asynchronous communication scheduling device includes:

[0038] An enqueue module, configured to call an enqueue operation instruction when detecting an asynchronous transmission task;

[0039] The enqueue module is further configured to place the task number corresponding to the asynchronous transmission task into the task queue according to the enqueue operation instruction, and adjust the task status corresponding to the asynchronous transmission task in the task queue to the waiting state;

[0040] The dequeue module is configured to call the dequeue operation instruction when receiving a periodic trigger signal;

[0041] The dequeue module is further configured to obtain the target task number and target task status corresponding to the task to be transmitted from the task queue according to the dequeue operation instruction;

[0042] The transmission module is configured to enter the execution state when the target task status is the waiting state and the current SPI transmission channel is in the idle state;

[0043] The transmission module is further configured to perform an SPI asynchronous transmission operation on the task to be transmitted according to the target execution function corresponding to the target task number in the execution state.

[0044] In addition, to achieve the above object, the present invention further provides an SPI asynchronous communication scheduling device, which includes: a memory, a processor, and an SPI asynchronous communication scheduling program stored on the memory and executable on the processor. The SPI asynchronous communication scheduling program is configured to implement the SPI asynchronous communication scheduling method as described above.

[0045] In addition, to achieve the above object, the present invention further provides a storage medium, on which an SPI asynchronous communication scheduling program is stored. When the SPI asynchronous communication scheduling program is executed by a processor, it implements the SPI asynchronous communication scheduling method as described above.

[0046] When the present invention detects an asynchronous transmission task, it calls an enqueue operation instruction; according to the enqueue operation instruction, it puts the task number corresponding to the asynchronous transmission task into the task queue, and adjusts the task status corresponding to the asynchronous transmission task in the task queue to the waiting state; when receiving a periodic trigger signal, it calls a dequeue operation instruction; according to the dequeue operation instruction, it obtains the target task number and the target task status corresponding to the task to be transmitted from the task queue; when the target task status is the waiting state and the current SPI transmission channel is in the idle state, it enters the execution state; in the execution state, it performs SPI asynchronous transmission operations on the task to be transmitted according to the target execution function corresponding to the target task number. Through the above method, it is possible to schedule and manage multiple SPI asynchronous transmission requests generated within a short period of time, put multiple SPI asynchronous transmission requests into the task queue, when a periodic trigger signal is triggered, take out tasks from the queue, and when the task status meets the requirements and the current SPI transmission channel is idle, perform SPI asynchronous transmission operations, reduce the occurrence of transmission errors, the receiving party and the sending party do not need to maintain the same clock frequency, realize SPI asynchronous communication, and reduce the time delay in the communication process. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] Figure 1 It is a schematic structural diagram of an SPI asynchronous communication scheduling device in the hardware operating environment involved in the embodiment solution of the present invention;

[0048] Figure 2 It is a schematic flowchart of the first embodiment of the SPI asynchronous communication scheduling method of the present invention;

[0049] Figure 3 It is a schematic diagram of an SPI asynchronous communication task manager in an embodiment of the SPI asynchronous communication scheduling method of the present invention;

[0050] Figure 4 It is a schematic diagram of the scheduler timing design in an embodiment of the SPI asynchronous communication scheduling method of the present invention;

[0051] Figure 5 It is a schematic flowchart of the second embodiment of the SPI asynchronous communication scheduling method of the present invention;

[0052] Figure 6 It is a schematic diagram of the enqueue process in an embodiment of the SPI asynchronous communication scheduling method of the present invention;

[0053] Figure 7 It is a schematic diagram of the dequeue process in an embodiment of the SPI asynchronous communication scheduling method of the present invention;

[0054] Figure 8 It is a schematic flowchart of the third embodiment of the SPI asynchronous communication scheduling method of the present invention;

[0055] Figure 9Schematic diagram of the scheduler state machine according to an embodiment of the SPI asynchronous communication scheduling method of the present invention;

[0056] Figure 10 Schematic diagram of the implementation example of the first task execution state according to an embodiment of the SPI asynchronous communication scheduling method of the present invention;

[0057] Figure 11 Schematic diagram of the implementation example of the second task execution state according to an embodiment of the SPI asynchronous communication scheduling method of the present invention;

[0058] Figure 12 Schematic diagram of the implementation example of the third task execution state according to an embodiment of the SPI asynchronous communication scheduling method of the present invention;

[0059] Figure 13 Schematic diagram of the implementation example of the message notification mechanism according to an embodiment of the SPI asynchronous communication scheduling method of the present invention;

[0060] Figure 14 Schematic diagram of the implementation example of the SPI asynchronous communication task manager according to an embodiment of the SPI asynchronous communication scheduling method of the present invention;

[0061] Figure 15 Schematic diagram of the implementation example of the scheduler state machine according to an embodiment of the SPI asynchronous communication scheduling method of the present invention;

[0062] Figure 16 Block diagram of the first embodiment of the SPI asynchronous communication scheduling device of the present invention.

[0063] The realization, functional features and advantages of the object of the present invention will be further described with reference to the embodiments and the accompanying drawings. Detailed implementation manners

[0064] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0065] Refer to Figure 1 , Figure 1 Schematic diagram of the structure of the SPI asynchronous communication scheduling device in the hardware operating environment related to the embodiment solution of the present invention.

[0066] As Figure 1As shown in the figure, the SPI asynchronous communication scheduling device may include: a processor 1001, such as a Central Processing Unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to implement connection communication between these components, such as an SPI bus. The user interface 1003 may include a display screen and an input unit such as a keyboard. Optionally, the user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a Wireless-Fidelity (Wi-Fi) interface). The memory 1005 may be a high-speed Random Access Memory (RAM) or a stable Non-Volatile Memory (NVM), such as a disk memory. Optionally, the memory 1005 may also be a storage device independent of the aforementioned processor 1001.

[0067] Those skilled in the art can understand that Figure 1 the structure shown in the figure does not constitute a limitation on the SPI asynchronous communication scheduling device, and it may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements.

[0068] As Figure 1 shown, the memory 1005, as a storage medium, may include an operating system, a network communication module, a user interface module, and an SPI asynchronous communication scheduling program.

[0069] In Figure 1 the SPI asynchronous communication scheduling device shown in the figure, the network interface 1004 is mainly used for data communication with a network server; the user interface 1003 is mainly used for data interaction with a user; the processor 1001 and the memory 1005 in the SPI asynchronous communication scheduling device of the present invention may be arranged in the SPI asynchronous communication scheduling device. The SPI asynchronous communication scheduling device calls the SPI asynchronous communication scheduling program stored in the memory 1005 through the processor 1001 and executes the SPI asynchronous communication scheduling method provided by the embodiments of the present invention.

[0070] The embodiments of the present invention provide an SPI asynchronous communication scheduling method. Referring to Figure 2 , Figure 2 it is a schematic flowchart of the first embodiment of the SPI asynchronous communication scheduling method of the present invention.

[0071] In this embodiment, the SPI asynchronous communication scheduling method includes the following steps:

[0072] Step S10: When an asynchronous transmission task is detected, call the enqueue operation instruction.

[0073] It can be understood that the execution subject of this embodiment is an SPI asynchronous communication scheduling device, and the SPI asynchronous communication scheduling device can be a main control chip, a controller including the main control chip, or a single-chip microcomputer, and this embodiment does not limit this.

[0074] It should be noted that as Figure 3 shown, Figure 3 FIG. is a schematic diagram of an SPI asynchronous communication task manager according to an embodiment of the SPI asynchronous communication scheduling method of the present invention. The SPI asynchronous communication scheduling device (hereinafter referred to as the scheduler) of this embodiment is provided with an SPI asynchronous communication task manager. Specifically, the SPI asynchronous communication task manager includes: a task queue 101 (ScheduleFifo_st), a queue information table 102 (FifoInfo_st), an active task status table 103 (TaskActive), a queue operation 104 (FifoOperation), a task function table 105 (TaskFunction), and an SPI operation status word 106 (SpiReqStatus). Among them, the task queue 101 is an array of structure types, composed of members TaskId and TaskState, which respectively store the task number and task status of the SPI asynchronous transmission task entering the task queue. The queue operation 104 includes an enqueue operation instruction (QueueTask()) and a dequeue operation instruction (UnqueueTask()). When an asynchronous transmission task is detected, the enqueue operation instruction is called to put the asynchronous transmission task into the task queue 101.

[0075] Step S20: According to the enqueue operation instruction, put the task number corresponding to the asynchronous transmission task into the task queue, and adjust the task status corresponding to the asynchronous transmission task in the task queue to the waiting state.

[0076] It should be understood that the enqueue operation instruction is used to put the task number (TaskId) and task state (TaskState) of the SPI asynchronous transmission task into the task queue 101. Optionally, the specific process is as follows: when it is determined that the task is in an inactive state and there is remaining space in the task queue, the task number and task state corresponding to the asynchronous transmission task are written into the tail element of the task queue. Specifically, the active task status table 103 stores the task numbers and active status values of each task, which are used to indicate whether the corresponding task is in an active state. By querying the active task status table 103 with the task number, it can be determined whether the task is in an active state; the members in the queue information table 102 include the remaining space quantity (NumFree) of the queue 101. By querying the queue information table 102, it can be determined whether there is remaining space in the task queue.

[0077] Step S30: When a periodic trigger signal is received, call the dequeue operation instruction.

[0078] It should be noted that the periodic trigger signal can be an event signal (EV_CYCLE) triggered when the main function (MainFunction()) of the peripheral driver is executed periodically. When the periodic trigger signal is received, the dequeue operation instruction is called to take out the task number (TaskId) and task state (TaskState) of the task to be operated from the task queue 101.

[0079] Refer to Figure 4 , Figure 4Schematic diagram of the scheduler timing design for an embodiment of the SPI asynchronous communication scheduling method of the present invention; when there is an SPI asynchronous transmission task, the enqueue operation instruction QueueTask() in the queue operation 104 is called to put the task TaskId into the task queue 101 and set the task to the waiting state (TASK_WAIT_START). When the main function MainFunction() of the peripheral driver is executed periodically, it triggers the event EV_CYCLE and calls the dequeue operation instruction UnqueueTask() to obtain the task TaskId and TaskState to be operated on from the task queue 101. The scheduler function Schedule() is called to determine the periodic trigger signal and the task state. According to the task state, the scheduler state machine enters the waiting state. If the SPI transmission channel is in the idle state at this time, it enters the execution state (TASK_RUNNING). If the SPI transmission channel is in the non-idle state at this time, it continues to stay in the waiting state until the SPI transmission channel is idle. After entering the execution state, first execute the operation SetSpiReq(SPI_REQ00) to write data in the SPI running status word 106 to indicate that SPI is transmitting, and then enter the request sub-state. In the request sub-state (SUBSTATE_SPI_REQ00), write the request data to the SPI module, that is, execute the operation Spi_AsyncTransmit(SPI_REQ00), so that the SPI module starts to work. If the SPI transmission is not completed, each time the main function MainFunction() is executed, the scheduler state machine stays in the request sub-state. When the SPI transmission is completed, the notification mechanism Spi_Notification() starts to execute. Spi_CopyData2Buffer() means to transfer the data received by the SPI module to the buffer. At the same time, the event EV_SPI_REQ00 is triggered and SetSpiReq(SPI_REQ_NONE) is called to set the SPI running status word 106 to NONE, indicating that there is no current SPI transmission, and the execution state enters the data processing sub-state (SUBSTATE_DATA_PROCESS00), and the data processing corresponding to SPI request 0 is completed in the data processing sub-state. There are two implementation methods for the notification mechanism after the SPI transmission is completed: the first is to generate an interrupt after the data is transmitted, and call the Spi_Notification() operation in the interrupt service program; the second is to periodically query the data transmission flag bit, and when it is set, call the Spi_Notification() operation. When the data processing is completed and / or the EV_CYCLE event occurs, it jumps to the next SPI instruction transmission and data processing state until all are completed.

[0080] Step S40: Obtain the target task number and target task status corresponding to the task to be transmitted from the task queue according to the dequeue operation instruction.

[0081] In a specific implementation, according to the call of the dequeue operation instruction, the task number and task status are taken out from the task queue 101 in the first-in, first-out principle.

[0082] Step S50: When the target task status is the waiting state and the current SPI transmission channel is in the idle state, enter the execution state.

[0083] It can be understood that the task status includes the stop state, the waiting state, and the execution state. Among them, the stop state indicates that the task is in the stop state, the waiting state indicates that the task is in the waiting state for execution, and the execution state indicates that the task is in the state of being executed. Determine whether the task is in the waiting state for execution according to the target task status output by the dequeue operation instruction. In a specific implementation, the SPI operation status word 106 is used to indicate the execution function and data being transmitted currently. When the status word shows that there is SPI transmission, the newly requested asynchronous transmission task cannot be executed immediately. When the status word shows no SPI transmission, it indicates that the current SPI transmission channel is in the idle state.

[0084] Step S60: Perform the SPI asynchronous transmission operation on the task to be transmitted according to the target execution function corresponding to the target task number in the execution state.

[0085] It should be noted that in the execution state, the task with the task number TaskId is completed, the SPI instruction and data corresponding to the task are transmitted, and the corresponding data processing is performed. Since each SPI asynchronous transmission task needs to transmit different instruction sequences and perform different data processing processes, in this embodiment, different implementation methods of the execution state are designed separately for different SPI transmission tasks and filled into the task function table 105 (TaskFunction) in the form of function pointers, so that the scheduler can call the corresponding execution function according to the task number to implement the corresponding execution state, thereby completing the SPI asynchronous transmission operation.

[0086] When an asynchronous transmission task is detected in this embodiment, an enqueue operation instruction is called; according to the enqueue operation instruction, the task number corresponding to the asynchronous transmission task is placed in the task queue, and the task status corresponding to the asynchronous transmission task in the task queue is adjusted to the waiting state; when a periodic trigger signal is received, a dequeue operation instruction is called; according to the dequeue operation instruction, the target task number and the target task status corresponding to the task to be transmitted are obtained from the task queue; when the target task status is the waiting state and the current SPI transmission channel is in the idle state, the execution state is entered; in the execution state, the SPI asynchronous transmission operation is performed on the task to be transmitted according to the target execution function corresponding to the target task number. Through the above method, it is possible to schedule and manage multiple SPI asynchronous transmission requests generated in a short time, place multiple SPI asynchronous transmission requests in the task queue, when a periodic trigger signal is triggered, take out the tasks from the queue, and when the task status meets the requirements and the current SPI transmission channel is idle, perform the SPI asynchronous transmission operation, reduce the occurrence of transmission errors, and the receiver and the sender do not need to maintain the same clock frequency, realizing SPI asynchronous communication and reducing the time delay in the communication process.

[0087] Reference Figure 5 , Figure 5 is a schematic flowchart of the second embodiment of the SPI asynchronous communication scheduling method of the present invention.

[0088] Based on the above first embodiment, step S20 of the SPI asynchronous communication scheduling method in this embodiment includes:

[0089] Step S201: Search for the corresponding status value from the active task status table according to the task number corresponding to the asynchronous transmission task.

[0090] It can be understood that the active task status table 103 stores the task numbers and active status values of each task, indicating whether the corresponding task is in the active state. If the task with the task number TaskId is in the active state, the content of the element TaskActive[TaskId] in the active task status table 103 is the position index IdxWrite of the task in the task queue 101. If the task with the task number TaskId is not in the active state, the content of TaskActive[TaskId] can be set to a specific status symbol, for example, it can be set to 0xFF in advance.

[0091] Step S202: Determine whether the asynchronous transmission task is in the active state according to the status value.

[0092] It should be noted that the status value is the content of the element TaskActive[TaskId] in the active task status table 103. If it is the position index IdxWrite, it indicates that the asynchronous transmission task is in the active state. If it is 0xFF, it indicates that the asynchronous transmission task is not in the active state.

[0093] Step S203: When the asynchronous transmission task is not in the active state, obtain the remaining space quantity corresponding to the task queue according to the queue information table.

[0094] Step S204: Judge whether there is remaining space in the task queue according to the remaining space quantity.

[0095] Step S205: When there is remaining space in the task queue, obtain the tail index number from the queue information table.

[0096] It should be noted that the queue information table 102 is used to store the real-time status of the task queue 101. It is of the structure type, and its members include IdxRead for storing the head index number of the task queue 101, IdxWrite for storing the tail index number of the queue 101, and NumFree for storing the remaining space quantity of the task queue 101. The task queue 101 follows the first-in, first-out principle. When there is an SPI asynchronous communication request, this request will be placed at the IdxWrite element of the task queue 101, and then IdxWrite will be updated to the next free element to store new SPI asynchronous requests generated in the future. When processing the SPI asynchronous request, the scheduler will obtain the task number TaskId and the task status TaskState from the task queue 101 according to IdxRead in the queue information table 102. After the request is processed, IdxRead points to the next element of the queue 101. When an SPI asynchronous task is placed in the task queue 101, NumFree will decrease by 1 unit; when an asynchronous task is processed, NumFree will increase by 1 unit.

[0097] Step S206: Obtain the element to be filled from the task queue according to the tail index number.

[0098] Step S207: Write the task number corresponding to the asynchronous transmission task into the element to be filled according to the enqueue operation instruction, and adjust the task status corresponding to the asynchronous transmission task in the element to be filled to the waiting state.

[0099] Further, after the step S207, the method further includes: writing the task number and the position index corresponding to the asynchronous transmission task into the active task status table to generate a corresponding status value.

[0100] Refer to Figure 6 , Figure 6Schematic diagram of the enqueue process for an embodiment of the SPI asynchronous communication scheduling method of the present invention; specifically, obtain the element TaskActive[TaskId] from the active task status table 103 according to the task number TaskId, and determine whether the corresponding task is in the active state. If so, exit QueueTask(); if not, determine whether there is still remaining space in the task queue 101 according to the element NumFree in the queue information table 102. If not, set the fault code and return QueueTask(); if there is still remaining space, obtain the index number IdxWrite of the queue tail from the queue information table 102; obtain the element from the task queue 101 according to the tail index number IdxWrite, and fill in the element members TaskId and TaskState, and the values are from the input parameters of QueueTask(); write IdxWrite into the element TaskActive[TaskId] in the active task status table 103 to indicate that the task is being executed; update the queue information table 102, specifically including: decrementing the remaining number of elements NumFree in the task queue 101 by 1; incrementing the queue tail index number IdxWrite by 1 to point to the next free position.

[0101] Further, step S40 includes:

[0102] Step S401: Obtain the head index number from the queue information table.

[0103] Step S402: Obtain the queue element from the task queue according to the head index number.

[0104] Step S403: Obtain the target task number and target task state corresponding to the task to be transmitted in the queue element according to the dequeue operation instruction.

[0105] It should be understood that with reference to Figure 7 , Figure 7 Schematic diagram of the dequeue process for an embodiment of the SPI asynchronous communication scheduling method of the present invention; specifically, obtain the head index number IdxRead from the queue information table 102; obtain the queue element ScheduleFifo_st[IdxRead] from the task queue 101 according to the head index number; pass the members TaskId and TaskState in the element to the output parameters of UnqueueTask(). TaskId is the task number that the scheduler is about to operate on, and TaskState is the state of the task.

[0106] After the step S60, the method further includes: when it is determined according to the event trigger condition that the task to be transmitted does not need to be transmitted again, adjusting the task status corresponding to the task to be transmitted in the task queue to the stop state, and moving the head index number forward to obtain a target head index number; updating the queue information table according to the target head index number.

[0107] It should be noted that after the execution state (TASK_RUNNING) is completed, if the task needs to be executed continuously, the TaskState in the task queue 101 is set to the waiting state and enters the waiting state. After the execution state is completed, if the task does not need to be executed again, the scheduler state machine jumps to the stop state (TASK_STOP) and moves the head index number IdxRead of the task queue forward to prepare to execute the next SPI asynchronous task.

[0108] In this embodiment, an active task status table is set up, the status value is found from the active task status table to determine whether the asynchronous transmission task is in the active state, the queue information is set, and it is determined whether there is remaining space in the task queue according to the queue information. When the asynchronous transmission task is not in the active state and the queue has remaining space, the element to be filled is determined according to the tail index number in the queue information table, and the task number and task status are written into the element to implement the enqueue operation. The head index number is obtained through the queue information table, and the queue element is obtained from the task queue according to the head index number to implement the dequeue operation. Through the above method, multiple SPI asynchronous transmission requests generated in a short time can be scheduled and managed. According to the task active state and queue information, multiple SPI asynchronous transmission requests are put into the task queue. When a periodic trigger signal is triggered, the task is taken out of the queue according to the queue information, following the first-in, first-out principle to prevent congestion in the task queue. When the task status meets the requirements and the current SPI transmission channel is idle, the SPI asynchronous transmission operation is executed, reducing the occurrence of transmission errors. The receiver and the sender do not need to maintain the same clock frequency, realizing SPI asynchronous communication and reducing the time delay in the communication process.

[0109] Reference Figure 8 , Figure 8 is a schematic flowchart of the third embodiment of the SPI asynchronous communication scheduling method of the present invention.

[0110] Based on the above first embodiment, the step S60 of the SPI asynchronous communication scheduling method in this embodiment includes:

[0111] Step S601: Search for a preset task function table according to the target task number in the execution state to obtain a target execution function.

[0112] It can be understood that the task function table (TaskFunction) 105 is an array structure used to store function pointers and is set with the task ID TaskId as the index. Based on the task ID, the corresponding execution function can be found, and different execution states can be implemented based on the execution function. Specific SPI asynchronous data transfer tasks can be completed according to different execution states.

[0113] Perform an SPI asynchronous transfer operation on the task to be transferred according to the target execution function.

[0114] Among them, the performing an SPI asynchronous transfer operation on the task to be transferred according to the target execution function includes:

[0115] Step S602: Enter the request sub-state.

[0116] Step S603: Write request data to the SPI module in the request sub-state, and control the SPI module to perform an SPI asynchronous transfer operation on the task to be transferred according to the target execution function.

[0117] It should be noted that the scheduler realizes the transmission and data processing process of the SPI task through sub-states in the execution state. Specifically, the sub-states at least include a request sub-state (SUBSTATE_SPI_REQn) and a data processing sub-state (SUBSTATE_DATA_PROCESSn). For example, in the sub-state SUBSTATE_SPI_REQ00, an SPI asynchronous transfer Spi_AsyncTransmit(SPI_REQ00) operation is performed, which is to write the data of request 0 to the SPI module to make the SPI module start working.

[0118] Furthermore, before the step S602, the method further includes:

[0119] Step S604: Write the target execution function and data into a preset SPI running status word, where the preset SPI running status word is used to indicate the execution function and data currently being transferred.

[0120] It should be noted that before entering the request sub-state, the operation SetSpiReq(SPI_REQ00) needs to be executed. This operation is used to write data into the SPI operation status word 106, indicating that the SPI is in transmission. If the SPI transmission is not completed, within each execution cycle of the main function, the scheduler state machine stays in the request sub-state. When the SPI transmission is completed, the event EV_SPI_REQ00 is triggered and the SPI operation status word 106 is set to NONE by calling the instruction SetSpiReq(SPI_REQ_NONE), indicating no SPI transmission, and the execution state enters the data processing sub-state (SUBSTATE_DATA_PROCESS00) to complete the data processing corresponding to SPI request 0. After the asynchronous SPI transmission is completed, the event EV_SPI_REQ00 is triggered through the notification mechanism. There are two specific methods: the first method is to generate an interrupt after transmitting the data and trigger the event EV_SPI_REQ00 in the interrupt service routine; the second method is to periodically query the data transmission flag bit, and when it is set, trigger the event EV_SPI_REQ00. When the data processing is completed and / or the EV_CYCLE event occurs, it jumps to the next SPI instruction transmission and data processing state until all are completed.

[0121] Correspondingly, after the step S40, the method further includes:

[0122] Step S501: When it is detected that the preset SPI operation status word contains the current execution function and the current data, it is determined that the current SPI transmission channel is in a non-idle state. At this time, it remains in the waiting state until an event instruction triggered at the end of the transmission and / or the next periodic trigger signal is received.

[0123] It should be understood that in this embodiment, the scheduler determines whether the current SPI transmission channel is in an idle state according to the data in the preset SPI operation status word. If the current SPI transmission channel is in a non-idle state, it indicates that there is another SPI task in transmission currently. At this time, it remains in the waiting state until the trigger event EV_SPI_REQ00 and / or the next periodic trigger signal EV_CYCLE are received, and then enters the execution state, and performs the SPI asynchronous transmission operation in the execution state.

[0124] Refer to Figure 9 , Figure 9Schematic diagram of the scheduler state machine for an embodiment of the SPI asynchronous communication scheduling method of the present invention; the scheduler state machine is periodically called by the main function of the peripheral chip driver and consists of three main states, namely the stop state (TASK_STOP), the wait state (TASK_WAIT_START), and the execution state (TASK_RUNNING), which are reflected by the member TaskState in the task queue 101. Among them, the stop state indicates that the task is in the stop state. When in the stop state, the state machine will periodically execute Figure 7 the dequeue operation instruction shown, obtain tasks from the task queue 101, and enter the corresponding state according to the task state TaskState and the event trigger situation. Among them, the wait state indicates that the task is in the wait execution state. If after obtaining a task from the task queue 101, the TaskState of the obtained task is the wait state and the event EV_CYCLE occurs, then it jumps from the stop state to the wait state; if it is not the wait state, the scheduler stays in the stop state until Figure 7The dequeue operation instruction shown is called, and an SPI asynchronous transmission task is placed in the task queue 101. When the scheduler state machine executes periodically, the event EV_CYCLE is triggered. Among them, the execution state indicates that the task is in the executing state. When in the waiting state, if the SPI transmission channel is in the idle state at this time, it enters the execution state; otherwise, it continues to stay in the waiting state until the SPI transmission channel is idle. When in the stop state, if the task state obtained by query is the waiting state, it directly enters the waiting state. In the execution state, the SPI instructions and data required for transmitting the task with the task number TaskId are completed, and corresponding data processing is performed. The execution state is implemented through the request sub-state and the data processing sub-state. Taking the request sub-state SUBSTATE_SPI_REQ00 and the data processing sub-state SUBSTATE_DATA_PROCESS00 as examples, by requesting to execute the Spi_AsyncTransmit(SPI_REQ00) operation, which is to write the data of request 0 to the SPI module, causing the SPI module to start working. Before entering the request sub-state, the operation SetSpiReq(SPI_REQ00) needs to be executed to write data in the SPI running status word 106, indicating that the SPI is transmitting. If the SPI transmission is not completed, within each execution cycle of the main function, the scheduler state machine stays in the request sub-state. When the SPI transmission is completed, the event EV_SPI_REQ00 is triggered and the SPI running status word 106 is set to NONE by calling SetSpiReq(SPI_REQ_NONE), indicating no SPI transmission, and the execution state enters the data processing sub-state to complete the data processing corresponding to SPI request 0. After the execution state is completed, if the task needs to be executed continuously, then the TaskState in the task queue 101 is set to the waiting state and enters the waiting state. After the execution state is completed, if the task does not need to be executed again, the scheduler state machine jumps to the stop state and moves forward the head index IdxRead of the task queue 101 to prepare to execute the next SPI asynchronous task.

[0125] The SPI asynchronous communication scheduling method of this embodiment is described below with reference to an example. The execution entity is the microcontroller Infineon TC277, which has 4 SPI modules, and each module supports 16 peripheral channels. The peripheral device communicating with the microcontroller is the CAN transceiver chip TJA1145. The microcontroller controls TJA1145 through the SPI interface to implement the following 3 tasks:

[0126] The first task is: chip mode switching. The task number TaskId is TASKID_SET_MODE. As Figure 10 shown, Figure 10This is a schematic diagram of the implementation example of the first task execution state in an embodiment of the SPI asynchronous communication scheduling method of the present invention. This task realizes the working mode switching of the TJA1145 chip, including the normal transceiver mode Normal, the standby mode Standby, and the sleep mode Sleep. Before officially switching the mode, it is necessary to query the status registers of the chip, including the transceiver status register, the event register, and the wake-up register. When the scheduler state machine is in the execution state, the internal sub-state process is implemented by the function CanTrcv_ChangeModeTask(). The operation SetSpiReq(SPI_READ_STATUS) is executed, and data is written in the SPI operation status word 106, indicating that the SPI is transmitting. Enter the request sub-state and execute the SPI asynchronous transmission Spi_AsyncTransmit(SPI_READ_STATUS) operation to write the data of the chip status query request into the SPI module, so that the SPI module starts to work. By calling SetSpiReq(SPI_REQ_NONE), the SPI operation status word 106 is set to NONE, indicating no SPI transmission. The execution state enters the data processing sub-state (SUBSTATE_DATA_PROCESS00) to complete the data processing corresponding to the SPI chip status query request, that is, obtain the chip status data and process the chip status. The operation SetSpiReq(SPI_MODE_CHANGE) is executed, and data is written in the SPI operation status word 106, indicating that the SPI is transmitting. Enter the request sub-state and execute the SPI asynchronous transmission Spi_AsyncTransmit(SPI_CHANGE_MODE) operation to write the data of the chip mode switching request into the SPI module, so that the SPI module starts to work. By calling SetSpiReq(SPI_REQ_NONE), the SPI operation status word 106 is set to NONE, indicating no SPI transmission. The execution state enters the data processing sub-state (SUBSTATE_DATA_PROCESS02) to complete the data processing corresponding to the SPI chip mode switching request, that is, obtain the chip mode register value and confirm whether the mode switching is correct.

[0127] The second task is: chip status query, and the task ID TaskId is TASKID_READ_STATUS. As Figure 11 shown, Figure 11Schematic diagram of the implementation example of the second task execution status in an embodiment of the SPI asynchronous communication scheduling method of the present invention. This task is used to query the status registers of the chip, including the transceiver status register, event register, and wake-up register. When the scheduler state machine is in the execution state, the internal sub-state process is implemented by the function CanTrcv_ReadStatusTask(). The operation SetSpiReq(SPI_READ_STATUS) is executed, and data is written into the SPI running status word 106, indicating that SPI is in transmission. Then it enters the request sub-state and executes the SPI asynchronous transmission operation Spi_AsyncTransmit(SPI_READ_STATUS), writing the data of the chip status query request into the SPI module to make the SPI module start working. By calling SetSpiReq(SPI_REQ_NONE), the SPI running status word 106 is set to NONE, indicating no SPI transmission. The execution state enters the data processing sub-state (SUBSTATE_DATA_PROCESS00) to complete the data processing corresponding to the SPI chip status query request, that is, to obtain the chip status data and process the chip status.

[0128] The third task is: event flag bit clearing, and the task ID TaskId is TASKID_CLEAR_EVENT. As Figure 12 shown, Figure 12Schematic diagram of the implementation example of the third task execution state of an embodiment of the SPI asynchronous communication scheduling method of the present invention. This task is used to clear the flag bits in the event register and wake-up register, and then return to the status register of the chip, including the transceiver status register, event register, and wake-up register. When the scheduler state machine is in the execution state, the internal sub-state process is implemented by the function CanTrcv_EvClearTask(). The operation SetSpiReq(SPI_READ_STATUS) is executed, and data is written into the SPI operation status word 106, indicating that the SPI is transmitting. Enter the request sub-state, and execute the SPI asynchronous transmission operation Spi_AsyncTransmit(SPI_READ_STATUS), and write the data of the chip status query request into the SPI module to make the SPI module start working. By calling SetSpiReq(SPI_REQ_NONE), the SPI operation status word 106 is set to NONE, indicating no SPI transmission. The execution state enters the data processing sub-state (SUBSTATE_DATA_PROCESS00) to complete the data processing corresponding to the SPI chip status query request, that is, obtain the chip status data and process the chip status. The operation SetSpiReq(SPI_ENENT_CLEAR) is executed, and data is written into the SPI operation status word 106, indicating that the SPI is transmitting. Enter the request sub-state, and execute the SPI asynchronous transmission operation Spi_AsyncTransmit(SPI_ENENT_CLEAR), and write the data of the event flag bit clear request into the SPI module to make the SPI module start working. By calling SetSpiReq(SPI_REQ_NONE), the SPI operation status word 106 is set to NONE, indicating no SPI transmission. The execution state enters the data processing sub-state (SUBSTATE_DATA_PROCESS01) to complete the data processing corresponding to the SPI event flag bit clear request, that is, confirm whether the event is cleared successfully.

[0129] In this embodiment, the MCAL configuration tool and its function library supporting Infineon TC277 are used to implement the initialization of SPI module parameters and the asynchronous data transmission function of Spi_AsyncTransmit(). After the SPI data transmission is completed, the notification function CanTrcv_SpiNotification() is executed, as Figure 13 shown. Figure 13 Schematic diagram of the implementation example of the message notification mechanism of an embodiment of the SPI asynchronous communication scheduling method of the present invention.

[0130] It should be noted that referring to Figure 14 , Figure 14 Schematic diagram of the implementation example of the SPI asynchronous communication task manager of an embodiment of the SPI asynchronous communication scheduling method of the present invention.Figure 14 Each module in Figure 3 corresponds to the SPI asynchronous task manager shown in Figure 14 where ScheduleFifoType in Figure 3 corresponds to task queue 101 in Figure 14 where FifoOperation in Figure 3 corresponds to queue operation 104 in Figure 14 where the FifoInfoType structure in Figure 3 corresponds to queue information table 102 in Figure 14 where the TaskActive array in Figure 3 corresponds to active task status table 103 in Figure 14 where the function pointer array TaskFunctionPtrType in Figure 3 corresponds to task function table 105 in Figure 14 where SpiReqStatus in Figure 3 corresponds to SPI operation status word 106 in Figure 6 and Figure 7 . After the SPI data transmission is completed, the notification function CanTrcv_SpiNotification() is executed, and the implementation method is as Figure 13 shown.

[0131] In this embodiment, the scheduler state machine is implemented as Figure 15 shown, consisting of three main states: stop state, wait state, and execution state. These three states are reflected by the member TaskState in the task queue ScheduleFifoType. The operations performed in the execution state depend on TaskId. The implementation of the sub-state machines in the execution state corresponding to each TaskId is respectively as Figure 10 , Figure 11 , Figure 12 shown.

[0132] When an asynchronous transmission task is detected in this embodiment, an enqueue operation instruction is called; according to the enqueue operation instruction, the task number corresponding to the asynchronous transmission task is placed in the task queue, and the task status corresponding to the asynchronous transmission task in the task queue is adjusted to the waiting state; when a periodic trigger signal is received, a dequeue operation instruction is called; according to the dequeue operation instruction, the target task number and target task status corresponding to the task to be transmitted are obtained from the task queue; when the target task status is the waiting state and the current SPI transmission channel is in the idle state, it enters the execution state; in the execution state, a preset task function table is searched according to the target task number to obtain the target execution function; the SPI asynchronous transmission operation is performed on the task to be transmitted according to the target execution function. This embodiment sets a preset task function table, which includes the task number and the corresponding execution function, and designs different implementation methods of the execution state for different SPI transmission tasks, that is, the execution function is found by using the task number, and different execution states are implemented according to the execution function, which can schedule and manage multiple SPI asynchronous transmission requests generated in a short time, and implement different execution states according to different execution functions, reduce the occurrence of transmission errors, the receiving party and the sending party do not need to maintain the same clock frequency, realize SPI asynchronous communication, and reduce the time delay in the communication process.

[0133] In addition, an embodiment of the present invention further provides a storage medium, on which an SPI asynchronous communication scheduling program is stored, and when the SPI asynchronous communication scheduling program is executed by a processor, the SPI asynchronous communication scheduling method as described above is implemented.

[0134] Since this storage medium adopts all the technical solutions of the above-mentioned all embodiments, it at least has all the beneficial effects brought by the technical solutions of the above-mentioned embodiments, and will not be elaborated here one by one.

[0135] Refer to Figure 16 , Figure 16 which is the structural block diagram of the first embodiment of the SPI asynchronous communication scheduling device of the present invention.

[0136] As Figure 16 shown, the SPI asynchronous communication scheduling device proposed by the embodiment of the present invention includes:

[0137] An enqueue module 10, configured to call an enqueue operation instruction when an asynchronous transmission task is detected;

[0138] The enqueue module 10 is further configured to place the task number corresponding to the asynchronous transmission task in the task queue according to the enqueue operation instruction, and adjust the task status corresponding to the asynchronous transmission task in the task queue to the waiting state;

[0139] A dequeue module 20, configured to call a dequeue operation instruction when a periodic trigger signal is received;

[0140] The dequeue module 20 is further configured to obtain the target task number and the target task status corresponding to the task to be transmitted from the task queue according to the dequeue operation instruction;

[0141] The transmission module 30 is configured to enter an execution state when the target task status is a waiting state and the current SPI transmission channel is in an idle state;

[0142] The transmission module 30 is further configured to perform an SPI asynchronous transmission operation on the task to be transmitted according to the target execution function corresponding to the target task number in the execution state.

[0143] It should be understood that the above is only an example for illustration and does not impose any limitation on the technical solution of the present invention. In specific applications, those skilled in the art can set according to needs, and the present invention does not limit this.

[0144] In this embodiment, when an asynchronous transmission task is detected, an enqueue operation instruction is called; according to the enqueue operation instruction, the task number corresponding to the asynchronous transmission task is placed in the task queue, and the task status corresponding to the asynchronous transmission task in the task queue is adjusted to the waiting state; when a periodic trigger signal is received, a dequeue operation instruction is called; according to the dequeue operation instruction, the target task number and the target task status corresponding to the task to be transmitted are obtained from the task queue; when the target task status is the waiting state and the current SPI transmission channel is in the idle state, enter the execution state; in the execution state, perform an SPI asynchronous transmission operation on the task to be transmitted according to the target execution function corresponding to the target task number. Through the above method, it is possible to schedule and manage multiple SPI asynchronous transmission requests generated within a short period of time, place multiple SPI asynchronous transmission requests in the task queue, when a periodic trigger signal is triggered, take out tasks from the queue, and when the task status meets the requirements and the current SPI transmission channel is idle, perform an SPI asynchronous transmission operation, reduce the occurrence of transmission errors, the receiving party and the sending party do not need to maintain the same clock frequency, realize SPI asynchronous communication, and reduce the time delay in the communication process.

[0145] It should be noted that the above-described work process is only illustrative and does not limit the protection scope of the present invention. In actual applications, those skilled in the art can select some or all of them according to actual needs to achieve the purpose of the solution of this embodiment, and no limitation is imposed here.

[0146] In addition, for the technical details not described in detail in this embodiment, reference can be made to the SPI asynchronous communication scheduling method provided in any embodiment of the present invention, which will not be elaborated here.

[0147] In one embodiment, the enqueue module 10 is further configured to find a corresponding status value from the active task status table according to the task number corresponding to the asynchronous transmission task; determine whether the asynchronous transmission task is in an active state according to the status value; when the asynchronous transmission task is not in an active state, obtain the remaining space quantity of the task queue according to the queue information table; determine whether the task queue has remaining space according to the remaining space quantity; when the task queue has remaining space, obtain the tail index number from the queue information table; obtain the element to be filled from the task queue according to the tail index number; write the task number corresponding to the asynchronous transmission task into the element to be filled according to the enqueue operation instruction, and adjust the task status corresponding to the asynchronous transmission task in the element to be filled to the waiting state.

[0148] In one embodiment, the dequeue module 20 is further configured to obtain the head index number from the queue information table; obtain the queue element from the task queue according to the head index number; obtain the target task number and the target task status corresponding to the task to be transmitted in the queue element according to the dequeue operation instruction.

[0149] In one embodiment, the SPI asynchronous communication scheduling device further includes: an update module;

[0150] The update module is configured to, when it is determined that the task to be transmitted does not need to be transmitted again according to the event trigger situation, adjust the task status corresponding to the task to be transmitted in the task queue to the stop state, and move the head index number forward to obtain a target head index number; update the queue information table according to the target head index number.

[0151] In one embodiment, the transmission module 30 is further configured to find a target execution function from a preset task function table according to the target task number in the execution state; perform an SPI asynchronous transmission operation on the task to be transmitted according to the target execution function.

[0152] In one embodiment, the transmission module 30 is further configured to enter a request sub-state; write request data to the SPI module in the request sub-state, and control the SPI module to perform an SPI asynchronous transmission operation on the task to be transmitted according to the target execution function.

[0153] In one embodiment, the transmission module 30 is further configured to write the target execution function and data into a preset SPI operation status word, where the preset SPI operation status word is used to indicate the execution function and data currently being transmitted;

[0154] The transmission module 30 is further configured to determine that the current SPI transmission channel is in a non-idle state when it detects that the preset SPI operation status word contains the current execution function and the current data. At this time, it remains in a waiting state until it receives an event instruction triggered at the end of the transmission and / or the next periodic trigger signal.

[0155] In addition, it should be noted that in this article, the terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements not only includes those elements, but also includes other elements not expressly listed, or elements inherent to such process, method, article or system. Without further limitation, an element defined by the statement "including one..." does not exclude the existence of additional identical elements in the process, method, article or system including that element.

[0156] The serial numbers of the above-described embodiments of the present invention are only for description and do not represent the superiority or inferiority of the embodiments.

[0157] Through the description of the above embodiments, those skilled in the art can clearly understand that the above-described embodiment methods can be implemented by means of software plus a necessary general hardware platform. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. The computer software product is stored in a storage medium (such as a read-only memory (ROM) / RAM, magnetic disk, optical disk), and includes several instructions for causing a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in various embodiments of the present invention.

[0158] The above are only the preferred embodiments of the present invention, and do not limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made by using the content of the specification and drawings of the present invention, or directly or indirectly applied in other related technical fields, shall be equally included in the patent protection scope of the present invention.

Claims

1. An SPI asynchronous communication scheduling method, characterized in that, The described SPI asynchronous communication scheduling method includes: When an asynchronous transmission task is detected, call the enqueue operation instruction; According to the enqueue operation instruction, put the task number corresponding to the asynchronous transmission task into the task queue, and adjust the task status corresponding to the asynchronous transmission task in the task queue to the waiting state; When a periodic trigger signal is received, call the dequeue operation instruction; According to the dequeue operation instruction, obtain the target task number and target task status corresponding to the task to be transmitted from the task queue; When the target task status is the waiting state and the current SPI transmission channel is in the idle state, enter the execution state; In the execution state, perform the SPI asynchronous transmission operation on the task to be transmitted according to the target execution function corresponding to the target task number; The step of putting the task number corresponding to the asynchronous transmission task into the task queue according to the enqueue operation instruction and adjusting the task status corresponding to the asynchronous transmission task in the task queue to the waiting state includes: Find the corresponding status value from the active task status table according to the task number corresponding to the asynchronous transmission task; Judge whether the asynchronous transmission task is in the active state according to the status value; When the asynchronous transmission task is not in the active state, obtain the remaining space quantity corresponding to the task queue according to the queue information table; Judge whether the task queue has remaining space according to the remaining space quantity; When the task queue has remaining space, obtain the tail index number from the queue information table; Obtain the element to be filled from the task queue according to the tail index number; Write the task number corresponding to the asynchronous transmission task into the element to be filled according to the enqueue operation instruction, and adjust the task status corresponding to the asynchronous transmission task in the element to be filled to the waiting state.

2. The SPI asynchronous communication scheduling method according to claim 1, wherein, The step of obtaining the target task number and target task status corresponding to the task to be transmitted from the task queue according to the dequeue operation instruction includes: Obtain the head index number from the queue information table; Obtain the queue element from the task queue according to the head index number; Obtain the target task number and target task status corresponding to the task to be transmitted in the queue element according to the dequeue operation instruction.

3. The SPI asynchronous communication scheduling method according to claim 2, wherein After performing the SPI asynchronous transmission operation on the task to be transmitted according to the target execution function corresponding to the target task number in the execution state, the method further includes: When it is determined according to the event trigger situation that the task to be transmitted does not need to be transmitted again, adjust the task status corresponding to the task to be transmitted in the task queue to the stop state, and move the head index number forward to obtain the target head index number; Update the queue information table according to the target head index number.

4. The SPI asynchronous communication scheduling method according to claim 1, wherein, The step of performing the SPI asynchronous transmission operation on the task to be transmitted according to the target execution function corresponding to the target task number in the execution state includes: In the execution state, find the preset task function table according to the target task number to obtain the target execution function; Perform the SPI asynchronous transmission operation on the task to be transmitted according to the target execution function.

5. The SPI asynchronous communication scheduling method according to claim 4, wherein Performing an SPI asynchronous transmission operation on the to-be-transmitted task according to the target execution function includes: Entering a request sub-state; Writing request data to the SPI module in the request sub-state, and controlling the SPI module to perform an SPI asynchronous transmission operation on the to-be-transmitted task according to the target execution function.

6. The SPI asynchronous communication scheduling method according to claim 5, wherein Before entering the request sub-state, the method further includes: Writing a target execution function and data in a preset SPI running status word, where the preset SPI running status word is used to indicate the execution function and data currently being transmitted; After obtaining the target task number and target task status corresponding to the to-be-transmitted task from the task queue according to the dequeue operation instruction, the method further includes: When it is detected that the preset SPI running status word contains the current execution function and current data, determining that the current SPI transmission channel is in a non-idle state, and at this time, maintaining a waiting state until an event instruction triggered at the end of transmission and / or the next periodic trigger signal is received.

7. An SPI asynchronous communication scheduling device, characterized in that, The SPI asynchronous communication scheduling device includes: An enqueue module, configured to call an enqueue operation instruction when an asynchronous transmission task is detected; The enqueue module is further configured to put the task number corresponding to the asynchronous transmission task into the task queue according to the enqueue operation instruction, and adjust the task status corresponding to the asynchronous transmission task in the task queue to a waiting state; The enqueue module is further configured to find a corresponding status value from the active task status table according to the task number corresponding to the asynchronous transmission task; Judging whether the asynchronous transmission task is in an active state according to the status value; When the asynchronous transmission task is not in an active state, obtaining the remaining space quantity corresponding to the task queue according to the queue information table; Judging whether the task queue has remaining space according to the remaining space quantity; When the task queue has remaining space, obtaining a tail index number from the queue information table; Obtaining an element to be filled from the task queue according to the tail index number; Writing the task number corresponding to the asynchronous transmission task into the element to be filled according to the enqueue operation instruction, and adjusting the task status corresponding to the asynchronous transmission task in the element to be filled to a waiting state; A dequeue module, configured to call a dequeue operation instruction when a periodic trigger signal is received; The dequeue module is further configured to obtain the target task number and target task status corresponding to the to-be-transmitted task from the task queue according to the dequeue operation instruction; A transmission module, configured to enter an execution state when the target task status is a waiting state and the current SPI transmission channel is in an idle state; The transmission module is further configured to perform an SPI asynchronous transmission operation on the to-be-transmitted task according to the target execution function corresponding to the target task number in the execution state.

8. An SPI asynchronous communication scheduling device, characterized in that, The device includes: a memory, a processor, and an SPI asynchronous communication scheduling program stored on the memory and executable on the processor, and the SPI asynchronous communication scheduling program is configured to implement the SPI asynchronous communication scheduling method according to any one of claims 1 to 6.

9. A storage medium, characterized in that, The SPI asynchronous communication scheduler is stored on the storage medium, and when the SPI asynchronous communication scheduler is executed by a processor, it implements the SPI asynchronous communication scheduling method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • SPI and Eprom asynchronous communication method of hierarchical task system

    CN109976898A

  • Task processing method and related device

    CN112181616A