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

Subversion Repositories w11

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 wfjm
-- $Id: byte2cdata.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:    byte2cdata - syn
16
-- Description:    Byte stream to 9 bit comma,data 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-08-27    76   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 byte2cdata is                    -- byte stream -> 9bit comma,data
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 slv8;                       -- input data
42
    ENA : in slbit;                     -- write enable
43
    BUSY : out slbit;                   -- write port hold    
44
    DO : out slv9;                      -- output data; bit 8 = komma flag
45
    VAL : out slbit;                    -- read valid
46
    HOLD : in slbit                     -- read hold
47
  );
48
end byte2cdata;
49
 
50
 
51
architecture syn of byte2cdata is
52
 
53
  type state_type is (
54
    s_idle,
55
    s_data,
56
    s_escape
57
  );
58
 
59
  type regs_type is record
60
    data : slv9;                        -- current data
61
    state : state_type;                 -- state
62
  end record regs_type;
63
 
64
  constant regs_init : regs_type := (
65
    (others=>'0'),
66
    s_idle
67
  );
68
 
69
  signal R_REGS : regs_type := regs_init;  -- state registers
70
  signal N_REGS : regs_type := regs_init;  -- next value state regs
71
 
72
begin
73
 
74
  assert NCOMM <= 14
75
    report "assert(NCOMM <= 14)"
76
    severity FAILURE;
77
 
78
  proc_regs: process (CLK)
79
  begin
80
 
81
    if CLK'event and CLK='1' then
82
      if RESET = '1' then
83
        R_REGS <= regs_init;
84
      else
85
        R_REGS <= N_REGS;
86
      end if;
87
    end if;
88
 
89
  end process proc_regs;
90
 
91
  proc_next: process (R_REGS, DI, ENA, HOLD)
92
 
93
    variable r : regs_type := regs_init;
94
    variable n : regs_type := regs_init;
95
 
96
    variable ival : slbit := '0';
97
    variable ibusy : slbit := '0';
98
 
99
  begin
100
 
101
    r := R_REGS;
102
    n := R_REGS;
103
 
104
    ival := '0';
105
    ibusy := '1';
106
 
107
    case r.state is
108
 
109
      when s_idle =>
110
        ibusy := '0';
111
        if ENA = '1' then
112
          n.data := "0" & DI;
113
          n.state := s_data;
114
          if DI(7 downto 4) = CPREF then
115
            if DI(3 downto 0) = "1111" then
116
              n.state := s_escape;
117
            elsif unsigned(DI(3 downto 0)) <= NCOMM then
118
              n.data := "10000" & DI(3 downto 0);
119
              n.state := s_data;
120
            end if;
121
          end if;
122
        end if;
123
 
124
      when s_data =>
125
        ival := '1';
126
        if HOLD = '0' then
127
          n.state := s_idle;
128
        end if;
129
 
130
      when s_escape =>
131
        ibusy := '0';
132
        if ENA = '1' then
133
          n.data := "0" & CPREF & DI(3 downto 0);
134
          n.state := s_data;
135
        end if;
136
 
137
      when others => null;
138
    end case;
139
 
140
    N_REGS <= n;
141
 
142
    DO <= r.data;
143
    VAL <= ival;
144
    BUSY <= ibusy;
145
 
146
  end process proc_next;
147
 
148
 
149
end syn;

powered by: WebSVN 2.1.0

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