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

Subversion Repositories hdlc

[/] [hdlc/] [trunk/] [CODE/] [TOP/] [core/] [RxFCS.vhd] - Blame information for rev 17

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 10 khatib
-------------------------------------------------------------------------------
2
-- Title      :  Rx FCS
3
-- Project    :  HDLC controller
4
-------------------------------------------------------------------------------
5
-- File        : RxFCS.vhd
6
-- Author      : Jamil Khatib  (khatib@ieee.org)
7
-- Organization: OpenIPCore Project
8
-- Created     :2001/04/05
9
-- Last update: 2001/04/20
10
-- Platform    : 
11
-- Simulators  : Modelsim 5.3XE/Windows98,NC-SIM/Linux
12
-- Synthesizers: 
13
-- Target      : 
14
-- Dependency  : ieee.std_logic_1164, ieee.std_logic_unsigned
15
--               hdlc.PCK_CRC16_D8
16
-------------------------------------------------------------------------------
17
-- Description:  HDLC RX FCS-16 checking
18
-------------------------------------------------------------------------------
19
-- Copyright (c) 2000 Jamil Khatib
20
-- 
21
-- This VHDL design file is an open design; you can redistribute it and/or
22
-- modify it and/or implement it after contacting the author
23
-- You can check the draft license at
24
-- http://www.opencores.org/OIPC/license.shtml
25
 
26
-------------------------------------------------------------------------------
27
-- Revisions  :
28
-- Revision Number :   1
29
-- Version         :   0.1
30
-- Date            :   5 April 2001
31
-- Modifier        :   Jamil Khatib (khatib@ieee.org)
32
-- Desccription    :   Created
33
-- ToOptimize      :
34
-- Bugs            :
35
-------------------------------------------------------------------------------
36
-- $Log: not supported by cvs2svn $
37
-- Revision 1.2  2001/04/20 18:29:01  jamil
38
-- Sencetivity list bug fixed
39
--
40
-- Revision 1.1  2001/04/14 15:02:25  jamil
41
-- Initial Release
42
--
43
-------------------------------------------------------------------------------
44
 
45
LIBRARY ieee;
46
USE ieee.std_logic_1164.ALL;
47
USE ieee.std_logic_unsigned.ALL;
48
 
49
LIBRARY hdlc;
50
USE hdlc.PCK_CRC16_D8.ALL;
51
 
52
 
53
ENTITY RxFCS_ent IS
54
  GENERIC (
55
    FCS_TYPE   :     INTEGER := 2);                 -- 2= FCS 16
56
                                                    -- 4= FCS 32
57
                                                    -- 0= disable FCS
58
  PORT (
59
    clk        : IN  STD_LOGIC;                     -- system clock
60
    rst_n      : IN  STD_LOGIC;                     -- system reset
61
    RxD        : IN  STD_LOGIC_VECTOR(7 DOWNTO 0);  -- Rx Data bus
62
    ValidFrame : IN  STD_LOGIC;                     -- Frame Strobe
63
    rdy        : IN  STD_LOGIC;                     -- rdy to send byte
64
    Readbyte   : OUT STD_LOGIC;                     -- Read byte
65
    DataBuff   : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);  -- Rx output data
66
    WrBuff     : OUT STD_LOGIC;                     -- Write to buffer
67
    EOF        : OUT STD_LOGIC;                     -- End of Frame pulse
68
    FCSen      : IN  STD_LOGIC;                     -- FCs enable
69
    FCSerr     : OUT STD_LOGIC);                    -- FCS error
70
 
71
END RxFCS_ent;
72
 
73
ARCHITECTURE RxFCS_rtl OF RxFCS_ent IS
74
 
75
  TYPE STATES_typ IS (IDLE_st, RUN_st, READ_st, EOF_st);  -- Internal states
76
  SIGNAL p_state : STATES_typ;                            -- Present state
77
  SIGNAL n_state : STATES_typ;                            -- Next state
78
 
79
  SIGNAL FCS_reg   : STD_LOGIC_VECTOR(15 DOWNTO 0);  -- FCS register
80
  SIGNAL FCS_value : STD_LOGIC_VECTOR(15 DOWNTO 0);  -- FCS value
81
 
82
  SIGNAL WrBuff_i : STD_LOGIC;          -- Internal WrBuff
83
  SIGNAL EOF_i    : STD_LOGIC;          -- Internal EOF
84
 
85
BEGIN  -- RxFCS_rtl
86
-- purpose: FSM 
87
-- type   : sequential
88
-- inputs : clk, rst_n
89
-- outputs: 
90
  fsm : PROCESS (clk, rst_n)
91
 
92
  BEGIN  -- PROCESS fsm
93
 
94
    IF rst_n = '0' THEN                 -- asynchronous reset (active low)
95
      p_state  <= IDLE_st;
96
      FCS_reg  <= (OTHERS => '1');
97
      WrBuff   <= '0';
98
      DataBuff <= (OTHERS => '1');
99
      EOF      <= '0';
100
    ELSIF clk'event AND clk = '1' THEN  -- rising clock edge
101
      p_state  <= n_state;
102
      FCS_reg  <= FCS_value;
103
      DataBuff <= RxD;
104
      WrBuff   <= WrBuff_i;
105
      EOF      <= EOF_i;
106
    END IF;
107
 
108
  END PROCESS fsm;
109
 
110
 
111
-- purpose: fsm combination input/output logic
112
-- type   : combinational
113
-- inputs : p_state,ValidFrame,rdy
114
-- outputs: 
115
  fsm_logic : PROCESS (p_state, ValidFrame, rdy, FCS_reg, FCSen,RxD)
116
 
117
  BEGIN  -- PROCESS fsm_logic
118
 
119
    CASE p_state IS
120
 
121
      WHEN IDLE_st =>
122
 
123
        FCSerr    <= '0';
124
        WrBuff_i  <= '0';
125
        FCS_value <= (OTHERS => '1');
126
        Readbyte  <= '0';
127
        EOF_i     <= '0';
128
        IF (ValidFrame = '1') THEN
129
          n_state <= RUN_st;
130
        ELSE
131
          n_state <= IDLE_st;
132
        END IF;
133
 
134
      WHEN RUN_st =>
135
        FCSerr   <= '0';
136
        WrBuff_i <= '0';
137
        IF (ValidFrame = '1') THEN
138
 
139
          FCS_value <= FCS_reg;
140
          EOF_i     <= '0';
141
 
142
          IF (rdy = '1') THEN
143
            n_state  <= READ_st;
144
            Readbyte <= '0';
145
          ELSE
146
            n_state  <= RUN_st;
147
            Readbyte <= '0';
148
          END IF;
149
 
150
        ELSE
151
          n_state   <= EOF_st;
152
          Readbyte  <= '0';
153
          FCS_value <= FCS_reg;
154
          EOF_i     <= '1';
155
 
156
        END IF;
157
 
158
      WHEN EOF_st =>
159
 
160
        n_state  <= IDLE_st;
161
        Readbyte <= '0';
162
        WrBuff_i <= '0';
163
        FCSerr   <= FCSen AND
164
                    NOT (NOT FCS_reg(15) AND NOT FCS_reg(14)AND NOT FCS_reg(13) AND FCS_reg(12)
165
                         AND FCS_reg(11) AND FCS_reg(10) AND NOT FCS_reg(9) AND FCS_reg(8)
166
                         AND NOT FCS_reg(7) AND NOT FCS_reg(6) AND NOT FCS_reg(5) AND NOT FCS_reg(4)
167
                         AND FCS_reg(3) AND FCS_reg(2) AND FCS_reg(1) AND FCS_reg(0)
168
                         );
169
--                    0001 1101 0000 1111
170
 
171
        FCS_value <= (OTHERS => '1');
172
        EOF_i     <= '0';
173
 
174
      WHEN READ_st =>
175
 
176
        FCSerr <= '0';
177
        EOF_i  <= '0';
178
 
179
        IF (rdy = '1') THEN
180
 
181
          n_state   <= READ_st;
182
          FCS_value <= FCS_reg;
183
          WrBuff_i  <= '0';
184
          Readbyte  <= '1';
185
 
186
        ELSE                            -- Data valid
187
 
188
          n_state   <= RUN_st;
189
          FCS_value <= nextCRC16_D8 ( RxD, FCS_reg );  --FCS_reg;
190
          WrBuff_i  <= '1';
191
          Readbyte  <= '0';
192
 
193
        END IF;
194
 
195
      WHEN OTHERS => NULL;
196
    END CASE;
197
 
198
  END PROCESS fsm_logic;
199
 
200
 
201
 
202
END RxFCS_rtl;

powered by: WebSVN 2.1.0

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