~ruther/vhdl-spi

ref: 6d6f0d480de810a2fe0d2c946ae9c61b6a85c4c6 vhdl-spi/src/spi_recv.vhd -rw-r--r-- 1.1 KiB
6d6f0d48 — František Boháček tests: add tests for shift registers 1 year, 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
library ieee;
use ieee.std_logic_1164.all;

entity spi_recv is

  generic (
    WIDTH : integer := 8);

  port (
    clk_i : in std_logic;
    rst_in : in std_logic;
    data_i : in std_logic;
    recv_o : out std_logic;
    recv_data_o : out std_logic_vector(WIDTH - 1 downto 0));
end entity spi_recv;

architecture a1 of spi_recv is
  signal bit_index_reg : integer range 0 to WIDTH;
  signal initialized : std_logic;
begin  -- architecture a1
  recv_o <= '1' when bit_index_reg = 0 and initialized = '1' else
            '0';

  set_bit_index: process (clk_i) is
  begin  -- process set_bit_index
    if rst_in = '0' then            -- synchronous reset (active low)
      bit_index_reg <= 0;
      initialized <= '0';
    elsif rising_edge(clk_i) then        -- rising clock edge
      initialized <= '1';
      bit_index_reg <= (bit_index_reg + 1) mod WIDTH;
    end if;
  end process set_bit_index;

  sr: entity work.sipo_shift_register
    generic map (
      WIDTH => WIDTH)
    port map (
      clk_i  => clk_i,
      data_i => data_i,
      q_o => recv_data_o);

end architecture a1;
Do not follow this link