A method and apparatus for interface encapsulation of microcontroller peripheral modules
By functionally classifying microcontroller peripheral modules and encapsulating interfaces twice, a file is generated that separates user data from calling methods. This solves the interface integration problem caused by MCU replacement and enables convenient module matching and rapid development.
Patent Information
- Application Number
- CN202211724722.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-30
- Publication Date
- 2025-12-02
- Estimated Expiration
- 2042-12-30
AI Technical Summary
When replacing a microcontroller, existing technologies require significant modifications to the interface, increasing the difficulty for users in matching MCU peripheral modules. Furthermore, different MCU manufacturers have different development approaches and interface definitions, making interface integration difficult.
By classifying peripheral modules by function and encapsulating the interfaces twice, encapsulation files for user data and calling methods are generated separately, providing a universal template that allows different users to easily modify them when replacing the MCU.
It reduces the difficulty for users to match peripheral modules with microcontrollers and provides highly versatile interface encapsulation files, making it easy to quickly adapt to the interface adjustments of different MCUs.
Smart Images

Figure CN116107776B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of software product technology, and in particular to an interface encapsulation method and apparatus for microcontroller peripheral modules. Background Technology
[0002] With the increasing electrification of automobiles, the number of Electronic Control Units (ECUs) inside vehicles has greatly increased, and each ECU typically uses a Microcontroller Unit (MCU). As the market share of new energy vehicles gradually increases, the demand for MCUs has surged; however, the pandemic has led to a shortage of MCU chips, necessitating the selection of various MCU alternatives. The MCU chip industry itself is rapidly evolving, with frequent upgrades and replacements; replacing an MCU means developing corresponding MCU peripheral drivers.
[0003] To facilitate customer development, MCU manufacturers typically provide software development kits (SDKs) or driver libraries. However, since each MCU manufacturer has different development approaches and interface definitions, directly using the original SDK can lead to significant interface modifications when changing MCUs. In extreme cases, this can render some interfaces incompatible with existing projects, greatly increasing the difficulty for users in matching MCU peripheral modules. Summary of the Invention
[0004] Therefore, it is necessary to provide an interface encapsulation method, apparatus, computer device, computer-readable storage medium, and computer program product for microcontroller peripheral modules that can independently encapsulate the calling method and data of the driver interface, in order to address the above-mentioned technical problems.
[0005] In a first aspect, this application provides an interface encapsulation method for a microcontroller peripheral module, the interface encapsulation method comprising:
[0006] Select peripheral modules that have association requirements with the microcontroller, obtain the interface information of the peripheral modules, and classify the peripheral modules according to the interface information;
[0007] Perform initial interface encapsulation on the peripheral modules under each category to obtain initial encapsulation information;
[0008] The initial encapsulation information is then subjected to secondary interface encapsulation to obtain an interface encapsulation file that separates user data from the calling method.
[0009] In one embodiment, the step of selecting peripheral modules that have association requirements with the microcontroller, obtaining the interface information of the peripheral modules, and classifying the peripheral modules according to the interface information includes:
[0010] Determine the association requirements of the microcontroller and select peripheral modules that meet the association requirements;
[0011] Obtain the interface information of the peripheral module, and determine the classification result corresponding to the interface information in the preset peripheral module list.
[0012] In one embodiment, the interface encapsulation method further includes:
[0013] Construct a list of peripheral modules that characterizes the interface information and the functional classification of the peripheral modules.
[0014] In one embodiment, obtaining the interface information of the peripheral module and determining the classification result corresponding to the interface information in a preset list of peripheral modules includes:
[0015] Extract interface information from the general documentation of the peripheral module;
[0016] The classification result of the peripheral module corresponding to the interface information is determined in the peripheral module list.
[0017] In one embodiment, the initial interface encapsulation of the peripheral modules under each category to obtain initial encapsulation information includes:
[0018] Obtain common information for all peripheral modules under each category, and construct an interface encapsulation template corresponding to each category based on the common information;
[0019] The interface information of the peripheral modules under each category is filled into the interface encapsulation template to obtain the initial encapsulation information after filling.
[0020] In one embodiment, the secondary interface encapsulation of the initial encapsulation information to obtain an interface encapsulation file that separates user data from the calling method includes:
[0021] Extract interface information and interface call relationships from the initial encapsulation information;
[0022] The interface information and the interface call relationship are encapsulated independently, and the user data and the calling method are separated into interface encapsulation files.
[0023] Secondly, this application also provides an interface packaging device for a microcontroller peripheral module.
[0024] The device includes:
[0025] The peripheral classification module is used to select peripheral modules that have association requirements with the microcontroller, obtain the interface information of the peripheral modules, and classify the peripheral modules according to the interface information.
[0026] The initial interface encapsulation module is used to perform initial interface encapsulation on the peripheral modules under each category to obtain initial encapsulation information.
[0027] The secondary interface encapsulation module is used to perform secondary interface encapsulation on the initial encapsulation information to obtain an interface encapsulation file that separates user data from the calling method.
[0028] Thirdly, this application also provides a computer device. The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to perform the following steps:
[0029] Select peripheral modules that have association requirements with the microcontroller, obtain the interface information of the peripheral modules, and classify the peripheral modules according to the interface information;
[0030] Perform initial interface encapsulation on the peripheral modules under each category to obtain initial encapsulation information;
[0031] The initial encapsulation information is then subjected to secondary interface encapsulation to obtain an interface encapsulation file that separates user data from the calling method.
[0032] Fourthly, this application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program thereon, which, when executed by a processor, performs the following steps:
[0033] Select peripheral modules that have association requirements with the microcontroller, obtain the interface information of the peripheral modules, and classify the peripheral modules according to the interface information;
[0034] Perform initial interface encapsulation on the peripheral modules under each category to obtain initial encapsulation information;
[0035] The initial encapsulation information is then subjected to secondary interface encapsulation to obtain an interface encapsulation file that separates user data from the calling method.
[0036] Fifthly, this application also provides a computer program product. The computer program product includes a computer program that, when executed by a processor, performs the following steps:
[0037] Select peripheral modules that have association requirements with the microcontroller, obtain the interface information of the peripheral modules, and classify the peripheral modules according to the interface information;
[0038] Perform initial interface encapsulation on the peripheral modules under each category to obtain initial encapsulation information;
[0039] The initial encapsulation information is then subjected to secondary interface encapsulation to obtain an interface encapsulation file that separates user data from the calling method.
[0040] The aforementioned interface encapsulation method, apparatus, computer device, storage medium, and computer program product for microcontroller peripheral modules, through the functional classification of peripheral modules and subsequent two-stage encapsulation of these classified peripheral modules, ensures that the peripheral modules are functionally compatible with the microcontroller while providing a relatively universal user data template. This allows different users to easily and clearly modify the templates to match the peripheral modules with the microcontroller, thus reducing the difficulty for users in matching peripheral modules with microcontrollers. Attached Figure Description
[0041] Figure 1 This is an application environment diagram of an interface encapsulation method for a microcontroller peripheral module in one embodiment;
[0042] Figure 2 This is a flowchart illustrating an interface encapsulation method for a microcontroller peripheral module in one embodiment.
[0043] Figure 3 This is a schematic diagram illustrating the partitioning of the MCU peripheral module in one embodiment;
[0044] Figure 4 This is a schematic diagram illustrating the file organization and division in one embodiment;
[0045] Figure 5 This is a schematic diagram illustrating the source code reuse relationship in one embodiment;
[0046] Figure 6 This is a structural block diagram of an interface packaging device for a microcontroller peripheral module in one embodiment;
[0047] Figure 7 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0048] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0049] The interface encapsulation method for microcontroller peripheral modules provided in this application embodiment can be applied to, for example... Figure 1In the application environment shown, terminal 102 communicates with server 104 via a network. A data storage system can store the data that server 104 needs to process. The data storage system can be integrated onto server 104 or placed on a cloud or other network server. The interface encapsulation method for the peripheral module is completed by performing operations including initial interface encapsulation and secondary interface encapsulation on the peripheral module. Terminal 102 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, etc. Server 104 can be implemented using a standalone server or a server cluster consisting of multiple servers.
[0050] In one embodiment, such as Figure 2 As shown, an interface encapsulation method for microcontroller peripheral modules is provided, which is applied to... Figure 1 Taking the terminal in the example, the explanation includes the following steps:
[0051] Step S20: Select peripheral modules that have association requirements with the microcontroller, obtain the interface information of the peripheral modules, and classify the peripheral modules according to the interface information.
[0052] Since the functions implemented by current microcontrollers are basically the same, peripheral modules can be selected based on the common requirements of microcontrollers to determine the peripheral modules that implement the common requirements of microcontrollers. Then, the selected peripheral modules can be functionally classified to obtain peripheral modules belonging to several categories.
[0053] Step S40: Perform initial interface encapsulation on the peripheral modules under each category to obtain initial encapsulation information.
[0054] After obtaining the peripheral modules categorized into several types, the peripheral modules under each category undergo initial interface encapsulation to obtain the initial encapsulation information for each category. Since the peripheral modules under each category implement similar functions, a consistent interface description method can be used to uniformly describe the peripheral modules under this category during the initial encapsulation process.
[0055] Step S60: Perform secondary interface encapsulation on the initial encapsulation information to obtain an interface encapsulation file that separates user data from the calling method.
[0056] After obtaining the initial encapsulation information for each category, all the initial encapsulation information is encapsulated in a similar manner to obtain a complete interface encapsulation file for the corresponding microcontroller. Since this interface encapsulation file encapsulates the user data and interface calling methods for each interface in two separate files, different users can adapt their interfaces to different MCUs by using the universal user data template and interface calling methods provided in the interface encapsulation file.
[0057] By categorizing peripheral modules by function and then encapsulating them twice, we ensure that the peripheral modules are functionally compatible with the microcontroller while providing a relatively universal user data template. This allows different users to easily and clearly modify the templates to match the peripheral modules with the microcontroller, thus reducing the difficulty for users in matching peripheral modules with microcontrollers.
[0058] In one embodiment, peripheral modules that have association requirements with the microcontroller are selected, their interface information is obtained, and the peripheral modules are classified according to the interface information. Step S20 includes:
[0059] Step S22: Determine the association requirements of the microcontroller and select peripheral modules that meet the association requirements;
[0060] Step S24: Obtain the interface information of the peripheral module and determine the classification result corresponding to the interface information in the preset peripheral module list.
[0061] In implementation, to adapt peripheral modules to different microcontrollers, it is first necessary to confirm the microcontroller's association requirements. Based on the different functions of the current MCU peripheral modules, they are divided into three categories, such as... Figure 3 As shown.
[0062] The first category is "MCU driver," which does not involve external hardware signals and operates purely within the MCU. The second category is "I / O driver." The third category is "communication driver." For each submodule, there are three main types of interfaces: "initialization (establishment preparation)," "read status," and "write control." Some modules also have other "miscellaneous auxiliary" interfaces.
[0063] Specifically, the "MCU driver" sub-modules are divided into CORE (core), TIM (timer), FLASH memory, and EEPROM memory (supported by specific MCUs). Each type of sub-module has different functions. Therefore, the interfaces of these sub-modules are relatively fixed and basically do not require configuration. When using them, you can directly call the API to achieve the corresponding functions.
[0064] The "IO Driver" submodules are divided into IOIN (input, external level signal detection), IOOUT (output, external level signal control), DIO (input / output, internal GPIO input / output control, such as enabling the board-level RTC (real-time clock), ADC (input, analog signal sampling), DAC (output, digital-to-analog conversion control), PWMO (output, PWM signal control), and PWMI (input, PWM signal detection). In actual use, each type of submodule (such as IOIN) may be used by multiple channels simultaneously. Therefore, this type of signal supports multi-channel configuration. Specifically, the initialization interface receives a configuration array parameter and initializes multiple channel configurations simultaneously. Moreover, the module's "read status" and "write control" interfaces both have a channel parameter to indicate which instance is being read / written.
[0065] Like the "IO Driver" submodule, the "Communication Driver" class supports multiple configurations for each class, so the initialization interface is exactly the same. The communication class is more complex than the "IO Driver," therefore each configuration parameter structure has more members. In addition, the communication driver receives data via interrupts, so it will be adapted in conjunction with the interrupt.c source code.
[0066] Based on the microcontroller association requirements in different application scenarios, a number of peripheral modules are selected from the three categories mentioned above. After selecting the peripheral modules, the interface information of each peripheral module is extracted. Then, the classification result corresponding to the interface information is determined from the preset peripheral module list.
[0067] It should be noted that before performing step S24 above, step S23 also needs to be performed, specifically as follows:
[0068] Step S23: Construct a list of peripheral modules that represent interface information and peripheral module functional classification.
[0069] In implementation, this embodiment requires the peripheral modules to be categorized so that they can be initially encapsulated in subsequent operations. The categorization is achieved by constructing a peripheral module list, which provides a detailed description of the category to which each peripheral module belongs. Therefore, after obtaining a peripheral module, its category can be confirmed in the peripheral module list based on its interface information, including module name and relevant API names.
[0070] For example, the list of peripheral modules is shown in Table 1.
[0071] Table 1 List of commonly used peripheral modules
[0072]
[0073]
[0074]
[0075] Based on the content of Table 1, it can be seen that, given the known peripheral module name or typical API, the classification result of the current peripheral module can be quickly determined.
[0076] Specifically, step S24 involves determining the classification result corresponding to the interface information from the preset list of peripheral modules, i.e., the step includes:
[0077] Step S242: Extract interface information from the general documentation of the peripheral module;
[0078] Step S244: Determine the classification result of the peripheral module corresponding to the interface information in the peripheral module list.
[0079] In implementation, each peripheral module has a general documentation for developers' reference. This documentation comprehensively lists the name, typical APIs, and detailed comments for each peripheral module. The interface information for each peripheral module can be obtained from the general documentation. An example of peripheral module interface information is as follows:
[0080] MCU driver class:
[0081] CORE is mainly used to configure the global and necessary operations for MCU operation.
[0082] mcu_hal encapsulates 6 APIs:
[0083] void mcu_core_init(void); / / Used to configure the necessary initialization of the MCU, including clock, interrupt vectors, etc.
[0084] void mcu_disable_irq(void); / / Disable the MCU's global interrupt switch;
[0085] void mcu_enable_irq(void); / / Enable the MCU's global interrupt switch;
[0086] void mcu_kick_dog(void); / / Software-controlled dog feeding;
[0087] void mcu_soft_reset(void); / / Software reset;
[0088] void mcu_soft_delayus(uint32 us); / / Soft delay, in microseconds;
[0089] Configuration method: No configuration is required. Simply call the above interfaces as needed to achieve the corresponding functions.
[0090] TIM is mainly used to configure a hardware time base timer to provide a cycle-driven tick for upper-layer operation. In addition, it provides a hardware delay interface to drive some chips that require precise delays and need to use hardware delay.
[0091] mcu_hal encapsulates 5 APIs:
[0092] void mcu_tim_init(uint16 tickms); / / Initialize the runtime base timer, where intvTime represents the tick duration;
[0093] void mcu_tim_init_call(uint16 tickms,void(*pfun_callBack)(void)); / / Same as mcu_tim_init;
[0094] void mcu_tim_delayus(uint16 delayus); / / Hard delay, in microseconds;
[0095] void mcu_tim_isr(void); / / Place the corresponding interrupt ISR in interrupt.c;
[0096] void mcu_tim_deinit(void); / / Timer reverse initialization (restores default settings);
[0097] Configuration method: mcu_hal_user requires no configuration; simply call the above interfaces as needed to achieve the corresponding functions. The tim ISR in interrupt.c needs to handle periodic timer interrupts.
[0098] I / O driver class:
[0099] IOIN is mainly used for asynchronous level input sampling. The module has an internal filtering function and is mainly used to detect external level signals.
[0100] mcu_hal encapsulates 5 APIs:
[0101] void mcu_ioin_init(MCU_IOIN_TAB*p_table, uint8 tableNum); / / Initialization;
[0102] uint16 mcu_ioin_get_ready(uint8 channel); / / Read signal ready flag;
[0103] void mcu_ioin_clr_ready(uint8 channel); / / Clear the signal ready flag;
[0104] uint8 mcu_ioin_get_status(uint8 channel); / / Read signal status;
[0105] void mcu_ioin_main(void); / / Periodic function;
[0106] Configuration method: In mcu_hal_user.c, a variable a_mcuIoInTale of type MCU_IOIN_TAB is defined. The MCU_IOIN_TAB type is defined in mcu_hal.h, and the specific content of this type depends on the specific MCU implementation.
[0107] IOOUT is mainly used to configure asynchronous level output, such as controlling the high or low output of a relay drive.
[0108] mcu_hal encapsulates 4 APIs:
[0109] void mcu_ioout_init(MCU_IOOUT_TAB*p_table, uint8 tableNum); / / Initialization;
[0110] void mcu_ioout_set_status(uint8 channel, uint8 status); / / Controls the output status;
[0111] uint8 mcu_ioout_get_status(uint8 channel); / / Read output status;
[0112] void mcu_ioout_main(void); / / Periodic function;
[0113] Configuration method: The MCU_IOOUT_TAB structure is implemented according to the specific MCU and mainly configures each GPIO port, polarity (active high or low), port output mode (open drain or push-pull), default state, etc.
[0114] Communication driver class:
[0115] CAN is mainly used to configure the CAN controller, meet the CAN communication requirements, and is responsible for sending and receiving CAN communication data.
[0116] mcu_hal encapsulates 7 APIs:
[0117] void mcu_can_init(MCU_CAN_TAB*p_table, uint8 tableNum); / / Initialization;
[0118] void mcu_can_reinit(uint8 channel); / / Reinitialize;
[0119] uint8 mcu_can_send(uint8 channel, CAN_MSG*p_send); / / Sends a CAN data type.
[0120] void mcu_can_rx_isr(uint8 channel, CAN_MSG*p_recv); / / Used for driver callback;
[0121] void mcu_can_busoff_isr(uint8 channel); / / busoff isr;
[0122] void mcu_can_deinit(uint8 channel); / / Reverse initialization;
[0123] void mcu_can_deinit_all(void); / / Reverse initialization of all CAN buses;
[0124] Configuration method: The MCU_CAN_TAB structure is implemented according to the specific MCU and mainly configures the TX / RXGPIO ports, baud rate, mailbox, interrupts, etc. for each CAN communication.
[0125] In one embodiment, initial interface encapsulation is performed on the peripheral modules under each category to obtain initial encapsulation information, i.e., step 40 includes:
[0126] Step S42: Obtain the common information of all peripheral modules under each category, and construct the interface encapsulation template corresponding to each category based on the common information.
[0127] Step S44: Fill the interface information of the peripheral modules under each category into the interface encapsulation template to obtain the initial encapsulation information after filling.
[0128] In implementation, common information, including typical APIs and configuration methods, is extracted from the peripheral modules provided in the aforementioned examples. Based on this known common information, an interface encapsulation template can be constructed. The interface encapsulation template includes the peripheral module name, typical APIs, and corresponding categories, facilitating a unified initial interface encapsulation for peripheral modules within the same category.
[0129] The initial encapsulation information is obtained by filling the interface information of the peripheral modules under each known category into the constructed interface encapsulation template according to the category.
[0130] In one embodiment, the initial encapsulation information is subjected to secondary interface encapsulation to obtain an interface encapsulation file that separates user data from the calling method. Step 60 includes:
[0131] Step S62: Extract interface information and interface call relationships from the initial encapsulation information.
[0132] Step S64: Separately encapsulate the interface information and interface call relationship into an interface encapsulation file that separates user data from the call method.
[0133] In implementation, such as Figure 4 As shown, the file is organized into three parts:
[0134] The first part, the MCU peripheral driver source code (method), namely mcu_hal.c / mcu_hal.h, can be loaded into the project for compilation in source code form (.h / .c) or library form (.h / .a).
[0135] The second part is the configuration source code (data), namely mcu_hal_user.c / mcu_hal_user.h.
[0136] The third part is the interrupt service routine (ISR) configuration source code (data), namely interrupt.c. It configures the function of each peripheral according to the specific circuit diagram, specifically by modifying mcu_hal_user.c / mcu_hal_user.h and interrupt.c.
[0137] The MCU peripheral modules are categorized, such as GPIO modules (IOIN, IOOUT, DIO), Time modules (TIM, PWMO, PWMI), and SPI modules (MSPI and SSPI). This categorization satisfies the needs of upper-layer applications to call MCU peripherals and simplifies the complexity of each module. The configuration structure is defined according to the specific MCU, separating methods and data. When the hardware schematic changes (based on the same MCU), only the data (mcu_hal_user) configuration needs to be adjusted, without modifying the method (mcu_hal), achieving convenient configuration while meeting the requirements of the encapsulation library.
[0138] Based on the program's composition: program = method + data, this solution divides the source code files into two categories: methods correspond to the mcu_hal.c / mcu_hal.h source code files, and data corresponds to the mcu_hal_user.c / mcu_hal_user.h and interrupt.c source code files, i.e., configuration files.
[0139] Based on a certain MCU model, manufacturer A's MCU peripheral driver, mcu_hal.c / mcu_hal.h (the core content of the interface encapsulation), requires no modification when applied to multiple projects (each manufacturer's MCU requires developing a corresponding mcu_hal.c / mcu_hal.h, but manufacturer B's MCU peripheral driver's mcu_hal API (encapsulated function interface) remains consistent). While the internal implementations of the MCU drivers from different manufacturers differ, the encapsulated API interfaces are completely identical (name, parameters).
[0140] For modules that do not require configuration (see CORE, TIM, FLASH, EEPROM below), the corresponding API can be called directly when using them; for modules that require configuration, the corresponding configuration parameters need to be implemented in the source code files mcu_hal_user.c / mcu_hal_user.h according to the hardware schematic, and then the configuration parameters are used as function parameters to call the API of the corresponding module.
[0141] By configuring mcu_hal_user.c / mcu_hal_user.h and interrupt.c, the reuse of the same MCU model for different projects and the ability to change to MCUs from other manufacturers within a project without affecting the application layer interface, thus achieving the goal of rapid development, are realized. The source code reuse relationships are as follows: Figure 5 As shown, the solutions based on manufacturer A's MCU were applied to project A1, project A2, and project B1, respectively.
[0142] The interface encapsulation file obtained based on the above method encapsulates data and methods in two different files. When developers develop peripheral module interfaces for a new MCU, they only need to make targeted adjustments to the calling method content in the data file. There is no need to modify the interface parameters in the method file. Compared with the development method in the existing technology, it can save the workload of developers and facilitate rapid product development and iteration.
[0143] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0144] Based on the same inventive concept, this application also provides an interface packaging device for a microcontroller peripheral module for implementing the interface packaging method for a microcontroller peripheral module described above. The solution provided by this device is similar to the solution described in the above method. Therefore, the specific limitations of one or more embodiments of the interface packaging device for a microcontroller peripheral module provided below can be found in the limitations of the interface packaging method for a microcontroller peripheral module described above, and will not be repeated here.
[0145] In one embodiment, such as Figure 6 As shown, an interface packaging device 70 for a microcontroller peripheral module is provided, including: a peripheral classification module 72, a primary interface packaging module 74, and a secondary interface packaging module 76, wherein:
[0146] The peripheral classification module 72 is used to select peripheral modules that have association requirements with the microcontroller, obtain the interface information of the peripheral modules, and classify the peripheral modules according to the interface information.
[0147] Since the functions implemented by current microcontrollers are basically the same, peripheral modules can be selected based on the common requirements of microcontrollers to determine the peripheral modules that implement the common requirements of microcontrollers. Then, the selected peripheral modules can be functionally classified to obtain peripheral modules belonging to several categories.
[0148] The initial interface encapsulation module 74 is used to perform initial interface encapsulation on peripheral modules under each category to obtain initial encapsulation information.
[0149] After obtaining the peripheral modules categorized into several types, the peripheral modules under each category undergo initial interface encapsulation to obtain the initial encapsulation information for each category. Since the peripheral modules under each category implement similar functions, a consistent interface description method can be used to uniformly describe the peripheral modules under this category during the initial encapsulation process.
[0150] The secondary interface encapsulation module 76 is used to perform secondary interface encapsulation on the initial encapsulation information to obtain an interface encapsulation file that separates user data from the calling method.
[0151] After obtaining the initial encapsulation information for each category, all the initial encapsulation information is encapsulated in a similar manner to obtain a complete interface encapsulation file for the corresponding microcontroller. Since this interface encapsulation file encapsulates the user data and interface calling methods for each interface in two separate files, different users can adapt their interfaces to different MCUs by using the universal user data template and interface calling methods provided in the interface encapsulation file.
[0152] By categorizing peripheral modules by function and then encapsulating them twice, we ensure that the peripheral modules are functionally compatible with the microcontroller while providing a relatively universal user data template. This allows different users to easily and clearly modify the templates to match the peripheral modules with the microcontroller, thus reducing the difficulty for users in matching peripheral modules with microcontrollers.
[0153] Each module in the aforementioned interface packaging device for microcontroller peripheral modules can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in hardware or independently of the processor in a computer device, or stored in software in the memory of the computer device, so that the processor can call and execute the operations corresponding to each module.
[0154] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 7 As shown, the computer device includes a processor, memory, and a network interface connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores data listing peripheral modules. The network interface communicates with external terminals via a network connection. When executed by the processor, the computer program implements an interface encapsulation method for microcontroller peripheral modules.
[0155] Those skilled in the art will understand that Figure 7The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0156] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0157] Step S20: Select peripheral modules that have association requirements with the microcontroller, obtain the interface information of the peripheral modules, and classify the peripheral modules according to the interface information.
[0158] Step S40: Perform initial interface encapsulation on the peripheral modules under each category to obtain initial encapsulation information.
[0159] Step S60: Perform secondary interface encapsulation on the initial encapsulation information to obtain an interface encapsulation file that separates user data from the calling method.
[0160] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, the computer program performing the following steps when executed by a processor:
[0161] Step S20: Select peripheral modules that have association requirements with the microcontroller, obtain the interface information of the peripheral modules, and classify the peripheral modules according to the interface information.
[0162] Step S40: Perform initial interface encapsulation on the peripheral modules under each category to obtain initial encapsulation information.
[0163] Step S60: Perform secondary interface encapsulation on the initial encapsulation information to obtain an interface encapsulation file that separates user data from the calling method.
[0164] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, performs the following steps:
[0165] Step S20: Select peripheral modules that have association requirements with the microcontroller, obtain the interface information of the peripheral modules, and classify the peripheral modules according to the interface information.
[0166] Step S40: Perform initial interface encapsulation on the peripheral modules under each category to obtain initial encapsulation information.
[0167] Step S60: Perform secondary interface encapsulation on the initial encapsulation information to obtain an interface encapsulation file that separates user data from the calling method.
[0168] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0169] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0170] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. An interface encapsulation method for a microcontroller peripheral module, characterized in that, The interface encapsulation method includes: Select peripheral modules that have association requirements with the microcontroller, obtain the interface information of the peripheral modules, and classify the peripheral modules according to the interface information; The peripheral modules under each category are initially encapsulated to obtain initial encapsulation information. This initial encapsulation includes: obtaining common information for all peripheral modules under each category; constructing an interface encapsulation template corresponding to each category based on the common information; and filling the interface information of the peripheral modules under each category into the interface encapsulation template to obtain the filled initial encapsulation information. The initial encapsulation information is subjected to secondary interface encapsulation to obtain an interface encapsulation file that separates user data from the calling method. The secondary interface encapsulation of the initial encapsulation information to obtain an interface encapsulation file that separates user data from the calling method includes: extracting interface information and interface calling relationships from the initial encapsulation information; and encapsulating the interface information and the interface calling relationships independently to obtain an interface encapsulation file that separates user data from the calling method.
2. The interface encapsulation method for microcontroller peripheral modules according to claim 1, characterized in that, The process of selecting peripheral modules that have association requirements with the microcontroller, obtaining the interface information of the peripheral modules, and classifying the peripheral modules according to the interface information includes: Determine the association requirements of the microcontroller and select peripheral modules that meet the association requirements; Obtain the interface information of the peripheral module, and determine the classification result corresponding to the interface information in the preset peripheral module list.
3. The interface encapsulation method for microcontroller peripheral modules according to claim 2, characterized in that, The interface encapsulation method further includes: Construct a list of peripheral modules that characterizes the interface information and the functional classification of the peripheral modules.
4. The interface encapsulation method for a microcontroller peripheral module according to claim 3, characterized in that, The step of obtaining the interface information of the peripheral module and determining the classification result corresponding to the interface information in a preset list of peripheral modules includes: Extract interface information from the general documentation of the peripheral module; The classification result of the peripheral module corresponding to the interface information is determined in the peripheral module list.
5. An interface packaging device for a microcontroller peripheral module, characterized in that, The device includes: The peripheral classification module is used to select peripheral modules that have association requirements with the microcontroller, obtain the interface information of the peripheral modules, and classify the peripheral modules according to the interface information. The initial interface encapsulation module is used to perform initial interface encapsulation on the peripheral modules under each category to obtain initial encapsulation information. The initial interface encapsulation on the peripheral modules under each category to obtain initial encapsulation information includes: obtaining common information of all peripheral modules under each category; constructing an interface encapsulation template corresponding to each category based on the common information; and filling the interface information of the peripheral modules under each category into the interface encapsulation template to obtain the filled initial encapsulation information. A secondary interface encapsulation module is used to perform secondary interface encapsulation on the initial encapsulation information to obtain an interface encapsulation file that separates user data from the calling method. The process of performing secondary interface encapsulation on the initial encapsulation information to obtain an interface encapsulation file that separates user data from the calling method includes: extracting interface information and interface calling relationships from the initial encapsulation information; and independently encapsulating the interface information and the interface calling relationships to obtain an interface encapsulation file that separates user data from the calling method.
6. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the interface encapsulation method for microcontroller peripheral modules as described in any one of claims 1 to 4.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the interface encapsulation method for microcontroller peripheral modules as described in any one of claims 1 to 4.
8. A computer program product, comprising a computer program, characterized in that, When executed by a processor, the computer program implements the steps of the interface encapsulation method for a microcontroller peripheral module as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Multi-model door controller switching control method and device, electronic equipment and storage medium
CN110533062A
API interface packaging and calling method and system
CN112631694A