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 8

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 8 rozpruwacz
//// http://opencores.org/project,sd_card_controller              ////
10 3 rozpruwacz
////                                                              ////
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 6 rozpruwacz
parameter voltage_controll_reg  = `SUPPLY_VOLTAGE_mV;
114 3 rozpruwacz
parameter capabilies_reg = 16'b0000_0000_0000_0000;
115
 
116
always @(posedge wb_clk_i or posedge wb_rst_i)
117
begin
118
    if (wb_rst_i)begin
119
        argument_reg <= 0;
120
        command_reg <= 0;
121
        software_reset_reg <= 0;
122
        timeout_reg <= 0;
123
        block_size_reg <= `RESET_BLOCK_SIZE;
124
        controll_setting_reg <= 0;
125
        cmd_int_enable_reg <= 0;
126
        clock_divider_reg <= `RESET_CLK_DIV;
127
        wb_ack_o <= 0;
128
        cmd_start <= 0;
129
        data_int_rst <= 0;
130
        data_int_enable_reg <= 0;
131
        cmd_int_rst <= 0;
132
        block_count_reg <= 0;
133
        dma_addr_reg <= 0;
134
    end
135
    else
136
    begin
137
        cmd_start <= 1'b0;
138
        data_int_rst <= 0;
139
        cmd_int_rst <= 0;
140
        if ((wb_stb_i & wb_cyc_i) || wb_ack_o)begin
141
            if (wb_we_i) begin
142
                case (wb_adr_i)
143
                    `argument: begin
144
                        argument_reg <= wb_dat_i;
145
                        cmd_start <= 1'b1;
146
                    end
147
                    `command: command_reg <= wb_dat_i[`CMD_REG_SIZE-1:0];
148
                    `reset: software_reset_reg <= wb_dat_i[0];
149
                    `timeout: timeout_reg  <=  wb_dat_i[15:0];
150
                    `blksize: block_size_reg <= wb_dat_i[`BLKSIZE_W-1:0];
151
                    `controller: controll_setting_reg <= wb_dat_i[15:0];
152
                    `cmd_iser: cmd_int_enable_reg <= wb_dat_i[4:0];
153
                    `cmd_isr: cmd_int_rst <= 1;
154
                    `clock_d: clock_divider_reg <= wb_dat_i[7:0];
155
                    `data_isr: data_int_rst <= 1;
156
                    `data_iser: data_int_enable_reg <= wb_dat_i[`INT_DATA_SIZE-1:0];
157
                    `dst_src_addr: dma_addr_reg <= wb_dat_i;
158
                    `blkcnt: block_count_reg <= wb_dat_i[`BLKCNT_W-1:0];
159
                endcase
160
            end
161
            wb_ack_o <= wb_cyc_i & wb_stb_i & ~wb_ack_o;
162
        end
163
    end
164
end
165
 
166
always @(posedge wb_clk_i or posedge wb_rst_i)begin
167
    if (wb_rst_i == 1)
168
        wb_dat_o <= 0;
169
    else
170
        if (wb_stb_i & wb_cyc_i) begin //CS
171
            case (wb_adr_i)
172
                `argument: wb_dat_o <= argument_reg;
173
                `command: wb_dat_o <= command_reg;
174
                `resp0: wb_dat_o <= response_0_reg;
175
                `resp1: wb_dat_o <= response_1_reg;
176
                `resp2: wb_dat_o <= response_2_reg;
177
                `resp3: wb_dat_o <= response_3_reg;
178
                `controller: wb_dat_o <= controll_setting_reg;
179
                `blksize: wb_dat_o <= block_size_reg;
180
                `voltage: wb_dat_o <= voltage_controll_reg;
181
                `reset: wb_dat_o <= software_reset_reg;
182
                `timeout: wb_dat_o <= timeout_reg;
183
                `cmd_isr: wb_dat_o <= cmd_int_status_reg;
184
                `cmd_iser: wb_dat_o <= cmd_int_enable_reg;
185
                `clock_d: wb_dat_o <= clock_divider_reg;
186
                `capa: wb_dat_o <= capabilies_reg;
187
                `data_isr: wb_dat_o <= data_int_status_reg;
188
                `blkcnt: wb_dat_o <= block_count_reg;
189
                `data_iser: wb_dat_o <= data_int_enable_reg;
190
                `dst_src_addr: wb_dat_o <= dma_addr_reg;
191
            endcase
192
        end
193
end
194
 
195
endmodule

powered by: WebSVN 2.1.0

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