Controller communication method, electronic device, storage medium and computer program product
By introducing a second processor into the processor, indirectly transmitting data to the UART controller, the problem of insufficient security in the controller driver in the kernel is solved, the risk of exposure to the UART controller hardware design is reduced, and the security is enhanced.
Patent Information
- Application Number
- CN202411139093.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-19
- Publication Date
- 2024-11-22
AI Technical Summary
The security of the controller driver is set in the kernel is poor, which easily exposes the controller hardware design, especially when the kernel or processor is compromised.
By introducing a second processor into the processor, communicating with the first processor, the data to be sent is indirectly transmitted to the UART controller, avoiding the first processor to directly transmit the data, thereby reducing the exposure risk of the UART controller hardware design.
Even if the kernel space or the first processor is compromised, the UART controller hardware design will not be leaked, reducing the risk of UART controller hardware design exposure and enhancing security.
Smart Images

Figure CN119003393A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of chips, specifically, to processor technology in the field of chips, and more specifically, to a communication method of a controller, an electronic device, a storage medium, and a computer program product. Background Art
[0002] With the rapid development of information technology, chip technology has become the core of modern electronic devices. As a key component in the chip, the controller driver needs to implement corresponding hardware access operations for different types of controller hardware. In order to ensure that the controller driver can smoothly manage, control and communicate with the corresponding controller hardware, the driving logic of the controller driver needs to be compatible with the design of the controller hardware.
[0003] However, the controller driver is usually set in the kernel (for example, the Linux kernel), which has poor security. Once the kernel or the corresponding hardware processor is hacked, the design of the controller hardware will be exposed. Summary of the invention
[0004] In order to solve the above technical problems, the present application provides a communication method, electronic device, storage medium and computer program product of a controller to achieve the purpose of reducing the exposure risk of controller hardware design.
[0005] To achieve the above technical objectives, the present application provides the following technical solutions:
[0006] In a first aspect, an embodiment of the present application provides a communication method of a controller, which is applied to a first processor, wherein the first processor is communicatively connected to a second processor, and the second processor is communicatively connected to a UART controller, and the method includes: obtaining data to be sent in response to a user request; transmitting the data to be sent to the second processor, so that the second processor transmits the data to be sent to the UART controller.
[0007] In the second aspect, an embodiment of the present application provides a communication method of a controller, which is applied to a second processor, and the second processor is communicatively connected to the first processor and the UART controller respectively. The method includes: obtaining data to be sent from the first processor, wherein the data to be sent is data obtained by the first processor in response to a user request; and transmitting the data to be sent to the UART controller.
[0008] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a first processor and a second processor that are communicatively connected to each other; wherein the first processor is configured to execute the communication method of the controller as described in the first aspect; and the second processor is configured to execute the communication method of the controller as described in the second aspect.
[0009] In a fourth aspect, an embodiment of the present application provides a storage medium having a computer program stored thereon. When the computer program is executed by a processor, the communication method of the controller as described in the first aspect or the second aspect is implemented.
[0010] In a fifth aspect, an embodiment of the present application provides a computer program product, on which a computer program is stored. When the computer program is executed by a processor, the communication method of the controller as described in the first aspect or the second aspect is implemented.
[0011] The controller communication method provided in the embodiment of the present application can be applied to the first processor. When responding to a user request, the first processor no longer directly transmits data to the UART controller, but first transmits the data to be sent to the second processor, and then transmits the data to be sent to the UART controller through the second processor. In this way, even if the kernel space or the first processor is hacked, the design of the UART controller hardware will not be leaked, reducing the risk of exposure of the UART controller hardware design. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0013] Figure 1 One of the schematic diagrams of feasible application scenarios of a communication method of a controller provided in an embodiment of the present application;
[0014] Figure 2 One of the flowcharts of a communication method of a controller provided in an embodiment of the present application;
[0015] Figure 3 One of the practical application flow diagrams of a controller communication method provided in an embodiment of the present application;
[0016] Figure 4 A second schematic diagram of a practical application flow of a communication method of a controller provided in an embodiment of the present application;
[0017] Figure 5 A schematic diagram of a process flow for processing data to be received provided in an embodiment of the present application;
[0018] Figure 6 A second flowchart of a communication method of a controller provided in an embodiment of the present application;
[0019] Figure 7 A second schematic diagram of a feasible application scenario of a communication method of a controller provided in an embodiment of the present application;
[0020] Figure 8 A third schematic diagram of a feasible application scenario of a communication method of a controller provided in an embodiment of the present application;
[0021] Fig. 9 One of the structural block diagrams of a communication device of a controller provided in an embodiment of the present application;
[0022] Fig.10 A second structural block diagram of a communication device of a controller provided in an embodiment of the present application;
[0023] Fig.11 A schematic diagram of the structure of an electronic device provided for one embodiment of the present application. DETAILED DESCRIPTION
[0024] Unless otherwise defined, the technical terms or scientific terms used in the embodiments of this specification shall have the common meanings understood by persons with ordinary skills in the field to which this specification belongs. The words "first", "second" and similar words used in the embodiments of this specification do not indicate any order, quantity or importance, but are only used to avoid confusion of constituent elements.
[0025] Unless the context requires otherwise, throughout the specification, "plurality" means "at least two", and "including" is interpreted as an open, inclusive meaning, that is, "including, but not limited to". In the description of the specification, the terms "one embodiment", "some embodiments", "exemplary embodiments", "examples", "specific examples" or "some examples" are intended to indicate that a particular feature, structure, material or characteristic associated with the embodiment or example is included in at least one embodiment or example of the specification. The schematic representation of the above terms does not necessarily refer to the same embodiment or example.
[0026] The following will be combined with the drawings in the embodiments of this specification to clearly and completely describe the technical solutions in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this specification.
[0027] Overview
[0028] As described in the background technology, the controller driver is usually set in the kernel (for example, the Linux kernel). Since the exposure of the driver logic will directly lead to the exposure of the controller hardware design, it is necessary to enhance the security of the controller driver or the hardware processor in which it is located.
[0029] At present, in order to ensure the security of the processor core, technical personnel in this field have developed a number of technologies, such as ARM's TrustZone technology, which provides a hardware-level security isolation by implementing two execution environments, secure and non-secure, on the processor core. Although these technologies have improved the security of the processor core, the implementation process is complicated and may also reduce the processing efficiency of the processor. In addition, the services and functions involved in the processor core are diverse, and the management and control of the controller only accounts for a small part of them. When considering how to improve the security of the processor core, all services and functions involved in the processor core need to be taken into account, which makes the research and development process of related security technologies very complicated.
[0030] In view of the above-mentioned technical status, the inventor of this application does not focus on how to improve the security of the processor core. Instead, he takes a different approach and considers how to avoid the direct exposure of the controller hardware design when the processor core is hacked. Based on the above considerations, the inventor thought of adding a core or processor, and the first processor first interacts with the newly added core or processor, and then interacts with the controller through the newly added core or processor. Furthermore, the inventor proposed a communication method for a controller, in which, in response to a user request, the first processor no longer directly transmits data to the UART controller, but first transmits the data to be sent to the second processor, and transmits the data to be sent to the UART controller through the second processor. In this way, even if the kernel space or the first processor is hacked, the design of the UART controller hardware will not be leaked, reducing the risk of exposure of the UART controller hardware design.
[0031] Example scenarios
[0032] The technical solution proposed in the embodiment of the present application is applicable to the scenario of driving the controller to operate. For ease of understanding, feasible application scenarios of the communication method of the controller are provided here. For example Figure 1 As shown, the system architecture in this application scenario can rely on UART (Universal Asynchronous Receiver / Transmitter) and Serial framework to realize serial communication. The system architecture can include: user space, kernel space, second processor and hardware.
[0033] Wherein, user space is User Space, which provides an execution environment for application program, and application program is loaded, runs in this environment, and interacts with other parts of operating system.In the embodiment of the present application, user can utilize the serial port setting 101 of user space to realize the relevant setting of serial port.For example, to open the serial port, the corresponding serial port node can be opened by open() function.Relevant parameters such as serial port baud rate can be set using methods such as stty tool.
[0034] The kernel space is Kernel Space, which is responsible for managing system resources, scheduling processes, handling interrupts and exceptions, etc., which will not be described in detail here. It can be understood that the kernel space can transmit the to-be-sent data that needs to be sent to the following hardware part controller 104 to the second processor through the data transmission interface 102, and can also obtain the to-be-received data from the controller 104 from the second processor.
[0035] The above-mentioned application space and kernel space are located in the hardware processor. The hardware processor here can be a main processor in a multi-processor architecture, for example, an ARM processor. For ease of description in this specification, the hardware processor or main processor is described as a first processor. The second processor is different from the first processor, as another core that can communicate between cores with the first processor. An operating system 103 runs in the second processor, and the operating system 103 can be, for example, a real-time operating system (Real Time Operating System, referred to as RTOS), but is not limited to this. The second processor can transmit relevant data between the data transmission interface 102 and the controller 104.
[0036] The hardware includes, but is not limited to, the controller 104 , and the controller 104 may be, for example, a UART controller.
[0037] Exemplary Methods
[0038] The present application embodiment provides a controller communication method, which can be applied to a first processor, wherein the first processor is connected to a second processor for communication, and the second processor is connected to a UART controller for communication. Figure 1 The kernel space shown implements the following operations S201 to S202. The second processor is another core different from the first processor, and the second processor can implement inter-core communication with the first processor. For example, the second processor can be an input-output processor. For example, a real-time operating system (RTOS) can be run on the input-output processor.
[0039] like Figure 2As shown, the communication method of the controller may include:
[0040] S201: Responding to a user request, obtaining data to be sent.
[0041] In this step, the user request can be a request or a serial port request triggered by the user that needs to transfer data to the UART controller. The data to be sent is the data that needs to be transmitted to the UART controller. For example, after the serial port setting is completed in the user space, a communication request (equivalent to a user request) is generated. At the same time, in order to ensure that the communication proceeds smoothly, the communication configuration parameters or the parameters that the UART controller needs to be configured (such as baud rate, data bit, stop bit, and parity information, etc.) can be used as data to be sent.
[0042] S202: Transmit the data to be sent to the second processor, so that the second processor transmits the data to be sent to the UART controller.
[0043] It should be noted that the first processor and the second processor can realize data interaction through inter-core communication. In the embodiment of the present application, the second processor directly communicates with the UART controller. The first processor only needs to transfer the data to be sent to the second processor. In this way, the controller driving logic is no longer retained on the first processor side. Even if the first processor is hacked and exposed, the design of the UART controller will not be exposed.
[0044] In the embodiment of the present application, it can be applied to the first processor. When responding to a user request, the first processor no longer directly transmits data to the UART controller, but first transmits the data to be sent to the second processor, and then transmits the data to be sent to the UART controller through the second processor. In this way, even if the kernel space or the first processor is compromised, the design of the UART controller hardware will not be leaked, reducing the risk of exposure of the UART controller hardware design.
[0045] In some embodiments of the present application, the second processor includes: a processing module, a storage module and an interrupt module respectively communicatively connected to the processing module and the first processor, wherein the storage module includes a target shared space accessible to both the first processor and the processing module;
[0046] The method transmits the data to be sent to the second processor, comprising:
[0047] The data to be sent is stored in the target shared space of the storage module;
[0048] The first interrupt is triggered by the interrupt module to notify the processing module to transmit the to-be-sent data in the target shared space to the UART controller.
[0049] It should be noted that the second processor can transmit the data to be sent to the UART controller through the cooperation between the processing module, the storage module and the interrupt module. The processing module has a data processing function. For example, the processing module can be a RISC-V processor, and a real-time operating system can be run in the RISC-V processor. The processing module and the first processor are both connected to the storage module and the interrupt module. Thus, the first processor can store the data to be sent in the target shared space of the storage module, the processing module can access the target shared space, and transmit the data to be sent to the UART controller. The first processor can trigger the first interrupt through the interrupt module, the processing module can receive the first interrupt, and transmit the data to be sent in the target shared space to the UART controller in response to the first interrupt.
[0050] The first interrupt may be any type of interrupt, for example, a security interrupt with higher security, but is not limited thereto. It is understandable that both the first processor and the second processor may trigger an interrupt, and the functions of the interrupts triggered by the two are different. In some embodiments, the information carried by the interrupt triggered by the first processor includes direction information from the first processor to the second processor. The information carried by the interrupt triggered by the second processor includes direction information from the second processor to the first processor.
[0051] In the embodiment of the present application, the shared memory and the interrupt mechanism cooperate with each other, so that the data to be sent can be transmitted to the second processor in a timely manner.
[0052] In some embodiments of the present application, transmitting the data to be sent to the second processor includes:
[0053] According to the available storage space of the message buffer in the target structure, the data to be sent is filled into the message buffer to generate structure information; when the proportion of the data to be sent in the available storage space reaches a first proportion, the structure information is transmitted to the second processor.
[0054] It should be noted that in the asynchronous transmission scenario of serial port data, the current driver can only transmit data with a fixed length, and the data length cannot be processed efficiently. At the same time, when the current serial port driver uses the FIFO (First In First Out) method to operate single-byte data, the interrupt is triggered more frequently, which is too frequent for the first processor, thereby affecting the services of other peripherals or hardware. For this reason, when transmitting data to the UART controller through the second processor, the number of data transmissions can be reduced as much as possible to increase the amount of data transmitted in a single time.
[0055] In this embodiment, the target structure can be understood as a communication protocol between the first processor and the second processor. Among them, the target structure includes a message buffer, which is used to store data to be sent. The storage space of the message buffer can be, for example, the size of the message buffer. The first proportion is a predetermined proportion with a higher value. It can be understood that if there is too much data in the message buffer, that is, the proportion of data in the storage space of the message buffer is too large, problems such as overflow may occur. Therefore, usually the first proportion is close to 100%, for example, the first proportion can be 80%, and the first proportion can also be 90%, but is not limited to this.
[0056] For example Figure 3 As shown, the communication method of the controller provided in this embodiment may include:
[0057] S301: Drive the data transmission interface to obtain data to be transmitted.
[0058] S302: Fill the data to be sent into the message buffer of the target structure to generate structure information;
[0059] S303: Determine whether the proportion of the data to be sent filled in the message buffer reaches a first proportion, and if so, execute S304.
[0060] S304: directly sending the structure information to the second processor.
[0061] It is understandable that when the amount of data to be sent is large, one structure information cannot carry all the data to be sent. Then, the data to be sent can be filled into the target structure in batches, thereby generating multiple structure information, and the generated multiple structure information are sent to the second processor. Limited by the original system framework, the amount of data that can be processed by each serial port communication is currently: 16*16=256 bytes. When using the method provided by the present application, the amount of data that can be processed by each serial port communication can be, for example, 20*128=2560 bytes.
[0062] In the embodiment of the present application, the message buffer of the target structure is used to carry the data to be sent. By reasonably setting the size of the message buffer, the data transmission efficiency can be improved; at the same time, the disturbance of the UART controller to the first processor can be reduced.
[0063] In order to avoid the situation where the amount of data to be sent is too small and the structure information cannot be sent successfully, in some embodiments of the present application, after generating the structure information, the method further includes:
[0064] When the waiting time reaches the target time and the proportion of the data to be sent in the storable space does not reach the first proportion, the structure information is transmitted to the second processor; wherein the waiting time is the time from generating the structure information to transmitting the structure information.
[0065] It should be noted that the target duration may be a pre-set reasonable duration. Even if the amount of data to be sent is too small and its proportion in the storage space of the message buffer cannot reach the first proportion, the structure information can be successfully sent to the second processor after the target duration. Figure 3 For example, when determining whether the proportion of the data to be sent filled in the message buffer reaches the first proportion, if not, S305 is executed to send the structure information to the second processor after waiting for timeout, wherein the timeout duration is the target duration.
[0066] In the embodiment of the present application, when the amount of data to be sent is too small and its proportion in the storable space of the message buffer cannot reach the first proportion, the structure information can still be successfully sent to ensure the smooth transmission of the data to be sent.
[0067] In order to balance resource utilization and transmission efficiency of data to be sent, in some embodiments of the present application, the method further includes:
[0068] When the number of consecutive occurrences of the first situation reaches a first number threshold, the message buffer is increased; wherein the first situation includes: the proportion of the data to be sent in the storable space is greater than or equal to a first proportion.
[0069] It should be noted that, when the amount of data to be sent is large enough (for example, the amount of data to be sent is greater than the size of the first proportion of the message buffer), after increasing the message buffer, a structure information can carry more information, thereby improving the transmission efficiency of the data to be sent. For example, the amount of data to be sent is 600 bytes, and the size of the first proportion of the message buffer is 128 bytes. Then, 5 pieces of structure information are needed to transfer all the data to be sent to the second processor. Assuming that the message buffer is increased, at this time, the size of the first proportion of the message buffer is 256 bytes. Then only 3 pieces of structure information need to be sent to transfer all the data to be sent to the second processor.
[0070] However, the amount of data to be sent is usually not fixed. If the message buffer is enlarged blindly, it will inevitably cause a waste of resources when the amount of data to be sent is small. Therefore, it is necessary to reasonably adjust the size of the message buffer, that is, choose a reasonable time to increase the size of the message buffer. For example Figure 4 As shown, in Figure 3On the basis of, S406, data length scheduling, can be added before or after S302 to increase the message buffer when appropriate conditions are met. For example, the filling status of the message buffer in the structural information (the proportion of the data to be sent in the storable space in the message buffer) during the current and previous transmissions of the data to be sent can be stored. If for several consecutive times, the proportion of the data to be sent in the storable space is greater than or equal to the first proportion, it is considered that the message buffer has been filled up multiple times, and the message buffer must be increased at this time. Regarding the number of times the message buffer is filled up, that is, the first number threshold, it can be a pre-set number of times with a smaller value, for example, the first number threshold can be 3 times, but is not limited to this.
[0071] In the embodiment of the present application, the resource utilization rate and the transmission efficiency of the data to be sent can be balanced, thereby reducing the waste of resources while maximizing the transmission efficiency of the data to be sent.
[0072] In order to balance resource utilization and transmission efficiency of data to be sent, in some embodiments of the present application, the method further includes:
[0073] When the number of consecutive occurrences of the second situation reaches a second number threshold, the message buffer is reduced; wherein the second situation includes: the proportion of the data to be sent in the storable space is less than or equal to the second proportion.
[0074] It should be noted that, when the amount of data to be sent is small (for example, the amount of data to be sent is smaller than the size of the second proportion of the message buffer), increasing the message buffer will undoubtedly cause a waste of resources.
[0075] However, the amount of data to be sent is usually not fixed. If the message buffer is reduced blindly, the transmission efficiency of the data to be sent will inevitably be reduced when the amount of data to be sent is large. Therefore, it is necessary to reasonably adjust the size of the message buffer, that is, choose a reasonable time to reduce the size of the message buffer. For example Figure 4 As shown, when executing S406 data length scheduling, the message buffer can be reduced when another suitable condition is met. For example, the filling situation of the message buffer in the structural information (the proportion of the data to be sent in the storable space in the message buffer) can be stored during the current and previous transmissions of the data to be sent. If the proportion of the data to be sent in the storable space is less than or equal to the second proportion for several consecutive times, it is regarded as that the message buffer is not filled up for many times, and the message buffer needs to be reduced at this time. Among them, the second proportion is less than or equal to the first proportion. For example, the second proportion can be a proportion of a smaller value, such as 1 / 2, but is not limited to this. Regarding the number of times the message buffer is not filled up, that is, the second number threshold, it can be a pre-set number of times with a smaller value, for example, the second number threshold can be 4 times, but is not limited to this.
[0076] In the embodiment of the present application, the resource utilization rate and the transmission efficiency of the data to be sent can be balanced, and the impact on the transmission efficiency of the data to be sent can be reduced while the resource utilization rate is improved as much as possible.
[0077] In order to balance resource utilization and transmission efficiency of data to be sent, in some embodiments of the present application, the method also includes: when the number of consecutive occurrences of the first situation reaches a first number threshold, increasing the target duration; wherein the first situation includes: the proportion of data to be sent in the storable space is greater than or equal to a first proportion.
[0078] It should be noted that for the relevant description of the first situation, please refer to the relevant description of the above embodiment, which will not be repeated here. It is understandable that when the amount of data to be sent is large enough (for example, the amount of data to be sent is greater than the size of the first proportion of the message buffer), the target duration can be increased / extended, thereby giving the first processor enough time to fill more data to be sent into the message buffer, thereby improving the transmission efficiency of the data to be sent. Figure 4 As shown, when executing S406 data length scheduling, the target duration can be increased / extended when another suitable condition is met. For example, the filling situation of the message buffer in the structure information (the proportion of the data to be sent in the storable space in the message buffer) can be stored in the process of transmitting the data to be sent for this time and the previous several times. If the proportion of the data to be sent in the storable space is greater than or equal to the first proportion for several consecutive times, it is regarded as filling up the message buffer for many times, and the target duration will be increased / extended at this time. About the number of times the message buffer is filled up, that is, the first number threshold, it can be a pre-set number of times with a smaller value, for example, the first number threshold can be 3 times, but is not limited to this.
[0079] In the embodiment of the present application, the resource utilization rate and the transmission efficiency of the data to be sent can be balanced, thereby reducing the waste of resources while maximizing the transmission efficiency of the data to be sent.
[0080] In order to control the size of the target duration and the transmission efficiency of the data to be sent, in some embodiments of the present application, the method also includes: reducing the target duration when the number of consecutive occurrences of the second situation reaches a second number threshold; wherein the second situation includes: the proportion of the data to be sent in the available storage space is less than or equal to the second proportion.
[0081] It should be noted that for the relevant description of the second situation, please refer to the relevant description of the above embodiment, which will not be repeated here. It is understandable that when the amount of data to be sent is small (for example, the amount of data to be sent is smaller than the size of the second proportion of the message buffer), the target duration can be reduced to avoid the first processor from waiting too long after filling all the data to be sent into the message buffer. Figure 4 As shown, when executing S406 data length scheduling, the target duration can be reduced when another suitable condition is met. For example, the filling status of the message buffer in the structure information (the proportion of the data to be sent in the storable space in the message buffer) can be stored during the current and previous transmissions of the data to be sent. If the proportion of the data to be sent in the storable space is less than or equal to the second proportion for several consecutive times, it is regarded as that the message buffer is not filled up for many times, and the target duration will be reduced at this time. Among them, the second proportion is less than or equal to the first proportion. For example, the second proportion can be a proportion of a smaller value, such as 1 / 2, but is not limited to this. Regarding the number of times the message buffer is not filled up, that is, the second number threshold, it can be a pre-set number of times with a smaller value, for example, the second number threshold can be 4 times, but is not limited to this.
[0082] In the embodiment of the present application, the resource utilization and the transmission efficiency of the data to be sent can be balanced, and the waiting time of the first processor can be reduced while trying not to affect the transmission efficiency of the data to be sent.
[0083] In some embodiments of the present application, after transmitting the data to be sent to the second processor, the method further includes:
[0084] The acquisition processing module transmits the to-be-received data from the UART controller to the target shared space.
[0085] It should be noted that the process of acquiring the data to be received is similar to the process of transmitting the data to be sent to the UART controller in the above embodiments, except that the data transmission directions of the two are different.
[0086] For example Figure 5 As shown, after the second processor stores the data to be received in the target shared space, it triggers an interrupt from the second processor to the first processor. The first processor drives the interrupt processing through S501, parses and identifies the interrupt information. Then it executes S502 to drive the receiving data interface to obtain the data to be received from the target shared space. In addition, the first processor will also execute S503 to schedule the data length. Among them, the data length scheduling process is the same as Figure 4 The data length scheduling process in S406 is similar and will not be described here in detail. It should be noted that in this embodiment, after adjusting the message buffer and the target duration, the adjusted data is synchronized to the second processor.
[0087] In the embodiment of the present application, the data to be received can be obtained from the second processor, thereby realizing data interaction between the first processor and the UART controller.
[0088] The present application embodiment provides a communication method of a controller, and the communication method of the controller can be applied to a second processor, and the second processor is respectively connected to the first processor and the UART controller. Wherein, the first processor, the second processor, and the UART controller can refer to the relevant description of the first processor, the second processor, and the UART controller in the above embodiment, which will not be repeated here. For example, the second processor can be an input and output processor.
[0089] like Figure 6 As shown, the communication method of the controller may include:
[0090] S601: Acquire data to be sent from a first processor, wherein the data to be sent is data acquired by the first processor in response to a user request;
[0091] S602: Transmit the data to be sent to the UART controller.
[0092] It should be noted that for the feasible execution methods of step S601 and step S602 and the possible beneficial effects, please refer to the relevant description above, and the embodiments of the present application will not be elaborated here.
[0093] In the embodiment of the present application, in response to a user request, the first processor no longer directly transmits data to the UART controller, but first transmits the data to be sent to the second processor, and then transmits the data to be sent to the UART controller by the second processor. In this way, even if the kernel space or the first processor is compromised, the design of the UART controller hardware will not be leaked, reducing the risk of exposure of the UART controller hardware design.
[0094] In some embodiments of the present application, the second processor includes: a processing module, a storage module and an interrupt module respectively connected to the processing module and the first processor in communication, wherein the storage module includes a target shared space accessible to both the first processor and the processing module; obtaining the data to be sent from the first processor includes: receiving the data to be sent through the target shared space of the storage module;
[0095] The method transmits the data to be sent to the UART controller, comprising: triggering a first interruption through an interruption module; and transmitting the data to be sent in the target shared space to the UART controller through a processing module when the first interruption is received.
[0096] It should be noted that the second processor can receive the data to be sent in the first processor through the cooperation between the processing module, the storage module and the interrupt module, and can also transmit the data to be sent to the UART controller. The processing module has a data processing function. For example, the processing module can be a RISC-V processor, and a real-time operating system can be run in the RISC-V processor. The processing module and the first processor are both connected to the storage module and the interrupt module. Thus, the first processor can store the data to be sent in the target shared space of the storage module, the processing module can access the target shared space, and transmit the data to be sent to the UART controller. The first processor can trigger the first interrupt through the interrupt module, the processing module can receive the first interrupt, and transmit the data to be sent in the target shared space to the UART controller in response to the first interrupt.
[0097] The first interruption may be, for example, an interruption triggered by the first processor. The content of the first interruption may refer to the relevant description of the first interruption in the above embodiment, which will not be repeated here.
[0098] In the embodiment of the present application, the shared memory and the interrupt mechanism cooperate with each other, so that the data to be sent can be transmitted to the second processor in a timely manner.
[0099] In some embodiments of the present application, transmitting the data to be sent in the target shared space to the UART controller includes:
[0100] Determine the interrupt type of the first interrupt; wherein the interrupt type is associated with the situation that triggers the first interrupt; apply for a DMA channel of corresponding width based on the interrupt type of the first interrupt; drive the DMA controller to transfer the data to be sent from the target shared space to the UART controller through the applied DMA channel.
[0101] It should be noted that the interrupt types include: the first type that triggers the first interrupt in the third case and the second type that triggers the first interrupt in the fourth case. The third case includes: the proportion of the data to be sent in the storable space reaches the first proportion; the fourth case includes: the waiting time reaches the target time, and the proportion of the data to be sent in the storable space does not reach the second proportion, and the waiting time is the time from generating the structure information to transmitting the structure information to the second processor. The third case is equivalent to the first case in the above embodiment, and the fourth case is equivalent to the second case in the above embodiment, which will not be repeated here. In some embodiments, the width of the DMA channel corresponding to the first type is greater than the width of the DMA channel corresponding to the second type.
[0102] For example Figure 7As shown, after the second processor transfers the data to be sent to the shared memory 701, the second processor side interrupt (the first processor points to the second processor) is triggered by the interrupt-sending module 702. The real-time operating system 703 is based on the interrupt type, and applies for a DMA channel to the DMA engine 704 based on the interrupt type. Wherein, about the interrupt type and the process of applying for a DMA channel, it can be seen from the aforementioned related content, which will not be repeated here. After successfully applying for a DMA channel, the DMA engine 704 will read the data to be sent from the shared memory 701 and transfer it to the UART controller, such as the UART-sending module 705 in the figure.
[0103] Wherein, the second processor can be a processor composed of a processing module, a storage module and an interrupt module in the aforementioned embodiment. The real-time operating system 703 can run in the processing module, the shared memory 701 can be the target shared space of the storage module, and the interrupt-sending module can be the interrupt module, which will not be described in detail here. In some embodiments, the shared memory 701 can be cleared when initialized. For example, the shared memory 701 can be 4-byte aligned. The interrupt-sending module 702 mainly stores a set of registers for managing the shared memory 701, each instruction type, including but not limited to: a count register, an interrupt status register, a custom register, etc.
[0104] In the embodiment of the present application, DMA channels of different widths can be applied for based on the interrupt type to transmit the data to be sent in a targeted manner, thereby reducing the number of interrupts.
[0105] In some embodiments of the present application, after transmitting the data to be sent in the target shared space to the UART controller, the method further includes:
[0106] The processing module transmits the data to be received in the UART controller to the target shared space;
[0107] The second interrupt is triggered by the interrupt module to notify the first processor to obtain the to-be-received data in the target shared space.
[0108] It should be noted that the process of obtaining the data to be received and transmitting it to the first processor in this embodiment is a data processing process in the opposite direction to the process of obtaining the data to be sent and transmitting it to the UART controller in the above embodiment.
[0109] For example Figure 8As shown, the UART-transmitting module 806 notifies the real-time operating system 703 through the serial port receiving interrupt to apply for a DMA channel again from the DMA engine 704. In addition, the DMA engine 704 will obtain the data to be received from the UART-transmitting module 806, and use the successfully applied DMA channel to transfer the data to be received to the shared memory 701. The real-time operating system 703 uses the interrupt-receiving module 807 to trigger a kernel-side interrupt to notify the first processor to obtain the data to be received from the shared memory 701, thereby realizing the transmission of the data to be received from the UART controller to the first processor.
[0110] Among them, the interrupt-receiving module 807 is similar to the interrupt-transmitting module 702, and the UART-receiving module 806 is a component unit of the UART controller, which is different from the UART-transmitting module 705. For example, the UART-receiving module 806 can be a UART-RX-FIFO, and the UART-transmitting module 705 can be a UART-TX-FIFO.
[0111] In the embodiment of the present application, data interaction between the first processor and the UART controller can be achieved.
[0112] Exemplary Devices
[0113] Some embodiments of the present application also provide a communication device of a controller, which is applied to a first processor, the first processor is connected to a second processor for communication, and the second processor is connected to a UART controller for communication, such as Fig. 9 As shown, the communication device of the controller includes:
[0114] The response module 901 obtains the data to be sent in response to the user request;
[0115] The sending module 902 transmits the data to be sent to the second processor, so that the second processor transmits the data to be sent to the UART controller.
[0116] In some embodiments, the second processor includes: a processing module, a storage module and an interrupt module respectively connected to the processing module and the first processor for communication, wherein the storage module includes a target shared space accessible to both the first processor and the processing module; a sending module 902, including: a sending unit, used to store the data to be sent in the target shared space of the storage module; an interrupt unit, used to trigger a first interrupt through the interrupt module to notify the processing module to transmit the data to be sent in the target shared space to the UART controller.
[0117] The sending module 902 includes: a structure unit, which is used to fill the data to be sent into the message buffer according to the available storage space of the message buffer in the target structure to generate structure information; a first sending unit, which is used to transmit the structure information to the second processor when the proportion of the data to be sent in the available storage space reaches a first proportion.
[0118] In some embodiments, the device also includes: a second sending unit, used to transmit the structure information to the second processor when the waiting time reaches the target time and the proportion of the data to be sent in the storage space does not reach the first proportion; wherein the waiting time is the time from generating the structure information to transmitting the structure information.
[0119] In some embodiments, the device also includes: a first adjustment module, used to increase the message buffer when the number of consecutive occurrences of the first situation reaches a first number threshold; wherein the first situation includes: the proportion of the data to be sent in the storable space is greater than or equal to the first proportion.
[0120] In some embodiments, the device also includes: a second adjustment module, used to reduce the message buffer when the number of consecutive occurrences of the second situation reaches a second number threshold; wherein the second situation includes: the proportion of the data to be sent in the storable space is less than or equal to the second proportion.
[0121] In some embodiments, the device also includes: a third adjustment module, used to increase the target duration when the number of consecutive occurrences of the first situation reaches a first number threshold; wherein the first situation includes: the proportion of the data to be sent in the storable space is greater than or equal to the first proportion.
[0122] In some embodiments, the device also includes: a fourth adjustment module, used to reduce the target duration when the number of consecutive occurrences of the second situation reaches a second number threshold; wherein the second situation includes: the proportion of the data to be sent in the storable space is less than or equal to the second proportion.
[0123] In some embodiments, the apparatus further comprises:
[0124] The receiving data processing module is used to obtain the to-be-received data transmitted by the processing module from the UART controller to the target shared space.
[0125] Some embodiments of the present application also provide a communication device of a controller, which is applied to a second processor, and the second processor is respectively connected to the first processor and the UART controller for communication, such as Fig.10 As shown, the communication device of the controller includes:
[0126] An acquisition module 1001 is used to acquire data to be sent from the first processor, wherein the data to be sent is data acquired by the first processor in response to a user request;
[0127] The operation module 1002 is used to transmit the data to be sent to the UART controller.
[0128] In some embodiments, the second processor includes: a processing module, a storage module and an interrupt module respectively connected to the processing module and the first processor in communication, wherein the storage module includes a target shared space accessible to both the first processor and the processing module; an acquisition module 1001, specifically used to receive data to be sent through the target shared space of the storage module; an operation module 1002, specifically used to trigger a first interrupt through the interrupt module; and when the first interrupt is received, the processing module transmits the data to be sent in the target shared space to the UART controller.
[0129] In some embodiments, the operation module 1002 is specifically used to determine the interrupt type of the first interrupt; wherein the interrupt type is associated with the situation that triggers the first interrupt; apply for a DMA channel of corresponding width based on the interrupt type of the first interrupt; and drive the DMA controller to transfer the data to be sent from the target shared space to the UART controller through the applied DMA channel.
[0130] In some embodiments, the processing module is a RISC-V processor.
[0131] In some embodiments, the device also includes: a receiving data operation module, which is used to transmit the data to be received in the UART controller to the target shared space through the processing module; trigger a second interrupt through the interrupt module to notify the first processor to obtain the data to be received in the target shared space.
[0132] The communication device of the controller provided in the embodiment of the present application belongs to the same inventive concept as the communication method of the controller provided in the above embodiment of the present application. For the technical details not described in detail in the present embodiment, please refer to the specific processing content of the communication method of the controller provided in the above embodiment of the present application, which will not be repeated here.
[0133] Exemplary Electronic Devices
[0134] Another embodiment of the present application further provides an electronic device, including a processor, wherein the processor is configured to execute the steps of the communication method of the controller according to various examples of the present application described in the above embodiments of the present application. Fig.11As shown, an exemplary embodiment of the present application also provides an electronic device, including: a memory and a processor, the memory storing a computer program, and the processor executing the computer program to perform the steps of the communication method of the controller according to various examples of the present application described in the above examples of the present application.
[0135] The internal structure of the electronic device can be as follows Fig.11 As shown, the electronic device includes a processor, a memory, a network interface and an input device connected via a system bus. The processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the electronic device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, the steps in the communication method of the controller according to various examples of the present application described in the above examples of the present application are performed.
[0136] The processor may include a main processor and may also include a baseband chip, a modem, etc.
[0137] The memory stores a program for executing the technical solution of the present invention, and may also store an operating system and other key services. Specifically, the program may include a program code, and the program code includes computer operation instructions. More specifically, the memory may include a read-only memory (ROM), other types of static storage devices that can store static information and instructions, a random access memory (RAM), other types of dynamic storage devices that can store information and instructions, a disk storage, a flash, and the like.
[0138] The processor may be a general-purpose processor, such as a general-purpose central processing unit (CPU), a microprocessor, etc., or an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the scheme of the present invention. It may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component.
[0139] The input device may include a device for receiving data and information input by a user, such as a keyboard, a mouse, a camera, a scanner, a light pen, a voice input device, a touch screen, a pedometer, or a gravity sensor.
[0140] Output devices may include means that allow information to be output to a user, such as display screens, printers, speakers, etc.
[0141] The communication interface may include using any transceiver or the like to communicate with other devices or communication networks, such as Ethernet, Radio Access Network (RAN), Wireless Local Area Network (WLAN), etc.
[0142] The processor executes the program stored in the memory and calls other devices, which can be used to implement the various steps of the communication method of any controller provided in the above examples of the present application.
[0143] The electronic device may also include a display component and a voice component. The display component may be a liquid crystal display or an electronic ink display. The input device of the electronic device may be a touch layer covered on the display component, or a button, trackball or touchpad provided on the housing of the electronic device, or an external keyboard, touchpad or mouse.
[0144] Those skilled in the art will understand that Fig.11 The structure shown in the figure is merely a block diagram of a partial structure related to the scheme of the present application, and does not constitute a limitation on the electronic device to which the scheme of the present application is applied. The specific electronic device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0145] Exemplary computer program products and storage media
[0146] In addition to the above-mentioned methods and devices, the communication method of the controller provided in the examples of the present application may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps of the communication method of the controller according to various examples of the present application described in the above-mentioned "Exemplary Method" section of the present application.
[0147] The computer program product may be written in any combination of one or more programming languages to write program codes for performing the operations of the present application examples, including object-oriented programming languages, such as Java, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0148] In addition, the present application example also provides a readable storage medium on which a computer program is stored, and the computer program is executed by a processor to execute the steps of the communication method of the controller according to various examples of the present application described in the above "Exemplary Method" section of the present application.
[0149] Those of ordinary skill in the art will appreciate that all or part of the processes in the above examples can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the examples of the above methods. Among them, any reference to memory, storage, database or other media used in the examples provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0150] The technical features of the above examples can be combined arbitrarily. In order to make the description concise, not all possible combinations of the technical features in the above examples are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0151] The above examples only express several examples of the present application, and the descriptions are relatively specific and detailed, but they cannot be understood as limiting the scope of the solutions provided by the examples of the present application. It should be pointed out that for ordinary technicians in this field, several modifications and improvements can be made without departing from the concept of the present application, which all belong to the protection scope of the present application. Therefore, the protection scope of the patent of this application shall be based on the attached claims.
Claims
1. A controller communication method, characterized in that: Applied to a first processor, the first processor is communicatively connected to a second processor, the second processor is communicatively connected to a UART controller, the method comprising: Responding to a user request, obtaining data to be sent; The data to be sent is transmitted to the second processor, so that the second processor transmits the data to be sent to the UART controller.
2. The method according to claim 1, characterized in that The second processor comprises: a processing module, a storage module and an interrupt module respectively connected to the processing module and the first processor in communication, wherein the storage module comprises a target shared space accessible to both the first processor and the processing module; Transmitting the data to be sent to the second processor includes: storing the data to be sent into the target shared space of the storage module; A first interrupt is triggered by the interrupt module to notify the processing module to transmit the to-be-sent data in the target shared space to the UART controller.
3. The method according to claim 1, characterized in that Transmitting the data to be sent to the second processor includes: According to the storage space available in the message buffer in the target structure, the data to be sent is filled into the message buffer to generate structure information; When the proportion of the data to be sent in the storable space reaches a first proportion, the structure information is transmitted to the second processor.
4. The method according to claim 3, characterized in that: After generating the structure information, the method further includes: When the waiting time reaches the target time and the proportion of the to-be-sent data in the storable space does not reach the first proportion, transmitting the structure information to the second processor; The waiting time is the time from generating the structure information to transmitting the structure information.
5. The method according to claim 3, characterized in that: The method further comprises: When the number of consecutive occurrences of the first situation reaches a first number threshold, increasing the message buffer; The first situation includes: the proportion of the data to be sent in the storable space is greater than or equal to the first proportion.
6. The method according to claim 3, characterized in that The method further comprises: When the number of consecutive occurrences of the second situation reaches a second number threshold, reducing the message buffer; The second situation includes: the proportion of the data to be sent in the storable space is less than or equal to the second proportion.
7. The method according to claim 4, characterized in that The method further includes: when the number of consecutive occurrences of the first situation reaches a first number threshold, increasing the target duration; The first situation includes: the proportion of the data to be sent in the storable space is greater than or equal to the first proportion.
8. The method according to claim 4, characterized in that The method further comprises: When the number of consecutive occurrences of the second situation reaches a second numerical threshold, reducing the target duration; The second situation includes: the proportion of the data to be sent in the storable space is less than or equal to the second proportion.
9. The method according to claim 2, characterized in that: After transmitting the to-be-sent data to the second processor, the method further includes: Acquire the to-be-received data transmitted by the processing module from the UART controller to the target shared space.
10. A controller communication method, characterized in that: Applied to a second processor, the second processor is respectively connected to the first processor and the UART controller for communication, the method comprising: Acquire data to be sent from the first processor, wherein the data to be sent is data acquired by the first processor in response to a user request; The data to be sent is transmitted to the UART controller.
11. The method according to claim 10, characterized in that The second processor comprises: a processing module, a storage module and an interrupt module respectively connected to the processing module and the first processor in communication, wherein the storage module comprises a target shared space accessible to both the first processor and the processing module; Acquiring data to be sent from the first processor, including: Receiving the data to be sent through the target shared space of the storage module; Transmitting the data to be sent to the UART controller includes: triggering a first interrupt by the interrupt module; When the first interrupt is received, the processing module transmits the to-be-sent data in the target shared space to the UART controller.
12. The method according to claim 11, characterized in that Transmitting the to-be-sent data in the target shared space to the UART controller includes: Determining an interrupt type of the first interrupt; wherein the interrupt type is associated with a situation that triggers the first interrupt; Applying for a DMA channel of corresponding width based on the interrupt type of the first interrupt; The DMA controller is driven to transfer the data to be sent from the target shared space to the UART controller through the applied DMA channel.
13. The method according to claim 11, characterized in that The processing module is a RISC-V processor.
14. The method according to claim 11, characterized in that After transmitting the to-be-sent data in the target shared space to the UART controller, the method further comprises: Transmitting the to-be-received data in the UART controller to the target shared space through the processing module; A second interrupt is triggered by the interrupt module to notify the first processor to obtain the to-be-received data in the target shared space.
15. An electronic device, characterized in that: include: A first processor and a second processor communicatively connected to each other; Wherein, the first processor is configured to execute the communication method of the controller according to any one of claims 1 to 9; The second processor is configured to execute the communication method of the controller according to any one of claims 10 to 14.
16. A storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by the processor, the communication method of the controller according to any one of claims 1 to 14 is implemented.
17. A computer program product, characterized in that The computer program product stores a computer program, and when the computer program is executed by a processor, the communication method of the controller according to any one of claims 1 to 14 is implemented.
Citation Information
Cited By
Data transmission method, device, equipment and medium
CN120768853A
