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

Subversion Repositories pci

[/] [pci/] [tags/] [working_demo/] [rtl/] [verilog/] [pci_parity_check.v] - Blame information for rev 154

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 6 mihad
// Revision 1.1.1.1  2001/10/02 15:33:47  mihad
46
// New project directory structure
47 2 mihad
//
48 6 mihad
//
49 2 mihad
 
50
`include "constants.v"
51 6 mihad
`include "timescale.v"
52
 
53 2 mihad
module PCI_PARITY_CHECK
54
(
55
    reset_in,
56
    clk_in,
57
    pci_par_in,
58
    pci_par_out,
59
    pci_par_en_out,
60
    pci_perr_in,
61
    pci_perr_out,
62
    pci_perr_out_in,
63
    pci_perr_en_out,
64
    pci_serr_en_in,
65
    pci_serr_out,
66
    pci_serr_out_in,
67
    pci_serr_en_out,
68
    pci_frame_reg_in,
69
    pci_frame_en_in,
70
    pci_irdy_en_in,
71
    pci_irdy_reg_in,
72
    pci_trdy_reg_in,
73
    pci_trdy_en_in,
74
    pci_par_en_in,
75
    pci_ad_out_in,
76
    pci_ad_reg_in,
77
    pci_cbe_in_in,
78
    pci_cbe_out_in,
79
    pci_cbe_en_in,
80
    pci_ad_en_in,
81
    par_err_response_in,
82
    par_err_detect_out,
83
    perr_mas_detect_out,
84
 
85
    serr_enable_in,
86
    sig_serr_out
87
 
88
);
89
 
90
// system inputs
91
input       reset_in ;
92
input       clk_in ;
93
 
94
// pci signals that are monitored or generated by parity error checker
95
input           pci_par_in ;            // pci PAR input
96
output          pci_par_out ;           // pci_PAR output
97
output          pci_par_en_out ;        // pci PAR enable output
98
input           pci_perr_in ;           // PERR# input
99
output          pci_perr_out ;          // PERR# output
100
output          pci_perr_en_out ;       // PERR# buffer enable output
101
input           pci_serr_en_in ;        // SERR enable input
102
output          pci_serr_out ;          // SERR# output
103
input           pci_serr_out_in ;       // SERR# output value input
104
input           pci_perr_out_in ;       // PERR# output value input
105
output          pci_serr_en_out ;       // SERR# buffer enable output
106
input           pci_frame_reg_in ;       // frame from pci bus input
107
input           pci_frame_en_in ;       // frame enable driven by master state machine
108
input           pci_irdy_en_in ;        // irdy enable input from PCI master
109
input           pci_irdy_reg_in ;        // irdy from PCI bus
110
input           pci_trdy_reg_in ;        // target ready from PCI bus
111
input           pci_trdy_en_in ;        // target ready output enable
112
input           pci_par_en_in ;         // par enable input
113
input [31:0]    pci_ad_out_in ;         // data driven by bridge to PCI
114
input [31:0]    pci_ad_reg_in ;          // data driven by other agents on PCI
115
input [3:0]     pci_cbe_in_in ;         // cbe driven by outside agents
116
input [3:0]     pci_cbe_out_in ;        // cbe driven by pci master state machine
117
input           pci_ad_en_in ;          // ad enable input
118
input           par_err_response_in ;   // parity error response bit from conf.space
119
output          par_err_detect_out ;    // parity error detected signal out
120
output          perr_mas_detect_out ;   // master asserted PERR or sampled PERR asserted
121
input           serr_enable_in ;        // system error enable bit from conf.space
122
output          sig_serr_out ;          // signalled system error output for configuration space
123
input           pci_cbe_en_in ;
124
 
125
// FFs for frame input - used for determining whether PAR is sampled for address phase or for data phase
126
reg     frame_dec2 ;
127
reg check_perr ;
128
 
129
/*=======================================================================================================================
130
Input and output data sampling - used by parity checking and generation logic
131
=======================================================================================================================*/
132
wire par_cbe_out = pci_cbe_out_in[3] ^^ pci_cbe_out_in[2] ^^ pci_cbe_out_in[1] ^^ pci_cbe_out_in[0] ;
133
wire par_cbe_include ;
134
 
135
PAR_CBE_CRIT cbe_par_calc
136
(
137
    .par_cbe_include_out(par_cbe_include),
138
    .par_cbe_out_in     (par_cbe_out),
139
    .par_cbe_en_in      (pci_cbe_en_in),
140
    .pci_cbe_in         (pci_cbe_in_in)
141
) ;
142
 
143
reg  cbe_par_reg ;
144
always@( posedge reset_in or posedge clk_in )
145
begin
146
    if (reset_in)
147
        cbe_par_reg <= #`FF_DELAY 1'b0 ;
148
    else
149
        cbe_par_reg <= #`FF_DELAY par_cbe_include ;
150
end
151
 
152
/*=======================================================================================================================
153
Parity generator - parity is generated and assigned to output on every clock edge. PAR output enable is active
154
one clock cycle after data output enable. Depending on whether master is performing access or target is responding,
155
apropriate cbe data is included in parity generation.
156
=======================================================================================================================*/
157
 
158
// generate appropriate par signal
159
wire data_par = (pci_ad_out_in[31] ^^ pci_ad_out_in[30] ^^ pci_ad_out_in[29] ^^ pci_ad_out_in[28]) ^^
160
                (pci_ad_out_in[27] ^^ pci_ad_out_in[26] ^^ pci_ad_out_in[25] ^^ pci_ad_out_in[24]) ^^
161
                (pci_ad_out_in[23] ^^ pci_ad_out_in[22] ^^ pci_ad_out_in[21] ^^ pci_ad_out_in[20]) ^^
162
                (pci_ad_out_in[19] ^^ pci_ad_out_in[18] ^^ pci_ad_out_in[17] ^^ pci_ad_out_in[16]) ^^
163
                (pci_ad_out_in[15] ^^ pci_ad_out_in[14] ^^ pci_ad_out_in[13] ^^ pci_ad_out_in[12]) ^^
164
                (pci_ad_out_in[11] ^^ pci_ad_out_in[10] ^^ pci_ad_out_in[9]  ^^ pci_ad_out_in[8])  ^^
165
                (pci_ad_out_in[7]  ^^ pci_ad_out_in[6]  ^^ pci_ad_out_in[5]  ^^ pci_ad_out_in[4])  ^^
166
                (pci_ad_out_in[3]  ^^ pci_ad_out_in[2]  ^^ pci_ad_out_in[1]  ^^ pci_ad_out_in[0]) ;
167
 
168
wire par_out_only = data_par ^^ par_cbe_out ;
169
PAR_CRIT par_gen
170
(
171
    .par_out        (pci_par_out),
172
    .par_out_in     (par_out_only),
173
    .pci_cbe_en_in  (pci_cbe_en_in),
174
    .data_par_in    (data_par),
175
    .pci_cbe_in     (pci_cbe_in_in)
176
) ;
177
 
178
// PAR enable = ad output enable delayed by one clock
179
assign pci_par_en_out = pci_ad_en_in ;
180
 
181
/*=======================================================================================================================
182
Parity checker - parity is checked on every clock cycle. When parity error is detected, appropriate action is taken
183
to signal address parity errors on SERR if enabled and data parity errors on PERR# if enabled. Logic also drives
184
outputs to configuration space to set appropriate status bits if parity error is detected. PAR signal is checked on
185
master read operations or writes through pci target. Master read is performed when master drives irdy output and
186
doesn't drive ad lines. Writes through target are performed when target is driving trdy and doesn't drive ad lines.
187
=======================================================================================================================*/
188
 
189
// equation indicating whether to check and generate or not PERR# signal on next cycle
190
wire perr_generate =  ~pci_par_en_in && ~pci_ad_en_in                   // par was not generated on this cycle, so it should be checked
191
                      && ((pci_irdy_en_in && ~pci_trdy_reg_in) ||       // and master is driving irdy and target is signaling ready
192
                          (pci_trdy_en_in && ~pci_irdy_reg_in)) ;       // or target is driving trdy and master is signaling ready
193
 
194
wire data_in_par = (pci_ad_reg_in[31] ^^ pci_ad_reg_in[30] ^^ pci_ad_reg_in[29] ^^ pci_ad_reg_in[28]) ^^
195
                   (pci_ad_reg_in[27] ^^ pci_ad_reg_in[26] ^^ pci_ad_reg_in[25] ^^ pci_ad_reg_in[24]) ^^
196
                   (pci_ad_reg_in[23] ^^ pci_ad_reg_in[22] ^^ pci_ad_reg_in[21] ^^ pci_ad_reg_in[20]) ^^
197
                   (pci_ad_reg_in[19] ^^ pci_ad_reg_in[18] ^^ pci_ad_reg_in[17] ^^ pci_ad_reg_in[16]) ^^
198
                   (pci_ad_reg_in[15] ^^ pci_ad_reg_in[14] ^^ pci_ad_reg_in[13] ^^ pci_ad_reg_in[12]) ^^
199
                   (pci_ad_reg_in[11] ^^ pci_ad_reg_in[10] ^^ pci_ad_reg_in[9]  ^^ pci_ad_reg_in[8])  ^^
200
                   (pci_ad_reg_in[7]  ^^ pci_ad_reg_in[6]  ^^ pci_ad_reg_in[5]  ^^ pci_ad_reg_in[4])  ^^
201
                   (pci_ad_reg_in[3]  ^^ pci_ad_reg_in[2]  ^^ pci_ad_reg_in[1]  ^^ pci_ad_reg_in[0]) ;
202
 
203
//wire perr = (cbe_par_reg ^ pci_par_in ^ data_in_par) ;
204
wire perr ;
205
wire perr_n ;
206
wire perr_en ;
207
 
208
assign pci_perr_out = perr_n ;
209
 
210
// parity error output assignment
211
//assign pci_perr_out = ~(perr && perr_generate) ;
212
 
213
wire non_critical_par = cbe_par_reg ^^ data_in_par ;
214
 
215
PERR_CRIT perr_crit_gen
216
(
217
    .perr_out           (perr),
218
    .perr_n_out         (perr_n),
219
    .non_critical_par_in(non_critical_par),
220
    .pci_par_in         (pci_par_in),
221
    .perr_generate_in   (perr_generate)
222
) ;
223
 
224
// PERR# enable
225
wire pci_perr_en_reg ;
226
PERR_EN_CRIT perr_en_crit_gen
227
(
228
    .reset_in               (reset_in),
229
    .clk_in                 (clk_in),
230
    .perr_en_out            (pci_perr_en_out),
231
    .perr_en_reg_out        (pci_perr_en_reg),
232
    .non_critical_par_in    (non_critical_par),
233
    .pci_par_in             (pci_par_in),
234
    .perr_generate_in       (perr_generate),
235
    .par_err_response_in    (par_err_response_in)
236
) ;
237
 
238
// address phase decoding
239
always@(posedge reset_in or posedge clk_in)
240
begin
241
    if (reset_in)
242
        frame_dec2 <= #`FF_DELAY 1'b0 ;
243
    else
244
        frame_dec2 <= #`FF_DELAY pci_frame_reg_in && ~pci_frame_en_in ;
245
end
246
 
247
// address phase parity indicator
248
wire check_for_serr = ~pci_frame_reg_in && frame_dec2 ;
249
wire serr_generate  = check_for_serr && serr_enable_in && par_err_response_in ;
250
 
251
SERR_EN_CRIT serr_en_crit_gen
252
(
253
    .serr_en_out        (pci_serr_en_out),
254
    .pci_par_in         (pci_par_in),
255
    .non_critical_par_in(non_critical_par),
256
    .serr_generate_in   (serr_generate)
257
);
258
 
259
 
260
// serr is enabled only for reporting errors - route this signal to configuration space
261
assign sig_serr_out = pci_serr_en_in ;
262
 
263
// SERR# output is always 0, just enable is driven apropriately
264
SERR_CRIT serr_crit_gen
265
(
266
    .serr_out               (pci_serr_out),
267
    .non_critical_par_in    (non_critical_par),
268
    .pci_par_in             (pci_par_in),
269
    .serr_check_in          (check_for_serr)
270
);
271
 
272
/*=======================================================================================================================================
273
    Synchronizing mechanism detecting what is supposed to be done - PERR# generation or PERR# checking
274
=======================================================================================================================================*/
275
// perr should be checked one clock after PAR is generated
276
always@(posedge reset_in or posedge clk_in)
277
begin
278
    if ( reset_in )
279
        check_perr <= #`FF_DELAY 1'b0 ;
280
    else
281
        check_perr <= #`FF_DELAY pci_par_en_in ;
282
end
283
 
284
wire perr_sampled_in = ~pci_perr_in && check_perr ;
285
reg perr_sampled ;
286
always@(posedge reset_in or posedge clk_in)
287
begin
288
    if (reset_in)
289
        perr_sampled <= #`FF_DELAY 1'b0 ;
290
    else
291
        perr_sampled <= #`FF_DELAY perr_sampled_in ;
292
end
293
 
294
// assign output for parity error detected bit
295
assign par_err_detect_out = ~pci_serr_out_in || ~pci_perr_out_in || perr_sampled ;
296
 
297
// FF indicating that that last operation was done as bus master
298
reg master_perr_report ;
299
always@(posedge reset_in or posedge clk_in)
300
begin
301
    if ( reset_in )
302
        master_perr_report <= #`FF_DELAY 1'b0 ;
303
    else
304
        master_perr_report <= #`FF_DELAY pci_irdy_en_in ;
305
end
306
 
307
assign perr_mas_detect_out = master_perr_report && ( (par_err_response_in && perr_sampled) || pci_perr_en_reg ) ;
308
 
309
endmodule

powered by: WebSVN 2.1.0

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