Monitoring method, monitoring device and electronic equipment of single-chip microcomputer
By configuring a watchdog program in each core of the microcontroller and monitoring its operation status in real time according to the task scheduling, the problem of poor monitoring effect of a single watchdog program in the prior art is solved, and effective monitoring and normal operation of all task scheduling are realized.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- WEICHAI POWER CO LTD
- Filing Date
- 2023-01-03
- Publication Date
- 2026-05-26
AI Technical Summary
In existing technologies, a dog-feeding program can only monitor one task scheduler, resulting in poor monitoring performance. Furthermore, when the program gets stuck in an infinite loop, the dog-feeding program cannot detect anomalies in a timely manner.
Configure a watchdog timer in each core of the microcontroller, and determine the watchdog timer interval and predetermined number of times by obtaining the real-time scheduling status and scheduling interval of the task scheduler, and execute or stop the watchdog timer to monitor the running status of all task schedulers.
It enables timely monitoring of all task scheduling in the microcontroller, preventing task scheduling from going awry or getting stuck in an infinite loop, thus ensuring the normal operation of the microcontroller and the effectiveness of monitoring.
Smart Images

Figure CN116225841B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of microcontroller technology, and more specifically, to a microcontroller monitoring method, monitoring device, and electronic device. Background Technology
[0002] The main way to prevent programs from crashing or getting stuck in an infinite loop is to add a watchdog timer. The watchdog timer is fed within a specified time. If the program crashes or gets stuck in an infinite loop, the watchdog feeding routine will fail to run, thus resetting the microcontroller. For example, the maximum watchdog feeding time can be set to 30ms, and the watchdog feeding routine can be added to a 10ms task scheduler. This means the routine runs every 10ms to feed the watchdog. If the program crashes or gets stuck in an infinite loop elsewhere, the watchdog feeding routine will fail to run, thus resetting the microcontroller.
[0003] In existing technologies, a single dog-feeding program can only monitor one task scheduler, resulting in poor monitoring performance.
[0004] Furthermore, if the program gets stuck in an infinite loop, and the watchdog program happens to be inside this infinite loop, the watchdog will continue to feed the dog normally, but the program will malfunction, making it impossible to monitor program malfunctions. Summary of the Invention
[0005] The main purpose of this application is to provide a microcontroller monitoring method, monitoring device, and electronic device to at least solve the problem in the prior art that a dog-feeding program can only monitor one task scheduler, resulting in poor monitoring effect.
[0006] To achieve the above objectives, according to one aspect of this application, a monitoring method for a microcontroller is provided. The microcontroller includes multiple kernels, each kernel including multiple task schedulers and a watchdog timer. The method includes: a configuration step, configuring a watchdog timer program in a target task scheduler, wherein the target task scheduler is a task scheduler in each kernel; an acquisition step, acquiring the real-time scheduling status of each task scheduler and corresponding first durations, wherein the real-time scheduling status includes the cumulative number of scheduling attempts, and the first duration is the scheduling interval duration of the task scheduler; a determination step, determining corresponding first predetermined number of times based on a second duration, the cumulative number of scheduling attempts, and the corresponding first durations, wherein the second duration is the watchdog timer interval duration of the watchdog timer program, and the first predetermined number of times includes at least one of the following: the cumulative number of scheduling attempts within the second duration, and the cumulative number of scheduling attempts corresponding to the case where the execution count of the watchdog timer program reaches the second predetermined number of times; and an execution step, executing a predetermined operation based on the first predetermined number of times, wherein the predetermined operation includes: executing the watchdog timer program and stopping the execution of the watchdog timer program.
[0007] Optionally, the determining step includes: if the first duration is less than the second duration, determining the first predetermined number of times is the cumulative number of scheduling within the second duration; if the first duration is greater than or equal to the corresponding second duration, determining the first predetermined number of times is the cumulative number of scheduling corresponding to the execution count reaching the second predetermined number of times, wherein the second predetermined number of times is an integer greater than a predetermined ratio, and the predetermined ratio is the ratio of the first duration to the second duration.
[0008] Optionally, the real-time scheduling situation further includes the scheduling time. Determining the first predetermined number of times as the cumulative number of scheduling within the second duration includes: determining a first scheduling number and a second scheduling number based on the scheduling time and the cumulative number of scheduling, wherein the first scheduling number is the cumulative number of scheduling before the i-th dog feeding program, and the second scheduling number is the cumulative number of scheduling after the (i-1)-th dog feeding program, where i ≥ 2 and i is an integer; subtracting the first scheduling number from the second scheduling number to obtain the first predetermined number of times.
[0009] Optionally, the second predetermined number is the minimum value among integers greater than the predetermined ratio.
[0010] Optionally, the execution steps include: executing the dog-feeding program when the first predetermined number of times is greater than 0; and stopping the execution of the dog-feeding program when the first predetermined number of times is equal to 0, so that the second duration reaches the maximum dog-feeding time, so as to perform a reset operation on the microcontroller.
[0011] Optionally, the configuration steps include: adding a watchdog timer to each of the target task schedulers; initializing each of the watchdog timers and configuring a maximum watchdog timer, wherein the maximum watchdog timer is greater than the second duration.
[0012] Optionally, executing the dog feeding procedure includes: sequentially executing the acquisition step, the determination step, and the execution step at least once, until the dog feeding procedure is stopped.
[0013] Optionally, the target task scheduling is the task scheduling with a scheduling interval equal to the second duration.
[0014] According to another aspect of this application, a monitoring device for a microcontroller is provided. The microcontroller includes multiple cores, each core including multiple task schedulers and a watchdog timer. The device includes: a configuration unit for configuring a watchdog timer program in a target task scheduler, wherein the target task scheduler is a task scheduler in each core; an acquisition unit for acquiring the real-time scheduling status of each task scheduler and corresponding first durations, wherein the real-time scheduling status includes the cumulative number of scheduling attempts, and the first duration is the scheduling interval duration of the task scheduler; a determination unit for determining the corresponding first predetermined number of times based on a second duration, the cumulative number of scheduling attempts, and the corresponding first durations, wherein the second duration is the watchdog timer interval duration of the watchdog timer program, and the first predetermined number of times includes at least one of the following: the cumulative number of scheduling attempts within the second duration, or the cumulative number of scheduling attempts when the execution count of the watchdog timer program reaches the second predetermined number of times; and an execution unit for executing a predetermined operation based on the first predetermined number of times, wherein the predetermined operation includes executing the watchdog timer program and stopping the execution of the watchdog timer program.
[0015] According to another aspect of this application, an electronic device is also provided, comprising: a microcontroller; a monitoring device for the microcontroller, comprising one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs comprising methods for performing any one of the methods described.
[0016] The technical solution of this application first performs a configuration step, configuring a watchdog timer in a task scheduler (referred to as the target task scheduler) within each kernel; then, by performing an acquisition step, it acquires the real-time scheduling status of each task scheduler, including the cumulative number of scheduling attempts and the scheduling interval duration; next, it performs a determination step, determining a first predetermined number of times for each task scheduler based on the interval duration of the watchdog timer, the cumulative number of each scheduler, and each first duration, wherein the first predetermined number of times includes the cumulative number of scheduling attempts within the second duration, and / or the cumulative number of scheduling attempts corresponding to the case where the execution count of the watchdog timer reaches a second predetermined number of times; finally, it runs an execution step, executing and stopping the watchdog timer based on the first predetermined number of times. This achieves the effect of monitoring the running status of all task schedulers in a kernel through a watchdog timer, ensuring the monitoring effect of all task schedulers in the microcontroller. This application can promptly monitor any task scheduler's runaway problem or deadlock problem, ensuring the normal operation of the microcontroller and effectively solving the problem that in the prior art, a watchdog timer can only monitor one task scheduler, resulting in poor monitoring effect. Attached Figure Description
[0017] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:
[0018] Figure 1 A hardware structure block diagram of a mobile terminal implementing a microcontroller monitoring method according to an embodiment of this application is shown.
[0019] Figure 2 A flowchart illustrating a microcontroller monitoring method according to an embodiment of this application is shown.
[0020] Figure 3 A flowchart illustrating a microcontroller monitoring process according to an embodiment of this application is shown.
[0021] Figure 4 A structural block diagram of a microcontroller monitoring device provided according to an embodiment of this application is shown.
[0022] The accompanying drawings include the following reference numerals:
[0023] 102. Processor; 104. Memory; 106. Transmission device; 108. Input / output device. Detailed Implementation
[0024] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0025] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0026] It should be noted that the terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be used interchangeably where appropriate for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0027] As described in the background section, in the prior art, a dog-feeding program can only monitor one task scheduler, resulting in poor monitoring performance. To solve the aforementioned problem, embodiments of this application provide a microcontroller monitoring method, monitoring device, and electronic device.
[0028] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.
[0029] The methods and embodiments provided in this application can be executed on a mobile terminal, computer terminal, or similar computing device. Taking running on a mobile terminal as an example, Figure 1 This is a hardware structure block diagram of a mobile terminal for a microcontroller-based monitoring method according to an embodiment of the present invention. (See diagram below.) Figure 1 As shown, a mobile terminal may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data are also shown. The mobile terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the mobile terminal. For example, the mobile terminal may also include components that are larger than... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0030] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the device information display method in this embodiment of the invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, thereby implementing the method described. The memory 104 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the mobile terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. The transmission device 106 is used to receive or send data via a network. Specific examples of such networks may include wireless networks provided by the mobile terminal's communication provider. In one example, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to communicate with the Internet. In one example, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0031] This embodiment provides a monitoring method for a microcontroller running on a mobile terminal, computer terminal, or similar computing device. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0032] Figure 2 This is a flowchart of a microcontroller monitoring method according to an embodiment of this application. The microcontroller includes multiple cores, and each core includes multiple task schedulers and a watchdog timer, such as... Figure 2 As shown, the method includes the following steps:
[0033] Step S201, configuration step, configure the dog-feeding program in the target task scheduler, wherein the target task scheduler is a task scheduler in each kernel;
[0034] The embodiment describes a dog-feeding program configured in a task scheduler within each kernel, so that the dog-feeding program is executed when the task scheduler is executed.
[0035] Specifically, the task scheduling refers to a timed task, that is, a task that runs at regular intervals. The watchdog timer is actually a counter. After an initial value is set, the watchdog timer starts counting after the target task scheduling begins execution. When it reaches a reset value (also called the maximum watchdog feeding time), the microcontroller is reset. Therefore, it needs to be fed periodically; that is, the initial count value must be rewritten before each time the reset value is reached. The watchdog feeding program is a program that clears the watchdog timer's count value to its initial value within a certain time range. Generally, the initial value is 0, and the watchdog feeding program clears the watchdog timer every second time interval. Of course, the initial value is not limited to 0 and can also be other values.
[0036] In one specific embodiment of this application, when the target task scheduler is run, the dog-feeding program located in the target task scheduler is executed. Therefore, the target task scheduler is a task scheduler with a scheduling interval equal to the second duration. For example, if the scheduling interval of the target task scheduler is 10ms, the dog-feeding program is executed every 10ms to feed the dog, thereby effectively monitoring the scheduling status of the target task scheduler. When the target program runs for too long or is not run for a long time, the dog-feeding program cannot be executed normally, thereby resetting the microcontroller.
[0037] Since a microcontroller includes multiple kernels, the scheduling intervals for task scheduling in different kernels may be the same or different. Therefore, the dog-feeding intervals for the dog-feeding program in different kernels may also be the same or different.
[0038] In one exemplary embodiment, step S201 can be implemented as follows:
[0039] Step S2011: Add a dog-feeding program to each of the target task schedulers;
[0040] Step S2012: Initialize each of the watchdog timers and configure the maximum watchdog feeding time, wherein the maximum watchdog feeding time is greater than the second duration.
[0041] This allows for further monitoring of the target task scheduling in each kernel. If the target task scheduling runs abnormally, the watchdog timer cannot be executed. When the watchdog timer count reaches the maximum watchdog time, the microcontroller is reset to prevent the abnormal target task scheduling from continuing to run, thus further ensuring better monitoring of each task scheduling.
[0042] Specifically, initializing each watchdog timer involves setting its count value to an initial value. Those skilled in the art can flexibly set the initial value and the maximum feeding time according to actual circumstances.
[0043] Step S202, obtaining the real-time scheduling status of each task and the corresponding first duration, wherein the real-time scheduling status includes the cumulative number of schedulings and the first duration is the scheduling interval duration of the task scheduling.
[0044] Specifically, the cumulative scheduling count is the cumulative number of times each task has been scheduled, which is the cumulative number of times a task has been run. The scheduling interval is the duration between two task runs. The correspondence between real-time scheduling status and the first duration refers to the real-time scheduling status of the same task and the first duration.
[0045] Step S203, Determine step, determine each first predetermined number of times according to the second duration, each cumulative number of scheduling and each corresponding first duration, the second duration is the dog feeding interval duration of the dog feeding program, and the first predetermined number of times includes at least one of the following: the cumulative number of scheduling within the second duration, the cumulative number of scheduling when the execution number of the dog feeding program reaches the second predetermined number of times;
[0046] Specifically, the dog-feeding interval is the scheduling interval of the target task, which is the time from the last execution of the dog-feeding program to the current execution of the dog-feeding program.
[0047] In practical applications, step S203 is executed when the microcontroller program is running and the scheduling of various tasks begins.
[0048] In practical applications, some task scheduling intervals in the kernel are shorter than the target task scheduling interval, while others have scheduling intervals longer than or equal to the target task scheduling interval. To further ensure that this application can meet the monitoring requirements of task scheduling with different scheduling intervals, in one optional solution, step S203 specifically includes:
[0049] Step S2031: If the first duration is less than the second duration, determine the first predetermined number of times as the cumulative number of scheduling times within the second duration;
[0050] Step S2032: When the first duration is greater than or equal to the corresponding second duration, determine the first predetermined number of times as the cumulative number of scheduling when the number of executions reaches the second predetermined number of times, wherein the second predetermined number of times is an integer greater than a predetermined ratio, and the predetermined ratio is the ratio of the first duration to the second duration.
[0051] In the embodiment, based on the relationship between the task scheduling interval (i.e., the first duration) and the dog-feeding interval (i.e., the second duration), task scheduling is divided into two categories. One category consists of task scheduling with a duration shorter than the corresponding second duration. Under normal operating conditions, these task schedulings will run at least once within one dog-feeding interval, and their corresponding first predetermined number of executions is the cumulative number of schedulings within the dog-feeding interval. The other category consists of task scheduling with a duration greater than or equal to the corresponding second duration. Under normal operating conditions, these task schedulings require multiple dog-feeding operations before they run once, and their corresponding first predetermined number of executions is the cumulative number of schedulings when the number of dog-feeding operations reaches the second predetermined number of executions.
[0052] For example, if the first duration is 30ms and the second duration is 10ms, the predetermined ratio is 30 / 10 = 3. Therefore, the second predetermined number of times will be an integer value greater than 3, such as 4, 5, 6, etc. As another example, if the first duration is 25ms and the second duration is 10ms, the predetermined ratio is 25 / 10 = 2.5. Therefore, the second predetermined number of times will be an integer value greater than 2.5, such as 3, 4, 5, etc.
[0053] Specifically, the real-time scheduling situation also includes the scheduling time. Determining the first predetermined number as the cumulative scheduling number within the second duration includes: determining a first scheduling number and a second scheduling number based on the scheduling time and the cumulative scheduling number, where the first scheduling number is the cumulative scheduling number before the i-th time the dog-feeding procedure is performed, and the second scheduling number is the cumulative scheduling number after the (i-1)-th time the dog-feeding procedure is performed, where i ≥ 2 and i is an integer; subtracting the first scheduling number from the second scheduling number yields the first predetermined number. This further ensures a relatively simple, easy, and accurate determination of the first predetermined number of task scheduling when the first duration is greater than or equal to the second duration.
[0054] To further ensure the accuracy of the predetermined operation performed according to the first predetermined number of times, and thus to further ensure more accurate monitoring of the microcontroller's operation, in this embodiment, the second predetermined number of times is the minimum integer value greater than the predetermined ratio. That is, when the first duration is 30ms and the second duration is 10ms, the predetermined ratio is 30 / 10 = 3, and the second predetermined number of times is 4. For example, when the first duration is 25ms and the second duration is 10ms, the predetermined ratio is 25 / 10 = 2.5, and the second predetermined number of times is 3.
[0055] Step S204: Execute the following steps: Perform a predetermined operation according to the first predetermined number of times. The predetermined operation includes: executing the dog feeding program and stopping the execution of the dog feeding program.
[0056] Further, step S204 includes: executing the watchdog timer program when the first predetermined number of times is greater than 0; and stopping the watchdog timer program when the first predetermined number of times is equal to 0, so that the second duration reaches the maximum watchdog timer duration, thereby performing a reset operation on the microcontroller. When the first predetermined number of times is greater than 0, it indicates that each task scheduling is running normally, and there is no need to reset the microcontroller, so the watchdog timer program continues. However, when the first predetermined number of times is equal to 0, it indicates that these task scheduling times are too long or have not run for a long time, indicating that the task scheduling is abnormal. In this case, the watchdog timer program is stopped, and a reset operation is performed on the microcontroller to correct the abnormal task scheduling.
[0057] In other words, if the first duration is less than the second duration, and the cumulative number of scheduling events within the second duration is greater than 0, it indicates that task scheduling with a scheduling interval shorter than the dog-feeding interval has been executed at least once within a dog-feeding interval. This means that these task scheduling events are running normally, without any abnormal issues such as excessive running time or prolonged inactivity, and the dog-feeding program is executed at this time. Conversely, if the first duration is less than the second duration, and the cumulative number of scheduling events within the second duration is equal to 0, it indicates that task scheduling with a scheduling interval shorter than the dog-feeding interval has not actually been executed within a dog-feeding interval, even though these task scheduling events should have been executed at least once. This indicates that the task scheduling is abnormal at this time, possibly due to excessive running time or prolonged inactivity, and the dog-feeding is stopped at this time, causing the microcontroller to reset, ensuring better monitoring results. For task scheduling with a scheduling interval shorter than the dog-feeding interval, this application only continues dog-feeding after determining that its first predetermined number of times is greater than 0, avoiding the problem of task scheduling getting stuck in an infinite loop while the dog-feeding program happens to be in the infinite loop, failing to monitor task scheduling abnormalities, and resulting in poor monitoring results.
[0058] For task scheduling with a scheduling interval greater than or equal to the dog-feeding interval, when the first duration is greater than or equal to the corresponding second duration, and the number of times the dog-feeding program is executed reaches the second predetermined number, it indicates that the duration of periodically executing the dog-feeding program a second predetermined number of times exceeds the scheduling interval of the task. If the cumulative number of scheduling occurrences is greater than 0, it means that the task scheduling has actually been executed at least once within that duration. At this point, it can be determined that these task scheduling operations are running normally, without any abnormal issues such as excessive running time or prolonged inactivity, and the dog-feeding program can be executed. Conversely, when the first duration is greater than or equal to the corresponding second duration, and the number of times the dog-feeding program is executed reaches the second predetermined number, these task scheduling operations should have been executed at least once. If the cumulative number of scheduling occurrences is equal to 0, it means that the task scheduling has not actually been executed within that duration. At this point, it can be determined that these task scheduling operations are abnormal, with abnormal issues such as excessive running time or prolonged inactivity. In this case, the dog-feeding is stopped, causing the microcontroller to reset, ensuring better monitoring results. For task scheduling with a scheduling interval greater than or equal to the dog-feeding interval, this application only continues to feed the dog when it is determined that the first predetermined number of times is greater than 0. This avoids the problem that the task scheduling will fall into an infinite loop and the dog-feeding program happens to be in the infinite loop, making it impossible to monitor the task scheduling anomaly and resulting in poor monitoring effect.
[0059] In another alternative approach, the dog-feeding procedure includes: sequentially executing the acquisition step, the determination step, and the execution step at least once, until the dog-feeding procedure is stopped. This process achieves continuous monitoring of each core and task of the microcontroller, further ensuring good monitoring performance.
[0060] In addition, if the first predetermined number of times is greater than 0, after executing the dog feeding program, the method further includes: exiting the dog feeding program and executing other programs.
[0061] In practical applications, when the target task begins execution but before the dog-feeding interval has elapsed and the dog-feeding procedure has been executed, this application can first sequentially execute the determining steps and execution steps for task scheduling with a first duration shorter than the second duration. If the task scheduling with a first duration shorter than the second duration satisfies a first predetermined number of times greater than 0, the dog-feeding procedure is executed. Then, for task scheduling with a first duration greater than or equal to the second duration, the determining steps and execution steps are sequentially executed. If the task scheduling with a first duration greater than or equal to the second duration satisfies a first predetermined number of times greater than 0, the dog-feeding procedure is executed. This ensures that the dog-feeding procedure is only executed after all task scheduling in the program has finished, avoiding the situation where the program enters an infinite loop while the dog-feeding procedure happens to be within the infinite loop, thereby further achieving effective monitoring of all tasks in the microcontroller.
[0062] In the above embodiment, a configuration step is first performed to configure a watchdog timer in a task scheduler (called the target task scheduler) in each kernel. Then, an acquisition step is performed to obtain the real-time scheduling status of each task scheduler, including the cumulative number of scheduling attempts and the scheduling interval duration (i.e., the first duration). Next, a determination step is performed to determine the first predetermined number of times for each task scheduler based on the interval duration of the watchdog timer (i.e., the second duration), the cumulative number of execution attempts for each scheduler, and the first duration. The first predetermined number of times includes the cumulative number of execution attempts within the second duration, and / or the cumulative number of execution attempts corresponding to the second predetermined number of execution attempts of the watchdog timer. Finally, an execution step is performed to execute and stop the watchdog timer based on the first predetermined number of execution attempts. This achieves the effect of monitoring the running status of all task schedulers in a kernel using a watchdog timer, ensuring effective monitoring of all task schedulers in the microcontroller. This application can promptly monitor any task scheduler's runaway or infinite loop problems, ensuring the normal operation of the microcontroller and effectively solving the problem that in the prior art, a watchdog timer can only monitor one task scheduler, resulting in poor monitoring performance.
[0063] To enable those skilled in the art to better understand the technical solution of this application, the implementation process of the microcontroller monitoring method of this application will be described in detail below with reference to specific embodiments.
[0064] This embodiment relates to a specific microcontroller monitoring method, such as... Figure 3 As shown, it includes the following steps:
[0065] Step S1: The cumulative scheduling count of each task scheduling in each kernel is monitored. For each execution of a task scheduling in a kernel, the corresponding cumulative scheduling count is incremented by 1.
[0066] Step S2: Initialize the watchdog timer, configure the maximum watchdog feeding time, and reset the microcontroller if the watchdog is not fed within the maximum watchdog feeding time;
[0067] Step S3: Select the 10ms task scheduler as the target task scheduler, and add a dog-feeding program to the 10ms task scheduler of each kernel. 10ms is the scheduling interval of this task scheduler.
[0068] Step S4: The program executes normally. When entering the dog-feeding procedure, it determines the cumulative number of times all task schedulers with intervals smaller than 10ms task scheduling have been executed. It checks if the difference between the current dog-feeding interval and the previous dog-feeding interval (i.e., the first predetermined number of times) is not zero. If any corresponding task scheduler has a count of 0, it indicates an abnormal loop, and the dog-feeding procedure is terminated. If none of the counts are zero, the next step is performed. For example, if the difference between the current dog-feeding interval and the previous dog-feeding interval for the 1ms task scheduling is 0, it indicates that the 10ms task scheduling has been executed at least once. However, the 1ms task scheduling has not been executed at all during this period, indicating an abnormal operation of the 1ms task scheduling.
[0069] Step S5: Determine whether the number of times the dog feeding program has been executed has reached the second predetermined number. If the second predetermined number has not been reached, continue feeding the dog; otherwise, proceed to step S6.
[0070] Step S6: When the number of times the dog-feeding program is executed reaches the second predetermined number, determine whether the difference between the cumulative number of times the corresponding task scheduler is executed before the current dog-feeding and after the previous dog-feeding is 0. If it is not 0, proceed to the next step; otherwise, exit the dog-feeding program. For example, if there are 20, 50, and 100ms task schedulers that are longer than 10ms, then every time the dog-feeding program is entered 3 times, determine whether the difference between the cumulative number of times the 20ms task scheduler is executed before the current dog-feeding and after the previous dog-feeding is 0. If it is 0, it means that the 10ms scheduler has been executed 3 times while the 20ms scheduler has not been executed. At this time, the program abnormally exits the dog-feeding program and does not feed the dog in this loop. If it is not 0, proceed to the next step. Similarly, every time the dog-feeding program is entered 6 times, determine the cumulative number of times the 50ms task scheduler is executed, and every time the dog-feeding program is entered 11 times, determine the cumulative number of times the 100ms task scheduler is executed.
[0071] Step S7: Once all the above conditions are met, you can feed the dog, then exit the dog feeding program and execute other programs.
[0072] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.
[0073] This application also provides a microcontroller monitoring device. It should be noted that the microcontroller monitoring device of this application can be used to execute the microcontroller monitoring method provided in this application. This device is used to implement the embodiments and preferred embodiments described herein; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0074] The following describes the microcontroller monitoring device provided in the embodiments of this application.
[0075] Figure 4 This is a schematic diagram of a microcontroller monitoring device according to an embodiment of this application. The microcontroller includes multiple cores, and each core includes multiple task schedulers and a watchdog timer, such as... Figure 4 As shown, the device includes:
[0076] Configuration unit 10 is used for configuring steps, configuring a dog-feeding program in the target task scheduler, wherein the target task scheduler is a task scheduler in each kernel;
[0077] The embodiment describes a dog-feeding program configured in a task scheduler within each kernel, so that the dog-feeding program is executed when the task scheduler is executed.
[0078] Specifically, the task scheduling refers to a timed task, that is, a task that runs at regular intervals. The watchdog timer is actually a counter. After an initial value is set, the watchdog timer starts counting after the target task scheduling begins execution. When it reaches a reset value (also called the maximum watchdog feeding time), the microcontroller is reset. Therefore, it needs to be fed periodically; that is, the initial count value must be rewritten before each time the reset value is reached. The watchdog feeding program is a program that clears the watchdog timer's count value to its initial value within a certain time range. Generally, the initial value is 0, and the watchdog feeding program clears the watchdog timer every second time interval. Of course, the initial value is not limited to 0 and can also be other values.
[0079] In one specific embodiment of this application, when the target task scheduler is run, the dog-feeding program located in the target task scheduler is executed. Therefore, the target task scheduler is a task scheduler with a scheduling interval equal to the second duration. For example, if the scheduling interval of the target task scheduler is 10ms, the dog-feeding program is executed every 10ms to feed the dog, thereby effectively monitoring the scheduling status of the target task scheduler. When the target program runs for too long or is not run for a long time, the dog-feeding program cannot be executed normally, thereby resetting the microcontroller.
[0080] Since a microcontroller includes multiple kernels, the scheduling intervals for task scheduling in different kernels may be the same or different. Therefore, the dog-feeding intervals for the dog-feeding program in different kernels may also be the same or different.
[0081] In one exemplary embodiment, the configuration unit specifically includes:
[0082] Add a module to add a dog-feeding program for each of the target task schedules;
[0083] An initialization module is used to initialize each of the watchdog timers and configure the maximum watchdog feeding time, wherein the maximum watchdog feeding time is greater than the second duration.
[0084] This allows for further monitoring of the target task scheduling in each kernel. If the target task scheduling runs abnormally, the watchdog timer cannot be executed. When the watchdog timer count reaches the maximum watchdog time, the microcontroller is reset to prevent the abnormal target task scheduling from continuing to run, thus further ensuring better monitoring of each task scheduling.
[0085] Specifically, initializing each watchdog timer involves setting its count value to an initial value. Those skilled in the art can flexibly set the initial value and the maximum feeding time according to actual circumstances.
[0086] The acquisition unit 20 is used to acquire the real-time scheduling status of each task and the corresponding first duration. The real-time scheduling status includes the cumulative number of schedulings, and the first duration is the scheduling interval duration of the task scheduling.
[0087] Specifically, the cumulative scheduling count is the cumulative number of times each task has been scheduled, which is the cumulative number of times a task has been run. The scheduling interval is the duration between two task runs. The correspondence between real-time scheduling status and the first duration refers to the real-time scheduling status of the same task and the first duration.
[0088] The determining unit 30 is used to determine the steps, and to determine the corresponding first predetermined number of times based on the second duration, the cumulative number of times of each scheduling and the corresponding first duration. The second duration is the dog feeding interval duration of the dog feeding program. The first predetermined number of times includes at least one of the following: the cumulative number of times of scheduling within the second duration, and the cumulative number of times of scheduling when the number of times the dog feeding program is executed reaches the second predetermined number of times.
[0089] Specifically, the dog-feeding interval is the scheduling interval of the target task, which is the time from the last execution of the dog-feeding program to the current execution of the dog-feeding program.
[0090] In practical applications, the determining unit is executed when the microcontroller program is running and the scheduling of various tasks begins.
[0091] In practical applications, some task scheduling intervals in the kernel are shorter than the target task scheduling interval, while others have scheduling intervals longer than or equal to the target task scheduling interval. To further ensure that this application can meet the monitoring requirements of task scheduling with different scheduling intervals, in one optional solution, the determining unit specifically includes:
[0092] The first determining module is configured to determine the first predetermined number of times as the cumulative number of scheduling times within the second time period when the first duration is less than the second duration.
[0093] The second determining module is used to determine the first predetermined number of times as the cumulative scheduling number when the execution number reaches the second predetermined number of times, provided that the first duration is greater than or equal to the corresponding second duration. The second predetermined number of times is an integer greater than a predetermined ratio, and the predetermined ratio is the ratio of the first duration to the second duration.
[0094] In the embodiment, based on the relationship between the task scheduling interval (i.e., the first duration) and the dog-feeding interval (i.e., the second duration), task scheduling is divided into two categories. One category consists of task scheduling with a duration shorter than the corresponding second duration. Under normal operating conditions, these task schedulings will run at least once within one dog-feeding interval, and their corresponding first predetermined number of executions is the cumulative number of schedulings within the dog-feeding interval. The other category consists of task scheduling with a duration greater than or equal to the corresponding second duration. Under normal operating conditions, these task schedulings require multiple dog-feeding operations before they run once, and their corresponding first predetermined number of executions is the cumulative number of schedulings when the number of dog-feeding operations reaches the second predetermined number of executions.
[0095] For example, if the first duration is 30ms and the second duration is 10ms, the predetermined ratio is 30 / 10 = 3. Therefore, the second predetermined number of times will be an integer value greater than 3, such as 4, 5, 6, etc. As another example, if the first duration is 25ms and the second duration is 10ms, the predetermined ratio is 25 / 10 = 2.5. Therefore, the second predetermined number of times will be an integer value greater than 2.5, such as 3, 4, 5, etc.
[0096] Specifically, the real-time scheduling situation also includes the scheduling time. The first determining module includes: a determining submodule, used to determine a first scheduling count and a second scheduling count based on the scheduling time and the cumulative scheduling count, wherein the first scheduling count is the cumulative scheduling count before the i-th time the dog-feeding program is performed, and the second scheduling count is the cumulative scheduling count after the (i-1)-th time the dog-feeding program is performed, where i ≥ 2 and i is an integer; and a subtraction submodule, used to subtract the first scheduling count from the second scheduling count to obtain the first predetermined count. This further ensures that the first predetermined count corresponding to task scheduling when the first duration is greater than or equal to the second duration can be determined relatively easily and accurately.
[0097] To further ensure the accuracy of the predetermined operation performed according to the first predetermined number of times, and thus to further ensure more accurate monitoring of the microcontroller's operation, in this embodiment, the second predetermined number of times is the minimum integer value greater than the predetermined ratio. That is, when the first duration is 30ms and the second duration is 10ms, the predetermined ratio is 30 / 10 = 3, and the second predetermined number of times is 4. For example, when the first duration is 25ms and the second duration is 10ms, the predetermined ratio is 25 / 10 = 2.5, and the second predetermined number of times is 3.
[0098] The execution unit 40 is used to execute steps and perform predetermined operations according to the first predetermined number of times. The predetermined operations include: executing the dog feeding program and stopping the execution of the dog feeding program.
[0099] Further, the execution unit includes: an execution module, used to execute the dog-feeding program when the first predetermined number of times is greater than 0; and a stop module, used to stop executing the dog-feeding program when the first predetermined number of times is equal to 0, so that the second duration reaches the maximum dog-feeding time, thereby performing a reset operation on the microcontroller. When the first predetermined number of times is greater than 0, it indicates that each task scheduling is running normally, and there is no need to reset the microcontroller, so the dog-feeding program continues. However, when the first predetermined number of times is equal to 0, it indicates that these task scheduling runs for too long or has not run for a long time, indicating that the task scheduling is abnormal. In this case, the execution of the dog-feeding program is stopped, and a reset operation is performed on the microcontroller to correct the abnormal task scheduling.
[0100] In other words, if the first duration is less than the second duration, and the cumulative number of scheduling events within the second duration is greater than 0, it indicates that task scheduling with a scheduling interval shorter than the dog-feeding interval has been executed at least once within a dog-feeding interval. This means that these task scheduling events are running normally, without any abnormal issues such as excessive running time or prolonged inactivity, and the dog-feeding program is executed at this time. Conversely, if the first duration is less than the second duration, and the cumulative number of scheduling events within the second duration is equal to 0, it indicates that task scheduling with a scheduling interval shorter than the dog-feeding interval has not actually been executed within a dog-feeding interval, even though these task scheduling events should have been executed at least once. This indicates that the task scheduling is abnormal at this time, possibly due to excessive running time or prolonged inactivity, and the dog-feeding is stopped at this time, causing the microcontroller to reset, ensuring better monitoring results. For task scheduling with a scheduling interval shorter than the dog-feeding interval, this application only continues dog-feeding after determining that its first predetermined number of times is greater than 0, avoiding the problem of task scheduling getting stuck in an infinite loop while the dog-feeding program happens to be in the infinite loop, failing to monitor task scheduling abnormalities, and resulting in poor monitoring results.
[0101] For task scheduling with a scheduling interval greater than or equal to the dog-feeding interval, when the first duration is greater than or equal to the corresponding second duration, and the number of times the dog-feeding program is executed reaches the second predetermined number, it indicates that the duration of periodically executing the dog-feeding program a second predetermined number of times exceeds the scheduling interval of the task. If the cumulative number of scheduling occurrences is greater than 0, it means that the task scheduling has actually been executed at least once within that duration. At this point, it can be determined that these task scheduling operations are running normally, without any abnormal issues such as excessive running time or prolonged inactivity, and the dog-feeding program can be executed. Conversely, when the first duration is greater than or equal to the corresponding second duration, and the number of times the dog-feeding program is executed reaches the second predetermined number, these task scheduling operations should have been executed at least once. If the cumulative number of scheduling occurrences is equal to 0, it means that the task scheduling has not actually been executed within that duration. At this point, it can be determined that these task scheduling operations are abnormal, with abnormal issues such as excessive running time or prolonged inactivity. In this case, the dog-feeding is stopped, causing the microcontroller to reset, ensuring better monitoring results. For task scheduling with a scheduling interval greater than or equal to the dog-feeding interval, this application only continues to feed the dog when it is determined that the first predetermined number of times is greater than 0. This avoids the problem that the task scheduling will fall into an infinite loop and the dog-feeding program happens to be in the infinite loop, making it impossible to monitor the task scheduling anomaly and resulting in poor monitoring effect.
[0102] In another optional embodiment, the execution module includes an execution submodule, configured to sequentially execute the acquisition step, the determination step, and the execution step at least once, until the dog-feeding program is stopped. This process achieves continuous monitoring of each core and task of the microcontroller, further ensuring good monitoring performance.
[0103] In addition, the device further includes an exit unit, which is used to exit the dog feeding program and execute other programs after executing the dog feeding program when the first predetermined number of times is greater than 0.
[0104] In practical applications, when the target task begins execution but before the dog-feeding interval has elapsed and the dog-feeding procedure has been executed, this application can first sequentially execute the determining steps and execution steps for task scheduling with a first duration shorter than the second duration. If the task scheduling with a first duration shorter than the second duration satisfies a first predetermined number of times greater than 0, the dog-feeding procedure is executed. Then, for task scheduling with a first duration greater than or equal to the second duration, the determining steps and execution steps are sequentially executed. If the task scheduling with a first duration greater than or equal to the second duration satisfies a first predetermined number of times greater than 0, the dog-feeding procedure is executed. This ensures that the dog-feeding procedure is only executed after all task scheduling in the program has finished, avoiding the situation where the program enters an infinite loop while the dog-feeding procedure happens to be within the infinite loop, thereby further achieving effective monitoring of all tasks in the microcontroller.
[0105] In this embodiment, a watchdog timer is configured in a task scheduler (called the target task scheduler) within each kernel by a configuration unit; a data acquisition unit acquires the real-time scheduling status of each task scheduler, including the cumulative number of scheduling attempts and the scheduling interval duration (i.e., the first duration); a determination unit determines the first predetermined number of times for each task scheduler based on the interval duration of the watchdog timer (i.e., the second duration), the cumulative number of scheduling attempts, and the first duration, where the first predetermined number of times includes the cumulative number of scheduling attempts within the second duration, and / or the cumulative number of scheduling attempts corresponding to the second predetermined number of times the watchdog timer is executed; and an execution unit executes and stops the watchdog timer based on the first predetermined number of times. This achieves the effect of monitoring the running status of all task schedulers in a kernel using a watchdog timer, ensuring the monitoring effect of all task schedulers in the microcontroller. This application can promptly monitor any task scheduler's runaway problem or deadlock problem, ensuring the normal operation of the microcontroller and effectively solving the problem that in the prior art, a watchdog timer can only monitor one task scheduler, resulting in poor monitoring effect.
[0106] The microcontroller monitoring device includes a processor and a memory. The configuration unit, acquisition unit, determination unit, and execution unit are all stored as program units in the memory. The processor executes the program units stored in the memory to achieve the corresponding functions. All modules reside in the same processor; alternatively, the modules may be located in different processors in any combination.
[0107] The processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured. By adjusting kernel parameters, the problem of poor monitoring performance caused by a single watchdog program monitoring only one task scheduler in existing technologies can be addressed.
[0108] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0109] This invention provides a computer-readable storage medium including a stored program, wherein the program, when running, controls the device where the computer-readable storage medium is located to execute the microcontroller's monitoring method.
[0110] Specifically, the microcontroller includes multiple cores, each core including multiple task schedulers and a watchdog timer, and the monitoring method of the microcontroller includes:
[0111] Step S201, configuration step, configure the dog-feeding program in the target task scheduler, wherein the target task scheduler is a task scheduler in each kernel;
[0112] Specifically, the task scheduling refers to a timed task, that is, a task that runs at regular intervals. The watchdog timer is actually a counter. After an initial value is set, the watchdog timer starts counting after the target task scheduling begins execution. When it reaches a reset value (also called the maximum watchdog feeding time), the microcontroller is reset. Therefore, it needs to be fed periodically; that is, the initial count value must be rewritten before each time the reset value is reached. The watchdog feeding program is a program that clears the watchdog timer's count value to its initial value within a certain time range. Generally, the initial value is 0, and the watchdog feeding program clears the watchdog timer every second time interval. Of course, the initial value is not limited to 0 and can also be other values.
[0113] Step S202, obtaining the real-time scheduling status of each task and the corresponding first duration, wherein the real-time scheduling status includes the cumulative number of schedulings and the first duration is the scheduling interval duration of the task scheduling.
[0114] Specifically, the cumulative scheduling count is the cumulative number of times each task has been scheduled, which is the cumulative number of times a task has been run. The scheduling interval is the duration between two task runs. The correspondence between real-time scheduling status and the first duration refers to the real-time scheduling status of the same task and the first duration.
[0115] Step S203, Determine step, determine each first predetermined number of times according to the second duration, each cumulative number of scheduling and each corresponding first duration, the second duration is the dog feeding interval duration of the dog feeding program, and the first predetermined number of times includes at least one of the following: the cumulative number of scheduling within the second duration, the cumulative number of scheduling when the execution number of the dog feeding program reaches the second predetermined number of times;
[0116] Specifically, the dog-feeding interval is the scheduling interval of the target task, which is the time from the last execution of the dog-feeding program to the current execution of the dog-feeding program.
[0117] Step S204: Execute the following steps: Perform a predetermined operation according to the first predetermined number of times. The predetermined operation includes: executing the dog feeding program and stopping the execution of the dog feeding program.
[0118] Optionally, the determining step includes: if the first duration is less than the second duration, determining the first predetermined number of times is the cumulative number of scheduling within the second duration; if the first duration is greater than or equal to the corresponding second duration, determining the first predetermined number of times is the cumulative number of scheduling corresponding to the execution count reaching the second predetermined number of times, wherein the second predetermined number of times is an integer greater than a predetermined ratio, and the predetermined ratio is the ratio of the first duration to the second duration.
[0119] Optionally, the real-time scheduling situation further includes the scheduling time. Determining the first predetermined number of times as the cumulative number of scheduling within the second duration includes: determining a first scheduling number and a second scheduling number based on the scheduling time and the cumulative number of scheduling, wherein the first scheduling number is the cumulative number of scheduling before the i-th dog feeding program, and the second scheduling number is the cumulative number of scheduling after the (i-1)-th dog feeding program, where i ≥ 2 and i is an integer; subtracting the first scheduling number from the second scheduling number to obtain the first predetermined number of times.
[0120] Optionally, the second predetermined number is the minimum value among integers greater than the predetermined ratio.
[0121] Optionally, the execution steps include: executing the dog-feeding program when the first predetermined number of times is greater than 0; and stopping the execution of the dog-feeding program when the first predetermined number of times is equal to 0, so that the second duration reaches the maximum dog-feeding time, so as to perform a reset operation on the microcontroller.
[0122] Optionally, the configuration steps include: adding a watchdog timer to each of the target task schedulers; initializing each of the watchdog timers and configuring a maximum watchdog timer, wherein the maximum watchdog timer is greater than the second duration.
[0123] Optionally, executing the dog feeding procedure includes: sequentially executing the acquisition step, the determination step, and the execution step at least once, until the dog feeding procedure is stopped.
[0124] Optionally, the target task scheduling is the task scheduling with a scheduling interval equal to the second duration.
[0125] This invention provides a processor for running a program, wherein the program executes a monitoring method for the microcontroller during runtime.
[0126] Specifically, the microcontroller includes multiple cores, each core including multiple task schedulers and a watchdog timer, and the monitoring method of the microcontroller includes:
[0127] Step S201, configuration step, configure the dog-feeding program in the target task scheduler, wherein the target task scheduler is a task scheduler in each kernel;
[0128] Specifically, the task scheduling refers to a timed task, that is, a task that runs at regular intervals. The watchdog timer is actually a counter. After an initial value is set, the watchdog timer starts counting after the target task scheduling begins execution. When it reaches a reset value (also called the maximum watchdog feeding time), the microcontroller is reset. Therefore, it needs to be fed periodically; that is, the initial count value must be rewritten before each time the reset value is reached. The watchdog feeding program is a program that clears the watchdog timer's count value to its initial value within a certain time range. Generally, the initial value is 0, and the watchdog feeding program clears the watchdog timer every second time interval. Of course, the initial value is not limited to 0 and can also be other values.
[0129] Step S202, obtaining the real-time scheduling status of each task and the corresponding first duration, wherein the real-time scheduling status includes the cumulative number of schedulings and the first duration is the scheduling interval duration of the task scheduling.
[0130] Specifically, the cumulative scheduling count is the cumulative number of times each task has been scheduled, which is the cumulative number of times a task has been run. The scheduling interval is the duration between two task runs. The correspondence between real-time scheduling status and the first duration refers to the real-time scheduling status of the same task and the first duration.
[0131] Step S203, Determine step, determine each first predetermined number of times according to the second duration, each cumulative number of scheduling and each corresponding first duration, the second duration is the dog feeding interval duration of the dog feeding program, and the first predetermined number of times includes at least one of the following: the cumulative number of scheduling within the second duration, the cumulative number of scheduling when the execution number of the dog feeding program reaches the second predetermined number of times;
[0132] Specifically, the dog-feeding interval is the scheduling interval of the target task, which is the time from the last execution of the dog-feeding program to the current execution of the dog-feeding program.
[0133] Step S204: Execute the following steps: Perform a predetermined operation according to the first predetermined number of times. The predetermined operation includes: executing the dog feeding program and stopping the execution of the dog feeding program.
[0134] Optionally, the determining step includes: if the first duration is less than the second duration, determining the first predetermined number of times is the cumulative number of scheduling within the second duration; if the first duration is greater than or equal to the corresponding second duration, determining the first predetermined number of times is the cumulative number of scheduling corresponding to the execution count reaching the second predetermined number of times, wherein the second predetermined number of times is an integer greater than a predetermined ratio, and the predetermined ratio is the ratio of the first duration to the second duration.
[0135] Optionally, the real-time scheduling situation further includes the scheduling time. Determining the first predetermined number of times as the cumulative number of scheduling within the second duration includes: determining a first scheduling number and a second scheduling number based on the scheduling time and the cumulative number of scheduling, wherein the first scheduling number is the cumulative number of scheduling before the i-th dog feeding program, and the second scheduling number is the cumulative number of scheduling after the (i-1)-th dog feeding program, where i ≥ 2 and i is an integer; subtracting the first scheduling number from the second scheduling number to obtain the first predetermined number of times.
[0136] Optionally, the second predetermined number is the minimum value among integers greater than the predetermined ratio.
[0137] Optionally, the execution steps include: executing the dog-feeding program when the first predetermined number of times is greater than 0; and stopping the execution of the dog-feeding program when the first predetermined number of times is equal to 0, so that the second duration reaches the maximum dog-feeding time, so as to perform a reset operation on the microcontroller.
[0138] Optionally, the configuration steps include: adding a watchdog timer to each of the target task schedulers; initializing each of the watchdog timers and configuring a maximum watchdog timer, wherein the maximum watchdog timer is greater than the second duration.
[0139] Optionally, executing the dog feeding procedure includes: sequentially executing the acquisition step, the determination step, and the execution step at least once, until the dog feeding procedure is stopped.
[0140] Optionally, the target task scheduling is the task scheduling with a scheduling interval equal to the second duration.
[0141] This invention provides an electronic device, which includes a microcontroller and a monitoring device for the microcontroller. The monitoring device includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs at least the following steps:
[0142] Step S201, configuration step, configure the dog-feeding program in the target task scheduler, wherein the target task scheduler is a task scheduler in each kernel;
[0143] Step S202, obtaining the real-time scheduling status of each task and the corresponding first duration, wherein the real-time scheduling status includes the cumulative number of schedulings and the first duration is the scheduling interval duration of the task scheduling.
[0144] Step S203, Determine step, determine each first predetermined number of times according to the second duration, each cumulative number of scheduling and each corresponding first duration, the second duration is the dog feeding interval duration of the dog feeding program, and the first predetermined number of times includes at least one of the following: the cumulative number of scheduling within the second duration, the cumulative number of scheduling when the execution number of the dog feeding program reaches the second predetermined number of times;
[0145] Step S204: Execute the following steps: Perform a predetermined operation according to the first predetermined number of times. The predetermined operation includes: executing the dog feeding program and stopping the execution of the dog feeding program.
[0146] Specifically, the monitoring device of the microcontroller is built into the microcontroller.
[0147] The devices mentioned in this article can be servers, PCs, tablets, mobile phones, etc.
[0148] Optionally, the determining step includes: if the first duration is less than the second duration, determining the first predetermined number of times is the cumulative number of scheduling within the second duration; if the first duration is greater than or equal to the corresponding second duration, determining the first predetermined number of times is the cumulative number of scheduling corresponding to the execution count reaching the second predetermined number of times, wherein the second predetermined number of times is an integer greater than a predetermined ratio, and the predetermined ratio is the ratio of the first duration to the second duration.
[0149] Optionally, the real-time scheduling situation further includes the scheduling time. Determining the first predetermined number of times as the cumulative number of scheduling within the second duration includes: determining a first scheduling number and a second scheduling number based on the scheduling time and the cumulative number of scheduling, wherein the first scheduling number is the cumulative number of scheduling before the i-th dog feeding program, and the second scheduling number is the cumulative number of scheduling after the (i-1)-th dog feeding program, where i ≥ 2 and i is an integer; subtracting the first scheduling number from the second scheduling number to obtain the first predetermined number of times.
[0150] Optionally, the second predetermined number is the minimum value among integers greater than the predetermined ratio.
[0151] Optionally, the execution steps include: executing the dog-feeding program when the first predetermined number of times is greater than 0; and stopping the execution of the dog-feeding program when the first predetermined number of times is equal to 0, so that the second duration reaches the maximum dog-feeding time, so as to perform a reset operation on the microcontroller.
[0152] Optionally, the configuration steps include: adding a watchdog timer to each of the target task schedulers; initializing each of the watchdog timers and configuring a maximum watchdog timer, wherein the maximum watchdog timer is greater than the second duration.
[0153] Optionally, executing the dog feeding procedure includes: sequentially executing the acquisition step, the determination step, and the execution step at least once, until the dog feeding procedure is stopped.
[0154] Optionally, the target task scheduling is the task scheduling with a scheduling interval equal to the second duration.
[0155] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program having at least the following method steps:
[0156] Step S201, configuration step, configure the dog-feeding program in the target task scheduler, wherein the target task scheduler is a task scheduler in each kernel;
[0157] Step S202, obtaining the real-time scheduling status of each task and the corresponding first duration, wherein the real-time scheduling status includes the cumulative number of schedulings and the first duration is the scheduling interval duration of the task scheduling.
[0158] Step S203, Determine step, determine each first predetermined number of times according to the second duration, each cumulative number of scheduling and each corresponding first duration, the second duration is the dog feeding interval duration of the dog feeding program, and the first predetermined number of times includes at least one of the following: the cumulative number of scheduling within the second duration, the cumulative number of scheduling when the execution number of the dog feeding program reaches the second predetermined number of times;
[0159] Step S204: Execute the following steps: Perform a predetermined operation according to the first predetermined number of times. The predetermined operation includes: executing the dog feeding program and stopping the execution of the dog feeding program.
[0160] Optionally, the determining step includes: if the first duration is less than the second duration, determining the first predetermined number of times is the cumulative number of scheduling within the second duration; if the first duration is greater than or equal to the corresponding second duration, determining the first predetermined number of times is the cumulative number of scheduling corresponding to the execution count reaching the second predetermined number of times, wherein the second predetermined number of times is an integer greater than a predetermined ratio, and the predetermined ratio is the ratio of the first duration to the second duration.
[0161] Optionally, the real-time scheduling situation further includes the scheduling time. Determining the first predetermined number of times as the cumulative number of scheduling within the second duration includes: determining a first scheduling number and a second scheduling number based on the scheduling time and the cumulative number of scheduling, wherein the first scheduling number is the cumulative number of scheduling before the i-th dog feeding program, and the second scheduling number is the cumulative number of scheduling after the (i-1)-th dog feeding program, where i ≥ 2 and i is an integer; subtracting the first scheduling number from the second scheduling number to obtain the first predetermined number of times.
[0162] Optionally, the second predetermined number is the minimum value among integers greater than the predetermined ratio.
[0163] Optionally, the execution steps include: executing the dog-feeding program when the first predetermined number of times is greater than 0; and stopping the execution of the dog-feeding program when the first predetermined number of times is equal to 0, so that the second duration reaches the maximum dog-feeding time, so as to perform a reset operation on the microcontroller.
[0164] Optionally, the configuration steps include: adding a watchdog timer to each of the target task schedulers; initializing each of the watchdog timers and configuring a maximum watchdog timer, wherein the maximum watchdog timer is greater than the second duration.
[0165] Optionally, executing the dog feeding procedure includes: sequentially executing the acquisition step, the determination step, and the execution step at least once, until the dog feeding procedure is stopped.
[0166] Optionally, the target task scheduling is the task scheduling with a scheduling interval equal to the second duration.
[0167] It will be apparent to those skilled in the art that the modules or steps of the present invention can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. They can be implemented using device-executable program code, and thus can be stored in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those presented herein, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular hardware and software combination.
[0168] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0169] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0170] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0171] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0172] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0173] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0174] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0175] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0176] As can be seen from the above description, the embodiments described in this application achieve the following technical effects:
[0177] 1) The microcontroller monitoring method of this application first performs a configuration step, configuring a watchdog timer in a task scheduler (called the target task scheduler) in each kernel; then, by performing an acquisition step, it acquires the real-time scheduling status of each task scheduler, including the cumulative number of scheduling attempts and the scheduling interval duration (i.e., the first duration); then, it performs a determination step, determining the first predetermined number of times for each task scheduler based on the interval duration of the watchdog timer (i.e., the second duration), the cumulative number of times for each scheduler, and each first duration. The first predetermined number of times includes the cumulative number of times the scheduler is within the second duration, and / or the cumulative number of times the watchdog timer is executed when the number of times the watchdog timer is executed reaches the second predetermined number of times; finally, it runs an execution step, executing the watchdog timer and stopping the execution of the watchdog timer based on the first predetermined number of times. This achieves the effect of monitoring the running status of all task schedulers in a kernel through a watchdog timer, ensuring the monitoring effect of all task schedulers in the microcontroller. This application can monitor any task scheduler's runaway problem or dead loop problem in a timely manner, ensuring the normal operation of the microcontroller, and effectively solving the problem that in the prior art, a watchdog timer can only monitor one task scheduler, resulting in poor monitoring effect.
[0178] 2) The microcontroller monitoring device of this application configures a watchdog timer in a task scheduler (called the target task scheduler) in each kernel through a configuration unit; it acquires the real-time scheduling status of each task scheduler, including the cumulative number of scheduling attempts and the scheduling interval duration (i.e., the first duration), through an acquisition unit; it determines the first predetermined number of times for each task scheduler based on the interval duration of the watchdog timer (i.e., the second duration), the cumulative number of scheduling attempts, and the first duration, wherein the first predetermined number of times includes the cumulative number of scheduling attempts within the second duration, and / or the cumulative number of scheduling attempts corresponding to the case where the execution count of the watchdog timer reaches the second predetermined number of times; and it executes and stops the watchdog timer based on the first predetermined number of times, thereby achieving the effect of monitoring the running status of all task schedulers in a kernel through a watchdog timer, ensuring the monitoring effect of all task schedulers in the microcontroller. This application can monitor any task scheduler's runaway problem or deadlock problem in a timely manner, ensuring the normal operation of the microcontroller, and effectively solving the problem that in the prior art, a watchdog timer can only monitor one task scheduler, resulting in poor monitoring effect.
[0179] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A monitoring method for a microcontroller, wherein the microcontroller includes multiple cores, each core including multiple task schedulers and a watchdog timer, characterized in that, The method includes: The configuration steps involve configuring a dog-feeding program in the target task scheduler, wherein the target task scheduler is a task scheduler in each kernel; The acquisition step involves acquiring the real-time scheduling status of each task and the corresponding first duration, wherein the real-time scheduling status includes the cumulative number of scheduling attempts, and the first duration is the scheduling interval duration of the task scheduling. The determination step involves determining each first predetermined number of times based on the second duration, the cumulative number of times each scheduling is performed, and the corresponding first duration. The second duration is the dog feeding interval duration of the dog feeding program. The first predetermined number of times includes at least one of the following: the cumulative number of times scheduling is performed within the second duration, or the cumulative number of times scheduling is performed when the number of times the dog feeding program is executed reaches the second predetermined number of times. The execution steps involve performing a predetermined operation based on the first predetermined number of times, the predetermined operation including: executing the dog feeding program and stopping the execution of the dog feeding program; The determining step includes: If the first duration is less than the second duration, the first predetermined number of times is determined to be the cumulative number of scheduling times within the second duration; When the first duration is greater than or equal to the corresponding second duration, the first predetermined number is determined to be the cumulative scheduling number when the execution number reaches the second predetermined number, wherein the second predetermined number is an integer greater than a predetermined ratio, and the predetermined ratio is the ratio of the first duration to the second duration.
2. The method according to claim 1, characterized in that, The real-time scheduling situation also includes the scheduling time, and determining the first predetermined number of times as the cumulative number of scheduling times within the second time period includes: Based on the scheduling time and the cumulative number of scheduling, a first scheduling count and a second scheduling count are determined. The first scheduling count is the cumulative number of scheduling before the i-th dog feeding program, and the second scheduling count is the cumulative number of scheduling after the (i-1)-th dog feeding program, where i ≥ 2 and i is an integer. Subtract the first scheduling count from the second scheduling count to obtain the first predetermined count.
3. The method according to claim 1, characterized in that, The second predetermined number is the minimum value among integers greater than the predetermined ratio.
4. The method according to any one of claims 1 to 3, characterized in that, The execution steps include: If the first predetermined number of times is greater than 0, the dog feeding program is executed; If the first predetermined number of times is equal to 0, the dog feeding program is stopped, so that the second duration reaches the maximum dog feeding time, so as to perform a reset operation on the microcontroller.
5. The method according to claim 4, characterized in that, The configuration steps include: Add one of the aforementioned dog-feeding procedures to each of the target task schedulers; Initialize each of the watchdog timers and configure the maximum watchdog feeding time, which is greater than the second duration.
6. The method according to any one of claims 1 to 3, characterized in that, Executing the dog feeding procedure includes: The acquisition step, the determination step, and the execution step are executed at least once in sequence until the dog feeding program is stopped.
7. The method according to any one of claims 1 to 3, characterized in that, The target task scheduling is the task scheduling with a scheduling interval equal to the second duration.
8. A monitoring device for a microcontroller, the microcontroller comprising multiple cores, each core comprising multiple task schedulers and a watchdog timer, characterized in that, The device includes: A configuration unit is used to configure a dog-feeding program in a target task scheduler, wherein the target task scheduler is a task scheduler in each kernel. The acquisition unit is used to acquire the real-time scheduling status of each task and the corresponding first duration, wherein the real-time scheduling status includes the cumulative number of schedulings and the first duration is the scheduling interval duration of the task scheduling. A determining unit is used to determine steps, and to determine corresponding first predetermined times based on the second duration, the cumulative number of each scheduling and the corresponding first duration, wherein the second duration is the dog feeding interval duration of the dog feeding program, and the first predetermined times include at least one of the following: the cumulative number of scheduling within the second duration, and the cumulative number of scheduling when the number of executions of the dog feeding program reaches the second predetermined times; An execution unit is configured to perform steps, including executing a predetermined operation based on a first predetermined number of times. The predetermined operation includes: executing the dog-feeding program and stopping the dog-feeding program. The determining unit includes: The first determining module is configured to determine the first predetermined number of times as the cumulative number of scheduling times within the second time period when the first duration is less than the second duration. The second determining module is used to determine the first predetermined number of times as the cumulative scheduling number when the execution number reaches the second predetermined number of times, provided that the first duration is greater than or equal to the corresponding second duration. The second predetermined number of times is an integer greater than a predetermined ratio, and the predetermined ratio is the ratio of the first duration to the second duration.
9. An electronic device, characterized in that, include: Microcontroller; The microcontroller monitoring device includes one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs include methods for performing any one of claims 1 to 7.