Master station control method and apparatus, electronic device, and readable storage medium

By constructing a real-time operating system and prioritizing kernel resources for target threads, the real-time processing requirements of the EtherCAT master station were addressed, achieving efficient and stable data interaction and adapting to high-precision and high-speed industrial control platforms.

CN119065834BActive Publication Date: 2026-07-21GREE ELECTRIC APPLIANCE INC OF ZHUHAI
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
GREE ELECTRIC APPLIANCE INC OF ZHUHAI
Filing Date
2024-07-29
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

In existing technologies, when implementing an EtherCAT master based on a non-real-time system, the real-time processing requirements of the EtherCAT master cannot be met, resulting in unstable communication.

Method used

By building a real-time operating system, configuring a preset non-real-time operating system using real-time patch packages, creating a target master station, and interacting with the master station through the target thread, the system can prioritize kernel resources and achieve efficient data transmission.

Benefits of technology

It improves the stability and efficiency of communication, meets the real-time requirements of the EtherCAT master station, reduces the response time of the operating system kernel, and adapts to the requirements of high-precision and high-speed industrial control platforms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119065834B_ABST
    Figure CN119065834B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a master station control method and device, electronic equipment and readable storage medium. The master station control method comprises: obtaining device configuration information corresponding to a slave station from a pre-configured user state shared memory; sending a start signal to a target master station and sending the device configuration information to a storage unit of the target master station; the device configuration information is used for the target master station to configure the slave station; the target master station is created based on a real-time operating system; the real-time operating system is obtained by pre-configuring a preset non-real-time operating system based on a real-time patch package; and in a case where a target signal indicating that the slave station is configured is received from the target master station, data interaction is performed between a target thread and the target master station. In this way, when the target thread performs data interaction with the target master station, kernel resources can be preempted in priority, the response time of the target operating system kernel is reduced, and the efficiency of data interaction is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a master station control method, apparatus, electronic device, and readable storage medium. Background Technology

[0002] With the development of technology, real-time Ethernet, represented by EtherCAT bus, is continuously occupying the fieldbus market in the industrial control field. It has the characteristics of high performance, high speed and support for multiple network topologies.

[0003] In related technologies, when implementing an EtherCAT master based on a non-real-time system, system resources need to be provided to the requester according to the processing order of the operating system kernel itself (e.g., the order of receiving time). This cannot meet the real-time processing requirements of the EtherCAT master. Therefore, there is an urgent need for a real-time operating system to implement the EtherCAT master in order to meet the real-time communication between the EtherCAT master and slave. Summary of the Invention

[0004] To overcome the problems existing in related technologies, the present invention provides a master station control method, device, electronic device, and readable storage medium.

[0005] In a first aspect, the present invention provides a master station control method, applied to a master station control program; the method includes:

[0006] Retrieve the device configuration information corresponding to the slave station from the pre-configured user-space shared memory;

[0007] A start signal is sent to the target master station, and the device configuration information is sent to the storage unit of the target master station; the device configuration information is used by the target master station to configure the slave station, the target master station is created based on a real-time operating system, and the real-time operating system is obtained by pre-configuring a preset non-real-time operating system based on a real-time patch package;

[0008] Upon receiving a target signal from the target master station indicating that the slave station configuration is complete, data interaction is performed between the target thread and the target master station.

[0009] Optionally, sending the device configuration information to the storage unit of the target master station includes:

[0010] The thread scheduler is invoked through a real-time thread; the thread priority of the real-time thread is higher than that of the non-real-time thread.

[0011] The thread scheduler calls the encapsulation function in the master station control encapsulation layer; the encapsulation function is used to automatically call the PCIe driver, and the PCIe driver is used to send the device configuration information to the storage unit of the target master station based on the PCIe bus.

[0012] Optionally, the encapsulation function includes a first file and a second file. The first file defines at least two kernel-mode interfaces corresponding to functions, and the second file is used to implement the calls of the kernel-mode interfaces of each function to the interface of the PCIe driver.

[0013] Optionally, the target thread includes a first target thread; the data interaction with the target master station based on the target thread includes:

[0014] Upon receiving the first transmit completion signal from the PCIe driver, the first target thread invokes the PCIe driver to retrieve slave-related data from kernel-mode memory; the slave-related data is sent to the kernel-mode memory by the target master station.

[0015] Based on the relevant data from the slave station, the target calculation result is obtained;

[0016] The target calculation result is sent to the data buffer of the target master station based on the PCIe driver, and a second transmission completion signal is sent to the target master station; the first transmission completion signal and the second transmission completion signal are interrupt signals, and the second transmission completion signal is used to instruct the target master station to read the target calculation result in the data buffer when the second transmission completion signal is received.

[0017] Optionally, the target thread further includes a second target thread; the data interaction between the target thread and the target master station further includes:

[0018] Based on the second target thread, the first register address corresponding to the first slave station is sent to the target master station; the first register address is used for the target master station to perform a first operation on the relevant parameters in the register corresponding to the register address of the first slave station, and the first target thread and the second target thread run in parallel.

[0019] Optionally, the target thread further includes a third target thread; the data interaction between the target thread and the target master station further includes:

[0020] Based on the third target thread, index information is sent to the target master station; the index information is used by the target master station to perform a second operation on the dictionary object parameter information corresponding to the index information; the second operation is used to configure the motion mode of the second slave station and check the interface connection status of the second slave station, and the first target thread and the third target thread run in parallel.

[0021] Optionally, the device configuration information is obtained by parsing the device configuration file corresponding to the slave station and writing the parsed device configuration information into user-mode shared memory according to a preset matching rule.

[0022] Secondly, the present invention provides a master station control device for use in a master station control program; the device includes:

[0023] The first acquisition module is used to acquire the device configuration information corresponding to the slave station from the pre-configured user-mode shared memory;

[0024] The first sending module is used to send a start signal to the target master station and send the device configuration information to the storage unit of the target master station; the device configuration information is used by the target master station to configure the slave station, the target master station is created based on a real-time operating system, and the real-time operating system is obtained by pre-configuring a preset non-real-time operating system based on a real-time patch package;

[0025] The first interaction module is used to perform data interaction with the target master station based on the target thread when it receives a target signal sent by the target master station indicating that the slave station has been configured.

[0026] Optionally, the first transmitting module includes:

[0027] The first calling module is used to call the thread scheduler through a real-time thread; the thread priority of the real-time thread is greater than the thread priority of the non-real-time thread.

[0028] The second calling module is used to call the encapsulation function in the master station control encapsulation layer through the thread scheduler; the encapsulation function is used to automatically call the PCIe driver, and the PCIe driver is used to send the device configuration information to the storage unit of the target master station based on the PCIe bus.

[0029] Optionally, the target thread includes a first target thread; the first interaction module includes:

[0030] The first acquisition module is used to, upon receiving a first transmission completion signal sent by the PCIe driver, invoke the PCIe driver based on the first target thread to acquire slave-related data from kernel-mode memory; the slave-related data is sent to the kernel-mode memory by the target master station;

[0031] The second acquisition module is used to acquire the target calculation result based on the slave station related data;

[0032] The first sending submodule is used to send the target calculation result to the data buffer of the target master station based on the PCIe driver, and send a second sending completion signal to the target master station; the first sending completion signal and the second sending completion signal are interrupt signals, and the second sending completion signal is used to instruct the target master station to read the target calculation result in the data buffer when the second sending completion signal is received.

[0033] Optionally, the target thread further includes a second target thread; the first interaction module includes:

[0034] The second sending submodule is used to send the first register address corresponding to the first slave station to the target master station based on the second target thread; the first register address is used for the target master station to perform a first operation on the relevant parameters in the register corresponding to the register address of the first slave station, and the first target thread and the second target thread run in parallel.

[0035] Optionally, the target thread further includes a third target thread; the first interaction module includes:

[0036] The third sending submodule is used to send index information to the target master station based on the third target thread; the index information is used by the target master station to perform a second operation on the dictionary object parameter information corresponding to the index information; the second operation is used to configure the motion mode of the second slave station and check the interface connection status of the second slave station, and the first target thread and the third target thread run in parallel.

[0037] Thirdly, the present invention provides an electronic device comprising: a processor, a memory, and a computer program stored in the memory and executable on the processor, characterized in that the processor, when executing the program, implements the master station control method described in any one of the first aspects above.

[0038] Fourthly, the present invention provides a readable storage medium that, when the instructions in the storage medium are executed by a processor of an electronic device, enables the electronic device to perform the steps of the master station control method as described in any of the embodiments of the first aspect above.

[0039] In this embodiment of the invention, device configuration information corresponding to the slave station is obtained from pre-configured user-mode shared memory; a start signal is sent to the target master station, and the device configuration information is sent to the target master station's storage unit; the device configuration information is used by the target master station to configure the slave station. The target master station is created based on a real-time operating system, which is pre-configured based on a real-time patch package on a preset non-real-time operating system; upon receiving a target signal from the target master station indicating that the slave station configuration is complete, data interaction is performed between the target thread and the target master station. Thus, by building a real-time operating system using a real-time patch package, the requirements of high-precision and high-speed industrial control platforms can be more flexibly matched. Simultaneously, based on the real-time operating system, data interaction between the target thread and the target master station improves communication stability, and the real-time operating system enhances the preemptibility of the operating system kernel, ensuring that kernel resources can be preempted first when the master station control program interacts with the target master station through the target thread, reducing the response time of the target operating system kernel and improving the efficiency of data interaction between the master station control program and the target master station. Attached Figure Description

[0040] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0041] Figure 1 This is a flowchart of the steps of a master station control method provided in an embodiment of the present invention;

[0042] Figure 2 This is a control framework diagram of a target master station provided in an embodiment of the present invention.

[0043] Figure 3 This is a flowchart of the operation of a master station control program provided in an embodiment of the present invention;

[0044] Figure 4 This is a structural diagram of a master station control device provided in an embodiment of the present invention;

[0045] Figure 5 This is a structural diagram of an electronic device provided in an embodiment of the present invention. Detailed Implementation

[0046] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0047] Figure 1 This is a flowchart illustrating the steps of a master station control method provided in an embodiment of the present invention, applied to a master station control program. The master station control program can be determined based on a real-time PCIe driver module, and can implement different functions by calling interfaces, such as start, configuration, activation, stop, data interaction, and interrupt interaction.

[0048] The main station control program can implement the following API functions:

[0049] EC_Master_start: Master start function. This function sends the master start signal, and the FPGA master station enters the PREOP stage from the INIT stage.

[0050] EC_Master_config: Master station configuration function. This function is used before the master station is activated to pass the required configuration data to the FPGA master station.

[0051] EC_Master_active: Master activation function, indicating that the FPGA master station has completed the data input and has entered the OP stage from the PREOP stage;

[0052] EC_Master_run: Process data interaction function. This function waits for all slave stations to enter OP before executing, which means that process data interaction is started.

[0053] EC_Master_stop: Master stop function. This function will stop the FPGA master station from running.

[0054] EC_sdo_read: Reads COE dictionary parameter information based on the SDO index and sub-index;

[0055] EC_sdo_write: Modifies COE dictionary parameter information based on SDO index and sub-index;

[0056] EC_reg_read: Reads relevant REG parameter information based on the REG address;

[0057] EC_reg_write: Modifies the relevant REG parameter information based on the REG address;

[0058] EC_send_process: Function to send process data to the FPGA master station;

[0059] EC_receive_process: Function to receive process data from the FPGA master station;

[0060] EC_receive_error_info: This function receives error messages. When a problem occurs on a slave device, it sends out the information about the problematic slave device and its status code.

[0061] like Figure 1 As shown, the method may include:

[0062] Step 101: Obtain the device configuration information corresponding to the slave station from the pre-configured user-mode shared memory.

[0063] In this embodiment of the invention, the user-space shared memory stores device configuration information corresponding to the slave station. This device configuration information is used by the target master station to initialize and configure the slave station based on the device configuration information. The device configuration information can be obtained in advance by parsing the device configuration file corresponding to the slave station. The device configuration information can include the device ID corresponding to the slave station, the motion state corresponding to the slave station, and the I / O point data corresponding to the slave station. The device configuration file can be an XML format device configuration file, determined based on the analysis of the EtherCAT slave station's ESI file. The device configuration file describes the device information of the EtherCAT slave station, and for example, it can include three elements: basic device information, basic data types, and an object dictionary description. After parsing the device configuration file, the device configuration information is written into the user-space shared memory according to a preset matching rule. The preset matching rule can include writing the parsed device configuration information into a predefined DeviceInfo structure, and storing the data based on the DeviceInfo structure.

[0064] For example, the steps of obtaining device configuration information and writing it into user-space shared memory can be as follows: A DeviceInfo structure is created based on the information acquisition requirements. This DeviceInfo structure stores the device configuration information parsed from the device configuration file. Device configuration information, such as ProductCode and RevisionNo, dictionaries, and IO data, is predefined in the DeviceInfo structure. The information acquisition requirements can be determined based on the information needed by the target master station when configuring the slave station.

[0065] The device configuration file is parsed using an XML file parser. This parser can be determined by writing a function called `parse_EtherCAT_XML`, which uses the TinyXML2 library to parse the configuration file. Specifically, a TinyXML2 XMLDocument object is created, the device configuration file is loaded, the root element is retrieved, its child elements are traversed, keywords are extracted from each element, and it is determined whether the extracted keywords match pre-defined device configuration information in the `DeviceInfo` structure. If a match is found, the matched content is stored in the corresponding device configuration information of the `DeviceInfo` structure.

[0066] Write the main function, call the ftok function to create a key for shared memory, use the shmget function to create a shared memory segment using this key, and use the shmat function to attach the shared memory segment to the current process. Create a std::vector. <deviceinfo>A pointer of type `sharedData` is used to associate a shared memory segment. This shared memory segment is configured at the user level; therefore, it can be user-mode shared memory. The current process refers to the process running the XML file parser. A `DeviceInfo` structure member `devices` is created, and the pre-written `parse_EtherCAT_XML` function is called, passing the path to the device configuration file and the `devices` variable as parameters. After processing, `*sharedData = devices` is used to assign a value to the corresponding block in the shared memory, ending the information storage. Finally, `shmdt(sharedData)` is used to detach the current process from the shared memory segment, ensuring that other processes can access it.

[0067] The master station control program retrieves the device configuration information corresponding to the slave station from user-space shared memory and sends the device configuration information to the target master station, so that the target master station can initialize and configure the slave station based on the device configuration information. If the master station control program needs to implement different functions, it needs to initiate kernel calls based on different API interfaces.

[0068] Step 102: Send a start signal to the target master station and send the device configuration information to the storage unit of the target master station; the device configuration information is used by the target master station to configure the slave station. The target master station is created based on a real-time operating system, which is obtained by pre-configuring a preset non-real-time operating system based on a real-time patch package.

[0069] In this embodiment of the invention, after the master station control program reads the device configuration information from the user-mode shared memory, it sends a start signal to the target master station via an MSI-X interrupt based on the PCIe protocol, and sends the device configuration information to the target master station's storage unit. The start signal instructs the target master station to enter the initialization configuration state, i.e., to transition from the INIT state to the PREOP state. The device configuration information is then sent to the target master station and stored in the target master station's storage unit. This storage unit can be Random Access Memory (RAM). For example, the master station control program can first use EC_Master_start() to send a start signal to the target master station, then use EC_Master_config() to transfer the device configuration information to the target master station's RAM. If the device configuration information transmission is complete, EC_Master_active() is used to notify the target master station that data transmission is complete; otherwise, it continues to wait for data transmission.

[0070] The target master station is built on a real-time operating system (RTOS), which is pre-configured using a pre-defined non-real-time operating system based on real-time patch packages. The target master station can be an FPGA master station, the ROS can be an x86-based RT-Linux operating system, and the pre-defined non-real-time operating system can be a Linux operating system. By configuring the pre-defined non-real-time operating system using real-time patch packages, an x86-based RT-Linux operating system can be built to support the flexible access of the EtherCAT-based target master station to the system as a PCIe device. The ROS can respond to external events and process tasks within strict time constraints. By employing a priority-based and deadline-based task scheduling strategy, it ensures that high-priority tasks are executed first, thereby completing critical tasks within a limited time.

[0071] For example, obtain a default non-real-time operating system, such as Linux. Based on a stable Linux operating system version, apply a real-time kernel patch to the default non-real-time operating system using the real-time patch package (RT Patch). Assuming Linux operating system version 4.19 is used, the RT Patch package can be selected as the patch-4.19-rt.patch.xz file. Extract and compile both the Linux source code and the RT Patch package. Use the command `patch-p1<[patch path] / patch-4.19-rt.patch.xz` to apply a real-time kernel patch to the Linux operating system kernel. Use the `make menuconfig` command to customize and configure the kernel. Specifically, first, select "FullyPreemptible Kernel (Real-time)" in "Preemption Model". In "General setup->Timers subsystem", select "High resolution Timer Support" to use a high-precision timer to improve the real-time performance of RT-Linux. Select 1000Hz for "Timer frequency" in "Processor type and features". After saving the above configuration information, check the `CONFIG_SYSTEM_TRUSTED_KEYS` setting in the `.config` file in the Linux source code root directory and comment it out. Compile the Linux kernel sequentially using the commands `make->make install->make modules_install`. Then, navigate to the ` / boot` directory of the Linux source code and use the command `mkinitramfs-ko initrd.img-4.19-rt 4.19-rt` to create the bootloader and build the RT-Linux real-time operating system. This approach, using preemptive patches (PREEMPT-RT patches), allows for a lighter kernel, minimizing the amount of code modifications and improving preemption for critical sections, interrupt handlers, and interrupt disabling code sequences. Furthermore, using the x86 platform enables communication between the target master station and the master control system via a high-speed PCIe bus, facilitating rapid replacement and compatibility between different master station devices and broadening the platform's compatibility.

[0072] Step 103: Upon receiving a target signal from the target master station indicating that the slave station configuration is complete, perform data interaction with the target master station based on the target thread.

[0073] In this embodiment of the invention, after the master station control program transmits the device configuration information to the target master station's storage unit, i.e., after the device configuration information data transmission is complete, it sends a data transmission completion signal to the target master station via an MSI-X interrupt based on the PCIe protocol. Upon receiving the data transmission completion signal, the target master station initializes the slave stations based on the device configuration information, causing the slave stations to enter the running state (OP state). Once all slave stations are in the running state, the target master station sends a target signal to the master station control program. This target signal can be an OP state signal, used to indicate that the slave station initialization configuration is complete. Upon receiving the target signal from the target master station, the master station control program can initiate data interaction with the target master station based on the target thread. Specifically, the EC_Master_run function can be used to initiate process data interaction between the master station control program and the target master station. Due to the characteristics of the real-time operating system, when the master station control program interacts with the target master station based on a thread, the thread with higher priority can preemptively preempt and call the real-time operating system kernel (Linux Kernel) for data interaction. The target thread may include at least two real-time threads, which may be parallel real-time threads. Different threads may be used to execute different tasks to achieve different functions. Each task may run independently without interfering with each other, such as motion state adjustment or slave status detection.

[0074] In summary, in this embodiment of the invention, device configuration information corresponding to the slave station is obtained from pre-configured user-mode shared memory; a start signal is sent to the target master station, and the device configuration information is sent to the target master station's storage unit; the device configuration information is used by the target master station to configure the slave station, the target master station is created based on a real-time operating system, and the real-time operating system is obtained by pre-configuring a preset non-real-time operating system based on a real-time patch package; upon receiving a target signal from the target master station indicating that the slave station configuration is complete, data interaction is performed between the target thread and the target master station. Thus, by building a real-time operating system using a real-time patch package, the requirements of high-precision and high-speed industrial control platforms can be more flexibly matched. Simultaneously, based on the real-time operating system, data interaction between the target thread and the target master station improves communication stability, and the real-time operating system enhances the preemptibility of the operating system kernel, ensuring that kernel resources can be preempted first when the master station control program interacts with the target master station through the target thread, reducing the response time of the target operating system kernel and improving the efficiency of data interaction between the master station control program and the target master station.

[0075] Optionally, step 102 may include the following steps:

[0076] Step 201: Call the thread scheduler through a real-time thread; the thread priority of the real-time thread is greater than the thread priority of the non-real-time thread.

[0077] In this embodiment of the invention, the real-time operating system may include a thread scheduler (RT Scheduler), which is used to allocate tasks based on thread priority. The master station control program calls the thread scheduler through real-time threads. Specifically, a real-time thread can initiate an API call to the thread scheduler. The thread priority of the real-time thread is higher than that of the non-real-time thread. If the thread scheduler determines that the real-time thread has a high priority, it is allowed to preempt the real-time operating system kernel (Linux Kernel) for priority operation. That is, if there is a non-real-time thread currently running in the real-time operating system, it will be directly interrupted, and the kernel will be preempted by the real-time thread.

[0078] Step 202: Call the encapsulation function in the master station control encapsulation layer through the thread scheduler; the encapsulation function is used to automatically call the PCIe driver, and the PCIe driver is used to send the device configuration information to the storage unit of the target master station based on the PCIe bus.

[0079] In this embodiment of the invention, after determining that the real-time thread has a high priority, the thread scheduler preferentially calls the encapsulation function of the master station control encapsulation layer in the real-time operating system kernel. The PCIe driver can be a real-time PCIe driver, such as the open-source project provided by Xilinx, which provides the PCIe communication IP core XDMA. Based on at least two functions required by the target master station, such as start, configuration, activation, stop, data interaction, and interrupt interaction, the open-source APIs provided by Xilinx are integrated. When the thread scheduler schedules the process to preempt the kernel and calls the PCIe driver in real time, a master station control encapsulation layer is added. This master station control encapsulation layer is located at the kernel level, facilitating direct API calls from the user-mode master station control program, simplifying later debugging and improving code stability. The master station control encapsulation layer contains encapsulation functions, which are functions that integrate and encapsulate the functions of the open-source PCIe driver APIs provided by Xilinx, for use by upper layers. The encapsulation functions may include a first file and a second file. The first file defines kernel-mode interfaces corresponding to at least two functions, and the second file is used to implement the calls from the kernel-mode interfaces of each function to the PCIe driver interface. The first file can be a header file, and the second file can be a C file. Specifically, new header and C files can be added to the kernel source code. The header file contains the encapsulated function definitions for at least two integrated functions, while the C file is responsible for the specific implementation of each function. For example, the header file can define kernel-mode interfaces corresponding to at least two functions, such as kernel-mode APIs for functions like start, configuration, activation, stop, data interaction, and interrupt interaction. The C file is used to implement the calls from the kernel-mode interfaces of each function to the PCIe driver interface. For instance, each kernel-mode API can be used to call the interface provided by the PCIe driver according to different functions. Furthermore, atomicity measures can be added to the C file to prevent the risk of dirty reads from parallel calls and to prevent disorder when multiple tasks call shared APIs. For example, for some shared function code, another task can only operate after one task completes its function call; otherwise, it must wait in a queue. The kernel-mode interface is used by the user-mode API of the master station control program, which facilitates later debugging, improves code stability, and avoids dirty read problems.

[0080] The encapsulated function is used to automatically invoke the PCIe driver, which then sends device configuration information to the target master's storage unit via the PCIe bus. For example, the PCIe driver saves the device configuration information to kernel-level memory and then notifies the Real-Time Operating System Extension / Plugin (RT-Linux Plugin) via input / output (I / O) to send the device configuration information to the target master via the PCIe bus. Specifically, after the RT-Linux Plugin receives the data transmission completion signal sent by the PCIe driver using the MSI-X interrupt method based on the PCIe protocol, it sends the device configuration information to the target master. The target master initializes the slave based on the device configuration information and, after the slave completes its initialization, sends the target signal to the master control program.

[0081] In this embodiment of the invention, the target master station is implemented using the RT-Linux operating system based on the x86 platform. Data transmission can be performed via the PCIe bus, improving platform compatibility and adaptability. Simultaneously, the PCIe bus offers extremely high scalability; the FPGA master station board can be inserted into the x86 motherboard via the PCIe interface, enabling flexible replacement of external devices. Compared to the hardware integration of the ARM platform, this embodiment facilitates rapid replacement and compatibility between different master station devices, resulting in a wider platform compatibility coverage. Furthermore, using the PCIe bus for communication between the x86 platform and the FPGA master station allows MSI interrupts and IO data to be transmitted on the same bus, increasing operational efficiency.

[0082] Optionally, the at least two target threads include a first target thread; step 103 may include the following steps:

[0083] Step 301: Upon receiving the first transmission completion signal from the PCIe driver, the PCIe driver is invoked based on the first target thread to obtain slave-related data from kernel-mode memory; the slave-related data is sent to the kernel-mode memory by the target master station.

[0084] In this embodiment of the invention, the target master station acquires slave-related data from the slave station, wherein the slave-related data may include slave station location data or slave station speed data. The target master station transmits the slave-related data to the Real-Time Operating System Extension / Plug-in (RT-Linux Plugin) via the PCIe bus. The RT-Linux Plugin then transmits the slave-related data to the PCIe driver through the input / output interface. After receiving the data transmission completion signal sent by the RT-Linux Plugin, the PCIe driver stores the slave-related data in kernel-mode memory.

[0085] The PCIe driver sends a first transmission completion signal to the master control program via an MSI-X interrupt based on the PCIe protocol. Upon receiving this signal, the master control program initiates a call to the PCIe driver via a first target thread to retrieve slave-related data stored in kernel-mode memory. The first transmission completion signal can be an interrupt signal, such as a data transfer completion signal (MSI-X). The first target thread is a real-time thread that calls the thread scheduler, which in turn calls the encapsulated function in the master control encapsulation layer to retrieve the slave-related data from kernel-mode memory.

[0086] Step 302: Based on the slave station related data, obtain the target calculation result.

[0087] In this embodiment of the invention, after receiving relevant data from the slave station, the master station control program determines the target calculation result based on preset calculation rules. For example, the target calculation result can be used to adjust the movement state of the slave station. It is understood that the steps for calculating the target result based on the slave station's relevant data can refer to existing technologies, and will not be elaborated further in this embodiment.

[0088] Step 303: Send the target calculation result to the data buffer of the target master station based on the PCIe driver, and send a second transmission completion signal to the target master station; the first transmission completion signal and the second transmission completion signal are interrupt signals, and the second transmission completion signal is used to instruct the target master station to read the target calculation result in the data buffer when the second transmission completion signal is received.

[0089] In this embodiment of the invention, the target calculation result is sent to the data buffer of the target master station via a PCIe driver. The data buffer can be a first-in, first-out (FIFO) memory. After the transmission of the target calculation result is completed, a second transmission completion signal is sent to the target master station. This second transmission completion signal can be an interrupt signal, such as a data transmission completion signal (MSI-X). The second transmission completion signal instructs the target master station, upon receiving the second transmission completion signal, to read the target calculation result from the data buffer and send it to the slave station to adjust the slave station's movement state.

[0090] In this embodiment of the invention, by building an x86 RT-Linux environment and constructing a real-time operating system to enable real-time functions, the target master station can realize the data transmission of slave-related data and target calculation results based on the PCIe bus, thereby improving task processing efficiency.

[0091] Optionally, the at least two target threads include a second target thread; step 103 may include the following steps:

[0092] Step 401: Based on the second target thread, send the first register address corresponding to the first slave station to the target master station; the first register address is used for the target master station to perform a first operation on the relevant parameters in the register corresponding to the register address of the first slave station, and the first target thread and the second target thread run in parallel.

[0093] In this embodiment of the invention, based on the second target thread, data timeout and packet loss detection of the slave station can be performed. Specifically, the first register address of the first slave station for which data timeout and packet loss detection needs to be performed is determined. The first slave station may include one or more slave stations. If the first slave station includes multiple slave stations, the register address of each slave station is obtained as the first register address. The first register address is sent to the target master station through the second target thread. Specifically, the second target thread can call the thread scheduler, causing the thread scheduler to call the encapsulation function in the master station's control encapsulation layer. The encapsulation function automatically calls the PCIe driver, which saves the first register address to kernel-mode memory and then notifies the Real-Time Operating System Extension / Plug-in (RT-Linux Plugin) to send the first register address to the target master station via the PCIe bus through the input / output interface (I / O). Specifically, after the Real-Time Operating System Extension / Plug-in (RT-Linux Plugin) receives the data transmission completion signal sent by the PCIe driver using the MSI-X interrupt method based on the PCIe protocol, it sends the first register address to the target master station. The target master station performs a first operation on the relevant parameters in the register corresponding to the first register address. The first operation may include obtaining and modifying the relevant parameters in the register corresponding to the first register address.

[0094] For example, the second target thread can use the EC_reg_read() function to read the relevant parameter status of the register corresponding to the first register address, and / or use the EC_reg_write() function to modify the register parameters of the register corresponding to the first register address, in order to detect whether data packet timeout or loss has occurred.

[0095] Optionally, the at least two target threads may further include a third target thread. Step 103 may include the following steps:

[0096] Step 501: Based on the third target thread, send index information to the target master station; the index information is used by the target master station to perform a second operation on the dictionary object parameter information corresponding to the index information; the first target thread and the third target thread run in parallel.

[0097] In this embodiment of the invention, tasks such as configuring slave station movement modes and checking physical interface connections can be performed based on a third target thread. Specifically, according to configuration or inspection requirements, the index information corresponding to the object to be configured or inspected is determined, such as the SDO index and sub-index, and sent to the target master station based on the third index information. Specifically, the third target thread can call the thread scheduler, which in turn calls the encapsulation function in the master station control encapsulation layer. The encapsulation function automatically calls the PCIe driver, which saves the index information to kernel-mode memory and then notifies the real-time operating system extension / plugin (RT-Linux Plugin) to send the index information to the target master station via the PCIe bus through the input / output interface (I / O). Specifically, after the real-time operating system extension / plugin (RT-Linux Plugin) receives the data transmission completion signal sent by the PCIe driver using the MSI-X interrupt method based on the PCIe protocol, it sends the index information to the target master station. Based on the index information, the target master station performs a second operation on the dictionary object parameter information corresponding to the index information. The second operation includes data acquisition operations and data modification operations. The second operation is used to configure the slave station's motion mode and check the slave station's interface connectivity.

[0098] For example, the third target thread can use the EC_sdo_read() function to read COE dictionary parameter information and / or use EC_sdo_write() to modify COE dictionary parameter information for real-time configuration of slave station motion mode and checking physical interface connection status.

[0099] In this embodiment of the invention, the second and third target threads, which run in parallel with the first target thread, can monitor or configure the relevant parameters and status of the slave station in real time, thereby improving the flexibility of data interaction.

[0100] For example, Figure 2 A control framework diagram of a target master station is shown, such as Figure 2 As shown in the diagram, it includes the user layer, kernel layer, and hardware layer. The following is based on... Figure 2 The master station control method of this invention will be described in general as follows:

[0101] User layer: After the device configuration file is parsed by the XML file parser, the device configuration information is obtained and stored in the user-mode shared memory. The master station control program retrieves the data from the user-mode shared memory and then needs to initiate kernel calls based on APIs of different functions to implement different functions.

[0102] Kernel Layer: Assuming the master station control application needs to execute a function, it will initiate an API call to the RT Scheduler via a real-time thread. The RT Scheduler, acting as the scheduler, determines that the real-time thread has high priority and allows it to preempt the Linux Kernel for priority operation. If there is a non-real-time thread currently running in the system, it will be directly interrupted, and the kernel will be preempted by the real-time thread. Next, the corresponding wrapper function in the master station control API wrapper layer will be called. This wrapper function itself calls the corresponding PCIe driver. The PCIe driver will save the user-mode data sent by the master station control program to kernel-mode memory and notify the RT-Linux Plugin to execute interrupt transmission or send data to the FPGA master station via the I / O interface.

[0103] Hardware layer: The level signals of data and PCIe interrupts are uniformly transmitted to the data buffer (FIFO) of the FPGA master station through PCIe 2.0x4 hardware routing.

[0104] like Figure 2 As shown, the signals sent by the FPGA master station to the real-time operating system (RT-Linux) (such as OP status signals, data transmission completion signals, etc.) and the signals sent by RT-Linux to the FPGA master station (such as master station start signals, master station activation signals, data transmission completion signals, etc.) are all MSI-X interrupts of the PCIe protocol. During communication, both the FPGA master station and RT-Linux implement interrupt and data transmission through the PCIe 2.0 bus. Furthermore, as... Figure 2 As shown, the data interaction between the XML file parser and the master station control program via shared memory is inter-process communication, while the interaction between RT-Linux and the FPGA master station is PCIe bus communication. In other words, the XML file parser and the master station control program are two independent processes, each containing threads that implement the functionality: "Normal Thread 1" and "RT Thread 1". The master station control program is a real-time RT thread, and the XML file parser is a normal thread. These two processes interact via shared memory.

[0105] For example, Figure 3 A flowchart of the operation of a master station control program is shown, such as... Figure 3 As shown, based on the XML configuration file, the XML file parsing program is started, user-space shared memory is opened, and after ensuring that all device configuration information has been parsed and written to user-space shared memory, the master station control program is started. The master station control program reads the device configuration information from user-space shared memory, first using EC_Master_start() to send a start signal to the target master station, then using EC_Master_config() to transfer the configuration data to the RAM (storage unit) of the FPGA (target master station). If the device configuration information has been transmitted successfully, EC_Master_active() is used to notify the FPGA master station that the data transmission is complete; otherwise, it continues to wait for data transmission. It waits for the FPGA master station to put all slave stations into OP state. Upon receiving the slave station OP signal (the target signal sent by the target master station), EC_Master_run() is used to start the data interaction process with the FPGA master station, based on the simultaneous operation of two target threads.

[0106] Thread 1: Used for data interaction related to slave motion state adjustment between RT-Linux and the FPGA master station. Specifically, RT-Linux uses `ec_receive_process()` to receive slave position / velocity information sent by the FPGA master station and stores it in kernel-mode memory. After performing the next position / velocity calculation, it sends the slave position / velocity information to the FPGA master station's FIFO via `ec_send_process()`, allowing the FPGA master station to control the slave to update its motion state. If communication is no longer desired, `EC_Master_stop` is used to stop the FPGA master station.

[0107] Thread 2: Used to detect data packet timeouts and losses, configure slave station operation modes in real time, and check physical interface connectivity. Specifically, this thread can use `ec_sdo_read()` to read COE dictionary parameter information and `ec_sdo_write()` to modify COE dictionary parameter information for real-time slave station operation mode configuration and physical interface connectivity checks; or it can use `ec_reg_read()` to read slave station register parameter status and `ec_reg_write()` to modify register parameters for detecting data packet timeouts and losses. If communication is no longer desired, `EC_Master_stop` is used to stop the FPGA master station.

[0108] Figure 3 This is a schematic diagram of the structure of a master station control device provided in an embodiment of the present invention, applied to a master station control program; such as Figure 3 As shown, the device may specifically include:

[0109] The first acquisition module 501 is used to acquire the device configuration information corresponding to the slave station from the pre-configured user-mode shared memory;

[0110] The first sending module 502 is used to send a start signal to the target master station and send the device configuration information to the storage unit of the target master station; the device configuration information is used by the target master station to configure the slave station, the target master station is created based on a real-time operating system, and the real-time operating system is obtained by pre-configuring a preset non-real-time operating system based on a real-time patch package;

[0111] The first interaction module 503 is used to perform data interaction with the target master station based on the target thread when it receives a target signal sent by the target master station indicating that the slave station configuration is complete.

[0112] The master station control device provided in this embodiment of the invention obtains the device configuration information corresponding to the slave station from a pre-configured user-mode shared memory; sends a start signal to the target master station and sends the device configuration information to the target master station's storage unit; the device configuration information is used by the target master station to configure the slave station, the target master station is created based on a real-time operating system, and the real-time operating system is obtained by pre-configuring a preset non-real-time operating system based on a real-time patch package; upon receiving a target signal from the target master station indicating that the slave station configuration is complete, data interaction is performed between the target thread and the target master station. In this way, building a real-time operating system through a real-time patch package can more flexibly match the requirements of high-precision and high-speed industrial control platforms. Simultaneously, based on the real-time operating system, data interaction between the target thread and the target master station improves communication stability, and the real-time operating system can improve the preemptibility of the operating system kernel, ensuring that when the master station control program interacts with the target master station through the target thread, kernel resources can be preempted first, reducing the response time of the target operating system kernel and improving the efficiency of data interaction between the master station control program and the target master station.

[0113] Optionally, the first transmitting module 502 includes:

[0114] The first calling module is used to call the thread scheduler through a real-time thread; the thread priority of the real-time thread is greater than the thread priority of the non-real-time thread.

[0115] The second calling module is used to call the encapsulation function in the master station control encapsulation layer through the thread scheduler; the encapsulation function is used to automatically call the PCIe driver, and the PCIe driver is used to send the device configuration information to the storage unit of the target master station based on the PCIe bus.

[0116] Optionally, the target thread includes a first target thread; the first interaction module 503 includes:

[0117] The first acquisition module is used to, upon receiving a first transmission completion signal sent by the PCIe driver, invoke the PCIe driver based on the first target thread to acquire slave-related data from kernel-mode memory; the slave-related data is sent to the kernel-mode memory by the target master station;

[0118] The second acquisition module is used to acquire the target calculation result based on the slave station related data;

[0119] The first sending submodule is used to send the target calculation result to the data buffer of the target master station based on the PCIe driver, and send a second sending completion signal to the target master station; the first sending completion signal and the second sending completion signal are interrupt signals, and the second sending completion signal is used to instruct the target master station to read the target calculation result in the data buffer when the second sending completion signal is received.

[0120] Optionally, the target thread further includes a second target thread; the first interaction module 503 includes:

[0121] The second sending submodule is used to send the first register address corresponding to the first slave station to the target master station based on the second target thread; the first register address is used for the target master station to perform a first operation on the relevant parameters in the register corresponding to the register address of the first slave station, and the first target thread and the second target thread run in parallel.

[0122] Optionally, the target thread further includes a third target thread; the first interaction module 503 includes:

[0123] The third sending submodule is used to send index information to the target master station based on the third target thread; the index information is used by the target master station to perform a second operation on the dictionary object parameter information corresponding to the index information; the second operation is used to configure the motion mode of the second slave station and check the interface connection status of the second slave station, and the first target thread and the third target thread run in parallel.

[0124] The present invention also provides an electronic device, see [link to relevant documentation]. Figure 5 It includes: a processor 601, a memory 602, and a computer program 6021 stored in the memory and executable on the processor. When the processor executes the program, it implements the master station control method of the foregoing embodiments.

[0125] The present invention also provides a readable storage medium, wherein when the instructions in the storage medium are executed by the processor of an electronic device, the electronic device is able to execute the master station control method of the foregoing embodiments.

[0126] As the device embodiment is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be found in the description of the method embodiment.

[0127] The algorithms and displays provided herein are not inherently related to any particular computer, virtual system, or other device. Various general-purpose systems can also be used in conjunction with the teachings herein. The required structure for constructing such systems is apparent from the above description. Furthermore, this invention is not directed to any particular programming language. It should be understood that the contents of the invention described herein can be implemented using various programming languages, and the above description of specific languages ​​is for the purpose of disclosing the best mode of implementation of the invention.

[0128] Numerous specific details are set forth in the specification provided herein. However, it will be understood that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures, and techniques have not been shown in detail so as not to obscure the understanding of this specification.

[0129] Similarly, it should be understood that, in order to simplify the invention and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof. However, this disclosure should not be construed as reflecting an intention that the claimed invention requires more features than are expressly recited in each claim. Rather, as reflected in the following claims, inventive aspects lie in fewer than all features of a single foregoing disclosed embodiment. Therefore, the claims following the detailed description are hereby expressly incorporated into this detailed description, wherein each claim itself is a separate embodiment of the invention.

[0130] Those skilled in the art will understand that modules in the device of the embodiments can be adaptively changed and placed in one or more devices different from that embodiment. Modules, units, or components in the embodiments can be combined into a single module, unit, or component, and further, they can be divided into multiple sub-modules, sub-units, or sub-components. Except where at least some of such features and / or processes or units are mutually exclusive, any combination can be used to combine all features disclosed in this specification (including the accompanying claims, abstract, and drawings) and all processes or units of any method or device so disclosed. Unless expressly stated otherwise, each feature disclosed in this specification (including the accompanying claims, abstract, and drawings) may be replaced by an alternative feature that serves the same, equivalent, or similar purpose.

[0131] The various component embodiments of the present invention can be implemented in hardware, or as software modules running on one or more processors, or a combination thereof. Those skilled in the art will understand that microprocessors or digital signal processors (DSPs) can be used in practice to implement some or all of the functions of some or all of the components in the sorting device according to the present invention. The present invention can also be implemented as a device or apparatus program for performing part or all of the methods described herein. Such a program implementing the present invention can be stored on a computer-readable medium, or can be in the form of one or more signals. Such signals can be downloaded from an Internet website, provided on a carrier signal, or provided in any other form.

[0132] It should be noted that the above embodiments are illustrative of the invention and not restrictive, and that those skilled in the art can devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses should not be construed as limiting the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention can be implemented by means of hardware comprising several different elements and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by the same item of hardware. The use of the words first, second, and third, etc., does not indicate any order. These words can be interpreted as names.

[0133] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0134] It should be noted that all actions involving the acquisition of signals, information, or data in this application are carried out in compliance with the relevant data protection laws and policies of the country where the application is located, and with the authorization granted by the owner of the relevant device.

[0135] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

[0136] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.< / deviceinfo>

Claims

1. A master station control method, characterized in that, Applied to the master station control program; the method includes: Retrieve the device configuration information corresponding to the slave station from the pre-configured user-space shared memory; A start signal is sent to the target master station, and the device configuration information is sent to the storage unit of the target master station; the device configuration information is used by the target master station to configure the slave station, the target master station is created based on a real-time operating system, and the real-time operating system is obtained by pre-configuring a preset non-real-time operating system based on a real-time patch package; Upon receiving a target signal from the target master station indicating that the slave station has completed its configuration, data interaction is performed between the target thread and the target master station. The target threads include a first target thread, a second target thread, and a third target thread; the data interaction between the target threads and the target master station includes: Upon receiving the first transmit completion signal from the PCIe driver, the first target thread invokes the PCIe driver to retrieve slave-related data from kernel-mode memory; the slave-related data is sent to the kernel-mode memory by the target master station. Based on the relevant data from the slave station, the target calculation result is obtained; The target calculation result is sent to the data buffer of the target master station based on the PCIe driver, and a second transmission completion signal is sent to the target master station; the first transmission completion signal and the second transmission completion signal are interrupt signals, and the second transmission completion signal is used to instruct the target master station to read the target calculation result in the data buffer when the second transmission completion signal is received; Based on the second target thread, the first register address corresponding to the first slave station is sent to the target master station; the first register address is used for the target master station to perform a first operation on the relevant parameters in the register corresponding to the register address of the first slave station, and the first target thread and the second target thread run in parallel; Based on the third target thread, index information is sent to the target master station; the index information is used by the target master station to perform a second operation on the dictionary object parameter information corresponding to the index information; the second operation is used to configure the motion mode of the second slave station and check the interface connection status of the second slave station, and the first target thread and the third target thread run in parallel.

2. The method according to claim 1, characterized in that, The step of sending the device configuration information to the storage unit of the target master station includes: The thread scheduler is invoked through a real-time thread; the thread priority of the real-time thread is higher than that of the non-real-time thread. The thread scheduler calls the encapsulation function in the master station control encapsulation layer; the encapsulation function is used to automatically call the PCIe driver, and the PCIe driver is used to send the device configuration information to the storage unit of the target master station based on the PCIe bus.

3. The method according to claim 2, characterized in that, The encapsulation function includes a first file and a second file. The first file defines at least two kernel-mode interfaces corresponding to functions, and the second file is used to implement the calls of the kernel-mode interfaces of each function to the interface of the PCIe driver.

4. The method according to claim 1, characterized in that, The device configuration information is obtained by parsing the device configuration file corresponding to the slave station and writing the parsed device configuration information into the user-space shared memory according to a preset matching rule.

5. A master station control device, characterized in that, Applied to the master station control program; the device includes: The first acquisition module is used to acquire the device configuration information corresponding to the slave station from the pre-configured user-mode shared memory; The first sending module is used to send a start signal to the target master station and send the device configuration information to the storage unit of the target master station; the device configuration information is used by the target master station to configure the slave station, the target master station is created based on a real-time operating system, and the real-time operating system is obtained by pre-configuring a preset non-real-time operating system based on a real-time patch package; The first interaction module is used to perform data interaction with the target master station based on the target thread when it receives a target signal sent by the target master station indicating that the slave station has been configured. The target threads include a first target thread, a second target thread, and a third target thread; the first interaction module includes: The first acquisition submodule is used to, upon receiving a first transmission completion signal sent by the PCIe driver, call the PCIe driver based on the first target thread to acquire slave-related data from kernel-mode memory; the slave-related data is sent to the kernel-mode memory by the target master station; The second acquisition submodule is used to acquire the target calculation result based on the slave station related data; The first sending submodule is used to send the target calculation result to the data buffer of the target master station based on the PCIe driver, and send a second sending completion signal to the target master station; the first sending completion signal and the second sending completion signal are interrupt signals, and the second sending completion signal is used to instruct the target master station to read the target calculation result in the data buffer when the second sending completion signal is received; The second sending submodule is used to send the first register address corresponding to the first slave station to the target master station based on the second target thread; the first register address is used for the target master station to perform a first operation on the relevant parameters in the register corresponding to the register address of the first slave station, and the first target thread and the second target thread run in parallel; The third sending submodule is used to send index information to the target master station based on the third target thread; the index information is used by the target master station to perform a second operation on the dictionary object parameter information corresponding to the index information; the second operation is used to configure the motion mode of the second slave station and check the interface connection status of the second slave station, and the first target thread and the third target thread run in parallel.

6. An electronic device, characterized in that, include: A processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the master station control method as described in any one of claims 1-4.

7. A readable storage medium, characterized in that, When the instructions in the storage medium are executed by the processor of the electronic device, the electronic device is able to perform the master station control method according to any one of claims 1-4.