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

Subversion Repositories adv_debug_sys

[/] [adv_debug_sys/] [tags/] [ADS_RELEASE_1_1_0/] [Hardware/] [adv_dbg_if/] [rtl/] [verilog/] [adbg_or1k_biu.v] - Blame information for rev 3

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

Line No. Rev Author Line
1 3 nyawn
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  adbg_or1k_biu.v                                             ////
4
////                                                              ////
5
////                                                              ////
6
////  This file is part of the SoC Advanced Debug Interface.      ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////       Nathan Yawn (nathan.yawn@opencores.org)                ////
10
////                                                              ////
11
////                                                              ////
12
////                                                              ////
13
//////////////////////////////////////////////////////////////////////
14
////                                                              ////
15
//// Copyright (C) 2008        Authors                            ////
16
////                                                              ////
17
//// This source file may be used and distributed without         ////
18
//// restriction provided that this copyright statement is not    ////
19
//// removed from the file and that any derivative work contains  ////
20
//// the original copyright notice and the associated disclaimer. ////
21
////                                                              ////
22
//// This source file is free software; you can redistribute it   ////
23
//// and/or modify it under the terms of the GNU Lesser General   ////
24
//// Public License as published by the Free Software Foundation; ////
25
//// either version 2.1 of the License, or (at your option) any   ////
26
//// later version.                                               ////
27
////                                                              ////
28
//// This source is distributed in the hope that it will be       ////
29
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
30
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
31
//// PURPOSE.  See the GNU Lesser General Public License for more ////
32
//// details.                                                     ////
33
////                                                              ////
34
//// You should have received a copy of the GNU Lesser General    ////
35
//// Public License along with this source; if not, download it   ////
36
//// from http://www.opencores.org/lgpl.shtml                     ////
37
////                                                              ////
38
//////////////////////////////////////////////////////////////////////
39
//
40
// CVS Revision History
41
//
42
// $Log: adbg_or1k_biu.v,v $
43
// Revision 1.2  2009/05/17 20:54:56  Nathan
44
// Changed email address to opencores.org
45
//
46
// Revision 1.1  2008/07/22 20:28:30  Nathan
47
// Changed names of all files and modules (prefixed an a, for advanced).  Cleanup, indenting.  No functional changes.
48
//
49
// Revision 1.5  2008/07/08 19:04:03  Nathan
50
// Many small changes to eliminate compiler warnings, no functional 
51
// changes.  System will now pass SRAM and CPU self-tests on Altera 
52
// FPGA using altera_virtual_jtag TAP.
53
//
54
 
55
 
56
 
57
module adbg_or1k_biu
58
  (
59
   // Debug interface signals
60
   tck_i,
61
   rst_i,
62
   data_i,
63
   data_o,
64
   addr_i,
65
   strobe_i,
66
   rd_wrn_i,           // If 0, then write op
67
   rdy_o,
68
 
69
   // OR1K SPR bus signals
70
   cpu_clk_i,
71
   cpu_addr_o,
72
   cpu_data_i,
73
   cpu_data_o,
74
   cpu_stb_o,
75
   cpu_we_o,
76
   cpu_ack_i
77
   );
78
 
79
   // Debug interface signals
80
   input tck_i;
81
   input rst_i;
82
   input [31:0] data_i;  // Assume short words are in UPPER order bits!
83
   output [31:0] data_o;
84
   input [31:0]  addr_i;
85
   input         strobe_i;
86
   input         rd_wrn_i;
87
   output        rdy_o;
88
 
89
 
90
   // OR1K SPR bus signals
91
   input         cpu_clk_i;
92
   output [31:0] cpu_addr_o;
93
   input [31:0]  cpu_data_i;
94
   output [31:0] cpu_data_o;
95
   output        cpu_stb_o;
96
   output        cpu_we_o;
97
   input         cpu_ack_i;
98
 
99
   reg           rdy_o;
100
   reg           cpu_stb_o;
101
 
102
 
103
   // Registers
104
   reg [31:0]     addr_reg;
105
   reg [31:0]     data_in_reg;  // dbg->WB
106
   reg [31:0]     data_out_reg;  // WB->dbg
107
   reg           wr_reg;
108
   reg           str_sync;  // This is 'active-toggle' rather than -high or -low.
109
   reg           rdy_sync;  // ditto, active-toggle
110
 
111
 
112
   // Sync registers.  TFF indicates TCK domain, WBFF indicates cpu_clk domain
113
   reg           rdy_sync_tff1;
114
   reg           rdy_sync_tff2;
115
   reg           rdy_sync_tff2q;  // used to detect toggles
116
   reg           str_sync_wbff1;
117
   reg           str_sync_wbff2;
118
   reg           str_sync_wbff2q;  // used to detect toggles
119
 
120
 
121
   // Control Signals
122
   reg           data_o_en;    // latch wb_data_i
123
   reg           rdy_sync_en;  // toggle the rdy_sync signal, indicate ready to TCK domain
124
 
125
 
126
   // Internal signals
127
   wire          start_toggle;  // CPU domain, indicates a toggle on the start strobe
128
 
129
 
130
   //////////////////////////////////////////////////////
131
   // TCK clock domain
132
   // There is no FSM here, just signal latching and clock
133
   // domain synchronization
134
 
135
 
136
   // Latch input data on 'start' strobe, if ready.
137
   always @ (posedge tck_i or posedge rst_i)
138
     begin
139
        if(rst_i) begin
140
           addr_reg <= 32'h0;
141
           data_in_reg <= 32'h0;
142
           wr_reg <= 1'b0;
143
        end
144
        else
145
          if(strobe_i && rdy_o) begin
146
             addr_reg <= addr_i;
147
             if(!rd_wrn_i) data_in_reg <= data_i;
148
             wr_reg <= ~rd_wrn_i;
149
          end
150
     end
151
 
152
   // Create toggle-active strobe signal for clock sync.  This will start a transaction
153
   // to the CPU once the toggle propagates to the FSM in the cpu_clk domain.
154
   always @ (posedge tck_i or posedge rst_i)
155
     begin
156
        if(rst_i) str_sync <= 1'b0;
157
        else if(strobe_i && rdy_o) str_sync <= ~str_sync;
158
     end
159
 
160
   // Create rdy_o output.  Set on reset, clear on strobe (if set), set on input toggle
161
   always @ (posedge tck_i or posedge rst_i)
162
     begin
163
        if(rst_i) begin
164
           rdy_sync_tff1 <= 1'b0;
165
           rdy_sync_tff2 <= 1'b0;
166
           rdy_sync_tff2q <= 1'b0;
167
           rdy_o <= 1'b1;
168
        end
169
        else begin
170
           rdy_sync_tff1 <= rdy_sync;       // Synchronize the ready signal across clock domains
171
           rdy_sync_tff2 <= rdy_sync_tff1;
172
           rdy_sync_tff2q <= rdy_sync_tff2;  // used to detect toggles
173
 
174
           if(strobe_i && rdy_o) rdy_o <= 1'b0;
175
           else if(rdy_sync_tff2 != rdy_sync_tff2q) rdy_o <= 1'b1;
176
        end
177
 
178
     end
179
 
180
   //////////////////////////////////////////////////////////
181
   // Direct assignments, unsynchronized
182
 
183
   assign cpu_data_o = data_in_reg;
184
   assign cpu_we_o = wr_reg;
185
   assign cpu_addr_o = addr_reg;
186
 
187
   assign data_o = data_out_reg;
188
 
189
 
190
   ///////////////////////////////////////////////////////
191
   // Wishbone clock domain
192
 
193
  // synchronize the start strobe
194
  always @ (posedge cpu_clk_i or posedge rst_i)
195
          begin
196
             if(rst_i) begin
197
                str_sync_wbff1 <= 1'b0;
198
                str_sync_wbff2 <= 1'b0;
199
                str_sync_wbff2q <= 1'b0;
200
             end
201
             else begin
202
                str_sync_wbff1 <= str_sync;
203
                str_sync_wbff2 <= str_sync_wbff1;
204
                str_sync_wbff2q <= str_sync_wbff2;  // used to detect toggles
205
             end
206
          end
207
 
208
   assign start_toggle = (str_sync_wbff2 != str_sync_wbff2q);
209
 
210
 
211
   // CPU->dbg data register
212
   always @ (posedge cpu_clk_i or posedge rst_i)
213
     begin
214
        if(rst_i) data_out_reg <= 32'h0;
215
        else if(data_o_en) data_out_reg <= cpu_data_i;
216
     end
217
 
218
   // Create a toggle-active ready signal to send to the TCK domain
219
   always @ (posedge cpu_clk_i or posedge rst_i)
220
     begin
221
        if(rst_i) rdy_sync <= 1'b0;
222
        else if(rdy_sync_en) rdy_sync <= ~rdy_sync;
223
     end
224
 
225
   /////////////////////////////////////////////////////
226
   // Small state machine to create OR1K SPR bus accesses
227
   // Not much more that an 'in_progress' bit, but easier
228
   // to read.  Deals with single-cycle and multi-cycle
229
   // accesses.
230
 
231
   reg cpu_fsm_state;
232
   reg next_fsm_state;
233
 
234
`define STATE_IDLE     1'h0
235
`define STATE_TRANSFER 1'h1
236
 
237
   // Sequential bit
238
   always @ (posedge cpu_clk_i or posedge rst_i)
239
     begin
240
        if(rst_i) cpu_fsm_state <= `STATE_IDLE;
241
        else cpu_fsm_state <= next_fsm_state;
242
     end
243
 
244
   // Determination of next state (combinatorial)
245
   always @ (cpu_fsm_state or start_toggle or cpu_ack_i)
246
     begin
247
        case (cpu_fsm_state)
248
          `STATE_IDLE:
249
            begin
250
               if(start_toggle && !cpu_ack_i) next_fsm_state <= `STATE_TRANSFER;  // Don't go to next state for 1-cycle transfer
251
               else next_fsm_state <= `STATE_IDLE;
252
            end
253
          `STATE_TRANSFER:
254
            begin
255
               if(cpu_ack_i) next_fsm_state <= `STATE_IDLE;
256
               else next_fsm_state <= `STATE_TRANSFER;
257
            end
258
        endcase
259
     end
260
 
261
   // Outputs of state machine (combinatorial)
262
   always @ (cpu_fsm_state or start_toggle or cpu_ack_i or wr_reg)
263
     begin
264
        rdy_sync_en <= 1'b0;
265
        data_o_en <= 1'b0;
266
        cpu_stb_o <= 1'b0;
267
 
268
        case (cpu_fsm_state)
269
          `STATE_IDLE:
270
            begin
271
               if(start_toggle) begin
272
                  cpu_stb_o <= 1'b1;
273
                  if(cpu_ack_i) begin
274
                     rdy_sync_en <= 1'b1;
275
                  end
276
 
277
                  if (cpu_ack_i && !wr_reg) begin  // latch read data
278
                     data_o_en <= 1'b1;
279
                  end
280
               end
281
            end
282
 
283
          `STATE_TRANSFER:
284
            begin
285
               cpu_stb_o <= 1'b1;  // OR1K behavioral model needs this.  OR1200 should be indifferent.
286
               if(cpu_ack_i) begin
287
                  data_o_en <= 1'b1;
288
                  rdy_sync_en <= 1'b1;
289
               end
290
            end
291
        endcase
292
 
293
     end
294
 
295
endmodule
296
 

powered by: WebSVN 2.1.0

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