// // Copyright 2013 Ettus Research LLC // `define BIT_WIDTH(N) (\ N <= 2 ? 1 : \ N <= 4 ? 2 : \ N <= 8 ? 3 : \ N <= 16 ? 4 : \ N <= 32 ? 5 : \ N <= 64 ? 6 : \ N <= 128 ? 7 : \ N <= 256 ? 8 : \ N <= 512 ? 9 : \ 10) `define GET_REG_OFFSET(reg_addr, chan_idx) (((chan_idx * (1< output translations assign set_frame_size[(FRAME_SIZE_W*(i+1))-1:(FRAME_SIZE_W*i)] = frame_size_mem[i]; assign swap_lanes[(3*(i+1))-1:(3*i)] = { ~(sw_buf_width_mem[i]), 2'b00 }; //Optimized for only 2 modes //Setting registers always @(posedge clk) begin if (reset) begin frame_size_mem[i] <= DEFAULT_FSIZE; set_clear[i] <= 0; sw_buf_width_mem[i] <= 1; end else if (regi_tready & regi_tvalid & regi_wr) begin if (regi_addr == `GET_REG_OFFSET(DMA_CTRL_STATUS_REG, i)) begin set_clear[i] <= regi_payload[0]; //DMA_CTRL_STATUS_REG[0] == Clear DMA queues sw_buf_width_mem[i] <= regi_payload[4]; //DMA_CTRL_STATUS_REG[5:4] == SW Buffer Size (See note above) end else if (regi_addr == `GET_REG_OFFSET(DMA_FSIZE_REG, i)) begin frame_size_mem[i] <= regi_payload[FRAME_SIZE_W-1:0]; //DMA_FSIZE_REG[14:0] == DMA Frame size set_clear[i] <= 1; end end else begin set_clear[i] <= 0; //set_clear should be "self-clearing" end end //Packet counter always @(posedge clk) begin if (reset | (regi_tvalid && regi_wr && (regi_addr == `GET_REG_OFFSET(DMA_PKT_CNT_REG, i)))) begin pkt_count_mem[i] <= 0; end else if (packet_stb[i]) begin pkt_count_mem[i] <= pkt_count_mem[i] + 1; end end //Sample counter always @(posedge clk) begin if (reset | (regi_tvalid && regi_wr && (regi_addr == `GET_REG_OFFSET(DMA_SAMP_CNT_REG, i)))) begin samp_count_mem[i] <= 0; end else if (sample_stb[i]) begin samp_count_mem[i] <= samp_count_mem[i] + 1; end end end endgenerate //Readback assign rego_payload = (regi_addr[DMA_REG_GRP_W-1:0] == DMA_PKT_CNT_REG) ? pkt_count_mem[`EXTRACT_CHAN_NUM(regi_addr)] : ( (regi_addr[DMA_REG_GRP_W-1:0] == DMA_SAMP_CNT_REG) ? samp_count_mem[`EXTRACT_CHAN_NUM(regi_addr)] : ( (regi_addr[DMA_REG_GRP_W-1:0] == DMA_FSIZE_REG) ? frame_size_mem[`EXTRACT_CHAN_NUM(regi_addr)] : ( (regi_addr[DMA_REG_GRP_W-1:0] == DMA_CTRL_STATUS_REG) ? {31'h0, stream_err[`EXTRACT_CHAN_NUM(regi_addr)]} : ( 32'hFFFFFFFF)))); assign rego_tvalid = regi_tvalid && regi_rd; assign regi_tready = rego_tready || (regi_tvalid && regi_wr); //Optional router if (ENABLE_ROUTER == 1) begin pcie_pkt_route_specifier #( .BASE_ADDR((1<