|
||||||
How to use on-target rapid prototyping
How to use on-target rapid prototyping Your new algorithm does the job on a real-time, rapid prototyping computer but will it work on your actual target, a highly complex automotive electronic control unit? On-target rapid prototyping, an emerging trend in embedded systems development, may provide the answer. Step back 15 years and envision an automotive-powertrain R&D or advanced-production engineer touting a hot new algorithm during a design review. All eyes turn to the grizzled project manager who inevitably grumbles, "Great, but will it drive an engine?" Months later, a hand-coded version of the algorithm appears, courtesy of the software department, and dynamometer or proving-ground tests begin. Eventually, these tests answer the project manager's question but only after significant time and expense. Now observe the R&D engineer today, touting yet another hot new algorithm with the added twist that it did indeed drive an engine in the lab or on the test track via the ever-present rapid-prototyping computer. All eyes once again turn to the grizzled project manager who inevitably asks, "Great, but will it drive an engine using real production hardware?" Is this progress? Definitely. One should first assess if it's even feasible for an algorithm to provide the correct behavior for a highly complex system, such as those found in many of today's automotive electronic control units (ECUs). Rapid prototyping on powerful real-time computers helps provide that understanding. However, one also needs to know if the algorithm is practical; that is, will it work on an 8-, 16-, or 32-bit resource-constrained ECU? In this article, I'll discuss how on-target rapid prototyping can lend a hand and how it differs from conventional rapid-prototyping approaches. Modeling 101 A classic model of a feedback controller or DSP algorithm is shown in Figure 1. With the emergence of finite state machines, another modeling capability is now available. When used with block diagrams, finite state machines provide a way to create complete behavioral models for embedded systems containing both event-based and time-based components. Examples of such systems include transmission control modules, gas turbine controllers, and flight management systems. These systems are likely to use block diagrams for specifying the digital processing, filters, and lookup tables, while state machines and flow diagrams provide the mechanisms for modeling fault detection, built-in testing, and mode and shift logic. If you don't have a sophisticated plant or environmental model, you can substitute the plant shown. It's straightforward to substitute the plant shown in Figure 1 into a software test harness by using stimulus input signals and scopes, instead of carefully formulated dynamic system equations. Thus, you can perform bench-type testing from your desk- or laptop. The model can be as detailed or as high-level as is appropriate for a given development stage. Perhaps your initial objective is to ensure that the system is stable and that performance objectives such as rise time and overshoot are satisfied. So your model might be based on a second or third order system using double-precision math. At the end of design, the final objectives may require an extremely detailed model to explicitly define all aspects of the required behavior. You may need to specify data in the form of signals and parameters in fixed point by adding scale factors, bias, overflow, and rounding logic. You may also incorporate robustness code into the model to check and protect against events such as divide-by-zero or array-out-of-bound accessing. Onboard Diagnostics II and other diagnostic routines are then folded in, often in such large quantities that they eventually constitute the majority of the model, leaving the control logic as a small (but important) player. In effect, these types of deta ils transform the model into a classic software design specification document. But the model is more than that for one important reason: it simulates. Simulating models It's now a common practice to simulate system models containing block diagrams and state machines, and it's not unusual to see system models containing tens or, in some cases, hundreds of thousands of blocks. These numbers are impressive when you consider that some blocks and state machines themselves represent 10 or more lines of code. The key to success here is to manage the model as you would a formal software specification by developing modeling guidelines, partitioning the model, holding model reviews, and so on. But not all embedded systems have enough spare memory or possess the computational speed necessary to implement such massive creations. So for smaller (for example 16-bit) applications with 32K ROM and 2K RAM, the modeler should recognize from the start that collections of deeply nested hierarchical state machines or filters made up of complex H-infinity matrix math operations probably just won't fit. The modeler for these applications needs to understand which block constructs yield the best code and the models should be carefully parameterized and reviewed to ensure maximum code efficiency. With this mindset and today's technology, it's certainly possible to deploy your model in a mass-production, low-cost hardware environment. High-complexity applications have accelerated the acceptance of Model-Based Design and code-generation technologies. They've also fostered industry guidelines and best practices. Several years ago an automotive leadership council, composed mostly of major OEMs and suppliers, published a production-intent modeling style guidelines document, based on Simulink.2 Many companies in a variety of industries now use this as a starting point for their internal standards. Other documents describing tips and techniques for production-intent modeling topics, such as fixed-point design and code generation, have also guided developers.3 But having a model that executes on a host computer can only offer so much. The key enabler is automatic code generation, which transforms models into C code that can run virtually anywhere with push-button automation. Getting code from models Some of the more popular activities based on automatically generated code from models include: After looking at these diagrams, it's not a stretch to realize that the automotive industry has envisioned this on-target approach for years. It just took the code-generation technology time to get there. Each approach fits a certain need. The following list compares these two approaches: Bypass rapid prototyping: Getting on target IAV, an automotive engineering company headquartered in Germany, supports its customers by employing an on-target rapid prototyping solution called the Universal Control Unit. It consists of several microcontrollers including Motorola MPC555, Infineon C167, Infineon TriCore, as well as an OSEK target. Additional block support for the Universal Control Unit is provided for interactive tuning over CAN Calibration Protocol (CCP) using CAN. Other companies offer combined hardware and software systems for on-target rapid prototyping. In addition, a growing number of companies offer embedded targets that consist of software blocksets and device drivers. The hardware is obtained separately. If you want to build an embedded target, it would be easier just to use your existing build environment and interface directly to the automatically generated code. This approach, sometimes termed algorithm export, can be implemented with code generators that allow you to specify that a model or subsystem within the model is reusable. The code generated would have the appropriate entry points and function-call signatures that interface with your existing scheduler and build process. However, if the application requires greater flexibility or is already modeled, it's probably worth the effort to develop an embedded target blockset as described in the next section. Building a baseline embedded target The approach for developing a baseline target will depend on the modeling environment you've chosen. The key is to understand the details of the code generation process and enter hooks into that process. See Figure 3, which shows the code generation process and the entry hooks into the process. These entry hooks are the points with which the model developer is able to interact and control the target code environment generated from that model. One of the first steps in the code-generation process shown in Figure 3 is to compile the model into an in-memory representation. At this point, it may be useful to use the target entry or target compiled hooks to add certain consistency checks to ensure that the model is suitable for deployment on your target. Checks might include confirmation that only integer code is used for fixed-point microcontrollers or DSPs. You might also want to check that only discrete time blocks are used. The next step in the code-generation process is often the actual outputting of the C code. Here you might use the target make hook to ensure that data is placed into the proper memory segments and that an appropriate main program was created, with single or multitasking scheduling capabilities. Template-driven technology might be available for accomplishing these tasks. It would also be a good idea to invoke source-code analysis or Lint tools to verify that the code satisfies in-house code standards. Finally, after the code is generated and the make process concludes, an automatic download utility can be invoked using the target exit hook to deploy the executable onto the target. Typically, this is done with a debugger utility. If the debugger supports command script files, this can be straightforward to implement. Another option is to invoke the instruction set simulator (ISS) and execute the code purely on the host. Some customers want to execute the code in an ISS and compare the results with the model that's simulating inside the modeling environment. This co-simulation approach facilitates host/target verification efforts. Building an advanced embedded target Some of the more desirable features for a turnkey production target include: Another item to consider is how you want the device driver block to behave during host simulation. One way to simplify development is to create the block with a pass-through option. When pass-through is enabled, the driver block input is passed through to the output during simulation, thus bypassing the driver block itself. This option affects simulation only. The code generated from the block interacts normally with I/O hardware on the target. This approach makes it easy to go from simulating to generating embedded systems code by using the same model. Processor-in-the-loop simulation requires that the plant or test harness model running on the host interact with the code running on the target. One way to do this is with some type of external mode operation that may be provided with the modeling environment. For example, a serial mode interface (RS-232) could be used between the host computer and target since many hosts and targets have a serial port available. The main task here is to develop a serial driver for the target hardware and include external mode support files used by the modeling environment during the build process. Executable placement in flash memory or RAM is typically controlled by the target's download utility. To support this capability you will likely need to provide multiple linker command files, multiple debugger scripts, and possibly multiple make or project files. One approach prevalent in the automotive industry to support target interaction and tuning is to use the CAN bus in conjunction with an ASAP2 file and CCP. Several host-based user interfaces connect to a CCP-enabled target and provide data viewing and parameter tuning. Supporting these tools requires the implementation of CAN hardware drivers and CCP for the target, as well as ASAP2 file generation. The effort required to build a full-featured target is considerable, so check with your vendor to see if documentation is available to serve as a guide. Consultants who have done this type of work previously are another good resource. And with a little luck, you may even find that a nice turnkey target that suits your needs is already available off-the-shelf. Example: Jaguar Tom Erkkinen is an embedded applications manager for The MathWorks, Inc. His focus is production code-generation products and related technologies. Tom has worked in the aerospace and automotive embedded system field for more than 15 years. He has a BS from Boston University and an MS from Santa Clara University. Tom's email address is terkkinen@mathworks.com. Endnotes Copyright 2005 © CMP Media LLC |
Home | Feedback | Register | Site Map |
All material on this site Copyright © 2017 Design And Reuse S.A. All rights reserved. |