Method for accessing peripheral equipment and embedded system

By mapping the physical address operated by users to the kernel virtual address in an embedded system, the complex access process of peripheral devices is solved, and the effect of simplifying the development process and improving security is achieved.

CN120371736APending Publication Date: 2025-07-25CONTEMPORARY AMPEREX FUTURE ENERGY RES INST (SHANGHAI) LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410109179.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-01-25
Publication Date
2025-07-25

AI Technical Summary

Technical Problem

In the prior art, during the driver development and debugging of peripheral devices, frequent address modifications lead to complex development processes, increasing development time and cost, and it is impossible to ensure normal access to peripheral devices.

Method used

User operation information is obtained through the user layer of the embedded system, and the first physical address is mapped to the kernel virtual address. The driver layer operates peripheral devices based on this address, simplifying the access process and increasing security.

Benefits of technology

Users can access peripheral devices directly, simplifying the development process, reducing development time and cost, while improving access security and accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120371736A_ABST
    Figure CN120371736A_ABST
Patent Text Reader

Abstract

The invention discloses a method for accessing peripheral equipment and an embedded system, and the method comprises the steps that a user layer of the embedded system obtains operation information input by a user through an equipment node and sends the operation information to a driving layer of the embedded system, and the operation information comprises a first physical address of the peripheral equipment needing to be accessed and operated; the driving layer maps the first physical address to a kernel virtual address, and operates the peripheral device based on the kernel virtual address mapped by the first physical address to obtain an operation result; and the driving layer feeds back the operation result to the user layer. According to the technical scheme, a user can directly access the peripheral equipment, and the access process is simplified.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of embedded technology, and particularly to a method for accessing peripheral devices and an embedded system. Background Art

[0002] Currently, the development and debugging of the PL side drivers are carried out by pre-dividing the peripheral device (such as registers) area, modifying the device tree, writing corresponding driver programs, and providing the generated driver device nodes for the user layer to operate.

[0003] During the development and debugging process, since the operation addresses of multiple modules are often modified, the driver developers also need to rewrite the driver programs and generate new module files for debugging, which will cause the PL side FPGA to modify the address and register interface, and the PS side driver developers also need to redefine the device tree and operation addresses, increasing the development process and time; the frequent modification of the read / write configuration bits of peripheral devices cannot ensure normal access to peripheral devices. Summary of the Invention

[0004] This application provides at least a method for accessing peripheral devices and an embedded system.

[0005] In the first aspect of this application, a method for accessing peripheral devices is provided. The method includes: the user layer of the embedded system obtains the operation information input by the user through the device node and sends the operation information to the driver layer of the embedded system. The operation information includes the first physical address of the peripheral device to be accessed and operated; the driver layer maps the first physical address to the kernel virtual address and operates on the peripheral device based on the kernel virtual address mapped by the first physical address to obtain an operation result; the driver layer feeds back the operation result to the user layer.

[0006] Therefore, after the driver layer receives the actual address of the peripheral device to be accessed and operated, it will perform the access operation of the peripheral device based on the actual address of the peripheral device to be accessed and operated to obtain an operation result; and the operation information is input by the user through the node device, so it can be understood that the user can directly operate on the peripheral device by passing in the first physical address of the peripheral device to be accessed and operated. Therefore, the user can directly access the peripheral device, which is convenient for the user to develop and debug functions, facilitates the rapid launch of functions, and is also convenient for troubleshooting; since the user can directly access the peripheral device, the access process to the peripheral device is simplified, the workload of developers is reduced, and thus the development time and cost are reduced.

[0007] In addition, operating on the peripheral device based on the kernel virtual address mapped by the first physical address increases the address access constraint and improves the security of access.

[0008] Among them, before the driver layer maps the first physical address to the kernel virtual address, the method for accessing a peripheral device further includes: the driver layer detects whether the current virtual address mapping condition is satisfied; wherein, the driver layer performs the step of mapping the first physical address to the kernel virtual address when it detects that the current virtual address mapping condition is satisfied.

[0009] Therefore, detecting whether the current virtual address mapping condition is satisfied enables mapping the first physical address to the kernel virtual address when the current virtual address mapping condition is satisfied, avoiding incorrect address mapping and improving the accuracy of accessing peripheral devices.

[0010] Among them, the virtual address mapping condition includes that the current access operation does not have an address out-of-bounds; the driver layer detecting whether the current virtual address mapping condition is satisfied includes: the driver layer detecting whether the current access operation has an address out-of-bounds based on the first physical address; and / or, the virtual address mapping condition includes that there are available virtual address resources in the operating system kernel currently; the driver layer detecting whether the current virtual address mapping condition is satisfied includes: the driver layer applying for virtual address resources from the operating system kernel and receiving the application feedback result from the operating system kernel, and the application feedback result includes that there are no available virtual address resources currently, or there are available virtual address resources currently.

[0011] Therefore, the virtual address mapping condition can be set flexibly.

[0012] Among them, the virtual address mapping condition includes that the current access operation does not have an address out-of-bounds and there are available virtual address resources in the operating system kernel currently; the driver layer detecting whether the current virtual address mapping condition is satisfied includes: the driver layer detecting whether the current access operation has an address out-of-bounds based on the first physical address; in response to the current access operation not having an address out-of-bounds, the driver layer applies for virtual address resources from the operating system kernel and receives the application feedback result from the operating system kernel; in response to the application feedback result indicating that there are available virtual address resources currently, the driver layer performs the step of mapping the first physical address to the kernel virtual address.

[0013] Therefore, considering both whether the current virtual address mapping condition is satisfied and whether there are available virtual address resources to determine whether the first physical address can be mapped to the kernel virtual address, the determined result is more accurate.

[0014] Among them, the driver layer detecting whether the current access operation has an address out-of-bounds based on the first physical address includes: the driver layer detecting whether the first physical address belongs to a preset operation area; in response to the first physical address belonging to the preset operation area, determining that the current access operation does not have an address out-of-bounds, and, in response to the first physical address not belonging to the preset operation area, determining that the current access operation has an address out-of-bounds.

[0015] Therefore, a preset operation area is set in advance, and the physical addresses within the preset operation area are addresses that can access the peripheral device. Therefore, by comparing the first physical address with the physical addresses within the preset operation area, it can be determined whether there is an address out-of-bounds for the first physical address.

[0016] Among them, before obtaining the operation information input by the user through the device node at the user layer of the embedded system, the method for accessing the peripheral device further includes: the driver layer determines the preset operation area based on the second physical address in the peripheral device configuration information, where the peripheral device configuration information is generated by the embedded device side of the embedded system based on the designed function and provided to the driver layer.

[0017] Therefore, the physical addresses within the preset operation area are addresses that can access the peripheral device. By comparing the first physical address with the physical addresses within the preset operation area, it can be determined whether there is an address out-of-bounds for the first physical address.

[0018] Among them, after the driver layer detects whether there is an address out-of-bounds for the current access operation based on the first physical address, the method for accessing the peripheral device further includes: in response to the current access operation having an address out-of-bounds, the driver layer returns a first error prompt to the user layer to prompt that there is an address out-of-bounds for the current access operation.

[0019] Therefore, in the case where the current access operation has an address out-of-bounds, the reason for the current abnormal situation will be promptly fed back to the user.

[0020] Among them, after receiving the application feedback result of the operating system kernel, the method for accessing the peripheral device further includes: in response to the application feedback result indicating that there are currently no available virtual address resources, the driver layer returns a second error prompt to the user layer to prompt that there are no available virtual address resources currently.

[0021] Therefore, in the case where the application feedback result indicates that there are currently no available virtual address resources, the reason for the current abnormal situation will be promptly fed back to the user.

[0022] Among them, the peripheral device is a peripheral register, and the operation information can represent that the current access operation is a read operation or a write operation; operating on the peripheral device based on the kernel virtual address to obtain an operation result, including: in response to the current access operation being a read operation, performing a read operation on the peripheral device based on the kernel virtual address mapped by the first physical address, obtaining the stored data corresponding to the first physical address, and generating a first operation result indicating that the read operation is successful, where the first operation result includes the stored data corresponding to the first physical address; in response to the current access operation being a write operation, obtaining the data to be written from the operation information, and performing a write operation on the peripheral device based on the kernel virtual address mapped by the first physical address to write the data to be written into the space corresponding to the first physical address, and generating a second operation result indicating that the write operation is successful.

[0023] Among them, when the current access operation is a read operation, the stored data corresponding to the first physical address is read, that is, the data stored in the peripheral register is read, and a first operation result including the stored data corresponding to the first physical address is generated, and then fed back to the user layer to realize direct access to the peripheral register; when the current access operation is a write operation, the data to be written is written into the space corresponding to the first physical address, that is, the data to be written is written into the peripheral register, and then the second operation result is fed back to the user layer to timely feedback the operation result of successfully writing the data to the user.

[0024] Among them, before the user layer of the embedded system obtains the operation information input by the user through the device node, the method for accessing the peripheral device further includes: the driver layer creates a device node based on the peripheral device configuration information; and / or, the driver layer establishes a mapping relationship between each second physical address and the kernel virtual address in the peripheral device configuration information.

[0025] Therefore, before the user layer of the embedded system obtains the operation information input by the user through the device node, the driver layer assists in providing address constraints, allocating driver modules, and device nodes to the user side.

[0026] Among them, the peripheral device is a peripheral register or a block device; and / or, the operating system of the embedded system is a linux operating system; and / or, the embedded system includes a processor and a field programmable gate array component, the processor can run the operating system, and the peripheral device is configured through the field programmable gate array component.

[0027] Therefore, the peripheral device and the embedded system can be flexibly set.

[0028] The second aspect of the present application provides an embedded system, which is configured to be able to implement the above-mentioned method.

[0029] Among them, the embedded system is a system-on-chip including a processor and a field programmable gate array component.

[0030] In the above technical solution, after the driver layer receives the actual address of the peripheral device that needs to be accessed, the access operation of the peripheral device is performed based on the actual address of the peripheral device that needs to be accessed to obtain an operation result; and the operation information is input by the user through the node device, so it can be understood that the user can directly operate the peripheral device by passing in the first physical address of the peripheral device that needs to be accessed. Therefore, the user can directly access the peripheral device, which is convenient for the user to develop and debug functions, facilitates the rapid launch of functions, and is also convenient for troubleshooting; since the user can directly access the peripheral device, the access process to the peripheral device is simplified, the workload of developers is reduced, thereby reducing the development time and cost.

[0031] In addition, the kernel virtual address based on the first physical address mapping is used to operate on the peripheral device, adding address access constraints and improving the security of access. Brief Description of the Drawings

[0032] The drawings herein are incorporated into and constitute a part of this specification. These drawings illustrate embodiments consistent with the present application and, together with the specification, are used to explain the technical solutions of the present application.

[0033] Figure 1 It is a schematic flowchart of an embodiment of a method for accessing a peripheral device provided by the present application. Detailed Embodiments

[0034] The following describes the solutions of the embodiments of the present application in detail with reference to the drawings in the specification.

[0035] In the following description, specific details such as specific system architectures, interfaces, and technologies are presented for the purpose of illustration rather than limitation, in order to thoroughly understand the present application.

[0036] As used herein, the term "and / or" is merely a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. In addition, the character " / " herein generally represents an "or" relationship between the associated objects before and after. Furthermore, the term "plurality" herein means two or more. In addition, the term "at least one" herein means any one of a plurality or any combination of at least two of a plurality. For example, including at least one of A, B, and C can represent including any one or more elements selected from the set composed of A, B, and C.

[0037] Please refer to Figure 1 , Figure 1 It is a schematic flowchart of an embodiment of a method for accessing a peripheral device provided by the present application. It should be noted that, if there are substantially the same results, the embodiments of the present application are not limited to Figure 1 the process sequence shown. As Figure 1 shown, this embodiment includes:

[0038] Step S11: The user layer of the embedded system obtains the operation information input by the user through the device node and sends the operation information to the driver layer of the embedded system.

[0039] The method of this embodiment is used for accessing peripheral devices. On the one hand, users (developers) can directly access peripheral devices, which is convenient for users to develop and debug functions, facilitates the rapid launch of functions, and is also convenient for troubleshooting. On the other hand, since users can directly access peripheral devices, the access process of peripheral devices by users is simplified, the workload of users is reduced, and the development time and cost are lowered. Moreover, unified management and protection of peripheral devices are achieved, and the stability and security of the embedded system are improved.

[0040] In this embodiment, the user layer of the embedded system obtains the operation information input by the user through the device node and sends the operation information to the driver layer of the embedded system. The operation information includes the first physical address of the peripheral device to be accessed and operated. The peripheral device is a related unit inside the embedded system; the first physical address is the actual address in the embedded system, which is used to locate the peripheral device. Therefore, after the driver layer receives the actual address of the peripheral device to be accessed and operated subsequently, the driver layer is loaded by the user layer and will perform the access operation of the peripheral device based on the actual address of the peripheral device to be accessed and operated to obtain the operation result; and the operation information is input by the user through the node device, so it can be understood that by passing in the first physical address of the peripheral device to be accessed and operated, the user can operate the peripheral device, that is, the user can directly access the peripheral device, which is convenient for users to develop and debug functions, facilitates the rapid launch of functions, and is also convenient for troubleshooting.

[0041] In one embodiment, the peripheral device can be a peripheral register. The peripheral register is a data storage unit inside the embedded system, which is used to temporarily store data for quick access; the first physical address is the actual address in the embedded system, which is used to locate the data. Therefore, after the driver layer receives the actual address of the peripheral register to be accessed and operated subsequently, it will perform the access operation of the peripheral register based on the actual address of the peripheral register to be accessed and operated to obtain the operation result; and the operation information is input by the user through the node device, so it can be understood that by passing in the first physical address of the peripheral register to be accessed and operated, the user can operate the peripheral register, that is, the user can directly access the peripheral register, which is convenient for users to develop and debug functions, facilitates the rapid launch of functions, and is also convenient for troubleshooting. In addition, since users can directly access the peripheral register, the access process of the peripheral register by users is simplified, the workload of users is reduced, and the development time and cost are lowered. Moreover, subsequently, through the combination of the virtual address mapping and physical address constraints of the embedded system, that is, through the access operation of the virtual address by the kernel of the embedded system, unified management and protection of peripheral devices are achieved, and the stability and security of the embedded system are improved.

[0042] In other embodiments, the peripheral device can also be a block device, which is another data storage unit in an embedded system. Block devices are typically used to store large amounts of data. They can randomly access blocks of a fixed size, and each block has its own address. Users can directly access the block device and directly access the large amounts of data stored in it, avoiding secondary copying of large amounts of data.

[0043] In other embodiments, the peripheral device can also be a flash device, which is not limited herein.

[0044] It should be noted that the peripheral device is a device other than the main circuits such as the processor and FPGA of the embedded system. In one embodiment, when the embedded system is ZYNQ, the embedded system includes a processor and a field programmable gate array component, and the peripheral device is a peripheral device of the FPGA. As an SoC (System-on-Chip) launched by Xilinx, ZYNQ integrates an ARM processor and programmable logic (FPGA). It has the following advantages: on the one hand, it has powerful processing capabilities: the ZYNQ SoC integrates an ARM Cortex-A series processor, providing high-performance processing capabilities, and can run complex application programs and operating systems, such as implementing the Linux operating system, providing stable and efficient device and memory management; on the other hand, it has programmable logic flexibility. The FPGA part in the ZYNQ SoC can be programmed and reconfigured as needed, making the system flexible and scalable. Functions such as hardware acceleration, protocol conversion, data processing, and custom interfaces can be implemented through the FPGA.

[0045] In other embodiments, the operating system of the embedded system is the linux system. On the one hand, linux system users can directly access the peripheral device, which is convenient for linux system application developers, linux driver developers, and hardware FPGA developers to carry out function development and debugging, facilitating the rapid launch of functions and also facilitating troubleshooting; on the other hand, since users can directly access the peripheral device, the access process of the user to the peripheral device is simplified, reducing the workload of the user, and reducing the development time and cost; furthermore, unified management and protection of the peripheral device are achieved, improving the stability and security of the embedded system.

[0046] In one embodiment, before the user layer of the embedded system obtains the operation information input by the user through the device node, the driver layer creates the device node based on the peripheral device configuration information. In one embodiment, before the user layer of the embedded system obtains the operation information input by the user through the device node, the driver layer establishes the mapping relationship between each second physical address and the kernel virtual address in the peripheral device configuration information. That is to say, before the user layer of the embedded system obtains the operation information input by the user through the device node, the driver layer assists in providing address constraints, allocating driver modules, and device nodes to the user side.

[0047] In a specific embodiment, the driver layer sends the operation point table (including the mapping relationship between each second physical address and the kernel virtual address) to the operating system kernel, and the operating system kernel performs the mapping behavior based on the operation point table.

[0048] Step S12: The driver layer maps the first physical address to the kernel virtual address, and operates on the peripheral device based on the kernel virtual address mapped from the first physical address to obtain an operation result.

[0049] In this embodiment, the driver layer maps the first physical address to the kernel virtual address, and operates on the peripheral device based on the kernel virtual address mapped from the first physical address to obtain an operation result. Through the access operation of the kernel virtual address, combined with virtual address mapping and physical address constraints, the unified management and protection of the peripheral device are realized, and the stability and security of the embedded system are improved. The driver layer does not directly operate on the peripheral device based on the first physical address of the peripheral device that needs to be accessed and operated received, but operates on the peripheral device based on the kernel virtual address mapped from the first physical address. On the one hand, directly using the physical address may cause interference and conflicts between programs. Providing an independent virtual address space for each program can ensure that the program runs in an exclusive memory space, preventing the errors of one program from affecting other programs, thereby improving the stability and reliability of the system. On the other hand, in a multitasking environment, multiple programs need to run simultaneously in the computer system. Using virtual addresses allows each program to have its own address space and does not need to care about the existence of other programs. This provides an effective mechanism for multitasking, enabling multiple programs to run concurrently without interfering with each other. In addition, the virtual address space is managed by the operating system and can be dynamically allocated and managed without considering the actual distribution of physical addresses. This improves the memory utilization efficiency and enables the program to use memory efficiently. Moreover, virtual addresses provide a memory protection mechanism. By isolating the virtual address spaces of different processes, it is possible to prevent interference and illegal access to memory between processes, thereby enhancing the security of the system. Furthermore, programs using virtual addresses do not need to care about the specific distribution of physical addresses, which enables the program to run on different computer systems and improves the portability of the program.

[0050] In one embodiment, the first physical address of the peripheral device to be accessed can be mapped to the kernel virtual address by means of ioremap. Of course, other methods can also be used for address mapping, which is not limited herein.

[0051] In one embodiment, the peripheral device is a peripheral register, and the operation information can represent that the current access operation is a read operation or a write operation. At this time, the peripheral device is operated based on the kernel virtual address to obtain an operation result. Specifically: in response to the current access operation being a read operation, the peripheral device is read based on the kernel virtual address mapped from the first physical address, the stored data corresponding to the first physical address is obtained, and a first operation result indicating the success of the read operation is generated. The first operation result includes the stored data corresponding to the first physical address; in response to the current access operation being a write operation, the data to be written is obtained from the operation information, and the peripheral device is written based on the kernel virtual address mapped from the first physical address, so as to write the data to be written into the space corresponding to the first physical address, and a second operation result indicating the success of the write operation is generated. That is to say, when the current access operation is a read operation, the stored data corresponding to the first physical address is read, that is, the data stored in the peripheral register is read, and a first operation result including the stored data corresponding to the first physical address is generated, which is subsequently fed back to the user layer to achieve direct access to the peripheral register; while when the current access operation is a write operation, the data to be written is written into the space corresponding to the first physical address, that is, the data to be written is written into the peripheral register, and the second operation result is subsequently fed back to the user layer to timely feedback the operation result of successfully writing the data to the user.

[0052] It should be noted that when the user needs to read data from the peripheral register, the operation information input by the user layer of the embedded system through the node device only includes the first physical address of the peripheral register to be accessed; while when the user needs to write data to the peripheral register, the operation information input by the user layer of the embedded system through the node device includes the first physical address of the peripheral register to be accessed and the data to be written, and the data to be written can be referred to as the operation value.

[0053] In one embodiment, before the driver layer maps the first physical address to the kernel virtual address, the driver layer detects whether the current virtual address mapping condition is satisfied. Among them, the driver layer executes the step of mapping the first physical address to the kernel virtual address when it detects that the current virtual address mapping condition is satisfied. That is to say, when the current virtual address mapping condition is satisfied, the first physical address is mapped to the kernel virtual address to avoid incorrect address mapping and improve the accuracy of accessing the peripheral device.

[0054] In a specific embodiment, the virtual address mapping conditions include that there is no address out-of-bounds in the current access operation. The driver layer detects whether the current virtual address mapping conditions are met. Specifically: the driver layer detects whether there is an address out-of-bounds in the current access operation based on the first physical address. When the virtual address mapping condition is that there is no address out-of-bounds in the current access operation, if the current virtual address mapping conditions are met, it indicates that the current first physical address is within the address range where the peripheral device can be accessed. If the current virtual address mapping conditions are not met, it indicates that the current first physical address is outside the address range where the peripheral device can be accessed, realizing address access constraints and improving the security of access.

[0055] In a specific embodiment, the virtual address mapping conditions include that there are available virtual address resources in the current operating system kernel. The driver layer detects whether the current virtual address mapping conditions are met. Specifically: the driver layer applies to the operating system kernel for virtual address resources and receives the application feedback result from the operating system kernel. The application feedback result includes that there are no available virtual address resources currently, or there are available virtual address resources currently. When the virtual address mapping condition is that there are available virtual address resources in the current operating system kernel, if the received application feedback result is that there are available virtual address resources currently, it indicates that the current first physical address can be mapped to the kernel virtual address for accessing the peripheral device. If the received application feedback result is that there are no available virtual address resources currently, it indicates that the current first physical address cannot be mapped to the kernel virtual address for accessing the peripheral device.

[0056] In a specific embodiment, the virtual address mapping conditions include that there is no address out-of-bounds in the current access operation and there are available virtual address resources in the current operating system kernel. The driver layer detects whether the current virtual address mapping conditions are met. Specifically: the driver layer detects whether there is an address out-of-bounds in the current access operation based on the first physical address; in response to there being no address out-of-bounds in the current access operation, the driver layer applies to the operating system kernel for virtual address resources and receives the application feedback result from the operating system kernel; in response to the application feedback result being that there are available virtual address resources currently, perform the step of the driver layer mapping the first physical address to the kernel virtual address. That is to say, by considering both whether the current virtual address mapping conditions are met and whether there are available virtual address resources, it is determined whether the first physical address can be mapped to the kernel virtual address, and the determined result is more accurate.

[0057] In one embodiment, after receiving the application feedback result of the operating system kernel, in response to the application feedback result indicating that there is currently no available virtual address resource, the driver layer returns a second error prompt to the user layer to indicate that there is no available virtual address resource currently. That is, when the application feedback result indicates that there is currently no available virtual address resource, the cause of the current abnormal situation will be promptly fed back to the user.

[0058] Among them, the driver layer can specifically detect whether there is an address out-of-bounds for this access operation based on the first physical address: the driver layer detects whether the first physical address belongs to a preset operation area; in response to the first physical address belonging to the preset operation area, it is determined that there is no address out-of-bounds for this access operation, and, in response to the first physical address not belonging to the preset operation area, it is determined that there is an address out-of-bounds for this access operation. That is to say, a preset operation area is set in advance, and the physical addresses within the preset operation area are the addresses that can access the peripheral device. Therefore, by comparing the first physical address with the physical addresses within the preset operation area, it can be determined whether there is an address out-of-bounds for the first physical address.

[0059] In addition, the preset operation area can also be divided into several sub-operation areas; the driver layer respectively detects whether the first physical address belongs to any one of the sub-operation areas, and in response to the first physical address belonging to any one of the sub-operation areas, it is determined that there is no address out-of-bounds for this access operation, and, in response to the first physical address not belonging to any one of the sub-operation areas, it is determined that there is an address out-of-bounds for this access operation.

[0060] In a specific embodiment, before the user layer of the embedded system obtains the operation information input by the user through the device node, the driver layer determines the preset operation area based on the second physical address in the peripheral device configuration information, where the peripheral device configuration information is generated by the embedded device side of the embedded system based on the designed function and provided to the driver layer. Among them, the peripheral device configuration information can be an operation point table.

[0061] In a specific embodiment, after the driver layer detects whether there is an address out-of-bounds for this access operation based on the first physical address, in response to the access operation having an address out-of-bounds, the driver layer returns a first error prompt to the user layer to indicate that there is an address out-of-bounds for this access operation. That is, when there is an address out-of-bounds for this access operation, the cause of the current abnormal situation will be promptly fed back to the user.

[0062] Step S13: The driver layer feeds back the operation result to the user layer.

[0063] In this embodiment, the driver layer feeds back the operation result to the user layer. The first operation result indicating a successful read operation or the second operation result indicating a successful write operation is fed back to the user in a timely manner to indicate the operation status of the peripheral device.

[0064] In the above technical solution, after the driver layer receives the actual address of the peripheral device to be accessed and operated, it will perform the access operation on the peripheral device based on the actual address of the peripheral device to be accessed and operated to obtain an operation result; and the operation information is input by the user through the node device. Therefore, it can be understood that the user can directly operate the peripheral device by passing in the first physical address of the peripheral device to be accessed and operated. Therefore, the user can directly access the peripheral device, which is convenient for the user to develop and debug functions, facilitates the rapid launch of functions, and is also convenient for troubleshooting; since the user can directly access the peripheral device, the access process to the peripheral device is simplified, the workload of developers is reduced, and thus the development time and cost are reduced.

[0065] In addition, operating on the peripheral device based on the kernel virtual address mapped from the first physical address increases the address access constraint and improves the access security.

[0066] This application also provides an embedded system, which is configured to be able to implement the above method. After the driver layer receives the actual address of the peripheral device to be accessed and operated, it will perform the access operation on the peripheral device based on the actual address of the peripheral device to be accessed and operated to obtain an operation result; and the operation information is input by the user through the node device. Therefore, it can be understood that the user can directly operate the peripheral device by passing in the first physical address of the peripheral device to be accessed and operated. Therefore, the user can directly access the peripheral device, which is convenient for the user to develop and debug functions, facilitates the rapid launch of functions, and is also convenient for troubleshooting; since the user can directly access the peripheral device, the access process to the peripheral device is simplified, the workload of developers is reduced, and thus the development time and cost are reduced.

[0067] In addition, operating on the peripheral device based on the kernel virtual address mapped from the first physical address increases the address access constraint and improves the access security.

[0068] In one embodiment, the embedded system is a system-on-chip including a processor and a field programmable gate array component.

Claims

1. A method for accessing a peripheral device, characterized in that, Including: The user layer of the embedded system obtains the operation information input by the user through the device node, and sends the operation information to the driver layer of the embedded system. The operation information includes the first physical address of the peripheral device to be accessed and operated. The driver layer maps the first physical address to a kernel virtual address, and operates on the peripheral device based on the kernel virtual address mapped by the first physical address to obtain an operation result. The driver layer feeds back the operation result to the user layer.

2. The method according to claim 1, wherein Before the driver layer maps the first physical address to a kernel virtual address, the method further includes: The driver layer detects whether the current virtual address mapping condition is satisfied. Wherein, the driver layer executes the step of mapping the first physical address to a kernel virtual address when it detects that the current virtual address mapping condition is satisfied.

3. The method according to claim 2, wherein The virtual address mapping condition includes that there is no address out-of-bounds in this access operation. The driver layer detects whether the current virtual address mapping condition is satisfied, including: The driver layer detects whether there is an address out-of-bounds in this access operation based on the first physical address. And / or, the virtual address mapping condition includes that there are available virtual address resources in the operating system kernel currently. The driver layer detects whether the current virtual address mapping condition is satisfied, including: The driver layer applies for virtual address resources from the operating system kernel and receives the application feedback result from the operating system kernel. The application feedback result includes that there are no available virtual address resources currently, or there are available virtual address resources currently.

4. The method according to claim 2, wherein The virtual address mapping condition includes that there is no address out-of-bounds in this access operation and there are available virtual address resources in the operating system kernel currently. The driver layer detects whether the current virtual address mapping condition is satisfied, including: The driver layer detects whether there is an address out-of-bounds in this access operation based on the first physical address. In response to there being no address out-of-bounds in this access operation, the driver layer applies for virtual address resources from the operating system kernel and receives the application feedback result from the operating system kernel. In response to the application feedback result indicating that there are available virtual address resources currently, execute the step of the driver layer mapping the first physical address to a kernel virtual address.

5. The method according to claim 3 or 4, characterized in that, The driver layer detects whether there is an address out-of-bounds in this access operation based on the first physical address, including: The driver layer detects whether the first physical address belongs to a preset operation area. In response to the first physical address belonging to the preset operation area, it is determined that there is no address out-of-bounds in this access operation, and in response to the first physical address not belonging to the preset operation area, it is determined that there is an address out-of-bounds in this access operation.

6. The method according to claim 5, characterized in that Before the user layer of the embedded system obtains the operation information input by the user through the device node, the method further includes: The driver layer determines a preset operation area based on the second physical address in the peripheral device configuration information, where the peripheral device configuration information is generated by the embedded device side of the embedded system based on the designed function and provided to the driver layer.

7. The method according to any one of claims 3 to 6, characterized in that, After detecting whether there is an address out-of-bounds in the current access operation based on the first physical address in the driver layer, the method further includes: In response to the current access operation having an address out-of-bounds, the driver layer returns a first error prompt to the user layer to indicate that the current access operation has an address out-of-bounds.

8. The method according to any one of claims 3 to 7, characterized in that, After receiving the application feedback result from the operating system kernel, the method further includes: In response to the application feedback result indicating that there is currently no available virtual address resource, the driver layer returns a second error prompt to the user layer to indicate that there is no available virtual address resource currently.

9. The method according to any one of claims 1 to 8, characterized in that The peripheral device is a peripheral register, and the operation information can characterize that the current access operation is a read operation or a write operation; Operating on the peripheral device based on the kernel virtual address to obtain an operation result includes: In response to the current access operation being a read operation, performing a read operation on the peripheral device based on the kernel virtual address mapped from the first physical address, obtaining the stored data corresponding to the first physical address, and generating a first operation result indicating that the read operation is successful, where the first operation result includes the stored data corresponding to the first physical address; In response to the current access operation being a write operation, obtaining the data to be written from the operation information, performing a write operation on the peripheral device based on the kernel virtual address mapped from the first physical address to write the data to be written into the space corresponding to the first physical address, and generating a second operation result indicating that the write operation is successful.

10. The method according to any one of claims 1 to 9, characterized in that Before the user layer of the embedded system obtains the operation information input by the user through the device node, the method further includes: The driver layer creates the device node based on the peripheral device configuration information; and / or, The driver layer establishes a mapping relationship between each second physical address and the kernel virtual address in the peripheral device configuration information.

11. The method according to any one of claims 1 to 10, characterized in that, The peripheral device is a peripheral register or a block device; and / or, the operating system of the embedded system is a linux operating system; and / or, the embedded system includes a processor and a field programmable gate array component, the processor can run an operating system, and the peripheral device is configured through the field programmable gate array component.

12. An embedded system, characterized in that, The embedded system is configured to be able to implement the method according to any one of claims 1-11.

13. The system according to claim 12, wherein The embedded system is a system-on-chip including a processor and a field programmable gate array component.