Automatic generation of controls code from models for real-time Linux platforms Bruno Morelli, Riccardo Schiavi, Claudio Scordino, Paolo Gai Evidence Srl Pisa, Italy {b.morelli, r.schiavi, claudio, pj}@evidence.eu.com Marco Di Natale Scuola Superiore Sant’Anna Pisa, Italy marco@sssup.it Abstract We present our experience in the design and realization of a toolset for the extension of the simu- lation and modeling capabilities and the automatic generation of code from ScicosLab models running on embedded Linux and RTAI. ScicosLab — a free system modeler and simulator — has been extended with add-ons for the modeling of hierarchical Finite State Machines (FSMs) and a GUI prototyper based on the Qt graphical libraries. The code generator supports multirate models and maps the model blocks onto multiple periodic threads, with the automatic synthesis of thread scheduling, communication and access to the I/O primitives. We discuss the design challenges and options and the implementation issues encountered during the development of the toolset, including the mapping of functionality onto threads, the problem of semantics preservation in the implementation of communication, the methods used to abstract from the architecture- specific I/O details and the concurrent use of PCI and video peripherals. We show an example of generated code and a set of performance measurements on real hardware with a data acquisition peripheral. 1 Introduction The Model-Based Design (MBD) development methodology is today widely used in several appli- cation domains like automotive, aerospace and con- trols. MBD can provide a significant reduction of development time and costs for embedded software by leveraging early verification and validation. In MBD, a model of the control functions is de- veloped together with a model of the controlled sys- tem (or plant). The behavior (within and possibly also outside the specification range) is verified by simulation and — in safety critical systems — by model checking. Automatic code generation tech- niques are then used to generate a software imple- mentation that is equivalent to the model, reducing the possibility of adding errors during the manual coding stage. Several commercial products are offered for the modeling, simulation and verification of systems ac- cording to a Synchronous Reactive (SR) semantics. Among them, Simulink, LabView and SCADE are probably the best known. ScicosLab [6], a free sys- tem modeler and simulator developed at Inria, start- ing from the late ’90s is a free and open source al- ternative for system simulation. However, the use of ScicosLab for the industrial development of em- bedded controls has been limited due to a number of issues, including the lack of support for model- ing finite state machines, a code generator not suit- able for systems with limited memory availability, no 1