Master-slave communication optimization method based on embedded operating system

By introducing master-slave communication optimization methods in the embedded operating system, using semaphore linked lists and system task management slave devices, the problem of CPU resource waste caused by periodic execution of threads is solved, and efficient and stable communication management is achieved.

CN120415944APending Publication Date: 2025-08-01HKUST DIGITAL (SHANGHAI) ENERGY TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510501774.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-21
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

In embedded product communication processing, periodic execution of threads leads to excessive CPU resource consumption, affecting system operation efficiency, especially in the case of high-priority communication threads or multi-communication ports, which reduces the overall efficiency of the system.

Method used

The master-slave communication optimization method is adopted to manage slave devices by creating semaphore linked lists, and use system tasks and interrupt mechanisms to achieve ready and sleep state switching of slave devices to avoid invalid CPU occupation.

Benefits of technology

It improves communication management efficiency, reduces CPU resource usage, and improves the operating efficiency and stability of the system, especially in the concurrent communication scenarios of multi-slave devices, which can respond to external events in a timely manner.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120415944A_ABST
    Figure CN120415944A_ABST
Patent Text Reader

Abstract

The invention discloses a master-slave communication optimization method based on an embedded operating system, and belongs to the technical field of communication. Comprising the steps that S1, a semaphore linked list is created, and master equipment manages slave equipment communicating with the master equipment through the semaphore linked list; s2, creating a semaphore structural body for each slave device, and inserting the semaphore structural body into a semaphore linked list; s3, initializing a driving module of the slave device and a corresponding interrupt enable; and S4, creating a system task for each slave device, and communicating the master device with the slave devices through the system tasks. The method has the advantages that communication of the master device and the slave device is associated with the semaphore linked list, the master device can conveniently manage communication of the slave device in a centralized mode, the problem that processor resources are occupied due to continuous operation of threads in a communication mechanism is solved through system tasks, and communication management efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technologies, and particularly to a master-slave communication optimization method. Background Art

[0002] In general communication processing of embedded products, the communication processing mechanism creates threads for each specific communication interface and sets a timeout period. When the system is running, it periodically enters the thread execution program according to the delay time set during thread creation. When there is external data communication, it interrupts the data reception and starts the counting of the timeout period. The thread determines whether the data reception is complete by the decreasing of the timeout period. Each time data is received during an interruption, the timeout period is reset until the timeout period is reduced to 0 before it is determined that the data reception is complete.

[0003] However, this mechanism has obvious drawbacks. If there is no data communication for a period of time, the thread still needs to be executed periodically, resulting in a large amount of CPU resources being occupied. When the thread for processing the communication timeout period has a high priority, or when there are many external communication ports with high priorities, it will seriously affect the execution efficiency of other threads, thereby reducing the running efficiency of the entire system. Summary of the Invention

[0004] The purpose of the present invention is to provide a master-slave communication optimization method based on an embedded operating system to solve the above technical problems;

[0005] A master-slave communication optimization method based on an embedded operating system includes:

[0006] Step S1, creating a semaphore linked list, and the master device manages the slave devices communicating with the master device through the semaphore linked list;

[0007] Step S2, creating a semaphore structure for each of the slave devices respectively, and inserting the semaphore structure into the semaphore linked list;

[0008] Step S3, initializing the driver module of the slave device and the corresponding interrupt enable;

[0009] Step S4, creating system tasks for each of the slave devices respectively, and the master device and the slave devices communicate through the system tasks.

[0010] Preferably, the semaphore structure in step S2 includes a semaphore, a communication timeout period, and a communication identifier.

[0011] Preferably, the slave devices and the master device communicate through communication resources, and the communication resources include serial ports, controller area networks, and network ports.

[0012] Preferably, the system tasks in step S4 include a query task and a communication task.

[0013] Preferably, the processing process of the communication task includes

[0014] judging whether the communication task obtains the semaphore of the slave device. If so, the communication task is in a ready state and processes the communication data sent by the slave device. If not, the communication task is in a sleep state.

[0015] Preferably, the processing process of the query task includes

[0016] Step S41, query the semaphore linked list;

[0017] Step S42, judge whether there is communication enabling in the semaphore structure. If so, decrement the timeout in the semaphore structure and then execute step S43. If not, return to execute step S41;

[0018] Step S43, judge whether the timeout has been decremented to zero. If so, send the semaphore to the corresponding communication task and then return to execute step S41. If not, return to execute step S41.

[0019] Preferably, the master device receives the communication data sent by the slave device through an interrupt mechanism.

[0020] Preferably, the semaphore linked list is created based on a group of buffers.

[0021] Preferably, data interaction is performed between the master device and the slave device through 485 communication, controller area network communication, and network communication.

[0022] Preferably, communication is carried out between the master device and the slave device through the Modbus protocol, and the embedded operating system is FreeRTOS.

[0023] The beneficial effect of the present invention is that the communication between the master device and the slave device is associated with the semaphore linked list, which is convenient for the master device to centrally manage the communication of the slave device. By using system tasks, the problem that threads continuously running in the communication mechanism occupy processor resources is solved, and the efficiency of communication management is improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] Figure 1 is a step diagram of the master-slave communication optimization method based on an embedded operating system of the present invention;

[0025] Figure 2 is a step diagram of the processing process of the query task of the present invention;

[0026] Figure 3 is a flowchart of the master-slave communication optimization method of the present invention;

[0027] Figure 4 is an execution flowchart of the present invention when an external communication data triggers an interruption;

[0028] Figure 5 is a flowchart of the processing process of the communication task of the present invention;

[0029] Figure 6 is a flowchart of the processing process of the query task of the present invention;

[0030] Figure 7 is a schematic diagram of the processor occupancy rate tested by using the traditional master-slave communication method;

[0031] Figure 8 is a schematic diagram of the processor occupancy rate tested by using the master-slave communication method of the present invention. Detailed implementation manners

[0032] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without making creative efforts belong to the scope of protection of the present invention.

[0033] It should be noted that, without conflict, the embodiments in the present invention and the features in the embodiments may be combined with each other.

[0034] Next, the present invention will be further described in conjunction with the accompanying drawings and specific embodiments, but it is not a limitation of the present invention.

[0035] A master-slave communication optimization method based on an embedded operating system, as Figure 1 shown, includes,

[0036] Step S1, create a semaphore linked list, and the master device manages the slave devices communicating with the master device through the semaphore linked list;

[0037] Step S2, create a semaphore structure for each slave device respectively, and insert the semaphore structure into the semaphore linked list;

[0038] Step S3, initialize the driver module of the slave device and the corresponding interrupt enable;

[0039] Step S4, create a system task for each slave device respectively, and the master device communicates with the slave device through the system task.

[0040] Specifically, the present invention provides a master-slave communication optimization method based on an embedded operating system, which associates the master-slave device communication with a semaphore linked list, facilitating the master device to centrally manage the slave device communication. The master device can schedule the communication of different slave devices according to the linked list information, avoiding task conflicts and chaos. When there is no external communication, the system tasks corresponding to the slave devices are suspended, not occupying the processor resources, thus improving the efficiency of communication management.

[0041] In a preferred embodiment, the semaphore structure in step S2 includes a semaphore, a communication timeout period, and a communication identifier.

[0042] Specifically, the semaphore enables the master device to effectively control the access of the slave device communication tasks to shared resources, avoiding conflicts caused by multi-task simultaneous access, and ensuring the accuracy and stability of communication. When multiple slave devices simultaneously request to use the serial port communication resources, the semaphore can ensure that only one slave device can perform communication operations at the same moment, preventing data chaos.

[0043] The communication timeout period is used to monitor the data reception or transmission progress of the slave device communication task. When the timeout period is reduced to 0, it means that an exception will occur in the communication, and the system can process it in a timely manner, such as retransmitting data or reporting an error, to ensure the reliability of communication. In CAN communication, if the data transmission of a certain slave device is interrupted due to bus interference or other problems when sending data, the timeout period can trigger a system response in a timely manner, avoiding the system waiting for a long time.

[0044] The communication identifier serves as the unique identity identifier of the slave device communication task, enabling the master device to quickly locate and identify the communication tasks of different slave devices when traversing the semaphore linked list, so as to perform scheduling and management in a targeted manner and improve the communication management efficiency. When the master device manages the communication of multiple serial port slave devices, the corresponding task can be quickly found through the communication identifier to process the corresponding communication data.

[0045] In a preferred embodiment, the slave device communicates with the master device through communication resources, and the communication resources include a serial port, a Controller Area Network (CAN), and a network interface.

[0046] Specifically, different slave devices have different communication interfaces, and the diversity of serial ports, CANs, and network interfaces can meet the access requirements of various devices.

[0047] For example, some simple sensor devices only support serial port communication, devices such as motor controllers in industrial fields often use CAN communication, while remote monitoring devices or high-speed data transmission devices rely on network interface communication. The diverse selection of communication resources enables the master device to connect different types and functions of slave devices to build a complex and feature-rich system.

[0048] Different communication resources have their own advantages in data transmission characteristics. Serial communication is simple, easy to use, and low in cost, suitable for device communication with low requirements for transmission rate and short distance, and can stably transmit a small amount of data.

[0049] CAN communication features high reliability and strong anti-interference ability, and is suitable for occasions with high requirements for data accuracy and real-time performance in industrial environments to ensure the reliable transmission of key data.

[0050] Ethernet communication has high-speed transmission capabilities and is suitable for the rapid transmission of large amounts of data, such as video surveillance data and a large number of device operation logs.

[0051] Through these communication resources with different characteristics, the system can select the most suitable method according to the data type and transmission requirements to ensure the reliability and efficiency of data transmission.

[0052] The existence of multiple communication resources makes the system more flexible when expanding new devices or docking with other systems. When a new slave device needs to be added, only the corresponding communication resource needs to be selected according to the device interface type for connection and configuration, without the need for large-scale transformation of the system. At the same time, when integrating with other systems using different communication standards, good compatibility can also be achieved through these communication resources, reducing the system integration difficulty and improving the versatility and expandability of the system.

[0053] In a preferred embodiment, the system tasks in step S4 include query tasks and communication tasks.

[0054] The processing process of the communication task includes

[0055] judging whether the communication task has obtained the semaphore of the slave device. If so, the communication task is in a ready state and processes the communication data sent by the slave device. If not, the communication task is in a sleep state.

[0056] Specifically, the system tasks are divided into query tasks and communication tasks. When there is no external communication, the communication task is suspended and sleeps, without occupying the processor resources. The processor can allocate resources to other more needed tasks, such as the real-time control tasks or data processing tasks of the system.

[0057] For example, in an energy storage system, when the communication is idle, the processor can focus on the monitoring and management of the battery power, improving the utilization efficiency of the entire system resources.

[0058] The query task is specifically responsible for monitoring the timeout of the communication task, while the communication task focuses on the reception and processing of data. The clear division of labor makes the communication management of the system more orderly.

[0059] For example, in the scenario of multi-slave device communication, the communication status of each slave device can be effectively monitored by the query task. Once a timeout occurs, the communication task can be notified in a timely manner for processing, avoiding the complex operation of the communication task having to handle data and pay attention to the timeout status at the same time, and improving the overall efficiency of communication management.

[0060] The ready and sleeping states of the communication task are controlled through the semaphore mechanism. When external communication data arrives, the communication task can quickly obtain the semaphore and enter the ready state to process the data. This ensures the system's real-time response to external communication events. Especially in application scenarios with high real-time requirements, such as industrial automation control, it can timely process control instructions or status information sent by slave devices to ensure the stable operation of the system.

[0061] In a preferred embodiment, referring to Figure 2 , the processing process of the query task includes

[0062] Step S41, query the semaphore linked list;

[0063] Step S42, determine whether there is communication occurrence enable in the semaphore structure. If so, decrement the timeout time in the semaphore structure and then execute Step S43. If not, return to execute Step S41;

[0064] Step S43, determine whether the timeout time has been decremented to zero. If so, send the semaphore to the corresponding communication task and then return to execute Step S41. If not, return to execute Step S41.

[0065] Specifically, by periodically querying the semaphore linked list, the query task can keep track of the communication status of each slave device in real time. Once the communication occurrence enable in the semaphore structure is triggered, it indicates that there is communication activity for the corresponding slave device, and the query task then intervenes to monitor, ensuring full tracking of the communication process and not missing any communication events.

[0066] In the complex scenario of multi-slave device concurrent communication, it can accurately identify the communication progress of each slave device, providing an accurate basis for system management.

[0067] The decrement operation and zero judgment of the timeout time in the semaphore structure are the keys to preventing the communication task from falling into infinite waiting due to abnormal situations. When the timeout time is decremented to zero, the query task sends a semaphore to notify the communication task, prompting the communication task to process data in a timely manner or execute an exception handling program. This avoids the long-term blocking of the communication task caused by problems such as data loss and transmission interruption, ensuring the reliability and timeliness of communication.

[0068] During the process of the query task's loop query, without communication enablement or the timeout not being reset to zero, it promptly returns to continue the query, without performing additional invalid operations, making the query task more efficient in using system resources and not wasting processor resources due to unnecessary calculations or waiting.

[0069] At the same time, when there is a communication event to be processed, it can quickly respond, reasonably allocate resources, and improve the overall operation efficiency of the system.

[0070] In a preferred embodiment, the master device receives communication data sent by the slave device through an interrupt mechanism.

[0071] Specifically, the slave device is connected to the interrupt pin of the master device to ensure that when the slave device has data to send, it can send an interrupt signal to the master device. In the hardware configuration of the master device, the interrupt controller needs to be correctly set, including enabling the corresponding interrupt channel, setting the interrupt trigger mode (such as rising edge trigger, falling edge trigger, or level trigger), etc.

[0072] Taking the ARM processor as an example, it is necessary to configure the registers of its internal interrupt controller, specify the interrupt number corresponding to the interrupt pin connected to the slave device, and set the corresponding trigger conditions.

[0073] At the software level, an interrupt handling program needs to be written. When an interrupt occurs, the CPU will jump to the corresponding interrupt handling program for execution. The main task of the interrupt handling program is to receive the data sent by the slave device and perform preliminary processing, such as storing the data in a buffer.

[0074] In the present invention, the interrupt handling program will also enable the communication resource occurrence flag and reset the timeout of the semaphore corresponding to the communication resource for subsequent query tasks and communication tasks to process.

[0075] The interrupt handling program and system tasks (such as query tasks and communication tasks) need to work together. When the interrupt handling program receives data, it will trigger the query task to monitor the timeout in the semaphore structure. When the timeout is reduced to 0, the query task will send a semaphore to notify the communication task to process the data, ensuring that the entire process from data reception, monitoring to processing can proceed orderly, and achieving efficient master-slave communication management.

[0076] The interrupt mechanism enables the master device to respond immediately when the slave device's data arrives, without continuously polling for data. In industrial control scenarios, the slave device (such as a sensor) may send critical data at any time, such as device fault signals or real-time measurement values. The interrupt mechanism can ensure that the master device promptly obtains this information and processes it, avoiding system failures or incorrect decisions caused by data reception delays, and greatly improving the real-time response ability of the system.

[0077] Through the interrupt mechanism, the master device can respond to the communication requests of the slave devices in a timely manner, avoiding data loss or backlog. In a complex environment with concurrent communication of multiple slave devices, the data of each slave device can be processed in a timely manner, without data chaos or loss due to waiting for processing, thus enhancing the stability and reliability of the entire system.

[0078] In a preferred embodiment, the semaphore linked list is created based on a set of buffers.

[0079] Specifically, the buffer serves as the physical carrier of the semaphore linked list, providing storage locations for the semaphore structures in a continuous or chained storage manner. By allocating fixed buffer spaces for each semaphore structure and connecting them in an orderly manner using the pointer structure of the linked list, a dynamically manageable data structure is formed. The master device can quickly access the first semaphore structure through the head pointer of the linked list, and then traverse the entire linked list in sequence according to the pointer order to achieve efficient monitoring and management of the communication status of the slave devices.

[0080] Creating a semaphore linked list based on a set of buffers provides an orderly space for storing semaphore structures, facilitating quick search and management. It enables the master device to efficiently organize and schedule the communication tasks of the slave devices, reducing the time overhead for searching and operating on semaphore structures, and thus improving the overall efficiency of communication management. At the same time, the reasonable use of buffers can effectively avoid the problem of memory fragmentation, improve memory utilization, and ensure the long-term stable operation of the system.

[0081] In a preferred embodiment, data interaction between the master device and the slave devices is carried out through 485 communication, Controller Area Network (CAN) communication, and network communication.

[0082] Specifically, 485 communication, CAN communication, and network communication each have their own advantages. The combination of multiple communication methods can meet the communication requirements of different slave devices. 485 communication has low cost and a relatively long transmission distance, and is suitable for connecting slave devices that are sensitive to cost and have a moderate distance; CAN communication has high reliability and strong anti-interference ability, and is suitable for scenarios with strict requirements for data accuracy and real-time performance in industrial environments; network communication has the ability of high-speed and large-data-volume transmission, meeting the needs of remote monitoring and large-data transmission. This diverse communication method enables the system to connect various types of slave devices, enhancing the compatibility and scalability of the system.

[0083] In a preferred embodiment, communication between the master device and the slave devices is carried out through the Modbus protocol, and the embedded operating system is FreeRTOS.

[0084] Specifically, as a general application layer communication protocol, the Modbus protocol provides a unified specification for data interaction between the master device and the slave device. It enables devices produced by different manufacturers to be easily connected to the system for communication as long as they support the Modbus protocol, greatly enhancing the openness and interoperability of the system. The FreeRTOS operating system provides strong support for the management of system tasks, with efficient task scheduling, memory management, and synchronization mechanisms. In the present invention, it can reasonably allocate CPU resources to ensure the orderly execution of tasks such as query tasks and communication tasks, improving the real-time performance and stability of the system.

[0085] Refer to Figure 3 , after the system initialization, first, a group of buffer (buffer area) is allocated as a linked list, and a header is created to obtain the semaphore linked list. For each communication resource, a semaphore structure is created and inserted into the linked list, and it is checked whether the linked list is full. The semaphore structure includes the created semaphore, the communication timeout period, and the identifier of the communication resource, which is used to identify the corresponding communication task;

[0086] Then, the drivers of various communication resources and the corresponding interrupt enables are initialized;

[0087] Then, corresponding tasks are created for each communication resource respectively, including communication tasks, query tasks, and other tasks, stack space and corresponding priorities are allocated. The execution period of the query task is 1 ms, which is used to query whether the timeout period of each communication task is 0. Once it is 0, a semaphore is sent to the corresponding communication task;

[0088] When there is no external communication, the communication tasks of the system will be directly suspended and in a dormant state, not occupying the resources of the CPU. The CPU will process the query tasks and other tasks.

[0089] Other tasks include system configuration tasks, which are responsible for managing the parameter configuration related to the communication between the master device and the slave device, as well as setting the operating parameters of the entire system.

[0090] For example, at the initial stage of system startup, parameters such as the pre-set communication baud rate, slave device address, and data verification method are read from an external storage device (such as EEPROM, Flash, etc.), and these parameters are passed to the corresponding communication driver module and task.

[0091] During the operation of the system, if some parameters need to be dynamically adjusted, such as adjusting the network communication timeout period according to the network conditions, the system configuration task can receive the parameter modification request from the human-machine interface or remote control instruction, then update the relevant configuration information, and notify the affected tasks (such as communication tasks) to make corresponding adjustments.

[0092] The system configuration task centralizes configuration management, facilitating flexible configuration of the system. Whether in the system initialization stage or during operation, configuration parameters can be easily modified and updated without affecting the core logic of other tasks. This improves the adaptability of the system, enabling it to quickly adjust configurations in different application scenarios and environments to meet diverse requirements.

[0093] For example, in different industrial sites, according to the actual equipment layout and communication requirements, the addresses and communication baud rates of slave devices need to be flexibly adjusted. The system configuration task can easily achieve these adjustments without large-scale modification of the code of the entire communication system.

[0094] Refer to Figure 4 , once an external communication data triggers an interruption, in the interruption handling function, enable the communication resource occurrence flag and reset the timeout time of the corresponding semaphore of the communication resource.

[0095] Refer to Figure 5 , which is the processing process of the communication task. As can be seen from the figure, the communication task always waits for the acquisition of the semaphore, judges whether the semaphore is acquired. If so, process the received communication data. If not, the communication task is suspended and enters the sleep state.

[0096] When there is no external data communication, the communication task cannot acquire the corresponding semaphore resource, so the task will be suspended and in the sleep state, not occupying the CPU resources. Usually, the priority of the communication task is relatively high. Once there is external data communication, after the task acquires the corresponding semaphore, it will transfer from the sleep state to the ready state and then process the corresponding communication data.

[0097] Refer to Figure 6 , query whether each semaphore structure in the semaphore linked list has communication occurrence enabled. If not, continue to query. If so, decrement the timeout time in the corresponding semaphore structure and judge whether it is decremented to 0. If so, perform semaphore reset communication occurrence enable and then continue to query. If not, continue to query.

[0098] In this task, it will query from the linked list whether there is a flag in the semaphore structure to enable communication occurrence. If so, decrement the corresponding timeout time count in the semaphore structure until the count is decremented to 0, and send the corresponding semaphore to notify the communication task to process the corresponding data.

[0099] Refer to Figure 7 、 Figure 8 , respectively tested the CPU occupancy rates in two cases for the master-slave serial communication (represented by boxes). Figure 8Adopting the communication method of the present invention, when there is no external data communication, the task is suspended and in a dormant state. From the perspective of the running count, the CPU utilization rate is 0. Figure 7 The traditional master-slave communication method is adopted, and the master-slave communication is processed according to the timeout period in the thread. In this way, even if there is no data communication, this thread will still occupy a certain amount of CPU, resulting in low communication management efficiency.

[0100] The present invention creates a semaphore linked list and a structure. Each slave device corresponds to a semaphore structure, which includes a semaphore, a timeout period, and a communication resource identifier. The semaphore is used to control task access, the timeout period monitors the communication progress, and the identifier is used to distinguish slave devices. This structure enables the master device to manage the communication tasks of slave devices in an orderly manner.

[0101] After initializing the slave device driver and enabling the interrupt, when the data of the slave device arrives, it triggers an interrupt. The master device responds to the interrupt to receive the data, sets the flag bit, and resets the semaphore timeout period. The query task periodically checks the linked list. When the timeout occurs, it sends a semaphore to wake up the communication task, enabling the system to quickly respond to communication requests under interrupt-driven and reasonably schedule tasks.

[0102] The present invention creates system tasks (communication tasks and query tasks) for slave devices. The communication tasks process data, and the query tasks monitor the timeout period. Different tasks are allocated different stack spaces and priorities, and they work together under the scheduling of the operating system to ensure the orderly progress of communication and improve the operating efficiency of the system.

[0103] The above are only the preferred embodiments of the present invention, and do not limit the implementation manners and protection scope of the present invention. For those skilled in the art, it should be realized that all equivalent replacements and obvious changes made by using the description and illustrations of the present invention should be included in the protection scope of the present invention.

Claims

1. A master-slave communication optimization method based on an embedded operating system, characterized in that, including Step S1: Create a semaphore linked list, and the master device manages the slave devices communicating with the master device through the semaphore linked list; Step S2: Create a semaphore structure for each of the slave devices respectively, and insert the semaphore structure into the semaphore linked list; Step S3: Initialize the driver module of the slave device and the corresponding interrupt enable; Step S4: Create system tasks for each of the slave devices respectively, and the master device and the slave devices communicate through the system tasks.

2. The master-slave communication optimization method based on an embedded operating system according to claim 1, wherein The semaphore structure in Step S2 includes a semaphore, a communication timeout period, and a communication identifier.

3. The master-slave communication optimization method based on an embedded operating system according to claim 1, characterized in that The slave devices communicate with the master device through communication resources, and the communication resources include a serial port, a controller area network, and a network interface.

4. The master-slave communication optimization method based on an embedded operating system according to claim 2, wherein The system tasks in Step S4 include a query task and a communication task.

5. The master-slave communication optimization method based on an embedded operating system according to claim 4, wherein The processing process of the communication task includes judging whether the communication task acquires the semaphore of the slave device. If so, the communication task is in a ready state and processes the communication data sent by the slave device. If not, the communication task is in a sleep state.

6. The master-slave communication optimization method based on an embedded operating system according to claim 4, characterized in that The processing process of the query task includes Step S41: Query the semaphore linked list; Step S42: Judge whether there is a communication occurrence enable in the semaphore structure. If so, decrement the timeout period in the semaphore structure and then execute Step S43. If not, return to execute Step S41; Step S43: Judge whether the timeout period is decremented to zero. If so, send the semaphore to the corresponding communication task and then return to execute Step S41. If not, return to execute Step S41.

7. The master-slave communication optimization method based on an embedded operating system according to claim 1, characterized in that, The master device receives the communication data sent by the slave device through an interrupt mechanism.

8. The master-slave communication optimization method based on an embedded operating system according to claim 1, wherein The semaphore linked list is created based on a group of buffers.

9. The master-slave communication optimization method based on an embedded operating system according to claim 1, characterized in that, Data interaction is performed between the master device and the slave devices through 485 communication, controller area network communication, and network communication.

10. The master-slave communication optimization method based on an embedded operating system according to claim 1, characterized in that, The master device and the slave devices communicate through the Modbus protocol, and the embedded operating system is FreeRTOS.