A data transmission method, a BMC chip and a server
By dynamically initializing the mode switching method of the I2C controller, the problem that the I2C controller cannot automatically switch between master and slave modes during the operation of the operating system is solved. Flexible switching of the I2C controller during the operation of the operating system is achieved, supporting complex data transmission protocols and communication with external devices.
Patent Information
- Application Number
- CN202410147037.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-01
- Publication Date
- 2025-10-24
- Estimated Expiration
- 2044-02-01
AI Technical Summary
Some I2C controllers cannot automatically switch between master and slave modes while the operating system is running, resulting in data transmission interruption and inability to support data exchange with certain transmission protocols such as the MCTP protocol.
By dynamically initializing command words and initialization parameters, the controller switches modes during the operation of the operating system, including canceling the current initialization state, registering interrupts and callback functions, and configuring new mode parameters to achieve dynamic initialization of the I2C controller.
It realizes flexible switching of the master and slave modes of the I2C controller during the operation of the operating system, supports complex data transmission protocols and communication requirements of external devices, and avoids data transmission interruptions.
Smart Images

Figure CN118132492B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application relates to the technical field of servers, and in particular to a data transmission method, a BMC chip and a server. BACKGROUND
[0002] The controller plays a bridging role between the operating system kernel and the hardware device, and is responsible for implementing instruction issuing and data uploading.
[0003] The operating system kernel sends instructions to the controller (such as an I2C controller, an SPI controller and an I3C controller) through a specific communication protocol (such as I2C, SPI and I3C), and the controller forwards the instructions to the hardware device to achieve control of the hardware device. The instructions may be, for example, read data, write data, register configuration and the like.
[0004] Taking an I2C controller as an example, the operating system kernel sends instructions to the I2C controller based on the I2C protocol. In the operating system, an Inter-Integrated Circuit (I2C) driver is responsible for supporting and interpreting the I2C protocol at the software level, and the I2C driver is responsible for controlling and managing various external devices mounted on the I2C bus. The I2C driver provides an access interface to the I2C bus and the external devices mounted on the I2C bus, allowing the operating system or an application program to communicate with the I2C devices mounted on the I2C bus.
[0005] When the operating system or the application program controls the external device, the operating system or the application program communicates with the I2C controller through the I2C interface provided by the I2C driver, sends instructions and data, and thus achieves data exchange between the operating system or the application program and the external device mounted on the I2C bus.
[0006] Data transmission between the master device and the slave device in the communication process is divided into two modes, namely master mode and slave mode. The master mode refers to control of the bus by the master device (such as the I2C controller) and sending of data to the slave device (such as the external device mounted on the I2C bus). The slave mode refers to waiting for the command of the master device by the slave device and replying to the command or data.
[0007] The I2C controller usually needs to switch between master mode and slave mode according to different data transmission modes, thereby supporting data exchange between the operating system or the application program and the external device mounted on the I2C bus.
[0008] However, some I2C controllers do not support automatic switching between master and slave modes during the running of an operating system, and the master-slave mode switching of the I2C controller can be realized only by restarting the operating system and initializing the I2C controller. For some transmission protocols (such as the management control transmission protocol), the I2C controller needs to switch between the master and slave modes during the running of the operating system to realize data interaction between the I2C controller and an external device. If the master-slave mode switching of the I2C controller is realized by restarting the operating system, the data transmission will be interrupted, and the data interaction will fail. SUMMARY
[0009] Therefore, embodiments of the present application provide a data transmission method, a BMC chip and a server, and aim to solve the problem that some I2C controllers cannot automatically switch between master and slave modes and do not support transmission protocols that need to switch between master and slave modes of the I2C controller during the running of an operating system.
[0010] In a first aspect, embodiments of the present application provide a data transmission method applied to a first device, and the method comprises the following steps.
[0011] In the embodiments of the present application, during data transmission between the first device and a second device, that is, during the running of an operating system of the first device, the first device can control the controller to switch between modes, so as to accurately transmit data to the second device or receive data from the second device through the controller. For example, after the first device transmits data to the second device, the first device can control the controller to switch from the first mode to the second mode.
[0012] In a possible implementation manner, the first device controls the controller in the first mode to switch from the first mode to the second mode, comprising the following steps.
[0013] The first device switches the mode of the controller according to a dynamic initialization command word and an initialization parameter. The dynamic initialization command word is used to instruct dynamic initialization of the mode of the controller, and the dynamic initialization of the mode of the controller refers to switching the mode of the controller during data transmission. The initialization parameter is used to indicate the mode required to be switched by the controller.
[0014] In the embodiments of the present application, the function of dynamically initializing the mode of the controller can be called through the dynamic initialization command word, and the mode required to be switched by the controller can be indicated through the initialization parameter, so as to realize dynamic initialization of the mode of the controller.
[0015] In a possible implementation, the operating system of the first device comprises an application layer and a driver layer; and the first device performs mode switching of the controller according to a dynamic initialization command word and initialization parameters, comprising:
[0016] The application layer invokes a command function in a character device to send the dynamic initialization command word and the initialization parameters to the driver layer;
[0017] The driver layer controls the controller to switch to a mode indicated by the initialization parameters according to the dynamic initialization command word and the initialization parameters.
[0018] In the embodiment of the application, the character device of the operating system of the first device comprises a command function for invoking a dynamic initialization I2C controller mode function, and the application layer can send a dynamic initialization command word and initialization parameters to the driver layer through the command function, so that the driver can be invoked through the dynamic initialization command word during the operation of the operating system, and the function of dynamically initializing the controller mode is realized. Then, the driver layer dynamically initializes the controller according to the dynamic initialization command word and the initialization parameters.
[0019] The driver layer is, for example, an I2C driver layer.
[0020] In a possible implementation, the driver layer comprises a control layer and a chip adaptation layer; and the driver layer controls the controller to switch to a mode indicated by the initialization parameters according to the dynamic initialization command word and the initialization parameters, comprising:
[0021] The control layer invokes an interface function corresponding to the dynamic initialization command word to send the initialization parameters to the chip adaptation layer;
[0022] The chip adaptation layer dynamically initializes the controller according to the initialization parameters, and switches the controller to the mode indicated by the initialization parameters.
[0023] In the embodiment of the application, the control layer comprises an interface function for dynamically initializing the controller, and the chip adaptation layer performs the function of dynamically initializing the I2C controller. When the control layer receives the dynamic initialization command word, the interface function corresponding to the dynamic initialization command word is invoked to send the initialization parameters to the chip adaptation layer; and the chip adaptation layer dynamically initializes the controller according to the initialization parameters.
[0024] In a possible implementation, the chip adaptation layer dynamically initializes the controller according to the initialization parameters, and switches the controller to the mode indicated by the initialization parameters, comprising:
[0025] The chip adaptation layer cancels the initialization state of the controller and dynamically initializes the mode of the controller according to the initialization parameter.
[0026] In the embodiments of the present application, since the controller has been initialized when the operating system loads the driver, the initialization state of the controller needs to be cancelled first, and then the controller is dynamically initialized according to the initialization parameter.
[0027] In a possible implementation, the chip adaptation layer cancelling the initialization state of the controller comprises:
[0028] The chip adaptation layer cancels the first callback function registered by the control layer, and the first callback function is a callback function for realizing data processing function of the controller in the first mode;
[0029] The chip adaptation layer cancels the enablement of the controller and cancels the registration of the interrupt.
[0030] In the embodiments of the present application, the chip adaptation layer cancels the callback function for realizing data processing function of the controller in the current mode, and cancels the registration of the interrupt and the enablement of the controller, thereby avoiding triggering the interrupt again in the dynamic initialization process.
[0031] In a possible implementation, the chip adaptation layer dynamically initializing the mode of the controller according to the initialization parameter comprises:
[0032] The chip adaptation layer registers the interrupt to the control layer and configures the controller according to the initialization parameter,
[0033] The chip adaptation layer controls the enablement of the controller and registers a second callback function to the control layer, and the second callback function is a callback function for realizing data processing function of the controller in the second mode.
[0034] In the embodiments of the present application, the chip adaptation layer can configure the controller according to the initialization parameter and register the callback function for realizing data processing function of the controller in the current mode to the control layer.
[0035] In a possible implementation, the method further comprises:
[0036] The first device controls the controller to switch from the second mode to the first mode after receiving the second packet.
[0037] In the embodiments of the present application, the first device can also control the controller to switch to the first mode after receiving the second packet, so as to perform the next data transmission.
[0038] In a second aspect, another data transmission method is provided in the embodiments of the present application, and is applied to a first device. The method comprises the following steps.
[0039] When the first device receives a third packet fed back by a second device based on the controller in the second mode, the first device controls the controller in the second mode to switch from the second mode to the first mode; and the controller in the first mode is used to send a fourth packet to the second device.
[0040] In the embodiments of the present application, during the data transmission between the first device and the second device, i.e. during the running of the operating system of the first device, the first device can control the controller to switch modes, so as to accurately send data to the second device or receive data from the second device through the controller. For example, when the first device receives data from the second device, the first device can control the controller to switch from the second mode to the first mode.
[0041] In a possible implementation, the first device controls the controller in the second mode to switch from the second mode to the first mode, which comprises the following steps.
[0042] The first device controls the controller to switch modes according to a dynamic initialization command word and an initialization parameter; the dynamic initialization command word is used to instruct to dynamically initialize the mode of the controller, and the dynamic initialization of the mode of the controller refers to switching the mode of the controller during the data transmission process; and the initialization parameter is used to instruct the mode to be switched by the controller.
[0043] In a possible implementation, the operating system of the first device comprises an application layer and a driver layer; and the first device controls the controller to switch modes according to a dynamic initialization command word and an initialization parameter, which comprises the following steps.
[0044] The application layer calls a command function in a character device to send the dynamic initialization command word and the initialization parameter to the driver layer;
[0045] The driver layer controls the controller to switch to the mode indicated by the initialization parameter according to the dynamic initialization command word and the initialization parameter.
[0046] In a possible implementation, the driver layer comprises a control layer and a chip adaptation layer; and the driver layer controls the controller to switch to the mode indicated by the initialization parameter according to the dynamic initialization command word and the initialization parameter, which comprises the following steps.
[0047] The control layer calls an interface function corresponding to the dynamic initialization command word to send the initialization parameter to the chip adaptation layer;
[0048] The chip adaptation layer dynamically initializes the controller according to the initialization parameter, and switches the controller to the mode indicated by the initialization parameter.
[0049] In a possible implementation, the chip adaptation layer dynamically initializes the controller according to the initialization parameter, and switches the controller to the mode indicated by the initialization parameter, including:
[0050] The chip adaptation layer cancels the initialization state of the controller, and dynamically initializes the mode of the controller according to the initialization parameter.
[0051] In a possible implementation, the chip adaptation layer cancels the initialization state of the controller, including:
[0052] The chip adaptation layer cancels the second callback function registered to the control layer, and the second callback function is a callback function for implementing a data processing function of the controller in the second mode;
[0053] The chip adaptation layer cancels the enablement of the controller, and cancels the registration of the interrupt.
[0054] In a possible implementation, the chip adaptation layer dynamically initializes the mode of the controller according to the initialization parameter, including:
[0055] The chip adaptation layer registers the interrupt to the control layer, and configures the controller according to the initialization parameter,
[0056] The chip adaptation layer controls the enablement of the controller, and registers a first callback function to the control layer, and the first callback function is a callback function for implementing a data processing function of the controller in the first mode.
[0057] In a possible implementation, the method further includes:
[0058] After the first device receives the third packet, the first device controls the controller to switch from the second mode to the second mode.
[0059] In a third aspect, an embodiment of the present application provides a data transmission device, applied to a first device, and the device includes:
[0060] A switching module, configured to control the controller in the first mode to switch from the first mode to the second mode when the first device sends a first packet to a second device based on the controller in the first mode; and the controller in the second mode is configured to receive a second packet fed back by the second device.
[0061] In a possible implementation, the switching module is specifically configured to switch the mode of the controller according to a dynamic initialization command word and an initialization parameter; the dynamic initialization command word is used to indicate a mode of dynamically initializing the controller, and the mode of dynamically initializing the controller refers to switching the mode of the controller in a data transmission process; and the initialization parameter is used to indicate a mode required to be switched by the controller.
[0062] In a possible implementation, the operating system of the first device includes an application layer and a driver layer; and the switching module includes a first switching unit and a second switching unit.
[0063] The first switching unit is configured to send the dynamic initialization command word and the initialization parameter to the driver layer based on the application layer invoking a command function in a character device.
[0064] The second switching unit is configured to control the controller to be switched to the mode indicated by the initialization parameter according to the dynamic initialization command word and the initialization parameter based on the driver layer.
[0065] In a possible implementation, the driver layer includes a control layer and a chip adaptation layer; and the second switching unit is specifically configured to:
[0066] send the initialization parameter to the chip adaptation layer based on the control layer invoking an interface function corresponding to the dynamic initialization command word; and switch the controller to the mode indicated by the initialization parameter based on the chip adaptation layer dynamically initializing the controller according to the initialization parameter.
[0067] In a possible implementation, the second switching unit is specifically configured to cancel an initialization state of the controller based on the chip adaptation layer, and dynamically initialize the mode of the controller according to the initialization parameter.
[0068] In a possible implementation, the second switching unit is specifically configured to cancel a first callback function registered by the chip adaptation layer to the control layer, the first callback function being a callback function for the controller to implement a data processing function in the first mode; and cancel an enablement of the controller and cancel registration of an interrupt based on the chip adaptation layer.
[0069] In a possible implementation, the second switching unit is specifically configured to register an interrupt to the control layer based on the chip adaptation layer, and configure the controller according to the initialization parameter; and control the controller to be enabled and register a second callback function to the control layer based on the chip adaptation layer, the second callback function being a callback function for the controller to implement a data processing function in the second mode.
[0070] In a fourth aspect, an embodiment of the present application provides a BMC chip, which is configured to implement the data transmission method according to any one of the embodiments of the first aspect and the second aspect.
[0071] In a fifth aspect, an embodiment of the present application provides a server comprising a BMC chip, which is configured to implement the data transmission method according to any one of the embodiments of the first aspect and the second aspect.
[0072] In a sixth aspect, an embodiment of the present application provides a device comprising a memory and a processor, wherein the memory is configured to store instructions or codes, and the processor is configured to execute the instructions or codes to enable the device to perform the data transmission method according to any one of the first aspect and the second aspect.
[0073] In a seventh aspect, an embodiment of the present application provides a computer storage medium, which stores codes, and when the codes are executed, a device executing the codes implements the data transmission method according to any one of the first aspect and the second aspect. BRIEF DESCRIPTION OF DRAWINGS
[0074] In order to more clearly illustrate the technical solutions in the embodiments or the prior art, the drawings needed in the embodiments or the prior art description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative effort.
[0075] Figure 1 A schematic diagram of an operating system architecture provided by an embodiment of the present application;
[0076] Figure 2 A schematic diagram of a data transmission scenario based on the MCTP protocol provided by an embodiment of the present application;
[0077] Figure 3 A schematic diagram of a BMC chip provided by an embodiment of the present application;
[0078] Figure 4 A structural schematic diagram of an operating system kernel provided by an embodiment of the present application;
[0079] Figure 5 A schematic diagram of an I2C control layer provided by an embodiment of the present application;
[0080] Figure 6 A schematic diagram of a chip driver adaptation layer provided by an embodiment of the present application;
[0081] Figure 7A flowchart of a method for dynamically initializing a master-slave mode of an I2C controller is provided in an embodiment of the present application.
[0082] Figure 8 A flowchart of a method for dynamically initializing an I2C controller is provided in an embodiment of the present application.
[0083] Figure 9 A flowchart of a method for dynamically initializing a master-slave mode of an I2C controller and initializing a master-slave mode of an I2C controller at startup of an operating system is provided in an embodiment of the present application.
[0084] Figure 10 A flowchart of a data transmission method is provided in an embodiment of the present application.
[0085] Figure 11 A flowchart of another data transmission method is provided in an embodiment of the present application. DETAILED DESCRIPTION
[0086] It should be noted that the embodiments described in the present application are only some of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative labor are within the scope of protection of the present application.
[0087] The method for switching a master-slave mode of a controller provided in the embodiments of the present application is applicable to a controller that does not support automatic switching of a master-slave mode. The controller can be an I2C controller, an SPI controller, an I3C controller, etc. In the embodiments of the present application, an I2C controller is taken as an example for illustration. Correspondingly, the driver layer in the operating system can include an I2C driver, the control layer in the driver layer can be an I2C control layer, and the chip adaptation layer in the driver layer can be an I2C chip adaptation layer.
[0088] To make the following embodiments clear, the technical terms involved in the present application are introduced first.
[0089] Inter-Integrated Circuit (I2C) driver, which is responsible for controlling and managing various external devices connected to the I2C bus. When reading and setting device register values, the I2C driver acts as an intermediary. Applications send control instructions to the I2C driver, which processes the control instructions accordingly and issues them to the corresponding hardware device. When the application layer needs to perform hardware operations, it will call the corresponding I2C driver through relevant instructions to execute the corresponding I2C communication. The I2C driver will be responsible for processing the underlying I2C protocol, including sending and receiving data, controlling the timing of the bus, etc. Through the I2C driver, the operating system or application can send read and write instructions to the underlying hardware device to obtain the status of the device or configure the parameters of the device.
[0090] Management Component Transport Protocol (MCTP) is a protocol used to manage and control communication between basic devices. In some scenarios, the MCTP protocol requires the I2C controller to support the master-slave switching function. For example, in a server, there may be some devices that need to be updated or configured, and these devices need to switch to the master device of the I2C bus to initiate communication when updating the firmware, that is, the I2C controller needs to be in master mode. After completing the update, it may need to switch to a slave device to receive the command of the master device and reply to the command, that is, the I2C controller needs to be in slave mode. Therefore, in the device management and control scenario involving the MCTP protocol, if it is necessary to switch the master-slave mode of the I2C bus between devices, the relevant I2C controller needs to provide the corresponding master-slave switching function to support the MCTP protocol.
[0091] Device Tree is a data structure that describes the specific hardware information of a computer, used to dynamically describe the resources of system hardware in embedded systems, including processors, memories, devices, buses and other hardware. This description method allows the operating system kernel to run on different hardware platforms without the need to customize a new kernel for each platform. In the operating system kernel, the device tree is used to describe the hardware structure of the system and configure the corresponding device driver.
[0092] Device bus driver framework refers to a software mechanism used in the operating system kernel to manage communication and data transmission between devices. In the operating system kernel, the device bus driver framework is responsible for managing the connection and communication between devices, providing a standard interface and mechanism so that different types of devices can interact with the kernel in a unified way.
[0093] The I2C controller is a kind of hardware responsible for managing and controlling the entire I2C transmission process. The I2C controller is responsible for forwarding the start signal, stop signal and timing control based on the I2C protocol. The I2C controller can be integrated into the motherboard or processor chip, or it can be an external I2C control chip.
[0094] The following describes the process of initializing and setting the master-slave mode of the I2C controller during the operating system startup process.
[0095] Figure 1 For example, it can be the architecture of the operating system. In the bus device driver framework of the operating system kernel, the configuration of the I2C driver is defined by the device tree. The operating system parses the device nodes in the device tree into platform devices (also known as platform devices, including I2C controllers, processors, memories and other external devices) and mounts them on the platform bus (also known as the platform bus, such as the I2C bus) during the startup phase. At the same time, it looks for whether there is a platform device corresponding driver (such as I2C driver) on the platform bus. If so, it matches successfully and runs the probe callback function of the driver to initialize the platform device. The I2C driver usually initializes the I2C controller in this phase and sets the master-slave mode of the I2C controller.
[0096] In some scenarios, such as device management and control scenarios involving the MCTP protocol, mutual MCTP message transmission between the master device and the slave device is required. Therefore, the I2C controller needs to automatically switch the master-slave mode according to the transmission direction at that time during the operating system running process.
[0097] However, some I2C controllers cannot provide the function of automatically switching the master-slave mode, that is, they cannot switch the master-slave mode during the operating system running process, and need to be reinitialized by the above-mentioned method of restarting the operating system to realize the master-slave mode. For these I2C controllers, it is not possible to support transmission protocols similar to the MCTP protocol, which require switching the master-slave mode during the system running process.
[0098] To solve the above technical problems, the embodiments of the present application provide a data transmission method, a BMC chip and a server. Compared with the related art, when the first device sends data to the second device through the controller (or receives data from the second device), the controller can be actively switched from the first mode to the second mode (or from the second mode to the first mode), so that the first device can accurately receive the data feedback by the second device through the controller.
[0099] And in the embodiment of the present application, the first device can be a BMC chip or a server comprising a BMC chip. The character device of the operating system of the first device comprises an ioctl command function for calling a dynamic initialization I2C controller master-slave mode function, the I2C control layer comprises an interface function for dynamically initializing an I2C controller, and the I2C chip adaptation layer comprises a function for implementing dynamic initialization of an I2C controller.
[0100] In the embodiment of the present application, if the first device (a BMC chip or a server comprising a BMC chip) sends data to the second device (a peer device), the first mode can be a master mode and the second mode can be a slave mode. If the first device (a BMC chip or a server comprising a BMC chip) receives data from the second device (a peer device), the first mode is a slave mode and the second mode is a master mode. The peer device can be a BMC chip or a server comprising a BMC chip, or other hardware devices.
[0101] The application program can pass an ioctl command word (also referred to as a dynamic initialization command word) indicating dynamic initialization and initialization parameters to the I2C control layer by calling the ioctl command function. The I2C control layer sends the initialization parameters to the I2C chip adaptation layer through the interface function corresponding to the dynamic initialization command word, and the I2C chip adaptation layer dynamically initializes the I2C controller according to the initialization parameters, so as to switch the master-slave mode of the I2C controller during the operation of the operating system.
[0102] The method for switching the master-slave mode of the I2C controller provided in the embodiment of the present application is applicable to the scenario where the processor communicates with external devices based on a transmission protocol requiring the I2C controller to support master-slave mode switching. For example, the processor can be a baseboard management controller (BMC) chip, the controller can be an I2C / SMBus controller, the transmission protocol can be a management component transport protocol over system management bus (MCTP over SMBUS), and the peer device can be a network card. Figure 2 For example, the processor can be a baseboard management controller (BMC) chip, the controller can be an I2C / SMBus controller, the transmission protocol can be a management component transport protocol over system management bus (MCTP over SMBUS), and the peer device can be a network card. When the BMC chip communicates with the network card based on the MCTP over SMBUS, the I2C / SMBus controller needs to support master-slave mode switching during the operation of the operating system.
[0103] The embodiment of the present application provides a schematic diagram of a BMC chip, as shown in Figure 3The BMC chip includes a processing core and an I2C / SMBus controller, the processing core runs an operating system, the operating system includes an I2C driver and a character device, and the BMC chip communicates with a peer device by calling the I2C / SMBus controller through the I2C driver. Figure 3 The I2C / SMBus controller shown in the figure is integrated in the BMC chip, and of course can also exist separately as an external control chip.
[0104] In the embodiments of the present application, the I2C driver can support dynamic initialization of the master-slave mode of the I2C controller, and the character device includes an ioctl command function for calling the dynamic initialization of the master-slave mode of the I2C controller. The application program sends a dynamic initialization command word and initialization parameters to the I2C driver by calling the ioctl command function, and can call the I2C driver through the dynamic initialization command word during the running of the operating system, to realize the function of dynamic initialization of the master-slave mode of the I2C controller. The I2C / SMBus controller is a controller that cannot automatically switch the master-slave mode during the running of the operating system; and the peer device is an external device that uses the MCTP protocol or other transmission protocols that require the controller to support the switching of the master-slave mode during the running of the operating system.
[0105] By adding the ioctl command function for calling the dynamic initialization of the master-slave mode of the I2C controller, during the running of the operating system, the application program sends a dynamic initialization command word and initialization parameters to the I2C driver through the ioctl command function; after the I2C control layer receives the dynamic initialization command word and the initialization parameters, it sends the initialization parameters to the I2C chip adaptation layer by calling the interface function corresponding to the dynamic initialization command word, and the I2C chip adaptation layer dynamically initializes the I2C controller according to the initialization parameters. This realizes that the I2C controller that does not support automatic switching of the master-slave mode can switch the master-slave mode of the I2C controller according to the change of the data transmission direction during the running of the operating system, and further makes the I2C controller support the transmission protocols that require flexible switching of the master-slave mode.
[0106] Through the function of dynamic initialization of the master-slave mode of the I2C controller, the operating system or the application program can change the master-slave mode of the I2C controller as needed during the running, which provides greater flexibility and controllability for communication with external devices, meets the requirements of some specific transmission protocols or external devices, and makes the I2C controller more flexible to support dynamic switching of the master-slave mode, thereby meeting the needs of complex data transmission protocols or external devices.
[0107] Next, combined with Figure 4 introduce the operating system kernel. As Figure 4As shown, the operating system kernel includes an I2C driver, which includes an I2C device interface, an I2C core, and an I2C bus driver.
[0108] The I2C device interface is responsible for managing and controlling various devices connected to the I2C bus. In the operating system, each device connected to the I2C bus is represented as a struct i2c_client structure. The functions of this layer include the registration of I2C slave devices (i.e., external devices mounted on the I2C bus) and I2C master devices (i.e., I2C controllers), sending and receiving data, and managing data transmission of devices.
[0109] The I2C core can be as shown in Figure 5 , Figure 5 a schematic diagram of an I2C core provided by an embodiment of the present application. The ".init" function is an interface function newly added by the embodiment of the present application in the I2C core, which is used for dynamically initializing and configuring the I2C controller; the ".master_xfer" function is used to initiate the master device transmission on the I2C bus, and the ".master_xfer" function allows the master device to send commands or data to the slave device and receive response data from the slave device; and the "etc" function is another interface function.
[0110] The I2C core is the core part of the I2C driver, which is responsible for managing and controlling the entire I2C bus. The I2C core provides interfaces and functions for driving and controlling devices on the I2C bus, including I2C controllers and other external devices. The main functions of the I2C core include:
[0111] (1) Isolate hardware device details. One of the main functions of the I2C core is to hide the details of the underlying hardware devices. The I2C core isolates the hardware details of the underlying hardware devices from the upper layer software by providing a unified interface and hardware abstraction layer. In this way, developers can focus more on the logic of devices and transmission without directly dealing with the underlying registers and communication protocols.
[0112] (2) Encapsulate interfaces. The I2C core encapsulates the operations of the underlying devices and I2C controllers in unified interface functions. These functions provide a set of abstract methods, such as dynamically initializing the I2C controller, setting the bus rate, sending and receiving data, and performing device addressing. Through these interface functions, the operating system or application program can easily operate the I2C bus and devices without directly accessing the underlying registers.
[0113] (3) Provides interfaces for device management and registration. The I2C control layer provides interfaces for device management and registration, allowing external devices mounted on the I2C bus to be associated with corresponding I2C controllers. By using these mechanisms, the kernel can correctly configure and manage external devices based on their addresses and other properties; and, by using related functions, it can register and unregister external devices.
[0114] (4) Provides an interface for dynamic initialization and configuration. The I2C control layer is responsible for dynamically initializing and configuring the I2C controller. During kernel startup, the I2C controller can be switched between master and slave modes and parameter configuration can be performed by executing the dynamic initialization functions associated with .init. These parameter configurations may include bus speed, pin mapping, and interrupt handlers.
[0115] The I2C chip adaptation layer can be Figure 6 As shown, Figure 6 A schematic diagram of a chip driver adaptation layer provided in an embodiment of the present application, wherein "init implementation" is the implementation of dynamic initialization and configuration functions; and "master_xfer implementation" is the implementation of initiating data transmission on the I2C bus.
[0116] The I2C chip adaptation layer is responsible for interacting with specific I2C controllers. It maps the operating system's general application programming interface (I2C API) to specific hardware registration interfaces, enabling the operating system to interact with and communicate with the I2C controller. The I2C chip adaptation layer provides a low-level interface for interacting with the I2C controller, enabling the operating system to adapt to different types of I2C controllers. This simplifies the interaction between applications and drivers and the I2C controller, improving the portability and versatility of the operating system.
[0117] The existence of the I2C chip adaptation layer enables the operating system to uniformly manage and control various types of I2C devices.
[0118] In the operating system, the I2C control layer provides interfaces corresponding to respective functions, and the I2C chip adaptation layer provides specific implementations corresponding to respective functions. The I2C control layer shields the differences between different chips (i.e., different I2C controllers). By defining a set of standardized interfaces and introducing a callback function mechanism, the I2C control layer enables different I2C controllers to implement a unified operation interface. The callback functions define the standardized operations that the I2C chip adaptation layer should implement. An application program can send a dynamic initialization command word and initialization parameters to the I2C control layer through an ioctl command function in a character device under a device filesystem (devfs), and the I2C control layer sends the initialization parameters to the I2C chip adaptation layer through an interface function corresponding to the dynamic initialization command (such as ".init" shown in Figure 5 ). After receiving the initialization parameters, the I2C chip adaptation layer performs dynamic initialization on the I2C controller according to a corresponding function implementation (such as "init implementation" shown in Figure 6 ).
[0119] Compared with the prior art, the embodiment of the application expands the interface function of dynamically initializing the I2C controller in the I2C control layer, adds the function implementation of dynamically initializing the I2C controller in the I2C chip adaptation layer, and adds an ioctl command function for calling the master-slave mode function of dynamically initializing the I2C controller in the character device. Through the I2C driver and the character device provided by the embodiment of the application, an application program transmits initialization parameters and a dynamic initialization command word to the I2C driver by calling the ioctl command function, triggers the corresponding operations of the I2C control layer and the I2C chip adaptation layer, and thus the operating system or the application program dynamically initializes the I2C controller.
[0120] In a possible implementation, the process of adding the ioctl command function in the character device can be as follows. First, find the character device of the I2C controller; then, open the character device using an editor and find the definition part of the ioctl function; second, in the definition part of the ioctl function, add a new ioctl command function to represent the operation of triggering the dynamic initialization of the master-slave mode of the I2C controller; and finally, after modifying the ioctl function, save the file and recompile the character device.
[0121] Through the above steps, a new ioctl command function can be added in the character device for calling the function of dynamically initializing the master-slave mode of the I2C controller. When the master-slave mode of the I2C controller needs to be dynamically initialized, the application passes a corresponding dynamic initialization command word to the I2C control layer through the ioctl command function to trigger the dynamic initialization operation of the I2C controller, so that the switching of the master-slave mode of the I2C controller during the running of the operating system can be realized.
[0122] In the embodiment of the application, for the dynamic initialization of the I2C controller, the dynamic initialization command word and initialization parameters such as the master-slave mode, the bus rate, the slave address and the storage space size can be passed through the ioctl command function, and then the I2C control layer sends the initialization parameters to the I2C chip adaptation layer according to the dynamic initialization command word, and the I2C chip adaptation layer dynamically initializes the I2C controller according to the initialization parameters.
[0123] Through the above method, not only the dynamic initialization of the I2C controller which does not support automatic switching of the master-slave mode can be completed during the running of the operating system, but also a unified interface can be provided to the application (i.e. the application layer), and the application can control and configure different types of I2C controllers through the unified ioctl command function, so that the kernel layer and the application layer can interact well.
[0124] The following will be described in combination with Figure 7 The process of dynamically initializing the master-slave mode of the I2C controller based on the kernel framework is introduced. As shown in Figure 7 , it is a process diagram of dynamically initializing the master-slave mode of the I2C controller provided in the embodiment of the application. Figure 7
[0125] S701: The application opens the character device.
[0126] In some implementation scenarios provided in the embodiment of the application, for example, the I2C controller and the opposite device perform data interaction based on the MCTP protocol, at this time, the I2C controller needs to switch the master mode and the slave mode according to the data transmission direction during the data transmission. For example, when the I2C controller sends the MCTP message to the opposite device, the I2C controller is in the master mode, and when the I2C controller receives the feedback data of the opposite device, the I2C controller is in the slave mode. That is, after the I2C controller sends the MCTP message to the opposite device, the master mode needs to be switched to the slave mode, so that the I2C controller can normally receive the feedback data of the opposite device.
[0127] The character device is a character device to which an ioctl command function for calling a dynamic initialization I2C controller master-slave mode function has been added. When it is necessary to switch the I2C controller master-slave mode, for example, after the I2C controller sends an MCTP message to a peer device, or after the I2C controller receives an MCTP message sent by a peer device, an application program can use a C language standard library function open system call to open the character device, or can use a command line tool such as cat or echo to perform read and write operations on the character device in the operating system. After the application program successfully opens the character device, the returned file descriptor can be used to perform operations, for example, using read and write system calls to read and write data, and calling the ioctl command function to send a dynamic initialization command word to the I2C control layer.
[0128] A file descriptor represents an integer identifier of an opened device file or socket. The file descriptor is a general way for an application program to perform I / O operations with the operating system kernel, and is used to uniquely identify an opened file or device. The file descriptor can usually be obtained through open, socket, and the like system calls. The file descriptor is returned when the character device is opened in step S701 using the open system call.
[0129] S702: The application program sends a dynamic initialization command word and initialization parameters to the I2C control layer by calling the ioctl command function.
[0130] The dynamic initialization command word is used to instruct switching of the I2C controller master-slave mode during operating system running. The dynamic initialization command word is defined and processed by the I2C control layer. The application program passes the dynamic initialization command word to the I2C control layer in the I2C driver by calling the ioctl command function, so that the I2C control layer knows that the operation to be performed is dynamic initialization of the I2C controller.
[0131] The initialization parameters can be passed to the I2C control layer through the arg field in the ioctl command function. The application program sends a dynamic initialization command word to the I2C control layer by using the ioctl system call, calls a function for implementing dynamic initialization of the I2C controller master-slave mode, and then switches the I2C controller master-slave mode. The ioctl system call can be used to exchange control information between the application layer application program and the I2C control layer.
[0132] The initialization parameter is used to pass additional data to the I2C control layer. The specific parameter format and meaning of the initialization parameter depends on the definition of the ioctl command function, which can be a structure, an integer, a pointer, or other forms of data. The initialization parameter includes one or more of the master-slave mode, bus speed, slave address, and memory space size.
[0133] As an example, when the I2C controller needs to be switched to the master mode, the initialization parameter includes the master mode type and the bus speed. The master mode type is used to indicate the type of switching to the master mode. The bus speed refers to the speed at which data is transmitted through the bus in a computer or electronic device. It is usually expressed in the number of bits transmitted per second (bit rate) or the number of bytes (data rate).
[0134] As another example, when the I2C controller needs to be switched to the slave mode, the initialization parameter includes the type of switching to the slave mode, the slave address, and the memory space size. The slave address is the address of the slave device, and each slave device has a unique address for communication with the host on the bus. In slave mode, the I2C controller will use the slave address to identify itself and communicate with the master device. The memory space size (EEPROM size) is used to specify the memory space size of the slave device, usually in bytes, which determines the amount of data that the slave device can store and its capabilities.
[0135] In a possible implementation, the application program can send the file descriptor, the dynamic initialization command word, and the initialization parameter to the operating system by calling the ioctl command function. The operating system sends the dynamic initialization command word and the initialization parameter to the I2C control layer according to the file descriptor.
[0136] The file descriptor is a file descriptor pointing to a specific device, which, in the embodiments of the present application, functions to identify and locate the I2C control layer. The operating system can determine the I2C control layer according to the file descriptor, and then send the dynamic initialization command word and the initialization parameter to the I2C control layer.
[0137] S703: The I2C control layer sends the initialization parameter to the I2C chip adaptation layer according to the interface function corresponding to the dynamic initialization command word.
[0138] The I2C control layer includes an interface function for dynamically initializing the master-slave mode of the I2C controller (such as the “.init” function shown in the figure). Figure 5 After receiving the dynamic initialization command word, the I2C control layer can determine that the interface function corresponding to the dynamic initialization command word i is the interface function for dynamically initializing the master-slave mode of the I2C controller by parsing the dynamic initialization command word.
[0139] The I2C control layer can determine the corresponding interface function according to the value of the dynamic initialization command word by using a lookup table or a conditional statement method.
[0140] The interface function for dynamically initializing the master-slave mode of the I2C controller can be a set of function pointers or a series of code segments for processing the dynamic initialization command word. The I2C control layer communicates with the I2C chip adaptation layer through the interface function to send initialization parameters to the I2C chip adaptation layer.
[0141] In a possible implementation, before step S703 is performed, the I2C control layer can verify whether the I2C controller supports the function of dynamically initializing the master-slave mode.
[0142] After receiving the dynamic initialization command word, the I2C control layer can first check whether the received dynamic initialization command word is used to indicate the dynamic initialization of the master-slave mode of the I2C controller. If so, the next step of support verification is performed to check whether the I2C controller supports the function of dynamically initializing the master-slave mode.
[0143] As an example, the I2C control layer determines whether the I2C controller supports the function of dynamically initializing the master-slave mode by querying the value of the I2C controller register.
[0144] The I2C controller generally has a set of configuration registers for controlling its working mode and parameter settings. By reading the value of the configuration register, it can be determined whether the controller supports the dynamic initialization of the master-slave mode setting. For example, the I2C control layer queries the I2C controller register to determine whether there is a configuration bit of the master-slave mode and the related parameter settings.
[0145] As another example, the I2C control layer verifies whether the I2C controller supports the function of dynamically initializing the master-slave mode by confirming whether the I2C controller supports the feature of dynamically initializing the master-slave mode defined in the I2C protocol.
[0146] In the embodiments of the present application, if the I2C controller supports the dynamic initialization of the master-slave mode, the I2C chip adaptation layer also supports the dynamic initialization of the master-slave mode of the I2C controller, that is, if the I2C chip adaptation layer supports the dynamic initialization of the master-slave mode of the I2C controller, the I2C controller also supports the dynamic initialization of the master-slave mode. Conversely, if the I2C chip adaptation layer does not support the dynamic initialization of the master-slave mode of the I2C controller, it is also impossible to dynamically initialize the I2C controller. Therefore, the I2C control layer can determine whether the I2C controller supports the dynamic initialization of the master-slave mode by verifying whether the I2C chip adaptation layer supports the function of dynamically initializing the I2C controller.
[0147] The I2C control layer can find the function flag, configuration option and function support of the I2C chip adaptation layer. These information can usually be found in the source code or related documents of the I2C chip adaptation layer. For example: check whether the function flag of the I2C chip adaptation layer contains the flag of the dynamic initialization master-slave mode function; check whether the configuration option of the I2C chip adaptation layer contains the setting of the I2C controller master-slave mode. Check whether the function interface of the I2C chip adaptation layer provides the control and operation of the I2C controller master-slave mode.
[0148] If it is found through the above verification that the I2C chip adaptation layer can support the dynamic initialization of the master-slave mode of the I2C controller, step S703 is continued. If the I2C chip adaptation layer does not support the dynamic initialization of the master-slave mode of the I2C controller, step S705 can be performed to close the character device and report an error to notify the application program that the I2C chip adaptation layer does not support the required function.
[0149] Some existing I2C controllers do not support dynamic initialization of the master-slave mode, and for such I2C controllers, dynamic initialization cannot be achieved. The embodiments of the present application can preliminarily determine whether the operation of the dynamic initialization of the I2C controller can be achieved by verifying whether the I2C controller supports dynamic initialization of the master-slave mode, and in the case that the I2C controller does not support dynamic initialization of the master-slave mode, the initialization parameters are intercepted in time and the application program is fed back that the dynamic initialization operation fails and the reason for the failure, so as to facilitate subsequent operation by the technician.
[0150] S704: The I2C chip adaptation layer parses the initialization parameters and dynamically initializes the I2C controller.
[0151] The I2C chip adaptation layer is responsible for communication with the I2C controller and performs the corresponding initialization operation. According to the received initialization parameters, the I2C chip adaptation layer may need to configure the clock frequency, address, data transmission mode, etc. of the I2C bus. The I2C chip adaptation layer can provide the function implementation (such as Figure 6 indicated as "init implementation") of the interface function in the I2C controller to communicate with the I2C controller to complete the operation of dynamically initializing the I2C controller.
[0152] In the I2C driver, the I2C chip adaptation layer can parse the received initialization parameters. Through the parsing of the initialization parameters, it can be determined that the type of the I2C controller to be switched is the master mode or the slave mode, as well as other related parameters, such as the slave address, the storage space size or the bus rate.
[0153] After the parsing is completed, according to the parameters obtained by the parsing, the parameter information needs to be configured to the I2C controller. For example, setting the clock frequency, setting the storage space size, switching the master-slave mode, and setting the slave address and the like, finally making the I2C controller in the mode indicated in the initialization parameters, making the I2C controller in a state capable of effective communication.
[0154] In a possible implementation, when the step S704 is performed, an error occurs in the process of initialization parameter parsing and dynamic initialization, error processing needs to be performed to cope with possible configuration errors or abnormal situations. If the parsed parameters are illegal or invalid, a proper error code needs to be returned. In the process of dynamic initialization of the I2C controller, proper cleaning and error processing need to be performed when an error occurs, to ensure that the I2C driver and the I2C controller are in a reliable state.
[0155] S705: The application program closes the character device.
[0156] When the dynamic initialization of the I2C controller is completed, the application program can trigger the closing operation by calling the release function in the character device, which is set when the character device is opened. In the initialization process of the character device, the release function defined in the I2C driver is registered to the character device, so as to be called when the character device is closed. By closing the character device, the system resources can be released, the occupation of resources is reduced, and the stability of the system is improved.
[0157] In the I2C driver provided by the embodiment of the application, the character device includes an ioctl command function for calling the dynamic initialization I2C controller master-slave mode function, the I2C control layer includes an interface function for dynamically initializing the I2C controller, and the I2C chip adaptation layer includes a function for dynamically initializing the I2C controller. When the master-slave mode of the I2C controller needs to be changed, the application program sends the initialization parameters and a dynamic initialization command word for indicating the dynamic initialization I2C controller master-slave mode to the I2C control layer in the I2C driver by calling the ioctl command function, and the I2C control layer and the I2C chip adaptation layer in the I2C driver dynamically initialize the I2C controller based on the initialization parameters and the dynamic initialization command word, switch the mode of the I2C controller to the mode indicated in the initialization parameters, and further make the I2C controller support the transmission protocol whose master-slave mode needs to be switched.
[0158] In the operating system kernel, when the I2C driver is loaded, the probe callback function corresponding to the I2C controller is triggered and the I2C controller is initialized. In other words, the I2C controller that has been initialized needs to be dynamically initialized again according to the embodiment of the application.
[0159] The following will be described in combination withFigure 8 The process of dynamically initializing the I2C controller is described, Figure 8 A flowchart of dynamically initializing the I2C controller is provided for the embodiments of the present application. As shown, Figure 8 The process of dynamically initializing the I2C controller can be divided into two parts, including canceling the original initialization state of the I2C controller and re-initializing the I2C controller according to the incoming initialization parameters.
[0160] Since the I2C controller has been initialized when the operating system loads the I2C driver, the initialization state of the I2C controller needs to be canceled first. The specific steps are as follows:
[0161] S801: The I2C chip adaptation layer cancels the first callback function registered by the I2C chip adaptation layer to the I2C control layer.
[0162] The first callback function is a callback function that implements data processing functions in the current mode of the I2C controller. The first callback function is a callback function that is different from the callback function that implements the same data processing functions in the target mode of the I2C controller. The current mode is the mode in which the I2C controller is currently located, and the target mode is the mode that the I2C controller needs to switch to. If the current mode is the master mode, then the target mode is the slave mode; otherwise, if the current mode is the slave mode, then the target mode is the master mode.
[0163] Taking the I2C control layer shown in Figure 5 As an example, the ".init" of the I2C controller in the master mode or the slave mode is the same and does not exist. Therefore, ".init" does not belong to the first callback function, in other words, when step S801 is executed, ".init" does not need to be canceled.
[0164] ".master_xfer" is a function used by the I2C controller in the master mode to send data, and when the I2C controller is switched to the slave mode, data is sent based on ".slave_rx". ".master_xfer" and ".slave_rx" are callback functions that implement the same data processing functions in different modes of the I2C controller. Therefore, ".master_xfer" belongs to the first callback function, in other words, when step S801 is executed, ".master_xfer" needs to be canceled.
[0165] The purpose of this step is to cancel the callback function that has been registered to the I2C control layer. In the operating system kernel, when the driver of the I2C controller is loaded, the I2C chip adaptation layer usually registers the corresponding callback function to the I2C control layer, which is used to process the data transmission, interrupt processing and other operations of the I2C controller. Therefore, the I2C chip adaptation layer needs to cancel the registration of these callback functions in the operation of canceling the initialization state, so as to prevent these callback functions from being triggered again before reinitialization. The I2C chip adaptation layer can cancel the callback function by calling the corresponding unregistration function, or by setting a flag to identify the cancellation of the registration state of the callback function.
[0166] S802: The I2C chip adaptation layer controls the I2C controller to cancel the enablement.
[0167] In the initialization process of the I2C controller, the I2C chip adaptation layer usually configures and enables the I2C controller to perform data transmission. There are related enablement registers or flags in the I2C controller to control the enablement or disablement of the I2C controller. Before reinitializing the I2C controller, the I2C chip adaptation layer needs to perform corresponding operations to set the I2C controller to a non-enabled state, so as to avoid the impact of I2C transmission operations or interrupt operations on the operation of reinitializing the I2C controller during the process of reinitializing the I2C controller.
[0168] S803: The I2C chip adaptation layer cancels the interrupt registration.
[0169] In some cases, the I2C controller may use interrupts for data transmission and processing. The purpose of this step is to cancel the registration of the interrupt to prevent the interrupt from being triggered again before reinitialization. By canceling the registration of the interrupt, the I2C chip adaptation layer can ensure that no interrupt-related operations occur before reinitialization. The I2C chip adaptation layer can cancel the terminal registration by unregistering the interrupt processing function, canceling the interrupt enablement, and releasing the interrupt resources.
[0170] By canceling the initialization state of the I2C controller before reinitialization, the I2C chip adaptation layer can ensure that the I2C controller starts with the correct state during the reinitialization process to a certain extent.
[0171] After canceling the original initialization state of the I2C controller, the I2C chip adaptation layer can reinitialize the I2C controller according to the initialization parameters passed in by the application program during the operation of the operating system, and the specific steps are as follows:
[0172] S804: The I2C chip adaptation layer registers the interrupt.
[0173] Firstly, the I2C chip adaptation layer determines a processing function for processing the I2C controller interrupt, which is usually an interrupt service program defined in the driver and is responsible for processing the interrupt signal generated by the I2C controller. The processing function can be a pre-defined general interrupt processing function or a custom interrupt processing function written according to specific needs.
[0174] Then, the I2C chip adaptation layer calls the appropriate interrupt registration function (such as the request_irq() function) to register the interrupt with the I2C control layer and assigns appropriate interrupt vectors and priorities. During the registration of the interrupt, parameters such as the interrupt number, interrupt processing function, and interrupt trigger type need to be specified.
[0175] Finally, the I2C chip adaptation layer checks whether the interrupt registration is successful. After registering the interrupt, error checking is needed to ensure that the interrupt registration operation is successful. If the registration fails, error logging or further troubleshooting can be performed.
[0176] S805: The I2C chip adaptation layer configures the I2C controller according to the initialization parameters.
[0177] The I2C chip adaptation layer parses the configuration information in the initialization parameters passed in by the application program, such as slave address, bus rate, storage space size, and mode to be switched. Then, according to the parsed parameters, the I2C controller related registers or flags are configured to switch the master-slave mode of the I2C controller.
[0178] When the I2C controller needs to be switched to the master mode, the initialization parameters include the master mode type and the bus rate; when the I2C controller needs to be switched to the slave mode, the initialization parameters include the type of the switched slave mode, the slave address, and the storage space size.
[0179] S806: The I2C chip adaptation layer controls the I2C controller to enable.
[0180] The I2C chip adaptation layer determines the enable register or flag for controlling the I2C controller by querying the driver, and sets the enable register or flag to the enabled state to enable the hardware functions of the I2C controller, so that the I2C controller can perform data transmission and interrupt processing operations.
[0181] S807: The I2C chip adaptation layer registers the second callback function with the I2C control layer.
[0182] The second callback function is a callback function for implementing data processing function in the target mode of the I2C controller. The second callback function and the first callback function are callback functions for implementing the same function in different modes of the I2C controller. The first callback function and the second callback function have the same implemented function, but there are differences between them, such as ".master_xfer" and ".slave_rx".
[0183] In this step, the corresponding callback function is created for processing the I2C operation to be processed, such as processing data transmission of the I2C device. For example, the second callback function when the data transmission is completed can be created. After the second callback function is created, the corresponding callback function structure (such as i2c_algorithm) can be created.
[0184] The I2C chip adaptation layer registers the second callback function to the I2C control layer through the callback function structure, and the I2C chip adaptation layer can establish contact with the I2C control layer and define some operations to be performed when a specific event occurs. In the embodiment of the present application, through the second callback function, the I2C chip adaptation layer can feed back the data transmitted by the opposite end device to the I2C control layer. For example, a callback function for transmitting data can be registered, so as to realize data transmission.
[0185] Through step S807, the I2C chip adaptation layer can interact and control the I2C control layer by means of the mechanism of registering the callback function, so as to realize flexible management and customized operation of the I2C controller.
[0186] The above steps S801-S807 describe the process of dynamically initializing the I2C controller in the running process of the operating system. For the I2C controller which does not support automatic switching of the master-slave mode, the application program can be used to control the switching of the master-slave mode of the I2C controller, so that the I2C controller can support the transmission protocol which needs to switch the master-slave mode in the running process of the operating system.
[0187] In actual application, the specific steps can be different according to the requirements of the hardware platform, the driver program and the operating system. The above steps S801-S807 are only one embodiment provided by the present application.
[0188] In the embodiment of the present application, the process of dynamically initializing the master-slave mode of the I2C controller is different from the process of initializing the master-slave mode of the I2C controller when the operating system is started. The differences between the two will be illustrated below. Figure 9 The differences between the two will be illustrated below. Figure 9 The flowcharts of dynamically initializing the master-slave mode of the I2C controller and initializing the master-slave mode of the I2C controller when the operating system is started are provided in the embodiment of the present application.
[0189] AsFigure 9 shown, Figure 9 The left side is the process of dynamically initializing the master-slave mode of the I2C controller, referred to as the dynamic initialization process. Figure 9 The right side is the process of initializing the master-slave mode of the I2C controller when the operating system starts, referred to as the startup initialization process.
[0190] When the master-slave mode of the I2C controller is dynamically initialized, the application sends a dynamic initialization command word and initialization parameters to the operating system kernel by calling the ioctl command function; after the I2C chip adaptation layer receives the initialization parameters sent by the I2C control layer according to the dynamic initialization command word, the initialization parameters are parsed and the I2C controller is configured according to the configuration information obtained by parsing, the original initialization state of the I2C controller is cancelled (i.e. the first callback function registered is cancelled, the I2C controller is disabled, and the interrupt registration is cancelled), and then the I2C controller is reinitialized according to the configuration information (i.e. the second callback function is registered, the I2C controller is enabled, the interrupt is registered, and the I2C controller is initialized), completing the dynamic switching of the master-slave mode of the I2C controller.
[0191] When the operating system starts, the master-slave mode configuration of the I2C controller can be configured by loading the I2C driver. When the I2C driver is loaded, system resources can be allocated for the I2C controller, including the private structure body iomap that needs to be allocated and initialized for the device, iomap is used to store and manage the related information and state of the I2C controller; the interrupt number of the I2C controller is obtained for use when registering the interrupt; the general callback function and the initialization semaphore are set, which are used to manage the synchronization operation of the I2C controller when transmitting data.
[0192] After the above operations are completed, the device tree is parsed to obtain the device information and configuration related to the I2C, and the I2C controller is initialized according to the device information and configuration corresponding to the I2C controller obtained by parsing, including: registering the callback function to handle events such as data transmission completion and interrupt occurrence; enabling the I2C controller to start executing I2C communication operations; registering the interrupt processing function when loading the I2C driver to respond to the interrupt events of the I2C controller; initializing the master-slave mode of the I2C control. Finally, the character device also needs to be registered so that the user layer can access and control the I2C device through the standard file operation interface.
[0193] In the dynamic initialization process, since the reloading of the I2C controller is not involved, the already allocated system resources do not need to be reallocated, and the character device does not need to be registered. However, in order to ensure that the I2C controller can start in the correct state during the reinitialization process, the initialization state of the I2C controller needs to be cancelled, and the interrupt processing function, the I2C controller, and the callback function all need to be reinitialized.
[0194] In the related art, some I2C controllers that don't support automatic master-slave mode switching require a boot initialization process to configure the I2C controller's master-slave mode. Specifically, if the current I2C controller is set to master mode and needs to be switched to slave mode, the operating system must be restarted and the initialization process must be started to configure the I2C controller to slave mode. However, for some transmission protocols that require support for switching between active and slave modes while the operating system is running, restarting the operating system during data transmission will interrupt data transmission, making these protocols unsupported.
[0195] The method provided in the embodiment of the present application can dynamically initialize an I2C controller that does not support automatic switching of master-slave modes during the operation of the operating system, switch the master-slave mode of the I2C controller, and enable the I2C controller to support this type of transmission protocol.
[0196] The following combination Figure 10 and Figure 11 , taking the MCTP protocol for data transmission as an example to introduce the data transmission method provided in the embodiment of the present application. Figure 10 This is a flow chart of a data transmission method provided in an embodiment of the present application. The first device executing the method can be a server or a BMC chip. Assuming the first device is a BMC chip, the first mode is the master mode, and the second mode is the slave mode, the process is as follows:
[0197] S1001: The BMC chip sends a first message to a peer device using an I2C controller.
[0198] The first message is assembled by the BMC chip's operating system based on instructions from the application. This first message can be an MCTP message, instructing the peer device to perform an operation. The first message can include instructions, command parameters, data transmission, and other information used to operate the peer device. The peer device can be an external device mounted on the I2C bus, such as a temperature sensor, humidity sensor, network card, or storage device. The operating system assembles the first message according to the specifications and requirements of the MCTP protocol. After assembly, it uses the I2C controller to send the first message to the peer device. In this case, the I2C controller is in master mode, acting as the master device and the peer device as the slave device.
[0199] S1002: The BMC chip switches the I2C controller to slave mode.
[0200] After sending the first message, the application of the BMC chip switches the I2C controller from the master mode to the slave mode, at which time the I2C controller is a slave device and the peer device is a master device. This means that the I2C controller will stop actively initiating I2C communication and enter a receiving mode. The I2C controller applies for storage space and waits for a reply from the peer device on the I2C bus.
[0201] The process of switching the I2C controller to the slave mode includes:
[0202] The application sends a dynamic initialization command word and an initialization parameter to the I2C control layer through an ioctl command function, where the initialization parameter is used to indicate that the I2C controller is switched to the slave mode. After receiving the dynamic initialization command word and the initialization parameter, the I2C control layer determines the interface function corresponding to the dynamic initialization command word by analyzing the dynamic initialization command word, that is, an interface function for dynamically initializing the master-slave mode of the I2C controller is called. Then the I2C control layer calls the interface function to send the initialization parameter to the I2C chip adaptation layer, and the I2C chip adaptation layer switches the I2C controller to the slave mode according to the initialization parameter. Specifically, the process of switching the I2C controller to the slave mode according to the initialization parameter can refer to S801-S807 described above.
[0203] In the embodiment of the present application, the operating system kernel can apply for storage space from the memory to store the data fed back by the peer device.
[0204] S1003: The BMC chip receives the second message replied by the peer device and stores it.
[0205] The second message can be an MCTP message. The second message is the data fed back by the peer device after the operation of the first message. After receiving the first message, the peer device processes the first message to obtain the second message. The peer device sends the second message back to the I2C controller of the BMC chip through the I2C bus, at which time the I2C controller is in the slave mode, and the I2C controller receives the second message replied by the peer device as a slave device and stores it in the storage space.
[0206] The MCTP protocol usually uses a master write transaction for transmission, so the I2C controller needs to be in the master mode when sending the first message. After sending the first message, the I2C controller needs to be ready to receive the master write transaction of the peer device, that is, the I2C controller needs to be switched from the master mode to the slave mode to support successful reception of the second message fed back by the peer device.
[0207] If the I2C controller is still in the master mode when the peer device feeds back the second message, the I2C controller may not be able to receive the second message, thereby causing the data interaction to fail.
[0208] S1004: The BMC chip reads the second message in the storage space and parses the second message.
[0209] The BMC chip operating system can obtain the result of the operation of the opposite device according to the first message by reading and parsing the second message in the storage space, and then can feed the result back to the upper-layer application or perform subsequent operations and decisions based on the result.
[0210] S1005: The BMC chip switches the I2C controller to master mode.
[0211] After completing the parsing and processing of the second message, the BMC chip application can also switch the I2C controller back to master mode to prepare for the next message transmission. This means that after completing the reception and processing of the message, the I2C controller will continue to be in master mode and return to the mode of actively initiating I2C communication in order to send the next message or perform other operations.
[0212] Steps S1001-S1005 above describe the various stages of the data transmission process based on the MCTP protocol. By controlling the I2C controller to switch between master and slave modes, the BMC chip and the peer device can communicate bidirectionally, achieving data transmission and exchange. For some I2C controllers that do not support automatic master-slave mode switching, the method for switching the I2C controller's master-slave mode provided in the above embodiments, based on the interface for dynamically initializing the I2C controller expanded by the I2C control layer and the addition of command words for dynamically initializing the I2C controller's master-slave mode in the I2C chip adaptation layer character device, can dynamically switch the master-slave mode of I2C controllers that do not support automatic master-slave mode switching, enabling such I2C controllers to support the MCTP protocol during the operation of the operating system.
[0213] like Figure 11 As shown, Figure 11 This is a flow chart of another data transmission method provided by an embodiment of the present application. The first device executing the method can be a server or a BMC chip. Assuming the first device is a BMC chip, the first mode is slave mode, and the second mode is master mode, the process is as follows:
[0214] S1101: The BMC chip receives a third message from the peer device using the I2C controller.
[0215] The third message is generated by the peer device, and the third message can be an MCTP message. The third message is a message indicating the BMC chip to perform an operation. The third message can include instructions, command parameters, data transmission, and other information for operating the BMC chip. At this time, the I2C controller is in slave mode, and the I2C controller acts as a slave device, and the peer device acts as a master device.
[0216] S1102: The BMC chip switches the I2C controller to master mode.
[0217] After receiving the third message, the application program of the BMC chip switches the I2C controller from slave mode to master mode. At this time, the I2C controller is a master device, and the peer device is a slave device. This means that the I2C controller will actively initiate I2C communication and enter transmission mode.
[0218] The process of switching the I2C controller to master mode includes:
[0219] The application program sends a dynamic initialization command word and initialization parameters to the I2C control layer through an ioctl command function. The initialization parameters are used to indicate that the I2C controller is switched to master mode. After receiving the dynamic initialization command word and the initialization parameters, the I2C control layer analyzes the dynamic initialization command word to determine the interface function corresponding to the dynamic initialization command word, that is, the interface function for dynamically initializing the master-slave mode of the I2C controller. Then the I2C control layer calls the interface function to send the initialization parameters to the I2C chip adaptation layer, and the I2C chip adaptation layer switches the I2C controller to master mode according to the initialization parameters. Specifically, the process of switching the I2C controller to master mode according to the initialization parameters can refer to S801-S807 described above.
[0220] S1103: The BMC chip feeds back a fourth message to the peer device using the I2C controller.
[0221] The fourth message can be an MCTP message. The fourth message is data fed back by the BMC chip to the peer device according to the operation of the third message. The BMC chip feeds back the fourth message to the peer device through the I2C controller. At this time, the I2C controller is in master mode, and the I2C controller acts as a master device to send the fourth message to the peer device.
[0222] S1104: The BMC chip switches the I2C controller to slave mode.
[0223] After sending the fourth packet, the application of the BMC chip can also switch the I2C controller back to the slave mode, to prepare for the transmission of the next packet. This means that after completing the reception and processing of the packet, the I2C controller will continue to be in the slave mode, and the I2C controller returns to the mode of receiving I2C communication, so as to receive the next packet or perform other operations.
[0224] Through steps S1101-S1104, the I2C controller can be controlled to switch between the master mode and the slave mode, so that the BMC chip and the peer device can perform bidirectional communication, and data transmission and exchange can be realized.
[0225] The above are some specific implementation manners of the method for switching the master-slave mode of the I2C controller and data transmission provided by the embodiments of the present application. Based on this, the present application also provides a corresponding data transmission device. The data transmission device provided by the embodiments of the present application will be introduced from the perspective of functional modularization. The device comprises:
[0226] The switching module is configured to switch the controller in the first mode from the first mode to the second mode when the first device sends a first packet to the second device based on the controller in the first mode, and the controller in the second mode is configured to receive a second packet fed back by the second device.
[0227] The device is configured to execute the technical solutions in the foregoing method embodiments, and has similar implementation principles and technical effects, which will not be described herein again.
[0228] The embodiments of the present application also provide a BMC chip. The BMC chip is configured to implement the technical solutions in any of the foregoing embodiments.
[0229] The embodiments of the present application also provide a server. The server can comprise a BMC chip, and the BMC chip is configured to implement the data transmission method in any of the foregoing embodiments.
[0230] The server is configured to execute the data transmission method in the foregoing method embodiments, and has similar implementation principles and technical effects, which will not be described herein again.
[0231] The embodiments of the present application also provide a processing chip, which is configured to execute instructions or codes to implement the data transmission method in any of the embodiments of the present application.
[0232] The embodiments of the present application also provide a computer readable storage medium. All or part of the processes in the foregoing method embodiments can be instructed by computer instructions to be completed by related hardware, and the program can be stored in the computer readable storage medium. When the program is executed, the program can include the processes of the foregoing method embodiments. The computer readable storage medium can be the memory in any of the foregoing embodiments.
[0233] The computer readable storage medium mentioned above can also be an external storage device of the computer device, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the computer device. Further, the computer readable storage medium mentioned above can include both an internal storage unit of the computer device and an external storage device. The computer readable storage medium mentioned above is used to store the computer program mentioned above and other programs and data required by the computer device. The computer readable storage medium mentioned above can also be used to temporarily store data that has been output or will be output.
[0234] The "first", "second" in the names mentioned in the embodiments of the present application are only used for name identification, and do not represent the first and second in order.
[0235] From the above description of the embodiments, those skilled in the art can clearly understand that all or part of the steps in the above-mentioned embodiment methods can be implemented by means of software plus a general hardware platform. Based on this understanding, the technical solutions of the present application can be embodied in the form of a software product. The computer software product can be stored in a storage medium, such as a read-only memory (English: read-only memory, ROM) / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions to make a computer device (which can be a personal computer, a server, or a network communication device such as a router) execute the methods described in various embodiments or some parts of the embodiments of the present application.
[0236] Each of the embodiments in the specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other. Each embodiment focuses on the difference from other embodiments. Especially, since the device embodiment is basically similar to the method embodiment, it is described relatively simply, and the relevant parts can be referred to the part of the method embodiment. According to the actual needs, some or all of the modules can be selected to achieve the purpose of the embodiment. Those skilled in the art can understand and implement without creative labor.
[0237] The above is only an exemplary embodiment of the present application, and is not intended to limit the protection scope of the present application.
Claims
1. A data transmission method, characterized by, The method is applied to a first device including a baseboard management controller (BMC) chip, and the method comprises the following steps: When the first device sends a first message to a second device based on a controller in a first mode, in a running process of an operating system of the BMC chip, the first device calls an interface function, and mode switching is performed on the controller according to initialization parameters, so that the controller in the first mode is switched from the first mode to a second mode; the initialization parameters include one or more of master-slave mode, bus rate, slave address and storage space size; the controller is a controller of the BMC chip; the interface function is used for sending the initialization parameters; The controller in the second mode is used for receiving a second message fed back by the second device.
2. The method of claim 1, wherein, The first device calling the interface function and performing mode switching on the controller according to the initialization parameters comprises the following steps: The first device performs mode switching on the controller according to an interface function corresponding to a dynamic initialization command word and initialization parameters; the dynamic initialization command word is used for instructing dynamic initialization of the mode of the controller, and the dynamic initialization of the mode of the controller refers to mode switching of the controller in a data transmission process; the initialization parameters are used for instructing the mode required to be switched by the controller.
3. The method according to claim 2, characterized in that The operating system of the first device comprises an application layer and a driver layer; The first device performing mode switching on the controller according to the interface function corresponding to the dynamic initialization command word and the initialization parameters comprises the following steps: The application layer calls a command function in a character device to send the dynamic initialization command word and the initialization parameters to the driver layer; The driver layer controls the controller to be switched to the mode indicated by the initialization parameters according to the interface function corresponding to the dynamic initialization command word and the initialization parameters.
4. The method of claim 3, wherein, The driver layer comprises a control layer and a chip adaptation layer; the driver layer controlling the controller to be switched to the mode indicated by the initialization parameters according to the interface function corresponding to the dynamic initialization command word and the initialization parameters comprises the following steps: The control layer calls the interface function corresponding to the dynamic initialization command word to send the initialization parameters to the chip adaptation layer; The chip adaptation layer dynamically initializes the controller according to the initialization parameters, and switches the controller to the mode indicated by the initialization parameters.
5. The method of claim 4, wherein, The chip adaptation layer dynamically initializing the controller according to the initialization parameters and switching the controller to the mode indicated by the initialization parameters comprises the following steps: The chip adaptation layer cancels the initialization state of the controller, and dynamically initializes the mode of the controller according to the initialization parameters.
6. The method of claim 5, wherein, The chip adaptation layer canceling the initialization state of the controller comprises the following steps: The chip adaptation layer cancels a first callback function registered by the control layer, and the first callback function is a callback function for realizing data processing functions of the controller in the first mode; The chip adaptation layer cancels the enablement of the controller, and cancels the registration of an interrupt.
7. The method of claim 5, wherein, The chip adaptation layer dynamically initializing the mode of the controller according to the initialization parameters comprises the following steps: The chip adaptation layer registers an interrupt to the control layer, and configures the controller according to the initialization parameter; The chip adaptation layer controls the controller to enable, and registers a second callback function to the control layer, the second callback function being a callback function for the controller to implement a data processing function in the second mode.
8. The method according to any one of claims 1 to 7, characterized in that, When it is required to switch the controller to the master mode, the initialization parameter comprises a master mode type and a bus rate; when it is required to switch the controller to the slave mode, the initialization parameter comprises a slave mode type, a slave address and a storage space size.
9. A data transmission method, characterized by, The method is applied to a first device comprising a baseboard management controller (BMC) chip, and the method comprises: When the first device receives a third packet fed back by a second device based on a controller in a second mode, the first device invokes an interface function in a running process of an operating system of the BMC chip, and performs mode switching on the controller according to an initialization parameter, so as to control the controller in the second mode to switch from the second mode to a first mode; the initialization parameter comprises one or more of a master-slave mode, a bus rate, a slave address and a storage space size; the controller is a controller of the BMC chip; the interface function is used to send the initialization parameter; The controller in the first mode is used to send a fourth packet to the second device.
10. A BMC chip, characterized by, The BMC chip is used to implement the data transmission method according to any one of claims 1-7 or the data transmission method according to claim 9.
11. A server, characterized by The BMC chip is used to implement the data transmission method according to any one of claims 1-8 or the data transmission method according to claim 9.