PLC equipment self-adaption method based on SPI equipment tree
A set of SPI device trees supports the loading of multiple PLC device drivers, solving the problems of cumbersome PLC device driver loading and difficult device tree updates, simplifying the process and improving reliability.
Patent Information
- Application Number
- CN202511281213.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-09
- Publication Date
- 2025-10-17
AI Technical Summary
In the prior art, the PLC device driver loading process is cumbersome and not conducive to the modification and update of the device tree.
A set of SPI device trees is used to support multiple PLC device drivers at the same time. The device driver to be loaded is identified by configuring the cs-gpio of the SPI controller node as the target chip select signal and reading the address information of the status register and control register in the PLC device driver.
It simplifies the PLC device driver loading process, facilitates the modification and update of the device tree, improves recognition reliability, and reduces dependence on application layer tools.
Smart Images

Figure CN120803981A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of PLC (Power Line Communication) device driver loading, and particularly relates to a PLC device self-adaptive method based on an SPI (Serial Peripheral Interface) device tree. BACKGROUND
[0002] In related technologies, when multiple PLC device drivers are loaded, a corresponding device tree is usually compiled according to the type in each PLC device, and then a corresponding PLC device driver is loaded based on different device trees. This not only has a complicated process, but also is not conducive to modification and updating of the device tree. SUMMARY
[0003] To solve the above technical problems, the present application provides a PLC device self-adaptive method based on an SPI device tree, which uses one set of SPI device trees to support loading of multiple PLC device drivers, thereby simplifying the process and facilitating modification and updating of the device tree.
[0004] The technical scheme adopted by the present application is as follows: A PLC device self-adaptive method based on an SPI device tree, the PLC devices being N in number, N being an integer greater than or equal to 2, the PLC device self-adaptive method based on the SPI device tree comprising the following steps: configuring a cs-gpio (Chip Select General-Purpose Input / Output) in an SPI controller node as a target chip selection signal, configuring a cs (Chip Select) number in an SPI controller sub-node corresponding to a first PLC device as 0, and configuring cs numbers in SPI controller sub-nodes corresponding to second to Nth PLC devices as numbers other than 0 and different from each other; configuring the cs-gpio in the SPI controller sub-node corresponding to the second to Nth PLC devices as the target chip selection signal; wherein, when driving any PLC device among the second to Nth PLC devices, reading the cs-gpio in the corresponding SPI controller sub-node and setting the read signal to the cs-gpio in the SPI controller node.
[0005] In an embodiment of the present application, the address information of the corresponding status register and control register can be read out in the N PLC device drivers, and the PLC device self-adaptive method based on the SPI device tree further comprises the following steps: after system startup, judging whether to load a corresponding PLC device driver according to the address information of the status register and the control register in each PLC device driver in turn.
[0006] In one embodiment of the present application, whether to load the corresponding PLC device driver is determined according to the address information of the status register and the control register in each of the PLC device drivers, specifically comprising: if the address information of the status register is the first address, and / or the address information of the control register is the second address, then the corresponding PLC device driver is loaded; if the address information of the status register is not the first address, and the address information of the control register is not the second address, then the corresponding PLC device driver is not loaded.
[0007] In one embodiment of the present application, the address information of the status register and the control register can be read in the first to N-1th PLC device drivers, but cannot be read in the Nth PLC device driver, and the PLC device self-adapting method based on the SPI device tree further comprises the following steps: setting a global variable in the first to N-1th PLC device drivers, wherein the global variable is one of the first to Nth characteristics; after the system is started, whether to load the corresponding PLC device driver is determined according to the address information of the status register and the control register in the first to N-1th PLC device drivers; the global variable is set according to the loading state of the first to N-1th PLC device drivers; whether to load the Nth PLC device driver is determined according to the global variable.
[0008] In one embodiment of the present application, the global variable is set according to the loading state of the first to N-1th PLC device drivers, specifically comprising: if none of the first to N-1th PLC device drivers is loaded, then the global variable is set as the Nth characteristic; if one of the first to N-1th PLC device drivers is loaded, then the global variable is set as one of the first to N-1th characteristics.
[0009] In one embodiment of the present application, whether to load the Nth PLC device driver is determined according to the global variable, specifically comprising: if the global variable is set as the Nth characteristic, then the Nth PLC device driver is loaded; if the global variable is set as one of the first to N-1th characteristics, then the Nth PLC device driver is not loaded.
[0010] A computer device comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes the computer program, the PLC device self-adapting method based on the SPI device tree is implemented.
[0011] A non-transitory computer readable storage medium, having stored thereon a computer program, which, when executed by a processor, implements the above-mentioned PLC device adaptation method based on SPI device tree.
[0012] Advantages of the present application: The present application adopts a set of SPI device tree to support loading of multiple PLC device drivers, which not only simplifies the process, but also facilitates modification and update of the device tree. BRIEF DESCRIPTION OF DRAWINGS
[0013] Figure 1 A flowchart of the PLC device adaptation method based on SPI device tree of the embodiment of the present application. DETAILED DESCRIPTION
[0014] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the protection scope of the present application.
[0015] Figure 1 A flowchart of the PLC device adaptation method based on SPI device tree of the embodiment of the present application.
[0016] It should be noted that the PLC device of the embodiment of the present application can be N, wherein N is an integer greater than or equal to 2, that is, a set of SPI device tree can be applied to multiple PLC devices at the same time.
[0017] Specifically, as shown in Figure 1 The PLC device adaptation method based on SPI device tree of the embodiment of the present application can include the following steps: S1, configure cs-gpio in the SPI controller node as the target chip selection signal, configure the cs number in the SPI controller sub-node corresponding to the first PLC device as 0, and configure the cs numbers in the SPI controller sub-nodes corresponding to the second to Nth PLC devices as numbers other than 0 and different from each other.
[0018] Specifically, when compiling the SPI device tree, the SPI controller node and the SPI controller sub-node corresponding to each PLC device can be set respectively, that is, the cs-gpio in the SPI controller node is configured as the target chip selection signal, for example, cs-gpios = <&gpio4 26 GPIO_ACTIVE_HIGH>, and the cs number in the SPI controller sub-node corresponding to each PLC device is configured as a different code, wherein the cs number in the SPI controller sub-node corresponding to the first PLC device is configured as 0, and the cs numbers in the SPI controller sub-nodes corresponding to the second to Nth PLC devices are configured as numbers other than 0 and different from each other, for example, the cs number in the SPI controller sub-node corresponding to the second PLC device is configured as 1, the cs number in the SPI controller sub-node corresponding to the third PLC device is configured as 2, and so on, and the cs number in the SPI controller sub-node corresponding to the Nth PLC device is configured as N-1.
[0019] S2, configuring the cs-gpio in the SPI controller sub-node corresponding to the second to Nth PLC devices as the target chip selection signal. When any one of the second to Nth PLC devices is driven, the cs-gpio in the corresponding SPI controller sub-node is read, and the read signal is set to the cs-gpio in the SPI controller node.
[0020] Specifically, in order to enable the compiled SPI device tree to support multiple PLC device nodes at the same time, the boards of the multiple PLC devices adopt the same one, therefore, the chip selection signals corresponding to each PLC device should also be the same, that is, the target chip selection signal. Specifically, the cs-gpio in the SPI controller sub-node corresponding to the second to Nth PLC devices can be configured as the target chip selection signal, for example, cs-gpio = <&gpio4 26 GPIO_ACTIVE_HIGH>. Thus, when any one of the second to Nth PLC devices is driven, the cs-gpio in the corresponding SPI controller sub-node can be read, and the target chip selection signal of the cs-gpio in the SPI controller sub-node is set to the cs-gpio in the SPI controller node.
[0021] Thus, by configuring the cs-gpio in the SPI controller node and the cs-gpio in the SPI controller sub-node as the same target chip selection signal, the SPI device tree can support multiple PLC device drivers to be loaded at the same time, thereby not only simplifying the process, but also facilitating the management of the SPI device tree, and facilitating the modification, updating and upgrading of the SPI device tree.
[0022] Further, on the basis of loading N PLC device drivers by using the same SPI device tree, in order to accurately and reliably identify the PLC device driver to be loaded, while avoiding the use of application layer scripts for identification and judgment, which is not conducive to the maintenance of the device script, therefore, the application uses the method of reading the register address to identify the PLC device driver to be loaded.
[0023] Specifically, first, it is necessary to judge whether the address information of the corresponding state register and control register can be read in the N PLC device drivers, and then different strategies are used for identification according to the judgment result.
[0024] Specifically, in one embodiment of the application, when the address information of the corresponding state register and control register can be read in the N PLC device drivers, after the system is started, whether to load the corresponding PLC device driver is judged according to the address information of the state register and the control register in each PLC device driver. If the address information of the state register is the first address, and / or the address information of the control register is the second address, the corresponding PLC device driver is loaded; if the address information of the state register is not the first address, and the address information of the control register is not the second address, the corresponding PLC device driver is not loaded.
[0025] For example, the PLC device is two, which are the first PLC device and the second PLC device, after the system is started, the kernel runs the first PLC device driver, the first PLC device driver reads the address information of the state register and the control register in the first PLC device driver. If the address information of the state register in the first PLC device driver is not the first address (for example, 0x02), and the address information of the control register is not the second address (for example, 0x03), the first PLC device driver is not loaded, otherwise, the first PLC device driver is loaded. Similarly, the second PLC device driver reads the address information of the state register and the control register in the second PLC device driver. If the address information of the state register in the second PLC device driver is not the first address (for example, 0x02), and the address information of the control register is not the second address (for example, 0x03), the second PLC device driver is not loaded, otherwise, the second PLC device driver is loaded.
[0026] In another embodiment of the application, the address information of the corresponding state register and control register can be read in the first to N-1 PLC device drivers, and the address information of the corresponding state register and control register cannot be read in the N PLC device driver. The global variable can be set in the first to N-1 PLC device drivers, wherein the global variable is one of the first to N characteristics, for example, it can be A1, A2, …, AN, and the N is an integer greater than or equal to 2. N .
[0027] Then, after the system is started, whether to load the corresponding PLC device driver is judged according to the address information of the status register and the control register in the first to the N-1th PLC device driver. The specific judging method can refer to the above embodiment, and will not be described in detail here to avoid redundancy.
[0028] Further, the global variable is set according to the loading state of the first to the N-1th PLC device driver. If none of the first to the N-1th PLC device driver is loaded, the global variable is set to the Nth feature, for example, the global variable is set to A N ; if one of the first to the N-1th PLC device driver is loaded, the global variable is set to one of the first to the N-1th feature, for example, the Kth (1≤K≤N-1) PLC device driver is loaded, and the global variable is set to A K .
[0029] Finally, whether to load the Nth PLC device driver is judged according to the global variable. If the global variable is set to the Nth feature, the Nth PLC device driver is loaded; if the global variable is set to one of the first to the N-1th feature, the Nth PLC device driver is not loaded.
[0030] For example, the PLC device is two, which are high-pass PLC device and joint-core PLC device. The global variable is added in the high-pass PLC device driver, which can be true or false. After the system is started, the kernel runs the high-pass PLC device driver, and the high-pass PLC device driver reads the address information of the status register and the control register in the high-pass PLC device driver. If the address information of the status register in the high-pass PLC device driver is not the first address (for example, 0×02), and the address information of the control register is not the second address (for example, 0×03), the high-pass PLC device driver is not loaded, and at this time, the global variable is set to the first feature (for example, false); otherwise, the high-pass PLC device driver is loaded, and at this time, the global variable is set to the second feature (for example, true).
[0031] Further, when the global variable is set to the first feature, the joint-core PLC device driver is loaded; when the global variable is set to the second feature, the joint-core PLC device driver is not loaded.
[0032] It should be noted that when the address information of the corresponding state register and control register cannot be read in the plurality of PLC device drivers in the N PLC devices, the system reports an error, at this time, a traditional identification method can be used for judgment, for example, an application layer script is used for judgment and identification. Therefore, the present application judges whether to load the corresponding PLC device driver based on the address information of the state register and the control register in the PLC device driver in the kernel layer, greatly reduces the dependence on the application layer tool, increases the identification reliability, and reduces the application layer development, and facilitates system maintenance.
[0033] In summary, according to the PLC device self-adaption method based on the SPI device tree in the embodiment of the present application, the cs-gpio in the SPI controller node is configured as the target chip selection signal, the cs number in the SPI controller sub-node corresponding to the first PLC device is configured as 0, and the cs number in the SPI controller sub-node corresponding to the second to Nth PLC device is configured as a number other than 0 and different from each other, and the cs-gpio in the SPI controller sub-node corresponding to the second to Nth PLC device is configured as the target chip selection signal; wherein, when the driver of any PLC device in the second to Nth PLC device is driven, the cs-gpio in the corresponding SPI controller sub-node is read, and the read signal is set to the cs-gpio in the SPI controller node. Therefore, a set of SPI device trees is used to support the loading of multiple PLC device drivers, which not only simplifies the process, but also facilitates the modification and update of the device tree.
[0034] Corresponding to the above embodiment, the present application also provides a computer device.
[0035] The computer device of the embodiment of the present application comprises a memory, a processor and a computer program stored on the memory and executable on the processor, and when the processor executes the computer program, the PLC device self-adaption method based on the SPI device tree in the above embodiment is realized.
[0036] According to the computer device of the embodiment of the present application, a set of SPI device trees is used to support the loading of multiple PLC device drivers, which not only simplifies the process, but also facilitates the modification and update of the device tree.
[0037] Corresponding to the above embodiment, the present application also provides a non-transitory computer readable storage medium.
[0038] The non-transitory computer readable storage medium of the embodiment of the present application stores a computer program, and when the processor executes the program, the PLC device self-adaption method based on the SPI device tree in the above embodiment is realized.
[0039] The non-transitory computer readable storage medium according to the embodiment of the present application supports loading of multiple PLC device drivers simultaneously by using a set of SPI device trees, thereby simplifying the process and facilitating modification and updating of the device trees.
[0040] In the description of the present application, the terms "first", "second", "third", "fourth", "fifth", "sixth", "seventh" and "eight" are used only for the purpose of description, and should not be understood as indicating or implying relative importance or implying the number of the technical features indicated. Therefore, the features defined as "first", "second", "third", "fourth", "fifth", "sixth", "seventh" and "eight" can explicitly or implicitly include one or more of the features. The meaning of "plurality" is two or more, unless otherwise specifically limited.
[0041] In the present application, unless otherwise specifically defined and limited, the terms "mounting", "connecting", "connecting", "fixing" and the like should be understood in a broad sense, for example, it can be fixed connection, or detachable connection, or integrated; it can be mechanical connection, or electrical connection; it can be directly connected, or indirectly connected through intermediate medium, or the internal communication of two elements or the interaction relationship between two elements. For those skilled in the art, the specific meaning of the above terms in the present application can be understood according to the specific circumstances.
[0042] In the present application, unless otherwise specifically defined and limited, the first feature is "on" or "under" the second feature, which can be direct contact between the first and second features, or indirect contact between the first and second features through intermediate medium. Moreover, the first feature "above", "above" and "above" the second feature can be directly above or obliquely above the first feature, or only indicate that the horizontal height of the first feature is higher than that of the second feature. The first feature "below", "below" and "below" the second feature can be directly below or obliquely below the first feature, or only indicate that the horizontal height of the first feature is less than that of the second feature.
[0043] In the description of the present application, the description of the terms "one embodiment", "some embodiments", "example", "specific example" or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In the present application, the illustrative description of the above terms is not necessarily for the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art can combine and combine the different embodiments or examples described in the present application and the features of the different embodiments or examples without contradiction.
[0044] In addition, each function unit in each embodiment of the present application can be integrated in one processing module, or each unit can exist physically separately, or two or more units can be integrated in one module. The integrated module can be realized in the form of hardware, or in the form of software function module. When the integrated module is realized in the form of software function module and sold or used as an independent product, it can also be stored in a computer readable storage medium.
[0045] Although the embodiments of the present application have been shown and described above, it should be understood by those ordinary skilled in the art that the above embodiments are exemplary and cannot be understood as limiting the present application, and those ordinary skilled in the art can make changes, modifications, replacements and variations to the above embodiments within the scope of the present application.
Claims
1. A PLC device adaptation method based on SPI device tree, characterized in that: The number of the PLC devices is N, where N is an integer greater than or equal to 2. The PLC device adaptation method based on the SPI device tree includes the following steps: Configure cs-gpio in the SPI controller node as the target chip select signal, and configure the cs number in the SPI controller subnode corresponding to the first PLC device to 0, and configure the cs numbers in the SPI controller subnodes corresponding to the second to Nth PLC devices to non-zero and different numbers. The cs-gpio is configured as the target chip select signal in the SPI controller sub-node corresponding to the second to Nth PLC devices; wherein, when any PLC device among the second to Nth PLC devices is driven, the cs-gpio in the corresponding SPI controller sub-node is read, and the read signal is set to the cs-gpio in the SPI controller node.
2. The PLC device self-adaptation method based on the SPI device tree according to claim 1, characterized in that: The address information of the corresponding status register and control register can be read from each of the N PLC device drivers. The PLC device adaptation method based on the SPI device tree further includes the following steps: After the system is started, it is determined whether to load the corresponding PLC device driver according to the address information of the status register and the control register in each PLC device driver.
3. The PLC device self-adaptation method based on the SPI device tree according to claim 2, characterized in that: Determining whether to load the corresponding PLC device driver according to the address information of the status register and the control register in each of the PLC device drivers specifically includes: If the address information of the status register is the first address, and / or the address information of the control register is the second address, loading the corresponding PLC device driver; If the address information of the status register is not the first address, and the address information of the control register is not the second address, the corresponding PLC device driver is not loaded.
4. The PLC device self-adaptation method based on the SPI device tree according to claim 1, characterized in that: The address information of the corresponding status register and control register can be read from the first to N-1th PLC device drivers, and the address information of the corresponding status register and control register cannot be read from the Nth PLC device driver. The PLC device adaptation method based on the SPI device tree further includes the following steps: Setting a global variable in the first to N-1th PLC device drivers, wherein the global variable is one of the first to Nth features; After the system is started, judging whether to load the corresponding PLC device driver according to the address information of the status register and the control register in the first to N-1th PLC device drivers; Setting the global variable according to the first to N-1th PLC device driver loading states; Determine whether to load the Nth PLC device driver according to the global variable.
5. The PLC device self-adaptation method based on the SPI device tree according to claim 4, characterized in that: According to the first to N-1th PLC device driver loading states, the global variable is set, specifically including: If the first to N-1th PLC device drivers are not loaded, setting the global variable to the Nth feature; If there is a PLC device driver loaded among the first to N-1th PLC devices, the global variable is set to one of the first to N-1th features.
6. The PLC device self-adaptation method based on the SPI device tree according to claim 5, characterized in that: Determining whether to load the Nth PLC device driver according to the global variable specifically includes: If the global variable is set to the Nth feature, then the Nth PLC device driver is loaded; If the global variable is set to one of the first to N-1th features, the Nth PLC device driver is not loaded.
7. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the PLC device adaptation method based on the SPI device tree according to any one of claims 1 to 6 is implemented.
8. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the PLC device adaptation method based on the SPI device tree according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Equipment tree configuration optimization method and device, computer equipment and storage medium
CN113504918A
Driving hardware configuration information loading method, device and system and computing equipment
CN114691240A
Device identification starting method, device and system based on multi-device tree file
CN119203112A
User mode driven cross-platform support method and device based on equipment tree and medium
CN119883410A
Multi-device communication system and method, electronic device and storage medium
CN120086167A