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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_3/] [rtl/] [verilog/] [decoder.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: decoder.v                                        ////
4
////                                                              ////
5
////  This file is part of the "PCI bridge" project               ////
6
////  http://www.opencores.org/cores/pci/                         ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Tadej Markovic, tadej@opencores.org                   ////
10
////      - Tilen Novak, tilen@opencores.org                      ////
11
////                                                              ////
12
////  All additional information is avaliable in the README.txt   ////
13
////  file.                                                       ////
14
////                                                              ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18
//// Copyright (C) 2000 Tadej Markovic, tadej@opencores.org       ////
19
////                    Tilen Novak, tilen@opencores.org          ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE.  See the GNU Lesser General Public License for more ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from http://www.opencores.org/lgpl.shtml                     ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43
//
44
// CVS Revision History
45
//
46
// $Log: not supported by cvs2svn $
47
//
48
 
49
`include "constants.v"
50
 
51
module DECODER (hit, addr_out, addr_in, base_addr, mask_addr, tran_addr, at_en) ;
52
 
53
// Decoding address size parameter - for FPGAs 1MegByte is recommended
54
//   MAXIMUM is 20 (4KBytes), length 12 is 1 MByte !!!
55
parameter               decode_len     = 12 ;
56
 
57
//###########################################################################################################
58
// ALL COMMENTS are written as there were decode_len 20. This number and 12 (32 - 20) are assigning the 
59
// numbers of decoded and compared bits, etc.
60
//###########################################################################################################
61
 
62
/*-----------------------------------------------------------------------------------------------------------
63
DECODER interface decodes input address (ADDR_IN); what means that it validates (HIT), if input address
64
falls within the defined image space boundaries. Image space boundarie is defined with image base address
65
register (BASE_ADDR) and address mask register (MASK_ADDR).
66
Beside that, it also translates (maps) the input address to the output address (ADDR_OUT), regarding the
67
translation address register (TRAN_ADDR) and the address mask register.
68
-----------------------------------------------------------------------------------------------------------*/
69
 
70
// output control  
71
output  hit ;
72
// output address 
73
output  [31:0]   addr_out ;
74
// input address
75
input   [31:0]   addr_in ;
76
 
77
// input registers - 12 LSbits are not valid since the smallest possible size is 4KB !
78
input   [31:(32-decode_len)]    base_addr ;
79
input   [31:(32-decode_len)]    mask_addr ;
80
input   [31:(32-decode_len)]    tran_addr ;
81
 
82
// input bit[2] of the Image Control register used to enable the address translation !
83
input   at_en ;
84
/*-----------------------------------------------------------------------------------------------------------
85
Internal signals !
86
-----------------------------------------------------------------------------------------------------------*/
87
 
88
// bit[31] if address mask register is IMAGE ENABLE bit (img_en)
89
wire    img_en ;
90
 
91
// addr_in_compare are masked input address bits that are compared with masked base_addr
92
wire    [31:(32-decode_len)]    addr_in_compare ;
93
// base_addr_compare are masked base address bits that are compared with masked addr_in
94
wire    [31:(32-decode_len)]    base_addr_compare ;
95
 
96
/*-----------------------------------------------------------------------------------------------------------
97
Decoding the input address!
98
This logic produces the loghest path in this module!
99
 
100
20 MSbits of input addres are as well as base address (20 bits) masked with corrected address mask. Only
101
masked bits of each vector are actually logically compared.
102
Bit[31] of address mask register is used to enable the image space !
103
-----------------------------------------------------------------------------------------------------------*/
104
 
105
assign addr_in_compare = (addr_in[31:(32-decode_len)] & mask_addr) ;
106
 
107
assign base_addr_compare = (base_addr & mask_addr) ;
108
 
109
assign img_en = mask_addr[31] ;
110
 
111
assign hit = { 1'b1, addr_in_compare } == { img_en, base_addr_compare } ;
112
 
113
/*-----------------------------------------------------------------------------------------------------------
114
Translating the input address!
115
 
116
Translation of input address is not implemented if ADDR_TRAN_IMPL is not defined
117
 
118
20 MSbits of input address are masked with negated value of the corrected address mask in order to get
119
address bits of the input address which won't be replaced with translation address bits.
120
Translation address bits (20 bits) are masked with corrected address mask. Only masked bits of vector are
121
actually valid, all others are zero.
122
Boath vectors are bit-wise ORed in order to get the valid translation address with an offset of an input
123
address.
124
12 LSbits of an input address are assigned to 12 LSbits of an output addres.
125
-----------------------------------------------------------------------------------------------------------*/
126
 
127
`ifdef ADDR_TRAN_IMPL
128
    // if Address Translation Enable bit is set, then translation address is used othervise input address is used!
129
    // addr_in_combine input address bits are not replaced with translation address!
130
    wire        [31:(32-decode_len)] addr_in_combine ;
131
    // tran_addr_combine are masked and combined with addr_in_combine!
132
    reg         [31:(32-decode_len)] tran_addr_combine ;
133
 
134
    assign addr_in_combine = (addr_in[31:(32-decode_len)] & ~mask_addr) ;
135
    always@(at_en or tran_addr or mask_addr or addr_in)
136
        begin
137
            if (at_en)
138
                        begin
139
                                tran_addr_combine <= (tran_addr & mask_addr) ;
140
                end
141
        else
142
                        begin
143
                                tran_addr_combine <= (addr_in[31:(32-decode_len)] & mask_addr) ;
144
                        end
145
        end
146
 
147
    assign addr_out[31:(32-decode_len)] = addr_in_combine | tran_addr_combine ;
148
    assign addr_out[(31-decode_len):0] = addr_in [(31-decode_len):0] ;
149
`else
150
    assign addr_out = addr_in ;
151
`endif
152
 
153
endmodule
154
 

powered by: WebSVN 2.1.0

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