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

Subversion Repositories pmodsf3driver

[/] [pmodsf3driver/] [trunk/] [hw/] [sources/] [Top_PmodSF3Driver.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: 11/03/2025
4
-- Module Name: Top_PmodSF3Driver
5
-- Description:
6
--      Top Module including Pmod SF3 Driver for the 32 MB NOR Flash memory MT25QL256ABA.
7
--
8
-- Ports
9
--              Input   -       i_sys_clock: System Input Clock
10
--              Input   -       i_reset: Module Reset ('0': No Reset, '1': Reset)
11
--              Input   -       i_start: Start Pmod SF3 Transmission ('0': No Start, '1': Start)
12
--              Output  -       o_led: Pmod SF3 Data from Memory
13
--              Output  -       o_reset: Pmod SF3 Reset ('0': Reset, '1': No Reset)
14
--              Output  -       o_sclk: Pmod SF3SPI Serial Clock
15
--              In/Out  -       io_dq: Pmod SF3SPI Data Lines (Simple, Dual or Quad Modes)
16
--              Output  -       o_ss: Pmod SF3 SPI Slave Select Line ('0': Enable, '1': Disable)
17
------------------------------------------------------------------------
18
 
19
LIBRARY IEEE;
20
USE IEEE.STD_LOGIC_1164.ALL;
21
USE IEEE.NUMERIC_STD.ALL;
22
 
23
ENTITY Top_PmodSF3Driver is
24
 
25
PORT(
26
        i_sys_clock: IN STD_LOGIC;
27
    i_reset: IN STD_LOGIC;
28
    i_start: IN STD_LOGIC;
29
    o_led: OUT UNSIGNED(15 downto 0);
30
    -- PMode Ports
31
    o_reset: OUT STD_LOGIC;
32
        o_sclk: OUT STD_LOGIC;
33
        io_dq: INOUT STD_LOGIC_VECTOR(3 downto 0);
34
        o_ss: OUT STD_LOGIC
35
);
36
 
37
END Top_PmodSF3Driver;
38
 
39
ARCHITECTURE Behavioral of Top_PmodSF3Driver is
40
 
41
------------------------------------------------------------------------
42
-- Component Declarations
43
------------------------------------------------------------------------
44
 
45
COMPONENT clk_wiz_0
46
PORT(
47
    clk_out1: OUT STD_LOGIC;
48
    clk_in1: IN STD_LOGIC
49
);
50
 
51
END COMPONENT;
52
 
53
COMPONENT PmodSF3Driver is
54
 
55
GENERIC(
56
        sys_clock: INTEGER := 100_000_000;
57
        max_data_byte: INTEGER := 1
58
);
59
 
60
PORT(
61
        i_sys_clock: IN STD_LOGIC;
62
        i_reset: IN STD_LOGIC;
63
    i_start: IN STD_LOGIC;
64
    i_rw: IN STD_LOGIC;
65
    i_command: IN UNSIGNED(7 downto 0);
66
        i_addr_bytes: IN INTEGER range 0 to 4;
67
    i_addr: IN UNSIGNED(23 downto 0);
68
    i_data_bytes: IN INTEGER range 0 to max_data_byte;
69
        i_data: IN UNSIGNED((max_data_byte*8)-1 downto 0);
70
        o_data: OUT UNSIGNED((max_data_byte*8)-1 downto 0);
71
        o_data_ready: OUT STD_LOGIC;
72
    o_ready: OUT STD_LOGIC;
73
        o_reset: OUT STD_LOGIC;
74
        o_sclk: OUT STD_LOGIC;
75
        io_dq: INOUT STD_LOGIC_VECTOR(3 downto 0);
76
        o_ss: OUT STD_LOGIC;
77
        o_spi_using_sys_freq: OUT STD_LOGIC
78
);
79
 
80
END COMPONENT;
81
 
82
------------------------------------------------------------------------
83
-- Constant Declarations
84
------------------------------------------------------------------------
85
-- Pmod SF3 Driver Read/Write Mode
86
constant PMOD_DRIVER_READ_MODE: STD_LOGIC := '1';
87
 
88
-- Pmod SF3 Driver Max Data Bytes
89
constant PMOD_DRIVER_MAX_DATA_BYTES: INTEGER := 1;
90
 
91
-- Pmod SF3 Read Volatile Dummy Cycles
92
constant READ_VOLATILE_DC_COMMAND: UNSIGNED(7 downto 0) := x"85";
93
 
94
------------------------------------------------------------------------
95
-- Signal Declarations
96
------------------------------------------------------------------------
97
-- Top Pmod SF3 Driver States
98
TYPE topPmodPSF3State is (  IDLE,
99
                            CONFIG_READ_VOLATILE_DC, START_READ_VOLATILE_DC, READ_VOLATILE_DC,
100
                            COMPLETED);
101
signal state: topPmodPSF3State := IDLE;
102
signal next_state: topPmodPSF3State;
103
 
104
-- Pmod SF3 System Clock
105
signal pmod_sys_clock: STD_LOGIC := '0';
106
 
107
-- Pmod SF3 Driver Reset
108
signal pmod_driver_reset: STD_LOGIC := '0';
109
 
110
-- Pmod SF3 Driver Start
111
signal pmod_driver_start: STD_LOGIC := '0';
112
 
113
-- Pmod SF3 Driver Read/Write Mode
114
signal pmod_driver_rw: STD_LOGIC := '0';
115
 
116
-- Pmod SF3 Driver Command Byte
117
signal pmod_driver_command: UNSIGNED(7 downto 0) := (others => '0');
118
 
119
-- Pmod SF3 Driver Address
120
signal pmod_driver_addr_bytes: INTEGER range 0 to 4 := 0;
121
signal pmod_driver_addr: UNSIGNED(23 downto 0) := (others => '0');
122
 
123
-- Pmod SF3 Driver Data
124
signal pmod_driver_data_bytes: INTEGER range 0 to PMOD_DRIVER_MAX_DATA_BYTES := 0;
125
signal pmod_driver_data_in: UNSIGNED((PMOD_DRIVER_MAX_DATA_BYTES*8)-1 downto 0) := (others => '0');
126
signal pmod_driver_data_out: UNSIGNED((PMOD_DRIVER_MAX_DATA_BYTES*8)-1 downto 0) := (others => '0');
127
signal pmod_driver_data_out_ready: STD_LOGIC := '0';
128
 
129
-- Pmod SF3 Driver Ready
130
signal pmod_driver_ready: STD_LOGIC := '0';
131
 
132
-- Pmod SF3 Driver SPI using Sys Clock
133
signal pmod_driver_spi_using_sys_clock: STD_LOGIC := '0';
134
 
135
-- Data from Memory Register
136
signal data_from_mem: UNSIGNED((PMOD_DRIVER_MAX_DATA_BYTES*8)-1 downto 0) := (others => '0');
137
 
138
------------------------------------------------------------------------
139
-- Module Implementation
140
------------------------------------------------------------------------
141
begin
142
 
143
    --------------------------------------
144
        -- Top Pmod SF3 Driver System Clock --
145
        --------------------------------------
146
    inst_clk_wiz_0: clk_wiz_0 port map(clk_out1 => pmod_sys_clock, clk_in1 => i_sys_clock);
147
 
148
        ---------------------------------------
149
        -- Top Pmod SF3 Driver State Machine --
150
        ---------------------------------------
151
        -- Top Pmod SF3 State
152
        process(pmod_sys_clock)
153
        begin
154
                if rising_edge(pmod_sys_clock) then
155
 
156
                        -- Reset
157
                        if (i_reset = '1') then
158
                                state <= IDLE;
159
                        else
160
                                state <= next_state;
161
                        end if;
162
 
163
                end if;
164
        end process;
165
 
166
        -- Top Pmod SF3 Next State
167
        process(state, i_start, pmod_driver_ready)
168
        begin
169
                case state is
170
                        -- IDLE
171
                        when IDLE =>    if (i_start = '1') then
172
                                                                next_state <= CONFIG_READ_VOLATILE_DC;
173
                                                        else
174
                                                                next_state <= IDLE;
175
                                                        end if;
176
 
177
            -- Config Read Volatile Dummy Cycles
178
            when CONFIG_READ_VOLATILE_DC => next_state <= START_READ_VOLATILE_DC;
179
 
180
                        -- Start Read Volatile Dummy Cycles
181
                        when START_READ_VOLATILE_DC =>
182
                            if (pmod_driver_ready = '0') then
183
                                                                next_state <= READ_VOLATILE_DC;
184
                                                        else
185
                                                                next_state <= START_READ_VOLATILE_DC;
186
                                                        end if;
187
 
188
                        -- Read Volatile Dummy Cycles
189
                        when READ_VOLATILE_DC =>
190
                            if (pmod_driver_ready = '1') then
191
                                                                next_state <= COMPLETED;
192
                                                        else
193
                                                                next_state <= READ_VOLATILE_DC;
194
                                                        end if;
195
 
196
                        -- Completed
197
                        when others => next_state <= COMPLETED;
198
                end case;
199
        end process;
200
 
201
    ---------------------------
202
        -- Pmod SF3 Driver Reset --
203
        ---------------------------
204
        process(pmod_sys_clock)
205
        begin
206
                if rising_edge(pmod_sys_clock) then
207
 
208
                        -- Start Pmod SF3 Driver
209
                        if (state = IDLE) then
210
                                pmod_driver_reset <= '1';
211
                        else
212
                pmod_driver_reset <= '0';
213
                        end if;
214
                end if;
215
        end process;
216
 
217
        ---------------------------
218
        -- Pmod SF3 Driver Start --
219
        ---------------------------
220
        process(pmod_sys_clock)
221
        begin
222
                if rising_edge(pmod_sys_clock) then
223
 
224
                        -- Start Pmod SF3 Driver
225
                        if (state = START_READ_VOLATILE_DC) then
226
                                pmod_driver_start <= '1';
227
                        else
228
                pmod_driver_start <= '0';
229
                        end if;
230
                end if;
231
        end process;
232
 
233
        -------------------------------------
234
        -- Pmod SF3 Driver Read/Write Mode --
235
        -------------------------------------
236
        process(pmod_sys_clock)
237
        begin
238
                if rising_edge(pmod_sys_clock) then
239
 
240
                        -- Start Pmod SF3 Driver
241
                        if (state = CONFIG_READ_VOLATILE_DC) then
242
                                pmod_driver_rw <= PMOD_DRIVER_READ_MODE;
243
                        end if;
244
                end if;
245
        end process;
246
 
247
        -----------------------------
248
        -- Pmod SF3 Driver Command --
249
        -----------------------------
250
        process(pmod_sys_clock)
251
        begin
252
                if rising_edge(pmod_sys_clock) then
253
 
254
                        -- Pmod SF3 Read Volatile Dummy Cycles Command
255
                        if (state = CONFIG_READ_VOLATILE_DC) then
256
                                pmod_driver_command <= READ_VOLATILE_DC_COMMAND;
257
                        end if;
258
                end if;
259
        end process;
260
 
261
        -----------------------------
262
        -- Pmod SF3 Driver Address --
263
        -----------------------------
264
        process(pmod_sys_clock)
265
        begin
266
                if rising_edge(pmod_sys_clock) then
267
 
268
                        -- Pmod SF3 Read Volatile Dummy Cycles Address
269
                        if (state = CONFIG_READ_VOLATILE_DC) then
270
                                pmod_driver_addr_bytes <= 0;
271
                pmod_driver_addr <= (others => '0');
272
                        end if;
273
                end if;
274
        end process;
275
 
276
    -------------------------------
277
        -- Pmod SF3 Driver Data Byte --
278
        -------------------------------
279
        process(pmod_sys_clock)
280
        begin
281
                if rising_edge(pmod_sys_clock) then
282
 
283
                        -- Pmod SF3 Read Volatile Dummy Cycles Data Byte
284
                        if (state = CONFIG_READ_VOLATILE_DC) then
285
                                pmod_driver_data_bytes <= 1;
286
                        end if;
287
                end if;
288
        end process;
289
 
290
        --------------------------------
291
        -- Pmod SF3 Driver Data Input --
292
        --------------------------------
293
        process(pmod_sys_clock)
294
        begin
295
                if rising_edge(pmod_sys_clock) then
296
 
297
                        -- Pmod SF3 Read Volatile Dummy Cycles Data Input
298
                        if (state = CONFIG_READ_VOLATILE_DC) then
299
                pmod_driver_data_in <= (others => '0');
300
                        end if;
301
                end if;
302
        end process;
303
 
304
        ---------------------------------
305
        -- Pmod SF3 Driver Data Output --
306
        ---------------------------------
307
        process(pmod_sys_clock)
308
        begin
309
                if rising_edge(pmod_sys_clock) then
310
 
311
            -- Reset
312
            if (state = IDLE) then
313
                data_from_mem <= (others => '0');
314
 
315
            -- Pmod SF3 Read Volatile Dummy Cycles Data Output
316
                        elsif (state = COMPLETED) and (pmod_driver_data_out_ready = '1') then
317
                data_from_mem <= pmod_driver_data_out;
318
                        end if;
319
                end if;
320
        end process;
321
 
322
        ---------------------
323
        -- Pmod SF3 Driver --
324
        ---------------------
325
        inst_PmodSF3Driver: PmodSF3Driver
326
        GENERIC map (
327
            sys_clock => 24_000_000,
328
            max_data_byte => PMOD_DRIVER_MAX_DATA_BYTES)
329
 
330
                PORT map (
331
                        i_sys_clock => pmod_sys_clock,
332
                        i_reset => pmod_driver_reset,
333
                        i_start => pmod_driver_start,
334
            i_rw => pmod_driver_rw,
335
            i_command => pmod_driver_command,
336
            i_addr_bytes => pmod_driver_addr_bytes,
337
            i_addr => pmod_driver_addr,
338
            i_data_bytes => pmod_driver_data_bytes,
339
            i_data => pmod_driver_data_in,
340
            o_data => pmod_driver_data_out,
341
            o_data_ready => pmod_driver_data_out_ready,
342
            o_ready => pmod_driver_ready,
343
            o_reset => o_reset,
344
            o_sclk => o_sclk,
345
            io_dq => io_dq,
346
            o_ss => o_ss,
347
            o_spi_using_sys_freq => pmod_driver_spi_using_sys_clock);
348
 
349
        -----------------
350
        -- LEDs Output --
351
        -----------------
352
    o_led(7 downto 0) <= data_from_mem;
353
    o_led(8 downto 8) <= (others => '0');
354
    o_led(9) <= i_start;
355
    o_led(10) <= pmod_driver_ready;
356
    o_led(11) <= '1' when state = IDLE else '0';
357
    o_led(12) <= '1' when state = CONFIG_READ_VOLATILE_DC else '0';
358
    o_led(13) <= '1' when state = START_READ_VOLATILE_DC else '0';
359
    o_led(14) <= '1' when state = READ_VOLATILE_DC else '0';
360
    o_led(15) <= '1' when state = COMPLETED else '0';
361
 
362
end Behavioral;

powered by: WebSVN 2.1.0

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