1 |
2 |
jondawson |
Chips-2.0 Demo for SP605 Development Card
|
2 |
|
|
=========================================
|
3 |
|
|
|
4 |
|
|
:Author: Jonathan P Dawson
|
5 |
|
|
:Date: 2013-10-17
|
6 |
|
|
:email: chips@jondawson.org.uk
|
7 |
|
|
|
8 |
|
|
This project implements a TCP/IP stack. The TCP/IP stack acts as a server, and
|
9 |
|
|
can accept a single connection to a TCP port. The connection is provided as a
|
10 |
|
|
bidirectional stream of data to the application. The following protocols are supported:
|
11 |
|
|
|
12 |
|
|
+ ARP request/response (with 16 level cache)
|
13 |
|
|
+ ICMP echo request/response (ping)
|
14 |
|
|
+ TCP/IP socket
|
15 |
|
|
|
16 |
|
|
Synthesis Estimate
|
17 |
|
|
==================
|
18 |
|
|
|
19 |
|
|
The TCP/IP server consumes around 800 LUTs and 300 Flip-Flops in a Xilinx Spartan 6 device.
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
Dependencies
|
23 |
|
|
============
|
24 |
|
|
|
25 |
|
|
The stack is implemented in C, and needs Chips-2.0 to compile it into a Verilog
|
26 |
|
|
module.
|
27 |
|
|
|
28 |
|
|
Source Files
|
29 |
|
|
============
|
30 |
|
|
|
31 |
|
|
The TCP/IP stack is provided by two source files:
|
32 |
|
|
|
33 |
|
|
+ source/server.h
|
34 |
|
|
+ source/server.c
|
35 |
|
|
|
36 |
|
|
Configuration
|
37 |
|
|
=============
|
38 |
|
|
|
39 |
|
|
The following parameters can be configured at compile time within source/server.h:
|
40 |
|
|
|
41 |
3 |
jondawson |
+ Local Ethernet MAC address (default: 0x000102030405)
|
42 |
|
|
+ Local IP Address (default: 192.168.1.1)
|
43 |
|
|
+ Local TCP Port number (default: 80 HTTP)
|
44 |
2 |
jondawson |
|
45 |
|
|
Compile
|
46 |
|
|
=======
|
47 |
|
|
|
48 |
|
|
Compile into a Verilog module (server.v) using the following command::
|
49 |
|
|
|
50 |
|
|
$ chip2/c2verilog source/server.v
|
51 |
|
|
|
52 |
|
|
Interface
|
53 |
|
|
=========
|
54 |
|
|
|
55 |
3 |
jondawson |
::
|
56 |
|
|
|
57 |
|
|
+-----------+
|
58 |
|
|
| SERVER |
|
59 |
|
|
+-----------+
|
60 |
|
|
ethernet_rx [15:0] >===> >===> output_socket [15:0]
|
61 |
|
|
| |
|
62 |
|
|
| |
|
63 |
|
|
ethernet_tx [15:0] <===< <===< input_socket [15:0]
|
64 |
|
|
+-----------+
|
65 |
|
|
|
66 |
|
|
|
67 |
2 |
jondawson |
Ethernet Interface
|
68 |
|
|
------------------
|
69 |
|
|
|
70 |
|
|
The Ethernet interface consists of two streams of data:
|
71 |
|
|
|
72 |
|
|
+ An input, input_eth_rx.
|
73 |
|
|
+ An output, output_eth_tx.
|
74 |
|
|
|
75 |
|
|
Both streams are 16 bits wide, and use the following protocol:
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
+------+-----------------+
|
79 |
|
|
| word | designation |
|
80 |
|
|
+------+-----------------+
|
81 |
|
|
| 0 | length in bytes |
|
82 |
|
|
+------+-----------------+
|
83 |
|
|
| n | data |
|
84 |
|
|
+------+-----------------+
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
Socket Interface
|
88 |
|
|
----------------
|
89 |
|
|
|
90 |
|
|
The socket interface consists of two streams of data:
|
91 |
|
|
|
92 |
|
|
+ An input, input_socket.
|
93 |
|
|
+ An output, output_socket.
|
94 |
|
|
|
95 |
|
|
Both streams are 16 bits wide, and use the following protocol:
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
+------+-----------------+
|
99 |
|
|
| word | designation |
|
100 |
|
|
+------+-----------------+
|
101 |
|
|
| 0 | length in bytes |
|
102 |
|
|
+------+-----------------+
|
103 |
|
|
| n | data |
|
104 |
|
|
+------+-----------------+
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
Stream Interconnect Conventions
|
108 |
|
|
===============================
|
109 |
|
|
|
110 |
|
|
The main aims of the interface are:
|
111 |
|
|
|
112 |
|
|
- To be simple to implement.
|
113 |
|
|
- Add little performance/logic overhead.
|
114 |
|
|
- Allow designs to grow without adding extra levels of asynchronous logic.
|
115 |
|
|
- Easy to interface with standard interconnects.
|
116 |
|
|
|
117 |
|
|
::
|
118 |
|
|
|
119 |
|
|
RST >-o-----------------------------+
|
120 |
|
|
CLK >-+-o-------------------------+ |
|
121 |
|
|
| | | |
|
122 |
|
|
| | +-----------+ | | +--------------+
|
123 |
|
|
| | | TX | | | | RX |
|
124 |
|
|
| +---> | | +-----> |
|
125 |
|
|
+-----> | +-------> |
|
126 |
|
|
| | | |
|
127 |
|
|
| | | |
|
128 |
|
|
| out >=================> in |
|
129 |
|
|
| | _STB | |
|
130 |
|
|
| out >-----------------> in |
|
131 |
|
|
| | _ACK | |
|
132 |
|
|
| in <-----------------< out |
|
133 |
|
|
| | | |
|
134 |
|
|
+-----------+ +--------------+
|
135 |
|
|
|
136 |
|
|
Global Signals
|
137 |
|
|
--------------
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
|
141 |
|
|
+------+-----------+------+-------------+
|
142 |
|
|
| Name | Direction | Type | Description |
|
143 |
|
|
+------+-----------+------+-------------+
|
144 |
|
|
| CLK | input | bit | Clock |
|
145 |
|
|
+------+-----------+------+-------------+
|
146 |
|
|
| RST | input | bit | Reset |
|
147 |
|
|
+------+-----------+------+-------------+
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
Interconnect Signals
|
152 |
|
|
--------------------
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
+----------------+-----------+------+-----------------------------------------------------------+
|
157 |
|
|
| Name | Direction | Type | Description |
|
158 |
|
|
+----------------+-----------+------+-----------------------------------------------------------+
|
159 |
|
|
| | TX to RX | bus | Payload Data |
|
160 |
|
|
+----------------+-----------+------+-----------------------------------------------------------+
|
161 |
|
|
| _STB | TX to RX | bit | '1' indicates that payload data is valid and TX is ready. |
|
162 |
|
|
+----------------+-----------+------+-----------------------------------------------------------+
|
163 |
|
|
| _ACK | TX to RX | bit | '1' indicates that RX is ready. |
|
164 |
|
|
+----------------+-----------+------+-----------------------------------------------------------+
|
165 |
|
|
|
166 |
|
|
|
167 |
|
|
|
168 |
|
|
Interconnect Bus Transaction
|
169 |
|
|
----------------------------
|
170 |
|
|
|
171 |
|
|
- Both transmitter and receiver shall be synchronised to the '0' -> '1' transition of CLK.
|
172 |
|
|
- If RST is set to '1' upon the '0' -> '1' transition of clock the transmitter shall terminate any active bus transaction and set _STB to '0'.
|
173 |
|
|
- If RST is set to '1' upon the '0' -> '1' transition of clock the receiver shall terminate any active bus transaction and set _ACK to '0'.
|
174 |
|
|
- If RST is set to '0', normal operation shall commence as follows:
|
175 |
|
|
- The transmitter may insert wait states on the bus by setting _STB '0'.
|
176 |
|
|
- The transmitter shall set _STB to '1' to signify that data is valid.
|
177 |
|
|
- Once _STB has been set to '1', it shall remain at '1' until the transaction completes.
|
178 |
|
|
- The transmitter shall ensure that contains valid data for the entire period that _STB is '1'.
|
179 |
|
|
- The transmitter may set to any value when _STB is '0'.
|
180 |
|
|
- The receiver may insert wait states on the bus by setting _ACK to '0'.
|
181 |
|
|
- The receiver shall set _ACK to '1' to signify that it is ready to receive data.
|
182 |
|
|
- Once _ACK has been set to '1', it shall remain at '1' until the transaction completes.
|
183 |
|
|
- Whenever _STB is '1' and _ACK are '1', a bus transaction shall complete on the following '0' -> '1' transition of CLK.
|
184 |
|
|
|
185 |
|
|
::
|
186 |
|
|
|
187 |
|
|
RST
|
188 |
|
|
--------------------------------------------------------------
|
189 |
|
|
- - - - - - - - - - - - - - -
|
190 |
|
|
CLK | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
191 |
|
|
- - - - - - - - - - - - - - - -
|
192 |
|
|
|
193 |
|
|
----- ------- ------------------------------------------------
|
194 |
|
|
X VALID X
|
195 |
|
|
----- ------- ------------------------------------------------
|
196 |
|
|
-------
|
197 |
|
|
_STB | |
|
198 |
|
|
----- ------------------------------------------------
|
199 |
|
|
---
|
200 |
|
|
_ACK | |
|
201 |
|
|
--------- ------------------------------------------------
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
^^^^ RX adds wait states
|
205 |
|
|
|
206 |
|
|
^^^^ Data transfers
|
207 |
|
|
|
208 |
|
|
RST
|
209 |
|
|
--------------------------------------------------------------
|
210 |
|
|
- - - - - - - - - - - - - - -
|
211 |
|
|
CLK | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
212 |
|
|
- - - - - - - - - - - - - - - -
|
213 |
|
|
|
214 |
|
|
----- ------- ------------------------------------------------
|
215 |
|
|
X VALID X
|
216 |
|
|
----- ------- ------------------------------------------------
|
217 |
|
|
---
|
218 |
|
|
_STB | |
|
219 |
|
|
--------- ------------------------------------------------
|
220 |
|
|
-------
|
221 |
|
|
_ACK | |
|
222 |
|
|
----- ------------------------------------------------
|
223 |
|
|
|
224 |
|
|
|
225 |
|
|
^^^^ TX adds wait states
|
226 |
|
|
|
227 |
|
|
^^^^ Data transfers
|
228 |
|
|
|
229 |
|
|
..
|
230 |
|
|
|
231 |
|
|
- Both the transmitter and receiver may commence a new transaction without inserting any wait states.
|
232 |
|
|
|
233 |
|
|
::
|
234 |
|
|
|
235 |
|
|
RST
|
236 |
|
|
--------------------------------------------------------------
|
237 |
|
|
- - - - - - - - - - - - - - -
|
238 |
|
|
CLK | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
239 |
|
|
- - - - - - - - - - - - - - - -
|
240 |
|
|
|
241 |
|
|
----- ------- ---- ---- --------------------------------------
|
242 |
|
|
X D0 X D1 X D2 X
|
243 |
|
|
----- ------- ---- ---- --------------------------------------
|
244 |
|
|
-------------
|
245 |
|
|
_STB | |
|
246 |
|
|
--------- --------------------------------------
|
247 |
|
|
-----------------
|
248 |
|
|
_ACK | |
|
249 |
|
|
----- --------------------------------------
|
250 |
|
|
|
251 |
|
|
^^^^ TX adds wait states
|
252 |
|
|
|
253 |
|
|
^^^^ Data transfers
|
254 |
|
|
|
255 |
|
|
^^^^ STB and ACK needn't return to 0 between data words
|
256 |
|
|
|
257 |
|
|
..
|
258 |
|
|
|
259 |
|
|
|
260 |
|
|
- The receiver may delay a transaction by inserting wait states until the transmitter indicates that data is available.
|
261 |
|
|
|
262 |
|
|
- The transmitter shall not delay a transaction by inserting wait states until the receiver is ready to accept data.
|
263 |
|
|
|
264 |
|
|
- Deadlock would occur if both the transmitter and receiver delayed a transaction until the other was ready.
|