Embedded Systems - Model-Based Design
You need to have MATLAB-Simulink (at least version 2007) installed.
In addition, you need to have the following:
For using the ReTiS toolset for the ERIKA/Flex environment follow these steps:
- Microchip MPLAB IDE - from the Microchip web page click here
- Microchip C30 compiler - (register to get free academic version) click here
- Erika for DsPIC - from Evidence click here
You are almost there. You should now be able to simulate your systems including the Flex mockup. The missing components relate to the code generation part.
for this you need additional component in your computer:
- Get the Flex blockset from here (zip file)
- Unpack it "as is" into a directory on your local hard drive.
- Setup the MATLAB path to include the directory "blockset" you just created and all its subdirectories (in the MATLAB menu File->Set Path)
- The next time you open Simulink, in the Library browser, you should find an additional Library "Model-Based Design ReTiS"
You also need some small library files and our OIL/task code generator.
- Python (2.6.4). Available from here
- PyQt (2.6). Available from here
- the libxml library for python libxml2-python (2.7.4). Available from here
- Install the packages in the following order:
Finally. This is your procedure for generating the code.
- Create a directory MBD under C: (C:\MBD)
- Get the additional Erika code and the code generator for the task skeleton and the OIL from here (zip file)
- Put the contents of the zip file into the MBD directory (C:\MBD). There are three directories: mbd_retis, retis_code_generator, to_be_copied
- Work on your system model until you are happy with it.
- Add the Retis blocks for I/O any time you are connecting parts of your model to the Flex mockup. Remember to give a name to the logical I/O channel using the block parameter!
- Wrap all the system model (without the flex mockup) in a subsystem and give it a suitable name (such as Stopwatch).
- Configure the code generation as follows:
- Open the configuration window in simulink (Simulation->Configuration Parameters)
- In the "Solver" section select: Solver options - type: fixed step
- In the "Real-Time Workshop" section,
- For the System target file select: ert.tlc (Real-Time Workshop Embedded Coder)
- disable/uncheck "Generate Makefile"
- enable/check "Generate code only"
- In the "custom code" section, select "Header file" and add to the right (in the Header file: textbox) the line
- In the "Interface" section
- disable/uncheck support for non-finite numbers, complex numbers and absolute time.
- disable/uncheck Terminate function required
- in the "Templates" section disable/uncheck "Generate an example main program"
- close the configuration window
- In your model, select your subsystem, right click on it and select "Real-time workshop->Build subsystem"
- After confirmation and a few steps, MATLAB/simulink/RTW will create a new directory for you with the name of the subsystem, followed by _ert_rtw. the directory contains the generated .c and .c files and an additional file Mylist.data (created for our custom blocks).
- From the directory "to_be_copied" in C:\MBD copy the two files run_codegen.py and matlab_out.xml.
- Edit the file matlab_out.xml. Replace the content of the element matlab with the contents of the file Mylist.data
- Execute (by double clicking) run_codegen.py. Fill in the subsystem name, the execution rate, and assign a physical index to all the logical devices. Press the button "Generate code".
- the program run_codegen will generate additional files, including: conf.oil, retis.c, retis.h and main.c
- Put the files generated from run_codegen together with the files generated by Real-Time workshop embedded coder in an Erika project, compile and upload on the board