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

Subversion Repositories crcahb

[/] [crcahb/] [trunk/] [rtl/] [host_interface.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 redbear
//////////////////////////////////////////////////////////////////
2
////
3
////
4
////    CRCAHB CORE BLOCK
5
////
6
////
7
////
8
//// This file is part of the APB to I2C project
9
////
10
//// http://www.opencores.org/cores/apbi2c/
11
////
12
////
13
////
14
//// Description
15
////
16
//// Implementation of APB IP core according to
17
////
18
//// crcahb IP core specification document.
19
////
20
////
21
////
22
//// To Do: Things are right here but always all block can suffer changes
23
////
24
////
25
////
26
////
27
////
28
//// Author(s): -  Julio Cesar 
29
////
30
///////////////////////////////////////////////////////////////// 
31
////
32
////
33
//// Copyright (C) 2009 Authors and OPENCORES.ORG
34
////
35
////
36
////
37
//// This source file may be used and distributed without
38
////
39
//// restriction provided that this copyright statement is not
40
////
41
//// removed from the file and that any derivative work contains
42
//// the original copyright notice and the associated disclaimer.
43
////
44
////
45
//// This source file is free software; you can redistribute it
46
////
47
//// and/or modify it under the terms of the GNU Lesser General
48
////
49
//// Public License as published by the Free Software Foundation;
50
//// either version 2.1 of the License, or (at your option) any
51
////
52
//// later version.
53
////
54
////
55
////
56
//// This source is distributed in the hope that it will be
57
////
58
//// useful, but WITHOUT ANY WARRANTY; without even the implied
59
////
60
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
61
////
62
//// PURPOSE. See the GNU Lesser General Public License for more
63
//// details.
64
////
65
////
66
////
67
//// You should have received a copy of the GNU Lesser General
68
////
69
//// Public License along with this source; if not, download it
70
////
71
//// from http://www.opencores.org/lgpl.shtml
72
////
73
////
74
///////////////////////////////////////////////////////////////////
75 2 julioameri
module host_interface
76
(
77
        //OUTPUTS
78
        output [31:0] HRDATA,
79
        output HREADYOUT,
80
        output HRESP,
81
        output [31:0] bus_wr,
82
        output [ 1:0] crc_poly_size,
83
        output [ 1:0] bus_size,
84
        output [ 1:0] rev_in_type,
85
        output rev_out_type,
86
        output crc_init_en,
87
        output crc_idr_en,
88
        output crc_poly_en,
89
        output buffer_write_en,
90
        output reset_chain,
91
        //INPUTS
92
        input [31:0] HWDATA,
93
        input [31:0] HADDR,
94
        input [ 2:0] HSIZE,
95
        input [ 1:0] HTRANS,
96
        input HWRITE,
97
        input HSElx,
98
        input HREADY,
99
        input HRESETn,
100
        input HCLK,
101
        input [31:0] crc_poly_out,
102
        input [31:0] crc_out,
103
        input [31:0] crc_init_out,
104
        input [ 7:0] crc_idr_out,
105
        input buffer_full,
106
        input reset_pending,
107
        input read_wait
108
);
109
 
110
//Reset Values
111
localparam RESET_CRC_CR = 6'h00;
112
 
113
//CRC Register Map
114
localparam CRC_DR   = 3'h0;
115
localparam CRC_IDR  = 3'h1;
116
localparam CRC_CR   = 3'h2;
117
localparam CRC_INIT = 3'h4;
118
localparam CRC_POL  = 3'h5;
119
 
120
//Transfer Type Encoding
121
localparam IDLE    = 2'b00;
122
localparam BUSY    = 2'b01;
123
localparam NON_SEQ = 2'b10;
124
localparam SEQ     = 2'b11;
125
 
126
//HRESP Encoding
127
localparam OK    = 1'b0;
128
localparam ERROR = 1'b1;
129
 
130
//Pipeline flops
131
reg [2:0] haddr_pp;
132
reg [2:0] hsize_pp;
133
reg [1:0] htrans_pp;
134
reg hwrite_pp;
135
reg hselx_pp;
136
 
137
//Flops
138
reg [4:0] crc_cr_ff;
139
 
140
//Internal Signals
141
wire [31:0] crc_cr_rd;
142
wire crc_dr_sel;
143
wire crc_init_sel;
144
wire crc_idr_sel;
145
wire crc_poly_sel;
146
wire crc_cr_sel;
147
wire ahb_enable;
148
wire write_en;
149
wire read_en;
150
wire crc_cr_en;
151
wire sample_bus;
152
wire buffer_read_en;
153
 
154
//Pipeline Registers for Address Phase of AHB Protocol
155
always @(posedge HCLK)
156
        begin
157
                if(!HRESETn)
158
                        begin
159
                                hselx_pp <= 1'b0;
160
                        end
161
                else
162
                        if(sample_bus)
163
                                begin
164
                                        haddr_pp  <= HADDR[4:2];
165
                                        hsize_pp  <= HSIZE;
166
                                        htrans_pp <= HTRANS;
167
                                        hwrite_pp <= HWRITE;
168
                                        hselx_pp  <= HSElx;
169
                                end
170
        end
171
 
172
//Enable Signals
173
assign ahb_enable = (htrans_pp == NON_SEQ);
174
assign write_en = hselx_pp &&  hwrite_pp && ahb_enable;
175
assign read_en  = hselx_pp && !hwrite_pp && ahb_enable;
176
 
177
//Registers decoding
178
assign crc_dr_sel   = (haddr_pp == CRC_DR  );
179
assign crc_init_sel = (haddr_pp == CRC_INIT);
180
assign crc_idr_sel  = (haddr_pp == CRC_IDR );
181
assign crc_poly_sel = (haddr_pp == CRC_POL );
182
assign crc_cr_sel   = (haddr_pp == CRC_CR  );
183
 
184
//Write Esnables Signals for Registers
185
assign buffer_write_en = crc_dr_sel   && write_en;
186
assign crc_init_en     = crc_init_sel && write_en;
187
assign crc_idr_en      = crc_idr_sel  && write_en;
188
assign crc_poly_en     = crc_poly_sel && write_en;
189
assign crc_cr_en       = crc_cr_sel   && write_en;
190
 
191
//Indicates reading operation request to crc_dr register
192
assign buffer_read_en = crc_dr_sel && read_en;
193
 
194
//Bus Size is the output of HSIZE pipeline register
195
assign bus_size = hsize_pp;
196
 
197
//The Write Bus is not pipelined
198
assign bus_wr = HWDATA;
199
 
200
//HREADY Signal outputed to Master
201
assign HREADYOUT = !((buffer_write_en && buffer_full   ) ||
202
                     (buffer_read_en  && read_wait     ) ||
203
                     (crc_init_en     && reset_pending ) );
204
 
205
//Signal to control sampling of bus
206
assign sample_bus = HREADYOUT && HREADY;
207
 
208
//HRESP Signal outputed to Master
209
//This implementation never signalize bus error to master
210
assign HRESP = OK;
211
 
212
//CRC_CR Data Read
213
assign crc_cr_rd = {24'h0, crc_cr_ff[4:0], 3'h0};
214
 
215
//Mux to HRDATA
216
assign HRDATA = ({32{crc_dr_sel  }} & crc_out             ) |
217
                ({32{crc_init_sel}} & crc_init_out        ) |
218
                ({32{crc_idr_sel }} & {24'h0, crc_idr_out}) |
219
                ({32{crc_poly_sel}} & crc_poly_out        ) |
220
                ({32{crc_cr_sel  }} & crc_cr_rd           ) ;
221
 
222
//Control Register
223
always @(posedge HCLK)
224
        begin
225
                if(!HRESETn)
226
                        crc_cr_ff <= RESET_CRC_CR;
227
                else
228
                        if(crc_cr_en)
229
                                crc_cr_ff <= {HWDATA[7], HWDATA[6:5], HWDATA[4:3]};
230
        end
231
 
232
//Configuration Signals
233
assign reset_chain   = (crc_cr_en && HWDATA[0]);
234
assign crc_poly_size = crc_cr_ff[1:0];
235
assign rev_in_type   = crc_cr_ff[3:2];
236
assign rev_out_type  = crc_cr_ff[4];
237
 
238
endmodule

powered by: WebSVN 2.1.0

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