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 6

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 6 lynn0p
                dq     : out std_logic_vector(15 downto 0)
49 2 lynn0p
        );
50
end sdram_writer;
51
 
52
architecture impl of sdram_writer is
53
 
54
        component oddr2_2 is
55
                port(
56
                        Q  : out std_logic_vector(1 downto 0);
57
                        C0 : in std_logic;
58
                        C1 : in std_logic;
59
                        CE : in std_logic;
60
                        D0 : in std_logic_vector(1 downto 0);
61
                        D1 : in std_logic_vector(1 downto 0);
62
                        R  : in std_logic;
63
                        S  : in std_logic );
64
        end component;
65
 
66
        component oddr2_16 is
67
                port(
68
                        Q  : out std_logic_vector(15 downto 0);
69
                        C0 : in std_logic;
70
                        C1 : in std_logic;
71
                        CE : in std_logic;
72
                        D0 : in std_logic_vector(15 downto 0);
73
                        D1 : in std_logic_vector(15 downto 0);
74
                        R  : in std_logic;
75
                        S  : in std_logic );
76
        end component;
77
 
78
        type WRITER_DQS_STATES is ( STATE_WRITER_DQS_0, STATE_WRITER_DQS_1, STATE_WRITER_DQS_DONE );
79
        type WRITER_DM_STATES is ( STATE_WRITER_DM_0, STATE_WRITER_DM_1, STATE_WRITER_DM_DONE );
80
 
81
        signal writer_dqs_state : WRITER_DQS_STATES := STATE_WRITER_DQS_0;
82
        signal writer_dm_state : WRITER_DM_STATES := STATE_WRITER_DM_0;
83
 
84
        signal dqs_rising : std_logic_vector(1 downto 0) := "00";
85
        signal dqs_falling : std_logic_vector(1 downto 0) := "00";
86
        signal dqs_fsm_r : std_logic;
87
        signal dqs_fsm_f : std_logic;
88
 
89
        signal dm_rising : std_logic_vector(1 downto 0) := "11";
90
        signal dm_falling : std_logic_vector(1 downto 0) := "11";
91
 
92
        signal dq_rising : std_logic_vector(15 downto 0) := x"0000";
93
        signal dq_falling : std_logic_vector(15 downto 0) := x"0000";
94
 
95
        signal data_out : std_logic_vector(15 downto 0);
96
        signal mask_out : std_logic_vector(1 downto 0);
97
 
98
begin
99
 
100
        ODDR2_dqs: oddr2_2
101
        port map(
102
                Q => dqs,
103
                C0 => clk,
104
                C1 => clk180,
105
                CE => '1',
106
                D0 => dqs_rising,
107
                D1 => dqs_falling,
108
                R => '0',
109
                S => '0'
110
        );
111
 
112
        ODDR2_dm: oddr2_2
113
        port map(
114
                Q => dm,
115
                C0 => clk090,
116
                C1 => clk270,
117
                CE => '1',
118
                D0 => dm_rising,
119
                D1 => dm_falling,
120
                R => '0',
121
                S => '0'
122
        );
123
 
124
        ODDR2_dq: oddr2_16
125
        port map(
126
                Q => dq,
127
                C0 => clk090,
128
                C1 => clk270,
129
                CE => '1',
130
                D0 => dq_rising,
131
                D1 => dq_falling,
132
                R => '0',
133
                S => '0'
134
        );
135
 
136
   dqs_rising(0)  <= dqs_fsm_r;
137
   dqs_rising(1)  <= dqs_fsm_r;
138
        dqs_falling(0) <= dqs_fsm_f;
139
        dqs_falling(1) <= dqs_fsm_f;
140
 
141
        -- this drives the oddr2_dqs
142
        process (clk180,rst)
143
        begin
144
                if (rst = '1') then
145
                        dqs_fsm_r <= '0';
146
                        dqs_fsm_f <= '0';
147
                        writer_dqs_state <= STATE_WRITER_DQS_0;
148
                elsif (rising_edge(clk180)) then
149
                        case writer_dqs_state is
150
                                when STATE_WRITER_DQS_0 =>
151
                                        dqs_fsm_r <= '0';
152
                                        dqs_fsm_f <= '0';
153
                                        writer_dqs_state <= STATE_WRITER_DQS_1;
154
                                when STATE_WRITER_DQS_1 =>
155
                                        dqs_fsm_r <= '1';
156
                                        dqs_fsm_f <= '0';
157
                                        writer_dqs_state <= STATE_WRITER_DQS_DONE;
158
                                when STATE_WRITER_DQS_DONE =>
159
                                        dqs_fsm_r <= '0';
160
                                        dqs_fsm_f <= '0';
161
                                        writer_dqs_state <= STATE_WRITER_DQS_DONE;
162
                        end case;
163
                end if;
164
        end process;
165
 
166
 
167
        data_out <= (x"00" & data_o) when addr = '0' else (data_o & x"00");
168
        mask_out <=             "10" when addr = '0' else "01";
169
 
170
        -- this drives the oddr2_dm and oddr2_dq
171
        process(clk,rst)
172
        begin
173
                if (rst = '1') then
174
                        dm_rising <= "11";
175
                        dq_rising <= x"0000";
176
                        dm_falling <= "11";
177
                        dq_falling <= x"0000";
178
                        writer_dm_state <= STATE_WRITER_DM_0;
179
                elsif (rising_edge(clk)) then
180
                        case writer_dm_state is
181
                                when STATE_WRITER_DM_0 =>
182
                                        dm_rising <= "11";
183
                                        dq_rising <= x"0000";
184
                                        dm_falling <= mask_out;
185
                                        dq_falling <= data_out;
186
                                        writer_dm_state <= STATE_WRITER_DM_1;
187
 
188
                                when STATE_WRITER_DM_1 =>
189
                                        dm_rising <= "11";
190
                                        dq_rising <= x"0000";
191
                                        dm_falling <= "11";
192
                                        dq_falling <= x"0000";
193
                                        writer_dm_state <= STATE_WRITER_DM_DONE;
194
 
195
                                when STATE_WRITER_DM_DONE =>
196
                                        dm_rising <= "00";
197
                                        dm_falling <= "00";
198
                                        writer_dm_state <= STATE_WRITER_DM_DONE;
199
                        end case;
200
                end if;
201
        end process;
202
 
203
end impl;

powered by: WebSVN 2.1.0

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