A system and method for USB device multitasking support based on Linux operating system
By optimizing the USB subsystem of the Linux kernel and extending the USB driver functions, combining the multi-process management mechanism and resource allocation strategy, the performance bottlenecks and resource conflicts of USB devices in multi-task scenarios in Linux environments are solved, and efficient and stable USB multi-task support is achieved, improving user experience and system reliability.
Patent Information
- Application Number
- CN202411570939.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-06
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2044-11-06
AI Technical Summary
In Linux environment, USB devices face problems such as resource competition, unreasonable task scheduling and degradation in multi-task scenarios, which affect user experience and system stability.
By optimizing the USB subsystem of the Linux kernel, expanding the USB driver functions, and introducing a multi-process management mechanism and resource allocation strategy, efficient multi-tasking support for USB devices is achieved. Specific measures include adding USB host-specific equipment and slave-specific equipment to the host and slave-specific equipment on the Linux USB system respectively, and using process resource management modules, host driver modules, slave driver modules and business processing modules to optimize the collaborative working mechanism between each module.
It realizes efficient and stable operation of USB devices in a multi-task environment, reduces the risks of task conflicts and resource competition, provides users with a smoother and more stable USB experience, and enhances the overall reliability and user satisfaction of the system.
Smart Images

Figure CN119065820B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of communication data processing, and more specifically, relates to a system and method for multi-tasking support of USB devices based on Linux operating system. Background Art
[0002] With the widespread application and continuous development of the Linux operating system, it has shown strong vitality and flexibility in many fields such as servers, embedded systems, cloud computing, and personal desktops. Linux has become the preferred operating system platform for many companies and developers due to its open source, stable, and efficient features. However, in the Linux environment, there are still some challenges and limitations in the multitasking support of USB (Universal Serial Bus) devices.
[0003] Chinese invention patent CN101691111A discloses an embedded vehicle-mounted multifunctional information platform, which uses ARM11 as an embedded CPU, runs a LINUX operating system, and performs multi-tasking, multi-process, and simultaneous management of multiple device modules.
[0004] First of all, as an important interface for computers to communicate with external devices, the multitasking capability of USB devices directly affects the overall performance of the system and user experience. In Linux systems, traditional USB device access is often achieved through the USB driver and file system interface provided by the kernel. This method performs well when processing simple tasks of a single USB device, but in multitasking scenarios, especially when complex tasks of multiple USB devices need to be processed simultaneously, problems such as resource contention, unreasonable task scheduling, and performance degradation will occur.
[0005] Secondly, although the Linux kernel's USB system provides rich functions and powerful scalability, it still needs to be continuously optimized and improved when facing diverse USB devices and complex application scenarios. Especially in terms of multi-tasking support, the Linux kernel needs to be able to efficiently manage and schedule access requests from multiple USB devices to ensure that they can obtain system resources fairly and orderly, thereby meeting users' needs for high performance and high reliability.
[0006] However, existing Linux USB multitasking support methods often have many shortcomings. On the one hand, they cannot fully utilize system resources, resulting in the inability to fully utilize the performance of USB devices; on the other hand, they lack effective task scheduling and conflict resolution mechanisms, resulting in conflicts and errors when multiple USB devices work simultaneously. These problems not only affect the user experience, but also threaten the stability and security of the system. Summary of the invention
[0007] The present invention aims to overcome at least one defect of the above-mentioned prior art, and proposes a system and method for multi-tasking support of USB devices based on the Linux operating system. The present invention realizes efficient multi-tasking support of USB devices under the Linux system through an innovative multi-process management mechanism and a resource allocation strategy mechanism. Specifically, the present invention improves the system's processing capability for USB devices, reduces the risk of task conflicts and resource contention, and provides users with a smoother, more stable, and more efficient USB usage experience by optimizing the USB subsystem of the Linux kernel, expanding the functions of the USB driver, and introducing multiple multi-tasking related modules and processing mechanisms.
[0008] The detailed technical scheme of the present invention is as follows:
[0009] A system for USB device multitasking support based on Linux operating system, the system comprising a Linux USB system host side and a Linux USB system slave side:
[0010] The host-side architecture of the Linux USB system includes, from bottom to top, a host, a USB host control layer, a USB core layer, and a USB host function driver layer, wherein the USB host function driver layer adds a USB host-specific device;
[0011] The USB host dedicated device is used for resource configuration and distribution of multiple tasks, and provides an interactive function with the USB slave dedicated device data packet;
[0012] The Linux USB system slave side architecture includes from bottom to top: USB hardware device, USB device control layer, USB composite layer, USB host controller interface layer and USB slave function driver layer, in which USB slave dedicated device is added;
[0013] The USB slave dedicated device is used to receive, analyze and respond to data packets sent by the Linux USB system host side.
[0014] Furthermore, the USB host-specific device includes a process resource management module, a host driver module and a host-side data processing module;
[0015] The process resource management module, as the cornerstone of multi-tasking implementation, is responsible for dynamically allocating resources required by the host multi-tasking;
[0016] The host driver module is used to complete the fine configuration of USB endpoints, the optimal selection of communication methods, and the accurate submission and efficient acquisition of messages;
[0017] The host-side data processing module is used to distribute and process multi-task data packets;
[0018] The USB slave dedicated device includes a slave driver module, a slave side data processing module and a service processing module;
[0019] The slave driver module is used to drive the operation of the slave device link;
[0020] The slave-side data processing module is used to receive, analyze, convert and send USB host data; further, the slave-side data processing module also alarms to complete the collection of blocking data;
[0021] The service processing module is used to receive multi-task data packets sent by the Linux USB system host side and implement specific service logic, including but not limited to data protocol conversion and user interaction response.
[0022] In addition, the present invention also includes a method for implementing a system for USB device multi-tasking support based on a Linux operating system, the method comprising:
[0023] S1. Register the newly added USB slave-specific device in the USB device controller interface layer based on the Linux USB system slave side, and flexibly configure the various parameters and communication capabilities of the USB slave-specific device in conjunction with the memory-based file system. After the configuration is completed, the system will automatically load the Linux USB system slave side data processing module and business processing module:
[0024] The slave-side data processing module is used for receiving, analyzing, converting and sending USB host data;
[0025] The service processing module is used to receive multi-task data packets sent by the Linux USB system host side and implement specific service logic, including but not limited to data protocol conversion and user interaction response;
[0026] S2. Registering a newly added USB host-specific device in the USB core layer on the host side of the Linux USB system to enhance the USB data processing capability of the host side of the Linux USB system in a multi-task concurrent scenario;
[0027] S3. When the USB hardware device is inserted into the host, the change of VBUS voltage is detected immediately, and then the USB host control layer interrupt is triggered; the response mechanism of this interrupt automatically calls back to the initialization function pre-registered on the USB bus and exclusively serving the USB slave-specific device, to create a data structure, create a buffer area, and start the data unit processing module and business processing module functions on the slave side of the Linux USB system;
[0028] Furthermore, the USB hardware device is a physical device.
[0029] S4, the user creates Task 1 and Task N on the Linux USB system host side through the system call interface provided by the USB host dedicated device, and saves the returned task handles. At the same time, the handles and related resources of this task are strongly bound in the process resource management module;
[0030] S5. After receiving the request, the process resource management module on the Linux USB system host side creates the resources required for Task 1 and Task N. Then, the process resource management module binds the handle to the kernel file and returns the handle to the user call layer on the Linux USB system host side.
[0031] Furthermore, the resources required for creating Task 1 and Task N include, but are not limited to, applying for a resource structure of the task, allocating a data buffer, setting a task priority, and generating a task identifier.
[0032] S6. In the multi-tasking environment of the Linux USB system host side, the user uses the system call interface ( Figure 2 , system call layer), performs data writing operations on Task 1 and Task N;
[0033] S7, when the process resource management module of the USB host dedicated device on the Linux USB system host side receives the system call request, it first accurately binds the unique identification bit assigned by the process resource management module on the Linux USB system host side to the message written by the identification bit; then, the process resource management module applies for a corresponding data structure for the message, and the process resource management module sends the encapsulated data to the USB endpoint of the specified USB hardware device through the USB core layer on the Linux USB system host side calling the interface of the USB host control layer, and finally, the data is sent to the USB slave dedicated device;
[0034] S8. On the slave side of the Linux USB system, after the USB hardware device triggers a hardware interrupt, the USB device control layer will call back the function interface that matches the device, and then the function interface will further bind the corresponding data structure of the USB composite layer according to the USB specific information, and finally call the USB slave-specific device related interface previously registered in the USB device controller structure layer to receive data; the slave-side data processing module and the slave driver module use an efficient IPC mechanism to monitor and receive the data sent from the Linux USB system host side; after the data is received, the slave-side data processing module forwards the data packet that meets the rules to the business processing module, and the latter performs professional business processing;
[0035] S9. On the slave side of the Linux USB system, after receiving the data sent by the host side of the Linux USB system, the business processing module immediately uses the custom dedicated protocol to encapsulate and process the data; then, according to business needs, the business processing module will process the encapsulated data, including in-depth calculation analysis or preparation for the next transmission operation; wherein, the custom dedicated protocol is expanded according to actual needs.
[0036] S10, on the Linux USB system slave side, after completing the data processing, the service processing module is connected to the slave driver module, and the processed corresponding data is efficiently and safely transmitted to the Linux USB system host side by using the URB mechanism;
[0037] S11, on the host side of the Linux USB system, the host side data processing module and the host driver module jointly undertake the task of receiving data on the host side of the Linux USB system; according to the custom dedicated protocol in S9, the host side data processing module performs format analysis on the received data packets; then, through the packet format verification mechanism, the data packets that do not meet the specifications are screened; for the data packets that pass the verification, the host side data processing module accurately distributes them to the corresponding task queue according to their identification information;
[0038] S12. On the host side of the Linux USB system, once the host side data processing module successfully fills the parsed and verified data packets into the respective task queues, it will immediately work with the IPC mechanism to wake up the task queues, and then the user will read the data through the user call layer and continue to wait for the transmission of subsequent data packets, and the cycle continues.
[0039] Furthermore, the method also includes user acquisition of data: the user retrieves and obtains the required data from one or more ready task queues through a standard calling interface provided by the system, and implements real-time access and extraction of data of task 1 or task N.
[0040] Furthermore, the method also includes a resource recovery operation: the user initiates a request to close the task channel through a dedicated API interface provided by a dedicated device on the Linux USB system host side; then, the process resource management module of the USB host dedicated device responds to the request and performs a corresponding resource recovery operation.
[0041] Furthermore, the interaction between the process resource management module on the host side of the Linux USB system and the business processing module and the data processing module on the slave side of the Linux USB system adopts a custom dedicated protocol for communication, thereby ensuring the security and integrity of the information;
[0042] Specifically, when data is sent on the Linux USB system host side or the Linux USB system slave side, a custom dedicated protocol will be added before the data; the custom dedicated protocol format includes but is not limited to the start identifier of the data frame and the entire data packet, and the custom fields will be expanded later according to needs.
[0043] Furthermore, the data is sent using a custom dedicated protocol as follows:
[0044] S01. On the Linux USB system host side, the process resource management module is responsible for encapsulating the data to be sent according to the custom dedicated protocol format. The encapsulated data format contains not only a unique protocol header, but also key information such as the task identifier (used to bind the buffer area), task priority, packet sequence number, and user data, thereby ensuring the integrity and identifiability of the data during transmission. Subsequently, these encapsulated data packets are accurately sent to the USB slave dedicated device.
[0045] S02. On the slave side of the Linux USB system, the slave side data processing module works closely with the slave driver module to monitor and receive the received data. The URB linked list and IPC mechanism can safely receive and forward data to the business processing module. The business processing module then uses a custom dedicated protocol format to deeply analyze the received data and calls a dedicated business interface to perform a series of efficient data processing tasks. After processing, the response packet data will also be repackaged according to the custom dedicated protocol format, and the processing results will be quickly responded to the Linux USB system host side through the slave driver module.
[0046] S03. On the host side of the Linux USB system, the host side data processing module works with the host driver module to continuously monitor and process data from the USB slave dedicated device. Based on the identification information in the custom dedicated protocol, they can accurately classify the data or discard data packets that do not meet the requirements to ensure the stability of the system and the accuracy of the data.
[0047] In another aspect of the present invention, a computer-readable storage medium is provided, which stores executable instructions, and when the instructions are executed, the machine executes the method for multi-tasking support of USB devices based on the Linux operating system as described above.
[0048] Compared with the prior art, the present invention has the following beneficial effects:
[0049] (1) The present invention provides a system and method for supporting USB device multitasking based on the Linux operating system, which solves the problem that USB devices often face performance bottlenecks and resource conflicts when processing multitasking in the traditional Linux environment, affecting user experience and system stability; by optimizing the USB subsystem of the Linux kernel, expanding the USB driver function, and introducing an efficient inter-process communication (IPC) mechanism and modules, the USB device can run efficiently and stably in a multitasking environment. This improvement not only reduces the risk of system errors, but also provides users with a smoother and more stable USB experience, enhancing the overall reliability of the system and user satisfaction.
[0050] (2) The present invention provides a system and method for supporting USB device multitasking based on the Linux operating system, which realizes the addition of multiple key modules on the host side and the slave side of the Linux USB system, such as the process resource management module, the slave side data processing module and the business processing module, and realizes efficient resource utilization and flexible scheduling by optimizing the collaborative working mechanism between the modules. This design enables the system to dynamically adjust resource allocation according to task requirements, ensuring that key tasks can be given priority processing, while avoiding idleness and waste of resources. In addition, the present invention also provides a flexible API interface, allowing users to create and close task channels according to actual needs, further improving the flexibility and scalability of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 This is a system structure diagram of a USB device multi-tasking support based on a Linux operating system described in the present invention.
[0052] Figure 2 This is a schematic diagram of the USB host-specific device and the USB slave-specific device described in Example 1.
[0053] Figure 3 This is a schematic diagram of the customized dedicated protocol described in Example 1. DETAILED DESCRIPTION
[0054] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0055] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.
[0056] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit exemplary embodiments according to the present invention. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.
[0057] In the absence of conflict, the embodiments of the present invention and the features of the embodiments may be combined with each other.
[0058] Example 1
[0059] A system for USB device multitasking support based on Linux operating system, the system comprising a Linux USB system host side and a Linux USB system slave side:
[0060] Ginseng Figure 1 The host-side architecture of the Linux USB system includes the host, USB host control layer, USB core layer, and USB host function driver layer from bottom to top, and USB host-specific devices are added to the USB host function driver layer;
[0061] The USB host dedicated device is used for resource configuration and distribution of multiple tasks, and provides an interactive function with the USB slave dedicated device data packet;
[0062] The slave-side architecture of the Linux USB system includes from bottom to top: USB hardware devices, USB device control layer, USB device controller interface layer and USB slave function driver layer. USB slave-specific devices are added to the USB slave function driver layer.
[0063] The USB slave dedicated device is used to receive, analyze and respond to data packets sent by the USB host.
[0064] Specifically, the function of the function driver layer (USB host function driver layer and USB slave function driver layer) is to provide an operation interface of the external device for the upper layer program and implement the device driver, where HD / MTP / is the driver layer protocol.
[0065] Furthermore, the USB host dedicated device includes a process resource management module, a host driver module and a host data processing module, such as Figure 2 As shown;
[0066] As the cornerstone of multi-tasking implementation, the process resource management module is responsible for dynamically allocating the resources required for multi-tasking of the host, including flexible setting of task priority, application and release of data structure memory such as URB (USB request block) and FIFO (first-in-first-out queue). This mechanism ensures efficient utilization and reasonable scheduling of resources, and provides a solid foundation for multi-tasking parallel processing.
[0067] The host driver module is used to complete the fine configuration of USB endpoints, the optimal selection of communication methods, and the accurate submission and efficient acquisition of messages, thereby ensuring smooth and reliable communication between the host and the device. This is the basic work to achieve stable communication between the two parties.
[0068] The Linux USB system host-side data processing module is used to distribute and process multi-task data packets; it plays a core role in distributing and processing multi-task data packets. It can accurately distribute the received data packets to each task, ensuring that each task can receive its own data packet in a timely and accurate manner, thereby completing the functional requirements of multi-task processing.
[0069] The USB slave dedicated device includes a slave driver module, a slave side data processing module and a service processing module, such as Figure 2 As shown;
[0070] The slave driver module is used to drive the operation of the slave device link, ensuring the accuracy and stable operation of the slave device link, and providing a strong guarantee for the reliability of the USB data link.
[0071] The slave-side data processing module is used to receive, parse, convert and send USB host data; further, through the linked list structure, the number of URB data structures is expanded and managed in conjunction with an efficient IPC (inter-process communication) mechanism to complete the blocking data collection work, which is used to provide the business processing module for specific business processing. This process not only improves the efficiency of data collection, but also ensures the integrity and accuracy of the data. Subsequently, the collected data is quickly sent to the business processing module for further processing.
[0072] The service processing module, as the final link of data processing, is used to receive multi-task data packets sent by the Linux USB system host side and implement specific service logic, including but not limited to data protocol conversion and user interaction response.
[0073] In order to maximize the performance of the entire link, this method adds dedicated device drivers on the Linux USB system host side and the Linux USB system slave side and cooperates with the IPC function under Linux to achieve the "flow" of data packets, reducing unnecessary delays and losses, where IPC is the general term for Linux multi-process communication methods. At the same time, this method takes into account factors such as error handling and security in the entire link to ensure that while pursuing high performance, the stability and reliability of the system can also be fully guaranteed. As much as possible, and to maximize the potential of the entire link.
[0074] In summary, the present invention successfully implements an efficient, stable and easily expandable USB multitasking support method by adding multiple key modules on the Linux USB system host side and the Linux USB system slave side, and optimizing the collaborative working mechanism between the modules. This method not only solves the performance bottleneck and resource conflict problems faced by USB devices in traditional Linux environments when processing multitasking, but also brings users a smoother, more stable and efficient USB usage experience.
[0075] This method is implemented based on the above system. A system and method for USB device multitasking support based on Linux operating system specifically includes the following steps: Figure 1 , Figure 2 As shown:
[0076] S1. Register the newly added USB slave-specific device in the USB device controller interface layer on the slave side of the Linux USB system (the device needs to be registered at the bottom layer), and flexibly configure the various parameters and communication capabilities of the USB slave-specific device with the memory-based file system. After the configuration is completed, the system will automatically load the Linux USB system slave-side data processing module and business processing module:
[0077] The slave-side data processing module is used for receiving, analyzing, converting and sending USB host data;
[0078] The service processing module is used to receive multi-task data packets sent by the Linux USB system host side and implement specific service logic, including but not limited to data protocol conversion and user interaction response;
[0079] The automatic loading of these two key modules ensures that the USB slave device can immediately have efficient data processing capabilities and rich business logic support when connected to the host, laying a solid foundation for the connection and communication between the USB slave device and the Linux USB system host side.
[0080] S2. Registering a newly added USB host-specific device in the USB core layer on the host side of the Linux USB system. This measure is intended to enhance the USB data processing capability of the Linux USB system host side and is more suitable for multi-tasking concurrent scenarios.
[0081] S1 and S2 are the preparations after the host is powered on for the first time, laying the foundation for subsequent data processing.
[0082] S3. When the USB hardware device is inserted into the host (USB interface), the change of VBUS voltage is detected immediately, and then the USB host control layer interrupt is triggered; the response mechanism of this interrupt automatically calls back to the initialization function pre-registered on the USB bus and exclusively serving the USB slave-specific device to create a data structure, create a buffer area, and enable the data unit processing module and business processing module functions on the slave side of the LinuxUSB system; further, the USB hardware device is a physical device.
[0083] S4. The user creates Task 1 and Task N on the Linux USB system host side through the system call interface provided by the USB host dedicated device, and saves the returned task handle. The handle and the related resources of this task are strongly bound in the process resource management module.
[0084] S5. After receiving the request, the process resource management module on the Linux USB system host side creates the resources required for Task 1 and Task N. The required resources include applying for the resource structure of the task, allocating data buffer, setting the priority of the task, and generating the task identifier;
[0085] After completing the above preparations, the process resource management module will bind the handle to the kernel file and return the handle to the user call layer on the Linux USB system host side ( Figure 2 , system call layer) for subsequent use.
[0086] S6. In the multi-tasking environment of the Linux USB system host side, the user performs a data write operation on Task 1 and Task N through a system call interface;
[0087] S7. When the process resource management module of the USB host-specific device on the Linux USB system host side receives the system call request, it first accurately binds the unique identification bit assigned by the process resource management module on the Linux USB system host side to the message written by the identification bit; then, the process resource management module applies for a corresponding data structure for the message, and the process resource management module sends the encapsulated data to the USB endpoint of the specified USB hardware device through the USB core layer on the Linux USB system host side calling the interface of the USB host control layer. Finally, the data is sent to the USB slave-specific device.
[0088] S8. On the slave side of the Linux USB system, after the USB hardware device triggers a hardware interrupt, it will call back the USB device control layer to match the functional interface of the device. Then the functional interface will further bind the corresponding data structure of the USB composite layer according to the USB specific information, and finally call the USB slave-specific device related interface previously registered in the USB device controller structure layer to receive data. The slave-side data processing module works closely with the slave driver module and uses an efficient IPC (inter-process communication) mechanism to monitor and receive the data sent from the Linux USB system host side. After the data is received, the slave-side data processing module will quickly forward the data packets that meet the rules to the business processing module, which will perform professional business processing.
[0089] S9. On the Linux USB system slave side, after receiving the data sent by the Linux USB system host side, the business processing module immediately uses a custom dedicated protocol to encapsulate the data; then, according to business needs, the business processing module will process the encapsulated data, including in-depth calculation analysis or preparation for the next transmission operation.
[0090] S10. On the Linux USB system slave side, after completing the data processing task, the business processing module will connect to the slave driver module and use the URB (USB request block) mechanism to efficiently and safely transmit the processed corresponding data to the Linux USB system host side. This process reflects the close cooperation and collaboration between the business module and the slave driver module, ensuring the timeliness and accuracy of data transmission, and providing strong support for the stable operation of the entire system.
[0091] S11. On the host side of the Linux USB system, the host side data processing module and the host driver module work closely together to jointly undertake the task of receiving data on the host side of the Linux USB system; according to the custom dedicated protocol format defined in S09, the host side data processing module performs format analysis on the received data packets; through the packet format verification mechanism, the data packets that do not meet the specifications are screened to ensure the accuracy and reliability of the data.
[0092] Specifically, for the data packets that pass the verification, the data unit processing module will accurately distribute them to the corresponding task queue according to their identification information. This process not only realizes the effective filling of multi-task queue data, but also ensures the orderly management and efficient processing of data in complex task environments.
[0093] S12. On the host side of the Linux USB system, once the host side data processing module successfully fills the parsed and verified data packets into their respective task queues, it will immediately work with the IPC mechanism to wake up the task queues, and then the user will read the data through the user call layer and continue to wait for the transmission of subsequent data packets, and so on. This process not only ensures the timeliness and accuracy of data processing, but also realizes the seamless connection and flow of data between tasks through an efficient queue management mechanism, providing a solid guarantee for the stable operation and high efficiency of the entire system.
[0094] Preferably, the method further comprises the user obtaining data:
[0095] Through the standard calling interface provided by the system, users can retrieve and obtain the required data from one or more ready task queues, and achieve real-time access and extraction of data for task 1 or task N. This process not only simplifies the user's data acquisition process, but also significantly improves the efficiency and accuracy of data access.
[0096] Preferably, the method further comprises a resource recovery operation:
[0097] The user initiates a request to close the task channel through the dedicated API interface provided by the dedicated device on the host side of the Linux USB system; then, the process resource management module of the USB host dedicated device responds to this request and performs the corresponding resource recovery operation. This process includes releasing the memory space occupied by the task, the data cache area, and any related system resources to ensure that the resources are reasonably and timely recycled and reused, thereby maintaining the stable operation of the system and optimizing the efficiency of resource utilization.
[0098] Preferably, the interaction between the process resource management module on the Linux USB system host side and the business processing module and the slave side data processing module on the Linux USB system slave side adopts a custom dedicated protocol for communication, thereby ensuring the security and integrity of information.
[0099] In summary, the present invention successfully implements an efficient, stable and easily expandable USB multitasking support method by adding multiple key modules on the Linux USB system host side and the Linux USB system slave side, and optimizing the collaborative working mechanism between the modules. This method not only solves the performance bottleneck and resource conflict problems faced by USB devices in traditional Linux environments when processing multitasking, but also brings users a smoother, more stable and efficient USB usage experience.
[0100] Specifically, when sending data on the Linux USB system host side or the Linux USB system slave side, a custom dedicated protocol will be added before the data. The custom dedicated protocol format includes but is not limited to a custom protocol header, a start identifier of a data frame, and a whole data packet. Custom fields will be expanded later according to needs, such as Figure 3 As shown;
[0101] Preferably, the custom fields include:
[0102] The msgLen field is used to indicate the total length of the entire data packet and is used to determine the data length;
[0103] The priority and identifier fields are sub-packed into priority and process identification fields, which are allocated and filled by the process resource management module on the host side of the Linux USB system;
[0104] The pkgNum field identifies the sequence number of the package;
[0105] Reserve is a reserved field to facilitate expansion and use in the future business needs;
[0106] The msg field is the data portion of the communication between the USB host-specific device and the USB slave-specific device.
[0107] Furthermore, the data is sent using a custom dedicated protocol as follows:
[0108] S01. On the Linux USB system host side, the process resource management module is responsible for encapsulating the data to be sent according to the custom dedicated protocol format. The encapsulated data format contains not only a unique protocol header, but also key information such as the task identifier (used to bind the buffer area), task priority, packet sequence number, and user data, thereby ensuring the integrity and identifiability of the data during transmission. Subsequently, these encapsulated data packets are accurately sent to the USB slave dedicated device.
[0109] S02. On the slave side of the Linux USB system, the slave side data processing module works closely with the slave driver module to monitor and receive the received data. The URB linked list and IPC mechanism can safely receive and forward data to the business processing module. The business processing module then uses a custom dedicated protocol format to deeply analyze the received data and calls a dedicated business interface to perform a series of efficient data processing tasks. After processing, the response packet data will also be repackaged according to the custom dedicated protocol format, and the processing results will be quickly responded to the Linux USB system host side through the slave driver module.
[0110] S03. On the host side of the Linux USB system, the host side data processing module works with the host driver module to continuously monitor and process data from the USB slave dedicated device. Based on the identification information in the custom dedicated protocol, they can accurately classify the data or discard data packets that do not meet the requirements to ensure the stability of the system and the accuracy of the data.
[0111] Example 2
[0112] This embodiment also provides a computer-readable storage medium storing executable instructions, which, when executed, enable the machine to execute the system and method for USB device multi-tasking support based on the Linux operating system as described above.
[0113] Specifically, a system or device equipped with a readable storage medium can be provided, on which software program codes that implement the functions of any of the above-mentioned embodiments are stored, and a computer or processor of the system or device can read and execute instructions stored in the readable storage medium.
[0114] In this case, the program code itself read from the machine-readable medium can realize the function of any one of the above embodiments, and thus the machine-readable code and the machine-readable storage medium storing the machine-readable code constitute part of this specification.
[0115] Examples of readable storage media include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD-RW), magnetic tapes, non-volatile memory cards, and ROMs. Optionally, the program code may be downloaded from a server computer or a cloud via a communication network.
[0116] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, systems or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0117] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0118] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0119] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0120] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the technical solution of the present invention, and are not intended to limit the specific implementation methods of the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the claims of the present invention shall be included in the protection scope of the claims of the present invention.
Claims
1. A system for USB device multitasking support based on Linux operating system, characterized in that: The system includes a Linux USB system host side and a Linux USB system slave side; The host-side architecture of the Linux USB system includes, from bottom to top, a host, a USB host control layer, a USB core layer, and a USB host function driver layer, wherein the USB host function driver layer adds a USB host-specific device; The USB host dedicated device is used for resource configuration and distribution of multiple tasks, and provides an interactive function with the USB slave dedicated device data packet; The Linux USB system slave side architecture includes from bottom to top: USB hardware device, USB device control layer, USB composite layer, USB device controller interface layer and USB slave function driver layer, in which USB slave dedicated device is added; The USB slave dedicated device is used to receive, parse and respond to data packets sent by the Linux USB system host side; The USB host dedicated device includes a process resource management module, a host driver module and a Linux USB system host side data processing module; The process resource management module is used to dynamically allocate resources required by the host multitasking; The host driver module is used to complete the detailed configuration of USB endpoints, the optimal selection of communication methods, and the submission and acquisition of messages; The Linux USB system host-side data processing module is used to distribute and process multi-task data packets; The USB slave dedicated device includes a slave driver module, a host side data processing module and a service processing module; The slave driver module is used to drive the operation of the slave device link; The Linux USB system slave side data processing module is used to complete the collection of blocking data; The business processing module is responsible for performing specific business processing on the received data packets.
2. A method for USB device multitasking support based on Linux operating system, characterized in that: include: S1. Register the newly added USB slave-specific device in the USB device controller interface layer on the slave side of the Linux USB system, and flexibly configure the various parameters and communication capabilities of the device in conjunction with the memory-based file system. After the configuration is completed, the system will automatically load the slave-side data processing module and business processing module: The slave-side data processing module focuses on receiving, parsing, converting and sending USB host data; The Linux USB system slave side service processing module is used to implement specific service logic, including but not limited to data protocol conversion and user interaction response; S2, registering the newly added USB host-specific device in the USB core layer on the host side based on the Linux USB system; S3. When the USB hardware device is inserted into the host, the change of VBUS voltage is detected immediately, and then the USB host control layer hardware interrupt is triggered; the response mechanism of this interrupt automatically calls back to the initialization function pre-registered on the USB bus and exclusively serving the USB slave-specific device, to create the data structure and the buffer area, and to start the data unit processing module and business processing module functions on the host side of the Linux USB system; S4, the user creates Task 1 and Task N on the Linux USB system host side through the system call interface provided by the USB host dedicated device, and saves the returned task handles. At the same time, the handles and related resources of this task are strongly bound in the process resource management module; S5. After receiving the request, the process resource management module on the Linux USB system host side creates the resources required for Task 1 and Task N. Then, the process resource management module binds the handle to the kernel file and returns the handle to the user call layer on the Linux USB system host side. S6. In the multi-tasking environment of the Linux USB system host side, the user performs a data write operation on Task 1 and Task N through a system call interface; S7, when the process resource management module of the dedicated device on the Linux USB system host side receives the request, firstly, according to the unique identification bit bound by the process resource management module on the Linux USB system host side, the identification bit is accurately bound to the message written by the identification bit; then, the process resource management module applies for a corresponding data structure for the message, and the process resource management module sends the encapsulated data to the specified USB physical endpoint through the USB core layer on the Linux USB system host side, and finally the data is sent to the USB slave dedicated device; S8. On the slave side of the Linux USB system, after the USB hardware device triggers a hardware interrupt, the USB device control layer will call back the function interface that matches the device, and then the function interface will further bind the corresponding data structure of the USB composite layer according to the USB specific information, and finally call the USB slave-specific device related interface previously registered in the USB device controller structure layer to receive data; the slave-side data processing module and the slave driver module use an efficient IPC mechanism to monitor and receive the data sent from the Linux USB system host side; after the data is received, the slave-side data processing module forwards the data packet that meets the rules to the business processing module, and the latter performs professional business processing; S9. On the Linux USB system slave side, after receiving the data sent by the Linux USB system host side, the business processing module uses a custom dedicated protocol to encapsulate the data; then, according to business needs, the business processing module processes the encapsulated data, including in-depth calculation analysis or preparing for the next transmission operation; S10, on the Linux USB system slave side, after completing the data processing, the service processing module is connected to the slave driver module, and the processed data is transmitted to the Linux USB system host side by using the URB mechanism; S11 is on the host side of the Linux USB system, where the host side data processing module and the host driver module jointly undertake the task of receiving data on the host side of the Linux USB system; According to the custom dedicated protocol, the host-side data processing module performs format analysis on the received data packets; then, through the packet format verification mechanism, the data packets that do not meet the specifications are screened; for the data packets that pass the verification, the host-side data processing module distributes them to the corresponding task queue according to their identification information; S12. On the host side of the Linux USB system, the host side data processing module successfully fills the parsed and verified data packets into the respective task queues, and immediately cooperates with the IPC mechanism to wake up the task queues. The user then reads the data, and after reading the data packet, continues to wait for the transmission of subsequent data packets, and the cycle continues.
3. The method for supporting USB device multitasking based on Linux operating system according to claim 2, characterized in that: The method also includes: the user retrieves and obtains the required data from one or more ready task queues through a standard calling interface provided by the system, and implements real-time access and extraction of the data of task 1 or task N.
4. The method for supporting USB device multitasking based on Linux operating system according to claim 2, characterized in that: The method further comprises: a user initiates a request to close a task channel through a dedicated API interface provided by a dedicated device on the host side of the Linux USB system; then, a process resource management module of the dedicated device on the USB host responds to the request and performs a corresponding resource recovery operation.
5. The method for supporting multitasking of USB devices based on Linux operating system according to claim 2, characterized in that: The resources required to create Task 1 and Task N include, but are not limited to, applying for the resource structure of the task, allocating data buffers, setting task priorities, and generating task identifiers.
6. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 2 to 5 are implemented.
Citation Information
Patent Citations
Embedded vehicle-mounted multifunctional information platform
CN101691111A
Slave USB HID device and firmware implementation method based on embedded Linux
CN101593164A
Business processing method, system and equipment based on double real-time kernels and medium
CN115964150A