You are on page 1of 74

in MicroC

3 Riverside Drive Andover, MA 01810 U.S.A.

Tutorial
Release 2.1

Copyright Notice and Proprietary Information


Copyright 2000 by I-Logix Inc. Printed in the United States of America. 3 Riverside Drive, Andover, MA 01810 U.S.A. All rights reserved. The software described in this document is furnished under a license and may be used or copied only in accordance with the terms of such license. Statemate software contains proprietary information, as well as trade secrets of I-Logix Inc., and is protected under international copyright law. Reproduction, adaptation, or translation, in whole or in part, by any means graphic, electronic or mechanical, including photocopying, recording, taping, or storage in an information retrieval system of any part of this work covered by copyright is prohibited without prior written permission of the copyright owner, except as allowed under the copyright laws. This product or products depicted herein may be protected by one or more U.S. or international patents or pending patents. The information in this manual is subject to change without notice. I-Logix assumes no responsibility or liability for any errors contained herein or direct, indirect, special, incidental or consequential damages in conjunction with the furnishing, performance, or use of this material. Restricted Rights Legend :. Use, duplication, or disclosure by the government is subject to restrictions set forth in subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Software clause at DFARS 252.227-7013 (October 1988) and FAR 52.227-19 (June 1987).

Trademarks
Statemate is a registered trademark of I-Logix Inc. I-Logix and the I-Logix logo are trademarks of I-Logix Inc. Microsoft, MS, and MS-DOS are registered trademarks, and Windows and Windows NT are trademarks of Microsoft Corporation. X Window System is a trademark and product of the Massachusetts Institute of Technology. Sun, SunOS, Solaris, OpenWindows, and NFS are trademarks or registered trademarks of Sun Microsystems, Inc. Other products mentioned may be trademarks or registered trademarks of their respective companies.

Part No. 2170 Printed in the United States of America

Preface
Welcome to the Rhapsody in MicroC Tutorial, Release 2.1. This manual is designed to be a stand-alone introduction to the use of Rhapsody in MicroC (RiMC) in developing an embedded software project. A copy of this manual is also available online. This document is part of the core document set for Rhapsody in MicroC. This core document set includes the following documents: Rhapsody in MicroC Administrator s Guide Rhapsody in MicroC Quick Reference Guide Modeling Reactive Systems with Statemate Rhapsody in MicroC On-Line Help Rhapsody in MicroC Tutorial Miscellaneous Errata Sheets, Release Notes, and other secondary documents In addition, your software includes a collection of electronic reference documents. This On-Line Reference Library consists of a collection of reference manuals and other documents provided in the Adobe Acrobat document format. A Master List document serves as the gateway to individual documents in the Reference Library. This gateway document is available from the main RiMC menu, from the on-line help, or directly1 when opened through the Acrobat Reader. Hard Copies of any of the on-line reference documents can be generated by printing the manual from the Acrobat reader.
1. Look for the document file named: MAGDOCS.PDF

Rhapsody in MicroC

iii

Whe re t o Fi nd I nf orm at io n
As mentioned earlier, the Rhapsody in MicroC documentation set typically consists of three principle parts: Printed Hard-copy documents and manuals On-line Help On-line Reference Library Hard-Copy Documents & Manuals Except for product versions delivered electronically, the core document set includes the following hard-copy documents: Release Notes Standard License Statement Installation Guide Tutorial
Note: In the case of products delivered electronically, all documents will be included in an electronic format.

There may also be a collection of Errata Sheets that list information that became available only after the other documents went to press. Hard copy manuals for other modules optional to the core RiMC product only include Release Notes, the Standard License Statement, and Errata Sheets (as needed). The balance of the modules document set is supplied in an electronic format. On-Line Help On-line Help is available throughout RiMC. To access this Help Information, you can use the Help menu items or the Help buttons on various screens. The help files have been designed to conform with the standard Windows NT 4.0 help engine, including full indexing, searching, printing, and hypertext

iv

Rhapsody in MicroC

Where to Find Information

links. For complete details please see the Help>Help on Help item in the RiMC main menu. Using the On-line Reference Library There are many reference documents available that focus on specific features and/or options for RiMC. Some additional documents are included that were written originally for Statemate MAGNUM, but which apply to RiMC. All of these documents make up an extensive library that is too large to print and store on a bookshelf. In fact, there is so much information available that it is sometimes difficult to find a specific piece of information. To solve these problems we have provided this reference library in the format of Adobe Acrobat Documents. Using the Adobe Acrobat Reader (supplied with your RiMC installation) you can view, search, print, and jump to cross references in other documents with ease. If you have not used the Acrobat Reader, an on-line guide is available from the Readers help menu. Documents within the reference library are accessed through a Master List document which serves as a gateway to the entire library. These documents are also used as additional reference material to support on-line help topics. Both the Master List and the on-line help are available from inside the RiMC main application. On-line help is also available throughout the application and its many modules. The latest versions of the Acrobat Reader (for all platforms) are available directly from Adobes website: www.adobe.com There is no charge for the viewer. If you download the viewer yourself, please be sure to select the version with extended search capabilities. This version will allow you to search multiple documents simultaneously.

Rhapsody in MicroC

Conv e nt ions
This book uses the following type conventions:
Type Style command1>command2 Description The greater-than (>) symbol leads you to the next item in a menu sequence. For example, File > Exit means to first select File from the menu bar, then select Exit from the File menu. Italic type is used for variable names that you should replace with actual names. For example, you should replace filename with the name of an actual file. Italics also indicate titles of referenced documents. Courier type is used for file names, directory names, keywords, code, and system output.

Italic type

Courier type

vi

Rhapsody in MicroC

Support

Su pport
The I-Logix Technical Support Help Desk provides assistance with installation, application issues, product defect reporting, and documentation questions. Technical support engineers, in conjunction with sales application engineers, assist prospective customers with product evaluations and provide timely responses to user issues. This ensures maximum productivity. The Technical Support Help Desk can be contacted in four different ways: email, the internet, by phone, or by fax. E-Mail and Web For the quickest and most effective response from anywhere in the world, contact Technical Support by filling out the support form found on our website at http://www.ilogix.com. You may also contact us via e-mail at the following address: support@ilogix.com. European customers should use eurosup@ilogix.com. In either case, if you use email to contact us, it is very important that you include the following information along with the description of your problem: Contact Information: Your Name: E-mail address: Phone: Company: Location:

Software Information:
Version and Build number of Rhapsody in MicroC: Operating system: Version and/or Patch Level or Service Pack applied: Any third-party tools you are using:

Rhapsody in MicroC

vii

Computer System Information:


Computer Model: Processor speed: RAM: Free disk space: Details of your problem: Please describe the nature of the problem, and the exact sequence of steps that caused or shows the problem. Also note any error messages that you have received. Telephone Support You can reach the helpdesk at 978-682-4884, Monday through Friday, 8:30 am till 5:30 pm Eastern Standard Time. European customers should call Technical Support at I-Logix UK Ltd., Monday through Friday, 9:00 am to 5:30 pm UK time. Their phone number is +44 (1249) 446-448. Fax Support Faxes can be sent to 978-682-5995. European customers should send faxes to +44 (1249) 447-373 .

viii

Rhapsody in MicroC

Support

NOTES

Rhapsody in MicroC

ix

Rhapsody in MicroC

Co nt e n t s
Preface ........................................................................... iii Introduction ................................................................... 15 Getting Started ............................................................... 19 Creating the Top Level ActivityChart ............................. 23 Defining Elements and Attributes ................................ 33 Creating Statecharts ....................................................... 41 Creating Panels .............................................................. 49 Executing the Model ...................................................... 57 Using the Test Driver ..................................................... 67 Index .............................................................................. 73

Statemate MAGNUM

xi

xii

Statemate MAGNUM

Statemate MAGNUM

xiii

xiv

Statemate MAGNUM

Introduction

Welcome to the Rhapsody in MicroC Tutorial. This tutorial will introduce you to the basic techniques required to use Rhapsody in MicroC (RiMC) by guiding you through a series of exercises. Each exercise will focus on familiarizing you with a basic set of skills necessary for using RiMCs core features. Because the focus of these exercises is on the mechanics of the RiMC tool, it is not intended to teach you the fine points of design methodology. However, additional information to use in learning more about modeling and design methodology has been provided for individual study. Please refer to the following documents which may be found online in the RiMC Reference Library: Modeling Reactive Systems with Statecharts: The Statemate Approach, by David Harel and Michal Politi, I-Logix P/N 2005. Statemate MAGNU M Methodology and Style Guidelines, Version 1.2, I-Logix P/N D-1100-51B, 08/97

Goa l s
At the completion of this tutorial you will have learned the following skills: How to start Rhapsody in MicroC. Creating a new project. Using Activity Charts to describe the functional view of a model.
Rhapsody in MicroC 15

Using the Data Dictionary to define textual elements and design attributes. Using Statecharts to describe the behavioral view of a model. Creating graphical panels to mock up the user interface of the system design. Setting up the C Code Generator to produce an executable running under Windows NT. Using test vectors to automate your code testing.

Who T his Tut oria l Is For


This tutorial is intended for any Software Developers who wants to learn how to use Rhapsody in MicroC. Users may or may not have previous experience with I-Logix Statemate MAGNUM automated system design tools, or with embedded system development. That experience might be helpful, but it is not necessary. This tutorial is not intended to be a primer on embedded systems development. Rather, it is simply intended to be a basic teaching aid on the mechanics of using the Rhapsody in MicroC tool. Any user seeking training in embedded system design should read any of the better technical books on the subject or enroll in a suitable seminar or college course. Advanced training with Rhapsody in MicroC, and the other development tools offered by I-Logix, is also available. Contact your sales representative for additional information.

Pr e- Tut oria l Che c kl is t


The following must be installed on your computer: Rhapsody in MicroC Microsoft Visual C++ V5.0 or later.

16

Rhapsody in MicroC

Using the Mouse Buttons

Us ing th e Mous e But to ns


It is necessary to briefly describe how to use the mouse buttons. It is assumed that you are using a 3button mouse. On this mouse, the Left button is called the Select button. This button is used for selecting elements, icons and menu items. It is also used for placing the starting points for transitions. Wherever you see to the direction to select an item, do so with a left mouse click. The Middle button is called the Transfer button. This button is used for moving elements. It is also used for placing the ending point for transitions. The Right button is called the Menu button. When this button is held down, a pop-up menu is displayed. When this is simply clicked, it deselects the selected item.

The E xa m ple P roj ec t


The example project is a traffic light with red, yellow, and green indicators. The design is extremely simple so you can fully concentrate on learning Rhapsody in MicroC, rather than on the design problem itself.

Rhapsody in MicroC

17

18

Rhapsody in MicroC

Getting Started
Lesson
Goa l s fo r t hi s Les s on
In this lesson you will learn to: Start Rhapsody in MicroC Create a new project

Step 1. St a rt in g Rha ps ody i n Mic ro C


Start RiMC by clicking on Start>Programs>Rhapsody in MicroC>RMC. If RiMC does not start, refer to the Troubleshooting section of the Rhapsody in MicroC Administrator s Guide.

Rhapsody in MicroC

19

Getting Started

Step 2. Cre a ti ng a N ew P roj ec t


1. From the main window, click the File > New Project... . The Create New Project form appears. 2. Fill in the form as shown:

Name : TRAFFIC_LIGHT or whatever you prefer. Databank : path to the databank directory (to use the browser click the [] button at the end of the line). If you are using this Tutorial in a training class, the instructor will tell you where to put the databank.
The Databank is a shared directory for all users involved in a specified project. It may be located on a network drive. This is where releases of a model will be saved. Its highly recommended that it not be shared with other projects or applications.

OS Implementation : MAINLOOP_SC

20

Rhapsody in MicroC

Goals for this Lesson

3. Click OK. The Open Project form appears with the project you just created selected.

4. Fill in the form as follows: Workarea : path to the workarea directory (to use the browser click the [] button at the end of the line). If you are using this Tutorial in a training class, the instructor will tell you where to put the workarea.
The Workarea is your personal working directory. Each user involved in a project needs to create at least one workarea. One user may have multiple workareas per project. Unlike databanks, workareas are stored on a local disk; they are not shared.

Rhapsody in MicroC

21

Getting Started

5. Click OK. The project opens and various tool icons appear in the Rhapsody in MicroC main widow.

Re vi ew
In this lesson, you have learned how to start a new project. In doing that, you have also learned how to get the main screen of RiMC to appear with all available tools ready to use.

You are now ready to proceed to Lesson 2...

22

Rhapsody in MicroC

Creating the Top Level ActivityChart


Lesson
Goa l f or t hi s Le ss on

In this lesson you will create the top level Activity Chart for the Traffic Light System. An Activity Chart represents the functional view of a system. It consists of the following elements: Activities Control Activities The functions in the system. Links to Statecharts that control other activities or that represent an activitys behavior.

External Activities Elements outside of the system to which the activities interface. Data Flows Exchanges of data between activities.

While creating the Activity Chart, you will functionally decompose the Traffic Light System into activities and show the external environment of the system using external activities. You will also use data flows to represent the exchange of information between activities. The finished Activity Chart will look like this:

Use the illustration as a guide as you draw your own chart.


Rhapsody in MicroC 23

Creating the Top Level ActivityChart

O NLIN E HELP
Rhapsody in MicroC has extensive online help available. Most tool windows (graphics editors, dialogs, etc.) have a Help menu item or a Help Button that calls up the context sensitive online help system. In Windows NT, the standard NT help engine is used, just like other Windows applications. And in the various versions of unix, the HyperHelp engine provides the same functionality as the NT help engine. In both cases, the online help is augmented by a library of online documents in Adobe Acrobat format. These documents can be opened through the List of Books menu item or as specific resources for further information from within an online help topic. For example, if you drop down the Help menu list in the main window of the Activity Chart Graphic Editor, and then choose the on Window menu item, the help window will open and the main topic for the Activity Chart Graphics Editor will appear. The illustration of the Graphic Editors main window has hot spots that supply additional information about the individual components of the editors main window. You will know that you are over a hot spot when the mouse cursor changes from an arrow to a pointing hand icon. If you position the mouse cursor over the button bar near the top of the window and click the Select mouse button, you will see a new window open with information like that shown above.
24 Rhapsody in MicroC

ONLINE HELP

Step 1. Cre a ti ng a n Act i vi ty C har t


1. Select the Graphic Editors icon from the main window.

2. The Open Chart dialog appears.

Rhapsody in MicroC

25

Creating the Top Level ActivityChart

Fill in the fields as follows: Type : Activity Chart Usage : Regular Name Pattern: TRAFFIC_LIGHT_CONTROLLER 3. Click the New button. The Activity Chart Graphic Editor appears.

Speed Buttons

Drawing Element Buttons

~ G raphics Drawing Area ~

Message Area

Help Information Area

26

Rhapsody in MicroC

ONLINE HELP

Step 2. Dra wi ng a n Int e rna l Act iv i ty


1. Select the C rea t e I n t er n a l A c t i v it y icon from the graphic editor. Notice the tool tips that appear as you hold the cursor over the drawing buttons. 2. Draw the TRAFFIC_LIGHT activity. Place the cursor at the desired location of the upper, left hand corner of the activity. Click and hold the left mouse button while dragging the crosshair (+) cursor to the lower, right hand corner of the activity. A dashed outline stretches with the cursor to show the shape of the activity. Release the mouse button at the lower, right hand corner of the activity. The outline of the activity becomes solid.

3. Name the TRAFFIC_LIGHT activity. While the Create Internal Activity mode is still active, type the activity name in uppercase or lowercase. The letters you are typing appear in the graphics drawing area. Move the name to the desired location inside the activity box. Click the left mouse button. The name is changed to uppercase letters and becomes associated with the activity in which it resides.

Rhapsody in MicroC

27

Creating the Top Level ActivityChart

Step 3. Dra wi ng a Cont rol Ac ti vi t y


1. Select the C re a t e C o n t r o l A c t iv i t y icon from the graphic editor. 2. Draw and label the TRAFFIC_LIGHT_CTRL activity inside the TRAFFIC_LIGHT activity using the same methods as in Step 2.

Step 4. Dra wi ng E x t er nal Ac t iv it ie s


1. Select the Create External Activity icon from the graphic editor. 2. Draw and label two external activities: INPUTS and OUTPUTS . Use the figure below as a guide.

28

Rhapsody in MicroC

ONLINE HELP

Step 5. Dra wi ng D at a Fl ows


1. Select the C r e a te D a ta F l o w button from the graphic editor. 2. Draw a data flow from INPUTS to TRAFFIC_LIGHT. Place the cursor (+) on the right edge of the INPUTS box and click the left mouse button. As you move the cursor, a dashed line stretches to show the shape of the data flow. Move the cursor to the right edge of the TRAFFIC_LIGHT box and click the middle button. The data flow arrow becomes solid.
To draw straight horizontal or vertical lines, hold down the Shift key while moving the cursor. You can click the left mouse button several times to mark corners on the way to the destination.

Rhapsody in MicroC

29

Creating the Top Level ActivityChart

Step 6. La bel li ng Da t a Flo ws


1. Label the data flow CHANGE .While the Create Data Flow mode is still active: Type the data flow label. Move the cursor to the data flow with the crosshair (+) just touching the line. Click the left mouse button to associate the label with the data flow. The label changes to uppercase.

To adjust the position of a label, place the cursor over the label, hold down the middle mouse button, move the label, and release the button.

2. Draw and label three additional data flows shown below: RED_LIGHT, YELLOW_LIGHT, and GREEN_LIGHT.

30

Rhapsody in MicroC

Review

Step 7. Che ck in g Y our Mode l


In the Activity Chart Graphic Editor menus, select Tools>Check Model. You should see the following message at the bottom of the screen. If not, go back and check your work.

Re vi ew
In this lesson, you have learned how to create the top level Activity Chart for the Traffic Light System. You have learned to create control activities, external activities, and to specify and name the data flows between activities.

You are now ready to proceed to Lesson 3...

Rhapsody in MicroC

31

Creating the Top Level ActivityChart

32

Rhapsody in MicroC

Defining Elements and Attributes


Lesson
Goa l f or t hi s Le ss on:

In this lesson you will learn how to define the elements and attributes in your design using a tool called the Data Dictionary. The textual elements in your design can be defined as any one of the following types: Event Condition Data-Item Edge trigger or impulse Level trigger or Boolean Integer, real, string, bit, bit-array, record, union, or user-defined type

Information-Flow Container used to group elements together The design attributes for activities can be defined as any one of the following types: Regular Task ISR Hierarchical or functionally decomposed Executed by scheduler Interrupt Service Routine

Rhapsody in MicroC

33

Defining Elements and Attributes

Step 1. Ide nt if y ing Unde f ine d E le m ent s


1. Select the Data Dictionary Browser icon from the Rhapsody in MicroC main window.

2. The Data Dictionary Browser window opens.(Only the top half is shown here.)

34

Rhapsody in MicroC

Goal for this Lesson:

3. In the top of the window select the following items (as shown above): Textual Type: All Structure: All Undefined (deselect Defined) Used (deselect Not Used) In Chart/GDS: TAIL_LIGHT_CONTROLLER . In the bottom of the window (shown below):

4. Click the Create New List button to display a list of undefined textual elements. 5. Click the Select All button to highlight all the elements in the list. 6. Click the Data Dict button to open the Data Dictionary Editor window on those elements.

Rhapsody in MicroC

35

Defining Elements and Attributes

Step 2. Re sol vi ng Unde fi ne d E le me nt s


1. The list of undefined elements appears in the Data Dictionary Editor. The first element in the list (in this case CHANGE ) is already selected for you.

2. Set the Type to Event and click the Save & Next button. 3. For the other three elements (GREEN_LIGHT, RED_LIGHT, and YELLOW_LIGHT), set the Type to Condition and save each change. 4. Click File>Exit.

Step 3. De fi ning Ac ti v it ie s
1. Open the Activity Chart TRAFFIC_LIGHT_CONTROLLER. 2. Select the external activity INPUTS by clicking on it with the left mouse button. At the same time, select the external activity OUTPUTS by holding down the Ctrl key and clicking on it.

36

Rhapsody in MicroC

Goal for this Lesson:

3. Click Tools>Data Dictionary.

4. The Data Dictionary Editor opens. For both elements, set the Type to Environment and save the changes.

Step 4. De fi ning De si gn At t ri but es


1. In the Activity Chart TRAFFIC_LIGHT_CONTROLLER, select the activity TRAFFIC_LIGHT.

Rhapsody in MicroC

37

Defining Elements and Attributes

2. Click Tools>Data Dictionary.

3. Click Design Attributes...

4. Set the Type to Task , click OK , and save the change.


A Task is an activity that the schedule executes. Note that the name of the Activity in the graphic editor now has an asterisk (*) appended to it to indicate that it is a Task.

5. In the Activity Chart TRAFFIC_LIGHT_CONTROLLER, select the data flow label CHANGE . 6. Click Tools>Data Dictionary. 7. Click the Design Attributes... button.

8. Select Its Task and click Choose...

38

Rhapsody in MicroC

Review

9. The Choose window opens.

10. Click TRAFFIC_LIGHT. 11. Click OK in the Design Attribute window. 12. Click Save in the Data Dictionary Editor and File>Exit .

Re vi ew
In this lesson, you have learned to use the Data Dictionary to define elements and attributes. You have learned that textual elements can be: Events, Conditions, Data-Items, or Information-Flows. You have also learned how to define design attributes such as Regular, Task, or ISR types.

You are now ready to proceed to Lesson 4...

Rhapsody in MicroC

39

Defining Elements and Attributes

40

Rhapsody in MicroC

Creating Statecharts
Lesson
Goa l f or t hi s Le ss on

In this lesson you will learn how to create a Statechart, which represents the Behavioral View of a system. It consists of the following elements: States Transitions Represent the states the functions can be in within the system. Show the paths the system can take to get from one state to another.

The finished Statechart will look like this:

Use the illustration as a guide as you draw your own chart.

Rhapsody in MicroC

41

Creating Statecharts

Step 1. Cre a ti ng a S t a te c ha rt
1. Open the activity chart TRAFFIC_LIGHT_CONTROLLER . 2. Select the state TRAFFIC_LIGHT_CTRL .

3. Click File>Create Sub-Chart.

4. Select Statechart and click OK .

5. The graphic editor opens with the basic state TRAFFIC_LIGHT_CTRL already drawn. You can develop the statechart from this starting point.

42

Rhapsody in MicroC

Goal for this Lesson

Speed Buttons

~ Graphics Drawing Area ~

Drawing Element Buttons

Message Area

Help Information Area

Step 2. Dra wi ng S t a te s
1. Move the name TRAFFIC_LIGHT_CTRL to the top, right-hand corner of the state. 2. Select the Create State icon from the Statechart graphic editor.

Rhapsody in MicroC

43

Creating Statecharts

3. Draw and name three additional states: RED , GREEN , and YELLOW as shown.

The technique for drawing states is the same as that for activities. Place the cursor at the desired location of the upper, left hand corner, click and hold the left mouse button, and drag the cursor (+) to the lower, right hand corner. Release the mouse button and the outline of the state becomes solid.

The technique for naming states is also the same as that for activities. Type the state name in uppercase or lowercase.

Move the name to the desired location inside the state box. Click the left mouse button.

44

Rhapsody in MicroC

Goal for this Lesson

Step 3. Dra wi ng T ra nsi t ions


1. Select the Create Transition icon from the Statechart graphic editor. 2. Draw a transition from RED to GREEN . The technique for drawing transitions is the same as that for data flows. Place the cursor (+) on the right edge of the RED box and click the left mouse button. Move the cursor to the right edge of the GREEN box and click the middle button. The transition arrow becomes solid.
To draw straight horizontal or vertical lines, hold down the Shift key while moving the cursor. You can click the left mouse button several times to mark corners on the way to the destination.

Step 4. La bel li ng Tr an si ti ons


1. Label the transition from RED to GREEN as follows:
CHANGE/GREEN_LIGHT:=TRUE; RED_LIGHT:=FALSE

The syntax of a transition label is trigger/action . In this case, the trigger is the CHANGE event. The action consists of two statements that assign values to the conditions GREEN_LIGHT and RED_LIGHT.

Rhapsody in MicroC

45

Creating Statecharts

The technique for labelling transitions is also the same as that for data flows. While the Create Transition mode is still active: Type the transition label. Press the Enter key to continue on a new line. Position the crosshair (+) just touching the line. Click the left mouse button to associate the label with the transition. The label changes to uppercase.
To adjust the position of a label, place the cursor over it, hold down the middle mouse button, move the label, and release the button.

2. Draw and label two additional transitions as shown:

GREEN to YELLOW CHANGE/YELLOW_LIGHT:=TRUE;


GREEN_LIGHT:=FALSE

YELLOW to RED

CHANGE/RED_LIGHT:=TRUE; YELLOW_LIGHT:=FALSE

46

Rhapsody in MicroC

Review

Step 5. Dra wi ng t he D ef a ult T ra nsi t ion


1. Select the Create Default Transition icon from the Statechart graphic editor. 2. Draw and label the default transition as shown.
/RED_LIGHT:=true; GREEN_LIGHT:=false; YELLOW_LIGHT:=false

Step 6. Che ck in g Y our Mode l


Select Tools>Check Model. You should see the following message at the bottom of the screen. If not, go back and check your work.

Re vi ew
In this lesson, you learned how to create a Statechart, which represents the Behavioral View of a system. It consists of States that represent the states the functions can be in within the system, and Transitions that show the paths the system can take to get from one state to another.

You are now ready to proceed to Lesson 5...


Rhapsody in MicroC 47

Creating Statecharts

48

Rhapsody in MicroC

Creating Panels
Lesson
Goa l s fo r t hi s Les s on:

In this lesson you will create a panel, which is a graphical user interface for testing your design. You will: Create a new panel Draw interactors Bind Panel Elements to Model Elements The finished panel will look like this:

Use the illustration as a guide as you draw your own panel.

Rhapsody in MicroC

49

Creating Panels

Step 1. Cre a ti ng a P a ne l
1. Click the Panel Editor icon in the Main Window of Rhapsody in MicroC.

2. The Open Panel window appears. Enter the Panel Name LIGHT_CTRL_PNL and click OK.

3. The Panel Graphic Editor opens.

50

Rhapsody in MicroC

Goals for this Lesson:

Speed Buttons

Drawing Element Buttons

~ G raphics Drawing Area ~

Message Area

Help Information Area

Step 2. Dra wi ng a Pus hbut t on Int e ra ct or


1. Select the Pushbutton icon from the Panel Graphic Editor. 2. The technique for drawing a pushbutton is the same as that for an activity or state. Place the cursor at the desired location of the upper, left hand corner, click and hold the left mouse button, and drag the cursor (+) to the lower, right hand corner.
Rhapsody in MicroC 51

Creating Panels

3. While the Create Pushbutton mode is still active, type the label and move it to the desired location inside the pushbutton box. Click the left mouse button. The name becomes associated with the interactor in which it resides.
Note that interactor labels (unlike other labels) do not automatically change to uppercase. They retain the case in which they are typed.

Step 3. Dra wi ng L am p I nt er ac t ors


1. Select the Lamp icon from the Panel Graphic Editor. 2. Draw a Lamp interactor to the left of the Pushbutton. There is no need to label the Lamp.

3. Draw two more Lamp interactors under the first one. You can use Edit>Copy and Edit>Paste to duplicate the first Lamp. 4. Draw a rectangle around the Lamps.

52

Rhapsody in MicroC

Goals for this Lesson:

5. Select the top Lamp interactor and click Tools>Properties... 6. The Bindings/Properties window appears.

7. Select Highlight Color and click Choose... The Color Viewer window opens. 8. Select RED from the list and click OK . 9. Select the bottom Lamp interactor and set the Highlight Color to GREEN .

Rhapsody in MicroC

53

Creating Panels

Step 4. Bind ing to Mode l El em en ts


1. Select the Pushbutton interactor. 2. Click Tools>Bind . 3. The Bindings/Properties window opens.

Note that the Bind Method is set to Input by default.

4. Select Controlled by and click Choose...

54

Rhapsody in MicroC

Goals for this Lesson:

5. The Element Selection for Panel window appears.

The Element Selection window is very similar to the Data Dictionary Browser in that you can create lists of elements to choose from.

6. Select CHANGE in the element list and click OK . The Pushbutton is now bound to the event and thus will cause CHANGE to occur whenever pushed. 7. Bind the three Lamp interactors (from the top down) to the conditions RED_LIGHT, YELLOW_LIGHT, and GREEN_LIGHT.

Rhapsody in MicroC

55

Creating Panels

8. Click Tools>Check Bindings to check your work.

Re vi ew
In this lesson, you have learned how to use the Panel Graphics Editor (PGE) to create a panel for your design. The PGE is a very important tool because it can be used to give you a virtual interface into your application. It can be set up to provide ways to input data and displays the results of program operation. The layout of your panel can emulate your targets interface or provide additional features useful for development and debugging of your application.

You are now ready to proceed to Lesson 6...

56

Rhapsody in MicroC

Executing the Model


Lesson
Goa l f or t hi s Le ss on:

In this lesson you will execute the Traffic Light model you just designed. You will: create a Code Generation Profile set up the correct properties for your code generate, link, and compile the code run the executable image
You need to have Microsoft Visual C++ 5.0 or later installed.

Rhapsody in MicroC

57

Executing the Model

Step 1. Cre a ti ng a C ode Ge ne ra t ion Pr of ile


1. In the main window of Rhapsody in MicroC, click on the Micro C Code Generation icon.

2. The New Compilation Profile window opens. 3. Type in a profile name (such as TEST01) and click OK .

4. The Code Generation Profile Editor opens.

58

Rhapsody in MicroC

Goal for this Lesson:

Step 2. Cre a ti ng a Mo dule


1. Click on the MOD icon. The Create Module window opens.

2. Enter TRAFFIC_LIGHT and click OK .

3. The Code Generation Profile now contains a Module.

Step 3. Addi ng Cha rt s t o the Module


1. Click the Connect to Workarea Browser icon.

2. The Workarea Browser opens. 3. Select the top level activity chart TAIL_LIGHT_ CONTROLLER .

Rhapsody in MicroC

59

Executing the Model

4. Return to the Profile window and click the Module TAIL_LIGHT, so it is highlighted. 5. Click the Add Selected Chart to Selected Module icon.

6. The charts are added to the profile.

Step 4. Addi ng a P a nel t o t he Mo dule


1. In the Workarea Browser, select the panel from the list of files.

2. In the Code Generation Profile, click on the Add Selected Panel icon. 3. The panel is added to the profile.

60

Rhapsody in MicroC

Goal for this Lesson:

Step 5. Se t t ing t he Ta rge t Conf ig ura t ion


1. Click the Options>Target Configuration menu item in the Profile editor window. 2. In the Target Configuration dialog, select MAINLOOP_SC_NT. 3. Click OK.

Step 6. Ge ne ra t ing Code


1. Click the Generate Code for Current Profile icon in the Profile Editor window.

2. The Output Directory window opens. 3. Select OK to accept the default directory.

Rhapsody in MicroC

61

Executing the Model

4. The Generate Code for Profile dialog appears and the code is generated. 5. Click Dismiss to close the dialog.

Step 7. Com pili ng t he G e ne ra te d Code


1. Click the Compile Generated Code icon in the Code Generation Profile Editor window. 2. The Selected Makefile dialog opens. 3. Click Open to accept the default makefile.

62

Rhapsody in MicroC

Goal for this Lesson:

4. A Command Prompt window appears as the code is compiled and linked.

5. Type exit to close the window.

Rhapsody in MicroC

63

Executing the Model

Step 8. Runni ng t he E x ec ut a ble I ma ge


1. Click Tools>Open GBA to start the GBA (Graphical Back Animation) server. You can minimize this window or select charts to animate. 2. Click the Execute Compiled Code icon in the Code Generation Profile Editor window. 3. The Run Command dialog appears. 4. Click Open . 5. A Command Prompt window appears. 6. Wait for the executable to start. (It may not start immediately.) 7. Click the CHANGE button and watch the Traffic Light.

64

Rhapsody in MicroC

Review

8. To end the run, simply close the panel. 9. The GBA server prints this error message. Click OK .

Re vi ew
In this lesson, you learned how to: create a Code Generation Profile set up the correct properties for your code generate, link, and compile the code run the executable image

You are now ready to proceed to Lesson 7...

Rhapsody in MicroC

65

Executing the Model

66

Rhapsody in MicroC

Using the Test Driver


Lesson
Goa l f or t hi s Le ss on

In this lesson, you will learn how to test the dynamic behavior of the developed application non-interactively, using test vector inputs and outputs. You will: Generate Test Vectors. Stream the inputs and outputs to disk for post analysis. Reuse Test Vectors for subsequent simulations.

Step 1. En abl e t he Te st Driv e r


1. Stop any executing models by closing the Panel window. 2. If it is not already running, start the GBA server. 3. Open the Compilation Profile. 4. Click Options>Settings... 5. The Properties for Code Generation dialog opens. 6. Click the Test Driver tab. 7. Click Enable and OK .

Rhapsody in MicroC

67

Using the Test Driver

Step 2. Vi ew S t re a min g V ec t or Da ta
1. Regenerate and recompile the code. 2. Run the model. 3. Press the CHANGE button and watch the Command Prompt window to see the Test Driver stream the data to the standard output.

4. Stop the model.

Step 3. Cre a te T es t V e ct or Fil es


1. Use a text editor such as Notepad to create the following batch file named dos_box.bat in the working directory (as shown in the Command Prompt window above.)

Setting these environment variables redirects the standard input and output to files, making it possible to post-process the results.

68

Rhapsody in MicroC

Goal for this Lesson

2. Run the model. 3. The Run Command dialog opens. 4. Select dos_box.bat and Click Open .

5. A Command Prompt window opens.

6. Type the name of the executable image (in this case, test01.exe ). 7. Once the model is running, click the CHANGE button several times to ensure that the Test Driver gets some data. 8. Stop the model.

Rhapsody in MicroC

69

Using the Test Driver

9. Test Vector files have been created in the working directory (see the Command Prompt window above).

The files are both of a similar format and are explained in the following table.
Time Absolute or Relative. Default is Absolute. Variable Name Variable Type As in Data Dictionary. See table below. Variable Value Comments The new value it is set to. As shown in file.

Data Type INTEGER_DATA_ITEM REAL_DATA_ITEM BIT BIT_ARRAY STRING_DATA_ITEM CONDITION

Identifier 0 1 2 3 4 5

70

Rhapsody in MicroC

Goal for this Lesson

EVENT STATE ACTIVITY ENUM_DATA_ITEM

6 7 8 9

Step 4. Run the Mode l Us in g a Te s t Ve c t or


1. Edit dos_box.bat and enable the line that was commented out.

2. Rename the file TESTDRIVER_INPUT_FROM_PNL_FILE.txt to TESTDRIVER_IN_FILE.txt . 3. Edit TESTDRIVER_IN_FILE.txt and modify the header (the first line) as shown.

4. Run the executable model as before but do not press the CHANGE button ! The Test Driver will use TESTDRIVER_IN_FILE.txt to stimulate the model. The output will be streamed to disk as before.

Rhapsody in MicroC

71

Using the Test Driver

Re vi ew
You have now used a test vector to automate your code testing. The inputs and outputs are all recorded for post processing. This feature greatly improves the testing of embedded applications.

Congratulations! You just finished your first design!

72

Rhapsody in MicroC

Index

A
activities, 33 ISR, 33 regular, 34 task, 33 Activity Chart, 23 advanced training,

E
edge trigger, 33 embedded system development,

16

16

F
functional decomposition,

B
Binding panel elements, Boolean, 33

23

G
54
Generate Code, Graphic Editors,

61 , 62 25

C
Code Generation Profile, Compilation Profile, 67 Control Activities, 28

I
57 , 65
impulse,

33

D
Data Dictionary, 16 Data Dictionary Browser, 34 Data Dictionary Editor, 35 David Harel, 15 drawing activities, 27 drawing control activities, 28

L
level trigger,

33

M
Microsoft Visual C++, 16 , 57 Modeling Reactive Systems with Statecharts, 15 Module Name, 59

Statemate MAGNUM

73

mouse buttons,

17

O
online help, 24 Help>on Help,

drawing transitions, 45 graphic editor, 43 , 51, 52 States, 41 Transitions, 41 Statemate MAGNUM Methodology and Style Guidelines,

15

24

P
panel, 49 Panel Graphic Editor, 50 project new, 20 , 22 proprietary information, ii

T
textual elements, 33 condition, 33 data-item, 33 event, 33 information-flow, 33 top level chart, 23 trademarks, ii

S
Statechart creating, Statecharts

W
41
Workarea Browser,

59

74

Statemate MAGNUM

You might also like