Master station control method and device, electronic equipment and readable storage medium
By building a real-time operating system based on real-time patch packages, the problem that the EtherCAT master station cannot meet the real-time processing requirements is solved, real-time communication and efficient data interaction between the EtherCAT master station and slave station are realized, and the requirements of the high-precision and high-speed industrial control platform are met. .
Patent Information
- Application Number
- CN202411025046.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-29
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2044-07-29
AI Technical Summary
In the prior art, when implementing the EtherCAT master based on a non-real-time system, the real-time processing requirements of the EtherCAT master cannot be met, and real-time communication between the EtherCAT master and the slave cannot be realized.
By building a real-time operating system that configures preset non-real-time operating systems based on real-time patch packages, obtain slave device configuration information, and send configuration information to the target master in the real-time operating system, and use real-time threads to perform data with the target master for data Interaction to ensure real-time and efficient.
Real-time communication between the EtherCAT master and slave station is realized, communication stability and efficiency are improved, the needs of high-precision and high-speed industrial control platform are met, and the response time of the operating system core is reduced.
Smart Images

Figure CN119065834A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a master station control method, device, electronic equipment and readable storage medium. Background Art
[0002] With the development of science and technology, real-time Ethernet represented by EtherCAT bus is constantly occupying the fieldbus market in the industrial control field. It has the characteristics of high performance, fast speed, and support for multiple network topologies.
[0003] In the related art, when the EtherCAT master station is implemented based on a non-real-time system, it is necessary to provide system resources to the requester according to the processing order of the operating system kernel itself (such as the receiving time order). This cannot meet the real-time processing requirements of the EtherCAT master station. Therefore, a real-time operating system is urgently needed to implement the EtherCAT master station to meet the real-time communication between the EtherCAT master station and the slave station. Summary of the invention
[0004] In order to overcome the problems existing in the related art, 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, which is applied to a master station control program; the method comprises:
[0006] Obtain the device configuration information corresponding to the slave station from the pre-configured user-mode shared memory;
[0007] 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, and the real-time operating system is pre-configured based on a real-time patch package to a preset non-real-time operating system;
[0008] When receiving a target signal sent by the target master station indicating that the configuration of the slave station is completed, data interaction is performed with the target master station based on a target thread.
[0009] Optionally, the sending the device configuration information to a storage unit of the target master station includes:
[0010] Calling a 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;
[0011] The encapsulation function in the master station control encapsulation layer is called 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.
[0012] Optionally, the encapsulation function includes a first file and a second file, wherein the first file defines kernel-mode interfaces corresponding to at least two functions, and the second file is used to implement the calling of the kernel-mode interface of each function to the interface of the PCIe driver.
[0013] Optionally, the target thread includes a first target thread; and the data interaction with the target main station based on the target thread includes:
[0014] In the case of receiving a first sending completion signal sent by the PCIe driver, calling the PCIe driver based on the first target thread to obtain slave station related data from the kernel state memory; the slave station related data is sent by the target master station to the kernel state memory;
[0015] Based on the slave station related data, obtaining a target calculation result;
[0016] The target calculation result is sent to the data buffer of the target master station based on the PCIe driver, and a second sending completion signal is sent 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 receiving the second sending completion signal.
[0017] Optionally, the target thread further includes a second target thread; and the data interaction with the target main station based on the target thread further includes:
[0018] Based on the second target thread, a 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 relevant parameters in the register corresponding to the register address of the first slave station, and the first target thread is parallel to the second target thread.
[0019] Optionally, the target thread further includes a third target thread; and the data interaction with the target main station based on the target thread further includes:
[0020] Based on the third target thread, index information is sent to the target master station; the index information is used for 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 is parallel to the third target thread.
[0021] Optionally, the device configuration information is obtained by parsing a device configuration file corresponding to the slave station, and writing the parsed device configuration information into a user state shared memory according to a preset matching rule.
[0022] In a second aspect, the present invention provides a master station control device, which is applied to a master station control program; the device comprises:
[0023] A first acquisition module is used to acquire device configuration information corresponding to the slave station from a pre-configured user state shared memory;
[0024] A first sending module is used to send a start signal to a target master station and send 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, and the real-time operating system is pre-configured based on a real-time patch package to a preset non-real-time operating system;
[0025] The first interaction module is used to perform data interaction with the target master station based on a target thread when receiving a target signal sent by the target master station indicating that the configuration of the slave station is completed.
[0026] Optionally, the first sending module includes:
[0027] The first calling module is used to call the thread scheduler through the 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; and the first interaction module includes:
[0030] A first acquisition module is used to call the PCIe driver based on the first target thread to acquire slave station related data from the kernel state memory when receiving a first sending completion signal sent by the PCIe driver; the slave station related data is sent by the target master station to the kernel state memory;
[0031] A second acquisition module, used for acquiring a 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 main station based on the PCIe driver, and send a second sending completion signal to the target main 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 main station to read the target calculation result in the data buffer when receiving the second sending completion signal.
[0033] Optionally, the target thread further includes a second target thread; and 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 is parallel to the second target thread.
[0035] Optionally, the target thread further includes a third target thread; and 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 for 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 is parallel to the third target thread.
[0037] In a third aspect, 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, wherein the processor implements the master station control method described in any one of the first aspects when executing the program.
[0038] In a fourth aspect, the present invention provides a readable storage medium. When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute the steps in the master station control method in any one of the embodiments of the first aspect above.
[0039] In the embodiment of the present invention, the device configuration information corresponding to the slave station is obtained from the pre-configured user-state 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 for 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 pre-configured based on a real-time patch package to obtain a preset non-real-time operating system; when a target signal sent by the target master station indicating that the configuration of the slave station is completed is received, data interaction is performed with the target master station based on the target thread. In this way, by constructing a real-time operating system through a real-time patch package, the requirements of a high-precision and high-speed industrial control platform can be more flexibly matched. At the same time, based on the real-time operating system, data interaction is performed with the target master station through the target thread, which improves the stability of communication, and the real-time operating system can improve the preemptibility of the operating system kernel, ensuring that when the master station control program and the target master station are interacting with each other through the target thread, kernel resources can be preempted first, the response time of the target operating system kernel is reduced, and the efficiency of data interaction between the master station control program and the target master station is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0041] Figure 1 is a step flow chart of a master station control method provided by an embodiment of the present invention;
[0042] Figure 2 A control framework diagram of a target master station provided by an embodiment of the present invention is shown in FIG.
[0043] Figure 3 It is an operation flow chart of a master station control program provided by an embodiment of the present invention;
[0044] Figure 4 is a structural diagram of a master station control device provided by an embodiment of the present invention;
[0045] Figure 5 It is a structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0046] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0047] Figure 1 The present invention provides a flow chart of the steps of a master station control method, which is applied to a master station control program. The master station control program can be determined based on a real-time PCIe driver module, and the master station control program can implement different functions by calling an interface, such as start, configuration, activation, stop, data interaction, interrupt interaction, and the like.
[0048] The functional APIs that can be implemented by the master station control program are as follows:
[0049] EC_Master_start: Master start function, this function sends the master start signal, and the FPGA master enters the PREOP stage from the INIT stage;
[0050] EC_Master_config: Master configuration function. This function is used before the master is activated to transfer the required configuration data to the FPGA master.
[0051] EC_Master_active: Master activation function, indicating that the data required by the FPGA master has been transmitted, and the FPGA master enters the OP stage from the PREOP stage;
[0052] EC_Master_run: Process data interaction function. This function is executed after all slaves have entered OP, indicating the start of process data interaction.
[0053] EC_Master_stop: Master stop function, this function will stop the FPGA master station from running;
[0054] EC_sdo_read: Read COE dictionary parameter information according to SDO index and sub-index;
[0055] EC_sdo_write: Modify COE dictionary parameter information according to SDO index and sub-index;
[0056] EC_reg_read: reads relevant REG parameter information according to the REG address;
[0057] EC_reg_write: Modify the relevant REG parameter information according to the REG address;
[0058] EC_send_process: Send process data function, send process data to FPGA master station;
[0059] EC_receive_process: Receive process data function, receives process data from the FPGA master station;
[0060] EC_receive_error_info: Receive error reporting function. When a problem occurs at a slave station, the slave station with the problem and the status code will be transmitted.
[0061] like Figure 1 As shown, the method may include:
[0062] Step 101: Obtain device configuration information corresponding to the slave station from the pre-configured user-mode shared memory.
[0063] In an embodiment of the present invention, the device configuration information corresponding to the slave station is stored in the user-state shared memory, and the device configuration information is used for the target master station to initialize and configure the slave station based on the device configuration information. The device configuration information can be obtained by pre-parsing the device configuration file corresponding to the slave station, and the device configuration information can include the device ID corresponding to the slave station, the motion state corresponding to the slave station, the IO point data corresponding to the slave station, etc. Among them, the device configuration file can be a device configuration file in XML format, and the device configuration file can be determined based on the analysis of the ESI file of the EtherCAT slave station device. The device configuration file is used to describe the device information of the EtherCAT slave station. For example, the device configuration file can include three elements such as the basic device information corresponding to the slave station, the basic data type, and the object dictionary description. After parsing the device configuration file, the device configuration information is written into the user-state shared memory according to the preset matching rules. Among them, the preset matching rules can include writing the parsed device configuration information into a pre-defined DeviceInfo structure, and storing data based on the DeviceInfo structure.
[0064] Exemplarily, the steps of obtaining device configuration information and writing the device configuration information into the user-mode shared memory may be: creating a DeviceInfo structure according to information acquisition requirements, the DeviceInfo structure is used to store the device configuration information parsed from the device configuration file, and pre-defining the device configuration information in the DeviceInfo structure, such as ProductCode and RevisionNo, dictionary and IO data, etc. The information acquisition requirements may be determined based on the information required by the target master station when configuring the slave station.
[0065] The device configuration file is parsed by an XML file parser, wherein the XML file parser may be determined based on the writing of a parse_EtherCAT_XML function, which is used to parse the device configuration file through the TinyXML2 library. Specifically, an XMLDocument object of TinyXML2 may be created, the device configuration file may be loaded, the root element may be obtained, its child elements may be traversed, keywords may be extracted from each element, and it may be determined whether the extracted keywords match the pre-defined device configuration information in the DeviceInfo structure, and if so, the matching content may be 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 with the key, and use the shmat function to attach the shared memory segment to the current process and create a std::vector <deviceinfo>The shared memory segment is associated with a pointer of type sharedData. Among them, the shared memory segment is configured at the user level, so the shared memory segment can be a user-mode shared memory, and the current process refers to the process running the XML file parser. Create the DeviceInfo structure member devices, and call the written parse_EtherCAT_XML function, passing the parameters as the path of the device configuration file and the devices variable. After the processing is completed, use *sharedData=devices to assign values to the corresponding blocks in the shared memory, and the information storage is completed. Finally, use shmdt(sharedData) to separate the current process from the shared memory segment to ensure that other processes can access the shared memory segment.
[0067] The master station control program obtains the device configuration information corresponding to the slave station from the user state shared memory, and sends the device configuration information to the target master station so that the target master station can initialize 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 for 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 pre-configured based on a real-time patch package to obtain a preset non-real-time operating system.
[0069] In an embodiment of the present 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 in an MSI-X interrupt mode based on the PCIe protocol, and sends the device configuration information to the storage unit of the target master station. Among them, the start signal is used to indicate that the target master station is in an initialization configuration state, that is, entering a PREOP state from an INIT state. The device configuration information is sent to the target master station, and the device configuration information is stored in the storage unit of the target master station. Among them, the storage unit can be a random access memory (Random Access Memory, RAM). Exemplarily, the master station control program can first use EC_Master_start() to send a start signal to the target master station, and then use EC_Master_config() to transfer the device configuration information to the RAM of the target master station. If the device configuration information has been transmitted, EC_Master_active() is used to notify the target master station that the data transmission is complete, otherwise continue to wait for data transmission.
[0070] The target master station is created based on a real-time operating system, which is obtained by pre-configuring the preset non-real-time operating system based on a real-time patch package. The target master station can be an FPGA master station, the real-time operating system can be an RT-Linux operating system based on the x86 platform, and the preset non-real-time operating system can be a Linux operating system. By configuring the preset non-real-time operating system based on the real-time patch package, an RT-Linux operating system based on the x86 platform can be built to support the EtherCAT-based target master station to flexibly access the system in the form of a PCIe device. The real-time operating system can respond to external events and process tasks within strict time limits. By adopting a task scheduling strategy based on priority and deadline, it can ensure that high-priority tasks can be executed first, so that critical tasks can be completed within a limited time.
[0071] Exemplarily, a preset non-real-time operating system, such as a Linux operating system, is obtained. According to a stable Linux operating system version, a real-time kernel patch is applied to the preset non-real-time operating system based on the real-time patch package RT Patch. Assuming that the Linux operating system is 4.19 as an example, the real-time patch package RT Patch can select the patch-4.19-rt.patch.xz file, and decompress and compile the Linux source code and RT Patch package respectively. Use the patch-p1<[patch path] / patch-4.19-rt.patch.xz command to apply the real-time kernel patch to the Linux operating system kernel, and use the make menuconfig command to customize the kernel for cutting and configuration. Specifically, first select "FullyPreemptible Kernel (Real-time)" in "Preemption Model". In "General setup->Timers subsystem", select "High resolution Timer Support" to use 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 root directory of the Linux source code and comment it out. Use the make->make install->make modules_install command to compile the Linux kernel in sequence, then enter the Linux source code / boot directory, and use the mkinitramfs-ko initrd.img-4.19-rt 4.19-rt command to create a boot boot to build the RT-Linux real-time operating system. In this way, the real-time preemption patch (PREEMPT-RT patch) can make the kernel more lightweight, minimize the amount of modified code, and realize the preemption improvement of code sequences such as critical sections, interrupt handling functions, and interrupt shutdown. At the same time, the x86 platform can use the high-speed PCIe bus for communication between the target master station and the master station control system, which is conducive to the rapid replacement and compatibility between different master station devices, making the platform compatible with a wider coverage.
[0072] Step 103: upon receiving a target signal sent by the target master station indicating that the slave station configuration is complete, data is exchanged with the target master station based on a target thread.
[0073] In an embodiment of the present invention, after the master station control program transfers the device configuration information to the storage unit of the target master station, that is, after the data transmission of the device configuration information is completed, the master station control program will send a data transmission completion signal to the target master station in an MSI-X interrupt mode based on the PCIe protocol. When the target master station receives the data transmission completion signal, the target master station will initialize the configuration of the slave station based on the device configuration information, so that the slave station enters the running state (OP state). When all the slave stations enter the running state, the target master station will send a target signal to the master station control program, and the target signal can be an OP state signal, which is used to characterize the completion of the initialization configuration of the slave station. When the master station control program receives the target signal sent by the target master station, it can start data interaction with the target master station based on the target thread. Specifically, the process data interaction between the master station control program and the target master station can be started through the EC_Master_run function. 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 priority of the thread is high, then the kernel (Linux Kernel) of the real-time operating system can be preempted and called for data interaction. Among them, the target thread can include at least two real-time threads, at least two threads can be parallel real-time threads, different threads can be used to execute different tasks to achieve different functions, each task can run independently without interfering with each other, for example, motion state adjustment or slave station status detection and other functions.
[0074] In summary, in the embodiment of the present invention, the device configuration information corresponding to the slave station is obtained from the pre-configured user-state 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 for the target master station to configure the slave station, the target master station is created based on the real-time operating system, and the real-time operating system is pre-configured based on the real-time patch package to obtain the preset non-real-time operating system; when the target signal sent by the target master station indicating that the configuration of the slave station is completed is received, data interaction is performed with the target master station based on the target thread. In this way, by constructing a real-time operating system through a real-time patch package, the requirements of a high-precision and high-speed industrial control platform can be more flexibly matched. At the same time, based on the real-time operating system, data interaction is performed with the target master station through the target thread, which improves the stability of communication, and the real-time operating system can improve the preemptibility of the operating system kernel, ensuring that when the master station control program and the target master station are interacting with each other through the target thread, kernel resources can be preempted first, the response time of the target operating system kernel is reduced, and the efficiency of data interaction between the master station control program and the target master station is improved.
[0075] Optionally, step 102 may include the following steps:
[0076] Step 201: Call a 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 an embodiment of the present invention, the real-time operating system may include a thread scheduler (RT Scheduler), and the ready-made scheduler is used to allocate tasks based on thread priority. The master station control program calls the thread scheduler through the real-time thread. Specifically, an API call can be initiated to the thread scheduler based on the real-time thread. The thread priority of the real-time thread is greater than the thread priority of the non-real-time thread. The thread scheduler determines that the real-time thread priority is high, and allows it to preempt the real-time operating system kernel Linux Kernel for priority operation. That is to say, if there is a non-real-time thread in progress 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 an embodiment of the present invention, after determining that the priority of the real-time thread is high, the thread scheduler preferentially calls the encapsulation function of the master station control encapsulation layer in the real-time operating system kernel. Among them, the PCIe driver can be a real-time PCIe driver, for example, an open source project provided by Xilinx is used, and the driver provides a PCIe communication IP core XDMA. According to at least two functions required by the target master station, such as start, configuration, activation, stop, data interaction, interrupt interaction and other functions, the open source API provided by Xilinx is functionally integrated, and when the thread scheduler schedules the process to seize the kernel and calls the PCIe driver in real time, a master station control encapsulation layer is added. The master station control encapsulation layer is at the kernel state level, which is convenient for the user state master station control program API to directly call, facilitates later debugging and improves the code running stability. The master station control encapsulation layer contains an encapsulation function, which can be a function that is functionally integrated for the open source PCIe driver API provided by Xilinx and encapsulated so as to be called by the upper layer. The encapsulation function may include a first file and a second file, the first file defines a kernel state interface corresponding to at least two functions, and the second file is used to implement the kernel state interface of each function to call the interface of the PCIe driver. The first file can be a header file, and the second file can be a c file. Specifically, a new header file and a c file can be added to the kernel source code, wherein the header file contains at least two functions that are integrated and encapsulated into a function definition, and the c file is responsible for the specific implementation of each function function. Exemplarily, the header file can define a kernel state interface corresponding to at least two functions, such as a kernel state API for functions such as start, configuration, activation, stop, data interaction, and interrupt interaction, and the c file is used to implement the kernel state interface of each function to call the interface of the PCIe driver. For example, each kernel state API can call the interface provided by the PCIe driver according to different functions. Further, atomic code measures can be added to the c file to prevent the risk of dirty reading of parallel calls and prevent the disorder phenomenon when multiple tasks call shared APIs. For example, for some shared function codes, only when one task completes the function call can another task perform the operation, otherwise it can only wait in line. Among them, the kernel state interface is used by the user state API of the master station control program, which facilitates later debugging and improves the stability of code operation, and can avoid data dirty reading problems.
[0080] The encapsulation function is used to automatically call the PCIe driver, and the PCIe driver will send the device configuration information to the storage unit of the target master station based on the PCIe bus. Exemplarily, the PCIe driver will save the device configuration information to the kernel state memory, and then notify the real-time operating system extension / plug-in (RT-Linux Plugin) through the input and output interface (I / O) to send the device configuration information to the target master station based on the PCIe bus. Specifically, after the real-time operating system extension / plug-in (RT-Linux Plugin) receives the data transmission completion signal sent by the PCIe driver in the MSI-X interrupt mode based on the PCIe protocol, the device configuration information is sent to the target master station, and the target master station initializes the configuration of the slave station based on the device configuration information, and after the slave station completes the initialization configuration, it sends a target signal to the master station control program.
[0081] In the embodiment of the present invention, the target master station is implemented by using the RT-Linux operating system based on the x86 platform, and data can be transmitted through the PCIe bus, thereby improving the compatibility and adaptability of the platform. At the same time, the PCIe bus also has extremely high scalability. The FPGA master station board can be inserted into the x86 motherboard through the PCIe interface, so as to flexibly change the external device. Compared with the hardware integration of the ARM platform, the embodiment of the present invention is conducive to the rapid replacement and compatibility between different master station devices, making the platform compatible with a wider coverage. In addition, using the PCIe bus to communicate between the x86 platform and the FPGA master station allows MSI interrupts and IO data to be transmitted on the same bus, increasing work 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 a first sending completion signal sent by a PCIe driver, calling the PCIe driver based on the first target thread, and obtaining slave station related data from the kernel state memory; the slave station related data is sent by the target master station to the kernel state memory.
[0084] In an embodiment of the present invention, the target master station obtains slave station related data from the slave station, wherein the slave station related data may include slave station position data or slave station speed data. The target master station transmits the slave station related data to a real-time operating system extension / plug-in (RT-Linux Plugin) based on a PCIe bus, and then the real-time operating system extension / plug-in (RT-Linux Plugin) transmits the slave station related data to a PCIe driver through an input and output interface. After receiving a data transmission completion signal sent by the RT-Linux Plugin, the PCIe driver stores the slave station related data in a kernel state memory.
[0085] The PCIe driver will send a first sending completion signal to the master station control program in an MSI-X interrupt mode based on the PCIe protocol. When the master station control program receives the first sending completion signal, it will initiate a first target thread to call the PCIe driver to obtain the slave station related data stored in the kernel state memory. The first sending completion signal can be an interrupt signal, such as a data transmission completion signal (MSI-X). The first target thread is a real-time thread. The thread scheduler is called through the first target thread, so that the thread scheduler calls the encapsulation function in the master station control encapsulation layer to obtain the slave station related data in the kernel state memory.
[0086] Step 302: Obtain target calculation results based on the slave station related data.
[0087] In the embodiment of the present invention, after receiving the slave station related data, the master station control program determines the target calculation result based on the preset calculation rule. Exemplarily, the target calculation result can be used to adjust the motion state of the slave station. It is understandable that the step of calculating the target calculation result based on the slave station related data can refer to the prior art, and the embodiment of the present invention will not be repeated.
[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 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 receiving the second sending completion signal.
[0089] In an embodiment of the present invention, the target calculation result is sent to the data buffer of the target master station based on the PCIe driver, wherein the data buffer may be a first-in-first-out memory (FIFO). After the transmission of the target calculation result is completed, a second transmission completion signal is sent to the target master station. The second transmission completion signal may be an interrupt signal, such as a data transmission completion signal (MSI-X), and the second transmission completion signal is used to indicate that the target master station reads the target calculation result in the data buffer when receiving the second transmission completion signal, and sends the target calculation result to the slave station to adjust the motion state of the slave station.
[0090] In the embodiment of the present invention, by building an x86 RT-Linux environment and constructing a real-time operating system to enable the real-time function, the target master station can realize the data transmission of slave station related data and target calculation results based on the PCIe bus, thereby improving the 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 a first register address corresponding to a 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 relevant parameters in a register corresponding to the register address of the first slave station, and the first target thread is parallel to the second target thread.
[0093] In an embodiment of the present invention, based on the second target thread, the data timeout and packet loss of the slave station can be detected. Specifically, the first register address of the first slave station that needs to detect the data timeout and packet loss is determined. Among them, the first slave station may include one or more slave stations. When the first slave station includes multiple slave stations, the register address of each slave station is obtained respectively as the first register address. The first register address is sent to the target master station through the second target thread. Specifically, the thread scheduler can be called by the second target thread, so that the thread scheduler calls the encapsulation function in the master station control encapsulation layer. The encapsulation function will automatically call the PCIe driver. The PCIe driver will save the first register address to the kernel state memory, and then notify the real-time operating system extension / plug-in (RT-Linux Plugin) through the input and output interface (I / O) to send the first register address to the target master station based on the PCIe bus. Specifically, after the real-time operating system extension / plug-in (RT-Linux Plugin) receives the data transmission completion signal sent by the PCIe driver in the MSI-X interrupt mode based on the PCIe protocol, the first register address is sent to the target master station. The target host performs a first operation on the relevant parameters in the register corresponding to the first register address based on the first register address. The first operation may include acquiring and modifying the relevant parameters in the register corresponding to the first register address.
[0094] Exemplarily, the second target thread may 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, so as to detect whether datagram timeout and packet loss occur.
[0095] Optionally, the at least two target threads further include a third target thread. Step 103 may include the following steps:
[0096] Step 501: Based on the third target thread, index information is sent to the target main station; the index information is used by the target main station to perform a second operation on the dictionary object parameter information corresponding to the index information; the first target thread is parallel to the third target thread.
[0097] In an embodiment of the present invention, based on the third target thread, tasks such as configuring the motion mode of the slave station and checking the connection status of the physical interface can be performed. Specifically, according to the configuration requirements or the inspection requirements, the index information corresponding to the object to be configured or inspected, such as the SDO index and the sub-index, is determined and sent to the target master station based on the third index information. Specifically, the thread scheduler can be called by the third target thread, so that the thread scheduler calls the encapsulation function in the control encapsulation layer of the master station, and the encapsulation function automatically calls the PCIe driver. The PCIe driver saves the index information to the kernel state memory, and then notifies the real-time operating system extension / plug-in (RT-Linux Plugin) through the input and output interface (I / O) to send the index information to the target master station based on the PCIe bus. Specifically, after the real-time operating system extension / plug-in (RT-Linux Plugin) receives the data transmission completion signal sent by the PCIe driver in the MSI-X interrupt mode based on the PCIe protocol, the index information is sent 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, and the second operation includes a data acquisition operation, a data modification operation, etc. The second operation is used to configure the motion mode of the slave station and to check the interface connection status of the slave station.
[0098] Exemplarily, the third target thread may use the EC_sdo_read() function to read the COE dictionary parameter information, and / or use the EC_sdo_write() function to modify the COE dictionary parameter information, so as to configure the slave motion mode and check the physical interface connection status in real time.
[0099] In the embodiment of the present invention, the second target thread and the third target thread running in parallel with the first target thread can monitor or configure the relevant parameters and the 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 figure, it includes the user layer, kernel layer and hardware layer. Figure 2 The master station control method of the embodiment of the present invention is generally described as follows:
[0101] User layer: After the device configuration file passes through the XML file parsing program, the device configuration information is obtained and stored in the user-state shared memory. The master station control program retrieves the data in the user-state shared memory, and then initiates kernel calls based on the APIs of different functions to implement different functions.
[0102] Kernel layer: Assuming that the master control application needs to execute a function, it will initiate an API call to the RT Scheduler through a real-time thread. As a scheduler, the RT Scheduler determines that the real-time thread has a high priority and allows it to preempt the Linux Kernel for priority operations. If there is a non-real-time thread in progress in the system, it will be interrupted directly and the kernel will be preempted by the real-time thread. Then the corresponding encapsulation function in the master control API encapsulation layer will be called. The encapsulation function will call the corresponding PCIe driver by itself. The PCIe driver will save the user-mode data sent by the master control program to the kernel-mode memory, and notify the RT-Linux Plugin through the I / O interface to execute interrupt transmission or send data to the FPGA master.
[0103] Hardware layer: The data and PCIe interrupt level signals are uniformly transmitted to the data buffer (FIFO) of the FPGA master station through the PCIe 2.0x4 hardware wiring.
[0104] like Figure 2 As shown in the figure, each signal sent by the FPGA master to the real-time operating system (RT-Linux) (such as OP status signal, data transmission completion signal, etc.) and the signal sent by RT-Linux to the FPGA master (such as master start signal, master activation signal, data transmission completion signal, etc.) are all MSI-X interrupts of the PCIe protocol. During the communication process, both the FPGA master and RT-Linux realize interrupt and data transmission through the PCIe2.0 bus. Further, as Figure 2 As shown in the figure, the data interaction between the XML file parser and the shared memory of the master station control program belongs to inter-process communication, and 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, and there are threads "ordinary thread 1 and RT thread 1" in the process to implement the function. The master station control program is a real-time RT thread, and the XML file parser is a normal thread. The two processes exchange data through shared memory.
[0105] For example, Figure 3 A flow chart of the operation of the master station control program is shown in FIG. Figure 3 As shown, based on the XML configuration file, start the XML file parsing program, open the user-mode shared memory, ensure that the device configuration information has been fully parsed and written into the user-mode shared memory, and then start the master control program; the master control program reads the device configuration information from the user-mode shared memory, first uses EC_Master_start() to send a start signal to the target master, and then uses EC_Master_config() to transfer the configuration data to the RAM (storage unit) of the FPGA (target master). If the device configuration information has been transmitted, use EC_Master_active() to notify the FPGA master that the data transmission is complete, otherwise continue to wait for data transmission. Wait for the FPGA master to put all slaves into the OP state. After receiving the slave OP signal (the target signal sent by the target master), use EC_Master_run() to start the data interaction process with the FPGA master, based on 2 target threads working together:
[0106] Thread 1: Used to implement data interaction between RT-Linux and the FPGA master station for adjusting the slave station motion state. Specifically, RT-Linux uses ec_receive_process() to receive the slave station position / speed information sent by the FPGA master station and stores it in the kernel state memory. After the next position / speed calculation, ec_send_process() is used to send the slave station position / speed information to the FIFO of the FPGA master station, so that the FPGA master station can control the slave station to update the motion state. If you no longer want to continue communication, use EC_Master_stop to stop the FPGA master station.
[0107] Thread 2: used to detect whether datagram timeout and packet loss occur, configure slave motion mode in real time, check physical interface connection, etc. Specifically, this thread can use ec_sdo_read() to read COE dictionary parameter information, and use ec_sdo_write() to modify COE dictionary parameter information, which is used to configure slave motion mode in real time and check physical interface connection; or use ec_reg_read() to read slave register related parameter status, and use ec_reg_write() to modify register parameters, which is used to detect whether datagram timeout and packet loss occur. If you do not want to continue communication, use EC_Master_stop to stop the FPGA master.
[0108] Figure 3 Schematic diagram of the structure of a master station control device provided by an embodiment of the present invention, which is applied to a master station control program; Figure 3 As shown, the device may specifically include:
[0109] The first acquisition module 501 is used to acquire device configuration information corresponding to the slave station from a 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 for 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 pre-configured based on a real-time patch package to a preset non-real-time operating system;
[0111] The first interaction module 503 is configured to perform data interaction with the target master station based on a target thread when receiving a target signal sent by the target master station indicating that the configuration of the slave station is completed.
[0112] The master station control device provided by the embodiment of the present invention obtains the device configuration information corresponding to the slave station from the pre-configured user state shared memory; sends a start signal to the target master station, and sends the device configuration information to the 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, and the real-time operating system is pre-configured based on a real-time patch package to obtain a preset non-real-time operating system; when receiving a target signal sent by the target master station indicating that the configuration of the slave station is completed, data interaction is performed with the target master station based on the target thread. In this way, by constructing a real-time operating system through a real-time patch package, the requirements of a high-precision and high-speed industrial control platform can be more flexibly matched. At the same time, based on the real-time operating system, data interaction is performed with the target master station through the target thread, which improves the stability of communication, and the real-time operating system can improve the preemptibility of the operating system kernel, ensuring that when the master station control program and the target master station are interacting with each other through the target thread, kernel resources can be preempted first, the response time of the target operating system kernel is reduced, and the efficiency of data interaction between the master station control program and the target master station is improved.
[0113] Optionally, the first sending module 502 includes:
[0114] The first calling module is used to call the thread scheduler through the 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; and the first interaction module 503 includes:
[0117] A first acquisition module is used to call the PCIe driver based on the first target thread to acquire slave station related data from the kernel state memory when receiving a first sending completion signal sent by the PCIe driver; the slave station related data is sent by the target master station to the kernel state memory;
[0118] A second acquisition module, used for acquiring a 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 main station based on the PCIe driver, and send a second sending completion signal to the target main 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 main station to read the target calculation result in the data buffer when receiving the second sending completion signal.
[0120] Optionally, the target thread further includes a second target thread; and 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 is parallel to the second target thread.
[0122] Optionally, the target thread further includes a third target thread; and 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 for 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 is parallel to the third target thread.
[0124] The present invention also provides an electronic device, see Figure 5 , including: a processor 601, a memory 602, and a computer program 6021 stored in the memory and executable on the processor, wherein the processor implements the master station control method of the aforementioned embodiment when executing the program.
[0125] The present invention also provides a readable storage medium. When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute the master station control method of the aforementioned embodiment.
[0126] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0127] The algorithm and display provided herein are not inherently related to any particular computer, virtual system or other device. Various general purpose systems can also be used together with the teachings based on this. According to the above description, it is obvious that the structure required for constructing such systems. In addition, the present invention is not directed to any specific programming language either. It should be understood that various programming languages can be utilized to realize the content of the present invention described herein, and the description of the above specific languages is for disclosing the best mode of the present invention.
[0128] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.
[0129] Similarly, it should be understood that in order to streamline the present invention and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, the various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting the following intention: that the claimed invention requires more features than the features explicitly recited in each claim. More specifically, as reflected in the claims below, inventive aspects lie in less than all the features of the individual embodiments disclosed above. Therefore, the claims that follow the specific embodiment are hereby expressly incorporated into the specific embodiment, with each claim itself serving as a separate embodiment of the present invention.
[0130] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.
[0131] The various component embodiments of the present invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It should be understood by those skilled in the art that a microprocessor or digital signal processor (DSP) may 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 may also be implemented as a device or apparatus program for executing part or all of the methods described herein. Such a program for implementing the present invention may be stored on a computer-readable medium, or may be in the form of one or more signals. Such a signal may be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.
[0132] It should be noted that the above embodiments illustrate the present invention rather than limit it, and that those skilled in the art may devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets shall not be construed as a limitation on the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present invention may be implemented by means of hardware comprising a number of different elements and by means of a suitably programmed computer. In a unit claim enumerating a number of devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc., does not indicate any order. These words may be interpreted as names.
[0133] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0134] It should be noted that all actions of acquiring signals, information or data in this application are carried out in compliance with the relevant data protection laws and policies of the country where they are located and with the authorization given by the owner of the corresponding 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 in the protection scope of the present invention.
[0136] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection 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: Get the device configuration information corresponding to the slave station from the pre-configured user-mode 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 by the target master station to configure the slave station, the target master station being created based on a real-time operating system, the real-time operating system being pre-configured from a preset non-real-time operating system based on a real-time patch package; When a target signal indicating that the slave station configuration is complete is received from the target master station, data is exchanged with the target master station based on a target thread.
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: Calling a 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; The encapsulation function in the master station control encapsulation layer is called 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.
3. The method according to claim 2, characterized in that The encapsulation function includes a first file and a second file, wherein the first file defines kernel-mode interfaces corresponding to at least two functions, and the second file is used to implement the calling of the kernel-mode interface of each function to the interface of the PCIe driver.
4. The method according to claim 1, wherein The target thread includes a first target thread; and the data interaction with the target main station based on the target thread includes: Upon receiving a first sending completion signal sent by the PCIe driver, calling the PCIe driver based on the first target thread to obtain slave station related data from the kernel state memory; the slave station related data is sent by the target master station to the kernel state memory; Based on the slave station related data, obtaining a target calculation result; The target calculation result is sent to the data buffer of the target master station based on the PCIe driver, and a second sending completion signal is sent 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.
5. The method according to claim 4, characterized in that The target thread further includes a second target thread; and the data interaction with the target master station based on the target thread further includes: Based on the second target thread, a 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 relevant parameters in the register corresponding to the register address of the first slave station, and the first target thread is parallel to the second target thread.
6. The method according to claim 4 or 5, characterized in that The target thread further includes a third target thread; and the data interaction with the target main station based on the target thread further includes: Based on the third target thread, index information is sent to the target master station; the index information is used for 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 is parallel to the third target thread.
7. 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 state shared memory according to a preset matching rule.
8. A master station control device, characterized in that: Applicable to the master station control program; the device includes: A first acquisition module is used to obtain device configuration information corresponding to the slave station from a pre-configured user-state shared memory; A first sending module is configured to send a start signal to a target master station and send the device configuration information to a 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 pre-configured from a preset non-real-time operating system based on a real-time patch package; The first interaction module is configured to perform data interaction with the target master station based on a target thread when a target signal indicating that the configuration of the slave station is completed and sent by the target master station is received.
9. 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 implements the master station control method according to any one of claims 1 to 7 when executing the program.
10. A readable storage medium, characterized in that: When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the master station control method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Design method of master / slave station card for implementing Powerlink industrial real-time Ethernet communication
CN108650136A
Design method of master / slave station cards for implementing Powerlink industrial real-time Ethernet communication
CN108833241A
Multi-axis motion control system for dual-channel bus communication
CN112147927A
Industrial robot general control and debugging system based on EtherCAT
CN117706989A
Modular computer system
US3419849A
