3 <title>UCSIM: Serial Interafces</title>
8 <h1>Using serial interfaces</h1>
10 <h3>Connecting a terminal</h3>
12 You can easily connect a terminal to the serial interface of the
13 simulated microcontroller. This terminal is just a file so it can be
14 anything which is represented as a file. It can be a real serial line
18 <font color="blue">$</font> s51 -s/dev/ttyS1
21 Of course you must use the actual device name of your operating
22 system. Device name <tt>ttyS1</tt> above is used in Linux
23 systems. Your system can use other names.
25 <p>You can use a terminal of your system. It can be a virtual console
26 if your system provides such as Linux does for example. On X Windows
27 you can use <b>xterm</b> windows as terminals, one for running the
28 simulator and one as a terminal on CPU's serial line. Here is a sample
31 <ol><li>Prepare the terminal window which will be connected to the
34 <p><ul><li>Check the device name which represents the terminal:
37 <font color="blue">$</font> tty
38 <font color="green">/dev/ttyp1</font>
41 <li>Disconnect the shell from the terminal. Usualy I use the
42 <b>tail</b> command and any existing text file:
45 <font color="blue">$</font> tail -f $HOME/.profile
50 <li>Run the simulator in the other window:
53 <font color="blue">$</font> s51 -s/dev/ttyp1 program.hex
56 Use the output of the <b>tty</b> command above as the parameter of the
61 Every character sent out by the simulated program
62 appears in the "terminal" window and every charater you type in there
63 will be received by the simulated controller's serial line.
66 <h3>Connecting two instances of simulator</h3>
68 Executing two instances of the simulator, serial lines of two
69 simulators (micros) can be connected together so they can talk to
70 each other over their serial interface. It is because you can specify
71 separate files for serial input and output. For example you run two
72 simulators "1" and "2", here is the sample how to connect them:
74 <p><img src="serial1.gif">
76 <ol><li>Make two FIFOs to represent physical wires in serial cable
77 connecting two micros:
80 <font color="blue">$</font> mkfifo 1-2 2-1 <font color="magenta"># 1-2: 1->2 and 2-1: 2->1</font>
83 <li>Start two simulators and specify the FIFOs as input and output of
87 <font color="blue">term1 $</font> <font color="magenta"># start sim "1"</font>
88 <font color="blue">term1 $</font> s51 -Sin=2-1,out=1-2 program_1_.hex
89 <font color="blue">term2 $</font> <font color="magenta"># start sim "2"</font>
90 <font color="blue">term2 $</font> s51 -Sout=2-1,in=1-2 program_2_.hex
93 Because opening a pipe blocks the program until other direction is
94 opened, the order of arguments above is <b>important</b>!
98 <li>Debug programs as usual.
102 Using the most usefull unix commands <b>cat</b> and <b>tee</b> and
103 just some more FIFOs you can monitor serial communication, here is a
106 <p><img src="serial2.gif">
108 <ol><li>Make some FIFOs to use between simulators and tee "monitors":
111 <font color="blue">$</font> mkfifo 1_tee tee_2 2_tee tee_2
114 <li>Run monitoring programs (in two xterms for example):
117 <font color="blue">xterm1 $</font> cat 1_tee|tee /dev/tty >tee_2 # monitor 1->2
118 <font color="blue">xterm2 $</font> cat 2_tee|tee /dev/tty >tee_1 # monitor 2->1
121 <li>Now you can start simulators (on two other terminals:)
124 <font color="blue">xterm3 $</font> s51 -Sin=tee_1,out=1_tee program_1_.hex
125 <font color="blue">xterm4 $</font> s51 -Sin=tee_2,out=2_tee program_2_.hex
128 <li>Start your apps and listen what they are talking about.