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

Subversion Repositories w11

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

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

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

powered by: WebSVN 2.1.0

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