The terminal provides a SystemC buffer to model the Rx and a port to model the Tx pins of a serial connection. The visualization is provided by a Linux xterm running in a child process, with communication through a pseudo-TTY[5].
Two SystemC processes are used, one a method waiting for bytes from the UART in the Rx buffer, the other a thread waiting for bytes from the xterm. When bytes are received in the Rx buffer, they are written to the xterm. When bytes are received from the xterm they are written to the Tx port. The key interfaces are shown in Figure 7.3.
The difficulty is in waiting for the xterm. As described above,
reading from the pseudo-TTY is an operating system call, and does not
use the SystemC wait
, so the thread will not
yield and the simulation will block. Instead the pseudo-TTY is set up
to use asynchronous I/O, which will cause a Linux
SIGIO
to be raised whenever data is available to
read. The event handler for SIGIO
will then notify
a SystemC event, and it is this SystemC event on which the thread
can safely wait.
[5] The description here is specific to Linux. A future version of this application note will describe use under Microsoft Windows.