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

Subversion Repositories crcahb

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

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

Line No. Rev Author Line
1 2 julioameri
module host_interface
2
(
3
        //OUTPUTS
4
        output [31:0] HRDATA,
5
        output HREADYOUT,
6
        output HRESP,
7
        output [31:0] bus_wr,
8
        output [ 1:0] crc_poly_size,
9
        output [ 1:0] bus_size,
10
        output [ 1:0] rev_in_type,
11
        output rev_out_type,
12
        output crc_init_en,
13
        output crc_idr_en,
14
        output crc_poly_en,
15
        output buffer_write_en,
16
        output reset_chain,
17
        //INPUTS
18
        input [31:0] HWDATA,
19
        input [31:0] HADDR,
20
        input [ 2:0] HSIZE,
21
        input [ 1:0] HTRANS,
22
        input HWRITE,
23
        input HSElx,
24
        input HREADY,
25
        input HRESETn,
26
        input HCLK,
27
        input [31:0] crc_poly_out,
28
        input [31:0] crc_out,
29
        input [31:0] crc_init_out,
30
        input [ 7:0] crc_idr_out,
31
        input buffer_full,
32
        input reset_pending,
33
        input read_wait
34
);
35
 
36
//Reset Values
37
localparam RESET_CRC_CR = 6'h00;
38
 
39
//CRC Register Map
40
localparam CRC_DR   = 3'h0;
41
localparam CRC_IDR  = 3'h1;
42
localparam CRC_CR   = 3'h2;
43
localparam CRC_INIT = 3'h4;
44
localparam CRC_POL  = 3'h5;
45
 
46
//Transfer Type Encoding
47
localparam IDLE    = 2'b00;
48
localparam BUSY    = 2'b01;
49
localparam NON_SEQ = 2'b10;
50
localparam SEQ     = 2'b11;
51
 
52
//HRESP Encoding
53
localparam OK    = 1'b0;
54
localparam ERROR = 1'b1;
55
 
56
//Pipeline flops
57
reg [2:0] haddr_pp;
58
reg [2:0] hsize_pp;
59
reg [1:0] htrans_pp;
60
reg hwrite_pp;
61
reg hselx_pp;
62
 
63
//Flops
64
reg [4:0] crc_cr_ff;
65
 
66
//Internal Signals
67
wire [31:0] crc_cr_rd;
68
wire crc_dr_sel;
69
wire crc_init_sel;
70
wire crc_idr_sel;
71
wire crc_poly_sel;
72
wire crc_cr_sel;
73
wire ahb_enable;
74
wire write_en;
75
wire read_en;
76
wire crc_cr_en;
77
wire sample_bus;
78
wire buffer_read_en;
79
 
80
//Pipeline Registers for Address Phase of AHB Protocol
81
always @(posedge HCLK)
82
        begin
83
                if(!HRESETn)
84
                        begin
85
                                hselx_pp <= 1'b0;
86
                        end
87
                else
88
                        if(sample_bus)
89
                                begin
90
                                        haddr_pp  <= HADDR[4:2];
91
                                        hsize_pp  <= HSIZE;
92
                                        htrans_pp <= HTRANS;
93
                                        hwrite_pp <= HWRITE;
94
                                        hselx_pp  <= HSElx;
95
                                end
96
        end
97
 
98
//Enable Signals
99
assign ahb_enable = (htrans_pp == NON_SEQ);
100
assign write_en = hselx_pp &&  hwrite_pp && ahb_enable;
101
assign read_en  = hselx_pp && !hwrite_pp && ahb_enable;
102
 
103
//Registers decoding
104
assign crc_dr_sel   = (haddr_pp == CRC_DR  );
105
assign crc_init_sel = (haddr_pp == CRC_INIT);
106
assign crc_idr_sel  = (haddr_pp == CRC_IDR );
107
assign crc_poly_sel = (haddr_pp == CRC_POL );
108
assign crc_cr_sel   = (haddr_pp == CRC_CR  );
109
 
110
//Write Esnables Signals for Registers
111
assign buffer_write_en = crc_dr_sel   && write_en;
112
assign crc_init_en     = crc_init_sel && write_en;
113
assign crc_idr_en      = crc_idr_sel  && write_en;
114
assign crc_poly_en     = crc_poly_sel && write_en;
115
assign crc_cr_en       = crc_cr_sel   && write_en;
116
 
117
//Indicates reading operation request to crc_dr register
118
assign buffer_read_en = crc_dr_sel && read_en;
119
 
120
//Bus Size is the output of HSIZE pipeline register
121
assign bus_size = hsize_pp;
122
 
123
//The Write Bus is not pipelined
124
assign bus_wr = HWDATA;
125
 
126
//HREADY Signal outputed to Master
127
assign HREADYOUT = !((buffer_write_en && buffer_full   ) ||
128
                     (buffer_read_en  && read_wait     ) ||
129
                     (crc_init_en     && reset_pending ) );
130
 
131
//Signal to control sampling of bus
132
assign sample_bus = HREADYOUT && HREADY;
133
 
134
//HRESP Signal outputed to Master
135
//This implementation never signalize bus error to master
136
assign HRESP = OK;
137
 
138
//CRC_CR Data Read
139
assign crc_cr_rd = {24'h0, crc_cr_ff[4:0], 3'h0};
140
 
141
//Mux to HRDATA
142
assign HRDATA = ({32{crc_dr_sel  }} & crc_out             ) |
143
                ({32{crc_init_sel}} & crc_init_out        ) |
144
                ({32{crc_idr_sel }} & {24'h0, crc_idr_out}) |
145
                ({32{crc_poly_sel}} & crc_poly_out        ) |
146
                ({32{crc_cr_sel  }} & crc_cr_rd           ) ;
147
 
148
//Control Register
149
always @(posedge HCLK)
150
        begin
151
                if(!HRESETn)
152
                        crc_cr_ff <= RESET_CRC_CR;
153
                else
154
                        if(crc_cr_en)
155
                                crc_cr_ff <= {HWDATA[7], HWDATA[6:5], HWDATA[4:3]};
156
        end
157
 
158
//Configuration Signals
159
assign reset_chain   = (crc_cr_en && HWDATA[0]);
160
assign crc_poly_size = crc_cr_ff[1:0];
161
assign rev_in_type   = crc_cr_ff[3:2];
162
assign rev_out_type  = crc_cr_ff[4];
163
 
164
endmodule

powered by: WebSVN 2.1.0

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