w11 - vhd  0.72
W11 CPU core and support modules
 All Classes Namespaces Files Functions Variables
byte2word.vhd
Go to the documentation of this file.
1 -- $Id: byte2word.vhd 649 2015-02-21 21:10:16Z 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: byte2word - syn
16 -- Description: 2 byte -> 1 word stream converter
17 --
18 -- Dependencies: -
19 -- Test bench: -
20 -- Target Devices: generic
21 -- Tool versions: xst 12.1-14.7; ghdl 0.29-0.31
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 byte2word is -- 2 byte -> 1 word stream converter
36  port (
37  CLK : in slbit; -- clock
38  RESET : in slbit; -- reset
39  DI : in slv8; -- input data (byte)
40  ENA : in slbit; -- write enable
41  BUSY : out slbit; -- write port hold
42  DO : out slv16; -- output data (word)
43  VAL : out slbit; -- read valid
44  HOLD : in slbit; -- read hold
45  ODD : out slbit -- odd byte pending
46  );
47 end byte2word;
48 
49 
50 architecture syn of byte2word is
51 
52  type state_type is (
53  s_idle,
54  s_vall,
55  s_valw
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;
111  n.state := s_vall;
112  end if;
113 
114  when s_vall =>
115  iodd := '1';
116  if ENA = '1' then
117  n.dath := DI;
118  n.state := s_valw;
119  end if;
120 
121  when s_valw =>
122  ival := '1';
123  if HOLD = '0' then
124  if ENA = '1' then
125  n.datl := DI;
126  n.state := s_vall;
127  else
128  n.state := s_idle;
129  end if;
130  else
131  ibusy := '1';
132  end if;
133 
134  when others => null;
135  end case;
136 
137  N_REGS <= n;
138 
139  DO <= r.dath & r.datl;
140  VAL <= ival;
141  BUSY <= ibusy;
142  ODD <= iodd;
143 
144  end process proc_next;
145 
146 
147 end syn;
in DIslv8
Definition: byte2word.vhd:39
( s_idle ,s_vall ,s_valw ) state_type
Definition: byte2word.vhd:52
datl:slv8 # dath:slv8 # state:state_type # regs_typerecorddatl:slv8%#%%dath:slv8%#%state:state_type%#
Definition: byte2word.vhd:58
out ODDslbit
Definition: byte2word.vhd:45
regs_type :=regs_init R_REGS
Definition: byte2word.vhd:70
in CLKslbit
Definition: byte2word.vhd:37
in RESETslbit
Definition: byte2word.vhd:38
in ENAslbit
Definition: byte2word.vhd:40
regs_type := ( ( others =>'0' ) ,( others =>'0' ) ,s_idle ) regs_init
Definition: byte2word.vhd:64
proc_nextR_REGS,DI,ENA,HOLD
Definition: byte2word.vhd:88
in HOLDslbit
Definition: byte2word.vhd:44
out DOslv16
Definition: byte2word.vhd:42
_library_ ieeeieee
Definition: byte2cdata.vhd:31
regs_type :=regs_init N_REGS
Definition: byte2word.vhd:71
out VALslbit
Definition: byte2word.vhd:43
out BUSYslbit
Definition: byte2word.vhd:41