Embedded software processing method, firmware generation method, embedded device and medium
By using configuration tables and conditional compilation technology, the same firmware can be adapted to multiple projects, solving the compatibility problem of traditional embedded software firmware, reducing error rate and maintenance cost, and improving repair efficiency and adaptation speed.
Patent Information
- Application Number
- CN202611322270.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-28
- Publication Date
- 2026-11-24
AI Technical Summary
Traditional embedded software firmware cannot be compatible with multiple projects, resulting in problems such as high firmware burning error rate, high maintenance cost of multiple branches, low efficiency of general defect repair, and long adaptation cycle for new projects.
By using configuration tables and conditional compilation techniques, the parameter configurations of multiple projects are centrally defined as a structure array, and a single firmware is generated through conditional compilation. The embedded device automatically completes the adaptation of differentiated functions and parameter configuration according to the project number at runtime.
It enables the same firmware to be adapted to multiple projects, reduces the firmware flashing error rate, simplifies code maintenance, improves the efficiency of general defect repair, and shortens the adaptation cycle for new projects.
Smart Images

Figure CN123157256A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of embedded software and firmware management technology, and in particular to an embedded software processing method, a firmware generation method, an embedded device, and a medium. Background Technology
[0002] In traditional embedded software development and production line delivery models, a single embedded software firmware typically only matches a single project and cannot be compatible with multiple projects using the same firmware. When a company's product line involves multiple projects, each project must correspond to a separate firmware, which leads to three prominent problems.
[0003] First, there is a risk of "zero tolerance" in firmware burning: when different projects are produced on the production line, if the firmware of project A is burned to project B due to mixed materials or operational errors, the equipment will not work properly or may even become "bricked", resulting in production line stoppage or after-sales return to the factory, causing direct economic losses.
[0004] Secondly, the maintenance cost of multiple branches increases linearly with the number of projects: developers must maintain N independent code projects at the same time, version management is extremely chaotic, engineers are very likely to confuse firmware versions of different projects, and code reuse rate is extremely low.
[0005] Third, the efficiency of fixing common defects is extremely low: when common defects are found in the underlying driver or core algorithm, the fixers need to merge or patch the code on each project branch separately, which involves a lot of repetitive work and it is very easy to miss a branch, resulting in some projects having security risks.
[0006] To address this, the industry has proposed an improved approach of "one firmware compatible with different devices." For example, patent application CN103823703A discloses a method and apparatus for one firmware to be compatible with different devices. Its core lies in storing hardware identification identifiers through a hardware identification identifier recording module, and having a hardware identification execution module read the identifier and copy the differentiated data to the system area, thereby enabling a single firmware to adapt to multiple hardware devices. Another example is patent application CN121541839B, which discloses a flash partition identification method and system for automatic adaptation of multiple hardware devices. It pre-sets hardware type information identifiers on the device side and stores the device tree binary files of each hardware version in the resource image. After the bootloader mounts the predefined partition, it automatically matches and loads the corresponding device tree.
[0007] However, the aforementioned existing technologies still have limitations: First, their differentiated data mostly adopts a method of partitioned storage plus runtime data copying, resulting in additional storage overhead and copying latency; second, they all rely on the device to passively read preset identifiers, lacking proactive interaction capabilities in batch scenarios where production lines need to flexibly switch project models; third, none of the above solutions address the deep engineering management issue of "code branch management during multi-project parallel development," failing to achieve standardized maintenance of "one set of code, one firmware." Therefore, there is an urgent need for a technical solution that can further reduce code maintenance complexity, improve the efficiency of general defect repair, and simplify the adaptation process for new projects, while achieving one firmware adaptability to multiple objects. Summary of the Invention
[0008] The purpose of this invention is to provide an embedded software processing method, firmware generation method, embedded device and medium to solve the problems of low firmware burning fault tolerance, high multi-branch maintenance cost, low efficiency of general defect repair and long adaptation cycle of new projects in traditional solutions.
[0009] To achieve the above objectives, the present invention adopts the following technical solution: On one hand, the present invention provides a runtime matching method executed by an embedded device, comprising: Includes the following steps: Receive a matching instruction from the host computer carrying a project number, where the project number is a unique code for the corresponding project; Extract the field that matches the project from the unique code of the project number to obtain the target project index; The system queries the configuration table pre-installed in the firmware based on the target project index, and automatically completes project identification, differential function adaptation and parameter configuration loading based on the query results, so that the embedded device can run multiple projects corresponding to the same firmware. The configuration table is a structure array. During the firmware compilation stage, the complete parameter configurations of multiple projects have been fully compiled into the firmware. Each array element of the structure array corresponds to a parameter set of a project. The parameter set includes at least one of the following: AFE configuration, sampling resistor, battery capacity, number of battery cells, protection value, temperature definition, and communication module configuration.
[0010] On the other hand, the present invention provides a firmware generation method executed by a computer device, comprising: In the embedded software source code, the complete parameter configurations of multiple projects are defined centrally in the form of a configuration table. The configuration table is a structure array, and each array element of the structure array corresponds to a parameter set of a project. The parameter set includes at least one of the following: AFE configuration, sampling resistor, battery capacity, number of battery cells, protection value, temperature definition, and communication module configuration. Conditional compilation compiles the entire configuration table into the same firmware, so that the firmware contains the parameter configurations of all items in the compilation output, without tailoring any single item.
[0011] The present invention also provides an embedded device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the embedded software processing method described in any of the above claims; The present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the embedded software processing method described above, or implements the steps of the firmware generation method described above.
[0012] Compared with existing technologies, the beneficial effects of this invention are as follows: First, by centralizing all project parameters in the same compilation unit through a configuration table, and compiling them into a single firmware with conditional compilation, the same firmware can correspond to any project, fundamentally eliminating device malfunctions caused by firmware burning errors; Second, by separating differences from the code logic layer to the data configuration layer, the general algorithm only calls the configuration table values without being aware of specific projects, achieving complete decoupling of logic and configuration; Third, by actively issuing project labels from the host computer and having the device parse the unique encoded field to obtain an index for table lookup, it has stronger production line flexibility switching capabilities compared to passively reading the identifier; Fourth, the R&D side only needs to maintain one main branch and compile a single firmware, and general defects only need to be modified once on the main branch and compiled once to cover all projects; Fifth, adding a new project only requires adding one entry to the configuration table, without copying the project or modifying the core logic code, significantly shortening the adaptation cycle. Attached Figure Description
[0013] Figure 1 A flowchart illustrating an embodiment of an embedded software processing method of the invention; Figure 2 This is a schematic flowchart of a firmware generation method according to an embodiment of the invention.
[0014] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0015] 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.
[0016] Those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the term “comprising” as used in this specification means the presence of features, integers, steps, operations, elements, modules, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, modules, components, and / or groups thereof. It should be understood that when we say an element is “connected” or “coupled” to another element, it can be directly connected or coupled to the other element, or there may be intermediate elements. Furthermore, “connected” or “coupled” as used herein can include wireless connections or wireless coupling. The term “and / or” as used herein includes all or any modules and all combinations of one or more associated listed items.
[0017] It will be understood by those skilled in the art that, unless otherwise defined, all terms used herein (including technical and scientific terms) have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. It should also be understood that terms such as those defined in general dictionaries should be understood to have the same meaning as in the context of the prior art, and should not be interpreted in an idealized or overly formal sense unless specifically defined as herein.
[0018] Reference Figure 1 This embodiment provides an embedded software processing method executed by an embedded device. All steps of the method described in this embodiment are completed by the embedded device as a single execution entity; the action of the host computer issuing matching instructions to the slave computer serves only as a triggering condition for this method. The method includes: Step S1: Receive a matching instruction carrying an item label from the host computer, where the item label is the unique code of the corresponding item.
[0019] Embedded devices refer to controlled lower-level machines running firmware; upper-level machines refer to computers or debugging tools that communicate with embedded devices in the production line or debugging process; project numbers are numbers assigned to each product project by humans, and their unique codes are a string of numbers concatenated according to preset rules, such as type segment, hardware version segment, and parameter version segment; matching instructions are communication messages sent by the upper-level machine to the device, carrying the project number.
[0020] This step uses an embedded device as the sole executor, receiving project model instructions from the host computer during the runtime phase. Compared to the device passively reading hardware identifiers, this "host computer actively sends instructions, device passively receives" interaction allows the production line to flexibly switch between different project models at the same workstation without changing firmware or modifying hardware, greatly improving the flexibility and efficiency of mass production.
[0021] Step S2: Extract the field that matches the project from the unique code of the project number to obtain the target project index.
[0022] The unique code is a complete numeric string of the project number; the target project index is the array index of the corresponding project in the configuration table structure array, which is used for subsequent table lookup and location.
[0023] This step parses the encoding, extracts matching fields, and converts them into array indices on the device side. Human-readable item labels are mapped to machine-addressable indexes, enabling rapid and unambiguous table lookup and providing precise data for differentiated loading.
[0024] Step S3: Query the configuration table pre-installed in the firmware based on the target project index, and automatically complete project identification, differential function adaptation and parameter configuration loading based on the query results, so that the same firmware can run multiple projects.
[0025] Differentiated function adaptation refers to enabling or disabling corresponding function modules based on the loaded parameters; parameter configuration loading refers to writing the values of the corresponding entries in the configuration table into runtime variables or registers; the configuration table pre-loaded into the firmware refers to the structure array that has been fully compiled into the firmware image during the compilation stage.
[0026] Specifically, the device retrieves the corresponding parameter set from the configuration table based on the target project index, writes the parameters into runtime variables or registers, and enables or disables the corresponding functional modules according to the communication module configuration parameters, thereby achieving project identification, differentiated adaptation, and parameter loading. The same firmware can complete the adaptation to any project with a single table lookup, realizing "one set of code, one firmware" to support the operation of multiple projects; all actions in this step are completed by the embedded device as a single non-human entity, with a clear entity and well-defined responsibilities.
[0027] For ease of understanding, the following configuration examples are provided (using two projects as examples, with simplified fields): Project 1 (labeled 10) has the following parameter fields: {AFE=Model A, Sampling Resistor=1mΩ, Capacity=20Ah, Number of Sections=16, Overvoltage Protection=4.25V, Temperature Definition=NTC1, Communication Module Configuration=4G On}; Project 2 (labeled 23) has the following parameter fields: {AFE=Model B, Sampling Resistor=2mΩ, Capacity=30Ah, Number of Sections=24, Overvoltage Protection=4.20V, Temperature Definition=NTC2, Communication Module Configuration=4G Off}. It is evident that the differences between the two projects are entirely reflected in the data; the algorithm itself is completely identical.
[0028] In this embodiment, the differences between multiple projects are fully digitized and configured through "full pre-compiled firmware + device-side table lookup loading". Specifically, data configuration replaces code branches, and a single firmware replaces multiple firmwares. With a single execution subject (embedded device), multiple synergistic benefits can be achieved, such as virtually eliminating false burn-in rate, normalizing maintenance, one-time defect repair, and incremental expansion for new projects.
[0029] In one embodiment, each array element of the structure array in the configuration table above includes a unique identifier field and a parameter field; the unique identifier field records the item number according to a preset encoding rule, and the parameter field records the AFE configuration, sampling resistor, battery capacity, number of battery cells, protection value, temperature definition and communication module configuration parameters of the item; the general algorithm code only calls the value of the parameter field without being aware of the specific item.
[0030] The unique identifier field is the key used for retrieval and location in the configuration table element, storing an identifier that is consistent with or convertible to the project number; the parameter field is the set of members in the element that carry specific hardware parameters; the general algorithm code refers to common logic that does not depend on specific projects, such as voltage sampling, equalization control, and communication scheduling.
[0031] This implementation explicitly splits configuration table elements into two types of fields: "identifier" and "parameter". The identifier field provides a unique key for table lookups, while the parameter field decouples algorithm calls from projects—the general algorithm only reads the parameter values and is unaware of which specific project is currently running. This decouples logic from configuration at the code level, eliminating the need to modify the algorithm itself when adding or modifying projects, thus improving security and maintainability.
[0032] In one embodiment, the above-mentioned extraction of fields matching the project from the unique code of the project identifier to obtain the target project index includes: The unique code N of the project number is parsed into a decimal L-digit sequence, with each digit denoted as d. i where i = 0, 1, ..., L-1; Calculate the target item index according to preset weights: (1) Where, p i =g i mod m is the weight of the i-th digit (i.e., g raised to the power of (i mod m), m is the preset positive integer cycle length, g is a pre-selected fixed positive integer generator that is coprime to the capacity K of the configuration table, K is the preset maximum capacity of the configuration table structure array, is a fixed positive integer constant, mod is the modulo operation, and the resulting idx falls in the interval [0, K-1]. The verification value is then calculated using the following formula for validity verification: (2) The configuration table is queried based on the target item index idx only if the verification value chk matches the verification field carried by the matching instruction.
[0033] The generator g is a fixed positive integer coprime to the configuration table capacity K, used to construct the weights of each element to ensure a uniform index distribution; the loop length m is the weight sequence p. i =g i mod m The cycle period, a positive integer pre-set during the design phase, serves to make the weights change periodically with the digits, avoiding the monotonic dominance of higher digits on the index; weight p i It is the multiplier of the i-th decimal digit in index calculation; the modulo operation mod K maps large numbers to 0 to K. 1 is the table index; the check value chk is a one-bit check code obtained by weighted summation of the encoded bits and modulo 11, used to verify the legality of the instruction.
[0034] This implementation presents the invention's unique "encoding → index" mapping formula and corresponding verification formula. Specifically, each d of the unique encoding N (such as a decimal multi-bit string) i Multiplied by the weight p generated bitwise by the generator g. i The target index idx is obtained by summing the values and then taking the modulo of the configuration table capacity K, as shown in formula (1). This formula distributes the human-compiled labels non-linearly and evenly into the configuration table index space, avoiding local conflicts caused by mapping adjacent labels to adjacent indices, and improving the efficiency of table lookup. At the same time, the check value is calculated according to formula (2), and this value is compared with the check field carried by the matching instruction. If they match, the table lookup is performed, thereby identifying illegal or tampered labels on the device side.
[0035] Regarding the settings for m, g, and K: K is the preset maximum capacity of the configuration table structure array (i.e., the maximum number of projects supported by the firmware plan), which is a fixed constant determined during the design phase and will not change due to variations in the actual number of projects; m is the preset positive integer loop length, which makes the weight p i The cycle repeats with a period of m; the selection of g must satisfy coprime with K (i.e., the greatest common divisor is 1). This constraint ensures that g is invertible modulo K and that the weight sequence can uniformly cover [0, K]. [1] The interval is used to make the index distribution of different labels as uniform as possible and reduce the probability of collision. For example, if K=16 and g=7, gcd(7,16)=1 satisfies the coprime condition.
[0036] The following is a specific example illustrating the execution of the above formula. Assume the configuration table capacity K=16, generator g=7, loop length m=4, and the host computer issues a unique project label code N=1007 (four decimal digits, i.e., d0=7, d1=0, d2=0, d3=1). Each weight p... i=7 i mod 4 The values are p0=1, p1=7, p2=49, and p3=343, respectively. Substituting these values into the formula: idx=(7×1+0×7+0×49+1×343) mod 16=350 mod 16=14, meaning the target item index is 14. Substituting these values into the verification formula: chk=(7×1+0×2+0×3+1×4)mod11=11 mod 11=0. After the device comparison shows chk=0 matches the command verification field, the 14th element of the configuration table is retrieved to complete the loading. Those skilled in the art can directly implement this through programming.
[0037] In one embodiment, the configuration table in the firmware is fully compiled into the firmware through conditional compilation. The conditional compilation uses compile-time macro switches or compile-time configuration items to retain all the parameter definitions and difference logic of each project in the same compilation unit. The single firmware image generated after compilation contains the configuration table entries of all projects.
[0038] Compile-time macro switches refer to the mechanism of controlling whether code participates in compilation through macro definitions; a compilation unit refers to the set of source files processed in a single compilation; a firmware image is a binary file generated after compilation and linking.
[0039] This embodiment explicitly replaces runtime or file system-level difference management with compile-time macros / configuration items. All project parameters are incorporated into the same firmware during compilation, eliminating the need for independent partition storage and runtime data copying. This avoids the additional overhead and latency of existing technologies that require "partition storage + data copying." Furthermore, adding or removing projects only changes the configuration and not the branch, thus abolishing the multi-branch model from an engineering organization perspective.
[0040] In one embodiment, the above-mentioned embedded software processing method further includes a processing step for matching failure, specifically including: when the verification value chk is inconsistent with the instruction verification field, or the target index idx exceeds the configuration table capacity K, refusing to perform table lookup, and loading the default configuration entry pre-placed at the beginning of the configuration table or the default parameter set stored independently in the firmware, or reporting the matching failure information to the host computer.
[0041] The default configuration entry is a set of fallback parameters that are pre-fixed at the beginning of the configuration table. It corresponds to a standard general item and is compiled and fixed along with the firmware. The firmware can allocate an independent area to store this set of default parameters, which is independent of the main configuration table. It can be read even if the configuration table is empty due to an abnormality. The matching failure information is an alarm message sent by the device back to the host computer.
[0042] This implementation adds a validity gate to the table lookup process and specifies two default storage methods: the first entry in the configuration table or a separate parameter area in the firmware. When a label is tampered with, a transmission error occurs, or the index goes out of bounds, the system will not blindly load erroneous parameters but will safely revert to the default configuration or issue a timely alarm. This ensures equipment operational safety and facilitates rapid location of abnormal workpieces on the production line, improving yield and traceability.
[0043] In one embodiment, the configuration table is a fixed-length array of slots with a capacity of K. When a new item is added, its parameter set is written into the array element corresponding to the hash index of the new item, without modifying any general algorithm code. The recompiled firmware is still the same. The "hash index" is determined by the formula... The calculated target item index idx, and the label N of the newly added item, are used to calculate a specific idx value using the above formula. This value is the storage location of the newly added item in the fixed-length array of the configuration table. The storage location corresponding to each label is definite and unique. Subsequent devices can reproducibly locate the same array element based on the same label using the above formula, ensuring the correctness and consistency of table lookup matching.
[0044] This implementation minimizes the cost of integrating new projects—developers only need to add one line of parameters to the configuration table, without requiring any changes to the core algorithms and compilation process. The adaptation cycle for new projects is significantly shortened, the reusability of core business logic code is significantly improved, and because no new branches are introduced, security risks caused by missed branch merging are avoided.
[0045] In one embodiment, the aforementioned differentiated function adaptation specifically includes: Based on the communication module configuration parameters in the loaded parameter set, enable or disable the corresponding functional modules; When the communication module configuration parameters indicate that the 4G function is enabled, load the 4G communication protocol stack and enable the corresponding interface; otherwise, put the function module into a dormant or disabled state.
[0046] Functional modules refer to software components such as 4G communication, CAN communication, and Bluetooth that can be started and stopped independently; the protocol stack is the software layer that implements a specific communication protocol; enable refers to enabling module power supply and task scheduling; communication module configuration parameters are the communication module configuration items in the above parameter set, used to declare the communication capabilities that the project needs to enable.
[0047] This implementation uses a communication module as an example to illustrate the differentiated adaptation approach: the device dynamically loads or unloads functional components based on configuration table parameters. Only the necessary modules are enabled on different projects using the same firmware, saving RAM / Flash resources and avoiding errors caused by irrelevant functions. This achieves on-demand customization without splitting the firmware for customization purposes.
[0048] Reference Figure 2This embodiment provides a method for generating embedded software firmware executed by a computer device, including the following steps: Step T1: In the embedded software source code, the complete parameter configurations of multiple projects are defined in a centralized manner in the form of a configuration table. The configuration table is a structure array, and each array element of the structure array corresponds to a parameter set of a project. The parameter set includes at least one of the following: AFE configuration, sampling resistor, battery capacity, number of battery cells, protection value, temperature definition, and communication module configuration.
[0049] The computer device refers to the development host used by the R&D side to compile firmware; the configuration table has the same meaning as in the above embodiment, and is defined here by the computer device in the form of a structure array at the source code level.
[0050] This step unifies all project hardware parameters into a configuration table before compilation, laying the data foundation for subsequent "full compilation, single firmware" and thoroughly digitizing the differences.
[0051] T2: The configuration table is fully compiled into the same firmware through conditional compilation, so that the firmware contains the parameter configuration of all items in the compilation output, without tailoring any single item.
[0052] This step uses conditional compilation to compile all entries in the configuration table into a single firmware image. The firmware released to the production line is "universally applicable," meaning the same firmware is used regardless of which project the device ultimately belongs to, eliminating anomalies caused by incorrect firmware flashing.
[0053] The firmware generation method in this embodiment and the embedded software processing method described above belong to different stages of the product development chain, each with a single non-human entity. The computer device completes "full pre-compilation" through steps T1 and T2 to generate a single general-purpose firmware. This firmware is then delivered to the production line and burned into the embedded device, which automatically matches it during runtime using the embedded software processing method. The two work together to achieve the engineering implementation of "one set of code, one firmware," significantly reducing maintenance costs and improving R&D efficiency.
[0054] This invention also provides an embedded device, including a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the steps of any of the above-described embedded software processing methods.
[0055] The memory can be Flash, EEPROM, or SDRAM, used to store firmware and configuration tables; the processor can be an MCU, MPU, or SoC, used to execute the steps of the above runtime method.
[0056] The embedded device in this implementation is the lower-level machine in the aforementioned runtime phase. By productizing the above runtime method on a hardware platform, the "one set of code, one firmware, and automatic matching of multiple projects" can be implemented and run in a real embedded system.
[0057] This invention also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the embedded software processing method described in any of the preceding embodiments.
[0058] Computer-readable storage media refers to physical media capable of storing computer programs, such as ROM, Flash, SD cards, and optical discs, and is distinct from signals themselves. In this embodiment, the medium corresponds to non-volatile memory in an embedded device, used to store computer programs that implement runtime methods.
[0059] This implementation embeds the aforementioned runtime methods into the medium as program instructions, facilitating firmware burning, distribution, and version management. The storage medium is deployed with the device at the factory or through remote upgrades, allowing the same medium content to power multiple project devices.
[0060] Embodiments of the present invention also provide another computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the firmware generation method described above.
[0061] The medium in this embodiment corresponds to the storage medium in a computer device (development host) and is used to store a computer program that implements the firmware generation method.
[0062] This implementation embeds the aforementioned firmware generation method into a medium as program instructions, facilitating the deployment of a compilation and build environment on the development side. Developers or continuous integration systems can automatically complete the full compilation of "one set of code, one firmware" by executing the program on this medium. This medium, along with the aforementioned embedded software processing method, corresponds to the development side and the device side, respectively, together forming a complete implementation system.
[0063] 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. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in this application and in the embodiments can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual-speed SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0064] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, apparatus, article, or method that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, apparatus, article, or method. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, apparatus, article, or method that includes that element.
[0065] The above description is merely a preferred embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent structural or procedural transformations made based on the content of the present invention's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. An embedded software processing method, executed by an embedded device, characterized in that, Includes the following steps: Receive a matching instruction from the host computer carrying a project number, where the project number is a unique code for the corresponding project; Extract the field that matches the project from the unique code of the project number to obtain the target project index; The system queries the configuration table pre-installed in the firmware based on the target project index, and automatically completes project identification, differential function adaptation and parameter configuration loading based on the query results, so that the embedded device can run multiple projects corresponding to the same firmware. The configuration table is a structure array. During the firmware compilation stage, the complete parameter configurations of multiple projects have been fully compiled into the firmware. Each array element of the structure array corresponds to a parameter set of a project. The parameter set includes at least one of the following: AFE configuration, sampling resistor, battery capacity, number of battery cells, protection value, temperature definition, and communication module configuration.
2. The method according to claim 1, characterized in that, Each array element of the structure array includes a unique identifier field and a parameter field; the unique identifier field records the project number of the corresponding project according to a preset encoding rule, and the parameter field records the AFE configuration, sampling resistor, battery capacity, number of battery cells, protection value, temperature definition and communication module configuration parameters of the project; the general algorithm code only calls the value of the parameter field and is not aware of the specific project.
3. The method according to claim 1 or 2, characterized in that, The step of extracting the field matching the project from the unique code of the project number to obtain the target project index includes: The unique code N of the project number is parsed into a decimal L-digit sequence, with each digit denoted as d. i where i = 0, 1, ..., L-1; Calculate the target item index according to preset weights: (1) Where, p i =g i mod m is the weight of the i-th digit, m is the preset positive integer loop length, g is a pre-selected fixed positive integer generator that is coprime to the configuration table capacity K, K is the preset maximum capacity of the configuration table structure array, is a fixed positive integer constant, mod is the modulo operation, and the resulting idx falls in the interval [0, K-1]. The verification value is then calculated using the following formula for validity verification: (2) The configuration table is queried based on the target item index idx only if the verification value chk matches the verification field carried by the matching instruction.
4. The method according to claim 1, characterized in that, The configuration tables in the firmware are fully compiled into the firmware through conditional compilation. The conditional compilation uses compile-time macro switches or compile-time configuration items to retain all the parameter definitions and difference logic of each project in the same compilation unit. The single firmware image generated after compilation contains the configuration table entries of all projects.
5. The method according to claim 3, characterized in that, Also includes: When the verification value chk is inconsistent with the verification field carried by the matching instruction, or when the target item index idx exceeds the capacity K of the configuration table, the table lookup is refused, and the default configuration entry pre-placed at the beginning of the configuration table or the default parameter set stored independently in the firmware is loaded, or the matching failure information is reported to the host computer.
6. The method according to claim 1, characterized in that, The configuration table is a fixed-length slot array with a capacity of K. When a new item is added, its parameter set is written into the array element corresponding to the hash index of the new item, without modifying any general algorithm code. After recompiling, the same firmware is still generated.
7. The method according to claim 1, characterized in that, The differentiated function adaptation includes: Based on the communication module configuration parameters in the loaded parameter set, enable or disable the corresponding functional modules; When the communication module configuration parameters indicate that the 4G function is enabled, the 4G communication protocol stack is loaded and the corresponding interface is enabled; otherwise, the function module is put into a dormant or disabled state.
8. A firmware generation method, executed by a computer device, characterized in that, Includes the following steps: In the embedded software source code, the complete parameter configurations of multiple projects are defined centrally in the form of a configuration table. The configuration table is a structure array, and each array element of the structure array corresponds to a parameter set of a project. The parameter set includes at least one of the following: AFE configuration, sampling resistor, battery capacity, number of battery cells, protection value, temperature definition, and communication module configuration. Conditional compilation compiles the entire configuration table into the same firmware, so that the firmware contains the parameter configurations of all items in the compilation output, without tailoring any single item.
9. An embedded device, characterized in that, It includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the steps of the embedded software processing method as described in any one of claims 1 to 7.
10. 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 embedded software processing method as described in any one of claims 1 to 7, or the steps of the firmware generation method as described in claim 8.
Citation Information
Patent Citations
Method and device in compatibility with different equipment with same firmware
CN103823703A
A flash partition identification multi-hardware automatic adaptation method and system
CN121541839B
