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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_1/] [rtl/] [verilog/] [pci_parity_check.v] - Blame information for rev 2

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

powered by: WebSVN 2.1.0

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