Embedded software code synthesis method based on model driving method

Through the embedded software code synthesis method based on the model-driven method, the operating system characteristic information is extracted and the packaging template is constructed, which solves the problems of high operating system understanding and frequent code replacement in the traditional development method, and realizes the automatic generation of operating system packaging. code, improving development efficiency and code quality.

CN118733019APending Publication Date: 2024-10-01BEIHANG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410846892.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2024-05-15
Filing Date
2024-06-27
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

In the development process of embedded software, traditional methods require developers to have an in-depth understanding of the target operating system and manually write operating system-related packaging codes, resulting in complex and error-prone development, especially when facing different operating systems. Frequent replacement and rewriting of code increases the workload and learning burden of developers.

Method used

An embedded software code synthesis method based on a model-driven approach is adopted to extract operating system feature information and build an operating system packaging template, separate platform-independent information and target operating system-related information, use code synthesis tools to generate operating system-related packaging code, and Combined with business code into a complete application, reducing the amount of manual writing and lowering the requirements for operating system knowledge.

Benefits of technology

It realizes the automatic generation of operating system-related packaging code, reduces developers' dependence on the operating system, improves development efficiency and code readability and maintainability, and reduces development complexity and error rates.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118733019A_ABST
    Figure CN118733019A_ABST
Patent Text Reader

Abstract

The invention provides an embedded software code synthesis method based on a model driving method. The method comprises the following steps: firstly, establishing an extraction process for executing operating system feature information on a software design document; furthermore, operating system packaging templates generated by codes are constructed for different target operating systems, and process codes are formed; constructing an operating system packaging code synthesis tool on the basis of the operating system packaging template; generating a packaging code related to the operating system by a code synthesis tool; and finally, the code synthesis tool synthesizes the packaging code and the service code into a complete flight control software application program. According to the scheme, feature information related to an operating system is extracted and separated from core logic of code generation to serve as a set of independent operating system packaging template classes, and the embedded software code synthesis method based on the model driving method is achieved on the basis of the operating system packaging template classes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computers, and more specifically, to an embedded software code synthesis method based on a model-driven approach. Background Art

[0002] The development of embedded software is inseparable from the integration with embedded operating systems. Since embedded operating systems are mostly customized for specific application requirements, they are highly platform-dependent. In actual embedded software development, it is often necessary to face frequently changing operating systems and hardware environments. The most affected by this situation is the encapsulation code related to the operating system in the embedded software, which mainly includes process management code (process creation, process scheduling, etc.) and inter-process communication code, and operating system initialization code. The business code that completes the calculation or actual function part in the corresponding flight control software is not affected by the operating system and hardware environment.

[0003] At present, the development of embedded software often still follows the traditional software development process. The application of models in development is quite limited and is often only used for feasibility analysis, pre-verification or to make requirements easier to understand. This traditional software development process is generally as follows: First, developers or modelers use modeling simulation tools (Simulink, SCADE, etc.) or other modeling tools to establish a formal model based on software requirements and a series of constraints and reliability guarantees. Developers implement the business code of the application based on the model and requirement documents, and write packaging code based on the software configuration information in the model or development documents (such as process configuration, inter-process communication information, etc.). Finally, developers organize the business code and packaging code and synthesize them into complete flight control software. This development process is like Figure 1 .

[0004] There are some obvious problems with this development process:

[0005] First, the traditional development method has high requirements for software developers. Developers need to have a certain understanding of the target operating system and understand the target operating system's system calls, process management methods, inter-process communication methods and other mechanisms. If the developer lacks understanding of the target operating system or experience in embedded development, errors are likely to occur during the development process.

[0006] Secondly, there are a lot of automatically generated and reusable patterns in the operating system-related codes in embedded software, but the traditional development method does not make full use of this feature: for example, the codes for process creation, process scheduling, and inter-process communication all follow a relatively unified format and are repeated in large quantities in the software (this part of the code generally accounts for 15% to 50%). As long as the key information required for this part of the code is provided, these codes can be generated according to the pattern.

[0007] Model driven software development (MDSD) can be used to solve these problems: the models in MDSD are not only used to describe system requirements and architecture, but also to automatically generate code. The code generators in model-based simulation software such as Simulink and SCADE provide code generation functions, which can generate business codes based on the mathematical models of the software. These codes have good readability and maintainability, and can ensure that the logic is consistent with the original model. If the original model has been strictly designed, analyzed and verified, then the generated code theoretically retains these verified properties.

[0008] There are already many mature modeling languages ​​and model-based simulation tools:

[0009] POK is an ARINC 653 operating system proposed by Julien Delange et al. of the European Space Agency. Its architecture is shown in the figure below. Figure 3 As shown. Based on the support of ARINC 653 partitioning mechanism and core services, POK partially adopts the MDSD method. The kernel initialization configuration is defined through AADL (ArchitectureAnalysis and Design Language), which can generate partial (initialization) code and graph the configuration. POK relies on a complete tool chain to automate its configuration and deployment and simplify the development of partitioned systems. It is designed to specify system architecture and properties using the modeling language AADL and verify its requirements using specialized analysis tools. Then, from these verified specifications, the tool chain automatically generates configuration / deployment kernels / partitions. This ensures the execution of the specification requirements and avoids all errors in the usual development process.

[0010] JHipster, at its core, is a Yeoman generator. Yeoman is a popular open source tool for automating the creation of a project's skeleton structure. JHipster uses the API provided by Yeoman to allow developers to select the required technology stack, features, and services through a series of question-and-answer interactions, and then dynamically generate project structures and basic code based on these selections. This includes but is not limited to database models, REST APIs, front-end pages, security configurations, test cases, and more. JHipster uses Handlebars, a flexible and powerful text template language that can dynamically generate code files based on input data.

[0011] However, the above-mentioned modeling simulation tools can only generate business codes containing calculation and business logic. These codes are far from the software system running on the actual operating system. Developers still need to supplement these task codes with encapsulation codes related to the target operating system. If encapsulation code is to be generated, it is necessary to obtain some characteristic information related to the operating system, such as interface information, scheduling method, etc. However, platform migration is very frequent in embedded development scenarios, and it is often necessary to develop for many different target operating systems. It is impossible to rewrite a set of encapsulation code generation tools every time the target operating system is switched. Therefore, when implementing code synthesis tools, it is necessary to consider the differences between different target operating systems. These differences are mainly reflected in the interfaces (system calls, core services, etc.) provided by different operating systems, as well as process management methods and inter-process communication methods. Summary of the invention

[0012] The present disclosure is based on the Beijing University of Aeronautics and Astronautics project: 2022YFB4501901, and aims to provide an embedded software code synthesis method based on a model-driven method, aiming to solve the following technical problems: In the MDSD process of embedded software, the task code generated by mathematical model conversion needs to be supplemented with a large amount of encapsulation code related to the target operating system, most of which are related to the interface provided by the target operating system and the characteristics of the target operating system (such as scheduling mode, initialization mode, etc.). If these encapsulation codes are developed in accordance with the traditional development method, the requirements for software developers are high. Developers need to have a certain understanding of the target operating system, and understand the mechanisms such as the system call, process management mode, and inter-process communication mode of the target operating system. In the development process, errors are often generated due to insufficient knowledge or experience of developers. At the same time, in the development process of embedded embedded software, it is inevitable to consider the differences between different target operating systems. The replacement of the target operating system will bring a lot of additional workload and overhead. Developers need to re-learn the knowledge related to the operating system, and the code structure may also change.

[0013] In a general aspect, a method for synthesizing embedded software code based on a model-driven approach is provided, firstly establishing a process for extracting operating system feature information from a software design document;

[0014] Then, the operating system encapsulation templates for code generation are constructed for different target operating systems and process codes are formed. The information required in the embedded software operating system encapsulation code generation process is separated into two parts: platform-independent information, which is provided manually or through software process modeling tools; and information related to the target operating system, which is saved in the code synthesis tool in the form of encapsulation template classes;

[0015] An operating system encapsulation code synthesis tool is constructed based on the operating system encapsulation template, and the specific process is as follows: after obtaining the input of the storage file of the platform-independent information and the task code file, the code synthesis tool first parses the storage file of the platform-independent information and saves the parsed information in the corresponding object; then, architecture code is generated according to the configured target operating system and the information saved in these objects, and after these architecture codes are generated, functions are first synthesized, and then code files are synthesized together with the task code; finally, the code synthesis tool outputs the finally generated software code to the original directory where the task code file is located;

[0016] Then, the code synthesis tool generates the encapsulation code related to the operating system. The specific process is as follows: the encapsulation code generation process is divided into the generation of process initialization code, the generation of process startup code, the generation of process scheduling code, the generation of process communication mechanism initialization code and the generation of process communication code;

[0017] Finally, the code synthesis tool synthesizes the encapsulation code and the business code into a complete flight control software application;

[0018] The code synthesis tool.

[0019] The information extracted in the extraction process of the operating system feature information is mainly divided into two categories: the first category is the interface information provided by the operating system to the user, and the second category is the information required by the entire software system.

[0020] The operating system encapsulation template includes a C language template class and a code factory class. The C language template class includes: a function template class, an input / output interface initialization template class, a variable initialization template class, a process loop body template class, and an operating system interface template class. Each template class includes a toC function, which generates a code fragment defined by the template class according to a series of parameters passed in and returns it. There is a nested calling relationship between the template classes, wherein the function template class may call the toC functions of all other template classes, and the process loop body template class and the input / output interface initialization template class may call the toC function of the system call template class;

[0021] The code factory class provides an abstract interface for generating code, and these interfaces correspond to the initialization function of each template class. Whenever a new operating system needs to be adapted, a set of specific template classes and specific code factories need to be implemented based on the operating system's system call interface, data type, process creation method, and inter-process communication method.

[0022] The platform-independent information is saved in the format of an XML configuration file. The information contained in the structure of the XML configuration file includes two parts. One part is information related to the process encapsulation of the model-generated task code, including process cycle, priority, process-related variables, and task code information contained in the process; the other part is information related to the inter-process communication relationship, including the initialization parameters of the inter-process communication relationship and the process's reference to the inter-process communication relationship.

[0023] The process code includes port initialization, variable initialization, model initialization, and model loop execution parts;

[0024] The port initialization process is as follows: each port corresponds to an inter-process communication data structure declared in the partition. In the port initialization part, the code synthesizer obtains the ID of the data structure or other variables used to indicate the data structure according to the XML configuration and OS type, and prepares for obtaining data from the data structure next;

[0025] The variable initialization process is as follows: declare a series of local variables required by the model modules and initialize them, assign values ​​to variables that do not participate in inter-process communication but only participate in calculation, and send variables that participate in inter-process communication to other processes after initialization;

[0026] The model initialization process is: calling a model initialization function to initialize the local model, the model initialization function is provided by the modeling tool when generating the model code;

[0027] The model loop execution part process is: according to the XML configuration, the function of the model module is executed in sequence and the variables therein are updated;

[0028] The inter-process communication code is automatically generated by the code synthesis tool according to the mapping relationship between variables and ports in XML and the model loop execution code process; in XML, if a variable needs to participate in inter-process communication, it corresponds to a port. If this port is an In type port, it means that the variable will receive data from the port. If it is an Out type port, it means that the variable will output data from the port; in the code of the model initialization part, when a variable is initialized, the code synthesizer will check whether it has a mapping with the Out type port. If so, it will generate a write code to write the initialization value of the variable to the corresponding port so that other processes can receive the initialization value; in the code of the model loop execution part, whenever a function function uses the variable or its pointer as a parameter, or uses the variable to save the return value, the code synthesizer will check the mapping relationship between the variable and the port. If it is mapped to an In type port, the code synthesizer will insert the receiving code before the function is called. If it is mapped to an Out type port, the code synthesizer will insert the sending code after the function is called.

[0029] The innovation of the embodiment of the present invention lies in:

[0030] The present invention extracts some characteristic information related to the operating system, separates it from the core logic of code generation, and uses it as a set of independent operating system encapsulation template classes. Based on these operating system encapsulation template classes, a model-driven method-based embedded software code synthesis tool is implemented to generate encapsulation code in embedded software and synthesize the encapsulation code and task code into a complete embedded software.

[0031] The method of the present invention constructs code generation templates for different target operating systems by abstracting information related to the target operating system, and constructs a generation and synthesis tool for operating system encapsulation code (code synthesis tool based on domain model, referred to as code synthesis tool) based on these templates, and the code synthesis tool generates encapsulation code related to the operating system, and synthesizes it with the business code into a complete application. In this way, the encapsulation code of the application is automatically generated by the operating system, which reduces a large amount of manual work while also making it unnecessary for developers to understand knowledge related to the target operating system, so that developers can focus on business-related details. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] The above and other objects and features of the present disclosure will become more apparent from the following description in conjunction with the accompanying drawings.

[0033] Figure 1 It is a schematic diagram showing an architecture diagram of an embedded software code synthesis method based on a model-driven method in the prior art;

[0034] Figure 2 is a schematic diagram showing an architecture diagram of an embedded software code synthesis method based on a model-driven approach according to an embodiment of the present disclosure;

[0035] Figure 3 is a diagram showing an example of a template class for message queue sending according to an embodiment of the present disclosure;

[0036] Figure 4 is a nested call relationship diagram showing a software partition master file template class according to an embodiment of the present disclosure;

[0037] Figure 5 is a nested call relationship diagram showing a process code file class according to an embodiment of the present disclosure;

[0038] Figure 6 is a diagram showing the structure of an XML configuration file according to an embodiment of the present disclosure;

[0039] Figure 7 is a diagram showing a code generation and synthesis process according to an embodiment of the present disclosure;

[0040] Figure 8 is a diagram showing a C syntax tree structure according to an embodiment of the present disclosure;

[0041] Fig. 9 is a process diagram showing a process code generation algorithm according to an embodiment of the present disclosure;

[0042] Fig.10 FIG. 4 is a flow chart showing an inter-process communication code generation algorithm according to an embodiment of the present disclosure. DETAILED DESCRIPTION

[0043] The following specific embodiments are provided to help the reader obtain a comprehensive understanding of the methods, devices and / or systems described herein. However, after understanding the disclosure of the present application, various changes, modifications and equivalents of the methods, devices and / or systems described herein will be clear. For example, the order of operations described herein is only an example and is not limited to those orders set forth herein, but can be changed as will be clear after understanding the disclosure of the present application, except for operations that must occur in a specific order. In addition, for greater clarity and simplicity, the description of features known in the art may be omitted.

[0044] The features described herein can be implemented in different forms and should not be construed as being limited to the examples described herein. Rather, the examples described herein have been provided to illustrate only some of the many possible ways to implement the methods, devices, and / or systems described herein, which will be clear after understanding the disclosure of the present application.

[0045] As used herein, the term "and / or" includes any one of the associated listed items and any combination of any two or more.

[0046] Although terms such as "first", "second", and "third" may be used herein to describe various members, components, regions, layers, or portions, these members, components, regions, layers, or portions should not be limited by these terms. Instead, these terms are only used to distinguish one member, component, region, layer, or portion from another member, component, region, layer, or portion. Therefore, without departing from the teachings of the examples described herein, the first member, first component, first region, first layer, or first portion referred to in the examples may also be referred to as the second member, second component, second region, second layer, or second portion.

[0047] In the specification, when an element (such as a layer, a region or a substrate) is described as being “on”, “connected to” or “coupled to” another element, the element may be directly “on”, “connected to” or “coupled to” another element, or one or more other elements may be present therebetween. Conversely, when an element is described as being “directly on”, “directly connected to” or “directly coupled to” another element, there may be no other elements present therebetween.

[0048] The terms used herein are only used to describe various examples and are not intended to limit the disclosure. Unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. The terms "comprise", "include" and "have" indicate the presence of the described features, quantities, operations, components, elements and / or combinations thereof, but do not exclude the presence or addition of one or more other features, quantities, operations, components, elements and / or combinations thereof.

[0049] Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as those generally understood by a person of ordinary skill in the art to which the present disclosure belongs after understanding the present disclosure. Unless explicitly defined as such herein, terms (such as those defined in a general dictionary) should be interpreted as having a meaning consistent with their meaning in the context of the relevant art and the present disclosure, and should not be interpreted in an idealized or overly formal manner.

[0050] Furthermore, in the description of examples, when it is considered that a detailed description of a well-known related structure or function would cause vague interpretation of the present disclosure, such a detailed description will be omitted.

[0051] Figure 2 is a schematic diagram showing an embedded software code synthesis method based on a model-driven approach according to an embodiment of the present disclosure.

[0052] The present invention needs to abstract the information related to the target operating system, construct templates for code generation for different target operating systems, and construct a generation and synthesis tool for operating system encapsulation code (code synthesis tool based on domain model, referred to as code synthesis tool) based on these templates, and the code synthesis tool is used to generate encapsulation code related to the operating system, and synthesize it with the business code into a complete application. In this way, the encapsulation code of the application is automatically generated by the operating system, which reduces a large amount of manual work while also making it unnecessary for developers to understand knowledge related to the target operating system, so that developers can focus on business-related details.

[0053] Extraction of operating system feature information:

[0054] For different target operating systems, the architecture code that needs to be generated and the organization of the generated architecture code may be very different, but the information required to generate these architecture codes is basically the same. Based on this situation, the code synthesis tool based on the domain model extracts the information related to the target operating system during design, and establishes a set of template classes and a template factory for each target operating system. If you need to support a new target operating system, you only need to implement a set of corresponding template classes and template factories without changing the overall structure of the code synthesis tool. First, you need to extract the operating system-related information from these encapsulated codes. This information is mainly divided into two parts:

[0055] The first part is the interface information provided by the operating system to the user, as shown in Table 1, including the process management interface, the interface for inter-process communication, and the interface for clock management. The example of interface information comes from an embedded real-time operating system. These interfaces are not all the interfaces provided by the embedded operating system to the user, but include all the interfaces that may be called when generating operating system-related encapsulation code. Whenever developing embedded software on a new target operating system, it is necessary to obtain information about these interfaces of the target operating system.

[0056] Table 1. Operating system interface table that may be called by generated encapsulation code

[0057]

[0058]

[0059] The second part of information is the information required by the software system as a whole. This part of information mainly includes some parameters required for the initialization of the software system and some common template functions (such as functions for initializing all inter-process communication relationships created, functions for checking the status of inter-process communication relationships, process loop bodies, etc. These template functions will call the interfaces provided by the operating system). These template functions are common to all operating systems.

[0060] After extracting this part of operating system related information, only some platform-independent parts are left when generating the encapsulation code. After providing this platform-independent information through process modeling tools or other means, it is possible to generate encapsulation codes for multiple different target operating systems based on this information. The platform-independent information that may be required is shown in Table 2.

[0061] Table 2 Platform-independent information table required to generate packaging code

[0062]

[0063] Creation of operating system packaging template:

[0064] Since the information required to generate the operating system encapsulation code is divided into two categories: one is information related to the target operating system, and the other is platform-independent information. When generating code, this platform-independent information should be provided by the outside of the code generation tool, either manually written by software developers or automatically generated by process modeling tools. This information related to the target operating system should be separately established as an operating system encapsulation template (which can be read by the code generation tool) and configured by the developer of the code generation tool before code generation.

[0065] Since the target code generated by the modeling simulation software conversion is generally in C language, and the code generation tool is written in C++, the present invention designs a series of operating system encapsulation template classes, including C language template classes and code factory classes. Among them, the C language template class mainly includes:

[0066] Function template class (including the following types of function templates: preparation function, responsible for creating the communication mechanism required for the process; verification function, mainly verifies whether the creation of the inter-process communication mechanism is successful through the return value; partition main function, mainly initializes the partition and creates processes and processes within the partition; entry function, mainly initializes the variables in the process and calls the task code corresponding to the process).

[0067] Input / output interface initialization template class (mainly responsible for initializing the correspondence between the process input / output interface and the inter-process communication mechanism in each process, and may need to call the content in the system call template class).

[0068] Variable initialization template class (mainly responsible for initializing a series of variables required during the running process).

[0069] Process loop body template class (mainly responsible for the operations in each process loop body, including obtaining input, calling task code, and performing output).

[0070] Operating system interface template class (mainly responsible for initializing the parameters required for system calls and calling the corresponding system calls, including inter-process communication template class - semaphores, message queues, etc.; communication mechanism creation template class, process creation template class).

[0071] Each template class contains a toC function, which generates the code snippet defined by the template class according to a series of parameters passed in and returns it. There is a nested calling relationship between template classes, in which the function template class may call the toC functions of all other template classes, and the process loop body template class and the input / output interface initialization template class may call the toC function of the system call template class.

[0072] The code factory class provides an abstract interface for generating code, and corresponds these interfaces to the initialization function of each template class. Whenever a new operating system needs to be adapted, a set of specific template classes (they inherit the above abstract template classes) and specific code factories need to be implemented according to the operating system's system call interface, data type, process creation method, inter-process communication method and other properties.

[0073] Figure 3 This is an example of a toC function in an operating system interface template class (message queue sending). The parameters of the toC function come from the internal variables of the template class. This toC function may be nested by other template classes. When generating code statements for message queue sending, the code engineering will call the toC function of this template class step by step through nested calls. The function will return a C statement array rt containing a series of target operating system interface call statements. Other function statements may be nested in rt, such as Figure 3 The rt in the example contains an if-else statement to determine whether the message queue sends the message successfully.

[0074] like Figure 4 The figure shows the nested calling relationship of the software partition master file template class, where XXOS is the target operating system name. When the code factory class calls the partition master file template class's toC function to generate the partition master file code, it will call the inter-process communication relationship template class's toC function to generate the inter-process communication relationship initialization code, and call the software partition master function template class's toC function to generate the partition initialization code where the software is located. The inter-process communication relationship template class's toC function will then call the message queue template class and the semaphore template class's toC function to generate the corresponding code, and the software partition master function template class's toC function will call the process creation template class's toC function to generate the process creation code.

[0075] Figure 5The nested calling relationship of the process code file class is shown. When generating the process code file, the toC function of the process entry function template class corresponding to the target operating system is first called to generate the process entry code. The toC function of the process entry function template class sequentially calls the toC function of the process IO port initialization template class, the task code initialization template class, and the task code loop body template class to generate the code inside the process entry function. Since the task code loop body needs to continuously communicate between processes, the toC function of the IO template class in the loop body needs to be called to generate IO code.

[0076] Generation and synthesis of operating system encapsulation code:

[0077] After the present invention establishes the abstract layer of operating system encapsulation code template class, the information required in the embedded software operating system encapsulation code generation process is separated into two parts: platform-independent information, which is provided manually or through a software process modeling tool; and information related to the target operating system, which is stored in the code synthesis tool in the form of an encapsulation template class.

[0078] Platform-independent information is saved in the format of an XML configuration file. The structure of the XML configuration file is as follows: Figure 6 As shown in the figure, the information contained in it mainly includes two parts. One part is the information related to the process encapsulation of the model-generated task code, including the process cycle, priority, process-related variables, task code information contained in the process, etc. The other part is the information related to the inter-process communication relationship, including the initialization parameters of the inter-process communication relationship, the reference of the process to the inter-process communication relationship, etc.

[0079] After obtaining the input of the XML configuration file and the task code file, the code synthesis tool will first parse the XML configuration file and save the parsed information in the corresponding object. tinyxml2 is a small and efficient open source c++XML parser. There are many ways to access and interact with XML data. tinyxml2 uses the Document Object Model (DOM), which means that the XML data is parsed into C++ objects that can be browsed and manipulated. After that, the architecture code will be generated according to the configured target operating system and the information stored in these objects. After the architecture code is generated, it will first synthesize functions one by one, and then synthesize code files together with the task code. Finally, the code synthesis tool will output the final generated software code to the original directory where the task code file is located. The process of code generation and synthesis is as follows. Figure 7 shown.

[0080] The encapsulation code generation process is divided into the generation of process initialization code, process startup code, process scheduling code, process communication mechanism initialization code, and process communication code. In the encapsulation code generation process, the operating system encapsulation code template class will be instantiated through the abstract factory class. These template classes actually correspond to multiple program fragments in the final C program. You only need to call the interface in the abstract factory class to create the corresponding class. Directly using C language strings is still too complicated. The cTree module in the code synthesis tool implements a simple C language syntax tree data structure. cTree represents a C program containing multiple C code files in a tree structure. It is more reasonable to convert the model tree into a C code tree by traversing all nodes of the model tree than to directly generate C code strings, and it can support more functions. This module mainly includes the following classes:

[0081] 1. CRoot class. This class is the root node of the entire C program.

[0082] 2. CFile class. This class represents a C language file.

[0083] 3.CDecl class and its subclasses. This class represents C language declarations. Function declarations and function definitions are all subclasses of this class.

[0084] 4.CInclude class, representing the #include statement.

[0085] 5. CSentence class and its subclasses. This class represents a C statement. Variable declaration statements, assignment statements, function call statements, loops, branch statements, etc. are all subclasses of this class. The C syntax tree structure is as follows Figure 8 As shown:

[0086] The process code is the code that actually executes the model module, which includes port initialization, variable initialization, model initialization, and model loop execution.

[0087] Each port corresponds to an inter-process communication data structure declared in the partition. In the port initialization part, the code synthesizer will obtain the ID of the data structure or other variables used to indicate the data structure according to the XML configuration and OS type, in preparation for obtaining data from the data structure.

[0088] Variable initialization declares and initializes a series of local variables required by the model module. For variables that do not participate in inter-process communication and only participate in calculation, they only need to be initialized and assigned values. For variables that participate in inter-process communication, they also need to be sent to other processes after initialization so that other processes receive the initialized value of the variable.

[0089] The model initialization part will call the model initialization function to initialize the local model. The model initialization function is provided by modeling tools such as Simulink / Scade when generating model code.

[0090] The model loop execution part will execute the function of the model module in sequence according to the XML configuration and update the variables in it. These function functions are provided by tools such as Simulink / Scade when generating model code. The algorithm process of process code generation is as follows Fig. 9 shown.

[0091] The inter-process communication code is automatically generated by the code synthesis tool according to the mapping relationship between variables and ports in XML and the model loop execution code process.

[0092] In XML, if a variable needs to participate in inter-process communication, it will correspond to a port. If the port is an In type port, it means that the variable will receive data from the port, and if it is an Out type port, it means that the variable will output data from the port.

[0093] In the code of the model initialization part, when a variable is initialized, the code synthesizer will check whether it is mapped to the Out type port. If so, it will generate write code to write the initialization value of the variable to the corresponding port so that other processes can receive the initialization value.

[0094] In the model loop execution part code, whenever the function uses the variable or its pointer as a parameter, or uses the variable to save the return value, the code synthesizer will check the mapping relationship between the variable and the port. If it is mapped to an In type port, the code synthesizer will insert the receiving code before the function is called. If it is mapped to an Out type port, the code synthesizer will insert the sending code after the function is called. The inter-process communication code generation algorithm process is as follows Fig.10 shown.

[0095] After the process is divided, the developers of aerospace embedded software can input some key information of the process, such as the priority and cycle of the process, into the aerospace embedded software process division modeling tool, and the aerospace embedded software process division modeling tool will generate the corresponding XML file according to the agreed XML Schema. At the same time, since the embedded operating system running the embedded software often only loads the program once at startup, this XML file may also need to contain some information related to process initialization, such as the stack size used by the process, the process cycle, etc.

[0096] The main contributions of the present invention include:

[0097] 1. The feature information related to the operating system required for the generation of the operating system encapsulation code was extracted, and the XML configuration file format specification containing all the information required to generate the architecture code of the embedded software was described through XML schema. The information contained in the XML configuration file mainly includes two parts. One part is the information related to the process encapsulation of the business code generated by the model, including the process cycle, priority, process-related variables, business code information contained in the process, etc. The other part is the information related to the inter-process communication relationship, including the initialization parameters of the inter-process communication relationship, the reference of the process to the inter-process communication relationship, etc.

[0098] 2. Establish an operating system encapsulation template class according to the XML configuration file format specification to implement the code synthesis tool. The code synthesis tool can complete the generation of the encapsulation code required when the task code runs on the target operating system, and synthesize the task code and the encapsulation code into a complete embedded software, thereby reducing a large amount of handwritten code, so that developers do not need to understand the details related to the operating system, but only need to focus on platform-independent information in the software, and make embedded software more reliable and easier to verify. The operating system encapsulation template class in the code synthesis tool allows the code synthesis tool to expand new target operating systems as needed by actual applications, and only a small amount of encapsulation template code needs to be changed.

[0099] Although some embodiments of the present disclosure have been shown and described, it will be appreciated by those skilled in the art that modifications may be made to the embodiments without departing from the principles and spirit of the present disclosure, the scope of which is defined by the claims and their equivalents.

Claims

1. A method for synthesizing embedded software code based on a model-driven approach, It is characterized in that Firstly, a process of extracting operating system feature information from software design documents is established; Then, the operating system encapsulation templates for code generation are constructed for different target operating systems and process codes are formed. The information required in the embedded software operating system encapsulation code generation process is separated into two parts: platform-independent information, which is provided manually or through software process modeling tools; and information related to the target operating system, which is saved in the code synthesis tool in the form of encapsulation template classes; An operating system encapsulation code synthesis tool is constructed based on the operating system encapsulation template, and the specific process is as follows: after obtaining the input of the storage file of the platform-independent information and the task code file, the code synthesis tool first parses the storage file of the platform-independent information and saves the parsed information in the corresponding object; then, architecture code is generated according to the configured target operating system and the information saved in these objects, and after these architecture codes are generated, functions are first synthesized, and then code files are synthesized together with the task code; finally, the code synthesis tool outputs the finally generated software code to the original directory where the task code file is located; Then, the code synthesis tool generates the encapsulation code related to the operating system. The specific process is as follows: the encapsulation code generation process is divided into the generation of process initialization code, the generation of process startup code, the generation of process scheduling code, the generation of process communication mechanism initialization code and the generation of process communication code; Finally, the code synthesis tool synthesizes the encapsulation code and the business code into a complete flight control software application.

2. The method for synthesizing embedded software code based on a model-driven approach as claimed in claim 1, It is characterized in that The information extracted in the extraction process of the operating system feature information is mainly divided into two categories: the first category is the interface information provided by the operating system to the user, and the second category is the information required by the entire software system.

3. The method for synthesizing embedded software code based on a model-driven approach as claimed in claim 2, It is characterized in that The operating system encapsulation template includes a C language template class and a code factory class. The C language template class includes: a function template class, an input / output interface initialization template class, a variable initialization template class, a process loop body template class, and an operating system interface template class. Each template class includes a toC function, which generates a code fragment defined by the template class according to a series of parameters passed in and returns it. There is a nested calling relationship between the template classes, wherein the function template class may call the toC functions of all other template classes, and the process loop body template class and the input / output interface initialization template class may call the toC function of the system call template class; The code factory class provides an abstract interface for generating code, and these interfaces correspond to the initialization function of each template class. Whenever a new operating system needs to be adapted, a set of specific template classes and specific code factories need to be implemented based on the operating system's system call interface, data type, process creation method, and inter-process communication method.

4. The method for synthesizing embedded software code based on a model-driven approach as claimed in claim 1, It is characterized in that The platform-independent information is saved in the format of an XML configuration file. The structure of the XML configuration file contains two parts of information. One part is information related to the process encapsulation of the model-generated task code, including process cycle, priority, process-related variables, and task code information contained in the process; the other part is information related to the inter-process communication relationship, including the initialization parameters of the inter-process communication relationship and the process's reference to the inter-process communication relationship.

5. The method for synthesizing embedded software code based on a model-driven approach as claimed in claim 1, It is characterized in that The process code includes port initialization, variable initialization, model initialization, and model loop execution parts; The port initialization process is as follows: each port corresponds to an inter-process communication data structure declared in the partition. In the port initialization part, the code synthesizer obtains the ID of the data structure or other variables used to indicate the data structure according to the XML configuration and OS type, and prepares for obtaining data from the data structure next; The variable initialization process is as follows: declare a series of local variables required by the model modules and initialize them, assign values ​​to variables that do not participate in inter-process communication but only participate in calculation, and send variables that participate in inter-process communication to other processes after initialization; The model initialization process is: calling a model initialization function to initialize the local model, the model initialization function is provided by the modeling tool when generating the model code; The model loop execution part process is: according to the XML configuration, the function of the model module is executed in sequence and the variables therein are updated; The inter-process communication code is automatically generated by the code synthesis tool according to the mapping relationship between variables and ports in XML and the model loop execution code process; in XML, if a variable needs to participate in inter-process communication, it corresponds to a port. If this port is an In type port, it means that the variable will receive data from the port. If it is an Out type port, it means that the variable will output data from the port; in the code of the model initialization part, when a variable is initialized, the code synthesizer will check whether it has a mapping with the Out type port. If so, it will generate a write code to write the initialization value of the variable to the corresponding port so that other processes can receive the initialization value; in the code of the model loop execution part, whenever a function function uses the variable or its pointer as a parameter, or uses the variable to save the return value, the code synthesizer will check the mapping relationship between the variable and the port. If it is mapped to an In type port, the code synthesizer will insert the receiving code before the function is called. If it is mapped to an Out type port, the code synthesizer will insert the sending code after the function is called.