CN113672542A - 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 PDF

Info

Publication number
CN113672542A
CN113672542A CN202110866031.5A CN202110866031A CN113672542A CN 113672542 A CN113672542 A CN 113672542A CN 202110866031 A CN202110866031 A CN 202110866031A CN 113672542 A CN113672542 A CN 113672542A
Authority
CN
China
Prior art keywords
frequency
slave device
target slave
data access
target
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.)
Granted
Application number
CN202110866031.5A
Other languages
Chinese (zh)
Other versions
CN113672542B (en
Inventor
林宁亚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shandong Yunhai Guochuang Cloud Computing Equipment Industry Innovation Center Co Ltd
Original Assignee
Shandong Yunhai Guochuang Cloud Computing Equipment Industry Innovation Center Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Shandong Yunhai Guochuang Cloud Computing Equipment Industry Innovation Center Co Ltd filed Critical Shandong Yunhai Guochuang Cloud Computing Equipment Industry Innovation Center Co Ltd
Priority to CN202110866031.5A priority Critical patent/CN113672542B/en
Publication of CN113672542A publication Critical patent/CN113672542A/en
Application granted granted Critical
Publication of CN113672542B publication Critical patent/CN113672542B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/42Bus transfer protocol, e.g. handshake; Synchronisation
    • G06F13/4282Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation 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; if so, 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 using the preset highest frequency; and 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 frequency of the slave device is automatically adjusted in a self-adaptive manner, labor is saved, the utilization rate of the bus is improved, the data access efficiency is improved, and time consumption is saved. The invention also discloses a data access device, equipment and a storage medium in the I2C bus, and has corresponding technical effects.

Description

Data access method, device, equipment and storage medium in I2C bus
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
An Inter-Integrated Circuit (I2C) is a two-wire serial bus, and is used to connect a microcontroller and its peripheral devices, and has the advantages of few interface wires, simple control method, small device packaging form, high communication rate, etc.
I2C transfers information between devices connected to a bus through a Serial Data (SDA) line and a Serial Clock (SCL) line. Each device has a unique address identification. The Master device (Master) is a device which initiates data transfer of the bus and generates a clock signal which allows the transfer, any addressed device is considered to be a Slave device (Slave), and the upper layer application makes data access to 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 applicable clock frequency range of the I2C slave device in advance, that is, within a certain frequency range, select several frequency points for testing, and finally use a compromise frequency to access the slave device. However, if a plurality of slave devices exist in the bus, the bus occupation time is long, time and labor are wasted, the method is only used universally, the specificity of each slave device is not considered, and the data access efficiency is influenced.
In summary, how to effectively solve the problems of long bus occupation time, time and labor waste, influence on data access efficiency and the like of the existing data access mode in the I2C bus is a problem that needs to be solved urgently by 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 manpower, improves the utilization rate of the bus, improves the data access efficiency and saves time; it is another object of the present invention to provide a data access apparatus, device and computer readable storage medium in the I2C bus.
In order to solve the technical problems, the invention provides the following technical scheme:
a data access method in an I2C bus 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;
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 using the preset highest frequency;
if not, acquiring an upper frequency 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 upper frequency limit.
In an 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 obtaining the upper limit of the frequency obtained by carrying out the frequency self-adaptive test on the target slave device.
In a specific embodiment of the present invention, the determining whether the target slave device supports frequency conversion includes:
reading a target frequency conversion setting zone bit corresponding to the target slave device from the frequency conversion table;
and judging whether the target frequency conversion setting zone bit can support frequency conversion setting.
In an embodiment of the present invention, when accessing multiple slave devices, before performing a 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 a data access operation on the target slave device, comprising:
and performing data access operation on the target slave device according to the target access priority.
In an 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 a 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;
if so, adjusting the current communication frequency by a first preset frequency interval, and determining the adjusted frequency as the current communication frequency;
repeatedly executing the step of communicating with the target slave device by using the current communication frequency until communication fails, and determining a nearest neighbor before-adjustment frequency corresponding to the current communication frequency when communication fails as the upper limit of the frequency;
if not, adjusting the current communication frequency down by a second preset frequency interval, and determining the adjusted frequency as the current communication frequency;
and repeatedly executing the step of communicating with the target slave device by using the current communication frequency until the communication is successful, and taking the current communication frequency when the communication is successful as the upper limit of the frequency.
In one embodiment of the present invention, the method further comprises:
and when the frequency of the interval of the second preset frequency which is adjusted downwards to the current communication frequency reaches the upper limit of the preset frequency, the fault zone bit corresponding to the target slave device in the frequency conversion table is modified into an enabling state.
In one embodiment of the present invention, the method further comprises:
and performing a verification operation on the slave device access request.
A data access device in an I2C bus, which is applied to an I2C bus master device, and comprises:
the request analysis module is used for analyzing the received slave device access request to obtain a target slave device to be accessed;
the first judgment module is used for judging whether the target slave device supports frequency conversion;
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 is determined to support frequency conversion, and performing data access operation on the target slave device by using the preset highest frequency;
and the second access module is used for acquiring an upper frequency 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 upper frequency 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, carries out the steps of the data access method in the I2C bus as previously described.
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; if so, 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 using the preset highest frequency; and 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, the frequency conversion table is preset, when the target slave device to be accessed supports frequency conversion, the preset highest frequency corresponding to the target slave device is directly searched from the frequency conversion table, and data access operation is conducted 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 does not support frequency conversion. The particularity of each slave device is fully considered, the frequency of the slave device is automatically adjusted in a self-adaptive mode, labor is saved, data access is performed on the slave device through the maximum frequency supported by the target slave device as far as possible, the bus utilization rate is improved, the data access efficiency is improved, and time consumption is reduced.
Correspondingly, the invention further provides a data access device, a device 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 described above and are not described herein again.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
FIG. 1 is a flowchart of an implementation of a method for accessing data in an I2C bus according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating another embodiment of a method for accessing data in an I2C bus according to the present invention;
FIG. 3 is a block diagram of 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 according to an embodiment of the present invention;
FIG. 5 is a block diagram of a data access device in an I2C bus according to an embodiment of the present invention;
FIG. 6 is a block diagram of a data access device in an I2C bus according to an embodiment of the present invention;
fig. 7 is a schematic structural diagram of a data access device in an I2C bus according to this embodiment.
Detailed Description
In order that those skilled in the art will better understand the disclosure, the invention will be described in further detail with reference to the accompanying drawings and specific embodiments. It is to be understood that the described embodiments are merely exemplary of the invention, and not restrictive of the full scope of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, fig. 1 is a flowchart of an implementation of a data access method in an I2C bus, applied to an I2C bus master device, where the method may include the following steps:
s101: and analyzing the received slave device access request to obtain a target slave device to be accessed.
When an upper-layer application needs to perform data access on a slave device 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 generating a slave device access request, the upper layer application sends the slave device access request to the I2C bus master device, and the I2C bus master device receives the slave device access request and analyzes the received slave device access request to obtain a target slave device to be accessed, so as to determine to which slave device in the I2C bus the upper layer application specifically needs to perform data access.
S102: and judging whether the target slave device supports frequency conversion, if so, executing the step S103, and if not, executing the 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, it is indicated that the previous configuration target slave device supports manual frequency conversion setting, if the previous configuration target slave device supports 100khz or 400khz, step S103 is executed, and if not, it is indicated that the previous configuration target slave device does not support manual frequency conversion setting, step S104 is executed.
S103: and searching the 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 using the preset highest frequency.
When the target slave device supports the frequency conversion, the fact that the target slave device supports manual frequency conversion 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 conducted on the target slave device through the preset highest frequency, so that data access is conducted on the target slave device through the maximum frequency supported by the target slave device as far as possible, the bus utilization rate is improved, the data access efficiency is improved, and time consumption is saved.
S104: and 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.
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 does not support frequency conversion, the fact that the target slave device does not support manual frequency conversion setting is explained, the upper frequency 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 by using the upper frequency limit, so that data access is performed on the target slave device by using the maximum frequency supported by the target slave device as much as possible, the bus utilization rate is improved, the data access efficiency is improved, and time consumption is saved.
According to the technical scheme, the frequency conversion table is preset, when the target slave device to be accessed supports frequency conversion, the preset highest frequency corresponding to the target slave device is directly searched from the frequency conversion table, and data access operation is conducted 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 does not support frequency conversion. The particularity of each slave device is fully considered, the frequency of the slave device is automatically adjusted in a self-adaptive mode, labor is saved, data access is performed on the slave device through the maximum frequency supported by the target slave device as far as possible, the bus utilization rate is improved, the data access efficiency is improved, and time consumption is reduced.
It should be noted that, based on the above embodiments, the embodiments of the present invention also provide corresponding improvements. In the following embodiments, steps that are the same as or correspond to those in the above embodiments may be referred to one another, and corresponding advantageous effects may also be referred to one another, which is not described in detail in the following modified embodiments.
Referring to fig. 2, fig. 2 is a flowchart of another implementation of a data access method in an I2C bus according to an embodiment of the present invention, applied to an I2C bus master device, where 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 established in advance, reference frequencies corresponding to the slave devices are stored in the frequency conversion table, and the reference frequency of the slave device can be set to be 100khz, for example. When the frequency self-adaptive test is carried out on the target slave device, the reference frequency corresponding to the target slave device is obtained from the frequency conversion table.
S202: the reference frequency is taken as the current communication frequency.
After acquiring the reference frequency corresponding to the target slave device, the reference frequency is used as the current communication frequency, that is, the reference frequency is used as the current communication frequency between the target slave device and the I2C bus master device.
S203: and communicating with the target slave device by using the current communication frequency.
After taking the reference frequency as the current communication frequency, the I2C bus master communicates with the target slave device using the current communication frequency.
S204: it is determined whether the communication is successful, if so, step S205 is executed, and if not, step S209 is executed.
After the I2C bus master device communicates with the target slave device by using the current communication frequency, whether the communication is successful is judged, if so, when the I2C bus master device communicates with the target slave device successfully, the target slave device returns an Acknowledgement Character (ACK) to the I2C bus master device, the I2C bus master device determines whether the communication with the target slave device is successful by detecting whether the acknowledgement character of the target slave device is received, if so, the I2C bus master device can communicate with the target slave device successfully through the current communication frequency, step S205 is executed, if not, the I2C bus master device cannot communicate with the target slave device successfully through the current communication frequency, and step S209 is executed.
S205: and adjusting the current communication frequency by a first preset frequency interval, and determining the adjusted frequency as the current communication frequency.
The method comprises the steps of presetting a first preset frequency interval for carrying out frequency up-regulation on a target slave device during frequency self-adaptive test, when the I2C bus master device is determined to successfully communicate with the target slave device by using a current communication frequency, indicating that the target slave device supports the current communication frequency, trying 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 finishing communication, the clock frequency is improved only when the frequency can stably work, and the frequent loss of bus data caused by frequent communication failure is avoided.
It should be noted that the first preset frequency interval may be set and adjusted according to actual situations, which is not limited in the embodiment of the present invention.
S206: and communicating with the target slave device by using the current communication frequency.
After the frequency is adjusted up by the first preset frequency interval to obtain a new current communication frequency, the current communication frequency is utilized to communicate with the target slave device for testing the support degree of the target slave device to the newly generated current communication frequency.
S207: and judging whether the communication fails, if so, executing step S208, and if not, executing step S205.
And judging whether the communication fails by communicating with the target slave device by using the newly generated current communication frequency, if so, indicating that the target slave device does not support the current communication frequency generated by the frequency up-regulation, executing step S208, otherwise, indicating that the target slave device still supports the current communication frequency generated by the frequency up-regulation, and executing step S205.
S208: and determining the nearest neighbor pre-up frequency corresponding to the current communication frequency as the upper frequency limit.
When the newly generated current communication frequency and the target slave device are determined to be failed in communication, the target slave device does not support the current communication frequency generated by frequency up-regulation, the nearest neighbor frequency before up-regulation corresponding to the current communication frequency is determined as the upper frequency limit, and a frequency value obtained by down-regulating the current communication frequency failed in target communication by a first preset frequency interval is used as the upper frequency limit of the target slave device.
S209: and adjusting the current communication frequency by a second preset frequency interval, and determining the adjusted frequency as the current communication frequency.
Presetting a second preset frequency interval for carrying out frequency down-regulation on the target slave device during the frequency self-adaptive test, when the I2C bus master device is determined to fail to communicate with the target slave device by using the current communication frequency, indicating that the target slave device does not support the current communication frequency, trying to down-regulate the current communication frequency, down-regulating the current communication frequency by using 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 actual situations, which is not limited in the embodiment of the present invention. The first and second preset frequency intervals are only to distinguish the up-regulation frequency interval from the down-regulation frequency interval, and have no order or magnitude, and the values of the first preset frequency interval and the second preset frequency interval may be the same or different, which is not limited in the embodiments of the present invention.
In one embodiment of the present invention, the method may further comprise the steps of:
and when the frequency of the interval of the second preset frequency which is adjusted downwards to the current communication frequency reaches the upper limit of the preset frequency, the fault zone bit corresponding to the target slave device in the frequency conversion table is modified into an enabling state.
Presetting a frequency threshold value of a second preset frequency interval for carrying out frequency down-regulation on the target slave device from the reference frequency, determining that the target slave device is in a fault state when the frequency of the second preset frequency interval for down-regulating the current communication frequency 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: and communicating with the target slave device by using the current communication frequency.
And after the frequency is adjusted downwards by a second preset frequency interval to obtain a new current communication frequency, the current communication frequency is utilized to communicate with the target slave device for testing the support degree of the target slave device to the newly generated 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 determining whether the communication fails by using the newly generated current communication frequency to communicate with the target slave device, if so, indicating that the target slave device supports the current communication frequency generated by the frequency down-regulation, executing step S212, otherwise, indicating that the target slave device still does not support the current communication frequency generated by the frequency down-regulation, and executing step S209.
S212: the current communication frequency is taken as the upper frequency limit.
When the communication between the newly generated current communication frequency and the target slave device is determined to be successful, the target slave device supports the current communication frequency generated by the current frequency down-regulation, and the current communication frequency is used as an upper frequency limit, namely the newly generated current communication frequency is 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: a verification operation is performed on the slave access request.
A verification condition for verifying the validity of a slave device access request sent by an upper-layer application is preset, and the I2C bus master device performs verification operation on the slave device access request after receiving the slave device access request. By checking the access request of the slave device, the illegal access of the data of the slave device is avoided, and the safety of the system is protected.
S215: and when the access request of the slave device passes the verification, analyzing the access request of the slave device to obtain a target slave device to be accessed.
And when the access request of the slave device passes the verification, analyzing the access request of the slave device to obtain a target slave device to be accessed. By allowing subsequent specific data access flow after the slave device access request is ensured, the safety of data is ensured, and the data is prevented from being illegally accessed.
S216: and reading the size of the data packet to be accessed corresponding to the target slave device from a preset frequency conversion table.
And storing the size of the data packet to be accessed in a frequency conversion table in advance, and reading the size of the data packet to be accessed corresponding to the target slave device from the preset frequency conversion table after the target slave device to be accessed is obtained through analysis.
S217: it is determined whether the size of the data packet to be accessed exceeds a predetermined threshold, if yes, step S218 is executed, and if not, step S222 is executed.
Presetting a data packet size threshold, after reading the size of a data packet to be accessed corresponding to a target slave device from a preset frequency conversion table, judging whether the size of the data packet to be accessed exceeds the preset data packet size threshold, if so, indicating that the data packet to be accessed is larger, executing step S218, otherwise, indicating that the data packet to be accessed is smaller, and executing step S222.
It should be noted that the preset data packet size threshold may be set and adjusted according to actual situations, which is not limited in the embodiment of the present invention.
S218: and reading a target frequency conversion setting zone bit corresponding to the target slave device from the frequency conversion table.
The method comprises the steps that frequency conversion setting zone bits for respectively identifying whether each slave device can support frequency conversion setting are stored in a frequency conversion table in advance, when the size of a data packet to be accessed is determined to exceed a preset data packet size threshold value, the data packet to be accessed is large, and a target frequency conversion setting zone bit corresponding to a target slave device is read from the frequency conversion table.
S219: and when the multiple slave devices are 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 multiple slave devices 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 set to be 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 corresponding data access is performed according to the preset access priority if a burst read-write operation exists or when a conflict is about to occur.
S220: and judging whether the target frequency conversion setting flag bit can support frequency conversion setting, if so, executing step 221, and if not, executing step 222.
After reading the target frequency conversion setting flag bit corresponding to the target slave device, judging whether the target frequency conversion setting flag bit is capable of supporting frequency conversion setting, if so, indicating that the slave device of the previous configuration target supports manual frequency conversion setting, executing step S221, otherwise, indicating that the slave device of the previous configuration target does not support manual frequency conversion setting, and executing step S222.
S221: and searching the 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 using the preset highest frequency.
When the target frequency conversion setting flag bit is determined to be supportable frequency conversion setting, it is indicated that the previously configured target slave device supports 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 performed on the target slave device according to the target access priority by using the preset highest frequency. By carrying out data access on the target slave devices 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 upper-layer resources are saved. Meanwhile, the safety verification and fault marking functions greatly improve the safety and stability of the bus.
S222: and 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 according to the target access priority by using the frequency upper limit.
When the target frequency conversion setting flag bit is determined to be not supporting frequency conversion setting, the previously configured target slave device does not support manual frequency conversion setting, the upper frequency 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 using the upper frequency limit.
As shown in table 1, table 1 is a frequency conversion table built in the system.
TABLE 1
Figure BDA0003187373350000111
Wherein, each serial number represents an I2C read-write operation, and the 8-bit 2-system number totals 256 operations, which is much larger than the conventional operand of an I2C bus. Each I2C operation is determined by the slave device address, and the offset address of the slave device internal register. The Byte (Byte) number indicates the number of bytes that a read operation or a write operation needs to occupy, and there is no need to distinguish between a read operation and a write operation.
The reference frequency may be determined manually from a device manual and, if not manually entered, follows the I2C protocol reference frequency (100khz or 400 khz). The upper frequency limit is obtained by the system through self-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 priority), failed (1 is failed), busy (1 is busy), disabled (1 is disabled). Priority is the definition of which operation is preferred when a conflict is about to occur, and the remaining time of another operation is delayed from adjustment. Failure indicates that the device is unable to obtain a response. Busy indicates that the device is currently communicating. Disabling is to intercept all communications of the device, write requests are not issued or are immediately terminated, and read requests are 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 in the AXI (advanced eXtensible interface) bus according to the priority.
Referring to fig. 3, fig. 3 is a block diagram of a data access system in an I2C bus according to an embodiment of the present invention. First, assume that there are 1 master 1, two slaves AB on the I2C bus, where the addresses of the A, B slaves are 0X33, 0X 34. Assume master 1 and a slave offset address 0x01 have write 0x88 operation, with a reference frequency of 100 khz. There is a 32 byte read operation for B from device offset address 0x2, with a reference frequency of 100 khz. The slave device supports frequency conversion through a write register. The upper layer application is formed as shown in table 2 by configuring the frequency conversion table.
TABLE 2
Figure BDA0003187373350000121
Referring to fig. 4, fig. 4 is a schematic diagram of a connection structure between a frequency conversion system and a master device in an embodiment of the present invention. The self-adaptive frequency conversion system is mainly composed of four parts:
(1) an analysis module: and the data analysis module is responsible for analyzing the data transmitted by the I2C bus, correlating the data with the data in the configuration register and updating the related information of the lookup table. In addition, if the verification function is started, the read-write operation which does not meet the verification condition can be intercepted, and the system safety is protected.
(2) A frequency conversion meter: contains frequency conversion table information which can be accessed by the master device and the upper layer of the I2C.
(3) A register is configured: including various conventional detailed configurations including disabling of various functions such as disabling of frequency conversion, turning off of frequency conversion tables, etc.
(4) And the timer is used for recording the bus time sequence, ensuring that the upper clock frequency and the lower clock frequency are consistent, and is also used for generating an I2C clock signal with the corresponding frequency.
Through the design of the bottom layer frequency conversion meter, the clock scheduling of the whole I2C bus is redistributed, the whole process is automatically carried out, and the labor maintenance cost is saved. And a better anti-collision mechanism is provided under the condition of multiple slave devices, so that the bus utilization rate is greatly improved, the occurrence of congestion is avoided, and upper-layer resources are saved. Meanwhile, the safety verification 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 the I2C bus, which is applied to the I2C bus master device, and the data access device in the I2C bus described below and the data access method in the I2C bus described above can be referred to correspondingly.
Referring to fig. 5, fig. 5 is a block diagram of a data access apparatus in an I2C bus according to an embodiment of the present invention, where the apparatus may include:
a request analysis module 51, configured to analyze a received slave device access request to obtain a target slave device 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 accessing module 54 is configured to, when it is determined that the target slave device does not support frequency conversion, obtain an upper frequency limit obtained by performing a frequency adaptive test on the target slave device, and perform a data access operation on the target slave device by using the upper frequency limit.
According to the technical scheme, the frequency conversion table is preset, when the target slave device to be accessed supports frequency conversion, the preset highest frequency corresponding to the target slave device is directly searched from the frequency conversion table, and data access operation is conducted 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 does not support frequency conversion. The particularity of each slave device is fully considered, the frequency of the slave device is automatically adjusted in a self-adaptive mode, labor is saved, data access is performed on the slave device through the maximum frequency supported by the target slave device as far as possible, the bus utilization rate is improved, the data access efficiency is improved, and time consumption is reduced.
In one embodiment of the present invention, the apparatus may further include:
the data packet size reading module is used for reading the size of the data packet to be accessed corresponding to the target slave device from the frequency conversion table before judging whether the target slave device supports frequency conversion;
the second judgment module is used for judging whether the size of the data packet to be accessed exceeds a preset data packet size threshold value or not;
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 further used for acquiring a frequency upper limit obtained by performing a frequency self-adaptive test on the target slave device when the size of the data packet to be accessed is determined not to exceed the preset data packet size threshold, and performing data access operation on the target slave device by using the frequency upper limit.
In one embodiment of the present invention, the first determining module includes:
the frequency conversion setting zone bit reading submodule is used for reading a target frequency conversion setting zone bit corresponding to a target slave device from the frequency conversion table;
and the first judgment submodule is used for judging whether the target frequency conversion setting zone bit can support frequency conversion setting.
In one embodiment of the present invention, the apparatus may further include:
the access priority determining module is used for determining a 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 a 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 submodule is used for acquiring the reference frequency corresponding to the target slave device from the frequency conversion table;
a current communication frequency determination submodule for taking the reference frequency as the current communication frequency;
the communication submodule is used for communicating with the target slave device by using the current communication frequency;
the second judgment submodule is used for judging whether the communication is successful;
the frequency up-regulation sub-module is used for up-regulating the current communication frequency by a first preset frequency interval when the communication is determined to be successful, and determining the regulated frequency as the current communication frequency;
a first frequency upper limit determining submodule, configured to repeatedly perform the step of communicating with the target slave device by using the current communication frequency until communication fails, and determine, as a frequency upper limit, a nearest neighbor pre-up frequency corresponding to the current communication frequency when communication fails;
the frequency down-regulation module is used for down-regulating the current communication frequency by a second preset frequency interval when the communication failure is determined, and determining the regulated 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 using 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:
and 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 interval of the second preset frequency which is adjusted downwards to the current communication frequency reaches the upper limit of the preset frequency.
In one embodiment of the present invention, the apparatus may further include:
and the request checking module is used for checking 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 above-described method embodiment when executing the computer program.
Specifically, referring to fig. 7, fig. 7 is a schematic diagram illustrating a specific structure of a data access device in an I2C bus provided in this embodiment, the data access device in the I2C bus may generate a relatively large difference due to different configurations or performances, and may include a processor (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. Memory 332 may be, among other things, transient or persistent storage. The program stored in memory 332 may include one or more modules (not shown), each of which may include a sequence of instructions operating on a data processing device. 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 embodiment, the present invention further provides a computer-readable storage medium having a computer program stored thereon, the computer program, when executed by a processor, implementing 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; if so, 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 using the preset highest frequency; and 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: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
For the introduction of the computer-readable storage medium provided by the present invention, please refer to the above method embodiments, which are not described herein again.
The embodiments are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same or similar parts among the embodiments are referred to each other. The device, the apparatus and the computer-readable storage medium disclosed in the embodiments correspond to the method disclosed in the embodiments, so that the description is simple, and the relevant points can be referred to the description of the method.
The principle and the implementation of the present invention are explained in the present application by using specific examples, and the above description of the embodiments is only used to help understanding the technical solution and the core idea of the present invention. It should be noted that, for those skilled in the art, it is possible to make various improvements and modifications to the present invention without departing from the principle of the present invention, and those improvements and modifications also fall within the scope of the claims of the present invention.

Claims (10)

1. A data access method in an I2C bus is characterized in that, when applied to an I2C bus master device, the method 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;
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 using the preset highest frequency;
if not, acquiring an upper frequency 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 upper frequency limit.
2. The method of claim 1, further comprising, prior to determining whether the target slave device supports frequency translation:
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 obtaining the upper limit of the frequency obtained by carrying out the frequency self-adaptive test on the target slave device.
3. The method of claim 2, wherein determining whether the target slave device supports frequency translation comprises:
reading a target frequency conversion setting zone bit corresponding to the target slave device from the frequency conversion table;
and judging whether the target frequency conversion setting zone bit can support frequency conversion setting.
4. The data access method in the I2C bus according to claim 3, wherein when accessing multiple slave devices, before performing data access operation on the target slave device, further comprising:
determining a target access priority corresponding to the target slave device according to the size of the data packet to be accessed;
performing a data access operation on the target slave device, comprising:
and performing data access operation on the target slave device according to the target access priority.
5. The data access method in the I2C bus according to any one of claims 2-4, wherein the process of performing frequency adaptive test on the target slave device to obtain the upper frequency limit comprises:
acquiring a 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;
if so, adjusting the current communication frequency by a first preset frequency interval, and determining the adjusted frequency as the current communication frequency;
repeatedly executing the step of communicating with the target slave device by using the current communication frequency until communication fails, and determining a nearest neighbor before-adjustment frequency corresponding to the current communication frequency when communication fails as the upper limit of the frequency;
if not, adjusting the current communication frequency down by a second preset frequency interval, and determining the adjusted frequency as the current communication frequency;
and repeatedly executing the step of communicating with the target slave device by using the current communication frequency until the communication is successful, and taking the current communication frequency when the communication is successful as the upper limit of the frequency.
6. The method of claim 5, further comprising:
and when the frequency of the interval of the second preset frequency which is adjusted downwards to the current communication frequency reaches the upper limit of the preset frequency, the fault zone bit corresponding to the target slave device in the frequency conversion table is modified into an enabling state.
7. The method of data access in an I2C bus of claim 1, further comprising:
and performing a verification operation on the slave device access request.
8. A data access device in an I2C bus, which is applied to an I2C bus master device and comprises:
the request analysis module is used for analyzing the received slave device access request to obtain a target slave device to be accessed;
the first judgment module is used for judging whether the target slave device supports frequency conversion;
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 is determined to support frequency conversion, and performing data access operation on the target slave device by using the preset highest frequency;
and the second access module is used for acquiring an upper frequency 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 upper frequency limit.
9. 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 of any one of claims 1-7 when executing the computer program.
10. A computer-readable storage medium, having stored thereon a computer program which, when being executed by a processor, carries out the steps of the method for data access in an I2C bus according to any one of claims 1 to 7.
CN202110866031.5A 2021-07-29 2021-07-29 Data access method, device, equipment and storage medium in I2C bus Active CN113672542B (en)

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 true CN113672542A (en) 2021-11-19
CN113672542B 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)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060212247A1 (en) * 2003-05-07 2006-09-21 Sony Corporation Frequency control apparatus, information processing apparatus and program
US20140025854A1 (en) * 2011-03-01 2014-01-23 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
US20170262173A1 (en) * 2016-03-10 2017-09-14 SK Hynix Inc. Data storage device and operating method thereof
WO2018040670A1 (en) * 2016-08-31 2018-03-08 深圳市中兴微电子技术有限公司 Frequency reduction method and device for public resource, and computer storage medium
US20200083730A1 (en) * 2018-09-12 2020-03-12 Contemporary Amperex Technology Co., Limited Battery management system, and method and apparatus for transmitting information
CN112860495A (en) * 2019-11-12 2021-05-28 中兴通讯股份有限公司 Debugging method of I2C slave device, I2C master device and storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060212247A1 (en) * 2003-05-07 2006-09-21 Sony Corporation Frequency control apparatus, information processing apparatus and program
US20140025854A1 (en) * 2011-03-01 2014-01-23 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
US20170262173A1 (en) * 2016-03-10 2017-09-14 SK Hynix Inc. Data storage device and operating method thereof
WO2018040670A1 (en) * 2016-08-31 2018-03-08 深圳市中兴微电子技术有限公司 Frequency reduction method and device for public resource, and computer storage medium
US20200083730A1 (en) * 2018-09-12 2020-03-12 Contemporary Amperex Technology Co., Limited Battery management system, and method and apparatus for transmitting information
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
CN113672542B (en) 2024-05-10

Similar Documents

Publication Publication Date Title
CN108683604B (en) Concurrent access control method, terminal device, and medium
CN111737173B (en) I2C bus communication control method, device, system and readable storage medium
EP1133733B1 (en) Host controller interface descriptor fetching unit
CN107590099B (en) Method for accessing slave machines by multiple hosts, extension device and storage medium
KR20010032953A (en) Mechanism that performs interrupt destination redirection
JPH0690699B2 (en) Interrupt interface circuit
CN102983989B (en) Removing method, device and equipment of server virtual address
CN111221765A (en) Communication method and communication system for preventing I2C bus address conflict
CN110896372B (en) I2C link switching method, terminal and storage medium
CN113114707A (en) Rule filtering method for power chip Ethernet controller
CN113672542A (en) Data access method, device, equipment and storage medium in I2C bus
US20040068598A1 (en) Multiprocessor system having interrupt controller
CN114185837A (en) System on chip and method for adjusting voltage and frequency
CN110990313B (en) Method, equipment and storage medium for processing clock stretching of I3C bus
CN114692191A (en) Data desensitization method, device and storage system
KR20160134994A (en) Interrupt processing method in modular plc system
CN112671561B (en) Network card configuration method and equipment of cloud host
CN116756078B (en) Notification method and device of pcie data packet and storage medium
CN112115451B (en) Method for identifying hot plug hardware USB dongle in Docker container of ARM architecture
CN114265627A (en) Method, system and device for modifying BIOS parameter to adapt to intelligent network card
WO2022022250A1 (en) Interrupt processing method, apparatus and system, and device and storage medium
CN112925730A (en) PCIe equipment link training control method and system
CN113919014A (en) Control method for USB user isolation
CN114185839A (en) System on chip and method for adjusting voltage and frequency
CN114185838A (en) System on chip and method for adjusting voltage and frequency

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