blob: 924a52c2904fc0ed16765f105df944b00b058368 [file] [log] [blame]
shalan0d14e6e2020-08-31 16:50:48 +02001module mega_project #(
2 parameter IO_PADS = 32,
3 parameter BITS = 32
4)(
5 // Wishbone Slave ports (WB MI A)
6 input wb_clk_i,
7 input wb_rst_i,
8 input wbs_stb_i,
9 input wbs_cyc_i,
10 input wbs_we_i,
11 input [3:0] wbs_sel_i,
12 input [31:0] wbs_dat_i,
13 input [31:0] wbs_adr_i,
14 output wbs_ack_o,
15 output [31:0] wbs_dat_o,
16 // Logic Analyzer Signals
17 input [127:0] la_data_in,
18 output [127:0] la_data_out,
19 input [127:0] la_oen,
20 // IOs
21 input [IO_PADS-1:0] io_in,
22 output [IO_PADS-1:0] io_out
23);
24 wire clk;
25 wire rst;
26
27 wire [31:0] rdata;
28 wire [31:0] wdata;
29 wire [BITS-1:0] count;
30
31 wire valid;
32 wire [3:0] wstrb;
33 wire [31:0] la_write;
34
35 // WB MI A
36 assign valid = wbs_cyc_i && wbs_stb_i;
37 assign wstrb = wbs_sel_i & {4{wbs_we_i}};
38 assign wbs_dat_o = rdata;
39 assign wdata = wbs_dat_i;
40
41 // IO
42 assign io_out = count;
43
44 // LA
45 assign la_data_out = {{(127-BITS){1'b0}}, count};
46 // Assuming LA probes [63:32] are for controlling the count register
47 assign la_write = ~la_oen[63:32] & ~{BITS{valid}};
48 // Assuming LA probes [65:64] are for controlling the count clk & reset
49 assign clk = (~la_oen[64]) ? la_data_in[64]: wb_clk_i;
50 assign rst = (~la_oen[65]) ? la_data_in[65]: wb_rst_i;
51
52 counter #(
53 .BITS(BITS)
54 ) counter(
55 .clk(clk),
56 .reset(rst),
57 .ready(wbs_ack_i),
58 .valid(valid),
59 .rdata(rdata),
60 .wdata(wbs_dat_i),
61 .wstrb(wstrb),
62 .la_write(la_write),
63 .la_input(la_data_in[63:32]),
64 .count(count)
65 );
66
67endmodule
68
69module counter #(
70 parameter BITS = 32
71)(
72 input clk,
73 input reset,
74 input valid,
75 input [3:0] wstrb,
76 input [BITS-1:0] wdata,
77 input [BITS-1:0] la_write,
78 input [BITS-1:0] la_input,
79 output ready,
80 output [BITS-1:0] rdata,
81 output [BITS-1:0] count
82);
83 reg ready;
84 reg [BITS-1:0] count;
85 reg [BITS-1:0] rdata;
86
87 always @(posedge clk) begin
88 if (reset) begin
89 count <= 0;
90 ready <= 0;
91 end else begin
92 ready <= 1'b0;
93 if (~|la_write) begin
94 count <= count + 1;
95 end
96 if (valid && !ready) begin
97 ready <= 1'b1;
98 rdata <= count;
99 if (wstrb[0]) count[7:0] <= wdata[7:0];
100 if (wstrb[1]) count[15:8] <= wdata[15:8];
101 if (wstrb[2]) count[23:16] <= wdata[23:16];
102 if (wstrb[3]) count[31:24] <= wdata[31:24];
103 end
104 end
105 end
106
107 genvar i;
108 generate
109 for(i=0; i<BITS; i=i+1) begin
110 always @(posedge clk) begin
111 if (la_write[i]) count[i] <= la_input[i];
112 end
113 end
114 endgenerate
115
116endmodule