Data processing methods, host and electronic devices in slave mode
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HOLLEY METERING LTD
- Filing Date
- 2025-09-04
- Publication Date
- 2026-06-30
Smart Images

Figure CN121092473B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a data processing method, host, and electronic device in slave mode. Background Technology
[0002] In embedded systems, the host often needs to interact with high-speed external peripherals. For example, the peripheral may continuously send large amounts of data via an SPI (Serial Peripheral Interface) bus, while the host passively receives the data in slave mode. Due to the large amount of data and the high transmission rate, failure to receive and process the data in a timely manner can easily lead to data loss or desynchronization, thus affecting the stable operation of the system.
[0003] Existing technologies typically employ the following methods to ensure data reception: First, a multi-core heterogeneous platform is used, with a dedicated core responsible for receiving high-speed data from peripherals. However, this method is limited by hardware conditions and cannot be universally applied. Second, an intermediate MCU (Microcontroller Unit) is introduced between the host and the peripheral, where the MCU buffers the data before handing it over to the host for processing. However, this solution requires the MCU to have a large amount of RAM (Random Access Memory), increasing hardware costs and system complexity. Third, DMA (Direct Memory Access) completion interrupt or semi-completion interrupt mode is used. However, this method requires frequent software transfer operations, which not only consumes CPU (Central Processing Unit) resources but is also prone to losing new data in high-speed transmission scenarios. Summary of the Invention
[0004] In view of this, the purpose of this application is to provide a data processing method, host, and electronic device in slave mode, which can achieve complete reception and efficient processing of high-speed data from peripherals in slave mode by means of a circular buffer and an adaptive reading strategy without additional hardware support.
[0005] In a first aspect, the present invention provides a data processing method in slave mode, applied to a host, the host including a hardware interface module, a driver layer, and an application layer; the method includes:
[0006] The hardware interface module stores data sent by external devices into a circular buffer using a circular write method; the application layer reads data from the circular buffer according to a preset read strategy.
[0007] The driver layer tracks the data write position in the circular buffer and the data read position in the application layer, and determines the amount of unread data based on the data write position and the data read position.
[0008] When the amount of unread data exceeds a preset threshold, the driver layer generates an abnormal status instruction and sends the abnormal status instruction to the application layer; the abnormal status instruction is used to indicate that there is a data backlog in the circular buffer.
[0009] The application layer responds to abnormal state commands, adjusts the read strategy, and reads data from the circular buffer according to the adjusted read strategy.
[0010] In an optional implementation, the host also includes a kernel layer; a ring buffer is set in the kernel layer; the ring buffer is set with a preset starting address and a preset ending address.
[0011] The hardware interface module is configured to, after writing data to the preset end address of the circular buffer, determine that the circular buffer is full, and then write the next data to the preset beginning address of the circular buffer.
[0012] In an optional implementation, after the step of the driver layer tracking the data write position in the circular buffer and the data read position in the application layer, and determining the amount of unread data based on the data write position and the data read position, the method includes:
[0013] When the amount of unread data does not exceed the preset threshold, the driver layer generates a normal status instruction and sends the normal status instruction to the application layer so that the application layer can continue to read data according to the reading strategy.
[0014] In an optional implementation, the step of sending the exception status command to the application layer includes:
[0015] When the driver layer calls the data reading interface at the application layer, it appends an exception status command to the reading result and returns it to the application layer.
[0016] In an optional implementation, the step of adjusting the read strategy in response to an abnormal state instruction at the application layer includes:
[0017] The application layer receives abnormal status commands.
[0018] The application layer shortens the reading cycle in the reading strategy based on a preset cycle step size until the preset minimum cycle is reached.
[0019] In an optional implementation, the method further includes:
[0020] If the abnormal state instruction still exists in the application layer under the preset minimum period, the application layer will increase the single data read length in the read strategy based on the preset read step size.
[0021] In an optional implementation, the method further includes:
[0022] When the application layer detects an error in the read data or a communication failure, it issues a reset command through the driver layer to reset the hardware interface module and the driver layer, so as to re-establish data synchronization with the external device.
[0023] Secondly, the present invention provides a host computer, which includes a hardware interface module, a driver layer and an application layer.
[0024] The hardware interface module is used to store data sent by external devices into a circular buffer in a circular write manner; the application layer reads data from the circular buffer according to a preset read strategy.
[0025] The driver layer is used to track the data write position in the circular buffer and the data read position in the application layer, and to determine the amount of unread data based on the data write position and the data read position.
[0026] The driver layer is used to generate an abnormal status instruction when the amount of unread data exceeds a preset threshold, and send the abnormal status instruction to the application layer; the abnormal status instruction is used to indicate that there is a data backlog in the circular buffer.
[0027] The application layer is used to respond to abnormal state commands, adjust the read strategy, and read data from the circular buffer according to the adjusted read strategy.
[0028] Thirdly, the present invention provides an electronic device, including a memory and a processor, wherein the memory stores computer-executable commands that can run on the processor, and the processor executes the computer-executable commands to implement the data processing method in slave mode of any of the foregoing embodiments.
[0029] Fourthly, the present invention provides a computer-readable storage medium storing computer instructions, which, when executed by a processor, implement a data processing method in slave mode as described in any of the foregoing embodiments.
[0030] This application provides a data processing method, host, and electronic device in slave mode. By setting up a hardware interface module, driver layer, and application layer in the host, and using a circular write method to store data sent by external devices into a circular buffer in the kernel layer, the complete reception of high-speed data can be guaranteed without frequent software intervention. By tracking the data write and read positions in the driver layer and generating an abnormal status instruction when the amount of unread data exceeds a preset threshold, the application layer can be promptly prompted to adjust the read strategy, thereby avoiding data backlog or loss in the circular buffer. By dynamically adjusting the read cycle and single read length based on the abnormal status instruction in the application layer, the transmission requirements of different data rates can be adapted to improve the host's processing efficiency and stability for high-speed data. Furthermore, when the application layer detects data errors or communication out of sync, a reset mechanism can be used to re-establish synchronization with the external device, further ensuring the reliability of data processing and the continuous operation of the system.
[0031] Other features and advantages of this application will be set forth in the following description and will be apparent in part from the description or may be learned by practicing the application.
[0032] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0033] To more clearly illustrate the technical solutions in the specific embodiments of this application or the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0034] Figure 1 A flowchart illustrating the data processing method in slave mode provided in this application embodiment;
[0035] Figure 2 A schematic diagram of a host provided in an embodiment of this application;
[0036] Figure 3 A schematic diagram of another host provided for an embodiment of this application;
[0037] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0038] Icons: 1-Hardware interface module; 2-Driver layer; 3-Application layer; 4-Kernel layer; 401-Processor; 402-Memory; 403-Bus; 404-Communication interface. Detailed Implementation
[0039] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0040] To facilitate understanding of this embodiment, the embodiments of this application will be described in detail below.
[0041] Example 1:
[0042] Figure 1 A flowchart illustrating the data processing method in slave mode provided in this application embodiment.
[0043] The data processing method in slave mode is applied to the host, which includes a hardware interface module, a driver layer, and an application layer.
[0044] In this context of data communication, slave mode means that the device is passive. It does not actively initiate communication but waits for the master device to send data. In this application, the external device is the master device, which actively and continuously sends high-speed data. The master being in slave mode means it must be ready to passively receive data at any time, which is a challenge for non-real-time systems like Linux, as the system may miss data while processing other tasks.
[0045] The hardware interface module is the physical part of the host computer, responsible for the actual data reception operation. It is used to move data from the peripheral interface to memory at high speed via hardware without software intervention, thereby freeing up the CPU.
[0046] The driver layer is a low-level software within the operating system kernel, responsible for managing and configuring hardware interface modules. It acts as a bridge between hardware and upper-layer applications, not only setting the hardware's operating mode but also monitoring the data buffer status and sending notifications to the upper layers when necessary.
[0047] The application layer consists of software programs on the host machine and is the final consumer of data. It is responsible for reading data from the circular buffer provided by the driver layer and processing it.
[0048] Reference Figure 1 Data processing methods include:
[0049] In step S101, the hardware interface module stores the data sent by the external device into a circular buffer in a circular writing manner; wherein, the application layer reads data from the circular buffer according to a preset reading strategy.
[0050] Here, the hardware interface module can specifically be a DMA controller. DMA mode allows the transfer of data from the peripheral interface to memory to be handled entirely by hardware, without the need for intervention from software such as the CPU.
[0051] The host also includes a kernel layer, in which a ring buffer is set; the ring buffer has a preset starting address and a preset ending address.
[0052] The circular buffer is a fixed-length contiguous physical memory block pre-allocated by the driver layer in the kernel layer.
[0053] Circular write refers to a hardware interface module being configured such that after data is written to the preset end address of the circular buffer, the next write will automatically return to the preset beginning address of the circular buffer, overwriting the oldest data. This circular write mechanism allows the hardware to receive data streams uninterruptedly without pausing or waiting for software intervention when the circular buffer is full.
[0054] The application layer, as the consumer of data, retrieves data from the buffer according to a predefined reading strategy. This reading strategy typically defines the application layer's initial data reading behavior. For example, the reading strategy might specify that the application layer calls the data reading interface (e.g., the `read()` function) once at a fixed time interval (e.g., T=50ms), and reads a fixed length of data (e.g., `ReadL=1KB`) each time.
[0055] In other feasible embodiments, the hardware interface module can also be other hardware logic units with similar functions, such as a dedicated FIFO (First-In First-Out) controller with circular buffer functionality. Similarly, the application layer's preset read strategy is not limited to a fixed period and length; it can be event-driven or dynamically set according to the initial system load.
[0056] In step S102, the driver layer tracks the data write position in the circular buffer and the data read position in the application layer, and determines the amount of unread data based on the data write position and the data read position.
[0057] Here, in order to achieve monitoring, the driver layer maintains two pointers: a pointer to the data write position and a pointer to the data read position.
[0058] The pointer to the data write position reflects the specific address where the hardware interface module has currently written data to the circular buffer. In a preferred embodiment, the driver layer calculates the current hardware write position by querying the hardware module's status register or calling a specific status function (such as the dmaengine_tx_status() function in the Linux dmaengine framework) to obtain the remaining transfer length.
[0059] The data read position pointer records the endpoint where the application layer has successfully read data. This pointer is a software variable managed by the driver layer, and the driver layer updates its value accordingly each time the application layer successfully reads a certain length of data.
[0060] The driver layer calculates the amount of unread data in the current buffer that has been written but not yet read by the application layer by comparing the positions of these two pointers. The calculation needs to consider the wraparound characteristics of the circular buffer. For example, when the write position is after the read position, the amount of unread data is the difference between the two; when the write position is before the read position due to wraparound, the amount of unread data needs to be calculated in segments.
[0061] In one embodiment, after step S102, the method further includes:
[0062] When the amount of unread data does not exceed the preset threshold, the driver layer generates a normal status instruction and sends the normal status instruction to the application layer so that the application layer can continue to read data according to the reading strategy.
[0063] Here, after the driver layer calculates the amount of unread data in the circular buffer, it compares it with a preset threshold. When the driver layer determines that the amount of unread data does not exceed the preset threshold, it indicates that the data consumption rate of the application layer and the data production rate of the hardware are in a balanced or healthy range, and there is no risk of data being overwritten in the circular buffer. In this case, the driver layer generates a normal status instruction. In a specific embodiment, the normal status instruction can be a specific status word, such as setting the status word to 0. The normal status instruction is then sent to the application layer, informing it that the current system status is good.
[0064] Upon receiving this normal status instruction, the application layer does not need to adjust its behavior. Therefore, the application layer will continue to read data from the circular buffer according to its preset read strategy (e.g., maintaining the initial read cycle and single read length).
[0065] Step S103: When the amount of unread data exceeds a preset threshold, the driver layer generates an abnormal status instruction and sends the abnormal status instruction to the application layer; the abnormal status instruction is used to indicate that there is a data backlog in the circular buffer.
[0066] Here, a preset threshold is used to determine the severity of data backlog. In a specific embodiment, the preset threshold can be set to twice the length of data read in a single application-layer request (i.e., 2). ReadL). When the amount of unread data exceeds this preset threshold, it indicates that the application layer's consumption rate can no longer keep up with the hardware's production speed, increasing the risk of data loss.
[0067] In other embodiments, the preset threshold may also be a fixed absolute value (such as 80% of the total length of the buffer) or a value that is dynamically adjusted according to the real-time performance of the system.
[0068] Once the driver layer detects that the amount of unread data exceeds a preset threshold, it generates an abnormal status instruction. An abnormal status instruction is a signal used to transmit warning information between the driver layer and the application layer. In a preferred embodiment, the abnormal status instruction can be a specific status word (e.g., status=1). The driver layer appends this status word to the return value of the data reading interface called by the application layer, efficiently transmitting the warning signal to the application layer without additional communication overhead.
[0069] In one embodiment, step S103, the step of sending the abnormal status command to the application layer, includes:
[0070] When the driver layer calls the data reading interface at the application layer, it appends an exception status command to the reading result and returns it to the application layer.
[0071] Here, when the application layer needs to retrieve data, it calls a data read interface. In a typical Linux system implementation, the data read interface is the read() function.
[0072] When the driver layer prepares to return the requested data to the application layer, it appends the generated status command (whether it is an exception status command or a normal status command) to the current read result and returns it to the application layer together. For example, the status command can be treated as a status word and encapsulated together with the length of the data returned or the data itself in the return value of the interface.
[0073] In step S104, the application layer responds to the abnormal state instruction, adjusts the reading strategy, and reads data from the circular buffer according to the adjusted reading strategy.
[0074] Here, the application layer responds to the warning and adaptively adjusts the reading strategy.
[0075] When the application layer receives an abnormal status instruction through the return value of the data reading interface, it starts the preset strategy adjustment logic. The strategy adjustment logic is used to increase its own data consumption rate in order to process the backlog of data in the buffer as soon as possible.
[0076] In one embodiment, step S104, in which the application layer adjusts the reading strategy in response to an abnormal state instruction, includes the following steps S201-S202.
[0077] Step S201: The application layer receives an abnormal status command.
[0078] Here, when the application layer receives an abnormal status instruction sent by the driver layer, it indicates that its current read rate can no longer keep up with the data write rate. At this time, the application layer will prioritize adjusting the time frequency of the read behavior.
[0079] In step S202, the application layer shortens the reading cycle in the reading strategy based on a preset cycle step size until the preset minimum cycle is reached.
[0080] Here, the application layer will first try to read data more frequently, that is, based on a preset cycle step, gradually shorten the time cycle T of calling the data reading interface until the minimum cycle allowed by the system is reached.
[0081] Specifically, each time the application layer receives an exception status command, it shortens its read cycle T by 5ms. After shortening the cycle, the application layer continues reading data. If it receives another exception status command in the next or subsequent reads, it shortens the cycle by another step. This process continues until the read cycle reaches a preset minimum cycle (e.g., 10ms) within a predefined, allowable range. The purpose of setting a minimum cycle is to prevent the application layer from excessively frequently calling the read interface, causing excessive CPU load and affecting the normal operation of other system tasks.
[0082] In one embodiment, the method further includes:
[0083] If the abnormal state instruction still exists in the application layer under the preset minimum period, the application layer will increase the single data read length in the read strategy based on the preset read step size.
[0084] Here, if the abnormal status command returned by the driver layer still exists even after shortening the read cycle to the minimum, it indicates that simply increasing the frequency is no longer sufficient to solve the problem. In this case, the application layer will gradually increase the length of its single read request, ReadL, based on a preset read step size (e.g., 1KB). Specifically, each time the application layer still receives an abnormal status command under the minimum cycle, it will increase its single read length by 1KB.
[0085] The application layer will continuously increase the length of data read in a single operation until the driver layer returns a normal state instruction, indicating that the data backlog problem has been alleviated.
[0086] In other feasible embodiments, the application layer adjustment strategy can also be other, such as combining two adjustment methods, or adopting a more aggressive adjustment magnitude based on the severity of the abnormal state (e.g., which can be characterized by different numerical values of instructions), or even creating a dedicated high-priority thread to be responsible for data reading to ensure the timeliness of data processing.
[0087] In one embodiment, the method further includes:
[0088] When the application layer detects an error in the read data or a communication failure, it issues a reset command through the driver layer to reset the hardware interface module and the driver layer, so as to re-establish data synchronization with the external device.
[0089] Here, the application layer can identify errors in the read data or communication failures in one or more of the following ways:
[0090] Data verification: External devices attach checksums (such as CRC (Cyclic Redundancy Check) or checksums) to the data frames they send. Upon receiving the data, the application layer recalculates the checksum according to an agreed-upon algorithm and compares it with the received checksum. If they do not match, an error is confirmed in the data.
[0091] Synchronization word or frame format check: The application layer and external devices agree on a specific data frame format, such as each data frame starting with a fixed synchronization word. When parsing the data stream, if the application layer fails to find the synchronization word at the expected position, or if the length of the data frame does not conform to the agreement, it can determine that communication has lost synchronization.
[0092] Sequence number verification: The external device appends a continuously increasing sequence number to each data packet it sends. The application layer checks whether the sequence numbers of the received data packets are consecutive. If a jump or duplicate sequence number is found, it can be determined that packet loss or communication abnormality has occurred.
[0093] Data content reasonableness analysis: The application layer judges the reasonableness of the data content based on its business logic. For example, if the received data is a sensor reading, the application layer can determine whether the reading exceeds a reasonable physical range.
[0094] Once the application layer detects a data error or communication failure, it will immediately initiate a reset process.
[0095] Specifically, the application layer sends an explicit reset command to the driver layer through a specific interface (in a typical Linux system implementation, this interface is the ioctl() function).
[0096] After receiving the reset command, the driver layer will execute a series of low-level hardware and software reset operations, including:
[0097] Reset the hardware interface module: for example, stop the current DMA transfer, clear the FIFO and status registers inside the DMA controller, and reinitialize the configuration of communication peripherals such as SPI to restore them to the initial state of waiting to establish a new connection.
[0098] Reset the driver layer: The driver layer will reset the various state variables maintained internally, such as restoring the pointer (ReadSp) that records the read position of the application layer to its initial value.
[0099] By simultaneously resetting the hardware and software, all states within the host related to this communication are cleared.
[0100] After the reset is complete, the host can re-establish data synchronization with the external device. The external device can detect the communication interruption and restart sending the synchronization sequence, while the host, after the reset, is ready to receive the new synchronization sequence. Once both parties are re-aligned, a completely new and accurate data transmission process can begin.
[0101] This application provides a data processing method in slave mode. High-speed data from external devices is cyclically written to a circular buffer via a hardware interface module, ensuring data reception integrity. By tracking read / write positions and generating status instructions at the driver layer, the data backlog in the buffer can be accurately reflected, prompting the application layer to adjust the reading strategy in a timely manner. By dynamically shortening the reading cycle or increasing the reading length based on abnormal status instructions at the application layer, data loss can be effectively avoided and data processing efficiency improved. Furthermore, when data errors or communication synchronization failures are detected, a reset mechanism is used to re-establish data synchronization, further enhancing the reliability of data processing and the stability of system operation.
[0102] Example 2:
[0103] Figure 2 This is a schematic diagram of a host provided in an embodiment of this application.
[0104] Reference Figure 2 The host includes a hardware interface module 1, a driver layer 2, and an application layer 3.
[0105] Hardware interface module 1 is used to store data sent by external devices into a circular buffer in a circular writing manner; wherein, application layer 3 reads data from the circular buffer according to a preset reading strategy.
[0106] Driver layer 2 is used to track the data write position in the circular buffer and the data read position in application layer 3, and to determine the amount of unread data based on the data write position and the data read position.
[0107] Driver layer 2 is used to generate an abnormal status instruction when the amount of unread data exceeds a preset threshold, and send the abnormal status instruction to the application layer; the abnormal status instruction is used to indicate that there is a data backlog in the circular buffer.
[0108] Application layer 3 is used to adjust the read strategy in response to abnormal state indicators and read data from the circular buffer according to the adjusted read strategy.
[0109] In an optional implementation, refer to Figure 3 The host also includes kernel layer 4; a ring buffer is set in kernel layer 4; the ring buffer has a preset starting address and a preset ending address.
[0110] Hardware interface module 1 is configured to, after writing data to the preset end address of the circular buffer, determine that the circular buffer is full, and then write the next data to the preset beginning address of the circular buffer.
[0111] In an optional implementation, the driver layer 2 is also used to generate a normal status instruction when the amount of unread data does not exceed a preset threshold, and send the normal status instruction to the application layer 3 so that the application layer 3 can continue to read data according to the reading strategy.
[0112] In an optional implementation, the driver layer 2 is also used to append an exception status instruction to the read result when the application layer 3 calls the data read interface, so as to return to the application layer 3.
[0113] In an optional implementation, application layer 3 is also used to receive abnormal status instructions.
[0114] Application layer 3 is also used to shorten the reading cycle in the reading strategy based on a preset cycle step size, until the preset minimum cycle is reached.
[0115] In an optional implementation, application layer 3 is further configured to increase the single data read length in the read strategy based on a preset read step size if the abnormal state instruction still exists within a preset minimum period.
[0116] In an optional implementation, the application layer 3 is also used to issue a reset command through the driver layer 2 when an error is detected in the read data or communication is out of sync, so as to reset the hardware interface module 1 and the driver layer and re-establish data synchronization with the external device.
[0117] This application provides a host that integrates a hardware interface module, a driver layer, and an application layer, and implements cyclic writing and reading of data in a circular buffer. This allows for efficient and complete reception of high-speed data from external devices without additional hardware support. Simultaneously, the driver layer can generate and transmit status instructions, and the application layer can dynamically adjust the reading strategy based on these status instructions, thereby avoiding data backlog or loss and improving the host's data processing efficiency and system stability in slave mode.
[0118] This application also provides an electronic device, such as... Figure 4 The diagram shows the structure of the electronic device, which includes a processor 401 and a memory 402. The memory 402 stores computer-executable instructions that can be executed by the processor 401. The processor 401 executes the computer-executable instructions to implement the above-mentioned method for identifying the planned path.
[0119] exist Figure 4 In the illustrated embodiment, the electronic device further includes a bus 403 and a communication interface 404, wherein the processor 401, the communication interface 404, and the memory 402 are connected via the bus 403.
[0120] The memory 402 may include high-speed random access memory (RAM) and may also include non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 404 (which can be wired or wireless), such as the Internet, wide area network, local area network, metropolitan area network, etc. The bus 403 may be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc. The bus 403 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.
[0121] Processor 401 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of processor 401 or by software instructions. The processor 401 can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiments of this application can be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. The storage medium is located in the memory. The processor 401 reads the information in the memory 402 and, in conjunction with its hardware, completes the steps of the data processing method in slave mode of the aforementioned embodiment.
[0122] This application also provides a computer-readable storage medium storing a computer program. The computer program stored on the computer-readable storage medium executes the steps of the data processing method in slave mode described above when the computer program is run by a processor.
[0123] The computer program product provided in this application includes a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the preceding method embodiments. For specific implementation details, please refer to the method embodiments, which will not be repeated here.
[0124] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the system and apparatus described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0125] Furthermore, in the description of the embodiments of this application, unless otherwise expressly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in this application based on the specific circumstances.
[0126] In the description of this application, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this application. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0127] Finally, it should be noted that the above-described embodiments are merely specific implementations of this application, used to illustrate the technical solutions of this application, and not to limit them. The protection scope of this application is not limited thereto. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the scope of the technology disclosed in this application, or make equivalent substitutions for some of the technical features. Such modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be covered within the protection scope of this application.
Claims
1. A data processing method in a slave mode, characterized by, Applied to a host computer, the host computer includes a hardware interface module, a driver layer, and an application layer; the method includes: The hardware interface module stores data sent by external devices into a circular buffer using a cyclic writing method; the application layer reads data from the circular buffer according to a preset reading strategy. The driver layer tracks the data write position in the circular buffer and the data read position in the application layer, and determines the amount of unread data based on the data write position and the data read position; When the amount of unread data exceeds a preset threshold, the driver layer generates an abnormal status instruction and sends the abnormal status instruction to the application layer; the abnormal status instruction is used to indicate that there is a data backlog in the circular buffer; In response to the abnormal state instruction, the application layer adjusts the reading strategy and reads data from the circular buffer according to the adjusted reading strategy. The step of adjusting the reading strategy in response to the abnormal state instruction at the application layer includes: The application layer receives the abnormal status instruction; The application layer shortens the reading cycle in the reading strategy based on a preset cycle step size until a preset minimum cycle is reached. The method further includes: If the abnormal state instruction still exists in the application layer under the preset minimum period, the application layer increases the single data read length in the read strategy based on the preset read step size.
2. The data processing method in slave mode according to claim 1, characterized in that, The host also includes a kernel layer; the circular buffer is located in the kernel layer; the circular buffer is configured with a preset starting address and a preset ending address; The hardware interface module is configured to, after writing data to the preset end address of the circular buffer, determine that the circular buffer is full, and then write the next data to the preset beginning address of the circular buffer.
3. The data processing method in slave mode according to claim 1, characterized in that, After the step of the driver layer tracking the data write position in the circular buffer and the data read position in the application layer, and determining the amount of unread data based on the data write position and the data read position, the method includes: When the amount of unread data does not exceed the preset threshold, the driver layer generates a normal status instruction and sends the normal status instruction to the application layer so that the application layer can continue to read data according to the reading strategy.
4. The data processing method in slave mode according to claim 1, characterized in that, The step of sending the abnormal status command to the application layer includes: When the application layer calls the data reading interface, the driver layer appends the abnormal status instruction to the reading result and returns it to the application layer.
5. The data processing method in slave mode according to claim 1, characterized in that, The method further includes: When the application layer detects an error in the read data or a communication failure, the application layer issues a reset command through the driver layer to reset the hardware interface module and the driver layer, so as to re-establish data synchronization with the external device.
6. A host computer, characterized in that, The host includes a hardware interface module, a driver layer, and an application layer; The hardware interface module is used to store data sent by external devices into a circular buffer in a circular write manner; wherein, the application layer reads data from the circular buffer according to a preset read strategy; The driver layer is used to track the data write position in the circular buffer and the data read position in the application layer, and to determine the amount of unread data based on the data write position and the data read position; The driver layer is used to generate an abnormal status instruction when the amount of unread data exceeds a preset threshold, and send the abnormal status instruction to the application layer; the abnormal status instruction is used to indicate that there is a data backlog in the circular buffer; The application layer is configured to adjust the reading strategy in response to the abnormal state instruction, and read the data from the circular buffer according to the adjusted reading strategy. The application layer is also used to receive the abnormal status instruction; The application layer is also used to shorten the reading cycle in the reading strategy based on a preset cycle step size, until a preset minimum cycle is reached; The application layer is further configured to, if the abnormal state instruction still exists within the preset minimum period, increase the single data read length in the reading strategy based on a preset read step size.
7. An electronic device, characterized in that, The device includes a memory and a processor, wherein the memory stores computer-executable commands that can run on the processor, characterized in that the processor executes the computer-executable commands to implement the data processing method in slave mode as described in any one of claims 1-5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a processor, implement the data processing method in slave mode as described in any one of claims 1-5.
Citation Information
Patent Citations
Data reading and writing method and device based on asynchronous annular buffer area
CN110704335A
Adaptive Prevention of Data Loss During Continuous Event Tracing with Limited Buffer Size
US20090113450A1