blob: a72d99ea6fba6e0679274c61bad1c9279cc59f39 [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 #(
shalan0d14e6e2020-08-31 16:50:48 +020023 parameter BITS = 32
24)(
Tim Edwards9eda80d2020-10-08 21:36:44 -040025 inout vdda1, // User area 1 3.3V supply
26 inout vdda2, // User area 2 3.3V supply
27 inout vssa1, // User area 1 analog ground
28 inout vssa2, // User area 2 analog ground
29 inout vccd1, // User area 1 1.8V supply
30 inout vccd2, // User area 2 1.8v supply
31 inout vssd1, // User area 1 digital ground
32 inout vssd2, // User area 2 digital ground
Tim Edwards9eda80d2020-10-08 21:36:44 -040033
shalan0d14e6e2020-08-31 16:50:48 +020034 // Wishbone Slave ports (WB MI A)
35 input wb_clk_i,
36 input wb_rst_i,
Tim Edwards05537512020-10-06 14:59:26 -040037 input wbs_stb_i,
38 input wbs_cyc_i,
shalan0d14e6e2020-08-31 16:50:48 +020039 input wbs_we_i,
Tim Edwards05537512020-10-06 14:59:26 -040040 input [3:0] wbs_sel_i,
shalan0d14e6e2020-08-31 16:50:48 +020041 input [31:0] wbs_dat_i,
42 input [31:0] wbs_adr_i,
43 output wbs_ack_o,
Tim Edwards05537512020-10-06 14:59:26 -040044 output [31:0] wbs_dat_o,
45
shalan0d14e6e2020-08-31 16:50:48 +020046 // Logic Analyzer Signals
47 input [127:0] la_data_in,
48 output [127:0] la_data_out,
49 input [127:0] la_oen,
Tim Edwards05537512020-10-06 14:59:26 -040050
shalan0d14e6e2020-08-31 16:50:48 +020051 // IOs
Ahmed Ghazy22d29d62020-10-28 03:42:02 +020052 input [`MPRJ_IO_PADS-1:0] io_in,
53 output [`MPRJ_IO_PADS-1:0] io_out,
54 output [`MPRJ_IO_PADS-1:0] io_oeb
shalan0d14e6e2020-08-31 16:50:48 +020055);
56 wire clk;
57 wire rst;
58
Ahmed Ghazy22d29d62020-10-28 03:42:02 +020059 wire [`MPRJ_IO_PADS-1:0] io_in;
60 wire [`MPRJ_IO_PADS-1:0] io_out;
61 wire [`MPRJ_IO_PADS-1:0] io_oeb;
Tim Edwardsef2b68d2020-10-11 17:00:44 -040062
shalan0d14e6e2020-08-31 16:50:48 +020063 wire [31:0] rdata;
64 wire [31:0] wdata;
65 wire [BITS-1:0] count;
66
67 wire valid;
68 wire [3:0] wstrb;
69 wire [31:0] la_write;
70
71 // WB MI A
72 assign valid = wbs_cyc_i && wbs_stb_i;
73 assign wstrb = wbs_sel_i & {4{wbs_we_i}};
74 assign wbs_dat_o = rdata;
75 assign wdata = wbs_dat_i;
76
77 // IO
78 assign io_out = count;
Ahmed Ghazy22d29d62020-10-28 03:42:02 +020079 assign io_oeb = {(`MPRJ_IO_PADS-1){rst}};
shalan0d14e6e2020-08-31 16:50:48 +020080
81 // LA
82 assign la_data_out = {{(127-BITS){1'b0}}, count};
83 // Assuming LA probes [63:32] are for controlling the count register
84 assign la_write = ~la_oen[63:32] & ~{BITS{valid}};
85 // Assuming LA probes [65:64] are for controlling the count clk & reset
86 assign clk = (~la_oen[64]) ? la_data_in[64]: wb_clk_i;
87 assign rst = (~la_oen[65]) ? la_data_in[65]: wb_rst_i;
88
89 counter #(
90 .BITS(BITS)
91 ) counter(
92 .clk(clk),
93 .reset(rst),
94 .ready(wbs_ack_i),
95 .valid(valid),
96 .rdata(rdata),
97 .wdata(wbs_dat_i),
98 .wstrb(wstrb),
99 .la_write(la_write),
100 .la_input(la_data_in[63:32]),
101 .count(count)
102 );
103
104endmodule
105
106module counter #(
107 parameter BITS = 32
108)(
109 input clk,
110 input reset,
111 input valid,
112 input [3:0] wstrb,
113 input [BITS-1:0] wdata,
114 input [BITS-1:0] la_write,
115 input [BITS-1:0] la_input,
116 output ready,
117 output [BITS-1:0] rdata,
118 output [BITS-1:0] count
119);
120 reg ready;
121 reg [BITS-1:0] count;
122 reg [BITS-1:0] rdata;
123
124 always @(posedge clk) begin
125 if (reset) begin
126 count <= 0;
127 ready <= 0;
128 end else begin
129 ready <= 1'b0;
130 if (~|la_write) begin
131 count <= count + 1;
132 end
133 if (valid && !ready) begin
134 ready <= 1'b1;
135 rdata <= count;
136 if (wstrb[0]) count[7:0] <= wdata[7:0];
137 if (wstrb[1]) count[15:8] <= wdata[15:8];
138 if (wstrb[2]) count[23:16] <= wdata[23:16];
139 if (wstrb[3]) count[31:24] <= wdata[31:24];
140 end
141 end
142 end
143
144 genvar i;
145 generate
146 for(i=0; i<BITS; i=i+1) begin
147 always @(posedge clk) begin
148 if (la_write[i]) count[i] <= la_input[i];
149 end
150 end
151 endgenerate
152
Tim Edwards05537512020-10-06 14:59:26 -0400153endmodule