Task scheduling processing method, system and device and medium

By pre-triggering the activation mechanism of periodic tasks in the inverter control system and prioritizing the execution of response tasks, the problem of long scanning time during task scheduling is solved, and the task scheduling efficiency is improved.

CN119938278APending Publication Date: 2025-05-06CHANGSHA YINGWEITENG ELECTRIC TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510103003.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-22
Publication Date
2025-05-06

AI Technical Summary

Technical Problem

In the inverter control system, scanning is required when switching to trigger another task during task scheduling, resulting in a long scanning time and reducing task scheduling efficiency.

Method used

By obtaining the time and the current execution task corresponding to the periodic task interval, if the first moment used to characterize the triggering of the periodic task and the current execution task is a normal task, the activation mechanism of the periodic task is triggered and the periodic task is executed at the second moment. At the same time, when responding to task requests are triggered, response tasks are performed first to reduce scanning time.

Benefits of technology

By pre-triggering the activation mechanism of periodic tasks and prioritizing the execution of response tasks, the task priority scanning process is reduced, scanning time and computing resources are saved, and task scheduling efficiency is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119938278A_ABST
    Figure CN119938278A_ABST
Patent Text Reader

Abstract

The invention discloses a task scheduling processing method, system and device and a medium, and relates to the technical field of task scheduling. In the process of executing a common task, when a periodic task needs to be executed, a first moment which corresponds to a timing moment and is used for representing triggering of the periodic task is known in advance, and a stack space of a running environment of the corresponding periodic task is scanned at a time interval between the first moment and a second moment; and the priority scanning process of other tasks does not need to be carried out, so that the priority scanning time of the other tasks and corresponding scanning computing resources are saved. When the timing moment reaches the first moment and the common task is executed currently, the response task is triggered, the response task is executed immediately, the response task is switched and executed at the moment, the scanning process of the scanning stack space of the task does not need to be carried out, and due to the fact that the data size corresponding to the response task is small, the response task occupies the stack space of the currently executed task, the task is not required to be scanned. Therefore, the scanning time is saved. In short, the task scheduling efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of task scheduling, and in particular to a task scheduling processing method, system, device and medium. Background Art

[0002] In the inverter control system, there are three main types of tasks: periodic control tasks, real-time response tasks of external time, and ordinary tasks. In the task scheduling process, no matter what type of task it is, before switching to trigger another task, it scans to determine whether there is a task with a higher priority and whether there are other tasks in the space corresponding to the current task being executed. This scanning process results in a longer scanning time during the entire task scheduling process, thereby extending the task scheduling time.

[0003] Therefore, how to improve task scheduling efficiency is an urgent problem that technical personnel in this field need to solve. Summary of the invention

[0004] The purpose of the present invention is to provide a task scheduling processing method, system, device and medium to solve the problem that when switching to trigger another task during the task scheduling process, the scanning time required is long, thereby reducing the task scheduling efficiency.

[0005] In order to solve the above technical problems, the present invention provides a task scheduling processing method, comprising:

[0006] Get the timing time corresponding to the periodic task interval and the currently executed task;

[0007] If the timing moment reaches the first moment used to characterize the triggering of the periodic task and the currently executed task is a common task, the activation mechanism of the periodic task corresponding to the timing moment is triggered, and when the timing moment reaches the second moment used to characterize the execution of the periodic task, the periodic task is executed; wherein the time interval between the last periodic task triggering moment corresponding to the timing moment and the current periodic task triggering moment is greater than the time interval between the first moment and the second moment, and the activation mechanism of the periodic task includes a scanning mechanism of the stack space corresponding to the periodic task;

[0008] If the timing moment reaches the first moment, the currently executed task is a common task and the request of the response task is triggered, then after waiting for the response task to be executed, return to the step of activating the periodic task corresponding to the timing moment to trigger the periodic task, so as to execute the periodic task; wherein the urgency of the response task, the periodic task and the common task decreases in sequence.

[0009] On the one hand, when the activation mechanism of the periodic task corresponding to the timing moment is triggered, it also includes:

[0010] Obtain a first stack space for storing a common task currently being executed;

[0011] If the common task is finished, the DMA mode is started to transfer the stack data of the common task currently executed and stored in the first stack space to the second stack space, and the next common task to be executed is determined in the second stack space;

[0012] When the timing reaches the second moment, the DMA mode is started to transfer the next common task to be executed in the second stack space to the first stack space, so as to wait for the completion of the periodic task and switch to the context of the first stack space to execute the next common task to be executed.

[0013] On the other hand, the first stack space and the third stack space for storing periodic tasks are located in the internal RAM space, and the number of stack spaces corresponding to each of the first stack space and the third stack space is one;

[0014] The second stack space is located in the external RAM space, and the number of stack spaces of the second stack space is at least one.

[0015] On the other hand, when the activation mechanism of the periodic task corresponding to the timing moment is triggered, it also includes:

[0016] If the ordinary task has not been completed, after the periodic task is completed, a new first moment of triggering the next periodic task corresponding to the timing moment is obtained;

[0017] Get the current time;

[0018] If the time interval between the new first moment and the current moment is less than the first preset time interval, the new first moment triggered by the next periodic task is waited for to arrive, and the execution of the ordinary task is prohibited.

[0019] On the other hand, waiting for the execution of the periodic task to be completed and switching to the context of the first stack space to execute the next common task to be executed includes:

[0020] Get the scan time corresponding to switching to the next common task to be executed;

[0021] Obtain the current time corresponding to when the periodic task is completed and the new first time and the new second time of triggering the next periodic task corresponding to the timing time;

[0022] Determine a preset time according to the current time, the scanning time and the new first time;

[0023] If the time interval between the preset moment and the new second moment is less than the second preset time interval, or the preset moment reaches or exceeds the new second moment, then wait for the new first moment triggered by the next periodic task to arrive to execute the next periodic task, and prohibit the execution of the next ordinary task to be executed;

[0024] If the time interval between the preset time and the new second time is greater than or equal to the second preset time interval, and the preset time has not reached the new second time, the next common task to be executed is executed.

[0025] On the other hand, it also includes:

[0026] If the timing moment corresponding to the periodic task interval does not exist, when the currently executed task is a common task, and when the request of the response task is triggered, the response task is executed, and the common task is continued to be executed after the response task is completed;

[0027] Alternatively, if the currently executed task is a periodic task and the request of the response task is triggered, the response task is executed, and the execution of the periodic task is continued after the response task is completed.

[0028] On the other hand, the response task occupies the stack space corresponding to the currently executed task during execution.

[0029] In order to solve the above technical problems, the present invention also provides a task scheduling processing system, comprising:

[0030] An acquisition module is used to obtain the timing time corresponding to the periodic task interval and the currently executed task;

[0031] A first execution module is used to trigger the activation mechanism of the periodic task corresponding to the timing moment if the timing moment reaches the first moment used to characterize the triggering of the periodic task and the currently executed task is a common task, and execute the periodic task when the timing moment reaches the second moment used to characterize the execution of the periodic task; wherein the time interval between the last periodic task triggering moment corresponding to the timing moment and the current periodic task triggering moment is greater than the time interval between the first moment and the second moment, and the activation mechanism of the periodic task includes a scanning mechanism of the stack space corresponding to the periodic task;

[0032] The second execution module is used to, if the timing moment reaches the first moment, the currently executed task is a common task and the request of the response task is triggered, then wait for the response task to be executed and then return to the step of activating the periodic task corresponding to the triggering timing moment to execute the periodic task; wherein the urgency of the response task, the periodic task and the common task decreases in sequence.

[0033] In order to solve the above technical problems, the present invention further provides a task scheduling processing device, comprising:

[0034] Memory for storing computer programs;

[0035] A processor is used to implement the steps of the task scheduling processing method when executing the computer program.

[0036] In order to solve the above technical problems, the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the task scheduling processing method as described above are implemented.

[0037] The present invention provides a task scheduling processing method. On the one hand, when a periodic task needs to be executed during the execution of an ordinary task, the first moment corresponding to the timing moment for characterizing the triggering of the periodic task is known in advance, which is obtained by the stack space scanning time corresponding to the operating environment of the periodic task obtained by reverse deduction when the periodic task is actually executed. When the first moment is reached and the second moment of the execution of the periodic task is not reached, the activation mechanism of the periodic task is triggered in advance, that is, the stack space of the operating environment of the corresponding periodic task is scanned in the time interval between the first moment and the second moment, and the priority scanning process of the remaining tasks is not required, saving the priority scanning time of the remaining tasks and the corresponding scanning computing resources. On the other hand, when the timing moment reaches the first moment and the ordinary task is currently executed, the response task is triggered, then based on the urgency of the response task, it takes precedence over the periodic task and the ordinary task, and the response task is executed immediately. At this time, the response task is switched to be executed, and there is no need to perform the scanning process of the task stack space. Considering that the amount of data corresponding to the response task is small, it occupies the stack space of the currently executed task, so as to save the scanning time. In short, the efficiency of task scheduling is improved.

[0038] In addition, the present invention also provides a task scheduling processing system, device and medium, which have the same beneficial effects as the above-mentioned task scheduling processing method. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0040] Figure 1 A flowchart of a task scheduling processing method provided by an embodiment of the present invention;

[0041] Figure 2 A flowchart of another task scheduling processing method provided by an embodiment of the present invention;

[0042] Figure 3 A structural diagram of a task scheduling processing system provided by an embodiment of the present invention;

[0043] Figure 4 A structural diagram of a task scheduling processing device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0044] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0045] The core of the present invention is to provide a task scheduling processing method, system, device and medium to solve the problem that when switching to trigger another task during the task scheduling process, the scanning time required is long, thereby reducing the task scheduling efficiency.

[0046] In order to enable those skilled in the art to better understand the solution of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0047] Currently, in the inverter control software, the task types can be divided into three types. The first type is the periodic control task. The operation cycle of this type of task is determined and the start time is predictable, but the real-time requirements for the task operation are not too high, and it only needs to be completed within a certain time. For example, the motor control algorithm task in the inverter generally uses the integer multiple period of the pulse width modulation (PWM) carrier frequency as the control cycle, and samples the current, voltage and other physical quantities in this fixed control cycle, and then activates the motor control algorithm task for calculation, and the results are output to the PWM and other actuators to achieve closed-loop regulation.

[0048] The second type is the real-time response task of external events. This type of task is driven by external events and is generally activated by interrupts. The activation time is unpredictable, but the real-time response is required to be high, and the response speed is generally required to be as fast as possible. For example, the hardware overcurrent fault protection task of the inverter is activated by triggering the external interrupt of the digital signal processor (DSP) after the hardware detects the occurrence of an overcurrent fault. Obviously, the system requires the response speed to be as fast as possible for this task.

[0049] The third type is ordinary tasks, which have unlimited running cycles and can be periodic or event-driven. The real-time requirements for tasks are lower than those for the other two types of tasks, and the response speed requirements vary. For example, the inverter's key and display processing tasks, serial port communication processing tasks, etc.

[0050] Commonly used task scheduling methods are foreground and background mode and real-time operating system (RTOS) mode. Of these two modes, the foreground and background mode has a higher resource utilization rate, but programming is more troublesome. It is necessary to design resource usage between tasks during code writing to prevent resource conflicts. Design data synchronization methods between tasks to prevent data read and write conflicts. In the foreground and background mode, tasks are often designed as functions, and each function is called once, that is, the task is run once. Each task does not have an independent stack space, and all tasks and foreground and background system-related codes share the same stack space. The real-time operating system mode has a relatively low resource utilization rate, but programming is relatively simple. RTOS can be used to schedule resources between tasks to prevent resource conflicts. Use semaphores and other methods provided by RTOS to achieve synchronous control of tasks and data. In the RTOS mode, tasks are designed as independent large loops, and central processing unit (CPU) resources are allocated according to the priority of each task through time slice polling or task blocking. Different tasks have independent stack spaces, and each occupies a piece of random access memory (RAM) as the stack space of the task. Therefore, the overall utilization rate of the stack space is lower than that of the foreground and background methods. When it comes to switching from one task to another, it is necessary to scan to determine whether there is a task with a higher priority than the other task to be processed. If so, it is necessary to schedule the task with a higher priority of the other task; if not, it is necessary to scan whether there is the possibility of executing other tasks in the storage stack space corresponding to the other task. Due to the attribute of the task's exclusive stack space, if so, it is necessary to wait for other tasks in the storage stack space of the task to be executed, and then release resources before executing the task. The entire scanning process takes a long time for scheduling processing, thereby reducing the efficiency of task scheduling. The task scheduling processing method provided by the present invention can solve the above technical problems.

[0051] Figure 1 A flowchart of a task scheduling method provided by an embodiment of the present invention is shown in FIG. Figure 1 As shown, the method includes:

[0052] S11: Obtain the timing time corresponding to the periodic task interval and the currently executed task;

[0053] S12: If the timing moment reaches the first moment used to characterize the triggering of the periodic task and the currently executed task is a common task, the activation mechanism of the periodic task corresponding to the timing moment is triggered, and when the timing moment reaches the second moment used to characterize the execution of the periodic task, the periodic task is executed;

[0054] Wherein, the time interval between the last periodic task triggering time corresponding to the timing time and the current periodic task triggering time is greater than the time interval between the first time and the second time, and the activation mechanism of the periodic task includes a scanning mechanism of the stack space corresponding to the periodic task;

[0055] S13: If the timing moment reaches the first moment, the currently executed task is a common task and the request of the response task is triggered, then after waiting for the response task to be executed, the process returns to the step of activating the periodic task corresponding to the trigger timing moment to execute the periodic task;

[0056] Among them, the urgency of response tasks, periodic tasks and ordinary tasks decreases in sequence.

[0057] Specifically, in step S11, the timing moment corresponding to the periodic task interval is obtained. The timing moment here is the triggering moment of the previous periodic task, or the execution moment of the previous periodic task, or the triggering moment of the current periodic task, or the execution moment of the current periodic task. It should be noted that the timing moment of the periodic task is valid based on the existence of the triggering moment of the previous periodic task. If there is no triggering moment of the previous periodic task, there is no periodic task. The currently executed task can be any type of task here. This embodiment provides response tasks, periodic tasks and ordinary tasks, among which the response task is a real-time response task corresponding to an external event, and the periodic task is a periodic control task. The urgency of the task execution decreases in sequence, that is, the response task is prioritized first, then the periodic task, and finally the ordinary task is executed.

[0058] In step S12, if the timing moment arrives at the first moment for characterizing the triggering of the periodic task, and the currently executed task is a common task, the timing moment arrives at the first moment at this time, indicating that there is a periodic task, and the triggering moment of the current periodic task to be executed has arrived. The recording of the timing moment here can be realized by hardware timer timing, or by software timing and other methods. It is not limited here, and can be set according to the actual situation. When the triggering moment arrives, it is necessary to check and compare the level of urgency of the currently executed task. When the currently executed task is a common task, the activation mechanism of the periodic task corresponding to the timing moment is triggered. The activation mechanism here is to give the periodic task preparation time before execution, and is used for the scanning mechanism of the stack space corresponding to the periodic task. Although the timing moment arrives at the first moment for characterizing the triggering of the periodic task, it is not directly triggered at this time, and the urgency of the task needs to be considered. If the currently executed task is a real-time response task, since the urgency of the real-time response task is better than that of the periodic task, even if the first moment is triggered, the periodic task is processed after the real-time response task is processed.

[0059] When the timing reaches the second moment for representing the execution of the periodic task, that is, the moment when the periodic task is actually executed, this embodiment is equivalent to predicting the first moment in advance and running the activation mechanism of the periodic task in advance.

[0060] The time interval between the triggering time of the previous periodic task and the triggering time of the current periodic task at the timing moment is much greater than the time interval between the first moment and the second moment, which means that the time interval between the triggering of two adjacent tasks provides enough scanning time for the periodic task. The time interval between the first moment and the second moment is the activation time of the activation mechanism for the periodic task. Currently, the activation mechanism can also include the system context switching time, the execution time of the Direct Memory Access (DMA) code, and the timing margin. Compared with the conventional switching from ordinary tasks to periodic tasks, the task priority comparison scanning process is reduced, which also reduces the scanning time of the process and speeds up the task scheduling process. It should be noted that although the urgency priority corresponding to each task is known in the conventional task scheduling, there will still be tasks with lower priority levels that need to be scanned when any task switching is involved.

[0061] Even if the timing moment in step S13 reaches the first moment, when the currently executed task is an ordinary task, the request instruction of the response task is triggered at this time, and the response task needs to be executed immediately to wait for the response task to be executed, and then trigger the activation mechanism of the periodic task, which is the same as the subsequent activation process and execution process of step S12, and will not be repeated here. It should be noted that when the response task is triggered, since the urgency of the response task is higher than the urgency of the periodic task and the ordinary task, the response task is directly executed without the need to perform activation scanning and other steps on the response task. Compared with the conventional task scheduling process, corresponding to the switching of the response task, the scanning process corresponding to the scanning task priority level and the scanning process of the stack space corresponding to the response task are reduced, and direct execution is performed, thereby improving the scheduling efficiency of the response task.

[0062] It should be noted here that the data volume of the response task is small, and the corresponding stack space is small. In this case, according to the occupancy of the stack space, the stack space corresponding to the currently executing task is directly used without opening up additional stack space.

[0063] A task scheduling processing method provided by an embodiment of the present invention includes: obtaining a timing moment corresponding to a periodic task interval and a currently executed task; if the timing moment reaches a first moment used to characterize the triggering of the periodic task and the currently executed task is an ordinary task, then triggering the activation mechanism of the periodic task corresponding to the timing moment, and executing the periodic task when the timing moment reaches a second moment used to characterize the execution of the periodic task; wherein the time interval between the last periodic task triggering moment corresponding to the timing moment and the current periodic task triggering moment is greater than the time interval between the first moment and the second moment, and the activation mechanism of the periodic task includes a scanning mechanism for the stack space corresponding to the periodic task; if the timing moment reaches the first moment, the currently executed task is an ordinary task and the request of the response task is triggered, then waiting for the response task to be executed and then returning to the step of triggering the activation mechanism of the periodic task corresponding to the timing moment to execute the periodic task; wherein the urgency of the response task, the periodic task and the ordinary task decreases in sequence. On one hand, in the process of executing ordinary tasks, when a periodic task needs to be executed, the first moment corresponding to the timing moment for characterizing the triggering of the periodic task is known in advance, which is obtained by the stack space scanning time corresponding to the operating environment of the periodic task obtained by reverse deduction when the periodic task is actually executed. When the first moment is reached and the second moment of the execution of the periodic task is not reached, the activation mechanism of the periodic task is triggered in advance, that is, the stack space of the operating environment of the corresponding periodic task is scanned in the time interval between the first moment and the second moment, without the need to perform the priority scanning process of the remaining tasks, saving the priority scanning time of the remaining tasks and the corresponding scanning computing resources. On the other hand, when the timing moment reaches the first moment and the ordinary task is currently executed, the response task is triggered, then based on the urgency of the response task, it takes precedence over the periodic task and the ordinary task, and the response task is executed immediately. At this time, the response task is switched to be executed, and there is no need to perform the scanning process of the task scanning stack space. Considering that the amount of data corresponding to the response task is small, it occupies the stack space of the currently executed task, so as to save the scanning time. In short, the task scheduling efficiency is improved.

[0064] In some embodiments, when the activation mechanism of the periodic task corresponding to the timing moment is triggered, it also includes:

[0065] Obtain a first stack space for storing a common task currently being executed;

[0066] If the common task is finished, the DMA mode is started to transfer the stack data of the common task currently executed and stored in the first stack space to the second stack space, and the next common task to be executed is determined in the second stack space;

[0067] When the timing reaches the second moment, the DMA mode is started to transfer the next common task to be executed in the second stack space to the first stack space, so as to wait for the periodic task to be executed and switch to the context of the first stack space to execute the next common task to be executed.

[0068] Specifically, when the activation mechanism of the periodic task corresponding to the timing moment is triggered, it is necessary to check the execution progress of the currently executed task. If the execution progress of the currently executed task has just ended, it is necessary to switch to the execution of the next ordinary task after the execution of the periodic task is completed. Therefore, when the CPU execution subject executes the activation mechanism of the periodic task, the DMA mode is started to transfer the stack data of the currently executed ordinary task stored in the first stack space to the second stack space, and determine the next ordinary task to be executed in the second stack space. It should be noted that the DAM controller can independently complete data transmission without the intervention of the CPU, and can complete various data transmission methods such as memory to memory, memory to peripherals, and peripherals to memory, thereby realizing parallel processing of data transmission and improving task scheduling efficiency.

[0069] In addition, when the timing reaches the second time, the DMA mode is started to transfer the next common task to be executed in the second stack space to the first stack space, so as to switch to the context of the first stack space to execute the next common task to be executed after waiting for the periodic task to be executed.

[0070] The present embodiment provides that when the currently executing task is a common task, when the execution progress of the currently executing task corresponding to the periodic task just ends, the execution data of the currently executing task is switched to the second stack space through DMA, and the switching preparation work corresponding to the next common task to be executed is ready, so that the CPU is activated and the periodic task is executed at the same time, and the DMA technology switches the parallel processing mode of the common task, thereby improving the efficiency of task scheduling.

[0071] In some embodiments, waiting for the periodic task to be executed and switching to the context of the first stack space to execute the next common task to be executed includes:

[0072] Get the scan time corresponding to switching to the next common task to be executed;

[0073] Get the current time corresponding to the completion of the periodic task and the new first time corresponding to the scheduled time when the next periodic task is triggered and the new second time when it is executed;

[0074] Determine a preset time according to the current time, the scanning time, and the new first time;

[0075] If the time interval between the preset time and the new second time is less than the second preset time interval, or the preset time reaches or exceeds the new second time, then wait for the new first time triggered by the next periodic task to arrive to execute the next periodic task, and prohibit the execution of the next ordinary task to be executed;

[0076] If the time interval between the preset time and the new second time is greater than or equal to the second preset time interval, and the preset time has not reached the new second time, the next common task to be executed is executed.

[0077] It should be noted that after the periodic task is executed, it switches to the ordinary task execution process. Combined with the above embodiment, the ordinary task is just completed before the periodic task is executed. When switching to the ordinary task execution process, it is necessary to switch to the next ordinary task for execution.

[0078] When processing the next common task, since the execution mechanism of the periodic task has been turned on, there will be the arrival of the next periodic task later. If the next common task is just beginning to be executed, and the next periodic task arrives, it will continue to switch to the next periodic task for execution, which will increase the switching computing resources caused by the switching mechanism. Therefore, this embodiment needs to predict in advance whether the next common task can be executed before the next periodic task is triggered.

[0079] Get the scan time corresponding to the switch to the next common task to be executed. The scan time here and the regular task scheduling process involve the scan time required to scan whether there are other tasks with higher priority during the normal task switching process, and the scan time to scan whether there are other tasks executing operations in the stack space corresponding to the normal task when there are no other tasks with higher priority. It is the same as the regular task scheduling process, that is, the same as the scheduling process of the real-time operating system.

[0080] The current moment corresponding to the time when the periodic task is completed and the timing moment corresponding to the new first moment of the next periodic task triggering and the new second moment of execution are obtained, and the current moment, the scanning time and the new first moment are added and processed to obtain the preset moment, that is, whether the sum of the time corresponding to the actual execution of the next ordinary task to be executed and the triggering moment of the next periodic task is expected to exceed the new second moment. If the time interval between the preset moment and the new second moment is less than the second preset time interval, and the preset moment reaches or exceeds the new second moment, it means that the next ordinary task to be executed cannot be processed in time, and the next periodic task is directly activated. Here, the judgment that the time interval between the preset moment and the new second moment is less than the second preset time interval includes the case where the preset moment is before the new second moment and the preset moment is after the new second moment. Therefore, in this embodiment, it is necessary to limit that when the preset moment reaches or exceeds the new second moment, or the time interval between the preset moment and the new second moment is less than the second preset time interval, it is necessary to wait for the new first moment triggered by the next periodic task to arrive to execute the next periodic task, and prohibit the execution of the next ordinary task to be executed.

[0081] When the time interval between the preset moment and the new second moment is greater than or equal to the second preset time interval, and the preset moment has not reached the new second moment, the case where the preset moment exceeds the new second moment is excluded here. The time interval between the preset moment and the new second moment is greater than or equal to the second preset time interval, indicating that the moment is far away from the moment when the next periodic task arrives to trigger, then the next ordinary task to be executed is executed.

[0082] Of course, this embodiment can also be applied to the scenario of switching to a normal task after the response task is completed, or switching to a normal task after the current normal task is completed, which can be set according to actual conditions.

[0083] This embodiment provides a comparison between a predicted preset moment and a new second moment based on the scanning time of the next ordinary task to be executed, so as to predict the corresponding time distance when the next periodic task arrives, avoid two switching processes when the time distance is short, and save the corresponding computing resources for switching.

[0084] In some embodiments, the first stack space and the third stack space for storing periodic tasks are located in the internal RAM space, and the number of stack spaces corresponding to each of the first stack space and the third stack space is one;

[0085] The second stack space is located in the external RAM space, and the number of stack spaces of the second stack space is at least one.

[0086] Specifically, in this embodiment, the RAM resources required for task scheduling are divided into three blocks, namely, the first stack space, the second stack space and the third stack space, wherein the first stack space and the third stack space are located in the internal RAM space, and the second stack space is located in the external RAM space.

[0087] The first stack space is used for the stack space of common tasks that are currently in the ready state (running). The second stack space is used to store the stack data of all common tasks. This part of the space can select the normal slower or even external RAM area. For example, the RAM space outside the external expansion RAM and the low 64k address of the C2000 series can make full use of RAM resources. The third stack space is used for periodic tasks and system schedulers. This part of the stack space selects the RAM space with a faster speed and can be addressed by the stack pointer. For example, the DCTM of the Cortex core and the low 64k RAM space of the C2000 series DSP. To improve the running efficiency of real-time tasks.

[0088] It should be noted that the number of stack spaces corresponding to the first stack space and the third stack space in this embodiment is one each. The resources of the internal RAM space are limited, so during the execution of the periodic task and the ordinary task, only the stack space of each is exclusively occupied. After the ordinary task is executed, the stack data of the ordinary task is transferred to the second stack space by DMA to call the next ordinary task to be executed in the second stack space.

[0089] The stack space memory management method provided in this embodiment is different from the conventional task scheduling method in which each task has its own exclusive stack space. The stack space is all in the internal RAM space and occupies more internal RAM space resources. In this embodiment, most of the stack space is transferred to the external RAM space to make full use of RAM resources.

[0090] In some embodiments, when the activation mechanism of the periodic task corresponding to the timing moment is triggered, it also includes:

[0091] If the ordinary task has not been completed, after the periodic task is completed, the new first moment of triggering the next periodic task corresponding to the timing moment is obtained;

[0092] Get the current time;

[0093] If the time interval between the new first moment and the current moment is less than the first preset time interval, the new first moment triggered by the next periodic task is waited for to arrive, and the execution of the ordinary task is prohibited.

[0094] Specifically, when the ordinary task is not completed, it is necessary to switch to the currently executed task to continue executing the ordinary task after the periodic task is completed. However, it is necessary to check whether the new first moment triggered by the next periodic task is close to the time of the current moment. If it is close, it is necessary to prohibit the execution of the currently executed task and wait for the next periodic task to arrive and directly trigger the next periodic task. That is, if the time interval between the new first moment and the current moment is less than the first preset time interval, wait for the new first moment triggered by the next periodic task to arrive and prohibit the execution of the ordinary task.

[0095] The new first moment provided in this embodiment based on the triggering of the next periodic task can predict the corresponding time distance when the next periodic task arrives through the comparison between the current moment and the new first moment, so as to avoid two switching processes when the time distance is short, thereby saving the computing resources corresponding to the switching.

[0096] In some embodiments, it also includes:

[0097] If the timing time corresponding to the periodic task interval does not exist, and the currently executed task is a normal task, and the request of the response task is triggered, the response task will be executed, and the normal task will continue to be executed after the response task is completed;

[0098] Alternatively, if the currently executed task is a periodic task and the request of the response task is triggered, the response task is executed, and the periodic task is continued to be executed after the response task is completed.

[0099] Specifically, if the timing corresponding to the periodic task interval does not exist, that is, the timing is invalid, there is no periodic task in the entire task scheduling process, only ordinary tasks and response tasks exist. Then it is necessary to directly execute the response task when the request of the response task is triggered, and continue to execute the ordinary task after waiting for the response task to be executed.

[0100] Alternatively, if the timing moment is valid during the entire task scheduling process, then all three types of tasks exist. If the currently executed task is a periodic task, the response task is triggered at this time, and the response task is executed immediately. After waiting for the response task to be completed, the periodic task can continue to be executed.

[0101] This embodiment provides different scenarios of currently executed tasks corresponding to when a response task is triggered, giving priority to the execution of the response task, and returning to the currently executed task after the execution is completed to continue the execution, thereby ensuring the smooth execution of the response task.

[0102] In some embodiments, during the execution of the response task, the stack space corresponding to the currently executed task is occupied.

[0103] Specifically, since the response task has a small amount of data, the space resources of the corresponding stack space are also small. In order to save internal RAM space, the response task in this embodiment occupies the stack space corresponding to the current execution task during execution.

[0104] During the execution of the response task in this embodiment, the stack space corresponding to the currently executed task is occupied, the resources of the internal RAM space are improved, the RAM resources are fully utilized, and the comprehensive and efficient utilization of resources with different performances is achieved.

[0105] Figure 2 A flowchart of another task scheduling method provided by an embodiment of the present invention is shown in FIG. Figure 2 As shown, the steps include:

[0106] S21: Switch to the normal task stack context and release CPU control;

[0107] S22: When the response task corresponding to the real-time task stack is triggered, switch to the real-time task stack for execution;

[0108] S23: After the response task is executed, if the timer corresponding to the periodic task reaches the first moment, an interrupt is triggered to perform context switching;

[0109] S24: Start DMA to transfer the data in the common task stack to the stack storage space;

[0110] S25: Determine the next task to be run;

[0111] S26: Start DMA and transfer the next task to be run in the stack storage space to the common task stack;

[0112] S27: Determine whether it is necessary to wait for the periodic task or whether the periodic task has been completed; if so, proceed to step S28; if not, return to step S27;

[0113] S28: Determine whether the DMA transfer is completed; if so, return to step S21, if not, return to step S28.

[0114] Specifically, steps S24 to S26 correspond to the current ordinary task in the ordinary task stack having just been executed and switching to the execution of the periodic task, while waiting for the actual execution of the periodic task, starting DMA to execute the stack data storage of the current ordinary task in parallel and searching for the next ordinary task.

[0115] The scheduling method adopted is as follows:

[0116] 1. Since the activation time of the periodic task is predictable (for the convenience of description, it is set as T0), and the time of system context switching can also be measured, the system context switching time + the execution time of the DMA code startup + the timing margin are collectively recorded as Tsw).

[0117] 2. Ordinary tasks can be scheduled in a similar way to general RTOS. The task period of the periodic task in (1) is used as the unit time of system scheduling.

[0118] 3. The hardware timer triggers an interrupt at time T0-Tsw to switch context and switch the system to the context of the real-time task stack. During the code execution in the real-time task stack, the periodic task is activated by the interrupt and executed in the interrupt.

[0119] 4. After the interrupt corresponding to the response task is triggered, it runs directly in the interrupt. The response task has no independent task stack space.

[0120] 5. During the normal task running process, if task scheduling occurs due to task blocking, an interrupt will be triggered to switch the context, and the CPU running context will be switched to the real-time task stack space. After executing the task scheduling process, the context will be switched back to the normal task stack context to switch to the next task to be run.

[0121] 6. The time for executing the task scheduling in point 5 is recorded as Tsh. Then T0-Tsw-Tsh starts and the system enters the protection state. The system will be set to "need to wait for periodic tasks" and wait until the periodic tasks are completed before continuing to run until switching to the normal task stack context.

[0122] In the embedded system of the inverter, according to the characteristics of DSP chips, limited resources are used, and the characteristics and requirements of periodic control tasks, real-time response tasks to external events, and ordinary tasks are efficiently scheduled. It can not only ensure the real-time performance of periodic control tasks and real-time response tasks to external events, but also realize task scheduling, inter-thread synchronization, inter-thread communication, memory management and other functions for ordinary tasks like RTOS.

[0123] A method for efficient scheduling based on the characteristics of control tasks, response tasks and common tasks. It can ensure the real-time performance of tasks while saving system resources. For control tasks and response tasks with high real-time requirements, independent stack space is used to ensure the real-time performance of the system. For systems with limited resources, tasks with low real-time requirements use time-division multiplexing to share the same stack space, and task stack data can be temporarily stored in other memories with lower requirements to efficiently utilize the system RAM space. The operating environment of periodic tasks is close to the foreground and background mode, and can be compatible with mature control algorithms written in traditional foreground and background systems. For common tasks, the code writing method is the same as RTOS, which can significantly reduce the complexity of development and make it easier to debug and verify complex functions. Improve the cohesion of code design and make it easy to reuse.

[0124] Verified on the GD27 platform, the GD27 platform uses TI's TMS320F2800137 chip and has 36kW of RAM.

[0125] The resource allocation plan is as follows: the M0 RAM block (1kW size) is used as the real-time task stack space; the M1 RAM block (1kW size) is used as the normal task stack space; LS0 (8kW size) is used as the code running space and normal task stack space; LS1 (8kW size) is used as the global variable and system heap space.

[0126] The RTOS interrupt of the C2000 kernel is used as the context switching interrupt, and CPU timer 2 is used to generate the system beat. After actual testing on the GD27 platform, the response time of the real-time task is within 2uS, and the execution cycle of the motor control algorithm is related to the setting of the carrier frequency. When the carrier frequency is 8kHz, the execution cycle of the control algorithm is the shortest, which is 125uS. CPU timer 1 is used as the timer for real-time task switching. The real-time task switching is triggered 2uS before the execution of the motor control algorithm, so that the real-time task response delay can be minimized.

[0127] The functions of the current software of GD27 are transplanted into this system, and the motor control algorithm is used as a real-time task. The functional part is uniformly divided into two common tasks with a cycle of 500uS and a cycle of 2mS. The codes such as overcurrent protection and current limiting action are respectively used as response tasks, which are triggered by interrupts such as overcurrent protection signal and current limiting protection signal.

[0128] Most of the software functions tested on the single-board platform are normal, only the dual CPU communication part with the display part needs to adjust the timing appropriately according to the communication protocol, split into a response task and a normal task, and the PWM waveform in the VF operation mode is normal. This verifies the feasibility of the task scheduling scheme of the present invention.

[0129] The above describes in detail various embodiments corresponding to the task scheduling processing method. On this basis, the present invention also discloses a task scheduling processing system corresponding to the above method. Figure 3 FIG. 1 is a structural diagram of a task scheduling processing system provided by an embodiment of the present invention. Figure 3 As shown, the task scheduling processing system includes:

[0130] An acquisition module 11 is used to acquire the timing time corresponding to the periodic task interval and the currently executed task;

[0131] The first execution module 12 is used to trigger the activation mechanism of the periodic task corresponding to the timing moment if the timing moment reaches the first moment used to characterize the triggering of the periodic task and the currently executed task is a common task, and execute the periodic task when the timing moment reaches the second moment used to characterize the execution of the periodic task; wherein the time interval between the last periodic task triggering moment corresponding to the timing moment and the current periodic task triggering moment is greater than the time interval between the first moment and the second moment, and the activation mechanism of the periodic task includes a scanning mechanism of the stack space corresponding to the periodic task;

[0132] The second execution module 13 is used to return to the step of activating the periodic task corresponding to the triggering timing moment after waiting for the response task to be executed if the timing moment reaches the first moment, the current execution task is a common task and the request of the response task is triggered, so as to execute the periodic task; wherein the urgency of the response task, the periodic task and the common task decreases in sequence.

[0133] Since the embodiments of the system part correspond to the above embodiments, please refer to the description of the embodiments of the method part for the embodiments of the system part, and will not be repeated here.

[0134] For an introduction to a task scheduling processing system provided by the present invention, please refer to the above method embodiment, and the present invention will not be repeated here. It has the same beneficial effects as the above task scheduling processing method.

[0135] Figure 4 A structural diagram of a task scheduling processing device provided by an embodiment of the present invention, such as Figure 4 As shown, the device comprises:

[0136] A memory 21, used for storing computer programs;

[0137] The processor 22 is used to implement the steps of the task scheduling processing method when executing a computer program.

[0138] Among them, the processor 22 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 22 can be implemented in at least one hardware form of DSP, Field-Programmable Gate Array (FPGA), and Programmable Logic Array (PLA). The processor 22 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU; the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 22 may be integrated with a graphics processing unit (GPU), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 22 may also include an artificial intelligence (AI) processor, which is used to process computing operations related to machine learning.

[0139] The memory 21 may include one or more computer-readable storage media, which may be non-transitory. The memory 21 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory 21 is at least used to store the following computer program 211, wherein, after the computer program is loaded and executed by the processor 22, it can implement the relevant steps of the task scheduling processing method disclosed in any of the aforementioned embodiments. In addition, the resources stored in the memory 21 may also include an operating system 212 and data 213, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system 212 may include Windows, Unix, Linux, etc. The data 213 may include, but is not limited to, data involved in the task scheduling processing method, etc.

[0140] In some embodiments, the task scheduling processing device may further include a display screen 23 , an input / output interface 24 , a communication interface 25 , a power supply 26 , and a communication bus 27 .

[0141] Those skilled in the art can understand that Figure 4 The structure shown in the figure does not constitute a limitation on the task scheduling processing device, and may include more or fewer components than those shown in the figure.

[0142] The processor 22 implements the task scheduling processing method provided by any of the above embodiments by calling the instructions stored in the memory 21 .

[0143] For an introduction to a task scheduling processing device provided by the present invention, please refer to the above method embodiment, and the present invention will not be repeated here. It has the same beneficial effects as the above task scheduling processing method.

[0144] Furthermore, the present invention also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by the processor 22, the steps of the task scheduling processing method as described above are implemented.

[0145] It is understandable that if the method in the above embodiment is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium to execute all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), RAM, disk or optical disk and other media that can store program code.

[0146] For an introduction to a computer-readable storage medium provided by the present invention, please refer to the above method embodiment, which will not be described in detail herein. It has the same beneficial effects as the above task scheduling processing method.

[0147] The above is a detailed introduction to a task scheduling processing method, system, device and medium provided by the present invention. The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the embodiments can be referenced to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description. It should be pointed out that for ordinary technicians in this technical field, without departing from the principle of the present invention, several improvements and modifications can be made to the present invention, and these improvements and modifications also fall within the scope of protection of the present invention.

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

Claims

1. A task scheduling processing method, characterized in that: include: Get the timing time corresponding to the periodic task interval and the currently executed task; If the timing moment reaches the first moment used to characterize the triggering of the periodic task and the currently executed task is a common task, the activation mechanism of the periodic task corresponding to the timing moment is triggered, and when the timing moment reaches the second moment used to characterize the execution of the periodic task, the periodic task is executed; wherein the time interval between the last periodic task triggering moment corresponding to the timing moment and the current periodic task triggering moment is greater than the time interval between the first moment and the second moment, and the activation mechanism of the periodic task includes a scanning mechanism of the stack space corresponding to the periodic task; If the timing moment reaches the first moment, the currently executed task is a common task and the request of the response task is triggered, then after waiting for the response task to be executed, return to the step of activating the periodic task corresponding to the timing moment to trigger the periodic task, so as to execute the periodic task; wherein the urgency of the response task, the periodic task and the common task decreases in sequence.

2. The task scheduling processing method according to claim 1, characterized in that: When the activation mechanism of the periodic task corresponding to the timing moment is triggered, it also includes: Obtain a first stack space for storing a common task currently being executed; If the common task is finished, the DMA mode is started to transfer the stack data of the common task currently executed and stored in the first stack space to the second stack space, and the next common task to be executed is determined in the second stack space; When the timing reaches the second moment, the DMA mode is started to transfer the next common task to be executed in the second stack space to the first stack space, so as to wait for the completion of the periodic task and switch to the context of the first stack space to execute the next common task to be executed.

3. The task scheduling processing method according to claim 2, characterized in that: The first stack space and the third stack space for storing periodic tasks are located in the internal RAM space, and the first stack space and the third stack space each correspond to one stack space; The second stack space is located in the external RAM space, and the number of stack spaces of the second stack space is at least one.

4. The task scheduling processing method according to claim 1, characterized in that: When the activation mechanism of the periodic task corresponding to the timing moment is triggered, it also includes: If the ordinary task has not been completed, after the periodic task is completed, a new first moment of triggering the next periodic task corresponding to the timing moment is obtained; Get the current time; If the time interval between the new first moment and the current moment is less than the first preset time interval, the new first moment triggered by the next periodic task is waited for to arrive, and the execution of the ordinary task is prohibited.

5. The task scheduling processing method according to claim 2, characterized in that: Waiting for the execution of the periodic task to be completed, switching to the context of the first stack space to execute the next common task to be executed, including: Get the scan time corresponding to switching to the next common task to be executed; Obtain the current time corresponding to when the periodic task is completed and the new first time and the new second time of triggering the next periodic task corresponding to the timing time; Determine a preset time according to the current time, the scanning time and the new first time; If the time interval between the preset moment and the new second moment is less than the second preset time interval, or the preset moment reaches or exceeds the new second moment, then wait for the new first moment triggered by the next periodic task to arrive to execute the next periodic task, and prohibit the execution of the next ordinary task to be executed; If the time interval between the preset time and the new second time is greater than or equal to the second preset time interval, and the preset time has not reached the new second time, the next common task to be executed is executed.

6. The task scheduling processing method according to claim 1, characterized in that: Also includes: If the timing moment corresponding to the periodic task interval does not exist, when the currently executed task is a common task, and when the request of the response task is triggered, the response task is executed, and the common task is continued to be executed after the response task is completed; Alternatively, if the currently executed task is a periodic task and the request of the response task is triggered, the response task is executed, and the execution of the periodic task is continued after the response task is completed.

7. The task scheduling processing method according to claim 6, characterized in that: The response task occupies the stack space corresponding to the currently executed task during the execution process.

8. A task scheduling processing system, characterized in that: include: An acquisition module is used to obtain the timing time corresponding to the periodic task interval and the currently executed task; A first execution module is used to trigger the activation mechanism of the periodic task corresponding to the timing moment if the timing moment reaches the first moment used to characterize the triggering of the periodic task and the currently executed task is a common task, and execute the periodic task when the timing moment reaches the second moment used to characterize the execution of the periodic task; wherein the time interval between the last periodic task triggering moment corresponding to the timing moment and the current periodic task triggering moment is greater than the time interval between the first moment and the second moment, and the activation mechanism of the periodic task includes a scanning mechanism of the stack space corresponding to the periodic task; The second execution module is used to, if the timing moment reaches the first moment, the currently executed task is a common task and the request of the response task is triggered, then wait for the response task to be executed and then return to the step of activating the periodic task corresponding to the triggering timing moment to execute the periodic task; wherein the urgency of the response task, the periodic task and the common task decreases in sequence.

9. A task scheduling processing device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the task scheduling method according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the task scheduling processing method according to any one of claims 1 to 7 are implemented.