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 5

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

Line No. Rev Author Line
1 2 microengin
-- IOTA Pearl Diver VHDL Port
2
--
3
-- Written 2018 by Thomas Pototschnig <microengineer18@gmail.com>
4
--
5
-- This source code is currently licensed under
6 5 microengin
-- Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)
7 2 microengin
-- 
8
-- http://www.microengineer.eu
9
-- 
10
-- If you like my project please consider a donation to
11
--
12
-- LLEYMHRKXWSPMGCMZFPKKTHSEMYJTNAZXSAYZGQUEXLXEEWPXUNWBFDWESOJVLHQHXOPQEYXGIRBYTLRWHMJAOSHUY
13
--
14
-- As soon as donations reach 1000MIOTA, everything will become
15
-- GPL and open for any use - commercial included.
16
 
17
library ieee;
18
 
19
use ieee.std_logic_1164.all;
20
use ieee.numeric_std.all;
21
 
22
 
23
entity spi_slave is
24
        port
25
        (
26
                clk : in std_logic;
27
                reset : in std_logic;
28
 
29
                mosi : in std_logic;
30
                miso : out std_logic;
31
                sck : in std_logic;
32
                ss : in std_logic;
33
 
34
 
35
                data_rd : in std_logic_vector(31 downto 0);
36
                data_wr : out std_logic_vector(31 downto 0);
37
                data_wren : out std_logic
38
 
39
        );
40
end spi_slave;
41
 
42
 
43
architecture behv of spi_slave is
44
signal sync_mosi : std_logic_vector(1 downto 0);
45
signal sync_sck : std_logic_vector(1 downto 0);
46
signal sync_ss : std_logic_vector(1 downto 0);
47
 
48
 
49
begin
50
 
51
        process(clk)
52
        variable cnt : integer range 0 to 32 := 0;
53
        variable iwren : std_logic;
54
        variable i_miso : std_logic;
55
        variable i_shiftregister : std_logic_vector(31 downto 0);
56
 
57
        begin
58
                if rising_edge(clk) then
59
                        if reset='1' then
60
                                cnt := 0;
61
                                data_wren <= '0';
62
                                iwren := '0';
63
                        else
64
                                iwren := '0';
65
 
66
                                sync_mosi <= sync_mosi(0) & mosi;
67
                                sync_sck <= sync_sck(0) & sck;
68
                                sync_ss <= sync_ss(0) & ss;
69
 
70
                                case sync_ss is
71
                                        when "11" =>
72
                                                i_shiftregister := data_rd;
73
                                                cnt := 0;
74
--                                              i_flip := '0';
75
                                        when "10" =>
76
                                                miso <= i_shiftregister(31);
77
                                        when "01" =>
78
                                                cnt := 0;
79
                                                iwren := '1';
80
                                                data_wr <= i_shiftregister;
81
                                        when "00" =>
82
                                                case sync_sck is
83
                                                        when "01" =>
84
                                                                i_shiftregister := i_shiftregister(30 downto 0) & sync_mosi(0);
85
                                                                cnt := cnt + 1;
86
                                                        when "10" =>
87
                                                                miso <= i_shiftregister(31);
88
                                                        when others =>
89
                                                end case;
90
                                        when others =>
91
                                end case;
92
                                data_wren <= iwren;
93
                        end if;
94
                end if;
95
        end process;
96
 
97
 
98 5 microengin
end behv;

powered by: WebSVN 2.1.0

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