CN113672542B - Data access method, device, equipment and storage medium in I2C bus - Google Patents
Data access method, device, equipment and storage medium in I2C bus Download PDFInfo
- Publication number
- CN113672542B CN113672542B CN202110866031.5A CN202110866031A CN113672542B CN 113672542 B CN113672542 B CN 113672542B CN 202110866031 A CN202110866031 A CN 202110866031A CN 113672542 B CN113672542 B CN 113672542B
- Authority
- CN
- China
- Prior art keywords
- frequency
- slave device
- target slave
- target
- current communication
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F13/00—Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
- G06F13/38—Information transfer, e.g. on bus
- G06F13/42—Bus transfer protocol, e.g. handshake; Synchronisation
- G06F13/4282—Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5027—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Software Systems (AREA)
- Debugging And Monitoring (AREA)
- Small-Scale Networks (AREA)
Abstract
The invention discloses a data access method in an I2C bus, which is applied to an I2C bus master device, and comprises the following steps: analyzing the received slave device access request to obtain a target slave device to be accessed; judging whether the target slave device supports frequency conversion or not; if yes, searching a preset highest frequency corresponding to the target slave device from a preset frequency conversion table, and performing data access operation on the target slave device by utilizing the preset highest frequency; if not, acquiring a frequency upper limit obtained by performing frequency self-adaptive test on the target slave device, and performing data access operation on the target slave device by using the frequency upper limit. By applying the data access method in the I2C bus, the self-adaptive automatic adjustment of the slave device frequency is realized, the labor is saved, the bus utilization rate is improved, the data access efficiency is improved, and the time consumption is saved. The invention also discloses a data access device, equipment and a storage medium in the I2C bus, which have corresponding technical effects.
Description
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a method, an apparatus, a device, and a computer readable storage medium for accessing data in an I2C bus.
Background
The internal integrated serial bus (Inter-INTEGRATED CIRCUIT, I2C) is a two-wire serial bus for connecting the microcontroller and its peripheral devices, and has the advantages of less interface wires, simple control mode, small device packaging form, higher communication rate, etc.
The I2C transfers information between devices connected to the bus through a Serial Data (SDA) line and a Serial Clock (SCL) line. Each device has a unique address identification. A Master device (Master) is a device that initiates data transfer on the bus and generates a clock signal that allows the transfer, any addressed device being known as a Slave device (Slave), and an upper layer application accesses data from each Slave device through the Master device in the I2C bus.
The existing data access mode in the I2C bus is to select one or more test frequencies from the pre-acquired applicable clock frequency range of the I2C slave device, that is, select several frequency points in a certain frequency range for testing, and finally use a compromise frequency to access the slave device. However, if there are multiple slave devices in the bus, it takes a long time and takes a lot of time and effort, and the method is only general, and the specificity of each slave device is not considered, so that the data access efficiency is affected.
In summary, how to effectively solve the problems of long bus occupation time, time and effort waste, influence on data access efficiency and the like in the existing data access mode of the I2C bus is an urgent need of those skilled in the art at present.
Disclosure of Invention
The invention aims to provide a data access method in an I2C bus, which realizes the self-adaptive automatic adjustment of the frequency of a slave device, saves labor, improves the bus utilization rate, improves the data access efficiency and saves time consumption; it is another object of the present invention to provide a data access apparatus, device and computer readable storage medium in an I2C bus.
In order to solve the technical problems, the invention provides the following technical scheme:
a data access method in an I2C bus, applied to an I2C bus master, comprising:
Analyzing the received slave device access request to obtain a target slave device to be accessed;
Judging whether the target slave device supports frequency conversion or not;
If yes, searching a preset highest frequency corresponding to the target slave device from a preset frequency conversion table, and performing data access operation on the target slave device by utilizing the preset highest frequency;
If not, acquiring a frequency upper limit obtained by carrying out frequency self-adaptive test on the target slave device, and carrying out data access operation on the target slave device by utilizing the frequency upper limit.
In a specific embodiment of the present invention, before determining whether the target slave device supports frequency conversion, the method further includes:
Reading the size of a data packet to be accessed corresponding to the target slave device from the frequency conversion table;
Judging whether the size of the data packet to be accessed exceeds a preset data packet size threshold value or not;
If yes, executing the step of judging whether the target slave device supports frequency conversion;
And if not, executing the step of acquiring the upper frequency limit obtained by performing frequency self-adaptive test on the target slave device.
In one embodiment of the present invention, determining whether the target slave device supports frequency conversion includes:
Reading a target variable frequency setting zone bit corresponding to the target slave device from the variable frequency table;
And judging whether the target variable frequency setting flag bit is supportable for variable frequency setting.
In a specific embodiment of the present invention, when accessing the multi-slave device, before performing the data access operation on the target slave device, the method further includes:
determining a target access priority corresponding to the target slave device according to the size of the data packet to be accessed;
performing data access operation on the target slave device, including:
And carrying out data access operation on the target slave device according to the target access priority.
In one embodiment of the present invention, the process of performing a frequency adaptive test on the target slave device to obtain the upper frequency limit includes:
acquiring the reference frequency corresponding to the target slave device from the frequency conversion table;
Taking the reference frequency as a current communication frequency;
Communicating with the target slave device using the current communication frequency;
judging whether the communication is successful or not;
if yes, the current communication frequency is up-regulated by a first preset frequency interval, and the regulated frequency is determined to be the current communication frequency;
Repeatedly executing the step of utilizing the current communication frequency to communicate with the target slave device until communication fails, and determining the nearest neighbor pre-adjustment frequency corresponding to the current communication frequency when the communication fails as the frequency upper limit;
If not, the current communication frequency is adjusted downwards by a second preset frequency interval, and the adjusted frequency is determined to be the current communication frequency;
and repeatedly executing the step of utilizing the current communication frequency to communicate with the target slave device until the communication is successful, and taking the current communication frequency when the communication is successful as the frequency upper limit.
In one embodiment of the present invention, the method further comprises:
and when the frequency of the second preset frequency interval is adjusted downwards for the current communication frequency to reach the upper limit of the preset frequency, modifying the fault zone bit corresponding to the target slave device in the frequency conversion table into an enabling state.
In one embodiment of the present invention, the method further comprises:
and performing verification operation on the slave device access request.
A data access arrangement in an I2C bus, for use in an I2C bus master, comprising:
The request analysis module is used for analyzing the received access request of the slave device to obtain a target slave device to be accessed;
The first judging module is used for judging whether the target slave device supports frequency conversion or not;
The first access module is used for searching a preset highest frequency corresponding to the target slave device from a preset frequency conversion table when the target slave device supports frequency conversion, and performing data access operation on the target slave device by utilizing the preset highest frequency;
And the second access module is used for acquiring a frequency upper limit obtained by performing frequency self-adaptive test on the target slave device when the target slave device is determined not to support frequency conversion, and performing data access operation on the target slave device by using the frequency upper limit.
A data access device in an I2C bus, comprising:
A memory for storing a computer program;
a processor for implementing the steps of the data access method in the I2C bus as described above when executing the computer program.
A computer readable storage medium having stored thereon a computer program which when executed by a processor implements the steps of a data access method in an I2C bus as described above.
The data access method in the I2C bus provided by the invention is applied to an I2C bus master device and comprises the following steps: analyzing the received slave device access request to obtain a target slave device to be accessed; judging whether the target slave device supports frequency conversion or not; if yes, searching a preset highest frequency corresponding to the target slave device from a preset frequency conversion table, and performing data access operation on the target slave device by utilizing the preset highest frequency; if not, acquiring a frequency upper limit obtained by performing frequency self-adaptive test on the target slave device, and performing data access operation on the target slave device by using the frequency upper limit.
According to the technical scheme, when the target slave device to be accessed is determined to support frequency conversion through the preset frequency conversion table, the preset highest frequency corresponding to the target slave device is directly searched from the frequency conversion table, and data access operation is performed on the target slave device based on the preset highest frequency. And performing frequency self-adaptive test on the target slave device in advance to obtain a frequency upper limit corresponding to the target slave device, and performing data access operation on the target slave device by using the frequency upper limit when the target slave device to be accessed is determined to not support frequency conversion. The method fully considers the specificity of each slave device, realizes the self-adaptive automatic adjustment of the slave device frequency, saves labor, improves the bus utilization rate by using the maximum frequency supported by the target slave device as much as possible to access the data, improves the data access efficiency and saves time consumption.
Correspondingly, the invention also provides a data access device, equipment and a computer readable storage medium in the I2C bus corresponding to the data access method in the I2C bus, which have the technical effects and are not repeated herein.
Drawings
In order to more clearly illustrate the embodiments of the invention or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art will be briefly described, it being obvious that the drawings in the following description are only some embodiments of the invention, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of an embodiment of a method for accessing data in an I2C bus according to the present invention;
FIG. 2 is a flow chart of another implementation of a method for accessing data in an I2C bus according to an embodiment of the present invention;
FIG. 3 is a block diagram illustrating a data access system in an I2C bus according to an embodiment of the present invention;
Fig. 4 is a schematic diagram of a connection structure between a frequency conversion system and a main device in an embodiment of the present invention;
FIG. 5 is a block diagram illustrating a data access device in an I2C bus according to an embodiment of the present invention;
FIG. 6 is a block diagram illustrating a data access device in an I2C bus according to an embodiment of the present invention;
Fig. 7 is a schematic diagram of a specific structure of a data access device in an I2C bus according to the present embodiment.
Detailed Description
In order to better understand the aspects of the present invention, the present invention will be described in further detail with reference to the accompanying drawings and detailed description. It will be apparent that the described embodiments are only some, but not all, embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Referring to fig. 1, fig. 1 is a flowchart of an implementation of a method for accessing data in an I2C bus, which is applied to an I2C bus master device, according to an embodiment of the present invention, the method may include the following steps:
s101: and analyzing the received slave device access request to obtain the target slave device to be accessed.
When the upper layer application needs to perform data access on the slave devices in the I2C bus, a slave device access request is generated, and the slave device access request contains a target slave device to be accessed. After the slave access request is generated by the upper layer application, the slave access request is sent to the I2C bus master device, the I2C bus master device receives the slave access request and analyzes the received slave access request to obtain a target slave device to be accessed, so that it is determined which slave device in the I2C bus is specifically required to be subjected to data access by the upper layer application.
S102: and judging whether the target slave device supports frequency conversion, if so, executing step S103, and if not, executing step S104.
After the target slave device to be accessed is obtained through analysis, whether the target slave device supports frequency conversion is judged, if yes, the fact that the target slave device is configured to support manual frequency conversion is indicated, if the target slave device is configured to support 100khz or 400khz in advance, step S103 is executed, if not, the fact that the target slave device is configured to not support manual frequency conversion is indicated, and step S104 is executed.
S103: searching a preset highest frequency corresponding to the target slave device from a preset frequency conversion table, and performing data access operation on the target slave device by utilizing the preset highest frequency.
When the target slave device supports frequency conversion, the fact that the target slave device supports manual frequency conversion is configured in advance is indicated, a frequency conversion table is preset, different frequency values supported by the target slave device are stored in the frequency conversion table, the preset highest frequency is searched from the frequency conversion table corresponding to the target slave device, and data access operation is carried out on the target slave device by using the preset highest frequency, so that data access is carried out on the target slave device by using the maximum frequency supported by the target slave device as much as possible, bus utilization rate is improved, data access efficiency is improved, and time consumption is saved.
S104: and obtaining a frequency upper limit obtained by performing frequency self-adaptive test on the target slave device, and performing data access operation on the target slave device by using the frequency upper limit.
And carrying out frequency self-adaptive test on the target slave device in advance to obtain the frequency upper limit corresponding to the target slave device. When the target slave device is determined to not support frequency conversion, the fact that the target slave device is not configured to support manual frequency conversion is indicated, the frequency upper limit obtained by performing frequency self-adaptive test on the target slave device is obtained, and the data access operation is performed on the target slave device by using the frequency upper limit, so that the maximum frequency supported by the target slave device is utilized to perform data access on the target slave device as much as possible, the bus utilization rate is improved, the data access efficiency is improved, and the time consumption is saved.
According to the technical scheme, when the target slave device to be accessed is determined to support frequency conversion through the preset frequency conversion table, the preset highest frequency corresponding to the target slave device is directly searched from the frequency conversion table, and data access operation is performed on the target slave device based on the preset highest frequency. And performing frequency self-adaptive test on the target slave device in advance to obtain a frequency upper limit corresponding to the target slave device, and performing data access operation on the target slave device by using the frequency upper limit when the target slave device to be accessed is determined to not support frequency conversion. The method fully considers the specificity of each slave device, realizes the self-adaptive automatic adjustment of the slave device frequency, saves labor, improves the bus utilization rate by using the maximum frequency supported by the target slave device as much as possible to access the data, improves the data access efficiency and saves time consumption.
It should be noted that, based on the above embodiments, the embodiments of the present invention further provide corresponding improvements. The following embodiments relate to the same steps as those in the above embodiments or the steps corresponding to the steps may be referred to each other, and the corresponding beneficial effects may also be referred to each other, which will not be described in detail in the following modified embodiments.
Referring to fig. 2, fig. 2 is a flowchart of another implementation of a method for accessing data in an I2C bus, applied to an I2C bus master device, according to an embodiment of the present invention, the method may include the following steps:
S201: and acquiring the reference frequency corresponding to the target slave device from the frequency conversion table.
A frequency conversion table is pre-established, and reference frequencies corresponding to the slave devices are stored in the frequency conversion table, for example, the reference frequency of the slave device can be set to be 100khz. And when the frequency self-adaptive test is carried out on the target slave device, acquiring the reference frequency corresponding to the target slave device from the frequency conversion table.
S202: the reference frequency is taken as the current communication frequency.
After the reference frequency corresponding to the target slave device is acquired, the reference frequency is taken as the current communication frequency, namely, the reference frequency is taken as the current communication frequency between the target slave device and the I2C bus master device.
S203: the current communication frequency is used to communicate with the target slave device.
After the reference frequency is taken as the current communication frequency, the I2C bus master device communicates with the target slave device by using the current communication frequency.
S204: whether the communication is successful is determined, if so, step S205 is executed, and if not, step S209 is executed.
After the I2C bus master communicates with the target slave using the current communication frequency, it may determine whether the communication is successful, if it may be set that when the I2C bus master communicates with the target slave successfully, the target slave returns an acknowledgement character (Acknowledge character, ACK) to the I2C bus master, and the I2C bus master determines whether the communication with the target slave is successful by detecting whether the acknowledgement character of the target slave is received, if so, it indicates that the I2C bus master can successfully communicate with the target slave through the current communication frequency, step S205 is executed, and if not, it indicates that the I2C bus master cannot successfully communicate with the target slave through the current communication frequency, and step S209 is executed.
S205: and up-regulating the current communication frequency by a first preset frequency interval, and determining the regulated frequency as the current communication frequency.
And presetting a first preset frequency interval for carrying out frequency up-regulation when the frequency of the target slave device is adaptively tested, when the I2C bus master device is determined to successfully communicate with the target slave device by utilizing the current communication frequency, indicating that the target slave device supports the current communication frequency, attempting to up-regulate the current communication frequency, up-regulating the current communication frequency by the first preset frequency interval, and determining the regulated frequency as the current communication frequency. In the process of determining the frequency, on the premise of normally completing communication, the clock frequency is improved only when the frequency can be ensured to stably work, and the frequent loss of bus data due to frequent communication failure is avoided.
It should be noted that, the first preset frequency interval may be set and adjusted according to the actual situation, which is not limited in the embodiment of the present invention.
S206: the current communication frequency is used to communicate with the target slave device.
And after the frequency is up-regulated by a first preset frequency interval to obtain a new current communication frequency, for testing the support degree of the target slave device to the newly generated current communication frequency, communicating with the target slave device by using the current communication frequency.
S207: whether the communication fails is judged, if so, step S208 is executed, and if not, step S205 is executed.
And judging whether the communication fails by utilizing the newly generated current communication frequency to communicate with the target slave device, if so, judging that the target slave device does not support the current communication frequency generated by frequency up-regulation, executing step S208, and if not, judging that the target slave device still supports the current communication frequency generated by frequency up-regulation, and executing step S205.
S208: and determining the nearest neighbor pre-rising frequency corresponding to the current communication frequency as a frequency upper limit.
When the newly generated current communication frequency and the target slave device are determined to fail in communication, the fact that the target slave device does not support the current communication frequency generated through frequency up-regulation is indicated, the nearest neighbor pre-up-regulation frequency corresponding to the current communication frequency is determined to be the upper frequency limit, and the frequency value obtained by down-regulating the current communication frequency of the target communication failure by a first preset frequency interval is taken as the upper frequency limit of the target slave device.
S209: and (3) downwards adjusting the current communication frequency by a second preset frequency interval, and determining the adjusted frequency as the current communication frequency.
And presetting a second preset frequency interval for carrying out frequency downregulation when the frequency of the target slave device is adaptively tested, when the I2C bus master device is determined to fail to communicate with the target slave device by utilizing the current communication frequency, indicating that the target slave device does not support the current communication frequency, attempting to downregulate the current communication frequency, downregulating the current communication frequency by the second preset frequency interval, and determining the regulated frequency as the current communication frequency.
It should be noted that, the second preset frequency interval may be set and adjusted according to the actual situation, which is not limited in the embodiment of the present invention. The first preset frequency interval and the second preset frequency interval are only used for distinguishing the up-regulated frequency interval from the down-regulated frequency interval, and the first preset frequency interval and the second preset frequency interval can be the same or different in value and are not limited by the embodiment of the invention.
In one embodiment of the present invention, the method may further comprise the steps of:
when the frequency of the second preset frequency interval is adjusted downwards to reach the upper limit of the preset frequency, the fault zone bit corresponding to the target slave device in the frequency conversion table is modified to be in an enabling state.
The method comprises the steps of presetting a frequency threshold value for performing frequency downregulation on a target slave device from a reference frequency for a second preset frequency interval, determining that the target slave device is in a fault state when the frequency of downregulation on the current communication frequency for the second preset frequency interval reaches a preset frequency upper limit, presetting a fault zone bit in a frequency conversion table, and modifying the fault zone bit corresponding to the target slave device in the frequency conversion table into an enabling state.
S210: the current communication frequency is used to communicate with the target slave device.
And after the frequency is subjected to the frequency down-regulation for a second preset frequency interval to obtain a new current communication frequency, for testing the support degree of the target slave device on the newly generated current communication frequency, communicating with the target slave device by using the current communication frequency.
S211: whether the communication is successful is determined, if so, step S212 is executed, and if not, step S209 is executed.
And judging whether the communication fails by utilizing the newly generated current communication frequency to communicate with the target slave device, if so, executing the step S212 by indicating that the target slave device supports the current communication frequency generated by the frequency down regulation, and if not, executing the step S209 by indicating that the target slave device does not support the current communication frequency generated by the frequency down regulation.
S212: the current communication frequency is taken as the upper frequency limit.
When the newly generated current communication frequency is determined to be successfully communicated with the target slave device, the target slave device is indicated to support the current communication frequency generated through the current frequency down-regulation, and the current communication frequency is taken as the upper frequency limit, namely the newly generated current communication frequency is taken as the maximum frequency supported by the target slave device.
S213: a slave access request is received.
The I2C bus master receives a slave access request sent by an upper layer application.
S214: and performing verification operation on the access request of the slave device.
And presetting a verification condition for verifying the validity of the access request of the slave device sent by the upper-layer application, and performing verification operation on the access request of the slave device by the I2C bus master device after receiving the access request of the slave device. By checking the access request of the slave device, illegal access of the data of the slave device is avoided, and the safety of the system is protected.
S215: and when the verification of the access request of the slave device is passed, the access request of the slave device is analyzed to obtain the target slave device to be accessed.
And when the verification of the access request of the slave device is passed, the access request of the slave device is analyzed to obtain the target slave device to be accessed. By allowing the subsequent specific data access flow after ensuring the access request to the slave device, the security of the data is ensured, and the illegal access of the data is avoided.
S216: and reading the size of the data packet to be accessed corresponding to the target slave device from a preset frequency conversion table.
The size of the data packet to be accessed is stored in the frequency conversion table in advance, and after the target slave device to be accessed is obtained through analysis, the size of the data packet to be accessed corresponding to the target slave device is read from the preset frequency conversion table.
S217: and judging whether the size of the data packet to be accessed exceeds a preset data packet size threshold, if so, executing step S218, and if not, executing step S222.
And (3) presetting a data packet size threshold, judging whether the size of the data packet to be accessed exceeds the preset data packet size threshold after the data packet size corresponding to the target slave device is read from a preset frequency conversion table, if so, executing step S218, and if not, executing step S222, wherein the data packet to be accessed is larger.
It should be noted that, the preset data packet size threshold may be set and adjusted according to the actual situation, which is not limited in the embodiment of the present invention.
S218: and reading a target variable frequency setting flag bit corresponding to the target slave device from the variable frequency table.
The variable frequency table is pre-stored with variable frequency setting zone bits for respectively identifying whether each slave device can support variable frequency setting, when the size of the data packet to be accessed exceeds the preset data packet size threshold value, the data packet to be accessed is larger, and the target variable frequency setting zone bits corresponding to the target slave device are read from the variable frequency table.
S219: and when the multi-slave device is accessed, determining the target access priority corresponding to the target slave device according to the size of the data packet to be accessed.
And when the current access to the multi-slave device is determined, determining the target access priority corresponding to the target slave device according to the size of the data packet to be accessed. If the size of the data packet to be accessed is inversely proportional to the access priority, that is, the smaller the data packet to be accessed is, the higher the access priority is, so that if burst read-write operation exists or if conflict is about to occur, corresponding data access is performed according to the preset access priority.
S220: and judging whether the target variable frequency setting flag bit is supportable for variable frequency setting, if so, executing step S221, and if not, executing step S222.
After the target frequency conversion setting flag bit corresponding to the target slave device is read, judging whether the target frequency conversion setting flag bit is supportable for frequency conversion setting, if so, executing step S221, if not, executing step S222, wherein the target slave device is not supportable for frequency conversion setting by the previous configuration.
S221: searching a preset highest frequency corresponding to the target slave device from the frequency conversion table, and performing data access operation on the target slave device according to the target access priority by utilizing the preset highest frequency.
When the target frequency conversion setting flag bit is confirmed to be supportable in frequency conversion setting, the target slave device is configured in advance to support manual frequency conversion setting, the preset highest frequency corresponding to the target slave device is searched from the frequency conversion table, and data access operation is carried out on the target slave device according to the target access priority by utilizing the preset highest frequency. By accessing the data of the target slave device according to the target access priority, a better anti-collision mechanism is provided under the condition of multiple slave devices, the bus utilization rate is greatly improved, the occurrence of congestion is avoided, and the upper layer resources are saved. Meanwhile, the safety check and fault marking functions greatly improve the safety and stability of the bus.
S222: and obtaining a frequency upper limit obtained by performing frequency self-adaptive test on the target slave device, and performing data access operation on the target slave device according to the target access priority by utilizing the frequency upper limit.
When the frequency conversion setting flag bit of the target is determined to be not supporting frequency conversion setting, the fact that the target slave device is not supporting manual frequency conversion setting is indicated, the frequency upper limit obtained by performing frequency self-adaptive test on the target slave device is obtained, and data access operation is performed on the target slave device according to the target access priority by utilizing the frequency upper limit.
As shown in table 1, table 1 is a frequency conversion table built in the system.
TABLE 1
Wherein each sequence number represents an I2C read-write operation, 256 operations are counted in 8-bit 2-system numbers, and the number is far larger than a conventional operand of an I2C bus. Each I2C operation is determined by the slave address, and the offset address from the device internal registers. The number of bytes (bytes) represents the number of bytes that a read or write operation needs to occupy, where it is not necessary to distinguish between a read operation and a write operation.
The reference frequency may be manually determined from a manual of devices, if manually not entered, according to the I2C protocol reference frequency (100 khz or 400 khz). The upper frequency limit is obtained by the system through an adaptive gradual change test and is updated in real time in daily communication.
The slave device state contains four bits, respectively: high priority (1 is high), fault (1 is fault), busy (1 is busy), disabled (1 is disabled). Priority is a definition of which operation is preferred when a conflict is about to occur, and the remaining time of another operation is delayed for adjustment. A failure indicates that the device is not available. Busy means that the device is currently communicating. Disabling is to intercept all the device communications, the write request is not issued or immediately ended, and the read request is not responded to.
Through the information, the upper layer application and the bottom layer program can accurately know the communication condition of the bus without frequent acquisition, and meanwhile, if sudden read-write operation exists, the function of updating the lookup table can be realized by writing the information according to the priority through the AXI (Advanced eXtensible Interface) bus.
Referring to fig. 3, fig. 3 is a block diagram illustrating a data access system in an I2C bus according to an embodiment of the present invention. First, assume that there are 1 master device 1 and two slave devices AB on the I2C bus, where A, B slave devices have addresses of 0X33, 0X34. Assume that master 1 and a slave have an operation to write 0x88 at offset address 0x01, with a reference frequency of 100khz. There is a read 32 byte operation for B from device offset address 0x2, with a reference frequency of 100khz. The slave device supports frequency conversion by writing a register. The upper layer application is formed by configuring the frequency conversion table as shown in table 2.
TABLE 2
Referring to fig. 4, fig. 4 is a schematic diagram of a connection structure between a frequency conversion system and a main device in an embodiment of the present invention. The self-adaptive frequency conversion system mainly comprises four parts:
(1) And an analysis module: and the data transmitted by the I2C bus is analyzed and correlated with the data in the configuration register, and the related information of the lookup table is updated. In addition, if the verification function is started, read-write operation which does not meet the verification condition can be intercepted, and the system safety is protected.
(2) Frequency conversion table: the system comprises frequency conversion table information which can be accessed by an I2C main device and an upper layer.
(3) Configuration registers: including various conventional detailed configurations including disabling various functions, such as disabling frequency conversion, turning off a frequency conversion table, etc.
(4) The timer is responsible for recording bus time sequence, ensuring the consistency of upper and lower clock frequencies and also used for generating I2C clock signals with corresponding frequencies.
Through the design of the bottom frequency conversion table, the clock scheduling of the whole I2C bus is redistributed, and the whole process is automatically carried out, so that the manpower maintenance cost is saved. And the multi-slave device has a better anti-collision mechanism, so that the bus utilization rate is greatly improved, the occurrence of congestion is avoided, and the upper layer resources are saved. Meanwhile, the safety check and fault marking functions greatly improve the safety and stability of the bus.
Corresponding to the above method embodiment, the present invention further provides a data access device in an I2C bus, which is applied to an I2C bus master, where the data access device in the I2C bus described below and the data access method in the I2C bus described above may be referred to correspondingly.
Referring to fig. 5, fig. 5 is a block diagram illustrating a data access apparatus in an I2C bus according to an embodiment of the present invention, the apparatus may include:
The request analysis module 51 is configured to analyze the received slave access request to obtain a target slave to be accessed;
a first judging module 52, configured to judge whether the target slave device supports frequency conversion;
the first access module 53 is configured to, when it is determined that the target slave device supports frequency conversion, search a preset highest frequency corresponding to the target slave device from a preset frequency conversion table, and perform a data access operation on the target slave device by using the preset highest frequency;
and the second access module 54 is configured to obtain a frequency upper limit obtained by performing the frequency adaptive test on the target slave device when it is determined that the target slave device does not support frequency conversion, and perform a data access operation on the target slave device by using the frequency upper limit.
According to the technical scheme, when the target slave device to be accessed is determined to support frequency conversion through the preset frequency conversion table, the preset highest frequency corresponding to the target slave device is directly searched from the frequency conversion table, and data access operation is performed on the target slave device based on the preset highest frequency. And performing frequency self-adaptive test on the target slave device in advance to obtain a frequency upper limit corresponding to the target slave device, and performing data access operation on the target slave device by using the frequency upper limit when the target slave device to be accessed is determined to not support frequency conversion. The method fully considers the specificity of each slave device, realizes the self-adaptive automatic adjustment of the slave device frequency, saves labor, improves the bus utilization rate by using the maximum frequency supported by the target slave device as much as possible to access the data, improves the data access efficiency and saves time consumption.
In one embodiment of the present invention, the apparatus may further include:
The data packet size reading module is used for reading the data packet size corresponding to the target slave device to be accessed from the frequency conversion table before judging whether the target slave device supports frequency conversion or not;
The second judging module is used for judging whether the size of the data packet to be accessed exceeds a preset data packet size threshold value;
the first judging module is specifically a module for judging whether the target slave device supports frequency conversion or not when the size of the data packet to be accessed exceeds a preset data packet size threshold value;
and the second access module is also used for acquiring a frequency upper limit obtained by performing frequency self-adaptive test on the target slave device when the size of the data packet to be accessed is not beyond the preset data packet size threshold value, and performing data access operation on the target slave device by utilizing the frequency upper limit.
In one embodiment of the present invention, the first judging module includes:
The variable frequency setting flag bit reading sub-module is used for reading a target variable frequency setting flag bit corresponding to a target slave device from a variable frequency table;
And the first judging submodule is used for judging whether the target variable frequency setting flag bit is supportable for variable frequency setting.
In one embodiment of the present invention, the apparatus may further include:
the access priority determining module is used for determining the target access priority corresponding to the target slave device according to the size of the data packet to be accessed;
the first access module is specifically a module for performing data access operation on the target slave device according to the target access priority;
The second access module is specifically a module for performing data access operation on the target slave device according to the target access priority.
In one embodiment of the present invention, the apparatus includes a frequency test module, the frequency test module including:
The reference frequency acquisition sub-module is used for acquiring the reference frequency corresponding to the target slave device from the frequency conversion table;
the current communication frequency determining submodule is used for taking the reference frequency as the current communication frequency;
a communication sub-module for communicating with the target slave device using the current communication frequency;
The second judging submodule is used for judging whether the communication is successful or not;
the frequency up-regulating sub-module is used for up-regulating the current communication frequency by a first preset frequency interval when the communication success is determined, and determining the regulated frequency as the current communication frequency;
The first frequency upper limit determining sub-module is used for repeatedly executing the step of communicating with the target slave device by utilizing the current communication frequency until the communication fails, and determining the nearest neighbor pre-rising frequency corresponding to the current communication frequency when the communication fails as the frequency upper limit;
A frequency downregulation sub-module, configured to downregulate a current communication frequency by a second preset frequency interval when determining that the communication fails, and determine the adjusted frequency as the current communication frequency;
And the second frequency upper limit determining submodule is used for repeatedly executing the step of communicating with the target slave device by utilizing the current communication frequency until the communication is successful, and taking the current communication frequency when the communication is successful as the frequency upper limit.
In one embodiment of the present invention, the apparatus may further include:
the fault zone bit modification module is used for modifying the fault zone bit corresponding to the target slave device in the frequency conversion table into an enabling state when the frequency of the current communication frequency for down-regulating the second preset frequency interval reaches the upper limit of the preset frequency.
In one embodiment of the present invention, the apparatus may further include:
And the request verification module is used for performing verification operation on the access request of the slave device.
Corresponding to the above method embodiment, referring to fig. 6, fig. 6 is a schematic diagram of a data access device in an I2C bus provided by the present invention, where the device may include:
a memory 332 for storing a computer program;
A processor 322 for implementing the steps of the data access method in the I2C bus of the method embodiment described above when executing a computer program.
Specifically, referring to fig. 7, fig. 7 is a schematic diagram of a specific structure of a data access device in an I2C bus according to the present embodiment, where the data access device in the I2C bus may have a relatively large difference due to different configurations or performances, and may include a processor (central processing units, CPU) 322 (e.g., one or more processors) and a memory 332, where the memory 332 stores one or more computer applications 342 or data 344. Wherein the memory 332 may be transient storage or persistent storage. The program stored in memory 332 may include one or more modules (not shown), each of which may include a series of instruction operations in the data processing apparatus. Still further, the processor 322 may be configured to communicate with the memory 332 to execute a series of instruction operations in the memory 332 on the data access device 301 in the I2C bus.
The data access device 301 in the I2C bus may also include one or more power supplies 326, one or more wired or wireless network interfaces 350, one or more input output interfaces 358, and/or one or more operating systems 341.
The steps in the data access method in the I2C bus described above may be implemented by the structure of the data access device in the I2C bus.
Corresponding to the above method embodiments, the present invention also provides a computer readable storage medium having a computer program stored thereon, which when executed by a processor, performs the steps of:
Analyzing the received slave device access request to obtain a target slave device to be accessed; judging whether the target slave device supports frequency conversion or not; if yes, searching a preset highest frequency corresponding to the target slave device from a preset frequency conversion table, and performing data access operation on the target slave device by utilizing the preset highest frequency; if not, acquiring a frequency upper limit obtained by performing frequency self-adaptive test on the target slave device, and performing data access operation on the target slave device by using the frequency upper limit.
The computer readable storage medium may include: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
For the description of the computer-readable storage medium provided by the present invention, refer to the above method embodiments, and the disclosure is not repeated here.
In this specification, each embodiment is described in a progressive manner, and each embodiment is mainly described in a different point from other embodiments, so that the same or similar parts between the embodiments are referred to each other. The apparatus, device and computer readable storage medium of the embodiments are described more simply because they correspond to the methods of the embodiments, and the description thereof will be given with reference to the method section.
The principles and embodiments of the present invention have been described herein with reference to specific examples, but the description of the examples above is only for aiding in understanding the technical solution of the present invention and its core ideas. It should be noted that it will be apparent to those skilled in the art that various modifications and adaptations of the invention can be made without departing from the principles of the invention and these modifications and adaptations are intended to be within the scope of the invention as defined in the following claims.
Claims (8)
1. A method of data access in an I2C bus, applied to an I2C bus master, comprising:
Analyzing the received slave device access request to obtain a target slave device to be accessed;
Judging whether the target slave device supports frequency conversion or not;
If yes, searching a preset highest frequency corresponding to the target slave device from a preset frequency conversion table, and performing data access operation on the target slave device by utilizing the preset highest frequency;
If not, acquiring a frequency upper limit obtained by performing frequency self-adaptive test on the target slave device, and performing data access operation on the target slave device by using the frequency upper limit;
before judging whether the target slave device supports frequency conversion, the method further comprises the following steps:
Reading the size of a data packet to be accessed corresponding to the target slave device from the frequency conversion table;
Judging whether the size of the data packet to be accessed exceeds a preset data packet size threshold value or not;
If yes, executing the step of judging whether the target slave device supports frequency conversion;
If not, executing the step of acquiring the upper frequency limit obtained by performing frequency self-adaptive test on the target slave device;
The process of obtaining the upper frequency limit by carrying out frequency self-adaptive test on the target slave device comprises the following steps:
acquiring the reference frequency corresponding to the target slave device from the frequency conversion table;
Taking the reference frequency as a current communication frequency;
Communicating with the target slave device using the current communication frequency;
judging whether the communication is successful or not;
if yes, the current communication frequency is up-regulated by a first preset frequency interval, and the regulated frequency is determined to be the current communication frequency;
Repeatedly executing the step of utilizing the current communication frequency to communicate with the target slave device until communication fails, and determining the nearest neighbor pre-adjustment frequency corresponding to the current communication frequency when the communication fails as the frequency upper limit;
If not, the current communication frequency is adjusted downwards by a second preset frequency interval, and the adjusted frequency is determined to be the current communication frequency;
and repeatedly executing the step of utilizing the current communication frequency to communicate with the target slave device until the communication is successful, and taking the current communication frequency when the communication is successful as the frequency upper limit.
2. The method of claim 1, wherein determining whether the target slave device supports frequency conversion comprises:
Reading a target variable frequency setting zone bit corresponding to the target slave device from the variable frequency table;
And judging whether the target variable frequency setting flag bit is supportable for variable frequency setting.
3. The method for accessing data in an I2C bus according to claim 2, further comprising, when accessing the multi-slave device, prior to the data access operation to the target slave device:
determining a target access priority corresponding to the target slave device according to the size of the data packet to be accessed;
performing data access operation on the target slave device, including:
And carrying out data access operation on the target slave device according to the target access priority.
4. A method of accessing data in an I2C bus according to any one of claims 1 to 3, further comprising:
and when the frequency of the second preset frequency interval is adjusted downwards for the current communication frequency to reach the upper limit of the preset frequency, modifying the fault zone bit corresponding to the target slave device in the frequency conversion table into an enabling state.
5. The method for accessing data in an I2C bus of claim 1, further comprising:
and performing verification operation on the slave device access request.
6. A data access apparatus in an I2C bus, for use with an I2C bus master, comprising:
The request analysis module is used for analyzing the received access request of the slave device to obtain a target slave device to be accessed;
The data packet size reading module is used for reading the data packet size corresponding to the target slave device to be accessed from the frequency conversion table before judging whether the target slave device supports frequency conversion or not;
The second judging module is used for judging whether the size of the data packet to be accessed exceeds a preset data packet size threshold value;
the first judging module is used for judging whether the target slave device supports frequency conversion or not when the size of the data packet to be accessed exceeds a preset data packet size threshold value;
The first access module is used for searching a preset highest frequency corresponding to the target slave device from a preset frequency conversion table when the target slave device supports frequency conversion, and performing data access operation on the target slave device by utilizing the preset highest frequency;
The second access module is used for acquiring a frequency upper limit obtained by performing frequency self-adaptive test on the target slave device when the size of the data packet to be accessed does not exceed a preset data packet size threshold or the target slave device does not support frequency conversion, and performing data access operation on the target slave device by utilizing the frequency upper limit;
The frequency test module, the frequency test module includes:
The reference frequency acquisition sub-module is used for acquiring the reference frequency corresponding to the target slave device from the frequency conversion table;
the current communication frequency determining submodule is used for taking the reference frequency as the current communication frequency;
a communication sub-module for communicating with the target slave device using the current communication frequency;
The second judging submodule is used for judging whether the communication is successful or not;
the frequency up-regulating sub-module is used for up-regulating the current communication frequency by a first preset frequency interval when the communication success is determined, and determining the regulated frequency as the current communication frequency;
The first frequency upper limit determining sub-module is used for repeatedly executing the step of communicating with the target slave device by utilizing the current communication frequency until the communication fails, and determining the nearest neighbor pre-rising frequency corresponding to the current communication frequency when the communication fails as the frequency upper limit;
A frequency downregulation sub-module, configured to downregulate a current communication frequency by a second preset frequency interval when determining that the communication fails, and determine the adjusted frequency as the current communication frequency;
And the second frequency upper limit determining submodule is used for repeatedly executing the step of communicating with the target slave device by utilizing the current communication frequency until the communication is successful, and taking the current communication frequency when the communication is successful as the frequency upper limit.
7. A data access device in an I2C bus, comprising:
A memory for storing a computer program;
A processor for implementing the steps of the data access method in an I2C bus as claimed in any one of claims 1 to 5 when executing said computer program.
8. A computer readable storage medium, characterized in that the computer readable storage medium has stored thereon a computer program which, when executed by a processor, implements the steps of the data access method in an I2C bus according to any of claims 1 to 5.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110866031.5A CN113672542B (en) | 2021-07-29 | 2021-07-29 | Data access method, device, equipment and storage medium in I2C bus |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110866031.5A CN113672542B (en) | 2021-07-29 | 2021-07-29 | Data access method, device, equipment and storage medium in I2C bus |
Publications (2)
Publication Number | Publication Date |
---|---|
CN113672542A CN113672542A (en) | 2021-11-19 |
CN113672542B true CN113672542B (en) | 2024-05-10 |
Family
ID=78540720
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202110866031.5A Active CN113672542B (en) | 2021-07-29 | 2021-07-29 | Data access method, device, equipment and storage medium in I2C bus |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113672542B (en) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115509983B (en) * | 2022-09-28 | 2025-05-16 | 山东云海国创云计算装备产业创新中心有限公司 | I2C bus communication method, device, equipment and readable medium |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2018040670A1 (en) * | 2016-08-31 | 2018-03-08 | 深圳市中兴微电子技术有限公司 | Frequency reduction method and device for public resource, and computer storage medium |
CN112860495A (en) * | 2019-11-12 | 2021-05-28 | 中兴通讯股份有限公司 | Debugging method of I2C slave device, I2C master device and storage medium |
Family Cites Families (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP4033066B2 (en) * | 2003-05-07 | 2008-01-16 | ソニー株式会社 | Frequency control apparatus, information processing apparatus, frequency control method, and program |
US9507661B2 (en) * | 2011-03-01 | 2016-11-29 | As-International Association E.V. | Bus system having a master and a group of slaves and communication method for interchanging data in said bus system |
KR102580820B1 (en) * | 2016-03-10 | 2023-09-20 | 에스케이하이닉스 주식회사 | Data storage device and operating method thereof |
CN110896543B (en) * | 2018-09-12 | 2021-01-12 | 宁德时代新能源科技股份有限公司 | Battery management system and method and device for transmitting information |
-
2021
- 2021-07-29 CN CN202110866031.5A patent/CN113672542B/en active Active
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2018040670A1 (en) * | 2016-08-31 | 2018-03-08 | 深圳市中兴微电子技术有限公司 | Frequency reduction method and device for public resource, and computer storage medium |
CN112860495A (en) * | 2019-11-12 | 2021-05-28 | 中兴通讯股份有限公司 | Debugging method of I2C slave device, I2C master device and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN113672542A (en) | 2021-11-19 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
KR100380197B1 (en) | Transactions supporting interrupt destination redirection and level triggered interrupt semantics | |
EP1133733B1 (en) | Host controller interface descriptor fetching unit | |
CN107590099A (en) | A kind of more main frames access method, expanding unit and the storage medium of slave | |
KR20010032953A (en) | Mechanism that performs interrupt destination redirection | |
CN109656630B (en) | Configuration space access method, device, framework and storage medium | |
US20140189179A1 (en) | System on chip and method for accessing device on bus | |
CN113672542B (en) | Data access method, device, equipment and storage medium in I2C bus | |
CN111221765A (en) | Communication method and communication system for preventing I2C bus address conflict | |
CN110896372B (en) | I2C link switching method, terminal and storage medium | |
US5958029A (en) | Method and system for efficient message validation | |
CN102830982A (en) | Processor configuring method, device and processor | |
CN111339137A (en) | Data verification method and device | |
US20130019032A1 (en) | Apparatus and method for generating interrupt signal that supports multi-processor | |
CN101387993B (en) | Method and system for dynamically collocating resource for equipment in computer system | |
US6678803B2 (en) | Method and device to use memory access request tags | |
CN116826909A (en) | Automatic access control method and system for terminal resistor | |
CN104424142B (en) | The method and apparatus of shared resource is accessed in a kind of multi-core processor system | |
CN116319320A (en) | A network performance optimization method, system, electronic equipment and medium | |
CN101441497B (en) | Information processing apparatus having memory clock setting function and memory clock setting method | |
WO2008005900A2 (en) | Methods and arrangements for devices to share a common address on a bus | |
CN110569933B (en) | Smart card management device and method | |
CN114221903A (en) | Data transmission method and device | |
CN101739367B (en) | Method and device for storing and controlling various buses | |
CN111697670A (en) | Automatic power distribution method, device, computer equipment and storage medium | |
CN110677353B (en) | Data access method and system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |