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

Subversion Repositories spi_slave

[/] [spi_slave/] [trunk/] [pcore/] [opb_spi_slave_v1_00_a/] [hdl/] [vhdl/] [crc_core.vhd] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 20 dkoethe
 
2
library ieee;
3
use ieee.std_logic_1164.all;
4
 
5
entity crc_core is
6
 
7
  generic (
8
    C_SR_WIDTH : integer := 32);
9
  port (
10
    rst              : in  std_logic;
11
    opb_clk          : in  std_logic;
12
    crc_en           : in  std_logic;
13
    crc_clr          : in  std_logic;
14
    opb_m_last_block : in  std_logic;
15
    -- RX
16
    fifo_rx_en       : in  std_logic;
17
    fifo_rx_data     : in  std_logic_vector(C_SR_WIDTH-1 downto 0);
18
    opb_rx_crc_value : out std_logic_vector(C_SR_WIDTH-1 downto 0);
19
    -- TX
20
    fifo_tx_en       : in  std_logic;
21
    fifo_tx_data     : in  std_logic_vector(C_SR_WIDTH-1 downto 0);
22
    tx_crc_insert    : out std_logic;
23
    opb_tx_crc_value : out std_logic_vector(C_SR_WIDTH-1 downto 0));
24
end crc_core;
25
 
26
 
27
architecture behavior of crc_core is
28
  component crc_gen
29
    generic (
30
      C_SR_WIDTH      : integer;
31
      crc_start_value : std_logic_vector(31 downto 0));
32
    port (
33
      clk          : in  std_logic;
34
      crc_clear    : in  std_logic;
35
      crc_en       : in  std_logic;
36
      crc_data_in  : in  std_logic_vector(C_SR_WIDTH-1 downto 0);
37
      crc_data_out : out std_logic_vector(C_SR_WIDTH-1 downto 0));
38
  end component;
39
 
40
  signal rx_crc_en : std_logic;
41
  signal tx_crc_en : std_logic;
42
 
43 28 dkoethe
 
44 33 dkoethe
  type state_define is (idle,
45
                        tx_insert_crc,
46
                        wait_done);
47
  signal state : state_define;
48
 
49 20 dkoethe
begin  -- behavior
50
 
51
  --* RX CRC_GEN
52
  crc_gen_rx : crc_gen
53
    generic map (
54
      C_SR_WIDTH      => C_SR_WIDTH,
55
      crc_start_value => (others => '1'))
56
    port map (
57
      clk          => OPB_Clk,
58
      crc_clear    => crc_clr,
59
      crc_en       => rx_crc_en,
60
      crc_data_in  => fifo_rx_data,
61
      crc_data_out => opb_rx_crc_value);
62
 
63
  -- disable crc_generation for last data block
64
  rx_crc_en <= '1' when (crc_en = '1' and fifo_rx_en = '1' and opb_m_last_block = '0') else
65
               '0';
66
 
67
  -----------------------------------------------------------------------------
68
  --* TX CRC_GEN
69
  crc_gen_tx : crc_gen
70
    generic map (
71
      C_SR_WIDTH      => C_SR_WIDTH,
72
      crc_start_value => (others => '1'))
73
    port map (
74
      clk          => OPB_Clk,
75
      crc_clear    => crc_clr,
76
      crc_en       => tx_crc_en,
77
      crc_data_in  => fifo_tx_data,
78
      crc_data_out => opb_tx_crc_value);
79
 
80
  -- disable crc_generation for last data block
81
  tx_crc_en <= '1' when (crc_en = '1' and fifo_tx_en = '1' and opb_m_last_block = '0') else
82
               '0';
83
 
84
  process(rst, OPB_Clk)
85
  begin
86
    if (rst = '1') then
87
      tx_crc_insert <= '0';
88 33 dkoethe
      state <= idle;
89 20 dkoethe
    elsif rising_edge(OPB_Clk) then
90 33 dkoethe
      case state is
91
        when idle =>
92
          if (opb_m_last_block = '1') then
93
            tx_crc_insert <= '1';
94
            state         <= tx_insert_crc;
95
          else
96
            tx_crc_insert <= '0';
97
            state <= idle;
98
          end if;
99
 
100
        when tx_insert_crc =>
101
          if (opb_m_last_block = '0') then
102
            -- abort
103
            tx_crc_insert <= '0';
104
            state         <= idle;
105
          elsif (fifo_tx_en = '1') then
106
            tx_crc_insert <= '0';
107
            state         <= wait_done;
108
          else
109
            state <= tx_insert_crc;
110
          end if;
111
 
112
        when wait_done =>
113
          if (opb_m_last_block = '0') then
114
            tx_crc_insert <= '0';
115
            state         <= idle;
116
 
117
          else
118
            state <= wait_done;
119
          end if;
120
 
121
        when others =>
122
          state <= idle;
123
      end case;
124
 
125 20 dkoethe
    end if;
126
  end process;
127
end behavior;

powered by: WebSVN 2.1.0

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