diff options
| author | Private Island Networks Inc <opensource@privateisland.tech> | 2026-11-24 15:46:56 -0500 |
|---|---|---|
| committer | Private Island Networks Inc <opensource@privateisland.tech> | 2026-11-24 15:46:56 -0500 |
| commit | 7dccad3e21126fdbb3953f65082bbb185c39011f (patch) | |
| tree | 4aaa006378ea8cb04975819656e24b1ebbe37ccb | |
| parent | 08aaf3243101cd35e6350fcfddecda6fcddeff09 (diff) | |
mle: add rx variables for mle processing
| -rw-r--r-- | src/ethernet_params.v | 5 | ||||
| -rw-r--r-- | src/ipv4_tx_mle.v | 2 | ||||
| -rw-r--r-- | src/mac_rgmii.v | 254 | ||||
| -rw-r--r-- | src/ml_engine.v | 247 | ||||
| -rw-r--r-- | src/mle_params.v | 3 |
5 files changed, 364 insertions, 147 deletions
diff --git a/src/ethernet_params.v b/src/ethernet_params.v index 406f46f..8baa669 100644 --- a/src/ethernet_params.v +++ b/src/ethernet_params.v @@ -26,8 +26,9 @@ localparam TX_SRC_SEL_PHY0 = 3'b000, TX_SRC_SEL_PHY1 = 3'b001, TX_SRC_SEL_PHY2 = 3'b010, - TX_SRC_SEL_MLE = 3'b110, - TX_SRC_SEL_UC = 3'b111; + TX_SRC_SEL_MLE = 3'b100, + TX_SRC_SEL_UC = 3'b101, + TX_SRC_SEL_PKT_GEN = 3'b110; localparam PHY_TYPE_SGMII = 2'b00, PHY_TYPE_RGMII = 2'b01, diff --git a/src/ipv4_tx_mle.v b/src/ipv4_tx_mle.v index 17749ff..3085aad 100644 --- a/src/ipv4_tx_mle.v +++ b/src/ipv4_tx_mle.v @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * function: Layer 3 (and 4) Support for Controller Transmit + * function: Layer 3 (and 4) Support for MLE Transmit * */ diff --git a/src/mac_rgmii.v b/src/mac_rgmii.v index b6ae629..0a1109f 100644 --- a/src/mac_rgmii.v +++ b/src/mac_rgmii.v @@ -20,11 +20,12 @@ * */ -module mac_rgmii #(parameter PHY_NUM=0) ( +module mac_rgmii #(parameter PHY_NUM=0, MLE_EOD_FLAG=0) ( input rstn, input phy_resetn, // The external PHY has its reset signal asserted - input rx_clk, // rx_clk + input rx_clk, // input tx_clk, + input mle_clk, input tap_port, // Control Interface @@ -37,12 +38,10 @@ module mac_rgmii #(parameter PHY_NUM=0) ( output cont_tgt_ready, // ML Engine Interface - input mle_active, + output reg mle_if_empty, input mle_if_enable, - input mle_if_oe, output reg mle_if_we, - output reg mle_if_empty, - output [8:0] mle_if_d_o, + output reg [8:0] mle_if_d_o, // Line State input fixed_speed, // 0 = 100 MBit, 1 = GigE @@ -76,7 +75,7 @@ module mac_rgmii #(parameter PHY_NUM=0) ( // MAC RX / FIFO Write output rx_fifo_we, output [8:0] rx_fifo_d, - output rx_keep, + output reg rx_trigger, output reg rx_wr_done, output reg [10:0] rx_byte_cnt, output reg rx_idle, @@ -150,6 +149,12 @@ module mac_rgmii #(parameter PHY_NUM=0) ( TX_ST_EOP=4'h8, TX_ST_9=4'h9, TX_ST_A=4'ha, TX_ST_B=4'hb, TX_ST_C=4'hc, TX_ST_D=4'hd, TX_ST_E=4'he, TX_ST_F=4'hf; + localparam MAX_IPG_CNT = 16'hffff; + + localparam MLE_ST_IDLE = 3'h0, MLE_ST_WAIT = 3'h1, MLE_ST_WR_ID = 3'h2, MLE_ST_WR_CODE = 3'h3, MLE_ST_XFER = 3'h4, MLE_ST_DONE = 3'h5; + localparam MLE_CNT_START_XFER = 6'd4; + localparam MLE_CNT_DONE = 6'd10; + // Controller Address Space localparam RX_PKT_CNT_ADDR = 16'h0000, @@ -194,12 +199,25 @@ module mac_rgmii #(parameter PHY_NUM=0) ( reg [2:0] rx_enet_bcast_cnt; // ML Engine - reg [3:0] mle_if_cnt; - reg [8:0] mle_if_d; + // rx_clk domain: + reg mle_enable_m1, mle_enable_m2; + reg mle_start; + reg [7:0] mle_pkt_cnt, mle_pkt_cnt_o; + reg [31:0] mle_rx_byte_cnt, mle_rx_byte_cnt_o; + reg [31:0] mle_rx_ipg_cnt, mle_rx_ipg_cnt_o; + + // mle_clk domain: + reg mle_start_m1, mle_start_m2; + reg [2:0] mle_state; + reg mle_rx_eop_m1, mle_rx_eop_m2; + reg [5:0] mle_cnt; - // Metrics - reg [15:0] rx_pkt_cnt; - reg [15:0] tx_pkt_cnt; + // Controller Mapped Metrics + reg [15:0] rx_cont_pkt_cnt; + reg [15:0] tx_cont_pkt_cnt; + + // MLE Metrics + reg [15:0] rx_ipg_cnt; /* @@ -215,8 +233,8 @@ module mac_rgmii #(parameter PHY_NUM=0) ( cont_d_o <= 16'hcccc; else case (cont_addr) - RX_PKT_CNT_ADDR: cont_d_o <= rx_pkt_cnt; - TX_PKT_CNT_ADDR: cont_d_o <= tx_pkt_cnt; + RX_PKT_CNT_ADDR: cont_d_o <= rx_cont_pkt_cnt; + TX_PKT_CNT_ADDR: cont_d_o <= tx_cont_pkt_cnt; default: cont_d_o <= cont_d_o; endcase @@ -228,46 +246,158 @@ module mac_rgmii #(parameter PHY_NUM=0) ( * ML Engine Interface * */ - - // mle_if_cnt: - // TODO: write cnt at end, rework this logic and make it more meaningful - always @(posedge tx_clk, negedge rstn) + + // Meta regs for mle_if_enable + always @(posedge rx_clk, negedge rstn) + if (!rstn) begin + mle_enable_m1 <= 1'b0; + mle_enable_m2 <= 1'b0; + end + else begin + mle_enable_m1 <= mle_if_enable; + mle_enable_m2 <= mle_enable_m1; + end + + // mle_start: one shot to trigger data exchange and locking between CDC domains + always @(posedge rx_clk, negedge rstn) + if(!rstn) + mle_start <= 1'b0; + else if (!mle_enable_m2 && mle_enable_m1) + mle_start <= 1'b1; + else + mle_start <= 1'b0; + + // capture byte cnt (for now). + always @(posedge rx_clk, negedge rstn) if(!rstn) begin - mle_if_cnt <= 4'd0; - mle_if_empty <= 1'b1; - mle_if_we <= 1'b0; + mle_pkt_cnt <= 'd0; + mle_rx_ipg_cnt <= 'd0; + mle_rx_byte_cnt <= 'd0; + end + else if (rx_eop && mle_start) begin + mle_pkt_cnt <= 'd1; + mle_rx_ipg_cnt <= rx_ipg_cnt; + mle_rx_byte_cnt <= rx_byte_cnt; end else if (rx_eop) begin - mle_if_cnt <= 4'd4; - mle_if_empty <= 1'b0; - mle_if_we <= 1'b0; + mle_pkt_cnt <= mle_pkt_cnt + 1'b1; + mle_rx_ipg_cnt <= mle_rx_ipg_cnt + rx_ipg_cnt; + mle_rx_byte_cnt <= rx_byte_cnt + mle_rx_byte_cnt; end - else if (mle_if_cnt > 4'd0 && mle_if_enable) begin - mle_if_cnt <= mle_if_cnt - 1'b1; - mle_if_empty <= 1'b0; - mle_if_we <= 1'b1; + else if (mle_start) begin + mle_pkt_cnt <= 'd0; + mle_rx_ipg_cnt <= 'd0; + mle_rx_byte_cnt <= 'd0; + end + + // update and lock the data, so it can be clocked out by the MLE + always @(posedge rx_clk, negedge rstn) + if(!rstn) begin + mle_pkt_cnt_o <= 'd0; + mle_rx_ipg_cnt_o <= 'd0; + mle_rx_byte_cnt_o <= 'd0; + end + else if (mle_start) begin + mle_pkt_cnt_o <= mle_pkt_cnt; + mle_rx_ipg_cnt_o <= mle_rx_ipg_cnt; + mle_rx_byte_cnt_o <= mle_rx_byte_cnt; + end + + // Meta regs for mle_start + always @(posedge mle_clk, negedge rstn) + if (!rstn) begin + mle_start_m1 <= 1'b0; + mle_start_m2 <= 1'b0; + end + else begin + mle_start_m1 <= mle_start; + mle_start_m2 <= mle_start_m1; end - else if (mle_if_cnt == 'd0 && mle_if_enable) begin + + // mle_state: state machine for transferring out data to the MLE + always @(posedge mle_clk, negedge rstn) + if (!rstn) + mle_state <= MLE_ST_IDLE; + else + case(mle_state) + MLE_ST_IDLE: if (mle_start_m2) + mle_state <= MLE_ST_WAIT; + MLE_ST_WAIT: if (mle_cnt == MLE_CNT_START_XFER) + mle_state <= MLE_ST_WR_ID; + MLE_ST_WR_ID: + mle_state <= MLE_ST_WR_CODE; + MLE_ST_WR_CODE: + mle_state <= MLE_ST_XFER; + MLE_ST_XFER: if (mle_cnt == MLE_CNT_DONE) + mle_state <= MLE_ST_DONE; + MLE_ST_DONE: + mle_state <= MLE_ST_IDLE; + default: + mle_state <= mle_state; + endcase + + + // mle_cnt: + always @(posedge mle_clk, negedge rstn) + if(!rstn) + mle_cnt <= 4'd0; + else if (mle_start_m2) + mle_cnt <= 4'd0; + else if (mle_state != MLE_ST_IDLE && mle_cnt <= MLE_CNT_DONE) + mle_cnt <= mle_cnt + 1'b1; + + // mle_rx_eop: CDC one shot in the tx_clock domain + always @(posedge mle_clk, negedge rstn) + if (!rstn) begin + mle_rx_eop_m1 <= 1'b0; + mle_rx_eop_m2 <= 1'b0; + end + else begin + mle_rx_eop_m1 <= rx_eop; + mle_rx_eop_m2 <= mle_rx_eop_m1; + end + + // mle_if_empty: indicate we have data once a packet has finished being received + always @(posedge tx_clk, negedge rstn) + if(!rstn) mle_if_empty <= 1'b1; + else if (mle_rx_eop_m2) + mle_if_empty <= 1'b0; + else if (mle_state == MLE_ST_DONE) + mle_if_empty <= 1'b1; + + // mle_if_we + always @(posedge tx_clk, negedge rstn) + if(!rstn) mle_if_we <= 1'b0; - end - + else if (mle_start_m2) + mle_if_we <= 1'b0; + else if (mle_state >= MLE_ST_WR_ID && mle_state <= MLE_ST_XFER) + mle_if_we <= 1'b1; + else + mle_if_we <= 1'b0; - // mle_if_d: - always @(posedge tx_clk, negedge rstn) - if(!rstn) - mle_if_d <= 'd0; - else if (mle_if_enable) begin - if (mle_if_cnt > 4'd1) - mle_if_d <= mle_if_d + 1'b1; - else if (mle_if_cnt == 4'd1) - mle_if_d <= (mle_if_d + 1'b1) | 9'h100; - else - mle_if_d <= 'd0; - end - - assign mle_if_d_o = mle_if_d + PHY_NUM; + // mle_if_d_o[7:0] data out mux + always @(*) + if (mle_state > MLE_ST_WR_ID && mle_state <= MLE_ST_DONE) + case(mle_cnt) + MLE_CNT_START_XFER+2: mle_if_d_o[7:0] = PHY_NUM; + MLE_CNT_START_XFER+3: mle_if_d_o[7:0] = 8'hef; + MLE_CNT_START_XFER+4: mle_if_d_o[7:0] = mle_rx_byte_cnt_o[31:24]; + MLE_CNT_START_XFER+5: mle_if_d_o[7:0] = mle_rx_byte_cnt_o[23:16]; + MLE_CNT_START_XFER+6: mle_if_d_o[7:0] = mle_rx_byte_cnt_o[15:8]; + MLE_CNT_START_XFER+7: mle_if_d_o[7:0] = mle_rx_byte_cnt_o[7:0]; + default: mle_if_d_o[7:0] = 8'h00; + endcase + else + mle_if_d_o[7:0] = 8'h00; + // mle_d_[8] end of data flag + always @(*) + if (MLE_EOD_FLAG && mle_state == MLE_ST_DONE) + mle_if_d_o[8] <= 1'b1; + else + mle_if_d_o[8] <= 1'b0; /* @@ -402,6 +532,7 @@ module mac_rgmii #(parameter PHY_NUM=0) ( /* * rx_fifo_we + * asserted first byte of Dest MAC Address through second byte of FCS */ assign rx_fifo_we = ( rx_sample && ( rx_state >= RX_ST_SFD && rx_state <= RX_ST_DATA_DONE1 ) ) ? 1'b1 : 1'b0; @@ -465,11 +596,15 @@ module mac_rgmii #(parameter PHY_NUM=0) ( rx_ipv4_arp <= 1'b0; /* - * rx_keep flag - * signals must be one shot + * rx_trigger: must be one shot */ - // assign rx_keep = rx_enet_bcast | rx_ipv4_arp; - assign rx_keep = rx_state == RX_ST_MAC_TYPE1; + always @(posedge rx_clk, negedge rstn) + if (!rstn) + rx_trigger <= 1'b0; + else if (rx_state == RX_ST_DATA && rx_byte_cnt == 11'd20) + rx_trigger <= 1'b1; + else + rx_trigger <= 1'b0; // rx_error always @(*) @@ -479,6 +614,15 @@ module mac_rgmii #(parameter PHY_NUM=0) ( rx_error = 1'b1; else rx_error = 1'b0; + + /* rx_ipg_cnt */ + always @(posedge rx_clk, negedge rstn) + if (!rstn) + rx_ipg_cnt <= 16'd0; + else if ( rx_eop ) // sync with MLE processing + rx_ipg_cnt <= 16'd0; + else if ( rx_state == RX_ST_IDLE && rx_ipg_cnt < MAX_IPG_CNT) // don't let it roll over + rx_ipg_cnt <= rx_ipg_cnt + 'b1; /* rx_byte_cnt */ always @(posedge rx_clk, negedge rstn) @@ -520,7 +664,7 @@ module mac_rgmii #(parameter PHY_NUM=0) ( if (rx_pkt_length >= 12'd46) rx_packet_complete = (rx_sample && rx_state >= RX_ST_DATA && rx_pkt_length == rx_byte_cnt); else - rx_packet_complete = (rx_sample && rx_state >= RX_ST_DATA && rx_byte_cnt == 12'd46); + rx_packet_complete = (rx_sample && rx_state >= RX_ST_DATA && rx_byte_cnt == 11'd46); // FIFO data interface assign rx_fifo_d[7:0] = rx_d_m1; @@ -580,12 +724,12 @@ module mac_rgmii #(parameter PHY_NUM=0) ( else rx_active <= 1'b0; - // rx_pkt_cnt + // rx_cont_pkt_cnt: # of received packets always @(posedge rx_clk or negedge rstn) if (!rstn) - rx_pkt_cnt <= 16'd0; + rx_cont_pkt_cnt <= 16'd0; else if (rx_eop) - rx_pkt_cnt <= rx_pkt_cnt + 1'b1; + rx_cont_pkt_cnt <= rx_cont_pkt_cnt + 1'b1; always @(*) if (mode_1Gbit && (rx_state > RX_ST_SFD && rx_state <= RX_ST_DATA_DONE0) ) @@ -992,9 +1136,9 @@ module mac_rgmii #(parameter PHY_NUM=0) ( always @(posedge tx_clk, negedge rstn) if (!rstn) - tx_pkt_cnt <= 16'd0; + tx_cont_pkt_cnt <= 16'd0; else if (tx_eop) - tx_pkt_cnt <= tx_pkt_cnt + 1'b1; + tx_cont_pkt_cnt <= tx_cont_pkt_cnt + 1'b1; diff --git a/src/ml_engine.v b/src/ml_engine.v index 9bde7fe..bcf6a10 100644 --- a/src/ml_engine.v +++ b/src/ml_engine.v @@ -33,22 +33,22 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) input [15:0] cont_addr, input [15:0] cont_d_i, output reg [15:0] cont_d_o, - output cont_tgt_ready, - - // module interface - output reg evt_start, - output reg evt_active, - output reg [NUM_IF-1:0] enable, - input [NUM_IF-1:0] empty, - input clk_e, - input we, - input [8:0] d_i, - - // switch interface - output reg fifo_empty_o, - input fifo_re, - output [8:0] fifo_d_o, - output [10:0] byte_cnt + output cont_tgt_ready_o, + + // rx module interface + output reg rx_evt_start_o, + output reg rx_evt_active_o, + output reg [NUM_IF-1:0] rx_enable_o, + input [NUM_IF-1:0] rx_empty_i, + input rx_clk_e_i, + input rx_we_i, + input [8:0] rx_d_i, + + // tx switch interface + 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 // action interface @@ -61,9 +61,11 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) `undef INCLUDED `define DIRECT_OUTPUT // this disables internal processing and second DPRAM +// `define TEST_MODE // transmit MLP dataset + // Define the size of a block (same for dpram_s0 and s1) localparam BLOCK_OFFSET = 'h80; // 128 bytes - localparam BLOCK_OFFSET_SHIT = 'd7; // Left shift to multiple by 128 + localparam BLOCK_OFFSET_SHIFT = 'd7; // Left shift to multiply by 128 `ifdef SIMULATION localparam EVT_CNT_DELAY_1 = 32'h0000_0010, @@ -76,14 +78,14 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) EVT_CNT_DELAY_2 = 32'h0000_0020, EVT_CNT_OUT = 32'h0000_0030, EVT_CNT_STOP = 32'h0010_0000, - EVT_CNT_MAX = 32'h0040_0000; // Sets max event interval + EVT_CNT_MAX = 32'h0773_5940; // Sets time-based event interval at 1 sec `endif - + // Controller I/F Addresses localparam MLE_ENABLE_ADDR = 'h0; - // FSM States: two loops: event/block and data unit (DU) + // FSM_0:2 States: two loops: event/block and data unit (DU) localparam MLE_ST_IDLE=4'h0, MLE_ST_START=4'h1, MLE_ST_EVT_START = 4'h2, MLE_ST_DU_START = 4'h3, MLE_ST_DU_CONT = 4'h4, MLE_ST_DU_DONE = 4'h5, MLE_ST_EVT_DONE = 4'h6; @@ -98,8 +100,6 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) reg[31:0] evt_counter; reg evt_delay_1, evt_delay_2, evt_delay_out; - reg [NUM_IF-1:0] empty_m1, empty_m2; - reg [3:0] mle_0_state, mle_1_state, mle_2_state, mle_3_state; reg [2:0] mle_3_hdr_cnt; reg [7:0] mle_3_hdr, mle_3_token; @@ -127,6 +127,13 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) reg fifo_empty; reg fifo_d_out_flag; +`ifdef TEST_MODE + reg [7:0] rom_mux_d; + wire [31:0] test_x, test_y; // fp32 values + reg [2:0] rom_cnt; + reg [6:0] rom_addr; +`endif + // Debug reg [8*12:1] mle_0_state_str; reg [8*12:1] mle_3_state_str; @@ -146,12 +153,12 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) cont_d_o <= 16'hcccc; else case (cont_addr) - MLE_ENABLE_ADDR: cont_d_o <= mle_enable; + MLE_ENABLE_ADDR: cont_d_o <= mle_enable_m2; default: cont_d_o <= cont_d_o; endcase // TODO: add logic to prevent controller reading metastable data - assign cont_tgt_ready = 1'b1; + assign cont_tgt_ready_o = 1'b1; // mle_enable: enable / disable the MLE @@ -171,6 +178,7 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) mle_enable_m1 <= mle_enable; mle_enable_m2 <= mle_enable_m1; end + /****************************************************** @@ -187,23 +195,23 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) else evt_counter <= evt_counter + 1'b1; - // evt_start: + // rx_evt_start_o: always @(posedge clk, negedge rstn) if( !rstn ) - evt_start <= 'd0; + rx_evt_start_o <= 'd0; else if (mle_enable_m2 && evt_counter == 32'd0) - evt_start <= 1'b1; + rx_evt_start_o <= 1'b1; else - evt_start <= 1'b0; + rx_evt_start_o <= 1'b0; - // evt_active: + // rx_evt_active_o: always @(posedge clk, negedge rstn) if( !rstn ) - evt_active <= 'd0; + rx_evt_active_o <= 'd0; else if (evt_counter == EVT_CNT_STOP) - evt_active <= 1'b0; - else if (evt_start) - evt_active <= 'd1; + rx_evt_active_o <= 1'b0; + else if (rx_evt_start_o) + rx_evt_active_o <= 'd1; /****************************************************** @@ -215,17 +223,17 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) always @(posedge clk, negedge rstn) if (!rstn) mle_0_state <= MLE_ST_IDLE; - else + else begin : FSM_0 case (mle_0_state) - MLE_ST_IDLE: if (evt_start && !(&empty)) + MLE_ST_IDLE: if (rx_evt_start_o && !(&rx_empty_i)) // Is a DU available? mle_0_state <= MLE_ST_EVT_START; - MLE_ST_EVT_START: if (!(&empty)) // Is a DU available? + MLE_ST_EVT_START: mle_0_state <= MLE_ST_DU_START; MLE_ST_DU_START: mle_0_state <= MLE_ST_DU_CONT; - MLE_ST_DU_CONT: if (d_i[8]) // Done flag set? + MLE_ST_DU_CONT: if (rx_d_i[8]) // Done flag set? mle_0_state <= MLE_ST_DU_DONE; - MLE_ST_DU_DONE: if (&empty) // Is another DU available? + MLE_ST_DU_DONE: if (&rx_empty_i) // Is another DU available? mle_0_state <= MLE_ST_EVT_DONE; else mle_0_state <= MLE_ST_DU_START; @@ -233,6 +241,7 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) mle_0_state <= MLE_ST_IDLE; default: mle_0_state <= mle_0_state; endcase + end always @(*) @@ -252,20 +261,20 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) always @(posedge clk, negedge rstn) if( !rstn ) wr_block0 <= 'd1; - else if (evt_start) + else if (rx_evt_start_o) wr_block0 <= wr_block0 + 1'b1; // wr_ptr0: dpram_s0 write address always @(posedge clk, negedge rstn) if( !rstn ) wr_ptr0 <= 'd0; - else if (!(|enable)) + else if (mle_0_state == MLE_ST_EVT_DONE) wr_ptr0 <= 'd0; else if (we0) wr_ptr0 <= wr_ptr0 + 1'b1; - assign wr_addr0 = (wr_block0 << BLOCK_OFFSET_SHIT) + wr_ptr0; - assign we0 = we; + assign wr_addr0 = (wr_block0 << BLOCK_OFFSET_SHIFT) + wr_ptr0; + assign we0 = rx_we_i; // enable_logic_active: assert a bit to indicate which enable logic block is active always @(posedge clk, negedge rstn) @@ -278,29 +287,19 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) else if (mle_0_state == MLE_ST_DU_DONE) enable_logic_active <= enable_logic_active << 1; - // enable logic: assert each enable until empty + // enable logic: assert each rx_enable_o until empty generate genvar i; for (i=0; i< NUM_IF; i=i+1) begin: enable_logic always @(posedge clk, negedge rstn) if(!rstn) - enable[i] <= 1'b0; - else if (enable[i] && empty[i]) - enable[i] <= 1'b0; - else if (enable_logic_active[i] && !empty[i]) - enable[i] <= 1'b1; + rx_enable_o[i] <= 1'b0; + else if (rx_enable_o[i] && rx_empty_i[i]) + rx_enable_o[i] <= 1'b0; + else if (enable_logic_active[i] && !rx_empty_i[i]) + rx_enable_o[i] <= 1'b1; else - enable[i] <= 1'b0; - - always @(posedge clk, negedge rstn) - if(!rstn) begin - empty_m1[i] <= 1'b1; - empty_m2[i] <= 1'b1; - end - else begin - empty_m1[i] <= empty[i]; - empty_m2[i] <= empty_m1[i]; - end + rx_enable_o[i] <= 1'b0; end endgenerate @@ -308,9 +307,9 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) always @(posedge clk, negedge rstn) if( !rstn ) cnt0 <= 'd0; - else if (!evt_active) + else if (!rx_evt_active_o) cnt0 <= 'd0; - else if (|enable && !(|empty)) + else if (|rx_enable_o && !(|rx_empty_i)) cnt0 <= cnt0 + 1'b1; @@ -318,11 +317,11 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) dpram_inf #(.ADDR_WIDTH(10),.DPRAM_INIT("mle_ram_0.txt")) dpram_s0( .rstn(rstn), .a_clk(clk), - .a_clk_e(clk_e), + .a_clk_e(rx_clk_e_i), .a_we(we0), .a_oe(1'b0), .a_addr(wr_addr0), - .a_din(d_i), + .a_din(rx_d_i), .a_dout(), // port B .b_clk(clk), @@ -336,14 +335,21 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) `ifdef DIRECT_OUTPUT - assign rd_oe0 = fifo_re; - assign fifo_d = (mle_3_state == MLE_3_ST_HDR) ? mle_3_hdr : d_s0_o; - assign fifo_d_o[7:0] = fifo_empty ? 8'h00 : fifo_d[7:0]; - assign fifo_d_o[8] = fifo_empty_o ? 1'b1 : 1'b0; + assign rd_oe0 = sw_fifo_re_i; + + `ifdef TEST_MODE + assign fifo_d = (mle_3_state == MLE_3_ST_HDR) ? mle_3_hdr : rom_mux_d; + assign sw_fifo_d_o[7:0] = fifo_empty ? 8'h00 : fifo_d[7:0]; + assign sw_fifo_d_o[8] = rom_cnt == 3'd7 ? 1'b1 : 1'b0; + `else + assign fifo_d = (mle_3_state == MLE_3_ST_HDR) ? mle_3_hdr : d_s0_o; + assign sw_fifo_d_o[7:0] = fifo_empty ? 8'h00 : fifo_d[7:0]; + assign sw_fifo_d_o[8] = sw_fifo_empty_o ? 1'b1 : 1'b0; + `endif assign rd_addr0 = rd_addr1; assign wr_addr1 = wr_addr0; assign we1 = we0; - + `else @@ -368,7 +374,7 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) always @(posedge clk, negedge rstn) if (!rstn) mle_1_state <= MLE_ST_IDLE; - else if (evt_active) + else if (rx_evt_active_o) case (mle_1_state) MLE_ST_IDLE: if (evt_delay_1) mle_1_state <= MLE_ST_DU_START; @@ -397,7 +403,7 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) else rd_ptr0 <= rd_ptr0 + 1'b1; - assign rd_addr0 = rd_block0 << BLOCK_OFFSET_SHIT + rd_ptr0; + assign rd_addr0 = rd_block0 << BLOCK_OFFSET_SHIFT + rd_ptr0; // rd_oe0: assign rd_oe0 = 1'b1; @@ -416,7 +422,7 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) else if (1'b0) wr_ptr1 <= wr_ptr1 + 1'b1; - assign wr_addr1 = wr_block1 << BLOCK_OFFSET_SHIT + wr_ptr1; + assign wr_addr1 = wr_block1 << BLOCK_OFFSET_SHIFT + wr_ptr1; @@ -446,7 +452,7 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) .b_clk(clk), .b_clk_e(1'b1), .b_we(1'b0), - .b_oe(fifo_re), + .b_oe(sw_fifo_re_i), .b_addr(rd_addr1), .b_din(9'h0), .b_dout(fifo_d) @@ -472,7 +478,7 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) always @(posedge clk, negedge rstn) if (!rstn) mle_2_state <= MLE_ST_IDLE; - else if (evt_active) + else if (rx_evt_active_o) case (mle_2_state) MLE_ST_EVT_START: if (1'b1) mle_2_state <= MLE_ST_DU_START; @@ -512,6 +518,60 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) evt_delay_out <= 1'b1; else evt_delay_out <= 1'b0; + + + +/********************************************************************** + + Test Mode: transmit into switch the MLP dataset (X,Y) fp32 points + +***********************************************************************/ + +`ifdef TEST_MODE + + // rom_cnt: count the number of bytes per 32-bit word(s) + always @(posedge clk, negedge rstn) + if( !rstn ) + rom_cnt <= 3'd0; + else if (mle_3_state != MLE_3_ST_DATA) + rom_cnt <= 3'd0; + else + rom_cnt <= rom_cnt + 1'b1; + + // rom_addr: shared rom address + always @(posedge clk, negedge rstn) + if( !rstn ) + rom_addr <= 7'd0; + else if (rom_cnt == 3'd7) + rom_addr <= rom_addr + 1'b1; + + + rom #(.DATA_WIDTH(32), .ADDR_WIDTH(7), .ROM_INIT("rom_x.txt")) rom_x( + .clk(clk), + .addr(rom_addr), + .q(test_x) + ); + + rom #(.DATA_WIDTH(32), .ADDR_WIDTH(7), .ROM_INIT("rom_y.txt")) rom_y( + .clk(clk), + .addr(rom_addr), + .q(test_y) + ); + + // rom_mux_d: mux the right data to the output + always @(*) + case (rom_cnt) + 3'd0: rom_mux_d = test_x[31:24]; + 3'd1: rom_mux_d = test_x[23:16]; + 3'd2: rom_mux_d = test_x[15:8]; + 3'd3: rom_mux_d = test_x[7:0]; + 3'd4: rom_mux_d = test_y[31:24]; + 3'd5: rom_mux_d = test_y[23:16]; + 3'd6: rom_mux_d = test_y[15:8]; + 3'd7: rom_mux_d = test_y[7:0]; + endcase + +`endif /****************************************************** @@ -519,12 +579,16 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) FSM_3, Provide output data (header + DPRAM) ******************************************************/ + + // FSM_3: always @(posedge clk, negedge rstn) if (!rstn) mle_3_state <= MLE_3_ST_IDLE; - else + else if (rx_evt_start_o) // TODO: This masks the problem of data out flag missing + mle_3_state <= MLE_3_ST_IDLE; + else begin: FSM_3 case (mle_3_state) MLE_3_ST_IDLE: if (evt_delay_out) mle_3_state <= MLE_3_ST_HDR; @@ -532,12 +596,13 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) mle_3_state <= MLE_3_ST_DATA; MLE_3_ST_DATA: if (fifo_d_out_flag) mle_3_state <= MLE_3_ST_PAD; - MLE_3_ST_PAD: if (fifo_empty_o) + MLE_3_ST_PAD: if (sw_fifo_empty_o) mle_3_state <= MLE_3_ST_EVT_DONE; MLE_3_ST_EVT_DONE: mle_3_state <= MLE_3_ST_IDLE; default: mle_3_state <= mle_3_state; endcase + end always @(*) case(mle_3_state) @@ -555,7 +620,7 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) mle_3_hdr_cnt <= 3'd0; else if (mle_3_state == MLE_3_ST_EVT_DONE) mle_3_hdr_cnt <= 3'd0; - else if (fifo_re && mle_3_state == MLE_3_ST_HDR) + else if (sw_fifo_re_i && mle_3_state == MLE_3_ST_HDR) mle_3_hdr_cnt <= mle_3_hdr_cnt + 1'b1; // mle_3_token @@ -572,17 +637,25 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) default: mle_3_hdr = 8'h55; endcase - // fifo_d_out_flag: bit 8 from dpram_s1 + // fifo_d_out_flag: bit 8 from dpram, signals end of data always @(posedge clk, negedge rstn) if (!rstn) fifo_d_out_flag <= 1'b0; - else if (fifo_re) +`ifdef TEST_MODE + else if (rom_cnt == 3'd7-1) // assert one byte early + fifo_d_out_flag <= 1'b1; +`else + else if (sw_fifo_re_i) fifo_d_out_flag <= fifo_d[8]; +`endif else fifo_d_out_flag <= 1'b0; - assign byte_cnt = BLOCK_OFFSET; - +`ifdef TEST_MODE + assign sw_byte_cnt_o = 11'd8; +`else + assign sw_byte_cnt_o = 11'd12; // TODO: need logic to determine this. +`endif // fifo_empty: assert when the last byte from the DPRAM is read always @(posedge clk, negedge rstn) @@ -594,14 +667,14 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) fifo_empty <= 1'b0; - // fifo_empty_o: module output to indicate to reader to stop + // sw_fifo_empty_o: module output to indicate to reader to stop always @(posedge clk, negedge rstn) if( !rstn ) - fifo_empty_o <= 1'b1; - else if (rd_addr1 == (rd_block1 << BLOCK_OFFSET_SHIT) + (byte_cnt-1)) - fifo_empty_o <= 1'b1; + sw_fifo_empty_o <= 1'b1; + else if (rd_addr1 == (rd_block1 << BLOCK_OFFSET_SHIFT) + (sw_byte_cnt_o-1)) + sw_fifo_empty_o <= 1'b1; else if (evt_delay_out) - fifo_empty_o <= 1'b0; + sw_fifo_empty_o <= 1'b0; // rd_block1: @@ -617,10 +690,10 @@ module ml_engine #(parameter NUM_IF=8, DPRAM_DEPTH=1024) rd_ptr1 <= 'd0; else if (evt_delay_out) rd_ptr1 <= 'd0; - else if (fifo_re && (mle_3_state == MLE_3_ST_HDR && mle_3_hdr_cnt == 3'd2) || mle_3_state > MLE_3_ST_HDR) + else if (sw_fifo_re_i && (mle_3_state == MLE_3_ST_HDR && mle_3_hdr_cnt == 3'd2) || mle_3_state > MLE_3_ST_HDR) rd_ptr1 <= rd_ptr1 + 1'b1; - assign rd_addr1 = (rd_block1 << BLOCK_OFFSET_SHIT) + rd_ptr1; + assign rd_addr1 = (rd_block1 << BLOCK_OFFSET_SHIFT) + rd_ptr1; // pkt_sz: store number of bytes in dpram_s1 to use as packet size always @(posedge clk, negedge rstn) diff --git a/src/mle_params.v b/src/mle_params.v index 7bbcd5b..a96d42e 100644 --- a/src/mle_params.v +++ b/src/mle_params.v @@ -1,8 +1,7 @@ /* * mle_params.v * - * Copyright (C) 2024-2025 Private Island Networks Inc. - * Copyright (C) 2018-2023 Mind Chasers Inc. + * Copyright (C) 2024-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. |

