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

Subversion Repositories sd_card_controller

[/] [sd_card_controller/] [trunk/] [rtl/] [verilog/] [sd_controller_wb.v] - Blame information for rev 3

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

Line No. Rev Author Line
1 3 rozpruwacz
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// WISHBONE SD Card Controller IP Core                          ////
4
////                                                              ////
5
//// sd_controller_wb.v                                           ////
6
////                                                              ////
7
//// This file is part of the WISHBONE SD Card                    ////
8
//// Controller IP Core project                                   ////
9
//// http://www.opencores.org/cores/xxx/                          ////
10
////                                                              ////
11
//// Description                                                  ////
12
//// Wishbone interface responsible for comunication with core    ////
13
////                                                              ////
14
//// Author(s):                                                   ////
15
////     - Marek Czerski, ma.czerski@gmail.com                    ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2013 Authors                                   ////
20
////                                                              ////
21
//// Based on original work by                                    ////
22
////     Adam Edvardsson (adam.edvardsson@orsoc.se)               ////
23
////                                                              ////
24
////     Copyright (C) 2009 Authors                               ////
25
////                                                              ////
26
//// This source file may be used and distributed without         ////
27
//// restriction provided that this copyright statement is not    ////
28
//// removed from the file and that any derivative work contains  ////
29
//// the original copyright notice and the associated disclaimer. ////
30
////                                                              ////
31
//// This source file is free software; you can redistribute it   ////
32
//// and/or modify it under the terms of the GNU Lesser General   ////
33
//// Public License as published by the Free Software Foundation; ////
34
//// either version 2.1 of the License, or (at your option) any   ////
35
//// later version.                                               ////
36
////                                                              ////
37
//// This source is distributed in the hope that it will be       ////
38
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
39
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
40
//// PURPOSE. See the GNU Lesser General Public License for more  ////
41
//// details.                                                     ////
42
////                                                              ////
43
//// You should have received a copy of the GNU Lesser General    ////
44
//// Public License along with this source; if not, download it   ////
45
//// from http://www.opencores.org/lgpl.shtml                     ////
46
////                                                              ////
47
//////////////////////////////////////////////////////////////////////
48
`include "sd_defines.h"
49
 
50
module sd_controller_wb(
51
           // WISHBONE slave
52
           wb_clk_i, wb_rst_i, wb_dat_i, wb_dat_o,
53
           wb_adr_i, wb_sel_i, wb_we_i, wb_cyc_i, wb_stb_i, wb_ack_o,
54
           cmd_start,
55
           data_int_rst,
56
           cmd_int_rst,
57
           argument_reg,
58
           command_reg,
59
           response_0_reg,
60
           response_1_reg,
61
           response_2_reg,
62
           response_3_reg,
63
           software_reset_reg,
64
           timeout_reg,
65
           block_size_reg,
66
           controll_setting_reg,
67
           cmd_int_status_reg,
68
           cmd_int_enable_reg,
69
           clock_divider_reg,
70
           block_count_reg,
71
           dma_addr_reg,
72
           data_int_status_reg,
73
           data_int_enable_reg
74
       );
75
 
76
// WISHBONE common
77
input wb_clk_i;     // WISHBONE clock
78
input wb_rst_i;     // WISHBONE reset
79
input [31:0] wb_dat_i;     // WISHBONE data input
80
output reg [31:0] wb_dat_o;     // WISHBONE data output
81
// WISHBONE error output
82
 
83
// WISHBONE slave
84
input [7:0] wb_adr_i;     // WISHBONE address input
85
input [3:0] wb_sel_i;     // WISHBONE byte select input
86
input wb_we_i;      // WISHBONE write enable input
87
input wb_cyc_i;     // WISHBONE cycle input
88
input wb_stb_i;     // WISHBONE strobe input
89
output reg wb_ack_o;     // WISHBONE acknowledge output
90
output reg cmd_start;
91
//Buss accessible registers
92
output reg [31:0] argument_reg;
93
output reg [`CMD_REG_SIZE-1:0] command_reg;
94
input wire [31:0] response_0_reg;
95
input wire [31:0] response_1_reg;
96
input wire [31:0] response_2_reg;
97
input wire [31:0] response_3_reg;
98
output reg [0:0] software_reset_reg;
99
output reg [15:0] timeout_reg;
100
output reg [`BLKSIZE_W-1:0] block_size_reg;
101
output reg [15:0] controll_setting_reg;
102
input wire [`INT_CMD_SIZE-1:0] cmd_int_status_reg;
103
output reg [`INT_CMD_SIZE-1:0] cmd_int_enable_reg;
104
output reg [7:0] clock_divider_reg;
105
input  wire [`INT_DATA_SIZE-1:0] data_int_status_reg;
106
output reg [`INT_DATA_SIZE-1:0] data_int_enable_reg;
107
//Register Controll
108
output reg data_int_rst;
109
output reg cmd_int_rst;
110
output reg [`BLKCNT_W-1:0]block_count_reg;
111
output reg [31:0] dma_addr_reg;
112
 
113
`ifdef SUPPLY_VOLTAGE_3_3
114
parameter voltage_controll_reg  = 8'b0000_111_1;
115
`elsif SUPPLY_VOLTAGE_3_0
116
parameter voltage_controll_reg  = 8'b0000_110_1;
117
`elsif SUPPLY_VOLTAGE_1_8
118
parameter voltage_controll_reg  = 8'b0000_101_1;
119
`endif
120
parameter capabilies_reg = 16'b0000_0000_0000_0000;
121
 
122
always @(posedge wb_clk_i or posedge wb_rst_i)
123
begin
124
    if (wb_rst_i)begin
125
        argument_reg <= 0;
126
        command_reg <= 0;
127
        software_reset_reg <= 0;
128
        timeout_reg <= 0;
129
        block_size_reg <= `RESET_BLOCK_SIZE;
130
        controll_setting_reg <= 0;
131
        cmd_int_enable_reg <= 0;
132
        clock_divider_reg <= `RESET_CLK_DIV;
133
        wb_ack_o <= 0;
134
        cmd_start <= 0;
135
        data_int_rst <= 0;
136
        data_int_enable_reg <= 0;
137
        cmd_int_rst <= 0;
138
        block_count_reg <= 0;
139
        dma_addr_reg <= 0;
140
    end
141
    else
142
    begin
143
        cmd_start <= 1'b0;
144
        data_int_rst <= 0;
145
        cmd_int_rst <= 0;
146
        if ((wb_stb_i & wb_cyc_i) || wb_ack_o)begin
147
            if (wb_we_i) begin
148
                case (wb_adr_i)
149
                    `argument: begin
150
                        argument_reg <= wb_dat_i;
151
                        cmd_start <= 1'b1;
152
                    end
153
                    `command: command_reg <= wb_dat_i[`CMD_REG_SIZE-1:0];
154
                    `reset: software_reset_reg <= wb_dat_i[0];
155
                    `timeout: timeout_reg  <=  wb_dat_i[15:0];
156
                    `blksize: block_size_reg <= wb_dat_i[`BLKSIZE_W-1:0];
157
                    `controller: controll_setting_reg <= wb_dat_i[15:0];
158
                    `cmd_iser: cmd_int_enable_reg <= wb_dat_i[4:0];
159
                    `cmd_isr: cmd_int_rst <= 1;
160
                    `clock_d: clock_divider_reg <= wb_dat_i[7:0];
161
                    `data_isr: data_int_rst <= 1;
162
                    `data_iser: data_int_enable_reg <= wb_dat_i[`INT_DATA_SIZE-1:0];
163
                    `dst_src_addr: dma_addr_reg <= wb_dat_i;
164
                    `blkcnt: block_count_reg <= wb_dat_i[`BLKCNT_W-1:0];
165
                endcase
166
            end
167
            wb_ack_o <= wb_cyc_i & wb_stb_i & ~wb_ack_o;
168
        end
169
    end
170
end
171
 
172
always @(posedge wb_clk_i or posedge wb_rst_i)begin
173
    if (wb_rst_i == 1)
174
        wb_dat_o <= 0;
175
    else
176
        if (wb_stb_i & wb_cyc_i) begin //CS
177
            case (wb_adr_i)
178
                `argument: wb_dat_o <= argument_reg;
179
                `command: wb_dat_o <= command_reg;
180
                `resp0: wb_dat_o <= response_0_reg;
181
                `resp1: wb_dat_o <= response_1_reg;
182
                `resp2: wb_dat_o <= response_2_reg;
183
                `resp3: wb_dat_o <= response_3_reg;
184
                `controller: wb_dat_o <= controll_setting_reg;
185
                `blksize: wb_dat_o <= block_size_reg;
186
                `voltage: wb_dat_o <= voltage_controll_reg;
187
                `reset: wb_dat_o <= software_reset_reg;
188
                `timeout: wb_dat_o <= timeout_reg;
189
                `cmd_isr: wb_dat_o <= cmd_int_status_reg;
190
                `cmd_iser: wb_dat_o <= cmd_int_enable_reg;
191
                `clock_d: wb_dat_o <= clock_divider_reg;
192
                `capa: wb_dat_o <= capabilies_reg;
193
                `data_isr: wb_dat_o <= data_int_status_reg;
194
                `blkcnt: wb_dat_o <= block_count_reg;
195
                `data_iser: wb_dat_o <= data_int_enable_reg;
196
                `dst_src_addr: wb_dat_o <= dma_addr_reg;
197
            endcase
198
        end
199
end
200
 
201
endmodule

powered by: WebSVN 2.1.0

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