USB implementation system and method based on microkernel user program polling mode
By implementing the USB main control function in the user state of the microkernel operating system and polling the register status value of the USB main controller in the polling mode, the problem of excessive CPU resource occupation in the existing USB data transmission technology is solved, and more efficient USB data transmission and processing is achieved.
Patent Information
- Application Number
- CN202510356169.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-25
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2045-03-25
AI Technical Summary
The existing USB data transmission technology mainly relies on the interrupt drive mode, resulting in a large CPU resource occupancy, affecting the real-time and stability of the system.
The USB implementation system is implemented based on the microkernel user program polling mode. By implementing the USB main control function in the user state of the microkernel operating system, the mapping relationship between virtual memory and physical memory is established, the register status value of the thread polling USB main controller is created, and CPU resources are dynamically allocated.
Real-time monitoring of USB events is realized, which reduces the negative impact on system performance and improves the system's response speed and data processing efficiency.
Smart Images

Figure CN119884004A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of industrial Internet of Things, and in particular to a USB implementation system and method based on a microkernel user program polling mode. Background Art
[0002] In the field of modern industrial automation and intelligent manufacturing, real-time data transmission and processing are essential to improving production efficiency and equipment performance. As a key data transmission interface technology, SuperSpeed USB (USB 3.0) plays a core role in the Industrial Internet of Things (IIoT). It is widely used in device connection, data transmission and system integration. Its high speed, stability and compatibility make it the preferred solution for communication between industrial equipment. With the increasing demand for data transmission rate, USB 3.0 and its subsequent versions provide transmission rates of up to 5Gbps to 10Gbps, which greatly meets the needs of industrial applications.
[0003] Existing USB data transmission technology mainly relies on interrupt-driven mode. In this mode, when a USB device needs to communicate with the host, an interrupt signal is triggered. The host's CPU responds to this interrupt and calls the corresponding driver function to handle the reception or transmission of data. The USB 3.0 specification defines the concept of maximum packet size (MPS), which is usually 512 bytes. At a transmission rate of 5Gbps, about 1,250,000 packets need to be processed per second, which requires the CPU to respond to interrupts quickly and process a large number of packets. Since interrupt processing occupies a large amount of CPU resources, it may cause the system response time to increase, thus affecting the real-time performance and stability of the entire system. Summary of the invention
[0004] The present application embodiment provides a USB implementation system based on a microkernel user program polling mode. In order to have a basic understanding of some aspects of the disclosed embodiments, a simple summary is given below. This summary is not a general review, nor is it intended to identify key / important components or describe the scope of protection of these embodiments. Its only purpose is to present some concepts in a simple form as a preface to the detailed description that follows.
[0005] In a first aspect, an embodiment of the present application provides a USB implementation system based on a microkernel user program polling mode, the system comprising: Industrial IoT service platform, microkernel operating system and USB host controller; among them, The microkernel operating system and USB host controller are integrated into the industrial IoT service platform. The microkernel operating system includes a user-mode USB driver. Industrial IoT service platform, used to initialize the USB driver when powered on; The USB driver is used to establish a mapping relationship between the virtual memory and the physical memory during the initialization process and create a thread; in the created thread, based on the mapping relationship, poll the status value of the register in the USB host controller; The USB host controller is used to respond to the polling instruction of the USB driver, obtain the status value of the register and feed it back to the USB driver; The USB driver is also used to receive the status value of the register fed back by the USB host controller, detect the target read and write events that occur according to the status value of the register, and call the corresponding event processing function to process the target read and write events.
[0006] Optionally, the physical memory corresponds to a physical address of a register, and the physical address includes an xHCI register address; Establish a mapping relationship between virtual memory and physical memory, including: According to the memory mapping address provided by the CPU chip, determine the base address of the xHCI register address; According to the preset xHCI standard protocol, determine the offset address of the xHCI register address; Create a mapped memory size based on the offset address range; Through the system function and the mapped memory size, the base address is mapped to the kernel virtual address area to establish a mapping relationship between the virtual address corresponding to the kernel virtual address area and the physical address, and obtain a mapping relationship between the virtual memory and the physical memory.
[0007] Optionally, the physical address also includes the xHCI memory address; The USB driver is also used to dynamically obtain the xHCI memory address and the virtual address corresponding to the xHCI memory address through the system function; and establish a mapping relationship between the xHCI memory address and the virtual address corresponding to the xHCI memory address.
[0008] Optionally, the register in the USB host controller is a USB status register; Based on the mapping relationship, poll the status values of the registers in the USB host controller, including: When the time between the current moment and the last polling moment is equal to the preset period, obtaining the target virtual address of the USB status register; From the mapping relationship, query the target physical address corresponding to the target virtual address; The target physical address is accessed through the target virtual address to read the status value of the register in the USB host controller.
[0009] Optionally, the target read and write events are detected based on the status value of the register, including: Parse the status value of the register to check whether a preset bit of the register is set and obtain the check result; Determine the type of event that occurred based on the preset bit set in the register; Use the event corresponding to the event type as the target read / write event.
[0010] Optionally, the type of event that occurred is determined based on the preset bit set in the register, including: When the register is a USBSTS register and the preset bit set in the register is the EINT bit, it is determined that an interrupt occurs, and the interrupt occurs as the type of event that occurs.
[0011] Optionally, call the corresponding event processing function to handle the target read and write events, including: When the event type of the target read / write event is an event type with an interrupt, the interrupt flag of USBSTS is cleared, and the IP suspend state in the register IMAN is cleared; Call the xHCI event processing function to handle target read and write events.
[0012] Optionally, the type of event that occurred is determined based on the preset bit set in the register, including: When the register is the PORTSC register and the preset bit set in the register is the CONNECT bit, it is determined that a new device is connected to the port, and the new device is connected to the port as the type of event that occurs.
[0013] Optionally, the industrial Internet of Things service platform is a product platform based on the RK3568 chip, the microkernel operating system is the XiZi microkernel operating system, and the main control function of the USB host controller is implemented in the user state.
[0014] In a second aspect, a USB implementation method based on a microkernel user program polling mode comprises: When the Industrial Internet of Things service platform is powered on, it initializes the USB driver; During the initialization process, the USB driver establishes a mapping relationship between the virtual memory and the physical memory and creates a thread; in the created thread, based on the mapping relationship, the status value of the register in the USB host controller is polled; The USB host controller responds to the polling instruction of the USB driver, obtains the status value of the register and feeds it back to the USB driver; The USB driver receives the status value of the register fed back by the USB host controller, detects the target read and write events that occur according to the status value of the register, and calls the corresponding event processing function to process the target read and write events.
[0015] In the embodiment of the present application, on the one hand, by creating a thread to poll the status value of the xHCI register, the scheme realizes real-time monitoring of USB events, and through the polling mechanism in the user program, CPU resources can be dynamically allocated, thereby reducing the negative impact on system performance. On the other hand, by realizing the USB main control function in the user state of the microkernel operating system, the response speed and data processing efficiency of the system can be improved. During the initialization process, the USB driver establishes a mapping relationship between virtual memory and physical memory, so that the user state program can directly access the register of the USB host controller. This mapping mechanism not only simplifies the interaction between the user state and the hardware, but also reduces the burden on the operating system kernel.
[0016] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0018] Figure 1 1 is a schematic diagram of the system structure of a USB implementation system based on a microkernel user program polling mode provided in an embodiment of the present application; Figure 2 It is a flow chart of a USB implementation method based on microkernel user program polling mode provided in an embodiment of the present application. DETAILED DESCRIPTION
[0019] The following description and the accompanying drawings sufficiently illustrate specific embodiments of the present application to enable those skilled in the art to practice them.
[0020] It should be clear that the described embodiments are only 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 ordinary technicians in the field without creative work are within the scope of protection of the present application.
[0021] When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Instead, they are only examples of systems and methods consistent with some aspects of the present application as detailed in the attached claims.
[0022] In the description of the present application, it should be understood that the terms "first", "second", etc. are used for descriptive purposes only and should not be understood as indicating or implying relative importance. For those of ordinary skill in the art, the specific meanings of the above terms in the present application can be understood according to the specific circumstances. In addition, in the description of the present application, unless otherwise specified, "multiple" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects associated before and after are in an "or" relationship.
[0023] The present application provides a USB implementation system and method based on a microkernel user program polling mode. In the embodiment of the present application, on the one hand, by creating a thread to poll the status value of the xHCI register, the scheme realizes real-time monitoring of USB events. Through the polling mechanism in the user program, CPU resources can be dynamically allocated, thereby reducing the negative impact on system performance. On the other hand, by implementing the USB main control function in the user state of the microkernel operating system, the response speed and data processing efficiency of the system can be improved. During the initialization process, the USB driver establishes a mapping relationship between virtual memory and physical memory, so that the user state program can directly access the register of the USB host controller. This mapping mechanism not only simplifies the interaction between the user state and the hardware, but also reduces the burden of the operating system kernel. The following exemplary embodiments are used to describe in detail.
[0024] See also Figure 1 , Figure 1 This is a system structure diagram of a USB implementation system based on a microkernel user program polling mode provided in an embodiment of the present application, the system comprising: an industrial Internet of Things service platform, a microkernel operating system and a USB host controller; the microkernel operating system and the USB host controller are integrated in the industrial Internet of Things service platform, and the microkernel operating system includes a user-mode USB driver.
[0025] Among them, the Industrial Internet of Things Service Platform is a service platform designed for Industrial Internet of Things (IIoT) applications. It usually contains hardware (such as processors, sensors, communication modules, etc.) and software (such as operating systems, middleware, applications, etc.) to support device connection, data collection, processing and analysis in industrial environments. The Industrial Internet of Things Service Platform can realize remote monitoring, control and management of equipment, improve production efficiency and automation level. The microkernel operating system is an operating system architecture whose core (kernel) only contains the most basic functions, such as process management, memory management, etc. Other functions, such as file systems, network protocols, device drivers, etc., are implemented in user mode. The advantages of this architecture include modularity, security, flexibility and scalability. The microkernel operating system is suitable for embedded systems and real-time systems that require high security and stability. The USB host controller is a hardware component responsible for managing and controlling USB devices (such as keyboards, mice, storage devices, etc.). It implements the USB protocol and handles data transmission and control of USB devices. In USB 3.0, the host controller usually adopts the xHCI (eXtensibleHost Controller Interface) standard to support high-speed data transmission and more complex device management functions. xHCI (eXtensible Host Controller Interface) is a USB host controller interface standard developed by Intel. In terms of hardware, the xHCI controller is usually integrated into the motherboard chipset or exists as an independent USB 3.0 / 3.1 / 3.2 controller chip. In terms of software, the operating system needs to contain xHCI drivers to communicate with the xHCI controller. These drivers are responsible for initializing the controller, configuring the device, processing data transfer requests, and managing power status. The user-mode USB driver is a software module running in the user mode of the microkernel operating system, which is responsible for interacting with the USB host controller to implement the functions of the USB device. Unlike traditional kernel-mode drivers, user-mode drivers have higher flexibility and portability, while reducing the switching overhead between kernel mode and user mode. The user-mode driver interacts with the kernel mode through system calls to access and control the USB host controller.
[0026] In some embodiments of the present application, the industrial Internet of Things service platform is used to initialize the USB driver when the power is turned on; the USB driver is used to establish a mapping relationship between virtual memory and physical memory and create a thread during the initialization process; in the created thread, based on the mapping relationship, the status value of the register in the USB host controller is polled; the USB host controller is used to respond to the polling instruction of the USB driver, obtain the status value of the register and feed it back to the USB driver; the USB driver is also used to receive the status value of the register fed back by the USB host controller, and detect the target read and write events that occur according to the status value of the register, and call the corresponding event processing function to process the target read and write events.
[0027] In the embodiment of the present application, on the one hand, by creating a thread to poll the status value of the xHCI register, the scheme realizes real-time monitoring of USB events, and through the polling mechanism in the user program, CPU resources can be dynamically allocated, thereby reducing the negative impact on system performance. On the other hand, by realizing the USB main control function in the user state of the microkernel operating system, the response speed and data processing efficiency of the system can be improved. During the initialization process, the USB driver establishes a mapping relationship between virtual memory and physical memory, so that the user state program can directly access the register of the USB host controller. This mapping mechanism not only simplifies the interaction between the user state and the hardware, but also reduces the burden on the operating system kernel.
[0028] The physical memory corresponds to a physical address of a register, and the physical address includes an xHCI register address.
[0029] In some embodiments of the present application, the specific process of establishing a mapping relationship between virtual memory and physical memory includes: determining the base address of the xHCI register address according to the memory mapping address provided by the CPU chip; determining the offset address of the xHCI register address according to the preset xHCI standard protocol; creating a mapping memory size based on the range of the offset address; mapping the base address to the kernel virtual address area through system functions and the mapped memory size to establish a mapping relationship between the virtual address corresponding to the kernel virtual address area and the physical address, and obtain a mapping relationship between the virtual memory and the physical memory.
[0030] For example, the base address is mapped into the kernel virtual address area through a system function (such as the ioremap function in Linux) and the mapped memory size.
[0031] Among them, the physical address also includes the xHCI memory address. The xHCI memory address refers to the memory required by xHCI, including the memory corresponding to DCBAAP, command memory, event memory, and scratchpad memory. The xHCI standard protocol requires that the memory address written to the register is a physical address. Therefore, in the user program, it is necessary to call the system function to dynamically obtain the physical address and the corresponding virtual address, and write the physical address to the corresponding xHCI register.
[0032] In some embodiments of the present application, the USB driver is also used to dynamically obtain the xHCI memory address and the virtual address corresponding to the xHCI memory address through a system function; and establish a mapping relationship between the xHCI memory address and the virtual address corresponding to the xHCI memory address.
[0033] Among them, the register in the USB host controller is a USB status register.
[0034] In some embodiments of the present application, based on the mapping relationship, the specific process of polling the status value of the register in the USB host controller includes: when the duration between the current moment and the previous polling moment is equal to a preset period, obtaining the target virtual address of the USB status register; from the mapping relationship, querying the target physical address corresponding to the target virtual address; accessing the target physical address through the target virtual address to read the status value of the register in the USB host controller.
[0035] In some embodiments of the present application, the specific process of detecting the occurrence of a target read / write event based on the status value of a register includes: parsing the status value of the register to check whether a preset bit of the register is set to obtain a check result; determining the type of event that occurred based on the preset bit set in the register; and taking the event corresponding to the event type as the target read / write event.
[0036] In some embodiments of the present application, the specific process of determining the type of event that occurred based on the preset bit set in the register includes: when the register is a USBSTS register and the preset bit set in the register is the EINT bit, it is determined that an interrupt has occurred, and the interrupt that occurred is used as the type of event that occurred.
[0037] In some embodiments of the present application, calling the corresponding event processing function to process the target read and write events specifically includes: when the event type of the target read and write event is an event type in which an interrupt occurs, clearing the interrupt flag of USBSTS and clearing the IP suspend state in the register IMAN; calling the xHCI event processing function to process the target read and write events.
[0038] The xHCI standard protocol provides a USB status register (USBSTS), in which the Event Interrupt (EINT) bit indicates the interrupt status. The xHCI standard protocol also provides an interrupt management register (IMAN), which can configure whether the interrupt is enabled (IE) and set the interrupt pending status (IP).
[0039] In some embodiments of the present application, the specific process of determining the type of event that occurred based on the preset bit set in the register includes: when the register is a PORTSC register and the preset bit set in the register is the CONNECT bit, it is determined that a new device is connected to the port, and the connection of the new device to the port is regarded as the type of event that occurred.
[0040] Specifically, the industrial Internet of Things service platform is a product platform based on the RK3568 chip, the microkernel operating system is the XiZi microkernel operating system, and the main control function of the USB host controller is implemented in user mode.
[0041] In the embodiment of the present application, the microkernel operating system can realize the advantage of peripheral drivers in user mode, detect the state of specific registers of the USB host controller (xHCI) through the polling mechanism, detect the occurrence of events, and call event processing tasks. Through the polling mechanism in the user program, CPU resources can be dynamically allocated, thereby reducing the negative impact on system performance.
[0042] See also Figure 2 , which is a flowchart of a USB implementation method based on a microkernel user program polling mode according to an embodiment of the present application. Figure 2 As shown, the method may include the following steps: S101, when the industrial IoT service platform is powered on, the USB driver is initialized; S102, during the initialization process, the USB driver establishes a mapping relationship between the virtual memory and the physical memory and creates a thread; in the created thread, based on the mapping relationship, polls the status value of the register in the USB host controller; S103, the USB host controller responds to the polling instruction of the USB driver, obtains the status value of the register and feeds it back to the USB driver; S104, the USB driver receives the state value of the register fed back by the USB host controller, detects the target read / write event according to the state value of the register, and calls a corresponding event processing function to process the target read / write event.
[0043] Among them, the mapping relationship between virtual memory and physical memory is a mechanism created by the operating system, which allows software components to access actual physical memory addresses through virtual addresses. Threads are concurrently executed program fragments used to perform specific tasks, such as polling hardware registers. Register status values are values stored in the USB host controller registers, reflecting the state of the controller and the events that have occurred. Target read and write events refer to specific events that occur in USB devices, such as device connection, disconnection, data transfer completion, etc. These events require special processing by the driver.
[0044] In some embodiments, when the industrial Internet of Things service platform is started, the microkernel operating system loads and initializes the user-mode USB driver. The USB driver uses system calls to establish a mapping relationship between virtual memory and physical memory in order to access the registers of the USB host controller. The driver creates one or more threads for polling the status register of the USB host controller. In the polling thread, the driver periodically reads the status register of the USB host controller to check whether any event has occurred. The USB host controller responds to the driver's polling instruction and feeds back the status value of the register to the driver. The driver detects the event that occurs based on the status value of the register and calls the corresponding event processing function. Depending on the type of event detected, the driver calls the corresponding processing function to handle the event, such as initializing the device, processing data transmission, etc.
[0045] In the embodiment of the present application, on the one hand, by creating a thread to poll the status value of the xHCI register, the scheme realizes real-time monitoring of USB events, and through the polling mechanism in the user program, CPU resources can be dynamically allocated, thereby reducing the negative impact on system performance. On the other hand, by realizing the USB main control function in the user state of the microkernel operating system, the response speed and data processing efficiency of the system can be improved. During the initialization process, the USB driver establishes a mapping relationship between virtual memory and physical memory, so that the user state program can directly access the register of the USB host controller. This mapping mechanism not only simplifies the interaction between the user state and the hardware, but also reduces the burden on the operating system kernel.
[0046] The present application also provides a computer-readable medium having program instructions stored thereon, which, when executed by a processor, implement the USB implementation method based on the microkernel user program polling mode provided by the above-mentioned various method embodiments.
[0047] The present application also provides a computer program product including instructions, which, when executed on a computer, enables the computer to execute the USB implementation method based on the microkernel user program polling mode of each of the above method embodiments.
[0048] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing related hardware through a computer program, and the program based on the USB implementation of the microkernel user program polling mode can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium of the USB implementation based on the microkernel user program polling mode can be a disk, an optical disk, a read-only storage memory, or a random access memory, etc.
[0049] The above disclosure is only the preferred embodiment of the present application, which certainly cannot be used to limit the scope of rights of the present application. Therefore, equivalent changes made according to the claims of the present application are still within the scope covered by the present application.
Claims
1. A USB implementation system based on microkernel user program polling mode, characterized in that: The system comprises: Industrial IoT service platform, microkernel operating system and USB host controller; among them, The microkernel operating system and the USB host controller are integrated into the industrial IoT service platform, and the microkernel operating system includes a user-mode USB driver; The industrial IoT service platform is used to initialize the USB driver when powered on; The USB driver is used to establish a mapping relationship between the virtual memory and the physical memory during the initialization process and create a thread; in the created thread, based on the mapping relationship, poll the status value of the register in the USB host controller; The USB host controller is used to respond to the polling instruction of the USB driver, obtain the status value of the register and feed it back to the USB driver; The USB driver is also used to receive the state value of the register fed back by the USB host controller, detect the target read / write event according to the state value of the register, and call the corresponding event processing function to process the target read / write event.
2. The system according to claim 1, characterized in that The physical memory corresponds to a physical address of the register, and the physical address includes an xHCI register address; Establish a mapping relationship between virtual memory and physical memory, including: Determine the base address of the xHCI register address according to the memory mapping address provided by the CPU chip; Determine the offset address of the xHCI register address according to the preset xHCI standard protocol; Based on the range of the offset address, create a mapped memory size; The base address is mapped to the kernel virtual address area through the system function and the mapped memory size to establish a mapping relationship between the virtual address corresponding to the kernel virtual address area and the physical address, thereby obtaining a mapping relationship between the virtual memory and the physical memory.
3. The system according to claim 2, characterized in that The physical address also includes an xHCI memory address; The USB driver is further used to dynamically obtain the xHCI memory address and the virtual address corresponding to the xHCI memory address through a system function; and establish a mapping relationship between the xHCI memory address and the virtual address corresponding to the xHCI memory address.
4. The system according to claim 2, characterized in that The register in the USB host controller is a USB status register; The step of polling the status value of the register in the USB host controller based on the mapping relationship includes: When the time between the current moment and the last polling moment is equal to the preset period, obtaining the target virtual address of the USB status register; From the mapping relationship, query the target physical address corresponding to the target virtual address; The target physical address is accessed through the target virtual address to read the status value of the register in the USB host controller.
5. The system according to claim 1, characterized in that The detecting a target read / write event occurring according to the state value of the register comprises: Parsing the state value of the register to check whether a preset bit of the register is set, and obtaining a check result; Determining the type of event that occurred according to the preset bit that is set in the register; The event corresponding to the event type is used as the target read / write event.
6. The system according to claim 5, characterized in that The determining the type of event that occurs according to the preset bit set in the register includes: When the register is a USBSTS register and the preset bit set in the register is the EINT bit, it is determined that an interrupt occurs, and the interrupt occurs as the type of event that occurs.
7. The system according to claim 6, characterized in that The calling of a corresponding event processing function to process the target read / write event includes: When the event type of the target read / write event is an event type in which an interrupt occurs, clear the interrupt flag of USBSTS, and clear the IP suspend state in the register IMAN; The xHCI event processing function is called to process the target read and write events.
8. The system according to claim 5, characterized in that The determining the type of event that occurs according to the preset bit set in the register includes: When the register is a PORTSC register and the preset bit set in the register is a CONNECT bit, it is determined that a new device is connected to the port, and the new device is connected to the port is regarded as the type of event that occurs.
9. The system according to claim 1, characterized in that The industrial Internet of Things service platform is a product platform based on the RK3568 chip, the microkernel operating system is the XiZi microkernel operating system, and the main control function of the USB host controller is implemented in the user state.
10. A USB implementation method based on microkernel user program polling mode, characterized in that: The method comprises: When the Industrial Internet of Things service platform is powered on, it initializes the USB driver; During the initialization process, the USB driver establishes a mapping relationship between the virtual memory and the physical memory and creates a thread; in the created thread, based on the mapping relationship, the status value of the register in the USB host controller is polled; The USB host controller responds to the polling instruction of the USB driver, obtains the status value of the register and feeds it back to the USB driver; The USB driver receives the state value of the register fed back by the USB host controller, detects the target read / write event according to the state value of the register, and calls the corresponding event processing function to process the target read / write event.
Citation Information
Patent Citations
Device authentication
CN110069439A
Direct memory access testing method and device based on virtual kernel environment
CN117311896A
Input / output expansion emulation with a programmable device
US20240070092A1