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

Subversion Repositories sdram_controller

[/] [sdram_controller/] [trunk/] [sdram_writer.vhd] - Blame information for rev 5

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

Line No. Rev Author Line
1 2 lynn0p
----------------------------------------------------------------------------------
2
-- Company: OPL Aerospatiale AG
3
-- Engineer: Owen Lynn <lynn0p@hotmail.com>
4
-- 
5
-- Create Date:    13:08:21 08/30/2009 
6
-- Design Name: 
7
-- Module Name:    sdram_writer - impl 
8
-- Project Name: 
9
-- Target Devices: 
10
-- Tool versions: 
11
-- Description: This module is responsible for generating the dqs, dq and dm waveforms
12
--  needed to tell the chip what to store.
13
--
14
-- Dependencies: 
15
--
16
-- Revision: 
17
-- Revision 0.01 - File Created
18
-- Additional Comments: 
19
--  Copyright (c) 2009 Owen Lynn <lynn0p@hotmail.com>
20
--  Released under the GNU Lesser General Public License, Version 3
21
--
22
----------------------------------------------------------------------------------
23
library IEEE;
24
use IEEE.STD_LOGIC_1164.ALL;
25
use IEEE.STD_LOGIC_ARITH.ALL;
26
use IEEE.STD_LOGIC_UNSIGNED.ALL;
27
 
28
---- Uncomment the following library declaration if instantiating
29
---- any Xilinx primitives in this code.
30
--library UNISIM;
31
--use UNISIM.VComponents.all;
32
 
33
-- Uses ODDR2 registers to generate the required DDR signals. Don't have to be as careful with the
34
--  timings as with sdram_reader, but you need to be able to feed the ODDR2's within their setup
35
--  and hold windows. Or very very hilarious things will occur. Post-PAR simulation is good for
36
--  getting a feel for the (mis)timings.
37
entity sdram_writer is
38
        port(
39
                clk    : in std_logic;
40
                clk090 : in std_logic;
41
                clk180 : in std_logic;
42
                clk270 : in std_logic;
43
                rst    : in std_logic;
44
                addr   : in std_logic;
45
                data_o : in std_logic_vector(7 downto 0);
46
                dqs    : out std_logic_vector(1 downto 0);
47
                dm     : out std_logic_vector(1 downto 0);
48
                dq     : out std_logic_vector(15 downto 0);
49
                done   : out std_logic
50
        );
51
end sdram_writer;
52
 
53
architecture impl of sdram_writer is
54
 
55
        component oddr2_2 is
56
                port(
57
                        Q  : out std_logic_vector(1 downto 0);
58
                        C0 : in std_logic;
59
                        C1 : in std_logic;
60
                        CE : in std_logic;
61
                        D0 : in std_logic_vector(1 downto 0);
62
                        D1 : in std_logic_vector(1 downto 0);
63
                        R  : in std_logic;
64
                        S  : in std_logic );
65
        end component;
66
 
67
        component oddr2_16 is
68
                port(
69
                        Q  : out std_logic_vector(15 downto 0);
70
                        C0 : in std_logic;
71
                        C1 : in std_logic;
72
                        CE : in std_logic;
73
                        D0 : in std_logic_vector(15 downto 0);
74
                        D1 : in std_logic_vector(15 downto 0);
75
                        R  : in std_logic;
76
                        S  : in std_logic );
77
        end component;
78
 
79
        type WRITER_DQS_STATES is ( STATE_WRITER_DQS_0, STATE_WRITER_DQS_1, STATE_WRITER_DQS_DONE );
80
        type WRITER_DM_STATES is ( STATE_WRITER_DM_0, STATE_WRITER_DM_1, STATE_WRITER_DM_DONE );
81
 
82
        signal writer_dqs_state : WRITER_DQS_STATES := STATE_WRITER_DQS_0;
83
        signal writer_dm_state : WRITER_DM_STATES := STATE_WRITER_DM_0;
84
 
85
        signal dqs_rising : std_logic_vector(1 downto 0) := "00";
86
        signal dqs_falling : std_logic_vector(1 downto 0) := "00";
87
        signal dqs_fsm_r : std_logic;
88
        signal dqs_fsm_f : std_logic;
89
 
90
        signal dm_rising : std_logic_vector(1 downto 0) := "11";
91
        signal dm_falling : std_logic_vector(1 downto 0) := "11";
92
 
93
        signal dq_rising : std_logic_vector(15 downto 0) := x"0000";
94
        signal dq_falling : std_logic_vector(15 downto 0) := x"0000";
95
 
96
        signal data_out : std_logic_vector(15 downto 0);
97
        signal mask_out : std_logic_vector(1 downto 0);
98
 
99
        signal writer_dqs_done : std_logic := '0';
100
        signal writer_dm_done : std_logic := '0';
101
 
102
begin
103
 
104
        ODDR2_dqs: oddr2_2
105
        port map(
106
                Q => dqs,
107
                C0 => clk,
108
                C1 => clk180,
109
                CE => '1',
110
                D0 => dqs_rising,
111
                D1 => dqs_falling,
112
                R => '0',
113
                S => '0'
114
        );
115
 
116
        ODDR2_dm: oddr2_2
117
        port map(
118
                Q => dm,
119
                C0 => clk090,
120
                C1 => clk270,
121
                CE => '1',
122
                D0 => dm_rising,
123
                D1 => dm_falling,
124
                R => '0',
125
                S => '0'
126
        );
127
 
128
        ODDR2_dq: oddr2_16
129
        port map(
130
                Q => dq,
131
                C0 => clk090,
132
                C1 => clk270,
133
                CE => '1',
134
                D0 => dq_rising,
135
                D1 => dq_falling,
136
                R => '0',
137
                S => '0'
138
        );
139
 
140
   dqs_rising(0)  <= dqs_fsm_r;
141
   dqs_rising(1)  <= dqs_fsm_r;
142
        dqs_falling(0) <= dqs_fsm_f;
143
        dqs_falling(1) <= dqs_fsm_f;
144
 
145
        -- this drives the oddr2_dqs
146
        process (clk180,rst)
147
        begin
148
                if (rst = '1') then
149
                        dqs_fsm_r <= '0';
150
                        dqs_fsm_f <= '0';
151
                        writer_dqs_done <= '0';
152
                        writer_dqs_state <= STATE_WRITER_DQS_0;
153
                elsif (rising_edge(clk180)) then
154
                        case writer_dqs_state is
155
                                when STATE_WRITER_DQS_0 =>
156
                                        dqs_fsm_r <= '0';
157
                                        dqs_fsm_f <= '0';
158
                                        writer_dqs_state <= STATE_WRITER_DQS_1;
159
                                when STATE_WRITER_DQS_1 =>
160
                                        dqs_fsm_r <= '1';
161
                                        dqs_fsm_f <= '0';
162
                                        writer_dqs_state <= STATE_WRITER_DQS_DONE;
163
                                when STATE_WRITER_DQS_DONE =>
164
                                        dqs_fsm_r <= '0';
165
                                        dqs_fsm_f <= '0';
166
                                        writer_dqs_done <= '1';
167
                                        writer_dqs_state <= STATE_WRITER_DQS_DONE;
168
                        end case;
169
                end if;
170
        end process;
171
 
172
 
173
        data_out <= (x"00" & data_o) when addr = '0' else (data_o & x"00");
174
        mask_out <=             "10" when addr = '0' else "01";
175
 
176
        -- this drives the oddr2_dm and oddr2_dq
177
        process(clk,rst)
178
        begin
179
                if (rst = '1') then
180
                        dm_rising <= "11";
181
                        dq_rising <= x"0000";
182
                        dm_falling <= "11";
183
                        dq_falling <= x"0000";
184
                        writer_dm_done <= '0';
185
                        writer_dm_state <= STATE_WRITER_DM_0;
186
                elsif (rising_edge(clk)) then
187
                        case writer_dm_state is
188
                                when STATE_WRITER_DM_0 =>
189
                                        dm_rising <= "11";
190
                                        dq_rising <= x"0000";
191
                                        dm_falling <= mask_out;
192
                                        dq_falling <= data_out;
193
                                        writer_dm_state <= STATE_WRITER_DM_1;
194
 
195
                                when STATE_WRITER_DM_1 =>
196
                                        dm_rising <= "11";
197
                                        dq_rising <= x"0000";
198
                                        dm_falling <= "11";
199
                                        dq_falling <= x"0000";
200
                                        writer_dm_state <= STATE_WRITER_DM_DONE;
201
 
202
                                when STATE_WRITER_DM_DONE =>
203
                                        dm_rising <= "00";
204
                                        dm_falling <= "00";
205
                                        writer_dm_done <= '1';
206
                                        writer_dm_state <= STATE_WRITER_DM_DONE;
207
                        end case;
208
                end if;
209
        end process;
210
 
211
        done <= writer_dqs_done and writer_dm_done;
212
 
213
end impl;

powered by: WebSVN 2.1.0

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