Matt Venn | 08cd6eb | 2020-11-16 12:01:14 +0100 | [diff] [blame] | 1 | `default_nettype none |
Tim Edwards | 0553751 | 2020-10-06 14:59:26 -0400 | [diff] [blame] | 2 | /* |
| 3 | *------------------------------------------------------------- |
| 4 | * |
| 5 | * user_proj_example |
| 6 | * |
| 7 | * This is an example of a (trivially simple) user project, |
| 8 | * showing how the user project can connect to the logic |
| 9 | * analyzer, the wishbone bus, and the I/O pads. |
| 10 | * |
| 11 | * This project generates an integer count, which is output |
| 12 | * on the user area GPIO pads (digital output only). The |
| 13 | * wishbone connection allows the project to be controlled |
| 14 | * (start and stop) from the management SoC program. |
| 15 | * |
| 16 | * See the testbenches in directory "mprj_counter" for the |
| 17 | * example programs that drive this user project. The three |
| 18 | * testbenches are "io_ports", "la_test1", and "la_test2". |
| 19 | * |
| 20 | *------------------------------------------------------------- |
| 21 | */ |
| 22 | |
| 23 | module user_proj_example #( |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 24 | parameter BITS = 32 |
| 25 | )( |
Ahmed Ghazy | df4dd88 | 2020-11-25 18:38:42 +0200 | [diff] [blame] | 26 | `ifdef USE_POWER_PINS |
Tim Edwards | 9eda80d | 2020-10-08 21:36:44 -0400 | [diff] [blame] | 27 | 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 |
Ahmed Ghazy | df4dd88 | 2020-11-25 18:38:42 +0200 | [diff] [blame] | 35 | `endif |
Tim Edwards | 9eda80d | 2020-10-08 21:36:44 -0400 | [diff] [blame] | 36 | |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 37 | // Wishbone Slave ports (WB MI A) |
| 38 | input wb_clk_i, |
| 39 | input wb_rst_i, |
Tim Edwards | 0553751 | 2020-10-06 14:59:26 -0400 | [diff] [blame] | 40 | input wbs_stb_i, |
| 41 | input wbs_cyc_i, |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 42 | input wbs_we_i, |
Tim Edwards | 0553751 | 2020-10-06 14:59:26 -0400 | [diff] [blame] | 43 | input [3:0] wbs_sel_i, |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 44 | input [31:0] wbs_dat_i, |
| 45 | input [31:0] wbs_adr_i, |
| 46 | output wbs_ack_o, |
Tim Edwards | 0553751 | 2020-10-06 14:59:26 -0400 | [diff] [blame] | 47 | output [31:0] wbs_dat_o, |
| 48 | |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 49 | // Logic Analyzer Signals |
| 50 | input [127:0] la_data_in, |
| 51 | output [127:0] la_data_out, |
| 52 | input [127:0] la_oen, |
Tim Edwards | 0553751 | 2020-10-06 14:59:26 -0400 | [diff] [blame] | 53 | |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 54 | // IOs |
Ahmed Ghazy | 22d29d6 | 2020-10-28 03:42:02 +0200 | [diff] [blame] | 55 | input [`MPRJ_IO_PADS-1:0] io_in, |
| 56 | output [`MPRJ_IO_PADS-1:0] io_out, |
| 57 | output [`MPRJ_IO_PADS-1:0] io_oeb |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 58 | ); |
| 59 | wire clk; |
| 60 | wire rst; |
| 61 | |
Ahmed Ghazy | 22d29d6 | 2020-10-28 03:42:02 +0200 | [diff] [blame] | 62 | wire [`MPRJ_IO_PADS-1:0] io_in; |
| 63 | wire [`MPRJ_IO_PADS-1:0] io_out; |
| 64 | wire [`MPRJ_IO_PADS-1:0] io_oeb; |
Tim Edwards | ef2b68d | 2020-10-11 17:00:44 -0400 | [diff] [blame] | 65 | |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 66 | wire [31:0] rdata; |
| 67 | wire [31:0] wdata; |
| 68 | wire [BITS-1:0] count; |
| 69 | |
| 70 | wire valid; |
| 71 | wire [3:0] wstrb; |
| 72 | wire [31:0] la_write; |
| 73 | |
| 74 | // WB MI A |
| 75 | assign valid = wbs_cyc_i && wbs_stb_i; |
| 76 | assign wstrb = wbs_sel_i & {4{wbs_we_i}}; |
| 77 | assign wbs_dat_o = rdata; |
| 78 | assign wdata = wbs_dat_i; |
| 79 | |
| 80 | // IO |
| 81 | assign io_out = count; |
Ahmed Ghazy | 22d29d6 | 2020-10-28 03:42:02 +0200 | [diff] [blame] | 82 | assign io_oeb = {(`MPRJ_IO_PADS-1){rst}}; |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 83 | |
| 84 | // LA |
| 85 | assign la_data_out = {{(127-BITS){1'b0}}, count}; |
| 86 | // Assuming LA probes [63:32] are for controlling the count register |
| 87 | assign la_write = ~la_oen[63:32] & ~{BITS{valid}}; |
| 88 | // Assuming LA probes [65:64] are for controlling the count clk & reset |
| 89 | assign clk = (~la_oen[64]) ? la_data_in[64]: wb_clk_i; |
| 90 | assign rst = (~la_oen[65]) ? la_data_in[65]: wb_rst_i; |
| 91 | |
| 92 | counter #( |
| 93 | .BITS(BITS) |
| 94 | ) counter( |
| 95 | .clk(clk), |
| 96 | .reset(rst), |
Dan Rodrigues | b9a8c91 | 2020-11-08 13:15:21 +1100 | [diff] [blame] | 97 | .ready(wbs_ack_o), |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 98 | .valid(valid), |
| 99 | .rdata(rdata), |
| 100 | .wdata(wbs_dat_i), |
| 101 | .wstrb(wstrb), |
| 102 | .la_write(la_write), |
| 103 | .la_input(la_data_in[63:32]), |
| 104 | .count(count) |
| 105 | ); |
| 106 | |
| 107 | endmodule |
| 108 | |
| 109 | module counter #( |
| 110 | parameter BITS = 32 |
| 111 | )( |
| 112 | input clk, |
| 113 | input reset, |
| 114 | input valid, |
| 115 | input [3:0] wstrb, |
| 116 | input [BITS-1:0] wdata, |
| 117 | input [BITS-1:0] la_write, |
| 118 | input [BITS-1:0] la_input, |
| 119 | output ready, |
| 120 | output [BITS-1:0] rdata, |
| 121 | output [BITS-1:0] count |
| 122 | ); |
| 123 | reg ready; |
| 124 | reg [BITS-1:0] count; |
| 125 | reg [BITS-1:0] rdata; |
| 126 | |
| 127 | always @(posedge clk) begin |
| 128 | if (reset) begin |
| 129 | count <= 0; |
| 130 | ready <= 0; |
| 131 | end else begin |
| 132 | ready <= 1'b0; |
| 133 | if (~|la_write) begin |
| 134 | count <= count + 1; |
| 135 | end |
| 136 | if (valid && !ready) begin |
| 137 | ready <= 1'b1; |
| 138 | rdata <= count; |
| 139 | if (wstrb[0]) count[7:0] <= wdata[7:0]; |
| 140 | if (wstrb[1]) count[15:8] <= wdata[15:8]; |
| 141 | if (wstrb[2]) count[23:16] <= wdata[23:16]; |
| 142 | if (wstrb[3]) count[31:24] <= wdata[31:24]; |
| 143 | end |
| 144 | end |
| 145 | end |
| 146 | |
| 147 | genvar i; |
| 148 | generate |
| 149 | for(i=0; i<BITS; i=i+1) begin |
| 150 | always @(posedge clk) begin |
| 151 | if (la_write[i]) count[i] <= la_input[i]; |
| 152 | end |
| 153 | end |
| 154 | endgenerate |
| 155 | |
Tim Edwards | 0553751 | 2020-10-06 14:59:26 -0400 | [diff] [blame] | 156 | endmodule |
Tim Edwards | 581068f | 2020-11-19 12:45:25 -0500 | [diff] [blame] | 157 | `default_nettype wire |