Revision 64e01dbe

b/usrp2/fifo/packet_router.v
31 31
        output [35:0] eth_out_data, output eth_out_valid, input eth_out_ready
32 32
    );
33 33

  
34
    assign wb_err_o = 1'b0;  // Unused for now
35
    assign wb_rty_o = 1'b0;  // Unused for now
36
    always @(posedge wb_clk_i)
37
        wb_ack_o <= wb_stb_i & ~wb_ack_o;
38

  
39
    ////////////////////////////////////////////////////////////////////
40
    // CPU interface to this packet router
41
    ////////////////////////////////////////////////////////////////////
42
    wire [35:0] cpu_inp_data;
43
    wire        cpu_inp_valid;
44
    wire        cpu_inp_ready;
45
    wire [35:0] cpu_out_data;
46
    wire        cpu_out_valid;
47
    wire        cpu_out_ready;
48

  
34 49
    //which buffer: 0 = CPU read buffer, 1 = CPU write buffer
35 50
    wire which_buf = wb_adr_i[BUF_SIZE+2];
36 51

  
37 52
    ////////////////////////////////////////////////////////////////////
38
    // status and controls
53
    // status and control handshakes
39 54
    ////////////////////////////////////////////////////////////////////
40
    wire eth_to_cpu_flag_ack = control[0];
55
    wire cpu_inp_hs_ctrl = control[0];
56
    wire cpu_out_hs_ctrl = control[1];
57
    wire [BUF_SIZE-1:0] cpu_out_line_count = control[BUF_SIZE-1+16:0+16];
58

  
59
    wire cpu_inp_hs_stat;
60
    assign status[0] = cpu_inp_hs_stat;
61

  
62
    wire [BUF_SIZE-1:0] cpu_inp_line_count;
63
    assign status[BUF_SIZE-1+16:0+16] = cpu_inp_line_count;
41 64

  
42
    wire eth_to_cpu_flag_rdy;
43
    assign status[0] = eth_to_cpu_flag_rdy;
65
    wire cpu_out_hs_stat;
66
    assign status[1] = cpu_out_hs_stat;
44 67

  
45 68
    ////////////////////////////////////////////////////////////////////
46 69
    // Ethernet input control
47 70
    ////////////////////////////////////////////////////////////////////
71
    //TODO: just connect eth input to cpu input for now
72
    assign cpu_inp_data = eth_inp_data;
73
    assign cpu_inp_valid = eth_inp_valid;
74
    assign eth_inp_ready = cpu_inp_ready;
48 75

  
49
    localparam ETH_TO_CPU_STATE_WAIT_SOF = 0;
50
    localparam ETH_TO_CPU_STATE_WAIT_EOF = 1;
51
    localparam ETH_TO_CPU_STATE_WAIT_ACK_HI = 2;
52
    localparam ETH_TO_CPU_STATE_WAIT_ACK_LO = 3;
76
    ////////////////////////////////////////////////////////////////////
77
    // Ethernet output control
78
    ////////////////////////////////////////////////////////////////////
79
    //TODO: just connect eth output to cpu output for now
80
    assign eth_out_data = cpu_out_data;
81
    assign eth_out_valid = cpu_out_valid;
82
    assign cpu_out_ready = eth_out_ready;
53 83

  
54
    reg [1:0] eth_to_cpu_state;
55
    reg [BUF_SIZE-1:0] eth_to_cpu_addr;
56
    wire [BUF_SIZE-1:0] eth_to_cpu_addr_next = eth_to_cpu_addr + 1'b1;
84
    ////////////////////////////////////////////////////////////////////
85
    // Interface CPU input interface to memory mapped wishbone
86
    ////////////////////////////////////////////////////////////////////
87
    localparam CPU_INP_STATE_WAIT_SOF = 0;
88
    localparam CPU_INP_STATE_WAIT_EOF = 1;
89
    localparam CPU_INP_STATE_WAIT_CTRL_HI = 2;
90
    localparam CPU_INP_STATE_WAIT_CTRL_LO = 3;
91

  
92
    reg [1:0] cpu_inp_state;
93
    reg [BUF_SIZE-1:0] cpu_inp_addr;
94
    assign cpu_inp_line_count = cpu_inp_addr;
95
    wire [BUF_SIZE-1:0] cpu_inp_addr_next = cpu_inp_addr + 1'b1;
57 96
    
58
    wire eth_to_cpu_reading_input = (
59
        eth_to_cpu_state == ETH_TO_CPU_STATE_WAIT_SOF ||
60
        eth_to_cpu_state == ETH_TO_CPU_STATE_WAIT_EOF
97
    wire cpu_inp_reading = (
98
        cpu_inp_state == CPU_INP_STATE_WAIT_SOF ||
99
        cpu_inp_state == CPU_INP_STATE_WAIT_EOF
61 100
    )? 1'b1 : 1'b0;
62 101

  
63
    wire eth_to_cpu_we = eth_to_cpu_reading_input;
64
    assign eth_inp_ready = eth_to_cpu_reading_input;
65
    assign eth_to_cpu_flag_rdy = (eth_to_cpu_state == ETH_TO_CPU_STATE_WAIT_ACK_HI)? 1'b1 : 1'b0;
66

  
67
    assign wb_err_o = 1'b0;  // Unused for now
68
    assign wb_rty_o = 1'b0;  // Unused for now
69
    always @(posedge wb_clk_i)
70
        wb_ack_o <= wb_stb_i & ~wb_ack_o;
102
    wire cpu_inp_we = cpu_inp_reading;
103
    assign cpu_inp_ready = cpu_inp_reading;
104
    assign cpu_inp_hs_stat = (cpu_inp_state == CPU_INP_STATE_WAIT_CTRL_HI)? 1'b1 : 1'b0;
71 105

  
72
    RAMB16_S36_S36 eth_to_cpu_buff(
73
        //port A = wishbone memory mapped address space
74
        .DOA(wb_dat_o),.ADDRA(wb_adr_i[BUF_SIZE+1:2]),.CLKA(wb_clk_i),.DIA(wb_dat_i),.DIPA(4'h0),
106
    RAMB16_S36_S36 cpu_inp_buff(
107
        //port A = wishbone memory mapped address space (output only)
108
        .DOA(wb_dat_o),.ADDRA(wb_adr_i[BUF_SIZE+1:2]),.CLKA(wb_clk_i),.DIA(36'b0),.DIPA(4'h0),
75 109
        .ENA(wb_stb_i & (which_buf == 1'b0)),.SSRA(0),.WEA(wb_we_i),
76
        //port B = input from ethernet packets
77
        .DOB(),.ADDRB(eth_to_cpu_addr),.CLKB(stream_clk),.DIB(eth_inp_data),.DIPB(4'h0),
78
        .ENB(eth_to_cpu_we),.SSRB(0),.WEB(eth_to_cpu_we)
110
        //port B = packet router interface to CPU (input only)
111
        .DOB(),.ADDRB(cpu_inp_addr),.CLKB(stream_clk),.DIB(cpu_inp_data),.DIPB(4'h0),
112
        .ENB(cpu_inp_we),.SSRB(0),.WEB(cpu_inp_we)
79 113
    );
80 114

  
81 115
    always @(posedge stream_clk)
82 116
    if(stream_rst) begin
83
        eth_to_cpu_state <= ETH_TO_CPU_STATE_WAIT_SOF;
84
        eth_to_cpu_addr <= 0;
117
        cpu_inp_state <= CPU_INP_STATE_WAIT_SOF;
118
        cpu_inp_addr <= 0;
85 119
    end
86 120
    else begin
87
        case(eth_to_cpu_state)
88
        ETH_TO_CPU_STATE_WAIT_SOF: begin
89
            if (eth_inp_ready & eth_inp_valid & (eth_inp_data[32] == 1'b1)) begin
90
                eth_to_cpu_state <= ETH_TO_CPU_STATE_WAIT_EOF;
91
                eth_to_cpu_addr <= eth_to_cpu_addr_next;
121
        case(cpu_inp_state)
122
        CPU_INP_STATE_WAIT_SOF: begin
123
            if (cpu_inp_ready & cpu_inp_valid & (cpu_inp_data[32] == 1'b1)) begin
124
                cpu_inp_state <= CPU_INP_STATE_WAIT_EOF;
125
                cpu_inp_addr <= cpu_inp_addr_next;
92 126
            end
93 127
        end
94 128

  
95
        ETH_TO_CPU_STATE_WAIT_EOF: begin
96
            if (eth_inp_ready & eth_inp_valid & (eth_inp_data[33] == 1'b1)) begin
97
                eth_to_cpu_state <= ETH_TO_CPU_STATE_WAIT_ACK_HI;
129
        CPU_INP_STATE_WAIT_EOF: begin
130
            if (cpu_inp_ready & cpu_inp_valid & (cpu_inp_data[33] == 1'b1)) begin
131
                cpu_inp_state <= CPU_INP_STATE_WAIT_CTRL_HI;
98 132
            end
99
            if (eth_inp_ready & eth_inp_valid) begin
100
                eth_to_cpu_addr <= eth_to_cpu_addr_next;
133
            if (cpu_inp_ready & cpu_inp_valid) begin
134
                cpu_inp_addr <= cpu_inp_addr_next;
101 135
            end
102 136
        end
103 137

  
104
        ETH_TO_CPU_STATE_WAIT_ACK_HI: begin
105
            if (eth_to_cpu_flag_ack == 1'b1) begin
106
                eth_to_cpu_state <= ETH_TO_CPU_STATE_WAIT_ACK_LO;
138
        CPU_INP_STATE_WAIT_CTRL_HI: begin
139
            if (cpu_inp_hs_ctrl == 1'b1) begin
140
                cpu_inp_state <= CPU_INP_STATE_WAIT_CTRL_LO;
107 141
            end
108 142
        end
109 143

  
110
        ETH_TO_CPU_STATE_WAIT_ACK_LO: begin
111
            if (eth_to_cpu_flag_ack == 0'b1) begin
112
                eth_to_cpu_state <= ETH_TO_CPU_STATE_WAIT_SOF;
144
        CPU_INP_STATE_WAIT_CTRL_LO: begin
145
            if (cpu_inp_hs_ctrl == 1'b0) begin
146
                cpu_inp_state <= CPU_INP_STATE_WAIT_SOF;
113 147
            end
148
            cpu_inp_addr <= 0; //reset the address counter
114 149
        end
115 150

  
116
        endcase //eth_to_cpu_state
151
        endcase //cpu_inp_state
117 152
    end
118 153

  
154
    ////////////////////////////////////////////////////////////////////
155
    // Interface CPU output interface to memory mapped wishbone
156
    ////////////////////////////////////////////////////////////////////
157
    localparam CPU_OUT_STATE_WAIT_CTRL_HI = 0;
158
    localparam CPU_OUT_STATE_WAIT_CTRL_LO = 1;
159
    localparam CPU_OUT_STATE_UNLOAD = 2;
160

  
161
    reg [1:0] cpu_out_state;
162
    reg [BUF_SIZE-1:0] cpu_out_addr;
163
    wire [BUF_SIZE-1:0] cpu_out_addr_next = cpu_out_addr + 1'b1;
164

  
165
    reg [BUF_SIZE-1:0] cpu_out_line_count_reg;
166

  
167
    reg cpu_out_flag_sof;
168
    reg cpu_out_flag_eof;
169
    assign cpu_out_data[35:32] = {2'b0, cpu_out_flag_eof, cpu_out_flag_sof};
170

  
171
    assign cpu_out_valid = (cpu_out_state == CPU_OUT_STATE_UNLOAD)? 1'b1 : 1'b0;
172
    assign cpu_out_hs_stat = (cpu_out_state == CPU_OUT_STATE_WAIT_CTRL_HI)? 1'b1 : 1'b0;
173

  
174
    RAMB16_S36_S36 cpu_out_buff(
175
        //port A = wishbone memory mapped address space (input only)
176
        .DOA(),.ADDRA(wb_adr_i[BUF_SIZE+1:2]),.CLKA(wb_clk_i),.DIA(wb_dat_i),.DIPA(4'h0),
177
        .ENA(wb_stb_i & (which_buf == 1'b1)),.SSRA(0),.WEA(wb_we_i),
178
        //port B = packet router interface from CPU (output only)
179
        .DOB(cpu_out_data[31:0]),.ADDRB(cpu_out_addr),.CLKB(stream_clk),.DIB(36'b0),.DIPB(4'h0),
180
        .ENB(1'b1),.SSRB(0),.WEB(1'b0)
181
    );
182

  
183
    always @(posedge stream_clk)
184
    if(stream_rst) begin
185
        cpu_out_state <= CPU_OUT_STATE_WAIT_CTRL_HI;
186
        cpu_out_addr <= 0;
187
    end
188
    else begin
189
        case(cpu_out_state)
190
        CPU_OUT_STATE_WAIT_CTRL_HI: begin
191
            if (cpu_out_hs_ctrl == 1'b1) begin
192
                cpu_out_state <= CPU_OUT_STATE_WAIT_CTRL_LO;
193
            end
194
            cpu_out_line_count_reg <= cpu_out_line_count;
195
            cpu_out_addr <= 0; //reset the address counter
196
        end
197

  
198
        CPU_OUT_STATE_WAIT_CTRL_LO: begin
199
            if (cpu_out_hs_ctrl == 1'b0) begin
200
                cpu_out_state <= CPU_OUT_STATE_UNLOAD;
201
                cpu_out_addr <= cpu_out_addr_next;
202
            end
203
            cpu_out_flag_sof <= 1'b1;
204
            cpu_out_flag_eof <= 1'b0;
205
        end
206

  
207
        CPU_OUT_STATE_UNLOAD: begin
208
            if (cpu_out_ready & cpu_out_valid) begin
209
                cpu_out_addr <= cpu_out_addr_next;
210
                cpu_out_flag_sof <= 1'b0;
211
                if (cpu_out_addr == cpu_out_line_count_reg) begin
212
                    cpu_out_flag_eof <= 1'b1;
213
                end
214
                else begin
215
                    cpu_out_flag_eof <= 1'b0;
216
                end
217
                if (cpu_out_flag_eof) begin
218
                    cpu_out_state <= CPU_OUT_STATE_WAIT_CTRL_HI;
219
                end
220
            end
221
        end
222

  
223
        endcase //cpu_out_state
224
    end
119 225

  
120 226
endmodule // packet_router

Also available in: Unified diff