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

Subversion Repositories w11

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 wfjm
-- $Id: byte2cdata.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:    byte2cdata - syn
16
-- Description:    Byte stream to 9 bit comma,data 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-08-27    76   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 byte2cdata is                    -- byte stream -> 9bit comma,data
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
    DI : in slv8;                       -- input data
44
    ENA : in slbit;                     -- write enable
45
    BUSY : out slbit;                   -- write port hold    
46 9 wfjm
    DO : out slv9;                      -- output data; bit 8 = comma flag
47 2 wfjm
    VAL : out slbit;                    -- read valid
48
    HOLD : in slbit                     -- read hold
49
  );
50
end byte2cdata;
51
 
52
 
53
architecture syn of byte2cdata is
54
 
55
  type state_type is (
56
    s_idle,
57
    s_data,
58
    s_escape
59
  );
60
 
61
  type regs_type is record
62
    data : slv9;                        -- 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 13 wfjm
    if rising_edge(CLK) then
84 2 wfjm
      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 ival : slbit := '0';
99
    variable ibusy : slbit := '0';
100
 
101
  begin
102
 
103
    r := R_REGS;
104
    n := R_REGS;
105
 
106
    ival := '0';
107
    ibusy := '1';
108
 
109
    case r.state is
110
 
111
      when s_idle =>
112
        ibusy := '0';
113
        if ENA = '1' then
114
          n.data := "0" & DI;
115
          n.state := s_data;
116
          if DI(7 downto 4) = CPREF then
117
            if DI(3 downto 0) = "1111" then
118
              n.state := s_escape;
119
            elsif unsigned(DI(3 downto 0)) <= NCOMM then
120
              n.data := "10000" & DI(3 downto 0);
121
              n.state := s_data;
122
            end if;
123
          end if;
124
        end if;
125
 
126
      when s_data =>
127
        ival := '1';
128
        if HOLD = '0' then
129
          n.state := s_idle;
130
        end if;
131
 
132
      when s_escape =>
133
        ibusy := '0';
134
        if ENA = '1' then
135
          n.data := "0" & CPREF & DI(3 downto 0);
136
          n.state := s_data;
137
        end if;
138
 
139
      when others => null;
140
    end case;
141
 
142
    N_REGS <= n;
143
 
144
    DO <= r.data;
145
    VAL <= ival;
146
    BUSY <= ibusy;
147
 
148
  end process proc_next;
149
 
150
 
151
end syn;

powered by: WebSVN 2.1.0

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