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

Subversion Repositories pmodsf3driver

[/] [pmodsf3driver/] [trunk/] [hw/] [sources/] [PmodSF3DummyCycles.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ldalmasso
------------------------------------------------------------------------
2
-- Engineer:    Dalmasso Loic
3
-- Create Date: 19/02/2025
4
-- Module Name: PmodSF3DummyCycles
5
-- Description:
6
--      Pmod SF3 Dummy Cycles Handler for the 32 MB NOR Flash Memory MT25QL256ABA:
7
--      - When User Read/Write Dummy Cycles from/to memory (Non-Volatile / Volatile register), the module updates its internal Dummy Cycles registers
8
--      - According to the Flash Memory specifications:
9
--                      - At Power-up, the Dummy Cycles from the Non-Volatile register is used
10
--                      - When RESET_NON_VOLATILE_COMMAND (0x99) command is executed, the Dummy Cycles from the Non-Volatile register is used
11
--                      - When WRITE_VOLATILE_CONFIG_COMMAND (0x81) command is executed, the Dummy Cycles from the Volatile register is used
12
--
13
-- Ports
14
--              Input   -       i_sys_clock: System Input Clock
15
--              Input   -       i_reset: Module Reset ('0': No Reset, '1': Reset)
16
--              Input   -       i_end_of_tx: End of SPI Transmission ('0': In progress, '1': End of Transmission)
17
--              Input   -       i_command: Command Byte
18
--              Input   -       i_new_data_to_mem: New Data to Write on FLASH Ready (Write Mode) ('0': NOT Ready, '1': Ready)
19
--              Input   -       i_data_to_mem: Data Bytes to Write on FLASH
20
--              Input   -       i_data_from_mem_ready: Data Bytes Read from FLASH Ready (Read Mode) ('0': NOT Ready, '1': Ready)
21
--              Input   -       i_data_from_mem: Data Bytes Read from FLASH
22
--              Output  -       o_dummy_cycles: Dummy Cycles Value
23
------------------------------------------------------------------------
24
 
25
LIBRARY IEEE;
26
USE IEEE.STD_LOGIC_1164.ALL;
27
USE IEEE.NUMERIC_STD.ALL;
28
 
29
ENTITY PmodSF3DummyCycles is
30
 
31
PORT(
32
        i_sys_clock: IN STD_LOGIC;
33
        i_reset: IN STD_LOGIC;
34
        i_end_of_tx: IN STD_LOGIC;
35
    i_command: IN UNSIGNED(7 downto 0);
36
        i_new_data_to_mem: IN STD_LOGIC;
37
    i_data_to_mem: IN UNSIGNED(7 downto 0);
38
        i_data_from_mem_ready: IN STD_LOGIC;
39
    i_data_from_mem: IN UNSIGNED(7 downto 0);
40
    o_dummy_cycles: OUT INTEGER range 0 to 14
41
);
42
 
43
END PmodSF3DummyCycles;
44
 
45
ARCHITECTURE Behavioral of PmodSF3DummyCycles is
46
 
47
------------------------------------------------------------------------
48
-- Constant Declarations
49
------------------------------------------------------------------------
50
-- Non Volatile Configuration Register
51
constant WRITE_NON_VOLATILE_COMMAND: UNSIGNED(7 downto 0) := x"B1";
52
constant READ_NON_VOLATILE_COMMAND: UNSIGNED(7 downto 0) := x"B5";
53
constant RESET_NON_VOLATILE_COMMAND: UNSIGNED(7 downto 0) := x"99";
54
 
55
-- Volatile Configuration Register
56
constant WRITE_VOLATILE_CONFIG_COMMAND: UNSIGNED(7 downto 0) := x"81";
57
constant READ_VOLATILE_CONFIG_COMMAND: UNSIGNED(7 downto 0) := x"85";
58
 
59
-- Dummy Cycle Bits
60
constant DUMMY_CYCLES_MSB_BIT: INTEGER := 7;
61
constant DUMMY_CYCLES_LSB_BIT: INTEGER := 4;
62
 
63
------------------------------------------------------------------------
64
-- Signal Declarations
65
------------------------------------------------------------------------
66
-- Non Volatile Dummy Cycles Byte
67
signal non_volatile_first_byte: STD_LOGIC := '0';
68
 
69
-- Non Volatile Dummy Cycles Register
70
signal non_volatile_dummy_cycles_reg: UNSIGNED(3 downto 0) := (others => '0');
71
 
72
-- Volatile Dummy Cycles Byte
73
signal volatile_first_byte: STD_LOGIC := '0';
74
 
75
-- Volatile Dummy Cycles Register
76
signal volatile_dummy_cycles_reg: UNSIGNED(3 downto 0) := (others => '0');
77
 
78
-- Apply New Dummy Cycles Trigger
79
signal end_of_tx_reg0: STD_LOGIC := '0';
80
signal end_of_tx_reg1: STD_LOGIC := '0';
81
signal apply_new_dummy_cycles: STD_LOGIC := '0';
82
 
83
-- Dummy Cycles Registers
84
signal dummy_cycles_reg: UNSIGNED(3 downto 0) := (others => '0');
85
signal dummy_cycles_out_reg: UNSIGNED(3 downto 0) := (others => '0');
86
 
87
------------------------------------------------------------------------
88
-- Module Implementation
89
------------------------------------------------------------------------
90
begin
91
 
92
        --------------------------------------------------------
93
        -- Non-Volatile Read/Write Byte Configuration Handler --
94
        --------------------------------------------------------
95
        process(i_sys_clock)
96
        begin
97
                if rising_edge(i_sys_clock) then
98
 
99
                        -- First Byte to Read/Write
100
                        if (i_end_of_tx = '1') then
101
                                non_volatile_first_byte <= '1';
102
 
103
                        -- Next Byte to Write
104
                        elsif (i_command = WRITE_NON_VOLATILE_COMMAND) and (i_new_data_to_mem = '1') then
105
                                non_volatile_first_byte <= '0';
106
 
107
                        -- Next Byte to Read
108
                        elsif (i_command = READ_NON_VOLATILE_COMMAND) and (i_data_from_mem_ready = '1') then
109
                                non_volatile_first_byte <= '0';
110
                        end if;
111
                end if;
112
        end process;
113
 
114
        ----------------------------------------
115
        -- Non-Volatile Configuration Handler --
116
        ----------------------------------------
117
        process(i_sys_clock)
118
        begin
119
                if rising_edge(i_sys_clock) then
120
 
121
                        -- First Byte to Read/Write
122
                        if (non_volatile_first_byte = '1') then
123
 
124
                                -- Write Non-Volatile Configuration Register
125
                                if (i_command = WRITE_NON_VOLATILE_COMMAND) then
126
                                        non_volatile_dummy_cycles_reg <= i_data_to_mem(DUMMY_CYCLES_MSB_BIT downto DUMMY_CYCLES_LSB_BIT);
127
 
128
                                -- Read Non-Volatile Configuration Register
129
                                elsif (i_command = READ_NON_VOLATILE_COMMAND) then
130
                                        non_volatile_dummy_cycles_reg <= i_data_from_mem(DUMMY_CYCLES_MSB_BIT downto DUMMY_CYCLES_LSB_BIT);
131
                                end if;
132
                        end if;
133
        end if;
134
    end process;
135
 
136
        ----------------------------------------------------
137
        -- Volatile Read/Write Byte Configuration Handler --
138
        ----------------------------------------------------
139
        process(i_sys_clock)
140
        begin
141
                if rising_edge(i_sys_clock) then
142
 
143
                        -- First Byte to Read/Write
144
                        if (i_end_of_tx = '1') then
145
                                volatile_first_byte <= '1';
146
 
147
                        -- Next Byte to Write
148
                        elsif (i_command = WRITE_VOLATILE_CONFIG_COMMAND) and (i_new_data_to_mem = '1') then
149
                                volatile_first_byte <= '0';
150
 
151
                        -- Next Byte to Read
152
                        elsif (i_command = READ_VOLATILE_CONFIG_COMMAND) and (i_data_from_mem_ready = '1') then
153
                                volatile_first_byte <= '0';
154
                        end if;
155
                end if;
156
        end process;
157
 
158
        ------------------------------------
159
        -- Volatile Configuration Handler --
160
        ------------------------------------
161
        process(i_sys_clock)
162
        begin
163
                if rising_edge(i_sys_clock) then
164
 
165
                        -- First Byte to Read/Write
166
                        if (volatile_first_byte = '1') then
167
 
168
                                -- Write Non-Volatile Configuration Register
169
                                if (i_command = WRITE_VOLATILE_CONFIG_COMMAND) then
170
                                        volatile_dummy_cycles_reg <= i_data_to_mem(DUMMY_CYCLES_MSB_BIT downto DUMMY_CYCLES_LSB_BIT);
171
 
172
                                -- Read Non-Volatile Configuration Register
173
                                elsif (i_command = READ_VOLATILE_CONFIG_COMMAND) then
174
                                        volatile_dummy_cycles_reg <= i_data_from_mem(DUMMY_CYCLES_MSB_BIT downto DUMMY_CYCLES_LSB_BIT);
175
                                end if;
176
                        end if;
177
        end if;
178
    end process;
179
 
180
        ----------------------------
181
        -- Apply New Dummy Cycles --
182
        ----------------------------
183
        process(i_sys_clock)
184
        begin
185
                if rising_edge(i_sys_clock) then
186
 
187
                        -- End of SPI Transmission Detection
188
                        end_of_tx_reg0 <= i_end_of_tx;
189
                        end_of_tx_reg1 <= end_of_tx_reg0;
190
                end if;
191
        end process;
192
        apply_new_dummy_cycles <= end_of_tx_reg0 and not(end_of_tx_reg1);
193
 
194
        ---------------------------
195
        -- Dummy Cycles Register --
196
        ---------------------------
197
        process(i_sys_clock)
198
        begin
199
                if rising_edge(i_sys_clock) then
200
 
201
                        -- Reset Memory Command (use Non-Volatile Dummy Cycles)
202
                        if (i_command = RESET_NON_VOLATILE_COMMAND) then
203
                                dummy_cycles_reg <= non_volatile_dummy_cycles_reg;
204
 
205
                        -- Write Volatile Configuration Register (use Volatile Dummy Cycles)
206
                        elsif (i_command = WRITE_VOLATILE_CONFIG_COMMAND) or (i_command = READ_VOLATILE_CONFIG_COMMAND) then
207
                                dummy_cycles_reg <= volatile_dummy_cycles_reg;
208
                        end if;
209
                end if;
210
        end process;
211
 
212
        ----------------------------------
213
        -- Dummy Cycles Register Format --
214
        ----------------------------------
215
        process(i_sys_clock)
216
        begin
217
                if rising_edge(i_sys_clock) then
218
 
219
                        -- Reset
220
                        if (i_reset = '1') then
221
                                dummy_cycles_out_reg <= (others => '0');
222
 
223
                        -- Apply New Dummy Cycles (at the End of SPI Transmission)
224
                        elsif (apply_new_dummy_cycles = '1') then
225
 
226
                                -- Dummy Cycles from 0 to 14
227
                                if (dummy_cycles_reg = x"F") then
228
                                        dummy_cycles_out_reg <= (others => '0');
229
 
230
                                else
231
                                        dummy_cycles_out_reg <= dummy_cycles_reg;
232
                                end if;
233
                        end if;
234
                end if;
235
        end process;
236
 
237
        -------------------------
238
        -- Dummy Cycles Output --
239
        -------------------------
240
        o_dummy_cycles <= TO_INTEGER(dummy_cycles_out_reg);
241
 
242
end Behavioral;

powered by: WebSVN 2.1.0

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