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_fifo_filler.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_fifo_filler.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
//// Fifo interface between sd card and wishbone clock domains    ////
13
//// and DMA engine eble to write/read to/from CPU memory         ////
14
////                                                              ////
15
//// Author(s):                                                   ////
16
////     - Marek Czerski, ma.czerski@gmail.com                    ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20
//// Copyright (C) 2013 Authors                                   ////
21
////                                                              ////
22
//// Based on original work by                                    ////
23
////     Adam Edvardsson (adam.edvardsson@orsoc.se)               ////
24
////                                                              ////
25
////     Copyright (C) 2009 Authors                               ////
26
////                                                              ////
27
//// This source file may be used and distributed without         ////
28
//// restriction provided that this copyright statement is not    ////
29
//// removed from the file and that any derivative work contains  ////
30
//// the original copyright notice and the associated disclaimer. ////
31
////                                                              ////
32
//// This source file is free software; you can redistribute it   ////
33
//// and/or modify it under the terms of the GNU Lesser General   ////
34
//// Public License as published by the Free Software Foundation; ////
35
//// either version 2.1 of the License, or (at your option) any   ////
36
//// later version.                                               ////
37
////                                                              ////
38
//// This source is distributed in the hope that it will be       ////
39
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
40
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
41
//// PURPOSE. See the GNU Lesser General Public License for more  ////
42
//// details.                                                     ////
43
////                                                              ////
44
//// You should have received a copy of the GNU Lesser General    ////
45
//// Public License along with this source; if not, download it   ////
46
//// from http://www.opencores.org/lgpl.shtml                     ////
47
////                                                              ////
48
//////////////////////////////////////////////////////////////////////
49
 
50
module sd_fifo_filler(
51
           input wb_clk,
52
           input rst,
53
           //WB Signals
54
           output [31:0] wbm_adr_o,
55
           output wbm_we_o,
56
           output [31:0] wbm_dat_o,
57
           input [31:0] wbm_dat_i,
58
           output wbm_cyc_o,
59
           output wbm_stb_o,
60
           input wbm_ack_i,
61
           //Data Master Control signals
62
           input en_rx_i,
63
           input en_tx_i,
64
           input [31:0] adr_i,
65
           //Data Serial signals
66
           input sd_clk,
67
           input [31:0] dat_i,
68
           output [31:0] dat_o,
69
           input wr_i,
70
           input rd_i,
71
           output sd_full_o,
72
           output sd_empty_o,
73
           output wb_full_o,
74
           output wb_empty_o
75
       );
76
 
77
`define FIFO_MEM_ADR_SIZE 4
78
`define MEM_OFFSET 4
79
 
80
wire reset_fifo;
81
wire fifo_rd;
82
reg [31:0] offset;
83
reg fifo_rd_ack;
84
reg fifo_rd_reg;
85
 
86
assign fifo_rd = wbm_cyc_o & wbm_ack_i;
87
assign reset_fifo = !en_rx_i & !en_tx_i;
88
 
89
assign wbm_we_o = en_rx_i & !wb_empty_o;
90
assign wbm_cyc_o = en_rx_i ? en_rx_i & !wb_empty_o : en_tx_i & !wb_full_o;
91
assign wbm_stb_o = en_rx_i ? wbm_cyc_o & fifo_rd_ack : wbm_cyc_o;
92
 
93
generic_fifo_dc_gray #(
94
    .dw(32),
95
    .aw(`FIFO_MEM_ADR_SIZE)
96
    ) generic_fifo_dc_gray0 (
97
    .rd_clk(wb_clk),
98
    .wr_clk(sd_clk),
99
    .rst(!(rst | reset_fifo)),
100
    .clr(1'b0),
101
    .din(dat_i),
102
    .we(wr_i),
103
    .dout(wbm_dat_o),
104
    .re(en_rx_i & wbm_cyc_o & wbm_ack_i),
105
    .full(sd_full_o),
106
    .empty(wb_empty_o),
107
    .wr_level(),
108
    .rd_level()
109
    );
110
 
111
generic_fifo_dc_gray #(
112
    .dw(32),
113
    .aw(`FIFO_MEM_ADR_SIZE)
114
    ) generic_fifo_dc_gray1 (
115
    .rd_clk(sd_clk),
116
    .wr_clk(wb_clk),
117
    .rst(!(rst | reset_fifo)),
118
    .clr(1'b0),
119
    .din(wbm_dat_i),
120
    .we(en_tx_i & wbm_cyc_o & wbm_stb_o & wbm_ack_i),
121
    .dout(dat_o),
122
    .re(rd_i),
123
    .full(wb_full_o),
124
    .empty(sd_empty_o),
125
    .wr_level(),
126
    .rd_level()
127
    );
128
 
129
assign wbm_adr_o = adr_i+offset;
130
 
131
always @(posedge wb_clk or posedge rst)
132
    if (rst) begin
133
        offset <= 0;
134
        fifo_rd_reg <= 0;
135
        fifo_rd_ack <= 1;
136
    end
137
    else begin
138
        fifo_rd_reg <= fifo_rd;
139
        fifo_rd_ack <= fifo_rd_reg | !fifo_rd;
140
        if (wbm_cyc_o & wbm_stb_o & wbm_ack_i)
141
            offset <= offset + `MEM_OFFSET;
142
        else if (reset_fifo)
143
            offset <= 0;
144
    end
145
 
146
endmodule
147
 
148
 

powered by: WebSVN 2.1.0

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