10 I/O SIMULATION

This chapter contains the following sections:

Introduction
I/O Streams
Setting Up File I/O Streams
Redirecting I/O Streams
File System Simulation
File System Simulation Libraries
Debug Instrument I/O
The Terminal Window

Terminal Window Keyboard Mappings

10.1 Introduction

The CrossView Pro Terminal windows provide an interface to exchange data with the application on the target. You can use the following I/O simulation types for this purpose.

File System Simulation (FSS)

With FSS you can use standard stream I/O function calls like printf() in your source, to test I/O to and from the target system or simulator.

File I/O (FIO)

With File I/O you can connect actions to a probe point. Probe points are breakpoints that do no update the graphical user interface (GUI) and when they are hit, connected actions are performed and execution continues. The actions are in this case I/O actions to a file and/or a terminal window.

Debug Instrument I/O (DIO)

If you have a debug instrument that supports it, the debug instrument can perform input and output using GDI callback functions.

10.2 I/O Streams

You can setup I/O streams with the I/O Simulation Setup dialog. There is virtually no limit on the number of streams that can be opened or created. Each type of I/O stream (FSS, DIO, FIO) has its own numbering:

FSS 0,1,2,...,k
DIO 0,1,2,...,m
FIO 0,1,2,...,n

You can map multiple streams to one terminal window.

For File I/O you can use the ios_ commands to open or close a FIO stream on the command line. Streams can be opened manually or are opened at the first call or operation that accesses a specified I/O stream (for Debug Instrument I/O handling). For FSS the target application can open or close streams with fopen(), open(), fclose() or close() calls.

Streams can be mapped to a terminal window and/or a file that is NOT the terminal log file. If a stream is mapped to a terminal window and a file the output will go to the terminal window and also to the file. In case of input the input will be read from the file. The read input will be echoed on the connected terminal window.

I/O streams opened by FSS are closed when end of program is reached or if a program reset occurs. I/O streams opened by CrossView Pro will be rewound. The windows to which the streams are mapped remain open.

In the I/O Simulation Setup dialog you can connect an I/O stream to a terminal window before the stream is opened by specifying the stream type, filename and terminal window name.

10.2.1 Setting Up File I/O Streams

You can set up an input or output stream. For input you may specify either a file or the keyboard, for output either a file or the screen. Each stream has its own identifying number.

You can also specify the format of the stream's values. The default is character, but you may want to use hexadecimal or octal values when directing data to or from a file.

To setup a File I/O stream:

From the menu system:

Enter the ios_open or ios_wopen command in the Command Window to open a File I/O stream.

FUNCTION: Open a File I/O stream

COMMAND: ios_open ["file"[,[ mode][,[r][,$xvw_variable]]]]

FUNCTION: Open a File I/O stream and map the stream to a terminal window

COMMAND: ios_wopen [["terminal_window"][,$xvw_variable]]

Enter the ios_read or ios_write command in the Command Window to read from or write to a File I/O stream.

FUNCTION: Read from a File I/O stream

COMMAND: ios_read {stream | "file"},address,number_of_maus[,x]

FUNCTION: Write to a File I/O stream

COMMAND: ios_write {stream | "file"},address,number_of_maus[,x]

To read 1 MAU hexadecimal value from file mydata.dat and store it at address 0x100, type:

10.2.2 Redirecting I/O Streams

In the I/O Simulation Setup dialog you can connnect an I/O stream to a terminal window before the stream is opened or you can redirect an existing stream to a file and/or terminal window.

To redirect an I/O stream to a file and/or terminal window:

From the menu system:

Enter the ios_open or ios_wopen command in the Command Window to open a File I/O stream.

To disconnect an I/O stream from a file and/or terminal window:

From the menu system:

Enter the ios_close command in the Command Window to close a File I/O stream.

FUNCTION: Close a File I/O stream

COMMAND: ios_close {stream | "file"}

To disable/enable an I/O stream:

From the menu system:

Disabling a File I/O stream means that I/O actions will not be honored. Writing is not passed to the output file, and reading does not result in new data being placed in the target buffer.

10.3 File System Simulation

File system simulation enables the application on the target board to use system calls (such as open, read, write) that are handled by the host system file I/O services. These files can be read directly from the host system, and output can be written to a file on the host system or in a CrossView Pro window. File system simulation is available for all execution environments.

The File System Simulation feature redirects I/O to a Terminal Window if the filename FSS_window:window_name is used in the "open" call, window_name is the name of a Terminal Window.

You can specify a root directory for FSS. CrossView Pro will search for the file from the root directory downwards. You can do this in the I/O Simulation Setup dialog, by entering a directory name in the FSS root directory field of the Options tab. This setting is saved in the xvw.ini file. Another possibility is to set a temporary resource by specifying the command line option --fss_root_dir="path" on CrossView Pro startup.

The libraries have been optimized to only attach the file I/O routines if the application actually uses file I/O. This includes the exit() routine, that must close all opened streams before returning to the debugger. The default I/O streams stdin, stdout and stderr are opened on the fly whenever file I/O is used; this behavior is transparent to the user. It is no longer necessary to inform CrossView Pro about the use of any streams.

You can redirect File System Simulation streams to a file or another stream. Redirection to a file can be needed when a stream is only mapped to a window and you want it to be mapped to a file also.

Redirection can be used for scripting purposes, using the FSS command.

FSS { < | > }{&stream | "file"}

For example,

The first example will redirect output of stream 2 to stream 1. The second example will retrieve input for stream 1 from stream 4. The third example will retrieve input for stream 4 from file "data.txt". The fourth example will redirect output of stream 3 to file "data.txt".

Disabling an FSS stream means in effect connecting the stream to /dev/null or NUL, causing writes to go into oblivion, and reads to return EOF.

10.3.1 File System Simulation Libraries

The functions _read() and _write() of the C library are modified to use File System Simulation. This redirects all high-level I/O calls such as printf() and scanf() type functions through CrossView Pro's FSS feature, allowing you to perform stdin, stdout and stderr I/O by just using these standard C library functions.

For more information see the section C Library Interface Description in the C Cross-Compiler User's Guide.

10.4 Debug Instrument I/O

If you have a debug instrument that supports it, the debug instrument can perform input and output using GDI callback functions. The Debug Instrument I/O (DIO) stream number is passed as parameter to these callbacks. The output can be redirected to DDE (Windows only). The first access to a DIO stream will create a new terminal window and the title of the window will be "DIO x", where x is is the number of the used stream. No new window will be created if the used stream is already mapped to a terminal window. You can use the I/O Streams Terminal Map dialog to map one or more streams to one window.

10.5 The Terminal Window

If you direct I/O simulation to the screen, CrossView Pro displays the output in the terminal window. Similarly, if you direct input from the keyboard; whatever you input appears in the appropriate terminal window. See section 4.6.8, Terminal Window for more information.

10.5.1 Terminal Window Keyboard Mappings

The following keyboard mappings, being both control codes and escape sequences, are supported by the VT100-like terminal mode of the terminal windows:

Key Character Sequence and/or Decimal Value
Backspace 8d
TAB 9d
DEL 127d
ESC 27d
Insert ESC [ 2 ~
Prev/Page Up ESC [ 5 ~
Next/Page Down ESC [ 6 ~
Arrow Up ESC [ A
Arrow Right ESC [ B
Arrow Left ESC [ C
Arrow Down ESC [ D

Table 10-1: General Keyboard Mappings

Display Control

The VT100-like terminal mode of the terminal windows comprises the following control codes and escape sequences for displaying:

ASCII Code Decimal Value Operation
BELL 7 Ring the bell
BS 8 Move cursor one position back
TAB 9 Move cursor to next tab stop
LF 10 Move cursor one line down
CR 13 Move cursor to start of line
ESC 27 Start escape sequence (see below)

Table 10-2: Control Codes

Escape Sequences

Escape Sequence Operation
ESC D Cursor one line down (scrolls if already at last line)
ESC E Cursor one line down and to left margin (scrolls)
ESC M Cursor one line up (scrolls if already at top line)
ESC [ n1 A Cursor n1 lines up
ESC [ n1 B Cursor n1 characters right
ESC [ n1 C Cursor n1 characters left
ESC [ n1 D Cursor n1 lines down
ESC [ H Cursor home
ESC [ n1 ; n2 H Move cursor to (n1,n2) with n1=row, n2=col

Table 10-3: Cursor Motion

Parameters n1 and/or n2 may be left out, in which case a value of 1 is assumed.

Escape Sequence Operation
ESC [ J Clear screen from cursor till bottom-right
ESC [ p1 J 0: Clear screen from cursor till bottom-right 1: Clear screen from top-left till cursor 2: Clear entire screen
ESC [ K Clear line from cursor till end
ESC [ p1 K 0: Clear line from cursor till end 1: Clear line from begin to cursor 2: Clear entire line

Table 10-4: Erasing

For example, to clear the entire screen in the C programming language, you can enter:

Escape Sequence Operation
ESC [ n1 @ Insert characters
ESC [ n1 P Delete n1 characters
ESC [ n1 L Insert n1 lines
ESC [ n1 M Delete n1 lines

Table 10-5: Inserting and Deleting

Parameter n1 may be left out, in which case a value of 1 is assumed.

Escape Sequence Operation
ESC [ m Turn off all attributes
ESC [ n1 m 0: turn off all attributes 1: bold 4: underline 5: blinking 7: reverse 8: invisible 22: turn off bold 24: turn off underline 25: turn off blinking 27: turn off reverse 28: turn off invisible

Table 10-6: Character Attributes

Multiple parameters may be specified simultaneously:

Some attributes or combinations of attributes are mapped to a regular standout mode.

Parameters may be left out, in which case a value of 0 is assumed.

Escape Sequence Operation
ESC [ 12 l Local echo on
ESC [ 12 h Local echo off
ESC [ ? 7 h Wrap around on
ESC [ ? 7 l Wrap around off
ESC [ ? 25 h Cursor on
ESC [ ? 25 l Cursor off
ESC [ ? 92 l Enquire after the window's size
Response:
ESC [ ? rows, columns c

Table 10-7: Miscellaneous


Copyright © 2002 Altium BV