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 7

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 7 lynn0p
-- Uses ODDR2 registers to generate the required DDR signals. Don't have to be as
34
--  careful with the timings as with sdram_reader, but you need to be able to feed
35
--  the ODDR2's within their setup and hold windows. Or very very hilarious things
36
--  will occur. Post-PAR simulation is good for getting a feel for the
37
--  (mis)timings.
38 2 lynn0p
entity sdram_writer is
39
        port(
40
                clk    : in std_logic;
41
                clk090 : in std_logic;
42
                clk180 : in std_logic;
43
                clk270 : in std_logic;
44
                rst    : in std_logic;
45
                addr   : in std_logic;
46
                data_o : in std_logic_vector(7 downto 0);
47
                dqs    : out std_logic_vector(1 downto 0);
48
                dm     : out std_logic_vector(1 downto 0);
49 6 lynn0p
                dq     : out std_logic_vector(15 downto 0)
50 2 lynn0p
        );
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
begin
100
 
101
        ODDR2_dqs: oddr2_2
102
        port map(
103
                Q => dqs,
104
                C0 => clk,
105
                C1 => clk180,
106
                CE => '1',
107
                D0 => dqs_rising,
108
                D1 => dqs_falling,
109
                R => '0',
110
                S => '0'
111
        );
112
 
113
        ODDR2_dm: oddr2_2
114
        port map(
115
                Q => dm,
116
                C0 => clk090,
117
                C1 => clk270,
118
                CE => '1',
119
                D0 => dm_rising,
120
                D1 => dm_falling,
121
                R => '0',
122
                S => '0'
123
        );
124
 
125
        ODDR2_dq: oddr2_16
126
        port map(
127
                Q => dq,
128
                C0 => clk090,
129
                C1 => clk270,
130
                CE => '1',
131
                D0 => dq_rising,
132
                D1 => dq_falling,
133
                R => '0',
134
                S => '0'
135
        );
136
 
137
   dqs_rising(0)  <= dqs_fsm_r;
138
   dqs_rising(1)  <= dqs_fsm_r;
139
        dqs_falling(0) <= dqs_fsm_f;
140
        dqs_falling(1) <= dqs_fsm_f;
141
 
142
        -- this drives the oddr2_dqs
143
        process (clk180,rst)
144
        begin
145
                if (rst = '1') then
146
                        dqs_fsm_r <= '0';
147
                        dqs_fsm_f <= '0';
148
                        writer_dqs_state <= STATE_WRITER_DQS_0;
149
                elsif (rising_edge(clk180)) then
150
                        case writer_dqs_state is
151
                                when STATE_WRITER_DQS_0 =>
152
                                        dqs_fsm_r <= '0';
153
                                        dqs_fsm_f <= '0';
154
                                        writer_dqs_state <= STATE_WRITER_DQS_1;
155
                                when STATE_WRITER_DQS_1 =>
156
                                        dqs_fsm_r <= '1';
157
                                        dqs_fsm_f <= '0';
158
                                        writer_dqs_state <= STATE_WRITER_DQS_DONE;
159
                                when STATE_WRITER_DQS_DONE =>
160
                                        dqs_fsm_r <= '0';
161
                                        dqs_fsm_f <= '0';
162
                                        writer_dqs_state <= STATE_WRITER_DQS_DONE;
163
                        end case;
164
                end if;
165
        end process;
166
 
167
 
168
        data_out <= (x"00" & data_o) when addr = '0' else (data_o & x"00");
169
        mask_out <=             "10" when addr = '0' else "01";
170
 
171
        -- this drives the oddr2_dm and oddr2_dq
172
        process(clk,rst)
173
        begin
174
                if (rst = '1') then
175
                        dm_rising <= "11";
176
                        dq_rising <= x"0000";
177
                        dm_falling <= "11";
178
                        dq_falling <= x"0000";
179
                        writer_dm_state <= STATE_WRITER_DM_0;
180
                elsif (rising_edge(clk)) then
181
                        case writer_dm_state is
182
                                when STATE_WRITER_DM_0 =>
183
                                        dm_rising <= "11";
184
                                        dq_rising <= x"0000";
185
                                        dm_falling <= mask_out;
186
                                        dq_falling <= data_out;
187
                                        writer_dm_state <= STATE_WRITER_DM_1;
188
 
189
                                when STATE_WRITER_DM_1 =>
190
                                        dm_rising <= "11";
191
                                        dq_rising <= x"0000";
192
                                        dm_falling <= "11";
193
                                        dq_falling <= x"0000";
194
                                        writer_dm_state <= STATE_WRITER_DM_DONE;
195
 
196
                                when STATE_WRITER_DM_DONE =>
197
                                        dm_rising <= "00";
198
                                        dm_falling <= "00";
199
                                        writer_dm_state <= STATE_WRITER_DM_DONE;
200
                        end case;
201
                end if;
202
        end process;
203
 
204
end impl;

powered by: WebSVN 2.1.0

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