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

Subversion Repositories w11

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 wfjm
-- $Id: cdata2byte.vhd 348 2010-12-26 15:23:44Z mueller $
2 2 wfjm
--
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 9 wfjm
-- Tool versions:  xst 8.1, 8.2, 9.1, 9.2, 12.1; ghdl 0.18-0.29
22
--
23 2 wfjm
-- Revision History: 
24
-- Date         Rev Version  Comment
25
-- 2007-10-12    88   1.0.1  avoid ieee.std_logic_unsigned, use cast to unsigned
26
-- 2007-06-30    62   1.0    Initial version 
27
------------------------------------------------------------------------------
28
 
29
library ieee;
30
use ieee.std_logic_1164.all;
31
use ieee.std_logic_arith.all;
32
 
33
use work.slvtypes.all;
34
 
35
entity cdata2byte is                    -- 9bit comma,data -> byte stream
36
  generic (
37
    CPREF : slv4 :=  "1000";            -- comma prefix
38
    NCOMM : positive :=  4);            -- number of comma chars
39
  port (
40
    CLK : in slbit;                     -- clock
41
    RESET : in slbit;                   -- reset
42 9 wfjm
    DI : in slv9;                       -- input data; bit 8 = comma flag
43 2 wfjm
    ENA : in slbit;                     -- write enable
44
    BUSY : out slbit;                   -- write port hold    
45
    DO : out slv8;                      -- output data
46
    VAL : out slbit;                    -- read valid
47
    HOLD : in slbit                     -- read hold
48
  );
49
end cdata2byte;
50
 
51
 
52
architecture syn of cdata2byte is
53
 
54
  type state_type is (
55
    s_idle,
56
    s_data,
57
    s_comma,
58
    s_escape,
59
    s_edata
60
  );
61
 
62
  type regs_type is record
63
    data : slv8;                        -- current data
64
    state : state_type;                 -- state
65
  end record regs_type;
66
 
67
  constant regs_init : regs_type := (
68
    (others=>'0'),
69
    s_idle
70
  );
71
 
72
  signal R_REGS : regs_type := regs_init;  -- state registers
73
  signal N_REGS : regs_type := regs_init;  -- next value state regs
74
 
75
begin
76
 
77
  assert NCOMM <= 14
78
    report "assert(NCOMM <= 14)"
79
    severity FAILURE;
80
 
81
  proc_regs: process (CLK)
82
  begin
83
 
84
    if CLK'event and CLK='1' then
85
      if RESET = '1' then
86
        R_REGS <= regs_init;
87
      else
88
        R_REGS <= N_REGS;
89
      end if;
90
    end if;
91
 
92
  end process proc_regs;
93
 
94
  proc_next: process (R_REGS, DI, ENA, HOLD)
95
 
96
    variable r : regs_type := regs_init;
97
    variable n : regs_type := regs_init;
98
 
99
    variable ido : slv8 := (others=>'0');
100
    variable ival : slbit := '0';
101
    variable ibusy : slbit := '0';
102
 
103
  begin
104
 
105
    r := R_REGS;
106
    n := R_REGS;
107
 
108
    ido := r.data;
109
    ival := '0';
110
    ibusy := '1';
111
 
112
    case r.state is
113
 
114
      when s_idle =>
115
        ibusy := '0';
116
        if ENA = '1' then
117
          n.data := DI(7 downto 0);
118
          n.state := s_data;
119
          if DI(8) = '1' then
120
            n.state := s_comma;
121
          else
122
            if DI(7 downto 4)=CPREF  and
123
              (DI(3 downto 0)="1111"  or
124
               unsigned(DI(3 downto 0))<=NCOMM) then
125
              n.state := s_escape;
126
            end if;
127
          end if;
128
        end if;
129
 
130
      when s_data =>
131
        ival := '1';
132
        if HOLD = '0' then
133
          n.state := s_idle;
134
        end if;
135
 
136
      when s_comma =>
137
        ido := CPREF & r.data(3 downto 0);
138
        ival := '1';
139
        if HOLD = '0' then
140
          n.state := s_idle;
141
        end if;
142
 
143
      when s_escape =>
144
        ido := CPREF & "1111";
145
        ival := '1';
146
        if HOLD = '0' then
147
          n.state := s_edata;
148
        end if;
149
 
150
      when s_edata =>
151
        ido := (not CPREF) & r.data(3 downto 0);
152
        ival := '1';
153
        if HOLD = '0' then
154
          n.state := s_idle;
155
        end if;
156
 
157
      when others => null;
158
    end case;
159
 
160
    N_REGS <= n;
161
 
162
    DO   <= ido;
163
    VAL  <= ival;
164
    BUSY <= ibusy;
165
 
166
  end process proc_next;
167
 
168
 
169
end syn;

powered by: WebSVN 2.1.0

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