A EC debugging method based on serial port instructions
Through the EC debugging method based on serial port instructions, the KMP algorithm and hash algorithm are used to quickly match instructions, and through the optimized serial port printing function and instruction sending queue scheduling mechanism, the problems of poor scalability and limited interface resources of the existing EC debugging methods are solved, and efficient and flexible EC debugging is achieved.
Patent Information
- Application Number
- CN202411159064.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-22
- Publication Date
- 2025-04-18
- Estimated Expiration
- 2044-08-22
AI Technical Summary
The existing EC debugging methods have poor scalability, it is difficult to flexibly add or modify debugging instructions, and the interface resources are limited, making it easy to have interface mutual exclusion problems.
The EC debugging method based on serial port instructions is adopted to establish a two-way data communication channel between the EC and the debugging device through serial port connection, and the KMP algorithm and hash algorithm are used to quickly match and parse dynamic new instructions, and improve debugging flexibility and efficiency through optimized serial port printing functions and command sending queue scheduling mechanism based on priority and timestamps.
It realizes the flexibility and scalability of EC debugging, which is easy to adapt to different debugging needs, improves debugging efficiency and reliability, and avoids the problems of limited interface resources and mutual exclusion.
Smart Images

Figure CN119046070B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to an EC debugging method based on serial port instructions. Background Art
[0002] With the continuous development of computer technology, embedded controllers (EC) play an increasingly important role in modern computer systems. EC is responsible for the overall coordination and control of the computer by connecting multiple subsystems such as power management, thermal management, keyboard control, etc. The normal operation of EC directly affects the reliability and stability of the entire machine. Therefore, in the process of computer design and production, EC debugging is an indispensable key link.
[0003] At present, EC debugging is mainly carried out through standard interfaces such as JTAG and I2C. Debuggers use various emulators and debuggers to connect to EC through these interfaces, and use the debugging functions provided by the emulators and debuggers to control and debug EC. However, this debugging method has many limitations: First, the debugging method based on standard interfaces has poor scalability. Since the debugging instruction set of standard interfaces such as JTAG and I2C is fixed, it is impossible to flexibly add debugging instructions. When EC chips are updated or debugging requirements change, the existing debugging instructions are often difficult to meet the requirements, and the debugger needs to be upgraded or even redesigned, which has poor scalability; in addition, debugging EC through standard interfaces also faces problems such as limited interface resources and mutual exclusion with other debugging objects. The number of JTAG and I2C interfaces on an EC chip is limited. When multiple objects need to be debugged, the interface must be switched, which affects the debugging efficiency. Moreover, when other devices also need to use these standard interfaces, they will conflict with EC debugging and interfere with the normal debugging of EC. Summary of the invention
[0004] In view of the problem of poor scalability of EC debugging in the prior art, the present application provides an EC debugging method based on serial port instructions, which can realize flexible and scalable EC debugging functions, facilitate the addition or modification of debugging instructions, and adapt to different EC debugging requirements.
[0005] The purpose of this application is achieved through the following technical solutions.
[0006] The present application provides an EC debugging method based on serial port instructions, comprising: S1, connecting the sending port and receiving port of the serial port from the EC end to the receiving port and sending port of the debugging device respectively, and setting the serial port parameters of the EC end and the debugging device; wherein the serial port parameters include baud rate, data bit, stop bit and check bit; specifically, connecting the serial port sending port (TX) of the EC end to the serial port receiving port (RX) of the debugging device through a serial port connection line, and connecting the serial port receiving port (RX) of the EC end to the serial port sending port (TX) of the debugging device, so as to establish a two-way data communication channel between the EC end and the debugging device; configuring the serial port communication parameters on the EC end and the debugging device respectively: by setting the baud rate parameter of the serial port, the serial port communication baud rate of the EC end and the debugging device is kept consistent, so as to ensure the rate matching of data transmission; by setting the data bit parameter of the serial port, the EC end and The serial communication data bit length of the debugging device is kept consistent to ensure that the data length of a single transmission matches; by setting the stop bit parameter of the serial port, the stop bit length of the serial communication between the EC end and the debugging device is kept consistent to ensure the timing synchronization of data transmission; by setting the parity bit parameter of the serial port, the serial communication parity mode of the EC end and the debugging device is kept consistent to ensure the integrity and accuracy of data transmission; the EC end and the debugging device initialize their respective serial port controllers according to the configured serial port parameters: write the configuration values of the baud rate, data bit, stop bit and parity bit into the corresponding registers of the serial port controller, and start the serial port controller; enable the sending and receiving functions of the serial port controller, and configure the corresponding interrupts to prepare for data transmission; the EC end and the debugging device establish a unified data transmission standard and control timing through serial port connection and parameter configuration, laying the communication foundation for subsequent command data interaction.
[0007] S2, the debugging device sends command data to the EC end through the serial port; S3, the EC end determines whether the command data is received through the serial port interrupt mechanism; S4, after the EC end obtains the received complete command data, it uses the KMP algorithm to match the obtained command data with the predefined command names in the instruction set array; where the instruction set array is a constant array inside the EC end; S5, the EC end determines whether the received command data is a command to open the serial port to print information based on the command matching result, and whether the flag bit corresponding to the command data is at a low level: if the received command is to open the serial port The EC end further determines the status of the serial port print switch flag. If the serial port print switch flag is off, the EC end sets the serial port print information flag to a high level to turn on the serial port printing function. The EC end periodically polls the status of the serial port print information flag through a priority task. If the flag is high, the ACPI information and battery information of the EC end are printed through the serial port at preset time intervals. When the EC end receives the stop printing command, it sets the serial port print information flag to a low level to turn off the serial port printing function.
[0008] Among them, EC (Embedded Controller): EC is a microcontroller in a laptop or other embedded system. The debugging device is an external device used to communicate and interact with EC. It can be a computer, a single-chip development board, or other devices with serial communication capabilities. The debugging device sends command data to EC through the serial port and receives information returned by EC to debug and monitor EC. Command data is a piece of data sent by the debugging device to EC through the serial port. It contains specific command names and related parameters, which are used to control the behavior of EC or obtain EC status information. The format and content of the command data are defined by the communication protocol between EC and the debugging device.
[0009] Among them, the KMP algorithm is an algorithm for string matching. It uses the information that has been matched to avoid repeated comparisons and improve the efficiency of string matching. In the EC debugging method, the KMP algorithm is used to match the received instruction data with the predefined instruction names in the instruction set array. The serial port printing information opening instruction is a specific instruction data used to control the serial port printing function of EC. When EC receives the instruction, if the flag bit corresponding to the instruction data is low level and the serial port printing switch flag bit is off, EC will set the serial port printing information flag bit to a high level and turn on the serial port printing function. ACPI information (Advanced Configuration and Power Interface Information): ACPI is a standard power management interface specification. ACPI information includes power status, power management events, power button status and other information related to system power management. In the EC debugging method, when the serial port printing function is turned on, EC will print ACPI information through the serial port to debug and monitor the power management status of the system. Battery information includes battery power, battery temperature, charge and discharge status and other information related to the laptop battery. EC is responsible for monitoring and managing the battery status and reporting battery information to the system. In the EC debugging method, when the serial port printing function is turned on, EC will print the battery information through the serial port to debug and monitor the battery status.
[0010] Further, S4, after the EC end obtains the received complete instruction data, it uses the KMP algorithm to match the obtained instruction data with the predefined instruction names in the instruction set array, including: pre-building a partial matching table PMT of the KMP algorithm according to the characteristics of each instruction name in the instruction set array, the partial matching table PMT stores the length of the longest common element of the prefix and suffix of each instruction name, which is used to accelerate the matching and avoid repeated matching during the matching process; using the received complete instruction data as the main string and the instruction name in the instruction set array as the pattern string, using the hash algorithm to screen the main string and the pattern string to obtain a candidate matching pair; using the partial matching table PMT to match the candidate matching pairs; if the match is successful, outputting the successfully matched instruction name.
[0011] Among them, the partial match table PMT (Partial Match Table): The partial match table is a data structure used to accelerate string matching in the KMP algorithm. It stores the length of the longest common element of the prefix and suffix of the pattern string. During the matching process, by querying the partial match table, the position of the next match can be quickly determined to avoid repeated matching.
[0012] Furthermore, a partial match table PMT is pre-constructed, including: setting a maximum match length threshold MAX_LEN, dividing the instruction names in the instruction set array whose length exceeds the maximum match length threshold MAX_LEN into multiple sub-patterns, and the length of the sub-pattern is less than or equal to the threshold MAX_LEN; for each instruction name or sub-pattern in the instruction set array, using the Next array construction method of the KMP algorithm, counting the maximum length of the common elements of the corresponding prefix and suffix, and generating a corresponding partial match table; using a radix tree trie to index the partial match table corresponding to each instruction name or sub-pattern in the instruction set array to speed up the query and access of the partial match table; combining the partial match table corresponding to each instruction name or sub-pattern in the instruction set array and the radix tree trie index into a complete partial match table data structure PMT.
[0013] Among them, radix tree trie (Trie Tree): radix tree is a tree data structure used to store and retrieve strings. Each of its nodes represents a character, and the path from the root node to a node represents a string. In the scheme, the radix tree is used to index the partial match table corresponding to each instruction name or sub-pattern in the instruction set array to speed up the query and access of the partial match table.
[0014] Preferably, a radix tree is used to index the partial matching table corresponding to each instruction name in the instruction set array, including: constructing a Trie tree with the character sequence of each instruction name or sub-pattern in the instruction set array as the basic data structure of the AC automaton; constructing a failure pointer based on the Trie tree to form an AC automaton; for each state node in the AC automaton, calculating the index position of the corresponding instruction name or sub-pattern in the original instruction set array, and storing the index position as satellite data in the state node; in the KMP matching process, traversing the characters of the instruction content, performing multi-pattern matching in the AC automaton, obtaining the satellite data of the successfully matched state node, and obtaining the index position of the corresponding instruction name or sub-pattern; according to the index position, quickly searching the partial matching table corresponding to the instruction name or sub-pattern in the instruction set array, determining the next matching character position, until the matching of the entire instruction content is completed. In the KMP matching process, the characters of the instruction content are traversed, and the steps of performing multi-mode matching in the AC automaton include: initializing the current state as the initial state of the AC automaton, setting the current matching character sequence to be empty; reading the next character in the instruction content in sequence, and adding the character to the end of the current matching character sequence; in the AC automaton, according to the current state and the newly read character, transferring to the next state along the Trie tree edge: if there is a Trie tree edge of the corresponding character, transferring to the corresponding child node and updating the current state; if there is no Trie tree edge of the corresponding character, recursively jumping to the failure pointer until falling back to a state or initial state with a corresponding character transfer edge; checking whether the current state corresponds to one or more completely matched instruction names or sub-patterns, if so, quickly searching the corresponding partial matching table according to its associated instruction name or sub-pattern index.
[0015] Furthermore, the received complete instruction data is used as the main string, and the instruction name in the instruction set array is used as the pattern string, and the main string and the pattern string are screened using a hash algorithm, including: using a Rolling Hash algorithm to build a sliding window of size L on the received complete instruction data, i.e., the main string, where L is the average length of the pattern string in the instruction set array; sliding from left to right on the main string, and each time a character is slid, the Rolling Hash algorithm uses a polynomial Hash function to complete the incremental update of the substring Hash value in the sliding window in a constant time, thereby realizing fast calculation of the substring Hash value; the polynomial Hash function maps characters to a prime number domain, and uses Horner's rule to efficiently merge new characters and eliminate the influence of old characters on the Hash value; and judging whether the Hash value of the substring in the sliding window is equal to the Hash value of the pattern string, and if so, taking the substring and the pattern string as a candidate matching pair.
[0016] Preferably, a Bloom filter is used to index the Hash value of each instruction name or sub-pattern in the instruction set array. Before determining whether the Hash values of the substring and the pattern string are equal, the Bloom filter is used to quickly determine whether the Hash value of the substring exists in the Hash value set of the pattern string. Only when the Bloom filter determines that it may exist, the Hash value comparison is performed.
[0017] Among them, the Rolling Hash algorithm: The Rolling Hash algorithm is an algorithm for quickly calculating the hash value of a string. It uses the characteristics of the sliding window and the hash function to complete the incremental update of the hash value of the substring in the sliding window in constant time. By comparing the hash value of the substring in the sliding window with the hash value of the pattern string, the potential matching position can be quickly screened out. The instruction set array is a constant array inside the EC end, which is used to store predefined instruction names. Each instruction name is a string that represents a specific instruction. During the matching process, the received instruction data is matched with the instruction name in the instruction set array to determine the type and function of the instruction. Horner's Rule: Horner's Rule is a method for efficiently calculating polynomial values. In the Rolling Hash algorithm, the polynomial hash function maps the string to the prime number field, and the update of the hash value can be completed in constant time using Horner's Rule. Horner's Rule avoids the overhead of repeated calculations by merging new characters and eliminating the influence of old characters on the hash value. The partial match table PMT and radix tree trie are used to optimize the matching process of the KMP algorithm. By pre-calculating and storing the prefix and suffix information of the instruction name, the matching process is accelerated and repeated matching is avoided. The Rolling Hash algorithm and Horner's rule are used to quickly screen candidate matching pairs. Through the characteristics of the sliding window and hash function, the substring hash value is updated and compared in a constant time, thereby quickly locating potential matching positions.
[0018] Furthermore, in S3, judging whether the command data is received through the serial port interrupt mechanism includes: the serial port receiving pin at the EC end receives the serial data bit stream, and converts the serial data bit stream into parallel data bytes through the shift register and data buffer in the serial port controller, and stores them in the serial port receiving buffer; the serial port controller judges whether the data in the receiving buffer meets the length of a complete data frame according to the preset data frame format, and the data frame format includes a start bit, a data bit, a check bit and a stop bit; when the data length in the receiving buffer meets the length of the complete data frame, the serial port controller sends a receiving completion interrupt request to the interrupt controller at the EC end; the interrupt controller responds to the receiving completion The interrupt request is received, the interrupt vector number is written into the interrupt vector table, and the interrupt service program on the EC side is triggered; the interrupt service program jumps to the pre-registered serial port receive interrupt processing function according to the interrupt vector number; the serial port receive interrupt processing function reads the complete instruction data frame from the serial port receive buffer and passes it to the instruction parsing module; the serial port receive interrupt processing function clears the receive completion interrupt flag, and the serial port controller continues to receive the next frame of data; if the data length in the receive buffer is less than a complete data frame, the serial port controller continues to receive subsequent bytes and merges them into the receive buffer through the shift register and the data buffer until the complete data frame length is met to trigger the receive completion interrupt.
[0019] Further, S2, the debugging device sends instruction data to the EC end through the serial port, including: S21, the debugging device generates a complete debugging instruction according to a predetermined instruction format, the debugging instruction is in frames, and adopts a frame format of frame header + instruction type + data length + instruction content + frame tail + CRC check; wherein, the frame header is used to identify the beginning of a frame of instructions, the frame tail is used to identify the end of a frame of instructions, the instruction type is used to identify the function of the instruction, the data length is used to identify the length of the instruction data, the instruction content is specific instruction data, and the CRC check is used to verify the correctness of the entire frame of data; S22, the debugging device writes the generated debugging instruction into the sending buffer of the serial port controller, and sends the instruction data through the serial port controller; wherein the serial port controller includes a data register, a status register and an interrupt enable register; S23, the serial port controller converts the parallel instruction data in the sending buffer into a serial bit stream and sends it through the TX pin; S24, after sending a frame of debugging instructions, the serial port controller clears the send enable bit and triggers a sending completion interrupt.
[0020] Among them, CRC check (Cyclic Redundancy Check): CRC check is a commonly used error detection method used to check whether errors occur during data transmission or storage. The sender generates a CRC check code based on the specified polynomial and appends it to the end of the data. The receiver calculates the CRC check code of the received data based on the same polynomial and compares it with the received CRC check code to detect whether the data is erroneous. Status Register (StatusRegister): The status register is a register in the serial port controller that reflects the current status of the serial port controller. It contains some flag bits, such as the send buffer empty flag, the receive buffer full flag, the send completion flag, etc. By reading the value of the status register, the working status of the serial port controller can be known so as to perform corresponding operations and processing. Interrupt Enable Register (Interrupt Enable Register): The interrupt enable register is a register in the serial port controller that controls the interrupt function of the serial port controller. It contains some enable bits, such as the send completion interrupt enable bit, the receive completion interrupt enable bit, etc. By setting the corresponding bit of the interrupt enable register, a specific interrupt source can be enabled or disabled so that an interrupt is triggered when the corresponding event occurs. Parallel instruction data: Parallel instruction data refers to instruction data transmitted in parallel. When sending instruction data, the debugging device writes the generated debugging instructions into the transmit buffer of the serial port controller in parallel. The serial port controller converts the parallel instruction data into a serial bit stream and sends it through the TX pin. TX pin (Transmit Pin): The TX pin is the transmit pin of the serial port controller, which is used to send the serial bit stream to the external device. After the serial port controller converts the parallel instruction data into a serial bit stream, it will send the data bit by bit through the TX pin. The level change of the TX pin represents the 0 and 1 of the serial data, and the receiving device receives the data by sampling the level of the TX pin. Transmit Enable Bit: The transmit enable bit is a control bit in the serial port controller, which is used to start or stop the transmission of data. When the transmit enable bit is set, the serial port controller starts to convert the data in the transmit buffer into a serial bit stream and sends it through the TX pin. When the transmission is completed, the serial port controller will clear the transmit enable bit, indicating that the current data has been sent and the next transmission can be carried out.
[0021] Preferably, S23, the serial port controller converts the parallel instruction data in the sending buffer into a serial bit stream and sends it through the TX pin, including: the parallel-to-serial conversion circuit inside the serial port controller reads a byte to be sent from the sending buffer and stores it in the parallel-to-serial conversion shift register; the baud rate generator generates a shift clock corresponding to the set baud rate, driving the bits in the parallel-to-serial conversion shift register to shift out in sequence; wherein the baud rate generator generates a shift clock based on a high-precision reference clock source and a configurable frequency division counter, and the data transmission rate can be flexibly set by adjusting the frequency division coefficient; during the shifting process, the output end of the parallel-to-serial conversion circuit automatically inserts a start bit and a stop bit between bytes according to the configured asynchronous serial frame format, calculates the check information of the current byte according to the configured check method, and inserts a check bit when necessary to form an asynchronous serial data frame; wherein, the asynchronous serial frame format and the check method can be flexibly configured by writing into the configuration register of the serial port controller; the asynchronous serial data frame is converted into a signal of the RS232 level standard through the RS232 level conversion circuit and sent from the TX pin; wherein, the RS232 level conversion circuit includes at least one RS232 transceiver chip, which can realize the bidirectional conversion between TTL / CMOS level and RS232 level, and improve the transmission distance and anti-interference ability of the signal; the TX pin is connected to the digital input pin of the debugging device, and the level status of each bit in the sending process is reflected in real time; the debugging device uses the digital input pin to read the TX signal in real time and monitor whether there is any abnormality in the sending process; if the TX signal is detected to be abnormal, the debugging device promptly sends a reset signal to the reset pin of the serial port controller to restart the transmission.
[0022] Further, S22, the debugging device writes the generated debugging instruction into the sending buffer of the serial port controller, and sends the instruction data through the serial port controller, including: judging the idle state of the sending buffer by reading the status register of the serial port controller; enabling the sending completion interrupt by setting the interrupt enable register; when the status register indicates that the sending buffer is idle and the sending completion interrupt is enabled in the interrupt enable register, writing each byte of the debugging instruction frame in sequence into the data register of the serial port controller, and storing it into the sending buffer via the parallel bus; after each byte is written, reading the status register to obtain the update state and the remaining state of the sending buffer to prevent the buffer from overflowing; when all the bytes of a frame of debugging instructions are written into the data register, writing a valid value into the sending enable bit of the control register to start the parallel-to-serial conversion and sending circuit of the serial port controller.
[0023] Buffer overflow: Buffer overflow refers to the situation where the amount of data written to the buffer exceeds the capacity of the buffer, causing data overflow and overwriting the adjacent memory area. In serial communication, if the capacity of the send buffer is limited and the amount of data written is too large, buffer overflow may occur. In order to prevent buffer overflow, the debugging device needs to check the status of the send buffer when writing data to ensure that there is enough space to accommodate the data to be written.
[0024] Valid Value: A valid value is a legal range of values in a variable or register. When starting the transmit circuit of a serial port controller, a valid value needs to be written to the transmit enable bit of the control register. Valid values are usually predefined and indicate whether a function is enabled or disabled. For example, writing 1 may indicate enabling transmit, while writing 0 may indicate disabling transmit.
[0025] Further, S24, after sending a frame of debugging instructions, the serial port controller clears the send enable bit and triggers a send completion interrupt, including: after the serial port controller sends the last bit of a frame, it clears the send enable bit in the control register and turns off the parallel-to-serial conversion and the sending circuit; the debugging device responds to the send completion interrupt in an interrupt-driven manner and stops the send timeout timer of the corresponding frame; by reading multiple status flags of the serial port controller, it is determined whether the sending process of the current frame instruction is completed normally; wherein the status flag includes the send status bit and the send error bit in the status register, the send timeout event bit in the interrupt time register, and the overflow flag of the send timeout timer; if the send status bit of the status register indicates that the sending is completed normally, and the send error bit, the send timeout event bit and the timeout timer overflow flag are not set, it is determined that the sending of the current frame instruction is successful; the debugging device records the sending completion time of the current frame instruction, deletes the instruction from the sending queue, and enters the deletion event into the debugging log; otherwise, it is determined that the sending of the current frame instruction fails and is marked as sending failure in the sending queue; the debugging device samples the scheduling algorithm based on priority and timestamp to manage the sending queue.
[0026] Among them, the timeout timer (TimeoutTimer): The timeout timer is a mechanism used to monitor whether the operation is completed within the specified time. When sending command data, the debugging device will start a timeout timer to monitor whether the sending of the command is completed within the expected time. If the timeout timer overflows before the sending is completed, it means that the sending operation has timed out and an abnormal situation may have occurred. The debugging device can determine whether the instruction sending has timed out by checking the overflow flag of the timeout timer and take corresponding processing measures.
[0027] Furthermore, the debugging device adopts a scheduling algorithm based on priority and timestamp to manage the sending queue, including: the debugging device associates a priority and a timestamp for each instruction in the sending queue, the priority is used to indicate the importance and urgency of the instruction, and the timestamp is used to record the time when the instruction was entered into the queue or the time when it was last sent; the debugging device periodically scans the sending queue, and for each instruction that has been sent but not yet confirmed: compares the current time with the timestamp of the instruction, and calculates the waiting time of the instruction in the queue; if the waiting time of the instruction exceeds the set timeout threshold and the number of retransmissions has not reached the maximum limit, the instruction is marked as a sending timeout, its timestamp is updated to the current time, the number of retransmissions is increased by 1, and it is reinserted into the sending queue; if the waiting time of the instruction exceeds the set timeout threshold and the number of retransmissions has reached the maximum limit, the instruction is removed from the sending queue, the removal event and the instruction content are reported, and recorded in the debugging log; the debugging device inserts the newly added instruction to be sent into the sending queue according to the priority: if the priority of the new instruction is higher than that of all instructions in the queue, it is inserted Enter the head of the queue; if the priority of the new instruction is lower than that of all instructions in the queue, insert it to the end of the queue; if the priority of the new instruction is the same as some instructions in the queue, insert it into the instruction group with the same priority and sort it according to the time of entering the queue; the debugging device selects the earliest instruction to be sent from the sending queue as the next frame according to the current time: scan the sending queue to find the instruction with the highest priority and the earliest timestamp; if the instruction has not timed out, send it as the next frame; if the instruction has timed out, perform timeout processing according to step S2452, and rescan the queue until an instruction that has not timed out is found and sent as the next frame; the debugging device provides a host-oriented configuration interface, allowing dynamic adjustment of the management strategy of the sending queue: receive the configuration parameters sent by the host, including the maximum number of retransmissions, timeout threshold, default priority, etc. of the instruction; dynamically adjust the relevant judgment conditions and operation methods according to the configuration parameters; feedback the real-time status of the sending queue to the host, including statistical information such as queue length, average waiting time, number of timed out instructions, number of retransmitted instructions, etc., to facilitate optimization of the debugging strategy. The dual attributes of priority and timestamp are introduced to comprehensively characterize the importance and timeliness of instructions, providing more abundant decision-making basis for queue scheduling. The periodic scanning and timeout detection mechanism dynamically updates the timestamp and retransmission times of instructions, promptly removes long-unconfirmed instructions, and improves the timeliness of the queue. The insertion and sorting rules of instructions are optimized. Instructions with high priority are always sent first, and instructions with the same priority are sorted according to the first-come-first-served principle, taking into account the importance and fairness of instructions.
[0028] Compared with the prior art, the advantages of this application are:
[0029] This method defines a frame-based instruction format, and the debugging instructions are encapsulated and transmitted in the form of frame header + instruction type + data length + instruction content + frame tail + CRC check. By increasing the instruction type and the corresponding instruction content, new debugging instructions can be easily added without modifying the communication protocol and data frame format. The EC side introduces an instruction set array to manage various debugging instructions. Combined with the partial matching table PMT of the KMP algorithm and the Rolling Hash of the hash algorithm, dynamically added instructions can be quickly matched and parsed. Therefore, this method has strong scalability and is easy to adapt to the changing needs of the EC debugging process.
[0030] This method uses the optimized KMP algorithm and hash algorithm on the EC side to match and parse the received instruction data. The KMP algorithm uses the partial matching table PMT to store the maximum length of the common elements of the prefix and suffix of each instruction in the instruction set, and can quickly generate PMT when adding new instructions. Based on PMT, the matching position of the instruction can be quickly found, reducing the time complexity of instruction matching. The hash algorithm uses the Rolling Hash method to quickly screen candidate instructions during the matching process, further improving the efficiency of instruction matching.
[0031] This method abstracts the serial port printing function of the EC end into a configurable item and introduces an independent serial port printing information flag. By adding printing instructions for different debugging objects and setting corresponding flags, the existing log printing mechanism can be used to flexibly output the required debugging information without modifying the EC end code. The debugger can dynamically turn on or off the log printing of the specified debugging object as needed, which improves the pertinence of debugging.
[0032] This method introduces a priority and timestamp-based instruction sending queue scheduling mechanism on the debugging device side, which supports priority management, timeout detection and retransmission control of debugging instructions. It ensures that important or time-sensitive debugging instructions can be transmitted and executed first, improving the reliability of the debugging process. The EC side uses an asynchronous communication method based on hardware interrupts to receive debugging instructions, and transparently processes them through the serial port receiving interrupt processing mechanism, which effectively avoids the impact of instruction reception and execution on the normal tasks of EC. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] The present application will be further described in the form of exemplary embodiments, which will be described in detail by the accompanying drawings. These embodiments are not restrictive, and in these embodiments, the same number represents the same structure, wherein:
[0034] Figure 1 is an exemplary flow chart of an EC debugging method based on serial port instructions according to some embodiments of the present application;
[0035] Figure 2It is a schematic diagram of the serial port interface design of the EC end according to some embodiments of the present application;
[0036] Figure 3 is an exemplary sub-step flow chart of matching instructions using the KMP algorithm according to some embodiments of the present application;
[0037] Figure 4 This is an exemplary sub-step flowchart of EC-side serial port debugging according to some embodiments of the present application.
[0038] Description of the numbers in the figure: DETAILED DESCRIPTION
[0039] The method and system provided in the embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0040] Figure 1 It is an exemplary flow chart of an EC debugging method based on serial port instructions shown in some embodiments of the present application, including: connecting the sending port and receiving port of the serial port from the EC end to the receiving port and sending port of the debugging device respectively, and setting the serial port parameters of the EC end and the debugging device; wherein the serial port parameters include baud rate, data bit, stop bit and check bit; the debugging device sends instruction data to the EC end through the serial port; the EC end determines whether the instruction data is received through the serial port interrupt mechanism; after the EC end obtains the received complete instruction data, the KMP algorithm is used to match the obtained instruction data with the predefined instruction name in the instruction set array; wherein the instruction set array is a constant array inside the EC end; the EC end determines the received instruction data according to the instruction matching result. Whether the received instruction data is an instruction to open the serial port printing information, and whether the flag bit corresponding to the instruction data is at a low level: if the received instruction is an instruction to open the serial port printing, and the corresponding flag bit is at a low level, the EC end further determines the state of the serial port printing switch flag bit. If the serial port printing switch flag bit is in the off state, the EC end sets the serial port printing information flag bit to a high level to turn on the serial port printing function; the EC end periodically polls and detects the state of the serial port printing information flag bit through a priority task. If the flag bit is at a high level, the ACPI information and battery information of the EC end are printed through the serial port at preset time intervals; when the EC end receives the stop printing instruction, it sets the serial port printing information flag bit to a low level to turn off the serial port printing function.
[0041] Establish a serial port connection between the EC end and the debugging device, and prepare the hardware equipment and cables required for the serial port connection: The EC end has a DB9 serial port interface that complies with the RS-232 standard. The interface definition is as follows: Figure 2As shown. The serial port interface includes the sending port TX, the receiving port RX, the ground wire GND, etc. The debugging device is equipped with a DB9 serial port interface that matches the EC end serial port interface, or provides serial port function through a USB to serial port adapter. Prepare a standard DB9 serial port cable with female connectors at both ends to connect the EC end and the serial port interface of the debugging device.
[0042] Establish a physical connection between the EC end and the debugging device: Insert one end of the serial cable into the DB9 serial port interface of the EC end, and note that the pins of the cable should correspond to the pins of the serial port on the EC end. Insert the other end of the serial cable into the DB9 serial port interface of the debugging device, or into the DB9 interface of the USB-to-serial adapter. Carefully check whether the cable is plugged in tightly to ensure that the connection is firm and not loose or falling off. Check whether the cable is damaged or bent to ensure the integrity of the cable and the quality of signal transmission.
[0043] Figure 2 According to the serial port interface design schematic diagram of the EC end shown in some embodiments of the present application, the serial port communication parameters of the EC end and the debugging device are configured: in the program code of the EC end, the communication parameters of the serial port are set, including baud rate, data bit, stop bit and check bit, etc. In the serial port communication program of the debugging device, the same communication parameters as the EC end are set. Take the commonly used serial port debugging tool PuTTY as an example: open the PuTTY configuration interface and select the "Serial" protocol type. Set the serial port number to the serial port number connected to the debugging device, such as "COM1". Set the baud rate to a value consistent with the EC end, such as 115200. Set the data bit to 8, the stop bit to 1, and the check bit to None. Click the "Open" button to establish a serial port connection with the EC end. Verify the validity of the serial port connection: in the program code of the EC end, add test code for serial port sending and receiving. In the serial port debugging tool of the debugging device, try to send test data to the EC end to observe whether the EC end can receive and respond normally. Send test data at the EC end to observe whether the debugging device can receive and display the received data normally. If the two-way communication test is normal, it means that the serial port connection is established successfully and subsequent debugging operations can be performed. If the test fails, you need to check whether the connection line, communication parameters, etc. are correct.
[0044] The debugging device generates and sends debugging instructions. The debugging device generates a complete debugging instruction according to the predetermined instruction format: the instruction is in frames and uses a fixed frame format, including a frame header, instruction type, data length, instruction content, frame tail and CRC checksum. The frame header is a fixed byte, such as 0xAA, which marks the beginning of a frame of instructions. The instruction type is a byte used to identify debugging instructions with different functions, such as 0x01 for reading registers and 0x02 for writing registers. The data length is a byte, indicating the number of bytes in the instruction content. The instruction content is the actual instruction data, and the length is specified by the data length field and can be variable. The frame tail is a fixed byte, such as 0x55, which marks the end of a frame of instructions. The CRC checksum is two bytes, which is used to verify the correctness of the entire frame of data and is calculated using the CRC-16-CCITT algorithm.
[0045] The debugging device writes the generated debugging instructions into the transmit buffer of the serial port controller, and sends the instruction data through the serial port controller. By reading the status register of the serial port controller, the idle state of the transmit buffer is determined: The debugging device obtains the current state of the transmit buffer by reading the status register of the serial port controller. There is usually a flag bit in the status register, such as TXE (Transmit Buffer Empty), indicating whether the transmit buffer is empty. The debugging device reads the TXE bit. If it is 1, it means that the transmit buffer is empty and new data can be written; if it is 0, it means that the transmit buffer is not empty and needs to wait. Enable the transmit completion interrupt by setting the interrupt enable register: The debugging device enables the transmit completion interrupt by writing the interrupt enable register of the serial port controller. The interrupt enable register has a control bit, such as TXEIE (Transmit Buffer Empty Interrupt Enable), which is used to enable the transmit completion interrupt. The debugging device sets the TXEIE bit to 1 to enable the transmit completion interrupt. When the transmit buffer is empty, the transmit completion interrupt will be triggered.
[0046] Write each byte of the debug command frame into the data register of the serial port controller in sequence: When the send buffer is empty and the send completion interrupt is enabled, the debug device writes each byte of the debug command frame into the data register of the serial port controller in sequence. The data register is usually called DR (Data Register), which is used to store the data bytes to be sent. The debug device writes each byte of the command frame into the send buffer via the parallel bus by writing it into the DR register.
[0047] After each byte is written, the status register is read to obtain the updated status and remaining space of the send buffer: After a byte is written to the data register, the status of the send buffer changes. The debug device obtains the latest status and remaining space of the send buffer by reading the status register again. There is usually a flag bit in the status register, such as TXE, which indicates the idle state of the send buffer. If TXE is 1, it means that there is remaining space in the send buffer; if TXE is 0, it means that the send buffer is full. The debug device determines whether it can continue to write the next byte based on the TXE flag bit to prevent the send buffer from overflowing.
[0048] After all bytes of a frame of debugging instructions are written into the data register, the serial port controller starts the sending operation: After all bytes of a frame of debugging instructions are written into the data register, the debugging device starts the sending operation of the serial port controller by writing a valid value to the send enable bit of the control register. The control register has a send enable bit, such as TE (TransmitEnable), which is used to control the sending circuit of the serial port controller. The debugging device sets the TE bit to 1, starts the parallel-to-serial conversion and the sending circuit, and starts converting the data in the send buffer into a serial bit stream and sending it through the TX pin.
[0049] The serial port controller converts the parallel instruction data in the send buffer into a serial bit stream and sends it through the TX pin: The parallel-to-serial conversion circuit inside the serial port controller reads a byte to be sent from the send buffer and stores it in the parallel-to-serial conversion shift register. The baud rate generator generates a shift clock corresponding to the set baud rate, driving the bits in the parallel-to-serial conversion shift register to shift out in sequence: The baud rate generator is based on a high-precision reference clock source and a configurable frequency division counter, and flexibly sets the data transmission rate by adjusting the frequency division coefficient. During the shifting process, the output end of the parallel-to-serial conversion circuit automatically inserts the start bit, stop bit and check bit according to the configured asynchronous serial frame format to form an asynchronous serial data frame: The asynchronous serial frame format and check mode can be flexibly configured by writing the configuration register of the serial port controller. The asynchronous serial data frame is converted into a signal of the RS232 level standard through the RS232 level conversion circuit and sent from the TX pin: The RS232 level conversion circuit contains an RS232 transceiver chip, which realizes bidirectional conversion between TTL / CMOS level and RS232 level, and improves the transmission distance and anti-interference ability. The TX pin is connected to the digital input pin of the debugging device, which reflects the level status of each bit in the transmission process in real time: the debugging device reads the TX signal in real time through the digital input pin to monitor whether there is any abnormality in the transmission process. If an abnormal TX signal is detected, the debugging device sends a reset signal to the reset pin of the serial port controller to restart the transmission.
[0050] After sending a frame of debugging instructions, the serial port controller clears the send enable bit and triggers the send completion interrupt. After the serial port controller sends the last bit of a frame, it automatically clears the send enable bit of the control register and turns off the parallel-to-serial conversion and the sending circuit: When the last bit of a frame of data is sent, the serial port controller hardware automatically clears the TE bit in the control register. After the TE bit is cleared, the parallel-to-serial conversion circuit and the sending circuit of the serial port controller are automatically turned off and the sending operation is stopped. The debugging device responds to the send completion interrupt in an interrupt manner and stops the send timeout timer of the corresponding frame: When the send completion interrupt is triggered, the debugging device responds to the interrupt in the interrupt service program. The debugging device stops the timeout timer started for the current sending frame to avoid subsequent triggering of the timeout event. The debugging device reads the status flag of the serial port controller to determine whether the sending of the instruction of this frame is completed normally: The debugging device reads the status register, interrupt status register and timeout timer flag of the serial port controller to comprehensively determine the instruction sending status.
[0051] Status judgment conditions: The TXE bit of the status register is 1, indicating that the transmit buffer is idle and there is no transmit error. The transmit error bits (such as ORE, NE, FE, PE) of the status register are all 0, indicating that there is no frame error, noise error, or parity error. The transmit timeout event bit of the interrupt status register is 0, indicating that the transmission is completed within the scheduled time and there is no timeout event. The overflow flag of the transmit timeout timer is 0, indicating that the timer has not overflowed and there is no timeout. According to the transmission status, the debugging device performs the corresponding instruction queue management operation: If the transmission is completed normally, the debugging device records the transmission completion time of the instruction, deletes the instruction from the transmission queue, and writes the deletion event to the debugging log. If the transmission fails, the debugging device marks the instruction as a transmission failure status in the transmission queue, and can resend or error handle it as needed later.
[0052] The debugging device uses a scheduling algorithm based on priority and timestamp to manage the sending queue: each instruction in the sending queue is associated with a priority and a timestamp. The priority indicates the importance of the instruction, and the timestamp records the time when the instruction was queued or the last time it was sent. The debugging device periodically scans the sending queue to check the waiting time of the instructions that have been sent but not confirmed, and calculates it by comparing the current time with the instruction timestamp. If the instruction waiting time exceeds the set timeout threshold, but the number of retransmissions does not reach the maximum limit, the instruction is marked as timed out, the timestamp and retransmission number are updated, and the instruction is reinserted into the sending queue to wait for sending. If the instruction still times out after multiple retransmissions and reaches the maximum number of retransmissions, the instruction is removed from the sending queue, and the removal event and instruction content are reported and written into the debugging log to facilitate subsequent problem location. For newly added instructions to be sent, the debugging device inserts them into the appropriate position of the sending queue according to their priority to ensure that instructions with high priority can be sent first. According to the current time, the debugging device selects the highest priority and earliest timestamp from the sending queue as the next frame to send, ensuring the real-time and importance of the instruction.
[0053] Determining whether the command data has been received through the serial port interrupt mechanism includes: Serial data reception and conversion: The serial port receiving pin (such as RX) on the EC side receives the serial data bit stream from the debugging device. The shift register (such as RXD) inside the serial port controller converts the received serial bit stream into parallel data bits. The parallel data bits in the shift register are transferred to the data buffer (such as RDR) to form a complete data byte. The data bytes in the data buffer are automatically stored in the serial port receiving buffer (such as RXFIFO). Determine the data length of the receiving buffer: The serial port controller determines whether the data length in the receiving buffer meets the length of a complete data frame according to the preset data frame format. The data frame format usually includes 1 start bit, 59 data bits, 01 check bits and 1 to 2 stop bits. The serial port controller sets the data frame format, such as data bit length, check mode and number of stop bits, through the configuration register (such as CR1). Triggering the receiving completion interrupt: When the data length in the receiving buffer reaches the complete data frame length, the serial port controller sends a receiving completion interrupt request to the interrupt controller on the EC side. The serial port controller sends an interrupt request by setting the receive completion interrupt flag bit (such as RXNE) of the interrupt status register (such as ISR).
[0054] The interrupt controller responds to the interrupt request: After the interrupt controller receives the receive completion interrupt request from the serial port controller, it writes the corresponding interrupt vector number into the interrupt vector table. The interrupt vector table is an array that stores the entry address of the interrupt service program. Each interrupt source corresponds to an interrupt vector number and a service program address. The interrupt controller triggers the corresponding interrupt service program according to the interrupt vector number. Execute the serial port receive interrupt service program: The interrupt service program jumps to the pre-registered serial port receive interrupt processing function according to the interrupt vector number. The serial port receive interrupt processing function reads the complete instruction data frame from the serial port receive buffer. The receive buffer is read through the data register (such as DR), one byte at a time, until the entire data frame is read.
[0055] Clear the receive completion interrupt flag: In the serial port receive interrupt processing function, after reading the complete instruction data frame, the receive completion interrupt flag needs to be cleared. Clear the interrupt flag by writing the corresponding bit of the interrupt status register (such as RXNE). After clearing the interrupt flag, the serial port controller can continue to receive the next frame of data and will not repeatedly trigger the current receive completion interrupt. Continue to receive subsequent data: If the data length in the receive buffer is less than a complete data frame, the serial port controller continues to receive subsequent bytes. The subsequent received bytes will be automatically merged into the existing data in the receive buffer through the shift register and the data buffer. The receive completion interrupt will be triggered only when the data length in the receive buffer accumulates to the length of the complete data frame.
[0056] Figure 3 This is an exemplary sub-step flowchart of matching instructions using the KMP algorithm as shown in some embodiments of the present application. The EC side parses the instruction data, builds a partial match table (PMT) of the KMP algorithm, and determines the instruction set array: according to the system design, an array containing all legal instruction names is defined, called the instruction set array. Each element in the instruction set array is a string representing the name of an instruction. The instruction name consists of letters, numbers and underscores, and the length does not exceed a fixed value. Analyze the characteristics of the instruction name: traverse the instruction set array and analyze the characteristics of each instruction name, such as length, prefix, suffix, etc. The maximum length of the instruction name is counted to determine the size of the partial match table. Identify the common prefixes and suffixes in the instruction name to optimize the matching process. Set the maximum match length threshold: according to system performance and memory limitations, set a maximum match length threshold MAX_LEN. MAX_LEN represents the maximum length of the instruction name or sub-pattern allowed when building the partial match table. Generally, the value of MAX_LEN should balance the matching efficiency and memory usage, and can be adjusted according to actual conditions.
[0057] Divide long instruction names into subpatterns: traverse the instruction set array and find instruction names whose length exceeds MAX_LEN. Divide these long instruction names into multiple subpatterns, and the length of each subpattern does not exceed MAX_LEN. The division of subpatterns should be as even as possible to avoid subpatterns that are too long or too short. Add the divided subpatterns to the instruction set array and process them as independent instruction names. Calculate the partial match table of the instruction name: traverse the instruction set array and calculate the partial match table for each instruction name or subpattern. The partial match table is an integer array whose length is equal to the length of the instruction name or subpattern. Each element of the partial match table represents the length of the longest common element of the prefix and suffix of the instruction name or subpattern.
[0058] The Next array construction method of the KMP algorithm is used to calculate the value of the partial match table. The process of constructing the Next array is as follows: Initialize the Next array and set the first element to 0, indicating that the longest common element length of the empty prefix and empty suffix is 0. Starting from the second element, traverse each character of the instruction name or sub-pattern. For the current position i, find the length j of the longest equal prefix and suffix in the substring before it. If the current character is equal to the next character of the prefix, Next[i] = j + 1, indicating that a longer equal prefix and suffix has been found. If the current character is not equal to the next character of the prefix, backtrack to Next[j] and continue to search for shorter equal prefixes and suffixes. Repeat the above process until the entire instruction name or sub-pattern is traversed and the complete Next array is obtained. Optimize the Next array: In the process of constructing the Next array, if it is found that the current character is equal to the next character of the prefix, in addition to updating the value of Next[i], it can be further optimized. If Next[j] = Next[Next[j]], it means that repeated matching process occurs, and some intermediate states can be directly skipped, and Next[i] is set to Next[Next[j]]. Through this optimization, unnecessary repeated comparisons in the matching process can be avoided, and matching efficiency can be improved.
[0059] Generate a partial match table: Generate a partial match table for each instruction name or sub-pattern based on the optimized Next array. The i-th element of the partial match table, PMT[i]=Next[i-1], represents the length of the longest equal prefix and suffix in the first i characters of the instruction name or sub-pattern. Store the generated partial match table in a two-dimensional array or hash table, with the instruction name or sub-pattern as the key and the partial match table as the value. Complete the construction of the partial match table: Repeat until all instruction names and sub-patterns in the instruction set array are processed. Finally, a complete partial match table data structure is obtained, which contains partial match information of all instruction names and sub-patterns. In the subsequent instruction data parsing process, this partial match table can be used to speed up the matching and recognition of instruction names.
[0060] Build a radix tree (Trie) index and define the radix tree node structure: Define a data structure for a radix tree node, which contains the following fields: Character (char): represents the character corresponding to the node. Child node pointer array (TrieNode*[]): stores the child node pointers of the node, and the array size is the size of the character set. Partial match table pointer (int*): points to the partial match table of the instruction name or sub-pattern corresponding to the node. End mark (bool): indicates whether the node is the end node of a certain instruction name or sub-pattern. Initialize the radix tree root node: create a new radix tree node as the root node, whose character field is empty, the child node pointer array is initialized to a null pointer, the partial match table pointer is empty, and the end mark is false. Insert instruction names or sub-patterns into the radix tree: traverse each instruction name or sub-pattern in the instruction set array and insert it into the radix tree. Starting from the root node of the radix tree, insert the instruction name or sub-pattern character by character.
[0061] For each character of the instruction name or subpattern, perform the following steps: If the pointer to the corresponding character in the child node pointer array of the current node is empty, create a new radix tree node and point the pointer to the new node. Update the current node to the newly created node or existing child node. When the last character of the instruction name or subpattern is inserted, set the end marker of the current node to true, indicating that the node is a complete instruction name or subpattern. Store the partial match table pointer corresponding to the instruction name or subpattern at the current node.
[0062] Query the partial match table of an instruction name or subpattern: Given an instruction name or subpattern, find its corresponding partial match table in the radix tree. Starting from the root node of the radix tree, match the instruction name or subpattern character by character. For each character of the instruction name or subpattern, perform the following steps: If the pointer to the corresponding character in the child node pointer array of the current node is empty, it means that the instruction name or subpattern does not exist and the query fails. Update the current node to the child node of the corresponding character. When the last character of the instruction name or subpattern is matched, check whether the end tag of the current node is true. If the end tag is true, it means that the complete instruction name or subpattern is found, and return the pointer to the partial match table stored in the node. If the end tag is false, it means that the instruction name or subpattern does not exist and the query fails.
[0063] Combine the partial match table and radix tree index: Combine the partial match table and radix tree index corresponding to each instruction name or sub-pattern in the instruction set array into a complete partial match table data structure PMT. The partial match table data structure PMT contains two parts: the radix tree index and the partial match table array. The radix tree index is a pointer to the root node of the radix tree, which is used to quickly find the partial match table corresponding to the instruction name or sub-pattern in the radix tree. The partial match table array is a one-dimensional array that stores the partial match tables of all instruction names or sub-patterns. The position of each instruction name or sub-pattern in the partial match table array can be determined by its index in the instruction set array. Each leaf node in the radix tree (i.e., the node with the end marker true) stores a pointer to the corresponding position in the partial match table array.
[0064] Use a hash algorithm to filter candidate matching pairs, use the received complete instruction data as the main string, and the instruction name in the instruction set array as the pattern string. Calculate the hash value of the main string and the pattern string: Select a suitable hash function, such as a polynomial hash function or a Bloom filter. Calculate the hash value of the main string and each pattern string separately. The calculation of the hash value should ensure a low probability of collision between different strings.
[0065] Use the Rolling Hash algorithm to build a sliding window: Determine the size of the sliding window: Calculate the average length of all pattern strings in the instruction set array, recorded as L. The size of the sliding window is L, that is, a window of length L is built on the main string. Initialize the sliding window: Set the starting position of the sliding window to the starting position of the main string. Extract the substring of length L starting from the starting position in the main string as the substring in the initial window. Calculate the hash value of the substring in the initial window: Use a polynomial hash function to calculate the hash value of the substring in the initial window.
[0066] The polynomial hash function can use the following formula: hash(s) = (s[0]*base^(L-1)+s[1]*base^(L-2)+...+s[L-1]*base^0)modprime; where s[i] represents the ASCII code value of the i-th character in the substring, base is a fixed constant (such as 31 or 37), and prime is a large prime number. Calculate the hash value of the substring in the initial window, recorded as window_hash. Move the sliding window: Move the sliding window one character position to the right. Update the substring in the window, remove the old character on the left, and add the new character on the right. Use the Rolling Hash algorithm to update the hash value: During the movement of the sliding window, use the Rolling Hash algorithm to update the hash value of the substring in the window in constant time. The Rolling Hash algorithm implements incremental updates through a polynomial hash function: Remove the contribution of the old character on the left: subtract the hash value contribution of the leftmost character from window_hash, that is, s[i]*base^(L-1). Shift the hash value in the window left by one position: multiply window_hash by base, which is equivalent to shifting the contribution of all characters left by one position. Add the contribution of the rightmost new character: add the ASCII code value of the rightmost new character to window_hash. Through the above steps, the new hash value after the sliding window is moved can be calculated in constant time.
[0067] Handling hash value overflow: Integer overflow may occur during the calculation of hash values. To avoid overflow, the hash value can be modulo after each calculation, that is, modulo prime. The modulo operation can limit the hash value to a fixed range while maintaining the uniqueness of the hash value. Repeat until the sliding window reaches the end of the main string. The Rolling Hash algorithm can efficiently build a sliding window and update the hash value of the substring in the window. The Rolling Hash algorithm utilizes the characteristics of the polynomial hash function and avoids the overhead of repeatedly calculating the hash value of the entire substring through incremental updates. In the process of moving the sliding window, the hash value of the substring in the new window can be obtained in constant time by removing the contribution of the leftmost old character, shifting the hash value in the window to the left, and adding the contribution of the rightmost new character. This incremental update method greatly improves the calculation efficiency. At the same time, using a polynomial hash function to map characters to the prime field can reduce the probability of hash conflicts.
[0068] Candidate matching pair screening: Initialize the candidate matching pair set: Create an empty candidate matching pair set to store potential matching pairs. Compare the hash value of the substring in the sliding window with the hash value of the pattern string: For each substring in the sliding window, calculate its hash value. Traverse each pattern string in the instruction set array and calculate its hash value. Compare the hash value of the substring in the sliding window with the hash value of each pattern string. If the hash values are equal, the substring in the sliding window and the corresponding pattern string are regarded as a candidate matching pair.
[0069] Record the position information of candidate matching pairs: For each candidate matching pair, record its starting position in the main string and the corresponding pattern string. A structure or tuple can be used to represent the candidate matching pair, which contains the starting position of the main string and the identifier of the pattern string. Add the candidate matching pair to the candidate matching pair set. Repeat the screening process: Move the sliding window to the right by one character position and update the hash value of the substring in the window. Repeat the comparison of the hash value of the substring in the new sliding window with the hash value of the pattern string, and record the new candidate matching pair. Keep moving the sliding window until the window reaches the end of the main string. Use the partial matching table to verify the candidate matching pair: traverse each candidate matching pair in the candidate matching pair set. For each candidate matching pair, search the partial matching table of the corresponding pattern string in the radix tree. Use the partial matching table to perform KMP algorithm matching at the candidate matching position of the main string. The KMP algorithm uses the information in the partial matching table to skip unnecessary comparisons and speed up the string matching process. Process the matching result: If a completely matching pattern string is found at the candidate matching position, the name of the instruction that successfully matched is recorded. The successfully matched instruction names can be added to a result list, or the matching results can be directly output, until all candidate matching pairs in the candidate matching pair set are verified.
[0070] Through the above steps, the hash algorithm can be used to quickly screen the main string and the pattern string to obtain potential candidate matching pairs. The Rolling Hash algorithm calculates the hash value of the substring in constant time through sliding windows and incremental updates, avoiding the overhead of repeated calculations. The polynomial hash function maps the string to the prime number field, reducing the probability of hash conflicts.
[0071] Figure 4 This is an exemplary sub-step flow chart of EC end serial port debugging according to some embodiments of the present application, where the EC end executes the instruction: Determination of instruction matching result: After the EC end receives the instruction data, it makes a judgment based on the matching result obtained by the instruction matching algorithm. Determine whether the received instruction data is an instruction to open the serial port to print information. Check whether the flag bit corresponding to the instruction data is in a low level state.
[0072] Turn on the serial port printing function: If the received command is a command to turn on the serial port printing, and the corresponding flag is low, the EC side further determines the status of the serial port printing switch flag. If the serial port printing switch flag is currently in the off state, the EC side will perform the following operations: Set the serial port printing information flag to a high level, indicating that the serial port printing function is turned on. Prepare the serial port communication interface and configure related serial port parameters, such as baud rate, data bit, stop bit, etc. Initialize the serial port printing buffer to store the information to be printed.
[0073] Periodic polling to detect the serial port print information flag: The EC end periodically polls and detects the status of the serial port print information flag through a priority task mechanism. The priority task can be an independent thread or a timer interrupt service program to ensure timely detection of flag changes. If the serial port print information flag is detected to be high, it means that serial port printing is required. Serial port printing EC end information: When the serial port print information flag is high, the EC end performs serial port printing at a preset time interval. At every preset time interval (for example, every 1 second), the EC end prints the following information through the serial port: ACPI information: including power status, power management events, power button status, etc. Battery information: including battery power, battery temperature, charge and discharge status, etc. The EC end formats the information to be printed into a string and sends it to the host computer or other connected devices through the serial port. After printing is completed, the EC end clears the serial port print buffer and waits for the next print.
[0074] Turn off the serial port printing function: When the EC receives the stop printing command, it means that the serial port printing function needs to be turned off. The EC sets the serial port printing information flag to a low level, indicating that serial port printing is turned off. Close the serial port communication interface and release related resources. Clear the serial port printing buffer to ensure that there is no residual printing information. Continue to listen for instructions: The EC continues to listen for instruction data from the host computer or other devices. Perform corresponding operations according to the received instruction data. The EC can control the opening and closing of the serial port printing function according to the received instruction data. When the serial port printing opening instruction is received and the corresponding flag is low, the EC will open the serial port printing function and periodically print ACPI information and battery information. When the stop printing instruction is received, the EC will close the serial port printing function and stop printing information. The instruction matching algorithm and the flag judgment realize the control of the serial port printing function by the EC. Through the periodic polling of the priority task, it is ensured that the change of the serial port printing information flag is detected in time, and the printing operation is performed when printing is required. At the same time, the printing frequency is controlled by the preset time interval to avoid the impact of too frequent printing on system performance.
Claims
1. An EC debugging method based on serial port instructions, comprising: S1, connect the sending port and receiving port of the serial port from the EC end to the receiving port and sending port of the debugging device respectively, and set the serial port parameters of the EC end and the debugging device; the serial port parameters include baud rate, data bit, stop bit and check bit; S2, the debugging device sends command data to the EC end through the serial port; S3, the EC end determines whether the command data has been received through the serial port interrupt mechanism; S4, after the EC end obtains the received complete instruction data, it uses the KMP algorithm to match the obtained instruction data with the predefined instruction name in the instruction set array; wherein the instruction set array is a constant array inside the EC end; S5, based on the command matching result, the EC determines whether the received command data is a command for opening the serial port to print information, and whether the flag bit corresponding to the command data is at a low level: If the received command is a command to open the serial port printing, and the corresponding flag is at a low level, the EC end further determines the state of the serial port printing switch flag. If the serial port printing switch flag is in the off state, the EC end sets the serial port printing information flag to a high level to open the serial port printing function. The EC end periodically polls and detects the status of the serial port print information flag through a priority task. If the flag is high, the ACPI information and battery information of the EC end are printed through the serial port at a preset time interval; When the EC end receives the stop printing instruction, it sets the serial port printing information flag to a low level to turn off the serial port printing function.
2. The EC debugging method based on serial port instructions according to claim 1, characterized in that: S4, after the EC side obtains the received complete instruction data, it uses the KMP algorithm to match the obtained instruction data with the predefined instruction name in the instruction set array, including: According to the characteristics of each instruction name in the instruction set array, a partial matching table PMT of the KMP algorithm is pre-built. The partial matching table PMT stores the length of the longest common element of the prefix and suffix of each instruction name, which is used to speed up the matching and avoid repeated matching during the matching process. The received complete instruction data is used as the main string, and the instruction name in the instruction set array is used as the pattern string. The main string and the pattern string are screened by a hash algorithm to obtain a candidate matching pair; Matching candidate matching pairs using a partial matching table PMT; If the match is successful, the command name that matched successfully is output.
3. The EC debugging method based on serial port instructions according to claim 2, characterized in that: Pre-build partial match table PMT, including: Set the maximum match length threshold MAX_LEN, and divide the instruction names in the instruction set array whose length exceeds the maximum match length threshold MAX_LEN into multiple sub-patterns, and the length of the sub-pattern is less than or equal to the threshold MAX_LEN; For each instruction name or sub-pattern in the instruction set array, the Next array construction method of the KMP algorithm is used to count the maximum length of the common elements of the corresponding prefix and suffix, and generate a corresponding partial matching table; A radix tree trie is used to index the partial match table corresponding to each instruction name or sub-pattern in the instruction set array to speed up the query and access of the partial match table; The partial match table and radix tree trie index corresponding to each instruction name or sub-pattern in the instruction set array are combined into a complete partial match table data structure PMT.
4. The EC debugging method based on serial port instructions according to claim 3 is characterized in that: The received complete instruction data is used as the main string, and the instruction name in the instruction set array is used as the pattern string. The main string and the pattern string are filtered using a hash algorithm, including: Using the Rolling Hash algorithm, a sliding window of size L is constructed on the main string, where L is the average length of the pattern string in the instruction set array; The Rolling Hash algorithm uses a polynomial hash function to complete the incremental update of the hash value of the substring in the sliding window in constant time. The polynomial hash function maps the string to the prime field and uses Horner's rule to merge new characters and eliminate the influence of old characters on the hash value. Determine whether the hash value of the substring in the sliding window is equal to the hash value of the pattern string. If they are equal, the corresponding substring and pattern string are taken as candidate matching pairs.
5. The EC debugging method based on serial port instructions according to claim 4 is characterized in that: S3, the EC end determines whether the command data has been received through the serial port interrupt mechanism, including: The serial port receiving pin on the EC side receives the serial data bit stream and converts it into parallel data bytes and stores it in the serial port receiving buffer; The serial port controller determines whether the data in the receiving buffer meets the length of a complete data frame according to the preset data frame format; When the data length in the receiving buffer meets the complete data frame length, the serial port controller sends a receiving completion interrupt request to the interrupt controller on the EC side; the interrupt controller responds to the receiving completion interrupt request and triggers the interrupt service routine on the EC side; If the length of the data in the receiving buffer is less than a complete data frame, the serial port controller continues to receive subsequent bytes until the complete data frame length is met.
6. The EC debugging method based on serial port instructions according to any one of claims 2 to 5, characterized in that: S2, the debugging device sends command data to the EC end through the serial port, including: S21, the debugging device generates a complete debugging instruction according to a predetermined instruction format. The debugging instruction is in frames and adopts a frame format of frame header + instruction type + data length + instruction content + frame tail + CRC check; wherein the frame header is used to identify the beginning of a frame of instructions, the frame tail is used to identify the end of a frame of instructions, the instruction type is used to identify the function of the instruction, the data length is used to identify the length of the instruction data, the instruction content is specific instruction data, and the CRC check is used to verify the correctness of the entire frame of data; S22, the debugging device writes the generated debugging instruction into the sending buffer of the serial port controller, and sends the instruction data through the serial port controller; wherein the serial port controller includes a data register, a status register and an interrupt enable register; S23, the serial port controller converts the parallel command data in the sending buffer into a serial bit stream and sends it through the TX pin; S24, after sending a frame of debugging instructions, the serial port controller clears the send enable bit and triggers the send completion interrupt.
7. The EC debugging method based on serial port instructions according to claim 6, characterized in that: S22, the debugging device writes the generated debugging instruction into the sending buffer of the serial port controller, and sends the instruction data through the serial port controller, including: By reading the status register of the serial port controller, the idle state of the send buffer is determined; Enable the send completion interrupt by setting the interrupt enable register; When the status register indicates that the transmit buffer is idle and the transmit completion interrupt is enabled in the interrupt enable register, each byte of the debug command frame is sequentially written into the data register of the serial port controller and stored into the transmit buffer via the parallel bus; After each byte is written, the status register is read to obtain the update status and remaining status of the send buffer to prevent buffer overflow; When all bytes of a frame of debugging instructions are written into the data register, a valid value is written into the transmit enable bit of the control register to start the parallel-to-serial conversion and transmission circuit of the serial port controller.
8. The EC debugging method based on serial port instructions according to claim 7, characterized in that: S24, after sending a frame of debugging instructions, the serial port controller clears the send enable bit and triggers the send completion interrupt, including: After the serial port controller sends the last bit of a frame, it clears the transmit enable bit in the control register and turns off the parallel-to-serial conversion and transmission circuits; The debugging device responds to the sending completion interrupt in an interrupt-driven manner and stops the sending timeout timer of the corresponding frame; by reading multiple status flags of the serial port controller, it is determined whether the sending process of the frame instruction is completed normally; wherein the status flags include the sending status bit and the sending error bit in the status register, the sending timeout event bit in the interrupt time register, and the overflow flag of the sending timeout timer; If the sending status bit of the status register indicates that the sending is completed normally, and the sending error bit, the sending timeout event bit and the timeout timer overflow flag are not set, it is judged that the sending of this frame instruction is successful; the debugging device records the sending completion time of the command of this frame, deletes the instruction from the sending queue, and records the deletion event in the debugging log; otherwise, it is judged that the sending of this frame instruction fails, and it is marked as sending failure in the sending queue; The debug device sampling scheduler manages the send queue based on priority and timestamp.
9. The EC debugging method based on serial port instructions according to claim 8, characterized in that: The debug device samples the priority and timestamp-based scheduling algorithm to manage the send queue, including: The debugging device associates a priority and a timestamp with each instruction in the sending queue. The priority is used to indicate the importance of the instruction, and the timestamp is used to record the time when the instruction was queued or the last time it was sent. The debugger periodically scans the transmit queue and for each instruction that has been sent but not yet acknowledged: Compare the current time with the timestamp of the instruction and calculate the waiting time of the instruction in the queue; If the waiting time of the instruction exceeds the set timeout threshold and the number of retransmissions has not reached the maximum limit, the corresponding instruction will be marked as sending timeout, the timestamp of the corresponding instruction will be updated to the current time, the number of retransmissions will be increased by 1, and the corresponding instruction will be reinserted into the sending queue; If the waiting time of the instruction exceeds the set timeout threshold and the number of retransmissions has reached the maximum limit, the corresponding instruction will be removed from the sending queue, the removal event and instruction content will be reported, and recorded in the debug log; The debugging device inserts the newly added instructions to be sent into the sending queue according to the priority.
10. The EC debugging method based on serial port instructions according to claim 9, characterized in that: Debug device sampling based on priority and timestamp scheduling algorithm to manage the send queue, including: The debugging device selects the earliest instruction to be sent from the sending queue as the next frame based on the current time: Scan the sending queue to find the instruction with the highest priority and the earliest timestamp. If the corresponding instruction has not timed out, send the obtained instruction as the next frame. If the obtained instruction has timed out, return to perform timeout processing and rescan the queue until an instruction that has not timed out is obtained and sent as the next frame.
Citation Information
Patent Citations
Method for inputting printing debugging information based on serial ports and device
CN103345370A
FPGA-based universal asynchronous serial port and response method thereof
CN108197042A