diff options
| author | Private Island Networks Inc <opensource@privateisland.tech> | 2026-11-24 15:50:06 -0500 |
|---|---|---|
| committer | Private Island Networks Inc <opensource@privateisland.tech> | 2026-11-24 15:50:06 -0500 |
| commit | 0bc7b0702ca2d99b853b5dcb3f0524d2cad78cd5 (patch) | |
| tree | 2927b6078965f8b9876a7e0795edb244a23b0fe6 /src | |
| parent | 7dccad3e21126fdbb3953f65082bbb185c39011f (diff) | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/cont_params.v | 3 | ||||
| -rw-r--r-- | src/controller.v | 9 | ||||
| -rw-r--r-- | src/pkt_gen.v | 152 |
3 files changed, 161 insertions, 3 deletions
diff --git a/src/cont_params.v b/src/cont_params.v index c9f85c2..c1acbac 100644 --- a/src/cont_params.v +++ b/src/cont_params.v @@ -47,7 +47,8 @@ localparam MSG_PKT_FILTER_ADDR = 16'h0200; localparam MSG_SWITCH_ADDR = 16'h0500; localparam MSG_MDIO_ADDR = 16'h0600; localparam MSG_MLE_ADDR = 16'h0700; -localparam MSG_INVALID_ADDR = 16'h0800; +localparam MSG_PKT_GEN_ADDR = 16'h0800; +localparam MSG_INVALID_ADDR = 16'h0900; localparam HF_TX_WR_PTR_ADDR = 16'd0; diff --git a/src/controller.v b/src/controller.v index e30d461..96c4f20 100644 --- a/src/controller.v +++ b/src/controller.v @@ -48,6 +48,7 @@ module controller #(parameter MDIO_ADDR_SZ = 7, parameter NUM_PHYS=3) output reg pkt_filter_sel, output reg mac_sel, output reg mle_sel, + output reg pkt_gen_sel, output reg hf_ptrs_sel, output reg hf_tx_sel, output reg hf_rx_sel, @@ -486,7 +487,7 @@ module controller #(parameter MDIO_ADDR_SZ = 7, parameter NUM_PHYS=3) mem_cmd <= 1'b0; else if (cont_state == CONT_ST_IDLE && !rx_msg_captured) mem_cmd <= 1'b0; - else if (rx_msg_captured && msg_addr[15:8] >= MSG_MAC_ADDR[15:8] && msg_addr[15:8] < MSG_MLE_ADDR[15:8]) + else if (rx_msg_captured && msg_addr[15:8] >= MSG_MAC_ADDR[15:8] && msg_addr[15:8] < MSG_INVALID_ADDR[15:8]) mem_cmd <= 1'b1; // Primary Memory Controller Actions @@ -498,6 +499,7 @@ module controller #(parameter MDIO_ADDR_SZ = 7, parameter NUM_PHYS=3) mac_sel <= 1'b0; mle_sel <= 1'b0; pkt_filter_sel <= 1'b0; + pkt_gen_sel <= 1'b0; hf_ptrs_sel <= 1'b0; hf_tx_sel <= 1'b0; hf_rx_sel <= 1'b0; @@ -534,6 +536,7 @@ module controller #(parameter MDIO_ADDR_SZ = 7, parameter NUM_PHYS=3) MSG_MAC_ADDR[15:8]: mac_sel <= 1'b1; MSG_PKT_FILTER_ADDR[15:8]: pkt_filter_sel <= 1'b1; MSG_MLE_ADDR[15:8]: mle_sel <= 1'b1; + MSG_PKT_GEN_ADDR[15:8]: pkt_gen_sel <= 1'b1; endcase end end @@ -544,6 +547,7 @@ module controller #(parameter MDIO_ADDR_SZ = 7, parameter NUM_PHYS=3) mac_sel <= 1'b0; mle_sel <= 1'b0; pkt_filter_sel <= 1'b0; + pkt_gen_sel <= 1'b0; end else if (mem_state == MEM_ST_REPLY_START && tx_fifo_empty) begin // write byte cnt hf_ptrs_sel <= 1'b1; @@ -606,6 +610,7 @@ module controller #(parameter MDIO_ADDR_SZ = 7, parameter NUM_PHYS=3) hf_ptrs_sel <= 1'b0; hf_tx_sel <= 1'b0; hf_rx_sel <= 1'b0; + pkt_gen_sel <= 1'b0; end // rx_cnt @@ -703,7 +708,7 @@ module controller #(parameter MDIO_ADDR_SZ = 7, parameter NUM_PHYS=3) if (!rstn) begin mac_addr <= 2'd0; mdio_mux_sel <= 2'b00; - pkt_filter_addr <= 16'd0; + pkt_filter_addr <= 16'h2001; // default is pkt_filter_21 end else if (rx_msg_captured && !msg_error && msg_type == MSG_TYPE_WRITE) begin if (msg_addr==MAC_ADDR) diff --git a/src/pkt_gen.v b/src/pkt_gen.v new file mode 100644 index 0000000..028728c --- /dev/null +++ b/src/pkt_gen.v @@ -0,0 +1,152 @@ +/* + * pkt_gen.v + * + * Copyright (C) 2026 Private Island Networks Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * function: programmable packet generator + * + * see https://privateisland.tech/dev/pi-pkt-gen + * + */ + +module pkt_gen #(parameter DATAW = 16) +( + input rstn, + + // controller interface + input cont_clk, + input cont_sel, + input cont_we, + input [15:0] cont_addr, + input [DATAW-1:0] cont_d_i, + output reg [DATAW-1:0] cont_d_o, + output cont_tgt_ready, + + // tx switch interface + input sw_fifo_clk, + output reg sw_fifo_empty_o, + input sw_fifo_re_i, + output [8:0] sw_fifo_d_o, + output [10:0] sw_byte_cnt_o +); + + /*** local params ***/ + localparam PKT_GEN_ENABLE_ADDR = 'h0; + + /* temp params, will become default */ + localparam PKT_SZ = 'd98; // ICMP Test Packet + localparam PKT_INTV = 'd256; + + /*** variables ***/ + reg pkt_gen_en, pkt_gen_en_m1, pkt_gen_en_m2; + reg pkt_gen_active; + reg[9:0] pkt_intv_cnt, data_cnt; // packet interval and data byte counter + + + /*** Controller Interface ***/ + + // enable / disable packet generation + always @(posedge cont_clk, negedge rstn) + if (!rstn) + pkt_gen_en <= 1'b0; + else if (cont_we && cont_sel && cont_addr == PKT_GEN_ENABLE_ADDR) + pkt_gen_en <= cont_d_i[0]; + + // Controller Read Data Mux + always @(posedge cont_clk, negedge rstn) + if (!rstn) + cont_d_o <= 16'hcccc; + else + case (cont_addr) + PKT_GEN_ENABLE_ADDR: cont_d_o <= pkt_gen_en; + default: cont_d_o <= cont_d_o; + endcase + + // meta regs for pkt_gen_en from controller + always @(posedge sw_fifo_clk, negedge rstn) + if (!rstn) begin + pkt_gen_en_m1 <= 1'b0; + pkt_gen_en_m2 <= 1'b0; + end + else begin + pkt_gen_en_m1 <= pkt_gen_en; + pkt_gen_en_m2 <= pkt_gen_en_m1; + end + + /*** Packet Generation Logic ***/ + + // Simple Binary State Machine for Now + always @(posedge sw_fifo_clk, negedge rstn) + if (!rstn) + pkt_gen_active <= 1'b0; + else if (!pkt_gen_en_m2) + pkt_gen_active <= 1'b0; + else if (pkt_gen_en_m2 && pkt_gen_active && data_cnt == PKT_SZ) + pkt_gen_active <= 1'b0; + else if (pkt_gen_en_m2 && !pkt_gen_active && pkt_intv_cnt == PKT_INTV) + pkt_gen_active <= 1'b1; + + // pkt_intv_cnt + always @(posedge sw_fifo_clk, negedge rstn) + if (!rstn) + pkt_intv_cnt <= 10'd0; + else if (!pkt_gen_en_m2 || pkt_gen_active) + pkt_intv_cnt <= 10'd0; + else if (pkt_intv_cnt < PKT_INTV) + pkt_intv_cnt <= pkt_intv_cnt + 1'b1; + + // data_cnt + always @(posedge sw_fifo_clk, negedge rstn) + if (!rstn) + data_cnt <= 10'd0; + else if (!pkt_gen_active) + data_cnt <= 10'd0; + else if (sw_fifo_re_i && data_cnt < PKT_SZ) + data_cnt <= data_cnt + 1'b1; + + // sw_fifo_empty_o + always @(posedge sw_fifo_clk, negedge rstn) + if (!rstn) + sw_fifo_empty_o <= 1'b1; + else if (pkt_gen_active) + sw_fifo_empty_o <= 1'b0; + else + sw_fifo_empty_o <= 1'b1; + + // tie offs for now + assign cont_tgt_ready = 1'b1; + assign sw_byte_cnt_o = PKT_SZ; + + dpram_inf #(.ADDR_WIDTH(10), .DPRAM_INIT("packet_gen.txt")) packet_mem( + .rstn(rstn), + .a_clk(cont_clk), + .a_clk_e(cont_sel), + .a_we(1'b0), // TODO: connect DPRAM with controller: cont_we + .a_oe(1'b0), + .a_addr(cont_addr[9:0]), + .a_din(cont_d_i[8:0]), + .a_dout(), + // port B + .b_clk(sw_fifo_clk), + .b_clk_e(1'b1), + .b_we(1'b0), + .b_oe(sw_fifo_re_i), + .b_addr(data_cnt), + .b_din(9'h0), + .b_dout(sw_fifo_d_o) + ); + + +endmodule
\ No newline at end of file |

