Read-write method and device
By employing a single process in the vehicle operating system to communicate exclusively with the I2C device, and utilizing inter-process communication, the problem of data loss in a multi-process environment for I2C devices with only one read/write register is solved, thus achieving the integrity and accuracy of data transmission.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-30
- Publication Date
- 2026-03-10
AI Technical Summary
In existing in-vehicle operating systems, including I2C devices with only one read/write register, critical data can easily be lost when multiple processes read the data simultaneously.
A single process communicates exclusively with the I2C device and sends data to other processes through inter-process communication, avoiding data loss caused by multiple processes reading simultaneously.
This effectively prevented the loss of critical data and ensured the integrity and accuracy of data transmission.
Smart Images

Figure CN121636403A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data communication, and more particularly to vehicle-mounted data communication. Background Technology
[0002] Current automotive operating systems, such as QNX, typically allow multiple processes to simultaneously read the same I2C (Integrated Circuit Interconnect) device. When the I2C device includes multiple registers storing different types of data, different processes can simultaneously read different types of data from the I2C device.
[0003] However, there are still I2C devices that consist of only one read / write register, which cannot be read simultaneously by multiple processes as is common with other I2C devices. Summary of the Invention
[0004] It is desirable to provide a read / write method and device that can be used to perform read / write operations on a device that includes only one read / write register and communicates based on a serial communication bus, without losing critical data.
[0005] According to one aspect, a method is provided for reading and writing to a device that communicates based on a serial communication bus, the device including only one read / write register, the method comprising: reading data from the one read / write register by a first process, wherein the device can only be read and written by the first process; and sending the data to at least one of one or more second processes via inter-process communication based on the data.
[0006] According to another aspect, a computing system is provided, comprising: a memory storing a computer program; and a processor executing the computer program such that the processor performs a method for reading and writing to a device communicating based on a serial communication bus, as described in various embodiments of the invention.
[0007] According to another aspect, a computer program product is provided, comprising computer program instructions that, when executed, cause a computer or processor to perform a method for reading and writing to a device communicating based on a serial communication bus, as described in various embodiments of the invention.
[0008] According to another aspect, a computer-readable medium is provided that stores computer program instructions, which, when executed, cause a computer or processor to perform a method for reading and writing to a device communicating based on a serial communication bus, as described in various embodiments of the invention.
[0009] According to various embodiments of the present disclosure, for a device that communicates based on a serial communication bus and includes only one read / write register, a single process is configured to communicate exclusively with the device, while other processes need to communicate with this single process to obtain data from the device. This avoids the problem of critical data loss that occurs when multiple processes simultaneously read the device which has only one read / write register. Attached Figure Description
[0010] In the accompanying drawings, embodiments are illustrated by way of example only and not by way of limitation, and similar reference numerals in the drawings refer to similar elements.
[0011] Figure 1 A method for reading and writing to a device communicating based on a serial communication bus, according to an embodiment of the present invention, is shown;
[0012] Figure 2 A method for reading and writing to a device communicating based on a serial communication bus, according to another embodiment of the present invention, is shown;
[0013] Figure 3 A structural diagram illustrating data reading and writing according to an embodiment of the present invention is shown;
[0014] Figure 4 A structural diagram illustrating data reading and writing according to another embodiment of the present invention is shown;
[0015] Figure 5 A computing system according to an embodiment of the present invention is shown.
[0016] Various aspects and features of the embodiments of the present invention have been described with reference to the accompanying drawings. The drawings are merely illustrative and not restrictive. The dimensions, shapes, reference numerals, or appearances of the various elements in the drawings may vary without departing from the spirit of the invention; furthermore, not all parts of the device of the embodiments of the present invention are indicated by reference numerals in the drawings, and only relevant components are indicated in some drawings. This does not limit the various parts to what is shown in the accompanying drawings. Detailed Implementation
[0017] For current devices that communicate via a serial communication bus and include multiple read / write registers (such as I2C devices), multiple processes can simultaneously read and write to the I2C device in the current automotive operating system. However, there are still I2C devices with only one read / write register. Such I2C devices cannot be actively read; they require an interrupt notification from the device, such as a GPIO interrupt, before they can be read. In response to an interrupt, if multiple processes read this type of I2C device simultaneously, a situation may arise where one process reads data, but the process that actually needs the data cannot. This results in some processes failing to obtain critical data, leading to the loss of critical data.
[0018] For I2C devices with only one read / write register, to avoid the loss of critical data, according to various embodiments of the present invention, a single process is configured to communicate exclusively with the I2C device. Other processes need to communicate with this single process via inter-process communication to obtain data from the I2C device. This avoids the problem of critical data loss that occurs when multiple processes simultaneously read this type of I2C device. The single process can act as an inter-process communication server, forwarding data from the I2C device to other processes acting as inter-process communication clients. This single process acting as the inter-process communication server can be bound to other processes acting as inter-process communication clients.
[0019] Figure 1 A flowchart of a method 100 for reading and writing to an I2C device according to an embodiment of the present invention is shown. The I2C device includes only one read / write register.
[0020] According to method 100, in step 110, a first process reads data from only one read / write register included in the I2C device. The I2C device is configured to be read and written only by the first process. In one embodiment, the first process can read from the I2C device in response to an interrupt message from the I2C device.
[0021] In step 120, based on the data read from the I2C device, the data read by the first process is sent to at least one of one or more second processes via inter-process communication (IPC). The at least one second process requires further processing of the data. The second process reads data from the I2C device via the first process through IPC, where the first process acts as an IPC server and the second process acts as an IPC client. Binding the client-side second process to the server-side first process ensures that the second process receives data from the I2C device from the first process, thus avoiding data loss caused by multiple second processes simultaneously reading data from the I2C device.
[0022] In one embodiment, in this step, after receiving an interrupt from the I2C device, the data read by the first process from the I2C device includes an identifier. For example, the read data is data of a fixed length of 15 characters, where the first two characters are the identifier. This identifier indicates which of one or more second processes should the data be sent to. Specifically, predetermined rules can exist to determine which of one or more second processes should be sent to based on the identifier. For example, 0x0001 is sent to second process 1, and 0x0002 is sent to second process 2.
[0023] In one scenario, the first process identifies which of one or more second processes (or processes) to send the read data to, based on identifiers included in the read data and predetermined rules. Then, based on the identification result, the first process sends the read data from the first process to the corresponding second process (or process 1) within the one or more second processes. For example, if the first process identifies that the first two characters of the read data are 0x0001, it sends the data to second process 1 according to predetermined rules. While this describes the first process performing the determination of which second processes (or processes) the read data should be sent to, this is not restrictive; this determination can be performed elsewhere, and the first process can then be notified to send the read data to the appropriate second process.
[0024] Figure 2 A flowchart of a method 200 for reading and writing to an I2C device according to another embodiment of the present invention is shown. Similarly, the I2C device includes only one read / write register.
[0025] like Figure 2 Method 200 shown Figure 1 The main difference in method 100 shown lies in steps 214 and 216. Steps 210 and 220 are essentially the same. Figure 1 Steps 110 and 120 are performed in the same way.
[0026] After the first process reads data from only one read / write register of the I2C device in step 210, the data is stored in a specific memory in step 214. In step 216, the data is read from this specific memory for subsequent transmission to at least one of one or more second processes. Setting up this specific memory further ensures that data is not lost. Even if the first process (server) and the second process (client) are asynchronous, especially if the first process starts earlier than the second process, the data read by the first process from the I2C device can be stored in this specific memory and wait for a period of time until the corresponding second process starts before being sent to that second process. This period of time can be predetermined; in one embodiment, it can be predetermined based on the difference in start times between the first process and one or more second processes.
[0027] However, it's also possible that this timeframe is determined in real-time based on the specific startup times of the first process and the corresponding second process (i.e., the second process to which the read data is to be sent). In this case, after reading data from the I2C device, the first process first determines which or which second processes it should be sent to based on the data, and then determines whether the corresponding second process has been started. If it has been started, the data is sent to the corresponding second process; otherwise, if it has not been started, the read data is sent to the specific memory for storage until the corresponding second process is started, at which point the data is read from the specific memory and sent to the corresponding second process.
[0028] Specifically, after the first process reads the data, it first identifies which second process(s) the data should be sent to, and then determines whether communication has been established between the first process and the corresponding second process. If no communication has been established, the data is stored in a specific memory and waits. If the communication has been established, the data is sent to the corresponding second process.
[0029] After the data read by the first process has been stored in a specific memory, it can continue to determine whether communication has been established between the first process and the corresponding identified second process. If the communication has been established, the data is read from the specific memory and sent to the corresponding second process. If the communication has not been established, the data is stored in the specific memory and the determination is made again to determine whether communication has been established between the first process and the corresponding identified second process.
[0030] Although reference Figure 1 and 2This primarily describes the process of reading from only one read / write register of an I2C device via a first process. It is also anticipated that the above methods may include the process of writing to only one read / write register of the I2C device via the first process. Specifically, methods 100 and 200 are expected to include writing data from at least one of one or more second processes to only one read / write register of the I2C device via the first process.
[0031] For the writing process, a specific memory can also be set up to further prevent data loss. Especially when the second process starts earlier than the first process, or when multiple second processes write to the I2C device simultaneously, the data can be first stored in the specific memory, then read from that specific memory according to predetermined rules, and then written to the I2C device's read / write register by the first process.
[0032] Specifically, the above method may include: a first process receiving data from a specific second process among one or more second processes and storing the data in a specific memory; and reading data from the specific second process from the specific memory and writing it to only one read / write register of the I2C device via the first process. In one embodiment, data from multiple specific second processes can be stored in a specific memory, and then the corresponding data can be read from the specific memory according to a first-in-first-out principle to write to the I2C device.
[0033] In one embodiment, the method further includes: when writing data from a specific second process of one or more second processes into only one read / write register of the I2C device via a first process, receiving additional data from another second process of one or more second processes that is different from the specific second process and storing the additional data in a specific memory; and reading the additional data from the specific memory and writing the additional data into only one read / write register of the I2C device via the first process.
[0034] Figure 3 A structural diagram illustrating data reading and writing according to an embodiment of the present invention is shown. Figure 3 As shown, the first process 11 is configured to communicate exclusively with the I2C device 10, thereby enabling the I2C device 10 to read data via the first process 11. After the first process 11 reads data from the I2C device 10, the first process 11 acts as an inter-process communication server, identifying which second processes(s) to send the read data to based on the data read. Figure 3 Three secondary processes, 121, 122, and 123, are shown. After performing the above identification, the read data is sent to the corresponding secondary process.
[0035] Although not shown, during the data writing process, the first process 11 receives data from the corresponding second process and then writes the received second data into the I2C device.
[0036] Figure 4 A structural diagram illustrating data reading and writing according to another embodiment of the present invention is shown. Figure 4 As shown, after the first process 11 reads data from the I2C device 10, it stores the read data in a specific memory 13. When communication between the first process and the second process can be established, that is, when both the first process and the second process are started, the data is read from the specific memory 13 and sent to the corresponding second process.
[0037] In one embodiment, after the first process reads data from the I2C device, the first process determines which or which second processes the read data should be sent to. If it is determined that the corresponding second process has been started, the first process can directly send the read data to the corresponding second process. Otherwise, if it is determined that the corresponding second process has not been started, the read data is sent to a specific memory for storage. Then, when it is determined that the corresponding second process has been started, the read data is read from the specific memory and sent to the corresponding second process.
[0038] Figure 5 A computing system 1 according to an embodiment of the present invention is shown. The computing system 1 includes: a memory 2 storing a computer program; and a processor 3 executing the computer program such that the processor 3 performs a method for reading and writing to a device communicating based on a serial communication bus, as described in various embodiments of the present invention.
[0039] The above is for reference only. Figure 1-5 Various embodiments of the method and apparatus of the present invention have been described. These embodiments can be combined with each other to obtain different effects, without being limited by the subject matter. Furthermore, the various units / steps / processes mentioned above are not limiting; the functions of the various units / steps / processes mentioned above can be combined / changed / modified to obtain corresponding effects.
[0040] The functions of each device in the system of the present invention can be implemented by software or corresponding hardware, or by means of a processor. For example, the processor can read computer programs stored in memory and run these computer programs to implement the functions of each unit. In one embodiment, the device of the present invention can also be implemented by a memory and a processor.
[0041] It is understood that the methods and apparatus of the various embodiments of this disclosure can be implemented by computer programs / software, such as by computer program products. This software can be loaded from a remote location into the processor's working memory and, when run, is used to execute the methods according to the invention for reading and writing to devices communicating based on a serial communication bus.
[0042] The exemplary embodiments of this disclosure cover both: creating / using computer programs / software of this disclosure from the outset, and converting existing programs / software to use computer programs / software of this disclosure by means of updates.
[0043] According to another embodiment of this disclosure, a machine-readable medium, such as a CD-ROM, is provided, including computer program code that, when executed, causes a computer or processor to perform a method according to the invention for reading and writing to a device communicating based on a serial communication bus. The machine-readable medium is, for example, an optical storage medium or a solid-state medium supplied together with or as part of other hardware.
[0044] Computer programs for performing the methods according to the embodiments of this disclosure may be distributed in other forms, such as via the Internet or other wired or wireless telecommunications systems. The computer programs may also be provided on networks such as the World Wide Web and can be downloaded from such networks to a microprocessor-operated computer or processor.
[0045] It must be noted that the embodiments of this disclosure are described with reference to different subjects. In particular, some embodiments are described with reference to method claims, while others are described with reference to device claims. However, those skilled in the art will understand from the above and below that, unless otherwise specified, any combination of features relating to different subjects, in addition to any combination of features belonging to one type of subject matter, is also considered to be disclosed in this application. Furthermore, it is possible to combine all features to provide a synergistic effect greater than the simple sum of the features.
[0046] The foregoing has described specific embodiments of this disclosure. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0047] The present disclosure has been described above with reference to specific embodiments. Those skilled in the art should understand that the technical solutions of the present disclosure can be implemented in various ways without departing from the spirit and essential characteristics of the present disclosure. The specific embodiments are merely illustrative and not restrictive. Furthermore, these embodiments can be arbitrarily combined to achieve the purposes of the present disclosure. The scope of protection of the present disclosure is defined by the appended claims.
[0048] The word "comprising" in the specification and claims does not exclude the presence of other elements or steps. The descriptions of each "step" and the order of the steps shown in the figures do not limit their sequence or quantity. The functions of the various elements described in the specification or recited in the claims can also be separated or combined, and implemented by multiple corresponding elements or a single element.
Claims
1. A method for reading and writing a device that communicates based on a serial communication bus, the device comprising only one read-write register, the method comprising: reading data from the one read-write register by a first process, wherein the device is only capable of reading and writing by the first process; and sending the data to at least one of one or more second processes based on the data by inter-process communication.
2. The method of claim 1, wherein, The data comprises an identifier, the method comprising: identifying by the first process based on the identifier and a predetermined rule which one or ones of the one or more second processes the data is to be sent to; and sending the data from the first process to the respective one or ones of the one or more second processes based on the result of the identification.
3. The method according to claim 1 or 2, further comprising: storing the data read by the first process in a specific memory for a period of time; and reading the data from the specific memory after the period of time and sending the data to at least one of the one or more second processes. The period of time is predetermined.
4. The method of claim 3, wherein, 5. The method according to claim 2, further comprising: after the data has been read by the first process, determining whether a communication between the first process and the respective one of the one or more second processes has been established; if the communication has not been established, storing the data in a specific memory; if the communication has been established, sending the data to the respective second process.
6. The method according to claim 5, further comprising: after the data has been stored in the specific memory, determining whether a communication between the first process and the respective one of the one or more second processes has been established; if the communication has been established, reading the data from the specific memory and sending the read data to the respective second process; if the communication has not been established, re-determining whether a communication between the first process and the respective one of the one or more second processes has been established. The serial communication bus comprises an Inter-Integrated Circuit bus.
7. The method of claim 1 or 2, wherein, 8. The method according to claim 1 or 2, further comprising: writing data from at least one of the one or more second processes into the one read-write register of the device via the first process.
9. The method according to claim 8, further comprising: receiving data from a specific one of the one or more second processes by the first process and storing the received data in a specific memory, and reading the received data from the specific memory and writing the received data into the one read-write register of the device via the first process.
10. The method according to claim 9, further comprising: receiving further data from a further second process of the one or more second processes different from the particular second process and storing the further data in a particular memory while writing the data from the particular second process to the one read-write register of the device via the first process; and reading out the further data from the particular memory and writing the further data to the one read-write register of the device via the first process.
11. The method of claim 1, wherein: reading the data from the one read-write register by the first process is in response to an interrupt from the device.
12. A computing system comprising: a memory storing a computer program; and a processor executing the computer program to cause the processor to perform the method for reading and writing to a device that communicates over a serial communication bus according to any of claims 1-11.
13. A computer program product comprising computer program instructions that, when executed, cause a processor or computer to perform the method for reading and writing to a device that communicates over a serial communication bus according to any of claims 1-11.
14. A computer readable medium storing computer program instructions that, when executed, cause a processor or computer to perform the method for reading and writing to a device that communicates over a serial communication bus according to any of claims 1-11.