Data interaction method and device, electronic equipment and storage medium
By using the GPIO line to output edge trigger signals and release semaphores in the data interaction between the SOC and the MCU, the problem of GPIO usage complexity and low compatibility in the existing technology is solved, and a simplified data interaction process is realized. and system performance optimization.
Patent Information
- Application Number
- CN202410891190.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-04
- Publication Date
- 2024-10-11
AI Technical Summary
In the existing technology, the driver layer of the SOC needs to be modified to use the GPIO line, resulting in increased complexity of GPIO use and reduced compatibility.
By obtaining the data to be sent and storing it in the sending buffer, the first GPIO line is controlled to output the first edge trigger signal, so that the micro control unit enters the data interaction process. After receiving the data, it controls the second GPIO line to output the signal and outputs it on the second GPIO line. The semaphore is released when the second edge triggers the signal to realize data interaction and avoid modification of the SOC driver layer.
It reduces the complexity of GPIO usage, improves GPIO compatibility, optimizes system performance, and avoids the waste of system resources caused by reloading the driver every time the GPIO line status changes.
Smart Images

Figure CN118760645A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of vehicle communication technology, and in particular to a data interaction method, device, electronic device and storage medium. Background Art
[0002] With the rapid development of the automobile industry, vehicles have become an indispensable means of transportation in people's daily lives. Vehicles are usually equipped with microcontroller units (MCU) and system-on-chips (SoC). MCU and SoC usually communicate through a 6-wire serial peripheral interface (SPI). The 6-wire SPI includes a clock line (SCK), a master-slave input data line (MISO), a master-slave input data line (MOSI), a chip select line (CS), and two general-purpose input / output (GPIO) lines. The two GPIOs are used to realize bidirectional notification when data is exchanged between SoC and MCU. In order to enable these two GPIOs to play a bidirectional notification role when SOC and MUC exchange data, the driver layer of SOC needs to be adapted and modified, which increases the complexity of GPIO use and reduces the compatibility of GPIO. Summary of the invention
[0003] In view of this, the embodiments of the present application provide a data interaction method, device, electronic device and storage medium to solve the problem in the prior art that the driver layer of the SOC needs to be modified before the GPIO line can be used, which increases the complexity of GPIO use and makes the GPIO compatibility low.
[0004] A first aspect of an embodiment of the present application provides a data interaction method, the method comprising: obtaining data to be sent, and storing the data to be sent in a sending buffer; controlling a first edge trigger signal output by a first general-purpose input / output (GPIO) line so that a microcontroller unit enters a data interaction process after receiving the first edge trigger signal output by the first GPIO line; after the receiving microcontroller unit enters the data interaction process, controlling the second GPIO line to output a signal; when the signal output by the second GPIO line is a second edge trigger signal, releasing a semaphore so that a blocking process sends the data to be sent in the sending buffer to the microcontroller unit based on the semaphore, and receives data returned by the microcontroller unit.
[0005] According to a second aspect of an embodiment of the present application, a data interaction device is provided, which includes: an acquisition module, used to acquire data to be sent and store the data to be sent in a sending buffer; an output module, used to control a first edge trigger signal output by a first general-purpose input / output (GPIO) line, so that a microcontroller unit enters a data interaction process after receiving the first edge trigger signal output by the first GPIO line; a receiving module, used to control the output signal of a second GPIO line after the microcontroller unit enters the data interaction process; and a process module, used to release a semaphore when the signal output by the second GPIO line is a second edge trigger signal, so that the blocked process sends the data to be sent in the sending buffer to the microcontroller unit based on the semaphore, and receives data returned by the microcontroller unit.
[0006] According to a third aspect of an embodiment of the present application, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.
[0007] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, which stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0008] Compared with the prior art, the embodiments of the present application have the following beneficial effects: the method in the embodiments of the present application obtains the data to be sent and stores the data to be sent in the sending buffer; controls the first edge trigger signal output by the first GPIO line so that the microcontroller unit enters the data interaction process after receiving the first edge trigger signal output by the first GPIO line; controls the second GPIO line to output the signal after the microcontroller unit enters the data interaction process; releases the semaphore when the signal output by the second GPIO line is the second edge trigger signal, so that the blocking process sends the data to be sent in the sending buffer to the microcontroller unit based on the semaphore, and receives the data returned by the microcontroller unit. When the SOC needs to interact with data, the above method can notify the MCU to enter the data interaction process by controlling the first GPIO line to output the first edge trigger signal, and after receiving the second edge trigger signal output by the second GPIO line, it is possible to know that the MCU has entered the data interaction process. Data interaction process, after determining that the MCU enters the data interaction process, release the semaphore to wake up the blocking process, and send the data to be sent and receive the data sent by the MCU through the blocking process, thereby completing the data interaction between the SOC and the MCU. The above method does not need to modify the driver layer of the SOC, reduces the complexity of GPIO use, and improves the compatibility of GPIO, avoids the need to modify the driver layer of the SOC to use the GPIO line, resulting in increased complexity of GPIO use and low compatibility of GPIO. In addition, the method uses a blocking waiting method to determine whether to exchange data through the blocking process. The blocking process does not occupy resources before receiving the semaphore. Only after the blocking event occurs, the value corresponding to the output signal of the second GPIO line is read to determine whether the second GPIO line has a pin level jump, and then the semaphore is released. The thread that executes the SPI data transmission and reception can block to get the semaphore. Compared with the prior art, this method needs to reload the driver every time the state of the second GPIO line changes, which consumes a large amount of system resources, and can better optimize system performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present application, 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 some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0010] Figure 1 It is a flowchart of a data interaction method provided in an embodiment of the present application;
[0011] Figure 2 This is a basic schematic diagram of a connection between a SOC and an MCU provided in an embodiment of the present application;
[0012] Figure 3 It is a flowchart of another data interaction method provided in an embodiment of the present application;
[0013] Figure 4 It is a flowchart of another data interaction method provided in an embodiment of the present application;
[0014] Figure 5 This is a basic flow chart of sending and receiving data at the application layer provided in an embodiment of the present application;
[0015] Figure 6 It is a flowchart of another data interaction method provided in an embodiment of the present application;
[0016] Figure 7 This is a flowchart of another optional data interaction method provided in an embodiment of the present application;
[0017] Figure 8 It is a flowchart of another optional data interaction method provided in an embodiment of the present application;
[0018] Fig. 9 This is a flowchart of another optional data interaction method provided in an embodiment of the present application;
[0019] Fig.10 It is a structural schematic diagram of a data interaction device provided in an embodiment of the present application;
[0020] Fig.11 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0021] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0022] A data interaction method and device according to an embodiment of the present application will be described in detail below with reference to the accompanying drawings.
[0023] Figure 1 This is a data interaction method provided by an embodiment of the present application, such as Figure 1 As shown, the method includes:
[0024] S101, obtaining data to be sent, and storing the data to be sent in a sending buffer;
[0025] S102, controlling the first edge trigger signal output by the first GPIO line so that the microcontroller unit enters a data interaction process after receiving the first edge trigger signal output by the first GPIO line;
[0026] S103, after the receiving microcontroller unit enters the data interaction process, controlling the signal output by the second GPIO line;
[0027] S104. When the signal output by the second GPIO line is a second edge-triggered signal, the semaphore is released, so that the blocking process sends the data to be sent in the sending buffer to the micro control unit based on the semaphore, and receives the data returned by the micro control unit.
[0028] It can be understood that the above-mentioned data interaction method provided in this example is applied to the SOC in the vehicle; the above-mentioned vehicles include vehicles with automatic driving or intelligent driving (including vehicles with passenger functions (such as cars, buses, large buses, minibuses, etc.), vehicles with cargo functions (such as ordinary trucks, vans, trailers, closed trucks, tank trucks, flatbed trucks, container trucks, dump trucks, special structure trucks), special vehicles (such as logistics distribution vehicles, automatic guided transport vehicles AGV, patrol cars, cranes, cranes, excavators, bulldozers, forklifts, rollers, loaders, off-road engineering vehicles, armored engineering vehicles, sewage treatment vehicles, sanitation vehicles, vacuum trucks, floor washing vehicles, sprinkler trucks, sweeping robots, food delivery robots, shopping guide robots, lawn mowers, golf carts, etc.), vehicles with entertainment functions (such as entertainment vehicles, amusement park automatic driving devices, balance cars, etc.), rescue vehicles (such as fire trucks, ambulances, power repair vehicles, engineering rescue vehicles, etc.)), etc.
[0029] Specifically, Figure 2 As shown, Figure 2The figure shows a basic schematic diagram of the connection between SOC and MCU, wherein a vehicle networking system (Telematics Box, TBOX) is provided in the vehicle, and SOC and MCU are provided in the TBOX, the MCU is connected to the electronic control unit (ECU) via a controller area network bus (CAN), the SOC can establish a connection with Ethernet, and the SOC and MCU are connected via a 6-wire SPI. In this example, the two GPIO lines between the SoC and the MCU are used as the first GPIO line and the second GPIO line respectively, the SOC initializes the first GPIO line as output, and the second GPIO line as input, that is, the SOC outputs a signal to the MCU via the first GPIO line, and receives a signal transmitted by the MCU via the second GPIO line; when data interaction is required between the SOC and the MCU subsequently, the data interaction method provided in this example is directly used to use GPIO for data interaction, thereby avoiding modification of the driver layer of the SOC to use GPIO for data interaction, which increases the complexity of GPIO use and makes the GPIO compatibility low.
[0030] Specifically, first obtain the data to be sent, and store the data to be sent in the sending buffer. The above-mentioned data to be sent is the data that the SOC application layer needs to send to the MCU. After obtaining the data to be sent, this example will store the data to be sent in the sending buffer, thereby optimizing resource management and preparing to send the data to be sent. It can be understood that the above-mentioned sending buffer includes but is not limited to a ring buffer, and relevant technical personnel can flexibly set the form of the above-mentioned sending buffer according to actual needs.
[0031] In some examples, after the data to be sent is stored in the sending buffer, the SOC controls the first edge trigger signal output by the first general-purpose input / output (GPIO) line. When the MCU subsequently receives the first edge trigger signal output by the first GPIO, it can know that the SOC needs to interact with data, and the MCU enters the data interaction process.
[0032] It can be understood that the above-mentioned first edge trigger signal refers to the signal at the moment when the signal level changes (that is, from a low level to a high level or from a high level to a low level). The above-mentioned first edge trigger signal can be a rising edge trigger signal or a falling edge trigger signal, and the first edge trigger signal can be specifically a rising edge trigger signal or a falling edge trigger signal, which can be flexibly set by relevant personnel according to actual needs.
[0033] Exemplarily, taking the above-mentioned first edge trigger signal as a rising edge trigger signal as an example, the SOC defaults to setting (setting when there is no data interaction requirement) that the first GPIO line outputs a low-level signal. After the SOC stores the data to be sent in the sending buffer, it controls the first GPIO line to output a high-level signal, so that the MCU receives a rising edge trigger signal that jumps from a low level to a high level; for another example, taking the above-mentioned first edge trigger signal as a falling edge trigger signal as an example, the SOC defaults to setting the first GPIO line to output a high-level signal. After the SOC stores the data to be sent in the sending buffer, it controls the first GPIO line to output a low-level signal, so that the MCU receives a falling edge trigger signal that drops from a high level to a low level.
[0034] In some examples, after receiving the first edge trigger signal, the MCU knows that the SOC needs to perform data interaction. After preparing for data interaction, the MCU enters the data interaction process and controls the second GPIO line to output the second edge trigger signal.
[0035] It can be understood that the above-mentioned second edge trigger signal refers to the signal at the moment when the signal level changes (that is, from a low level to a high level or from a high level to a low level), and the above-mentioned second edge trigger signal can be a rising edge trigger signal or a falling edge trigger signal, and the second edge trigger signal can be specifically a rising edge trigger signal or a falling edge trigger signal, which can be flexibly set by relevant personnel according to actual needs, and will not be repeated here.
[0036] In some examples, after the SOC receives a signal output by the MCU through the second GPIO line, if it is determined that the signal output by the second GPIO line is a second edge-triggered signal, the semaphore is released, so that the blocking process sends the data to be sent in the sending buffer to the microcontroller unit based on the semaphore, and receives the data returned by the microcontroller unit; it can be understood that the blocking process is set in advance in this example, and the blocking process will be in a blocked state before receiving the semaphore, and will not occupy the system resources of the SOC, so that the SOC can allocate system resources to other executable processes or threads, thereby improving the overall system performance of the SOC, and then the blocking process will no longer block when receiving the semaphore, and will take out the data to be sent from the sending buffer, and then send the data to be sent to the MCU, and receive the data returned by the MCU, thereby completing the data interaction between the SOC and the MCU.
[0037] In order to better understand the above method, this embodiment provides a more specific example for illustration. First, the GPIO pins (the first GPIO line and the second GPIO line pins) and SPI properties required for the project are initialized in the constructor of the SPIMSGWrapper class. After the first GPIO line and the second GPIO line pins are initialized, a thread is created to register the file descriptor of the second GPIO line to the newly created epoll instance. The epoll is provided with an epoll_wait function, which is used to block and wait for an event to occur, and detect whether the output of the second GPIO line is a second edge-triggered signal, and if so, release the semaphore.
[0038] Then create a thread for blocking to obtain the semaphore and sending the data to be sent, and put the data exchanged at the same time (i.e. the received data) into the callback function, and then set the default sending signal of the first GPIO line to a low level, and set it to a high level thread when data needs to be sent; subsequently determine whether the application layer has data to be sent, if not, end the process, if so, obtain the data to be sent, and store the data to be sent in the ring buffer, and pull up the signal output by the first GPIO line to notify the MCU to receive the data, and then epoll_wait blocks and waits, and determines whether the second GPIO is a rising edge, if not, end or continue to wait, if so, release the semaphore, pull down the signal output by the first GPIO line, and prepare to send the data to be sent. After the subsequent blocking process obtains the semaphore, it immediately calls the system call function to send data and waits for the data transmission exchange to be completed.
[0039] According to the technical solution provided in the embodiment of the present application, by obtaining the data to be sent and storing the data to be sent in the sending buffer; controlling the first edge trigger signal output by the first GPIO line so that the microcontroller unit enters the data interaction process after receiving the first edge trigger signal output by the first GPIO line; after receiving the microcontroller unit entering the data interaction process, controlling the second GPIO line to output the signal; when the signal output by the second GPIO line is the second edge trigger signal, releasing the semaphore, so that the blocking process sends the data to be sent in the sending buffer to the microcontroller unit based on the semaphore, and receives the data returned by the microcontroller unit. When the SOC needs to interact with data, the above method can notify the MCU to enter the data interaction process by controlling the first GPIO line to output the first edge trigger signal, and after receiving the second edge trigger signal output by the second GPIO line, it is realized that the MCU has entered the data interaction process. After determining that the MCU enters the data interaction process, the semaphore is released to wake up the blocking process, and the data to be sent and the data sent by the MCU are sent through the blocking process, thereby completing the data interaction between the SOC and the MCU. The above method does not need to modify the driver layer of the SOC, reduces the complexity of GPIO use, and improves the compatibility of GPIO, avoids the need to modify the driver layer of the SOC to use the GPIO line, resulting in increased complexity of GPIO use and low compatibility of GPIO. In addition, the method uses a blocking waiting method to determine whether to exchange data through the blocking process. The blocking process does not occupy resources before receiving the semaphore. Only after the blocking event occurs, the value corresponding to the output signal of the second GPIO line is read to determine whether the second GPIO line has a pin level jump, and then the semaphore is released. The thread that executes the data transmission and reception of SPI can block to obtain the semaphore. Compared with the prior art, this method needs to reload the driver every time the state of the second GPIO line changes, which consumes a large amount of system resources, and can better optimize system performance.
[0040] In some embodiments, Figure 3 As shown, the blocking process sends the data to be sent in the sending buffer to the micro control unit based on the semaphore, and receives the data returned by the micro control unit, including:
[0041] S301, the blocking process calls a preset system call function to obtain the data to be sent from the sending buffer, and transmits the data to be sent to the micro control unit through the system call function;
[0042] S302, the blocking process calls the system call function to receive data returned by the micro control unit.
[0043] In some examples, a system call function is pre-set, which can obtain the data to be sent from the sending buffer, and transmit the data to be sent to the micro control unit through the system call function, and the system call function can also receive data returned by the micro control unit.
[0044] Exemplarily, taking the above-mentioned system call function as the ioctl function as an example, the blocking process calls the ioctl function to obtain the data to be sent from the sending buffer, and transmits the data to be sent to the micro control unit through the system call function. At the same time, the blocking process calls the ioctl function to receive the data returned by the micro control unit, thereby realizing the sending of the data to be sent and receiving the data at the same time, avoiding the need for the blocking process to call the read function when sending the data to be sent, obtain the data to be sent from the ring buffer, and transmit the data to be sent to the micro control unit through the read function. When receiving the data subsequently, it is necessary to call write again to receive the data returned by the micro control unit, resulting in the need to call at least two functions, and the need to perform big-endian and small-endian data processing, resulting in a waste of system resources.
[0045] In order to better understand this method, this embodiment provides a more specific example to illustrate that the blocking process waits for the semaphore. Before the semaphore arrives, the blocking process is always in a waiting state, avoiding the problem of continuously occupying SOC system resources. When the signal output by the second GPIO line is the second edge trigger signal, the semaphore is released. When the blocking process receives the semaphore, it is no longer blocked. The blocking process takes out the data to be sent from the ring buffer, and uses the ioctl function to send the data to be sent to the MCU, and receives the data returned by the MCU through the ioctl function, completing the data exchange between the SOC and the MCU, and realizing that the data is received while sending the data. This method reads and writes the first GPIO line and uses epoll_wait() to detect the rising edge of the second GPIO line, forming a six-wire SPI communication. In this way, the application layer and the driver layer of the SOC do not need to manage the GPIO pins, which not only increases the portability and cross-platform nature of the driver layer code in the SOC, but also makes the application layer not manage and operate the first GPIO line and the second GPIO line, and directly calls the data transceiver interface provided by the data interaction method in this example, realizing the hardware and software layering, and will not affect the SPI transmission rate. The underlying SPI data transceiver interface is also changed from read / write to ioctl. SPI can receive data while sending data, without the need to make code changes for SPI reading and writing in the kernel, thus increasing portability.
[0046] According to the technical solution provided in the embodiment of the present application, the blocking process calls a pre-set system call function to obtain the data to be sent from the sending buffer, and transmits the data to be sent to the microcontroller unit through the system call function; the blocking process calls the system call function to receive the data returned by the microcontroller unit, thereby realizing the sending and receiving of data through the same system call function, avoiding the problem of wasting system resources due to calling multiple functions.
[0047] In some embodiments, Figure 4 As shown, after receiving the data returned by the microcontroller unit, the method further includes:
[0048] S401, putting the data returned by the microcontroller unit into the receiving buffer;
[0049] S402, reading the data returned by the micro control unit from the receiving buffer area, and putting the read data into a preset callback function, so that the application layer obtains the data returned by the micro control unit based on the callback function.
[0050] Specifically, the blocking process puts the data returned by the microcontroller into the receiving buffer through the system call function, then reads the data returned by the microcontroller from the receiving buffer, and puts the read data into a pre-set callback function, so that the application layer obtains the data returned by the microcontroller based on the callback function.
[0051] After data interaction through the above method, the program logic design of the application layer in the SOC is very clear and simple. No operations related to GPIO and SPI protocols are required. The application layer program only needs to create a class object -> register a callback function for receiving data -> call the interface provided by the data interaction method in this example to send the data to be sent -> the callback function receives the data. Figure 5 As shown, Figure 5 The figure shows a basic flow chart of sending and receiving data by the application layer. Through the above method, the application layer can directly call the encapsulated interface to perform SPI reading and writing to realize sending and receiving data without paying attention to the specific implementation of the underlying layer, thereby improving the flexibility and efficiency of the system.
[0052] The code example of the above application is as follows:
[0053] bool spiRcvMsgCallback(rpcMsgPayload_s*rx_buf,uint16_t len)
[0054] {printf("--->RcvMsg:\nLen=%d,",len); / / Print the length of the received data
[0055] for(int i = 0; i <len;i++)
[0056] {printf("%#x",rx_buf->data[i]); / / print received data}
[0057] return true;}
[0058] int main(int argc,char const*argv[])
[0059] { / / 1. Create the following objects
[0060] seres::spimsgwrapper::SPIMSGWrapper*rpcmsgTest=newseres::spimsgwrapper::SPIMSGWrapper;
[0061] rpcmsgTest->RpcMsgCallbackRegister(spiRcvMsgCallback); / / 2. Register callback function
[0062] rpcmsgTest->RpcSendToMcuApi("hello",6); / / 3.SPI data sending
[0063] delete(rpcmsgTest);
[0064] return 0;
[0065] }.
[0066] According to the technical solution provided in the embodiment of the present application, the data returned by the microcontroller unit is placed in a receiving buffer area; the data returned by the microcontroller unit is read from the receiving buffer area, and the read data is placed in a pre-set callback function, so that the application layer obtains the data returned by the microcontroller unit based on the callback function, thereby enabling the application layer in the SOC to simply and efficiently send the data to be sent and receive the data returned by the MCU.
[0067] In some embodiments, Figure 6 As shown, the second edge trigger signal is a rising edge signal, and when the signal output by the second GPIO line is the second edge trigger signal, the signal quantity is released, including:
[0068] S601, obtaining a value corresponding to a signal currently output by the second GPIO line, and obtaining a value corresponding to a signal output by the second GPIO line at a previous moment;
[0069] S602: If the value corresponding to the signal currently output by the second GPIO line is greater than the value corresponding to the signal output at the previous moment, determine that the signal output by the second GPIO line is a rising edge signal, and release the semaphore.
[0070] Specifically, this example takes the second edge trigger signal as a rising edge signal as an example, wherein this example sets the value corresponding to the low-level signal to 0, and the value corresponding to the high-level signal to 1. This example obtains the value corresponding to the signal currently output by the second GPIO line, and obtains the value corresponding to the signal output by the second GPIO line at the previous moment. If the value corresponding to the signal currently output by the second GPIO line is greater than the value corresponding to the signal output at the previous moment, it is determined that the signal output by the second GPIO line is a rising edge signal, and the semaphore is released.
[0071] For example, the value corresponding to the signal currently output by the second GPIO line is 1, and the value corresponding to the signal output by the second GPIO line at the last moment is 0. Since 1 is greater than 0, it is determined that the signal output by the second GPIO line is a rising edge signal, and the semaphore is released. For another example, the value corresponding to the signal currently output by the second GPIO line is 0, and the value corresponding to the signal output by the second GPIO line at the last moment is 0. Since 0 is equal to 0, it is determined that the signal output by the second GPIO line is not a rising edge signal, and the semaphore will not be released. For another example, the value corresponding to the signal currently output by the second GPIO line is 0, and the value corresponding to the signal output by the second GPIO line at the last moment is 1. Since 0 is less than 1, it is determined that the signal output by the second GPIO line is not a rising edge signal, and the semaphore will not be released.
[0072] Exemplarily, 1) initialize the first GPIO line as output and the second GPIO line as input mode, then open the path of the second GPIO line (for example, the path is in " / sys / class / gpio / gpiox / value"), then use epoll_create(1) to create an epoll instance, register the file descriptor fd for opening the path of the second GPIO line to the epoll instance using epoll_ctl(), create a thread, then use epoll_wait() in the thread to block and wait for an event to occur. After the event occurs, read the value corresponding to the current second GPIO line signal. The value corresponding to the second GPIO line signal must be 1, and the value read last time is 0, thereby determining that this is a rising edge signal, and then releasing the semaphore.
[0073] According to the technical solution provided in the embodiment of the present application, the value corresponding to the signal currently output by the second GPIO line is obtained, and the value corresponding to the signal output by the second GPIO line at the previous moment is obtained; if the value corresponding to the signal currently output by the second GPIO line is greater than the value corresponding to the signal output at the previous moment, it is determined that the signal output by the second GPIO line is a rising edge signal, and the signal quantity is released, thereby achieving the effect of accurately determining the rising edge signal output by the second GPIO line and accurately determining the timing of releasing the signal quantity.
[0074] In some embodiments, Figure 7 As shown, the data to be sent is obtained and stored in the sending buffer, including:
[0075] S701, receiving a data sending request from the application layer, where the data sending request includes a data address and a data size;
[0076] S702: Obtain the data to be sent according to the data address and the data size, and store the data to be sent in the sending buffer.
[0077] Specifically, in the step of obtaining the data to be sent, this example receives a data sending request from the application layer, which includes a data address and a data size, and then obtains the data to be sent based on the data address and the data size, and stores the data to be sent in a sending buffer, thereby accurately obtaining the above-mentioned data to be sent.
[0078] According to the technical solution provided in the embodiment of the present application, a data sending request is received from the application layer, the data sending request includes a data address and a data size; the data to be sent is obtained according to the data address and the data size, and the data to be sent is stored in a sending buffer, thereby realizing accurate acquisition of the above-mentioned data to be sent.
[0079] In some embodiments, Figure 8 As shown, after releasing the semaphore, the method further includes:
[0080] S801, controlling the first GPIO line to output a logic level signal, and obtaining data contained in a sending buffer;
[0081] S802: When the sending buffer contains unretrieved data to be sent, re-control the first GPIO line to output a first edge-triggered signal.
[0082] Specifically, after releasing the semaphore, the method provided in this example further includes controlling the first GPIO line to output a logic level signal, so that when there is data to be sent subsequently, the first GPIO line can be re-controlled to output a first edge-triggered signal.
[0083] Exemplarily, taking the first edge trigger signal as a rising edge trigger signal as an example, the preset logic level signal is a low level signal. When there is no data to be sent, the first GPIO line continues to output a low level signal, and after the SOC stores the data to be sent in the sending buffer, the first GPIO line is controlled to output a high level signal, so that the MCU receives the rising edge trigger signal that jumps from a low level to a high level, and after the signal amount is released, the first GPIO line is controlled to output a low level signal again.
[0084] After the semaphore is released and the blocking process completes a data interaction, the method provided in this example will also re-acquire the data contained in the sending buffer; when the sending buffer contains unretrieved data to be sent, the first GPIO line is re-controlled to output the first edge trigger signal until all the data to be sent in the sending buffer are sent to the MCU.
[0085] According to the technical solution provided in the embodiment of the present application, the first GPIO line is controlled to output a logic level signal, and the data contained in the sending buffer is obtained; when the sending buffer contains unremoved data to be sent, the first GPIO line is re-controlled to output a first edge trigger signal. The method provided in this example controls the first GPIO line to output a logic level signal, so that when there is data to be sent subsequently, the first GPIO line can be re-controlled to output the first edge trigger signal until all the data to be sent in the sending buffer are sent to the MCU, thereby improving the data exchange speed between the SOC and the MCU.
[0086] In some examples, such as Fig. 9 As shown, the first edge trigger signal for controlling the output of the first GPIO line includes:
[0087] S901, determining a value corresponding to a signal currently output by the first GPIO line;
[0088] S902: When the value corresponding to the signal currently output by the first GPIO line is a first preset value, adjust the signal currently output by the first GPIO line so that the value corresponding to the signal output by the first GPIO line is a second preset value.
[0089] Specifically, taking the first edge trigger signal as a rising edge signal, and the value corresponding to the low level signal is 0, and the value corresponding to the high level signal is 1 as an example, the value corresponding to the signal output by the first GPIO line at the beginning should be 0. After the signal output by the first GPIO line is subsequently adjusted, the value corresponding to the signal output by the first GPIO line is 1. When the first edge trigger signal is a falling edge signal, the above principle is the same and will not be repeated here.
[0090] Based on the above principles, this example will determine the value corresponding to the signal currently output by the first GPIO line. When the value corresponding to the signal currently output by the first GPIO line is a first preset value, the signal currently output by the first GPIO line is adjusted so that the value corresponding to the signal output by the first GPIO line is a second preset value, thereby achieving the effect of outputting the first edge trigger signal through the first GPIO line. It can be understood that when the first edge trigger signal is a rising edge signal, the first preset value is 0, and the second preset value is 1; when the first edge trigger signal is a falling edge signal, the first preset value is 1, and the second preset value is 0.
[0091] According to the technical solution provided in the embodiment of the present application, the value corresponding to the signal currently output by the first GPIO line is determined; when the value corresponding to the signal currently output by the first GPIO line is a first preset value, the signal currently output by the first GPIO line is adjusted so that the value corresponding to the signal output by the first GPIO line is a second preset value, thereby achieving the effect of outputting a first edge-triggered signal through the first GPIO line.
[0092] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present application, which will not be described one by one here.
[0093] The following are device embodiments of the present application, which can be used to execute the method embodiments of the present application. For details not disclosed in the device embodiments of the present application, please refer to the method embodiments of the present application.
[0094] This embodiment also provides a data interaction device, such as Fig.10 As shown, the device comprises:
[0095] An acquisition module 1001 is used to acquire data to be sent and store the data to be sent in a sending buffer;
[0096] The output module 1002 is used to control a first edge trigger signal output by a first general-purpose input / output (GPIO) line, so that the microcontroller unit enters a data interaction process after receiving the first edge trigger signal output by the first GPIO line;
[0097] The receiving module 1003 is used to control the second GPIO line to output a signal after receiving the micro control unit entering the data interaction process;
[0098] The process module 1004 is used to release the semaphore when the signal output by the second GPIO line is a second edge-triggered signal, so that the blocking process sends the data to be sent in the sending buffer to the micro control unit based on the semaphore, and receives the data returned by the micro control unit.
[0099] In some examples, the process module 1004 is also used to block the process from calling a preset system call function to obtain the data to be sent from the send buffer, and transmit the data to be sent to the micro control unit through the system call function; the blocking process calls the system call function to receive the data returned by the micro control unit.
[0100] In some examples, the process module 1004 is also used to place the data returned by the microcontroller unit into a receiving buffer; read the data returned by the microcontroller unit from the receiving buffer, and place the read data into a pre-set callback function, so that the application layer obtains the data returned by the microcontroller unit based on the callback function.
[0101] In some examples, the second edge trigger signal is a rising edge signal, and the process module 1004 is also used to obtain the value corresponding to the signal currently output by the second GPIO line, and obtain the value corresponding to the signal output by the second GPIO line at the previous moment; if the value corresponding to the signal currently output by the second GPIO line is greater than the value corresponding to the signal output at the previous moment, it is determined that the signal output by the second GPIO line is a rising edge signal, and the semaphore is released.
[0102] In some examples, the acquisition module 1001 is also used to receive a data sending request from the application layer, the data sending request includes a data address and a data size; obtain the data to be sent according to the data address and the data size, and store the data to be sent in a sending buffer.
[0103] In some examples, the output module 1002 is also used to control the first GPIO line to output a preset logic level signal and obtain the data contained in the sending buffer; when the sending buffer contains unretrieved data to be sent, the first GPIO line is re-controlled to output the first edge trigger signal.
[0104] In some examples, the output module 1002 is also used to determine a value corresponding to a signal currently output by the first GPIO line; when the value corresponding to the signal currently output by the first GPIO line is a first preset value, the signal currently output by the first GPIO line is adjusted so that the value corresponding to the signal output by the first GPIO line is a second preset value.
[0105] According to the technical solution provided by the embodiment of the present application, the data interaction device provided by the present embodiment obtains the data to be sent and stores the data to be sent in the sending buffer; controls the first edge trigger signal output by the first GPIO line so that the microcontroller unit enters the data interaction process after receiving the first edge trigger signal output by the first GPIO line; controls the second GPIO line to output the signal after the receiving microcontroller unit enters the data interaction process; when the signal output by the second GPIO line is the second edge trigger signal, releases the semaphore so that the blocking process sends the data to be sent in the sending buffer to the microcontroller unit based on the semaphore, and receives the data returned by the microcontroller unit. When the SOC needs to perform data interaction, the above method controls the first GPIO line to output the signal. The IO line outputs a first edge trigger signal to notify the MCU to enter the data interaction process. After receiving the second edge trigger signal output by the second GPIO line, it is realized that the MCU has entered the data interaction process. After determining that the MCU has entered the data interaction process, the semaphore is released to wake up the blocking process. The blocking process is used to send the data to be sent and receive the data sent by the MCU, thereby completing the data interaction between the SOC and the MCU. The above method does not require modification to the driver layer of the SOC, reduces the complexity of GPIO use, and improves the compatibility of GPIO, avoiding the need to modify the driver layer of the SOC to use the GPIO line, which increases the complexity of GPIO use and makes the GPIO compatibility low.
[0106] Fig.11 Schematic diagram of an electronic device 11 provided in an embodiment of the present application. Fig.11 As shown, the electronic device 11 of this embodiment includes: a processor 1101, a memory 1102, and a computer program 1103 stored in the memory 1102 and executable on the processor 1101. When the processor 1101 executes the computer program 1103, the steps in the above-mentioned method embodiments are implemented. Alternatively, when the processor 1101 executes the computer program 1103, the functions of the modules / units in the above-mentioned device embodiments are implemented.
[0107] The electronic device 11 may be a desktop computer, a notebook, a PDA, a cloud server, or other electronic device. The electronic device 11 may include, but is not limited to, a processor 1101 and a memory 1102. Those skilled in the art will appreciate that Fig.11 The electronic device 11 is merely an example and does not limit the electronic device 11 , and may include more or less components than those shown in the figure, or different components.
[0108] Processor 1101 can be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0109] The memory 1102 may be an internal storage unit of the electronic device 11, for example, a hard disk or memory of the electronic device 11. The memory 1102 may also be an external storage device of the electronic device 11, for example, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card (FlashCard), etc. equipped on the electronic device 11. The memory 1102 may also include both an internal storage unit of the electronic device 11 and an external storage device. The memory 1102 is used to store computer programs and other programs and data required by the electronic device.
[0110] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units.
[0111] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. The computer program may include computer program code, and the computer program code may be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of regional requirements and patent practice. For example, in some areas, according to regional requirements and patent practice, the computer-readable medium does not include electric carrier signals and telecommunication signals.
[0112] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A data interaction method, characterized in that: The method comprises: Acquire the data to be sent, and store the data to be sent in a sending buffer; Controlling a first edge trigger signal output by a first general-purpose input / output (GPIO) line so that the microcontroller unit enters a data interaction process after receiving the first edge trigger signal output by the first GPIO line; After receiving the microcontroller entering the data interaction process, controlling the second GPIO line to output a signal; When the signal output by the second GPIO line is a second edge-triggered signal, the semaphore is released, so that the blocking process sends the data to be sent in the sending buffer to the micro control unit based on the semaphore, and receives the data returned by the micro control unit.
2. The method according to claim 1, characterized in that The blocking process sends the to-be-sent data in the sending buffer to the micro control unit based on the semaphore, and receives data returned by the micro control unit, including: The blocking process calls a preset system call function to obtain the data to be sent from the sending buffer, and transmits the data to be sent to the micro control unit through the system call function; The blocking process calls the system call function to receive the data returned by the micro control unit.
3. The method according to claim 1, characterized in that After receiving the data returned by the microcontroller unit, the method further includes: Put the data returned by the microcontroller into the receiving buffer; The data returned by the micro control unit is read from the receiving buffer area, and the read data is put into a preset callback function, so that the application layer obtains the data returned by the micro control unit based on the callback function.
4. The method according to claim 1, characterized in that: The second edge trigger signal is a rising edge signal, and when the signal output by the second GPIO line is the second edge trigger signal, releasing the signal quantity includes: Obtain a value corresponding to a signal currently output by the second GPIO line, and obtain a value corresponding to a signal output by the second GPIO line at a previous moment; If the value corresponding to the signal currently output by the second GPIO line is greater than the value corresponding to the signal output at the previous moment, it is determined that the signal output by the second GPIO line is a rising edge signal, and the signal quantity is released.
5. The method according to claim 1, characterized in that Acquiring data to be sent and storing the data to be sent in a sending buffer includes: Receiving a data transmission request from an application layer, wherein the data transmission request includes a data address and a data size; The data to be sent is acquired according to the data address and the data size, and the data to be sent is stored in the sending buffer.
6. The method according to claim 1, characterized in that After releasing the semaphore, the method further includes: Controlling the first GPIO line to output a preset logic level signal, and obtaining the data contained in the sending buffer; When the sending buffer contains the to-be-sent data that has not been taken out, the first GPIO line is controlled again to output the first edge-triggered signal.
7. The method according to claim 1, characterized in that The first edge trigger signal for controlling the output of the first GPIO line includes: Determine a value corresponding to a signal currently output by the first GPIO line; When the value corresponding to the signal currently output by the first GPIO line is a first preset value, the signal currently output by the first GPIO line is adjusted so that the value corresponding to the signal output by the first GPIO line is a second preset value.
8. A data interaction device, characterized in that: The device comprises: An acquisition module, used for acquiring data to be sent, and storing the data to be sent in a sending buffer; An output module, used for controlling a first edge trigger signal output by a first general-purpose input / output (GPIO) line, so that the microcontroller unit enters a data interaction process after receiving the first edge trigger signal output by the first GPIO line; A receiving module, used for receiving a signal output by the microcontroller after entering a data interaction process, and controlling the second GPIO line to output a signal; The process module is used to release the semaphore when the signal output by the second GPIO line is a second edge-triggered signal, so that the blocking process sends the data to be sent in the sending buffer to the micro control unit based on the semaphore, and receives the data returned by the micro control unit.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Data transmission method and device, vehicle and storage medium
CN119781824A
