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 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 microengin
-- IOTA Pearl Diver VHDL Port
2
--
3 7 microengin
-- 2018 by Thomas Pototschnig <microengineer18@gmail.com,
4
-- http://microengineer.eu
5
-- discord: pmaxuw#8292
6 5 microengin
--
7 7 microengin
-- Permission is hereby granted, free of charge, to any person obtaining
8
-- a copy of this software and associated documentation files (the
9
-- "Software"), to deal in the Software without restriction, including
10
-- without limitation the rights to use, copy, modify, merge, publish,
11
-- distribute, sublicense, and/or sell copies of the Software, and to
12
-- permit persons to whom the Software is furnished to do so, subject to
13
-- the following conditions:
14 5 microengin
-- 
15 7 microengin
-- The above copyright notice and this permission notice shall be
16
-- included in all copies or substantial portions of the Software.
17 5 microengin
-- 
18 7 microengin
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
-- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
-- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
-- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
 
26
 
27 4 microengin
library ieee;
28
 
29
use ieee.std_logic_1164.all;
30
use ieee.numeric_std.all;
31
 
32
 
33
entity spi_slave is
34
        port
35
        (
36
                clk : in std_logic;
37
                reset : in std_logic;
38
 
39
                mosi : in std_logic;
40
                miso : out std_logic;
41
                sck : in std_logic;
42
                ss : in std_logic;
43
 
44
 
45
                data_rd : in std_logic_vector(31 downto 0);
46
                data_wr : out std_logic_vector(31 downto 0);
47 7 microengin
                data_wren : out std_logic;
48
                data_strobe : in std_logic
49 4 microengin
 
50
        );
51
end spi_slave;
52
 
53
 
54
architecture behv of spi_slave is
55
signal sync_mosi : std_logic_vector(1 downto 0);
56
signal sync_sck : std_logic_vector(1 downto 0);
57
signal sync_ss : std_logic_vector(1 downto 0);
58
 
59
 
60
begin
61
 
62
        process(clk)
63
        variable cnt : integer range 0 to 32 := 0;
64
        variable iwren : std_logic;
65
        variable i_miso : std_logic;
66
        variable i_shiftregister : std_logic_vector(31 downto 0);
67
 
68
        begin
69
                if rising_edge(clk) then
70
                        if reset='1' then
71
                                cnt := 0;
72
                                data_wren <= '0';
73
                                iwren := '0';
74
                        else
75
                                iwren := '0';
76
 
77
                                sync_mosi <= sync_mosi(0) & mosi;
78
                                sync_sck <= sync_sck(0) & sck;
79
                                sync_ss <= sync_ss(0) & ss;
80
 
81 7 microengin
                                if data_strobe = '1' then
82
                                        i_shiftregister := data_rd;
83
                                end if;
84
 
85 4 microengin
                                case sync_ss is
86
                                        when "11" =>
87 7 microengin
--                                              i_shiftregister := data_rd;
88 4 microengin
                                                cnt := 0;
89
--                                              i_flip := '0';
90
                                        when "10" =>
91
                                                miso <= i_shiftregister(31);
92
                                        when "01" =>
93
                                                cnt := 0;
94
                                                iwren := '1';
95
                                                data_wr <= i_shiftregister;
96
                                        when "00" =>
97
                                                case sync_sck is
98
                                                        when "01" =>
99 7 microengin
                                                                i_shiftregister := i_shiftregister(30 downto 0) & mosi;
100 4 microengin
                                                                cnt := cnt + 1;
101
                                                        when "10" =>
102
                                                                miso <= i_shiftregister(31);
103
                                                        when others =>
104
                                                end case;
105
                                        when others =>
106
                                end case;
107
                                data_wren <= iwren;
108
                        end if;
109
                end if;
110
        end process;
111
 
112
 
113
end behv;

powered by: WebSVN 2.1.0

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