-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTx_MAC.v
1487 lines (1325 loc) · 50.9 KB
/
Tx_MAC.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// HPSDR - High Performance Software Defined Radio
//
// Metis code.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// Tx_MAC - Copyright 2009, 2010, 2011 Phil Harman VK6APH
//----------------------------------------
// Tx_MAC - Interface to PHY
//----------------------------------------
/*
The format of the data to the PHY at 100T is as follows
+----+ +----+ +----+ +----+ +----+ +----+ +----+ +----+
PHY_Tx_clock --+ +----+ +----+ +----+ +----+ +----+ +----+ +----+ 25MHz
+-----------------------------------------------------------------
Tx_CTL ------------+
+---------+---------+---------+---------+---------+---------+---------+
TD +---------+---------+---------+---------+---------+---------+---------+
nibble (100T) 3:0 7:4 3:0 7:4 3:0 7:4 3:0 7:4
At 1000T the 3:0 nibble is sent on the positive edge of Rx_clock and 7:4 on the negative edge vis:
+----+ +----+ +----+ +----+ +----+ +----+ +----+ +----+
PHY_Tx_clock + +----+ +----+ +----+ +----+ +----+ +----+ +----+ 125MHz
+-----------------------------------------------------------------
Tx_CTL ------------+
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
TD +----+----+----+----+----+----+----+----+----+----+----+----+----+----+
nibble (100T) 3:0 7:4 3:0 7:4 3:0 7:4 3:0 7:4 3:0 7:4 3:0 7:4 3:0 7:4 3:0
Operation is as follows:
The transmit state machine loops looking for either an APR request, ping request or the PHY_Tx fifo having > 1023
bytes in it. The latter conditions indicates a UDP/IP send request.
ARP:
This causes a read of a predetermed sequence of bytes that are addressed in sequence by a state machine.
During the procees the CRC32 calculation is started and appended at the end of the sequence of bytes.
PING:
This first calculates the ping checksum, reads a predetermend sequence of bytes that are addressed in sequence
then appends the original ping data obtained by the Rx_MAC. During the procees the CRC32 calculation is started
and appended at the end of the ping data.
UDP/IP:
This causes a read of a predetermed sequence of bytes that are addressed in sequence by a state machine.
1024 bytes from the PHY_Tx fifo are then appended. During the procees the CRC32 calculation is started
and appended at the end of the fifo bytes.
NOTE: This code makes use of a large number of states. Each packet that we send uses it own dedicated state
machine. It is possible to combine common elements of the code e.g. preamble. However, doing so does not
reduced the size of the code since Quartus is able to optimise away the duplicated states. The use of individual
state machines had been used to make the code more readable.
Change log:
2011 Mar 11 - Send DHCP server IP address as an option in DHCP_request.
Apr 2 - Reset sequence number when not running rather than when Discovery received.
- Add run state and Metis software version to Discovery reply.
3 - Add wide band spectrum and on/off enable
May 13 - Added independant serial number for wide bandscope data.
*/
module Tx_MAC (Tx_clock, Tx_clock_2, IF_rst, Send_ARP,ping_reply,
PHY_Tx_data, PHY_Tx_rdused, ping_data, LED, Tx_fifo_rdreq,
Tx_CTL, ARP_sent, ping_sent, TD, DHCP_discover, DHCP_discover_sent,
This_MAC,SIADDR, DHCP_request,
DHCP_request_sent, METIS_discovery, PC_IP, PC_MAC,
Port, This_IP, METIS_discover_sent, ARP_PC_MAC, ARP_PC_IP,
Ping_PC_MAC, Ping_PC_IP, Length, speed_100T, Tx_reset, run, wide_spectrum,
IP_valid, printf, IP_lease, DHCP_IP, DHCP_MAC, DHCP_request_renew, DHCP_request_renew_sent,
erase_done, erase_done_ACK, send_more, send_more_ACK, Angelia_version,
sp_fifo_rddata, sp_fifo_rdreq, sp_fifo_rdempty, sp_fifo_rdused, have_sp_data,
AssignIP);
input Tx_clock; // 25MHz for 100T
input Tx_clock_2; // clock/2
input IF_rst; // reset signal
input Send_ARP; // high to send ARP response
input ping_reply; // high to send ping response
input [7:0]PHY_Tx_data; // data to send to PHY
input [10:0]PHY_Tx_rdused; // data available in Tx fifo
input [7:0]ping_data[0:59]; // data to send back
input DHCP_discover; // high when requested
input [47:0]This_MAC; // MAC address of this Metis board
input [31:0]SIADDR; // IP address of server that provided IP address
input DHCP_request; // high when request required
input METIS_discovery; // high when reply required
input [31:0]PC_IP; // IP address of the PC we are connecting to
input [47:0]PC_MAC; // MAC address of the PC we are connecting to
input [15:0]Port; // Port on the PC we are sending to
input [31:0]This_IP; // IP address provided by PC or DHCP at start up
input [47:0]ARP_PC_MAC; // MAC address of PC requesting ARP
input [31:0]ARP_PC_IP; // IP address of PC requesting ARP
input [47:0]Ping_PC_MAC; // MAC address of PC requesting ping
input [31:0]Ping_PC_IP; // IP address of PC requesting ping
input [15:0]Length; // Lenght of packet - used by ping
input speed_100T; // high for 100T,low for 1000T ************ check
input Tx_reset; // high to prevent I&Q data being sent
input run; // high to enable data to be sent
input wide_spectrum; // high to enable wide spectrum data to be sent
input IP_valid; // high when we have a valid IP address
input printf; // high when we want to send debug data
input [31:0]IP_lease; // *** test data - IP lease time in seconds
input [31:0]DHCP_IP; // IP address of DHCP server
input [47:0]DHCP_MAC; // MAC address of DHCP server
input DHCP_request_renew; // set when renew required
input erase_done; // set when we what to tell the PC we have completed the EPCS16 erase
input send_more; // set when we want the next block of 256 bytes for the EPCS16
input [7:0]Angelia_version; // Angelia code version
input [7:0]sp_fifo_rddata; // raw ACD data from Mercury for wide bandscope
input sp_fifo_rdempty; // SP_fifo read empty
input [12:0]sp_fifo_rdused; // SP_fifo contents
input have_sp_data; // high when sp_fifo is full.
input [31:0]AssignIP; // IP address read from EEPROM
output LED; // show MAC is doing something!
output Tx_fifo_rdreq; // high to indicate read from Tx fifo required
output Tx_CTL; // high to enable write to PHY
output ARP_sent; // high indicates ARP has been sent
output ping_sent; // high indicates ping reply has been sent
output [3:0]TD; // nibble to send to PHY
output DHCP_discover_sent; // high when has been sent
output DHCP_request_sent; // high when has been sent
output METIS_discover_sent; // high when has been sent ** pulse
output DHCP_request_renew_sent; // high when has been sent
output erase_done_ACK; // set when we have sent erase of EPCS16 complete to PC
output send_more_ACK; // set when we confirm we have requested more EPCS data from PC
output sp_fifo_rdreq; // SP_fifo read require signal
// HPSDR specific
parameter HPSDR_frame = 8'h01; // HPSDR Frame type
parameter HPSDR_IP_frame = 8'h03; // Read IP Frame type
// parameter end_point = 8'h06; // HPSDR end point - 6 to indicate fifo write
parameter Type_1 = 8'hEF; // Ethernet Frame type
parameter Type_2 = 8'hFE;
localparam TxPort = 16'd1024; // Metis 'from' port
localparam IP_MAC = 48'h11_22_33_44_55_66; // MAC address used for setting and reading IP address
localparam
RESET = 0,
UDP = 1,
METIS_DISCOVERY = 2,
ARP = 3,
PING1 = 4,
PING2 = 5,
DHCP_DISCOVER = 6,
DHCP_REQUEST = 7,
DHCP_REQUEST_RENEW = 8,
PRINTF = 9,
SPECTRUM = 10,
SENDIP = 11,
CRC = 12;
wire [31:0] CRC32; // holds 802.3 CRC result
reg [31:0] temp_CRC32 = 0;
reg [31:0] sequence_number = 0;
reg [31:0] spec_seq_number = 0;
reg [6:0] state_Tx; // state for FX2
reg [10:0] data_count;
reg [10:0] sp_data_count;
reg reset_CRC;
reg [7:0] Tx_data;
reg [4:0] gap_count;
reg ARP_sent; // true when we have replied to an ARP request
reg LED; // Test LED
reg erase_done_ACK; // set when we have sent erase of EPCS16 complete to PC
reg send_more_ACK; // set when we confirm we have requested more EPCS data from PC
reg [31:0]Discovery_IP; // IP address of PC doing Discovery
reg [47:0]Discovery_MAC; // MAC address of PC doing Discovery
reg [15:0]Discovery_Port; // Port Address of PC doing Discovery
reg [7:0]end_point; // USB end point equivalent 8'h06 for IQ data and 8'h04 for Spectrum
reg [4:0]IP_count; // holds shift count when sending IP to PHY TX fifo
// calculate the IP checksum, big-endian style
// The 0xC935 is fixed and made up of the 16 bit add of the header data. *** this will need changing if we change payload size ****
// i.e. 0x4500 + 0x0424 + 0x8011 = 0xC935
// then add the IPsource and IPDesitination in 16 bits using 1's complement and then complement
// calculate the UDP/IP checksum
wire [31:0]IPchecksum1;
wire [31:0]IPchecksum2;
wire [15:0]IPchecksum3;
assign IPchecksum1 = 32'h0000C935 + This_IP[31:16] + This_IP[15:0] + PC_IP[31:16] + PC_IP[15:0];
assign IPchecksum2 = ((IPchecksum1 & 32'h0000FFFF) + (IPchecksum1 >> 16)); // 1's complement add, shift the higher order bits and add
assign IPchecksum3 = ~((IPchecksum2 & 32'h0000FFFF) + (IPchecksum2 >> 16)); // again, then complement
// calculate the UDP/IP checksum for Metis discovery
wire [31:0]DISchecksum1;
wire [31:0]DISchecksum2;
wire [15:0]DISchecksum3;
assign DISchecksum1 = 32'h00004500 + 32'h00000058 + 32'h00008011 + This_IP[31:16] + This_IP[15:0] +
Discovery_IP[31:16] + Discovery_IP[15:0];
assign DISchecksum2 = ((DISchecksum1 & 32'h0000FFFF) + (DISchecksum1 >> 16)); // 1's complement add, shift the higher order bits and add
assign DISchecksum3 = ~((DISchecksum2 & 32'h0000FFFF) + (DISchecksum2 >> 16)); // again, then complement
// calculate the IP checksum for ICMP (ping)
wire [31:0]ICMPchecksum1;
wire [31:0]ICMPchecksum2;
wire [15:0]ICMPchecksum3;
assign ICMPchecksum1 = 32'h00004500 + Length + 32'h00008001 + This_IP[31:16] + This_IP[15:0] +
Ping_PC_IP[31:16] + Ping_PC_IP[15:0];
assign ICMPchecksum2 = ((ICMPchecksum1 & 32'h0000FFFF) + (ICMPchecksum1 >> 16)); // 1's complement add, shift the higher order bits and add
assign ICMPchecksum3 = ~((ICMPchecksum2 & 32'h0000FFFF) + (ICMPchecksum2 >> 16)); // again, then complement
// calculate the IP checksum for DHCP discovery
wire [31:0]DHCPchecksum1;
wire [31:0]DHCPchecksum2;
wire [15:0]DHCPchecksum3;
assign DHCPchecksum1 = 32'h00004500 + UDP_DHCP_length + 32'h00008011 + 32'h0000FFFF + 32'h0000FFFF;
assign DHCPchecksum2 = ((DHCPchecksum1 & 32'h0000FFFF) + (DHCPchecksum1 >> 16)); // 1's complement add, shift the higher order bits and add
assign DHCPchecksum3 = ~((DHCPchecksum2 & 32'h0000FFFF) + (DHCPchecksum2 >> 16)); // again, then complement
// calculate IP checksum for DHCP request
wire [31:0]DHCP_req_checksum1;
wire [31:0]DHCP_req_checksum2;
wire [15:0]DHCP_req_checksum3;
assign DHCP_req_checksum1 = 32'h00004500 + UDP_DHCP_req_length + 32'h00008011 + 32'h0000FFFF + 32'h0000FFFF;
assign DHCP_req_checksum2 = ((DHCP_req_checksum1 & 32'h0000FFFF) + (DHCP_req_checksum1 >> 16)); // 1's complement add, shift the higher order bits and add
assign DHCP_req_checksum3 = ~((DHCP_req_checksum2 & 32'h0000FFFF) + (DHCP_req_checksum2 >> 16)); // again, then complement
// calculate IP checksum for DHCP request renew
wire [31:0]DHCP_req_renew_checksum1;
wire [31:0]DHCP_req_renew_checksum2;
wire [15:0]DHCP_req_renew_checksum3;
assign DHCP_req_renew_checksum1 = 32'h00004500 + UDP_DHCP_req_renew_length + 32'h00008011 + This_IP[31:16] + This_IP[15:0] +
DHCP_IP[31:16] + DHCP_IP[15:0];
assign DHCP_req_renew_checksum2 = ((DHCP_req_renew_checksum1 & 32'h0000FFFF) + (DHCP_req_renew_checksum1 >> 16)); // 1's complement add, shift the higher order bits and add
assign DHCP_req_renew_checksum3 = ~((DHCP_req_renew_checksum2 & 32'h0000FFFF) + (DHCP_req_renew_checksum2 >> 16)); // again, then complement
wire [15:0]DHCP_length;
wire [15:0]UDP_DHCP_length;
wire [15:0]DHCP_req_length;
wire [15:0]UDP_DHCP_req_length;
wire [15:0]DHCP_req_renew_length;
wire [15:0]UDP_DHCP_req_renew_length;
reg [9:0] rdaddress;
reg [7:0] pkt_data;
reg [7:0] ck_count;
reg [31:0]ping_check_temp;
reg [15:0]ping_check_sum;
reg ping_sent;
reg [8:0] zero_count;
reg [3:0]interframe;
reg printf;
reg DHCP_request_renew_sent;
reg Metis_discover_sent;
reg [7:0] frame; // HPSDR frame type; 0x02 for Discovery reply,
// 0x03 for EPCS16 erase complete and
// 0x04 for send next 256 bytes for EPCS16 program
reg [31:0]temp_IP; // holds IP address from EEPROM whilst we are shifting
always @ *
case(rdaddress)
//---------- UDP/IP packet --------
// Ethernet preamble
0 : pkt_data <= 8'h55;
1 : pkt_data <= 8'h55;
2 : pkt_data <= 8'h55;
3 : pkt_data <= 8'h55;
4 : pkt_data <= 8'h55;
5 : pkt_data <= 8'h55;
6 : pkt_data <= 8'h55;
7 : pkt_data <= 8'hD5;
// Ethernet header
8 : pkt_data <= PC_MAC[47:40];
9 : pkt_data <= PC_MAC[39:32];
10: pkt_data <= PC_MAC[31:24];
11: pkt_data <= PC_MAC[23:16];
12: pkt_data <= PC_MAC[15:8];
13: pkt_data <= PC_MAC[7:0];
14: pkt_data <= This_MAC[47:40];
15: pkt_data <= This_MAC[39:32];
16: pkt_data <= This_MAC[31:24];
17: pkt_data <= This_MAC[23:16];
18: pkt_data <= This_MAC[15:8];
19: pkt_data <= This_MAC[7:0];
20: pkt_data <= 8'h08;
21: pkt_data <= 8'h00;
// IP header
22: pkt_data <= 8'h45; // Version
23: pkt_data <= 8'h00; // Type of service
24: pkt_data <= 8'h04; // length ***** CHANGE CHECKSUM IF LENGTH CHANGES *****
25: pkt_data <= 8'h24; // total of 1060 bytes, 1032 UDP data + 8 UDP header + 20 IP header
26: pkt_data <= 8'h00; // Identification
27: pkt_data <= 8'h00;
28: pkt_data <= 8'h00; // Flags, Fragment
29: pkt_data <= 8'h00;
30: pkt_data <= 8'h80; // Time to live
31: pkt_data <= 8'h11; // Protocol (0x11 = UDP)
32: pkt_data <= IPchecksum3[15:8]; // Checksum
33: pkt_data <= IPchecksum3[ 7:0];
34: pkt_data <= This_IP[31:24]; // Source IP Address is IP address allocated to this board
35: pkt_data <= This_IP[23:16];
36: pkt_data <= This_IP[15:8];
37: pkt_data <= This_IP[7:0];
38: pkt_data <= PC_IP[31:24]; // Destination PC IP Address
39: pkt_data <= PC_IP[23:16];
40: pkt_data <= PC_IP[15:8];
41: pkt_data <= PC_IP[7:0];
// UDP header
42: pkt_data <= TxPort[15:8]; // 'from' port = 1024
43: pkt_data <= TxPort[7:0];
44: pkt_data <= Port[15:8]; // destination port assigned by PC during Metis Discovery (i.e. PC 'from' Port)
45: pkt_data <= Port[7:0];
46: pkt_data <= 8'h04; // length
47: pkt_data <= 8'h10; // total of 1040 bytes (1032 UDP data + 8 UDP header)
48: pkt_data <= 8'h00; // UDP Checksum (set to all zero which is valid for IP4 but not IP6)
49: pkt_data <= 8'h00;
// Start of Payload
50: pkt_data <= Type_1; // Ethernet Frame type 0xEFFE (HPSDR)
51: pkt_data <= Type_2;
52: pkt_data <= HPSDR_frame; // HPSDR Frame type
53: pkt_data <= end_point; // HPSDR end point
54: pkt_data <= (state_Tx == SPECTRUM) ? spec_seq_number[31:24] : sequence_number[31:24]; // 32bit sequence numbers
55: pkt_data <= (state_Tx == SPECTRUM) ? spec_seq_number[23:16] : sequence_number[23:16];
56: pkt_data <= (state_Tx == SPECTRUM) ? spec_seq_number[15:8] : sequence_number[15:8];
57: pkt_data <= (state_Tx == SPECTRUM) ? spec_seq_number[7:0] : sequence_number[7:0];
// followed by 1024 bytes of data
// then CRC32 - CRC[7:0] is stored in each state &
// all states use this code to add the balance of the CRC
58: pkt_data <= temp_CRC32[15:8];
59: pkt_data <= temp_CRC32[23:16];
60: pkt_data <= temp_CRC32[31:24];
//---------- ARP reply data -----------
// Ethernet preamble
100: pkt_data <= 8'h55;
101: pkt_data <= 8'h55;
102: pkt_data <= 8'h55;
103: pkt_data <= 8'h55;
104: pkt_data <= 8'h55;
105: pkt_data <= 8'h55;
106: pkt_data <= 8'h55;
107: pkt_data <= 8'hD5;
// Ethernet header
108: pkt_data <= ARP_PC_MAC[47:40]; // MAC address of PC requesting ARP
109: pkt_data <= ARP_PC_MAC[39:32];
110: pkt_data <= ARP_PC_MAC[31:24];
111: pkt_data <= ARP_PC_MAC[23:16];
112: pkt_data <= ARP_PC_MAC[15:8];
113: pkt_data <= ARP_PC_MAC[7:0];
114: pkt_data <= This_MAC[47:40]; // MAC address of this Metis board
115: pkt_data <= This_MAC[39:32];
116: pkt_data <= This_MAC[31:24];
117: pkt_data <= This_MAC[23:16];
118: pkt_data <= This_MAC[15:8];
119: pkt_data <= This_MAC[7:0];
// ARP reply
120: pkt_data <= 8'h08;
121: pkt_data <= 8'h06;
122: pkt_data <= 8'h00; // Hardware type
123: pkt_data <= 8'h01;
124: pkt_data <= 8'h08; // Protocol Type
125: pkt_data <= 8'h00;
126: pkt_data <= 8'h06; // Hardware Length
127: pkt_data <= 8'h04; // Protocol Length
128: pkt_data <= 8'h00; // Operation, ARP reply, 0x0002
129: pkt_data <= 8'h02;
130: pkt_data <= This_MAC[47:40]; // MAC address of this Metis board
131: pkt_data <= This_MAC[39:32];
132: pkt_data <= This_MAC[31:24];
133: pkt_data <= This_MAC[23:16];
134: pkt_data <= This_MAC[15:8];
135: pkt_data <= This_MAC[7:0];
136: pkt_data <= This_IP[31:24]; // IP address assigned to this Metis board
137: pkt_data <= This_IP[23:16];
138: pkt_data <= This_IP[15:8];
139: pkt_data <= This_IP[7:0];
140: pkt_data <= ARP_PC_MAC[47:40]; // MAC address of PC requesting ARP
141: pkt_data <= ARP_PC_MAC[39:32];
142: pkt_data <= ARP_PC_MAC[31:24];
143: pkt_data <= ARP_PC_MAC[23:16];
144: pkt_data <= ARP_PC_MAC[15:8];
145: pkt_data <= ARP_PC_MAC[7:0];
146: pkt_data <= ARP_PC_IP[31:24]; // IP address of PC requesting ARP
147: pkt_data <= ARP_PC_IP[23:16];
148: pkt_data <= ARP_PC_IP[15:8];
149: pkt_data <= ARP_PC_IP[7:0];
// send 18 zeros to pad payload out to 60 bytes
// followed by CRC at raddress = 58
//---------- ping reply -----------
// Ethernet preamble
200: pkt_data <= 8'h55;
201: pkt_data <= 8'h55;
202: pkt_data <= 8'h55;
203: pkt_data <= 8'h55;
204: pkt_data <= 8'h55;
205: pkt_data <= 8'h55;
206: pkt_data <= 8'h55;
207: pkt_data <= 8'hD5;
// Ethernet header
208: pkt_data <= Ping_PC_MAC[47:40]; // MAC address of PC requesting the ping
209: pkt_data <= Ping_PC_MAC[39:32];
210: pkt_data <= Ping_PC_MAC[31:24];
211: pkt_data <= Ping_PC_MAC[23:16];
212: pkt_data <= Ping_PC_MAC[15:8];
213: pkt_data <= Ping_PC_MAC[7:0];
214: pkt_data <= This_MAC[47:40];
215: pkt_data <= This_MAC[39:32];
216: pkt_data <= This_MAC[31:24];
217: pkt_data <= This_MAC[23:16];
218: pkt_data <= This_MAC[15:8];
219: pkt_data <= This_MAC[7:0];
220: pkt_data <= 8'h08;
221: pkt_data <= 8'h00;
// IP header
222: pkt_data <= 8'h45; // Version
223: pkt_data <= 8'h00; // Type of service
224: pkt_data <= Length[15:8];//8'h00; // length
225: pkt_data <= Length[7:0];//8'h3C; // total of 60 bytes
226: pkt_data <= 8'h00; // Identification
227: pkt_data <= 8'h00;
228: pkt_data <= 8'h00; // Flags, Fragment
229: pkt_data <= 8'h00;
230: pkt_data <= 8'h80; // Time to live
231: pkt_data <= 8'h01; // Protocol (0x01 = ICMP - ping)
232: pkt_data <= ICMPchecksum3[15:8]; // Checksum
233: pkt_data <= ICMPchecksum3[ 7:0];
234: pkt_data <= This_IP[31:24]; // IP Address of this Metis board
235: pkt_data <= This_IP[23:16];
236: pkt_data <= This_IP[15:8];
237: pkt_data <= This_IP[7:0];
238: pkt_data <= Ping_PC_IP[31:24]; // IP address of PC requesting the ping
239: pkt_data <= Ping_PC_IP[23:16];
240: pkt_data <= Ping_PC_IP[15:8];
241: pkt_data <= Ping_PC_IP[7:0];
// ICMP packet
242: pkt_data <= 8'h00; // 0x00 echo reply, 0x08 for request
243: pkt_data <= 8'h00; // code
244: pkt_data <= ping_check_sum[15:8]; // Checksum
245: pkt_data <= ping_check_sum[7:0];
// Start data - 36 bytes
// followed by CRC at raddress = 58
//---------- DHCP discover -----------
// UDP/IP packet
// Ethernet preamble
300: pkt_data <= 8'h55;
301: pkt_data <= 8'h55;
302: pkt_data <= 8'h55;
303: pkt_data <= 8'h55;
304: pkt_data <= 8'h55;
305: pkt_data <= 8'h55;
306: pkt_data <= 8'h55;
307: pkt_data <= 8'hD5;
// Ethernet header
308: pkt_data <= 8'hFF; // Destination MAC is FF FF FF FF FF FF
309: pkt_data <= 8'hFF;
310: pkt_data <= 8'hFF;
311: pkt_data <= 8'hFF;
312: pkt_data <= 8'hFF;
313: pkt_data <= 8'hFF;
314: pkt_data <= This_MAC[47:40];
315: pkt_data <= This_MAC[39:32];
316: pkt_data <= This_MAC[31:24];
317: pkt_data <= This_MAC[23:16];
318: pkt_data <= This_MAC[15:8];
319: pkt_data <= This_MAC[7:0];
320: pkt_data <= 8'h08;
321: pkt_data <= 8'h00;
// IP header
322: pkt_data <= 8'h45; // Version
323: pkt_data <= 8'h00; // Type of service
324: pkt_data <= UDP_DHCP_length[15:8]; // length
325: pkt_data <= UDP_DHCP_length[7:0]; // UDP data + 8 UDP header + 20 IP header
326: pkt_data <= 8'h00; // Identification
327: pkt_data <= 8'h00;
328: pkt_data <= 8'h00; // Flags, Fragment
329: pkt_data <= 8'h00;
330: pkt_data <= 8'h80; // Time to live
331: pkt_data <= 8'h11; // Protocol (0x11 = UDP)
332: pkt_data <= DHCPchecksum3[15:8]; // Checksum
333: pkt_data <= DHCPchecksum3[ 7:0];
334: pkt_data <= 8'h00; // Source IP Address
335: pkt_data <= 8'h00;
336: pkt_data <= 8'h00;
337: pkt_data <= 8'h00;
338: pkt_data <= 8'hFF; // Destination IP Address
339: pkt_data <= 8'hFF;
340: pkt_data <= 8'hFF;
341: pkt_data <= 8'hFF;
// UDP header
342: pkt_data <= 8'h00; // source port = 68
343: pkt_data <= 8'h44;
344: pkt_data <= 8'h00; // destination port = 67
345: pkt_data <= 8'h43;
346: pkt_data <= DHCP_length[15:8]; // length
347: pkt_data <= DHCP_length[7:0]; // total of 252 bytes (244 UDP data + 8 UDP header)
348: pkt_data <= 8'h00; // UDP Checksum (set to all zero which is valid for IP4 but not IP6)
349: pkt_data <= 8'h00;
// DHCP Discover
350: pkt_data <= 8'h01;
351: pkt_data <= 8'h01;
352: pkt_data <= 8'h06;
353: pkt_data <= 8'h00;
// 24 x 0x00
354: pkt_data <= This_MAC[47:40];
355: pkt_data <= This_MAC[39:32];
356: pkt_data <= This_MAC[31:24];
357: pkt_data <= This_MAC[23:16];
358: pkt_data <= This_MAC[15:8];
359: pkt_data <= This_MAC[7:0];
// 202 x 0x00
360: pkt_data <= 8'h63; // Magic Cookie
361: pkt_data <= 8'h82;
362: pkt_data <= 8'h53;
363: pkt_data <= 8'h63;
// Options
364: pkt_data <= 8'h35; // Options
365: pkt_data <= 8'h01;
366: pkt_data <= 8'h01;
// End
367: pkt_data <= 8'hFF;
//---------- DHCP request ----------
// UDP/IP packet
// Ethernet preamble
400: pkt_data <= 8'h55;
401: pkt_data <= 8'h55;
402: pkt_data <= 8'h55;
403: pkt_data <= 8'h55;
404: pkt_data <= 8'h55;
405: pkt_data <= 8'h55;
406: pkt_data <= 8'h55;
407: pkt_data <= 8'hD5;
// Ethernet header
408: pkt_data <= 8'hFF; // Destination MAC is FF FF FF FF FF FF
409: pkt_data <= 8'hFF;
410: pkt_data <= 8'hFF;
411: pkt_data <= 8'hFF;
412: pkt_data <= 8'hFF;
413: pkt_data <= 8'hFF;
414: pkt_data <= This_MAC[47:40];
415: pkt_data <= This_MAC[39:32];
416: pkt_data <= This_MAC[31:24];
417: pkt_data <= This_MAC[23:16];
418: pkt_data <= This_MAC[15:8];
419: pkt_data <= This_MAC[7:0];
420: pkt_data <= 8'h08;
421: pkt_data <= 8'h00;
// IP header
422: pkt_data <= 8'h45; // Version
423: pkt_data <= 8'h00; // Type of service
424: pkt_data <= UDP_DHCP_req_length[15:8]; // length
425: pkt_data <= UDP_DHCP_req_length[7:0]; // UDP data + 8 UDP header + 20 IP header
426: pkt_data <= 8'h00; // Identification
427: pkt_data <= 8'h00;
428: pkt_data <= 8'h00; // Flags, Fragment
429: pkt_data <= 8'h00;
430: pkt_data <= 8'h80; // Time to live
431: pkt_data <= 8'h11; // Protocol (0x11 = UDP)
432: pkt_data <= DHCP_req_checksum3[15:8]; // Checksum
433: pkt_data <= DHCP_req_checksum3[ 7:0];
434: pkt_data <= 8'h00; // Source IP Address
435: pkt_data <= 8'h00;
436: pkt_data <= 8'h00;
437: pkt_data <= 8'h00;
438: pkt_data <= 8'hFF; // Destination IP Address
439: pkt_data <= 8'hFF;
440: pkt_data <= 8'hFF;
441: pkt_data <= 8'hFF;
// UDP header
442: pkt_data <= 8'h00; // source port = 68
443: pkt_data <= 8'h44;
444: pkt_data <= 8'h00; // destination port = 67
445: pkt_data <= 8'h43;
446: pkt_data <= DHCP_req_length[15:8]; // length
447: pkt_data <= DHCP_req_length[7:0]; // total of 252 bytes (246 UDP data + 8 UDP header)
448: pkt_data <= 8'h00; // UDP Checksum (set to all zero which is valid for IP4 but not IP6)
449: pkt_data <= 8'h00;
// DHCP Request
450: pkt_data <= 8'h01;
451: pkt_data <= 8'h01;
452: pkt_data <= 8'h06;
453: pkt_data <= 8'h00;
// 24 x 0x00
454: pkt_data <= This_MAC[47:40];
455: pkt_data <= This_MAC[39:32];
456: pkt_data <= This_MAC[31:24];
457: pkt_data <= This_MAC[23:16];
458: pkt_data <= This_MAC[15:8];
459: pkt_data <= This_MAC[7:0];
// 202 x 0x00
460: pkt_data <= 8'h63; // Magic Cookie
461: pkt_data <= 8'h82;
462: pkt_data <= 8'h53;
463: pkt_data <= 8'h63;
// Options
464: pkt_data <= 8'h35; // Options
465: pkt_data <= 8'h01;
466: pkt_data <= 8'h03;
467: pkt_data <= 8'h32;
468: pkt_data <= 8'h04;
469: pkt_data <= This_IP[31:24]; // IP address being accepted
470: pkt_data <= This_IP[23:16];
471: pkt_data <= This_IP[15:8];
472: pkt_data <= This_IP[7:0];
473: pkt_data <= 8'h36;
474: pkt_data <= 8'h04;
475: pkt_data <= DHCP_IP[31:24]; // IP address of DHCP server
476: pkt_data <= DHCP_IP[23:16];
477: pkt_data <= DHCP_IP[15:8];
478: pkt_data <= DHCP_IP[7:0];
// End
479: pkt_data <= 8'hFF;
//---------- UDP/IP packet in reply to Metis discovery request ----
// Ethernet preamble
500: pkt_data <= 8'h55;
501: pkt_data <= 8'h55;
502: pkt_data <= 8'h55;
503: pkt_data <= 8'h55;
504: pkt_data <= 8'h55;
505: pkt_data <= 8'h55;
506: pkt_data <= 8'h55;
507: pkt_data <= 8'hD5;
// Ethernet header
508: pkt_data <= Discovery_MAC[47:40];
509: pkt_data <= Discovery_MAC[39:32];
510: pkt_data <= Discovery_MAC[31:24];
511: pkt_data <= Discovery_MAC[23:16];
512: pkt_data <= Discovery_MAC[15:8];
513: pkt_data <= Discovery_MAC[7:0];
514: pkt_data <= This_MAC[47:40];
515: pkt_data <= This_MAC[39:32];
516: pkt_data <= This_MAC[31:24];
517: pkt_data <= This_MAC[23:16];
518: pkt_data <= This_MAC[15:8];
519: pkt_data <= This_MAC[7:0];
520: pkt_data <= 8'h08;
521: pkt_data <= 8'h00;
// IP header
522: pkt_data <= 8'h45; // Version
523: pkt_data <= 8'h00; // Type of service
524: pkt_data <= 8'h00; // length ***** CHANGE CHECKSUM IF LENGTH CHANGES *****
525: pkt_data <= 8'h58; // total of 88 bytes, 60 UDP data + 8 UDP header + 20 IP header
526: pkt_data <= 8'h00; // Identification
527: pkt_data <= 8'h00;
528: pkt_data <= 8'h00; // Flags, Fragment
529: pkt_data <= 8'h00;
530: pkt_data <= 8'h80; // Time to live
531: pkt_data <= 8'h11; // Protocol (0x11 = UDP)
532: pkt_data <= DISchecksum3[15:8]; // Checksum
533: pkt_data <= DISchecksum3[ 7:0];
534: pkt_data <= This_IP[31:24]; // Source IP Address
535: pkt_data <= This_IP[23:16];
536: pkt_data <= This_IP[15:8];
537: pkt_data <= This_IP[7:0];
538: pkt_data <= Discovery_IP[31:24]; // Destination PC IP Address
539: pkt_data <= Discovery_IP[23:16];
540: pkt_data <= Discovery_IP[15:8];
541: pkt_data <= Discovery_IP[7:0];
// UDP header
542: pkt_data <= TxPort[15:8]; // 'from' port
543: pkt_data <= TxPort[7:0];
544: pkt_data <= Discovery_Port[15:8]; // destination port assigned by PC
545: pkt_data <= Discovery_Port[7:0];
546: pkt_data <= 8'h00; // length
547: pkt_data <= 8'h44; // total of 68 bytes (60 UDP data + 8 UDP header)
548: pkt_data <= 8'h00; // UDP Checksum (set to all zero which is valid for IP4 but not IP6)
549: pkt_data <= 8'h00;
// Start of Payload
550: pkt_data <= Type_1; // Ethernet Frame type 0xEFFE (HPSDR)
551: pkt_data <= Type_2;
552: pkt_data <= frame + run; // HPSDR Frame type = discovery reply = 0x02 or 0x03 if running
553: pkt_data <= This_MAC[47:40]; // This Metis MAC Address
554: pkt_data <= This_MAC[39:32];
555: pkt_data <= This_MAC[31:24];
556: pkt_data <= This_MAC[23:16];
557: pkt_data <= This_MAC[15:8];
558: pkt_data <= This_MAC[7:0];
559: pkt_data <= Angelia_version;
// send 50 zeros to give a minimum payload of 60 bytes *** sending 0x01 now
// then CRC
// ---------- printf test code -----------------
// Ethernet preamble
600 : pkt_data <= 8'h55;
601 : pkt_data <= 8'h55;
602 : pkt_data <= 8'h55;
603 : pkt_data <= 8'h55;
604 : pkt_data <= 8'h55;
605 : pkt_data <= 8'h55;
606 : pkt_data <= 8'h55;
607 : pkt_data <= 8'hD5;
// Ethernet header
608 : pkt_data <= 8'hFF;
609 : pkt_data <= 8'hFF;
610 : pkt_data <= 8'hFF;
611 : pkt_data <= 8'hFF;
612 : pkt_data <= 8'hFF;
613 : pkt_data <= 8'hFF;
614 : pkt_data <= This_MAC[47:40]; // MAC address of this Metis Board
615 : pkt_data <= This_MAC[39:32];
616 : pkt_data <= This_MAC[31:24];
617 : pkt_data <= This_MAC[23:16];
618 : pkt_data <= This_MAC[15:8];
619 : pkt_data <= This_MAC[7:0];
// Start of Payload
620: pkt_data <= 8'hEF; // Ethernet Frame type 0xEFFF (printf)
621: pkt_data <= 8'hFF;
622: pkt_data <= HPSDR_frame; // HPSDR Frame type
623: pkt_data <= 8'hFF;
624: pkt_data <= This_IP[31:24]; // Source IP Address
625: pkt_data <= This_IP[23:16];
626: pkt_data <= This_IP[15:8];
627: pkt_data <= This_IP[7:0];
628: pkt_data <= PC_IP[31:24]; // Destination PC IP Address
629: pkt_data <= PC_IP[23:16];
630: pkt_data <= PC_IP[15:8];
631: pkt_data <= PC_IP[7:0];
632: pkt_data <= PC_MAC[47:40];
633: pkt_data <= PC_MAC[39:32];
634: pkt_data <= PC_MAC[31:24];
635: pkt_data <= PC_MAC[23:16];
636: pkt_data <= PC_MAC[15:8];
637: pkt_data <= PC_MAC[7:0];
638: pkt_data <= IP_lease[31:24];
639: pkt_data <= IP_lease[23:16];
640: pkt_data <= IP_lease[15:8];
641: pkt_data <= IP_lease[7:0];
642: pkt_data <= DHCP_IP[31:24]; // DHCP IP Address
643: pkt_data <= DHCP_IP[23:16];
644: pkt_data <= DHCP_IP[15:8];
645: pkt_data <= DHCP_IP[7:0];
646: pkt_data <= DHCP_MAC[47:40];
647: pkt_data <= DHCP_MAC[39:32];
648: pkt_data <= DHCP_MAC[31:24];
649: pkt_data <= DHCP_MAC[23:16];
650: pkt_data <= DHCP_MAC[15:8];
651: pkt_data <= DHCP_MAC[7:0]; // when changing add one and edit code
// followed by data
// then CRC32 at 58
//---------- DHCP request renew ----------
// UDP/IP packet
// Ethernet preamble
700: pkt_data <= 8'h55;
701: pkt_data <= 8'h55;
702: pkt_data <= 8'h55;
703: pkt_data <= 8'h55;
704: pkt_data <= 8'h55;
705: pkt_data <= 8'h55;
706: pkt_data <= 8'h55;
707: pkt_data <= 8'hD5;
// Ethernet header
708: pkt_data <= DHCP_MAC[47:40]; // DHCP Server MAC
709: pkt_data <= DHCP_MAC[39:32];
710: pkt_data <= DHCP_MAC[31:24];
711: pkt_data <= DHCP_MAC[23:16];
712: pkt_data <= DHCP_MAC[15:8];
713: pkt_data <= DHCP_MAC[7:0];
714: pkt_data <= This_MAC[47:40];
715: pkt_data <= This_MAC[39:32];
716: pkt_data <= This_MAC[31:24];
717: pkt_data <= This_MAC[23:16];
718: pkt_data <= This_MAC[15:8];
719: pkt_data <= This_MAC[7:0];
720: pkt_data <= 8'h08;
721: pkt_data <= 8'h00;
// IP header
722: pkt_data <= 8'h45; // Version
723: pkt_data <= 8'h00; // Type of service
724: pkt_data <= UDP_DHCP_req_renew_length[15:8]; // length
725: pkt_data <= UDP_DHCP_req_renew_length[7:0]; // 244 UDP data + 8 UDP header + 20 IP header
726: pkt_data <= 8'h00; // Identification
727: pkt_data <= 8'h00;
728: pkt_data <= 8'h00; // Flags, Fragment
729: pkt_data <= 8'h00;
730: pkt_data <= 8'h80; // Time to live
731: pkt_data <= 8'h11; // Protocol (0x11 = UDP)
732: pkt_data <= DHCP_req_renew_checksum3[15:8]; // Checksum
733: pkt_data <= DHCP_req_renew_checksum3[ 7:0];
734: pkt_data <= This_IP[31:24]; // Source IP Address is IP address allocated to this board
735: pkt_data <= This_IP[23:16];
736: pkt_data <= This_IP[15:8];
737: pkt_data <= This_IP[7:0];
738: pkt_data <= DHCP_IP[31:24]; // DHCP Server IP Address
739: pkt_data <= DHCP_IP[23:16];
740: pkt_data <= DHCP_IP[15:8];
741: pkt_data <= DHCP_IP[7:0];
// UDP header
742: pkt_data <= 8'h00; // source port = 68
743: pkt_data <= 8'h44;
744: pkt_data <= 8'h00; // destination port = 67
745: pkt_data <= 8'h43;
746: pkt_data <= DHCP_req_renew_length[15:8]; // length
747: pkt_data <= DHCP_req_renew_length[7:0]; // total of 252 bytes ( 244 UDP data + 8 UDP header)
748: pkt_data <= 8'h00; // UDP Checksum (set to all zero which is valid for IP4 but not IP6)
749: pkt_data <= 8'h00;
// DHCP Request
750: pkt_data <= 8'h01;
751: pkt_data <= 8'h01;
752: pkt_data <= 8'h06;
753: pkt_data <= 8'h00;
// XID, SECS, FLAGS
754: pkt_data <= 8'h00;
755: pkt_data <= 8'h00;
756: pkt_data <= 8'h00;
757: pkt_data <= 8'h00;
758: pkt_data <= 8'h00;
759: pkt_data <= 8'h00;
760: pkt_data <= 8'h00;
761: pkt_data <= 8'h00;
// CIADDR
762: pkt_data <= This_IP[31:24]; // CIADDR is IP address allocated to this board
763: pkt_data <= This_IP[23:16];
764: pkt_data <= This_IP[15:8];
765: pkt_data <= This_IP[7:0];
// 12 x 0x00
766: pkt_data <= This_MAC[47:40];
767: pkt_data <= This_MAC[39:32];
768: pkt_data <= This_MAC[31:24];
769: pkt_data <= This_MAC[23:16];
770: pkt_data <= This_MAC[15:8];
771: pkt_data <= This_MAC[7:0];
// 202 x 0x00
772: pkt_data <= 8'h63; // Magic Cookie
773: pkt_data <= 8'h82;
774: pkt_data <= 8'h53;
775: pkt_data <= 8'h63;
// Options
776: pkt_data <= 8'h35; // Options NOTE: No IP requested nor Server IP as per rfc2131
777: pkt_data <= 8'h01;
778: pkt_data <= 8'h03;
// End
779: pkt_data <= 8'hFF;
// followed by CRC32 at 58
default: pkt_data <= 0;
endcase
// to calculate length ; 8 + (end - DHCP_start + 1) + nulls + 202
assign DHCP_length = 16'd8 + (16'd367 - 16'd350 + 16'd1) + 16'd24 + 16'd202; // 8 + 244
assign UDP_DHCP_length = DHCP_length + 16'd20;
assign DHCP_req_length = 16'd8 + (16'd479 - 16'd450 + 16'd1) + 16'd24 + 16'd202; // 8 + 256
assign UDP_DHCP_req_length = DHCP_req_length + 16'd20;
assign DHCP_req_renew_length = 16'd8 + (16'd779 - 16'd750 + 16'd1) + 16'd12 + 16'd202; // 8 + 244
assign UDP_DHCP_req_renew_length = DHCP_req_renew_length + 16'd20;
always @ (negedge Tx_clock_2) // clock at half speed since we read bytes but write nibbles
begin
case(state_Tx)
RESET:
begin
LED <= 1'b0;
sync_Tx_CTL <= 1'b0;
data_count <= 0;
reset_CRC <= 0;
rdaddress <= 0;
ARP_sent <= 0;
ping_sent <= 0;
ping_check_temp <= 0; // reset ping check sum calculation
ck_count <= 0;
zero_count <= 0;
DHCP_discover_sent <= 0;
DHCP_request_sent <= 0;
METIS_discover_sent <= 0;
DHCP_request_renew_sent <= 0;
interframe <= 0;
erase_done_ACK <= 0;
send_more_ACK <= 0;
IP_count <= 0;
if (IF_rst)
state_Tx <= RESET;
else begin
if (run == 1'b0) begin
sequence_number <= 0; // reset sequence numbers when not running.
spec_seq_number <= 0;
end
if (printf) begin
rdaddress <= 600;
state_Tx <= PRINTF;
end
else if (DHCP_discover) begin
rdaddress <= 300; // point to start of DHCP table
state_Tx <= DHCP_DISCOVER;
end
else if (DHCP_request) begin
rdaddress <= 400;
state_Tx <= DHCP_REQUEST;
end
else if (DHCP_request_renew) begin
rdaddress <= 700;
state_Tx <= DHCP_REQUEST_RENEW;
end
else if (Send_ARP) begin // Pending ARP request
rdaddress <= 100; // point to start of ARP table
state_Tx <= ARP;
end
else if (ping_reply)begin
rdaddress <= 200; // point to ping checksum code
state_Tx <= PING1;
end
else if (METIS_discovery && IP_valid) begin // only respond if we have a valid IP address
Discovery_IP <= PC_IP; // reply to the requesting PC without changing IP etc for other commands
Discovery_MAC <= PC_MAC;
Discovery_Port <= Port;
rdaddress <= 500; // point to start of discovery reply table
frame <= 8'h02; // Discovery reply type
METIS_discover_sent <= 1'b1; // let Rx_MAC know Discovery has been responded to
state_Tx <= METIS_DISCOVERY;
end
else if (erase_done && IP_valid) begin // only respond if we have a valid IP address
erase_done_ACK <= 1'b1; // ACK the ASMI request
rdaddress <= 500; // point to start of discovery reply table
frame <= 8'h03; // erase_done reply type
state_Tx <= METIS_DISCOVERY;
end
else if (send_more && IP_valid) begin // only respond if we have a valid IP address
send_more_ACK <= 1'b1; // ACK the ASMI request
rdaddress <= 500; // point to start of discovery reply table
frame <= 8'h04; // send_more reply type
state_Tx <= METIS_DISCOVERY;
end
else if (PHY_Tx_rdused > 1023 && !Tx_reset && run) begin // wait until we have at least 1024 bytes in Tx fifo
rdaddress <= 0; // and we have completed a Metis Discovery
state_Tx <= UDP;