OpenCores
URL https://opencores.org/ocsvn/openarty/openarty/trunk

Subversion Repositories openarty

[/] [openarty/] [trunk/] [rtl/] [addemac.v] - Blame information for rev 30

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    addemac.v
4
//
5
// Project:     OpenArty, an entirely open SoC based upon the Arty platform
6
//
7
// Purpose:     To add the device hardware MAC address into a data stream
8
//              that doesn't have it.
9
//
10
// Creator:     Dan Gisselquist, Ph.D.
11
//              Gisselquist Technology, LLC
12
//
13
////////////////////////////////////////////////////////////////////////////////
14
//
15
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
16
//
17
// This program is free software (firmware): you can redistribute it and/or
18
// modify it under the terms of  the GNU General Public License as published
19
// by the Free Software Foundation, either version 3 of the License, or (at
20
// your option) any later version.
21
//
22
// This program is distributed in the hope that it will be useful, but WITHOUT
23
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
24
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25
// for more details.
26
//
27
// You should have received a copy of the GNU General Public License along
28
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
29
// target there if the PDF file isn't present.)  If not, see
30
// <http://www.gnu.org/licenses/> for a copy.
31
//
32
// License:     GPL, v3, as defined and found on www.gnu.org,
33
//              http://www.gnu.org/licenses/gpl.html
34
//
35
//
36
////////////////////////////////////////////////////////////////////////////////
37
//
38
//
39
module  addemac(i_clk, i_ce, i_en, i_cancel, i_hw_mac,
40
                i_v, i_nibble, o_v, o_nibble);
41
        input                   i_clk, i_ce, i_en, i_cancel;
42
        input           [47:0]   i_hw_mac;
43
        input                   i_v;
44
        input           [3:0]    i_nibble;
45
        output  reg             o_v;
46
        output  reg     [3:0]    o_nibble;
47
 
48
        wire    [47:0]   mac_remapped;
49
        assign  mac_remapped[47:44] = i_hw_mac[43:40];
50
        assign  mac_remapped[43:40] = i_hw_mac[47:44];
51
        assign  mac_remapped[39:36] = i_hw_mac[35:32];
52
        assign  mac_remapped[35:32] = i_hw_mac[39:36];
53
        assign  mac_remapped[31:28] = i_hw_mac[27:24];
54
        assign  mac_remapped[27:24] = i_hw_mac[31:28];
55
        assign  mac_remapped[23:20] = i_hw_mac[19:16];
56
        assign  mac_remapped[19:16] = i_hw_mac[23:20];
57
        assign  mac_remapped[15:12] = i_hw_mac[11: 8];
58
        assign  mac_remapped[11: 8] = i_hw_mac[15:12];
59
        assign  mac_remapped[ 7: 4] = i_hw_mac[ 3: 0];
60
        assign  mac_remapped[ 3: 0] = i_hw_mac[ 7: 4];
61
 
62
        reg     [47:0]   r_hw;
63
        reg     [59:0]   r_buf;
64
        reg     [5:0]    r_pos;
65
 
66
        always @(posedge i_clk)
67
        if (i_ce)
68
        begin
69
                r_buf <= { r_buf[54:0], i_v, i_nibble };
70
 
71
                if (((!i_v)&&(!o_v))||(i_cancel))
72
                begin
73
                        r_buf[ 4] <= 1'b0;
74
                        r_buf[ 9] <= 1'b0;
75
                        r_buf[14] <= 1'b0;
76
                        r_buf[19] <= 1'b0;
77
                        r_buf[24] <= 1'b0;
78
                        r_buf[29] <= 1'b0;
79
                        r_buf[34] <= 1'b0;
80
                        r_buf[39] <= 1'b0;
81
                        r_buf[44] <= 1'b0;
82
                        r_buf[49] <= 1'b0;
83
                        r_buf[54] <= 1'b0;
84
                        r_buf[59] <= 1'b0;
85
                end
86
 
87
                if ((!i_v)||(i_cancel))
88
                        r_hw <= mac_remapped;
89
                else
90
                        r_hw <= { r_hw[43:0], r_hw[47:44] };
91
 
92
                if (((!i_v)&&(!o_v))||(i_cancel))
93
                        r_pos <= 6'h0;
94
                else if ((r_pos < 6'h18 )&&(i_en))
95
                        r_pos <= r_pos + 6'h1;
96
                else if ((r_pos < 6'h20 )&&(!i_en))
97
                        r_pos <= r_pos + 6'h1;
98
 
99
                if (i_en)
100
                begin
101
                        if (((!i_v)&&(!o_v))||(i_cancel))
102
                        begin
103
                                o_v <= 1'b0;
104
                        end else begin
105
                                if (r_pos < 6'hc) // six bytes, but counted as 
106
                                begin           // nibbles
107
                                        { o_v, o_nibble } <= { i_v, i_nibble };
108
                                end else if (r_pos < 6'h18)
109
                                begin
110
                                        { o_v, o_nibble } <= { 1'b1, r_hw[47:44] };
111
                                end else
112
                                        { o_v, o_nibble } <= r_buf[59:55];
113
                        end
114
                end else if (r_pos < 6'h20)
115
                        { o_v, o_nibble } <= r_buf[19:15];
116
                else
117
                        { o_v, o_nibble } <= { i_v, i_nibble };
118
                if(i_cancel)
119
                        o_v <= 1'b0;
120
        end
121
 
122
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.