[27] | 1 | module oscilloscope
|
---|
| 2 | (
|
---|
[90] | 3 | input wire clock, frame, reset,
|
---|
| 4 |
|
---|
| 5 | input wire [16:0] cfg_data,
|
---|
| 6 |
|
---|
| 7 | input wire trg_flag,
|
---|
| 8 |
|
---|
| 9 | input wire [47:0] osc_data,
|
---|
| 10 |
|
---|
| 11 | output wire ram_wren,
|
---|
| 12 | output wire [19:0] ram_addr,
|
---|
| 13 | inout wire [17:0] ram_data,
|
---|
| 14 |
|
---|
| 15 | input wire bus_ssel, bus_wren,
|
---|
| 16 | input wire [19:0] bus_addr,
|
---|
| 17 | input wire [15:0] bus_mosi,
|
---|
| 18 |
|
---|
| 19 | output wire [15:0] bus_miso,
|
---|
| 20 | output wire bus_busy
|
---|
[27] | 21 | );
|
---|
| 22 |
|
---|
| 23 |
|
---|
[90] | 24 | reg [47:0] osc_data_reg, osc_data_next;
|
---|
[27] | 25 |
|
---|
[90] | 26 | reg [2:0] int_case_reg, int_case_next;
|
---|
| 27 |
|
---|
| 28 | reg int_trig_reg, int_trig_next;
|
---|
| 29 | reg [19:0] int_trig_addr_reg, int_trig_addr_next;
|
---|
| 30 |
|
---|
[91] | 31 | reg [19:0] int_cntr_reg [1:0];
|
---|
| 32 | reg [19:0] int_cntr_next [1:0];
|
---|
| 33 |
|
---|
[90] | 34 | reg [15:0] bus_mosi_reg [2:0];
|
---|
| 35 | reg [15:0] bus_mosi_next [2:0];
|
---|
| 36 |
|
---|
| 37 | reg [15:0] bus_miso_reg, bus_miso_next;
|
---|
| 38 | reg bus_busy_reg, bus_busy_next;
|
---|
| 39 |
|
---|
| 40 | reg ram_wren_reg [2:0];
|
---|
| 41 | reg ram_wren_next [2:0];
|
---|
| 42 |
|
---|
| 43 | reg [17:0] ram_data_reg, ram_data_next;
|
---|
| 44 | reg [19:0] ram_addr_reg, ram_addr_next;
|
---|
| 45 |
|
---|
| 46 | wire [17:0] ram_wren_wire;
|
---|
| 47 |
|
---|
| 48 | assign ram_wren = ~ram_wren_reg[0];
|
---|
| 49 | assign ram_addr = ram_addr_reg;
|
---|
| 50 |
|
---|
| 51 | integer i;
|
---|
| 52 | genvar j;
|
---|
| 53 |
|
---|
| 54 | generate
|
---|
| 55 | for (j = 0; j < 18; j = j + 1)
|
---|
| 56 | begin : SRAM_WREN
|
---|
| 57 | assign ram_wren_wire[j] = ram_wren_reg[2];
|
---|
| 58 | assign ram_data[j] = ram_wren_wire[j] ? ram_data_reg[j] : 1'bz;
|
---|
| 59 | end
|
---|
| 60 | endgenerate
|
---|
| 61 |
|
---|
| 62 | always @(posedge clock)
|
---|
[27] | 63 | begin
|
---|
| 64 | if (reset)
|
---|
[90] | 65 | begin
|
---|
| 66 | osc_data_reg <= 48'd0;
|
---|
| 67 | ram_data_reg <= 18'd0;
|
---|
| 68 | ram_addr_reg <= 20'd0;
|
---|
| 69 | bus_miso_reg <= 16'd0;
|
---|
| 70 | bus_busy_reg <= 1'b0;
|
---|
| 71 | int_case_reg <= 5'd0;
|
---|
[91] | 72 | int_cntr_reg[0] <= 20'd0;
|
---|
| 73 | int_cntr_reg[1] <= 20'd0;
|
---|
[90] | 74 | int_trig_reg <= 1'b0;
|
---|
| 75 | int_trig_addr_reg <= 20'd0;
|
---|
| 76 |
|
---|
| 77 | for(i = 0; i <= 2; i = i + 1)
|
---|
| 78 | begin
|
---|
| 79 | ram_wren_reg[i] <= 1'b0;
|
---|
| 80 | bus_mosi_reg[i] <= 16'd0;
|
---|
| 81 | end
|
---|
[27] | 82 | end
|
---|
| 83 | else
|
---|
| 84 | begin
|
---|
[90] | 85 | osc_data_reg <= osc_data_next;
|
---|
| 86 | ram_data_reg <= ram_data_next;
|
---|
| 87 | ram_addr_reg <= ram_addr_next;
|
---|
| 88 | bus_miso_reg <= bus_miso_next;
|
---|
| 89 | bus_busy_reg <= bus_busy_next;
|
---|
| 90 | int_case_reg <= int_case_next;
|
---|
[91] | 91 | int_cntr_reg[0] <= int_cntr_next[0];
|
---|
| 92 | int_cntr_reg[1] <= int_cntr_next[1];
|
---|
[90] | 93 | int_trig_reg <= int_trig_next;
|
---|
| 94 | int_trig_addr_reg <= int_trig_addr_next;
|
---|
| 95 |
|
---|
| 96 | for(i = 0; i <= 2; i = i + 1)
|
---|
| 97 | begin
|
---|
| 98 | ram_wren_reg[i] <= ram_wren_next[i];
|
---|
| 99 | bus_mosi_reg[i] <= bus_mosi_next[i];
|
---|
| 100 | end
|
---|
[27] | 101 | end
|
---|
| 102 | end
|
---|
| 103 |
|
---|
| 104 | always @*
|
---|
| 105 | begin
|
---|
| 106 |
|
---|
[90] | 107 | osc_data_next = osc_data_reg;
|
---|
| 108 | ram_data_next = ram_data_reg;
|
---|
| 109 | ram_addr_next = ram_addr_reg;
|
---|
| 110 | bus_miso_next = bus_miso_reg;
|
---|
| 111 | bus_busy_next = bus_busy_reg;
|
---|
| 112 | int_case_next = int_case_reg;
|
---|
[91] | 113 | int_cntr_next[0] = int_cntr_reg[0];
|
---|
| 114 | int_cntr_next[1] = int_cntr_reg[1];
|
---|
[90] | 115 | int_trig_next = int_trig_reg;
|
---|
| 116 | int_trig_addr_next = int_trig_addr_reg;
|
---|
| 117 |
|
---|
| 118 | for(i = 0; i < 2; i = i + 1)
|
---|
| 119 | begin
|
---|
| 120 | ram_wren_next[i+1] = ram_wren_reg[i];
|
---|
| 121 | bus_mosi_next[i+1] = bus_mosi_reg[i];
|
---|
| 122 | end
|
---|
| 123 | ram_wren_next[0] = 1'b0;
|
---|
| 124 | bus_mosi_next[0] = 16'd0;
|
---|
| 125 |
|
---|
| 126 | case (int_case_reg)
|
---|
[51] | 127 | 0:
|
---|
[27] | 128 | begin
|
---|
[90] | 129 | ram_data_next = 18'd0;
|
---|
| 130 | ram_addr_next = 20'd0;
|
---|
| 131 | bus_busy_next = 1'b0;
|
---|
[91] | 132 | int_cntr_next[0] = 20'd0;
|
---|
| 133 | int_cntr_next[1] = 20'd0;
|
---|
[90] | 134 | int_trig_next = 1'b0;
|
---|
| 135 |
|
---|
| 136 | ram_data_next = {bus_mosi_reg[1][15:8], 1'b0, bus_mosi_reg[1][7:0], 1'b0};
|
---|
| 137 |
|
---|
| 138 | if (bus_ssel)
|
---|
[27] | 139 | begin
|
---|
[90] | 140 | bus_miso_next = {ram_data[17:10], ram_data[8:1]};
|
---|
| 141 | ram_wren_next[0] = bus_wren;
|
---|
| 142 | if (bus_wren)
|
---|
| 143 | begin
|
---|
| 144 | ram_addr_next = bus_addr;
|
---|
| 145 | bus_mosi_next[0] = bus_mosi;
|
---|
| 146 | end
|
---|
| 147 | else
|
---|
| 148 | begin
|
---|
| 149 | // ram_addr_next = int_trig_addr_reg + bus_addr;
|
---|
| 150 | ram_addr_next = bus_addr;
|
---|
| 151 | end
|
---|
[27] | 152 | end
|
---|
[90] | 153 | else if (cfg_data[16])
|
---|
[27] | 154 | begin
|
---|
[90] | 155 | // start recording
|
---|
| 156 | ram_wren_next[0] = 1'b1;
|
---|
| 157 | bus_busy_next = 1'b1;
|
---|
| 158 | int_case_next = 3'd1;
|
---|
| 159 | int_trig_addr_next = 20'd0;
|
---|
[91] | 160 | int_cntr_next[0] = {cfg_data[7:0], 10'd0};
|
---|
| 161 | int_cntr_next[1] = {cfg_data[15:8], 10'd0};
|
---|
[27] | 162 | end
|
---|
[90] | 163 |
|
---|
[27] | 164 | end
|
---|
[51] | 165 |
|
---|
[90] | 166 | // sample recording
|
---|
| 167 | 1:
|
---|
[27] | 168 | begin
|
---|
[90] | 169 | ram_wren_next[0] = 1'b1;
|
---|
| 170 | if (frame)
|
---|
[27] | 171 | begin
|
---|
[90] | 172 | osc_data_next = osc_data;
|
---|
| 173 | ram_addr_next = ram_addr_reg + 20'd1;
|
---|
| 174 | int_case_next = 3'd2;
|
---|
[51] | 175 |
|
---|
[91] | 176 | if ((~int_trig_reg) & (trg_flag) & (int_cntr_reg[1] == 0))
|
---|
[27] | 177 | begin
|
---|
[90] | 178 | int_trig_next = 1'b1;
|
---|
| 179 | int_trig_addr_next = ram_addr_reg;
|
---|
[27] | 180 | end
|
---|
[51] | 181 |
|
---|
[91] | 182 | if ((int_trig_reg) & (|int_cntr_reg[0]))
|
---|
[51] | 183 | begin
|
---|
[91] | 184 | int_cntr_next[0] = int_cntr_reg[0] - 20'd1;
|
---|
[51] | 185 | end
|
---|
[91] | 186 |
|
---|
| 187 | if ((|int_cntr_reg[1]))
|
---|
| 188 | begin
|
---|
| 189 | int_cntr_next[1] = int_cntr_reg[1] - 20'd1;
|
---|
| 190 | end
|
---|
[27] | 191 | end
|
---|
| 192 | end
|
---|
| 193 |
|
---|
[90] | 194 | 2:
|
---|
[27] | 195 | begin
|
---|
[90] | 196 | ram_wren_next[0] = 1'b1;
|
---|
| 197 | ram_data_next = {osc_data_reg[15:8], 1'b0, osc_data_reg[7:0], 1'b0};
|
---|
| 198 | ram_addr_next = ram_addr_reg + 20'd1;
|
---|
| 199 | int_case_next = 3'd3;
|
---|
[27] | 200 | end
|
---|
[90] | 201 |
|
---|
| 202 | 3:
|
---|
| 203 | begin
|
---|
| 204 | ram_wren_next[0] = 1'b1;
|
---|
| 205 | ram_data_next = {osc_data_reg[31:24], 1'b0, osc_data_reg[23:16], 1'b0};
|
---|
| 206 | ram_addr_next = ram_addr_reg + 20'd1;
|
---|
| 207 | int_case_next = 3'd4;
|
---|
| 208 | end
|
---|
| 209 |
|
---|
| 210 | 4:
|
---|
| 211 | begin
|
---|
| 212 | ram_wren_next[0] = 1'b1;
|
---|
| 213 | ram_data_next = {osc_data_reg[47:40], 1'b0, osc_data_reg[39:32], 1'b0};
|
---|
| 214 | int_case_next = 3'd1;
|
---|
[91] | 215 | if (int_cntr_reg[0] == 0)
|
---|
[90] | 216 | begin
|
---|
| 217 | ram_wren_next[0] = 1'b0;
|
---|
| 218 | ram_addr_next = 20'd0;
|
---|
| 219 | int_case_next = 3'd0;
|
---|
| 220 | end
|
---|
| 221 | end
|
---|
| 222 |
|
---|
[27] | 223 | endcase
|
---|
| 224 | end
|
---|
| 225 |
|
---|
[90] | 226 | assign bus_miso = bus_miso_reg;
|
---|
| 227 | assign bus_busy = bus_busy_reg;
|
---|
[27] | 228 |
|
---|
| 229 | endmodule
|
---|