aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/synth/fsm02/recv.vhdl
blob: 11bbb152a94d41cc668ea8bfc85ae152944208f5 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
library ieee;
use ieee.std_logic_1164.all;

entity recv is
  port (
    rst : std_logic;
    clk : std_logic;
    rx : std_logic;
    byte : out std_logic_vector (7 downto 0);
    b_err : out std_logic;
    b_en : out std_logic);
end recv;

architecture behav of recv
is
    type state_t is
         (s_wait, s0, s1, s2, s3, s4, s5, s6, s7, s_parity, s_stop);
    signal state: state_t;
    signal parity: std_logic;
    signal err : std_logic;
    signal en : std_logic;
begin
  process (clk) is
  begin
    if rising_edge(clk) then
      if rst = '1' then
        state <= s_wait;
        err <= '0';
        en <= '0';
      else
        en <= '0';
        case state is
          when s_wait =>
            if rx = '0' then
              state <= s0;
              err <= '0';
              parity <= '0';
            end if;
          when s0 =>
            byte (0) <= rx;
            parity <= parity xor rx;
            state <= s1;
          when s1 =>
            byte (1) <= rx;
            parity <= parity xor rx;
            state <= s2;
          when s2 =>
            byte (2) <= rx;
            parity <= parity xor rx;
            state <= s3;
          when s3 =>
            byte (3) <= rx;
            parity <= parity xor rx;
            state <= s4;
          when s4 =>
            byte (4) <= rx;
            parity <= parity xor rx;
            state <= s5;
          when s5 =>
            byte (5) <= rx;
            parity <= parity xor rx;
            state <= s6;
          when s6 =>
            byte (6) <= rx;
            parity <= parity xor rx;
            state <= s7;
          when s7 =>
            byte (7) <= rx;
            parity <= parity xor rx;
            state <= s_parity;
          when s_parity =>
            if rx /= parity then
              err <= '1';
            end if;
            state <= s_stop;
          when s_stop =>
            if rx /= '1' then
              err <= '1';
            end if;
            en <= '1';
            state <= s_wait;
        end case;
      end if;
    end if;
  end process;

    b_en <= en;
    b_err <= err;

    --psl default clock is rising_edge(clk);
    --psl restrict {rst;(not rst)[*]};

    assert rst = '1' or err /= '1' report "parity error" severity error;
end behav;