Friday, August 28, 2009

Serial To Ethernet Gateway Part 1

In this article, I will talk about the design considerations for making serial to ethernet gateway.
One might think it is very easy to implement such a device. If you have both the Ethernet and Serial Input/Output (I/O) , you just have to connect the serial output to the ethernet input or vice versa to do the conversion. There you have it!! Finished! That is actually a very ideal case.

In real life, data doesn't just come in and out at a constant flow. Sometimes there are a lot of data to process, but sometimes there are none. This is similar to a highway. During the morning traffic, there are tons of people driving to work, but during the off hours, there are none.

So how do we design a system so that we can accommodate all the data coming in from serial and convert them into Ethernet data?
Well the answer is ring buffer.

A Ring buffer is type of data structure which returns to the starting point whenever the maximum is reached. In this case, the older data get written over by the new data. When using a ring buffer you need to have a write pointer and read pointer so that you can keep track of your data.

There are four cases to consider
(Notice that orange box indicates new data is written into the buffer)

1) Empty Buffer (Write pointer = Read pointer)


2) New data is written into buffer (Write pointer > Read pointer)


3) New data is written into buffer and the write pointer loops back to the beginning
(Read Pointer > Write Pointer)


4) Buffer is full (Write pointer = Read Pointer)
If your buffer is large enough, the likelihood of case 4 is very slim. However, you should still put case 4 into your consideration when designing the ring buffer.

After observing the behavior of these cases, it is important that you implement every possible cases to ensure that your system is stable. Next time, I will go through the source code for this project. Thanks for viewing

Enjoy!








No comments:

Post a Comment