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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.74/] [rtl/] [vlib/] [comlib/] [byte2cdata.vhd] - Diff between revs 13 and 27

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 13 Rev 27
-- $Id: byte2cdata.vhd 427 2011-11-19 21:04:11Z mueller $
-- $Id: byte2cdata.vhd 596 2014-10-17 19:50:07Z mueller $
--
--
-- Copyright 2007-2011 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
-- Copyright 2007-2014 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
--
--
-- This program is free software; you may redistribute and/or modify it under
-- This program is free software; you may redistribute and/or modify it under
-- the terms of the GNU General Public License as published by the Free
-- the terms of the GNU General Public License as published by the Free
-- Software Foundation, either version 2, or at your option any later version.
-- Software Foundation, either version 2, or at your option any later version.
--
--
-- This program is distributed in the hope that it will be useful, but
-- This program is distributed in the hope that it will be useful, but
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-- for complete details.
-- for complete details.
--
--
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Module Name:    byte2cdata - syn
-- Module Name:    byte2cdata - syn
-- Description:    Byte stream to 9 bit comma,data converter
-- Description:    Byte stream to 9 bit comma,data converter
--
--
-- Dependencies:   -
-- Dependencies:   -
-- Test bench:     -
-- Test bench:     -
-- Target Devices: generic
-- Target Devices: generic
-- Tool versions:  xst 8.2, 9.1, 9.2, 12.1, 13.1; ghdl 0.18-0.29
-- Tool versions:  xst 8.2-14.7; ghdl 0.18-0.31
--
--
-- Revision History: 
-- Revision History: 
-- Date         Rev Version  Comment
-- Date         Rev Version  Comment
 
-- 2014-10-17   596   2.0    re-write, commas now 2 byte sequences
-- 2011-11-19   427   1.0.2  now numeric_std clean
-- 2011-11-19   427   1.0.2  now numeric_std clean
-- 2007-10-12    88   1.0.1  avoid ieee.std_logic_unsigned, use cast to unsigned
-- 2007-10-12    88   1.0.1  avoid ieee.std_logic_unsigned, use cast to unsigned
-- 2007-08-27    76   1.0    Initial version 
-- 2007-08-27    76   1.0    Initial version 
------------------------------------------------------------------------------
------------------------------------------------------------------------------
 
 
library ieee;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.numeric_std.all;
 
 
use work.slvtypes.all;
use work.slvtypes.all;
 
use work.comlib.all;
 
 
entity byte2cdata is                    -- byte stream -> 9bit comma,data
entity byte2cdata is                    -- byte stream -> 9bit comma,data
  generic (
 
    CPREF : slv4 :=  "1000";            -- comma prefix
 
    NCOMM : positive :=  4);            -- number of comma chars
 
  port (
  port (
    CLK : in slbit;                     -- clock
    CLK : in slbit;                     -- clock
    RESET : in slbit;                   -- reset
    RESET : in slbit;                   -- reset
    DI : in slv8;                       -- input data
    DI : in slv8;                       -- input data
    ENA : in slbit;                     -- write enable
    ENA : in slbit;                     -- input data enable
    BUSY : out slbit;                   -- write port hold    
    ERR : in slbit;                     -- input data error
 
    BUSY : out slbit;                   -- input data busy
    DO : out slv9;                      -- output data; bit 8 = comma flag
    DO : out slv9;                      -- output data; bit 8 = comma flag
    VAL : out slbit;                    -- read valid
    VAL : out slbit;                    -- output data valid
    HOLD : in slbit                     -- read hold
    HOLD : in slbit                     -- output data hold
  );
  );
end byte2cdata;
end byte2cdata;
 
 
 
 
architecture syn of byte2cdata is
architecture syn of byte2cdata is
 
 
  type state_type is (
 
    s_idle,
 
    s_data,
 
    s_escape
 
  );
 
 
 
  type regs_type is record
  type regs_type is record
    data : slv9;                        -- current data
    data : slv9;                        -- data
    state : state_type;                 -- state
    dataval : slbit;                    -- data valid
 
    edpend : slbit;                     -- edata pending
  end record regs_type;
  end record regs_type;
 
 
  constant regs_init : regs_type := (
  constant regs_init : regs_type := (
    (others=>'0'),
    (others=>'0'),                      -- data
    s_idle
    '0','0'                             -- dataval,edpend
  );
  );
 
 
  signal R_REGS : regs_type := regs_init;  -- state registers
  signal R_REGS : regs_type := regs_init;  -- state registers
  signal N_REGS : regs_type := regs_init;  -- next value state regs
  signal N_REGS : regs_type := regs_init;  -- next value state regs
 
 
begin
begin
 
 
  assert NCOMM <= 14
 
    report "assert(NCOMM <= 14)"
 
    severity FAILURE;
 
 
 
  proc_regs: process (CLK)
  proc_regs: process (CLK)
  begin
  begin
 
 
    if rising_edge(CLK) then
    if rising_edge(CLK) then
      if RESET = '1' then
      if RESET = '1' then
        R_REGS <= regs_init;
        R_REGS <= regs_init;
      else
      else
        R_REGS <= N_REGS;
        R_REGS <= N_REGS;
      end if;
      end if;
    end if;
    end if;
 
 
  end process proc_regs;
  end process proc_regs;
 
 
  proc_next: process (R_REGS, DI, ENA, HOLD)
  proc_next: process (R_REGS, DI, ENA, ERR, HOLD)
 
 
    variable r : regs_type := regs_init;
    variable r : regs_type := regs_init;
    variable n : regs_type := regs_init;
    variable n : regs_type := regs_init;
 
 
    variable ival : slbit := '0';
    variable idata : slv9 := (others=>'0');
 
    variable iesc :  slbit := '0';
    variable ibusy : slbit := '0';
    variable ibusy : slbit := '0';
 
 
  begin
  begin
 
 
    r := R_REGS;
    r := R_REGS;
    n := R_REGS;
    n := R_REGS;
 
 
    ival := '0';
    -- data path logic
    ibusy := '1';
    idata := '1' & "00000" & "100";   -- clobber
 
    iesc  := '0';
    case r.state is
 
 
    if r.edpend = '1' then
      when s_idle =>
      if DI(c_cdata_edf_pref) = c_cdata_ed_pref and
        ibusy := '0';
         (not DI(c_cdata_edf_eci)) = DI(c_cdata_edf_ec) then
        if ENA = '1' then
        case DI(c_cdata_edf_ec) is
          n.data := "0" & DI;
          when c_cdata_ec_xon =>
          n.state := s_data;
            idata := '0' & c_cdata_xon;
          if DI(7 downto 4) = CPREF then
          when c_cdata_ec_xoff =>
            if DI(3 downto 0) = "1111" then
            idata := '0' & c_cdata_xoff;
              n.state := s_escape;
          when c_cdata_ec_fill =>
            elsif unsigned(DI(3 downto 0)) <= NCOMM then
            idata := '0' & c_cdata_fill;
              n.data := "10000" & DI(3 downto 0);
          when c_cdata_ec_esc =>
              n.state := s_data;
            idata := '0' & c_cdata_escape;
 
          when others =>
 
            idata := '1' &  "00000" & DI(c_cdata_edf_ec);
 
        end case;
            end if;
            end if;
 
    else
 
      idata := '0' & DI;
 
      if DI = c_cdata_escape then
 
        iesc := '1';
          end if;
          end if;
        end if;
    end if;
 
 
      when s_data =>
    -- control path logic
        ival := '1';
    ibusy := '1';
        if HOLD = '0' then
        if HOLD = '0' then
          n.state := s_idle;
 
        end if;
 
 
 
      when s_escape =>
 
        ibusy := '0';
        ibusy := '0';
 
      n.dataval := '0';
 
      n.data    := idata;
        if ENA = '1' then
        if ENA = '1' then
          n.data := "0" & CPREF & DI(3 downto 0);
        if r.edpend = '0' then
          n.state := s_data;
          if iesc = '0' then
 
            n.dataval := '1';
 
          else
 
            n.edpend  := '1';
 
          end if;
 
        else
 
          n.dataval := '1';
 
          n.edpend  := '0';
 
        end if;
 
      elsif ERR = '1' then
 
        n.dataval := '1';
 
      end if;
        end if;
        end if;
 
 
      when others => null;
 
    end case;
 
 
 
    N_REGS <= n;
    N_REGS <= n;
 
 
    DO <= r.data;
    DO <= r.data;
    VAL <= ival;
    VAL  <= r.dataval;
    BUSY <= ibusy;
    BUSY <= ibusy;
 
 
  end process proc_next;
  end process proc_next;
 
 
 
 
end syn;
end syn;
 
 

powered by: WebSVN 2.1.0

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