Interface configuration construction method, system, device, electronic device and storage medium
By building hardware interface functions and operation functions and determining the target interface and operation functions based on hardware resource information, the problem of strong coupling of interface configuration is solved, and the applicability and flexibility of interface configuration is improved.
Patent Information
- Application Number
- CN202411074209.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-07
- Publication Date
- 2024-11-01
- Estimated Expiration
- 2044-08-07
AI Technical Summary
The existing interface configuration has strong coupling, resulting in poor applicability of the interface configuration and cannot continue to be applied when microcontroller units or chips are replaced. The interface configuration needs to be redeveloped.
By building an interface function based on the input parameters and return values of the hardware interface, building an operation function based on the hardware channel information and data operation information, and determining the target hardware interface and operation function based on the hardware resource information of the second device, realizing the decoupling of interface configuration and flexibility.
It realizes decoupling of hardware interfaces and devices, allowing the use of the same interface functions and operation functions to interact, avoiding the problem of redeveloping interface configurations during device switching, and improving the applicability of interface configurations.
Smart Images

Figure CN118605356B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of interface configuration, and in particular to an interface configuration construction method, system, device, electronic equipment and storage medium. Background Art
[0002] The microcontroller unit (MCU) can connect to the chip in the device and exchange data, such as obtaining the feedback signal of the motor. If the microcontroller unit wants to successfully exchange data with the chip, it needs to design the corresponding driver, that is, the interface configuration, and the interaction can only be carried out based on the appropriate interface configuration.
[0003] Currently, the corresponding interface configuration is developed for the specific microcontroller unit and chip used. However, the interface configuration is only applicable to the current microcontroller unit and chip, and the interface configuration has a strong coupling. When the microcontroller unit or chip is replaced, the interface configuration can no longer be applied, and a new interface configuration needs to be developed based on the new microcontroller unit and chip, so the interface configuration has poor applicability. Summary of the invention
[0004] The embodiments of the present invention provide an interface configuration construction method, system, device, electronic device and computer-readable storage medium to solve the problem in the prior art that the interface configuration has strong coupling and thus leads to poor applicability of the interface configuration.
[0005] In a first aspect, an embodiment of the present invention provides an interface configuration construction method, comprising:
[0006] Based on the input parameters and return values of the hardware interface in the first device, an interface function corresponding to the hardware interface is constructed; the hardware interface has at least one hardware channel, and the hardware channel is used for data interaction; the interface function is used to implement the interface function of the hardware interface when executed;
[0007] Based on the interface function, hardware channel information, and data operation information, an operation function corresponding to the hardware interface is constructed; the hardware channel information is used to determine a target hardware channel for data interaction; the operation function is used to perform the interaction operation indicated by the data operation information based on the interface function and the target hardware channel;
[0008] According to the hardware resource information of the second device, determining, in at least one hardware interface, a target hardware interface corresponding to the second device and a target interface function and a target operation function of the target hardware interface;
[0009] Based on the target interface function and the target operation function, an interface configuration for the first device to interact with the second device is constructed.
[0010] In a second aspect, an embodiment of the present invention provides an interface configuration construction system, including:
[0011] configuring a construction device, a first device, and a second device;
[0012] The configuration construction device is used to construct an interface function corresponding to the hardware interface in the first device based on input parameters and return values of the hardware interface; the hardware interface has at least one hardware channel, and the hardware channel is used for data interaction; the interface function is used to implement the interface function of the hardware interface when executed;
[0013] The configuration construction device is used to construct an operation function corresponding to the hardware interface based on the interface function, hardware channel information, and data operation information; the hardware channel information is used to determine a target hardware channel for data interaction; the operation function is used to perform an interaction operation indicated by the data operation information based on the interface function and the target hardware channel;
[0014] The configuration construction device is used to determine, in at least one hardware interface, a target hardware interface corresponding to the second device and a target interface function and a target operation function of the target hardware interface according to the hardware resource information of the second device;
[0015] The configuration building device is used to build an interface configuration for the first device to interact with the second device based on the target interface function and the target operation function.
[0016] In a third aspect, an embodiment of the present invention provides an interface configuration construction device, including:
[0017] An interface function module, configured to construct an interface function corresponding to a hardware interface in a first device based on input parameters and return values of the hardware interface; the hardware interface has at least one hardware channel, and the hardware channel is used for data interaction; the interface function is configured to implement an interface function of the hardware interface when executed;
[0018] An operation function module, used to construct an operation function corresponding to the hardware interface based on the interface function, hardware channel information, and data operation information; the hardware channel information is used to determine a target hardware channel for data interaction; the operation function is used to perform an interaction operation indicated by the data operation information based on the interface function and the target hardware channel;
[0019] a function determination module, configured to determine, in at least one hardware interface, a target hardware interface corresponding to the second device and a target interface function and a target operation function of the target hardware interface according to the hardware resource information of the second device;
[0020] A configuration building module is used to build an interface configuration for interaction between the first device and the second device based on the target interface function and the target operation function.
[0021] In a fourth aspect, an embodiment of the present invention provides an electronic device, comprising: a processor, a communication interface, a memory, and a communication bus; wherein the processor, the communication interface, and the memory communicate with each other via the communication bus;
[0022] Memory, used to store computer programs;
[0023] The processor is used to implement the steps in the interface configuration construction method described in the first aspect when executing the program stored in the memory.
[0024] In a fifth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps in the interface configuration construction method described in the first aspect above.
[0025] Compared with the prior art, the present invention has the following advantages:
[0026] In an embodiment of the present invention, an interface function corresponding to the hardware interface is constructed based on the input parameters and return values of the hardware interface in the first device, and an operation function corresponding to the hardware interface is constructed based on the interface function, hardware channel information, and data operation information; according to the hardware resource information of the second device, in at least one hardware interface, the target hardware interface corresponding to the second device and the operation function corresponding to the target hardware interface are determined, and an interface configuration for interacting with the second device is constructed based on the target interface function and the target operation function. Based on the functionalization of the hardware interface and the functionalization of the interface operation, the decoupling of the hardware interface and the first device can be achieved. When using different first devices or second devices, the same interface function and operation function can be used for interaction, and the corresponding target interface function and target operation function can be flexibly selected based on the hardware resource information required by the second device, thereby avoiding the problem of redeveloping the interface configuration when switching the first device or the second device, thereby improving the applicability of the interface configuration.
[0027] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for describing the embodiments are briefly introduced below.
[0029] Figure 1 A step diagram of an interface configuration construction method provided by an embodiment of the present invention;
[0030] Figure 2 A schematic diagram of the corresponding relationship between the hardware interface and the chip provided in the embodiment of the present invention;
[0031] Figure 3 A step diagram of another interface configuration construction method provided by an embodiment of the present invention;
[0032] Figure 4 A schematic diagram of a hardware interface and an interface function library provided by an embodiment of the present invention;
[0033] Figure 5 A schematic diagram of an interface configuration construction system provided by an embodiment of the present invention;
[0034] Figure 6 A schematic diagram of an interface configuration construction device provided by an embodiment of the present invention;
[0035] Figure 7 A block diagram of an electronic device provided by an embodiment of the present invention.
[0036] Description of reference numerals:
[0037] Microcontrol unit 201, first chip 202, second chip 203, third chip 204; first hardware interface subset 401, second hardware interface subset 402, third hardware interface subset 403, interface function library 404; configuration construction device 501, first device 502, second device 503; interface function module 601, operation function module 602, function determination module 603, configuration construction module 604; processor 701, communication interface 702, memory 703, communication bus 704. DETAILED DESCRIPTION
[0038] The exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can also be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present invention and to enable the scope of the present invention to be fully communicated to those skilled in the art.
[0039] Figure 1 An interface configuration construction method provided by an embodiment of the present invention includes:
[0040] Step 101, based on the input parameters and return values of the hardware interface in the first device, construct an interface function corresponding to the hardware interface; the hardware interface has at least one hardware channel, and the hardware channel is used for data interaction; the interface function is used to implement the interface function of the hardware interface when executed.
[0041] The first device may be a microcontroller unit (MCU), which may be connected to the internal chip of the second device, and may control the second device or obtain data of the second device. The second device may be a motor, etc. The MCU includes at least one hardware interface, which may include an analog input interface (AI, Analog Input), a serial peripheral interface (SPI, Serial Peripheral Interface), a digital output interface (DO, Digital Output), a pulse width modulation interface (PWM, Pulse Width Modulation), a digital input interface (DI, Digital Input), an input capture unit interface (ICU, Input Capture Unit), an internal integrated circuit interface (IIC, Inter-Integrated Circuit) or an I2C interface. These hardware interfaces correspond to different device drivers, i.e., interface configurations.
[0042] Figure 2 Schematic diagram of the correspondence between hardware interfaces and chips provided in the embodiment of the present disclosure; the first device may be a micro control unit 201, which includes multiple hardware interfaces, and each of the four hardware interfaces may correspond to one chip, and the first chip 202, the second chip 203, and the third chip 204 may correspond to different second devices, or may correspond to the same second device. In addition, Figure 2 The number of hardware interfaces and chips in the figure are only examples and can be adjusted according to actual needs.
[0043] According to the input parameters and return values of each hardware interface, the interface function corresponding to the hardware interface can be constructed. When the interface function is executed, it can realize the function of the corresponding hardware interface, for example, it can realize the functions of data receiving and sending through the hardware channel of the hardware interface.
[0044] For example, the SPI interface is mainly used for high-speed data transmission. It usually requires the use of four pin resources: chip select (CS, ChipSelect), clock (CLK, Clock), master input slave output (MISO, Master In Slave Out) and master output slave input (MOSI, Master Out Slave In). It uses a synchronous method to interact with data and abstractly encapsulates the SPI interface function. The interface function can be:
[0045] typedefStd_ReturnType(*HW_SpiSendDataFun)(uint8*SrcBufPtr,uint8*DesBufPtr,uint16Length);
[0046] The input parameters are: send data (data in SrcBufPtr), receive data (data in DesBufPtr) and data length (Length). The return value (Std_ReturnType) indicates whether the sending is successful. Function: Send the data in SrcBufPtr, the data length is Length, and synchronously save the received data in DesBufPtr.
[0047] The PWM interface is mainly used in scenarios such as fan speed regulation and analog communication. Usually only one pin is needed for output. The cycle and duty cycle of the PWM signal need to be controlled. The PWM interface function is abstractly encapsulated. The interface function can be:
[0048] typedefStd_ReturnType(*HW_PwmSetPeriodAndDutyFun)(uint32Period,uint16Duty);
[0049] The input parameters include: period (Period), duty cycle (Duty). The return value (Std_ReturnType) indicates whether the output is successful. Function: Configure the PWM interface according to the input period and duty cycle to achieve PWM signal output.
[0050] The ICU interface is mainly used to collect PWM signals fed back by devices such as fans. Usually only one pin is needed for collection. The period and duty cycle of the PWM signal need to be collected. The ICU interface function is abstractly encapsulated. The interface function can be:
[0051] typedef Icu_captureValType(*HW_IcuGetPeriodAndDutyFun)(void);
[0052] The input parameters of the interface function of the ICU interface can be empty. The return value (Icu_captureValType) contains the period and duty cycle of the captured PWM signal. Function: Collect the period and duty cycle of the input PWM signal and store them in the structure. The structure is as follows:
[0053] typedefstruct{
[0054] uint32 IcuPeriodVal; period;
[0055] uint16 IcuDutyVal; duty cycle;
[0056] }Icu_captureValType;return value;
[0057] The DO interface is mainly used to control the high and low levels of the input and output ports. The DO interface function is abstracted and encapsulated, and the interface function can be:
[0058] Typedef Std_ReturnType(*HW_SetPinLevelFun)(uint8Level);
[0059] The input parameters include: level control parameter (Level), when the level control parameter is 0, it indicates low level, and when the level control parameter is 1, it indicates high level. The return value (Std_ReturnType) indicates whether the output is successful. Function: Control the input and output ports to output low level or high level according to the level control parameter (0 or 1).
[0060] The DI interface is mainly used to collect the high and low levels of the input and output ports. The DI interface function is abstracted and encapsulated, and the interface function can be:
[0061] Typedef Std_ReturnType(*HW_DI DataGetFun)(uint8*Level);
[0062] The input parameters include: level data (Level), when the level data is 0, it indicates a low level, and when the level data is 1, it indicates a high level. The return value (Std_ReturnType) indicates whether the acquisition is successful. Function: Collect the high and low levels of the input and output ports, save the collected high and low levels into the level data, and return the acquisition status.
[0063] The AI interface is mainly used to collect the voltage value of analog signal input. The AI interface function is abstracted and encapsulated, and the interface function can be:
[0064] typedefStd_ReturnType(*HW_AiDataGetFun)(uint16*data);
[0065] The input parameters include: collected voltage data (data). The return value (Std_ReturnType) indicates whether the collection is successful. Function: Collect the voltage value of the analog signal input, save the collected data in the voltage data, and return the collection status.
[0066] The I2C interface is mainly used for low-speed data transmission between chips. It usually requires SDA and SCL2 pin resources, uses synchronous mode for data exchange, and abstractly encapsulates the sending function of the I2C interface. The interface function can be:
[0067] typedefStd_ReturnType(*HW_I2CSendDataFun)(uint8*SrcBufPtr,uint16Length);
[0068] The input parameters include: send data (data in SrcBufPtr) and data length (Length). The return value (Std_ReturnType) indicates whether the sending is successful. Function: Send the data in SrcBufPtr, the length is Length.
[0069] Step 102, constructing an operation function corresponding to the hardware interface based on the interface function, hardware channel information, and data operation information; the hardware channel information is used to determine a target hardware channel for data interaction; the operation function is used to perform the data interaction operation indicated by the data operation information based on the interface function and the target hardware channel.
[0070] In the disclosed embodiment, an operation function corresponding to a hardware interface can be constructed based on an interface function, hardware channel information, and data operation information. The interface function represents a functionalized hardware interface, and by further specifying the hardware channel information, the hardware channel based on which the data interaction operation is to be performed can be clearly defined.
[0071] Among them, the hardware channel information can be used to represent the hardware channel SPISend_Channel corresponding to the SPI interface, used to represent the hardware channel ICU_Channel corresponding to the IUC interface, used to represent the hardware channel IORead_DiPin corresponding to the input and output interface, used to represent the hardware channel PWM_Channel corresponding to the PWM interface and other hardware channel information, which is not limited here.
[0072] By continuing to specify the data operation information, it is possible to clearly define what kind of data interaction is to be performed, such as data sending or data receiving, and specific parameters of the data interaction, such as data length.
[0073] For example, data interaction based on the SPI interface relies on hardware channels and hardware queues. The data to be sent and received is associated with the hardware channel through macro definitions, and then the hardware queue is started to complete the data transmission. The following is an example of the macro-defined operation function:
[0074] #defineHW_SPISendFunDef(SPISend_FunName,SPISend_Channel,SPISend_Sequence);Macro name: HW_SPISendFunDef, macro parameters: SPISend_FunName (SPI interface function name) SPISend_Channel (SPI interface channel), SPISend_Sequence (SPI interface send queue);
[0075] staticStd_ReturnTypSPISend_FunName(uint8*SrcBufPtr,uint8*DesBufPtr,uint16Length); Define the SPI interface sending function named SPISend_FunName, which includes three parameters: SrcBufPtr (pointer to the source data buffer), DesBufPtr (pointer to the target data buffer), Length (length of data to be sent);
[0076] Std_ReturnType res; The function returns a res value of Std_ReturnType type;
[0077] Call SPISend_Channel and SPISend_Sequence hardware interfaces to send data;
[0078] Spi_SetupEB(SPISend_Channel,SrcBufPtr,DesBufPtr,Length);Set the send data, receive data and data length;
[0079] res = Spi_SyncTransmit (SPISend_Sequence); Start hardware transmission, call SPISend_Channel and SPISend_Sequence hardware interfaces to send data;
[0080] Return res; return res value.
[0081] Among them, the input parameters include: interface function name (SPISend_FunName), hardware channel information (SPISend_Channel), and SPI interface send queue (SPISend_Sequence).
[0082] The hardware channel information (SPISend_Channel), data operation information (hardware interface sends data, sets send data, receives data and data length, starts hardware transmission, and returns value) corresponding to the SPI interface can be associated with the interface function corresponding to SPISend_FunName to quickly generate the operation function of the SPI interface.
[0083] PWM signal output requires associating the hardware channel with the PWM interface. The following is an example of macro definition:
[0084] #defineHW_PWMOutPut_DutyFunDef(PWMOut_FunName,PWM_Channel); Macro name: HW_PWMOutPut_DutyFunDef; Macro parameters: PWMOut_FunName (interface function name of the PWM interface); PWM_Channel (channel of the PWM signal).
[0085] staticStd_ReturnTypePWMOut_FunName(uint16Duty); defines a static function named PWMOut_FunName, whose return type is Std_ReturnType and includes a parameter Duty of type uint16 (indicating the duty cycle of the PWM signal);
[0086] returnBsp_Pwm_OutPut(PWM_Channel,Duty); Call the Bsp_Pwm_OutPut function and pass the channel and duty cycle of the PWM signal as parameters; The Bsp_Pwm_OutPut function sets the output of the PWM signal according to the given channel and duty cycle of the PWM signal.
[0087] The input parameters include: interface function name (PWMOut_FunName), hardware channel information (PWM_Channel). Through the above macro definition process, the hardware channel information (PWM_Channel) corresponding to the PWM interface, data operation information (calling Bsp_Pwm_OutPut function, transmitting the channel and duty cycle of the PWM signal, setting the PWM signal output) and the interface function corresponding to PWMOut_FunName are associated, and the operation function of the PWM interface can be quickly generated.
[0088] The implementation of the input capture unit acquisition function requires associating the hardware channel with the ICU interface. The following is an example of the macro-defined operation function:
[0089] #defineHW_ICUGetFunDef(ICUGet_FunName,ICU_Channel);Macro name: HW_ICUGetFunDef,Macro parameters: ICUGet_FunName(Interface function of ICU interface),ICU_Channel(Channel of ICU interface);
[0090] Static Icu_captureValTypeICUGet_FunName(void); The expansion part of the macro definition creates a static Icu_captureValType type function ICUGet_FunName, which does not accept any parameters and has a return type of Icu_captureValType;
[0091] ...Other treatments...
[0092] returnBsp_IcuGetDutyandFre(ICU_Channel); Read the collected ICU information;
[0093] The input parameters include: interface function name (ICUGet_FunName), hardware channel information (ICU_Channel); through the above macro definition process, the hardware channel information (ICU_Channel) of the ICU interface, data operation information (reading the input capture unit information collected by the hardware) and the interface function corresponding to ICUGet_FunName can be associated, and the operation function of the ICU interface can be quickly generated.
[0094] The function implementation of the DO interface requires associating the corresponding hardware channel to the DO interface. The following is an example of macro definition:
[0095] #defineHW_IOConFUNDef(IOSet_FunName,IOSet_ConPin);Macro name: HW_IOConFUNDef ,Macro parameters: IOSet_FunName(interface function of DO interface),hardware channel information(IOSet_ConPin);
[0096] staticStd_ReturnTypeIOSet_FunName(uint8Level); The macro defines a static function IOSet_FunName, which accepts a parameter Level of type uint8 and has a return type of Std_ReturnType;
[0097] ...Other treatments...
[0098] Res=Dio_WriteChannel(IOSet_ConPin,Level);Hardware output high and low levels;
[0099] ...Other treatments...
[0100] Return res; return res value.
[0101] The input parameters include: interface function name (IOSet_FunName), hardware channel information (IOSet_ConPin). Through the above macro definition process, the hardware channel information (IOSet_ConPin), data operation information (output high and low levels, return value) corresponding to the DO interface and the interface function corresponding to IOSet_FunName can be associated, and the operation function of the DO interface can be quickly generated.
[0102] To realize the acquisition of the DI interface function, you need to associate the corresponding hardware channel with the DI interface. The following is an example of the macro-defined operation function:
[0103] #define HW_IOReadFUNDef(IORead_FunName,IORead_DiPin);Macro name: HW_IOReadFUNDef,Macro parameters: IORead_FunName(interface function name of DI interface),hardware channel information(IORead_DiPin);
[0104] staticStd_ReturnTypeIORead_FunName(uint8*Level); defines the interface function IORead_FunName, Std_ReturnType is the return type of the function, uint8* Level is the function parameter, and points to a pointer of type uint8;
[0105] ...Other treatments...
[0106] *Level=DIo_ReadChannel(IORead_DIPin);Hardware read level;
[0107] ...Other treatments...
[0108] Return res; Return res value;
[0109] The input parameters include: interface function name (IORead_FunName) and hardware channel information (IORead_DiPin).
[0110] Through the above macro definition process, the hardware channel information (IORead_DiPin), data operation information (reading level, return value) corresponding to the DI interface and the interface function corresponding to IORead_FunName can be associated, and the operation function of the DI interface can be quickly generated.
[0111] To realize the acquisition of AI interface functions, you need to associate the corresponding hardware channel with the AI interface. The following is an example of the macro-defined operation function:
[0112] #defineHW_ADCGetDataFunDef(ADCGet_FunName,AI_Index);Macro name: HW_ADCGetDataFunDef,Macro parameters: ADCGet_FunName(interface function name of AI interface),hardware channel information(AI_Index);
[0113] staticStd_ReturnTypeADCGet_FunName(uint16*data); A static function ADCGet_FunName is declared using the static keyword, which accepts a pointer data of type uint16 *;
[0114] ...Other treatments...
[0115] *data=Bsp_Adc_Get_Val(AI_Index);Get the analog input signal value collected by hardware;
[0116] ...Other treatments...
[0117] Return res; return res value.
[0118] The input parameters include: interface function name (ADCGet_FunName), hardware channel information (AI_Index). You can associate the hardware channel information (AI_Index) corresponding to the AI interface, data operation information (getting the analog input signal value collected by the hardware, return value) and the interface function corresponding to ADCGet_FunName to quickly generate the operation function of the AI interface.
[0119] The data transmission function of the I2U interface needs to associate the corresponding hardware channel and slave address with the I2C channel. The following is an example of the macro-defined operation function:
[0120] #defineHW_I2CSendFunDef(I2CSend_FunName,I2cChannel,I2cSlaveAddr) defines a macro HW_I2CSendFunDef, macro parameters: I2CSend_FunName (interface function name of I2C interface), hardware channel information (I2cChannel), slave address (I2cSlaveAddr);
[0121] staticStd_ReturnTypeI2CSend_FunName(uint8*SrcBufPtr,uint16Length); defines an interface function I2CSend_FunName, including two parameters: uint8* SrcBufPtr represents the pointer of the source buffer, and uint16 Length represents the length of the data to be sent;
[0122] ...Other treatments...
[0123] ret = I2c_write (I2cGlobalDev [I2cChannel], I2cSlaveAddr, SrcBufPtr, Length); write the data of length Length in SrcBufPtr to the slave address I2cSlaveAddr based on the I2C interface and hardware channel I2cChannel;
[0124] ...Other treatments...
[0125] Return res; return res value.
[0126] The input parameters include: interface function name (I2CSend_FunName), hardware channel information (I2cChannel), and slave address (I2cSlaveAddr).
[0127] Through the above macro definition process, the hardware channel information (I2cChannel) corresponding to the I2C sending interface, the data operation information (the data with a length of Length in SrcBufPtr is written to the slave address I2cSlaveAddr and the return value based on the I2C hardware sending interface hardware channel I2cChannel) and the interface function corresponding to I2CSend_FunName can be associated, and the operation function of the I2C interface can be quickly generated.
[0128] The data receiving function of the I2C interface needs to associate the corresponding hardware channel and slave address with the I2C channel. The following is an example of the macro-defined operation function:
[0129] #defineHW_I2CReadFunDef(I2CRead_FunName,I2cChannel,I2cSlaveAddr) defines the macro HW_I2CSendFunDef, macro parameters: I2CSend_FunName (interface function name of the I2C interface), hardware channel information (I2cChannel), slave address (I2cSlaveAddr);
[0130] staticStd_ReturnTypeI2CRead_FunName(uint8*SrcBufPtr,uint16Length); defines the static function I2CSend_FunName, Std_ReturnType is the return type, uint8 *SrcBufPtr and uint16Length are input parameters, which represent the data buffer pointer and data length to be read respectively;
[0131] ...Other treatments...
[0132] ret = I2c_read (I2cGlobalDev [I2cChannel], I2cSlaveAddr, SrcBufPtr, Length); write the data of length Length in SrcBufPtr to the slave address I2cSlaveAddr based on the I2C interface and hardware channel I2cChannel;
[0133] ...Other treatments...
[0134] return res; return res value.
[0135] The input parameters include: interface function name (I2CSend_FunName), hardware channel information (I2cChannel), slave address (I2cSlaveAddr). Through the above macro definition process, the hardware channel information (I2cChannel) corresponding to the I2C interface, data operation information (write the data with length Length in SrcBufPtr to the slave address I2cSlaveAddr based on the I2C interface and hardware channel I2cChannel, return value) and the interface function corresponding to I2CSend_FunName can be associated to quickly generate the operation function of the I2C interface.
[0136] Step 103: Determine, in at least one hardware interface, a target hardware interface corresponding to the second device and a target interface function and a target operation function of the target hardware interface according to the hardware resource information of the second device.
[0137] In the embodiments of the present disclosure, it can be understood that the hardware resource information of the second device is determined according to the function of the second device or the operation to be implemented. Different second devices have different hardware resource information. The hardware resource information may point to specific channels and pins, or directly point to specific hardware interfaces. For example, the hardware resource information may include SEL pins (SEL0PinSet), control pins 1 (ConPin1Set), control pins 2 (ConPin2Set), current acquisition channels (ANPin), and more.
[0138] The pins and hardware channels in the above-mentioned hardware resource information can correspond to different interfaces, and the functions of the interfaces can be realized through pins and hardware channels, and each interface corresponds to different pins and hardware channels. Based on the pins and hardware channels in the hardware resource information, the corresponding target hardware interface can be determined in at least one hardware interface provided by the microcontroller unit, such as an SPI interface, a DO interface, a DI interface, and more interfaces. Since the corresponding interface function and operation function have been constructed based on the hardware interface of the microcontroller unit, the target interface function and target operation function corresponding to the target hardware interface can be determined based on the target hardware interface.
[0139] For example, when the target hardware interface is an SPI interface, the target interface function is: "typedefStd_ReturnType(*HW_SpiSendDataFun)(uint8*SrcBufPtr,uint8*DesBufPtr,uint16Length)".
[0140] Then the target operation function is:
[0141] #defineHW_SPISendFunDef(SPISend_FunName,SPISend_Channel,SPISend_Sequence;
[0142] staticStd_ReturnTypSPISend_FunName(uint8*SrcBufPtr,uint8*DesBufPtr,uint16Length);
[0143] Std_ReturnType res;
[0144] Spi_SetupEB(SPISend_Channel,SrcBufPtr,DesBufPtr,Length);
[0145] res=Spi_SyncTransmit(SPISend_Sequence);
[0146] Return res;
[0147] When there are more target hardware interfaces, there are correspondingly more target interface functions and target operation functions, which are not specifically limited here.
[0148] For example, when the second device includes a VNH7070 chip, the target interface function corresponding to the above hardware resource information may be the target interface function in the following structure:
[0149] typedef struct
[0150] {
[0151] HW_SetPinLevelFun SEL0PinSet; Interface function of the DO interface used to control the high and low levels of the pin (SEL0PinSet);
[0152] HW_SetPinLevelFun ConPinSet[VNH7070_OUT_NULL]; Interface function of the DO interface used to control the high and low levels of the pin (ConPinSet);
[0153] HW_AiDataGetFun CsAdGetFun; Interface function of AI interface used to obtain voltage data;
[0154] HW_PwmSetPeriodAndDutyFun PwmOutFun; Interface function of the PWM interface used to control the PWM signal output;
[0155] boolean BridgeMode; indicates bridge mode (chip control mode);
[0156] ...Other configuration information...
[0157] } VNH7070_ConfigType.
[0158] The operation function may be an operation function in IOConFUNDef, a macro name corresponding to the DO interface, and an operation function in ADCGetDataFunDef, a macro name corresponding to the AI interface.
[0159] It can be understood that pins can be used for data exchange between the chip and external devices, hardware channels can be data transmission paths within the chip, interfaces can be logic function modules within the chip, interfaces can correspond to multiple pins, and interface functions can be realized through multiple pins. There is a certain correspondence between pins, hardware channels, and interfaces.
[0160] Step 104: construct an interface configuration for the first device to interact with the second device based on the target interface function and the target operation function.
[0161] In the disclosed embodiment, the process of constructing the interface configuration based on the target interface function and the target operation function can be through macro definition, first associating the hardware resources (pins, channels) represented by the hardware resource information and the target operation function to construct an instantiated interface.
[0162] Taking the second device as an example, which is a device including a single VNH7070 chip, the instantiation interface may be represented by the following macro definition:
[0163] #defineVNH7070HBINITDEF(HBNUM,SEL0PinSet,ConPin1Set,ConPin2Set,ANPin)
[0164] HW_IOConFUNDef(HW_##HBNUM##_VNH7070_SEL0PinSet, SEL0PinSet); Associate the operation function of the DO interface (the operation function defined in the macro IOConFUNDef) with the pin (SEL0PinSet);
[0165] HW_IOConFUNDef(HW_##HBNUM##_VNH7070_ConPin1Set, ConPin1Set); Associate the operation function of the DO interface (the operation function defined in the macro IOConFUNDef) with the control pin 1 (ConPin1Set);
[0166] HW_IOConFUNDef(HW_##HBNUM##_VNH7070_ConPin2Set, ConPin2Set); Associate the operation function of the DO interface (the operation function defined in the macro IOConFUNDef) with the control pin 2 (ConPin2Set);
[0167] HW_ADCGetDataFunDef(HW_##HBNUM##_VNH7070_CsAdGetFun, ANPin); Associate the current acquisition operation function (CsAdGetFun) with the current acquisition channel (ANPin);
[0168] The input parameters of the above macro definition include the device name (HBNUM) and hardware resource information (SEL pin, control pin 1, control pin 2, current acquisition channel). The macro definition also includes multiple operation functions (3 macros named IOConFUNDef and the operation function in the macro named ADCGetDataFunDef).
[0169] The instantiation interface of the above single VNH7070 chip can be applied to multiple, for example, four VNH7070 chips. The pins and hardware channels used by each VNH7070 chip can be different. Then the instantiation interfaces corresponding to the four VNH7070 chips can be as follows:
[0170] VNH7070HBINITDEF(HB_DEV_2A_VNF7070_1,DO_HB_2A_SEL1, DO_HB_2A_IN1,DO_HB_2A_IN2,AI_HB_2A_OUT1); indicates that the chip HB_DEV_2A_VNF7070_1 includes the current selection pin DO_HB_2A_SEL1, the control channel pins DO_HB_2A_IN1 and DO_HB_2A_IN2, and the current acquisition channel AI_HB_2A_OUT1;
[0171] VNH7070HBINITDEF(HB_DEV_2A_VNF7070_2,DO_HB_2A_SEL2, DO_HB_2A_IN3,DO_HB_2A_IN4,AI_HB_2A_OUT2); indicates that the chip HB_DEV_2A_VNF7070_2 includes the current selection pin DO_HB_2A_SEL2, the control channel pins DO_HB_2A_IN3 and DO_HB_2A_IN4, and the current acquisition channel AI_HB_2A_OUT2;
[0172] VNH7070HBINITDEF(HB_DEV_5A_VNF7070_1,DO_HB_5A_SEL1, DO_HB_5A_IN1,DO_HB_5A_IN2,AI_HB_5A_OUT1); indicates that the chip HB_DEV_5A_VNF7070_1 includes the current selection pin DO_HB_5A_SEL1, the control channel pins DO_HB_5A_IN1 and DO_HB_5A_IN2, and the current acquisition channel AI_HB_5A_OUT1;
[0173] VNH7070HBINITDEF(HB_DEV_5A_VNF7070_2,DO_HB_5A_SEL2, DO_HB_5A_IN3,DO_HB_5A_IN4,AI_HB_5A_OUT2); indicates that the chip HB_DEV_5A_VNF7070_2 includes the current selection pin DO_HB_5A_SEL1, the control channel pins DO_HB_5A_IN1 and DO_HB_5A_IN2, and the current acquisition channel AI_HB_5A_OUT2;
[0174] Among them, HB_DEV_2A_VNF7070_1: indicates the name of the first VNH7070 chip, and the hardware module carries 2 amperes (A); DO_HB_2A_SEL1: indicates the current selection pin of the first VNH7070 chip, and the hardware module carries 2A; DO_HB_2A_IN1, DO_HB_2A_IN2: indicate the pins of the two control channels of the first VNH7070 chip, and the hardware module carries 2A; AI_HB_2A_OUT1: indicates the current acquisition channel of the first VNH7070 chip, and the hardware module carries 2A. The meanings of the pins corresponding to the other three VNH7070 chips in the above code are similar, and will not be repeated here. Based on the construction of the operation function based on the data operation information macro definition, the hardware resource information of a chip is macro-defined using the secondary macro definition, which can determine the hardware resources required by a chip as a whole and form a single-chip device resource macro definition. Based on the existing single-chip device resource macro definition, the device resource macro definition can be reused to multiple chips, and each chip can be associated with its own hardware resources and target operation functions, so as to realize batch construction operations of chip instantiation interfaces and improve configuration construction efficiency.
[0175] Furthermore, macro definition can be performed based on the instantiated interface and the interface function in the structure to generate the interface configuration. The specific macro definition process can be as follows:
[0176] #define VNH7070InitConfigDEF(HBNUM); define the interface configuration of the device corresponding to HBNUM;
[0177] SEL0PinSet = HW_##HBNUM##_VNH7070_SEL0PinSet; associate the current selection instantiation interface with the target interface function corresponding to SEL0PinSet through instantiation assignment;
[0178] . ConPinSet[0] = HW_##HBNUM##_VNH7070_ConPin1Set; associate the instantiated control channel 1 interface with the target interface function corresponding to ConPinSet[0] through instantiation assignment;
[0179] .ConPinSet[1] = HW_##HBNUM##_VNH7070_ConPin2Set; Associate the instantiated control channel 2 interface with the target interface function corresponding to ConPinSet[1] through instantiation assignment;
[0180] .CsAdGetFun = HW_##HBNUM##_VNH7070_CsAdGetFun; Associate the instantiated current acquisition interface with the target interface function corresponding to CsAdGetFun through instantiation assignment;
[0181] .PwmOutFun = NULL_PTR; associate the instantiated PWM interface with the target interface function corresponding to .PwmOutFun through instantiation assignment;
[0182] BridgeMode = FALSE; drive control mode assignment;
[0183] ...Other information assignments...
[0184] The input parameters include the device name (HBNUM). The above macro definition process can associate and package the instantiation interface and the target interface function through instantiation assignment to generate an interface configuration. The generated interface configuration can be the following interface configuration:
[0185] VNH7070_ConfigType sHB_VNH7070_Config[VNH7070NUM] = {
[0186] VNH7070InitConfigDEF(HB_DEV_2A_VNF7070_1); Interface configuration for instantiation of 2A control chip 1;
[0187] VNH7070InitConfigDEF(HB_DEV_2A_VNF7070_2); Interface configuration instantiated for the 2A control chip 2;
[0188] VNH7070InitConfigDEF(HB_DEV_5A_VNF7070_1); Interface configuration instantiated for the 5A control chip 1;
[0189] VNH7070InitConfigDEF(HB_DEV_5A_VNF7070_2); Interface configuration instantiated for the 5A control chip 2.
[0190] It can be understood that, depending on the interface configuration, the interactions that can be performed based on the interface configuration can also be different. For example, various functional designs such as device initialization, control, and current feedback can be implemented:
[0191] Call the initialization function of the interface configuration and transmit the chip configuration information in sequence. The process of completing chip initialization is as follows:
[0192] void Bsp_HB_Init(void); Initialize through the Bsp_HB_Init function;
[0193] ...... Other processing......
[0194] for (i = 0; i < VNH7070NUM; i++); Initialize the variable i to 0. i++ is an iteration expression. After each loop ends, the value of i will increase by 1 until i exceeds the value corresponding to VNH7070NUM;
[0195] { / / Initialize the HB device
[0196] CDD_VNH7070_Init(&sHB_VNH7070_Config[i]); Call the configuration information to complete driver initialization;
[0197] ...... Other processing......
[0198] The process of calling the functional DO interface to implement the chip initialization logic is as follows:
[0199] void CDD_VNH7070_Init(VNH7070_ConfigType* ConfigPtr) {
[0200] ...... Other processing......
[0201] HW_ExeOneParamFun(ConfigPtr->ConPinSet[0], STD_LOW, res); Default to turn off output 1;
[0202] HW_ExeOneParamFun(ConfigPtr->ConPinSet[1],STD_LOW,res);Output 2 is disabled by default;
[0203] HW_ExeOneParamFun(ConfigPtr->SEL0PinSet,STD_HIGH,res);Default current acquisition channel 1;
[0204] ...Other treatments...
[0205] }
[0206] The process of calling the operation function configured by the interface to realize the drive output control is as follows:
[0207] case (uint16) HB_DEV_2A_VNF7070_1; The case statement specifies a constant HB_DEV_2A_VNF7070_1 of type uint16 to match the driver chip;
[0208] case (uint16) HB_DEV_2A_VNF7070_2; The case statement specifies a constant HB_DEV_2A_VNF7070_2 of type uint16 to match the driver chip;
[0209] case (uint16) HB_DEV_5A_VNF7070_1; The case statement specifies a constant HB_DEV_5A_VNF7070_1 of type uint16 to match the driver chip;
[0210] case (uint16) HB_DEV_5A_VNF7070_2; The case statement specifies a constant HB_DEV_5A_VNF7070_2 of type uint16 to match the driver chip;
[0211] ...Other treatments...
[0212] res=CDD_VNH7070_PutOut(&sHB_VNH7070_Config[u16Temp],u16Ch,ConSta);Call the driver control interface;
[0213] ...Other treatments...
[0214] }break;
[0215] The process of calling the functionalized DO interface to realize the chip drive control output function is as follows:
[0216] Std_ReturnTypeCDD_VNH7070_PutOut(*ConfigPtr,CH,Hbmode){
[0217] ...Other treatments...
[0218] switch (Hbmode); control mode identification;
[0219] caseVNH7070_HB_MODE_LS; Half-bridge mode: low-side output;
[0220] res=ConfigPtr->ConPinSet[CH](STD_LOW); call the abstract interface and output the control signal;
[0221] }
[0222] The process of calling the current acquisition function configured by the interface to realize the drive load current acquisition function is as follows:
[0223] case (uint16) HB_CURR_SEL0_AI_HB_2A_OUT1; Matching chip current channel;
[0224] case (uint16) HB_CURR_SEL1_AI_HB_2A_OUT1; Matching chip current channel;
[0225] ...Other treatments...
[0226] res=CDD_VNH7070_Get_LoadCurrent(&sHB_VNH7070_Config[u16Temp],u8Ch);Call the current acquisition function;
[0227] ...Other treatments...
[0228] }break;
[0229] The process of calling the functionalized AI interface to implement the chip current acquisition function is as follows:
[0230] uint16CDD_VNH7070_Get_LoadCurrent(VNH7070_ConfigType*ConfigPtr,uint8Ch)
[0231] ...Other treatments...
[0232] ConfigPtr->CsAdGetFun(&AiTemp);Call AI acquisition interface;
[0233] ...Other treatments...
[0234] return AiTemp.
[0235] The various functional designs that can be implemented by the above-mentioned interface configuration method are not specifically limited here.
[0236] In summary, in the embodiment of the present invention, an interface function corresponding to the hardware interface is constructed based on the input parameters and return values of the hardware interface in the first device, and an operation function corresponding to the hardware interface is constructed based on the interface function, hardware channel information, and data operation information; according to the hardware resource information of the second device, in at least one hardware interface, the target hardware interface corresponding to the second device and the target operation function corresponding to the target hardware interface are determined, and based on the target interface function and the target operation function, an interface configuration for interacting with the second device is constructed. Based on the functionalization of the hardware interface and the functionalization of the interface operation, the decoupling of the hardware interface and the first device can be achieved. When using different first devices or second devices, the same interface function and operation function can be used for interaction, and the corresponding target interface function and target operation function can be flexibly selected based on the hardware resource information required by the second device, thereby avoiding the problem of redeveloping the interface configuration when switching the first device or the second device, thereby improving the applicability of the interface configuration.
[0237] Optional, Figure 3 is a step diagram of another interface configuration construction method provided by an embodiment of the present disclosure;
[0238] Step 301, constructing an interface function corresponding to the hardware interface in the first device based on input parameters and return values of the hardware interface; the hardware interface has at least one hardware channel, and the hardware channel is used for data interaction; the interface function is used to implement the interface function of the hardware interface when executed;
[0239] Step 302, constructing an operation function corresponding to the hardware interface based on the interface function, hardware channel information, and data operation information; the hardware channel information is used to determine a target hardware channel for data interaction; the operation function is used to perform the interaction operation indicated by the data operation information based on the interface function and the target hardware channel;
[0240] Step 303, determining a target hardware interface corresponding to the second device and a target interface function and a target operation function of the target hardware interface in at least one hardware interface according to the hardware resource information of the second device;
[0241] Step 304: construct an interface configuration for the first device to interact with the second device based on the target interface function and the target operation function.
[0242] The specific contents of steps 301-304 can refer to the above Figure 1 The embodiments of the present invention will not be described in detail here.
[0243] Optionally, the hardware resource information includes interface indication information and channel indication information;
[0244] The step 303 of determining, in at least one hardware interface according to the hardware resource information of the second device, a target hardware interface corresponding to the second device and a target interface function and a target operation function of the target hardware interface comprises:
[0245] Sub-step 3031, determining a corresponding target hardware interface in at least one hardware interface according to the interface indication information;
[0246] Sub-step 3032, obtaining a target interface function and at least one operation function corresponding to the target hardware interface; each operation function carries hardware channel information;
[0247] Sub-step 3033: determining a matching target operation function in the at least one operation function according to the channel indication information; the target operation function has hardware channel information matching the channel indication information.
[0248] In the disclosed embodiment, the corresponding target hardware interface can be first determined in at least one hardware interface according to the interface indication information, and the target interface function corresponding to the target hardware interface can be obtained. The interface indication information can record information such as the interface name or interface type, where the interface name can include AI interface, SPI interface, DO interface, PWM interface, DI interface, ICU interface and I2C interface, as well as other interface names, which are not limited here. There are also some interfaces that are the same but have different functions, so the interface type information can be distinguished, for example, the I2C interface has two corresponding types of sending interface and receiving interface.
[0249] Since the interface function and the operation function corresponding to the interface are pre-constructed, the target interface function and at least one operation function corresponding to the target hardware interface can be determined according to the determined target hardware interface.
[0250] For example, corresponding to Figure 1 According to the content of the embodiment, the interface function can be SPISendDataFun, PwmSetPeriodAndDutyFun, IcuGetPeriodAndDutyFun, SetPinLevelFun, DiDataGetFun, AiDataGetFun, I2CSendDataFun, and I2CReadDataFun.
[0251] In addition, an operation function is constructed based on the interface function of the hardware interface as well as the hardware channel information and data operation information. Different operation functions can be constructed based on different hardware channel information and data operation information. Each operation function can carry the name of the interface function (SPISendDataFun, PwmSetPeriodAndDutyFun or others) and hardware channel information (SPISend_Channel, PWM_Channel, ICU_Channel or others), which can represent the interface function and hardware channel corresponding to the current operation function.
[0252] Then, according to the channel indication information, in at least one operation function, a matching target operation function is determined, and the hardware channel pointed to by the hardware channel information of the target operation function is the same as the hardware channel pointed to by the channel indication information. The channel indication information can be similar to the hardware channel information, both of which indicate the hardware channels that some interfaces need to use. The difference is that the hardware channel indicated by the hardware channel information is used in the construction process of the operation function, and the hardware channel indicated by the channel indication information is used in the selection process of the operation function. Therefore, the channel indication information can also be the names of SPISend_Channel, PWM_Channel, ICU_Channel and more hardware channels.
[0253] By implementing the embodiments of the present disclosure, the corresponding target hardware interface and the corresponding target interface function can be determined according to the interface indication information; after obtaining at least one operation function corresponding to the target hardware interface, the target operation function can be accurately matched according to the channel indication information, thereby improving the accuracy of interface configuration construction.
[0254] Optionally, the second device includes at least one interaction chip, and the second device performs data interaction with the first device through the interaction chip;
[0255] The method further comprises:
[0256] Determining the target hardware interface corresponding to each of the at least one interactive chip according to the hardware resource information corresponding to each of the at least one interactive chip;
[0257] The target operation function corresponding to the target hardware interface is encapsulated to obtain an operation function structure of the second device.
[0258] In the embodiment of the present disclosure, the second device includes at least one interactive chip (for example, a VNH7070 chip), and the second device interacts with the first device through the interactive chip. Each interactive chip actually interacts with data through different or partially different hardware interfaces. Then, the hardware resource information may include sub-hardware resource information, and each sub-hardware resource information corresponds to an interactive chip.
[0259] It is necessary to determine the target hardware interface corresponding to at least one interactive chip based on the hardware resource information. For example, the hardware interfaces corresponding to model A chip are AI interface and SPI interface, and the hardware interfaces corresponding to model B chip are DO interface and DI interface. The target hardware interface corresponding to at least one interactive chip and the corresponding target operation functions are uniformly encapsulated to obtain the operation function structure of the second device as a whole. The operation functions of the operation function structure include the operation functions required for the interaction of each chip inside the second device. Encapsulation as an operation function structure enables the subsequent generation of the interface configuration based on the target interface function and the target operation function to directly obtain the interface function required by the second device as a whole, avoiding the need to separately and individually obtain the interface functions corresponding to each chip, thereby improving the efficiency of generating interface configuration.
[0260] Optionally, there is at least one target hardware interface; and the step of encapsulating the target operation function corresponding to the target hardware interface to obtain the operation function structure of the second device includes:
[0261] Classifying at least one target hardware interface to obtain at least one type of target hardware interface;
[0262] For each type of target hardware interface, determining a common target operation function for each type of target hardware interface;
[0263] Based on the target operation functions respectively corresponding to the at least one type of target hardware interface, an operation function structure of the second device is encapsulated.
[0264] In the disclosed embodiment, there is at least one target hardware interface. For example, the hardware interfaces corresponding to the A-type chip are the AI interface, the SPI interface, and the DO interface. The hardware interfaces corresponding to the B-type chip are the DO interface, the DI interface, and the AI interface. There are a total of 6 target hardware interfaces.
[0265] These target hardware interfaces are classified into, for example, AI interface type (quantity is 2), SPI interface type (quantity is 1), DO interface type (quantity is 2), and DI interface type (quantity is 1). For each type of target hardware interface, determine the target operation function common to each type of target hardware interface. Since the AI interface type (quantity is 2) and the two AI interfaces have the same target operation function, only the target operation function common to each type of target hardware interface can be determined, rather than determining two identical target operation functions, to reduce the number of target operation functions.
[0266] Similarly, for each type of target hardware interface, only the target operation function common to each type of target hardware interface is determined, and the number of target operation functions finally obtained is proportional to the number of types of target hardware interfaces. It is understandable that each type of target hardware interface may correspond to one or more target operation functions.
[0267] In implementing the embodiments of the present disclosure, at least one type of target hardware interface is obtained by classifying at least one target hardware interface; for each type of target hardware interface, a common target operation function of each type of target hardware interface is determined; based on the target operation functions corresponding to the at least one type of target hardware interface, an operation function structure of the second device is encapsulated, which can reduce the number of target operation functions corresponding to the second device, thereby improving the simplicity of the data.
[0268] Optionally, the step of determining a matching target operation function in the at least one operation function according to the channel indication information includes:
[0269] Matching the channel indication information with the hardware channel information of the at least one operation function respectively;
[0270] When the hardware channel information matches the channel indication information, a target operation function corresponding to the channel indication information is determined.
[0271] In the embodiments of the present disclosure, when determining a matching target operation function based on channel indication information, the channel indication information can be matched with the hardware channel information of each operation function respectively, and hardware channel information pointing to the same hardware channel can be searched based on the hardware channel pointed to by the channel indication information. When the hardware channel information exists, it can be determined that the hardware channel information corresponds to the target operation function.
[0272] For example, the channel indication information and the hardware channel information may both be the names of the hardware channels, and the channel indication information may be Figure 1 The hardware channel information of the three operation functions of SPISend_Channel in the embodiment code can be respectively Figure 1 SPISend_Channel, PWM_Channel, and ICU_Channel in the embodiment code can be matched to determine that the operation function having the hardware channel information "SPISend_Channel" is the target operation function.
[0273] Optionally, the second device includes at least one interactive chip; the step 301 of constructing an interface function corresponding to the hardware interface based on the input parameters and return values of the hardware interface in the first device includes:
[0274] Sub-step 3011, determining a subset of hardware interfaces to which the at least one interaction chip in the second device corresponds respectively; the subset of hardware interfaces includes at least one hardware interface;
[0275] Sub-step 3012, obtaining a hardware interface set corresponding to the second device according to the hardware interface subset;
[0276] Sub-step 3013, classifying the hardware interfaces in the hardware interface set, and generating an interface function corresponding to each type of hardware interface according to the input parameters and return values of each type of hardware interface.
[0277] In the embodiment of the present disclosure, the second device includes multiple interaction chips, and each interaction chip performs data interaction through a different hardware channel.
[0278] Determine the hardware interface subsets corresponding to the at least one interactive chip in the second device. For example, the hardware interfaces corresponding to the A-type chip are AI interface, SPI interface, and DO interface, and the hardware interface subset corresponding to the A-type chip is "AI interface, SPI interface, and DO interface"; the hardware interfaces corresponding to the B-type chip are DO interface, DI interface, and AI interface, and the hardware interface subset corresponding to the B-type chip is "DO interface, DI interface, and AI interface".
[0279] According to the hardware interface subsets corresponding to each interactive chip, the hardware interface set corresponding to the second device as a whole can be obtained. The hardware interfaces in the hardware interface set are classified, for example, the A and B model chips above correspond to: AI interface, SPI interface, DO interface, DI interface.
[0280] Since the AI interface category actually includes two AI interfaces, there are two identical interfaces. Therefore, based on the input parameters and return values of any AI interface, the interface function corresponding to the hardware interface of this type can be generated. There is no need to repeatedly construct interface functions based on the same type of interface. All types of corresponding interface functions can form an interface function library.
[0281] Figure 4 is a schematic diagram of a hardware interface and an interface function library provided by an embodiment of the present disclosure; Figure 4 It includes a first hardware interface subset 401 corresponding to type A chips, a second hardware interface subset 402 corresponding to type B chips, and a third hardware interface subset 403 corresponding to type C chips, and finally an interface function library 404 corresponding to each type of interface can be obtained.
[0282] In the implementation of the embodiment of the present disclosure, the hardware interface subsets corresponding to at least one interactive chip in the second device are determined; based on the hardware interface subsets, the hardware interface set corresponding to the second device is obtained; the hardware interfaces in the hardware interface set are classified, and the interface functions corresponding to each type of hardware interface are generated for the input parameters and return values of each type of hardware interface. The interface functions are generated according to the interface types, so that the repeated construction of the interface functions is avoided, and the construction efficiency of the interface configuration is improved.
[0283] Figure 5 Schematic diagram of an interface configuration construction system provided by an embodiment of the present invention, including:
[0284] Configuration construction device 501, first device 502 and second device 503;
[0285] The configuration construction device 501 is used to construct an interface function corresponding to the hardware interface based on the input parameters and return values of the hardware interface in the first device 502; the hardware interface has at least one hardware channel, and the hardware channel is used for data interaction; the interface function is used to implement the interface function of the hardware interface when executed;
[0286] The configuration construction device 501 is used to construct an operation function corresponding to the hardware interface based on the interface function, hardware channel information, and data operation information; the hardware channel information is used to determine a target hardware channel for data interaction; the operation function is used to perform the interaction operation indicated by the data operation information based on the interface function and the target hardware channel;
[0287] The configuration construction device 501 is used to determine, according to the hardware resource information of the second device 503, in at least one hardware interface, a target hardware interface corresponding to the second device and a target interface function and a target operation function of the target hardware interface;
[0288] The configuration building device 501 is used to build an interface configuration for the first device to interact with the second device based on the target interface function and the target operation function.
[0289] Figure 6 Schematic diagram of an interface configuration construction device provided by an embodiment of the present invention, including:
[0290] The interface function module 601 is used to construct an interface function corresponding to the hardware interface in the first device based on the input parameters and return values of the hardware interface; the hardware interface has at least one hardware channel, and the hardware channel is used for data interaction; the interface function is used to implement the interface function of the hardware interface when executed;
[0291] The operation function module 602 is used to construct the operation function corresponding to the hardware interface based on the interface function, the hardware channel information, and the data operation information; the hardware channel information is used to determine the target hardware channel for data interaction; the operation function is used to perform the interaction operation indicated by the data operation information based on the interface function and the target hardware channel;
[0292] A function determination module 603 is used to determine, according to the hardware resource information of the second device, in at least one hardware interface, a target hardware interface corresponding to the second device and a target interface function and a target operation function of the target hardware interface;
[0293] The configuration building module 604 is used to build an interface configuration for the first device to interact with the second device based on the target interface function and the target operation function.
[0294] Optionally, the hardware resource information includes interface indication information and channel indication information;
[0295] Function determination module, including:
[0296] An interface function determination submodule, used to determine a corresponding target hardware interface in at least one hardware interface according to the interface indication information;
[0297] A multi-operation function acquisition submodule, used to acquire a target interface function and at least one operation function corresponding to the target hardware interface; each operation function carries hardware channel information;
[0298] The operation function determination submodule is used to determine a matching target operation function in the at least one operation function according to the channel indication information; the target operation function has hardware channel information matching the channel indication information.
[0299] Optionally, the second device includes at least one interaction chip, and the second device performs data interaction with the first device through the interaction chip;
[0300] The interface function determines the submodule, including:
[0301] A chip interface unit, configured to determine a target hardware interface corresponding to each of the at least one interactive chip according to hardware resource information corresponding to each of the at least one interactive chip;
[0302] The device structure unit is used to encapsulate the target operation function corresponding to the target hardware interface to obtain the operation function structure of the second device.
[0303] Optionally, the operation function determines the submodule, including:
[0304] An information matching unit, used to match the channel indication information with the hardware channel information of the at least one operation function respectively;
[0305] The information consistency unit is used to determine the target operation function corresponding to the channel indication information when the hardware channel information matches the channel indication information.
[0306] Optionally, the second device includes at least one interactive chip; an interface function module, including:
[0307] A chip subset unit, used to determine a hardware interface subset corresponding to each of the at least one interactive chip in the second device; the hardware interface subset includes at least one hardware interface;
[0308] A device collection unit, configured to obtain a hardware interface collection corresponding to the second device according to the hardware interface subset;
[0309] The type function unit is used to classify the hardware interfaces in the hardware interface set, and generate an interface function corresponding to each type of hardware interface according to the input parameters and return values of each type of hardware interface.
[0310] Optionally, the target hardware interface has at least one type function unit, including:
[0311] An interface classification subunit, used to classify at least one target hardware interface to obtain at least one type of target hardware interface;
[0312] The type interface function subunit is used to determine the common target operation function of each type of target hardware interface for each type of target hardware interface;
[0313] The type function subunit is used to encapsulate the operation function structure of the second device based on the target operation functions corresponding to the at least one type of target hardware interface.
[0314] As for the above-mentioned device embodiment, since it is basically similar to the interface configuration construction method embodiment, the relevant parts can be referred to the partial description of the method embodiment.
[0315] The interface configuration construction device provided by the embodiment of the present invention constructs an interface function corresponding to the hardware interface based on the input parameters and return values of the hardware interface in the first device, and constructs an operation function corresponding to the hardware interface based on the interface function, hardware channel information, and data operation information; according to the hardware resource information of the second device, in at least one hardware interface, the target hardware interface corresponding to the second device and the operation function corresponding to the target hardware interface are determined, and based on the target interface function and the target operation function, an interface configuration for interacting with the second device is constructed. Based on the functionalization of the hardware interface and the functionalization of the interface operation, the decoupling of the hardware interface and the first device can be achieved. When using different first devices or second devices, the same interface function and operation function can be used for interaction, and the corresponding target interface function and target operation function can be flexibly selected based on the hardware resource information required by the second device, thereby avoiding the problem of redeveloping the interface configuration when switching the first device or the second device, thereby improving the applicability of the interface configuration.
[0316] The embodiment of the present invention further provides an electronic device, such as Figure 7 As shown, it includes a processor 701 , a communication interface 702 , a memory 703 and a communication bus 704 , wherein the processor 701 , the communication interface 702 , and the memory 703 communicate with each other via the communication bus 704 .
[0317] The memory 703 is used to store computer programs.
[0318] When the processor 701 is used to execute the program stored in the memory 703, the steps in the above-mentioned interface configuration construction method are implemented, which will not be repeated here.
[0319] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0320] The communication interface is used for communication between the above electronic device and other devices.
[0321] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0322] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0323] In another embodiment of the present invention, a computer-readable storage medium is provided. The computer-readable storage medium stores instructions. When the instructions are executed on a computer, the computer executes the interface configuration construction method described in the above embodiment.
[0324] In another embodiment of the present invention, a computer program product including instructions is provided. When the computer program product is run on a computer, the computer executes the interface configuration construction method described in the above embodiment.
[0325] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive Solid State Disk (SSD)), etc.
[0326] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0327] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. For the embodiments of the device, electronic device, computer-readable storage medium and computer program products containing instructions, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0328] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims
1. A method for constructing an interface configuration, characterized in that: include: Constructing an interface function corresponding to the hardware interface based on the input parameters and return values of the hardware interface in the first device; The hardware interface has at least one hardware channel, and the hardware channel is used for data interaction; the interface function is used to implement the interface function of the hardware interface when executed; Based on the interface function, hardware channel information, and data operation information, construct an operation function corresponding to the hardware interface; The hardware channel information is used to determine the target hardware channel for data interaction; the operation function is used to perform the interaction operation indicated by the data operation information based on the interface function and the target hardware channel; According to the hardware resource information of the second device, determining, among a plurality of hardware interfaces, a target hardware interface corresponding to the second device and a target interface function and a target operation function of the target hardware interface; Based on the target interface function and the target operation function, an interface configuration for the first device to interact with the second device is constructed.
2. The method according to claim 1, characterized in that The hardware resource information includes interface indication information and channel indication information; The step of determining, according to the hardware resource information of the second device, a target hardware interface corresponding to the second device and a target interface function and a target operation function of the target hardware interface from among a plurality of hardware interfaces comprises: Determining a corresponding target hardware interface among a plurality of hardware interfaces according to the interface indication information; Acquire a target interface function and at least one operation function corresponding to the target hardware interface; each operation function carries hardware channel information; According to the channel indication information, a matching target operation function is determined in the at least one operation function; the target operation function has hardware channel information matching the channel indication information.
3. The method according to claim 1, characterized in that: The second device includes at least one interaction chip, and the second device interacts with the first device through the interaction chip; The method further comprises: Determining the target hardware interface corresponding to each of the at least one interactive chip according to the hardware resource information corresponding to each of the at least one interactive chip; The target operation function corresponding to the target hardware interface is encapsulated to obtain an operation function structure of the second device.
4. The method according to claim 2, characterized in that: The step of determining a matching target operation function in the at least one operation function according to the channel indication information comprises: Matching the channel indication information with the hardware channel information of the at least one operation function respectively; When the hardware channel information matches the channel indication information, a target operation function corresponding to the channel indication information is determined.
5. The method according to claim 3, characterized in that: The target hardware interface has at least one; and the step of encapsulating the target operation function corresponding to the target hardware interface to obtain the operation function structure of the second device includes: Classifying at least one target hardware interface to obtain at least one type of target hardware interface; For each type of target hardware interface, determining a common target operation function for each type of target hardware interface; Based on the target operation functions respectively corresponding to the at least one type of target hardware interface, an operation function structure of the second device is encapsulated.
6. The method according to any one of claims 1 to 5, characterized in that: The second device includes at least one interactive chip; the step of constructing an interface function corresponding to the hardware interface based on the input parameters and return values of the hardware interface in the first device includes: Determine a hardware interface subset corresponding to each of the at least one interaction chip in the second device; the hardware interface subset includes a plurality of hardware interfaces; Obtaining a hardware interface set corresponding to the second device according to the hardware interface subset; The hardware interfaces in the hardware interface set are classified, and an interface function corresponding to each type of hardware interface is generated according to input parameters and return values of each type of hardware interface.
7. An interface configuration construction system, characterized in that: include: configuring a construction device, a first device, and a second device; The configuration construction device is used to construct an interface function corresponding to the hardware interface in the first device based on input parameters and return values of the hardware interface; the hardware interface has at least one hardware channel, and the hardware channel is used for data interaction; the interface function is used to implement the interface function of the hardware interface when executed; The configuration construction device is used to construct the operation function corresponding to the hardware interface based on the interface function, hardware channel information, and data operation information; The hardware channel information is used to determine the target hardware channel for data interaction; the operation function is used to perform the interaction operation indicated by the data operation information based on the interface function and the target hardware channel; The configuration construction device is used to determine, according to the hardware resource information of the second device, a target hardware interface corresponding to the second device and a target interface function and a target operation function of the target hardware interface from a plurality of hardware interfaces; The configuration building device is used to build an interface configuration for the first device to interact with the second device based on the target interface function and the target operation function.
8. An interface configuration construction device, characterized in that: include: An interface function module, used to construct an interface function corresponding to the hardware interface in the first device based on input parameters and return values of the hardware interface; The hardware interface has at least one hardware channel, and the hardware channel is used for data interaction; the interface function is used to implement the interface function of the hardware interface when executed; An operation function module, used to construct an operation function corresponding to the hardware interface based on the interface function, hardware channel information, and data operation information; The hardware channel information is used to determine the target hardware channel for data interaction; the operation function is used to perform the interaction operation indicated by the data operation information based on the interface function and the target hardware channel; a function determination module, configured to determine, according to the hardware resource information of the second device, a target hardware interface corresponding to the second device and a target interface function and a target operation function of the target hardware interface from among a plurality of hardware interfaces; A configuration building module is used to build an interface configuration for interaction between the first device and the second device based on the target interface function and the target operation function.
9. An electronic device, characterized in that: include: A processor, a communication interface, a memory and a communication bus; wherein the processor, the communication interface and the memory communicate with each other via the communication bus; Memory, used to store computer programs; A processor, for implementing the steps in the interface configuration construction method as described in any one of claims 1 to 6 when executing a program stored in a memory.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps in the interface configuration construction method according to any one of claims 1 to 6 are implemented.
