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

Subversion Repositories graphiti

[/] [graphiti/] [trunk/] [xilinx/] [spi.vhd] - Blame information for rev 10

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

Line No. Rev Author Line
1 3 pototschni
-------------------------------------------------------------------------------
2
--      MiniGA
3
--  Author: Thomas Pototschnig (thomas.pototschnig@gmx.de)
4
--
5
--  License: Creative Commons Attribution-NonCommercial-ShareAlike 2.0 License
6
--           http://creativecommons.org/licenses/by-nc-sa/2.0/de/
7
--
8
--  If you want to use MiniGA for commercial purposes please contact the author
9
-------------------------------------------------------------------------------
10
-- spi interface 
11
-- very slow because this component is crap!
12
-- reason: tried to implement a shift register which gets the clock from SCK
13
-- but this makes a lot harder. Next version will sample the SPI pins
14
 
15
library IEEE;
16
use IEEE.STD_LOGIC_1164.ALL;
17
use IEEE.STD_LOGIC_ARITH.ALL;
18
use IEEE.STD_LOGIC_UNSIGNED.ALL;
19
 
20
entity spi is
21
        port (
22
                clk : in std_logic;
23
                reset : in std_logic;
24
                spi_ss : in std_logic;
25
                spi_clk : in std_logic;
26
                spi_data : in std_logic;
27
                spi_cd : in std_logic;
28
 
29
                out_adr : out std_logic_vector (18 downto 0);
30
                out_data : out std_logic_vector (15 downto 0);
31
                out_wr : out std_logic;
32
                testbild_en : out std_logic
33
        );
34
end spi;
35
 
36
architecture behaviour of spi is
37
signal rcvd_flag : std_logic;
38
signal rcvd_data : std_logic_vector (15 downto 0);
39
signal rcvd_cd : std_logic;
40
signal ack : std_logic;
41
 
42
begin
43
 
44
        process (spi_ss, spi_clk, ack, reset)
45
        variable ctr : integer := 0;
46
        variable data : std_logic_vector (15 downto 0);
47
        begin
48
                if spi_ss='1' or ack='0' or reset='0' then
49
                        ctr := 0;
50
                        rcvd_flag <= '0';
51
                elsif spi_clk'event and spi_clk='1' then
52
                        if ctr /= 16 then -- braucht man nicht - aber erstmal testen wie simuliert
53
                                data(15-ctr):=spi_data;
54
                                ctr:=ctr+1;
55
                                if ctr = 16 then
56
                                        rcvd_data <= data;
57
                                        rcvd_flag <= '1';
58
                                        rcvd_cd <= spi_cd;
59
                                        ctr := 0;
60
                                end if;
61
                        end if;
62
                end if;
63
        end process;
64
 
65
        process (clk, reset)
66
        variable state : integer := 0;
67
        variable adr : unsigned (18 downto 0);
68
        variable cmd : integer := 0;
69
        begin
70
                if reset='0' then
71
                        state := 0;
72
                        adr := conv_unsigned(0,19);
73
                        out_adr <= (others => '0');
74
                        out_data <= (others => '0');
75
                        out_wr <= '1';
76
                        ack <= '1';
77
                        testbild_en <= '1';
78
                elsif clk'event and clk='1' then
79
                        case state is
80
                                when 0 =>        -- etwas per spi empfangen?
81
                                        if rcvd_flag = '1' then
82
                                                state:=1;
83
                                        end if;
84
                                when 1 =>       -- ja - dann adr und data ausgeben und schreiben aktivieren
85
                                        ack <= '0'; -- spi resetten
86
 
87
                                        out_adr <= conv_std_logic_vector(adr,19);
88
                                        adr := adr + 1;
89
 
90
                                        if rcvd_cd='0' then      -- datum empfangen
91
                                                out_data <= rcvd_data;
92
                                                out_wr <= '0';
93
                                        else                            -- commando empfangen
94
                                                cmd := conv_integer(rcvd_data (15 downto 10));
95
                                                case cmd is
96
                                                        when 1 => -- low-byte der adresse
97
                                                                adr (9 downto 0) := unsigned(rcvd_data(9 downto 0));
98
                                                        when 2 => -- high-byte der adresse
99
                                                                adr (18 downto 10) := unsigned(rcvd_data (8 downto 0));
100
                                                        when 3 => -- testbild an / aus
101
                                                                testbild_en <= rcvd_data(0);
102
                                                        when others =>
103
                                                end case;
104
                                        end if;
105
 
106
                                        state := 2;
107
 
108
                                when 2 =>       -- jetzt wurde das zeugs geschrieben
109
                                        ack <= '1';
110
                                        out_wr <= '1';
111
                                        state := 0;
112
                                when others =>
113
                                        state:=0;
114
                        end case;
115
                end if;
116
        end process;
117
 
118
end architecture;

powered by: WebSVN 2.1.0

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