Memory negotiation method and negotiation system of embedded code module
By configuring the memory negotiation callback function and the module manager transfer parameters, the problem of inconsistent initialization parameters of code modules in the embedded software architecture is solved, reducing the difficulty of user configuration and development costs, and ensuring successful initialization.
Patent Information
- Application Number
- CN202510199589.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-21
- Publication Date
- 2025-08-15
AI Technical Summary
In the embedded software architecture, there are many code modules and inconsistent initialization parameters, which makes it difficult to configure user, lead to high development and maintenance costs, and prone to initialization failure problems.
Provides a memory negotiation method for embedded code modules. By configuring the memory negotiation callback function, the module manager transmits the memory pool initialization parameters, and negotiates the most appropriate parameters with the code module through the memory negotiation callback function. If the negotiation fails, the negotiation will be repeated until successful.
It lowers the threshold for user development and use, reduces the cost of users to understand each parameter, and ensures successful initialization of the code module.
Smart Images

Figure CN120491932A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of embedded system software, and in particular relates to a memory negotiation method and a negotiation system for an embedded code module. Background Art
[0002] Currently, code modules in embedded software architectures support memory management. However, these modules are numerous and require different initialization parameters and memory managers. Because the memory manager is shared by multiple code modules, improper configuration can lead to code package initialization failures and unexpected performance. Enabling users to gain a deeper understanding of the relevant code modules and the impact of various parameters can help prevent initialization failures and unexpected performance, significantly raising the bar for code package users.
[0003] Therefore, the current embedded software architecture has technical problems such as high user threshold, difficult user configuration, and high development and maintenance costs.
[0004] It should be noted that the above information disclosed in this background technology section is only used to understand the background technology of the present application concept, and therefore, the above description is not considered to constitute information of the prior art. Summary of the Invention
[0005] The purpose of the present invention is to provide a memory negotiation method and negotiation system for an embedded code module.
[0006] In order to solve the above technical problems, the present invention provides a memory negotiation method for an embedded code module, comprising:
[0007] Step S01, setting a code package; the code package includes: a memory pool management module, a module manager and at least one code module; wherein the method of setting the code module includes configuring a memory negotiation callback function for the code module;
[0008] Step S02: the memory pool management module transmits the memory pool initialization parameters to each of the code modules through the module manager; and
[0009] In step S03, the code module negotiates the memory pool initialization parameters and the memory pool parameters required by itself through the memory negotiation callback function. If the negotiation is successful, the negotiated memory pool parameters are fed back to the module manager. If the negotiation fails, steps S02 and S03 are repeated to perform the next round of negotiation.
[0010] In another aspect, the present invention further provides a memory negotiation system for an embedded code module, comprising:
[0011] A setting module is configured to set a code package and configure a memory negotiation callback function for the code module, wherein the code package includes: a memory pool management module, a module manager and at least one of the code modules;
[0012] a transmission module configured to transmit the memory pool initialization parameters of the memory pool management module to each of the code modules through the module manager; and
[0013] The negotiation module is configured to negotiate the memory pool initialization parameters and the memory pool parameters required by itself through the memory negotiation callback function, and feed back the negotiation results to the module manager.
[0014] In a third aspect, the present invention further provides a readable storage medium storing embedded system readable instructions, which, when executed by at least one embedded processor, enables the memory negotiation method as described above to be executed.
[0015] In a fourth aspect, the present invention further provides an electronic device comprising: at least one memory and at least one embedded processor, wherein the memory stores executable instructions, and when the executable instructions are executed by the embedded processor, the embedded processor executes the memory negotiation method as described above.
[0016] In a fifth aspect, the present invention further provides an embedded program product, comprising a program or instructions, wherein when the program or instructions are executed on an embedded system, the memory negotiation method as described above is executed.
[0017] The beneficial effect of the present invention is that the memory negotiation method of the embedded code module of the present invention includes configuring a memory negotiation callback function for the code module, transmitting the memory pool initialization parameters to each code module through the module manager, and then negotiating the memory pool initialization parameters and the memory pool parameters required by each code module itself through the memory negotiation callback function, and negotiating the parameter data required by the most suitable code module, that is, the code module only needs to care about the memory pool initialization parameters and write the corresponding memory negotiation callback function according to the code module initialization structure for subsequent processing, which reduces the cost that users need to understand during development and lowers the user usage threshold.
[0018] Other features and advantages of the present invention will be described in the following description, and in part will become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention are realized and obtained by the structures particularly pointed out in the description and the drawings.
[0019] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the specific embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0021] Figure 1 A diagram showing the steps of a memory negotiation method for an embedded code module according to some embodiments is shown;
[0022] Figure 2 A flowchart of a method in which the code module of some embodiments negotiates memory pool initialization parameters and memory pool parameters required by the code module itself through the memory negotiation callback function is shown;
[0023] Figure 3 Shows some embodiments involved Figure 2 Flowchart of the method for calling the memory negotiation callback function in step S34;
[0024] Figure 4 Shows some embodiments involved Figure 3 Flowchart of the method for performing negotiation processing by the memory negotiation callback function in step S342;
[0025] Figure 5 A schematic structural diagram of a memory negotiation system for embedded code modules according to some embodiments is shown;
[0026] Figure 6 A schematic structural diagram of an electronic device involved in some embodiments is shown. DETAILED DESCRIPTION
[0027] The present invention will now be described in further detail with reference to the accompanying drawings, which are simplified schematic diagrams that illustrate the basic structure of the present invention in a schematic manner.
[0028] Current embedded software architectures support memory management for code modules, but these modules are numerous and each requires different initialization parameters and different memory manager requirements. Because the memory manager is shared by multiple code modules, improper configuration can lead to code package initialization failures and unexpected performance. This significantly increases the barrier to entry for code package users by requiring them to thoroughly understand the relevant code modules and the impact of various parameters to avoid initialization failures and unexpected performance.
[0029] In order to solve the above technical problems, Figure 1As shown, at least one embodiment provides a memory negotiation method for an embedded code module, comprising:
[0030] Step S01, setting a code package; the code package includes: a memory pool management module, a module manager and at least one code module; wherein the method of setting the code module includes configuring a memory negotiation callback function for the code module;
[0031] Step S02: the memory pool management module transmits the memory pool initialization parameters to each of the code modules through the module manager; and
[0032] In step S03, the code module negotiates the memory pool initialization parameters and the memory pool parameters required by itself through the memory negotiation callback function. If the negotiation is successful, the negotiated memory pool parameters are fed back to the module manager. If the negotiation fails, steps S02 and S03 are repeated to perform the next round of negotiation.
[0033] In some embodiments, the method by which the code module negotiates the memory pool initialization parameters and the memory pool parameters required by itself through the memory negotiation callback function includes:
[0034] The memory pool initialization parameters are compared one by one with the memory pool parameters required by each code module. If the memory pool initialization parameters do not meet the memory pool parameter requirements of any code module, the negotiation fails. That is, the memory negotiation callback function returns an error value or the memory pool parameters required by the code module to the module manager. The module manager then reports an error or modifies the memory pool parameters to the memory pool parameters required by the code module. Steps S02 and S03 are then repeated to proceed to the next round of negotiation until the memory pool parameters meet the memory pool parameter requirements of all code modules.
[0035] Specifically, situations where the memory pool initialization parameters do not meet the memory pool parameter requirements of the code module itself include, but are not limited to, the following:
[0036] 1) If the data length stored in the memory pool is shorter than the data length required by the corresponding code module, it is considered unsatisfactory. In this case, the memory negotiation callback function returns the memory pool parameters required by the code module to the module manager, and the module manager modifies the memory pool parameters to the memory pool parameters required by the code module.
[0037] 2) If the allocation method of the memory pool or the data format of the memory pool is different from that required by the corresponding code module itself, it is considered unsatisfactory. At this time, the memory negotiation callback function will return an error value to the module manager, and the module manager will report an error.
[0038] It should be noted that during the negotiation process, as long as any modification or error reporting is performed, the negotiation is considered unsuccessful and the next round of negotiation is required.
[0039] The memory negotiation method of the embedded code module includes configuring a memory negotiation callback function for the code module, transmitting the memory pool initialization parameters to each code module through the module manager, and then negotiating the memory pool initialization parameters and the memory pool parameters required by each code module itself through the memory negotiation callback function, and negotiating the parameter data required by the most suitable code module. That is, the code module only needs to care about the memory pool initialization parameters and write the corresponding memory negotiation callback function according to the code module initialization structure for subsequent processing, which reduces the cost that users need to understand during development and lowers the user usage threshold.
[0040] In some embodiments, the input parameters of the memory negotiation callback function include: a memory pool index value to be verified, an initialization structure pointer of a corresponding code module, a memory pool initialization structure pointer to be verified, and a flag bit indicating whether there is inheritance; obtaining memory pool parameters required by the code module itself through the initialization structure pointer of the code module; and obtaining memory pool initialization parameters through the memory pool initialization structure pointer.
[0041] Specifically, the inherited flag is used to determine whether the code module has a parent class node.
[0042] In some embodiments, the memory pool initialization parameters include: memory pool management type, memory block length, and memory allocation address alignment requirements.
[0043] It should be noted that the memory pool initialization parameters are not limited to the memory pool management type, memory block length, and memory allocation address alignment requirements, but may also include other parameters that the user considers necessary to negotiate, which are defined by the user in specific applications.
[0044] Specifically, the initialization structure of the code module in the input parameter of the memory negotiation callback function can be customized by the user. Taking the code module for checking whether the memory pool satisfies the user-defined structure as an example, the sample code is given as follows:
[0045] The custom initialization structure of the sample code module is as follows:
[0046]
[0047]
[0048] Based on the code module of the above user-defined structure, the code for negotiating and comparing the required memory pool parameters with the memory pool initialization parameters found according to the memory pool index value is as follows:
[0049]
[0050]
[0051] In some embodiments, there may be multiple memory pool objects and multiple code module objects, so it is necessary to call the memory negotiation callback function cyclically. Figure 2 As shown, the method in which the code module negotiates the memory pool initialization parameters and the memory pool parameters required by itself through the memory negotiation callback function includes:
[0052] Step S31, determine whether all memory pool index values have been traversed, if so, return success; otherwise, execute step S32;
[0053] Step S32, finding the corresponding memory pool initialization structure according to the memory pool index value;
[0054] Step S33, determining whether the code module initialization structure has been traversed, if so, returning to step S31, otherwise, executing step S34;
[0055] Step S34, calling the memory negotiation callback function to negotiate the memory pool initialization parameters and the memory pool parameters required by itself;
[0056] Step S35, determine whether failure is returned, if so, return failure; otherwise, repeat step S33.
[0057] Specifically, determining whether the traversal of the code module initialization structure is completed in step S33 refers to whether each code module initialization structure corresponding to the memory pool initialization structure in step S32 has negotiated with the memory pool initialization structure one by one in sequence.
[0058] In some embodiments, as Figure 3 As shown, the method of calling the memory negotiation callback function in the aforementioned step S34 includes:
[0059] Step S341, determine whether the code module has a parent class node, if so, execute step S342, otherwise execute step S343;
[0060] Step S342: determine whether the memory negotiation callback function is saved. If so, call the memory negotiation callback function to perform negotiation processing. Otherwise, return success.
[0061] Step S343: using the initialized structure pointer of the parent class of the code module as an input parameter of the memory negotiation callback function;
[0062] Step S344, determining whether the parent class negotiation of the code module is successful, if successful, executing step S342, otherwise returning failure;
[0063] Step S345: determine whether the negotiation is successful. If successful, return success; otherwise, return failure.
[0064] In some embodiments, as Figure 4 As shown, the method for performing negotiation processing by the memory negotiation callback function in the aforementioned step S342 includes:
[0065] Step S3421, determine whether the memory pool index value is correct, if it is correct, execute step S3422, otherwise return success;
[0066] Step S3422, determine whether the message format of the memory pool is correct, if it is correct, execute step S3423, otherwise return failure;
[0067] Step S3423, determine whether the length of a single message is greater than or equal to the requirement, if so, return success, otherwise return failure.
[0068] Specifically, the sample code for calling the memory negotiation callback function is as follows, where the input parameters of the memory negotiation callback function include: the initialization structure of the code module, the function structure pointer of the code module, the index value of the memory pool, the initialization structure pointer of the memory pool, and whether the code module has a parent class node as an example:
[0069]
[0070]
[0071] Specifically, the sample code for processing the return value of the memory negotiation callback function is as follows. The parameters are the pointer to the memory pool initialization structure, the memory pool index value, and whether to change the flag bit:
[0072]
[0073]
[0074]
[0075]
[0076] like Figure 5As shown, some embodiments also provide a memory negotiation system for an embedded code module, comprising: a setting module, configured to set a code package and configure a memory negotiation callback function for the code module, wherein the code package comprises: a memory pool management module, a module manager and at least one of the code modules; a transmission module, configured to transmit the memory pool initialization parameters of the memory pool management module to each of the code modules through the module manager; and a negotiation module, configured to negotiate the memory pool initialization parameters and the memory pool parameters required by itself through the memory negotiation callback function, and feed back the negotiated memory pool parameters to the module manager.
[0077] Among them, the specific implementation functions of the setting module, the transmission module and the negotiation module are realized in the embedded system. For details, please refer to the content of the memory negotiation method of the aforementioned embedded code module, which will not be repeated here.
[0078] Some embodiments also provide a readable storage medium storing embedded system readable instructions, which, when executed by at least one embedded processor, enables the memory negotiation method of the embedded code module to be executed; the memory negotiation method of the embedded code module includes: step S01, setting a code package; the code package includes: a memory pool management module, a module manager and at least one code module; wherein the method of setting the code module includes configuring a memory negotiation callback function for the code module; step S02, the memory pool management module transmits the memory pool initialization parameters to each of the code modules through the module manager; and step S03, the code module negotiates the memory pool initialization parameters with the memory pool parameters required by itself through the memory negotiation callback function; if the negotiation is successful, the negotiated memory pool parameters are fed back to the module manager; if the negotiation fails, steps S02 and S03 are repeated to perform the next round of negotiation.
[0079] Some embodiments also provide an embedded program product, including a program or instruction, wherein when the program or instruction is executed on an embedded system, a memory negotiation method of an embedded code module is executed; the memory negotiation method of the embedded code module includes: step S01, setting a code package; the code package includes: a memory pool management module, a module manager and at least one code module; wherein the method of setting the code module includes configuring a memory negotiation callback function for the code module; step S02, the memory pool management module transmits the memory pool initialization parameters to each of the code modules through the module manager; and step S03, the code module negotiates the memory pool initialization parameters and the memory pool parameters required by itself through the memory negotiation callback function; if the negotiation is successful, the negotiated memory pool parameters are fed back to the module manager; if the negotiation fails, steps S02 and S03 are repeated to perform the next round of negotiation.
[0080] Some embodiments also provide an embedded program product, including a readable storage medium on which a readable program code is stored, the embedded readable program code including instructions that cause at least one processor (one or more embedded devices) to perform the following operations: Step S01, setting a code package; the code package includes: a memory pool management module, a module manager and at least one code module; wherein the method of setting the code module includes configuring a memory negotiation callback function for the code module; Step S02, the memory pool management module transmits the memory pool initialization parameters to each of the code modules through the module manager; and Step S03, the code module negotiates the memory pool initialization parameters with the memory pool parameters required by itself through the memory negotiation callback function; if the negotiation is successful, the negotiated memory pool parameters are fed back to the module manager; if the negotiation fails, Steps S02 and S03 are repeated to perform the next round of negotiation.
[0081] like Figure 6 As shown, some embodiments further provide an electronic device, such as an embedded device, comprising: at least one memory and at least one embedded processor, wherein the memory stores executable instructions, and when the executable instructions are executed by the embedded processor, the embedded processor executes a memory negotiation method of an embedded code module; the memory negotiation method of the embedded code module comprises: step S01, setting a code package; the code package comprises: a memory pool management module, a module manager and at least one code module; wherein the method of setting the code module comprises configuring a memory negotiation callback function for the code module; step S02, the memory pool management module transmits memory pool initialization parameters to each of the code modules through the module manager; and step S03, the code module negotiates the memory pool initialization parameters and the memory pool parameters required by itself through the memory negotiation callback function, and if the negotiation is successful, the negotiated memory pool parameters are fed back to the module manager, and if the negotiation fails, steps S02 and S03 are repeated to perform the next round of negotiation.
[0082] In some embodiments, the device may be an embedded control device or a single-chip control device, including at least one memory and at least one embedded processor.
[0083] In some embodiments, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architectures, functions, and operations of the devices, methods, and embedded program products according to multiple embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or part of a code, and the module, program segment, or part of the code contains one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or action.
[0084] In addition, the functional modules in the various embodiments of the present invention may be integrated together to form an independent part, or each module may exist independently, or two or more modules may be integrated to form an independent part.
[0085] If the functions are implemented as software modules and sold or used as independent products, they can be stored in a readable storage medium. Based on this understanding, the technical solution of the present invention, or the portion that contributes to the prior art, or part of the technical solution, can be embodied in the form of a software product. This embedded software product, stored in a storage medium, executes all or part of the steps of the methods described in various embodiments of the present invention.
[0086] With the above-described preferred embodiments of the present invention as a guide, and with reference to the above description, relevant personnel are fully capable of making various changes and modifications without departing from the technical scope of this invention. The technical scope of this invention is not limited to the contents of the specification and must be determined according to the scope of the claims.
Claims
1. A memory negotiation method for an embedded code module, characterized in that: include: Step S01, setting a code package; The code package includes: a memory pool management module, a module manager and at least one code module; wherein the method for setting the code module includes configuring a memory negotiation callback function for the code module; Step S02: the memory pool management module transmits the memory pool initialization parameters to each of the code modules through the module manager; and In step S03, the code module negotiates the memory pool initialization parameters and the memory pool parameters required by itself through the memory negotiation callback function. If the negotiation is successful, the negotiated memory pool parameters are fed back to the module manager. If the negotiation fails, steps S02 and S03 are repeated to perform the next round of negotiation.
2. The memory negotiation method of the embedded code module according to claim 1, characterized in that: The input parameters of the memory negotiation callback function include: The memory pool index value that needs to be verified, the initialization structure pointer of the corresponding code module, the memory pool initialization structure pointer that needs to be verified, and the flag bit of whether there is inheritance; Obtain the memory pool parameters required by the code module itself through the code module's initialization structure pointer; and Get the memory pool initialization parameters through the memory pool initialization structure pointer.
3. The memory negotiation method of the embedded code module according to claim 2, characterized in that: The memory pool initialization parameters include: memory pool management type, memory block length, and memory allocation address alignment requirements.
4. The memory negotiation method of the embedded code module according to claim 3, characterized in that: The method in which the code module negotiates the memory pool initialization parameters and the memory pool parameters required by the code module itself through the memory negotiation callback function includes: Step S31, determine whether all memory pool index values have been traversed, if so, return success; otherwise, execute step S32; Step S32, finding the corresponding memory pool initialization structure according to the memory pool index value; Step S33, determining whether the code module initialization structure has been traversed, if so, returning to step S31, otherwise, executing step S34; Step S34, calling the memory negotiation callback function to negotiate the memory pool initialization parameters and the memory pool parameters required by itself; Step S35, determine whether failure is returned, if so, return failure; otherwise, repeat step S33.
5. The memory negotiation method of the embedded code module according to claim 4, characterized in that: The method of calling the memory negotiation callback function includes: Step S341, determine whether the code module has a parent class node, if so, execute step S342, otherwise execute step S343; Step S342: determine whether the memory negotiation callback function is saved. If so, call the memory negotiation callback function to perform negotiation processing. Otherwise, return success. Step S343: using the initialized structure pointer of the parent class of the code module as an input parameter of the memory negotiation callback function; Step S344, determining whether the parent class negotiation of the code module is successful, if successful, executing step S342, otherwise returning failure; Step S345: determine whether the negotiation is successful. If successful, return success; otherwise, return failure.
6. The memory negotiation method of the embedded code module according to claim 5, characterized in that: The method for performing negotiation processing by the memory negotiation callback function includes: Step S3421, determine whether the memory pool index value is correct, if it is correct, execute step S3422, otherwise return success; Step S3422, determine whether the message format of the memory pool is correct, if it is correct, execute step S3423, otherwise return failure; Step S3423, determine whether the length of a single message is greater than or equal to the requirement, if so, return success, otherwise return failure.
7. A memory negotiation system for an embedded code module, characterized in that: Including embedded devices, The embedded device is configured to include: A setting module is configured to set a code package and configure a memory negotiation callback function for the code module, wherein the code package includes: a memory pool management module, a module manager and at least one of the code modules; a transmission module configured to transmit the memory pool initialization parameters of the memory pool management module to each of the code modules through the module manager; and The negotiation module is configured to negotiate the memory pool initialization parameters and the memory pool parameters required by itself through the memory negotiation callback function, and feed back the negotiation results to the module manager.
8. A readable storage medium storing embedded system readable instructions, which, when executed by at least one embedded processor, enables the memory negotiation method according to any one of claims 1 to 6 to be executed.
9. An electronic device, characterized in that: include: At least one memory and at least one embedded processor, wherein the memory stores executable instructions, and when the executable instructions are executed by the embedded processor, the embedded processor executes the memory negotiation method according to any one of claims 1 to 6.
10. An embedded program product, comprising a program or an instruction, wherein when the program or the instruction is executed on an embedded system, the memory negotiation method according to any one of claims 1 to 6 is executed.