1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-2">
<title>µCsim: Serial Interfaces</title>
</head>
<body style="background-color: white;">
<h1>Using serial interfaces</h1>
<h3>Connecting a terminal</h3>
You can easily connect a terminal to the serial interface of the simulated
microcontroller. This terminal is just a file so it can be anything which is
represented as a file. It even can be a real serial line of the computer:
<pre><font color="blue">$</font> ucsim_51 -s/dev/ttyS1
</pre>
<p><img src="serial_comport.svg"></p>
<p>Of course you must use the actual device name of your operating system.
Device name <tt>ttyS1</tt> above is used in Linux systems. Your system
can use other names. </p>
<p>You can use a terminal of your system. It can be a virtual console if
your system provides such as Linux does for example. On X Windows you can
use <b>xterm</b> windows as terminals, one for running the simulator and
one as a terminal on CPU's serial line. Here is a sample how to do this: </p>
<ol>
<li>Prepare the terminal window which will be connected to the serial
line:
<p></p>
<ul>
<li>Check the device name which represents the terminal:
<pre><font color="blue">$</font> tty
<font color="green">/dev/ttyp1</font>
</pre> </li>
<li>Disconnect the shell from the terminal. Usually I use the <b>tail</b>
command and any existing text file:
<pre><font color="blue">$</font> tail -f $HOME/.profile
</pre> </li>
</ul>
</li>
<li>Run the simulator in the other window:
<pre><font color="blue">$</font> ucsim_51 -s/dev/ttyp1 program.hex
</pre> Use the output of the <b>tty</b> command above as the parameter of the <tt>-s</tt>
option. </li>
</ol>
<p> Every character sent out by the simulated program appears in the
"terminal" window and every character you type in there will be received
by the simulated controller's serial line.</p>
<p><b><i>Notes</i></b></p>
<p>-s option is deprecated, it is recommended to use -S instead. Option -S
provides more features and flexibility but it requires to use different
syntax:</p>
<p>-S subopt1,subopt2,...</p>
<p>Known suboptions are:</p>
<ul>
<li>uart=nr<br>
This option specifies ID of the uart that following options will be
attached to. Default is 0.</li>
<li>in=filename<br>
Specified file will be used as input for the uart. When simulated uart
is able to receive, it will get content of this file.</li>
<li>out=filename<br>
Specified file will be used as output for the uart. When simulated uart
sends a byte, it will be written into this file.</li>
<li>port=nr<br>
Specified port number will be listened for incoming connections (TCP
server) and if connected, the socket will be used as both input and
output for the uart.</li>
<li>iport=nr<br>
Specified port number will be listened for incoming connections (TCP
server) and if connected, the socket will be used as input of the uart.</li>
<li>oport=nr<br>
Specified port number will be listened for incoming connections (TCP
server) and if connected, the socket will be used as output of the uart.</li>
<li>raw<br>
Raw, non-interactive communication will be performed on both input and
output files. Default is interactive (non-raw) mode.</li>
</ul>
Input and output file can be a regular file or a special one, for example
pipe (fifo) or a TCP socket. If a file is a tty, the simulator will assume
that a terminal is connected and will start an interactive session. TCP
socket is treated as a tty, and telnet protocol is used to control the
terminal settings. This can be turned off by <b>raw</b> suboption. If <b>raw</b>
is used, simulator will not perform any terminal control and will not
use/interpret telnet protocol commands.<br>
<br>
<h3>Connecting two instances of simulator</h3>
Executing two instances of the simulator, serial lines of two simulators
(micros) can be connected together so they can talk to each other over their
serial interface. It is because you can specify separate files for serial
input and output. For example, you run two simulators "1" and "2", here is
the sample how to connect them:
<p><img src="serial1.svg"> </p>
<ol>
<li>Make two FIFOs to represent physical wires in serial cable connecting
two micros:
<pre><font color="blue">$</font> mkfifo 1-2 2-1 <font color="magenta"># 1-2: 1->2 and 2-1: 2->1</font>
</pre> </li>
<li>Start two simulators and specify the FIFOs as input and output of
serial interface:
<pre><font color="blue">term1 $</font> <font color="magenta"># start sim "1"</font>
<font color="blue">term1 $</font> ucsim_51 -Sin=2-1,out=1-2,raw program_1_.hex
<font color="blue">term2 $</font> <font color="magenta"># start sim "2"</font>
<font color="blue">term2 $</font> ucsim_51 -Sout=2-1,in=1-2,raw program_2_.hex
</pre> Because opening a pipe blocks the program until other direction is
opened, the order of arguments above is <b>important</b>!
<p> </p>
</li>
<li>Debug programs as usual. </li>
</ol>
Using the most useful unix commands <b>cat</b> and <b>tee</b> and just
some more FIFOs you can monitor serial communication, here is a sample:
<p><img src="serial2.svg"> </p>
<ol>
<li>Make some FIFOs to use between simulators and tee "monitors":
<pre><font color="blue">$</font> mkfifo 1_tee tee_2 2_tee tee_2
</pre> </li>
<li>Run monitoring programs (in two xterms for example):
<pre><font color="blue">xterm1 $</font> cat 1_tee|tee /dev/tty >tee_2 # monitor 1->2
<font color="blue">xterm2 $</font> cat 2_tee|tee /dev/tty >tee_1 # monitor 2->1
</pre> </li>
<li>Now you can start simulators (on two other terminals:)
<pre><font color="blue">xterm3 $</font> ucsim_51 -Sin=tee_1,out=1_tee,raw program_1_.hex
<font color="blue">xterm4 $</font> ucsim_51 -Sin=tee_2,out=2_tee,raw program_2_.hex
</pre> </li>
<li>Start your apps and listen what they are talking about. </li>
</ol>
<hr>
</body>
</html>
|