OpenCores
URL https://opencores.org/ocsvn/logicprobe/logicprobe/trunk

Subversion Repositories logicprobe

[/] [logicprobe/] [trunk/] [src/] [fpga/] [LogicProbe.v] - Blame information for rev 8

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 hellwig
//
2
// LogicProbe.v -- on-chip logic probe with trace memory and read-out facility
3
//
4
 
5
`timescale 1ns/1ns
6
 
7
module LogicProbe(clock, reset, trigger, sample, channels, serial_out);
8
    input clock;
9
    input reset;
10
    input trigger;
11
    input sample;
12
    input [127:0] channels;
13
    output serial_out;
14
 
15
  wire full;
16
  reg [12:0] rdaddr;
17
  wire [7:0] data;
18
  reg write;
19
  wire ready;
20
  reg done;
21
  reg state;
22
 
23
  LogicProbe_sampler
24
    sampler(clock, reset, trigger, sample, channels, full, rdaddr, data);
25
 
26
  LogicProbe_xmtbuf
27
    xmtbuf(clock, reset, write, ready, data, serial_out);
28
 
29
  always @(posedge clock) begin
30
    if (reset == 1) begin
31
      rdaddr <= 13'd0;
32
      write <= 0;
33
      done <= 0;
34
      state <= 0;
35
    end else begin
36
      if (full == 1 && done == 0) begin
37
        if (state == 0) begin
38
          if (ready == 1) begin
39
            state <= 1;
40
            write <= 1;
41
          end
42
        end else begin
43
          if (rdaddr == 13'd8191) begin
44
            done <= 1;
45
          end
46
          state <= 0;
47
          write <= 0;
48
          rdaddr <= rdaddr + 1;
49
        end
50
      end
51
    end
52
  end
53
 
54
endmodule
55
 
56
 
57
module LogicProbe_sampler(clock, reset, trigger, sample,
58
                          data_in, full, rdaddr, data_out);
59
    input clock;
60
    input reset;
61
    input trigger;
62
    input sample;
63
    input [127:0] data_in;
64
    output reg full;
65
    input [12:0] rdaddr;
66
    output reg [7:0] data_out;
67
 
68
  reg [31:0] mem3[0:511];
69
  reg [31:0] mem2[0:511];
70
  reg [31:0] mem1[0:511];
71
  reg [31:0] mem0[0:511];
72
 
73
  reg [8:0] wraddr;
74
  wire [8:0] addr;
75
  reg [31:0] data3;
76
  reg [31:0] data2;
77
  reg [31:0] data1;
78
  reg [31:0] data0;
79
 
80
  reg [3:0] muxctrl;
81
  reg triggered;
82
 
83
  // addr for trace memory
84
  // full == 0 means data capture
85
  // full == 1 means data readout
86
  assign addr = (full == 0) ? wraddr: rdaddr[12:4];
87
 
88
  // pipeline register for output mux control: necessary
89
  // because the trace memory has one clock delay too
90
  always @(posedge clock) begin
91
    muxctrl <= rdaddr[3:0];
92
  end
93
 
94
  // output multiplexer
95
  always @(*) begin
96
    case (muxctrl)
97
      4'h0: data_out = data3[31:24];
98
      4'h1: data_out = data3[23:16];
99
      4'h2: data_out = data3[15: 8];
100
      4'h3: data_out = data3[ 7: 0];
101
      4'h4: data_out = data2[31:24];
102
      4'h5: data_out = data2[23:16];
103
      4'h6: data_out = data2[15: 8];
104
      4'h7: data_out = data2[ 7: 0];
105
      4'h8: data_out = data1[31:24];
106
      4'h9: data_out = data1[23:16];
107
      4'hA: data_out = data1[15: 8];
108
      4'hB: data_out = data1[ 7: 0];
109
      4'hC: data_out = data0[31:24];
110
      4'hD: data_out = data0[23:16];
111
      4'hE: data_out = data0[15: 8];
112
      4'hF: data_out = data0[ 7: 0];
113
    endcase
114
  end
115
 
116
  // trace memory
117
  always @(posedge clock) begin
118
    if (full == 0) begin
119
      mem3[addr] <= data_in[127:96];
120
      mem2[addr] <= data_in[ 95:64];
121
      mem1[addr] <= data_in[ 63:32];
122
      mem0[addr] <= data_in[ 31: 0];
123
    end
124
    data3 <= mem3[addr];
125
    data2 <= mem2[addr];
126
    data1 <= mem1[addr];
127
    data0 <= mem0[addr];
128
  end
129
 
130
  // state machine which fills trace memory after trigger occurred
131
  // it takes one sample per clock tick, but only when sample == 1
132
  always @(posedge clock) begin
133
    if (reset == 1) begin
134
      wraddr <= 9'd0;
135
      triggered <= 0;
136
      full <= 0;
137
    end else begin
138
      if (triggered == 1) begin
139
        // capture data, but only when sample == 1
140
        if (sample == 1) begin
141
          if (wraddr == 9'd511) begin
142
            // last sample, memory is full
143
            full <= 1;
144
          end else begin
145
            wraddr <= wraddr + 1;
146
          end
147
        end
148
      end else begin
149
        // wait for trigger, possibly capture first sample
150
        if (trigger == 1) begin
151
          triggered <= 1;
152
          if (sample == 1) begin
153
            wraddr <= wraddr + 1;
154
          end
155
        end
156
      end
157
    end
158
  end
159
 
160
endmodule
161
 
162
 
163
module LogicProbe_xmtbuf(clock, reset, write, ready, data_in, serial_out);
164
    input clock;
165
    input reset;
166
    input write;
167
    output reg ready;
168
    input [7:0] data_in;
169
    output serial_out;
170
 
171
  reg [1:0] state;
172
  reg [7:0] data_hold;
173
  reg load;
174
  wire empty;
175
 
176
  LogicProbe_xmt xmt(clock, reset, load, empty, data_hold, serial_out);
177
 
178
  always @(posedge clock) begin
179
    if (reset == 1) begin
180
      state <= 2'b00;
181
      ready <= 1;
182
      load <= 0;
183
    end else begin
184
      case (state)
185
        2'b00:
186
          begin
187
            if (write == 1) begin
188
              state <= 2'b01;
189
              data_hold <= data_in;
190
              ready <= 0;
191
              load <= 1;
192
            end
193
          end
194
        2'b01:
195
          begin
196
            state <= 2'b10;
197
            ready <= 1;
198
            load <= 0;
199
          end
200
        2'b10:
201
          begin
202
            if (empty == 1 && write == 0) begin
203
              state <= 2'b00;
204
              ready <= 1;
205
              load <= 0;
206
            end else
207
            if (empty == 1 && write == 1) begin
208
              state <= 2'b01;
209
              data_hold <= data_in;
210
              ready <= 0;
211
              load <= 1;
212
            end else
213
            if (empty == 0 && write == 1) begin
214
              state <= 2'b11;
215
              data_hold <= data_in;
216
              ready <= 0;
217
              load <= 0;
218
            end
219
          end
220
        2'b11:
221
          begin
222
            if (empty == 1) begin
223
              state <= 2'b01;
224
              ready <= 0;
225
              load <= 1;
226
            end
227
          end
228
      endcase
229
    end
230
  end
231
 
232
endmodule
233
 
234
 
235
module LogicProbe_xmt(clock, reset, load, empty, parallel_in, serial_out);
236
    input clock;
237
    input reset;
238
    input load;
239
    output reg empty;
240
    input [7:0] parallel_in;
241
    output serial_out;
242
 
243
  reg [3:0] state;
244
  reg [8:0] shift;
245
  reg [10:0] count;
246
 
247
  assign serial_out = shift[0];
248
 
249
  always @(posedge clock) begin
250
    if (reset == 1) begin
251
      state <= 4'h0;
252
      shift <= 9'b111111111;
253
      empty <= 1;
254
    end else begin
255
      if (state == 4'h0) begin
256
        if (load == 1) begin
257
          state <= 4'h1;
258
          shift <= { parallel_in, 1'b0 };
259
          count <= 1302;
260
          empty <= 0;
261
        end
262
      end else
263
      if (state == 4'hb) begin
264
        state <= 4'h0;
265
        empty <= 1;
266
      end else begin
267
        if (count == 0) begin
268
          state <= state + 1;
269
          shift[8:0] <= { 1'b1, shift[8:1] };
270
          count <= 1302;
271
        end else begin
272
          count <= count - 1;
273
        end
274
      end
275
    end
276
  end
277
 
278
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.