]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/lx-rocon.git/blob - hw/crc.vhd
Testbed for receiver CRC processing check.
[fpga/lx-cpu1/lx-rocon.git] / hw / crc.vhd
1 --
2 -- * CRC-8 generator *
3 --
4 -- part of LXPWR motion control board (c) PiKRON Ltd
5 -- idea by Pavel Pisa PiKRON Ltd <pisa@cmp.felk.cvut.cz>
6 -- code by Marek Peca <mp@duch.cz>
7 -- 01/2013
8 --
9 -- license: GNU GPLv3
10 --
11
12 library ieee;
13 use ieee.std_logic_1164.all;
14 use ieee.numeric_std.all;
15
16 entity crc is
17         port
18         (
19                 clk_i   : in std_logic;
20                 reset_i : in std_logic;
21                 input_i : in std_logic;
22                 crc_o   : out std_logic_vector(7 downto 0)
23         );
24 end crc;
25
26 architecture behavioral of crc is
27         signal reg_s, next_reg_s : std_logic_vector(7 downto 0);
28 begin
29         crc_o <= next_reg_s;
30
31 comb: process (reset_i, input_i, reg_s)
32         begin
33                 if reset_i = '1' then
34                         next_reg_s <= (others => '1');
35                 else
36                         next_reg_s(4 downto 0) <= reg_s(5 downto 1);
37                         next_reg_s(5) <= reg_s(0) xor reg_s(6);
38                         next_reg_s(6) <= reg_s(0) xor reg_s(7);
39                         next_reg_s(7) <= reg_s(0) xor input_i;
40                 end if;
41         end process;
42
43 seq: process
44   begin
45                 wait until clk_i'event and clk_i = '1';
46                 reg_s <= next_reg_s;
47         end process;
48
49 end behavioral;