A CAN signal sending method and system in an operating system-free environment
By calculating the target time slice and setting the timing benchmark in an operating system-free environment, and using decision variables to determine the CAN transmission task, the problems of resource consumption and transmission delay were solved, and high-precision transmission of CAN messages was achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- FORYOU GENERAL ELECTRONICS
- Filing Date
- 2022-04-19
- Publication Date
- 2026-05-19
AI Technical Summary
In an environment without an operating system, the excessive number of CAN message sending tasks leads to excessive resource consumption and task sending delays, and existing technologies cannot effectively guarantee the accuracy of the CAN message sending cycle.
By obtaining the minimum CAN signal transmission period and transmission period error, the target time slice time is calculated, and a timing reference is set according to the target time slice time. The decision variable and preset threshold are used to determine whether to execute the CAN transmission task, thereby realizing the scheduling compensation of the task.
It improves the accuracy of CAN task transmission cycle, reduces resource consumption, and ensures that CAN messages are sent in a timely manner within the allowable error range.
Smart Images

Figure CN114880087B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of task scheduling technology, and in particular to a CAN signal transmission method and system in an operating system-free environment. Background Technology
[0002] Based on the non-OS operating system MCU software, task execution is divided using time-slice scheduling, with a 1ms clock interrupt as the baseline. Time slices include 1ms, 4ms, 10ms, 20ms, and 100ms. Regular tasks are concentrated in the 10ms region.
[0003] Some CAN message transmissions have precise period requirements (for example, a CAN message transmitting a voltage signal, message ID 2c6, has a fixed transmission period of 100ms). The CAN message should be sent after 100ms, but because there are many other 10ms tasks that are not processed in time, the message is delayed (i.e., the 10ms time slice is usually inaccurate), which causes the CAN transmission period to change from 100ms to 115ms.
[0004] Because there are too many CAN messages, they will consume too many resources and compete with serial ports for resources, causing problems. Therefore, the CAN sending task cannot be placed in the interrupt. Summary of the Invention
[0005] This invention provides a CAN signal transmission method and system in an operating system-free environment, which solves the technical problems of resource consumption and task transmission delay caused by too many queued CAN transmission tasks in existing task scheduling.
[0006] To solve the above technical problems, the present invention provides a CAN signal transmission method in an operating system-free environment, comprising the following steps:
[0007] S1. Obtain the minimum CAN signal transmission period and transmission period error;
[0008] S2. Calculate the target time slice time based on the minimum CAN signal transmission period and the transmission period error, and then determine the target time slice task based on the target time slice time.
[0009] S3. Set the timing reference according to the target time slice time;
[0010] S4. Assign the CAN transmission task to the target time slice task, set a decision variable in the target time slice task, and determine whether to execute the task transmission based on the decision variable.
[0011] This basic scheme determines the target time-slice task based on the transmission cycle error and the minimum CAN signal transmission cycle in the system. It sets the timing reference according to the target time-slice time, and then executes the CAN transmission task according to the timing reference and the target time-slice task. By using the transmission cycle error to set the timing reference, scheduling compensation can be performed on the task scheduling within the range of the transmission cycle error, thereby effectively improving the accuracy of the CAN task transmission cycle.
[0012] In a further implementation, in step S2, the calculation formula for the target time slice time is as follows:
[0013]
[0014] Where t0 is the target time slice time, t min denoted as the minimum CAN signal transmission period, and k as the transmission period error.
[0015] In a further embodiment, step S3 includes the following steps:
[0016] S31. Set a first variable outside the target time slice task as a timing reference;
[0017] S32. Obtain the initial count value and assign it to the first variable;
[0018] S33. Set a timer according to the target time slice time, and periodically increment the count value of the first variable by 1.
[0019] In a further embodiment, step S4 includes the following steps:
[0020] S41. Assign the CAN transmission task to the target time slice task;
[0021] S42. Set decision variables in the target time slice task;
[0022] S43. Assign the decision variable according to the first variable;
[0023] S44. Determine whether the decision variable is less than a preset threshold; otherwise, execute the CAN transmission task.
[0024] In a further embodiment, step S4 further includes the step:
[0025] S40. Calculate the preset threshold based on the minimum CAN signal transmission period and the target time slice time, using the following formula:
[0026]
[0027] Where n is a preset threshold, t mint0 is the minimum CAN signal transmission period, and t0 is the target time slice time.
[0028] In a further embodiment, step S4 further includes the step:
[0029] S45. When it is determined that the decision variable is not less than the preset threshold, the initial count value is calculated based on the decision variable and the preset threshold, using the following formula:
[0030] m = Bn;
[0031] Where m is the initial count value, B is the decision variable, and n is the preset threshold.
[0032] This scheme calculates the initial count value of the first variable (timing reference) based on the decision variable and preset threshold, and performs targeted scheduling compensation for the queued CAN transmission tasks, completing the task transmission in a timely manner within the allowable transmission error, effectively reducing resource consumption.
[0033] The present invention also provides a CAN signal transmission system in an operating system-free environment, for implementing the above-mentioned CAN signal transmission method in an operating system-free environment, including a minimum period acquisition module, and a system error setting module, a task allocation module, a judgment module, a correction module, and a timing reference module connected in sequence; the minimum period acquisition module is connected to the task allocation module, and the timing reference module is connected to the judgment module;
[0034] The minimum period acquisition module is used to acquire the minimum CAN signal transmission period;
[0035] The system error setting module is used to set the system's allowed transmission cycle error;
[0036] The task allocation module is used to determine the target time slice task based on the minimum CAN signal transmission period and the transmission period error.
[0037] The timing reference module is used to set the timing reference according to the target time slice time;
[0038] The judgment module is used to determine whether to send the task based on the timing reference.
[0039] The correction module is used to correct the timing reference according to the timing reference.
[0040] In a further implementation, the target time slice time is calculated using the following formula:
[0041]
[0042] Where t0 is the target time slice time, t mindenoted as the minimum CAN signal transmission period, and k as the transmission period error. Attached Figure Description
[0043] Figure 1 This is a flowchart of a CAN signal transmission method in an operating system-free environment provided in Embodiment 1 of the present invention;
[0044] Figure 2 This is a system framework diagram of a CAN signal transmission system without an operating system provided in Embodiment 2 of the present invention. Detailed Implementation
[0045] The embodiments of the present invention are described in detail below with reference to the accompanying drawings. The embodiments are given for illustrative purposes only and should not be construed as limiting the present invention. The accompanying drawings are for reference and illustration only and do not constitute a limitation on the scope of patent protection of the present invention, because many changes can be made to the present invention without departing from the spirit and scope of the present invention.
[0046] Example 1
[0047] This invention provides a CAN signal transmission method in an operating system-free environment, such as... Figure 1 As shown, in this embodiment, steps S1 to S4 are included:
[0048] S1. Obtain the minimum CAN signal transmission period and transmission period error;
[0049] Specifically, obtaining the minimum CAN signal transmission period can be achieved by either obtaining a pre-set minimum CAN signal transmission period or by reading all CAN signal transmission periods from an external CAN database file and determining the minimum CAN signal transmission period from all CAN signal transmission periods.
[0050] S2. Calculate the target time slice time based on the minimum CAN signal transmission period and the transmission period error, and then determine the target time slice task based on the target time slice time.
[0051] The formula for calculating the target time slice is as follows:
[0052]
[0053] Where t0 is the target time slice time, t min denoted as the minimum CAN signal transmission period, and k as the transmission period error.
[0054] For example, when t min =10ms, when k=10, t0=10ms / 10=1ms.
[0055] S3. Set the timing reference according to the target time slice time, including steps S31 to S33:
[0056] S31. Set a first variable A outside the target time slice task as a timing reference;
[0057] S32. Obtain the initial count value and assign it to the first variable A;
[0058] S33. Set a timer according to the target time slice time, and periodically increment the count value of the first variable A by 1.
[0059] For example, if t0 = 1ms, then the count value of the first variable A increases by 1 every 1ms.
[0060] S4. Assign the CAN transmission task to the target time-slice task, set a decision variable in the target time-slice task, and determine whether to execute the task transmission based on the decision variable, including steps S40 to S45:
[0061] S40. Calculate the preset threshold based on the minimum CAN signal transmission period and the target time slice time. The calculation formula is as follows:
[0062]
[0063] Where n is a preset threshold, t min t0 is the minimum CAN signal transmission period, and t0 is the target time slice time.
[0064] For example, when t min =10ms, t0=1ms, then
[0065] S41. Assign the CAN transmission task to the target time-slice task;
[0066] S42. Set decision variable B in the target time slice task;
[0067] S43. Assign a value to variable B based on the first variable A;
[0068] S44. Determine whether the decision variable B is less than the preset threshold. If not, execute the CAN transmission task.
[0069] S45. When it is determined that the decision variable B is not less than the preset threshold, the initial count value is calculated based on the decision variable B and the preset threshold. The calculation formula is as follows:
[0070] m = Bn;
[0071] Where m is the initial count value (m≥0), B is the decision variable, and n is the preset threshold.
[0072] Specifically:
[0073] 1) When B = n, Bn is 0, so A starts timing from 0;
[0074] 2) When B is greater than n, Bn is not 0, so A starts timing from m.
[0075] This embodiment calculates the initial count value of the first variable A (timing reference) based on the decision variable B and the preset threshold, and performs targeted scheduling compensation for the queued CAN transmission tasks, completing the task transmission in a timely manner within the allowable transmission error, effectively reducing resource consumption.
[0076] In this embodiment of the invention, the target time slice task is determined by the transmission cycle error and the minimum CAN signal transmission cycle in the system. A timing reference is set according to the target time slice time, and then the CAN transmission task is executed according to the timing reference and the target time slice task. By using the transmission cycle error to set the timing reference, scheduling compensation can be performed on the task scheduling within the range of the transmission cycle error, thereby effectively improving the accuracy of the CAN task transmission cycle.
[0077] Example 2
[0078] The reference numerals in the accompanying drawings of this embodiment include: minimum period acquisition module 1, system error setting module 2, task allocation module 3, judgment module 4, correction module 5, and timing reference module 6.
[0079] This invention also provides a CAN signal transmission system without an operating system, see [link to relevant documentation]. Figure 2 It includes a minimum cycle acquisition module 1, and a system error setting module 2, a task allocation module 3, a judgment module 4, a correction module 5, and a timing reference module 6 connected in sequence; the minimum cycle acquisition module 1 is connected to the task allocation module 3, and the timing reference module 6 is connected to the judgment module 4.
[0080] Minimum cycle acquisition module 1 is used to acquire the minimum CAN signal transmission cycle;
[0081] System error setting module 2 is used to set the system's allowed transmission cycle error;
[0082] Task allocation module 3 is used to determine the target time slice task based on the minimum CAN signal transmission period and the transmission period error;
[0083] In this embodiment, the formula for calculating the target time slice time is as follows:
[0084]
[0085] Where t0 is the target time slice time, t min denoted as the minimum CAN signal transmission period, and k as the transmission period error.
[0086] Timing reference module 6 is used to set the timing reference according to the target time slice time;
[0087] In the timing reference module 6, a first variable A is set. Every t0ms, the count value of the first variable A is incremented by 1, which serves as the reference for the timing of the task cycle.
[0088] Module 4 is used to determine whether to send the task based on the timing reference.
[0089] In the target time slice task of timing reference module 6, a decision variable B is set. After receiving the first variable A transmitted by timing reference module 6, the count value of the first variable A is used to determine whether to send a CAN task. Specifically: when it is determined that... Then execute the CAN transmission task.
[0090] Correction module 5 is used to correct the timing reference based on the timing reference.
[0091] The sending system provided in this embodiment uses various modules to implement each step of the sending method, providing a hardware foundation for the sending method and facilitating its implementation.
[0092] The above embodiments are preferred embodiments of the present invention, but the embodiments of the present invention are not limited to the above embodiments. Any changes, modifications, substitutions, combinations, or simplifications made without departing from the spirit and principle of the present invention shall be considered equivalent substitutions and shall be included within the protection scope of the present invention.
Claims
1. A method for transmitting CAN signals in an operating system-free environment, characterized in that, Including the following steps: S1. Obtain the minimum CAN signal transmission period and transmission period error; S2. Calculate the target time slice time based on the minimum CAN signal transmission period and the transmission period error, and then determine the target time slice task based on the target time slice time. S3. Set the timing reference according to the target time slice time; S4. Assign the CAN transmission task to the target time slice task, set a decision variable in the target time slice task, and determine whether to execute the task transmission based on the decision variable; Step S3 includes the following steps: S31. Set a first variable outside the target time slice task as a timing reference; S32. Obtain the initial count value and assign it to the first variable; S33. Set a timer according to the target time slice time, and periodically increment the count value of the first variable by 1; Step S4 includes the following steps: S41. Assign the CAN transmission task to the target time slice task; S42. Set decision variables in the target time slice task; S43. Assign the decision variable according to the first variable; S44. Determine whether the decision variable is less than a preset threshold; otherwise, execute the CAN transmission task.
2. The CAN signal transmission method in an operating system-free environment as described in claim 1, characterized in that, In step S2, the formula for calculating the target time slice time is as follows: in, For the target time slice time, denoted as the minimum CAN signal transmission period, and k as the transmission period error.
3. The CAN signal transmission method in an operating system-free environment as described in claim 1, characterized in that, Step S4 further includes the following steps: S40. Calculate the preset threshold based on the minimum CAN signal transmission period and the target time slice time, using the following formula: Where n is a preset threshold, The minimum CAN signal transmission period, The target time slice time.
4. The CAN signal transmission method in an operating system-free environment as described in claim 1, characterized in that, Step S4 further includes the following steps: S45. When it is determined that the decision variable is not less than the preset threshold, the initial count value is calculated based on the decision variable and the preset threshold, using the following formula: in, is the initial count value, B is the decision variable, and n is the preset threshold.
5. A CAN signal transmission system without an operating system, used to implement the CAN signal transmission method without an operating system as described in any one of claims 1 to 4, characterized in that: It includes a minimum cycle acquisition module, and a system error setting module, a task allocation module, a judgment module, a correction module, and a timing reference module connected in sequence; the minimum cycle acquisition module is connected to the task allocation module, and the timing reference module is connected to the judgment module. The minimum period acquisition module is used to acquire the minimum CAN signal transmission period; The system error setting module is used to set the system's allowed transmission cycle error; The task allocation module is used to determine the target time slice task based on the minimum CAN signal transmission period and the transmission period error. The timing reference module is used to set the timing reference according to the target time slice time; The judgment module is used to determine whether to send the task based on the timing reference. The correction module is used to correct the timing reference according to the timing reference.
6. The CAN signal transmission system in an operating system-free environment as described in claim 5, characterized in that, The formula for calculating the target time slice is as follows: in, For the target time slice time, denoted as the minimum CAN signal transmission period, and k as the transmission period error.