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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_8/] [rtl/] [verilog/] [pci_parity_check.v] - Blame information for rev 77

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

Line No. Rev Author Line
1 2 mihad
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name "pci_parity_check.v"                              ////
4
////                                                              ////
5
////  This file is part of the "PCI bridge" project               ////
6
////  http://www.opencores.org/cores/pci/                         ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Miha Dolenc (mihad@opencores.org)                     ////
10
////                                                              ////
11
////  All additional information is avaliable in the README       ////
12
////  file.                                                       ////
13
////                                                              ////
14
////                                                              ////
15
//////////////////////////////////////////////////////////////////////
16
////                                                              ////
17
//// Copyright (C) 2001 Miha Dolenc, mihad@opencores.org          ////
18
////                                                              ////
19
//// This source file may be used and distributed without         ////
20
//// restriction provided that this copyright statement is not    ////
21
//// removed from the file and that any derivative work contains  ////
22
//// the original copyright notice and the associated disclaimer. ////
23
////                                                              ////
24
//// This source file is free software; you can redistribute it   ////
25
//// and/or modify it under the terms of the GNU Lesser General   ////
26
//// Public License as published by the Free Software Foundation; ////
27
//// either version 2.1 of the License, or (at your option) any   ////
28
//// later version.                                               ////
29
////                                                              ////
30
//// This source is distributed in the hope that it will be       ////
31
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
32
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
33
//// PURPOSE.  See the GNU Lesser General Public License for more ////
34
//// details.                                                     ////
35
////                                                              ////
36
//// You should have received a copy of the GNU Lesser General    ////
37
//// Public License along with this source; if not, download it   ////
38
//// from http://www.opencores.org/lgpl.shtml                     ////
39
////                                                              ////
40
//////////////////////////////////////////////////////////////////////
41
//
42
// CVS Revision History
43
//
44
// $Log: not supported by cvs2svn $
45 77 mihad
// Revision 1.4  2002/08/13 11:03:53  mihad
46
// Added a few testcases. Repaired wrong reset value for PCI_AM5 register. Repaired Parity Error Detected bit setting. Changed PCI_AM0 to always enabled(regardles of PCI_AM0 define), if image 0 is used as configuration image
47
//
48 45 mihad
// Revision 1.3  2002/02/01 15:25:12  mihad
49
// Repaired a few bugs, updated specification, added test bench files and design document
50
//
51 21 mihad
// Revision 1.2  2001/10/05 08:14:30  mihad
52
// Updated all files with inclusion of timescale file for simulation purposes.
53
//
54 6 mihad
// Revision 1.1.1.1  2001/10/02 15:33:47  mihad
55
// New project directory structure
56 2 mihad
//
57 6 mihad
//
58 2 mihad
 
59 21 mihad
// synopsys translate_off
60 6 mihad
`include "timescale.v"
61 21 mihad
// synopsys translate_on
62
`include "pci_constants.v"
63
`include "bus_commands.v"
64 6 mihad
 
65 77 mihad
module pci_parity_check
66 2 mihad
(
67
    reset_in,
68
    clk_in,
69
    pci_par_in,
70
    pci_par_out,
71
    pci_par_en_out,
72
    pci_perr_in,
73
    pci_perr_out,
74
    pci_perr_out_in,
75
    pci_perr_en_out,
76
    pci_serr_en_in,
77
    pci_serr_out,
78
    pci_serr_out_in,
79
    pci_serr_en_out,
80
    pci_frame_reg_in,
81
    pci_frame_en_in,
82
    pci_irdy_en_in,
83
    pci_irdy_reg_in,
84
    pci_trdy_reg_in,
85
    pci_trdy_en_in,
86
    pci_par_en_in,
87
    pci_ad_out_in,
88
    pci_ad_reg_in,
89
    pci_cbe_in_in,
90 21 mihad
    pci_cbe_reg_in,
91 2 mihad
    pci_cbe_out_in,
92
    pci_cbe_en_in,
93
    pci_ad_en_in,
94
    par_err_response_in,
95
    par_err_detect_out,
96
    perr_mas_detect_out,
97
 
98
    serr_enable_in,
99
    sig_serr_out
100 21 mihad
 
101 2 mihad
);
102
 
103
// system inputs
104
input       reset_in ;
105
input       clk_in ;
106
 
107
// pci signals that are monitored or generated by parity error checker
108
input           pci_par_in ;            // pci PAR input
109
output          pci_par_out ;           // pci_PAR output
110
output          pci_par_en_out ;        // pci PAR enable output
111
input           pci_perr_in ;           // PERR# input
112
output          pci_perr_out ;          // PERR# output
113
output          pci_perr_en_out ;       // PERR# buffer enable output
114
input           pci_serr_en_in ;        // SERR enable input
115
output          pci_serr_out ;          // SERR# output
116
input           pci_serr_out_in ;       // SERR# output value input
117
input           pci_perr_out_in ;       // PERR# output value input
118
output          pci_serr_en_out ;       // SERR# buffer enable output
119
input           pci_frame_reg_in ;       // frame from pci bus input
120
input           pci_frame_en_in ;       // frame enable driven by master state machine
121
input           pci_irdy_en_in ;        // irdy enable input from PCI master
122
input           pci_irdy_reg_in ;        // irdy from PCI bus
123
input           pci_trdy_reg_in ;        // target ready from PCI bus
124
input           pci_trdy_en_in ;        // target ready output enable
125
input           pci_par_en_in ;         // par enable input
126
input [31:0]    pci_ad_out_in ;         // data driven by bridge to PCI
127
input [31:0]    pci_ad_reg_in ;          // data driven by other agents on PCI
128
input [3:0]     pci_cbe_in_in ;         // cbe driven by outside agents
129 21 mihad
input [3:0]     pci_cbe_reg_in ;        // registered cbe driven by outside agents
130 2 mihad
input [3:0]     pci_cbe_out_in ;        // cbe driven by pci master state machine
131
input           pci_ad_en_in ;          // ad enable input
132
input           par_err_response_in ;   // parity error response bit from conf.space
133
output          par_err_detect_out ;    // parity error detected signal out
134
output          perr_mas_detect_out ;   // master asserted PERR or sampled PERR asserted
135
input           serr_enable_in ;        // system error enable bit from conf.space
136
output          sig_serr_out ;          // signalled system error output for configuration space
137
input           pci_cbe_en_in ;
138
 
139
// FFs for frame input - used for determining whether PAR is sampled for address phase or for data phase
140
reg     frame_dec2 ;
141
reg check_perr ;
142
 
143
/*=======================================================================================================================
144 21 mihad
CBE lines' parity is needed for overall parity calculation
145 2 mihad
=======================================================================================================================*/
146
wire par_cbe_out = pci_cbe_out_in[3] ^^ pci_cbe_out_in[2] ^^ pci_cbe_out_in[1] ^^ pci_cbe_out_in[0] ;
147 21 mihad
wire par_cbe_in  = pci_cbe_reg_in[3] ^^ pci_cbe_reg_in[2] ^^ pci_cbe_reg_in[1] ^^ pci_cbe_reg_in[0] ;
148 2 mihad
 
149
/*=======================================================================================================================
150
Parity generator - parity is generated and assigned to output on every clock edge. PAR output enable is active
151
one clock cycle after data output enable. Depending on whether master is performing access or target is responding,
152 21 mihad
apropriate cbe data is included in parity generation. Non - registered CBE is used during reads through target SM
153 2 mihad
=======================================================================================================================*/
154
 
155
// generate appropriate par signal
156
wire data_par = (pci_ad_out_in[31] ^^ pci_ad_out_in[30] ^^ pci_ad_out_in[29] ^^ pci_ad_out_in[28]) ^^
157
                (pci_ad_out_in[27] ^^ pci_ad_out_in[26] ^^ pci_ad_out_in[25] ^^ pci_ad_out_in[24]) ^^
158
                (pci_ad_out_in[23] ^^ pci_ad_out_in[22] ^^ pci_ad_out_in[21] ^^ pci_ad_out_in[20]) ^^
159
                (pci_ad_out_in[19] ^^ pci_ad_out_in[18] ^^ pci_ad_out_in[17] ^^ pci_ad_out_in[16]) ^^
160
                (pci_ad_out_in[15] ^^ pci_ad_out_in[14] ^^ pci_ad_out_in[13] ^^ pci_ad_out_in[12]) ^^
161
                (pci_ad_out_in[11] ^^ pci_ad_out_in[10] ^^ pci_ad_out_in[9]  ^^ pci_ad_out_in[8])  ^^
162
                (pci_ad_out_in[7]  ^^ pci_ad_out_in[6]  ^^ pci_ad_out_in[5]  ^^ pci_ad_out_in[4])  ^^
163
                (pci_ad_out_in[3]  ^^ pci_ad_out_in[2]  ^^ pci_ad_out_in[1]  ^^ pci_ad_out_in[0]) ;
164
 
165
wire par_out_only = data_par ^^ par_cbe_out ;
166 21 mihad
 
167 77 mihad
pci_par_crit par_gen
168 2 mihad
(
169
    .par_out        (pci_par_out),
170
    .par_out_in     (par_out_only),
171
    .pci_cbe_en_in  (pci_cbe_en_in),
172
    .data_par_in    (data_par),
173
    .pci_cbe_in     (pci_cbe_in_in)
174
) ;
175
 
176
// PAR enable = ad output enable delayed by one clock
177
assign pci_par_en_out = pci_ad_en_in ;
178
 
179
/*=======================================================================================================================
180
Parity checker - parity is checked on every clock cycle. When parity error is detected, appropriate action is taken
181 21 mihad
to signal address parity errors on SERR if enabled and data parity errors on PERR# if enabled. Logic also drives
182 2 mihad
outputs to configuration space to set appropriate status bits if parity error is detected. PAR signal is checked on
183
master read operations or writes through pci target. Master read is performed when master drives irdy output and
184
doesn't drive ad lines. Writes through target are performed when target is driving trdy and doesn't drive ad lines.
185
=======================================================================================================================*/
186
 
187
// equation indicating whether to check and generate or not PERR# signal on next cycle
188
wire perr_generate =  ~pci_par_en_in && ~pci_ad_en_in                   // par was not generated on this cycle, so it should be checked
189
                      && ((pci_irdy_en_in && ~pci_trdy_reg_in) ||       // and master is driving irdy and target is signaling ready
190
                          (pci_trdy_en_in && ~pci_irdy_reg_in)) ;       // or target is driving trdy and master is signaling ready
191
 
192
wire data_in_par = (pci_ad_reg_in[31] ^^ pci_ad_reg_in[30] ^^ pci_ad_reg_in[29] ^^ pci_ad_reg_in[28]) ^^
193
                   (pci_ad_reg_in[27] ^^ pci_ad_reg_in[26] ^^ pci_ad_reg_in[25] ^^ pci_ad_reg_in[24]) ^^
194
                   (pci_ad_reg_in[23] ^^ pci_ad_reg_in[22] ^^ pci_ad_reg_in[21] ^^ pci_ad_reg_in[20]) ^^
195
                   (pci_ad_reg_in[19] ^^ pci_ad_reg_in[18] ^^ pci_ad_reg_in[17] ^^ pci_ad_reg_in[16]) ^^
196
                   (pci_ad_reg_in[15] ^^ pci_ad_reg_in[14] ^^ pci_ad_reg_in[13] ^^ pci_ad_reg_in[12]) ^^
197
                   (pci_ad_reg_in[11] ^^ pci_ad_reg_in[10] ^^ pci_ad_reg_in[9]  ^^ pci_ad_reg_in[8])  ^^
198
                   (pci_ad_reg_in[7]  ^^ pci_ad_reg_in[6]  ^^ pci_ad_reg_in[5]  ^^ pci_ad_reg_in[4])  ^^
199
                   (pci_ad_reg_in[3]  ^^ pci_ad_reg_in[2]  ^^ pci_ad_reg_in[1]  ^^ pci_ad_reg_in[0]) ;
200
 
201
//wire perr = (cbe_par_reg ^ pci_par_in ^ data_in_par) ;
202
wire perr ;
203
wire perr_n ;
204
wire perr_en ;
205
 
206
assign pci_perr_out = perr_n ;
207
 
208
// parity error output assignment
209
//assign pci_perr_out = ~(perr && perr_generate) ;
210
 
211 21 mihad
wire non_critical_par = par_cbe_in ^^ data_in_par ;
212 2 mihad
 
213 77 mihad
pci_perr_crit perr_crit_gen
214 2 mihad
(
215
    .perr_out           (perr),
216
    .perr_n_out         (perr_n),
217
    .non_critical_par_in(non_critical_par),
218
    .pci_par_in         (pci_par_in),
219
    .perr_generate_in   (perr_generate)
220
) ;
221
 
222
// PERR# enable
223
wire pci_perr_en_reg ;
224 77 mihad
pci_perr_en_crit perr_en_crit_gen
225 2 mihad
(
226
    .reset_in               (reset_in),
227
    .clk_in                 (clk_in),
228
    .perr_en_out            (pci_perr_en_out),
229
    .perr_en_reg_out        (pci_perr_en_reg),
230
    .non_critical_par_in    (non_critical_par),
231
    .pci_par_in             (pci_par_in),
232
    .perr_generate_in       (perr_generate),
233
    .par_err_response_in    (par_err_response_in)
234
) ;
235
 
236
// address phase decoding
237
always@(posedge reset_in or posedge clk_in)
238
begin
239
    if (reset_in)
240
        frame_dec2 <= #`FF_DELAY 1'b0 ;
241
    else
242 21 mihad
        frame_dec2 <= #`FF_DELAY pci_frame_reg_in ;
243 2 mihad
end
244
 
245 21 mihad
// address phase parity error checking - done after address phase is detected - which is - when bridge's master is not driving frame,
246
// frame was asserted on previous cycle and was not asserted two cycles before.
247
wire check_for_serr_on_first = ~pci_frame_reg_in && frame_dec2  && ~pci_frame_en_in ;
248 2 mihad
 
249 21 mihad
reg  check_for_serr_on_second ;
250
always@(posedge reset_in or posedge clk_in)
251
begin
252
    if ( reset_in )
253
        check_for_serr_on_second <= #`FF_DELAY 1'b0 ;
254
    else
255
        check_for_serr_on_second <= #`FF_DELAY check_for_serr_on_first && ( pci_cbe_reg_in == `BC_DUAL_ADDR_CYC ) ;
256
end
257
 
258
wire check_for_serr = check_for_serr_on_first || check_for_serr_on_second ;
259
 
260
wire serr_generate = check_for_serr && serr_enable_in && par_err_response_in ;
261
 
262 77 mihad
pci_serr_en_crit serr_en_crit_gen
263 2 mihad
(
264
    .serr_en_out        (pci_serr_en_out),
265
    .pci_par_in         (pci_par_in),
266
    .non_critical_par_in(non_critical_par),
267
    .serr_generate_in   (serr_generate)
268
);
269
 
270
 
271
// serr is enabled only for reporting errors - route this signal to configuration space
272
assign sig_serr_out = pci_serr_en_in ;
273
 
274
// SERR# output is always 0, just enable is driven apropriately
275 77 mihad
pci_serr_crit serr_crit_gen
276 2 mihad
(
277
    .serr_out               (pci_serr_out),
278
    .non_critical_par_in    (non_critical_par),
279
    .pci_par_in             (pci_par_in),
280
    .serr_check_in          (check_for_serr)
281
);
282
 
283
/*=======================================================================================================================================
284
    Synchronizing mechanism detecting what is supposed to be done - PERR# generation or PERR# checking
285
=======================================================================================================================================*/
286
// perr should be checked one clock after PAR is generated
287
always@(posedge reset_in or posedge clk_in)
288
begin
289
    if ( reset_in )
290
        check_perr <= #`FF_DELAY 1'b0 ;
291
    else
292
        check_perr <= #`FF_DELAY pci_par_en_in ;
293
end
294
 
295
wire perr_sampled_in = ~pci_perr_in && check_perr ;
296
reg perr_sampled ;
297
always@(posedge reset_in or posedge clk_in)
298
begin
299
    if (reset_in)
300
        perr_sampled <= #`FF_DELAY 1'b0 ;
301
    else
302
        perr_sampled <= #`FF_DELAY perr_sampled_in ;
303
end
304
 
305
// assign output for parity error detected bit
306 45 mihad
assign par_err_detect_out = ~pci_serr_out_in || ~pci_perr_out_in ;//|| perr_sampled ; MihaD - removed - detected parity error is set only during Master Reads or Target Writes
307 2 mihad
 
308
// FF indicating that that last operation was done as bus master
309 21 mihad
reg frame_and_irdy_en_prev      ;
310
reg frame_and_irdy_en_prev_prev ;
311 2 mihad
reg master_perr_report ;
312
always@(posedge reset_in or posedge clk_in)
313
begin
314
    if ( reset_in )
315 21 mihad
    begin
316
        master_perr_report          <= #`FF_DELAY 1'b0 ;
317
        frame_and_irdy_en_prev      <= #`FF_DELAY 1'b0 ;
318
        frame_and_irdy_en_prev_prev <= #`FF_DELAY 1'b0 ;
319
    end
320 2 mihad
    else
321 21 mihad
    begin
322
        master_perr_report          <= #`FF_DELAY frame_and_irdy_en_prev_prev ;
323
        frame_and_irdy_en_prev      <= #`FF_DELAY pci_irdy_en_in && pci_frame_en_in ;
324
        frame_and_irdy_en_prev_prev <= #`FF_DELAY frame_and_irdy_en_prev ;
325
    end
326 2 mihad
end
327
 
328
assign perr_mas_detect_out = master_perr_report && ( (par_err_response_in && perr_sampled) || pci_perr_en_reg ) ;
329
 
330 21 mihad
endmodule

powered by: WebSVN 2.1.0

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