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] - Diff between revs 5 and 7

Only display areas with differences | Details | Blame | View Log

Rev 5 Rev 7
-- IOTA Pearl Diver VHDL Port
-- IOTA Pearl Diver VHDL Port
--
--
-- Written 2018 by Thomas Pototschnig <microengineer18@gmail.com>
-- 2018 by Thomas Pototschnig <microengineer18@gmail.com,
--
-- http://microengineer.eu
-- This source code is currently licensed under
-- discord: pmaxuw#8292
-- Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)
--
-- 
-- Permission is hereby granted, free of charge, to any person obtaining
-- http://www.microengineer.eu
-- a copy of this software and associated documentation files (the
-- 
-- "Software"), to deal in the Software without restriction, including
-- If you like my project please consider a donation to
-- without limitation the rights to use, copy, modify, merge, publish,
--
-- distribute, sublicense, and/or sell copies of the Software, and to
-- LLEYMHRKXWSPMGCMZFPKKTHSEMYJTNAZXSAYZGQUEXLXEEWPXUNWBFDWESOJVLHQHXOPQEYXGIRBYTLRWHMJAOSHUY
-- permit persons to whom the Software is furnished to do so, subject to
--
-- the following conditions:
-- As soon as donations reach 1000MIOTA, everything will become
-- 
-- GPL and open for any use - commercial included.
-- The above copyright notice and this permission notice shall be
 
-- included in all copies or substantial portions of the Software.
 
-- 
 
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
-- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
-- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
-- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 
 
 
library ieee;
library ieee;
 
 
use ieee.std_logic_1164.all;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.numeric_std.all;
 
 
 
 
entity spi_slave is
entity spi_slave is
        port
        port
        (
        (
                clk : in std_logic;
                clk : in std_logic;
                reset : in std_logic;
                reset : in std_logic;
 
 
                mosi : in std_logic;
                mosi : in std_logic;
                miso : out std_logic;
                miso : out std_logic;
                sck : in std_logic;
                sck : in std_logic;
                ss : in std_logic;
                ss : in std_logic;
 
 
 
 
                data_rd : in std_logic_vector(31 downto 0);
                data_rd : in std_logic_vector(31 downto 0);
                data_wr : out std_logic_vector(31 downto 0);
                data_wr : out std_logic_vector(31 downto 0);
                data_wren : out std_logic
                data_wren : out std_logic;
 
                data_strobe : in std_logic
 
 
        );
        );
end spi_slave;
end spi_slave;
 
 
 
 
architecture behv of spi_slave is
architecture behv of spi_slave is
signal sync_mosi : std_logic_vector(1 downto 0);
signal sync_mosi : std_logic_vector(1 downto 0);
signal sync_sck : std_logic_vector(1 downto 0);
signal sync_sck : std_logic_vector(1 downto 0);
signal sync_ss : std_logic_vector(1 downto 0);
signal sync_ss : std_logic_vector(1 downto 0);
 
 
 
 
begin
begin
 
 
        process(clk)
        process(clk)
        variable cnt : integer range 0 to 32 := 0;
        variable cnt : integer range 0 to 32 := 0;
        variable iwren : std_logic;
        variable iwren : std_logic;
        variable i_miso : std_logic;
        variable i_miso : std_logic;
        variable i_shiftregister : std_logic_vector(31 downto 0);
        variable i_shiftregister : std_logic_vector(31 downto 0);
 
 
        begin
        begin
                if rising_edge(clk) then
                if rising_edge(clk) then
                        if reset='1' then
                        if reset='1' then
                                cnt := 0;
                                cnt := 0;
                                data_wren <= '0';
                                data_wren <= '0';
                                iwren := '0';
                                iwren := '0';
                        else
                        else
                                iwren := '0';
                                iwren := '0';
 
 
                                sync_mosi <= sync_mosi(0) & mosi;
                                sync_mosi <= sync_mosi(0) & mosi;
                                sync_sck <= sync_sck(0) & sck;
                                sync_sck <= sync_sck(0) & sck;
                                sync_ss <= sync_ss(0) & ss;
                                sync_ss <= sync_ss(0) & ss;
 
 
 
                                if data_strobe = '1' then
 
                                        i_shiftregister := data_rd;
 
                                end if;
 
 
                                case sync_ss is
                                case sync_ss is
                                        when "11" =>
                                        when "11" =>
                                                i_shiftregister := data_rd;
--                                              i_shiftregister := data_rd;
                                                cnt := 0;
                                                cnt := 0;
--                                              i_flip := '0';
--                                              i_flip := '0';
                                        when "10" =>
                                        when "10" =>
                                                miso <= i_shiftregister(31);
                                                miso <= i_shiftregister(31);
                                        when "01" =>
                                        when "01" =>
                                                cnt := 0;
                                                cnt := 0;
                                                iwren := '1';
                                                iwren := '1';
                                                data_wr <= i_shiftregister;
                                                data_wr <= i_shiftregister;
                                        when "00" =>
                                        when "00" =>
                                                case sync_sck is
                                                case sync_sck is
                                                        when "01" =>
                                                        when "01" =>
                                                                i_shiftregister := i_shiftregister(30 downto 0) & sync_mosi(0);
                                                                i_shiftregister := i_shiftregister(30 downto 0) & mosi;
                                                                cnt := cnt + 1;
                                                                cnt := cnt + 1;
                                                        when "10" =>
                                                        when "10" =>
                                                                miso <= i_shiftregister(31);
                                                                miso <= i_shiftregister(31);
                                                        when others =>
                                                        when others =>
                                                end case;
                                                end case;
                                        when others =>
                                        when others =>
                                end case;
                                end case;
                                data_wren <= iwren;
                                data_wren <= iwren;
                        end if;
                        end if;
                end if;
                end if;
        end process;
        end process;
 
 
 
 
end behv;
end behv;
 
 

powered by: WebSVN 2.1.0

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