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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [orp/] [orp_soc/] [bench/] [verilog/] [dbg_comm2.v] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 779 lampret
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File_communication.v                                        ////
4
////                                                              ////
5
////                                                              ////
6
////  This file is part of the SoC/OpenRISC Development Interface ////
7
////  http://www.opencores.org/cores/DebugInterface/              ////
8
////                                                              ////
9
////                                                              ////
10
////  Author(s):                                                  ////
11
////       Igor Mohor                                             ////
12
////       igorm@opencores.org                                    ////
13
////                                                              ////
14
////                                                              ////
15
////  All additional information is avaliable in the README.txt   ////
16
////  file.                                                       ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20
//// Copyright (C) 2000,2001 Authors                              ////
21
////                                                              ////
22
//// This source file may be used and distributed without         ////
23
//// restriction provided that this copyright statement is not    ////
24
//// removed from the file and that any derivative work contains  ////
25
//// the original copyright notice and the associated disclaimer. ////
26
////                                                              ////
27
//// This source file is free software; you can redistribute it   ////
28
//// and/or modify it under the terms of the GNU Lesser General   ////
29
//// Public License as published by the Free Software Foundation; ////
30
//// either version 2.1 of the License, or (at your option) any   ////
31
//// later version.                                               ////
32
////                                                              ////
33
//// This source is distributed in the hope that it will be       ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
36
//// PURPOSE.  See the GNU Lesser General Public License for more ////
37
//// details.                                                     ////
38
////                                                              ////
39
//// You should have received a copy of the GNU Lesser General    ////
40
//// Public License along with this source; if not, download it   ////
41
//// from http://www.opencores.org/lgpl.shtml                     ////
42
////                                                              ////
43
//////////////////////////////////////////////////////////////////////
44
//
45
// CVS Revision History
46
//
47
// $Log: not supported by cvs2svn $
48
// Revision 1.1.1.1  2001/11/04 18:51:07  lampret
49
// First import.
50
//
51
// Revision 1.3  2001/09/24 14:06:13  mohor
52
// Changes connected to the OpenRISC access (SPR read, SPR write).
53
//
54
// Revision 1.2  2001/09/20 10:10:30  mohor
55
// Working version. Few bugs fixed, comments added.
56
//
57
// Revision 1.1.1.1  2001/09/13 13:49:19  mohor
58
// Initial official release.
59
//
60
//
61
//
62
//
63
//
64
 
65
`ifdef DBG_IF_COMM
66
 
67
`include "dbg_timescale.v"
68
`include "dbg_defines.v"
69
//`include "dbg_tb_defines.v"
70
 
71
 
72
 
73
`define GDB_IN  "/projects/xess-damjan/sim/run/gdb_in.dat"
74
`define GDB_OUT "/projects/xess-damjan/sim/run/gdb_out.dat"
75
//`define GDB_IN        "/tmp/gdb_in.dat"
76
//`define GDB_OUT       "/tmp/gdb_out.dat"
77
//`define GDB_IN        "../src/gdb_in.dat"
78
//`define GDB_OUT       "../src/gdb_out.dat"
79
 
80
module dbg_comm2(P_TMS, P_TCK, P_TRST, P_TDI, P_TDO);
81
 
82
parameter Tp = 1;
83
parameter Tclk = 50;   // Clock half period (Clok period = 100 ns => 10 MHz)
84
 
85
output          P_TMS;
86
output          P_TCK;
87
output          P_TRST;
88
output          P_TDI;
89
input           P_TDO;
90
 
91
integer handle1, handle2;
92
reg [87:0] memory[0:0];
93
reg [87:0] file;
94
reg Mclk;
95
reg wb_rst_i;
96
 
97
reg alternator;
98
 
99
reg StartTesting;
100
reg P_TCK;
101
reg  P_TRST;
102
reg  P_TDI;
103
reg  P_TMS;
104
wire P_TDO;
105
 
106
reg transition_detected;
107
reg update_state;
108
reg latchedbit;
109
reg [31:0] data_out;
110
 
111
 
112
initial
113
begin
114
  P_TCK = 0;
115
  P_TMS = 0;
116
  P_TDI = 0;
117
  alternator = 0;
118
  StartTesting = 0;
119
  wb_rst_i = 0;
120
  P_TRST = 1;
121
  #500;
122
  wb_rst_i = 1;
123
  P_TRST = 0;
124
  #500;
125
  wb_rst_i = 0;
126
  P_TRST = 1;
127
 
128
  #2000;
129
  StartTesting = 1;
130
  $display("StartTesting = 1");
131
 
132
 
133
end
134
 
135
initial
136
begin
137
  wait(StartTesting);
138
  while(1)
139
  begin
140
//    while(~transition_detected)
141
//      begin
142
        #1000;
143
        $readmemh(`GDB_OUT, memory);
144
//        $readmemh(`GDB_OUT, file);
145
//      end
146
//    wait(update_state);
147
    handle1 = $fopen(`GDB_OUT);
148
//    $fwrite(handle1, "%h", memory[0]);  // To ack to jp1 that we read dgb_out.dat
149
    $fwrite(handle1, "%h", {Temp[15:1], 1'b1});  // To ack to jp1 that we read dgb_out.dat
150
    $fclose(handle1);
151
//    end
152
  end
153
end
154
 
155
//always alternator = #100 ~alternator;
156
 
157
//always @ (posedge P_TCK or alternator)
158
always @ (posedge Mclk)
159
begin
160
  handle2 = $fopen(`GDB_IN);
161
  wait(update_state);
162
  $fdisplay(handle2, "%h", data_out);  // Writing output data to file
163
  $fclose(handle2);
164
end
165
 
166
wire [87:0]word = memory[0];
167
 
168
always @ (posedge Mclk or posedge wb_rst_i)
169
begin
170
  if(wb_rst_i)
171
    begin
172
      transition_detected <= 1'b0;
173
    end
174
  else if(!word[0])
175
    begin
176
      file = word;
177
      transition_detected = 1'b1;
178
    end
179
  else
180
    transition_detected = 1'b0;
181
end
182
 
183
wire [87:0]Temp = file;
184
/*
185
always @ (posedge Mclk or posedge wb_rst_i)
186
begin
187
  if(wb_rst_i)
188
    begin
189
      transition_detected <= 1'b0;
190
      latchedbit <= 1'b0;
191
    end
192
  else
193
  if(~latchedbit & Temp[2])
194
    transition_detected = 1'b1;
195
  else
196
    transition_detected = 1'b0;
197
  latchedbit <= Temp[2];
198
end
199
*/
200
 
201
 
202
 
203
reg [3:0]  chain     ;
204
reg [7:0]  chain_crc ;
205
reg [31:0] address   ;
206
reg        rw        ;
207
reg [31:0] data      ;
208
reg [7:0]  data_crc  ;
209
 
210
always @ (posedge Mclk or posedge wb_rst_i)
211
begin
212
  if(wb_rst_i)
213
    begin
214
      chain     = 'h0;
215
      chain_crc = 'h0;
216
      address   = 'h0;
217
      rw        = 'h0;
218
      data      = 'h0;
219
      data_crc  = 'h0;
220
    end
221
  else
222
  if(transition_detected)
223
  begin
224
    chain     = Temp[87:84];
225
    chain_crc = Temp[83:76];
226
    address   = Temp[75:44];
227
    rw        = Temp[43];
228
    data      = Temp[42:11];
229
    data_crc  = Temp[10:3];
230
  end
231
end
232
 
233
 
234
 
235
 
236
// assign P_TCK  = Temp[0];
237
// assign P_TRST = Temp[1];
238
// assign P_TDI  = Temp[2];
239
// assign P_TMS  = Temp[3];
240
 
241
 
242
 
243
always @ (posedge Mclk or posedge wb_rst_i)
244
begin
245
  if(wb_rst_i)
246
    update_state <= 1'b0;
247
  else
248
  if(transition_detected)
249
    begin
250
      update_state <= 1'b0;
251
        begin
252
          SetInstruction(`CHAIN_SELECT);
253
          ChainSelect(chain, chain_crc);                  // {chain, crc}
254
          SetInstruction(`DEBUG);
255
          if(rw)
256
            begin
257
              WriteRISCRegister(data, address, data_crc);   // {data, addr, crc}
258
              update_state <= 1'b1;
259
            end
260
          else
261
            begin
262
              ReadRISCRegister(address, data_crc, data_out);          // {addr, crc, read_data}
263
              ReadRISCRegister(address, data_crc, data_out);          // {addr, crc, read_data}
264
              update_state <= 1'b1;
265
            end
266
        end
267
    end
268
end
269
 
270
 
271
 
272
 
273
 
274
 
275
 
276
 
277
 
278
 
279
 
280
 
281
 
282
 
283
 
284
 
285
 
286
 
287
 
288
 
289
 
290
 
291
 
292
 
293
 
294
 
295
// Generating master clock (RISC clock) 10 MHz
296
initial
297
begin
298
  Mclk<=#Tp 0;
299
  #1 forever #`RISC_CLOCK Mclk<=~Mclk;
300
end
301
 
302
// Generating random number for use in DATAOUT_RISC[31:0]
303
reg [31:0] RandNumb;
304
always @ (posedge Mclk or posedge wb_rst_i)
305
begin
306
  if(wb_rst_i)
307
    RandNumb[31:0]<=#Tp 0;
308
  else
309
    RandNumb[31:0]<=#Tp RandNumb[31:0] + 1;
310
end
311
 
312
wire [31:0] DataIn = RandNumb;
313
 
314
// Connecting dbgTAP module
315
`ifdef UNUSED
316
dbg_top dbg1  (.tms_pad_i(P_TMS), .tck_pad_i(P_TCK), .trst_pad_i(P_TRST), .tdi_pad_i(P_TDI), .tdo_pad_o(P_TDO),
317
               .wb_rst_i(wb_rst_i), .risc_clk_i(Mclk), .risc_addr_o(), .risc_data_i(DataIn),
318
               .risc_data_o(), .wp_i(11'h0), .bp_i(1'b0),
319
               .opselect_o(), .lsstatus_i(4'h0), .istatus_i(2'h0),
320
               .risc_stall_o(), .reset_o()
321
              );
322
`endif
323
 
324
 
325
 
326
// Generation of the TCLK signal
327
task GenClk;
328
  input [7:0] Number;
329
  integer i;
330
  begin
331
    for(i=0; i<Number; i=i+1)
332
      begin
333
        #Tclk P_TCK<=1;
334
        #Tclk P_TCK<=0;
335
      end
336
  end
337
endtask
338
 
339
 
340
 
341
// sets the instruction to the IR register and goes to the RunTestIdle state
342
task SetInstruction;
343
  input [3:0] Instr;
344
  integer i;
345
 
346
  begin
347
    P_TMS<=#Tp 1;
348
    GenClk(2);
349
    P_TMS<=#Tp 0;
350
    GenClk(2);  // we are in shiftIR
351
 
352
    for(i=0; i<`IR_LENGTH-1; i=i+1)   // error?
353
    begin
354
      P_TDI<=#Tp Instr[i];
355
      GenClk(1);
356
    end
357
 
358
    P_TDI<=#Tp Instr[i]; // last shift
359
    P_TMS<=#Tp 1;        // going out of shiftIR
360
    GenClk(1);
361
      P_TDI<=#Tp 'hz;    // tri-state
362
    GenClk(1);
363
    P_TMS<=#Tp 0;
364
    GenClk(1);       // we are in RunTestIdle
365
  end
366
endtask
367
 
368
 
369
// sets the selected scan chain and goes to the RunTestIdle state
370
task ChainSelect;
371
  input [3:0] Data;
372
  input [7:0] Crc;
373
  integer i;
374
 
375
  begin
376
    P_TMS<=#Tp 1;
377
    GenClk(1);
378
    P_TMS<=#Tp 0;
379
    GenClk(2);  // we are in shiftDR
380
 
381
    for(i=0; i<`CHAIN_ID_LENGTH; i=i+1)
382
    begin
383
      P_TDI<=#Tp Data[i];
384
      GenClk(1);
385
    end
386
 
387
    for(i=0; i<`CRC_LENGTH-1; i=i+1)
388
    begin
389
      P_TDI<=#Tp Crc[i];
390
      GenClk(1);
391
    end
392
 
393
    P_TDI<=#Tp Crc[i]; // last shift
394
    P_TMS<=#Tp 1;        // going out of shiftIR
395
    GenClk(1);
396
      P_TDI<=#Tp 'hz; // tri-state
397
    GenClk(1);
398
    P_TMS<=#Tp 0;
399
    GenClk(1);       // we are in RunTestIdle
400
  end
401
endtask
402
 
403
 
404
// Write the RISC register
405
task WriteRISCRegister;
406
  input [31:0] Data;
407
  input [31:0] Address;
408
  input [`CRC_LENGTH-1:0] Crc;
409
  integer i;
410
 
411
  begin
412
    P_TMS<=#Tp 1;
413
    GenClk(1);
414
    P_TMS<=#Tp 0;
415
    GenClk(2);  // we are in shiftDR
416
 
417
    for(i=0; i<32; i=i+1)
418
    begin
419
      P_TDI<=#Tp Address[i];  // Shifting address
420
      GenClk(1);
421
    end
422
 
423
    P_TDI<=#Tp 1;             // shifting RW bit = write
424
    GenClk(1);
425
 
426
    for(i=0; i<32; i=i+1)
427
    begin
428
      P_TDI<=#Tp Data[i];     // Shifting data
429
      GenClk(1);
430
    end
431
 
432
    for(i=0; i<`CRC_LENGTH-1; i=i+1)
433
    begin
434
      P_TDI<=#Tp Crc[i];     // Shifting CRC
435
      GenClk(1);
436
    end
437
 
438
    P_TDI<=#Tp Crc[i];        // shifting last bit of CRC
439
    P_TMS<=#Tp 1;        // going out of shiftIR
440
    GenClk(1);
441
      P_TDI<=#Tp 'hz;        // tristate TDI
442
    GenClk(1);
443
 
444
    P_TMS<=#Tp 0;
445
    GenClk(1);       // we are in RunTestIdle
446
 
447
    GenClk(10);      // Generating few clock cycles needed for the write operation to accomplish
448
  end
449
endtask
450
 
451
 
452
// Reads the RISC register and latches the data so it is ready for reading
453
task ReadRISCRegister;
454
  input [31:0] Address;
455
  input [7:0] Crc;
456
  output [31:0] read_data;
457
  integer i;
458
 
459
  begin
460
    P_TMS<=#Tp 1;
461
    GenClk(1);
462
    P_TMS<=#Tp 0;
463
    GenClk(2);  // we are in shiftDR
464
 
465
    for(i=0; i<32; i=i+1)
466
    begin
467
      P_TDI<=#Tp Address[i];  // Shifting address
468
      GenClk(1);
469
    end
470
 
471
    P_TDI<=#Tp 0;             // shifting RW bit = read
472
    GenClk(1);
473
 
474
    for(i=0; i<32; i=i+1)
475
    begin
476
      P_TDI<=#Tp 0;     // Shifting data. Data is not important in read cycle.
477
      read_data[i]<=#Tp P_TDO;    // Assembling data to read_data
478
      GenClk(1);
479
    end
480
 
481
    for(i=0; i<`CRC_LENGTH-1; i=i+1)
482
    begin
483
      P_TDI<=#Tp Crc[i];     // Shifting CRC.
484
      GenClk(1);
485
    end
486
 
487
    P_TDI<=#Tp Crc[i];   // Shifting last bit of CRC.
488
    P_TMS<=#Tp 1;        // going out of shiftIR
489
    GenClk(1);
490
      P_TDI<=#Tp 'hz;   // Tristate TDI.
491
    GenClk(1);
492
 
493
    P_TMS<=#Tp 0;
494
    GenClk(1);       // we are in RunTestIdle
495
  end
496
endtask
497
 
498
 
499
 
500
 
501
 
502
 
503
 
504
endmodule // TAP
505
 
506
`endif

powered by: WebSVN 2.1.0

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