eZ80 Serial To TCP/IP Gateway


Application Note
powered by the eZ80 Remote Access™
ZiLOG Application Note
Using eZ80 family processors as a bridge between RS232 and Ethernet interfaces
Author: Andrei Kovalev
FAE ZiLOG Germany

the Project workflow

This is a Remote Access™ project. The main starts the Remote Access control thread, initializes the COM driver, then starts the serial receiver thread and the TCP output thread. The first thread provides remote control from a Remote Access client, the other listens to the UART and does serial reception, the last but by no means the later converts everything to the TCP link.

The serial thread. The serial thread works with the COM driver, which enables the stable data reception. The packet queue is created using the mblock structure of IPWorks. The memory for the packets is dynamically allocated providing additional flexibility. As soon as a complete packet - from a header to a terminator - is received to an internal buffer, its length is parsed and the sufficient memory block allocated for it. The packet is then inserted to the queue for sending.

The queue size is limited by 32 packets. This parameter is configurable. When there is no TCP connection, meaning the server is not available or there is a communication problems, the serial thread stores the received packets into the queue. If the queue size exceeds 32 packets the old packets will become getting discarded for new packets to be stored.

The queue is thus cyclic and allows for some maximum number of elements. Every time the a packet is received from COM device driver, the serial thread appends it at the tail of the queue. The TCP thread picks packets from the head of the queue.

Packet format.

General format: PPxxxxLLLL<DATA>5
Comments:
PP   - packet header
xxxx - packet number
LLLL - packet length
<DATA> - packet contents, LLLL bytes
5 - packet terminator

The TCP thread. If there is no connection made the thread continuously tries to establish it to the given TCP server. The attempts are made periodically every 3 seconds. The address and the socket port used by the server for this connection must be set in the initialization parameters of the thread. Once the server is available the connection to it will be made. Until that time all packets that do not fit to the size of the serial queue will be discarded.

Once the connection is made, the thread looks if there are packets available in the queue. The TCP thread should pick packets at the head pointer of the queue. As soon as the queue head pointer is not null, the packet will be picked from the queue and written to the connected TCP socket.

In the opposite direction, when a data is entered into PC emulation terminal, the PC client sends the data to the Gateway. The eZ80 server Gateway takes the data and sends them to the serial end device. Thus the communication cycle of the application completes.

The TCP server. The TCP server must be arranged and setup for the receiving side on TCP end. In this project a Remote Access TCPHost application module is used for testing purpose. It creates the listening socket for eZ80 to connect to. It also allows the user to select the UART to work with and set the communication parameters of the UART. The client then commands to the server to start serial 2 TCP gateway function.

When the JClient starts, the Network Scanner is used to find the servers. The Serial 2 TCP Gateway answers with the name "Gateway" as shown on the following picture.

Use the IP address of the Gateway to connect to it form within the Gateway panel.

After the connection is established the module window displays the received packet data in the form of dual hexadecimal and ASCII dump. The view can be switched to a dialog view, where the user can work with the serial device connected to the gateway just like via a terminal programm. That is why the client window has the feature of the terminal emulation, emulation of a serial terminal on a TCP client side!

The sample TCP Host panel used in this application note is shown on the figure. Once activated, it creates a server sockets that accepts incoming connections on a port given by the options of the panel. The received packet contents will be displayed in the "Packet contents" window. The packet count is displayed. The option "Log" allows to create a packet log file where all accepted packets will be stored. The View button can be used to start the Windows notepad.exe application that will show the contents of the packet log file.

Setting up the TCP Client module. The TCP Client module is the module of JClient application. The JClient allows the setup the module. To open the settings dialog the user chooses Tools\Options menu, or Ctrl-O key combination. The settings dialog is shown on the picture.

With this dialog it can be chosen if UART1 or UART2 on eZ80 is used for the communication to end device, the serial rate and the data transfer settings as well as flow control. The TCP port setting is for the local TCP port to be set.

Documenation Index
Home | Downloads | eZ80 Module

1