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

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [trunk/] [soc/] [rtl/] [adv_debug_sys/] [Hardware/] [adv_dbg_if/] [rtl/] [verilog/] [adbg_or1k_biu.v] - Blame information for rev 21

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 21 xianfeng
//////////////////////////////////////////////////////////////////////
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 - 2010       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.3  2010-01-10 22:54:10  Nathan
44
// Update copyright dates
45
//
46
// Revision 1.2  2009/05/17 20:54:56  Nathan
47
// Changed email address to opencores.org
48
//
49
// Revision 1.1  2008/07/22 20:28:30  Nathan
50
// Changed names of all files and modules (prefixed an a, for advanced).  Cleanup, indenting.  No functional changes.
51
//
52
// Revision 1.5  2008/07/08 19:04:03  Nathan
53
// Many small changes to eliminate compiler warnings, no functional 
54
// changes.  System will now pass SRAM and CPU self-tests on Altera 
55
// FPGA using altera_virtual_jtag TAP.
56
//
57
 
58
 
59
 
60
module adbg_or1k_biu
61
  (
62
   // Debug interface signals
63
   tck_i,
64
   rst_i,
65
   data_i,
66
   data_o,
67
   addr_i,
68
   strobe_i,
69
   rd_wrn_i,           // If 0, then write op
70
   rdy_o,
71
 
72
   // OR1K SPR bus signals
73
   cpu_clk_i,
74
   cpu_addr_o,
75
   cpu_data_i,
76
   cpu_data_o,
77
   cpu_stb_o,
78
   cpu_we_o,
79
   cpu_ack_i
80
   );
81
 
82
   // Debug interface signals
83
   input tck_i;
84
   input rst_i;
85
   input [31:0] data_i;  // Assume short words are in UPPER order bits!
86
   output [31:0] data_o;
87
   input [31:0]  addr_i;
88
   input         strobe_i;
89
   input         rd_wrn_i;
90
   output        rdy_o;
91
 
92
 
93
   // OR1K SPR bus signals
94
   input         cpu_clk_i;
95
   output [31:0] cpu_addr_o;
96
   input [31:0]  cpu_data_i;
97
   output [31:0] cpu_data_o;
98
   output        cpu_stb_o;
99
   output        cpu_we_o;
100
   input         cpu_ack_i;
101
 
102
   reg           rdy_o;
103
   reg           cpu_stb_o;
104
 
105
 
106
   // Registers
107
   reg [31:0]     addr_reg;
108
   reg [31:0]     data_in_reg;  // dbg->WB
109
   reg [31:0]     data_out_reg;  // WB->dbg
110
   reg           wr_reg;
111
   reg           str_sync;  // This is 'active-toggle' rather than -high or -low.
112
   reg           rdy_sync;  // ditto, active-toggle
113
 
114
 
115
   // Sync registers.  TFF indicates TCK domain, WBFF indicates cpu_clk domain
116
   reg           rdy_sync_tff1;
117
   reg           rdy_sync_tff2;
118
   reg           rdy_sync_tff2q;  // used to detect toggles
119
   reg           str_sync_wbff1;
120
   reg           str_sync_wbff2;
121
   reg           str_sync_wbff2q;  // used to detect toggles
122
 
123
 
124
   // Control Signals
125
   reg           data_o_en;    // latch wb_data_i
126
   reg           rdy_sync_en;  // toggle the rdy_sync signal, indicate ready to TCK domain
127
 
128
 
129
   // Internal signals
130
   wire          start_toggle;  // CPU domain, indicates a toggle on the start strobe
131
 
132
 
133
   //////////////////////////////////////////////////////
134
   // TCK clock domain
135
   // There is no FSM here, just signal latching and clock
136
   // domain synchronization
137
 
138
 
139
   // Latch input data on 'start' strobe, if ready.
140
   always @ (posedge tck_i or posedge rst_i)
141
     begin
142
        if(rst_i) begin
143
           addr_reg <= 32'h0;
144
           data_in_reg <= 32'h0;
145
           wr_reg <= 1'b0;
146
        end
147
        else
148
          if(strobe_i && rdy_o) begin
149
             addr_reg <= addr_i;
150
             if(!rd_wrn_i) data_in_reg <= data_i;
151
             wr_reg <= ~rd_wrn_i;
152
          end
153
     end
154
 
155
   // Create toggle-active strobe signal for clock sync.  This will start a transaction
156
   // to the CPU once the toggle propagates to the FSM in the cpu_clk domain.
157
   always @ (posedge tck_i or posedge rst_i)
158
     begin
159
        if(rst_i) str_sync <= 1'b0;
160
        else if(strobe_i && rdy_o) str_sync <= ~str_sync;
161
     end
162
 
163
   // Create rdy_o output.  Set on reset, clear on strobe (if set), set on input toggle
164
   always @ (posedge tck_i or posedge rst_i)
165
     begin
166
        if(rst_i) begin
167
           rdy_sync_tff1 <= 1'b0;
168
           rdy_sync_tff2 <= 1'b0;
169
           rdy_sync_tff2q <= 1'b0;
170
           rdy_o <= 1'b1;
171
        end
172
        else begin
173
           rdy_sync_tff1 <= rdy_sync;       // Synchronize the ready signal across clock domains
174
           rdy_sync_tff2 <= rdy_sync_tff1;
175
           rdy_sync_tff2q <= rdy_sync_tff2;  // used to detect toggles
176
 
177
           if(strobe_i && rdy_o) rdy_o <= 1'b0;
178
           else if(rdy_sync_tff2 != rdy_sync_tff2q) rdy_o <= 1'b1;
179
        end
180
 
181
     end
182
 
183
   //////////////////////////////////////////////////////////
184
   // Direct assignments, unsynchronized
185
 
186
   assign cpu_data_o = data_in_reg;
187
   assign cpu_we_o = wr_reg;
188
   assign cpu_addr_o = addr_reg;
189
 
190
   assign data_o = data_out_reg;
191
 
192
 
193
   ///////////////////////////////////////////////////////
194
   // Wishbone clock domain
195
 
196
  // synchronize the start strobe
197
  always @ (posedge cpu_clk_i or posedge rst_i)
198
          begin
199
             if(rst_i) begin
200
                str_sync_wbff1 <= 1'b0;
201
                str_sync_wbff2 <= 1'b0;
202
                str_sync_wbff2q <= 1'b0;
203
             end
204
             else begin
205
                str_sync_wbff1 <= str_sync;
206
                str_sync_wbff2 <= str_sync_wbff1;
207
                str_sync_wbff2q <= str_sync_wbff2;  // used to detect toggles
208
             end
209
          end
210
 
211
   assign start_toggle = (str_sync_wbff2 != str_sync_wbff2q);
212
 
213
 
214
   // CPU->dbg data register
215
   always @ (posedge cpu_clk_i or posedge rst_i)
216
     begin
217
        if(rst_i) data_out_reg <= 32'h0;
218
        else if(data_o_en) data_out_reg <= cpu_data_i;
219
     end
220
 
221
   // Create a toggle-active ready signal to send to the TCK domain
222
   always @ (posedge cpu_clk_i or posedge rst_i)
223
     begin
224
        if(rst_i) rdy_sync <= 1'b0;
225
        else if(rdy_sync_en) rdy_sync <= ~rdy_sync;
226
     end
227
 
228
   /////////////////////////////////////////////////////
229
   // Small state machine to create OR1K SPR bus accesses
230
   // Not much more that an 'in_progress' bit, but easier
231
   // to read.  Deals with single-cycle and multi-cycle
232
   // accesses.
233
 
234
   reg cpu_fsm_state;
235
   reg next_fsm_state;
236
 
237
`define STATE_IDLE     1'h0
238
`define STATE_TRANSFER 1'h1
239
 
240
   // Sequential bit
241
   always @ (posedge cpu_clk_i or posedge rst_i)
242
     begin
243
        if(rst_i) cpu_fsm_state <= `STATE_IDLE;
244
        else cpu_fsm_state <= next_fsm_state;
245
     end
246
 
247
   // Determination of next state (combinatorial)
248
   always @ (cpu_fsm_state or start_toggle or cpu_ack_i)
249
     begin
250
        case (cpu_fsm_state)
251
          `STATE_IDLE:
252
            begin
253
               if(start_toggle && !cpu_ack_i) next_fsm_state <= `STATE_TRANSFER;  // Don't go to next state for 1-cycle transfer
254
               else next_fsm_state <= `STATE_IDLE;
255
            end
256
          `STATE_TRANSFER:
257
            begin
258
               if(cpu_ack_i) next_fsm_state <= `STATE_IDLE;
259
               else next_fsm_state <= `STATE_TRANSFER;
260
            end
261
        endcase
262
     end
263
 
264
   // Outputs of state machine (combinatorial)
265
   always @ (cpu_fsm_state or start_toggle or cpu_ack_i or wr_reg)
266
     begin
267
        rdy_sync_en <= 1'b0;
268
        data_o_en <= 1'b0;
269
        cpu_stb_o <= 1'b0;
270
 
271
        case (cpu_fsm_state)
272
          `STATE_IDLE:
273
            begin
274
               if(start_toggle) begin
275
                  cpu_stb_o <= 1'b1;
276
                  if(cpu_ack_i) begin
277
                     rdy_sync_en <= 1'b1;
278
                  end
279
 
280
                  if (cpu_ack_i && !wr_reg) begin  // latch read data
281
                     data_o_en <= 1'b1;
282
                  end
283
               end
284
            end
285
 
286
          `STATE_TRANSFER:
287
            begin
288
               cpu_stb_o <= 1'b1;  // OR1K behavioral model needs this.  OR1200 should be indifferent.
289
               if(cpu_ack_i) begin
290
                  data_o_en <= 1'b1;
291
                  rdy_sync_en <= 1'b1;
292
               end
293
            end
294
        endcase
295
 
296
     end
297
 
298
endmodule
299
 

powered by: WebSVN 2.1.0

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