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

Subversion Repositories iota_pow_vhdl

[/] [iota_pow_vhdl/] [trunk/] [vhdl_cyclone10_lp/] [spi_slave.vhd] - Blame information for rev 4

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

Line No. Rev Author Line
1 4 microengin
library ieee;
2
 
3
use ieee.std_logic_1164.all;
4
use ieee.numeric_std.all;
5
 
6
 
7
entity spi_slave is
8
        port
9
        (
10
                clk : in std_logic;
11
                reset : in std_logic;
12
 
13
                mosi : in std_logic;
14
                miso : out std_logic;
15
                sck : in std_logic;
16
                ss : in std_logic;
17
 
18
 
19
                data_rd : in std_logic_vector(31 downto 0);
20
                data_wr : out std_logic_vector(31 downto 0);
21
                data_wren : out std_logic
22
 
23
        );
24
end spi_slave;
25
 
26
 
27
architecture behv of spi_slave is
28
signal sync_mosi : std_logic_vector(1 downto 0);
29
signal sync_sck : std_logic_vector(1 downto 0);
30
signal sync_ss : std_logic_vector(1 downto 0);
31
 
32
 
33
begin
34
 
35
        process(clk)
36
        variable cnt : integer range 0 to 32 := 0;
37
        variable iwren : std_logic;
38
        variable i_miso : std_logic;
39
        variable i_shiftregister : std_logic_vector(31 downto 0);
40
 
41
        begin
42
                if rising_edge(clk) then
43
                        if reset='1' then
44
                                cnt := 0;
45
                                data_wren <= '0';
46
                                iwren := '0';
47
                        else
48
                                iwren := '0';
49
 
50
                                sync_mosi <= sync_mosi(0) & mosi;
51
                                sync_sck <= sync_sck(0) & sck;
52
                                sync_ss <= sync_ss(0) & ss;
53
 
54
                                case sync_ss is
55
                                        when "11" =>
56
                                                i_shiftregister := data_rd;
57
                                                cnt := 0;
58
--                                              i_flip := '0';
59
                                        when "10" =>
60
                                                miso <= i_shiftregister(31);
61
                                        when "01" =>
62
                                                cnt := 0;
63
                                                iwren := '1';
64
                                                data_wr <= i_shiftregister;
65
                                        when "00" =>
66
                                                case sync_sck is
67
                                                        when "01" =>
68
                                                                i_shiftregister := i_shiftregister(30 downto 0) & sync_mosi(0);
69
                                                                cnt := cnt + 1;
70
                                                        when "10" =>
71
                                                                miso <= i_shiftregister(31);
72
                                                        when others =>
73
                                                end case;
74
                                        when others =>
75
                                end case;
76
                                data_wren <= iwren;
77
                        end if;
78
                end if;
79
        end process;
80
 
81
 
82
end behv;

powered by: WebSVN 2.1.0

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