blob: d010e77f6ce9398a452c9cfa1fddba363cbcf857 [file] [log] [blame]
Tim Edwards05537512020-10-06 14:59:26 -04001/*
2 *-------------------------------------------------------------
3 *
4 * user_proj_example
5 *
6 * This is an example of a (trivially simple) user project,
7 * showing how the user project can connect to the logic
8 * analyzer, the wishbone bus, and the I/O pads.
9 *
10 * This project generates an integer count, which is output
11 * on the user area GPIO pads (digital output only). The
12 * wishbone connection allows the project to be controlled
13 * (start and stop) from the management SoC program.
14 *
15 * See the testbenches in directory "mprj_counter" for the
16 * example programs that drive this user project. The three
17 * testbenches are "io_ports", "la_test1", and "la_test2".
18 *
19 *-------------------------------------------------------------
20 */
21
22module user_proj_example #(
Tim Edwardsb6dd1522020-10-19 15:58:25 -040023 parameter IO_PADS = 38,
Tim Edwards9eda80d2020-10-08 21:36:44 -040024 parameter PWR_PADS = 4,
shalan0d14e6e2020-08-31 16:50:48 +020025 parameter BITS = 32
26)(
Tim Edwards9eda80d2020-10-08 21:36:44 -040027 inout vdda1, // User area 1 3.3V supply
28 inout vdda2, // User area 2 3.3V supply
29 inout vssa1, // User area 1 analog ground
30 inout vssa2, // User area 2 analog ground
31 inout vccd1, // User area 1 1.8V supply
32 inout vccd2, // User area 2 1.8v supply
33 inout vssd1, // User area 1 digital ground
34 inout vssd2, // User area 2 digital ground
Tim Edwards9eda80d2020-10-08 21:36:44 -040035
shalan0d14e6e2020-08-31 16:50:48 +020036 // Wishbone Slave ports (WB MI A)
37 input wb_clk_i,
38 input wb_rst_i,
Tim Edwards05537512020-10-06 14:59:26 -040039 input wbs_stb_i,
40 input wbs_cyc_i,
shalan0d14e6e2020-08-31 16:50:48 +020041 input wbs_we_i,
Tim Edwards05537512020-10-06 14:59:26 -040042 input [3:0] wbs_sel_i,
shalan0d14e6e2020-08-31 16:50:48 +020043 input [31:0] wbs_dat_i,
44 input [31:0] wbs_adr_i,
45 output wbs_ack_o,
Tim Edwards05537512020-10-06 14:59:26 -040046 output [31:0] wbs_dat_o,
47
shalan0d14e6e2020-08-31 16:50:48 +020048 // Logic Analyzer Signals
49 input [127:0] la_data_in,
50 output [127:0] la_data_out,
51 input [127:0] la_oen,
Tim Edwards05537512020-10-06 14:59:26 -040052
shalan0d14e6e2020-08-31 16:50:48 +020053 // IOs
54 input [IO_PADS-1:0] io_in,
Tim Edwardsef2b68d2020-10-11 17:00:44 -040055 output [IO_PADS-1:0] io_out,
56 output [IO_PADS-1:0] io_oeb
shalan0d14e6e2020-08-31 16:50:48 +020057);
58 wire clk;
59 wire rst;
60
Tim Edwardsef2b68d2020-10-11 17:00:44 -040061 wire [IO_PADS-1:0] io_in;
62 wire [IO_PADS-1:0] io_out;
63 wire [IO_PADS-1:0] io_oeb;
64
shalan0d14e6e2020-08-31 16:50:48 +020065 wire [31:0] rdata;
66 wire [31:0] wdata;
67 wire [BITS-1:0] count;
68
69 wire valid;
70 wire [3:0] wstrb;
71 wire [31:0] la_write;
72
73 // WB MI A
74 assign valid = wbs_cyc_i && wbs_stb_i;
75 assign wstrb = wbs_sel_i & {4{wbs_we_i}};
76 assign wbs_dat_o = rdata;
77 assign wdata = wbs_dat_i;
78
79 // IO
80 assign io_out = count;
Tim Edwardsef2b68d2020-10-11 17:00:44 -040081 assign io_oeb = {(IO_PADS-1){rst}};
shalan0d14e6e2020-08-31 16:50:48 +020082
83 // LA
84 assign la_data_out = {{(127-BITS){1'b0}}, count};
85 // Assuming LA probes [63:32] are for controlling the count register
86 assign la_write = ~la_oen[63:32] & ~{BITS{valid}};
87 // Assuming LA probes [65:64] are for controlling the count clk & reset
88 assign clk = (~la_oen[64]) ? la_data_in[64]: wb_clk_i;
89 assign rst = (~la_oen[65]) ? la_data_in[65]: wb_rst_i;
90
91 counter #(
92 .BITS(BITS)
93 ) counter(
94 .clk(clk),
95 .reset(rst),
96 .ready(wbs_ack_i),
97 .valid(valid),
98 .rdata(rdata),
99 .wdata(wbs_dat_i),
100 .wstrb(wstrb),
101 .la_write(la_write),
102 .la_input(la_data_in[63:32]),
103 .count(count)
104 );
105
106endmodule
107
108module counter #(
109 parameter BITS = 32
110)(
111 input clk,
112 input reset,
113 input valid,
114 input [3:0] wstrb,
115 input [BITS-1:0] wdata,
116 input [BITS-1:0] la_write,
117 input [BITS-1:0] la_input,
118 output ready,
119 output [BITS-1:0] rdata,
120 output [BITS-1:0] count
121);
122 reg ready;
123 reg [BITS-1:0] count;
124 reg [BITS-1:0] rdata;
125
126 always @(posedge clk) begin
127 if (reset) begin
128 count <= 0;
129 ready <= 0;
130 end else begin
131 ready <= 1'b0;
132 if (~|la_write) begin
133 count <= count + 1;
134 end
135 if (valid && !ready) begin
136 ready <= 1'b1;
137 rdata <= count;
138 if (wstrb[0]) count[7:0] <= wdata[7:0];
139 if (wstrb[1]) count[15:8] <= wdata[15:8];
140 if (wstrb[2]) count[23:16] <= wdata[23:16];
141 if (wstrb[3]) count[31:24] <= wdata[31:24];
142 end
143 end
144 end
145
146 genvar i;
147 generate
148 for(i=0; i<BITS; i=i+1) begin
149 always @(posedge clk) begin
150 if (la_write[i]) count[i] <= la_input[i];
151 end
152 end
153 endgenerate
154
Tim Edwards05537512020-10-06 14:59:26 -0400155endmodule