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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.5/] [rtl/] [vlib/] [comlib/] [cdata2byte.vhd] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 wfjm
-- $Id: cdata2byte.vhd 314 2010-07-09 17:38:41Z mueller $
2
--
3
-- Copyright 2007- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4
--
5
-- This program is free software; you may redistribute and/or modify it under
6
-- the terms of the GNU General Public License as published by the Free
7
-- Software Foundation, either version 2, or at your option any later version.
8
--
9
-- This program is distributed in the hope that it will be useful, but
10
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
-- for complete details.
13
--
14
------------------------------------------------------------------------------
15
-- Module Name:    cdata2byte - syn
16
-- Description:    9 bit comma,data to Byte stream converter
17
--
18
-- Dependencies:   -
19
-- Test bench:     -
20
-- Target Devices: generic
21
-- Tool versions:  xst 8.1, 8.2, 9.1, 9.2; ghdl 0.18-0.25
22
-- Revision History: 
23
-- Date         Rev Version  Comment
24
-- 2007-10-12    88   1.0.1  avoid ieee.std_logic_unsigned, use cast to unsigned
25
-- 2007-06-30    62   1.0    Initial version 
26
------------------------------------------------------------------------------
27
 
28
library ieee;
29
use ieee.std_logic_1164.all;
30
use ieee.std_logic_arith.all;
31
 
32
use work.slvtypes.all;
33
 
34
entity cdata2byte is                    -- 9bit comma,data -> byte stream
35
  generic (
36
    CPREF : slv4 :=  "1000";            -- comma prefix
37
    NCOMM : positive :=  4);            -- number of comma chars
38
  port (
39
    CLK : in slbit;                     -- clock
40
    RESET : in slbit;                   -- reset
41
    DI : in slv9;                       -- input data; bit 8 = komma flag
42
    ENA : in slbit;                     -- write enable
43
    BUSY : out slbit;                   -- write port hold    
44
    DO : out slv8;                      -- output data
45
    VAL : out slbit;                    -- read valid
46
    HOLD : in slbit                     -- read hold
47
  );
48
end cdata2byte;
49
 
50
 
51
architecture syn of cdata2byte is
52
 
53
  type state_type is (
54
    s_idle,
55
    s_data,
56
    s_comma,
57
    s_escape,
58
    s_edata
59
  );
60
 
61
  type regs_type is record
62
    data : slv8;                        -- current data
63
    state : state_type;                 -- state
64
  end record regs_type;
65
 
66
  constant regs_init : regs_type := (
67
    (others=>'0'),
68
    s_idle
69
  );
70
 
71
  signal R_REGS : regs_type := regs_init;  -- state registers
72
  signal N_REGS : regs_type := regs_init;  -- next value state regs
73
 
74
begin
75
 
76
  assert NCOMM <= 14
77
    report "assert(NCOMM <= 14)"
78
    severity FAILURE;
79
 
80
  proc_regs: process (CLK)
81
  begin
82
 
83
    if CLK'event and CLK='1' then
84
      if RESET = '1' then
85
        R_REGS <= regs_init;
86
      else
87
        R_REGS <= N_REGS;
88
      end if;
89
    end if;
90
 
91
  end process proc_regs;
92
 
93
  proc_next: process (R_REGS, DI, ENA, HOLD)
94
 
95
    variable r : regs_type := regs_init;
96
    variable n : regs_type := regs_init;
97
 
98
    variable ido : slv8 := (others=>'0');
99
    variable ival : slbit := '0';
100
    variable ibusy : slbit := '0';
101
 
102
  begin
103
 
104
    r := R_REGS;
105
    n := R_REGS;
106
 
107
    ido := r.data;
108
    ival := '0';
109
    ibusy := '1';
110
 
111
    case r.state is
112
 
113
      when s_idle =>
114
        ibusy := '0';
115
        if ENA = '1' then
116
          n.data := DI(7 downto 0);
117
          n.state := s_data;
118
          if DI(8) = '1' then
119
            n.state := s_comma;
120
          else
121
            if DI(7 downto 4)=CPREF  and
122
              (DI(3 downto 0)="1111"  or
123
               unsigned(DI(3 downto 0))<=NCOMM) then
124
              n.state := s_escape;
125
            end if;
126
          end if;
127
        end if;
128
 
129
      when s_data =>
130
        ival := '1';
131
        if HOLD = '0' then
132
          n.state := s_idle;
133
        end if;
134
 
135
      when s_comma =>
136
        ido := CPREF & r.data(3 downto 0);
137
        ival := '1';
138
        if HOLD = '0' then
139
          n.state := s_idle;
140
        end if;
141
 
142
      when s_escape =>
143
        ido := CPREF & "1111";
144
        ival := '1';
145
        if HOLD = '0' then
146
          n.state := s_edata;
147
        end if;
148
 
149
      when s_edata =>
150
        ido := (not CPREF) & r.data(3 downto 0);
151
        ival := '1';
152
        if HOLD = '0' then
153
          n.state := s_idle;
154
        end if;
155
 
156
      when others => null;
157
    end case;
158
 
159
    N_REGS <= n;
160
 
161
    DO   <= ido;
162
    VAL  <= ival;
163
    BUSY <= ibusy;
164
 
165
  end process proc_next;
166
 
167
 
168
end syn;

powered by: WebSVN 2.1.0

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