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

Subversion Repositories w11

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 17 wfjm
-- $Id: word2byte.vhd 432 2011-11-25 20:16:28Z mueller $
2
--
3
-- Copyright 2011- 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:    word2byte - syn
16
-- Description:    1 word -> 2 byte stream converter
17
--
18
-- Dependencies:   -
19
-- Test bench:     -
20
-- Target Devices: generic
21
-- Tool versions:  xst 12.1; ghdl 0.29
22
--
23
-- Revision History: 
24
-- Date         Rev Version  Comment
25
-- 2011-11-21   432   1.0.1  now numeric_std clean
26
-- 2011-07-30   400   1.0    Initial version 
27
------------------------------------------------------------------------------
28
 
29
library ieee;
30
use ieee.std_logic_1164.all;
31
use ieee.numeric_std.all;
32
 
33
use work.slvtypes.all;
34
 
35
entity word2byte is                     -- 1 word -> 2 byte stream converter
36
  port (
37
    CLK : in slbit;                     -- clock
38
    RESET : in slbit;                   -- reset
39
    DI : in slv16;                      -- input data (word)
40
    ENA : in slbit;                     -- write enable
41
    BUSY : out slbit;                   -- write port hold    
42
    DO : out slv8;                      -- output data (byte)
43
    VAL : out slbit;                    -- read valid
44
    HOLD : in slbit;                    -- read hold
45
    ODD : out slbit                     -- odd byte pending
46
  );
47
end word2byte;
48
 
49
 
50
architecture syn of word2byte is
51
 
52
  type state_type is (
53
    s_idle,
54
    s_valw,
55
    s_valh
56
  );
57
 
58
  type regs_type is record
59
    datl : slv8;                        -- lsb data
60
    dath : slv8;                        -- msb data
61
    state : state_type;                 -- state
62
  end record regs_type;
63
 
64
  constant regs_init : regs_type := (
65
    (others=>'0'),
66
    (others=>'0'),
67
    s_idle
68
  );
69
 
70
  signal R_REGS : regs_type := regs_init;  -- state registers
71
  signal N_REGS : regs_type := regs_init;  -- next value state regs
72
 
73
begin
74
 
75
  proc_regs: process (CLK)
76
  begin
77
 
78
    if rising_edge(CLK) then
79
      if RESET = '1' then
80
        R_REGS <= regs_init;
81
      else
82
        R_REGS <= N_REGS;
83
      end if;
84
    end if;
85
 
86
  end process proc_regs;
87
 
88
  proc_next: process (R_REGS, DI, ENA, HOLD)
89
 
90
    variable r : regs_type := regs_init;
91
    variable n : regs_type := regs_init;
92
 
93
    variable ival  : slbit := '0';
94
    variable ibusy : slbit := '0';
95
    variable iodd  : slbit := '0';
96
 
97
  begin
98
 
99
    r := R_REGS;
100
    n := R_REGS;
101
 
102
    ival  := '0';
103
    ibusy := '0';
104
    iodd  := '0';
105
 
106
    case r.state is
107
 
108
      when s_idle =>
109
        if ENA = '1' then
110
          n.datl := DI( 7 downto 0);
111
          n.dath := DI(15 downto 8);
112
          n.state := s_valw;
113
        end if;
114
 
115
      when s_valw =>
116
        ibusy := '1';
117
        ival  := '1';
118
        if HOLD = '0' then
119
          n.datl := r.dath;
120
          n.state := s_valh;
121
        end if;
122
 
123
      when s_valh =>
124
        ival := '1';
125
        iodd := '1';
126
        if HOLD = '0' then
127
          if ENA = '1' then
128
            n.datl := DI( 7 downto 0);
129
            n.dath := DI(15 downto 8);
130
            n.state := s_valw;
131
          else
132
            n.state := s_idle;
133
          end if;
134
        else
135
          ibusy := '1';
136
        end if;
137
 
138
      when others => null;
139
    end case;
140
 
141
    N_REGS <= n;
142
 
143
    DO   <= r.datl;
144
    VAL  <= ival;
145
    BUSY <= ibusy;
146
    ODD  <= iodd;
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.