Table of Contents Previous Chapter 32 The Simulator

32 dThe Simulator

Target Simulation

Overview

A simulation program communicates with the SDT tools via the SDT communication mechanism (The SDT PostMaster). By using some special features in SDT, it is possible to run the simulation program on a target system, while the SDT tools and the PostMaster run on a host system separate from the target system. This set-up is known as target simulation.

The simulation program running on the target system must be built using a special library that includes a communication interface to the host system. On the host system, the simulation program is replaced by a gateway, a program that communicates with the simulation program on the target system. The host and target communicate via a standard RS-232C connection using a simple protocol. Figure 541 shows the set-up for target simulation.

Figure 541 : Target Simulation Set-up. 
-----
(fig)  
       
-----
Target simulation can be valuable in the following situations:

The rest of this section will explain how to use target simulation, concentrating on the following system set-up:

Example code for this set-up can be found in the subdirectories to $sdtrelease/examples/tarsim.

-----------------------------------------------------------------------
Caution!                                                                 
The following description of target simulation is not to be consid       
ered as generally applicable. The source code is provided "As is"        
and is intended to be used for the set-up described above. This set-     
up was chosen as a typical example of when target simulation may         
be useful. The use of target simulation for other set-ups is not docu    
mented.                                                                  
There is no commitment from Telelogic to support the example in          
this section. Telelogic has used the example in internal projects with   
successful results.                                                      
-----------------------------------------------------------------------

Building the Tools

This subsection describes how to build the tools necessary for target simulation, i.e., the gateway on the host and the simulator on the target.

----------------------------------------------------------------
Note:                                                             
The target simulator can only be built by customers who have pur  
chased the Master Library.                                        
----------------------------------------------------------------

Building the Gateway on the Host

Instead of starting a normal simulator on the host system, you have to start a gateway program called sdtatgate. The gateway acts just like a simulator to the other SDT tools. The gateway communicates with the actual simulator on the target system and forwards all SDT messages to and from the simulator monitor.

The source code needed to build the gateway can be found in the directory $sdtrelease/examples/tarsim/gate. This directory also includes an already built executable for a SPARC system. To build the gateway for other UNIX platforms, use the provided UNIX makefile. In addition to the provided source code, the SDT library post.o and the SDT header files in $sdtdir/INCLUDE are used to build the gateway.

When building the gateway, the following compilation switches are recognized. If used, they should be included in the makefile in -D statements to the C compiler.

-----------------------------------------------------------------
Switch        Behavior if switch is defined                        
-----------------------------------------------------------------
XNOPROTO      Function prototypes according to ANSI-C are not      
              used. (Should be defined for non-ANSI C compil       
              ers.)                                                
XNO_STDARG_H  Functions with variable number of parameters are     
              handled according to the non-ANSI standard           
              (varargs.h). (Should be defined for non-ANSI C       
              compilers.)                                          
SENDSYNC      The gateway will send "OK\r" to try to sync with     
              the target. (Should always be defined on the host    
              system.)                                             
ANSWER        Return codes from functions for sending PostMas      
              ter messages from the simulator are propagated       
              back to the target. If not defined, all PostMaster   
              messages from the simulator are assumed to be        
              received correctly by the PostMaster on the host.    
              Also see the subsection "Message Format" on          
              page 1877.                                           
-----------------------------------------------------------------

Building the Simulator on the Target

To build a simulator on the target system, you need the following:

To build a simulator on a PC system, proceed as follows:

  1. Generate the simulation source code on a UNIX system that includes the C Code Generator:
  2. Copy the following source code from a UNIX system to a single directory on the PC system:
  3. On the PC system, build the complete simulator by using the provided Borland C makefile and/or project file. These files are example files for a simulator called "demon" and should be edited to suit your particular system.
When building the simulator on the PC system, the following compilation switches are recognized:

--------------------------------------------------------------------
Switch           Behavior if switch is defined                        
--------------------------------------------------------------------
IC86             Code specific to the Borland or Microsoft C          
                 compiler on PC systems is used.                      
XNOPROTO         Function prototypes according to ANSI C are          
                 not used. (Should be defined for non-ANSI C          
                 compilers.)                                          
XNO_STDARG_H     Functions with variable number of parameters         
                 are handled according to the non-ANSI stan           
                 dard (varargs.h). (Should be defined for non-        
                 ANSI C compilers.)                                   
SENDSYNC         The communication interface will send "OK\r"         
                 to try to sync with the host. (Should not be         
                 defined on the target, since this slows down the     
                 simulator.)                                          
ANSWER           Return codes from functions for sending              
                 PostMaster messages from the simulator are           
                 propagated back to the target. If not defined, all   
                 PostMaster messages from the simulator are           
                 assumed to be received correctly by the Post         
                 Master on the host. Also see the subsection          
                 "Message Format" on page 1877.                       
TARGETSIM        The <mode> parameter to the simulator is rec   
                 ognized (described below). (Should always be         
                 defined.)                                            
SCTDEBCOM
A Simulation library is used. (One of the three SCTDEBCLCOM
should always be defined.) SCTDEBCLENVCOM XCHECKALLOC Memory is checked when allocating; exit if all memory is used. XNOERRORTRACE No error messages are printed if trace is on and the connection to the host is lost. Also see the section "Executing and Terminating the Simula tion" on page 1875. --------------------------------------------------------------------

Starting the Tools

Starting the Gateway on the Host

A suitable way to start the gateway is to create a link to the gateway executable sdtatgate with the same name as the simulator. As an example, you can use the following UNIX command:

ln -s $sdtrelease/examples/tarsim/gate/sdtatgate \
DemonGame.sct
In this way, you can use the Simulator UI command from Organizer to start the simulation. The .sct file is then found and the gateway is started automatically.

Starting the Simulator on the Target

The target simulator should be started after the gateway has been started on the host system. The simulator is started with the following command line:

<simulator> -post <SPId> <mode>
where

  1. Start the simulator in the interactive monitor as usual and await monitor commands from the user.
  2. Do not start the simulator in the interactive monitor. Instead, the simulation is started immediately, as if the monitor command Go has been issued. The monitor becomes active when an error occurs, the system is completely inactive, or the user presses the Break button. Also, no trace information is printed by default in this mode (trace value is 0).
  3. As mode 2, but the execution is not stopped if the user presses <Return> or the Break button.

Executing and Terminating the Simulation

When the RS-232C connection is set up and the gateway and target simulator have been started, the target simulator can be controlled from the host in the same way as a normal simulator. Differences may be seen in execution performance and in the printing of error messages (see the compilation switches ANSWER and XNOERRORTRACE above).

The target simulator is terminated by using the monitor command Exit or Quit. Terminating the graphical user interface to the Simulator (SimUI) by using the Exit command in the File menu, or by exiting SDT, does not terminate the target simulator. Instead, the following things occur:

Communication Details

The gateway communicates with the SDT PostMaster on the host as a normal simulator would. The gateway communicates with the target simulator via an asynchronous serial channel. The provided example uses an RS-232C channel, but it should be possible to use TCP/IP or similar.

Hardware Devices

The hardware devices used for the RS-232C connection are controlled during runtime by the following environment variables:

Communication Log

The communication on the RS-232C channel may be logged by setting the environment variable SULOGLEV. On a UNIX system, the log is displayed in the terminal window from which SDT was started. The log level may be set independently on the host and on the target. The possible integer values for SULOGLEV are listed in the file sulog.h provided with the example. The default value is 2.

Message Format

Messages sent via the RS-232C connection have the following format. A single-character header indicating the type of message is packed with possible data for the message. The message type usually indicates a certain PostMaster function, and the data is usually a PostMaster message. The complete message is then coded in lowercase hexadecimal characters and is sent with a checksum in lowercase hexadecimal characters, using the format "+" <message> "-" <checksum>.

Example 55 : PostMaster Message Format  
A message consisting of the header "1" and the data "123" is sent by using the following characters:

+31313233-c7
  
A received message is always acknowledged by sending a single "Y" back.

The possible messages from target to host are:

------------------------------------------------------
Header  Data        Description                         
------------------------------------------------------
"1"     --          Call to PostMaster function SPInit  
"2"     --          Call to PostMaster function SPExit  
"3"     PostMaster  Call to PostMaster function         
        message     SPSendToTool and / or SPSendToPid   
"4"     PostMaster  Call to PostMaster function         
        message     SPBroadcast                         
------------------------------------------------------
The possible messages from host to target are:

--------------------------------------------------------------
Header  Data        Description                                 
--------------------------------------------------------------
"1"     PId         Response to target message "1".             
"1"     --          Response to target message "2".             
"5"     PostMaster  Message to simulator received from          
        message     PostMaster (unless it is a SESTOP mes       
                    sage; see below).                           
"6"     --          Connection broken. Sent by the gateway      
                    before it exits, after receiving a SESTOP   
                    message from the PostMaster.                
"0"     --          Response to target message "3" or "4",      
                    indicating no error from the PostMaster     
                    (SPOK). This is only sent if the compila    
                    tion switch ANSWER was used.                
"1"     --          Response to target message "3" or "4",      
                    indicating an error from the PostMaster     
                    (SPERROR). This is only sent if the         
                    compilation switch ANSWER was used.         
--------------------------------------------------------------
For information about PostMaster messages and functions mentioned above, see chapter 42, The SDT PostMaster, section "PostMaster Reference" on page 2484.

Source Code Files

The source code files for the gateway and the communication interface are listed below.

---------------------------------------------------------------
File       Contents                                              
---------------------------------------------------------------
satgate.c  Main program for communication between the SDT        
           PostMaster and the communication port.                
sudisp.h   Header file for sudisp.c                              
sudisp.c   Dispatcher for callback functions in satgate.c        
sp.h       Header file for sp.c                                  
sp.c       New implementation of all PostMaster functions        
           used in the Simulator library.                        
stack.c    For changing the stack size for IC86.                 
sumem.h    Header file for sumem.c                               
sumem.c    Memory management routines.                           
sat.h      Header file for satgen.c and satread.c                
satgen.c   Functions to Open, Close, Flush, Sync and Send to     
           the communication port.                               
satread.c  Functions to Poll and Read from the communication     
           port.                                                 
sattty.c   Open, set attributes and close of tty (not used for   
           IC86).                                                
sulog.h    Header file for sulog.c                               
sulog.c    Functions for error and debug logging.                
suos.h     Header file for OS dependent definitions.             
postf.c    PostMaster interface source code. Located in direc    
           tory $sdtdir/INCLUDE                                  
           This file is included in the Master Library distribu  
           tion.                                                 
---------------------------------------------------------------
This page intentionally left blank


Footnotes

(1)
If your PC supports another compiler than Borland, you may need to modify some files, such as the makefile.
 
Table of Contents Next Chapter