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

Subversion Repositories iota_pow_vhdl

[/] [iota_pow_vhdl/] [trunk/] [vhdl_altera_de1/] [spi_slave.vhd] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 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 2 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 2 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 2 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 SOFTWAR
25 2 microengin
 
26
library ieee;
27
 
28
use ieee.std_logic_1164.all;
29
use ieee.numeric_std.all;
30
 
31
 
32
entity spi_slave is
33
        port
34
        (
35
                clk : in std_logic;
36
                reset : in std_logic;
37
 
38
                mosi : in std_logic;
39
                miso : out std_logic;
40
                sck : in std_logic;
41
                ss : in std_logic;
42
 
43
 
44
                data_rd : in std_logic_vector(31 downto 0);
45
                data_wr : out std_logic_vector(31 downto 0);
46
                data_wren : out std_logic
47
 
48
        );
49
end spi_slave;
50
 
51
 
52
architecture behv of spi_slave is
53
signal sync_mosi : std_logic_vector(1 downto 0);
54
signal sync_sck : std_logic_vector(1 downto 0);
55
signal sync_ss : std_logic_vector(1 downto 0);
56
 
57
 
58
begin
59
 
60
        process(clk)
61
        variable cnt : integer range 0 to 32 := 0;
62
        variable iwren : std_logic;
63
        variable i_miso : std_logic;
64
        variable i_shiftregister : std_logic_vector(31 downto 0);
65
 
66
        begin
67
                if rising_edge(clk) then
68
                        if reset='1' then
69
                                cnt := 0;
70
                                data_wren <= '0';
71
                                iwren := '0';
72
                        else
73
                                iwren := '0';
74
 
75
                                sync_mosi <= sync_mosi(0) & mosi;
76
                                sync_sck <= sync_sck(0) & sck;
77
                                sync_ss <= sync_ss(0) & ss;
78
 
79
                                case sync_ss is
80
                                        when "11" =>
81
                                                i_shiftregister := data_rd;
82
                                                cnt := 0;
83
--                                              i_flip := '0';
84
                                        when "10" =>
85
                                                miso <= i_shiftregister(31);
86
                                        when "01" =>
87
                                                cnt := 0;
88
                                                iwren := '1';
89
                                                data_wr <= i_shiftregister;
90
                                        when "00" =>
91
                                                case sync_sck is
92
                                                        when "01" =>
93
                                                                i_shiftregister := i_shiftregister(30 downto 0) & sync_mosi(0);
94
                                                                cnt := cnt + 1;
95
                                                        when "10" =>
96
                                                                miso <= i_shiftregister(31);
97
                                                        when others =>
98
                                                end case;
99
                                        when others =>
100
                                end case;
101
                                data_wren <= iwren;
102
                        end if;
103
                end if;
104
        end process;
105
 
106
 
107 5 microengin
end behv;

powered by: WebSVN 2.1.0

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