blob: 44e8eda5ca7d217b73fcf02ecca77d4f5d4bd3d3 [file] [log] [blame]
agorararmard6c766a82020-12-10 18:13:12 +02001// SPDX-FileCopyrightText: 2020 Efabless Corporation
agorararmarde5780bf2020-12-09 21:27:56 +00002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
agorararmardafa96ea2020-12-09 23:37:31 +020014// SPDX-License-Identifier: Apache-2.0
agorararmarde5780bf2020-12-09 21:27:56 +000015
Matt Venn08cd6eb2020-11-16 12:01:14 +010016`default_nettype none
Tim Edwards05537512020-10-06 14:59:26 -040017/*
18 *-------------------------------------------------------------
19 *
20 * user_proj_example
21 *
22 * This is an example of a (trivially simple) user project,
23 * showing how the user project can connect to the logic
24 * analyzer, the wishbone bus, and the I/O pads.
25 *
26 * This project generates an integer count, which is output
27 * on the user area GPIO pads (digital output only). The
28 * wishbone connection allows the project to be controlled
29 * (start and stop) from the management SoC program.
30 *
31 * See the testbenches in directory "mprj_counter" for the
32 * example programs that drive this user project. The three
33 * testbenches are "io_ports", "la_test1", and "la_test2".
34 *
35 *-------------------------------------------------------------
36 */
37
38module user_proj_example #(
shalan0d14e6e2020-08-31 16:50:48 +020039 parameter BITS = 32
40)(
Ahmed Ghazydf4dd882020-11-25 18:38:42 +020041`ifdef USE_POWER_PINS
Tim Edwards9eda80d2020-10-08 21:36:44 -040042 inout vdda1, // User area 1 3.3V supply
43 inout vdda2, // User area 2 3.3V supply
44 inout vssa1, // User area 1 analog ground
45 inout vssa2, // User area 2 analog ground
46 inout vccd1, // User area 1 1.8V supply
47 inout vccd2, // User area 2 1.8v supply
48 inout vssd1, // User area 1 digital ground
49 inout vssd2, // User area 2 digital ground
Ahmed Ghazydf4dd882020-11-25 18:38:42 +020050`endif
Tim Edwards9eda80d2020-10-08 21:36:44 -040051
shalan0d14e6e2020-08-31 16:50:48 +020052 // Wishbone Slave ports (WB MI A)
53 input wb_clk_i,
54 input wb_rst_i,
Tim Edwards05537512020-10-06 14:59:26 -040055 input wbs_stb_i,
56 input wbs_cyc_i,
shalan0d14e6e2020-08-31 16:50:48 +020057 input wbs_we_i,
Tim Edwards05537512020-10-06 14:59:26 -040058 input [3:0] wbs_sel_i,
shalan0d14e6e2020-08-31 16:50:48 +020059 input [31:0] wbs_dat_i,
60 input [31:0] wbs_adr_i,
61 output wbs_ack_o,
Tim Edwards05537512020-10-06 14:59:26 -040062 output [31:0] wbs_dat_o,
63
shalan0d14e6e2020-08-31 16:50:48 +020064 // Logic Analyzer Signals
65 input [127:0] la_data_in,
66 output [127:0] la_data_out,
67 input [127:0] la_oen,
Tim Edwards05537512020-10-06 14:59:26 -040068
shalan0d14e6e2020-08-31 16:50:48 +020069 // IOs
Ahmed Ghazy22d29d62020-10-28 03:42:02 +020070 input [`MPRJ_IO_PADS-1:0] io_in,
71 output [`MPRJ_IO_PADS-1:0] io_out,
72 output [`MPRJ_IO_PADS-1:0] io_oeb
shalan0d14e6e2020-08-31 16:50:48 +020073);
74 wire clk;
75 wire rst;
76
Ahmed Ghazy22d29d62020-10-28 03:42:02 +020077 wire [`MPRJ_IO_PADS-1:0] io_in;
78 wire [`MPRJ_IO_PADS-1:0] io_out;
79 wire [`MPRJ_IO_PADS-1:0] io_oeb;
Tim Edwardsef2b68d2020-10-11 17:00:44 -040080
shalan0d14e6e2020-08-31 16:50:48 +020081 wire [31:0] rdata;
82 wire [31:0] wdata;
83 wire [BITS-1:0] count;
84
85 wire valid;
86 wire [3:0] wstrb;
87 wire [31:0] la_write;
88
89 // WB MI A
90 assign valid = wbs_cyc_i && wbs_stb_i;
91 assign wstrb = wbs_sel_i & {4{wbs_we_i}};
92 assign wbs_dat_o = rdata;
93 assign wdata = wbs_dat_i;
94
95 // IO
96 assign io_out = count;
Ahmed Ghazy22d29d62020-10-28 03:42:02 +020097 assign io_oeb = {(`MPRJ_IO_PADS-1){rst}};
shalan0d14e6e2020-08-31 16:50:48 +020098
99 // LA
100 assign la_data_out = {{(127-BITS){1'b0}}, count};
101 // Assuming LA probes [63:32] are for controlling the count register
102 assign la_write = ~la_oen[63:32] & ~{BITS{valid}};
103 // Assuming LA probes [65:64] are for controlling the count clk & reset
104 assign clk = (~la_oen[64]) ? la_data_in[64]: wb_clk_i;
105 assign rst = (~la_oen[65]) ? la_data_in[65]: wb_rst_i;
106
107 counter #(
108 .BITS(BITS)
109 ) counter(
110 .clk(clk),
111 .reset(rst),
Dan Rodriguesb9a8c912020-11-08 13:15:21 +1100112 .ready(wbs_ack_o),
shalan0d14e6e2020-08-31 16:50:48 +0200113 .valid(valid),
114 .rdata(rdata),
115 .wdata(wbs_dat_i),
116 .wstrb(wstrb),
117 .la_write(la_write),
118 .la_input(la_data_in[63:32]),
119 .count(count)
120 );
121
122endmodule
123
124module counter #(
125 parameter BITS = 32
126)(
127 input clk,
128 input reset,
129 input valid,
130 input [3:0] wstrb,
131 input [BITS-1:0] wdata,
132 input [BITS-1:0] la_write,
133 input [BITS-1:0] la_input,
134 output ready,
135 output [BITS-1:0] rdata,
136 output [BITS-1:0] count
137);
138 reg ready;
139 reg [BITS-1:0] count;
140 reg [BITS-1:0] rdata;
141
142 always @(posedge clk) begin
143 if (reset) begin
144 count <= 0;
145 ready <= 0;
146 end else begin
147 ready <= 1'b0;
148 if (~|la_write) begin
149 count <= count + 1;
150 end
151 if (valid && !ready) begin
152 ready <= 1'b1;
153 rdata <= count;
154 if (wstrb[0]) count[7:0] <= wdata[7:0];
155 if (wstrb[1]) count[15:8] <= wdata[15:8];
156 if (wstrb[2]) count[23:16] <= wdata[23:16];
157 if (wstrb[3]) count[31:24] <= wdata[31:24];
158 end
159 end
160 end
161
162 genvar i;
163 generate
164 for(i=0; i<BITS; i=i+1) begin
165 always @(posedge clk) begin
166 if (la_write[i]) count[i] <= la_input[i];
167 end
168 end
169 endgenerate
170
Tim Edwards05537512020-10-06 14:59:26 -0400171endmodule
Tim Edwards581068f2020-11-19 12:45:25 -0500172`default_nettype wire